summaryrefslogtreecommitdiff
path: root/instruction-init.h
blob: 01b3fd854821c2b1598098d83ffe10b41e18b005 (plain)
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
//	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
void* IT;



void setIT(int i, uintptr_t p, Addressing r){
	uintptr_t* p1 = (IT + (i * sizeof(uintptr_t)));
	*p1 = p;

	Addressing* r1 = (IT + ((sizeof(uintptr_t)*256)) + (i * sizeof(Addressing)));
	*r1 = r;
}

Addressing getITAddressing(int i){
	Addressing* r = IT + (sizeof(uintptr_t)*256)) + (sizeof(Addressing)*i)
	return *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);
void fLDX(Addressing, address);
void fLDY(Addressing, address);
void fSTA(Addressing, address);
void fSTX(Addressing, address);
void fSTY(Addressing, address);
// Arithmetic Instructions
void fADC(Addressing, address);
void fSBC(Addressing, address);
//Increment and Decrement Instructions
void fINC(Addressing, address);
void fINX(Addressing, address);
void fINY(Addressing, address);
void fDEC(Addressing, address);
void fDEX(Addressing, address);
void fDEY(Addressing, address);
// Logical Instructions
void fAND(Addressing, address);
void fORA(Addressing, address);
void fEOR(Addressing, address);
// Jump, Branch, Compare, and Test Bits
void fJMP(Addressing, address);
void fBCC(Addressing, address);
void fBCS(Addressing, address);
void fBEQ(Addressing, address);
void fBNE(Addressing, address);
void fBMI(Addressing, address);
void fBPL(Addressing, address);
void fBVS(Addressing, address);
void fBVC(Addressing, address);
void fCMP(Addressing, address);
void fCPX(Addressing, address);
void fCPY(Addressing, address);
void fBIT(Addressing, address);
// Shift and Rotate Instructions
void fASL(Addressing, address);
void fLSR(Addressing, address);
void fROL(Addressing, address);
void fROR(Addressing, address);
// Transfer Instructions
void fTAX(Addressing, address);
void fTAY(Addressing, address);
void fTXA(Addressing, address);
void fTYA(Addressing, address);
// Stack Instructions
void fTSX(Addressing, address);
void fTXS(Addressing, address);
void fPHA(Addressing, address);
void fPHP(Addressing, address);
void fPLA(Addressing, address);
void fPLP(Addressing, address);
// Subroutine Instructions
void fJSR(Addressing, address);
void fRTS(Addressing, address);
void fRTI(Addressing, address);
// Set/Reset Insutrctions
void fCLC(Addressing, address);
void fCLD(Addressing, address);
void fCLI(Addressing, address);
void fCLV(Addressing, address);
void fSEC(Addressing, address);
void fSED(Addressing, address);
void fSEI(Addressing, address);
// NOP/BRK Instructions
void fNOP(Addressing, address);
void fBRK(Addressing, address);

