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