OSDN Git Service

instruction cycle & timing updated.
[motonesemu/motonesemu.git] / emulator / 6502core.c
1 #include <libio.h>
2 #include "tools.h"
3
4 typedef int (handler_6502_t) (void);
5
6 struct opcode_map {
7     unsigned char   opcode;
8     char            mnemonic[4];
9     handler_6502_t  *func;
10     int             addr_mode;
11     int             cycle;
12     int             inst_len;
13 };
14
15 static struct opcode_map *current_inst;
16 static int current_exec_index;
17
18 int func_ADC(void);
19 int func_AND(void);
20 int func_ASL(void);
21 int func_BCC(void);
22 int func_BCS(void);
23 int func_BEQ(void);
24 int func_BIT(void);
25 int func_BMI(void);
26 int func_BNE(void);
27 int func_BPL(void);
28 int func_BRK(void);
29 int func_BVC(void);
30 int func_BVS(void);
31 int func_CLC(void);
32 int func_CLD(void);
33 int func_CLI(void);
34 int func_CLV(void);
35 int func_CMP(void);
36 int func_CPX(void);
37 int func_CPY(void);
38 int func_DEC(void);
39 int func_DEX(void);
40 int func_DEY(void);
41 int func_EOR(void);
42 int func_INC(void);
43 int func_INX(void);
44 int func_INY(void);
45 int func_JMP(void);
46 int func_JSR(void);
47 int func_LDA(void);
48 int func_LDX(void);
49 int func_LDY(void);
50 int func_LSR(void);
51 int func_NOP(void);
52 int func_ORA(void);
53 int func_PHA(void);
54 int func_PHP(void);
55 int func_PLA(void);
56 int func_PLP(void);
57 int func_ROL(void);
58 int func_ROR(void);
59 int func_RTI(void);
60 int func_RTS(void);
61 int func_SBC(void);
62 int func_SEC(void);
63 int func_SED(void);
64 int func_SEI(void);
65 int func_STA(void);
66 int func_STX(void);
67 int func_STY(void);
68 int func_TAX(void);
69 int func_TAY(void);
70 int func_TSX(void);
71 int func_TXA(void);
72 int func_TXS(void);
73 int func_TYA(void);
74
75 struct opcode_map opcode_list [255] = {
76 #include "opcode"
77 };
78
79
80 /*
81  * awk '{print "int func_" $2 "(void) {\n\n}"}' < opcode-6502 | sort | uniq
82  *
83  * */
84
85 int func_ADC(void) {
86     return FALSE;
87 }
88
89 int func_AND(void) {
90     return FALSE;
91 }
92
93 int func_ASL(void) {
94     return FALSE;
95 }
96
97 int func_BCC(void) {
98     return FALSE;
99 }
100
101 int func_BCS(void) {
102     return FALSE;
103 }
104
105 int func_BEQ(void) {
106     return FALSE;
107 }
108
109 int func_BIT(void) {
110     return FALSE;
111 }
112
113 int func_BMI(void) {
114     return FALSE;
115 }
116
117 int func_BNE(void) {
118     return FALSE;
119 }
120
121 int func_BPL(void) {
122     return FALSE;
123 }
124
125 int func_BRK(void) {
126     return FALSE;
127 }
128
129 int func_BVC(void) {
130     return FALSE;
131 }
132
133 int func_BVS(void) {
134     return FALSE;
135 }
136
137 int func_CLC(void) {
138     return FALSE;
139 }
140
141 int func_CLD(void) {
142     return FALSE;
143 }
144
145 int func_CLI(void) {
146     return FALSE;
147 }
148
149 int func_CLV(void) {
150     return FALSE;
151 }
152
153 int func_CMP(void) {
154     return FALSE;
155 }
156
157 int func_CPX(void) {
158     return FALSE;
159 }
160
161 int func_CPY(void) {
162     return FALSE;
163 }
164
165 int func_DEC(void) {
166     return FALSE;
167 }
168
169 int func_DEX(void) {
170     return FALSE;
171 }
172
173 int func_DEY(void) {
174     return FALSE;
175 }
176
177 int func_EOR(void) {
178     return FALSE;
179 }
180
181 int func_INC(void) {
182     return FALSE;
183 }
184
185 int func_INX(void) {
186     return FALSE;
187 }
188
189 int func_INY(void) {
190     return FALSE;
191 }
192
193 int func_JMP(void) {
194     return FALSE;
195 }
196
197 int func_JSR(void) {
198     return FALSE;
199 }
200
201 int func_LDA(void) {
202     return FALSE;
203 }
204
205 int func_LDX(void) {
206     return FALSE;
207 }
208
209 int func_LDY(void) {
210     return FALSE;
211 }
212
213 int func_LSR(void) {
214     return FALSE;
215 }
216
217 int func_NOP(void) {
218     return FALSE;
219 }
220
221 int func_ORA(void) {
222     return FALSE;
223 }
224
225 int func_PHA(void) {
226     return FALSE;
227 }
228
229 int func_PHP(void) {
230     return FALSE;
231 }
232
233 int func_PLA(void) {
234     return FALSE;
235 }
236
237 int func_PLP(void) {
238     return FALSE;
239 }
240
241 int func_ROL(void) {
242     return FALSE;
243 }
244
245 int func_ROR(void) {
246     return FALSE;
247 }
248
249 int func_RTI(void) {
250     return FALSE;
251 }
252
253 int func_RTS(void) {
254     return FALSE;
255 }
256
257 int func_SBC(void) {
258     return FALSE;
259 }
260
261 int func_SEC(void) {
262     return FALSE;
263 }
264
265 int func_SED(void) {
266     return FALSE;
267 }
268
269 int func_SEI(void) {
270     return FALSE;
271 }
272
273 int func_STA(void) {
274     return FALSE;
275 }
276
277 int func_STX(void) {
278     return FALSE;
279 }
280
281 int func_STY(void) {
282     return FALSE;
283 }
284
285 int func_TAX(void) {
286     return FALSE;
287 }
288
289 int func_TAY(void) {
290     return FALSE;
291 }
292
293 int func_TSX(void) {
294     return FALSE;
295 }
296
297 int func_TXA(void) {
298     return FALSE;
299 }
300
301 int func_TXS(void) {
302     return FALSE;
303 }
304
305 int func_TYA(void) {
306     return FALSE;
307 }
308
309 /*
310  * decode6502:
311  * return execution cycle count
312  * */
313 int decode6502(unsigned char inst, int *cycle_cnt, int *inst_len) {
314
315     struct opcode_map * omap = &opcode_list[inst];
316     if (omap->func == NULL) {
317         return FALSE;
318     }
319
320     dprint("decode inst: %02x > %s, %d cycle, %d len\n", 
321             inst, omap->mnemonic, omap->cycle, omap->inst_len);
322     *cycle_cnt = omap->cycle;
323     *inst_len = omap->inst_len;
324
325     current_inst = omap;
326     current_exec_index = 0;
327
328     return TRUE;
329 }
330
331 int execute6502(void) {
332     current_exec_index++;
333     return current_inst->func();
334 }
335
336 int init_6502core(void) {
337     current_inst = NULL;
338     current_exec_index = 0;
339     return TRUE;
340 }
341