more properly handling new haa semantics
[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 if (Settings.SoundSkipMethod == 1) {\
2466                         return;\
2467                 } else if (Settings.SoundSkipMethod == 3) {\
2468                         if( CPU.PC - CPU.PCBase > OpAddress)\
2469                             return;\
2470                         else\
2471                                 CPU.PC = CPU.PCBase + OpAddress;\
2472                 }\
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 if (Settings.SoundSkipMethod == 1) {\
2483                         CPU.PC = CPU.PCBase + OpAddress;\
2484                 } else if (Settings.SoundSkipMethod == 3) {\
2485                         if (CPU.PC - CPU.PCBase > OpAddress)\
2486                             return;\
2487                         else\
2488                                 CPU.PC = CPU.PCBase + OpAddress;\
2489                 }\
2490     }
2491
2492 #else
2493 #define BranchCheck0()
2494 #define BranchCheck1()
2495 #define BranchCheck2()
2496 #endif
2497
2498 #ifdef CPU_SHUTDOWN
2499 #ifndef SA1_OPCODES
2500 INLINE void CPUShutdown()
2501 {
2502     if (Settings.Shutdown && CPU.PC == CPU.WaitAddress)
2503     {
2504         // Don't skip cycles with a pending NMI or IRQ - could cause delayed
2505         // interrupt. Interrupts are delayed for a few cycles alreadybut
2506         // the delay could allow the shutdown code to cycle skip again.
2507         // Was causing screen flashing on Top Gear 3000.
2508
2509         if (CPU.WaitCounter == 0 && 
2510             !(CPU.Flags & (IRQ_PENDING_FLAG | NMI_FLAG)))
2511         {
2512             CPU.WaitAddress = NULL;
2513 #ifdef USE_SA1
2514             if (Settings.SA1) {
2515                 S9xSA1ExecuteDuringSleep ();
2516             }
2517 #endif
2518             ApuSync();
2519         }
2520         else
2521         if (CPU.WaitCounter >= 2)
2522             CPU.WaitCounter = 1;
2523         else
2524             CPU.WaitCounter--;
2525     }
2526 }
2527 #else
2528 INLINE void CPUShutdown()
2529 {
2530     if (Settings.Shutdown && CPU.PC == CPU.WaitAddress)
2531     {
2532         if (CPU.WaitCounter >= 1)
2533         {
2534             SA1.Executing = FALSE;
2535             SA1.CPUExecuting = FALSE;
2536         }
2537         else
2538             CPU.WaitCounter++;
2539     }
2540 }
2541 #endif
2542 #else
2543 #define CPUShutdown()
2544 #endif
2545
2546 /* BCC */
2547 static void Op90 ()
2548 {
2549     long OpAddress = Relative ();
2550     BranchCheck0 ();
2551     if (!CheckCarry())
2552     {
2553         CPU.PC = CPU.PCBase + OpAddress;
2554 #ifdef VAR_CYCLES
2555         CPU.Cycles += ONE_CYCLE;
2556 #else
2557 #ifndef SA1_OPCODES
2558         CPU.Cycles++;
2559 #endif
2560 #endif
2561         CPUShutdown();
2562     }
2563 }
2564
2565 /* BCS */
2566 static void OpB0 ()
2567 {
2568     long OpAddress = Relative ();
2569     BranchCheck0 ();
2570     if (CheckCarry())
2571     {
2572         CPU.PC = CPU.PCBase + OpAddress;
2573 #ifdef VAR_CYCLES
2574         CPU.Cycles += ONE_CYCLE;
2575 #else
2576 #ifndef SA1_OPCODES
2577         CPU.Cycles++;
2578 #endif
2579 #endif
2580         CPUShutdown();
2581     }
2582 }
2583
2584 /* BEQ */
2585 static void OpF0 ()
2586 {
2587     long OpAddress = Relative ();
2588     BranchCheck2 ();
2589     if (CheckZero())
2590     {
2591         CPU.PC = CPU.PCBase + OpAddress;
2592 #ifdef VAR_CYCLES
2593         CPU.Cycles += ONE_CYCLE;
2594 #else
2595 #ifndef SA1_OPCODES
2596         CPU.Cycles++;
2597 #endif
2598 #endif
2599         CPUShutdown();
2600     }
2601 }
2602
2603 /* BMI */
2604 static void Op30 ()
2605 {
2606     long OpAddress = Relative ();
2607     BranchCheck1 ();
2608     if (CheckNegative())
2609     {
2610         CPU.PC = CPU.PCBase + OpAddress;
2611 #ifdef VAR_CYCLES
2612         CPU.Cycles += ONE_CYCLE;
2613 #else
2614 #ifndef SA1_OPCODES
2615         CPU.Cycles++;
2616 #endif
2617 #endif
2618         CPUShutdown();
2619     }
2620 }
2621
2622 /* BNE */
2623 static void OpD0 ()
2624 {
2625     long OpAddress = Relative ();
2626     BranchCheck1 ();
2627     if (!CheckZero())
2628     {
2629         CPU.PC = CPU.PCBase + OpAddress;
2630
2631 #ifdef VAR_CYCLES
2632         CPU.Cycles += ONE_CYCLE;
2633 #else
2634 #ifndef SA1_OPCODES
2635         CPU.Cycles++;
2636 #endif
2637 #endif
2638         CPUShutdown();
2639     }
2640 }
2641
2642 /* BPL */
2643 static void Op10 ()
2644 {
2645     long OpAddress = Relative ();
2646     BranchCheck1 ();
2647     if (!CheckNegative())
2648     {
2649         CPU.PC = CPU.PCBase + OpAddress;
2650 #ifdef VAR_CYCLES
2651         CPU.Cycles += ONE_CYCLE;
2652 #else
2653 #ifndef SA1_OPCODES
2654         CPU.Cycles++;
2655 #endif
2656 #endif
2657         CPUShutdown();
2658     }
2659 }
2660
2661 /* BRA */
2662 static void Op80 ()
2663 {
2664     long OpAddress = Relative ();
2665     CPU.PC = CPU.PCBase + OpAddress;
2666 #ifdef VAR_CYCLES
2667     CPU.Cycles += ONE_CYCLE;
2668 #else
2669 #ifndef SA1_OPCODES
2670     CPU.Cycles++;
2671 #endif
2672 #endif
2673     CPUShutdown();
2674 }
2675
2676 /* BVC */
2677 static void Op50 ()
2678 {
2679     long OpAddress = Relative ();
2680     BranchCheck0 ();
2681     if (!CheckOverflow())
2682     {
2683         CPU.PC = CPU.PCBase + OpAddress;
2684 #ifdef VAR_CYCLES
2685         CPU.Cycles += ONE_CYCLE;
2686 #else
2687 #ifndef SA1_OPCODES
2688         CPU.Cycles++;
2689 #endif
2690 #endif
2691         CPUShutdown();
2692     }
2693 }
2694
2695 /* BVS */
2696 static void Op70 ()
2697 {
2698     long OpAddress = Relative ();
2699     BranchCheck0 ();
2700     if (CheckOverflow())
2701     {
2702         CPU.PC = CPU.PCBase + OpAddress;
2703 #ifdef VAR_CYCLES
2704         CPU.Cycles += ONE_CYCLE;
2705 #else
2706 #ifndef SA1_OPCODES
2707         CPU.Cycles++;
2708 #endif
2709 #endif
2710         CPUShutdown();
2711     }
2712 }
2713 /**********************************************************************************************/
2714
2715 /* ClearFlag Instructions ******************************************************************** */
2716 /* CLC */
2717 static void Op18 ()
2718 {
2719     ClearCarry ();
2720 #ifdef VAR_CYCLES
2721     CPU.Cycles += ONE_CYCLE;
2722 #endif
2723 }
2724
2725 /* CLD */
2726 static void OpD8 ()
2727 {
2728     ClearDecimal ();
2729 #ifdef VAR_CYCLES
2730     CPU.Cycles += ONE_CYCLE;
2731 #endif
2732 }
2733
2734 /* CLI */
2735 static void Op58 ()
2736 {
2737     ClearIRQ ();
2738 #ifdef VAR_CYCLES
2739     CPU.Cycles += ONE_CYCLE;
2740 #endif
2741 /*    CHECK_FOR_IRQ(); */
2742 }
2743
2744 /* CLV */
2745 static void OpB8 ()
2746 {
2747     ClearOverflow();
2748 #ifdef VAR_CYCLES
2749     CPU.Cycles += ONE_CYCLE;
2750 #endif
2751 }
2752 /**********************************************************************************************/
2753
2754 /* DEX/DEY *********************************************************************************** */
2755 static void OpCAX1 ()
2756 {
2757 #ifdef VAR_CYCLES
2758     CPU.Cycles += ONE_CYCLE;
2759 #endif
2760 #ifdef CPU_SHUTDOWN
2761     CPU.WaitAddress = NULL;
2762 #endif
2763
2764     Registers.XL--;
2765     SETZN8 (Registers.XL);
2766 }
2767
2768 static void OpCAX0 ()
2769 {
2770 #ifdef VAR_CYCLES
2771     CPU.Cycles += ONE_CYCLE;
2772 #endif
2773 #ifdef CPU_SHUTDOWN
2774     CPU.WaitAddress = NULL;
2775 #endif
2776
2777     Registers.X.W--;
2778     SETZN16 (Registers.X.W);
2779 }
2780
2781 static void Op88X1 ()
2782 {
2783 #ifdef VAR_CYCLES
2784     CPU.Cycles += ONE_CYCLE;
2785 #endif
2786 #ifdef CPU_SHUTDOWN
2787     CPU.WaitAddress = NULL;
2788 #endif
2789
2790     Registers.YL--;
2791     SETZN8 (Registers.YL);
2792 }
2793
2794 static void Op88X0 ()
2795 {
2796 #ifdef VAR_CYCLES
2797     CPU.Cycles += ONE_CYCLE;
2798 #endif
2799 #ifdef CPU_SHUTDOWN
2800     CPU.WaitAddress = NULL;
2801 #endif
2802
2803     Registers.Y.W--;
2804     SETZN16 (Registers.Y.W);
2805 }
2806 /**********************************************************************************************/
2807
2808 /* INX/INY *********************************************************************************** */
2809 static void OpE8X1 ()
2810 {
2811 #ifdef VAR_CYCLES
2812     CPU.Cycles += ONE_CYCLE;
2813 #endif
2814 #ifdef CPU_SHUTDOWN
2815     CPU.WaitAddress = NULL;
2816 #endif
2817
2818     Registers.XL++;
2819     SETZN8 (Registers.XL);
2820 }
2821
2822 static void OpE8X0 ()
2823 {
2824 #ifdef VAR_CYCLES
2825     CPU.Cycles += ONE_CYCLE;
2826 #endif
2827 #ifdef CPU_SHUTDOWN
2828     CPU.WaitAddress = NULL;
2829 #endif
2830
2831     Registers.X.W++;
2832     SETZN16 (Registers.X.W);
2833 }
2834
2835 static void OpC8X1 ()
2836 {
2837 #ifdef VAR_CYCLES
2838     CPU.Cycles += ONE_CYCLE;
2839 #endif
2840 #ifdef CPU_SHUTDOWN
2841     CPU.WaitAddress = NULL;
2842 #endif
2843
2844     Registers.YL++;
2845     SETZN8 (Registers.YL);
2846 }
2847
2848 static void OpC8X0 ()
2849 {
2850 #ifdef VAR_CYCLES
2851     CPU.Cycles += ONE_CYCLE;
2852 #endif
2853 #ifdef CPU_SHUTDOWN
2854     CPU.WaitAddress = NULL;
2855 #endif
2856
2857     Registers.Y.W++;
2858     SETZN16 (Registers.Y.W);
2859 }
2860
2861 /**********************************************************************************************/
2862
2863 /* NOP *************************************************************************************** */
2864 static void OpEA ()
2865 {
2866 #ifdef VAR_CYCLES
2867     CPU.Cycles += ONE_CYCLE;
2868 #endif
2869
2870 }
2871 /**********************************************************************************************/
2872
2873 /* PUSH Instructions ************************************************************************* */
2874 #define PUSHW(w) \
2875     S9xSetWord (w, Registers.S.W - 1);\
2876     Registers.S.W -= 2;
2877 #define PUSHB(b)\
2878     S9xSetByte (b, Registers.S.W--);
2879
2880 static void OpF4 ()
2881 {
2882     long OpAddress = Absolute ();
2883     PUSHW (OpAddress);
2884 }
2885
2886 static void OpD4 ()
2887 {
2888     long OpAddress = DirectIndirect ();
2889     PUSHW (OpAddress);
2890 }
2891
2892 static void Op62 ()
2893 {
2894     long OpAddress = RelativeLong ();
2895     PUSHW (OpAddress);
2896 }
2897
2898 static void Op48M1 ()
2899 {
2900     PUSHB (Registers.AL);
2901 #ifdef VAR_CYCLES
2902     CPU.Cycles += ONE_CYCLE;
2903 #endif
2904 }
2905
2906 static void Op48M0 ()
2907 {
2908     PUSHW (Registers.A.W);
2909 #ifdef VAR_CYCLES
2910     CPU.Cycles += ONE_CYCLE;
2911 #endif
2912 }
2913
2914 static void Op8B ()
2915 {
2916     PUSHB (Registers.DB);
2917 #ifdef VAR_CYCLES
2918     CPU.Cycles += ONE_CYCLE;
2919 #endif
2920 }
2921
2922 static void Op0B ()
2923 {
2924     PUSHW (Registers.D.W);
2925 #ifdef VAR_CYCLES
2926     CPU.Cycles += ONE_CYCLE;
2927 #endif
2928 }
2929
2930 static void Op4B ()
2931 {
2932     PUSHB (Registers.PB);
2933 #ifdef VAR_CYCLES
2934     CPU.Cycles += ONE_CYCLE;
2935 #endif
2936 }
2937
2938 static void Op08 ()
2939 {
2940     S9xPackStatus ();
2941     PUSHB (Registers.PL);
2942 #ifdef VAR_CYCLES
2943     CPU.Cycles += ONE_CYCLE;
2944 #endif
2945 }
2946
2947 static void OpDAX1 ()
2948 {
2949     PUSHB (Registers.XL);
2950 #ifdef VAR_CYCLES
2951     CPU.Cycles += ONE_CYCLE;
2952 #endif
2953 }
2954
2955 static void OpDAX0 ()
2956 {
2957     PUSHW (Registers.X.W);
2958 #ifdef VAR_CYCLES
2959     CPU.Cycles += ONE_CYCLE;
2960 #endif
2961 }
2962
2963 static void Op5AX1 ()
2964 {
2965     PUSHB (Registers.YL);
2966 #ifdef VAR_CYCLES
2967     CPU.Cycles += ONE_CYCLE;
2968 #endif
2969 }
2970
2971 static void Op5AX0 ()
2972 {
2973     PUSHW (Registers.Y.W);
2974 #ifdef VAR_CYCLES
2975     CPU.Cycles += ONE_CYCLE;
2976 #endif
2977 }
2978 /**********************************************************************************************/
2979
2980 /* PULL Instructions ************************************************************************* */
2981 #define PullW(w) \
2982         w = S9xGetWord (Registers.S.W + 1); \
2983         Registers.S.W += 2;
2984
2985 #define PullB(b)\
2986         b = S9xGetByte (++Registers.S.W);
2987
2988 static void Op68M1 ()
2989 {
2990 #ifdef VAR_CYCLES
2991     CPU.Cycles += TWO_CYCLES;
2992 #endif
2993     PullB (Registers.AL);
2994     SETZN8 (Registers.AL);
2995 }
2996
2997 static void Op68M0 ()
2998 {
2999 #ifdef VAR_CYCLES
3000     CPU.Cycles += TWO_CYCLES;
3001 #endif
3002     PullW (Registers.A.W);
3003     SETZN16 (Registers.A.W);
3004 }
3005
3006 static void OpAB ()
3007 {
3008 #ifdef VAR_CYCLES
3009     CPU.Cycles += TWO_CYCLES;
3010 #endif
3011     PullB (Registers.DB);
3012     SETZN8 (Registers.DB);
3013     ICPU.ShiftedDB = (Registers.DB & 0xff) << 16;
3014 }
3015
3016 /* PHP */
3017 static void Op2B ()
3018 {
3019 #ifdef VAR_CYCLES
3020     CPU.Cycles += TWO_CYCLES;
3021 #endif
3022     PullW (Registers.D.W);
3023     SETZN16 (Registers.D.W);
3024 }
3025
3026 /* PLP */
3027 static void Op28 ()
3028 {
3029 #ifdef VAR_CYCLES
3030     CPU.Cycles += TWO_CYCLES;
3031 #endif
3032     PullB (Registers.PL);
3033     S9xUnpackStatus ();
3034
3035     if (CheckIndex())
3036     {
3037         Registers.XH = 0;
3038         Registers.YH = 0;
3039     }
3040     S9xFixCycles();
3041 /*     CHECK_FOR_IRQ();*/
3042 }
3043
3044 static void OpFAX1 ()
3045 {
3046 #ifdef VAR_CYCLES
3047     CPU.Cycles += TWO_CYCLES;
3048 #endif
3049     PullB (Registers.XL);
3050     SETZN8 (Registers.XL);
3051 }
3052
3053 static void OpFAX0 ()
3054 {
3055 #ifdef VAR_CYCLES
3056     CPU.Cycles += TWO_CYCLES;
3057 #endif
3058     PullW (Registers.X.W);
3059     SETZN16 (Registers.X.W);
3060 }
3061
3062 static void Op7AX1 ()
3063 {
3064 #ifdef VAR_CYCLES
3065     CPU.Cycles += TWO_CYCLES;
3066 #endif
3067     PullB (Registers.YL);
3068     SETZN8 (Registers.YL);
3069 }
3070
3071 static void Op7AX0 ()
3072 {
3073 #ifdef VAR_CYCLES
3074     CPU.Cycles += TWO_CYCLES;
3075 #endif
3076     PullW (Registers.Y.W);
3077     SETZN16 (Registers.Y.W);
3078 }
3079
3080 /**********************************************************************************************/
3081
3082 /* SetFlag Instructions ********************************************************************** */
3083 /* SEC */
3084 static void Op38 ()
3085 {
3086     SetCarry();
3087 #ifdef VAR_CYCLES
3088     CPU.Cycles += ONE_CYCLE;
3089 #endif
3090 }
3091
3092 /* SED */
3093 static void OpF8 ()
3094 {
3095     SetDecimal();
3096 #ifdef VAR_CYCLES
3097     CPU.Cycles += ONE_CYCLE;
3098 #endif
3099     missing.decimal_mode = 1;
3100 }
3101
3102 /* SEI */
3103 static void Op78 ()
3104 {
3105     SetIRQ ();
3106 #ifdef VAR_CYCLES
3107     CPU.Cycles += ONE_CYCLE;
3108 #endif
3109 }
3110 /**********************************************************************************************/
3111
3112 /* Transfer Instructions ********************************************************************* */
3113 /* TAX8 */
3114 static void OpAAX1 ()
3115 {
3116 #ifdef VAR_CYCLES
3117     CPU.Cycles += ONE_CYCLE;
3118 #endif
3119     Registers.XL = Registers.AL;
3120     SETZN8 (Registers.XL);
3121 }
3122
3123 /* TAX16 */
3124 static void OpAAX0 ()
3125 {
3126 #ifdef VAR_CYCLES
3127     CPU.Cycles += ONE_CYCLE;
3128 #endif
3129     Registers.X.W = Registers.A.W;
3130     SETZN16 (Registers.X.W);
3131 }
3132
3133 /* TAY8 */
3134 static void OpA8X1 ()
3135 {
3136 #ifdef VAR_CYCLES
3137     CPU.Cycles += ONE_CYCLE;
3138 #endif
3139     Registers.YL = Registers.AL;
3140     SETZN8 (Registers.YL);
3141 }
3142
3143 /* TAY16 */
3144 static void OpA8X0 ()
3145 {
3146 #ifdef VAR_CYCLES
3147     CPU.Cycles += ONE_CYCLE;
3148 #endif
3149     Registers.Y.W = Registers.A.W;
3150     SETZN16 (Registers.Y.W);
3151 }
3152
3153 static void Op5B ()
3154 {
3155 #ifdef VAR_CYCLES
3156     CPU.Cycles += ONE_CYCLE;
3157 #endif
3158     Registers.D.W = Registers.A.W;
3159     SETZN16 (Registers.D.W);
3160 }
3161
3162 static void Op1B ()
3163 {
3164 #ifdef VAR_CYCLES
3165     CPU.Cycles += ONE_CYCLE;
3166 #endif
3167     Registers.S.W = Registers.A.W;
3168     if (CheckEmulation())
3169         Registers.SH = 1;
3170 }
3171
3172 static void Op7B ()
3173 {
3174 #ifdef VAR_CYCLES
3175     CPU.Cycles += ONE_CYCLE;
3176 #endif
3177     Registers.A.W = Registers.D.W;
3178     SETZN16 (Registers.A.W);
3179 }
3180
3181 static void Op3B ()
3182 {
3183 #ifdef VAR_CYCLES
3184     CPU.Cycles += ONE_CYCLE;
3185 #endif
3186     Registers.A.W = Registers.S.W;
3187     SETZN16 (Registers.A.W);
3188 }
3189
3190 static void OpBAX1 ()
3191 {
3192 #ifdef VAR_CYCLES
3193     CPU.Cycles += ONE_CYCLE;
3194 #endif
3195     Registers.XL = Registers.SL;
3196     SETZN8 (Registers.XL);
3197 }
3198
3199 static void OpBAX0 ()
3200 {
3201 #ifdef VAR_CYCLES
3202     CPU.Cycles += ONE_CYCLE;
3203 #endif
3204     Registers.X.W = Registers.S.W;
3205     SETZN16 (Registers.X.W);
3206 }
3207
3208 static void Op8AM1 ()
3209 {
3210 #ifdef VAR_CYCLES
3211     CPU.Cycles += ONE_CYCLE;
3212 #endif
3213     Registers.AL = Registers.XL;
3214     SETZN8 (Registers.AL);
3215 }
3216
3217 static void Op8AM0 ()
3218 {
3219 #ifdef VAR_CYCLES
3220     CPU.Cycles += ONE_CYCLE;
3221 #endif
3222     Registers.A.W = Registers.X.W;
3223     SETZN16 (Registers.A.W);
3224 }
3225
3226 static void Op9A ()
3227 {
3228 #ifdef VAR_CYCLES
3229     CPU.Cycles += ONE_CYCLE;
3230 #endif
3231     Registers.S.W = Registers.X.W;
3232     if (CheckEmulation())
3233         Registers.SH = 1;
3234 }
3235
3236 static void Op9BX1 ()
3237 {
3238 #ifdef VAR_CYCLES
3239     CPU.Cycles += ONE_CYCLE;
3240 #endif
3241     Registers.YL = Registers.XL;
3242     SETZN8 (Registers.YL);
3243 }
3244
3245 static void Op9BX0 ()
3246 {
3247 #ifdef VAR_CYCLES
3248     CPU.Cycles += ONE_CYCLE;
3249 #endif
3250     Registers.Y.W = Registers.X.W;
3251     SETZN16 (Registers.Y.W);
3252 }
3253
3254 static void Op98M1 ()
3255 {
3256 #ifdef VAR_CYCLES
3257     CPU.Cycles += ONE_CYCLE;
3258 #endif
3259     Registers.AL = Registers.YL;
3260     SETZN8 (Registers.AL);
3261 }
3262
3263 static void Op98M0 ()
3264 {
3265 #ifdef VAR_CYCLES
3266     CPU.Cycles += ONE_CYCLE;
3267 #endif
3268     Registers.A.W = Registers.Y.W;
3269     SETZN16 (Registers.A.W);
3270 }
3271
3272 static void OpBBX1 ()
3273 {
3274 #ifdef VAR_CYCLES
3275     CPU.Cycles += ONE_CYCLE;
3276 #endif
3277     Registers.XL = Registers.YL;
3278     SETZN8 (Registers.XL);
3279 }
3280
3281 static void OpBBX0 ()
3282 {
3283 #ifdef VAR_CYCLES
3284     CPU.Cycles += ONE_CYCLE;
3285 #endif
3286     Registers.X.W = Registers.Y.W;
3287     SETZN16 (Registers.X.W);
3288 }
3289
3290 /**********************************************************************************************/
3291
3292 /* XCE *************************************************************************************** */
3293 static void OpFB ()
3294 {
3295 #ifdef VAR_CYCLES
3296     CPU.Cycles += ONE_CYCLE;
3297 #endif
3298
3299     uint8 A1 = (ICPU._Carry & 0xff);
3300     uint8 A2 = Registers.PH;
3301     ICPU._Carry = A2 & 1;
3302     Registers.PH = A1;
3303
3304     if (CheckEmulation())
3305     {
3306         SetFlags(MemoryFlag | IndexFlag);
3307         Registers.SH = 1;
3308         missing.emulate6502 = 1;
3309     }
3310     if (CheckIndex ())
3311     {
3312         Registers.XH = 0;
3313         Registers.YH = 0;
3314     }
3315     S9xFixCycles();
3316 }
3317 /**********************************************************************************************/
3318
3319 /* BRK *************************************************************************************** */
3320 static void Op00 ()
3321 {
3322 #ifdef DEBUGGER
3323     if (CPU.Flags & TRACE_FLAG)
3324         S9xTraceMessage ("*** BRK");
3325 #endif
3326
3327 #ifndef SA1_OPCODES
3328     CPU.BRKTriggered = TRUE;
3329 #endif
3330
3331     if (!CheckEmulation())
3332     {
3333         PUSHB (Registers.PB);
3334         PUSHW (CPU.PC - CPU.PCBase + 1);
3335         S9xPackStatus ();
3336         PUSHB (Registers.PL);
3337         ClearDecimal ();
3338         SetIRQ ();
3339
3340         Registers.PB = 0;
3341         ICPU.ShiftedPB = 0;
3342         S9xSetPCBase (S9xGetWord (0xFFE6));
3343 #ifdef VAR_CYCLES
3344         CPU.Cycles += TWO_CYCLES;
3345 #else
3346 #ifndef SA1_OPCODES
3347         CPU.Cycles += 8;
3348 #endif
3349 #endif
3350     }
3351     else
3352     {
3353         PUSHW (CPU.PC - CPU.PCBase);
3354         S9xPackStatus ();
3355         PUSHB (Registers.PL);
3356         ClearDecimal ();
3357         SetIRQ ();
3358
3359         Registers.PB = 0;
3360         ICPU.ShiftedPB = 0;
3361         S9xSetPCBase (S9xGetWord (0xFFFE));
3362 #ifdef VAR_CYCLES
3363         CPU.Cycles += ONE_CYCLE;
3364 #else
3365 #ifndef SA1_OPCODES
3366         CPU.Cycles += 6;
3367 #endif
3368 #endif
3369     }
3370 }
3371 /**********************************************************************************************/
3372
3373 /* BRL ************************************************************************************** */
3374 static void Op82 ()
3375 {
3376     long OpAddress = RelativeLong ();
3377     S9xSetPCBase (ICPU.ShiftedPB + OpAddress);
3378 }
3379 /**********************************************************************************************/
3380
3381 /* IRQ *************************************************************************************** */
3382 void S9xOpcode_IRQ ()
3383 {
3384 #ifdef DEBUGGER
3385     if (CPU.Flags & TRACE_FLAG)
3386         S9xTraceMessage ("*** IRQ");
3387 #endif
3388     if (!CheckEmulation())
3389     {
3390         PUSHB (Registers.PB);
3391         PUSHW (CPU.PC - CPU.PCBase);
3392         S9xPackStatus ();
3393         PUSHB (Registers.PL);
3394         ClearDecimal ();
3395         SetIRQ ();
3396
3397         Registers.PB = 0;
3398         ICPU.ShiftedPB = 0;
3399 #ifdef SA1_OPCODES
3400         S9xSA1SetPCBase (Memory.FillRAM [0x2207] |
3401                          (Memory.FillRAM [0x2208] << 8));
3402 #else
3403         if (Settings.SA1 && (Memory.FillRAM [0x2209] & 0x40))
3404             S9xSetPCBase (Memory.FillRAM [0x220e] | 
3405                           (Memory.FillRAM [0x220f] << 8));
3406         else
3407             S9xSetPCBase (S9xGetWord (0xFFEE));
3408 #endif
3409 #ifdef VAR_CYCLES
3410         CPU.Cycles += TWO_CYCLES;
3411 #else
3412 #ifndef SA1_OPCODES
3413         CPU.Cycles += 8;
3414 #endif
3415 #endif
3416     }
3417     else
3418     {
3419         PUSHW (CPU.PC - CPU.PCBase);
3420         S9xPackStatus ();
3421         PUSHB (Registers.PL);
3422         ClearDecimal ();
3423         SetIRQ ();
3424
3425         Registers.PB = 0;
3426         ICPU.ShiftedPB = 0;
3427 #ifdef SA1_OPCODES
3428         S9xSA1SetPCBase (Memory.FillRAM [0x2207] |
3429                          (Memory.FillRAM [0x2208] << 8));
3430 #else
3431         if (Settings.SA1 && (Memory.FillRAM [0x2209] & 0x40))
3432             S9xSetPCBase (Memory.FillRAM [0x220e] | 
3433                           (Memory.FillRAM [0x220f] << 8));
3434         else
3435             S9xSetPCBase (S9xGetWord (0xFFFE));
3436 #endif
3437 #ifdef VAR_CYCLES
3438         CPU.Cycles += ONE_CYCLE;
3439 #else
3440 #ifndef SA1_OPCODES
3441         CPU.Cycles += 6;
3442 #endif
3443 #endif
3444     }
3445 }
3446
3447 /**********************************************************************************************/
3448
3449 /* NMI *************************************************************************************** */
3450 void S9xOpcode_NMI ()
3451 {
3452 #ifdef DEBUGGER
3453     if (CPU.Flags & TRACE_FLAG)
3454         S9xTraceMessage ("*** NMI");
3455 #endif
3456     if (!CheckEmulation())
3457     {
3458         PUSHB (Registers.PB);
3459         PUSHW (CPU.PC - CPU.PCBase);
3460         S9xPackStatus ();
3461         PUSHB (Registers.PL);
3462         ClearDecimal ();
3463         SetIRQ ();
3464
3465         Registers.PB = 0;
3466         ICPU.ShiftedPB = 0;
3467 #ifdef SA1_OPCODES
3468         S9xSA1SetPCBase (Memory.FillRAM [0x2205] |
3469                          (Memory.FillRAM [0x2206] << 8));
3470 #else
3471         if (Settings.SA1 && (Memory.FillRAM [0x2209] & 0x20))
3472             S9xSetPCBase (Memory.FillRAM [0x220c] |
3473                           (Memory.FillRAM [0x220d] << 8));
3474         else
3475             S9xSetPCBase (S9xGetWord (0xFFEA));
3476 #endif
3477 #ifdef VAR_CYCLES
3478         CPU.Cycles += TWO_CYCLES;
3479 #else
3480 #ifndef SA1_OPCODES
3481         CPU.Cycles += 8;
3482 #endif
3483 #endif
3484     }
3485     else
3486     {
3487         PUSHW (CPU.PC - CPU.PCBase);
3488         S9xPackStatus ();
3489         PUSHB (Registers.PL);
3490         ClearDecimal ();
3491         SetIRQ ();
3492
3493         Registers.PB = 0;
3494         ICPU.ShiftedPB = 0;
3495 #ifdef SA1_OPCODES
3496         S9xSA1SetPCBase (Memory.FillRAM [0x2205] |
3497                          (Memory.FillRAM [0x2206] << 8));
3498 #else
3499         if (Settings.SA1 && (Memory.FillRAM [0x2209] & 0x20))
3500             S9xSetPCBase (Memory.FillRAM [0x220c] |
3501                           (Memory.FillRAM [0x220d] << 8));
3502         else
3503             S9xSetPCBase (S9xGetWord (0xFFFA));
3504 #endif
3505 #ifdef VAR_CYCLES
3506         CPU.Cycles += ONE_CYCLE;
3507 #else
3508 #ifndef SA1_OPCODES
3509         CPU.Cycles += 6;
3510 #endif
3511 #endif
3512     }
3513 }
3514 /**********************************************************************************************/
3515
3516 /* COP *************************************************************************************** */
3517 static void Op02 ()
3518 {
3519 #ifdef DEBUGGER
3520     if (CPU.Flags & TRACE_FLAG)
3521         S9xTraceMessage ("*** COP");
3522 #endif  
3523     if (!CheckEmulation())
3524     {
3525         PUSHB (Registers.PB);
3526         PUSHW (CPU.PC - CPU.PCBase + 1);
3527         S9xPackStatus ();
3528         PUSHB (Registers.PL);
3529         ClearDecimal ();
3530         SetIRQ ();
3531
3532         Registers.PB = 0;
3533         ICPU.ShiftedPB = 0;
3534         S9xSetPCBase (S9xGetWord (0xFFE4));
3535 #ifdef VAR_CYCLES
3536         CPU.Cycles += TWO_CYCLES;
3537 #else
3538 #ifndef SA1_OPCODES
3539         CPU.Cycles += 8;
3540 #endif
3541 #endif
3542     }
3543     else
3544     {
3545         PUSHW (CPU.PC - CPU.PCBase);
3546         S9xPackStatus ();
3547         PUSHB (Registers.PL);
3548         ClearDecimal ();
3549         SetIRQ ();
3550
3551         Registers.PB = 0;
3552         ICPU.ShiftedPB = 0;
3553         S9xSetPCBase (S9xGetWord (0xFFF4));
3554 #ifdef VAR_CYCLES
3555         CPU.Cycles += ONE_CYCLE;
3556 #else
3557 #ifndef SA1_OPCODES
3558         CPU.Cycles += 6;
3559 #endif
3560 #endif
3561     }
3562 }
3563 /**********************************************************************************************/
3564
3565 /* JML *************************************************************************************** */
3566 static void OpDC ()
3567 {
3568     long OpAddress = AbsoluteIndirectLong ();
3569     Registers.PB = (uint8) (OpAddress >> 16);
3570     ICPU.ShiftedPB = OpAddress & 0xff0000;
3571     S9xSetPCBase (OpAddress);
3572 #ifdef VAR_CYCLES
3573     CPU.Cycles += TWO_CYCLES;
3574 #endif
3575 }
3576
3577 static void Op5C ()
3578 {
3579     long OpAddress = AbsoluteLong ();
3580     Registers.PB = (uint8) (OpAddress >> 16);
3581     ICPU.ShiftedPB = OpAddress & 0xff0000;
3582     S9xSetPCBase (OpAddress);
3583 }
3584 /**********************************************************************************************/
3585
3586 /* JMP *************************************************************************************** */
3587 static void Op4C ()
3588 {
3589     long OpAddress = Absolute ();
3590     S9xSetPCBase (ICPU.ShiftedPB + (OpAddress & 0xffff));
3591 #if defined(CPU_SHUTDOWN) && defined(SA1_OPCODES)
3592     CPUShutdown();
3593 #endif
3594 }
3595
3596 static void Op6C ()
3597 {
3598     long OpAddress = AbsoluteIndirect ();
3599     S9xSetPCBase (ICPU.ShiftedPB + (OpAddress & 0xffff));
3600 }
3601
3602 static void Op7C ()
3603 {
3604     long OpAddress = AbsoluteIndexedIndirect ();
3605     S9xSetPCBase (ICPU.ShiftedPB + OpAddress);
3606 #ifdef VAR_CYCLES
3607     CPU.Cycles += ONE_CYCLE;
3608 #endif
3609 }
3610 /**********************************************************************************************/
3611
3612 /* JSL/RTL *********************************************************************************** */
3613 static void Op22 ()
3614 {
3615     long OpAddress = AbsoluteLong ();
3616     PUSHB (Registers.PB);
3617     PUSHW (CPU.PC - CPU.PCBase - 1);
3618     Registers.PB = (uint8) (OpAddress >> 16);
3619     ICPU.ShiftedPB = OpAddress & 0xff0000;
3620     S9xSetPCBase (OpAddress);
3621 }
3622
3623 static void Op6B ()
3624 {
3625     PullW (Registers.PC);
3626     PullB (Registers.PB);
3627     ICPU.ShiftedPB = (Registers.PB & 0xff) << 16;
3628     S9xSetPCBase (ICPU.ShiftedPB + ((Registers.PC + 1) & 0xffff));
3629 #ifdef VAR_CYCLES
3630     CPU.Cycles += TWO_CYCLES;
3631 #endif
3632 }
3633 /**********************************************************************************************/
3634
3635 /* JSR/RTS *********************************************************************************** */
3636 static void Op20 ()
3637 {
3638     long OpAddress = Absolute ();
3639     PUSHW (CPU.PC - CPU.PCBase - 1);
3640     S9xSetPCBase (ICPU.ShiftedPB + (OpAddress & 0xffff));
3641 #ifdef VAR_CYCLES
3642     CPU.Cycles += ONE_CYCLE;
3643 #endif
3644 }
3645
3646 static void OpFC ()
3647 {
3648     long OpAddress = AbsoluteIndexedIndirect ();
3649     PUSHW (CPU.PC - CPU.PCBase - 1);
3650     S9xSetPCBase (ICPU.ShiftedPB + OpAddress);
3651 #ifdef VAR_CYCLES
3652     CPU.Cycles += ONE_CYCLE;
3653 #endif
3654 }
3655
3656 static void Op60 ()
3657 {
3658     PullW (Registers.PC);
3659     S9xSetPCBase (ICPU.ShiftedPB + ((Registers.PC + 1) & 0xffff));
3660 #ifdef VAR_CYCLES
3661     CPU.Cycles += ONE_CYCLE * 3;
3662 #endif
3663 }
3664
3665 /**********************************************************************************************/
3666
3667 /* MVN/MVP *********************************************************************************** */
3668 static void Op54X1 ()
3669 {
3670     uint32 SrcBank;
3671
3672 #ifdef VAR_CYCLES
3673     CPU.Cycles += CPU.MemSpeedx2 + TWO_CYCLES;
3674 #endif
3675     
3676     Registers.DB = *CPU.PC++;
3677     ICPU.ShiftedDB = (Registers.DB & 0xff) << 16;
3678     SrcBank = *CPU.PC++;
3679
3680     S9xSetByte (S9xGetByte ((SrcBank << 16) + Registers.X.W),
3681              ICPU.ShiftedDB + Registers.Y.W);
3682
3683     Registers.XL++;
3684     Registers.YL++;
3685     Registers.A.W--;
3686     if (Registers.A.W != 0xffff)
3687         CPU.PC -= 3;
3688 }
3689
3690 static void Op54X0 ()
3691 {
3692     uint32 SrcBank;
3693
3694 #ifdef VAR_CYCLES
3695     CPU.Cycles += CPU.MemSpeedx2 + TWO_CYCLES;
3696 #endif
3697     
3698     Registers.DB = *CPU.PC++;
3699     ICPU.ShiftedDB = (Registers.DB & 0xff) << 16;
3700     SrcBank = *CPU.PC++;
3701
3702     S9xSetByte (S9xGetByte ((SrcBank << 16) + Registers.X.W),
3703              ICPU.ShiftedDB + Registers.Y.W);
3704
3705     Registers.X.W++;
3706     Registers.Y.W++;
3707     Registers.A.W--;
3708     if (Registers.A.W != 0xffff)
3709         CPU.PC -= 3;
3710 }
3711
3712 static void Op44X1 ()
3713 {
3714     uint32 SrcBank;
3715
3716 #ifdef VAR_CYCLES
3717     CPU.Cycles += CPU.MemSpeedx2 + TWO_CYCLES;
3718 #endif    
3719     Registers.DB = *CPU.PC++;
3720     ICPU.ShiftedDB = (Registers.DB & 0xff) << 16;
3721     SrcBank = *CPU.PC++;
3722     S9xSetByte (S9xGetByte ((SrcBank << 16) + Registers.X.W),
3723              ICPU.ShiftedDB + Registers.Y.W);
3724
3725     Registers.XL--;
3726     Registers.YL--;
3727     Registers.A.W--;
3728     if (Registers.A.W != 0xffff)
3729         CPU.PC -= 3;
3730 }
3731
3732 static void Op44X0 ()
3733 {
3734     uint32 SrcBank;
3735
3736 #ifdef VAR_CYCLES
3737     CPU.Cycles += CPU.MemSpeedx2 + TWO_CYCLES;
3738 #endif    
3739     Registers.DB = *CPU.PC++;
3740     ICPU.ShiftedDB = (Registers.DB & 0xff) << 16;
3741     SrcBank = *CPU.PC++;
3742     S9xSetByte (S9xGetByte ((SrcBank << 16) + Registers.X.W),
3743              ICPU.ShiftedDB + Registers.Y.W);
3744
3745     Registers.X.W--;
3746     Registers.Y.W--;
3747     Registers.A.W--;
3748     if (Registers.A.W != 0xffff)
3749         CPU.PC -= 3;
3750 }
3751
3752 /**********************************************************************************************/
3753
3754 /* REP/SEP *********************************************************************************** */
3755 static void OpC2 ()
3756 {
3757     uint8 Work8 = ~*CPU.PC++;
3758     Registers.PL &= Work8;
3759     ICPU._Carry &= Work8;
3760     ICPU._Overflow &= (Work8 >> 6);
3761     ICPU._Negative &= Work8;
3762     ICPU._Zero |= ~Work8 & Zero;
3763
3764 #ifdef VAR_CYCLES
3765     CPU.Cycles += CPU.MemSpeed + ONE_CYCLE;
3766 #endif
3767     if (CheckEmulation())
3768     {
3769         SetFlags(MemoryFlag | IndexFlag);
3770         missing.emulate6502 = 1;
3771     }
3772     if (CheckIndex ())
3773     {
3774         Registers.XH = 0;
3775         Registers.YH = 0;
3776     }
3777     S9xFixCycles();
3778 /*    CHECK_FOR_IRQ(); */
3779 }
3780
3781 static void OpE2 ()
3782 {
3783     uint8 Work8 = *CPU.PC++;
3784     Registers.PL |= Work8;
3785     ICPU._Carry |= Work8 & 1;
3786     ICPU._Overflow |= (Work8 >> 6) & 1;
3787     ICPU._Negative |= Work8;
3788     if (Work8 & Zero)
3789         ICPU._Zero = 0;
3790 #ifdef VAR_CYCLES
3791     CPU.Cycles += CPU.MemSpeed + ONE_CYCLE;
3792 #endif
3793     if (CheckEmulation())
3794     {
3795         SetFlags(MemoryFlag | IndexFlag);
3796         missing.emulate6502 = 1;
3797     }
3798     if (CheckIndex ())
3799     {
3800         Registers.XH = 0;
3801         Registers.YH = 0;
3802     }
3803     S9xFixCycles();
3804 }
3805 /**********************************************************************************************/
3806
3807 /* XBA *************************************************************************************** */
3808 static void OpEB ()
3809 {
3810     uint8 Work8 = Registers.AL;
3811     Registers.AL = Registers.AH;
3812     Registers.AH = Work8;
3813
3814     SETZN8 (Registers.AL);
3815 #ifdef VAR_CYCLES
3816     CPU.Cycles += TWO_CYCLES;
3817 #endif
3818 }
3819 /**********************************************************************************************/
3820
3821 /* RTI *************************************************************************************** */
3822 static void Op40 ()
3823 {
3824     PullB (Registers.PL);
3825     S9xUnpackStatus ();
3826     PullW (Registers.PC);
3827     if (!CheckEmulation())
3828     {
3829         PullB (Registers.PB);
3830         ICPU.ShiftedPB = (Registers.PB & 0xff) << 16;
3831     }
3832     else
3833     {
3834         SetFlags (MemoryFlag | IndexFlag);
3835         missing.emulate6502 = 1;
3836     }
3837     S9xSetPCBase (ICPU.ShiftedPB + Registers.PC);
3838     
3839     if (CheckIndex ())
3840     {
3841         Registers.XH = 0;
3842         Registers.YH = 0;
3843     }
3844 #ifdef VAR_CYCLES
3845     CPU.Cycles += TWO_CYCLES;
3846 #endif
3847     S9xFixCycles();
3848 /*    CHECK_FOR_IRQ(); */
3849 }
3850
3851 /**********************************************************************************************/
3852
3853 /* STP/WAI/DB ******************************************************************************** */
3854 // WAI
3855 static void OpCB ()
3856 {
3857     if (CPU.IRQActive)
3858     {
3859 #ifdef VAR_CYCLES
3860         CPU.Cycles += TWO_CYCLES;
3861 #else
3862 #ifndef SA1_OPCODES
3863         CPU.Cycles += 2;
3864 #endif
3865 #endif
3866     }
3867     else
3868     {
3869         CPU.WaitingForInterrupt = TRUE;
3870         CPU.PC--;
3871 #ifdef CPU_SHUTDOWN
3872 #ifndef SA1_OPCODES
3873         if (Settings.Shutdown)
3874         {
3875                 ApuSync();
3876         }
3877 #else
3878         if (Settings.Shutdown)
3879         {
3880             SA1.CPUExecuting = FALSE;
3881             SA1.Executing = FALSE;
3882         }
3883 #endif
3884 #endif
3885     }
3886 }
3887
3888 // STP
3889 static void OpDB ()
3890 {
3891     CPU.PC--;
3892     CPU.Flags |= DEBUG_MODE_FLAG;
3893 }
3894
3895 // Reserved S9xOpcode
3896 static void Op42 ()
3897 {
3898 #if defined(CPU_SHUTDOWN) && !defined(SA1_OPCODES)
3899
3900         CPU.WaitAddress = NULL;
3901         if (Settings.SA1) S9xSA1ExecuteDuringSleep ();
3902
3903         ApuSync();\r\r#ifdef VAR_CYCLES
3904         CPU.Cycles += CPU.MemSpeed;
3905 #endif
3906
3907         //relative
3908         int8 b = *CPU.PC;
3909         CPU.PC++;
3910
3911         int8 BranchOffset = ((b & 0xF) | 0xF0);
3912         uint16 OpAddress = (int)(CPU.PC - CPU.PCBase) + BranchOffset;
3913
3914         // Assume we're going to branch
3915 #ifdef VAR_CYCLES
3916         CPU.Cycles += ONE_CYCLE;
3917 #else
3918         CPU.Cycles++;
3919 #endif
3920
3921         switch (b >> 4) {
3922         case 0x1: //BPL
3923                 BranchCheck1 ();
3924                 if (!CheckNegative ()) {
3925                         CPU.PC = CPU.PCBase + OpAddress;
3926 #                       ifdef VAR_CYCLES
3927                                 CPU.Cycles += ONE_CYCLE;
3928 #                       else
3929                                 CPU.Cycles++;
3930 #                       endif
3931                         CPUShutdown ();
3932                 }
3933                 return;
3934         case 0x3: //BMI
3935                 BranchCheck1 ();
3936                 if (CheckNegative ()) {
3937                         CPU.PC = CPU.PCBase + OpAddress;
3938 #                       ifdef VAR_CYCLES
3939                                 CPU.Cycles += ONE_CYCLE;
3940 #                       else
3941                                 CPU.Cycles++;
3942 #                       endif
3943                         CPUShutdown ();
3944                 }
3945                 return;
3946         case 0x5: //BVC
3947                 BranchCheck0 ();
3948                 if (!CheckOverflow ()) {
3949                         CPU.PC = CPU.PCBase + OpAddress;
3950 #                       ifdef VAR_CYCLES
3951                                 CPU.Cycles += ONE_CYCLE;
3952 #                       else
3953                                 CPU.Cycles++;
3954 #                       endif
3955                         CPUShutdown ();
3956                 }
3957                 return;
3958         case 0x7: //BVS
3959                 BranchCheck0 ();
3960                 if (CheckOverflow ()) {
3961                                 CPU.PC = CPU.PCBase + OpAddress;
3962 #                       ifdef VAR_CYCLES
3963                                 CPU.Cycles += ONE_CYCLE;
3964 #                       else
3965                                 CPU.Cycles++;
3966 #                       endif
3967                         CPUShutdown ();
3968                         }
3969                 return;
3970         case 0x8: //BRA
3971                 CPU.PC = CPU.PCBase + OpAddress;
3972 #               ifdef VAR_CYCLES
3973                         CPU.Cycles += ONE_CYCLE;
3974 #               else
3975                         CPU.Cycles++;
3976 #               endif
3977                 CPUShutdown ();
3978                 return;
3979         case 0x9: //BCC
3980                 BranchCheck0 ();
3981             if (!CheckCarry ()) {
3982                         CPU.PC = CPU.PCBase + OpAddress;
3983 #                       ifdef VAR_CYCLES
3984                                 CPU.Cycles += ONE_CYCLE;
3985 #                       else
3986                                 CPU.Cycles++;
3987 #                       endif
3988                         CPUShutdown ();
3989                 }
3990                 return;
3991         case 0xB: //BCS
3992                 BranchCheck0 ();
3993                 if (CheckCarry ()) {
3994                         CPU.PC = CPU.PCBase + OpAddress;
3995 #                       ifdef VAR_CYCLES
3996                                 CPU.Cycles += ONE_CYCLE;
3997 #                       else
3998                                 CPU.Cycles++;
3999 #                       endif
4000                         CPUShutdown ();
4001                 }
4002                 return;
4003         case 0xD: //BNE
4004                 BranchCheck1 ();
4005                 if (!CheckZero ()) {
4006                         CPU.PC = CPU.PCBase + OpAddress;
4007 #                       ifdef VAR_CYCLES
4008                         CPU.Cycles += ONE_CYCLE;
4009 #                       else
4010                                 CPU.Cycles++;
4011 #                       endif
4012                         CPUShutdown ();
4013                 }
4014                 return;
4015         case 0xF: //BEQ
4016                 BranchCheck2 ();
4017                 if (CheckZero ()) {
4018                         CPU.PC = CPU.PCBase + OpAddress;
4019 #                       ifdef VAR_CYCLES
4020                                 CPU.Cycles += ONE_CYCLE;
4021 #                       else
4022                                 CPU.Cycles++;
4023 #                       endif
4024                         CPUShutdown ();
4025                         }
4026                 return;
4027 #ifdef DEBUG
4028         default:
4029                 printf("Invalid Op42 branch type %hx\n", b >> 4);
4030                 return;
4031 #endif
4032         }
4033 #endif
4034 }
4035
4036 /**********************************************************************************************/
4037
4038 /**********************************************************************************************/
4039 /* CPU-S9xOpcodes Definitions                                                                    */
4040 /**********************************************************************************************/
4041 struct SOpcodes S9xOpcodesM1X1[256] =
4042 {
4043     {Op00},      {Op01M1},    {Op02},      {Op03M1},    {Op04M1},
4044     {Op05M1},    {Op06M1},    {Op07M1},    {Op08},      {Op09M1},
4045     {Op0AM1},    {Op0B},      {Op0CM1},    {Op0DM1},    {Op0EM1},
4046     {Op0FM1},    {Op10},      {Op11M1},    {Op12M1},    {Op13M1},
4047     {Op14M1},    {Op15M1},    {Op16M1},    {Op17M1},    {Op18},
4048     {Op19M1},    {Op1AM1},    {Op1B},      {Op1CM1},    {Op1DM1},
4049     {Op1EM1},    {Op1FM1},    {Op20},      {Op21M1},    {Op22},
4050     {Op23M1},    {Op24M1},    {Op25M1},    {Op26M1},    {Op27M1},
4051     {Op28},      {Op29M1},    {Op2AM1},    {Op2B},      {Op2CM1},
4052     {Op2DM1},    {Op2EM1},    {Op2FM1},    {Op30},      {Op31M1},
4053     {Op32M1},    {Op33M1},    {Op34M1},    {Op35M1},    {Op36M1},
4054     {Op37M1},    {Op38},      {Op39M1},    {Op3AM1},    {Op3B},
4055     {Op3CM1},    {Op3DM1},    {Op3EM1},    {Op3FM1},    {Op40},
4056     {Op41M1},    {Op42},      {Op43M1},    {Op44X1},    {Op45M1},
4057     {Op46M1},    {Op47M1},    {Op48M1},    {Op49M1},    {Op4AM1},
4058     {Op4B},      {Op4C},      {Op4DM1},    {Op4EM1},    {Op4FM1},
4059     {Op50},      {Op51M1},    {Op52M1},    {Op53M1},    {Op54X1},
4060     {Op55M1},    {Op56M1},    {Op57M1},    {Op58},      {Op59M1},
4061     {Op5AX1},    {Op5B},      {Op5C},      {Op5DM1},    {Op5EM1},
4062     {Op5FM1},    {Op60},      {Op61M1},    {Op62},      {Op63M1},
4063     {Op64M1},    {Op65M1},    {Op66M1},    {Op67M1},    {Op68M1},
4064     {Op69M1},    {Op6AM1},    {Op6B},      {Op6C},      {Op6DM1},
4065     {Op6EM1},    {Op6FM1},    {Op70},      {Op71M1},    {Op72M1},
4066     {Op73M1},    {Op74M1},    {Op75M1},    {Op76M1},    {Op77M1},
4067     {Op78},      {Op79M1},    {Op7AX1},    {Op7B},      {Op7C},
4068     {Op7DM1},    {Op7EM1},    {Op7FM1},    {Op80},      {Op81M1},
4069     {Op82},      {Op83M1},    {Op84X1},    {Op85M1},    {Op86X1},
4070     {Op87M1},    {Op88X1},    {Op89M1},    {Op8AM1},    {Op8B},
4071     {Op8CX1},    {Op8DM1},    {Op8EX1},    {Op8FM1},    {Op90},
4072     {Op91M1},    {Op92M1},    {Op93M1},    {Op94X1},    {Op95M1},
4073     {Op96X1},    {Op97M1},    {Op98M1},    {Op99M1},    {Op9A},
4074     {Op9BX1},    {Op9CM1},    {Op9DM1},    {Op9EM1},    {Op9FM1},
4075     {OpA0X1},    {OpA1M1},    {OpA2X1},    {OpA3M1},    {OpA4X1},
4076     {OpA5M1},    {OpA6X1},    {OpA7M1},    {OpA8X1},    {OpA9M1},
4077     {OpAAX1},    {OpAB},      {OpACX1},    {OpADM1},    {OpAEX1},
4078     {OpAFM1},    {OpB0},      {OpB1M1},    {OpB2M1},    {OpB3M1},
4079     {OpB4X1},    {OpB5M1},    {OpB6X1},    {OpB7M1},    {OpB8},
4080     {OpB9M1},    {OpBAX1},    {OpBBX1},    {OpBCX1},    {OpBDM1},
4081     {OpBEX1},    {OpBFM1},    {OpC0X1},    {OpC1M1},    {OpC2},
4082     {OpC3M1},    {OpC4X1},    {OpC5M1},    {OpC6M1},    {OpC7M1},
4083     {OpC8X1},    {OpC9M1},    {OpCAX1},    {OpCB},      {OpCCX1},
4084     {OpCDM1},    {OpCEM1},    {OpCFM1},    {OpD0},      {OpD1M1},
4085     {OpD2M1},    {OpD3M1},    {OpD4},      {OpD5M1},    {OpD6M1},
4086     {OpD7M1},    {OpD8},      {OpD9M1},    {OpDAX1},    {OpDB},
4087     {OpDC},      {OpDDM1},    {OpDEM1},    {OpDFM1},    {OpE0X1},
4088     {OpE1M1},    {OpE2},      {OpE3M1},    {OpE4X1},    {OpE5M1},
4089     {OpE6M1},    {OpE7M1},    {OpE8X1},    {OpE9M1},    {OpEA},
4090     {OpEB},      {OpECX1},    {OpEDM1},    {OpEEM1},    {OpEFM1},
4091     {OpF0},      {OpF1M1},    {OpF2M1},    {OpF3M1},    {OpF4},
4092     {OpF5M1},    {OpF6M1},    {OpF7M1},    {OpF8},      {OpF9M1},
4093     {OpFAX1},    {OpFB},      {OpFC},      {OpFDM1},    {OpFEM1},
4094     {OpFFM1}
4095 };
4096
4097 struct SOpcodes S9xOpcodesM1X0[256] =
4098 {
4099     {Op00},      {Op01M1},    {Op02},      {Op03M1},    {Op04M1},
4100     {Op05M1},    {Op06M1},    {Op07M1},    {Op08},      {Op09M1},
4101     {Op0AM1},    {Op0B},      {Op0CM1},    {Op0DM1},    {Op0EM1},
4102     {Op0FM1},    {Op10},      {Op11M1},    {Op12M1},    {Op13M1},
4103     {Op14M1},    {Op15M1},    {Op16M1},    {Op17M1},    {Op18},
4104     {Op19M1},    {Op1AM1},    {Op1B},      {Op1CM1},    {Op1DM1},
4105     {Op1EM1},    {Op1FM1},    {Op20},      {Op21M1},    {Op22},
4106     {Op23M1},    {Op24M1},    {Op25M1},    {Op26M1},    {Op27M1},
4107     {Op28},      {Op29M1},    {Op2AM1},    {Op2B},      {Op2CM1},
4108     {Op2DM1},    {Op2EM1},    {Op2FM1},    {Op30},      {Op31M1},
4109     {Op32M1},    {Op33M1},    {Op34M1},    {Op35M1},    {Op36M1},
4110     {Op37M1},    {Op38},      {Op39M1},    {Op3AM1},    {Op3B},
4111     {Op3CM1},    {Op3DM1},    {Op3EM1},    {Op3FM1},    {Op40},
4112     {Op41M1},    {Op42},      {Op43M1},    {Op44X0},    {Op45M1},
4113     {Op46M1},    {Op47M1},    {Op48M1},    {Op49M1},    {Op4AM1},
4114     {Op4B},      {Op4C},      {Op4DM1},    {Op4EM1},    {Op4FM1},
4115     {Op50},      {Op51M1},    {Op52M1},    {Op53M1},    {Op54X0},
4116     {Op55M1},    {Op56M1},    {Op57M1},    {Op58},      {Op59M1},
4117     {Op5AX0},    {Op5B},      {Op5C},      {Op5DM1},    {Op5EM1},
4118     {Op5FM1},    {Op60},      {Op61M1},    {Op62},      {Op63M1},
4119     {Op64M1},    {Op65M1},    {Op66M1},    {Op67M1},    {Op68M1},
4120     {Op69M1},    {Op6AM1},    {Op6B},      {Op6C},      {Op6DM1},
4121     {Op6EM1},    {Op6FM1},    {Op70},      {Op71M1},    {Op72M1},
4122     {Op73M1},    {Op74M1},    {Op75M1},    {Op76M1},    {Op77M1},
4123     {Op78},      {Op79M1},    {Op7AX0},    {Op7B},      {Op7C},
4124     {Op7DM1},    {Op7EM1},    {Op7FM1},    {Op80},      {Op81M1},
4125     {Op82},      {Op83M1},    {Op84X0},    {Op85M1},    {Op86X0},
4126     {Op87M1},    {Op88X0},    {Op89M1},    {Op8AM1},    {Op8B},
4127     {Op8CX0},    {Op8DM1},    {Op8EX0},    {Op8FM1},    {Op90},
4128     {Op91M1},    {Op92M1},    {Op93M1},    {Op94X0},    {Op95M1},
4129     {Op96X0},    {Op97M1},    {Op98M1},    {Op99M1},    {Op9A},
4130     {Op9BX0},    {Op9CM1},    {Op9DM1},    {Op9EM1},    {Op9FM1},
4131     {OpA0X0},    {OpA1M1},    {OpA2X0},    {OpA3M1},    {OpA4X0},
4132     {OpA5M1},    {OpA6X0},    {OpA7M1},    {OpA8X0},    {OpA9M1},
4133     {OpAAX0},    {OpAB},      {OpACX0},    {OpADM1},    {OpAEX0},
4134     {OpAFM1},    {OpB0},      {OpB1M1},    {OpB2M1},    {OpB3M1},
4135     {OpB4X0},    {OpB5M1},    {OpB6X0},    {OpB7M1},    {OpB8},
4136     {OpB9M1},    {OpBAX0},    {OpBBX0},    {OpBCX0},    {OpBDM1},
4137     {OpBEX0},    {OpBFM1},    {OpC0X0},    {OpC1M1},    {OpC2},
4138     {OpC3M1},    {OpC4X0},    {OpC5M1},    {OpC6M1},    {OpC7M1},
4139     {OpC8X0},    {OpC9M1},    {OpCAX0},    {OpCB},      {OpCCX0},
4140     {OpCDM1},    {OpCEM1},    {OpCFM1},    {OpD0},      {OpD1M1},
4141     {OpD2M1},    {OpD3M1},    {OpD4},      {OpD5M1},    {OpD6M1},
4142     {OpD7M1},    {OpD8},      {OpD9M1},    {OpDAX0},    {OpDB},
4143     {OpDC},      {OpDDM1},    {OpDEM1},    {OpDFM1},    {OpE0X0},
4144     {OpE1M1},    {OpE2},      {OpE3M1},    {OpE4X0},    {OpE5M1},
4145     {OpE6M1},    {OpE7M1},    {OpE8X0},    {OpE9M1},    {OpEA},
4146     {OpEB},      {OpECX0},    {OpEDM1},    {OpEEM1},    {OpEFM1},
4147     {OpF0},      {OpF1M1},    {OpF2M1},    {OpF3M1},    {OpF4},
4148     {OpF5M1},    {OpF6M1},    {OpF7M1},    {OpF8},      {OpF9M1},
4149     {OpFAX0},    {OpFB},      {OpFC},      {OpFDM1},    {OpFEM1},
4150     {OpFFM1}
4151 };
4152
4153 struct SOpcodes S9xOpcodesM0X0[256] =
4154 {
4155     {Op00},      {Op01M0},    {Op02},      {Op03M0},    {Op04M0},
4156     {Op05M0},    {Op06M0},    {Op07M0},    {Op08},      {Op09M0},
4157     {Op0AM0},    {Op0B},      {Op0CM0},    {Op0DM0},    {Op0EM0},
4158     {Op0FM0},    {Op10},      {Op11M0},    {Op12M0},    {Op13M0},
4159     {Op14M0},    {Op15M0},    {Op16M0},    {Op17M0},    {Op18},
4160     {Op19M0},    {Op1AM0},    {Op1B},      {Op1CM0},    {Op1DM0},
4161     {Op1EM0},    {Op1FM0},    {Op20},      {Op21M0},    {Op22},
4162     {Op23M0},    {Op24M0},    {Op25M0},    {Op26M0},    {Op27M0},
4163     {Op28},      {Op29M0},    {Op2AM0},    {Op2B},      {Op2CM0},
4164     {Op2DM0},    {Op2EM0},    {Op2FM0},    {Op30},      {Op31M0},
4165     {Op32M0},    {Op33M0},    {Op34M0},    {Op35M0},    {Op36M0},
4166     {Op37M0},    {Op38},      {Op39M0},    {Op3AM0},    {Op3B},
4167     {Op3CM0},    {Op3DM0},    {Op3EM0},    {Op3FM0},    {Op40},
4168     {Op41M0},    {Op42},      {Op43M0},    {Op44X0},    {Op45M0},
4169     {Op46M0},    {Op47M0},    {Op48M0},    {Op49M0},    {Op4AM0},
4170     {Op4B},      {Op4C},      {Op4DM0},    {Op4EM0},    {Op4FM0},
4171     {Op50},      {Op51M0},    {Op52M0},    {Op53M0},    {Op54X0},
4172     {Op55M0},    {Op56M0},    {Op57M0},    {Op58},      {Op59M0},
4173     {Op5AX0},    {Op5B},      {Op5C},      {Op5DM0},    {Op5EM0},
4174     {Op5FM0},    {Op60},      {Op61M0},    {Op62},      {Op63M0},
4175     {Op64M0},    {Op65M0},    {Op66M0},    {Op67M0},    {Op68M0},
4176     {Op69M0},    {Op6AM0},    {Op6B},      {Op6C},      {Op6DM0},
4177     {Op6EM0},    {Op6FM0},    {Op70},      {Op71M0},    {Op72M0},
4178     {Op73M0},    {Op74M0},    {Op75M0},    {Op76M0},    {Op77M0},
4179     {Op78},      {Op79M0},    {Op7AX0},    {Op7B},      {Op7C},
4180     {Op7DM0},    {Op7EM0},    {Op7FM0},    {Op80},      {Op81M0},
4181     {Op82},      {Op83M0},    {Op84X0},    {Op85M0},    {Op86X0},
4182     {Op87M0},    {Op88X0},    {Op89M0},    {Op8AM0},    {Op8B},
4183     {Op8CX0},    {Op8DM0},    {Op8EX0},    {Op8FM0},    {Op90},
4184     {Op91M0},    {Op92M0},    {Op93M0},    {Op94X0},    {Op95M0},
4185     {Op96X0},    {Op97M0},    {Op98M0},    {Op99M0},    {Op9A},
4186     {Op9BX0},    {Op9CM0},    {Op9DM0},    {Op9EM0},    {Op9FM0},
4187     {OpA0X0},    {OpA1M0},    {OpA2X0},    {OpA3M0},    {OpA4X0},
4188     {OpA5M0},    {OpA6X0},    {OpA7M0},    {OpA8X0},    {OpA9M0},
4189     {OpAAX0},    {OpAB},      {OpACX0},    {OpADM0},    {OpAEX0},
4190     {OpAFM0},    {OpB0},      {OpB1M0},    {OpB2M0},    {OpB3M0},
4191     {OpB4X0},    {OpB5M0},    {OpB6X0},    {OpB7M0},    {OpB8},
4192     {OpB9M0},    {OpBAX0},    {OpBBX0},    {OpBCX0},    {OpBDM0},
4193     {OpBEX0},    {OpBFM0},    {OpC0X0},    {OpC1M0},    {OpC2},
4194     {OpC3M0},    {OpC4X0},    {OpC5M0},    {OpC6M0},    {OpC7M0},
4195     {OpC8X0},    {OpC9M0},    {OpCAX0},    {OpCB},      {OpCCX0},
4196     {OpCDM0},    {OpCEM0},    {OpCFM0},    {OpD0},      {OpD1M0},
4197     {OpD2M0},    {OpD3M0},    {OpD4},      {OpD5M0},    {OpD6M0},
4198     {OpD7M0},    {OpD8},      {OpD9M0},    {OpDAX0},    {OpDB},
4199     {OpDC},      {OpDDM0},    {OpDEM0},    {OpDFM0},    {OpE0X0},
4200     {OpE1M0},    {OpE2},      {OpE3M0},    {OpE4X0},    {OpE5M0},
4201     {OpE6M0},    {OpE7M0},    {OpE8X0},    {OpE9M0},    {OpEA},
4202     {OpEB},      {OpECX0},    {OpEDM0},    {OpEEM0},    {OpEFM0},
4203     {OpF0},      {OpF1M0},    {OpF2M0},    {OpF3M0},    {OpF4},
4204     {OpF5M0},    {OpF6M0},    {OpF7M0},    {OpF8},      {OpF9M0},
4205     {OpFAX0},    {OpFB},      {OpFC},      {OpFDM0},    {OpFEM0},
4206     {OpFFM0}
4207 };
4208
4209 struct SOpcodes S9xOpcodesM0X1[256] =
4210 {
4211     {Op00},      {Op01M0},    {Op02},      {Op03M0},    {Op04M0},
4212     {Op05M0},    {Op06M0},    {Op07M0},    {Op08},      {Op09M0},
4213     {Op0AM0},    {Op0B},      {Op0CM0},    {Op0DM0},    {Op0EM0},
4214     {Op0FM0},    {Op10},      {Op11M0},    {Op12M0},    {Op13M0},
4215     {Op14M0},    {Op15M0},    {Op16M0},    {Op17M0},    {Op18},
4216     {Op19M0},    {Op1AM0},    {Op1B},      {Op1CM0},    {Op1DM0},
4217     {Op1EM0},    {Op1FM0},    {Op20},      {Op21M0},    {Op22},
4218     {Op23M0},    {Op24M0},    {Op25M0},    {Op26M0},    {Op27M0},
4219     {Op28},      {Op29M0},    {Op2AM0},    {Op2B},      {Op2CM0},
4220     {Op2DM0},    {Op2EM0},    {Op2FM0},    {Op30},      {Op31M0},
4221     {Op32M0},    {Op33M0},    {Op34M0},    {Op35M0},    {Op36M0},
4222     {Op37M0},    {Op38},      {Op39M0},    {Op3AM0},    {Op3B},
4223     {Op3CM0},    {Op3DM0},    {Op3EM0},    {Op3FM0},    {Op40},
4224     {Op41M0},    {Op42},      {Op43M0},    {Op44X1},    {Op45M0},
4225     {Op46M0},    {Op47M0},    {Op48M0},    {Op49M0},    {Op4AM0},
4226     {Op4B},      {Op4C},      {Op4DM0},    {Op4EM0},    {Op4FM0},
4227     {Op50},      {Op51M0},    {Op52M0},    {Op53M0},    {Op54X1},
4228     {Op55M0},    {Op56M0},    {Op57M0},    {Op58},      {Op59M0},
4229     {Op5AX1},    {Op5B},      {Op5C},      {Op5DM0},    {Op5EM0},
4230     {Op5FM0},    {Op60},      {Op61M0},    {Op62},      {Op63M0},
4231     {Op64M0},    {Op65M0},    {Op66M0},    {Op67M0},    {Op68M0},
4232     {Op69M0},    {Op6AM0},    {Op6B},      {Op6C},      {Op6DM0},
4233     {Op6EM0},    {Op6FM0},    {Op70},      {Op71M0},    {Op72M0},
4234     {Op73M0},    {Op74M0},    {Op75M0},    {Op76M0},    {Op77M0},
4235     {Op78},      {Op79M0},    {Op7AX1},    {Op7B},      {Op7C},
4236     {Op7DM0},    {Op7EM0},    {Op7FM0},    {Op80},      {Op81M0},
4237     {Op82},      {Op83M0},    {Op84X1},    {Op85M0},    {Op86X1},
4238     {Op87M0},    {Op88X1},    {Op89M0},    {Op8AM0},    {Op8B},
4239     {Op8CX1},    {Op8DM0},    {Op8EX1},    {Op8FM0},    {Op90},
4240     {Op91M0},    {Op92M0},    {Op93M0},    {Op94X1},    {Op95M0},
4241     {Op96X1},    {Op97M0},    {Op98M0},    {Op99M0},    {Op9A},
4242     {Op9BX1},    {Op9CM0},    {Op9DM0},    {Op9EM0},    {Op9FM0},
4243     {OpA0X1},    {OpA1M0},    {OpA2X1},    {OpA3M0},    {OpA4X1},
4244     {OpA5M0},    {OpA6X1},    {OpA7M0},    {OpA8X1},    {OpA9M0},
4245     {OpAAX1},    {OpAB},      {OpACX1},    {OpADM0},    {OpAEX1},
4246     {OpAFM0},    {OpB0},      {OpB1M0},    {OpB2M0},    {OpB3M0},
4247     {OpB4X1},    {OpB5M0},    {OpB6X1},    {OpB7M0},    {OpB8},
4248     {OpB9M0},    {OpBAX1},    {OpBBX1},    {OpBCX1},    {OpBDM0},
4249     {OpBEX1},    {OpBFM0},    {OpC0X1},    {OpC1M0},    {OpC2},
4250     {OpC3M0},    {OpC4X1},    {OpC5M0},    {OpC6M0},    {OpC7M0},
4251     {OpC8X1},    {OpC9M0},    {OpCAX1},    {OpCB},      {OpCCX1},
4252     {OpCDM0},    {OpCEM0},    {OpCFM0},    {OpD0},      {OpD1M0},
4253     {OpD2M0},    {OpD3M0},    {OpD4},      {OpD5M0},    {OpD6M0},
4254     {OpD7M0},    {OpD8},      {OpD9M0},    {OpDAX1},    {OpDB},
4255     {OpDC},      {OpDDM0},    {OpDEM0},    {OpDFM0},    {OpE0X1},
4256     {OpE1M0},    {OpE2},      {OpE3M0},    {OpE4X1},    {OpE5M0},
4257     {OpE6M0},    {OpE7M0},    {OpE8X1},    {OpE9M0},    {OpEA},
4258     {OpEB},      {OpECX1},    {OpEDM0},    {OpEEM0},    {OpEFM0},
4259     {OpF0},      {OpF1M0},    {OpF2M0},    {OpF3M0},    {OpF4},
4260     {OpF5M0},    {OpF6M0},    {OpF7M0},    {OpF8},      {OpF9M0},
4261     {OpFAX1},    {OpFB},      {OpFC},      {OpFDM0},    {OpFEM0},
4262     {OpFFM0}
4263 };
4264