2 * $Id: opcode.c,v 1.2 2007/07/22 13:33:26 khansen Exp $
4 * Revision 1.2 2007/07/22 13:33:26 khansen
5 * convert tabs to whitespaces
7 * Revision 1.1 2004/06/30 07:55:46 kenth
13 * (C) 2004 Kent Hansen
15 * The XORcyst is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * The XORcyst is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with The XORcyst; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 * This file contains functions for converting 6502 instruction mnemonics from
32 * an enumerated type to actual 6502 opcodes, getting zeropage-equivalent opcode
33 * of an absolute-mode opcode, getting instruction lengths, mnemonic strings ...
39 * Gets the opcode that a pair of (mnemonic, addressing mode) maps to.
40 * @param mnc Instruction mnemonic
41 * @param amode Addressing mode
42 * @return Valid opcode byte, or 0xFF if mnc and amode are an invalid combination
44 unsigned char opcode_get(instr_mnemonic mnc
, addressing_mode amode
)
46 /* 56 instructions, 13 addressing modes. */
47 static unsigned char opcode_lookup
[56][13] = {
50 /* IMPLIED_MODE */ 0xFF,
51 /* ACCUMULATOR_MODE */ 0xFF,
52 /* IMMEDIATE_MODE */ 0x69,
53 /* ZEROPAGE_MODE */ 0x65,
54 /* ZEROPAGE_X_MODE */ 0x75,
55 /* ZEROPAGE_Y_MODE */ 0xFF,
56 /* ABSOLUTE_MODE */ 0x6D,
57 /* ABSOLUTE_X_MODE */ 0x7D,
58 /* ABSOLUTE_Y_MODE */ 0x79,
59 /* PREINDEXED_INDIRECT_MODE */ 0x61,
60 /* POSTINDEXED_INDIRECT_MODE */ 0x71,
61 /* INDIRECT_MODE */ 0xFF,
62 /* RELATIVE_MODE */ 0xFF
66 /* IMPLIED_MODE */ 0xFF,
67 /* ACCUMULATOR_MODE */ 0xFF,
68 /* IMMEDIATE_MODE */ 0x29,
69 /* ZEROPAGE_MODE */ 0x25,
70 /* ZEROPAGE_X_MODE */ 0x35,
71 /* ZEROPAGE_Y_MODE */ 0xFF,
72 /* ABSOLUTE_MODE */ 0x2D,
73 /* ABSOLUTE_X_MODE */ 0x3D,
74 /* ABSOLUTE_Y_MODE */ 0x39,
75 /* PREINDEXED_INDIRECT_MODE */ 0x21,
76 /* POSTINDEXED_INDIRECT_MODE */ 0x31,
77 /* INDIRECT_MODE */ 0xFF,
78 /* RELATIVE_MODE */ 0xFF
82 /* IMPLIED_MODE */ 0x0A,
83 /* ACCUMULATOR_MODE */ 0x0A,
84 /* IMMEDIATE_MODE */ 0xFF,
85 /* ZEROPAGE_MODE */ 0x06,
86 /* ZEROPAGE_X_MODE */ 0x16,
87 /* ZEROPAGE_Y_MODE */ 0xFF,
88 /* ABSOLUTE_MODE */ 0x0E,
89 /* ABSOLUTE_X_MODE */ 0x1E,
90 /* ABSOLUTE_Y_MODE */ 0xFF,
91 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
92 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
93 /* INDIRECT_MODE */ 0xFF,
94 /* RELATIVE_MODE */ 0xFF
98 /* IMPLIED_MODE */ 0xFF,
99 /* ACCUMULATOR_MODE */ 0xFF,
100 /* IMMEDIATE_MODE */ 0xFF,
101 /* ZEROPAGE_MODE */ 0xFF,
102 /* ZEROPAGE_X_MODE */ 0xFF,
103 /* ZEROPAGE_Y_MODE */ 0xFF,
104 /* ABSOLUTE_MODE */ 0xFF,
105 /* ABSOLUTE_X_MODE */ 0xFF,
106 /* ABSOLUTE_Y_MODE */ 0xFF,
107 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
108 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
109 /* INDIRECT_MODE */ 0xFF,
110 /* RELATIVE_MODE */ 0x90
114 /* IMPLIED_MODE */ 0xFF,
115 /* ACCUMULATOR_MODE */ 0xFF,
116 /* IMMEDIATE_MODE */ 0xFF,
117 /* ZEROPAGE_MODE */ 0xFF,
118 /* ZEROPAGE_X_MODE */ 0xFF,
119 /* ZEROPAGE_Y_MODE */ 0xFF,
120 /* ABSOLUTE_MODE */ 0xFF,
121 /* ABSOLUTE_X_MODE */ 0xFF,
122 /* ABSOLUTE_Y_MODE */ 0xFF,
123 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
124 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
125 /* INDIRECT_MODE */ 0xFF,
126 /* RELATIVE_MODE */ 0xB0
130 /* IMPLIED_MODE */ 0xFF,
131 /* ACCUMULATOR_MODE */ 0xFF,
132 /* IMMEDIATE_MODE */ 0xFF,
133 /* ZEROPAGE_MODE */ 0xFF,
134 /* ZEROPAGE_X_MODE */ 0xFF,
135 /* ZEROPAGE_Y_MODE */ 0xFF,
136 /* ABSOLUTE_MODE */ 0xFF,
137 /* ABSOLUTE_X_MODE */ 0xFF,
138 /* ABSOLUTE_Y_MODE */ 0xFF,
139 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
140 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
141 /* INDIRECT_MODE */ 0xFF,
142 /* RELATIVE_MODE */ 0xF0
146 /* IMPLIED_MODE */ 0xFF,
147 /* ACCUMULATOR_MODE */ 0xFF,
148 /* IMMEDIATE_MODE */ 0xFF,
149 /* ZEROPAGE_MODE */ 0x24,
150 /* ZEROPAGE_X_MODE */ 0xFF,
151 /* ZEROPAGE_Y_MODE */ 0xFF,
152 /* ABSOLUTE_MODE */ 0x2C,
153 /* ABSOLUTE_X_MODE */ 0xFF,
154 /* ABSOLUTE_Y_MODE */ 0xFF,
155 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
156 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
157 /* INDIRECT_MODE */ 0xFF,
158 /* RELATIVE_MODE */ 0xFF
162 /* IMPLIED_MODE */ 0xFF,
163 /* ACCUMULATOR_MODE */ 0xFF,
164 /* IMMEDIATE_MODE */ 0xFF,
165 /* ZEROPAGE_MODE */ 0xFF,
166 /* ZEROPAGE_X_MODE */ 0xFF,
167 /* ZEROPAGE_Y_MODE */ 0xFF,
168 /* ABSOLUTE_MODE */ 0xFF,
169 /* ABSOLUTE_X_MODE */ 0xFF,
170 /* ABSOLUTE_Y_MODE */ 0xFF,
171 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
172 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
173 /* INDIRECT_MODE */ 0xFF,
174 /* RELATIVE_MODE */ 0x30
178 /* IMPLIED_MODE */ 0xFF,
179 /* ACCUMULATOR_MODE */ 0xFF,
180 /* IMMEDIATE_MODE */ 0xFF,
181 /* ZEROPAGE_MODE */ 0xFF,
182 /* ZEROPAGE_X_MODE */ 0xFF,
183 /* ZEROPAGE_Y_MODE */ 0xFF,
184 /* ABSOLUTE_MODE */ 0xFF,
185 /* ABSOLUTE_X_MODE */ 0xFF,
186 /* ABSOLUTE_Y_MODE */ 0xFF,
187 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
188 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
189 /* INDIRECT_MODE */ 0xFF,
190 /* RELATIVE_MODE */ 0xD0
194 /* IMPLIED_MODE */ 0xFF,
195 /* ACCUMULATOR_MODE */ 0xFF,
196 /* IMMEDIATE_MODE */ 0xFF,
197 /* ZEROPAGE_MODE */ 0xFF,
198 /* ZEROPAGE_X_MODE */ 0xFF,
199 /* ZEROPAGE_Y_MODE */ 0xFF,
200 /* ABSOLUTE_MODE */ 0xFF,
201 /* ABSOLUTE_X_MODE */ 0xFF,
202 /* ABSOLUTE_Y_MODE */ 0xFF,
203 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
204 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
205 /* INDIRECT_MODE */ 0xFF,
206 /* RELATIVE_MODE */ 0x10
210 /* IMPLIED_MODE */ 0x00,
211 /* ACCUMULATOR_MODE */ 0xFF,
212 /* IMMEDIATE_MODE */ 0xFF,
213 /* ZEROPAGE_MODE */ 0xFF,
214 /* ZEROPAGE_X_MODE */ 0xFF,
215 /* ZEROPAGE_Y_MODE */ 0xFF,
216 /* ABSOLUTE_MODE */ 0xFF,
217 /* ABSOLUTE_X_MODE */ 0xFF,
218 /* ABSOLUTE_Y_MODE */ 0xFF,
219 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
220 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
221 /* INDIRECT_MODE */ 0xFF,
222 /* RELATIVE_MODE */ 0xFF
226 /* IMPLIED_MODE */ 0xFF,
227 /* ACCUMULATOR_MODE */ 0xFF,
228 /* IMMEDIATE_MODE */ 0xFF,
229 /* ZEROPAGE_MODE */ 0xFF,
230 /* ZEROPAGE_X_MODE */ 0xFF,
231 /* ZEROPAGE_Y_MODE */ 0xFF,
232 /* ABSOLUTE_MODE */ 0xFF,
233 /* ABSOLUTE_X_MODE */ 0xFF,
234 /* ABSOLUTE_Y_MODE */ 0xFF,
235 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
236 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
237 /* INDIRECT_MODE */ 0xFF,
238 /* RELATIVE_MODE */ 0x50
242 /* IMPLIED_MODE */ 0xFF,
243 /* ACCUMULATOR_MODE */ 0xFF,
244 /* IMMEDIATE_MODE */ 0xFF,
245 /* ZEROPAGE_MODE */ 0xFF,
246 /* ZEROPAGE_X_MODE */ 0xFF,
247 /* ZEROPAGE_Y_MODE */ 0xFF,
248 /* ABSOLUTE_MODE */ 0xFF,
249 /* ABSOLUTE_X_MODE */ 0xFF,
250 /* ABSOLUTE_Y_MODE */ 0xFF,
251 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
252 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
253 /* INDIRECT_MODE */ 0xFF,
254 /* RELATIVE_MODE */ 0x70
258 /* IMPLIED_MODE */ 0x18,
259 /* ACCUMULATOR_MODE */ 0xFF,
260 /* IMMEDIATE_MODE */ 0xFF,
261 /* ZEROPAGE_MODE */ 0xFF,
262 /* ZEROPAGE_X_MODE */ 0xFF,
263 /* ZEROPAGE_Y_MODE */ 0xFF,
264 /* ABSOLUTE_MODE */ 0xFF,
265 /* ABSOLUTE_X_MODE */ 0xFF,
266 /* ABSOLUTE_Y_MODE */ 0xFF,
267 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
268 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
269 /* INDIRECT_MODE */ 0xFF,
270 /* RELATIVE_MODE */ 0xFF
274 /* IMPLIED_MODE */ 0xD8,
275 /* ACCUMULATOR_MODE */ 0xFF,
276 /* IMMEDIATE_MODE */ 0xFF,
277 /* ZEROPAGE_MODE */ 0xFF,
278 /* ZEROPAGE_X_MODE */ 0xFF,
279 /* ZEROPAGE_Y_MODE */ 0xFF,
280 /* ABSOLUTE_MODE */ 0xFF,
281 /* ABSOLUTE_X_MODE */ 0xFF,
282 /* ABSOLUTE_Y_MODE */ 0xFF,
283 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
284 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
285 /* INDIRECT_MODE */ 0xFF,
286 /* RELATIVE_MODE */ 0xFF
290 /* IMPLIED_MODE */ 0x58,
291 /* ACCUMULATOR_MODE */ 0xFF,
292 /* IMMEDIATE_MODE */ 0xFF,
293 /* ZEROPAGE_MODE */ 0xFF,
294 /* ZEROPAGE_X_MODE */ 0xFF,
295 /* ZEROPAGE_Y_MODE */ 0xFF,
296 /* ABSOLUTE_MODE */ 0xFF,
297 /* ABSOLUTE_X_MODE */ 0xFF,
298 /* ABSOLUTE_Y_MODE */ 0xFF,
299 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
300 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
301 /* INDIRECT_MODE */ 0xFF,
302 /* RELATIVE_MODE */ 0xFF
306 /* IMPLIED_MODE */ 0xB8,
307 /* ACCUMULATOR_MODE */ 0xFF,
308 /* IMMEDIATE_MODE */ 0xFF,
309 /* ZEROPAGE_MODE */ 0xFF,
310 /* ZEROPAGE_X_MODE */ 0xFF,
311 /* ZEROPAGE_Y_MODE */ 0xFF,
312 /* ABSOLUTE_MODE */ 0xFF,
313 /* ABSOLUTE_X_MODE */ 0xFF,
314 /* ABSOLUTE_Y_MODE */ 0xFF,
315 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
316 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
317 /* INDIRECT_MODE */ 0xFF,
318 /* RELATIVE_MODE */ 0xFF
322 /* IMPLIED_MODE */ 0xFF,
323 /* ACCUMULATOR_MODE */ 0xFF,
324 /* IMMEDIATE_MODE */ 0xC9,
325 /* ZEROPAGE_MODE */ 0xC5,
326 /* ZEROPAGE_X_MODE */ 0xD5,
327 /* ZEROPAGE_Y_MODE */ 0xFF,
328 /* ABSOLUTE_MODE */ 0xCD,
329 /* ABSOLUTE_X_MODE */ 0xDD,
330 /* ABSOLUTE_Y_MODE */ 0xD9,
331 /* PREINDEXED_INDIRECT_MODE */ 0xC1,
332 /* POSTINDEXED_INDIRECT_MODE */ 0xD1,
333 /* INDIRECT_MODE */ 0xFF,
334 /* RELATIVE_MODE */ 0xFF
338 /* IMPLIED_MODE */ 0xFF,
339 /* ACCUMULATOR_MODE */ 0xFF,
340 /* IMMEDIATE_MODE */ 0xE0,
341 /* ZEROPAGE_MODE */ 0xE4,
342 /* ZEROPAGE_X_MODE */ 0xFF,
343 /* ZEROPAGE_Y_MODE */ 0xFF,
344 /* ABSOLUTE_MODE */ 0xEC,
345 /* ABSOLUTE_X_MODE */ 0xFF,
346 /* ABSOLUTE_Y_MODE */ 0xFF,
347 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
348 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
349 /* INDIRECT_MODE */ 0xFF,
350 /* RELATIVE_MODE */ 0xFF
354 /* IMPLIED_MODE */ 0xFF,
355 /* ACCUMULATOR_MODE */ 0xFF,
356 /* IMMEDIATE_MODE */ 0xC0,
357 /* ZEROPAGE_MODE */ 0xC4,
358 /* ZEROPAGE_X_MODE */ 0xFF,
359 /* ZEROPAGE_Y_MODE */ 0xFF,
360 /* ABSOLUTE_MODE */ 0xCC,
361 /* ABSOLUTE_X_MODE */ 0xFF,
362 /* ABSOLUTE_Y_MODE */ 0xFF,
363 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
364 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
365 /* INDIRECT_MODE */ 0xFF,
366 /* RELATIVE_MODE */ 0xFF
370 /* IMPLIED_MODE */ 0xFF,
371 /* ACCUMULATOR_MODE */ 0xFF,
372 /* IMMEDIATE_MODE */ 0xFF,
373 /* ZEROPAGE_MODE */ 0xC6,
374 /* ZEROPAGE_X_MODE */ 0xD6,
375 /* ZEROPAGE_Y_MODE */ 0xFF,
376 /* ABSOLUTE_MODE */ 0xCE,
377 /* ABSOLUTE_X_MODE */ 0xDE,
378 /* ABSOLUTE_Y_MODE */ 0xFF,
379 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
380 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
381 /* INDIRECT_MODE */ 0xFF,
382 /* RELATIVE_MODE */ 0xFF
386 /* IMPLIED_MODE */ 0xCA,
387 /* ACCUMULATOR_MODE */ 0xFF,
388 /* IMMEDIATE_MODE */ 0xFF,
389 /* ZEROPAGE_MODE */ 0xFF,
390 /* ZEROPAGE_X_MODE */ 0xFF,
391 /* ZEROPAGE_Y_MODE */ 0xFF,
392 /* ABSOLUTE_MODE */ 0xFF,
393 /* ABSOLUTE_X_MODE */ 0xFF,
394 /* ABSOLUTE_Y_MODE */ 0xFF,
395 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
396 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
397 /* INDIRECT_MODE */ 0xFF,
398 /* RELATIVE_MODE */ 0xFF
402 /* IMPLIED_MODE */ 0x88,
403 /* ACCUMULATOR_MODE */ 0xFF,
404 /* IMMEDIATE_MODE */ 0xFF,
405 /* ZEROPAGE_MODE */ 0xFF,
406 /* ZEROPAGE_X_MODE */ 0xFF,
407 /* ZEROPAGE_Y_MODE */ 0xFF,
408 /* ABSOLUTE_MODE */ 0xFF,
409 /* ABSOLUTE_X_MODE */ 0xFF,
410 /* ABSOLUTE_Y_MODE */ 0xFF,
411 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
412 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
413 /* INDIRECT_MODE */ 0xFF,
414 /* RELATIVE_MODE */ 0xFF
418 /* IMPLIED_MODE */ 0xFF,
419 /* ACCUMULATOR_MODE */ 0xFF,
420 /* IMMEDIATE_MODE */ 0x49,
421 /* ZEROPAGE_MODE */ 0x45,
422 /* ZEROPAGE_X_MODE */ 0x55,
423 /* ZEROPAGE_Y_MODE */ 0xFF,
424 /* ABSOLUTE_MODE */ 0x4D,
425 /* ABSOLUTE_X_MODE */ 0x5D,
426 /* ABSOLUTE_Y_MODE */ 0x59,
427 /* PREINDEXED_INDIRECT_MODE */ 0x41,
428 /* POSTINDEXED_INDIRECT_MODE */ 0x51,
429 /* INDIRECT_MODE */ 0xFF,
430 /* RELATIVE_MODE */ 0xFF
434 /* IMPLIED_MODE */ 0xFF,
435 /* ACCUMULATOR_MODE */ 0xFF,
436 /* IMMEDIATE_MODE */ 0xFF,
437 /* ZEROPAGE_MODE */ 0xE6,
438 /* ZEROPAGE_X_MODE */ 0xF6,
439 /* ZEROPAGE_Y_MODE */ 0xFF,
440 /* ABSOLUTE_MODE */ 0xEE,
441 /* ABSOLUTE_X_MODE */ 0xFE,
442 /* ABSOLUTE_Y_MODE */ 0xFF,
443 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
444 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
445 /* INDIRECT_MODE */ 0xFF,
446 /* RELATIVE_MODE */ 0xFF
450 /* IMPLIED_MODE */ 0xE8,
451 /* ACCUMULATOR_MODE */ 0xFF,
452 /* IMMEDIATE_MODE */ 0xFF,
453 /* ZEROPAGE_MODE */ 0xFF,
454 /* ZEROPAGE_X_MODE */ 0xFF,
455 /* ZEROPAGE_Y_MODE */ 0xFF,
456 /* ABSOLUTE_MODE */ 0xFF,
457 /* ABSOLUTE_X_MODE */ 0xFF,
458 /* ABSOLUTE_Y_MODE */ 0xFF,
459 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
460 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
461 /* INDIRECT_MODE */ 0xFF,
462 /* RELATIVE_MODE */ 0xFF
466 /* IMPLIED_MODE */ 0xC8,
467 /* ACCUMULATOR_MODE */ 0xFF,
468 /* IMMEDIATE_MODE */ 0xFF,
469 /* ZEROPAGE_MODE */ 0xFF,
470 /* ZEROPAGE_X_MODE */ 0xFF,
471 /* ZEROPAGE_Y_MODE */ 0xFF,
472 /* ABSOLUTE_MODE */ 0xFF,
473 /* ABSOLUTE_X_MODE */ 0xFF,
474 /* ABSOLUTE_Y_MODE */ 0xFF,
475 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
476 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
477 /* INDIRECT_MODE */ 0xFF,
478 /* RELATIVE_MODE */ 0xFF
482 /* IMPLIED_MODE */ 0xFF,
483 /* ACCUMULATOR_MODE */ 0xFF,
484 /* IMMEDIATE_MODE */ 0xFF,
485 /* ZEROPAGE_MODE */ 0xFF,
486 /* ZEROPAGE_X_MODE */ 0xFF,
487 /* ZEROPAGE_Y_MODE */ 0xFF,
488 /* ABSOLUTE_MODE */ 0x4C,
489 /* ABSOLUTE_X_MODE */ 0xFF,
490 /* ABSOLUTE_Y_MODE */ 0xFF,
491 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
492 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
493 /* INDIRECT_MODE */ 0x6C,
494 /* RELATIVE_MODE */ 0xFF
498 /* IMPLIED_MODE */ 0xFF,
499 /* ACCUMULATOR_MODE */ 0xFF,
500 /* IMMEDIATE_MODE */ 0xFF,
501 /* ZEROPAGE_MODE */ 0xFF,
502 /* ZEROPAGE_X_MODE */ 0xFF,
503 /* ZEROPAGE_Y_MODE */ 0xFF,
504 /* ABSOLUTE_MODE */ 0x20,
505 /* ABSOLUTE_X_MODE */ 0xFF,
506 /* ABSOLUTE_Y_MODE */ 0xFF,
507 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
508 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
509 /* INDIRECT_MODE */ 0xFF,
510 /* RELATIVE_MODE */ 0xFF
514 /* IMPLIED_MODE */ 0xFF,
515 /* ACCUMULATOR_MODE */ 0xFF,
516 /* IMMEDIATE_MODE */ 0xA9,
517 /* ZEROPAGE_MODE */ 0xA5,
518 /* ZEROPAGE_X_MODE */ 0xB5,
519 /* ZEROPAGE_Y_MODE */ 0xFF,
520 /* ABSOLUTE_MODE */ 0xAD,
521 /* ABSOLUTE_X_MODE */ 0xBD,
522 /* ABSOLUTE_Y_MODE */ 0xB9,
523 /* PREINDEXED_INDIRECT_MODE */ 0xA1,
524 /* POSTINDEXED_INDIRECT_MODE */ 0xB1,
525 /* INDIRECT_MODE */ 0xFF,
526 /* RELATIVE_MODE */ 0xFF
530 /* IMPLIED_MODE */ 0xFF,
531 /* ACCUMULATOR_MODE */ 0xFF,
532 /* IMMEDIATE_MODE */ 0xA2,
533 /* ZEROPAGE_MODE */ 0xA6,
534 /* ZEROPAGE_X_MODE */ 0xFF,
535 /* ZEROPAGE_Y_MODE */ 0xB6,
536 /* ABSOLUTE_MODE */ 0xAE,
537 /* ABSOLUTE_X_MODE */ 0xFF,
538 /* ABSOLUTE_Y_MODE */ 0xBE,
539 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
540 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
541 /* INDIRECT_MODE */ 0xFF,
542 /* RELATIVE_MODE */ 0xFF
546 /* IMPLIED_MODE */ 0xFF,
547 /* ACCUMULATOR_MODE */ 0xFF,
548 /* IMMEDIATE_MODE */ 0xA0,
549 /* ZEROPAGE_MODE */ 0xA4,
550 /* ZEROPAGE_X_MODE */ 0xB4,
551 /* ZEROPAGE_Y_MODE */ 0xFF,
552 /* ABSOLUTE_MODE */ 0xAC,
553 /* ABSOLUTE_X_MODE */ 0xBC,
554 /* ABSOLUTE_Y_MODE */ 0xFF,
555 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
556 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
557 /* INDIRECT_MODE */ 0xFF,
558 /* RELATIVE_MODE */ 0xFF
562 /* IMPLIED_MODE */ 0x4A,
563 /* ACCUMULATOR_MODE */ 0x4A,
564 /* IMMEDIATE_MODE */ 0xFF,
565 /* ZEROPAGE_MODE */ 0x46,
566 /* ZEROPAGE_X_MODE */ 0x56,
567 /* ZEROPAGE_Y_MODE */ 0xFF,
568 /* ABSOLUTE_MODE */ 0x4E,
569 /* ABSOLUTE_X_MODE */ 0x5E,
570 /* ABSOLUTE_Y_MODE */ 0xFF,
571 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
572 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
573 /* INDIRECT_MODE */ 0xFF,
574 /* RELATIVE_MODE */ 0xFF
578 /* IMPLIED_MODE */ 0xEA,
579 /* ACCUMULATOR_MODE */ 0xFF,
580 /* IMMEDIATE_MODE */ 0xFF,
581 /* ZEROPAGE_MODE */ 0xFF,
582 /* ZEROPAGE_X_MODE */ 0xFF,
583 /* ZEROPAGE_Y_MODE */ 0xFF,
584 /* ABSOLUTE_MODE */ 0xFF,
585 /* ABSOLUTE_X_MODE */ 0xFF,
586 /* ABSOLUTE_Y_MODE */ 0xFF,
587 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
588 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
589 /* INDIRECT_MODE */ 0xFF,
590 /* RELATIVE_MODE */ 0xFF
594 /* IMPLIED_MODE */ 0xFF,
595 /* ACCUMULATOR_MODE */ 0xFF,
596 /* IMMEDIATE_MODE */ 0x09,
597 /* ZEROPAGE_MODE */ 0x05,
598 /* ZEROPAGE_X_MODE */ 0x15,
599 /* ZEROPAGE_Y_MODE */ 0xFF,
600 /* ABSOLUTE_MODE */ 0x0D,
601 /* ABSOLUTE_X_MODE */ 0x1D,
602 /* ABSOLUTE_Y_MODE */ 0x19,
603 /* PREINDEXED_INDIRECT_MODE */ 0x01,
604 /* POSTINDEXED_INDIRECT_MODE */ 0x11,
605 /* INDIRECT_MODE */ 0xFF,
606 /* RELATIVE_MODE */ 0xFF
610 /* IMPLIED_MODE */ 0x48,
611 /* ACCUMULATOR_MODE */ 0xFF,
612 /* IMMEDIATE_MODE */ 0xFF,
613 /* ZEROPAGE_MODE */ 0xFF,
614 /* ZEROPAGE_X_MODE */ 0xFF,
615 /* ZEROPAGE_Y_MODE */ 0xFF,
616 /* ABSOLUTE_MODE */ 0xFF,
617 /* ABSOLUTE_X_MODE */ 0xFF,
618 /* ABSOLUTE_Y_MODE */ 0xFF,
619 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
620 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
621 /* INDIRECT_MODE */ 0xFF,
622 /* RELATIVE_MODE */ 0xFF
626 /* IMPLIED_MODE */ 0x08,
627 /* ACCUMULATOR_MODE */ 0xFF,
628 /* IMMEDIATE_MODE */ 0xFF,
629 /* ZEROPAGE_MODE */ 0xFF,
630 /* ZEROPAGE_X_MODE */ 0xFF,
631 /* ZEROPAGE_Y_MODE */ 0xFF,
632 /* ABSOLUTE_MODE */ 0xFF,
633 /* ABSOLUTE_X_MODE */ 0xFF,
634 /* ABSOLUTE_Y_MODE */ 0xFF,
635 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
636 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
637 /* INDIRECT_MODE */ 0xFF,
638 /* RELATIVE_MODE */ 0xFF
642 /* IMPLIED_MODE */ 0x68,
643 /* ACCUMULATOR_MODE */ 0xFF,
644 /* IMMEDIATE_MODE */ 0xFF,
645 /* ZEROPAGE_MODE */ 0xFF,
646 /* ZEROPAGE_X_MODE */ 0xFF,
647 /* ZEROPAGE_Y_MODE */ 0xFF,
648 /* ABSOLUTE_MODE */ 0xFF,
649 /* ABSOLUTE_X_MODE */ 0xFF,
650 /* ABSOLUTE_Y_MODE */ 0xFF,
651 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
652 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
653 /* INDIRECT_MODE */ 0xFF,
654 /* RELATIVE_MODE */ 0xFF
658 /* IMPLIED_MODE */ 0x28,
659 /* ACCUMULATOR_MODE */ 0xFF,
660 /* IMMEDIATE_MODE */ 0xFF,
661 /* ZEROPAGE_MODE */ 0xFF,
662 /* ZEROPAGE_X_MODE */ 0xFF,
663 /* ZEROPAGE_Y_MODE */ 0xFF,
664 /* ABSOLUTE_MODE */ 0xFF,
665 /* ABSOLUTE_X_MODE */ 0xFF,
666 /* ABSOLUTE_Y_MODE */ 0xFF,
667 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
668 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
669 /* INDIRECT_MODE */ 0xFF,
670 /* RELATIVE_MODE */ 0xFF
674 /* IMPLIED_MODE */ 0x2A,
675 /* ACCUMULATOR_MODE */ 0x2A,
676 /* IMMEDIATE_MODE */ 0xFF,
677 /* ZEROPAGE_MODE */ 0x26,
678 /* ZEROPAGE_X_MODE */ 0x36,
679 /* ZEROPAGE_Y_MODE */ 0xFF,
680 /* ABSOLUTE_MODE */ 0x2E,
681 /* ABSOLUTE_X_MODE */ 0x3E,
682 /* ABSOLUTE_Y_MODE */ 0xFF,
683 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
684 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
685 /* INDIRECT_MODE */ 0xFF,
686 /* RELATIVE_MODE */ 0xFF
690 /* IMPLIED_MODE */ 0x6A,
691 /* ACCUMULATOR_MODE */ 0x6A,
692 /* IMMEDIATE_MODE */ 0xFF,
693 /* ZEROPAGE_MODE */ 0x66,
694 /* ZEROPAGE_X_MODE */ 0x76,
695 /* ZEROPAGE_Y_MODE */ 0xFF,
696 /* ABSOLUTE_MODE */ 0x6E,
697 /* ABSOLUTE_X_MODE */ 0x7E,
698 /* ABSOLUTE_Y_MODE */ 0xFF,
699 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
700 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
701 /* INDIRECT_MODE */ 0xFF,
702 /* RELATIVE_MODE */ 0xFF
706 /* IMPLIED_MODE */ 0x40,
707 /* ACCUMULATOR_MODE */ 0xFF,
708 /* IMMEDIATE_MODE */ 0xFF,
709 /* ZEROPAGE_MODE */ 0xFF,
710 /* ZEROPAGE_X_MODE */ 0xFF,
711 /* ZEROPAGE_Y_MODE */ 0xFF,
712 /* ABSOLUTE_MODE */ 0xFF,
713 /* ABSOLUTE_X_MODE */ 0xFF,
714 /* ABSOLUTE_Y_MODE */ 0xFF,
715 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
716 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
717 /* INDIRECT_MODE */ 0xFF,
718 /* RELATIVE_MODE */ 0xFF
722 /* IMPLIED_MODE */ 0x60,
723 /* ACCUMULATOR_MODE */ 0xFF,
724 /* IMMEDIATE_MODE */ 0xFF,
725 /* ZEROPAGE_MODE */ 0xFF,
726 /* ZEROPAGE_X_MODE */ 0xFF,
727 /* ZEROPAGE_Y_MODE */ 0xFF,
728 /* ABSOLUTE_MODE */ 0xFF,
729 /* ABSOLUTE_X_MODE */ 0xFF,
730 /* ABSOLUTE_Y_MODE */ 0xFF,
731 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
732 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
733 /* INDIRECT_MODE */ 0xFF,
734 /* RELATIVE_MODE */ 0xFF
738 /* IMPLIED_MODE */ 0xFF,
739 /* ACCUMULATOR_MODE */ 0xFF,
740 /* IMMEDIATE_MODE */ 0xE9,
741 /* ZEROPAGE_MODE */ 0xE5,
742 /* ZEROPAGE_X_MODE */ 0xF5,
743 /* ZEROPAGE_Y_MODE */ 0xFF,
744 /* ABSOLUTE_MODE */ 0xED,
745 /* ABSOLUTE_X_MODE */ 0xFD,
746 /* ABSOLUTE_Y_MODE */ 0xF9,
747 /* PREINDEXED_INDIRECT_MODE */ 0xE1,
748 /* POSTINDEXED_INDIRECT_MODE */ 0xF1,
749 /* INDIRECT_MODE */ 0xFF,
750 /* RELATIVE_MODE */ 0xFF
754 /* IMPLIED_MODE */ 0x38,
755 /* ACCUMULATOR_MODE */ 0xFF,
756 /* IMMEDIATE_MODE */ 0xFF,
757 /* ZEROPAGE_MODE */ 0xFF,
758 /* ZEROPAGE_X_MODE */ 0xFF,
759 /* ZEROPAGE_Y_MODE */ 0xFF,
760 /* ABSOLUTE_MODE */ 0xFF,
761 /* ABSOLUTE_X_MODE */ 0xFF,
762 /* ABSOLUTE_Y_MODE */ 0xFF,
763 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
764 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
765 /* INDIRECT_MODE */ 0xFF,
766 /* RELATIVE_MODE */ 0xFF
770 /* IMPLIED_MODE */ 0xF8,
771 /* ACCUMULATOR_MODE */ 0xFF,
772 /* IMMEDIATE_MODE */ 0xFF,
773 /* ZEROPAGE_MODE */ 0xFF,
774 /* ZEROPAGE_X_MODE */ 0xFF,
775 /* ZEROPAGE_Y_MODE */ 0xFF,
776 /* ABSOLUTE_MODE */ 0xFF,
777 /* ABSOLUTE_X_MODE */ 0xFF,
778 /* ABSOLUTE_Y_MODE */ 0xFF,
779 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
780 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
781 /* INDIRECT_MODE */ 0xFF,
782 /* RELATIVE_MODE */ 0xFF
786 /* IMPLIED_MODE */ 0x78,
787 /* ACCUMULATOR_MODE */ 0xFF,
788 /* IMMEDIATE_MODE */ 0xFF,
789 /* ZEROPAGE_MODE */ 0xFF,
790 /* ZEROPAGE_X_MODE */ 0xFF,
791 /* ZEROPAGE_Y_MODE */ 0xFF,
792 /* ABSOLUTE_MODE */ 0xFF,
793 /* ABSOLUTE_X_MODE */ 0xFF,
794 /* ABSOLUTE_Y_MODE */ 0xFF,
795 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
796 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
797 /* INDIRECT_MODE */ 0xFF,
798 /* RELATIVE_MODE */ 0xFF
802 /* IMPLIED_MODE */ 0xFF,
803 /* ACCUMULATOR_MODE */ 0xFF,
804 /* IMMEDIATE_MODE */ 0xFF,
805 /* ZEROPAGE_MODE */ 0x85,
806 /* ZEROPAGE_X_MODE */ 0x95,
807 /* ZEROPAGE_Y_MODE */ 0xFF,
808 /* ABSOLUTE_MODE */ 0x8D,
809 /* ABSOLUTE_X_MODE */ 0x9D,
810 /* ABSOLUTE_Y_MODE */ 0x99,
811 /* PREINDEXED_INDIRECT_MODE */ 0x81,
812 /* POSTINDEXED_INDIRECT_MODE */ 0x91,
813 /* INDIRECT_MODE */ 0xFF,
814 /* RELATIVE_MODE */ 0xFF
818 /* IMPLIED_MODE */ 0xFF,
819 /* ACCUMULATOR_MODE */ 0xFF,
820 /* IMMEDIATE_MODE */ 0xFF,
821 /* ZEROPAGE_MODE */ 0x86,
822 /* ZEROPAGE_X_MODE */ 0xFF,
823 /* ZEROPAGE_Y_MODE */ 0x96,
824 /* ABSOLUTE_MODE */ 0x8E,
825 /* ABSOLUTE_X_MODE */ 0xFF,
826 /* ABSOLUTE_Y_MODE */ 0xFF,
827 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
828 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
829 /* INDIRECT_MODE */ 0xFF,
830 /* RELATIVE_MODE */ 0xFF
834 /* IMPLIED_MODE */ 0xFF,
835 /* ACCUMULATOR_MODE */ 0xFF,
836 /* IMMEDIATE_MODE */ 0xFF,
837 /* ZEROPAGE_MODE */ 0x84,
838 /* ZEROPAGE_X_MODE */ 0x94,
839 /* ZEROPAGE_Y_MODE */ 0xFF,
840 /* ABSOLUTE_MODE */ 0x8C,
841 /* ABSOLUTE_X_MODE */ 0xFF,
842 /* ABSOLUTE_Y_MODE */ 0xFF,
843 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
844 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
845 /* INDIRECT_MODE */ 0xFF,
846 /* RELATIVE_MODE */ 0xFF
850 /* IMPLIED_MODE */ 0xAA,
851 /* ACCUMULATOR_MODE */ 0xFF,
852 /* IMMEDIATE_MODE */ 0xFF,
853 /* ZEROPAGE_MODE */ 0xFF,
854 /* ZEROPAGE_X_MODE */ 0xFF,
855 /* ZEROPAGE_Y_MODE */ 0xFF,
856 /* ABSOLUTE_MODE */ 0xFF,
857 /* ABSOLUTE_X_MODE */ 0xFF,
858 /* ABSOLUTE_Y_MODE */ 0xFF,
859 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
860 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
861 /* INDIRECT_MODE */ 0xFF,
862 /* RELATIVE_MODE */ 0xFF
866 /* IMPLIED_MODE */ 0xA8,
867 /* ACCUMULATOR_MODE */ 0xFF,
868 /* IMMEDIATE_MODE */ 0xFF,
869 /* ZEROPAGE_MODE */ 0xFF,
870 /* ZEROPAGE_X_MODE */ 0xFF,
871 /* ZEROPAGE_Y_MODE */ 0xFF,
872 /* ABSOLUTE_MODE */ 0xFF,
873 /* ABSOLUTE_X_MODE */ 0xFF,
874 /* ABSOLUTE_Y_MODE */ 0xFF,
875 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
876 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
877 /* INDIRECT_MODE */ 0xFF,
878 /* RELATIVE_MODE */ 0xFF
882 /* IMPLIED_MODE */ 0xBA,
883 /* ACCUMULATOR_MODE */ 0xFF,
884 /* IMMEDIATE_MODE */ 0xFF,
885 /* ZEROPAGE_MODE */ 0xFF,
886 /* ZEROPAGE_X_MODE */ 0xFF,
887 /* ZEROPAGE_Y_MODE */ 0xFF,
888 /* ABSOLUTE_MODE */ 0xFF,
889 /* ABSOLUTE_X_MODE */ 0xFF,
890 /* ABSOLUTE_Y_MODE */ 0xFF,
891 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
892 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
893 /* INDIRECT_MODE */ 0xFF,
894 /* RELATIVE_MODE */ 0xFF
898 /* IMPLIED_MODE */ 0x8A,
899 /* ACCUMULATOR_MODE */ 0xFF,
900 /* IMMEDIATE_MODE */ 0xFF,
901 /* ZEROPAGE_MODE */ 0xFF,
902 /* ZEROPAGE_X_MODE */ 0xFF,
903 /* ZEROPAGE_Y_MODE */ 0xFF,
904 /* ABSOLUTE_MODE */ 0xFF,
905 /* ABSOLUTE_X_MODE */ 0xFF,
906 /* ABSOLUTE_Y_MODE */ 0xFF,
907 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
908 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
909 /* INDIRECT_MODE */ 0xFF,
910 /* RELATIVE_MODE */ 0xFF
914 /* IMPLIED_MODE */ 0x9A,
915 /* ACCUMULATOR_MODE */ 0xFF,
916 /* IMMEDIATE_MODE */ 0xFF,
917 /* ZEROPAGE_MODE */ 0xFF,
918 /* ZEROPAGE_X_MODE */ 0xFF,
919 /* ZEROPAGE_Y_MODE */ 0xFF,
920 /* ABSOLUTE_MODE */ 0xFF,
921 /* ABSOLUTE_X_MODE */ 0xFF,
922 /* ABSOLUTE_Y_MODE */ 0xFF,
923 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
924 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
925 /* INDIRECT_MODE */ 0xFF,
926 /* RELATIVE_MODE */ 0xFF
930 /* IMPLIED_MODE */ 0x98,
931 /* ACCUMULATOR_MODE */ 0xFF,
932 /* IMMEDIATE_MODE */ 0xFF,
933 /* ZEROPAGE_MODE */ 0xFF,
934 /* ZEROPAGE_X_MODE */ 0xFF,
935 /* ZEROPAGE_Y_MODE */ 0xFF,
936 /* ABSOLUTE_MODE */ 0xFF,
937 /* ABSOLUTE_X_MODE */ 0xFF,
938 /* ABSOLUTE_Y_MODE */ 0xFF,
939 /* PREINDEXED_INDIRECT_MODE */ 0xFF,
940 /* POSTINDEXED_INDIRECT_MODE */ 0xFF,
941 /* INDIRECT_MODE */ 0xFF,
942 /* RELATIVE_MODE */ 0xFF
946 return opcode_lookup
[mnc
][amode
];
950 * Gets the length of an instruction, in bytes, given an opcode.
951 * The length includes the opcode (1 byte) and operand (0, 1 or 2 bytes).
952 * @param op Operation code
954 int opcode_length(unsigned char op
)
956 /* Lookup-table indexed by opcode */
957 static int length_lookup
[] = {
958 1, 2, 0, 0, 0, 2, 2, 0, 1, 2, 1, 0, 0, 3, 3, 0,
959 2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
960 3, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
961 2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
962 1, 2, 0, 0, 0, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
963 2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
964 1, 2, 0, 0, 0, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
965 2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
966 0, 2, 0, 0, 2, 2, 2, 0, 1, 1, 1, 0, 3, 3, 3, 0,
967 2, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 0, 3, 0, 0,
968 2, 2, 2, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
969 2, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 3, 3, 3, 0,
970 2, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
971 2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
972 2, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
973 2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0
976 return length_lookup
[op
];
980 * Gets the zeropage-equivalent opcode of an absolute-mode opcode, if such a
981 * conversion is possible.
983 * @return Equivalent opcode, or 0xFF if one does not exist
985 unsigned char opcode_zp_equiv(unsigned char op
)
988 case 0x6D: return 0x65; /* ADC oper */
989 case 0x7D: return 0x75; /* ADC oper,X */
990 case 0x2D: return 0x25; /* AND oper */
991 case 0x3D: return 0x35; /* AND oper,X */
992 case 0x0E: return 0x06; /* ASL oper */
993 case 0x1E: return 0x16; /* ASL oper,X */
994 case 0x2C: return 0x24; /* BIT oper */
995 case 0xCD: return 0xC5; /* CMP oper */
996 case 0xDD: return 0xD5; /* CMP oper,X */
997 case 0xEC: return 0xE4; /* CPX oper */
998 case 0xCC: return 0xC4; /* CPY oper */
999 case 0xCE: return 0xC6; /* DEC oper */
1000 case 0xDE: return 0xD6; /* DEC oper,X */
1001 case 0x4D: return 0x45; /* EOR oper */
1002 case 0x5D: return 0x55; /* EOR oper,X */
1003 case 0xEE: return 0xE6; /* INC oper */
1004 case 0xFE: return 0xF6; /* INC oper,X */
1005 case 0xAD: return 0xA5; /* LDA oper */
1006 case 0xBD: return 0xB5; /* LDA oper,X */
1007 case 0xAE: return 0xA6; /* LDX oper */
1008 case 0xBE: return 0xB6; /* LDX oper,Y */
1009 case 0xAC: return 0xA4; /* LDY oper */
1010 case 0xBC: return 0xB4; /* LDY oper,X */
1011 case 0x4E: return 0x46; /* LSR oper */
1012 case 0x5E: return 0x56; /* LSR oper,X */
1013 case 0x0D: return 0x05; /* ORA oper */
1014 case 0x1D: return 0x15; /* ORA oper,X */
1015 case 0x2E: return 0x26; /* ROL oper */
1016 case 0x3E: return 0x36; /* ROL oper,X */
1017 case 0x6E: return 0x66; /* ROR oper */
1018 case 0x7E: return 0x76; /* ROR oper,X */
1019 case 0xED: return 0xE5; /* SBC oper */
1020 case 0xFD: return 0xF5; /* SBC oper,X */
1021 case 0x8D: return 0x85; /* STA oper */
1022 case 0x9D: return 0x95; /* STA oper,X */
1023 case 0x8E: return 0x86; /* STX oper */
1024 case 0x8C: return 0x84; /* STY oper */
1030 * Gets the string mnemonic of a 6502 opcode.
1032 * @return String representation of opcode
1034 const char *opcode_to_string(unsigned char op
)
1036 static char *mnemonic_lookup
[256] = {
1037 "BRK","ORA","???","???","???","ORA","ASL","???","PHP","ORA","ASL","???","???","ORA","ASL","???",
1038 "BPL","ORA","???","???","???","ORA","ASL","???","CLC","ORA","???","???","???","ORA","ASL","???",
1039 "JSR","AND","???","???","BIT","AND","ROL","???","PLP","AND","ROL","???","BIT","AND","ROL","???",
1040 "BMI","AND","???","???","???","AND","ROL","???","SEC","AND","???","???","???","AND","ROL","???",
1041 "RTI","EOR","???","???","???","EOR","LSR","???","PHA","EOR","LSR","???","JMP","EOR","LSR","???",
1042 "BVC","EOR","???","???","???","EOR","LSR","???","CLI","EOR","???","???","???","EOR","LSR","???",
1043 "RTS","ADC","???","???","???","ADC","ROR","???","PLA","ADC","ROR","???","JMP","ADC","ROR","???",
1044 "BVS","ADC","???","???","???","ADC","ROR","???","SEI","ADC","???","???","???","ADC","ROR","???",
1045 "???","STA","???","???","STY","STA","STX","???","DEY","???","TXA","???","STY","STA","STX","???",
1046 "BCC","STA","???","???","STY","STA","STX","???","TYA","STA","TXS","???","???","STA","???","???",
1047 "LDY","LDA","LDX","???","LDY","LDA","LDX","???","TAY","LDA","TAX","???","LDY","LDA","LDX","???",
1048 "BCS","LDA","???","???","LDY","LDA","LDX","???","CLV","LDA","TSX","???","LDY","LDA","LDX","???",
1049 "CPY","CMP","???","???","CPY","CMP","DEC","???","INY","CMP","DEX","???","CPY","CMP","DEC","???",
1050 "BNE","CMP","???","???","???","CMP","DEC","???","CLD","CMP","???","???","???","CMP","DEC","???",
1051 "CPX","SBC","???","???","CPX","SBC","INC","???","INX","SBC","NOP","???","CPX","SBC","INC","???",
1052 "BEQ","SBC","???","???","???","SBC","INC","???","SED","SBC","???","???","???","SBC","INC","???"
1054 return mnemonic_lookup
[op
];
1057 addressing_mode
opcode_addressing_mode(unsigned char op
)
1059 /* Lookup-table indexed by opcode */
1060 static addressing_mode amode_lookup
[256] = {
1061 IMPLIED_MODE
, /* BRK */
1062 PREINDEXED_INDIRECT_MODE
, /* ORA (Indirect,X) */
1066 ZEROPAGE_MODE
, /* ORA */
1067 ZEROPAGE_MODE
, /* ASL */
1069 IMPLIED_MODE
, /* PHP */
1070 IMMEDIATE_MODE
, /* ORA */
1071 ACCUMULATOR_MODE
, /* ASL */
1074 ABSOLUTE_MODE
, /* ORA */
1075 ABSOLUTE_MODE
, /* ASL */
1078 RELATIVE_MODE
, /* BPL */
1079 POSTINDEXED_INDIRECT_MODE
, /* ORA (Indirect),Y */
1083 ZEROPAGE_X_MODE
, /* ORA */
1084 ZEROPAGE_X_MODE
, /* ASL */
1086 IMPLIED_MODE
, /* CLC */
1087 ABSOLUTE_Y_MODE
, /* ORA */
1091 ABSOLUTE_X_MODE
, /* ORA */
1092 ABSOLUTE_X_MODE
, /* ASL */
1095 ABSOLUTE_MODE
, /* JSR */
1096 PREINDEXED_INDIRECT_MODE
, /* AND */
1099 ZEROPAGE_MODE
, /* BIT */
1100 ZEROPAGE_MODE
, /* AND */
1101 ZEROPAGE_MODE
, /* ROL */
1103 IMPLIED_MODE
, /* PLP */
1104 IMMEDIATE_MODE
, /* AND */
1105 ACCUMULATOR_MODE
, /* ROL */
1107 ABSOLUTE_MODE
, /* BIT */
1108 ABSOLUTE_MODE
, /* AND */
1109 ABSOLUTE_MODE
, /* ROL */
1112 RELATIVE_MODE
, /* BMI */
1113 POSTINDEXED_INDIRECT_MODE
, /* AND */
1117 ZEROPAGE_X_MODE
, /* AND */
1118 ZEROPAGE_X_MODE
, /* ROL */
1120 IMPLIED_MODE
, /* SEC */
1121 ABSOLUTE_Y_MODE
, /* AND */
1125 ABSOLUTE_X_MODE
, /* AND */
1126 ABSOLUTE_X_MODE
, /* ROL */
1129 IMPLIED_MODE
, /* RTI */
1130 PREINDEXED_INDIRECT_MODE
, /* EOR */
1134 ZEROPAGE_MODE
, /* EOR */
1135 ZEROPAGE_MODE
, /* LSR */
1137 IMPLIED_MODE
, /* PHA */
1138 IMMEDIATE_MODE
, /* EOR */
1139 ACCUMULATOR_MODE
, /* LSR */
1141 ABSOLUTE_MODE
, /* JMP */
1142 ABSOLUTE_MODE
, /* EOR */
1143 ABSOLUTE_MODE
, /* LSR */
1146 RELATIVE_MODE
, /* BVC */
1147 POSTINDEXED_INDIRECT_MODE
, /* EOR */
1151 ZEROPAGE_X_MODE
, /* EOR */
1152 ZEROPAGE_X_MODE
, /* LSR */
1154 IMPLIED_MODE
, /* CLI */
1155 ABSOLUTE_Y_MODE
, /* EOR */
1159 ABSOLUTE_X_MODE
, /* EOR */
1160 ABSOLUTE_X_MODE
, /* LSR */
1163 IMPLIED_MODE
, /* RTS */
1164 PREINDEXED_INDIRECT_MODE
, /* ADC */
1168 ZEROPAGE_MODE
, /* ADC */
1169 ZEROPAGE_MODE
, /* ROR */
1171 IMPLIED_MODE
, /* PLA */
1172 IMMEDIATE_MODE
, /* ADC */
1173 ACCUMULATOR_MODE
, /* ROR */
1175 INDIRECT_MODE
, /* JMP */
1176 ABSOLUTE_MODE
, /* ADC */
1177 ABSOLUTE_MODE
, /* ROR */
1180 RELATIVE_MODE
, /* BVS */
1181 POSTINDEXED_INDIRECT_MODE
, /* ADC */
1185 ZEROPAGE_X_MODE
, /* ADC */
1186 ZEROPAGE_X_MODE
, /* ROR */
1188 IMPLIED_MODE
, /* SEI */
1189 ABSOLUTE_Y_MODE
, /* ADC */
1193 ABSOLUTE_X_MODE
, /* ADC */
1194 ABSOLUTE_X_MODE
, /* ROR */
1198 PREINDEXED_INDIRECT_MODE
, /* STA */
1201 ZEROPAGE_MODE
, /* STY */
1202 ZEROPAGE_MODE
, /* STA */
1203 ZEROPAGE_MODE
, /* STX */
1205 IMPLIED_MODE
, /* DEY */
1207 IMPLIED_MODE
, /* TXA */
1209 ABSOLUTE_MODE
, /* STY */
1210 ABSOLUTE_MODE
, /* STA */
1211 ABSOLUTE_MODE
, /* STX */
1214 RELATIVE_MODE
, /* BCC */
1215 POSTINDEXED_INDIRECT_MODE
, /* STA */
1218 ZEROPAGE_X_MODE
, /* STY */
1219 ZEROPAGE_X_MODE
, /* STA */
1220 ZEROPAGE_X_MODE
, /* STX */
1222 IMPLIED_MODE
, /* TYA */
1223 ABSOLUTE_Y_MODE
, /* STA */
1224 IMPLIED_MODE
, /* TXS */
1227 ABSOLUTE_X_MODE
, /* STA */
1231 IMMEDIATE_MODE
, /* LDY */
1232 PREINDEXED_INDIRECT_MODE
, /* LDA */
1233 IMMEDIATE_MODE
, /* LDX */
1235 ZEROPAGE_MODE
, /* LDY */
1236 ZEROPAGE_MODE
, /* LDA */
1237 ZEROPAGE_MODE
, /* LDX */
1239 IMPLIED_MODE
, /* TAY */
1240 IMMEDIATE_MODE
, /* LDA */
1241 IMPLIED_MODE
, /* TAX */
1243 ABSOLUTE_MODE
, /* LDY */
1244 ABSOLUTE_MODE
, /* LDA */
1245 ABSOLUTE_MODE
, /* LDX */
1248 RELATIVE_MODE
, /* BCS */
1249 POSTINDEXED_INDIRECT_MODE
, /* LDA */
1252 ZEROPAGE_X_MODE
, /* LDY */
1253 ZEROPAGE_X_MODE
, /* LDA */
1254 ZEROPAGE_X_MODE
, /* LDX */
1256 IMPLIED_MODE
, /* CLV */
1257 ABSOLUTE_Y_MODE
, /* LDA */
1258 IMPLIED_MODE
, /* TSX */
1260 ABSOLUTE_X_MODE
, /* LDY */
1261 ABSOLUTE_X_MODE
, /* LDA */
1262 ABSOLUTE_X_MODE
, /* LDX */
1265 IMMEDIATE_MODE
, /* CPY */
1266 PREINDEXED_INDIRECT_MODE
, /* CMP */
1269 ZEROPAGE_MODE
, /* CPY */
1270 ZEROPAGE_MODE
, /* CMP */
1271 ZEROPAGE_MODE
, /* DEC */
1273 IMPLIED_MODE
, /* INY */
1274 IMMEDIATE_MODE
, /* CMP */
1275 IMPLIED_MODE
, /* DEX */
1277 ABSOLUTE_MODE
, /* CPY */
1278 ABSOLUTE_MODE
, /* CMP */
1279 ABSOLUTE_MODE
, /* DEC */
1282 RELATIVE_MODE
, /* BNE */
1283 POSTINDEXED_INDIRECT_MODE
, /* CMP */
1287 ZEROPAGE_X_MODE
, /* CMP */
1288 ZEROPAGE_X_MODE
, /* DEC */
1290 IMPLIED_MODE
, /* CLD */
1291 ABSOLUTE_Y_MODE
, /* CMP */
1295 ABSOLUTE_X_MODE
, /* CMP */
1296 ABSOLUTE_X_MODE
, /* DEC */
1299 IMMEDIATE_MODE
, /* CPX */
1300 PREINDEXED_INDIRECT_MODE
, /* SBC */
1303 ZEROPAGE_MODE
, /* CPX */
1304 ZEROPAGE_MODE
, /* SBC */
1305 ZEROPAGE_MODE
, /* INC */
1307 IMPLIED_MODE
, /* INX */
1308 IMMEDIATE_MODE
, /* SBC */
1309 IMPLIED_MODE
, /* NOP */
1311 ABSOLUTE_MODE
, /* CPX */
1312 ABSOLUTE_MODE
, /* SBC */
1313 ABSOLUTE_MODE
, /* INC */
1316 RELATIVE_MODE
, /* BEQ */
1317 POSTINDEXED_INDIRECT_MODE
, /* SBC */
1321 ZEROPAGE_X_MODE
, /* SBC */
1322 ZEROPAGE_X_MODE
, /* INC */
1324 IMPLIED_MODE
, /* SED */
1325 ABSOLUTE_Y_MODE
, /* SBC */
1329 ABSOLUTE_X_MODE
, /* SBC */
1330 ABSOLUTE_X_MODE
, /* INC */
1334 return amode_lookup
[op
];