void initIT(){
	IT = malloc(256 * (sizeof(uintptr_t) + sizeof(Addressing)));

	// Load and Store Instructions
	// fLDA(Addressing, address);
	setIT(0xA9, &fLDA, eImmediate);
	setIT(0xA5, &fLDA, eZeroPage);
	setIT(0xB5, &fLDA, eZeroPageIndexedX);
	setIT(0xAD, &fLDA, eAbsolute);
	setIT(0xBD, &fLDA, eAbsoluteIndexedX);
	setIT(0xB9, &fLDA, eAbsoluteIndexedY);
	setIT(0xA1, &fLDA, eIndexedIndirect);
	setIT(0xB1, &fLDA, eIndirectIndexed);
	// fLDX(Addressing, address);
	setIT(0xA2, &fLDX, eImmediate);
	setIT(0xA6, &fLDX, eZeroPage);
	setIT(0xB6, &fLDX, eZeroPageIndexedY);
	setIT(0xAE, &fLDX, eAbsolute);
	setIT(0xBE, &fLDX, eAbsoluteIndexedY);
	// fLDY(Addressing, address);
	setIT(0xA0, &fLDY, eImmediate);
	setIT(0xA4, &fLDY, eZeroPage);
	setIT(0xB4, &fLDY, eZeroPageIndexedX);
	setIT(0xAC, &fLDY, eAbsolute);
	setIT(0xBC, &fLDY, eAbsoluteIndexedX);
	// fSTA(Addressing, address);
	setIT(0x85, &fSTA, eZeroPage);
	setIT(0x95, &fSTA, eZeroPageIndexedX);
	setIT(0x8D, &fSTA, eAbsolute);
	setIT(0x9D, &fSTA, eAbsoluteIndexedX);
	setIT(0x99, &fSTA, eAbsoluteIndexedY);
	setIT(0x81, &fSTA, eIndexedIndirect);
	setIT(0x91, &fSTA, eIndirectIndexed);
	// fSTX(Addressing, address);
	setIT(0x86, &fSTX, eZeroPage);
	setIT(0x96, &fSTX, eZeroPageIndexedX);
	setIT(0x8E, &fSTX, eAbsolute);
	// fSTY(Addressing, address);
	setIT(0x84, &fSTY, eZeroPage);
	setIT(0x94, &fSTY, eZeroPageIndexedY);
	setIT(0x8C, &fSTY, eAbsolute);

	// Arithmetic Instructions
	// fADC(Addressing, address);
	setIT(0x69, &fADC, eImmediate);
	setIT(0x65, &fADC, eZeroPage);
	setIT(0x75, &fADC, eZeroPageIndexedX);
	setIT(0x6D, &fADC, eAbsolute);
	setIT(0x7D, &fADC, eAbsoluteIndexedX);
	setIT(0x79, &fADC, eAbsoluteIndexedY);
	setIT(0x61, &fADC, eIndexedIndirect);
	setIT(0x71, &fADC, eIndirectIndexed);
	// fSBC(Addressing, address);
	setIT(0xE9, &fSBC, eImmediate);
	setIT(0xE5, &fSBC, eZeroPage);
	setIT(0xF5, &fSBC, eZeroPageIndexedX);
	setIT(0xED, &fSBC, eAbsolute);
	setIT(0xFD, &fSBC, eAbsoluteIndexedX);
	setIT(0xF9, &fSBC, eAbsoluteIndexedY);
	setIT(0xE1, &fSBC, eIndexedIndirect);
	setIT(0xF1, &fSBC, eIndirectIndexed);

	//Increment and Decrement Instructions
	//INC(Addressing, address);
	setIT(0xE6, &fINC, eZeroPage);
	setIT(0xF6, &fINC, eZeroPageIndexedX);
	setIT(0xEE, &fINC, eAbsolute);
	setIT(0xFE, &fINC, eAbsoluteIndexedX);
	//INX(Addressing, address);
	setIT(0xE8, &fINX, eImplied);
	//INY(Addressing, address);
	setIT(0xC8, &fINY, eImplied);
	//DEC(Addressing, address);
	setIT(0xC6, &fDEC, eZeroPage);
	setIT(0xD6, &fDEC, eZeroPageIndexedX);
	setIT(0xCE, &fDEC, eAbsolute);
	setIT(0xDE, &fDEC, eAbsoluteIndexedX);
	//DEX(Addressing, address);
	setIT(0xCA, &fDEX, eImplied);
	//DEY(Addressing, address);
	setIT(0x88, &fDEY, eImplied);

	// Logical Instructions
	//AND(Addressing, address);
	setIT(0x29, &fAND, eImmediate);
	setIT(0x25, &fAND, eZeroPage);
	setIT(0x35, &fAND, eZeroPageIndexedX);
	setIT(0x2D, &fAND, eAbsolute);
	setIT(0x3D, &fAND, eAbsoluteIndexedX);
	setIT(0x39, &fAND, eAbsoluteIndexedY);
	setIT(0x21, &fAND, eIndexedIndirect);
	setIT(0x31, &fAND, eIndirectIndexed);
	//ORA(Addressing, address);
	setIT(0x09, &fORA, eImmediate);
	setIT(0x05, &fORA, eZeroPage);
	setIT(0x15, &fORA, eZeroPageIndexedX);
	setIT(0x0D, &fORA, eAbsolute);
	setIT(0x1D, &fORA, eAbsoluteIndexedX);
	setIT(0x19, &fORA, eAbsoluteIndexedY);
	setIT(0x01, &fORA, eIndexedIndirect);
	setIT(0x11, &fORA, eIndirectIndexed);
	//EOR(Addressing, address);
	setIT(0x49, &fEOR, eImmediate);
	setIT(0x45, &fEOR, eZeroPage);
	setIT(0x55, &fEOR, eZeroPageIndexedX);
	setIT(0x4D, &fEOR, eAbsolute);
	setIT(0x5D, &fEOR, eAbsoluteIndexedX);
	setIT(0x59, &fEOR, eAbsoluteIndexedY);
	setIT(0x41, &fEOR, eIndexedIndirect);
	setIT(0x51, &fEOR, eIndirectIndexed);

	// Jump, Branch, Compare, and Test Bits
	//JMP(Addressing, address);
	setIT(0x4C, &fJMP, eAbsolute);
	setIT(0x6C, &fJMP, eIndirectAbsolute);
	//BCC(Addressing, address);
	setIT(0x90, &fBCC, eRelative);
	//BCS(Addressing, address);
	setIT(0xB0, &fBCS, eRelative);
	//BEQ(Addressing, address);
	setIT(0xF0, &fBEQ, eRelative);
	//BNE(Addressing, address);
	setIT(0xD0, &fBNE, eRelative);
	//BMI(Addressing, address);
	setIT(0x30, &fBMI, eRelative);
	//BPL(Addressing, address);
	setIT(0x10, &fBPL, eRelative);
	//BVS(Addressing, address);
	setIT(0x70, &fBVS, eRelative);
	//BVC(Addressing, address);
	setIT(0x50, &fBVC, eRelative);
	//CMP(Addressing, address);
	setIT(0xC9, &fCMP, eImmediate);
	setIT(0xC5, &fCMP, eZeroPage);
	setIT(0xD5, &fCMP, eZeroPageIndexedX);
	setIT(0xCD, &fCMP, eAbsolute);
	setIT(0xDD, &fCMP, eAbsoluteIndexedX);
	setIT(0xD9, &fCMP, eAbsoluteIndexedY);
	setIT(0xC1, &fCMP, eIndexedIndirect);
	setIT(0xD1, &fCMP, eIndirectIndexed);
	//CPX(Addressing, address);
	setIT(0xE0, &fCPX, eImmediate);
	setIT(0xE4, &fCPX, eZeroPage);
	setIT(0xEC, &fCPX, eAbsolute);
	//CPY(Addressing, address);
	setIT(0xC0, &fCPY, eImmediate);
	setIT(0xC4, &fCPY, eZeroPage);
	setIT(0xCC, &fCPY, eAbsolute);
	//BIT(Addressing, address);
	setIT(0x4C, &fBIT, eZeroPage);
	setIT(0x6C, &fBIT, eAbsolute);

	// Shift and Rotate Instructions
	//ASL(Addressing, address);
	setIT(0x0A, &fASL, eAccumulator);
	setIT(0x06, &fASL, eZeroPage);
	setIT(0x16, &fASL, eZeroPageIndexedX);
	setIT(0x0E, &fASL, eAbsolute);
	setIT(0x1E, &fASL, eAbsoluteIndexedX);
	//LSR(Addressing, address);
	setIT(0x4A, &fLSR, eAccumulator);
	setIT(0x46, &fLSR, eZeroPage);
	setIT(0x56, &fLSR, eZeroPageIndexedX);
	setIT(0x4E, &fLSR, eAbsolute);
	setIT(0x5E, &fLSR, eAbsoluteIndexedX);
	//ROL(Addressing, address);
	setIT(0x2A, &fROL, eAccumulator);
	setIT(0x26, &fROL, eZeroPage);
	setIT(0x36, &fROL, eZeroPageIndexedX);
	setIT(0x2E, &fROL, eAbsolute);
	setIT(0x3E, &fROL, eAbsoluteIndexedX);
	//ROR(Addressing, address);
	setIT(0x6A, &fROR, eAccumulator);
	setIT(0x66, &fROR, eZeroPage);
	setIT(0x76, &fROR, eZeroPageIndexedX);
	setIT(0x6E, &fROR, eAbsolute);
	setIT(0x7E, &fROR, eAbsoluteIndexedX);

	// Transfer Instructions
	//TAX(Addressing, address);
	setIT(0xAA, &fTAX, eImplied);
	//TAY(Addressing, address);
	setIT(0xA8, &fTAY, eImplied);
	//TXA(Addressing, address);
	setIT(0x8A, &fTXA, eImplied);
	//TYA(Addressing, address);
	setIT(0x98, &fTYA, eImplied);

	// Stack Instructions
	//TSX(Addressing, address);
	setIT(0xBA, &fTSX, eImplied);
	//TXS(Addressing, address);
	setIT(0x9A, &fTXS, eImplied);
	//PHA(Addressing, address);
	setIT(0x48, &fPHA, eImplied);
	//PHP(Addressing, address);
	setIT(0x08, &fPHP, eImplied);
	//PLA(Addressing, address);
	setIT(0x68, &fPLA, eImplied);
	//PLP(Addressing, address);
	setIT(0x28, &fPLP, eImplied);

	// Subroutine Instructions
	//JSR(Addressing, address);
	setIT(0x20, &fJSR, eAbsolute);
	//RTS(Addressing, address);
	setIT(0x60, &fRTS, eImplied);
	//RTI(Addressing, address);
	setIT(0x40, &fRTI, eImplied);

	// Set/Reset Insutrctions
	//CLC(Addressing, address);
	setIT(0x18, &fCLC, eImplied);
	//CLD(Addressing, address);
	setIT(0xD8, &fCLD, eImplied);
	//CLI(Addressing, address);
	setIT(0x58, &fCLI, eImplied);
	//CLV(Addressing, address);
	setIT(0xB8, &fCLV, eImplied);
	//SEC(Addressing, address);
	setIT(0x38, &fSEC, eImplied);
	//SED(Addressing, address);
	setIT(0xF8, &fSED, eImplied);
	//SEI(Addressing, address);
	setIT(0x78, &fSEI, eImplied);

	// NOP/BRK Instructions
	//NOP(Addressing, address);
	setIT(0xEA, &fNOP, eImplied);
	//BRK(Addressing, address);
	setIT(0x00, &fBRK, eImplied);
}