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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
// instruction-init.h
// Initializes every instruction function prior to addressing.h so that function addresses are accessible
// also defines the array used to refer to functions
//InstructionTable
const IT = malloc(256 * (sizeof(uintptr_t) + sizeof(Addressing)));
void setIT(int i, uintptr_t p, Addressing r){
uintptr_t* p1 = (IT + (i * sizeof(uintptr_t)));
*p1 = p;
Addressing* r1 = (IT + ((i * sizeof(Addressing)) + (sizeof(uintptr_t)*256)));
*r1 = r;
}
void callIT(int i, address val){
void (*func)(Addressing, address);
func = (IT + (sizeof(uintptr_t) * i));
Addressing r = (IT + ((i * sizeof(Addressing)) + (sizeof(uintptr_t)*256)));
func(*r, val);
}
// Load and Store Instructions
void fLDA(Addressing, address);
setIT(0xA9, &fLDA, eImmediate);
// For the sake of testing, only Immediate LDA will be trialled initially to make compiling and solving easier.
/* IT[0xA5] = {&fLDA, eZeroPage};
IT[0xB5] = {&fLDA, eZeroPageIndexedX};
IT[0xAD] = {&fLDA, eAbsolute};
IT[0xBD] = {&fLDA, eAbsoluteIndexedX};
IT[0xB9] = {&fLDA, eAbsoluteIndexedY};
IT[0xA1] = {&fLDA, eIndexedIndirect};
IT[0xB1] = {&fLDA, eIndirectIndexed};
void fLDX(Addressing, address);
IT[0xA2] = {&fLDX, eImmediate};
IT[0xA6] = {&fLDX, eZeroPage};
IT[0xB6] = {&fLDX, eZeroPageIndexedY};
IT[0xAE] = {&fLDX, eAbsolute};
IT[0xBE] = {&fLDX, eAbsoluteIndexedY};
void fLDY(Addressing, address);
IT[0xA0] = {&fLDY, eImmediate};
IT[0xA4] = {&fLDY, eZeroPage};
IT[0xB4] = {&fLDY, eZeroPageIndexedX};
IT[0xAC] = {&fLDY, eAbsolute};
IT[0xBC] = {&fLDY, eAbsoluteIndexedX};
void fSTA(Addressing, address);
IT[0x85] = {&fSTA, eZeroPage};
IT[0x95] = {&fSTA, eZeroPageIndexedX};
IT[0x8D] = {&fSTA, eAbsolute};
IT[0x9D] = {&fSTA, eAbsoluteIndexedX};
IT[0x99] = {&fSTA, eAbsoluteIndexedY};
IT[0x81] = {&fSTA, eIndexedIndirect};
IT[0x91] = {&fSTA, eIndirectIndexed};
void fSTX(Addressing, address);
IT[0x86] = {&fSTX, eZeroPage};
IT[0x96] = {&fSTX, eZeroPageIndexedX};
IT[0x8E] = {&fSTX, eAbsolute};
void fSTY(Addressing, address);
IT[0x84] = {&fSTY, eZeroPage};
IT[0x94] = {&fSTY, eZeroPageIndexedY};
IT[0x8C] = {&fSTY, eAbsolute};
// Arithmetic Instructions
void fADC(Addressing, address);
IT[0x69] = {&fADC, eImmediate};
IT[0x65] = {&fADC, eZeroPage};
IT[0x75] = {&fADC, eZeroPageIndexedX};
IT[0x6D] = {&fADC, eAbsolute};
IT[0x7D] = {&fADC, eAbsoluteIndexedX};
IT[0x79] = {&fADC, eAbsoluteIndexedY};
IT[0x61] = {&fADC, eIndexedIndirect};
IT[0x71] = {&fADC, eIndirectIndexed};
void fSBC(Addressing, address);
IT[0xE9] = {&fSBC, eImmediate};
IT[0xE5] = {&fSBC, eZeroPage};
IT[0xF5] = {&fSBC, eZeroPageIndexedX};
IT[0xED] = {&fSBC, eAbsolute};
IT[0xFD] = {&fSBC, eAbsoluteIndexedX};
IT[0xF9] = {&fSBC, eAbsoluteIndexedY};
IT[0xE1] = {&fSBC, eIndexedIndirect};
IT[0xF1] = {&fSBC, eIndirectIndexed};
//Increment and Decrement Instructions
void fINC(Addressing, address);
IT[0xE6] = {&fINC, eZeroPage};
IT[0xF6] = {&fINC, eZeroPageIndexedX};
IT[0xEE] = {&fINC, eAbsolute};
IT[0xFE] = {&fINC, eAbsoluteIndexedX};
void fINX(Addressing, address);
IT[0xE8] = {&fINX, eImplied};
void fINY(Addressing, address);
IT[0xC8] = {&fINY, eImplied};
void fDEC(Addressing, address);
IT[0xC6] = {&fDEC, eZeroPage};
IT[0xD6] = {&fDEC, eZeroPageIndexedX};
IT[0xCE] = {&fDEC, eAbsolute};
IT[0xDE] = {&fDEC, eAbsoluteIndexedX};
void fDEX(Addressing, address);
IT[0xCA] = {&fDEX, eImplied};
void fDEY(Addressing, address);
IT[0x88] = {&fDEY, eImplied};
// Logical Instructions
void fAND(Addressing, address);
IT[0x29] = {&fAND, eImmediate};
IT[0x25] = {&fAND, eZeroPage};
IT[0x35] = {&fAND, eZeroPageIndexedX};
IT[0x2D] = {&fAND, eAbsolute};
IT[0x3D] = {&fAND, eAbsoluteIndexedX};
IT[0x39] = {&fAND, eAbsoluteIndexedY};
IT[0x21] = {&fAND, eIndexedIndirect};
IT[0x31] = {&fAND, eIndirectIndexed};
void fORA(Addressing, address);
IT[0x09] = {&fORA, eImmediate};
IT[0x05] = {&fORA, eZeroPage};
IT[0x15] = {&fORA, eZeroPageIndexedX};
IT[0x0D] = {&fORA, eAbsolute};
IT[0x1D] = {&fORA, eAbsoluteIndexedX};
IT[0x19] = {&fORA, eAbsoluteIndexedY};
IT[0x01] = {&fORA, eIndexedIndirect};
IT[0x11] = {&fORA, eIndirectIndexed};
void fEOR(Addressing, address);
IT[0x49] = {&fEOR, eImmediate};
IT[0x45] = {&fEOR, eZeroPage};
IT[0x55] = {&fEOR, eZeroPageIndexedX};
IT[0x4D] = {&fEOR, eAbsolute};
IT[0x5D] = {&fEOR, eAbsoluteIndexedX};
IT[0x59] = {&fEOR, eAbsoluteIndexedY};
IT[0x41] = {&fEOR, eIndexedIndirect};
IT[0x51] = {&fEOR, eIndirectIndexed};
// Jump, Branch, Compare, and Test Bits
void fJMP(Addressing, address);
IT[0x4C] = {&fJMP, eAbsolute};
IT[0x6C] = {&fJMP, eIndirectAbsolute};
void fBCC(Addressing, address);
IT[0x90] = {&fBCC, eRelative};
void fBCS(Addressing, address);
IT[0xB0] = {&fBCS, eRelative};
void fBEQ(Addressing, address);
IT[0xF0] = {&fBEQ, eRelative};
void fBNE(Addressing, address);
IT[0xD0] = {&fBNE, eRelative};
void fBMI(Addressing, address);
IT[0x30] = {&fBMI, eRelative};
void fBPL(Addressing, address);
IT[0x10] = {&fBPL, eRelative};
void fBVS(Addressing, address);
IT[0x70] = {&fBVS, eRelative};
void fBVC(Addressing, address);
IT[0x50] = {&fBVC, eRelative};
void fCMP(Addressing, address);
IT[0xC9] = {&fCMP, eImmediate};
IT[0xC5] = {&fCMP, eZeroPage};
IT[0xD5] = {&fCMP, eZeroPageIndexedX};
IT[0xCD] = {&fCMP, eAbsolute};
IT[0xDD] = {&fCMP, eAbsoluteIndexedX};
IT[0xD9] = {&fCMP, eAbsoluteIndexedY};
IT[0xC1] = {&fCMP, eIndexedIndirect};
IT[0xD1] = {&fCMP, eIndirectIndexed};
void fCPX(Addressing, address);
IT[0xE0] = {&fCPX, eImmediate};
IT[0xE4] = {&fCPX, eZeroPage};
IT[0xEC] = {&fCPX, eAbsolute};
void fCPY(Addressing, address);
IT[0xC0] = {&fCPY, eImmediate};
IT[0xC4] = {&fCPY, eZeroPage};
IT[0xCC] = {&fCPY, eAbsolute};
void fBIT(Addressing, address);
IT[0x4C] = {&fBIT, eZeroPage};
IT[0x6C] = {&fBIT, eAbsolute};
// Shift and Rotate Instructions
void fASL(Addressing, address);
IT[0x0A] = {&fASL, eAccumulator};
IT[0x06] = {&fASL, eZeroPage};
IT[0x16] = {&fASL, eZeroPageIndexedX};
IT[0x0E] = {&fASL, eAbsolute};
IT[0x1E] = {&fASL, eAbsoluteIndexedX};
void fLSR(Addressing, address);
IT[0x4A] = {&fLSR, eAccumulator};
IT[0x46] = {&fLSR, eZeroPage};
IT[0x56] = {&fLSR, eZeroPageIndexedX};
IT[0x4E] = {&fLSR, eAbsolute};
IT[0x5E] = {&fLSR, eAbsoluteIndexedX};
void fROL(Addressing, address);
IT[0x2A] = {&fROL, eAccumulator};
IT[0x26] = {&fROL, eZeroPage};
IT[0x36] = {&fROL, eZeroPageIndexedX};
IT[0x2E] = {&fROL, eAbsolute};
IT[0x3E] = {&fROL, eAbsoluteIndexedX};
void fROR(Addressing, address);
IT[0x6A] = {&fROR, eAccumulator};
IT[0x66] = {&fROR, eZeroPage};
IT[0x76] = {&fROR, eZeroPageIndexedX};
IT[0x6E] = {&fROR, eAbsolute};
IT[0x7E] = {&fROR, eAbsoluteIndexedX};
// Transfer Instructions
void fTAX(Addressing, address);
IT[0xAA] = {&fTAX, eImplied};
void fTAY(Addressing, address);
IT[0xA8] = {&fTAY, eImplied};
void fTXA(Addressing, address);
IT[0x8A] = {&fTXA, eImplied};
void fTYA(Addressing, address);
IT[0x98] = {&fTYA, eImplied};
// Stack Instructions
void fTSX(Addressing, address);
IT[0xBA] = {&fTSX, eImplied};
void fTXS(Addressing, address);
IT[0x9A] = {&fTXS, eImplied};
void fPHA(Addressing, address);
IT[0x48] = {&fPHA, eImplied};
void fPHP(Addressing, address);
IT[0x08] = {&fPHP, eImplied};
void fPLA(Addressing, address);
IT[0x68] = {&fPLA, eImplied};
void fPLP(Addressing, address);
IT[0x28] = {&fPLP, eImplied};
// Subroutine Instructions
void fJSR(Addressing, address);
IT[0x20] = {&fJSR, eAbsolute};
void fRTS(Addressing, address);
IT[0x60] = {&fRTS, eImplied};
void fRTI(Addressing, address);
IT[0x40] = {&fRTI, eImplied};
// Set/Reset Insutrctions
void fCLC(Addressing, address);
IT[0x18] = {&fCLC, eImplied};
void fCLD(Addressing, address);
IT[0xD8] = {&fCLD, eImplied};
void fCLI(Addressing, address);
IT[0x58] = {&fCLI, eImplied};
void fCLV(Addressing, address);
IT[0xB8] = {&fCLV, eImplied};
void fSEC(Addressing, address);
IT[0x38] = {&fSEC, eImplied};
void fSED(Addressing, address);
IT[0xF8] = {&fSED, eImplied};
void fSEI(Addressing, address);
IT[0x78] = {&fSEI, eImplied};
// NOP/BRK Instructions
void fNOP(Addressing, address);
IT[0xEA] = {&fNOP, eImplied};
void fBRK(Addressing, address);
IT[0x00] = {&fBRK, eImplied};
*/
|