fbc7e71d615581000c28ac1e53569ade0083aaf9
[drnoksnes] / 65c816ops.inc
1 /*
2  * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3  *
4  * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
5  *                           Jerremy Koot (jkoot@snes9x.com)
6  *
7  * Super FX C emulator code 
8  * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
9  *                           Gary Henderson.
10  * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
11  *
12  * DSP1 emulator code (c) Copyright 1998 Ivar_Demo_ and Gary Henderson.
13  * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
14  * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
15  *
16  * DOS port code contains the works of other authors. See headers in
17  * individual files.
18  *
19  * Snes9x homepage: http://www.snes9x.com
20  *
21  * Permission to usecopymodify and distribute Snes9x in both binary and
22  * source formfor non-commercial purposesis hereby granted without fee,
23  * providing that this license information and copyright notice appear with
24  * all copies and any derived work.
25  *
26  * This software is provided 'as-is'without any express or implied
27  * warranty. In no event shall the authors be held liable for any damages
28  * arising from the use of this software.
29  *
30  * Snes9x is freeware for PERSONAL USE only. Commercial users should
31  * seek permission of the copyright holders first. Commercial use includes
32  * charging money for Snes9x or software derived from Snes9x.
33  *
34  * The copyright holders request that bug fixes and improvements to the code
35  * should be forwarded to them so everyone can benefit from the modifications
36  * in future versions.
37  *
38  * Super NES and Super Nintendo Entertainment System are trademarks of
39  * Nintendo Co.Limited and its subsidiary companies.
40  */
41 /**********************************************************************************************/
42 /* CPU-S9xOpcodes.CPP                                                                            */
43 /* This file contains all the opcodes                                                         */
44 /**********************************************************************************************/
45
46 #include "cpuexec.h"
47 #include "cpuaddr.h"
48 #include "cpuops.h"
49 #include "cpumacro.h"
50 #include "apu.h"
51
52 #define ApuSync() do { \
53         CPU.Cycles = CPU.NextEvent; \
54         if (CPU.APU_APUExecuting) { \
55                 ICPU.CPUExecuting = FALSE; \
56                 do \
57                 { \
58                         APU_EXECUTE1 (); \
59                 } while (CPU.APU_Cycles < CPU.NextEvent); \
60                 ICPU.CPUExecuting = TRUE; \
61         } \
62 } while (0);
63
64
65 /* ADC *************************************************************************************** */
66 static void Op69M1 ()
67 {
68     long OpAddress = Immediate8 ();
69     ADC8 (OpAddress);
70 }
71
72 static void Op69M0 ()
73 {
74     long OpAddress = Immediate16 ();
75     ADC16 (OpAddress);
76 }
77
78 static void Op65M1 ()
79 {
80     long OpAddress = Direct ();
81     ADC8 (OpAddress);
82 }
83
84 static void Op65M0 ()
85 {
86     long OpAddress = Direct ();
87     ADC16 (OpAddress);
88 }
89
90 static void Op75M1 ()
91 {
92     long OpAddress = DirectIndexedX ();
93     ADC8 (OpAddress);
94 }
95
96 static void Op75M0 ()
97 {
98     long OpAddress = DirectIndexedX ();
99     ADC16 (OpAddress);
100 }
101
102 static void Op72M1 ()
103 {
104     long OpAddress = DirectIndirect ();
105     ADC8 (OpAddress);
106 }
107
108 static void Op72M0 ()
109 {
110     long OpAddress = DirectIndirect ();
111     ADC16 (OpAddress);
112 }
113
114 static void Op61M1 ()
115 {
116     long OpAddress = DirectIndexedIndirect ();
117     ADC8 (OpAddress);
118 }
119
120 static void Op61M0 ()
121 {
122     long OpAddress = DirectIndexedIndirect ();
123     ADC16 (OpAddress);
124 }
125
126 static void Op71M1 ()
127 {
128     long OpAddress = DirectIndirectIndexed ();
129     ADC8 (OpAddress);
130 }
131
132 static void Op71M0 ()
133 {
134     long OpAddress = DirectIndirectIndexed ();
135     ADC16 (OpAddress);
136 }
137
138 static void Op67M1 ()
139 {
140     long OpAddress = DirectIndirectLong ();
141     ADC8 (OpAddress);
142 }
143
144 static void Op67M0 ()
145 {
146     long OpAddress = DirectIndirectLong ();
147     ADC16 (OpAddress);
148 }
149
150 static void Op77M1 ()
151 {
152     long OpAddress = DirectIndirectIndexedLong ();
153     ADC8 (OpAddress);
154 }
155
156 static void Op77M0 ()
157 {
158     long OpAddress = DirectIndirectIndexedLong ();
159     ADC16 (OpAddress);
160 }
161
162 static void Op6DM1 ()
163 {
164     long OpAddress = Absolute ();
165     ADC8 (OpAddress);
166 }
167
168 static void Op6DM0 ()
169 {
170     long OpAddress = Absolute ();
171     ADC16 (OpAddress);
172 }
173
174 static void Op7DM1 ()
175 {
176     long OpAddress = AbsoluteIndexedX ();
177     ADC8 (OpAddress);
178 }
179
180 static void Op7DM0 ()
181 {
182     long OpAddress = AbsoluteIndexedX ();
183     ADC16 (OpAddress);
184 }
185
186 static void Op79M1 ()
187 {
188     long OpAddress = AbsoluteIndexedY ();
189     ADC8 (OpAddress);
190 }
191
192 static void Op79M0 ()
193 {
194     long OpAddress = AbsoluteIndexedY ();
195     ADC16 (OpAddress);
196 }
197
198 static void Op6FM1 ()
199 {
200     long OpAddress = AbsoluteLong ();
201     ADC8 (OpAddress);
202 }
203
204 static void Op6FM0 ()
205 {
206     long OpAddress = AbsoluteLong ();
207     ADC16 (OpAddress);
208 }
209
210 static void Op7FM1 ()
211 {
212     long OpAddress = AbsoluteLongIndexedX ();
213     ADC8 (OpAddress);
214 }
215
216 static void Op7FM0 ()
217 {
218     long OpAddress = AbsoluteLongIndexedX ();
219     ADC16 (OpAddress);
220 }
221
222 static void Op63M1 ()
223 {
224     long OpAddress = StackRelative ();
225     ADC8 (OpAddress);
226 }
227
228 static void Op63M0 ()
229 {
230     long OpAddress = StackRelative ();
231     ADC16 (OpAddress);
232 }
233
234 static void Op73M1 ()
235 {
236     long OpAddress = StackRelativeIndirectIndexed ();
237     ADC8 (OpAddress);
238 }
239
240 static void Op73M0 ()
241 {
242     long OpAddress = StackRelativeIndirectIndexed ();
243     ADC16 (OpAddress);
244 }
245
246 /**********************************************************************************************/
247
248 /* AND *************************************************************************************** */
249 static void Op29M1 ()
250 {
251     Registers.AL &= *CPU.PC++;
252 #ifdef VAR_CYCLES
253     CPU.Cycles += CPU.MemSpeed;
254 #endif
255     SETZN8 (Registers.AL);
256 }
257
258 static void Op29M0 ()
259 {
260 #ifdef FAST_LSB_WORD_ACCESS
261     Registers.A.W &= *(uint16 *) CPU.PC;
262 #else
263     Registers.A.W &= *CPU.PC + (*(CPU.PC + 1) << 8);
264 #endif
265     CPU.PC += 2;
266 #ifdef VAR_CYCLES
267     CPU.Cycles += CPU.MemSpeedx2;
268 #endif
269     SETZN16 (Registers.A.W);
270 }
271
272 static void Op25M1 ()
273 {
274     long OpAddress = Direct ();
275     AND8 (OpAddress);
276 }
277
278 static void Op25M0 ()
279 {
280     long OpAddress = Direct ();
281     AND16 (OpAddress);
282 }
283
284 static void Op35M1 ()
285 {
286     long OpAddress = DirectIndexedX ();
287     AND8 (OpAddress);
288 }
289
290 static void Op35M0 ()
291 {
292     long OpAddress = DirectIndexedX ();
293     AND16 (OpAddress);
294 }
295
296 static void Op32M1 ()
297 {
298     long OpAddress = DirectIndirect ();
299     AND8 (OpAddress);
300 }
301
302 static void Op32M0 ()
303 {
304     long OpAddress = DirectIndirect ();
305     AND16 (OpAddress);
306 }
307
308 static void Op21M1 ()
309 {
310     long OpAddress = DirectIndexedIndirect ();
311     AND8 (OpAddress);
312 }
313
314 static void Op21M0 ()
315 {
316     long OpAddress = DirectIndexedIndirect ();
317     AND16 (OpAddress);
318 }
319
320 static void Op31M1 ()
321 {
322     long OpAddress = DirectIndirectIndexed ();
323     AND8 (OpAddress);
324 }
325
326 static void Op31M0 ()
327 {
328     long OpAddress = DirectIndirectIndexed ();
329     AND16 (OpAddress);
330 }
331
332 static void Op27M1 ()
333 {
334     long OpAddress = DirectIndirectLong ();
335     AND8 (OpAddress);
336 }
337
338 static void Op27M0 ()
339 {
340     long OpAddress = DirectIndirectLong ();
341     AND16 (OpAddress);
342 }
343
344 static void Op37M1 ()
345 {
346     long OpAddress = DirectIndirectIndexedLong ();
347     AND8 (OpAddress);
348 }
349
350 static void Op37M0 ()
351 {
352     long OpAddress = DirectIndirectIndexedLong ();
353     AND16 (OpAddress);
354 }
355
356 static void Op2DM1 ()
357 {
358     long OpAddress = Absolute ();
359     AND8 (OpAddress);
360 }
361
362 static void Op2DM0 ()
363 {
364     long OpAddress = Absolute ();
365     AND16 (OpAddress);
366 }
367
368 static void Op3DM1 ()
369 {
370     long OpAddress = AbsoluteIndexedX ();
371     AND8 (OpAddress);
372 }
373
374 static void Op3DM0 ()
375 {
376     long OpAddress = AbsoluteIndexedX ();
377     AND16 (OpAddress);
378 }
379
380 static void Op39M1 ()
381 {
382     long OpAddress = AbsoluteIndexedY ();
383     AND8 (OpAddress);
384 }
385
386 static void Op39M0 ()
387 {
388     long OpAddress = AbsoluteIndexedY ();
389     AND16 (OpAddress);
390 }
391
392 static void Op2FM1 ()
393 {
394     long OpAddress = AbsoluteLong ();
395     AND8 (OpAddress);
396 }
397
398 static void Op2FM0 ()
399 {
400     long OpAddress = AbsoluteLong ();
401     AND16 (OpAddress);
402 }
403
404 static void Op3FM1 ()
405 {
406     long OpAddress = AbsoluteLongIndexedX ();
407     AND8 (OpAddress);
408 }
409
410 static void Op3FM0 ()
411 {
412     long OpAddress = AbsoluteLongIndexedX ();
413     AND16 (OpAddress);
414 }
415
416 static void Op23M1 ()
417 {
418     long OpAddress = StackRelative ();
419     AND8 (OpAddress);
420 }
421
422 static void Op23M0 ()
423 {
424     long OpAddress = StackRelative ();
425     AND16 (OpAddress);
426 }
427
428 static void Op33M1 ()
429 {
430     long OpAddress = StackRelativeIndirectIndexed ();
431     AND8 (OpAddress);
432 }
433
434 static void Op33M0 ()
435 {
436     long OpAddress = StackRelativeIndirectIndexed ();
437     AND16 (OpAddress);
438 }
439 /**********************************************************************************************/
440
441 /* ASL *************************************************************************************** */
442 static void Op0AM1 ()
443 {
444     A_ASL8 ();
445 }
446
447 static void Op0AM0 ()
448 {
449     A_ASL16 ();
450 }
451
452 static void Op06M1 ()
453 {
454     long OpAddress = Direct ();
455     ASL8 (OpAddress);
456 }
457
458 static void Op06M0 ()
459 {
460     long OpAddress = Direct ();
461     ASL16 (OpAddress);
462 }
463
464 static void Op16M1 ()
465 {
466     long OpAddress = DirectIndexedX ();
467     ASL8 (OpAddress);
468 }
469
470 static void Op16M0 ()
471 {
472     long OpAddress = DirectIndexedX ();
473     ASL16 (OpAddress);
474 }
475
476 static void Op0EM1 ()
477 {
478     long OpAddress = Absolute ();
479     ASL8 (OpAddress);
480 }
481
482 static void Op0EM0 ()
483 {
484     long OpAddress = Absolute ();
485     ASL16 (OpAddress);
486 }
487
488 static void Op1EM1 ()
489 {
490     long OpAddress = AbsoluteIndexedX ();
491     ASL8 (OpAddress);
492 }
493
494 static void Op1EM0 ()
495 {
496     long OpAddress = AbsoluteIndexedX ();
497     ASL16 (OpAddress);
498 }
499 /**********************************************************************************************/
500
501 /* BIT *************************************************************************************** */
502 static void Op89M1 ()
503 {
504     ICPU._Zero = Registers.AL & *CPU.PC++;
505 #ifdef VAR_CYCLES
506     CPU.Cycles += CPU.MemSpeed;
507 #endif
508 }
509
510 static void Op89M0 ()
511 {
512 #ifdef FAST_LSB_WORD_ACCESS
513     ICPU._Zero = (Registers.A.W & *(uint16 *) CPU.PC) != 0;
514 #else
515     ICPU._Zero = (Registers.A.W & (*CPU.PC + (*(CPU.PC + 1) << 8))) != 0;
516 #endif  
517 #ifdef VAR_CYCLES
518     CPU.Cycles += CPU.MemSpeedx2;
519 #endif
520     CPU.PC += 2;
521 }
522
523 static void Op24M1 ()
524 {
525     long OpAddress = Direct ();
526     BIT8 (OpAddress);
527 }
528
529 static void Op24M0 ()
530 {
531     long OpAddress = Direct ();
532     BIT16 (OpAddress);
533 }
534
535 static void Op34M1 ()
536 {
537     long OpAddress = DirectIndexedX ();
538     BIT8 (OpAddress);
539 }
540
541 static void Op34M0 ()
542 {
543     long OpAddress = DirectIndexedX ();
544     BIT16 (OpAddress);
545 }
546
547 static void Op2CM1 ()
548 {
549     long OpAddress = Absolute ();
550     BIT8 (OpAddress);
551 }
552
553 static void Op2CM0 ()
554 {
555     long OpAddress = Absolute ();
556     BIT16 (OpAddress);
557 }
558
559 static void Op3CM1 ()
560 {
561     long OpAddress = AbsoluteIndexedX ();
562     BIT8 (OpAddress);
563 }
564
565 static void Op3CM0 ()
566 {
567     long OpAddress = AbsoluteIndexedX ();
568     BIT16 (OpAddress);
569 }
570 /**********************************************************************************************/
571
572 /* CMP *************************************************************************************** */
573 static void OpC9M1 ()
574 {
575     int32 Int32 = (int) Registers.AL - (int) *CPU.PC++;
576     ICPU._Carry = Int32 >= 0;
577     SETZN8 ((uint8) Int32);
578 #ifdef VAR_CYCLES
579     CPU.Cycles += CPU.MemSpeed;
580 #endif
581 }
582
583 static void OpC9M0 ()
584 {
585 #ifdef FAST_LSB_WORD_ACCESS    
586     int32 Int32 = (long) Registers.A.W - (long) *(uint16 *) CPU.PC;
587 #else
588     int32 Int32 = (long) Registers.A.W -
589             (long) (*CPU.PC + (*(CPU.PC + 1) << 8));
590 #endif
591     ICPU._Carry = Int32 >= 0;
592     SETZN16 ((uint16) Int32);
593     CPU.PC += 2;
594 #ifdef VAR_CYCLES
595     CPU.Cycles += CPU.MemSpeedx2;
596 #endif
597 }
598
599 static void OpC5M1 ()
600 {
601     long OpAddress = Direct ();
602     CMP8 (OpAddress);
603 }
604
605 static void OpC5M0 ()
606 {
607     long OpAddress = Direct ();
608     CMP16 (OpAddress);
609 }
610
611 static void OpD5M1 ()
612 {
613     long OpAddress = DirectIndexedX ();
614     CMP8 (OpAddress);
615 }
616
617 static void OpD5M0 ()
618 {
619     long OpAddress = DirectIndexedX ();
620     CMP16 (OpAddress);
621 }
622
623 static void OpD2M1 ()
624 {
625     long OpAddress = DirectIndirect ();
626     CMP8 (OpAddress);
627 }
628
629 static void OpD2M0 ()
630 {
631     long OpAddress = DirectIndirect ();
632     CMP16 (OpAddress);
633 }
634
635 static void OpC1M1 ()
636 {
637     long OpAddress = DirectIndexedIndirect ();
638     CMP8 (OpAddress);
639 }
640
641 static void OpC1M0 ()
642 {
643     long OpAddress = DirectIndexedIndirect ();
644     CMP16 (OpAddress);
645 }
646
647 static void OpD1M1 ()
648 {
649     long OpAddress = DirectIndirectIndexed ();
650     CMP8 (OpAddress);
651 }
652
653 static void OpD1M0 ()
654 {
655     long OpAddress = DirectIndirectIndexed ();
656     CMP16 (OpAddress);
657 }
658
659 static void OpC7M1 ()
660 {
661     long OpAddress = DirectIndirectLong ();
662     CMP8 (OpAddress);
663 }
664
665 static void OpC7M0 ()
666 {
667     long OpAddress = DirectIndirectLong ();
668     CMP16 (OpAddress);
669 }
670
671 static void OpD7M1 ()
672 {
673     long OpAddress = DirectIndirectIndexedLong ();
674     CMP8 (OpAddress);
675 }
676
677 static void OpD7M0 ()
678 {
679     long OpAddress = DirectIndirectIndexedLong ();
680     CMP16 (OpAddress);
681 }
682
683 static void OpCDM1 ()
684 {
685     long OpAddress = Absolute ();
686     CMP8 (OpAddress);
687 }
688
689 static void OpCDM0 ()
690 {
691     long OpAddress = Absolute ();
692     CMP16 (OpAddress);
693 }
694
695 static void OpDDM1 ()
696 {
697     long OpAddress = AbsoluteIndexedX ();
698     CMP8 (OpAddress);
699 }
700
701 static void OpDDM0 ()
702 {
703     long OpAddress = AbsoluteIndexedX ();
704     CMP16 (OpAddress);
705 }
706
707 static void OpD9M1 ()
708 {
709     long OpAddress = AbsoluteIndexedY ();
710     CMP8 (OpAddress);
711 }
712
713 static void OpD9M0 ()
714 {
715     long OpAddress = AbsoluteIndexedY ();
716     CMP16 (OpAddress);
717 }
718
719 static void OpCFM1 ()
720 {
721     long OpAddress = AbsoluteLong ();
722     CMP8 (OpAddress);
723 }
724
725 static void OpCFM0 ()
726 {
727     long OpAddress = AbsoluteLong ();
728     CMP16 (OpAddress);
729 }
730
731 static void OpDFM1 ()
732 {
733     long OpAddress = AbsoluteLongIndexedX ();
734     CMP8 (OpAddress);
735 }
736
737 static void OpDFM0 ()
738 {
739     long OpAddress = AbsoluteLongIndexedX ();
740     CMP16 (OpAddress);
741 }
742
743 static void OpC3M1 ()
744 {
745     long OpAddress = StackRelative ();
746     CMP8 (OpAddress);
747 }
748
749 static void OpC3M0 ()
750 {
751     long OpAddress = StackRelative ();
752     CMP16 (OpAddress);
753 }
754
755 static void OpD3M1 ()
756 {
757     long OpAddress = StackRelativeIndirectIndexed ();
758     CMP8 (OpAddress);
759 }
760
761 static void OpD3M0 ()
762 {
763     long OpAddress = StackRelativeIndirectIndexed ();
764     CMP16 (OpAddress);
765 }
766
767 /**********************************************************************************************/
768
769 /* CMX *************************************************************************************** */
770 static void OpE0X1 ()
771 {
772     int32 Int32 = (int) Registers.XL - (int) *CPU.PC++;
773     ICPU._Carry = Int32 >= 0;
774     SETZN8 ((uint8) Int32);
775 #ifdef VAR_CYCLES
776     CPU.Cycles += CPU.MemSpeed;
777 #endif
778 }
779
780 static void OpE0X0 ()
781 {
782 #ifdef FAST_LSB_WORD_ACCESS    
783     int32 Int32 = (long) Registers.X.W - (long) *(uint16 *) CPU.PC;
784 #else
785     int32 Int32 = (long) Registers.X.W -
786             (long) (*CPU.PC + (*(CPU.PC + 1) << 8));
787 #endif
788     ICPU._Carry = Int32 >= 0;
789     SETZN16 ((uint16) Int32);
790     CPU.PC += 2;
791 #ifdef VAR_CYCLES
792     CPU.Cycles += CPU.MemSpeedx2;
793 #endif
794 }
795
796 static void OpE4X1 ()
797 {
798     long OpAddress = Direct ();
799     CMX8 (OpAddress);
800 }
801
802 static void OpE4X0 ()
803 {
804     long OpAddress = Direct ();
805     CMX16 (OpAddress);
806 }
807
808 static void OpECX1 ()
809 {
810     long OpAddress = Absolute ();
811     CMX8 (OpAddress);
812 }
813
814 static void OpECX0 ()
815 {
816     long OpAddress = Absolute ();
817     CMX16 (OpAddress);
818 }
819
820 /**********************************************************************************************/
821
822 /* CMY *************************************************************************************** */
823 static void OpC0X1 ()
824 {
825     int32 Int32 = (int) Registers.YL - (int) *CPU.PC++;
826     ICPU._Carry = Int32 >= 0;
827     SETZN8 ((uint8) Int32);
828 #ifdef VAR_CYCLES
829     CPU.Cycles += CPU.MemSpeed;
830 #endif
831 }
832
833 static void OpC0X0 ()
834 {
835 #ifdef FAST_LSB_WORD_ACCESS    
836     int32 Int32 = (long) Registers.Y.W - (long) *(uint16 *) CPU.PC;
837 #else
838     int32 Int32 = (long) Registers.Y.W -
839             (long) (*CPU.PC + (*(CPU.PC + 1) << 8));
840 #endif
841     ICPU._Carry = Int32 >= 0;
842     SETZN16 ((uint16) Int32);
843     CPU.PC += 2;
844 #ifdef VAR_CYCLES
845     CPU.Cycles += CPU.MemSpeedx2;
846 #endif
847 }
848
849 static void OpC4X1 ()
850 {
851     long OpAddress = Direct ();
852     CMY8 (OpAddress);
853 }
854
855 static void OpC4X0 ()
856 {
857     long OpAddress = Direct ();
858     CMY16 (OpAddress);
859 }
860
861 static void OpCCX1 ()
862 {
863     long OpAddress = Absolute ();
864     CMY8 (OpAddress);
865 }
866
867 static void OpCCX0 ()
868 {
869     long OpAddress = Absolute ();
870     CMY16 (OpAddress);
871 }
872
873 /**********************************************************************************************/
874
875 /* DEC *************************************************************************************** */
876 static void Op3AM1 ()
877 {
878     A_DEC8 ();
879 }
880
881 static void Op3AM0 ()
882 {
883     A_DEC16 ();
884 }
885
886 static void OpC6M1 ()
887 {
888     long OpAddress = Direct ();
889     DEC8 (OpAddress);
890 }
891
892 static void OpC6M0 ()
893 {
894     long OpAddress = Direct ();
895     DEC16 (OpAddress);
896 }
897
898 static void OpD6M1 ()
899 {
900     long OpAddress = DirectIndexedX ();
901     DEC8 (OpAddress);
902 }
903
904 static void OpD6M0 ()
905 {
906     long OpAddress = DirectIndexedX ();
907     DEC16 (OpAddress);
908 }
909
910 static void OpCEM1 ()
911 {
912     long OpAddress = Absolute ();
913     DEC8 (OpAddress);
914 }
915
916 static void OpCEM0 ()
917 {
918     long OpAddress = Absolute ();
919     DEC16 (OpAddress);
920 }
921
922 static void OpDEM1 ()
923 {
924     long OpAddress = AbsoluteIndexedX ();
925     DEC8 (OpAddress);
926 }
927
928 static void OpDEM0 ()
929 {
930     long OpAddress = AbsoluteIndexedX ();
931     DEC16 (OpAddress);
932 }
933
934 /**********************************************************************************************/
935
936 /* EOR *************************************************************************************** */
937 static void Op49M1 ()
938 {
939     Registers.AL ^= *CPU.PC++;
940 #ifdef VAR_CYCLES
941     CPU.Cycles += CPU.MemSpeed;
942 #endif
943     SETZN8 (Registers.AL);
944 }
945
946 static void Op49M0 ()
947 {
948 #ifdef FAST_LSB_WORD_ACCESS
949     Registers.A.W ^= *(uint16 *) CPU.PC;
950 #else
951     Registers.A.W ^= *CPU.PC + (*(CPU.PC + 1) << 8);
952 #endif
953     CPU.PC += 2;
954 #ifdef VAR_CYCLES
955     CPU.Cycles += CPU.MemSpeedx2;
956 #endif
957     SETZN16 (Registers.A.W);
958 }
959
960 static void Op45M1 ()
961 {
962     long OpAddress = Direct ();
963     EOR8 (OpAddress);
964 }
965
966 static void Op45M0 ()
967 {
968     long OpAddress = Direct ();
969     EOR16 (OpAddress);
970 }
971
972 static void Op55M1 ()
973 {
974     long OpAddress = DirectIndexedX ();
975     EOR8 (OpAddress);
976 }
977
978 static void Op55M0 ()
979 {
980     long OpAddress = DirectIndexedX ();
981     EOR16 (OpAddress);
982 }
983
984 static void Op52M1 ()
985 {
986     long OpAddress = DirectIndirect ();
987     EOR8 (OpAddress);
988 }
989
990 static void Op52M0 ()
991 {
992     long OpAddress = DirectIndirect ();
993     EOR16 (OpAddress);
994 }
995
996 static void Op41M1 ()
997 {
998     long OpAddress = DirectIndexedIndirect ();
999     EOR8 (OpAddress);
1000 }
1001
1002 static void Op41M0 ()
1003 {
1004     long OpAddress = DirectIndexedIndirect ();
1005     EOR16 (OpAddress);
1006 }
1007
1008 static void Op51M1 ()
1009 {
1010     long OpAddress = DirectIndirectIndexed ();
1011     EOR8 (OpAddress);
1012 }
1013
1014 static void Op51M0 ()
1015 {
1016     long OpAddress = DirectIndirectIndexed ();
1017     EOR16 (OpAddress);
1018 }
1019
1020 static void Op47M1 ()
1021 {
1022     long OpAddress = DirectIndirectLong ();
1023     EOR8 (OpAddress);
1024 }
1025
1026 static void Op47M0 ()
1027 {
1028     long OpAddress = DirectIndirectLong ();
1029     EOR16 (OpAddress);
1030 }
1031
1032 static void Op57M1 ()
1033 {
1034     long OpAddress = DirectIndirectIndexedLong ();
1035     EOR8 (OpAddress);
1036 }
1037
1038 static void Op57M0 ()
1039 {
1040     long OpAddress = DirectIndirectIndexedLong ();
1041     EOR16 (OpAddress);
1042 }
1043
1044 static void Op4DM1 ()
1045 {
1046     long OpAddress = Absolute ();
1047     EOR8 (OpAddress);
1048 }
1049
1050 static void Op4DM0 ()
1051 {
1052     long OpAddress = Absolute ();
1053     EOR16 (OpAddress);
1054 }
1055
1056 static void Op5DM1 ()
1057 {
1058     long OpAddress = AbsoluteIndexedX ();
1059     EOR8 (OpAddress);
1060 }
1061
1062 static void Op5DM0 ()
1063 {
1064     long OpAddress = AbsoluteIndexedX ();
1065     EOR16 (OpAddress);
1066 }
1067
1068 static void Op59M1 ()
1069 {
1070     long OpAddress = AbsoluteIndexedY ();
1071     EOR8 (OpAddress);
1072 }
1073
1074 static void Op59M0 ()
1075 {
1076     long OpAddress = AbsoluteIndexedY ();
1077     EOR16 (OpAddress);
1078 }
1079
1080 static void Op4FM1 ()
1081 {
1082     long OpAddress = AbsoluteLong ();
1083     EOR8 (OpAddress);
1084 }
1085
1086 static void Op4FM0 ()
1087 {
1088     long OpAddress = AbsoluteLong ();
1089     EOR16 (OpAddress);
1090 }
1091
1092 static void Op5FM1 ()
1093 {
1094     long OpAddress = AbsoluteLongIndexedX ();
1095     EOR8 (OpAddress);
1096 }
1097
1098 static void Op5FM0 ()
1099 {
1100     long OpAddress = AbsoluteLongIndexedX ();
1101     EOR16 (OpAddress);
1102 }
1103
1104 static void Op43M1 ()
1105 {
1106     long OpAddress = StackRelative ();
1107     EOR8 (OpAddress);
1108 }
1109
1110 static void Op43M0 ()
1111 {
1112     long OpAddress = StackRelative ();
1113     EOR16 (OpAddress);
1114 }
1115
1116 static void Op53M1 ()
1117 {
1118     long OpAddress = StackRelativeIndirectIndexed ();
1119     EOR8 (OpAddress);
1120 }
1121
1122 static void Op53M0 ()
1123 {
1124     long OpAddress = StackRelativeIndirectIndexed ();
1125     EOR16 (OpAddress);
1126 }
1127
1128 /**********************************************************************************************/
1129
1130 /* INC *************************************************************************************** */
1131 static void Op1AM1 ()
1132 {
1133     A_INC8 ();
1134 }
1135
1136 static void Op1AM0 ()
1137 {
1138     A_INC16 ();
1139 }
1140
1141 static void OpE6M1 ()
1142 {
1143     long OpAddress = Direct ();
1144     INC8 (OpAddress);
1145 }
1146
1147 static void OpE6M0 ()
1148 {
1149     long OpAddress = Direct ();
1150     INC16 (OpAddress);
1151 }
1152
1153 static void OpF6M1 ()
1154 {
1155     long OpAddress = DirectIndexedX ();
1156     INC8 (OpAddress);
1157 }
1158
1159 static void OpF6M0 ()
1160 {
1161     long OpAddress = DirectIndexedX ();
1162     INC16 (OpAddress);
1163 }
1164
1165 static void OpEEM1 ()
1166 {
1167     long OpAddress = Absolute ();
1168     INC8 (OpAddress);
1169 }
1170
1171 static void OpEEM0 ()
1172 {
1173     long OpAddress = Absolute ();
1174     INC16 (OpAddress);
1175 }
1176
1177 static void OpFEM1 ()
1178 {
1179     long OpAddress = AbsoluteIndexedX ();
1180     INC8 (OpAddress);
1181 }
1182
1183 static void OpFEM0 ()
1184 {
1185     long OpAddress = AbsoluteIndexedX ();
1186     INC16 (OpAddress);
1187 }
1188
1189 /**********************************************************************************************/
1190 /* LDA *************************************************************************************** */
1191 static void OpA9M1 ()
1192 {
1193     Registers.AL = *CPU.PC++;
1194 #ifdef VAR_CYCLES
1195     CPU.Cycles += CPU.MemSpeed;
1196 #endif
1197     SETZN8 (Registers.AL);
1198 }
1199
1200 static void OpA9M0 ()
1201 {
1202 #ifdef FAST_LSB_WORD_ACCESS
1203     Registers.A.W = *(uint16 *) CPU.PC;
1204 #else
1205     Registers.A.W = *CPU.PC + (*(CPU.PC + 1) << 8);
1206 #endif
1207
1208     CPU.PC += 2;
1209 #ifdef VAR_CYCLES
1210     CPU.Cycles += CPU.MemSpeedx2;
1211 #endif
1212     SETZN16 (Registers.A.W);
1213 }
1214
1215 static void OpA5M1 ()
1216 {
1217     long OpAddress = Direct ();
1218     LDA8 (OpAddress);
1219 }
1220
1221 static void OpA5M0 ()
1222 {
1223     long OpAddress = Direct ();
1224     LDA16 (OpAddress);
1225 }
1226
1227 static void OpB5M1 ()
1228 {
1229     long OpAddress = DirectIndexedX ();
1230     LDA8 (OpAddress);
1231 }
1232
1233 static void OpB5M0 ()
1234 {
1235     long OpAddress = DirectIndexedX ();
1236     LDA16 (OpAddress);
1237 }
1238
1239 static void OpB2M1 ()
1240 {
1241     long OpAddress = DirectIndirect ();
1242     LDA8 (OpAddress);
1243 }
1244
1245 static void OpB2M0 ()
1246 {
1247     long OpAddress = DirectIndirect ();
1248     LDA16 (OpAddress);
1249 }
1250
1251 static void OpA1M1 ()
1252 {
1253     long OpAddress = DirectIndexedIndirect ();
1254     LDA8 (OpAddress);
1255 }
1256
1257 static void OpA1M0 ()
1258 {
1259     long OpAddress = DirectIndexedIndirect ();
1260     LDA16 (OpAddress);
1261 }
1262
1263 static void OpB1M1 ()
1264 {
1265     long OpAddress = DirectIndirectIndexed ();
1266     LDA8 (OpAddress);
1267 }
1268
1269 static void OpB1M0 ()
1270 {
1271     long OpAddress = DirectIndirectIndexed ();
1272     LDA16 (OpAddress);
1273 }
1274
1275 static void OpA7M1 ()
1276 {
1277     long OpAddress = DirectIndirectLong ();
1278     LDA8 (OpAddress);
1279 }
1280
1281 static void OpA7M0 ()
1282 {
1283     long OpAddress = DirectIndirectLong ();
1284     LDA16 (OpAddress);
1285 }
1286
1287 static void OpB7M1 ()
1288 {
1289     long OpAddress = DirectIndirectIndexedLong ();
1290     LDA8 (OpAddress);
1291 }
1292
1293 static void OpB7M0 ()
1294 {
1295     long OpAddress = DirectIndirectIndexedLong ();
1296     LDA16 (OpAddress);
1297 }
1298
1299 static void OpADM1 ()
1300 {
1301     long OpAddress = Absolute ();
1302     LDA8 (OpAddress);
1303 }
1304
1305 static void OpADM0 ()
1306 {
1307     long OpAddress = Absolute ();
1308     LDA16 (OpAddress);
1309 }
1310
1311 static void OpBDM1 ()
1312 {
1313     long OpAddress = AbsoluteIndexedX ();
1314     LDA8 (OpAddress);
1315 }
1316
1317 static void OpBDM0 ()
1318 {
1319     long OpAddress = AbsoluteIndexedX ();
1320     LDA16 (OpAddress);
1321 }
1322
1323 static void OpB9M1 ()
1324 {
1325     long OpAddress = AbsoluteIndexedY ();
1326     LDA8 (OpAddress);
1327 }
1328
1329 static void OpB9M0 ()
1330 {
1331     long OpAddress = AbsoluteIndexedY ();
1332     LDA16 (OpAddress);
1333 }
1334
1335 static void OpAFM1 ()
1336 {
1337     long OpAddress = AbsoluteLong ();
1338     LDA8 (OpAddress);
1339 }
1340
1341 static void OpAFM0 ()
1342 {
1343     long OpAddress = AbsoluteLong ();
1344     LDA16 (OpAddress);
1345 }
1346
1347 static void OpBFM1 ()
1348 {
1349     long OpAddress = AbsoluteLongIndexedX ();
1350     LDA8 (OpAddress);
1351 }
1352
1353 static void OpBFM0 ()
1354 {
1355     long OpAddress = AbsoluteLongIndexedX ();
1356     LDA16 (OpAddress);
1357 }
1358
1359 static void OpA3M1 ()
1360 {
1361     long OpAddress = StackRelative ();
1362     LDA8 (OpAddress);
1363 }
1364
1365 static void OpA3M0 ()
1366 {
1367     long OpAddress = StackRelative ();
1368     LDA16 (OpAddress);
1369 }
1370
1371 static void OpB3M1 ()
1372 {
1373     long OpAddress = StackRelativeIndirectIndexed ();
1374     LDA8 (OpAddress);
1375 }
1376
1377 static void OpB3M0 ()
1378 {
1379     long OpAddress = StackRelativeIndirectIndexed ();
1380     LDA16 (OpAddress);
1381 }
1382
1383 /**********************************************************************************************/
1384
1385 /* LDX *************************************************************************************** */
1386 static void OpA2X1 ()
1387 {
1388     Registers.XL = *CPU.PC++;
1389 #ifdef VAR_CYCLES
1390     CPU.Cycles += CPU.MemSpeed;
1391 #endif
1392     SETZN8 (Registers.XL);
1393 }
1394
1395 static void OpA2X0 ()
1396 {
1397 #ifdef FAST_LSB_WORD_ACCESS
1398     Registers.X.W = *(uint16 *) CPU.PC;
1399 #else
1400     Registers.X.W = *CPU.PC + (*(CPU.PC + 1) << 8);
1401 #endif
1402     CPU.PC += 2;
1403 #ifdef VAR_CYCLES
1404     CPU.Cycles += CPU.MemSpeedx2;
1405 #endif
1406     SETZN16 (Registers.X.W);
1407 }
1408
1409 static void OpA6X1 ()
1410 {
1411     long OpAddress = Direct ();
1412     LDX8 (OpAddress);
1413 }
1414
1415 static void OpA6X0 ()
1416 {
1417     long OpAddress = Direct ();
1418     LDX16 (OpAddress);
1419 }
1420
1421 static void OpB6X1 ()
1422 {
1423     long OpAddress = DirectIndexedY ();
1424     LDX8 (OpAddress);
1425 }
1426
1427 static void OpB6X0 ()
1428 {
1429     long OpAddress = DirectIndexedY ();
1430     LDX16 (OpAddress);
1431 }
1432
1433 static void OpAEX1 ()
1434 {
1435     long OpAddress = Absolute ();
1436     LDX8 (OpAddress);
1437 }
1438
1439 static void OpAEX0 ()
1440 {
1441     long OpAddress = Absolute ();
1442     LDX16 (OpAddress);
1443 }
1444
1445 static void OpBEX1 ()
1446 {
1447     long OpAddress = AbsoluteIndexedY ();
1448     LDX8 (OpAddress);
1449 }
1450
1451 static void OpBEX0 ()
1452 {
1453     long OpAddress = AbsoluteIndexedY ();
1454     LDX16 (OpAddress);
1455 }
1456 /**********************************************************************************************/
1457
1458 /* LDY *************************************************************************************** */
1459 static void OpA0X1 ()
1460 {
1461     Registers.YL = *CPU.PC++;
1462 #ifdef VAR_CYCLES
1463     CPU.Cycles += CPU.MemSpeed;
1464 #endif
1465     SETZN8 (Registers.YL);
1466 }
1467
1468 static void OpA0X0 ()
1469 {
1470 #ifdef FAST_LSB_WORD_ACCESS
1471     Registers.Y.W = *(uint16 *) CPU.PC;
1472 #else
1473     Registers.Y.W = *CPU.PC + (*(CPU.PC + 1) << 8);
1474 #endif
1475
1476     CPU.PC += 2;
1477 #ifdef VAR_CYCLES
1478     CPU.Cycles += CPU.MemSpeedx2;
1479 #endif
1480     SETZN16 (Registers.Y.W);
1481 }
1482
1483 static void OpA4X1 ()
1484 {
1485     long OpAddress = Direct ();
1486     LDY8 (OpAddress);
1487 }
1488
1489 static void OpA4X0 ()
1490 {
1491     long OpAddress = Direct ();
1492     LDY16 (OpAddress);
1493 }
1494
1495 static void OpB4X1 ()
1496 {
1497     long OpAddress = DirectIndexedX ();
1498     LDY8 (OpAddress);
1499 }
1500
1501 static void OpB4X0 ()
1502 {
1503     long OpAddress = DirectIndexedX ();
1504     LDY16 (OpAddress);
1505 }
1506
1507 static void OpACX1 ()
1508 {
1509     long OpAddress = Absolute ();
1510     LDY8 (OpAddress);
1511 }
1512
1513 static void OpACX0 ()
1514 {
1515     long OpAddress = Absolute ();
1516     LDY16 (OpAddress);
1517 }
1518
1519 static void OpBCX1 ()
1520 {
1521     long OpAddress = AbsoluteIndexedX ();
1522     LDY8 (OpAddress);
1523 }
1524
1525 static void OpBCX0 ()
1526 {
1527     long OpAddress = AbsoluteIndexedX ();
1528     LDY16 (OpAddress);
1529 }
1530 /**********************************************************************************************/
1531
1532 /* LSR *************************************************************************************** */
1533 static void Op4AM1 ()
1534 {
1535     A_LSR8 ();
1536 }
1537
1538 static void Op4AM0 ()
1539 {
1540     A_LSR16 ();
1541 }
1542
1543 static void Op46M1 ()
1544 {
1545     long OpAddress = Direct ();
1546     LSR8 (OpAddress);
1547 }
1548
1549 static void Op46M0 ()
1550 {
1551     long OpAddress = Direct ();
1552     LSR16 (OpAddress);
1553 }
1554
1555 static void Op56M1 ()
1556 {
1557     long OpAddress = DirectIndexedX ();
1558     LSR8 (OpAddress);
1559 }
1560
1561 static void Op56M0 ()
1562 {
1563     long OpAddress = DirectIndexedX ();
1564     LSR16 (OpAddress);
1565 }
1566
1567 static void Op4EM1 ()
1568 {
1569     long OpAddress = Absolute ();
1570     LSR8 (OpAddress);
1571 }
1572
1573 static void Op4EM0 ()
1574 {
1575     long OpAddress = Absolute ();
1576     LSR16 (OpAddress);
1577 }
1578
1579 static void Op5EM1 ()
1580 {
1581     long OpAddress = AbsoluteIndexedX ();
1582     LSR8 (OpAddress);
1583 }
1584
1585 static void Op5EM0 ()
1586 {
1587     long OpAddress = AbsoluteIndexedX ();
1588     LSR16 (OpAddress);
1589 }
1590
1591 /**********************************************************************************************/
1592
1593 /* ORA *************************************************************************************** */
1594 static void Op09M1 ()
1595 {
1596     Registers.AL |= *CPU.PC++;
1597 #ifdef VAR_CYCLES
1598     CPU.Cycles += CPU.MemSpeed;
1599 #endif
1600     SETZN8 (Registers.AL);
1601 }
1602
1603 static void Op09M0 ()
1604 {
1605 #ifdef FAST_LSB_WORD_ACCESS
1606     Registers.A.W |= *(uint16 *) CPU.PC;
1607 #else
1608     Registers.A.W |= *CPU.PC + (*(CPU.PC + 1) << 8);
1609 #endif
1610     CPU.PC += 2;
1611 #ifdef VAR_CYCLES
1612     CPU.Cycles += CPU.MemSpeedx2;
1613 #endif
1614     SETZN16 (Registers.A.W);
1615 }
1616
1617 static void Op05M1 ()
1618 {
1619     long OpAddress = Direct ();
1620     ORA8 (OpAddress);
1621 }
1622
1623 static void Op05M0 ()
1624 {
1625     long OpAddress = Direct ();
1626     ORA16 (OpAddress);
1627 }
1628
1629 static void Op15M1 ()
1630 {
1631     long OpAddress = DirectIndexedX ();
1632     ORA8 (OpAddress);
1633 }
1634
1635 static void Op15M0 ()
1636 {
1637     long OpAddress = DirectIndexedX ();
1638     ORA16 (OpAddress);
1639 }
1640
1641 static void Op12M1 ()
1642 {
1643     long OpAddress = DirectIndirect ();
1644     ORA8 (OpAddress);
1645 }
1646
1647 static void Op12M0 ()
1648 {
1649     long OpAddress = DirectIndirect ();
1650     ORA16 (OpAddress);
1651 }
1652
1653 static void Op01M1 ()
1654 {
1655     long OpAddress = DirectIndexedIndirect ();
1656     ORA8 (OpAddress);
1657 }
1658
1659 static void Op01M0 ()
1660 {
1661     long OpAddress = DirectIndexedIndirect ();
1662     ORA16 (OpAddress);
1663 }
1664
1665 static void Op11M1 ()
1666 {
1667     long OpAddress = DirectIndirectIndexed ();
1668     ORA8 (OpAddress);
1669 }
1670
1671 static void Op11M0 ()
1672 {
1673     long OpAddress = DirectIndirectIndexed ();
1674     ORA16 (OpAddress);
1675 }
1676
1677 static void Op07M1 ()
1678 {
1679     long OpAddress = DirectIndirectLong ();
1680     ORA8 (OpAddress);
1681 }
1682
1683 static void Op07M0 ()
1684 {
1685     long OpAddress = DirectIndirectLong ();
1686     ORA16 (OpAddress);
1687 }
1688
1689 static void Op17M1 ()
1690 {
1691     long OpAddress = DirectIndirectIndexedLong ();
1692     ORA8 (OpAddress);
1693 }
1694
1695 static void Op17M0 ()
1696 {
1697     long OpAddress = DirectIndirectIndexedLong ();
1698     ORA16 (OpAddress);
1699 }
1700
1701 static void Op0DM1 ()
1702 {
1703     long OpAddress = Absolute ();
1704     ORA8 (OpAddress);
1705 }
1706
1707 static void Op0DM0 ()
1708 {
1709     long OpAddress = Absolute ();
1710     ORA16 (OpAddress);
1711 }
1712
1713 static void Op1DM1 ()
1714 {
1715     long OpAddress = AbsoluteIndexedX ();
1716     ORA8 (OpAddress);
1717 }
1718
1719 static void Op1DM0 ()
1720 {
1721     long OpAddress = AbsoluteIndexedX ();
1722     ORA16 (OpAddress);
1723 }
1724
1725 static void Op19M1 ()
1726 {
1727     long OpAddress = AbsoluteIndexedY ();
1728     ORA8 (OpAddress);
1729 }
1730
1731 static void Op19M0 ()
1732 {
1733     long OpAddress = AbsoluteIndexedY ();
1734     ORA16 (OpAddress);
1735 }
1736
1737 static void Op0FM1 ()
1738 {
1739     long OpAddress = AbsoluteLong ();
1740     ORA8 (OpAddress);
1741 }
1742
1743 static void Op0FM0 ()
1744 {
1745     long OpAddress = AbsoluteLong ();
1746     ORA16 (OpAddress);
1747 }
1748
1749 static void Op1FM1 ()
1750 {
1751     long OpAddress = AbsoluteLongIndexedX ();
1752     ORA8 (OpAddress);
1753 }
1754
1755 static void Op1FM0 ()
1756 {
1757     long OpAddress = AbsoluteLongIndexedX ();
1758     ORA16 (OpAddress);
1759 }
1760
1761 static void Op03M1 ()
1762 {
1763     long OpAddress = StackRelative ();
1764     ORA8 (OpAddress);
1765 }
1766
1767 static void Op03M0 ()
1768 {
1769     long OpAddress = StackRelative ();
1770     ORA16 (OpAddress);
1771 }
1772
1773 static void Op13M1 ()
1774 {
1775     long OpAddress = StackRelativeIndirectIndexed ();
1776     ORA8 (OpAddress);
1777 }
1778
1779 static void Op13M0 ()
1780 {
1781     long OpAddress = StackRelativeIndirectIndexed ();
1782     ORA16 (OpAddress);
1783 }
1784
1785 /**********************************************************************************************/
1786
1787 /* ROL *************************************************************************************** */
1788 static void Op2AM1 ()
1789 {
1790     A_ROL8 ();
1791 }
1792
1793 static void Op2AM0 ()
1794 {
1795     A_ROL16 ();
1796 }
1797
1798 static void Op26M1 ()
1799 {
1800     long OpAddress = Direct ();
1801     ROL8 (OpAddress);
1802 }
1803
1804 static void Op26M0 ()
1805 {
1806     long OpAddress = Direct ();
1807     ROL16 (OpAddress);
1808 }
1809
1810 static void Op36M1 ()
1811 {
1812     long OpAddress = DirectIndexedX ();
1813     ROL8 (OpAddress);
1814 }
1815
1816 static void Op36M0 ()
1817 {
1818     long OpAddress = DirectIndexedX ();
1819     ROL16 (OpAddress);
1820 }
1821
1822 static void Op2EM1 ()
1823 {
1824     long OpAddress = Absolute ();
1825     ROL8 (OpAddress);
1826 }
1827
1828 static void Op2EM0 ()
1829 {
1830     long OpAddress = Absolute ();
1831     ROL16 (OpAddress);
1832 }
1833
1834 static void Op3EM1 ()
1835 {
1836     long OpAddress = AbsoluteIndexedX ();
1837     ROL8 (OpAddress);
1838 }
1839
1840 static void Op3EM0 ()
1841 {
1842     long OpAddress = AbsoluteIndexedX ();
1843     ROL16 (OpAddress);
1844 }
1845 /**********************************************************************************************/
1846
1847 /* ROR *************************************************************************************** */
1848 static void Op6AM1 ()
1849 {
1850     A_ROR8 ();
1851 }
1852
1853 static void Op6AM0 ()
1854 {
1855     A_ROR16 ();
1856 }
1857
1858 static void Op66M1 ()
1859 {
1860     long OpAddress = Direct ();
1861     ROR8 (OpAddress);
1862 }
1863
1864 static void Op66M0 ()
1865 {
1866     long OpAddress = Direct ();
1867     ROR16 (OpAddress);
1868 }
1869
1870 static void Op76M1 ()
1871 {
1872     long OpAddress = DirectIndexedX ();
1873     ROR8 (OpAddress);
1874 }
1875
1876 static void Op76M0 ()
1877 {
1878     long OpAddress = DirectIndexedX ();
1879     ROR16 (OpAddress);
1880 }
1881
1882 static void Op6EM1 ()
1883 {
1884     long OpAddress = Absolute ();
1885     ROR8 (OpAddress);
1886 }
1887
1888 static void Op6EM0 ()
1889 {
1890     long OpAddress = Absolute ();
1891     ROR16 (OpAddress);
1892 }
1893
1894 static void Op7EM1 ()
1895 {
1896     long OpAddress = AbsoluteIndexedX ();
1897     ROR8 (OpAddress);
1898 }
1899
1900 static void Op7EM0 ()
1901 {
1902     long OpAddress = AbsoluteIndexedX ();
1903     ROR16 (OpAddress);
1904 }
1905 /**********************************************************************************************/
1906
1907 /* SBC *************************************************************************************** */
1908 static void OpE9M1 ()
1909 {
1910     long OpAddress = Immediate8 ();
1911     SBC8 (OpAddress);
1912 }
1913
1914 static void OpE9M0 ()
1915 {
1916     long OpAddress = Immediate16 ();
1917     SBC16 (OpAddress);
1918 }
1919
1920 static void OpE5M1 ()
1921 {
1922     long OpAddress = Direct ();
1923     SBC8 (OpAddress);
1924 }
1925
1926 static void OpE5M0 ()
1927 {
1928     long OpAddress = Direct ();
1929     SBC16 (OpAddress);
1930 }
1931
1932 static void OpF5M1 ()
1933 {
1934     long OpAddress = DirectIndexedX ();
1935     SBC8 (OpAddress);
1936 }
1937
1938 static void OpF5M0 ()
1939 {
1940     long OpAddress = DirectIndexedX ();
1941     SBC16 (OpAddress);
1942 }
1943
1944 static void OpF2M1 ()
1945 {
1946     long OpAddress = DirectIndirect ();
1947     SBC8 (OpAddress);
1948 }
1949
1950 static void OpF2M0 ()
1951 {
1952     long OpAddress = DirectIndirect ();
1953     SBC16 (OpAddress);
1954 }
1955
1956 static void OpE1M1 ()
1957 {
1958     long OpAddress = DirectIndexedIndirect ();
1959     SBC8 (OpAddress);
1960 }
1961
1962 static void OpE1M0 ()
1963 {
1964     long OpAddress = DirectIndexedIndirect ();
1965     SBC16 (OpAddress);
1966 }
1967
1968 static void OpF1M1 ()
1969 {
1970     long OpAddress = DirectIndirectIndexed ();
1971     SBC8 (OpAddress);
1972 }
1973
1974 static void OpF1M0 ()
1975 {
1976     long OpAddress = DirectIndirectIndexed ();
1977     SBC16 (OpAddress);
1978 }
1979
1980 static void OpE7M1 ()
1981 {
1982     long OpAddress = DirectIndirectLong ();
1983     SBC8 (OpAddress);
1984 }
1985
1986 static void OpE7M0 ()
1987 {
1988     long OpAddress = DirectIndirectLong ();
1989     SBC16 (OpAddress);
1990 }
1991
1992 static void OpF7M1 ()
1993 {
1994     long OpAddress = DirectIndirectIndexedLong ();
1995     SBC8 (OpAddress);
1996 }
1997
1998 static void OpF7M0 ()
1999 {
2000     long OpAddress = DirectIndirectIndexedLong ();
2001     SBC16 (OpAddress);
2002 }
2003
2004 static void OpEDM1 ()
2005 {
2006     long OpAddress = Absolute ();
2007     SBC8 (OpAddress);
2008 }
2009
2010 static void OpEDM0 ()
2011 {
2012     long OpAddress = Absolute ();
2013     SBC16 (OpAddress);
2014 }
2015
2016 static void OpFDM1 ()
2017 {
2018     long OpAddress = AbsoluteIndexedX ();
2019     SBC8 (OpAddress);
2020 }
2021
2022 static void OpFDM0 ()
2023 {
2024     long OpAddress = AbsoluteIndexedX ();
2025     SBC16 (OpAddress);
2026 }
2027
2028 static void OpF9M1 ()
2029 {
2030     long OpAddress = AbsoluteIndexedY ();
2031     SBC8 (OpAddress);
2032 }
2033
2034 static void OpF9M0 ()
2035 {
2036     long OpAddress = AbsoluteIndexedY ();
2037     SBC16 (OpAddress);
2038 }
2039
2040 static void OpEFM1 ()
2041 {
2042     long OpAddress = AbsoluteLong ();
2043     SBC8 (OpAddress);
2044 }
2045
2046 static void OpEFM0 ()
2047 {
2048     long OpAddress = AbsoluteLong ();
2049     SBC16 (OpAddress);
2050 }
2051
2052 static void OpFFM1 ()
2053 {
2054     long OpAddress = AbsoluteLongIndexedX ();
2055     SBC8 (OpAddress);
2056 }
2057
2058 static void OpFFM0 ()
2059 {
2060     long OpAddress = AbsoluteLongIndexedX ();
2061     SBC16 (OpAddress);
2062 }
2063
2064 static void OpE3M1 ()
2065 {
2066     long OpAddress = StackRelative ();
2067     SBC8 (OpAddress);
2068 }
2069
2070 static void OpE3M0 ()
2071 {
2072     long OpAddress = StackRelative ();
2073     SBC16 (OpAddress);
2074 }
2075
2076 static void OpF3M1 ()
2077 {
2078     long OpAddress = StackRelativeIndirectIndexed ();
2079     SBC8 (OpAddress);
2080 }
2081
2082 static void OpF3M0 ()
2083 {
2084     long OpAddress = StackRelativeIndirectIndexed ();
2085     SBC16 (OpAddress);
2086 }
2087 /**********************************************************************************************/
2088
2089 /* STA *************************************************************************************** */
2090 static void Op85M1 ()
2091 {
2092     long OpAddress = Direct ();
2093     STA8 (OpAddress);
2094 }
2095
2096 static void Op85M0 ()
2097 {
2098     long OpAddress = Direct ();
2099     STA16 (OpAddress);
2100 }
2101
2102 static void Op95M1 ()
2103 {
2104     long OpAddress = DirectIndexedX ();
2105     STA8 (OpAddress);
2106 }
2107
2108 static void Op95M0 ()
2109 {
2110     long OpAddress = DirectIndexedX ();
2111     STA16 (OpAddress);
2112 }
2113
2114 static void Op92M1 ()
2115 {
2116     long OpAddress = DirectIndirect ();
2117     STA8 (OpAddress);
2118 }
2119
2120 static void Op92M0 ()
2121 {
2122     long OpAddress = DirectIndirect ();
2123     STA16 (OpAddress);
2124 }
2125
2126 static void Op81M1 ()
2127 {
2128     long OpAddress = DirectIndexedIndirect ();
2129     STA8 (OpAddress);
2130 #ifdef noVAR_CYCLES
2131     if (CheckIndex ())
2132         CPU.Cycles += ONE_CYCLE;
2133 #endif
2134 }
2135
2136 static void Op81M0 ()
2137 {
2138     long OpAddress = DirectIndexedIndirect ();
2139     STA16 (OpAddress);
2140 #ifdef noVAR_CYCLES
2141     if (CheckIndex ())
2142         CPU.Cycles += ONE_CYCLE;
2143 #endif
2144 }
2145
2146 static void Op91M1 ()
2147 {
2148     long OpAddress = DirectIndirectIndexed ();
2149     STA8 (OpAddress);
2150 }
2151
2152 static void Op91M0 ()
2153 {
2154     long OpAddress = DirectIndirectIndexed ();
2155     STA16 (OpAddress);
2156 }
2157
2158 static void Op87M1 ()
2159 {
2160     long OpAddress = DirectIndirectLong ();
2161     STA8 (OpAddress);
2162 }
2163
2164 static void Op87M0 ()
2165 {
2166     long OpAddress = DirectIndirectLong ();
2167     STA16 (OpAddress);
2168 }
2169
2170 static void Op97M1 ()
2171 {
2172     long OpAddress = DirectIndirectIndexedLong ();
2173     STA8 (OpAddress);
2174 }
2175
2176 static void Op97M0 ()
2177 {
2178     long OpAddress = DirectIndirectIndexedLong ();
2179     STA16 (OpAddress);
2180 }
2181
2182 static void Op8DM1 ()
2183 {
2184     long OpAddress = Absolute ();
2185     STA8 (OpAddress);
2186 }
2187
2188 static void Op8DM0 ()
2189 {
2190     long OpAddress = Absolute ();
2191     STA16 (OpAddress);
2192 }
2193
2194 static void Op9DM1 ()
2195 {
2196     long OpAddress = AbsoluteIndexedX ();
2197     STA8 (OpAddress);
2198 }
2199
2200 static void Op9DM0 ()
2201 {
2202     long OpAddress = AbsoluteIndexedX ();
2203     STA16 (OpAddress);
2204 }
2205
2206 static void Op99M1 ()
2207 {
2208     long OpAddress = AbsoluteIndexedY ();
2209     STA8 (OpAddress);
2210 }
2211
2212 static void Op99M0 ()
2213 {
2214     long OpAddress = AbsoluteIndexedY ();
2215     STA16 (OpAddress);
2216 }
2217
2218 static void Op8FM1 ()
2219 {
2220     long OpAddress = AbsoluteLong ();
2221     STA8 (OpAddress);
2222 }
2223
2224 static void Op8FM0 ()
2225 {
2226     long OpAddress = AbsoluteLong ();
2227     STA16 (OpAddress);
2228 }
2229
2230 static void Op9FM1 ()
2231 {
2232     long OpAddress = AbsoluteLongIndexedX ();
2233     STA8 (OpAddress);
2234 }
2235
2236 static void Op9FM0 ()
2237 {
2238     long OpAddress = AbsoluteLongIndexedX ();
2239     STA16 (OpAddress);
2240 }
2241
2242 static void Op83M1 ()
2243 {
2244     long OpAddress = StackRelative ();
2245     STA8 (OpAddress);
2246 }
2247
2248 static void Op83M0 ()
2249 {
2250     long OpAddress = StackRelative ();
2251     STA16 (OpAddress);
2252 }
2253
2254 static void Op93M1 ()
2255 {
2256     long OpAddress = StackRelativeIndirectIndexed ();
2257     STA8 (OpAddress);
2258 }
2259
2260 static void Op93M0 ()
2261 {
2262     long OpAddress = StackRelativeIndirectIndexed ();
2263     STA16 (OpAddress);
2264 }
2265 /**********************************************************************************************/
2266
2267 /* STX *************************************************************************************** */
2268 static void Op86X1 ()
2269 {
2270     long OpAddress = Direct ();
2271     STX8 (OpAddress);
2272 }
2273
2274 static void Op86X0 ()
2275 {
2276     long OpAddress = Direct ();
2277     STX16 (OpAddress);
2278 }
2279
2280 static void Op96X1 ()
2281 {
2282     long OpAddress = DirectIndexedY ();
2283     STX8 (OpAddress);
2284 }
2285
2286 static void Op96X0 ()
2287 {
2288     long OpAddress = DirectIndexedY ();
2289     STX16 (OpAddress);
2290 }
2291
2292 static void Op8EX1 ()
2293 {
2294     long OpAddress = Absolute ();
2295     STX8 (OpAddress);
2296 }
2297
2298 static void Op8EX0 ()
2299 {
2300     long OpAddress = Absolute ();
2301     STX16 (OpAddress);
2302 }
2303 /**********************************************************************************************/
2304
2305 /* STY *************************************************************************************** */
2306 static void Op84X1 ()
2307 {
2308     long OpAddress = Direct ();
2309     STY8 (OpAddress);
2310 }
2311
2312 static void Op84X0 ()
2313 {
2314     long OpAddress = Direct ();
2315     STY16 (OpAddress);
2316 }
2317
2318 static void Op94X1 ()
2319 {
2320     long OpAddress = DirectIndexedX ();
2321     STY8 (OpAddress);
2322 }
2323
2324 static void Op94X0 ()
2325 {
2326     long OpAddress = DirectIndexedX ();
2327     STY16 (OpAddress);
2328 }
2329
2330 static void Op8CX1 ()
2331 {
2332     long OpAddress = Absolute ();
2333     STY8 (OpAddress);
2334 }
2335
2336 static void Op8CX0 ()
2337 {
2338     long OpAddress = Absolute ();
2339     STY16 (OpAddress);
2340 }
2341 /**********************************************************************************************/
2342
2343 /* STZ *************************************************************************************** */
2344 static void Op64M1 ()
2345 {
2346     long OpAddress = Direct ();
2347     STZ8 (OpAddress);
2348 }
2349
2350 static void Op64M0 ()
2351 {
2352     long OpAddress = Direct ();
2353     STZ16 (OpAddress);
2354 }
2355
2356 static void Op74M1 ()
2357 {
2358     long OpAddress = DirectIndexedX ();
2359     STZ8 (OpAddress);
2360 }
2361
2362 static void Op74M0 ()
2363 {
2364     long OpAddress = DirectIndexedX ();
2365     STZ16 (OpAddress);
2366 }
2367
2368 static void Op9CM1 ()
2369 {
2370     long OpAddress = Absolute ();
2371     STZ8 (OpAddress);
2372 }
2373
2374 static void Op9CM0 ()
2375 {
2376     long OpAddress = Absolute ();
2377     STZ16 (OpAddress);
2378 }
2379
2380 static void Op9EM1 ()
2381 {
2382     long OpAddress = AbsoluteIndexedX ();
2383     STZ8 (OpAddress);
2384 }
2385
2386 static void Op9EM0 ()
2387 {
2388     long OpAddress = AbsoluteIndexedX ();
2389     STZ16 (OpAddress);
2390 }
2391
2392 /**********************************************************************************************/
2393
2394 /* TRB *************************************************************************************** */
2395 static void Op14M1 ()
2396 {
2397     long OpAddress = Direct ();
2398     TRB8 (OpAddress);
2399 }
2400
2401 static void Op14M0 ()
2402 {
2403     long OpAddress = Direct ();
2404     TRB16 (OpAddress);
2405 }
2406
2407 static void Op1CM1 ()
2408 {
2409     long OpAddress = Absolute ();
2410     TRB8 (OpAddress);
2411 }
2412
2413 static void Op1CM0 ()
2414 {
2415     long OpAddress = Absolute ();
2416     TRB16 (OpAddress);
2417 }
2418 /**********************************************************************************************/
2419
2420 /* TSB *************************************************************************************** */
2421 static void Op04M1 ()
2422 {
2423     long OpAddress = Direct ();
2424     TSB8 (OpAddress);
2425 }
2426
2427 static void Op04M0 ()
2428 {
2429     long OpAddress = Direct ();
2430     TSB16 (OpAddress);
2431 }
2432
2433 static void Op0CM1 ()
2434 {
2435     long OpAddress = Absolute ();
2436     TSB8 (OpAddress);
2437 }
2438
2439 static void Op0CM0 ()
2440 {
2441     long OpAddress = Absolute ();
2442     TSB16 (OpAddress);
2443 }
2444
2445 /**********************************************************************************************/
2446
2447 /* Branch Instructions *********************************************************************** */
2448 #ifndef SA1_OPCODES
2449 #define BranchCheck0()\
2450     if( CPU.BranchSkip)\
2451     {\
2452         CPU.BranchSkip = FALSE;\
2453         if (!Settings.SoundSkipMethod)\
2454             if( CPU.PC - CPU.PCBase > OpAddress)\
2455                 return;\
2456     }
2457
2458 #define BranchCheck1()\
2459     if( CPU.BranchSkip)\
2460     {\
2461         CPU.BranchSkip = FALSE;\
2462         if (!Settings.SoundSkipMethod) {\
2463             if( CPU.PC - CPU.PCBase > OpAddress)\
2464                 return;\
2465         } else \
2466         if (Settings.SoundSkipMethod == 1)\
2467             return;\
2468         if (Settings.SoundSkipMethod == 3)\
2469             if( CPU.PC - CPU.PCBase > OpAddress)\
2470                 return;\
2471             else\
2472                 CPU.PC = CPU.PCBase + OpAddress;\
2473     }
2474
2475 #define BranchCheck2()\
2476     if( CPU.BranchSkip)\
2477     {\
2478         CPU.BranchSkip = FALSE;\
2479         if (!Settings.SoundSkipMethod) {\
2480             if( CPU.PC - CPU.PCBase > OpAddress)\
2481                 return;\
2482         } else \
2483         if (Settings.SoundSkipMethod == 1)\
2484             CPU.PC = CPU.PCBase + OpAddress;\
2485         if (Settings.SoundSkipMethod == 3)\
2486             if (CPU.PC - CPU.PCBase > OpAddress)\
2487                 return;\
2488             else\
2489                 CPU.PC = CPU.PCBase + OpAddress;\
2490     }
2491 #else
2492 #define BranchCheck0()
2493 #define BranchCheck1()
2494 #define BranchCheck2()
2495 #endif
2496
2497 #ifdef CPU_SHUTDOWN
2498 #ifndef SA1_OPCODES
2499 INLINE void CPUShutdown()
2500 {
2501     if (Settings.Shutdown && CPU.PC == CPU.WaitAddress)
2502     {
2503         // Don't skip cycles with a pending NMI or IRQ - could cause delayed
2504         // interrupt. Interrupts are delayed for a few cycles alreadybut
2505         // the delay could allow the shutdown code to cycle skip again.
2506         // Was causing screen flashing on Top Gear 3000.
2507
2508         if (CPU.WaitCounter == 0 && 
2509             !(CPU.Flags & (IRQ_PENDING_FLAG | NMI_FLAG)))
2510         {
2511             CPU.WaitAddress = NULL;
2512 #ifdef USE_SA1
2513             if (Settings.SA1) {
2514                 S9xSA1ExecuteDuringSleep ();
2515             }
2516 #endif
2517             ApuSync();
2518         }
2519         else
2520         if (CPU.WaitCounter >= 2)
2521             CPU.WaitCounter = 1;
2522         else
2523             CPU.WaitCounter--;
2524     }
2525 }
2526 #else
2527 INLINE void CPUShutdown()
2528 {
2529     if (Settings.Shutdown && CPU.PC == CPU.WaitAddress)
2530     {
2531         if (CPU.WaitCounter >= 1)
2532         {
2533             SA1.Executing = FALSE;
2534             SA1.CPUExecuting = FALSE;
2535         }
2536         else
2537             CPU.WaitCounter++;
2538     }
2539 }
2540 #endif
2541 #else
2542 #define CPUShutdown()
2543 #endif
2544
2545 /* BCC */
2546 static void Op90 ()
2547 {
2548     long OpAddress = Relative ();
2549     BranchCheck0 ();
2550     if (!CheckCarry())
2551     {
2552         CPU.PC = CPU.PCBase + OpAddress;
2553 #ifdef VAR_CYCLES
2554         CPU.Cycles += ONE_CYCLE;
2555 #else
2556 #ifndef SA1_OPCODES
2557         CPU.Cycles++;
2558 #endif
2559 #endif
2560         CPUShutdown();
2561     }
2562 }
2563
2564 /* BCS */
2565 static void OpB0 ()
2566 {
2567     long OpAddress = Relative ();
2568     BranchCheck0 ();
2569     if (CheckCarry())
2570     {
2571         CPU.PC = CPU.PCBase + OpAddress;
2572 #ifdef VAR_CYCLES
2573         CPU.Cycles += ONE_CYCLE;
2574 #else
2575 #ifndef SA1_OPCODES
2576         CPU.Cycles++;
2577 #endif
2578 #endif
2579         CPUShutdown();
2580     }
2581 }
2582
2583 /* BEQ */
2584 static void OpF0 ()
2585 {
2586     long OpAddress = Relative ();
2587     BranchCheck2 ();
2588     if (CheckZero())
2589     {
2590         CPU.PC = CPU.PCBase + OpAddress;
2591 #ifdef VAR_CYCLES
2592         CPU.Cycles += ONE_CYCLE;
2593 #else
2594 #ifndef SA1_OPCODES
2595         CPU.Cycles++;
2596 #endif
2597 #endif
2598         CPUShutdown();
2599     }
2600 }
2601
2602 /* BMI */
2603 static void Op30 ()
2604 {
2605     long OpAddress = Relative ();
2606     BranchCheck1 ();
2607     if (CheckNegative())
2608     {
2609         CPU.PC = CPU.PCBase + OpAddress;
2610 #ifdef VAR_CYCLES
2611         CPU.Cycles += ONE_CYCLE;
2612 #else
2613 #ifndef SA1_OPCODES
2614         CPU.Cycles++;
2615 #endif
2616 #endif
2617         CPUShutdown();
2618     }
2619 }
2620
2621 /* BNE */
2622 static void OpD0 ()
2623 {
2624     long OpAddress = Relative ();
2625     BranchCheck1 ();
2626     if (!CheckZero())
2627     {
2628         CPU.PC = CPU.PCBase + OpAddress;
2629
2630 #ifdef VAR_CYCLES
2631         CPU.Cycles += ONE_CYCLE;
2632 #else
2633 #ifndef SA1_OPCODES
2634         CPU.Cycles++;
2635 #endif
2636 #endif
2637         CPUShutdown();
2638     }
2639 }
2640
2641 /* BPL */
2642 static void Op10 ()
2643 {
2644     long OpAddress = Relative ();
2645     BranchCheck1 ();
2646     if (!CheckNegative())
2647     {
2648         CPU.PC = CPU.PCBase + OpAddress;
2649 #ifdef VAR_CYCLES
2650         CPU.Cycles += ONE_CYCLE;
2651 #else
2652 #ifndef SA1_OPCODES
2653         CPU.Cycles++;
2654 #endif
2655 #endif
2656         CPUShutdown();
2657     }
2658 }
2659
2660 /* BRA */
2661 static void Op80 ()
2662 {
2663     long OpAddress = Relative ();
2664     CPU.PC = CPU.PCBase + OpAddress;
2665 #ifdef VAR_CYCLES
2666     CPU.Cycles += ONE_CYCLE;
2667 #else
2668 #ifndef SA1_OPCODES
2669     CPU.Cycles++;
2670 #endif
2671 #endif
2672     CPUShutdown();
2673 }
2674
2675 /* BVC */
2676 static void Op50 ()
2677 {
2678     long OpAddress = Relative ();
2679     BranchCheck0 ();
2680     if (!CheckOverflow())
2681     {
2682         CPU.PC = CPU.PCBase + OpAddress;
2683 #ifdef VAR_CYCLES
2684         CPU.Cycles += ONE_CYCLE;
2685 #else
2686 #ifndef SA1_OPCODES
2687         CPU.Cycles++;
2688 #endif
2689 #endif
2690         CPUShutdown();
2691     }
2692 }
2693
2694 /* BVS */
2695 static void Op70 ()
2696 {
2697     long OpAddress = Relative ();
2698     BranchCheck0 ();
2699     if (CheckOverflow())
2700     {
2701         CPU.PC = CPU.PCBase + OpAddress;
2702 #ifdef VAR_CYCLES
2703         CPU.Cycles += ONE_CYCLE;
2704 #else
2705 #ifndef SA1_OPCODES
2706         CPU.Cycles++;
2707 #endif
2708 #endif
2709         CPUShutdown();
2710     }
2711 }
2712 /**********************************************************************************************/
2713
2714 /* ClearFlag Instructions ******************************************************************** */
2715 /* CLC */
2716 static void Op18 ()
2717 {
2718     ClearCarry ();
2719 #ifdef VAR_CYCLES
2720     CPU.Cycles += ONE_CYCLE;
2721 #endif
2722 }
2723
2724 /* CLD */
2725 static void OpD8 ()
2726 {
2727     ClearDecimal ();
2728 #ifdef VAR_CYCLES
2729     CPU.Cycles += ONE_CYCLE;
2730 #endif
2731 }
2732
2733 /* CLI */
2734 static void Op58 ()
2735 {
2736     ClearIRQ ();
2737 #ifdef VAR_CYCLES
2738     CPU.Cycles += ONE_CYCLE;
2739 #endif
2740 /*    CHECK_FOR_IRQ(); */
2741 }
2742
2743 /* CLV */
2744 static void OpB8 ()
2745 {
2746     ClearOverflow();
2747 #ifdef VAR_CYCLES
2748     CPU.Cycles += ONE_CYCLE;
2749 #endif
2750 }
2751 /**********************************************************************************************/
2752
2753 /* DEX/DEY *********************************************************************************** */
2754 static void OpCAX1 ()
2755 {
2756 #ifdef VAR_CYCLES
2757     CPU.Cycles += ONE_CYCLE;
2758 #endif
2759 #ifdef CPU_SHUTDOWN
2760     CPU.WaitAddress = NULL;
2761 #endif
2762
2763     Registers.XL--;
2764     SETZN8 (Registers.XL);
2765 }
2766
2767 static void OpCAX0 ()
2768 {
2769 #ifdef VAR_CYCLES
2770     CPU.Cycles += ONE_CYCLE;
2771 #endif
2772 #ifdef CPU_SHUTDOWN
2773     CPU.WaitAddress = NULL;
2774 #endif
2775
2776     Registers.X.W--;
2777     SETZN16 (Registers.X.W);
2778 }
2779
2780 static void Op88X1 ()
2781 {
2782 #ifdef VAR_CYCLES
2783     CPU.Cycles += ONE_CYCLE;
2784 #endif
2785 #ifdef CPU_SHUTDOWN
2786     CPU.WaitAddress = NULL;
2787 #endif
2788
2789     Registers.YL--;
2790     SETZN8 (Registers.YL);
2791 }
2792
2793 static void Op88X0 ()
2794 {
2795 #ifdef VAR_CYCLES
2796     CPU.Cycles += ONE_CYCLE;
2797 #endif
2798 #ifdef CPU_SHUTDOWN
2799     CPU.WaitAddress = NULL;
2800 #endif
2801
2802     Registers.Y.W--;
2803     SETZN16 (Registers.Y.W);
2804 }
2805 /**********************************************************************************************/
2806
2807 /* INX/INY *********************************************************************************** */
2808 static void OpE8X1 ()
2809 {
2810 #ifdef VAR_CYCLES
2811     CPU.Cycles += ONE_CYCLE;
2812 #endif
2813 #ifdef CPU_SHUTDOWN
2814     CPU.WaitAddress = NULL;
2815 #endif
2816
2817     Registers.XL++;
2818     SETZN8 (Registers.XL);
2819 }
2820
2821 static void OpE8X0 ()
2822 {
2823 #ifdef VAR_CYCLES
2824     CPU.Cycles += ONE_CYCLE;
2825 #endif
2826 #ifdef CPU_SHUTDOWN
2827     CPU.WaitAddress = NULL;
2828 #endif
2829
2830     Registers.X.W++;
2831     SETZN16 (Registers.X.W);
2832 }
2833
2834 static void OpC8X1 ()
2835 {
2836 #ifdef VAR_CYCLES
2837     CPU.Cycles += ONE_CYCLE;
2838 #endif
2839 #ifdef CPU_SHUTDOWN
2840     CPU.WaitAddress = NULL;
2841 #endif
2842
2843     Registers.YL++;
2844     SETZN8 (Registers.YL);
2845 }
2846
2847 static void OpC8X0 ()
2848 {
2849 #ifdef VAR_CYCLES
2850     CPU.Cycles += ONE_CYCLE;
2851 #endif
2852 #ifdef CPU_SHUTDOWN
2853     CPU.WaitAddress = NULL;
2854 #endif
2855
2856     Registers.Y.W++;
2857     SETZN16 (Registers.Y.W);
2858 }
2859
2860 /**********************************************************************************************/
2861
2862 /* NOP *************************************************************************************** */
2863 static void OpEA ()
2864 {
2865 #ifdef VAR_CYCLES
2866     CPU.Cycles += ONE_CYCLE;
2867 #endif
2868
2869 }
2870 /**********************************************************************************************/
2871
2872 /* PUSH Instructions ************************************************************************* */
2873 #define PUSHW(w) \
2874     S9xSetWord (w, Registers.S.W - 1);\
2875     Registers.S.W -= 2;
2876 #define PUSHB(b)\
2877     S9xSetByte (b, Registers.S.W--);
2878
2879 static void OpF4 ()
2880 {
2881     long OpAddress = Absolute ();
2882     PUSHW (OpAddress);
2883 }
2884
2885 static void OpD4 ()
2886 {
2887     long OpAddress = DirectIndirect ();
2888     PUSHW (OpAddress);
2889 }
2890
2891 static void Op62 ()
2892 {
2893     long OpAddress = RelativeLong ();
2894     PUSHW (OpAddress);
2895 }
2896
2897 static void Op48M1 ()
2898 {
2899     PUSHB (Registers.AL);
2900 #ifdef VAR_CYCLES
2901     CPU.Cycles += ONE_CYCLE;
2902 #endif
2903 }
2904
2905 static void Op48M0 ()
2906 {
2907     PUSHW (Registers.A.W);
2908 #ifdef VAR_CYCLES
2909     CPU.Cycles += ONE_CYCLE;
2910 #endif
2911 }
2912
2913 static void Op8B ()
2914 {
2915     PUSHB (Registers.DB);
2916 #ifdef VAR_CYCLES
2917     CPU.Cycles += ONE_CYCLE;
2918 #endif
2919 }
2920
2921 static void Op0B ()
2922 {
2923     PUSHW (Registers.D.W);
2924 #ifdef VAR_CYCLES
2925     CPU.Cycles += ONE_CYCLE;
2926 #endif
2927 }
2928
2929 static void Op4B ()
2930 {
2931     PUSHB (Registers.PB);
2932 #ifdef VAR_CYCLES
2933     CPU.Cycles += ONE_CYCLE;
2934 #endif
2935 }
2936
2937 static void Op08 ()
2938 {
2939     S9xPackStatus ();
2940     PUSHB (Registers.PL);
2941 #ifdef VAR_CYCLES
2942     CPU.Cycles += ONE_CYCLE;
2943 #endif
2944 }
2945
2946 static void OpDAX1 ()
2947 {
2948     PUSHB (Registers.XL);
2949 #ifdef VAR_CYCLES
2950     CPU.Cycles += ONE_CYCLE;
2951 #endif
2952 }
2953
2954 static void OpDAX0 ()
2955 {
2956     PUSHW (Registers.X.W);
2957 #ifdef VAR_CYCLES
2958     CPU.Cycles += ONE_CYCLE;
2959 #endif
2960 }
2961
2962 static void Op5AX1 ()
2963 {
2964     PUSHB (Registers.YL);
2965 #ifdef VAR_CYCLES
2966     CPU.Cycles += ONE_CYCLE;
2967 #endif
2968 }
2969
2970 static void Op5AX0 ()
2971 {
2972     PUSHW (Registers.Y.W);
2973 #ifdef VAR_CYCLES
2974     CPU.Cycles += ONE_CYCLE;
2975 #endif
2976 }
2977 /**********************************************************************************************/
2978
2979 /* PULL Instructions ************************************************************************* */
2980 #define PullW(w) \
2981         w = S9xGetWord (Registers.S.W + 1); \
2982         Registers.S.W += 2;
2983
2984 #define PullB(b)\
2985         b = S9xGetByte (++Registers.S.W);
2986
2987 static void Op68M1 ()
2988 {
2989 #ifdef VAR_CYCLES
2990     CPU.Cycles += TWO_CYCLES;
2991 #endif
2992     PullB (Registers.AL);
2993     SETZN8 (Registers.AL);
2994 }
2995
2996 static void Op68M0 ()
2997 {
2998 #ifdef VAR_CYCLES
2999     CPU.Cycles += TWO_CYCLES;
3000 #endif
3001     PullW (Registers.A.W);
3002     SETZN16 (Registers.A.W);
3003 }
3004
3005 static void OpAB ()
3006 {
3007 #ifdef VAR_CYCLES
3008     CPU.Cycles += TWO_CYCLES;
3009 #endif
3010     PullB (Registers.DB);
3011     SETZN8 (Registers.DB);
3012     ICPU.ShiftedDB = (Registers.DB & 0xff) << 16;
3013 }
3014
3015 /* PHP */
3016 static void Op2B ()
3017 {
3018 #ifdef VAR_CYCLES
3019     CPU.Cycles += TWO_CYCLES;
3020 #endif
3021     PullW (Registers.D.W);
3022     SETZN16 (Registers.D.W);
3023 }
3024
3025 /* PLP */
3026 static void Op28 ()
3027 {
3028 #ifdef VAR_CYCLES
3029     CPU.Cycles += TWO_CYCLES;
3030 #endif
3031     PullB (Registers.PL);
3032     S9xUnpackStatus ();
3033
3034     if (CheckIndex())
3035     {
3036         Registers.XH = 0;
3037         Registers.YH = 0;
3038     }
3039     S9xFixCycles();
3040 /*     CHECK_FOR_IRQ();*/
3041 }
3042
3043 static void OpFAX1 ()
3044 {
3045 #ifdef VAR_CYCLES
3046     CPU.Cycles += TWO_CYCLES;
3047 #endif
3048     PullB (Registers.XL);
3049     SETZN8 (Registers.XL);
3050 }
3051
3052 static void OpFAX0 ()
3053 {
3054 #ifdef VAR_CYCLES
3055     CPU.Cycles += TWO_CYCLES;
3056 #endif
3057     PullW (Registers.X.W);
3058     SETZN16 (Registers.X.W);
3059 }
3060
3061 static void Op7AX1 ()
3062 {
3063 #ifdef VAR_CYCLES
3064     CPU.Cycles += TWO_CYCLES;
3065 #endif
3066     PullB (Registers.YL);
3067     SETZN8 (Registers.YL);
3068 }
3069
3070 static void Op7AX0 ()
3071 {
3072 #ifdef VAR_CYCLES
3073     CPU.Cycles += TWO_CYCLES;
3074 #endif
3075     PullW (Registers.Y.W);
3076     SETZN16 (Registers.Y.W);
3077 }
3078
3079 /**********************************************************************************************/
3080
3081 /* SetFlag Instructions ********************************************************************** */
3082 /* SEC */
3083 static void Op38 ()
3084 {
3085     SetCarry();
3086 #ifdef VAR_CYCLES
3087     CPU.Cycles += ONE_CYCLE;
3088 #endif
3089 }
3090
3091 /* SED */
3092 static void OpF8 ()
3093 {
3094     SetDecimal();
3095 #ifdef VAR_CYCLES
3096     CPU.Cycles += ONE_CYCLE;
3097 #endif
3098     missing.decimal_mode = 1;
3099 }
3100
3101 /* SEI */
3102 static void Op78 ()
3103 {
3104     SetIRQ ();
3105 #ifdef VAR_CYCLES
3106     CPU.Cycles += ONE_CYCLE;
3107 #endif
3108 }
3109 /**********************************************************************************************/
3110
3111 /* Transfer Instructions ********************************************************************* */
3112 /* TAX8 */
3113 static void OpAAX1 ()
3114 {
3115 #ifdef VAR_CYCLES
3116     CPU.Cycles += ONE_CYCLE;
3117 #endif
3118     Registers.XL = Registers.AL;
3119     SETZN8 (Registers.XL);
3120 }
3121
3122 /* TAX16 */
3123 static void OpAAX0 ()
3124 {
3125 #ifdef VAR_CYCLES
3126     CPU.Cycles += ONE_CYCLE;
3127 #endif
3128     Registers.X.W = Registers.A.W;
3129     SETZN16 (Registers.X.W);
3130 }
3131
3132 /* TAY8 */
3133 static void OpA8X1 ()
3134 {
3135 #ifdef VAR_CYCLES
3136     CPU.Cycles += ONE_CYCLE;
3137 #endif
3138     Registers.YL = Registers.AL;
3139     SETZN8 (Registers.YL);
3140 }
3141
3142 /* TAY16 */
3143 static void OpA8X0 ()
3144 {
3145 #ifdef VAR_CYCLES
3146     CPU.Cycles += ONE_CYCLE;
3147 #endif
3148     Registers.Y.W = Registers.A.W;
3149     SETZN16 (Registers.Y.W);
3150 }
3151
3152 static void Op5B ()
3153 {
3154 #ifdef VAR_CYCLES
3155     CPU.Cycles += ONE_CYCLE;
3156 #endif
3157     Registers.D.W = Registers.A.W;
3158     SETZN16 (Registers.D.W);
3159 }
3160
3161 static void Op1B ()
3162 {
3163 #ifdef VAR_CYCLES
3164     CPU.Cycles += ONE_CYCLE;
3165 #endif
3166     Registers.S.W = Registers.A.W;
3167     if (CheckEmulation())
3168         Registers.SH = 1;
3169 }
3170
3171 static void Op7B ()
3172 {
3173 #ifdef VAR_CYCLES
3174     CPU.Cycles += ONE_CYCLE;
3175 #endif
3176     Registers.A.W = Registers.D.W;
3177     SETZN16 (Registers.A.W);
3178 }
3179
3180 static void Op3B ()
3181 {
3182 #ifdef VAR_CYCLES
3183     CPU.Cycles += ONE_CYCLE;
3184 #endif
3185     Registers.A.W = Registers.S.W;
3186     SETZN16 (Registers.A.W);
3187 }
3188
3189 static void OpBAX1 ()
3190 {
3191 #ifdef VAR_CYCLES
3192     CPU.Cycles += ONE_CYCLE;
3193 #endif
3194     Registers.XL = Registers.SL;
3195     SETZN8 (Registers.XL);
3196 }
3197
3198 static void OpBAX0 ()
3199 {
3200 #ifdef VAR_CYCLES
3201     CPU.Cycles += ONE_CYCLE;
3202 #endif
3203     Registers.X.W = Registers.S.W;
3204     SETZN16 (Registers.X.W);
3205 }
3206
3207 static void Op8AM1 ()
3208 {
3209 #ifdef VAR_CYCLES
3210     CPU.Cycles += ONE_CYCLE;
3211 #endif
3212     Registers.AL = Registers.XL;
3213     SETZN8 (Registers.AL);
3214 }
3215
3216 static void Op8AM0 ()
3217 {
3218 #ifdef VAR_CYCLES
3219     CPU.Cycles += ONE_CYCLE;
3220 #endif
3221     Registers.A.W = Registers.X.W;
3222     SETZN16 (Registers.A.W);
3223 }
3224
3225 static void Op9A ()
3226 {
3227 #ifdef VAR_CYCLES
3228     CPU.Cycles += ONE_CYCLE;
3229 #endif
3230     Registers.S.W = Registers.X.W;
3231     if (CheckEmulation())
3232         Registers.SH = 1;
3233 }
3234
3235 static void Op9BX1 ()
3236 {
3237 #ifdef VAR_CYCLES
3238     CPU.Cycles += ONE_CYCLE;
3239 #endif
3240     Registers.YL = Registers.XL;
3241     SETZN8 (Registers.YL);
3242 }
3243
3244 static void Op9BX0 ()
3245 {
3246 #ifdef VAR_CYCLES
3247     CPU.Cycles += ONE_CYCLE;
3248 #endif
3249     Registers.Y.W = Registers.X.W;
3250     SETZN16 (Registers.Y.W);
3251 }
3252
3253 static void Op98M1 ()
3254 {
3255 #ifdef VAR_CYCLES
3256     CPU.Cycles += ONE_CYCLE;
3257 #endif
3258     Registers.AL = Registers.YL;
3259     SETZN8 (Registers.AL);
3260 }
3261
3262 static void Op98M0 ()
3263 {
3264 #ifdef VAR_CYCLES
3265     CPU.Cycles += ONE_CYCLE;
3266 #endif
3267     Registers.A.W = Registers.Y.W;
3268     SETZN16 (Registers.A.W);
3269 }
3270
3271 static void OpBBX1 ()
3272 {
3273 #ifdef VAR_CYCLES
3274     CPU.Cycles += ONE_CYCLE;
3275 #endif
3276     Registers.XL = Registers.YL;
3277     SETZN8 (Registers.XL);
3278 }
3279
3280 static void OpBBX0 ()
3281 {
3282 #ifdef VAR_CYCLES
3283     CPU.Cycles += ONE_CYCLE;
3284 #endif
3285     Registers.X.W = Registers.Y.W;
3286     SETZN16 (Registers.X.W);
3287 }
3288
3289 /**********************************************************************************************/
3290
3291 /* XCE *************************************************************************************** */
3292 static void OpFB ()
3293 {
3294 #ifdef VAR_CYCLES
3295     CPU.Cycles += ONE_CYCLE;
3296 #endif
3297
3298     uint8 A1 = (ICPU._Carry & 0xff);
3299     uint8 A2 = Registers.PH;
3300     ICPU._Carry = A2 & 1;
3301     Registers.PH = A1;
3302
3303     if (CheckEmulation())
3304     {
3305         SetFlags(MemoryFlag | IndexFlag);
3306         Registers.SH = 1;
3307         missing.emulate6502 = 1;
3308     }
3309     if (CheckIndex ())
3310     {
3311         Registers.XH = 0;
3312         Registers.YH = 0;
3313     }
3314     S9xFixCycles();
3315 }
3316 /**********************************************************************************************/
3317
3318 /* BRK *************************************************************************************** */
3319 static void Op00 ()
3320 {
3321 #ifdef DEBUGGER
3322     if (CPU.Flags & TRACE_FLAG)
3323         S9xTraceMessage ("*** BRK");
3324 #endif
3325
3326 #ifndef SA1_OPCODES
3327     CPU.BRKTriggered = TRUE;
3328 #endif
3329
3330     if (!CheckEmulation())
3331     {
3332         PUSHB (Registers.PB);
3333         PUSHW (CPU.PC - CPU.PCBase + 1);
3334         S9xPackStatus ();
3335         PUSHB (Registers.PL);
3336         ClearDecimal ();
3337         SetIRQ ();
3338
3339         Registers.PB = 0;
3340         ICPU.ShiftedPB = 0;
3341         S9xSetPCBase (S9xGetWord (0xFFE6));
3342 #ifdef VAR_CYCLES
3343         CPU.Cycles += TWO_CYCLES;
3344 #else
3345 #ifndef SA1_OPCODES
3346         CPU.Cycles += 8;
3347 #endif
3348 #endif
3349     }
3350     else
3351     {
3352         PUSHW (CPU.PC - CPU.PCBase);
3353         S9xPackStatus ();
3354         PUSHB (Registers.PL);
3355         ClearDecimal ();
3356         SetIRQ ();
3357
3358         Registers.PB = 0;
3359         ICPU.ShiftedPB = 0;
3360         S9xSetPCBase (S9xGetWord (0xFFFE));
3361 #ifdef VAR_CYCLES
3362         CPU.Cycles += ONE_CYCLE;
3363 #else
3364 #ifndef SA1_OPCODES
3365         CPU.Cycles += 6;
3366 #endif
3367 #endif
3368     }
3369 }
3370 /**********************************************************************************************/
3371
3372 /* BRL ************************************************************************************** */
3373 static void Op82 ()
3374 {
3375     long OpAddress = RelativeLong ();
3376     S9xSetPCBase (ICPU.ShiftedPB + OpAddress);
3377 }
3378 /**********************************************************************************************/
3379
3380 /* IRQ *************************************************************************************** */
3381 void S9xOpcode_IRQ ()
3382 {
3383 #ifdef DEBUGGER
3384     if (CPU.Flags & TRACE_FLAG)
3385         S9xTraceMessage ("*** IRQ");
3386 #endif
3387     if (!CheckEmulation())
3388     {
3389         PUSHB (Registers.PB);
3390         PUSHW (CPU.PC - CPU.PCBase);
3391         S9xPackStatus ();
3392         PUSHB (Registers.PL);
3393         ClearDecimal ();
3394         SetIRQ ();
3395
3396         Registers.PB = 0;
3397         ICPU.ShiftedPB = 0;
3398 #ifdef SA1_OPCODES
3399         S9xSA1SetPCBase (Memory.FillRAM [0x2207] |
3400                          (Memory.FillRAM [0x2208] << 8));
3401 #else
3402         if (Settings.SA1 && (Memory.FillRAM [0x2209] & 0x40))
3403             S9xSetPCBase (Memory.FillRAM [0x220e] | 
3404                           (Memory.FillRAM [0x220f] << 8));
3405         else
3406             S9xSetPCBase (S9xGetWord (0xFFEE));
3407 #endif
3408 #ifdef VAR_CYCLES
3409         CPU.Cycles += TWO_CYCLES;
3410 #else
3411 #ifndef SA1_OPCODES
3412         CPU.Cycles += 8;
3413 #endif
3414 #endif
3415     }
3416     else
3417     {
3418         PUSHW (CPU.PC - CPU.PCBase);
3419         S9xPackStatus ();
3420         PUSHB (Registers.PL);
3421         ClearDecimal ();
3422         SetIRQ ();
3423
3424         Registers.PB = 0;
3425         ICPU.ShiftedPB = 0;
3426 #ifdef SA1_OPCODES
3427         S9xSA1SetPCBase (Memory.FillRAM [0x2207] |
3428                          (Memory.FillRAM [0x2208] << 8));
3429 #else
3430         if (Settings.SA1 && (Memory.FillRAM [0x2209] & 0x40))
3431             S9xSetPCBase (Memory.FillRAM [0x220e] | 
3432                           (Memory.FillRAM [0x220f] << 8));
3433         else
3434             S9xSetPCBase (S9xGetWord (0xFFFE));
3435 #endif
3436 #ifdef VAR_CYCLES
3437         CPU.Cycles += ONE_CYCLE;
3438 #else
3439 #ifndef SA1_OPCODES
3440         CPU.Cycles += 6;
3441 #endif
3442 #endif
3443     }
3444 }
3445
3446 /**********************************************************************************************/
3447
3448 /* NMI *************************************************************************************** */
3449 void S9xOpcode_NMI ()
3450 {
3451 #ifdef DEBUGGER
3452     if (CPU.Flags & TRACE_FLAG)
3453         S9xTraceMessage ("*** NMI");
3454 #endif
3455     if (!CheckEmulation())
3456     {
3457         PUSHB (Registers.PB);
3458         PUSHW (CPU.PC - CPU.PCBase);
3459         S9xPackStatus ();
3460         PUSHB (Registers.PL);
3461         ClearDecimal ();
3462         SetIRQ ();
3463
3464         Registers.PB = 0;
3465         ICPU.ShiftedPB = 0;
3466 #ifdef SA1_OPCODES
3467         S9xSA1SetPCBase (Memory.FillRAM [0x2205] |
3468                          (Memory.FillRAM [0x2206] << 8));
3469 #else
3470         if (Settings.SA1 && (Memory.FillRAM [0x2209] & 0x20))
3471             S9xSetPCBase (Memory.FillRAM [0x220c] |
3472                           (Memory.FillRAM [0x220d] << 8));
3473         else
3474             S9xSetPCBase (S9xGetWord (0xFFEA));
3475 #endif
3476 #ifdef VAR_CYCLES
3477         CPU.Cycles += TWO_CYCLES;
3478 #else
3479 #ifndef SA1_OPCODES
3480         CPU.Cycles += 8;
3481 #endif
3482 #endif
3483     }
3484     else
3485     {
3486         PUSHW (CPU.PC - CPU.PCBase);
3487         S9xPackStatus ();
3488         PUSHB (Registers.PL);
3489         ClearDecimal ();
3490         SetIRQ ();
3491
3492         Registers.PB = 0;
3493         ICPU.ShiftedPB = 0;
3494 #ifdef SA1_OPCODES
3495         S9xSA1SetPCBase (Memory.FillRAM [0x2205] |
3496                          (Memory.FillRAM [0x2206] << 8));
3497 #else
3498         if (Settings.SA1 && (Memory.FillRAM [0x2209] & 0x20))
3499             S9xSetPCBase (Memory.FillRAM [0x220c] |
3500                           (Memory.FillRAM [0x220d] << 8));
3501         else
3502             S9xSetPCBase (S9xGetWord (0xFFFA));
3503 #endif
3504 #ifdef VAR_CYCLES
3505         CPU.Cycles += ONE_CYCLE;
3506 #else
3507 #ifndef SA1_OPCODES
3508         CPU.Cycles += 6;
3509 #endif
3510 #endif
3511     }
3512 }
3513 /**********************************************************************************************/
3514
3515 /* COP *************************************************************************************** */
3516 static void Op02 ()
3517 {
3518 #ifdef DEBUGGER
3519     if (CPU.Flags & TRACE_FLAG)
3520         S9xTraceMessage ("*** COP");
3521 #endif  
3522     if (!CheckEmulation())
3523     {
3524         PUSHB (Registers.PB);
3525         PUSHW (CPU.PC - CPU.PCBase + 1);
3526         S9xPackStatus ();
3527         PUSHB (Registers.PL);
3528         ClearDecimal ();
3529         SetIRQ ();
3530
3531         Registers.PB = 0;
3532         ICPU.ShiftedPB = 0;
3533         S9xSetPCBase (S9xGetWord (0xFFE4));
3534 #ifdef VAR_CYCLES
3535         CPU.Cycles += TWO_CYCLES;
3536 #else
3537 #ifndef SA1_OPCODES
3538         CPU.Cycles += 8;
3539 #endif
3540 #endif
3541     }
3542     else
3543     {
3544         PUSHW (CPU.PC - CPU.PCBase);
3545         S9xPackStatus ();
3546         PUSHB (Registers.PL);
3547         ClearDecimal ();
3548         SetIRQ ();
3549
3550         Registers.PB = 0;
3551         ICPU.ShiftedPB = 0;
3552         S9xSetPCBase (S9xGetWord (0xFFF4));
3553 #ifdef VAR_CYCLES
3554         CPU.Cycles += ONE_CYCLE;
3555 #else
3556 #ifndef SA1_OPCODES
3557         CPU.Cycles += 6;
3558 #endif
3559 #endif
3560     }
3561 }
3562 /**********************************************************************************************/
3563
3564 /* JML *************************************************************************************** */
3565 static void OpDC ()
3566 {
3567     long OpAddress = AbsoluteIndirectLong ();
3568     Registers.PB = (uint8) (OpAddress >> 16);
3569     ICPU.ShiftedPB = OpAddress & 0xff0000;
3570     S9xSetPCBase (OpAddress);
3571 #ifdef VAR_CYCLES
3572     CPU.Cycles += TWO_CYCLES;
3573 #endif
3574 }
3575
3576 static void Op5C ()
3577 {
3578     long OpAddress = AbsoluteLong ();
3579     Registers.PB = (uint8) (OpAddress >> 16);
3580     ICPU.ShiftedPB = OpAddress & 0xff0000;
3581     S9xSetPCBase (OpAddress);
3582 }
3583 /**********************************************************************************************/
3584
3585 /* JMP *************************************************************************************** */
3586 static void Op4C ()
3587 {
3588     long OpAddress = Absolute ();
3589     S9xSetPCBase (ICPU.ShiftedPB + (OpAddress & 0xffff));
3590 #if defined(CPU_SHUTDOWN) && defined(SA1_OPCODES)
3591     CPUShutdown();
3592 #endif
3593 }
3594
3595 static void Op6C ()
3596 {
3597     long OpAddress = AbsoluteIndirect ();
3598     S9xSetPCBase (ICPU.ShiftedPB + (OpAddress & 0xffff));
3599 }
3600
3601 static void Op7C ()
3602 {
3603     long OpAddress = AbsoluteIndexedIndirect ();
3604     S9xSetPCBase (ICPU.ShiftedPB + OpAddress);
3605 #ifdef VAR_CYCLES
3606     CPU.Cycles += ONE_CYCLE;
3607 #endif
3608 }
3609 /**********************************************************************************************/
3610
3611 /* JSL/RTL *********************************************************************************** */
3612 static void Op22 ()
3613 {
3614     long OpAddress = AbsoluteLong ();
3615     PUSHB (Registers.PB);
3616     PUSHW (CPU.PC - CPU.PCBase - 1);
3617     Registers.PB = (uint8) (OpAddress >> 16);
3618     ICPU.ShiftedPB = OpAddress & 0xff0000;
3619     S9xSetPCBase (OpAddress);
3620 }
3621
3622 static void Op6B ()
3623 {
3624     PullW (Registers.PC);
3625     PullB (Registers.PB);
3626     ICPU.ShiftedPB = (Registers.PB & 0xff) << 16;
3627     S9xSetPCBase (ICPU.ShiftedPB + ((Registers.PC + 1) & 0xffff));
3628 #ifdef VAR_CYCLES
3629     CPU.Cycles += TWO_CYCLES;
3630 #endif
3631 }
3632 /**********************************************************************************************/
3633
3634 /* JSR/RTS *********************************************************************************** */
3635 static void Op20 ()
3636 {
3637     long OpAddress = Absolute ();
3638     PUSHW (CPU.PC - CPU.PCBase - 1);
3639     S9xSetPCBase (ICPU.ShiftedPB + (OpAddress & 0xffff));
3640 #ifdef VAR_CYCLES
3641     CPU.Cycles += ONE_CYCLE;
3642 #endif
3643 }
3644
3645 static void OpFC ()
3646 {
3647     long OpAddress = AbsoluteIndexedIndirect ();
3648     PUSHW (CPU.PC - CPU.PCBase - 1);
3649     S9xSetPCBase (ICPU.ShiftedPB + OpAddress);
3650 #ifdef VAR_CYCLES
3651     CPU.Cycles += ONE_CYCLE;
3652 #endif
3653 }
3654
3655 static void Op60 ()
3656 {
3657     PullW (Registers.PC);
3658     S9xSetPCBase (ICPU.ShiftedPB + ((Registers.PC + 1) & 0xffff));
3659 #ifdef VAR_CYCLES
3660     CPU.Cycles += ONE_CYCLE * 3;
3661 #endif
3662 }
3663
3664 /**********************************************************************************************/
3665
3666 /* MVN/MVP *********************************************************************************** */
3667 static void Op54X1 ()
3668 {
3669     uint32 SrcBank;
3670
3671 #ifdef VAR_CYCLES
3672     CPU.Cycles += CPU.MemSpeedx2 + TWO_CYCLES;
3673 #endif
3674     
3675     Registers.DB = *CPU.PC++;
3676     ICPU.ShiftedDB = (Registers.DB & 0xff) << 16;
3677     SrcBank = *CPU.PC++;
3678
3679     S9xSetByte (S9xGetByte ((SrcBank << 16) + Registers.X.W),
3680              ICPU.ShiftedDB + Registers.Y.W);
3681
3682     Registers.XL++;
3683     Registers.YL++;
3684     Registers.A.W--;
3685     if (Registers.A.W != 0xffff)
3686         CPU.PC -= 3;
3687 }
3688
3689 static void Op54X0 ()
3690 {
3691     uint32 SrcBank;
3692
3693 #ifdef VAR_CYCLES
3694     CPU.Cycles += CPU.MemSpeedx2 + TWO_CYCLES;
3695 #endif
3696     
3697     Registers.DB = *CPU.PC++;
3698     ICPU.ShiftedDB = (Registers.DB & 0xff) << 16;
3699     SrcBank = *CPU.PC++;
3700
3701     S9xSetByte (S9xGetByte ((SrcBank << 16) + Registers.X.W),
3702              ICPU.ShiftedDB + Registers.Y.W);
3703
3704     Registers.X.W++;
3705     Registers.Y.W++;
3706     Registers.A.W--;
3707     if (Registers.A.W != 0xffff)
3708         CPU.PC -= 3;
3709 }
3710
3711 static void Op44X1 ()
3712 {
3713     uint32 SrcBank;
3714
3715 #ifdef VAR_CYCLES
3716     CPU.Cycles += CPU.MemSpeedx2 + TWO_CYCLES;
3717 #endif    
3718     Registers.DB = *CPU.PC++;
3719     ICPU.ShiftedDB = (Registers.DB & 0xff) << 16;
3720     SrcBank = *CPU.PC++;
3721     S9xSetByte (S9xGetByte ((SrcBank << 16) + Registers.X.W),
3722              ICPU.ShiftedDB + Registers.Y.W);
3723
3724     Registers.XL--;
3725     Registers.YL--;
3726     Registers.A.W--;
3727     if (Registers.A.W != 0xffff)
3728         CPU.PC -= 3;
3729 }
3730
3731 static void Op44X0 ()
3732 {
3733     uint32 SrcBank;
3734
3735 #ifdef VAR_CYCLES
3736     CPU.Cycles += CPU.MemSpeedx2 + TWO_CYCLES;
3737 #endif    
3738     Registers.DB = *CPU.PC++;
3739     ICPU.ShiftedDB = (Registers.DB & 0xff) << 16;
3740     SrcBank = *CPU.PC++;
3741     S9xSetByte (S9xGetByte ((SrcBank << 16) + Registers.X.W),
3742              ICPU.ShiftedDB + Registers.Y.W);
3743
3744     Registers.X.W--;
3745     Registers.Y.W--;
3746     Registers.A.W--;
3747     if (Registers.A.W != 0xffff)
3748         CPU.PC -= 3;
3749 }
3750
3751 /**********************************************************************************************/
3752
3753 /* REP/SEP *********************************************************************************** */
3754 static void OpC2 ()
3755 {
3756     uint8 Work8 = ~*CPU.PC++;
3757     Registers.PL &= Work8;
3758     ICPU._Carry &= Work8;
3759     ICPU._Overflow &= (Work8 >> 6);
3760     ICPU._Negative &= Work8;
3761     ICPU._Zero |= ~Work8 & Zero;
3762
3763 #ifdef VAR_CYCLES
3764     CPU.Cycles += CPU.MemSpeed + ONE_CYCLE;
3765 #endif
3766     if (CheckEmulation())
3767     {
3768         SetFlags(MemoryFlag | IndexFlag);
3769         missing.emulate6502 = 1;
3770     }
3771     if (CheckIndex ())
3772     {
3773         Registers.XH = 0;
3774         Registers.YH = 0;
3775     }
3776     S9xFixCycles();
3777 /*    CHECK_FOR_IRQ(); */
3778 }
3779
3780 static void OpE2 ()
3781 {
3782     uint8 Work8 = *CPU.PC++;
3783     Registers.PL |= Work8;
3784     ICPU._Carry |= Work8 & 1;
3785     ICPU._Overflow |= (Work8 >> 6) & 1;
3786     ICPU._Negative |= Work8;
3787     if (Work8 & Zero)
3788         ICPU._Zero = 0;
3789 #ifdef VAR_CYCLES
3790     CPU.Cycles += CPU.MemSpeed + ONE_CYCLE;
3791 #endif
3792     if (CheckEmulation())
3793     {
3794         SetFlags(MemoryFlag | IndexFlag);
3795         missing.emulate6502 = 1;
3796     }
3797     if (CheckIndex ())
3798     {
3799         Registers.XH = 0;
3800         Registers.YH = 0;
3801     }
3802     S9xFixCycles();
3803 }
3804 /**********************************************************************************************/
3805
3806 /* XBA *************************************************************************************** */
3807 static void OpEB ()
3808 {
3809     uint8 Work8 = Registers.AL;
3810     Registers.AL = Registers.AH;
3811     Registers.AH = Work8;
3812
3813     SETZN8 (Registers.AL);
3814 #ifdef VAR_CYCLES
3815     CPU.Cycles += TWO_CYCLES;
3816 #endif
3817 }
3818 /**********************************************************************************************/
3819
3820 /* RTI *************************************************************************************** */
3821 static void Op40 ()
3822 {
3823     PullB (Registers.PL);
3824     S9xUnpackStatus ();
3825     PullW (Registers.PC);
3826     if (!CheckEmulation())
3827     {
3828         PullB (Registers.PB);
3829         ICPU.ShiftedPB = (Registers.PB & 0xff) << 16;
3830     }
3831     else
3832     {
3833         SetFlags (MemoryFlag | IndexFlag);
3834         missing.emulate6502 = 1;
3835     }
3836     S9xSetPCBase (ICPU.ShiftedPB + Registers.PC);
3837     
3838     if (CheckIndex ())
3839     {
3840         Registers.XH = 0;
3841         Registers.YH = 0;
3842     }
3843 #ifdef VAR_CYCLES
3844     CPU.Cycles += TWO_CYCLES;
3845 #endif
3846     S9xFixCycles();
3847 /*    CHECK_FOR_IRQ(); */
3848 }
3849
3850 /**********************************************************************************************/
3851
3852 /* STP/WAI/DB ******************************************************************************** */
3853 // WAI
3854 static void OpCB ()
3855 {
3856     if (CPU.IRQActive)
3857     {
3858 #ifdef VAR_CYCLES
3859         CPU.Cycles += TWO_CYCLES;
3860 #else
3861 #ifndef SA1_OPCODES
3862         CPU.Cycles += 2;
3863 #endif
3864 #endif
3865     }
3866     else
3867     {
3868         CPU.WaitingForInterrupt = TRUE;
3869         CPU.PC--;
3870 #ifdef CPU_SHUTDOWN
3871 #ifndef SA1_OPCODES
3872         if (Settings.Shutdown)
3873         {
3874                 ApuSync();
3875         }
3876 #else
3877         if (Settings.Shutdown)
3878         {
3879             SA1.CPUExecuting = FALSE;
3880             SA1.Executing = FALSE;
3881         }
3882 #endif
3883 #endif
3884     }
3885 }
3886
3887 // STP
3888 static void OpDB ()
3889 {
3890     CPU.PC--;
3891     CPU.Flags |= DEBUG_MODE_FLAG;
3892 }
3893
3894 // Reserved S9xOpcode
3895 static void Op42 ()
3896 {
3897 #if defined(CPU_SHUTDOWN) && !defined(SA1_OPCODES)
3898
3899         CPU.WaitAddress = NULL;
3900         if (Settings.SA1) S9xSA1ExecuteDuringSleep ();
3901
3902         ApuSync();\r\r#ifdef VAR_CYCLES
3903         CPU.Cycles += CPU.MemSpeed;
3904 #endif
3905
3906         //relative
3907         int8 b = *CPU.PC;
3908         CPU.PC++;
3909
3910         int8 BranchOffset = ((b & 0xF) | 0xF0);
3911         uint16 OpAddress = (int)(CPU.PC - CPU.PCBase) + BranchOffset;
3912
3913         // Assume we're going to branch
3914 #ifdef VAR_CYCLES
3915         CPU.Cycles += ONE_CYCLE;
3916 #else
3917         CPU.Cycles++;
3918 #endif
3919
3920         switch (b >> 4) {
3921         case 0x1: //BPL
3922                 BranchCheck1 ();
3923                 if (!CheckNegative ()) {
3924                         CPU.PC = CPU.PCBase + OpAddress;
3925 #                       ifdef VAR_CYCLES
3926                                 CPU.Cycles += ONE_CYCLE;
3927 #                       else
3928                                 CPU.Cycles++;
3929 #                       endif
3930                         CPUShutdown ();
3931                 }
3932                 return;
3933         case 0x3: //BMI
3934                 BranchCheck1 ();
3935                 if (CheckNegative ()) {
3936                         CPU.PC = CPU.PCBase + OpAddress;
3937 #                       ifdef VAR_CYCLES
3938                                 CPU.Cycles += ONE_CYCLE;
3939 #                       else
3940                                 CPU.Cycles++;
3941 #                       endif
3942                         CPUShutdown ();
3943                 }
3944                 return;
3945         case 0x5: //BVC
3946                 BranchCheck0 ();
3947                 if (!CheckOverflow ()) {
3948                         CPU.PC = CPU.PCBase + OpAddress;
3949 #                       ifdef VAR_CYCLES
3950                                 CPU.Cycles += ONE_CYCLE;
3951 #                       else
3952                                 CPU.Cycles++;
3953 #                       endif
3954                         CPUShutdown ();
3955                 }
3956                 return;
3957         case 0x7: //BVS
3958                 BranchCheck0 ();
3959                 if (CheckOverflow ()) {
3960                                 CPU.PC = CPU.PCBase + OpAddress;
3961 #                       ifdef VAR_CYCLES
3962                                 CPU.Cycles += ONE_CYCLE;
3963 #                       else
3964                                 CPU.Cycles++;
3965 #                       endif
3966                         CPUShutdown ();
3967                         }
3968                 return;
3969         case 0x8: //BRA
3970                 CPU.PC = CPU.PCBase + OpAddress;
3971 #               ifdef VAR_CYCLES
3972                         CPU.Cycles += ONE_CYCLE;
3973 #               else
3974                         CPU.Cycles++;
3975 #               endif
3976                 CPUShutdown ();
3977                 return;
3978         case 0x9: //BCC
3979                 BranchCheck0 ();
3980             if (!CheckCarry ()) {
3981                         CPU.PC = CPU.PCBase + OpAddress;
3982 #                       ifdef VAR_CYCLES
3983                                 CPU.Cycles += ONE_CYCLE;
3984 #                       else
3985                                 CPU.Cycles++;
3986 #                       endif
3987                         CPUShutdown ();
3988                 }
3989                 return;
3990         case 0xB: //BCS
3991                 BranchCheck0 ();
3992                 if (CheckCarry ()) {
3993                         CPU.PC = CPU.PCBase + OpAddress;
3994 #                       ifdef VAR_CYCLES
3995                                 CPU.Cycles += ONE_CYCLE;
3996 #                       else
3997                                 CPU.Cycles++;
3998 #                       endif
3999                         CPUShutdown ();
4000                 }
4001                 return;
4002         case 0xD: //BNE
4003                 BranchCheck1 ();
4004                 if (!CheckZero ()) {
4005                         CPU.PC = CPU.PCBase + OpAddress;
4006 #                       ifdef VAR_CYCLES
4007                         CPU.Cycles += ONE_CYCLE;
4008 #                       else
4009                                 CPU.Cycles++;
4010 #                       endif
4011                         CPUShutdown ();
4012                 }
4013                 return;
4014         case 0xF: //BEQ
4015                 BranchCheck2 ();
4016                 if (CheckZero ()) {
4017                         CPU.PC = CPU.PCBase + OpAddress;
4018 #                       ifdef VAR_CYCLES
4019                                 CPU.Cycles += ONE_CYCLE;
4020 #                       else
4021                                 CPU.Cycles++;
4022 #                       endif
4023                         CPUShutdown ();
4024                         }
4025                 return;
4026 #ifdef DEBUG
4027         default:
4028                 printf("Invalid Op42 branch type %hx\n", b >> 4);
4029                 return;
4030 #endif
4031         }
4032 #endif
4033 }
4034
4035 /**********************************************************************************************/
4036
4037 /**********************************************************************************************/
4038 /* CPU-S9xOpcodes Definitions                                                                    */
4039 /**********************************************************************************************/
4040 struct SOpcodes S9xOpcodesM1X1[256] =
4041 {
4042     {Op00},      {Op01M1},    {Op02},      {Op03M1},    {Op04M1},
4043     {Op05M1},    {Op06M1},    {Op07M1},    {Op08},      {Op09M1},
4044     {Op0AM1},    {Op0B},      {Op0CM1},    {Op0DM1},    {Op0EM1},
4045     {Op0FM1},    {Op10},      {Op11M1},    {Op12M1},    {Op13M1},
4046     {Op14M1},    {Op15M1},    {Op16M1},    {Op17M1},    {Op18},
4047     {Op19M1},    {Op1AM1},    {Op1B},      {Op1CM1},    {Op1DM1},
4048     {Op1EM1},    {Op1FM1},    {Op20},      {Op21M1},    {Op22},
4049     {Op23M1},    {Op24M1},    {Op25M1},    {Op26M1},    {Op27M1},
4050     {Op28},      {Op29M1},    {Op2AM1},    {Op2B},      {Op2CM1},
4051     {Op2DM1},    {Op2EM1},    {Op2FM1},    {Op30},      {Op31M1},
4052     {Op32M1},    {Op33M1},    {Op34M1},    {Op35M1},    {Op36M1},
4053     {Op37M1},    {Op38},      {Op39M1},    {Op3AM1},    {Op3B},
4054     {Op3CM1},    {Op3DM1},    {Op3EM1},    {Op3FM1},    {Op40},
4055     {Op41M1},    {Op42},      {Op43M1},    {Op44X1},    {Op45M1},
4056     {Op46M1},    {Op47M1},    {Op48M1},    {Op49M1},    {Op4AM1},
4057     {Op4B},      {Op4C},      {Op4DM1},    {Op4EM1},    {Op4FM1},
4058     {Op50},      {Op51M1},    {Op52M1},    {Op53M1},    {Op54X1},
4059     {Op55M1},    {Op56M1},    {Op57M1},    {Op58},      {Op59M1},
4060     {Op5AX1},    {Op5B},      {Op5C},      {Op5DM1},    {Op5EM1},
4061     {Op5FM1},    {Op60},      {Op61M1},    {Op62},      {Op63M1},
4062     {Op64M1},    {Op65M1},    {Op66M1},    {Op67M1},    {Op68M1},
4063     {Op69M1},    {Op6AM1},    {Op6B},      {Op6C},      {Op6DM1},
4064     {Op6EM1},    {Op6FM1},    {Op70},      {Op71M1},    {Op72M1},
4065     {Op73M1},    {Op74M1},    {Op75M1},    {Op76M1},    {Op77M1},
4066     {Op78},      {Op79M1},    {Op7AX1},    {Op7B},      {Op7C},
4067     {Op7DM1},    {Op7EM1},    {Op7FM1},    {Op80},      {Op81M1},
4068     {Op82},      {Op83M1},    {Op84X1},    {Op85M1},    {Op86X1},
4069     {Op87M1},    {Op88X1},    {Op89M1},    {Op8AM1},    {Op8B},
4070     {Op8CX1},    {Op8DM1},    {Op8EX1},    {Op8FM1},    {Op90},
4071     {Op91M1},    {Op92M1},    {Op93M1},    {Op94X1},    {Op95M1},
4072     {Op96X1},    {Op97M1},    {Op98M1},    {Op99M1},    {Op9A},
4073     {Op9BX1},    {Op9CM1},    {Op9DM1},    {Op9EM1},    {Op9FM1},
4074     {OpA0X1},    {OpA1M1},    {OpA2X1},    {OpA3M1},    {OpA4X1},
4075     {OpA5M1},    {OpA6X1},    {OpA7M1},    {OpA8X1},    {OpA9M1},
4076     {OpAAX1},    {OpAB},      {OpACX1},    {OpADM1},    {OpAEX1},
4077     {OpAFM1},    {OpB0},      {OpB1M1},    {OpB2M1},    {OpB3M1},
4078     {OpB4X1},    {OpB5M1},    {OpB6X1},    {OpB7M1},    {OpB8},
4079     {OpB9M1},    {OpBAX1},    {OpBBX1},    {OpBCX1},    {OpBDM1},
4080     {OpBEX1},    {OpBFM1},    {OpC0X1},    {OpC1M1},    {OpC2},
4081     {OpC3M1},    {OpC4X1},    {OpC5M1},    {OpC6M1},    {OpC7M1},
4082     {OpC8X1},    {OpC9M1},    {OpCAX1},    {OpCB},      {OpCCX1},
4083     {OpCDM1},    {OpCEM1},    {OpCFM1},    {OpD0},      {OpD1M1},
4084     {OpD2M1},    {OpD3M1},    {OpD4},      {OpD5M1},    {OpD6M1},
4085     {OpD7M1},    {OpD8},      {OpD9M1},    {OpDAX1},    {OpDB},
4086     {OpDC},      {OpDDM1},    {OpDEM1},    {OpDFM1},    {OpE0X1},
4087     {OpE1M1},    {OpE2},      {OpE3M1},    {OpE4X1},    {OpE5M1},
4088     {OpE6M1},    {OpE7M1},    {OpE8X1},    {OpE9M1},    {OpEA},
4089     {OpEB},      {OpECX1},    {OpEDM1},    {OpEEM1},    {OpEFM1},
4090     {OpF0},      {OpF1M1},    {OpF2M1},    {OpF3M1},    {OpF4},
4091     {OpF5M1},    {OpF6M1},    {OpF7M1},    {OpF8},      {OpF9M1},
4092     {OpFAX1},    {OpFB},      {OpFC},      {OpFDM1},    {OpFEM1},
4093     {OpFFM1}
4094 };
4095
4096 struct SOpcodes S9xOpcodesM1X0[256] =
4097 {
4098     {Op00},      {Op01M1},    {Op02},      {Op03M1},    {Op04M1},
4099     {Op05M1},    {Op06M1},    {Op07M1},    {Op08},      {Op09M1},
4100     {Op0AM1},    {Op0B},      {Op0CM1},    {Op0DM1},    {Op0EM1},
4101     {Op0FM1},    {Op10},      {Op11M1},    {Op12M1},    {Op13M1},
4102     {Op14M1},    {Op15M1},    {Op16M1},    {Op17M1},    {Op18},
4103     {Op19M1},    {Op1AM1},    {Op1B},      {Op1CM1},    {Op1DM1},
4104     {Op1EM1},    {Op1FM1},    {Op20},      {Op21M1},    {Op22},
4105     {Op23M1},    {Op24M1},    {Op25M1},    {Op26M1},    {Op27M1},
4106     {Op28},      {Op29M1},    {Op2AM1},    {Op2B},      {Op2CM1},
4107     {Op2DM1},    {Op2EM1},    {Op2FM1},    {Op30},      {Op31M1},
4108     {Op32M1},    {Op33M1},    {Op34M1},    {Op35M1},    {Op36M1},
4109     {Op37M1},    {Op38},      {Op39M1},    {Op3AM1},    {Op3B},
4110     {Op3CM1},    {Op3DM1},    {Op3EM1},    {Op3FM1},    {Op40},
4111     {Op41M1},    {Op42},      {Op43M1},    {Op44X0},    {Op45M1},
4112     {Op46M1},    {Op47M1},    {Op48M1},    {Op49M1},    {Op4AM1},
4113     {Op4B},      {Op4C},      {Op4DM1},    {Op4EM1},    {Op4FM1},
4114     {Op50},      {Op51M1},    {Op52M1},    {Op53M1},    {Op54X0},
4115     {Op55M1},    {Op56M1},    {Op57M1},    {Op58},      {Op59M1},
4116     {Op5AX0},    {Op5B},      {Op5C},      {Op5DM1},    {Op5EM1},
4117     {Op5FM1},    {Op60},      {Op61M1},    {Op62},      {Op63M1},
4118     {Op64M1},    {Op65M1},    {Op66M1},    {Op67M1},    {Op68M1},
4119     {Op69M1},    {Op6AM1},    {Op6B},      {Op6C},      {Op6DM1},
4120     {Op6EM1},    {Op6FM1},    {Op70},      {Op71M1},    {Op72M1},
4121     {Op73M1},    {Op74M1},    {Op75M1},    {Op76M1},    {Op77M1},
4122     {Op78},      {Op79M1},    {Op7AX0},    {Op7B},      {Op7C},
4123     {Op7DM1},    {Op7EM1},    {Op7FM1},    {Op80},      {Op81M1},
4124     {Op82},      {Op83M1},    {Op84X0},    {Op85M1},    {Op86X0},
4125     {Op87M1},    {Op88X0},    {Op89M1},    {Op8AM1},    {Op8B},
4126     {Op8CX0},    {Op8DM1},    {Op8EX0},    {Op8FM1},    {Op90},
4127     {Op91M1},    {Op92M1},    {Op93M1},    {Op94X0},    {Op95M1},
4128     {Op96X0},    {Op97M1},    {Op98M1},    {Op99M1},    {Op9A},
4129     {Op9BX0},    {Op9CM1},    {Op9DM1},    {Op9EM1},    {Op9FM1},
4130     {OpA0X0},    {OpA1M1},    {OpA2X0},    {OpA3M1},    {OpA4X0},
4131     {OpA5M1},    {OpA6X0},    {OpA7M1},    {OpA8X0},    {OpA9M1},
4132     {OpAAX0},    {OpAB},      {OpACX0},    {OpADM1},    {OpAEX0},
4133     {OpAFM1},    {OpB0},      {OpB1M1},    {OpB2M1},    {OpB3M1},
4134     {OpB4X0},    {OpB5M1},    {OpB6X0},    {OpB7M1},    {OpB8},
4135     {OpB9M1},    {OpBAX0},    {OpBBX0},    {OpBCX0},    {OpBDM1},
4136     {OpBEX0},    {OpBFM1},    {OpC0X0},    {OpC1M1},    {OpC2},
4137     {OpC3M1},    {OpC4X0},    {OpC5M1},    {OpC6M1},    {OpC7M1},
4138     {OpC8X0},    {OpC9M1},    {OpCAX0},    {OpCB},      {OpCCX0},
4139     {OpCDM1},    {OpCEM1},    {OpCFM1},    {OpD0},      {OpD1M1},
4140     {OpD2M1},    {OpD3M1},    {OpD4},      {OpD5M1},    {OpD6M1},
4141     {OpD7M1},    {OpD8},      {OpD9M1},    {OpDAX0},    {OpDB},
4142     {OpDC},      {OpDDM1},    {OpDEM1},    {OpDFM1},    {OpE0X0},
4143     {OpE1M1},    {OpE2},      {OpE3M1},    {OpE4X0},    {OpE5M1},
4144     {OpE6M1},    {OpE7M1},    {OpE8X0},    {OpE9M1},    {OpEA},
4145     {OpEB},      {OpECX0},    {OpEDM1},    {OpEEM1},    {OpEFM1},
4146     {OpF0},      {OpF1M1},    {OpF2M1},    {OpF3M1},    {OpF4},
4147     {OpF5M1},    {OpF6M1},    {OpF7M1},    {OpF8},      {OpF9M1},
4148     {OpFAX0},    {OpFB},      {OpFC},      {OpFDM1},    {OpFEM1},
4149     {OpFFM1}
4150 };
4151
4152 struct SOpcodes S9xOpcodesM0X0[256] =
4153 {
4154     {Op00},      {Op01M0},    {Op02},      {Op03M0},    {Op04M0},
4155     {Op05M0},    {Op06M0},    {Op07M0},    {Op08},      {Op09M0},
4156     {Op0AM0},    {Op0B},      {Op0CM0},    {Op0DM0},    {Op0EM0},
4157     {Op0FM0},    {Op10},      {Op11M0},    {Op12M0},    {Op13M0},
4158     {Op14M0},    {Op15M0},    {Op16M0},    {Op17M0},    {Op18},
4159     {Op19M0},    {Op1AM0},    {Op1B},      {Op1CM0},    {Op1DM0},
4160     {Op1EM0},    {Op1FM0},    {Op20},      {Op21M0},    {Op22},
4161     {Op23M0},    {Op24M0},    {Op25M0},    {Op26M0},    {Op27M0},
4162     {Op28},      {Op29M0},    {Op2AM0},    {Op2B},      {Op2CM0},
4163     {Op2DM0},    {Op2EM0},    {Op2FM0},    {Op30},      {Op31M0},
4164     {Op32M0},    {Op33M0},    {Op34M0},    {Op35M0},    {Op36M0},
4165     {Op37M0},    {Op38},      {Op39M0},    {Op3AM0},    {Op3B},
4166     {Op3CM0},    {Op3DM0},    {Op3EM0},    {Op3FM0},    {Op40},
4167     {Op41M0},    {Op42},      {Op43M0},    {Op44X0},    {Op45M0},
4168     {Op46M0},    {Op47M0},    {Op48M0},    {Op49M0},    {Op4AM0},
4169     {Op4B},      {Op4C},      {Op4DM0},    {Op4EM0},    {Op4FM0},
4170     {Op50},      {Op51M0},    {Op52M0},    {Op53M0},    {Op54X0},
4171     {Op55M0},    {Op56M0},    {Op57M0},    {Op58},      {Op59M0},
4172     {Op5AX0},    {Op5B},      {Op5C},      {Op5DM0},    {Op5EM0},
4173     {Op5FM0},    {Op60},      {Op61M0},    {Op62},      {Op63M0},
4174     {Op64M0},    {Op65M0},    {Op66M0},    {Op67M0},    {Op68M0},
4175     {Op69M0},    {Op6AM0},    {Op6B},      {Op6C},      {Op6DM0},
4176     {Op6EM0},    {Op6FM0},    {Op70},      {Op71M0},    {Op72M0},
4177     {Op73M0},    {Op74M0},    {Op75M0},    {Op76M0},    {Op77M0},
4178     {Op78},      {Op79M0},    {Op7AX0},    {Op7B},      {Op7C},
4179     {Op7DM0},    {Op7EM0},    {Op7FM0},    {Op80},      {Op81M0},
4180     {Op82},      {Op83M0},    {Op84X0},    {Op85M0},    {Op86X0},
4181     {Op87M0},    {Op88X0},    {Op89M0},    {Op8AM0},    {Op8B},
4182     {Op8CX0},    {Op8DM0},    {Op8EX0},    {Op8FM0},    {Op90},
4183     {Op91M0},    {Op92M0},    {Op93M0},    {Op94X0},    {Op95M0},
4184     {Op96X0},    {Op97M0},    {Op98M0},    {Op99M0},    {Op9A},
4185     {Op9BX0},    {Op9CM0},    {Op9DM0},    {Op9EM0},    {Op9FM0},
4186     {OpA0X0},    {OpA1M0},    {OpA2X0},    {OpA3M0},    {OpA4X0},
4187     {OpA5M0},    {OpA6X0},    {OpA7M0},    {OpA8X0},    {OpA9M0},
4188     {OpAAX0},    {OpAB},      {OpACX0},    {OpADM0},    {OpAEX0},
4189     {OpAFM0},    {OpB0},      {OpB1M0},    {OpB2M0},    {OpB3M0},
4190     {OpB4X0},    {OpB5M0},    {OpB6X0},    {OpB7M0},    {OpB8},
4191     {OpB9M0},    {OpBAX0},    {OpBBX0},    {OpBCX0},    {OpBDM0},
4192     {OpBEX0},    {OpBFM0},    {OpC0X0},    {OpC1M0},    {OpC2},
4193     {OpC3M0},    {OpC4X0},    {OpC5M0},    {OpC6M0},    {OpC7M0},
4194     {OpC8X0},    {OpC9M0},    {OpCAX0},    {OpCB},      {OpCCX0},
4195     {OpCDM0},    {OpCEM0},    {OpCFM0},    {OpD0},      {OpD1M0},
4196     {OpD2M0},    {OpD3M0},    {OpD4},      {OpD5M0},    {OpD6M0},
4197     {OpD7M0},    {OpD8},      {OpD9M0},    {OpDAX0},    {OpDB},
4198     {OpDC},      {OpDDM0},    {OpDEM0},    {OpDFM0},    {OpE0X0},
4199     {OpE1M0},    {OpE2},      {OpE3M0},    {OpE4X0},    {OpE5M0},
4200     {OpE6M0},    {OpE7M0},    {OpE8X0},    {OpE9M0},    {OpEA},
4201     {OpEB},      {OpECX0},    {OpEDM0},    {OpEEM0},    {OpEFM0},
4202     {OpF0},      {OpF1M0},    {OpF2M0},    {OpF3M0},    {OpF4},
4203     {OpF5M0},    {OpF6M0},    {OpF7M0},    {OpF8},      {OpF9M0},
4204     {OpFAX0},    {OpFB},      {OpFC},      {OpFDM0},    {OpFEM0},
4205     {OpFFM0}
4206 };
4207
4208 struct SOpcodes S9xOpcodesM0X1[256] =
4209 {
4210     {Op00},      {Op01M0},    {Op02},      {Op03M0},    {Op04M0},
4211     {Op05M0},    {Op06M0},    {Op07M0},    {Op08},      {Op09M0},
4212     {Op0AM0},    {Op0B},      {Op0CM0},    {Op0DM0},    {Op0EM0},
4213     {Op0FM0},    {Op10},      {Op11M0},    {Op12M0},    {Op13M0},
4214     {Op14M0},    {Op15M0},    {Op16M0},    {Op17M0},    {Op18},
4215     {Op19M0},    {Op1AM0},    {Op1B},      {Op1CM0},    {Op1DM0},
4216     {Op1EM0},    {Op1FM0},    {Op20},      {Op21M0},    {Op22},
4217     {Op23M0},    {Op24M0},    {Op25M0},    {Op26M0},    {Op27M0},
4218     {Op28},      {Op29M0},    {Op2AM0},    {Op2B},      {Op2CM0},
4219     {Op2DM0},    {Op2EM0},    {Op2FM0},    {Op30},      {Op31M0},
4220     {Op32M0},    {Op33M0},    {Op34M0},    {Op35M0},    {Op36M0},
4221     {Op37M0},    {Op38},      {Op39M0},    {Op3AM0},    {Op3B},
4222     {Op3CM0},    {Op3DM0},    {Op3EM0},    {Op3FM0},    {Op40},
4223     {Op41M0},    {Op42},      {Op43M0},    {Op44X1},    {Op45M0},
4224     {Op46M0},    {Op47M0},    {Op48M0},    {Op49M0},    {Op4AM0},
4225     {Op4B},      {Op4C},      {Op4DM0},    {Op4EM0},    {Op4FM0},
4226     {Op50},      {Op51M0},    {Op52M0},    {Op53M0},    {Op54X1},
4227     {Op55M0},    {Op56M0},    {Op57M0},    {Op58},      {Op59M0},
4228     {Op5AX1},    {Op5B},      {Op5C},      {Op5DM0},    {Op5EM0},
4229     {Op5FM0},    {Op60},      {Op61M0},    {Op62},      {Op63M0},
4230     {Op64M0},    {Op65M0},    {Op66M0},    {Op67M0},    {Op68M0},
4231     {Op69M0},    {Op6AM0},    {Op6B},      {Op6C},      {Op6DM0},
4232     {Op6EM0},    {Op6FM0},    {Op70},      {Op71M0},    {Op72M0},
4233     {Op73M0},    {Op74M0},    {Op75M0},    {Op76M0},    {Op77M0},
4234     {Op78},      {Op79M0},    {Op7AX1},    {Op7B},      {Op7C},
4235     {Op7DM0},    {Op7EM0},    {Op7FM0},    {Op80},      {Op81M0},
4236     {Op82},      {Op83M0},    {Op84X1},    {Op85M0},    {Op86X1},
4237     {Op87M0},    {Op88X1},    {Op89M0},    {Op8AM0},    {Op8B},
4238     {Op8CX1},    {Op8DM0},    {Op8EX1},    {Op8FM0},    {Op90},
4239     {Op91M0},    {Op92M0},    {Op93M0},    {Op94X1},    {Op95M0},
4240     {Op96X1},    {Op97M0},    {Op98M0},    {Op99M0},    {Op9A},
4241     {Op9BX1},    {Op9CM0},    {Op9DM0},    {Op9EM0},    {Op9FM0},
4242     {OpA0X1},    {OpA1M0},    {OpA2X1},    {OpA3M0},    {OpA4X1},
4243     {OpA5M0},    {OpA6X1},    {OpA7M0},    {OpA8X1},    {OpA9M0},
4244     {OpAAX1},    {OpAB},      {OpACX1},    {OpADM0},    {OpAEX1},
4245     {OpAFM0},    {OpB0},      {OpB1M0},    {OpB2M0},    {OpB3M0},
4246     {OpB4X1},    {OpB5M0},    {OpB6X1},    {OpB7M0},    {OpB8},
4247     {OpB9M0},    {OpBAX1},    {OpBBX1},    {OpBCX1},    {OpBDM0},
4248     {OpBEX1},    {OpBFM0},    {OpC0X1},    {OpC1M0},    {OpC2},
4249     {OpC3M0},    {OpC4X1},    {OpC5M0},    {OpC6M0},    {OpC7M0},
4250     {OpC8X1},    {OpC9M0},    {OpCAX1},    {OpCB},      {OpCCX1},
4251     {OpCDM0},    {OpCEM0},    {OpCFM0},    {OpD0},      {OpD1M0},
4252     {OpD2M0},    {OpD3M0},    {OpD4},      {OpD5M0},    {OpD6M0},
4253     {OpD7M0},    {OpD8},      {OpD9M0},    {OpDAX1},    {OpDB},
4254     {OpDC},      {OpDDM0},    {OpDEM0},    {OpDFM0},    {OpE0X1},
4255     {OpE1M0},    {OpE2},      {OpE3M0},    {OpE4X1},    {OpE5M0},
4256     {OpE6M0},    {OpE7M0},    {OpE8X1},    {OpE9M0},    {OpEA},
4257     {OpEB},      {OpECX1},    {OpEDM0},    {OpEEM0},    {OpEFM0},
4258     {OpF0},      {OpF1M0},    {OpF2M0},    {OpF3M0},    {OpF4},
4259     {OpF5M0},    {OpF6M0},    {OpF7M0},    {OpF8},      {OpF9M0},
4260     {OpFAX1},    {OpFB},      {OpFC},      {OpFDM0},    {OpFEM0},
4261     {OpFFM0}
4262 };
4263