-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathemulator.cpp
96 lines (81 loc) · 2.45 KB
/
emulator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//==============================================================================
// _____ __ __ __ ____ ____ ___ _ __
// | ____| \/ | / /_| ___| / ___( _ )/ |/ /_
// | _| | |\/| |_____| '_ \___ \| | / _ \| | '_ \
// | |___| | | |_____| (_) |__) | |__| (_) | | (_) |
// |_____|_|__|_|___ __\___/____/ \____\___/|_|\___/
// | ____/ ___|| _ \___ /___ \
// | _| \___ \| |_) ||_ \ __) |
// | |___ ___) | __/___) / __/
// |_____|____/|_| |____/_____|
//
//------------------------------------------------------------------------------
// Copyright (C),2019 Andrew John Jacobs
// All rights reserved.
//
// This work is made available under the terms of the Creative Commons
// Attribution-NonCommercial-ShareAlike 4.0 International license. Open the
// following URL to see the details.
//
// http://creativecommons.org/licenses/by-nc-sa/4.0/
//------------------------------------------------------------------------------
// Notes:
//
//==============================================================================
#include <Arduino.h>
#pragma GCC optimize ("-O3")
#include "Emulator.h"
//==============================================================================
// Registers & State
//------------------------------------------------------------------------------
Word Registers::pc;
Word Registers::sp;
Word Registers::dp;
Word Registers::c;
Word Registers::x;
Word Registers::y;
Address Registers::pbr;
Address Registers::dbr;
Flags Registers::p;
bool Registers::e;
Interrupts Registers::ier;
volatile Interrupts Registers::ifr;
bool Registers::stopped = true;
bool Registers::interrupted;
bool Registers::waiting;
const OpcodeSet *Registers::pOpcodeSet;
//------------------------------------------------------------------------------
void Emulator::setMode(void)
{
if (e) {
pOpcodeSet = &CpuModeE11::opcodeSet;
sp.h = 0x01;
}
else {
if (p.m)
pOpcodeSet = p.x ? &CpuModeN11::opcodeSet : &CpuModeN10::opcodeSet;
else
pOpcodeSet = p.x ? &CpuModeN01::opcodeSet : &CpuModeN00::opcodeSet;
}
if (e || p.x) {
x.w = x.l;
y.w = y.l;
}
}
void Emulator::reset(void)
{
pc.w = Memory::getWord(0xfffc, 0xfffd);
sp.w = 0x0100;
dp.w = 0x0000;
p.i = 1;
p.d = 0;
p.m = 1;
p.x = 1;
pbr.a = 0;
dbr.a = 0;
e = true;
stopped = false;
interrupted = false;
waiting = false;
setMode();
}