home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / atari / atari800-0.8.6 / cpu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-10  |  83.4 KB  |  2,870 lines

  1. /*
  2.    Ideas for Speed Improvements
  3.    ============================
  4.  
  5.    N = (result >= 128) could become N = NTAB[result];
  6.  
  7.    This saves the branch which breaks the
  8.    pipeline.
  9.  
  10.    Flags could be 0x00 or 0xff instead of 0x00 or 0x01
  11.  
  12.    This allows branches to be implemented as
  13.    follows :-
  14.  
  15.    BEQ  PC += (offset & Z)
  16.    BNE  PC += (offset & (~Z))
  17.  
  18.    again, this prevents the pipeline from
  19.    being broken.
  20.  
  21.    The 6502 emulation ignore memory attributes for
  22.    instruction fetch. This is because the instruction
  23.    must come from either RAM or ROM. A program that
  24.    executes instructions from within hardware
  25.    addresses will fail since there is never any
  26.    usable code there.
  27.  
  28.    The 6502 emulation also ignores memory attributes
  29.    for accesses to page 0 and page 1.
  30.  */
  31.  
  32. #include        <stdio.h>
  33. #include        <stdlib.h>
  34.  
  35. static char *rcsid = "$Id: cpu.c,v 1.22 1998/02/21 15:02:12 david Exp $";
  36.  
  37. #define FALSE   0
  38. #define TRUE    1
  39.  
  40. #include        "atari.h"
  41. #include        "cpu.h"
  42.  
  43. /*
  44.    ==========================================================
  45.    Emulated Registers and Flags are kept local to this module
  46.    ==========================================================
  47.  */
  48.  
  49. #define UPDATE_GLOBAL_REGS regPC=PC;regS=S;regA=A;regX=X;regY=Y
  50. #define UPDATE_LOCAL_REGS PC=regPC;S=regS;A=regA;X=regX;Y=regY
  51.  
  52. UWORD regPC;
  53. UBYTE regA;
  54. UBYTE regP;                                             /* Processor Status Byte (Partial) */
  55. UBYTE regS;
  56. UBYTE regX;
  57. UBYTE regY;
  58.  
  59. static UBYTE N;                                 /* bit7 zero (0) or bit 7 non-zero (1) */
  60. static UBYTE Z;                                 /* zero (0) or non-zero (1) */
  61. static UBYTE V;
  62. static UBYTE C;                                 /* zero (0) or one(1) */
  63.  
  64. #define RAM 0
  65. #define ROM 1
  66. #define HARDWARE 2
  67.  
  68. /*
  69.    #define PROFILE
  70.  */
  71.  
  72. #ifdef TRACE
  73. extern int tron;
  74. #endif
  75.  
  76. /*
  77.  * The following array is used for 6502 instruction profiling
  78.  */
  79.  
  80. int count[256];
  81.  
  82. UBYTE memory[65536];
  83.  
  84. UBYTE IRQ;
  85.  
  86. #ifdef MONITOR_BREAK
  87. UWORD remember_PC[REMEMBER_PC_STEPS];
  88. extern UWORD break_addr;
  89. #endif
  90.  
  91. static UBYTE attrib[65536];
  92. #define GetByte(addr)           ((attrib[addr] == HARDWARE) ? Atari800_GetByte(addr) : memory[addr])
  93. #define PutByte(addr,byte)      if (attrib[addr] == RAM) memory[addr] = byte; else if (attrib[addr] == HARDWARE) if (Atari800_PutByte(addr,byte)) break;
  94.  
  95. /*
  96.    ===============================================================
  97.    Z flag: This actually contains the result of an operation which
  98.    would modify the Z flag. The value is tested for
  99.    equality by the BEQ and BNE instruction.
  100.    ===============================================================
  101.  */
  102.  
  103. void CPU_GetStatus(void)
  104. {
  105.         if (N)
  106.                 SetN;
  107.         else
  108.                 ClrN;
  109.  
  110.         if (Z)
  111.                 ClrZ;
  112.         else
  113.                 SetZ;
  114.  
  115.         if (V)
  116.                 SetV;
  117.         else
  118.                 ClrV;
  119.  
  120.         if (C)
  121.                 SetC;
  122.         else
  123.                 ClrC;
  124. }
  125.  
  126. void CPU_PutStatus(void)
  127. {
  128.         if (regP & N_FLAG)
  129.                 N = 0x80;
  130.         else
  131.                 N = 0x00;
  132.  
  133.         if (regP & Z_FLAG)
  134.                 Z = 0;
  135.         else
  136.                 Z = 1;
  137.  
  138.         if (regP & V_FLAG)
  139.                 V = 1;
  140.         else
  141.                 V = 0;
  142.  
  143.         if (regP & C_FLAG)
  144.                 C = 1;
  145.         else
  146.                 C = 0;
  147. }
  148.  
  149. UBYTE BCDtoDEC[256];
  150. UBYTE DECtoBCD[256];
  151.  
  152. void CPU_Reset(void)
  153. {
  154.         int i;
  155.  
  156.         for (i = 0; i < 256; i++) {
  157.                 BCDtoDEC[i] = ((i >> 4) & 0xf) * 10 + (i & 0xf);
  158.                 DECtoBCD[i] = (((i % 100) / 10) << 4) | (i % 10);
  159. #ifdef PROFILE
  160.                 count[i] = 0;
  161. #endif
  162.         }
  163.  
  164.         IRQ = 0;
  165.  
  166.         regP = 0x20;                            /* The unused bit is always 1 */
  167.         regS = 0xff;
  168.         regPC = (GetByte(0xfffd) << 8) | GetByte(0xfffc);
  169. }
  170.  
  171. void SetRAM(int addr1, int addr2)
  172. {
  173.         int i;
  174.  
  175.         for (i = addr1; i <= addr2; i++) {
  176.                 attrib[i] = RAM;
  177.         }
  178. }
  179.  
  180. void SetROM(int addr1, int addr2)
  181. {
  182.         int i;
  183.  
  184.         for (i = addr1; i <= addr2; i++) {
  185.                 attrib[i] = ROM;
  186.         }
  187. }
  188.  
  189. void SetHARDWARE(int addr1, int addr2)
  190. {
  191.         int i;
  192.  
  193.         for (i = addr1; i <= addr2; i++) {
  194.                 attrib[i] = HARDWARE;
  195.         }
  196. }
  197.  
  198. #define AND(t_data) data = t_data; Z = N = A &= data
  199. #define CMP(t_data) data = t_data; Z = N = A - data; C = (A >= data)
  200. #define CPX(t_data) data = t_data; Z = N = X - data; C = (X >= data);
  201. #define CPY(t_data) data = t_data; Z = N = Y - data; C = (Y >= data);
  202. #define EOR(t_data) data = t_data; Z = N = A ^= data;
  203. #define LDA(data) Z = N = A = data;
  204. #define LDX(data) Z = N = X = data;
  205. #define LDY(data) Z = N = Y = data;
  206. #define ORA(t_data) data = t_data; Z = N = A |= data
  207.  
  208. #define PHP data =  (N & 0x80); \
  209.             data |= V ? 0x40 : 0; \
  210.             data |= (regP & 0x3c); \
  211.             data |= (Z == 0) ? 0x02 : 0; \
  212.             data |= C; \
  213.             memory[0x0100 + S--] = data;
  214.  
  215. #define PLP data = memory[0x0100 + ++S]; \
  216.             N = (data & 0x80); \
  217.             V = (data & 0x40) ? 1 : 0; \
  218.             Z = (data & 0x02) ? 0 : 1; \
  219.             C = (data & 0x01); \
  220.             regP = (data & 0x3c) | 0x20;
  221.  
  222. void NMI(void)
  223. {
  224.         UBYTE S = regS;
  225.         UBYTE data;
  226.  
  227.         memory[0x0100 + S--] = regPC >> 8;
  228.         memory[0x0100 + S--] = regPC & 0xff;
  229.         PHP;
  230.         SetI;
  231.         regPC = (memory[0xfffb] << 8) | memory[0xfffa];
  232.         regS = S;
  233. }
  234.  
  235. /*
  236.    ==============================================================
  237.    The first switch statement is used to determine the addressing
  238.    mode, while the second switch implements the opcode. When I
  239.    have more confidence that these are working correctly they
  240.    will be combined into a single switch statement. At the
  241.    moment changes can be made very easily.
  242.    ==============================================================
  243.  */
  244.  
  245. /* 0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F */
  246. int cycles[256] =
  247. {
  248.         7, 2, 2, 8, 3, 3, 5, 5, 3, 2, 2, 2, 4, 4, 6, 6,
  249.         2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7,
  250.         6, 6, 2, 8, 3, 3, 5, 5, 4, 2, 2, 2, 4, 4, 6, 6,
  251.         2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7,
  252.  
  253.         6, 6, 2, 8, 3, 3, 7, 5, 3, 2, 2, 2, 3, 4, 6, 6,
  254.         2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7,
  255.         6, 6, 2, 8, 3, 3, 5, 5, 4, 2, 2, 2, 5, 4, 6, 6,
  256.         2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7,
  257.  
  258.         2, 6, 2, 6, 3, 3, 3, 3, 2, 2, 2, 2, 4, 4, 4, 4,
  259.         2, 6, 2, 6, 4, 4, 4, 4, 2, 5, 2, 5, 5, 5, 5, 5,
  260.         2, 6, 2, 6, 3, 3, 3, 3, 2, 2, 2, 2, 4, 4, 4, 4,
  261.         2, 5, 2, 5, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 4, 4,
  262.  
  263.         2, 6, 2, 8, 3, 3, 5, 5, 2, 2, 2, 2, 4, 4, 6, 6,
  264.         2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7,
  265.         2, 6, 2, 8, 3, 3, 5, 5, 2, 2, 2, 2, 4, 4, 6, 6,
  266.         2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7
  267. };
  268.  
  269. void GO(int ncycles)
  270. {
  271. #ifdef GNU_C
  272.         static void *opcode[256] =
  273.         {
  274.                 &&opcode_00, &&opcode_01, &&opcode_02, &&opcode_03,
  275.                 &&opcode_04, &&opcode_05, &&opcode_06, &&opcode_07,
  276.                 &&opcode_08, &&opcode_09, &&opcode_0a, &&opcode_0b,
  277.                 &&opcode_0c, &&opcode_0d, &&opcode_0e, &&opcode_0f,
  278.  
  279.                 &&opcode_10, &&opcode_11, &&opcode_12, &&opcode_13,
  280.                 &&opcode_14, &&opcode_15, &&opcode_16, &&opcode_17,
  281.                 &&opcode_18, &&opcode_19, &&opcode_1a, &&opcode_1b,
  282.                 &&opcode_1c, &&opcode_1d, &&opcode_1e, &&opcode_1f,
  283.  
  284.                 &&opcode_20, &&opcode_21, &&opcode_22, &&opcode_23,
  285.                 &&opcode_24, &&opcode_25, &&opcode_26, &&opcode_27,
  286.                 &&opcode_28, &&opcode_29, &&opcode_2a, &&opcode_2b,
  287.                 &&opcode_2c, &&opcode_2d, &&opcode_2e, &&opcode_2f,
  288.  
  289.                 &&opcode_30, &&opcode_31, &&opcode_32, &&opcode_33,
  290.                 &&opcode_34, &&opcode_35, &&opcode_36, &&opcode_37,
  291.                 &&opcode_38, &&opcode_39, &&opcode_3a, &&opcode_3b,
  292.                 &&opcode_3c, &&opcode_3d, &&opcode_3e, &&opcode_3f,
  293.  
  294.                 &&opcode_40, &&opcode_41, &&opcode_42, &&opcode_43,
  295.                 &&opcode_44, &&opcode_45, &&opcode_46, &&opcode_47,
  296.                 &&opcode_48, &&opcode_49, &&opcode_4a, &&opcode_4b,
  297.                 &&opcode_4c, &&opcode_4d, &&opcode_4e, &&opcode_4f,
  298.  
  299.                 &&opcode_50, &&opcode_51, &&opcode_52, &&opcode_53,
  300.                 &&opcode_54, &&opcode_55, &&opcode_56, &&opcode_57,
  301.                 &&opcode_58, &&opcode_59, &&opcode_5a, &&opcode_5b,
  302.                 &&opcode_5c, &&opcode_5d, &&opcode_5e, &&opcode_5f,
  303.  
  304.                 &&opcode_60, &&opcode_61, &&opcode_62, &&opcode_63,
  305.                 &&opcode_64, &&opcode_65, &&opcode_66, &&opcode_67,
  306.                 &&opcode_68, &&opcode_69, &&opcode_6a, &&opcode_6b,
  307.                 &&opcode_6c, &&opcode_6d, &&opcode_6e, &&opcode_6f,
  308.  
  309.                 &&opcode_70, &&opcode_71, &&opcode_72, &&opcode_73,
  310.                 &&opcode_74, &&opcode_75, &&opcode_76, &&opcode_77,
  311.                 &&opcode_78, &&opcode_79, &&opcode_7a, &&opcode_7b,
  312.                 &&opcode_7c, &&opcode_7d, &&opcode_7e, &&opcode_7f,
  313.  
  314.                 &&opcode_80, &&opcode_81, &&opcode_82, &&opcode_83,
  315.                 &&opcode_84, &&opcode_85, &&opcode_86, &&opcode_87,
  316.                 &&opcode_88, &&opcode_89, &&opcode_8a, &&opcode_8b,
  317.                 &&opcode_8c, &&opcode_8d, &&opcode_8e, &&opcode_8f,
  318.  
  319.                 &&opcode_90, &&opcode_91, &&opcode_92, &&opcode_93,
  320.                 &&opcode_94, &&opcode_95, &&opcode_96, &&opcode_97,
  321.                 &&opcode_98, &&opcode_99, &&opcode_9a, &&opcode_9b,
  322.                 &&opcode_9c, &&opcode_9d, &&opcode_9e, &&opcode_9f,
  323.  
  324.                 &&opcode_a0, &&opcode_a1, &&opcode_a2, &&opcode_a3,
  325.                 &&opcode_a4, &&opcode_a5, &&opcode_a6, &&opcode_a7,
  326.                 &&opcode_a8, &&opcode_a9, &&opcode_aa, &&opcode_ab,
  327.                 &&opcode_ac, &&opcode_ad, &&opcode_ae, &&opcode_af,
  328.  
  329.                 &&opcode_b0, &&opcode_b1, &&opcode_b2, &&opcode_b3,
  330.                 &&opcode_b4, &&opcode_b5, &&opcode_b6, &&opcode_b7,
  331.                 &&opcode_b8, &&opcode_b9, &&opcode_ba, &&opcode_bb,
  332.                 &&opcode_bc, &&opcode_bd, &&opcode_be, &&opcode_bf,
  333.  
  334.                 &&opcode_c0, &&opcode_c1, &&opcode_c2, &&opcode_c3,
  335.                 &&opcode_c4, &&opcode_c5, &&opcode_c6, &&opcode_c7,
  336.                 &&opcode_c8, &&opcode_c9, &&opcode_ca, &&opcode_cb,
  337.                 &&opcode_cc, &&opcode_cd, &&opcode_ce, &&opcode_cf,
  338.  
  339.                 &&opcode_d0, &&opcode_d1, &&opcode_d2, &&opcode_d3,
  340.                 &&opcode_d4, &&opcode_d5, &&opcode_d6, &&opcode_d7,
  341.                 &&opcode_d8, &&opcode_d9, &&opcode_da, &&opcode_db,
  342.                 &&opcode_dc, &&opcode_dd, &&opcode_de, &&opcode_df,
  343.  
  344.                 &&opcode_e0, &&opcode_e1, &&opcode_e2, &&opcode_e3,
  345.                 &&opcode_e4, &&opcode_e5, &&opcode_e6, &&opcode_e7,
  346.                 &&opcode_e8, &&opcode_e9, &&opcode_ea, &&opcode_eb,
  347.                 &&opcode_ec, &&opcode_ed, &&opcode_ee, &&opcode_ef,
  348.  
  349.                 &&opcode_f0, &&opcode_f1, &&opcode_f2, &&opcode_f3,
  350.                 &&opcode_f4, &&opcode_f5, &&opcode_f6, &&opcode_f7,
  351.                 &&opcode_f8, &&opcode_f9, &&opcode_fa, &&opcode_fb,
  352.                 &&opcode_fc, &&opcode_fd, &&opcode_fe, &&opcode_ff,
  353.         };
  354. #endif
  355.  
  356.         UWORD PC;
  357.         UBYTE S;
  358.         UBYTE A;
  359.         UBYTE X;
  360.         UBYTE Y;
  361.  
  362.         UWORD addr;
  363.         UBYTE data;
  364.  
  365. /*
  366.    This used to be in the main loop but has been removed to improve
  367.    execution speed. It does not seem to have any adverse effect on
  368.    the emulation for two reasons:-
  369.  
  370.    1. NMI's will can only be raised in atari_custom.c - there is
  371.    no way an NMI can be generated whilst in this routine.
  372.  
  373.    2. The timing of the IRQs are not that critical.
  374.  */
  375.  
  376.         UPDATE_LOCAL_REGS;
  377.  
  378.         if (IRQ) {
  379.                 if (!(regP & I_FLAG)) {
  380.                         UWORD retadr = PC;
  381.  
  382.                         memory[0x0100 + S--] = retadr >> 8;
  383.                         memory[0x0100 + S--] = retadr & 0xff;
  384.                         PHP;
  385.                         SetI;
  386.                         PC = (memory[0xffff] << 8) | memory[0xfffe];
  387.                         IRQ = 0;
  388.                 }
  389.         }
  390.  
  391. /*
  392.    =====================================
  393.    Extract Address if Required by Opcode
  394.    =====================================
  395.  */
  396.  
  397. #define ABSOLUTE        addr=(memory[PC+1]<<8)+memory[PC];PC+=2;
  398. #define ZPAGE           addr=memory[PC++];
  399. #define ABSOLUTE_X      addr=((memory[PC+1]<<8)+memory[PC])+(UWORD)X;PC+=2;
  400. #define ABSOLUTE_Y      addr=((memory[PC+1]<<8)+memory[PC])+(UWORD)Y;PC+=2;
  401. #define INDIRECT_X      addr=(UWORD)memory[PC++]+(UWORD)X;addr=(memory[addr+1]<<8)+memory[addr];
  402. #define INDIRECT_Y      addr=memory[PC++];addr=(memory[addr+1]<<8)+memory[addr]+(UWORD)Y;
  403. #define ZPAGE_X         addr=(memory[PC++]+X)&0xff;
  404. #define ZPAGE_Y         addr=(memory[PC++]+Y)&0xff;
  405.  
  406. #ifdef __i386__
  407. #undef ABSOLUTE
  408. #undef ABSOLUTE_X
  409. #undef ABSOLUTE_Y
  410. #ifdef __ELF__
  411. #define ABSOLUTE asm("movw memory(%1),%0" \
  412.                      : "=r" (addr) \
  413.                      : "r" ((ULONG)PC)); PC+=2;
  414. #define ABSOLUTE_X asm("movw memory(%1),%0; addw %2,%0" \
  415.                        : "=r" (addr) \
  416.                        : "r" ((ULONG)PC), "r" ((UWORD)X));PC+=2;
  417. #define ABSOLUTE_Y asm("movw memory(%1),%0; addw %2,%0" \
  418.                        : "=r" (addr) \
  419.                        : "r" ((ULONG)PC), "r" ((UWORD)Y));PC+=2;
  420. #else
  421. #define ABSOLUTE asm("movw _memory(%1),%0" \
  422.                      : "=r" (addr) \
  423.                      : "r" ((ULONG)PC)); PC+=2;
  424. #define ABSOLUTE_X asm("movw _memory(%1),%0; addw %2,%0" \
  425.                        : "=r" (addr) \
  426.                        : "r" ((ULONG)PC), "r" ((UWORD)X));PC+=2;
  427. #define ABSOLUTE_Y asm("movw _memory(%1),%0; addw %2,%0" \
  428.                        : "=r" (addr) \
  429.                        : "r" ((ULONG)PC), "r" ((UWORD)Y));PC+=2;
  430. #endif
  431. #endif
  432.  
  433.         while (ncycles > 0) {
  434. #ifdef TRACE
  435.                 if (tron) {
  436.                         disassemble(PC, PC + 1);
  437.                         printf("\tA=%2x, X=%2x, Y=%2x, S=%2x\n",
  438.                                    A, X, Y, S);
  439.                 }
  440. #endif
  441.  
  442. #ifdef PROFILE
  443.                 count[memory[PC]]++;
  444. #endif
  445.  
  446. #ifdef MONITOR_BREAK
  447.                 memmove(&remember_PC[0], &remember_PC[1], (REMEMBER_PC_STEPS - 1) * 2);
  448.                 remember_PC[REMEMBER_PC_STEPS - 1] = PC;
  449.  
  450.                 if (break_addr == PC) {
  451.                         data = ESC_BREAK;
  452.                         UPDATE_GLOBAL_REGS;
  453.                         CPU_GetStatus();
  454.                         Escape(data);
  455.                         CPU_PutStatus();
  456.                         UPDATE_LOCAL_REGS;
  457.                 }
  458. #endif
  459.  
  460.                 ncycles -= cycles[memory[PC]];
  461.  
  462. #ifdef GNU_C
  463.                 goto *opcode[memory[PC++]];
  464. #else
  465.                 switch (memory[PC++]) {
  466.                 case 0x00:
  467.                         goto opcode_00;
  468.                 case 0x01:
  469.                         goto opcode_01;
  470.                 case 0x02:
  471.                         goto opcode_02;
  472.                 case 0x03:
  473.                         goto opcode_03;
  474.                 case 0x04:
  475.                         goto opcode_04;
  476.                 case 0x05:
  477.                         goto opcode_05;
  478.                 case 0x06:
  479.                         goto opcode_06;
  480.                 case 0x07:
  481.                         goto opcode_07;
  482.                 case 0x08:
  483.                         goto opcode_08;
  484.                 case 0x09:
  485.                         goto opcode_09;
  486.                 case 0x0a:
  487.                         goto opcode_0a;
  488.                 case 0x0b:
  489.                         goto opcode_0b;
  490.                 case 0x0c:
  491.                         goto opcode_0c;
  492.                 case 0x0d:
  493.                         goto opcode_0d;
  494.                 case 0x0e:
  495.                         goto opcode_0e;
  496.                 case 0x0f:
  497.                         goto opcode_0f;
  498.  
  499.                 case 0x10:
  500.                         goto opcode_10;
  501.                 case 0x11:
  502.                         goto opcode_11;
  503.                 case 0x12:
  504.                         goto opcode_12;
  505.                 case 0x13:
  506.                         goto opcode_13;
  507.                 case 0x14:
  508.                         goto opcode_14;
  509.                 case 0x15:
  510.                         goto opcode_15;
  511.                 case 0x16:
  512.                         goto opcode_16;
  513.                 case 0x17:
  514.                         goto opcode_17;
  515.                 case 0x18:
  516.                         goto opcode_18;
  517.                 case 0x19:
  518.                         goto opcode_19;
  519.                 case 0x1a:
  520.                         goto opcode_1a;
  521.                 case 0x1b:
  522.                         goto opcode_1b;
  523.                 case 0x1c:
  524.                         goto opcode_1c;
  525.                 case 0x1d:
  526.                         goto opcode_1d;
  527.                 case 0x1e:
  528.                         goto opcode_1e;
  529.                 case 0x1f:
  530.                         goto opcode_1f;
  531.  
  532.                 case 0x20:
  533.                         goto opcode_20;
  534.                 case 0x21:
  535.                         goto opcode_21;
  536.                 case 0x22:
  537.                         goto opcode_22;
  538.                 case 0x23:
  539.                         goto opcode_23;
  540.                 case 0x24:
  541.                         goto opcode_24;
  542.                 case 0x25:
  543.                         goto opcode_25;
  544.                 case 0x26:
  545.                         goto opcode_26;
  546.                 case 0x27:
  547.                         goto opcode_27;
  548.                 case 0x28:
  549.                         goto opcode_28;
  550.                 case 0x29:
  551.                         goto opcode_29;
  552.                 case 0x2a:
  553.                         goto opcode_2a;
  554.                 case 0x2b:
  555.                         goto opcode_2b;
  556.                 case 0x2c:
  557.                         goto opcode_2c;
  558.                 case 0x2d:
  559.                         goto opcode_2d;
  560.                 case 0x2e:
  561.                         goto opcode_2e;
  562.                 case 0x2f:
  563.                         goto opcode_2f;
  564.  
  565.                 case 0x30:
  566.                         goto opcode_30;
  567.                 case 0x31:
  568.                         goto opcode_31;
  569.                 case 0x32:
  570.                         goto opcode_32;
  571.                 case 0x33:
  572.                         goto opcode_33;
  573.                 case 0x34:
  574.                         goto opcode_34;
  575.                 case 0x35:
  576.                         goto opcode_35;
  577.                 case 0x36:
  578.                         goto opcode_36;
  579.                 case 0x37:
  580.                         goto opcode_37;
  581.                 case 0x38:
  582.                         goto opcode_38;
  583.                 case 0x39:
  584.                         goto opcode_39;
  585.                 case 0x3a:
  586.                         goto opcode_3a;
  587.                 case 0x3b:
  588.                         goto opcode_3b;
  589.                 case 0x3c:
  590.                         goto opcode_3c;
  591.                 case 0x3d:
  592.                         goto opcode_3d;
  593.                 case 0x3e:
  594.                         goto opcode_3e;
  595.                 case 0x3f:
  596.                         goto opcode_3f;
  597.  
  598.                 case 0x40:
  599.                         goto opcode_40;
  600.                 case 0x41:
  601.                         goto opcode_41;
  602.                 case 0x42:
  603.                         goto opcode_42;
  604.                 case 0x43:
  605.                         goto opcode_43;
  606.                 case 0x44:
  607.                         goto opcode_44;
  608.                 case 0x45:
  609.                         goto opcode_45;
  610.                 case 0x46:
  611.                         goto opcode_46;
  612.                 case 0x47:
  613.                         goto opcode_47;
  614.                 case 0x48:
  615.                         goto opcode_48;
  616.                 case 0x49:
  617.                         goto opcode_49;
  618.                 case 0x4a:
  619.                         goto opcode_4a;
  620.                 case 0x4b:
  621.                         goto opcode_4b;
  622.                 case 0x4c:
  623.                         goto opcode_4c;
  624.                 case 0x4d:
  625.                         goto opcode_4d;
  626.                 case 0x4e:
  627.                         goto opcode_4e;
  628.                 case 0x4f:
  629.                         goto opcode_4f;
  630.  
  631.                 case 0x50:
  632.                         goto opcode_50;
  633.                 case 0x51:
  634.                         goto opcode_51;
  635.                 case 0x52:
  636.                         goto opcode_52;
  637.                 case 0x53:
  638.                         goto opcode_53;
  639.                 case 0x54:
  640.                         goto opcode_54;
  641.                 case 0x55:
  642.                         goto opcode_55;
  643.                 case 0x56:
  644.                         goto opcode_56;
  645.                 case 0x57:
  646.                         goto opcode_57;
  647.                 case 0x58:
  648.                         goto opcode_58;
  649.                 case 0x59:
  650.                         goto opcode_59;
  651.                 case 0x5a:
  652.                         goto opcode_5a;
  653.                 case 0x5b:
  654.                         goto opcode_5b;
  655.                 case 0x5c:
  656.                         goto opcode_5c;
  657.                 case 0x5d:
  658.                         goto opcode_5d;
  659.                 case 0x5e:
  660.                         goto opcode_5e;
  661.                 case 0x5f:
  662.                         goto opcode_5f;
  663.  
  664.                 case 0x60:
  665.                         goto opcode_60;
  666.                 case 0x61:
  667.                         goto opcode_61;
  668.                 case 0x62:
  669.                         goto opcode_62;
  670.                 case 0x63:
  671.                         goto opcode_63;
  672.                 case 0x64:
  673.                         goto opcode_64;
  674.                 case 0x65:
  675.                         goto opcode_65;
  676.                 case 0x66:
  677.                         goto opcode_66;
  678.                 case 0x67:
  679.                         goto opcode_67;
  680.                 case 0x68:
  681.                         goto opcode_68;
  682.                 case 0x69:
  683.                         goto opcode_69;
  684.                 case 0x6a:
  685.                         goto opcode_6a;
  686.                 case 0x6b:
  687.                         goto opcode_6b;
  688.                 case 0x6c:
  689.                         goto opcode_6c;
  690.                 case 0x6d:
  691.                         goto opcode_6d;
  692.                 case 0x6e:
  693.                         goto opcode_6e;
  694.                 case 0x6f:
  695.                         goto opcode_6f;
  696.  
  697.                 case 0x70:
  698.                         goto opcode_70;
  699.                 case 0x71:
  700.                         goto opcode_71;
  701.                 case 0x72:
  702.                         goto opcode_72;
  703.                 case 0x73:
  704.                         goto opcode_73;
  705.                 case 0x74:
  706.                         goto opcode_74;
  707.                 case 0x75:
  708.                         goto opcode_75;
  709.                 case 0x76:
  710.                         goto opcode_76;
  711.                 case 0x77:
  712.                         goto opcode_77;
  713.                 case 0x78:
  714.                         goto opcode_78;
  715.                 case 0x79:
  716.                         goto opcode_79;
  717.                 case 0x7a:
  718.                         goto opcode_7a;
  719.                 case 0x7b:
  720.                         goto opcode_7b;
  721.                 case 0x7c:
  722.                         goto opcode_7c;
  723.                 case 0x7d:
  724.                         goto opcode_7d;
  725.                 case 0x7e:
  726.                         goto opcode_7e;
  727.                 case 0x7f:
  728.                         goto opcode_7f;
  729.  
  730.                 case 0x80:
  731.                         goto opcode_80;
  732.                 case 0x81:
  733.                         goto opcode_81;
  734.                 case 0x82:
  735.                         goto opcode_82;
  736.                 case 0x83:
  737.                         goto opcode_83;
  738.                 case 0x84:
  739.                         goto opcode_84;
  740.                 case 0x85:
  741.                         goto opcode_85;
  742.                 case 0x86:
  743.                         goto opcode_86;
  744.                 case 0x87:
  745.                         goto opcode_87;
  746.                 case 0x88:
  747.                         goto opcode_88;
  748.                 case 0x89:
  749.                         goto opcode_89;
  750.                 case 0x8a:
  751.                         goto opcode_8a;
  752.                 case 0x8b:
  753.                         goto opcode_8b;
  754.                 case 0x8c:
  755.                         goto opcode_8c;
  756.                 case 0x8d:
  757.                         goto opcode_8d;
  758.                 case 0x8e:
  759.                         goto opcode_8e;
  760.                 case 0x8f:
  761.                         goto opcode_8f;
  762.  
  763.                 case 0x90:
  764.                         goto opcode_90;
  765.                 case 0x91:
  766.                         goto opcode_91;
  767.                 case 0x92:
  768.                         goto opcode_92;
  769.                 case 0x93:
  770.                         goto opcode_93;
  771.                 case 0x94:
  772.                         goto opcode_94;
  773.                 case 0x95:
  774.                         goto opcode_95;
  775.                 case 0x96:
  776.                         goto opcode_96;
  777.                 case 0x97:
  778.                         goto opcode_97;
  779.                 case 0x98:
  780.                         goto opcode_98;
  781.                 case 0x99:
  782.                         goto opcode_99;
  783.                 case 0x9a:
  784.                         goto opcode_9a;
  785.                 case 0x9b:
  786.                         goto opcode_9b;
  787.                 case 0x9c:
  788.                         goto opcode_9c;
  789.                 case 0x9d:
  790.                         goto opcode_9d;
  791.                 case 0x9e:
  792.                         goto opcode_9e;
  793.                 case 0x9f:
  794.                         goto opcode_9f;
  795.  
  796.                 case 0xa0:
  797.                         goto opcode_a0;
  798.                 case 0xa1:
  799.                         goto opcode_a1;
  800.                 case 0xa2:
  801.                         goto opcode_a2;
  802.                 case 0xa3:
  803.                         goto opcode_a3;
  804.                 case 0xa4:
  805.                         goto opcode_a4;
  806.                 case 0xa5:
  807.                         goto opcode_a5;
  808.                 case 0xa6:
  809.                         goto opcode_a6;
  810.                 case 0xa7:
  811.                         goto opcode_a7;
  812.                 case 0xa8:
  813.                         goto opcode_a8;
  814.                 case 0xa9:
  815.                         goto opcode_a9;
  816.                 case 0xaa:
  817.                         goto opcode_aa;
  818.                 case 0xab:
  819.                         goto opcode_ab;
  820.                 case 0xac:
  821.                         goto opcode_ac;
  822.                 case 0xad:
  823.                         goto opcode_ad;
  824.                 case 0xae:
  825.                         goto opcode_ae;
  826.                 case 0xaf:
  827.                         goto opcode_af;
  828.  
  829.                 case 0xb0:
  830.                         goto opcode_b0;
  831.                 case 0xb1:
  832.                         goto opcode_b1;
  833.                 case 0xb2:
  834.                         goto opcode_b2;
  835.                 case 0xb3:
  836.                         goto opcode_b3;
  837.                 case 0xb4:
  838.                         goto opcode_b4;
  839.                 case 0xb5:
  840.                         goto opcode_b5;
  841.                 case 0xb6:
  842.                         goto opcode_b6;
  843.                 case 0xb7:
  844.                         goto opcode_b7;
  845.                 case 0xb8:
  846.                         goto opcode_b8;
  847.                 case 0xb9:
  848.                         goto opcode_b9;
  849.                 case 0xba:
  850.                         goto opcode_ba;
  851.                 case 0xbb:
  852.                         goto opcode_bb;
  853.                 case 0xbc:
  854.                         goto opcode_bc;
  855.                 case 0xbd:
  856.                         goto opcode_bd;
  857.                 case 0xbe:
  858.                         goto opcode_be;
  859.                 case 0xbf:
  860.                         goto opcode_bf;
  861.  
  862.                 case 0xc0:
  863.                         goto opcode_c0;
  864.                 case 0xc1:
  865.                         goto opcode_c1;
  866.                 case 0xc2:
  867.                         goto opcode_c2;
  868.                 case 0xc3:
  869.                         goto opcode_c3;
  870.                 case 0xc4:
  871.                         goto opcode_c4;
  872.                 case 0xc5:
  873.                         goto opcode_c5;
  874.                 case 0xc6:
  875.                         goto opcode_c6;
  876.                 case 0xc7:
  877.                         goto opcode_c7;
  878.                 case 0xc8:
  879.                         goto opcode_c8;
  880.                 case 0xc9:
  881.                         goto opcode_c9;
  882.                 case 0xca:
  883.                         goto opcode_ca;
  884.                 case 0xcb:
  885.                         goto opcode_cb;
  886.                 case 0xcc:
  887.                         goto opcode_cc;
  888.                 case 0xcd:
  889.                         goto opcode_cd;
  890.                 case 0xce:
  891.                         goto opcode_ce;
  892.                 case 0xcf:
  893.                         goto opcode_cf;
  894.  
  895.                 case 0xd0:
  896.                         goto opcode_d0;
  897.                 case 0xd1:
  898.                         goto opcode_d1;
  899.                 case 0xd2:
  900.                         goto opcode_d2;
  901.                 case 0xd3:
  902.                         goto opcode_d3;
  903.                 case 0xd4:
  904.                         goto opcode_d4;
  905.                 case 0xd5:
  906.                         goto opcode_d5;
  907.                 case 0xd6:
  908.                         goto opcode_d6;
  909.                 case 0xd7:
  910.                         goto opcode_d7;
  911.                 case 0xd8:
  912.                         goto opcode_d8;
  913.                 case 0xd9:
  914.                         goto opcode_d9;
  915.                 case 0xda:
  916.                         goto opcode_da;
  917.                 case 0xdb:
  918.                         goto opcode_db;
  919.                 case 0xdc:
  920.                         goto opcode_dc;
  921.                 case 0xdd:
  922.                         goto opcode_dd;
  923.                 case 0xde:
  924.                         goto opcode_de;
  925.                 case 0xdf:
  926.                         goto opcode_df;
  927.  
  928.                 case 0xe0:
  929.                         goto opcode_e0;
  930.                 case 0xe1:
  931.                         goto opcode_e1;
  932.                 case 0xe2:
  933.                         goto opcode_e2;
  934.                 case 0xe3:
  935.                         goto opcode_e3;
  936.                 case 0xe4:
  937.                         goto opcode_e4;
  938.                 case 0xe5:
  939.                         goto opcode_e5;
  940.                 case 0xe6:
  941.                         goto opcode_e6;
  942.                 case 0xe7:
  943.                         goto opcode_e7;
  944.                 case 0xe8:
  945.                         goto opcode_e8;
  946.                 case 0xe9:
  947.                         goto opcode_e9;
  948.                 case 0xea:
  949.                         goto opcode_ea;
  950.                 case 0xeb:
  951.                         goto opcode_eb;
  952.                 case 0xec:
  953.                         goto opcode_ec;
  954.                 case 0xed:
  955.                         goto opcode_ed;
  956.                 case 0xee:
  957.                         goto opcode_ee;
  958.                 case 0xef:
  959.                         goto opcode_ef;
  960.  
  961.                 case 0xf0:
  962.                         goto opcode_f0;
  963.                 case 0xf1:
  964.                         goto opcode_f1;
  965.                 case 0xf2:
  966.                         goto opcode_f2;
  967.                 case 0xf3:
  968.                         goto opcode_f3;
  969.                 case 0xf4:
  970.                         goto opcode_f4;
  971.                 case 0xf5:
  972.                         goto opcode_f5;
  973.                 case 0xf6:
  974.                         goto opcode_f6;
  975.                 case 0xf7:
  976.                         goto opcode_f7;
  977.                 case 0xf8:
  978.                         goto opcode_f8;
  979.                 case 0xf9:
  980.                         goto opcode_f9;
  981.                 case 0xfa:
  982.                         goto opcode_fa;
  983.                 case 0xfb:
  984.                         goto opcode_fb;
  985.                 case 0xfc:
  986.                         goto opcode_fc;
  987.                 case 0xfd:
  988.                         goto opcode_fd;
  989.                 case 0xfe:
  990.                         goto opcode_fe;
  991.                 case 0xff:
  992.                         goto opcode_ff;
  993.                 }
  994. #endif
  995.  
  996.           opcode_00:                            /* BRK */
  997.                 if (!(regP & I_FLAG)) {
  998.                         UWORD retadr = PC + 1;
  999.                         memory[0x0100 + S--] = retadr >> 8;
  1000.                         memory[0x0100 + S--] = retadr & 0xff;
  1001.                         SetB;
  1002.                         PHP;
  1003.                         SetI;
  1004.                         PC = (memory[0xffff] << 8) | memory[0xfffe];
  1005.                 }
  1006.                 goto next;
  1007.  
  1008.           opcode_01:                            /* ORA (ab,x) */
  1009.                 INDIRECT_X;
  1010.                 ORA(GetByte(addr));
  1011.                 goto next;
  1012.  
  1013.           opcode_04:                            /* SKB [unofficial - skip byte] */
  1014.                 PC++;
  1015.                 goto next;
  1016.  
  1017.           opcode_05:                            /* ORA ab */
  1018.                 ZPAGE;
  1019.                 ORA(memory[addr]);
  1020.                 goto next;
  1021.  
  1022.           opcode_06:                            /* ASL ab */
  1023.                 ZPAGE;
  1024.                 data = memory[addr];
  1025.                 C = (data & 0x80) ? 1 : 0;
  1026.                 Z = N = data << 1;
  1027.                 memory[addr] = Z;
  1028.                 goto next;
  1029.  
  1030.           opcode_08:                            /* PHP */
  1031.                 PHP;
  1032.                 goto next;
  1033.  
  1034.           opcode_09:                            /* ORA #ab */
  1035.                 ORA(memory[PC++]);
  1036.                 goto next;
  1037.  
  1038.           opcode_0a:                            /* ASL */
  1039.                 C = (A & 0x80) ? 1 : 0;
  1040.                 Z = N = A = A << 1;
  1041.                 goto next;
  1042.  
  1043.           opcode_0c:                            /* SKW [unofficial - skip word] */
  1044.                 PC += 2;
  1045.                 goto next;
  1046.  
  1047.           opcode_0d:                            /* ORA abcd */
  1048.                 ABSOLUTE;
  1049.                 ORA(GetByte(addr));
  1050.                 goto next;
  1051.  
  1052.           opcode_0e:                            /* ASL abcd */
  1053.                 ABSOLUTE;
  1054.                 data = GetByte(addr);
  1055.                 C = (data & 0x80) ? 1 : 0;
  1056.                 Z = N = data << 1;
  1057.                 PutByte(addr, Z);
  1058.                 goto next;
  1059.  
  1060.           opcode_10:                            /* BPL */
  1061.                 if (!(N & 0x80)) {
  1062.                         SBYTE sdata = memory[PC];
  1063.                         PC += (SWORD) sdata;
  1064.                 }
  1065.                 PC++;
  1066.                 goto next;
  1067.  
  1068.           opcode_11:                            /* ORA (ab),y */
  1069.                 INDIRECT_Y;
  1070.                 ORA(GetByte(addr));
  1071.                 goto next;
  1072.  
  1073.           opcode_14:                            /* SKB [unofficial - skip byte] */
  1074.                 PC++;
  1075.  
  1076.                 goto next;
  1077.  
  1078.  
  1079.           opcode_15:                            /* ORA ab,x */
  1080.                 ZPAGE_X;
  1081.                 ORA(memory[addr]);
  1082.                 goto next;
  1083.  
  1084.           opcode_16:                            /* ASL ab,x */
  1085.                 ZPAGE_X;
  1086.                 data = memory[addr];
  1087.                 C = (data & 0x80) ? 1 : 0;
  1088.                 Z = N = data << 1;
  1089.                 memory[addr] = Z;
  1090.                 goto next;
  1091.  
  1092.           opcode_18:                            /* CLC */
  1093.                 C = 0;
  1094.                 goto next;
  1095.  
  1096.           opcode_19:                            /* ORA abcd,y */
  1097.                 ABSOLUTE_Y;
  1098.                 ORA(GetByte(addr));
  1099.                 goto next;
  1100.  
  1101.           opcode_1a:                            /* NOP (1 byte) [unofficial] */
  1102.                 goto next;
  1103.  
  1104.           opcode_1c:                            /* SKW [unofficial - skip word] !RS! */
  1105.                 PC += 2;
  1106.  
  1107.                 goto next;
  1108.  
  1109.  
  1110.           opcode_1d:                            /* ORA abcd,x */
  1111.                 ABSOLUTE_X;
  1112.                 ORA(GetByte(addr));
  1113.                 goto next;
  1114.  
  1115.           opcode_1e:                            /* ASL abcd,x */
  1116.                 ABSOLUTE_X;
  1117.                 data = GetByte(addr);
  1118.                 C = (data & 0x80) ? 1 : 0;
  1119.                 Z = N = data << 1;
  1120.                 PutByte(addr, Z);
  1121.                 goto next;
  1122.  
  1123.           opcode_20:                            /* JSR abcd */
  1124.                 {
  1125.                         UWORD retadr = PC + 1;
  1126.                         memory[0x0100 + S--] = retadr >> 8;
  1127.                         memory[0x0100 + S--] = retadr & 0xff;
  1128.                         PC = (memory[PC + 1] << 8) | memory[PC];
  1129.                 }
  1130.                 goto next;
  1131.  
  1132.           opcode_21:                            /* AND (ab,x) */
  1133.                 INDIRECT_X;
  1134.                 AND(GetByte(addr));
  1135.                 goto next;
  1136.  
  1137.           opcode_24:                            /* BIT ab */
  1138.                 ZPAGE;
  1139.                 N = memory[addr];
  1140.                 V = N & 0x40;
  1141.                 Z = (A & N);
  1142.                 goto next;
  1143.  
  1144.           opcode_25:                            /* AND ab */
  1145.                 ZPAGE;
  1146.                 AND(memory[addr]);
  1147.                 goto next;
  1148.  
  1149.           opcode_26:                            /* ROL ab */
  1150.                 ZPAGE;
  1151.                 data = memory[addr];
  1152.                 if (C) {
  1153.                         C = (data & 0x80) ? 1 : 0;
  1154.                         Z = N = (data << 1) | 1;
  1155.                 }
  1156.                 else {
  1157.                         C = (data & 0x80) ? 1 : 0;
  1158.                         Z = N = (data << 1);
  1159.                 }
  1160.                 memory[addr] = Z;
  1161.                 goto next;
  1162.  
  1163.           opcode_28:                            /* PLP */
  1164.                 PLP;
  1165.                 goto next;
  1166.  
  1167.           opcode_29:                            /* AND #ab */
  1168.                 AND(memory[PC++]);
  1169.                 goto next;
  1170.  
  1171.           opcode_2a:                            /* ROL */
  1172.                 if (C) {
  1173.                         C = (A & 0x80) ? 1 : 0;
  1174.                         Z = N = A = (A << 1) | 1;
  1175.                 }
  1176.                 else {
  1177.                         C = (A & 0x80) ? 1 : 0;
  1178.                         Z = N = A = (A << 1);
  1179.                 }
  1180.                 goto next;
  1181.  
  1182.           opcode_2c:                            /* BIT abcd */
  1183.                 ABSOLUTE;
  1184.                 N = GetByte(addr);
  1185.                 V = N & 0x40;
  1186.                 Z = (A & N);
  1187.                 goto next;
  1188.  
  1189.           opcode_2d:                            /* AND abcd */
  1190.                 ABSOLUTE;
  1191.                 AND(GetByte(addr));
  1192.                 goto next;
  1193.  
  1194.           opcode_2e:                            /* ROL abcd */
  1195.                 ABSOLUTE;
  1196.                 data = GetByte(addr);
  1197.                 if (C) {
  1198.                         C = (data & 0x80) ? 1 : 0;
  1199.                         Z = N = (data << 1) | 1;
  1200.                 }
  1201.                 else {
  1202.                         C = (data & 0x80) ? 1 : 0;
  1203.                         Z = N = (data << 1);
  1204.                 }
  1205.                 PutByte(addr, Z);
  1206.                 goto next;
  1207.  
  1208.           opcode_30:                            /* BMI */
  1209.                 if (N & 0x80) {
  1210.                         SBYTE sdata = memory[PC];
  1211.                         PC += (SWORD) sdata;
  1212.                 }
  1213.                 PC++;
  1214.                 goto next;
  1215.  
  1216.           opcode_31:                            /* AND (ab),y */
  1217.                 INDIRECT_Y;
  1218.                 AND(GetByte(addr));
  1219.                 goto next;
  1220.  
  1221.           opcode_34:                            /* SKB [unofficial - skip byte] */
  1222.                 PC++;
  1223.  
  1224.                 goto next;
  1225.  
  1226.  
  1227.           opcode_35:                            /* AND ab,x */
  1228.                 ZPAGE_X;
  1229.                 AND(memory[addr]);
  1230.                 goto next;
  1231.  
  1232.           opcode_36:                            /* ROL ab,x */
  1233.                 ZPAGE_X;
  1234.                 data = memory[addr];
  1235.                 if (C) {
  1236.                         C = (data & 0x80) ? 1 : 0;
  1237.                         Z = N = (data << 1) | 1;
  1238.                 }
  1239.                 else {
  1240.                         C = (data & 0x80) ? 1 : 0;
  1241.                         Z = N = (data << 1);
  1242.                 }
  1243.                 memory[addr] = Z;
  1244.                 goto next;
  1245.  
  1246.           opcode_38:                            /* SEC */
  1247.                 C = 1;
  1248.                 goto next;
  1249.  
  1250.           opcode_39:                            /* AND abcd,y */
  1251.                 ABSOLUTE_Y;
  1252.                 AND(GetByte(addr));
  1253.                 goto next;
  1254.  
  1255.           opcode_3a:                            /* NOP (1 byte) [unofficial] */
  1256.                 goto next;
  1257.  
  1258.           opcode_3c:                            /* SKW [unofficial - skip word] */
  1259.                 PC += 2;
  1260.  
  1261.                 goto next;
  1262.  
  1263.  
  1264.           opcode_3d:                            /* AND abcd,x */
  1265.                 ABSOLUTE_X;
  1266.                 AND(GetByte(addr));
  1267.                 goto next;
  1268.  
  1269.           opcode_3e:                            /* ROL abcd,x */
  1270.                 ABSOLUTE_X;
  1271.                 data = GetByte(addr);
  1272.                 if (C) {
  1273.                         C = (data & 0x80) ? 1 : 0;
  1274.                         Z = N = (data << 1) | 1;
  1275.                 }
  1276.                 else {
  1277.                         C = (data & 0x80) ? 1 : 0;
  1278.                         Z = N = (data << 1);
  1279.                 }
  1280.                 PutByte(addr, Z);
  1281.                 goto next;
  1282.  
  1283.           opcode_40:                            /* RTI */
  1284.                 PLP;
  1285.                 data = memory[0x0100 + ++S];
  1286.                 PC = (memory[0x0100 + ++S] << 8) | data;
  1287.                 goto next;
  1288.  
  1289.           opcode_41:                            /* EOR (ab,x) */
  1290.                 INDIRECT_X;
  1291.                 EOR(GetByte(addr));
  1292.                 goto next;
  1293.  
  1294.           opcode_44:                            /* SKB [unofficial - skip byte] */
  1295.                 PC++;
  1296.  
  1297.                 goto next;
  1298.  
  1299.  
  1300.           opcode_45:                            /* EOR ab */
  1301.                 ZPAGE;
  1302.                 EOR(memory[addr]);
  1303.                 goto next;
  1304.  
  1305.           opcode_46:                            /* LSR ab */
  1306.                 ZPAGE;
  1307.                 data = memory[addr];
  1308.                 C = data & 1;
  1309.                 Z = data >> 1;
  1310.                 N = 0;
  1311.                 memory[addr] = Z;
  1312.                 goto next;
  1313.  
  1314.           opcode_48:                            /* PHA */
  1315.                 memory[0x0100 + S--] = A;
  1316.                 goto next;
  1317.  
  1318.           opcode_49:                            /* EOR #ab */
  1319.                 EOR(memory[PC++]);
  1320.                 goto next;
  1321.  
  1322.           opcode_4a:                            /* LSR */
  1323.                 C = A & 1;
  1324.                 A = A >> 1;
  1325.                 N = 0;
  1326.                 Z = A;
  1327.                 goto next;
  1328.  
  1329.           opcode_4c:                            /* JMP abcd */
  1330.                 PC = (memory[PC + 1] << 8) | memory[PC];
  1331.                 goto next;
  1332.  
  1333.           opcode_4d:                            /* EOR abcd */
  1334.                 ABSOLUTE;
  1335.                 EOR(GetByte(addr));
  1336.                 goto next;
  1337.  
  1338.           opcode_4e:                            /* LSR abcd */
  1339.                 ABSOLUTE;
  1340.                 data = GetByte(addr);
  1341.                 C = data & 1;
  1342.                 Z = data >> 1;
  1343.                 N = 0;
  1344.                 PutByte(addr, Z);
  1345.                 goto next;
  1346.  
  1347.           opcode_50:                            /* BVC */
  1348.                 if (!V) {
  1349.                         SBYTE sdata = memory[PC];
  1350.                         PC += (SWORD) sdata;
  1351.                 }
  1352.                 PC++;
  1353.                 goto next;
  1354.  
  1355.           opcode_51:                            /* EOR (ab),y */
  1356.                 INDIRECT_Y;
  1357.                 EOR(GetByte(addr));
  1358.                 goto next;
  1359.  
  1360.           opcode_54:                            /* SKB [unofficial - skip byte] */
  1361.                 PC++;
  1362.  
  1363.                 goto next;
  1364.  
  1365.  
  1366.           opcode_55:                            /* EOR ab,x */
  1367.                 ZPAGE_X;
  1368.                 EOR(memory[addr]);
  1369.                 goto next;
  1370.  
  1371.           opcode_56:                            /* LSR ab,x */
  1372.                 ZPAGE_X;
  1373.                 data = memory[addr];
  1374.                 C = data & 1;
  1375.                 Z = data >> 1;
  1376.                 N = 0;
  1377.                 memory[addr] = Z;
  1378.                 goto next;
  1379.  
  1380.           opcode_58:                            /* CLI */
  1381.                 ClrI;
  1382.                 if (IRQ) {                              /* check pending IRQ, helps in Lucasfilm games */
  1383.                         UWORD retadr = PC;
  1384.  
  1385.                         memory[0x0100 + S--] = retadr >> 8;
  1386.                         memory[0x0100 + S--] = retadr & 0xff;
  1387.                         PHP;
  1388.                         SetI;
  1389.                         PC = (memory[0xffff] << 8) | memory[0xfffe];
  1390.                         IRQ = 0;
  1391.                 }
  1392.                 goto next;
  1393.  
  1394.           opcode_59:                            /* EOR abcd,y */
  1395.                 ABSOLUTE_Y;
  1396.                 EOR(GetByte(addr));
  1397.                 goto next;
  1398.  
  1399.           opcode_5a:                            /* NOP (1 byte) [unofficial] */
  1400.                 goto next;
  1401.  
  1402.           opcode_5c:                            /* SKW [unofficial - skip word] */
  1403.                 PC += 2;
  1404.  
  1405.                 goto next;
  1406.  
  1407.  
  1408.           opcode_5d:                            /* EOR abcd,x */
  1409.                 ABSOLUTE_X;
  1410.                 EOR(GetByte(addr));
  1411.                 goto next;
  1412.  
  1413.           opcode_5e:                            /* LSR abcd,x */
  1414.                 ABSOLUTE_X;
  1415.                 data = GetByte(addr);
  1416.                 C = data & 1;
  1417.                 Z = data >> 1;
  1418.                 N = 0;
  1419.                 PutByte(addr, Z);
  1420.                 goto next;
  1421.  
  1422.           opcode_60:                            /* RTS */
  1423.                 data = memory[0x0100 + ++S];
  1424.                 PC = ((memory[0x0100 + ++S] << 8) | data) + 1;
  1425.                 goto next;
  1426.  
  1427.           opcode_61:                            /* ADC (ab,x) */
  1428.                 INDIRECT_X;
  1429.                 data = GetByte(addr);
  1430.                 goto adc;
  1431.  
  1432.           opcode_64:                            /* SKB [unofficial - skip byte] */
  1433.                 PC++;
  1434.  
  1435.                 goto next;
  1436.  
  1437.  
  1438.           opcode_65:                            /* ADC ab */
  1439.                 ZPAGE;
  1440.                 data = memory[addr];
  1441.                 goto adc;
  1442.  
  1443.           opcode_66:                            /* ROR ab */
  1444.                 ZPAGE;
  1445.                 data = memory[addr];
  1446.                 if (C) {
  1447.                         C = data & 1;
  1448.                         Z = N = (data >> 1) | 0x80;
  1449.                 }
  1450.                 else {
  1451.                         C = data & 1;
  1452.                         Z = N = (data >> 1);
  1453.                 }
  1454.                 memory[addr] = Z;
  1455.                 goto next;
  1456.  
  1457.           opcode_68:                            /* PLA */
  1458.                 Z = N = A = memory[0x0100 + ++S];
  1459.                 goto next;
  1460.  
  1461.           opcode_69:                            /* ADC #ab */
  1462.                 data = memory[PC++];
  1463.                 goto adc;
  1464.  
  1465.           opcode_6a:                            /* ROR */
  1466.                 if (C) {
  1467.                         C = A & 1;
  1468.                         Z = N = A = (A >> 1) | 0x80;
  1469.                 }
  1470.                 else {
  1471.                         C = A & 1;
  1472.                         Z = N = A = (A >> 1);
  1473.                 }
  1474.                 goto next;
  1475.  
  1476.           opcode_6c:                            /* JMP (abcd) */
  1477.                 addr = (memory[PC + 1] << 8) | memory[PC];
  1478. #ifdef M65C02
  1479.                 PC = (memory[addr + 1] << 8) | memory[addr];
  1480. #else                                                   /* original 6502 had a bug in jmp (addr) when addr crossed page boundary */
  1481.                 if ((addr & 0xff) == 0xff)
  1482.                         PC = (memory[addr & ~0xff] << 8) | memory[addr];
  1483.                 else
  1484.                         PC = (memory[addr + 1] << 8) | memory[addr];
  1485. #endif
  1486.                 goto next;
  1487.  
  1488.           opcode_6d:                            /* ADC abcd */
  1489.                 ABSOLUTE;
  1490.                 data = GetByte(addr);
  1491.                 goto adc;
  1492.  
  1493.           opcode_6e:                            /* ROR abcd */
  1494.                 ABSOLUTE;
  1495.                 data = GetByte(addr);
  1496.                 if (C) {
  1497.                         C = data & 1;
  1498.                         Z = N = (data >> 1) | 0x80;
  1499.                 }
  1500.                 else {
  1501.                         C = data & 1;
  1502.                         Z = N = (data >> 1);
  1503.                 }
  1504.                 PutByte(addr, Z);
  1505.                 goto next;
  1506.  
  1507.           opcode_70:                            /* BVS */
  1508.                 if (V) {
  1509.                         SBYTE sdata = memory[PC];
  1510.                         PC += (SWORD) sdata;
  1511.                 }
  1512.                 PC++;
  1513.                 goto next;
  1514.  
  1515.           opcode_71:                            /* ADC (ab),y */
  1516.                 INDIRECT_Y;
  1517.                 data = GetByte(addr);
  1518.                 goto adc;
  1519.  
  1520.           opcode_74:                            /* SKB [unofficial - skip byte] */
  1521.                 PC++;
  1522.  
  1523.                 goto next;
  1524.  
  1525.  
  1526.           opcode_75:                            /* ADC ab,x */
  1527.                 ZPAGE_X;
  1528.                 data = memory[addr];
  1529.                 goto adc;
  1530.  
  1531.           opcode_76:                            /* ROR ab,x */
  1532.                 ZPAGE_X;
  1533.                 data = memory[addr];
  1534.                 if (C) {
  1535.                         C = data & 1;
  1536.                         Z = N = (data >> 1) | 0x80;
  1537.                 }
  1538.                 else {
  1539.                         C = data & 1;
  1540.                         Z = N = (data >> 1);
  1541.                 }
  1542.                 memory[addr] = Z;
  1543.                 goto next;
  1544.  
  1545.           opcode_78:                            /* SEI */
  1546.                 SetI;
  1547.                 goto next;
  1548.  
  1549.           opcode_79:                            /* ADC abcd,y */
  1550.                 ABSOLUTE_Y;
  1551.                 data = GetByte(addr);
  1552.                 goto adc;
  1553.  
  1554.           opcode_7a:                            /* NOP (1 byte) [unofficial] */
  1555.                 goto next;
  1556.  
  1557.           opcode_7c:                            /* SKW [unofficial - skip word] */
  1558.                 PC += 2;
  1559.  
  1560.                 goto next;
  1561.  
  1562.  
  1563.           opcode_7d:                            /* ADC abcd,x */
  1564.                 ABSOLUTE_X;
  1565.                 data = GetByte(addr);
  1566.                 goto adc;
  1567.  
  1568.           opcode_7e:                            /* ROR abcd,x */
  1569.                 ABSOLUTE_X;
  1570.                 data = GetByte(addr);
  1571.                 if (C) {
  1572.                         C = data & 1;
  1573.                         Z = N = (data >> 1) | 0x80;
  1574.                 }
  1575.                 else {
  1576.                         C = data & 1;
  1577.                         Z = N = (data >> 1);
  1578.                 }
  1579.                 PutByte(addr, Z);
  1580.                 goto next;
  1581.  
  1582.           opcode_80:                            /* SKB [unofficial - skip byte] */
  1583.                 PC++;
  1584.  
  1585.                 goto next;
  1586.  
  1587.  
  1588.           opcode_81:                            /* STA (ab,x) */
  1589.                 INDIRECT_X;
  1590.                 PutByte(addr, A);
  1591.                 goto next;
  1592.  
  1593.           opcode_82:                            /* SKB [unofficial - skip byte] */
  1594.                 PC++;
  1595.  
  1596.                 goto next;
  1597.  
  1598.  
  1599.           opcode_84:                            /* STY ab */
  1600.                 ZPAGE;
  1601.                 memory[addr] = Y;
  1602.                 goto next;
  1603.  
  1604.           opcode_85:                            /* STA ab */
  1605.                 ZPAGE;
  1606.                 memory[addr] = A;
  1607.                 goto next;
  1608.  
  1609.           opcode_86:                            /* STX ab */
  1610.                 ZPAGE;
  1611.                 memory[addr] = X;
  1612.                 goto next;
  1613.  
  1614.           opcode_88:                            /* DEY */
  1615.                 Z = N = --Y;
  1616.                 goto next;
  1617.  
  1618.           opcode_8a:                            /* TXA */
  1619.                 Z = N = A = X;
  1620.                 goto next;
  1621.  
  1622.           opcode_8c:                            /* STY abcd */
  1623.                 ABSOLUTE;
  1624.                 PutByte(addr, Y);
  1625.                 goto next;
  1626.  
  1627.           opcode_8d:                            /* STA abcd */
  1628.                 ABSOLUTE;
  1629.                 PutByte(addr, A);
  1630.                 goto next;
  1631.  
  1632.           opcode_8e:                            /* STX abcd */
  1633.                 ABSOLUTE;
  1634.                 PutByte(addr, X);
  1635.                 goto next;
  1636.  
  1637.           opcode_90:                            /* BCC */
  1638.                 if (!C) {
  1639.                         SBYTE sdata = memory[PC];
  1640.                         PC += (SWORD) sdata;
  1641.                 }
  1642.                 PC++;
  1643.                 goto next;
  1644.  
  1645.           opcode_91:                            /* STA (ab),y */
  1646.                 INDIRECT_Y;
  1647.                 PutByte(addr, A);
  1648.                 goto next;
  1649.  
  1650.           opcode_94:                            /* STY ab,x */
  1651.                 ZPAGE_X;
  1652.                 memory[addr] = Y;
  1653.                 goto next;
  1654.  
  1655.           opcode_95:                            /* STA ab,x */
  1656.                 ZPAGE_X;
  1657.                 memory[addr] = A;
  1658.                 goto next;
  1659.  
  1660.           opcode_96:                            /* STX ab,y */
  1661.                 ZPAGE_Y;
  1662.                 PutByte(addr, X);
  1663.                 goto next;
  1664.  
  1665.           opcode_98:                            /* TYA */
  1666.                 Z = N = A = Y;
  1667.                 goto next;
  1668.  
  1669.           opcode_99:                            /* STA abcd,y */
  1670.                 ABSOLUTE_Y;
  1671.                 PutByte(addr, A);
  1672.                 goto next;
  1673.  
  1674.           opcode_9a:                            /* TXS */
  1675.                 S = X;
  1676.                 goto next;
  1677.  
  1678.           opcode_9d:                            /* STA abcd,x */
  1679.                 ABSOLUTE_X;
  1680.                 PutByte(addr, A);
  1681.                 goto next;
  1682.  
  1683.           opcode_a0:                            /* LDY #ab */
  1684.                 LDY(memory[PC++]);
  1685.                 goto next;
  1686.  
  1687.           opcode_a1:                            /* LDA (ab,x) */
  1688.                 INDIRECT_X;
  1689.                 LDA(GetByte(addr));
  1690.                 goto next;
  1691.  
  1692.           opcode_a2:                            /* LDX #ab */
  1693.                 LDX(memory[PC++]);
  1694.                 goto next;
  1695.  
  1696.           opcode_a3:                            /* LAX (ind,x) [unofficial] */
  1697.                 INDIRECT_X;
  1698.                 Z = N = X = A = GetByte(addr);
  1699.                 goto next;
  1700.  
  1701.           opcode_a4:                            /* LDY ab */
  1702.                 ZPAGE;
  1703.                 LDY(memory[addr]);
  1704.                 goto next;
  1705.  
  1706.           opcode_a5:                            /* LDA ab */
  1707.                 ZPAGE;
  1708.                 LDA(memory[addr]);
  1709.                 goto next;
  1710.  
  1711.           opcode_a6:                            /* LDX ab */
  1712.                 ZPAGE;
  1713.                 LDX(memory[addr]);
  1714.                 goto next;
  1715.  
  1716.           opcode_a7:                            /* LAX zpage [unofficial] */
  1717.                 ZPAGE;
  1718.                 Z = N = X = A = GetByte(addr);
  1719.                 goto next;
  1720.  
  1721.           opcode_a8:                            /* TAY */
  1722.                 Z = N = Y = A;
  1723.                 goto next;
  1724.  
  1725.           opcode_a9:                            /* LDA #ab */
  1726.                 LDA(memory[PC++]);
  1727.                 goto next;
  1728.  
  1729.           opcode_aa:                            /* TAX */
  1730.                 Z = N = X = A;
  1731.                 goto next;
  1732.  
  1733.           opcode_ac:                            /* LDY abcd */
  1734.                 ABSOLUTE;
  1735.                 LDY(GetByte(addr));
  1736.                 goto next;
  1737.  
  1738.           opcode_ad:                            /* LDA abcd */
  1739.                 ABSOLUTE;
  1740.                 LDA(GetByte(addr));
  1741.                 goto next;
  1742.  
  1743.           opcode_ae:                            /* LDX abcd */
  1744.                 ABSOLUTE;
  1745.                 LDX(GetByte(addr));
  1746.                 goto next;
  1747.  
  1748.           opcode_af:                            /* LAX absolute [unofficial] */
  1749.                 ABSOLUTE;
  1750.                 Z = N = X = A = GetByte(addr);
  1751.                 goto next;
  1752.  
  1753.           opcode_b0:                            /* BCS */
  1754.                 if (C) {
  1755.                         SBYTE sdata = memory[PC];
  1756.                         PC += (SWORD) sdata;
  1757.                 }
  1758.                 PC++;
  1759.                 goto next;
  1760.  
  1761.           opcode_b1:                            /* LDA (ab),y */
  1762.                 INDIRECT_Y;
  1763.                 LDA(GetByte(addr));
  1764.                 goto next;
  1765.  
  1766.           opcode_b3:                            /* LAX (ind),y [unofficial] */
  1767.                 INDIRECT_Y;
  1768.                 Z = N = X = A = GetByte(addr);
  1769.                 goto next;
  1770.  
  1771.           opcode_b4:                            /* LDY ab,x */
  1772.                 ZPAGE_X;
  1773.                 LDY(memory[addr]);
  1774.                 goto next;
  1775.  
  1776.           opcode_b5:                            /* LDA ab,x */
  1777.                 ZPAGE_X;
  1778.                 LDA(memory[addr]);
  1779.                 goto next;
  1780.  
  1781.           opcode_b6:                            /* LDX ab,y */
  1782.                 ZPAGE_Y;
  1783.                 LDX(GetByte(addr));
  1784.                 goto next;
  1785.  
  1786.           opcode_b7:                            /* LAX zpage,y [unofficial] */
  1787.                 ZPAGE_Y;
  1788.                 Z = N = X = A = GetByte(addr);
  1789.                 goto next;
  1790.  
  1791.           opcode_b8:                            /* CLV */
  1792.                 V = 0;
  1793.                 goto next;
  1794.  
  1795.           opcode_b9:                            /* LDA abcd,y */
  1796.                 ABSOLUTE_Y;
  1797.                 LDA(GetByte(addr));
  1798.                 goto next;
  1799.  
  1800.           opcode_ba:                            /* TSX */
  1801.                 Z = N = X = S;
  1802.                 goto next;
  1803.  
  1804.           opcode_bc:                            /* LDY abcd,x */
  1805.                 ABSOLUTE_X;
  1806.                 LDY(GetByte(addr));
  1807.                 goto next;
  1808.  
  1809.           opcode_bd:                            /* LDA abcd,x */
  1810.                 ABSOLUTE_X;
  1811.                 LDA(GetByte(addr));
  1812.                 goto next;
  1813.  
  1814.           opcode_be:                            /* LDX abcd,y */
  1815.                 ABSOLUTE_Y;
  1816.                 LDX(GetByte(addr));
  1817.                 goto next;
  1818.  
  1819.           opcode_bf:                            /* LAX absolute,y [unofficial] */
  1820.                 ABSOLUTE_Y;
  1821.                 Z = N = X = A = GetByte(addr);
  1822.                 goto next;
  1823.  
  1824.           opcode_c0:                            /* CPY #ab */
  1825.                 CPY(memory[PC++]);
  1826.                 goto next;
  1827.  
  1828.           opcode_c1:                            /* CMP (ab,x) */
  1829.                 INDIRECT_X;
  1830.                 CMP(GetByte(addr));
  1831.                 goto next;
  1832.  
  1833.           opcode_c2:                            /* SKB [unofficial - skip byte] */
  1834.                 PC++;
  1835.  
  1836.                 goto next;
  1837.  
  1838.  
  1839.           opcode_c4:                            /* CPY ab */
  1840.                 ZPAGE;
  1841.                 CPY(memory[addr]);
  1842.                 goto next;
  1843.  
  1844.           opcode_c5:                            /* CMP ab */
  1845.                 ZPAGE;
  1846.                 CMP(memory[addr]);
  1847.                 goto next;
  1848.  
  1849.           opcode_c6:                            /* DEC ab */
  1850.                 ZPAGE;
  1851.                 Z = N = --memory[addr];
  1852.                 goto next;
  1853.  
  1854.           opcode_c8:                            /* INY */
  1855.                 Z = N = ++Y;
  1856.                 goto next;
  1857.  
  1858.           opcode_c9:                            /* CMP #ab */
  1859.                 CMP(memory[PC++]);
  1860.                 goto next;
  1861.  
  1862.           opcode_ca:                            /* DEX */
  1863.                 Z = N = --X;
  1864.                 goto next;
  1865.  
  1866.           opcode_cc:                            /* CPY abcd */
  1867.                 ABSOLUTE;
  1868.                 CPY(GetByte(addr));
  1869.                 goto next;
  1870.  
  1871.           opcode_cd:                            /* CMP abcd */
  1872.                 ABSOLUTE;
  1873.                 CMP(GetByte(addr));
  1874.                 goto next;
  1875.  
  1876.           opcode_ce:                            /* DEC abcd */
  1877.                 ABSOLUTE;
  1878.                 Z = N = GetByte(addr) - 1;
  1879.                 PutByte(addr, Z);
  1880.                 goto next;
  1881.  
  1882.           opcode_d0:                            /* BNE */
  1883.                 if (Z) {
  1884.                         SBYTE sdata = memory[PC];
  1885.  
  1886.                         PC += (SWORD) sdata;
  1887.                 }
  1888.                 PC++;
  1889.                 goto next;
  1890.  
  1891.           opcode_d1:                            /* CMP (ab),y */
  1892.                 INDIRECT_Y;
  1893.                 CMP(GetByte(addr));
  1894.                 goto next;
  1895.  
  1896.           opcode_d4:                            /* SKB [unofficial - skip byte] */
  1897.                 PC++;
  1898.  
  1899.                 goto next;
  1900.  
  1901.  
  1902.           opcode_d5:                            /* CMP ab,x */
  1903.                 ZPAGE_X;
  1904.                 CMP(memory[addr]);
  1905.                 Z = N = A - data;
  1906.                 C = (A >= data);
  1907.                 goto next;
  1908.  
  1909.           opcode_d6:                            /* DEC ab,x */
  1910.                 ZPAGE_X;
  1911.                 Z = N = --memory[addr];
  1912.                 goto next;
  1913.  
  1914.           opcode_d8:                            /* CLD */
  1915.                 ClrD;
  1916.                 goto next;
  1917.  
  1918.           opcode_d9:                            /* CMP abcd,y */
  1919.                 ABSOLUTE_Y;
  1920.                 CMP(GetByte(addr));
  1921.                 goto next;
  1922.  
  1923.           opcode_da:                            /* NOP (1 byte) [unofficial] */
  1924.                 goto next;
  1925.  
  1926.           opcode_dc:                            /* SKW [unofficial - skip word] */
  1927.                 PC += 2;
  1928.                 goto next;
  1929.  
  1930.           opcode_dd:                            /* CMP abcd,x */
  1931.                 ABSOLUTE_X;
  1932.                 CMP(GetByte(addr));
  1933.                 goto next;
  1934.  
  1935.           opcode_de:                            /* DEC abcd,x */
  1936.                 ABSOLUTE_X;
  1937.                 Z = N = GetByte(addr) - 1;
  1938.                 PutByte(addr, Z);
  1939.                 goto next;
  1940.  
  1941.           opcode_e0:                            /* CPX #ab */
  1942.                 CPX(memory[PC++]);
  1943.                 goto next;
  1944.  
  1945.           opcode_e1:                            /* SBC (ab,x) */
  1946.                 INDIRECT_X;
  1947.                 data = GetByte(addr);
  1948.                 goto sbc;
  1949.  
  1950.           opcode_e2:                            /* SKB [unofficial - skip byte] */
  1951.                 PC++;
  1952.  
  1953.                 goto next;
  1954.  
  1955.  
  1956.           opcode_e4:                            /* CPX ab */
  1957.                 ZPAGE;
  1958.                 CPX(memory[addr]);
  1959.                 goto next;
  1960.  
  1961.           opcode_e5:                            /* SBC ab */
  1962.                 ZPAGE;
  1963.                 data = memory[addr];
  1964.                 goto sbc;
  1965.  
  1966.           opcode_e6:                            /* INC ab */
  1967.                 ZPAGE;
  1968.                 Z = N = ++memory[addr];
  1969.                 goto next;
  1970.  
  1971.           opcode_e8:                            /* INX */
  1972.                 Z = N = ++X;
  1973.                 goto next;
  1974.  
  1975.           opcode_e9:                            /* SBC #ab */
  1976.                 data = memory[PC++];
  1977.                 goto sbc;
  1978.  
  1979.           opcode_ea:                            /* NOP */
  1980.                 goto next;
  1981.  
  1982.           opcode_ec:                            /* CPX abcd */
  1983.                 ABSOLUTE;
  1984.                 CPX(GetByte(addr));
  1985.                 goto next;
  1986.  
  1987.           opcode_ed:                            /* SBC abcd */
  1988.                 ABSOLUTE;
  1989.                 data = GetByte(addr);
  1990.                 goto sbc;
  1991.  
  1992.           opcode_ee:                            /* INC abcd */
  1993.                 ABSOLUTE;
  1994.                 Z = N = GetByte(addr) + 1;
  1995.                 PutByte(addr, Z);
  1996.                 goto next;
  1997.  
  1998.           opcode_f0:                            /* BEQ */
  1999.                 if (!Z) {
  2000.                         SBYTE sdata = memory[PC];
  2001.                         PC += (SWORD) sdata;
  2002.                 }
  2003.                 PC++;
  2004.                 goto next;
  2005.  
  2006.           opcode_f1:                            /* SBC (ab),y */
  2007.                 INDIRECT_Y;
  2008.                 data = GetByte(addr);
  2009.                 goto sbc;
  2010.  
  2011.           opcode_f4:                            /* SKB [unofficial - skip byte] */
  2012.                 PC++;
  2013.  
  2014.                 goto next;
  2015.  
  2016.  
  2017.           opcode_f5:                            /* SBC ab,x */
  2018.                 ZPAGE_X;
  2019.                 data = memory[addr];
  2020.                 goto sbc;
  2021.  
  2022.           opcode_f6:                            /* INC ab,x */
  2023.                 ZPAGE_X;
  2024.                 Z = N = ++memory[addr];
  2025.                 goto next;
  2026.  
  2027.           opcode_f8:                            /* SED */
  2028.                 SetD;
  2029.                 goto next;
  2030.  
  2031.           opcode_f9:                            /* SBC abcd,y */
  2032.                 ABSOLUTE_Y;
  2033.                 data = GetByte(addr);
  2034.                 goto sbc;
  2035.  
  2036.           opcode_fa:                            /* NOP (1 byte) [unofficial] */
  2037.                 goto next;
  2038.  
  2039.           opcode_fc:                            /* SKW [unofficial - skip word] */
  2040.                 PC += 2;
  2041.  
  2042.                 goto next;
  2043.  
  2044.  
  2045.           opcode_fd:                            /* SBC abcd,x */
  2046.                 ABSOLUTE_X;
  2047.                 data = GetByte(addr);
  2048.                 goto sbc;
  2049.  
  2050.           opcode_fe:                            /* INC abcd,x */
  2051.                 ABSOLUTE_X;
  2052.                 Z = N = GetByte(addr) + 1;
  2053.                 PutByte(addr, Z);
  2054.                 goto next;
  2055.  
  2056.           opcode_d2:                            /* ESCRTS #ab (JAM) - on Atari is here instruction CIM [unofficial] !RS! */
  2057.                 data = memory[PC++];
  2058.                 UPDATE_GLOBAL_REGS;
  2059.                 CPU_GetStatus();
  2060.                 Escape(data);
  2061.                 CPU_PutStatus();
  2062.                 UPDATE_LOCAL_REGS;
  2063.                 data = memory[0x0100 + ++S];
  2064.                 PC = ((memory[0x0100 + ++S] << 8) | data) + 1;
  2065.                 goto next;
  2066.  
  2067.           opcode_f2:                            /* ESC #ab (JAM) - on Atari is here instruction CIM [unofficial] !RS! */
  2068.                 /* opcode_ff: ESC #ab - opcode FF is now used for INS [unofficial] instruction !RS! */
  2069.                 data = memory[PC++];
  2070.                 UPDATE_GLOBAL_REGS;
  2071.                 CPU_GetStatus();
  2072.                 Escape(data);
  2073.                 CPU_PutStatus();
  2074.                 UPDATE_LOCAL_REGS;
  2075.                 goto next;
  2076.  
  2077. /* R.S.980113
  2078.    My changes of original code is marked !RS!
  2079.    UNDOCUMENTED INSTRUCTIONS
  2080.    NOP (2 bytes) => SKB [unofficial - skip byte]
  2081.    NOP (3 bytes) => SKW [unofficial - skip word]
  2082.    CIM [unoficial - crash intermediate] => implemented as "PC--;"
  2083.    AXS [unofficial - Store result A AND X]
  2084.    ASO [unofficial - ASL then ORA with Acc]
  2085.    XAA [unofficial - X AND Mem to Acc]
  2086.    MKA [unofficial - Acc AND #$40 to Acc]
  2087.    MKX [unofficial - X AND #$40 to X]
  2088.  */
  2089.  
  2090.           opcode_02:                            /* CIM [unofficial - crash intermediate] */
  2091.           opcode_12:
  2092.           opcode_22:
  2093.           opcode_32:
  2094.           opcode_42:
  2095.           opcode_52:
  2096.           opcode_62:
  2097.           opcode_72:
  2098.           opcode_92:
  2099.           opcode_b2:
  2100.                 /* opcode_d2: Used for ESCRTS #ab (JAM) */
  2101.                 /* opcode_f2: Used for ESC #ab (JAM) */
  2102.                 PC--;
  2103.  
  2104.                 goto next;
  2105.  
  2106.  
  2107.           opcode_83:                            /* AXS (ab,x) [unofficial - Store result A AND X] */
  2108.                 INDIRECT_X;
  2109.  
  2110.                 Z = N = A & X;
  2111.  
  2112.                 PutByte(addr, Z);
  2113.  
  2114.                 goto next;
  2115.  
  2116.  
  2117.           opcode_87:                            /* AXS zpage [unofficial - Store result A AND X] */
  2118.                 ZPAGE;
  2119.  
  2120.                 Z = N = memory[addr] = A & X;
  2121.  
  2122.                 goto next;
  2123.  
  2124.  
  2125.           opcode_8f:                            /* AXS abcd [unofficial - Store result A AND X] */
  2126.                 ABSOLUTE;
  2127.  
  2128.                 Z = N = A & X;
  2129.  
  2130.                 PutByte(addr, Z);
  2131.  
  2132.                 goto next;
  2133.  
  2134.  
  2135.           opcode_93:                            /* AXS (ab),y [unofficial - Store result A AND X] */
  2136.                 INDIRECT_Y;
  2137.  
  2138.                 Z = N = A & X;
  2139.  
  2140.                 PutByte(addr, Z);
  2141.  
  2142.                 goto next;
  2143.  
  2144.  
  2145.           opcode_97:                            /* AXS zpage,y [unofficial - Store result A AND X] */
  2146.                 ZPAGE_Y;
  2147.  
  2148.                 Z = N = memory[addr] = A & X;
  2149.  
  2150.                 goto next;
  2151.  
  2152.  
  2153.           opcode_03:                            /* ASO (ab,x) [unofficial - ASL then ORA with Acc] */
  2154.                 INDIRECT_X;
  2155.  
  2156.                 data = GetByte(addr);
  2157.  
  2158.                 C = (data & 0x80) ? 1 : 0;
  2159.  
  2160.                 Z = N = A | (data << 1);
  2161.  
  2162.                 goto next;
  2163.  
  2164.  
  2165.           opcode_07:                            /* ASO zpage [unofficial - ASL then ORA with Acc] */
  2166.                 ZPAGE;
  2167.  
  2168.                 data = memory[addr];
  2169.  
  2170.                 C = (data & 0x80) ? 1 : 0;
  2171.  
  2172.                 Z = N = A | (data << 1);
  2173.  
  2174.                 goto next;
  2175.  
  2176.  
  2177.           opcode_0b:                            /* ASO #ab [unofficial - ASL then ORA with Acc] */
  2178.                 data = memory[PC++];
  2179.  
  2180.                 C = (data & 0x80) ? 1 : 0;
  2181.  
  2182.                 Z = N = A | (data << 1);
  2183.  
  2184.                 goto next;
  2185.  
  2186.  
  2187.           opcode_0f:                            /* ASO abcd [unofficial - ASL then ORA with Acc] */
  2188.                 ABSOLUTE;
  2189.  
  2190.                 data = GetByte(addr);
  2191.  
  2192.                 C = (data & 0x80) ? 1 : 0;
  2193.  
  2194.                 Z = N = A | (data << 1);
  2195.  
  2196.                 goto next;
  2197.  
  2198.  
  2199.           opcode_13:                            /* ASO (ab),y [unofficial - ASL then ORA with Acc] */
  2200.                 INDIRECT_Y;
  2201.  
  2202.                 data = GetByte(addr);
  2203.  
  2204.                 C = (data & 0x80) ? 1 : 0;
  2205.  
  2206.                 Z = N = A | (data << 1);
  2207.  
  2208.                 goto next;
  2209.  
  2210.  
  2211.           opcode_17:                            /* ASO zpage,x [unofficial - ASL then ORA with Acc] */
  2212.                 ZPAGE_X;
  2213.  
  2214.                 data = memory[addr];
  2215.  
  2216.                 C = (data & 0x80) ? 1 : 0;
  2217.  
  2218.                 Z = N = A | (data << 1);
  2219.  
  2220.                 goto next;
  2221.  
  2222.  
  2223.           opcode_1b:                            /* ASO abcd,y [unofficial - ASL then ORA with Acc] */
  2224.                 ABSOLUTE_Y;
  2225.  
  2226.                 data = GetByte(addr);
  2227.  
  2228.                 C = (data & 0x80) ? 1 : 0;
  2229.  
  2230.                 Z = N = A | (data << 1);
  2231.  
  2232.                 goto next;
  2233.  
  2234.  
  2235.           opcode_1f:                            /* ASO abcd,x [unofficial - ASL then ORA with Acc] */
  2236.                 ABSOLUTE_X;
  2237.  
  2238.                 data = GetByte(addr);
  2239.  
  2240.                 C = (data & 0x80) ? 1 : 0;
  2241.  
  2242.                 Z = N = A | (data << 1);
  2243.  
  2244.                 goto next;
  2245.  
  2246.  
  2247.           opcode_8b:                            /* XAA #ab [unofficial - X AND Mem to Acc] */
  2248.                 Z = N = A = X & memory[PC++];
  2249.  
  2250.                 goto next;
  2251.  
  2252.  
  2253.           opcode_9b:                            /* XAA abcd,y [unofficial - X AND Mem to Acc] */
  2254.                 ABSOLUTE_Y;
  2255.  
  2256.                 Z = N = A = X & GetByte(addr);
  2257.  
  2258.                 goto next;
  2259.  
  2260.  
  2261.           opcode_9f:                            /* MKA abcd [unofficial - Acc AND #$40 to Acc] */
  2262.                 ABSOLUTE;
  2263.  
  2264.                 Z = N = A &= 0x04;
  2265.  
  2266.                 goto next;
  2267.  
  2268.  
  2269.           opcode_9e:                            /* MKX abcd [unofficial - X AND #$40 to X] */
  2270.                 ABSOLUTE;
  2271.  
  2272.                 Z = N = X &= 0x04;
  2273.  
  2274.                 goto next;
  2275.  
  2276.  
  2277. /* UNDOCUMENTED INSTRUCTIONS (Part II)
  2278.    LSE [unofficial - LSR then EOR result with A]
  2279.    ALR [unofficial - Acc AND Data, LSR result]
  2280.    ARR [unofficial - Acc AND Data, ROR result]
  2281.  */
  2282.           opcode_43:                            /* LSE (ab,x) [unofficial - LSR then EOR result with A] */
  2283.                 INDIRECT_X;
  2284.  
  2285.                 data = GetByte(addr);
  2286.  
  2287.                 C = data & 1;
  2288.  
  2289.                 Z = N = A ^ (data >> 1);
  2290.  
  2291.                 goto next;
  2292.  
  2293.  
  2294.           opcode_47:                            /* LSE zpage [unofficial - LSR then EOR result with A] */
  2295.                 ZPAGE;
  2296.  
  2297.                 data = memory[addr];
  2298.  
  2299.                 C = data & 1;
  2300.  
  2301.                 Z = N = A ^ (data >> 1);
  2302.  
  2303.                 goto next;
  2304.  
  2305.  
  2306.           opcode_4f:                            /* LSE abcd [unofficial - LSR then EOR result with A] */
  2307.                 ABSOLUTE;
  2308.  
  2309.                 data = GetByte(addr);
  2310.  
  2311.                 C = data & 1;
  2312.  
  2313.                 Z = N = A ^ (data >> 1);
  2314.  
  2315.                 goto next;
  2316.  
  2317.  
  2318.           opcode_53:                            /* LSE (ab),y [unofficial - LSR then EOR result with A] */
  2319.                 INDIRECT_Y;
  2320.  
  2321.                 data = GetByte(addr);
  2322.  
  2323.                 C = data & 1;
  2324.  
  2325.                 Z = N = A ^ (data >> 1);
  2326.  
  2327.                 goto next;
  2328.  
  2329.  
  2330.           opcode_57:                            /* LSE zpage,x [unofficial - LSR then EOR result with A] */
  2331.                 ZPAGE_X;
  2332.  
  2333.                 data = memory[addr];
  2334.  
  2335.                 C = data & 1;
  2336.  
  2337.                 Z = N = A ^ (data >> 1);
  2338.  
  2339.                 goto next;
  2340.  
  2341.  
  2342.           opcode_5b:                            /* LSE abcd,y [unofficial - LSR then EOR result with A] */
  2343.                 ABSOLUTE_Y;
  2344.  
  2345.                 data = GetByte(addr);
  2346.  
  2347.                 C = data & 1;
  2348.  
  2349.                 Z = N = A ^ (data >> 1);
  2350.  
  2351.                 goto next;
  2352.  
  2353.  
  2354.           opcode_5f:                            /* LSE abcd,x [unofficial - LSR then EOR result with A] */
  2355.                 ABSOLUTE_X;
  2356.  
  2357.                 data = GetByte(addr);
  2358.  
  2359.                 C = data & 1;
  2360.  
  2361.                 Z = N = A ^ (data >> 1);
  2362.  
  2363.                 goto next;
  2364.  
  2365.  
  2366.           opcode_4b:                            /* ALR #ab [unofficial - Acc AND Data, LSR result] */
  2367.                 data = A & memory[PC++];
  2368.  
  2369.                 C = data & 1;
  2370.  
  2371.                 Z = N = (data >> 1);
  2372.  
  2373.                 goto next;
  2374.  
  2375.  
  2376.           opcode_6b:                            /* ARR #ab [unofficial - Acc AND Data, ROR result] */
  2377.                 data = A & memory[PC++];
  2378.  
  2379.                 if (C) {
  2380.  
  2381.                         C = data & 1;
  2382.  
  2383.                         Z = N = (data >> 1) | 0x80;
  2384.  
  2385.                 }
  2386.  
  2387.                 else {
  2388.  
  2389.                         C = data & 1;
  2390.  
  2391.                         Z = N = (data >> 1);
  2392.  
  2393.                 }
  2394.  
  2395.                 goto next;
  2396.  
  2397.  
  2398. /* UNDOCUMENTED INSTRUCTIONS (Part III)
  2399.    RLA [unofficial - ROL Mem, then AND with A]
  2400.  */
  2401.           opcode_23:                            /* RLA (ab,x) [unofficial - ROL Mem, then AND with A] */
  2402.                 INDIRECT_X;
  2403.  
  2404.           rla:
  2405.                 data = GetByte(addr);
  2406.  
  2407.                 if (C) {
  2408.  
  2409.                         C = (data & 0x80) ? 1 : 0;
  2410.                         Z = N = (data << 1) | 1;
  2411.  
  2412.                 }
  2413.  
  2414.                 else {
  2415.  
  2416.                         C = (data & 0x80) ? 1 : 0;
  2417.                         Z = N = (data << 1);
  2418.  
  2419.                 }
  2420.  
  2421.                 PutByte(addr, Z);
  2422.  
  2423.                 Z = N = A & Z;
  2424.  
  2425.                 goto next;
  2426.  
  2427.  
  2428.           opcode_27:                            /* RLA zpage [unofficial - ROL Mem, then AND with A] */
  2429.                 ZPAGE;
  2430.  
  2431.           rla_zpage:
  2432.                 data = memory[addr];
  2433.  
  2434.                 if (C) {
  2435.  
  2436.                         C = (data & 0x80) ? 1 : 0;
  2437.                         Z = N = (data << 1) | 1;
  2438.  
  2439.                 }
  2440.  
  2441.                 else {
  2442.  
  2443.                         C = (data & 0x80) ? 1 : 0;
  2444.                         Z = N = (data << 1);
  2445.  
  2446.                 }
  2447.  
  2448.                 memory[addr] = Z;
  2449.  
  2450.                 Z = N = A & Z;
  2451.  
  2452.                 goto next;
  2453.  
  2454.  
  2455.           opcode_2b:                            /* RLA #ab [unofficial - ROL Mem, then AND with A] */
  2456.                 data = memory[PC++];
  2457.  
  2458.                 if (C) {
  2459.  
  2460.                         C = (data & 0x80) ? 1 : 0;
  2461.                         Z = N = (data << 1) | 1;
  2462.  
  2463.                 }
  2464.  
  2465.                 else {
  2466.  
  2467.                         C = (data & 0x80) ? 1 : 0;
  2468.                         Z = N = (data << 1);
  2469.  
  2470.                 }
  2471.  
  2472.                 Z = N = A & Z;
  2473.  
  2474.                 goto next;
  2475.  
  2476.  
  2477.           opcode_2f:                            /* RLA abcd [unofficial - ROL Mem, then AND with A] */
  2478.                 ABSOLUTE;
  2479.  
  2480.                 goto rla;
  2481.  
  2482.  
  2483.           opcode_33:                            /* RLA (ab),y [unofficial - ROL Mem, then AND with A] */
  2484.                 INDIRECT_Y;
  2485.  
  2486.                 goto rla;
  2487.  
  2488.  
  2489.           opcode_37:                            /* RLA zpage,x [unofficial - ROL Mem, then AND with A] */
  2490.                 ZPAGE_X;
  2491.  
  2492.                 goto rla_zpage;
  2493.  
  2494.  
  2495.           opcode_3b:                            /* RLA abcd,y [unofficial - ROL Mem, then AND with A] */
  2496.                 ABSOLUTE_Y;
  2497.  
  2498.                 goto rla;
  2499.  
  2500.  
  2501.           opcode_3f:                            /* RLA abcd,x [unofficial - ROL Mem, then AND with A] */
  2502.                 ABSOLUTE_X;
  2503.  
  2504.                 goto rla;
  2505.  
  2506.  
  2507. /* R.S.980113<<<
  2508.    R.S.980114>>>
  2509.    RRA [unofficial - ROR Mem, then ADC to Acc]
  2510.  */
  2511.  
  2512.           opcode_63:                            /* RRA (ab,x) [unofficial - ROR Mem, then ADC to Acc] */
  2513.                 INDIRECT_X;
  2514.           rra:
  2515.                 data = GetByte(addr);
  2516.  
  2517.                 if (C) {
  2518.                         C = data & 1;
  2519.                         Z = N = (data >> 1) | 0x80;
  2520.                 }
  2521.  
  2522.                 else {
  2523.                         C = data & 1;
  2524.                         Z = N = (data >> 1);
  2525.                 }
  2526.  
  2527.                 PutByte(addr, Z);
  2528.  
  2529.                 goto adc;
  2530.  
  2531.  
  2532.           opcode_67:                            /* RRA zpage [unofficial - ROR Mem, then ADC to Acc] */
  2533.                 ZPAGE;
  2534.  
  2535.           rra_zpage:
  2536.                 data = memory[addr];
  2537.  
  2538.                 if (C) {
  2539.                         C = data & 1;
  2540.                         Z = N = (data >> 1) | 0x80;
  2541.                 }
  2542.  
  2543.                 else {
  2544.                         C = data & 1;
  2545.                         Z = N = (data >> 1);
  2546.                 }
  2547.  
  2548.                 memory[addr] = Z;
  2549.  
  2550.                 goto adc;
  2551.  
  2552.  
  2553.           opcode_6f:                            /* RRA abcd [unofficial - ROR Mem, then ADC to Acc] */
  2554.                 ABSOLUTE;
  2555.  
  2556.                 goto rra;
  2557.  
  2558.  
  2559.           opcode_73:                            /* RRA (ab),y [unofficial - ROR Mem, then ADC to Acc] */
  2560.                 INDIRECT_Y;
  2561.  
  2562.                 goto rra;
  2563.  
  2564.  
  2565.           opcode_77:                            /* RRA zpage,x [unofficial - ROR Mem, then ADC to Acc] */
  2566.                 ZPAGE_X;
  2567.  
  2568.                 goto rra_zpage;
  2569.  
  2570.  
  2571.           opcode_7b:                            /* RRA abcd,y [unofficial - ROR Mem, then ADC to Acc] */
  2572.                 ABSOLUTE_Y;
  2573.  
  2574.                 goto rra;
  2575.  
  2576.  
  2577.           opcode_7f:                            /* RRA abcd,x [unofficial - ROR Mem, then ADC to Acc] */
  2578.                 ABSOLUTE_X;
  2579.  
  2580.                 goto rra;
  2581.  
  2582.  
  2583. /* OAL [unofficial - ORA Acc with #$EE, then AND with data, then TAX] */
  2584.  
  2585.           opcode_ab:                            /* OAL #ab [unofficial - ORA Acc with #$EE, then AND with data, then TAX] */
  2586.                 A |= 0xEE;
  2587.  
  2588.                 A &= memory[PC++];
  2589.  
  2590.                 Z = N = X = A;
  2591.  
  2592.                 goto next;
  2593.  
  2594.  
  2595. /* DCM [unofficial - DEC Mem then CMP with Acc] */
  2596.  
  2597.           opcode_c3:                            /* DCM (ab,x) [unofficial - DEC Mem then CMP with Acc] */
  2598.                 INDIRECT_X;
  2599.  
  2600.           dcm:
  2601.                 data = GetByte(addr) - 1;
  2602.  
  2603.                 PutByte(addr, data);
  2604.  
  2605.                 CMP(data);
  2606.  
  2607.                 goto next;
  2608.  
  2609.  
  2610.           opcode_c7:                            /* DCM zpage [unofficial - DEC Mem then CMP with Acc] */
  2611.                 ZPAGE;
  2612.  
  2613.           dcm_zpage:
  2614.  
  2615.                 data = memory[addr] = memory[addr] - 1;
  2616.  
  2617.                 CMP(data);
  2618.  
  2619.                 goto next;
  2620.  
  2621.  
  2622.           opcode_cf:                            /* DCM abcd [unofficial - DEC Mem then CMP with Acc] */
  2623.                 ABSOLUTE;
  2624.  
  2625.                 goto dcm;
  2626.  
  2627.  
  2628.           opcode_d3:                            /* DCM (ab),y [unofficial - DEC Mem then CMP with Acc] */
  2629.                 INDIRECT_Y;
  2630.  
  2631.                 goto dcm;
  2632.  
  2633.  
  2634.           opcode_d7:                            /* DCM zpage,x [unofficial - DEC Mem then CMP with Acc] */
  2635.                 ZPAGE_X;
  2636.  
  2637.                 goto dcm_zpage;
  2638.  
  2639.  
  2640.           opcode_db:                            /* DCM abcd,y [unofficial - DEC Mem then CMP with Acc] */
  2641.                 ABSOLUTE_Y;
  2642.  
  2643.                 goto dcm;
  2644.  
  2645.  
  2646.           opcode_df:                            /* DCM abcd,x [unofficial - DEC Mem then CMP with Acc] */
  2647.                 ABSOLUTE_X;
  2648.  
  2649.                 goto dcm;
  2650.  
  2651.  
  2652. /* SAX   [unofficial - A AND X, then SBC Mem, store to X] */
  2653.  
  2654.           opcode_cb:                            /* SAX #ab [unofficial - A AND X, then SBC Mem, store to X] */
  2655.                 X = A & X;
  2656.  
  2657.                 data = memory[PC++];
  2658.  
  2659.                 if (!(regP & D_FLAG)) {
  2660.  
  2661.                         UWORD temp;
  2662.  
  2663.                         UWORD t_data;
  2664.  
  2665.  
  2666.                         t_data = (UWORD) data + (UWORD) ! C;
  2667.  
  2668.                         temp = (UWORD) X - t_data;
  2669.  
  2670.  
  2671.                         Z = N = temp & 0xff;
  2672.  
  2673.  
  2674.                         V = (~(X ^ t_data)) & (Z ^ X) & 0x80;
  2675.  
  2676.                         C = (temp > 255) ? 0 : 1;
  2677.  
  2678.                         X = Z;
  2679.  
  2680.                 }
  2681.  
  2682.                 else {
  2683.  
  2684.                         int bcd1, bcd2;
  2685.  
  2686.  
  2687.                         bcd1 = BCDtoDEC[X];
  2688.  
  2689.                         bcd2 = BCDtoDEC[data];
  2690.  
  2691.  
  2692.                         bcd1 = bcd1 - bcd2 - !C;
  2693.  
  2694.  
  2695.                         if (bcd1 < 0)
  2696.                                 bcd1 = 100 - (-bcd1);
  2697.  
  2698.                         Z = N = DECtoBCD[bcd1];
  2699.  
  2700.  
  2701.                         C = (X < (data + !C)) ? 0 : 1;
  2702.  
  2703.                         V = (Z ^ X) & 0x80;
  2704.  
  2705.                         X = Z;
  2706.  
  2707.                 }
  2708.  
  2709.                 goto next;
  2710.  
  2711.  
  2712. /* INS [unofficial - INC Mem then SBC with Acc] */
  2713.  
  2714.           opcode_e3:                            /* INS (ab,x) [unofficial - INC Mem then SBC with Acc] */
  2715.                 INDIRECT_X;
  2716.  
  2717.           ins:
  2718.                 data = Z = N = GetByte(addr) + 1;
  2719.  
  2720.                 PutByte(addr, data);
  2721.  
  2722.                 goto sbc;
  2723.  
  2724.  
  2725.           opcode_e7:                            /* INS zpage [unofficial - INC Mem then SBC with Acc] */
  2726.                 ZPAGE;
  2727.  
  2728.           ins_zpage:
  2729.                 data = Z = N = memory[addr] + 1;
  2730.  
  2731.                 memory[addr] = data;
  2732.  
  2733.                 goto sbc;
  2734.  
  2735.  
  2736.           opcode_ef:                            /* INS abcd [unofficial - INC Mem then SBC with Acc] */
  2737.                 ABSOLUTE;
  2738.  
  2739.                 goto ins;
  2740.  
  2741.           opcode_f3:                            /* INS (ab),y [unofficial - INC Mem then SBC with Acc] */
  2742.                 INDIRECT_Y;
  2743.  
  2744.                 goto ins;
  2745.  
  2746.  
  2747.           opcode_f7:                            /* INS zpage,x [unofficial - INC Mem then SBC with Acc] */
  2748.                 ZPAGE_X;
  2749.  
  2750.                 goto ins_zpage;
  2751.  
  2752.  
  2753.           opcode_fb:                            /* INS abcd,y [unofficial - INC Mem then SBC with Acc] */
  2754.                 ABSOLUTE_Y;
  2755.  
  2756.                 goto ins;
  2757.  
  2758.  
  2759.           opcode_ff:                            /* INS abcd,x [unofficial - INC Mem then SBC with Acc] */
  2760.                 ABSOLUTE_X;
  2761.  
  2762.                 goto ins;
  2763.  
  2764.  
  2765. /* R.S.980114<<< */
  2766.  
  2767.           opcode_89:                            /* SKB [unofficial - skip byte] */
  2768.                 PC++;
  2769.  
  2770.                 goto next;
  2771.  
  2772.  
  2773.           opcode_9c:                            /* SKW [unofficial - skip word] */
  2774.                 PC += 2;
  2775.  
  2776.                 goto next;
  2777.  
  2778.  
  2779. /* AXA [unofficial - original decode by R.Sterba and R.Petruzela 15.1.1998 :-)]
  2780.    AXA - this is our new imaginative name for instruction with opcode hex BB.
  2781.    AXA - Store Mem AND #$FD to Acc and X, then set stackpoint to value (Acc - 4)
  2782.    It's cool! :-)
  2783.  */
  2784.  
  2785.           opcode_bb:                            /* AXA abcd,y [unofficial - Store Mem AND #$FD to Acc and X, then set stackpoint to value (Acc - 4) */
  2786.                 ABSOLUTE_Y;
  2787.  
  2788.                 Z = N = A = X = GetByte(addr) & 0xFD;
  2789.                 S = ((UWORD) A - 4) & 0xFF;
  2790.  
  2791.                 goto next;
  2792.  
  2793.  
  2794.           opcode_eb:                            /* SBC #ab [unofficial] */
  2795.                 data = memory[PC++];
  2796.  
  2797.                 goto sbc;
  2798.  
  2799.  
  2800.           adc:
  2801.                 if (!(regP & D_FLAG)) {
  2802.                         UWORD temp;
  2803.                         UWORD t_data;
  2804.  
  2805.                         t_data = (UWORD) data + (UWORD) C;
  2806.                         Z = N = temp = (UWORD) A + t_data;
  2807.  
  2808.                         V = (~(A ^ t_data)) & (Z ^ A) & 0x80;
  2809.                         C = temp >> 8;
  2810.                         A = Z;
  2811.                 }
  2812.                 else {
  2813.                         int bcd1, bcd2;
  2814.  
  2815.                         bcd1 = BCDtoDEC[A];
  2816.                         bcd2 = BCDtoDEC[data];
  2817.  
  2818.                         bcd1 += bcd2 + C;
  2819.  
  2820.                         Z = N = DECtoBCD[bcd1];
  2821.  
  2822.                         V = (Z ^ A) & 0x80;
  2823.                         C = (bcd1 > 99);
  2824.                         A = Z;
  2825.                 }
  2826.                 goto next;
  2827.  
  2828.           sbc:
  2829.                 if (!(regP & D_FLAG)) {
  2830.                         UWORD temp;
  2831.                         UWORD t_data;
  2832.  
  2833.                         t_data = (UWORD) data + (UWORD) ! C;
  2834.                         temp = (UWORD) A - t_data;
  2835.  
  2836.                         Z = N = temp & 0xff;
  2837.  
  2838. /*
  2839.  * This was the old code that I have been using upto version 0.5.2
  2840.  *  C = (A < ((UWORD)data + (UWORD)!C)) ? 0 : 1;
  2841.  */
  2842.                         V = (~(A ^ t_data)) & (Z ^ A) & 0x80;
  2843.                         C = (temp > 255) ? 0 : 1;
  2844.                         A = Z;
  2845.                 }
  2846.                 else {
  2847.                         int bcd1, bcd2;
  2848.  
  2849.                         bcd1 = BCDtoDEC[A];
  2850.                         bcd2 = BCDtoDEC[data];
  2851.  
  2852.                         bcd1 = bcd1 - bcd2 - !C;
  2853.  
  2854.                         if (bcd1 < 0)
  2855.                                 bcd1 = 100 - (-bcd1);
  2856.                         Z = N = DECtoBCD[bcd1];
  2857.  
  2858.                         C = (A < (data + !C)) ? 0 : 1;
  2859.                         V = (Z ^ A) & 0x80;
  2860.                         A = Z;
  2861.                 }
  2862.                 goto next;
  2863.  
  2864.           next:
  2865.                 continue;
  2866.         }
  2867.  
  2868.         UPDATE_GLOBAL_REGS;
  2869. }
  2870.