unit KBComponent;

interface

Const
  Cycles6502 : Packed Array[0..255] Of Byte =
   (7,6,0,8,3,3,5,5, 3,2,2,2,4,4,6,6,  { 00-0F }
    2,5,0,8,4,4,6,6, 2,4,2,7,4,4,7,7,  { 10-1F }
    6,6,0,8,3,3,5,5, 4,2,2,2,4,4,6,6,  { 20-2F }
    2,5,0,8,4,4,6,6, 2,4,2,7,4,4,7,7,  { 30-3F }
    6,6,0,8,3,3,5,5, 3,2,2,2,3,4,6,6,  { 40-4F }
    2,5,0,8,4,4,6,6, 2,4,2,7,4,4,7,7,  { 50-5F }
    6,6,0,8,3,3,5,5, 4,2,2,2,5,4,6,6,  { 60-6F }
    2,5,0,8,4,4,6,6, 2,4,2,7,4,4,7,7,  { 70-7F }
    2,6,2,6,3,3,3,3, 2,2,2,2,4,4,4,4,  { 80-8F }
    2,6,0,6,4,4,4,4, 2,5,2,5,5,5,5,5,  { 90-9F }
    2,6,2,6,3,3,3,3, 2,2,2,2,4,4,4,4,  { A0-AF }
    2,5,0,5,4,4,4,4, 2,4,2,4,4,4,4,4,  { B0-BF }
    2,6,2,8,3,3,5,5, 2,2,2,2,4,4,6,6,  { C0-CF }
    2,5,0,8,4,4,6,6, 2,4,2,7,4,4,7,7,  { D0-DF }
    2,6,2,8,3,3,5,5, 2,2,2,2,4,4,6,6,  { E0-EF }
    2,5,0,8,4,4,6,6, 2,4,2,7,0,4,7,7); { F0-FF }

Type
  T6502Rec = Packed Record
    Cycles    : LongInt;
    AddCycle  : LongInt;
    PC        : Word;
    P         : Byte;
    A         : Byte;
    X         : Byte;
    Y         : Byte;
    S         : Byte;
    OldByte   : Byte;
    ResetOfs  : LongInt;
  End;

Var
  Game6502: T6502Rec;

Procedure Interpret6502(Var _Start: Word; Var _P,_A,_X,_Y,_S: Byte);
Procedure Perform6502Interrupt;

implementation

Uses Base,Equation6502,SysUtils,frmMainUnt,Keyboard,DirectX,   HexWrite;

Var
  Locations    : Packed Array[0..$FF] Of LongInt;
  SetLocations : Boolean;

Procedure Perform6502Interrupt;
Var H,L: Word;
Begin

  Mem6502[$4006] := Mem6502[$4006] Xor $80;

//  Randomize;
//  Mem6502[$4060] := Random(256);

//  Mem6502[$4060] := Mem6502[$4060] Xor $80;

{
  IntvMem[$8007] := IntvMem[$8007] Xor $80;
  Mem6502[$4007] := IntvMem[$8007];

  If (IntvMem[$8007] And $80) = 0 Then
  Begin
    IntvMem[$8006] := IntvMem[$8006] Xor $80;
    Mem6502[$4006] := IntvMem[$8006];
  End;

  If (IntvMem[$8006] And $80) = 0 Then
   Mem6502[$B7FE] := Mem6502[$B7FE] Xor $80;
}
  If (Game6502.P And 4) = 0 Then
  Begin

    If LogOutput Then WriteLn(LogFile,'6502 interrupt -- old PC = ',HexWord(Game6502.PC));

    Mem6502[Game6502.S + $100] := Hi(Game6502.PC);
    Dec(Game6502.S);
    Mem6502[Game6502.S + $100] := Lo(Game6502.PC);
    Dec(Game6502.S);
    Mem6502[Game6502.S + $100] := Game6502.P;
    Dec(Game6502.S);
    Game6502.P  := Game6502.P Or 4;                // Turn interrupts off
    H           := Mem6502[$DFFF];
    L           := Mem6502[$DFFE];
    Game6502.PC := (H Shl 8) + L;

    If LogOutput Then WriteLn(LogFile,'6502 interrupt -- new PC = ',HexWord(Game6502.PC));

  End;
End; // Perform6502_Interrupt

Procedure Handle_IO_Write(Addr,Value: Word);
Var _EDI : LongInt;
Begin
  Asm
    MOV   DWORD PTR _EDI,EDI
    SUB   DWORD PTR _EDI,Offset Mem6502
  End; // Asm

  ReadMem6502  := False;
  WriteMem6502 := True;
  RWMemLoc6502 := Addr;

  If LogOutput And
     ((Addr < $90) Or (Addr > $FFF)) And
     ((Addr < $4044) Or (Addr > $4047)) And
     ((Addr < $40C0) Or (Addr > $40CF)) And
     ((Addr < $4200) Or (Addr > $4FFF)) And
     ((Addr < $B800) Or (Addr > $DFFF)) Then

{  If LogOutput And
     ((Addr < $4044) Or (Addr > $4047)) And
     ((Addr < $40C0) Or (Addr > $40CF)) And
     (((Addr >= $4000) And (Addr < $4200)) Or
      ((Addr And $FF00) = $B700) Or
      ((Addr >= $DE) And (Addr <= $F0))) Then}
  Begin
    WriteLn(LogFile);
    WriteLn(LogFile,'6502: W[',HexWord(Addr),'] = ',HexByte(Value),' --- ',HexWord(_EDI));
  End;

  If (Addr >= $200) And (Addr <= $3FFF) Then
   IntvMem[$8000 + Addr] := (IntvMem[$8000 + Addr] And $300) + (Value And $FF);

  If (Addr >= $4200) And (Addr <= $7FFF) Then
   IntvMem[$4000 + Addr] := (IntvMem[$4000 + Addr] And $FF) + ((Value And 3) Shl 8);

  // Handle screen scrolling

  If Addr = $40CB Then
  Begin
    Inc(ScrollKBDC);
    If ScrollKBDC >= 24 Then ScrollKBDC := 0;
  End;

  // Prevent write to basic ROM

  If Addr = $E003 Then Mem6502[$E003] := 0;

{
  If (Addr >= $300) And (Addr <= $305) Then
   IntvMem[$8000 + (Addr - $0000)] := Value;
}
End; // Handle_IO_Write

//Var ReadK: Boolean;

Procedure Handle_IO_Read(Addr,Value: Word);
Var
  _EDI        : LongInt;
  I           : Integer;
  Found       : Boolean;
  B0,B1,B2,B3 : Byte;
  B           : Byte;
  U,S         : Byte;

Begin
  Asm
    MOV   DWORD PTR _EDI,EDI
    SUB   DWORD PTR _EDI,Offset Mem6502
  End; // Asm

  ReadMem6502  := True;
  WriteMem6502 := False;
  RWMemLoc6502 := Addr;

  If Addr = $4003 Then Mem6502[Addr] := $7F;

  If LogOutput And
     (Addr <> $4060) And
     ((Addr < $40C0) Or (Addr > $40CF)) And
     ((Addr >= $4000) And (Addr < $4200)) Or
     ((Addr And $FF00) = $B700) Then
   WriteLn(LogFile,'6502: R[',HexWord(Addr),'] = ',HexByte(Mem6502[Addr]),' --- ',HexWord(_EDI));

  If Addr = $4060 Then
  Begin
    B0 := Mem6502[$4044] And 1;
    B1 := Mem6502[$4045] And 1;
    B2 := Mem6502[$4046] And 1;
    B3 := Mem6502[$4047] And 1;
    B  := B0 + (B1 Shl 1) + (B2 Shl 2) + (B3 Shl 3);
    If ImportRead Then
    Begin
      If Not Eof(ImportFile) Then
      Begin
        If ImportCount = 0 Then
        Begin
          BlockRead(ImportFile,ImportKey,1);
          ImportCount := 1;
        End
        Else If ImportCount In [1,2] Then
        Begin
          U := ASCIIToKBDCUnshift[ImportKey];
          S := ASCIIToKBDCShift[ImportKey];
          If U <> ECSInvalidKey Then
          Begin
            If ImportCount = 1 Then
            Begin
              Mem6502[Addr] := $FF;
              If B = 0 Then Inc(ImportCount);
            End
            Else
            Begin
              If B = (U Shr 3) Then
              Begin
                Mem6502[Addr] := $FF Xor ($80 Shr (U And 7));
                Inc(ImportCount);
              End
              Else Mem6502[Addr] := $FF;
            End;
          End
          Else If S <> ECSInvalidKey Then
          Begin
            If ImportCount = 1 Then
            Begin
              If B = 0 Then
              Begin
                Mem6502[Addr] := $FE;
                Inc(ImportCount);
              End
              Else Mem6502[Addr] := $FF;
            End
            Else
            Begin
              If B = (S Shr 3) Then
              Begin
                Mem6502[Addr] := $FF Xor ($80 Shr (S And 7));
                Inc(ImportCount);
              End
              Else Mem6502[Addr] := $FF;
            End;  
          End
          Else
          Begin
            Mem6502[Addr] := $FF;
            Inc(ImportCount);
          End;
        End
        Else
        Begin
          Mem6502[Addr] := $FF;
          ImportCount   := (ImportCount + 1) And $F;
        End;
      End;
      If Eof(ImportFile) Then
      Begin
        CloseFile(ImportFile);
        Importing   := False;
        ImportRead  := False;
        ECSKey      := False;         { No key currently being typed in   }
        ImportKey   := ECSInvalidKey; { No key currently being typed in   }
        ImportShift := False;         { ECS Shift key not needed          }
        ECSDelay    := 0;             { Reset auto-repeat delay           }
        ECSPCKey    := 0;             { No PC keyboard key being pressed  }
        ImportCount := 0;
      End;
    End
    Else
    Begin
      I     := 0;
      Found := False;
      While (I < 8) And Not Found Do
      Begin
        If (KBDCKeyTable[B,I] <> 0) And
        frmMain.DXInput1.Keyboard.DIKeys[KBDCKeyTable[B,I]] Then Found := True Else Inc(I);
      End; // While
      If Found
       Then Mem6502[Addr] := $FF Xor ($80 Shr I)
       Else Mem6502[Addr] := $FF;
      If (frmMain.DXInput1.Keyboard.DIKeys[DIK_LSHIFT]  Or
          frmMain.DXInput1.Keyboard.DIKeys[DIK_RSHIFT]) And
         (B = 0)                                        Then
       Mem6502[Addr] := Mem6502[Addr] And $FE;

      If (frmMain.DXInput1.Keyboard.DIKeys[DIK_LCONTROL]  Or
          frmMain.DXInput1.Keyboard.DIKeys[DIK_RCONTROL]) And
         (Mem6502[$4044] = 0)                             Then
       Mem6502[Addr] := Mem6502[Addr] And $FD;
    End;
  End;
End; // Handle_IO_Read

Procedure ADC_BCD; Assembler;
{ In:   CL    - accumulator            }
{       DL    - value to add           }
{       Flags - carry is set correctly }
{ Out:  CL    - set on exit            }
{       CH    - set on exit            }
Asm
  PUSH   EBX
  PUSHF
  PUSH   EDX
  PUSHF
  AND    CH,03Ch
  MOV    BL,CL
  MOV    BH,CL
  SHR    BH,4
  AND    DL,0Fh
  AND    BL,0Fh
  POPF
  ADC    BL,DL
  POP    EDX
  PUSH   EDX
  SHR    DL,4
  ADD    BH,DL

  CMP    BL,9
  JBE    @L1
  ADD    BL,6         { Fixup the low nibble }
@L1:
  POP    EDX
  POPF
  PUSH   EDX

  ADC    DL,CL
  JNZ    @L2
  OR     CH,2         { Set the zero flag }
@L2:
  MOV    DL,BH
  SHL    DL,4
  AND    DL,80h
  OR     CH,DL        { Set the negative flag }

  MOV    DL,BH
  SHL    DL,4
  XOR    DL,CL
  AND    DL,80h
  JZ     @L3
  POP    EDX
  PUSH   EDX
  XOR    DL,CL
  AND    DL,80h
  JNZ    @L3
  OR     CH,40h       { Set the overflow flag }
@L3:
  POP    EDX

  TEST   BL,0F0h
  JZ     @L7
  INC    BH
@L7:
  CMP    BH,9
  JBE    @L4
  ADD    BH,6         { Fixup the high nibble }
@L4:

  TEST   BH,0F0h
  JZ     @L5
  OR     CH,1         { Set the carry flag }
@L5:

  SHL    BH,4
  AND    BL,0Fh
  OR     BL,BH
  MOV    CL,BL        { Set the result }
  POP    EBX
End; { ADC_BCD }


Procedure SBC_BCD; Assembler;
{ In:   CL    - accumulator            }
{       DL    - value to subtract      }
{       Flags - carry is set correctly }
{ Out:  CL    - set on exit            }
{       CH    - set on exit            }

Asm
  PUSH   EBX
  PUSHF
  PUSH   EDX
  PUSHF
  AND    CH,03Ch
  MOV    BL,CL
  MOV    BH,CL
  SHR    BH,4
  AND    DL,0Fh
  AND    BL,0Fh
  POPF
  SBB    BL,DL
  TEST   BL,0F0h      { TEST clears the carry flag }
  JZ     @L1
  SUB    BL,6
  AND    BL,0Fh
  STC
@L1:
  POP    EDX
  PUSH   EDX
  PUSHF
  SHR    DL,4
  POPF
  SBB    BH,DL
  TEST   BH,0F0h
  JZ     @L2
  SUB    BH,6
@L2:
  SHL    BH,4
  OR     BL,BH
  POP    EDX
  POPF
  MOV    BH,CL
  SBB    BH,DL
  JC     @L6          { Note the difference! }
  PUSHF
  OR     CH,1
  POPF
@L6:
  JNO    @L7
  OR     CH,40h
@L7:
  OR     BH,BH
  JNZ    @L8
  OR     CH,2
@L8:
  MOV    DL,BH
  AND    DL,80h
  ADD    CH,DL
  MOV    CL,BL
  POP    EBX
End; { SBC_BCD }

Procedure Interpret6502(Var _Start: Word; Var _P,_A,_X,_Y,_S: Byte);
Var
  P,A,X,Y,S : Byte;
  Start     : Word;

Label DoNothing,EmulateStart,EmulateLoop,DoneReadTime,GetOut,
      L00,L01,L02,L03,L04,L05,L06,L07,L08,L09,L0A,L0B,L0C,L0D,L0E,L0F,
      L10,L11,L12,L13,L14,L15,L16,L17,L18,L19,L1A,L1B,L1C,L1D,L1E,L1F,
      L20,L21,L22,L23,L24,L25,L26,L27,L28,L29,L2A,L2B,L2C,L2D,L2E,L2F,
      L30,L31,L32,L33,L34,L35,L36,L37,L38,L39,L3A,L3B,L3C,L3D,L3E,L3F,
      L40,L41,L42,L43,L44,L45,L46,L47,L48,L49,L4A,L4B,L4C,L4D,L4E,L4F,
      L50,L51,L52,L53,L54,L55,L56,L57,L58,L59,L5A,L5B,L5C,L5D,L5E,L5F,
      L60,L61,L62,L63,L64,L65,L66,L67,L68,L69,L6A,L6B,L6C,L6D,L6E,L6F,
      L70,L71,L72,L73,L74,L75,L76,L77,L78,L79,L7A,L7B,L7C,L7D,L7E,L7F,
      L80,L81,L82,L83,L84,L85,L86,L87,L88,L89,L8A,L8B,L8C,L8D,L8E,L8F,
      L90,L91,L92,L93,L94,L95,L96,L97,L98,L99,L9A,L9B,L9C,L9D,L9E,L9F,
      LA0,LA1,LA2,LA3,LA4,LA5,LA6,LA7,LA8,LA9,LAA,LAB,LAC,LAD,LAE,LAF,
      LB0,LB1,LB2,LB3,LB4,LB5,LB6,LB7,LB8,LB9,LBA,LBB,LBC,LBD,LBE,LBF,
      LC0,LC1,LC2,LC3,LC4,LC5,LC6,LC7,LC8,LC9,LCA,LCB,LCC,LCD,LCE,LCF,
      LD0,LD1,LD2,LD3,LD4,LD5,LD6,LD7,LD8,LD9,LDA,LDB,LDC,LDD,LDE,LDF,
      LE0,LE1,LE2,LE3,LE4,LE5,LE6,LE7,LE8,LE9,LEA,LEB,LEC,LED,LEE,LEF,
      LF0,LF1,LF2,LF3,LF4,LF5,LF6,LF7,LF8,LF9,LFA,LFB,LFC,LFD,LFE,LFF;

Begin

  { AL - X reg            AH - Y reg    }
  { BL - work             BH - work     }
  { CL - Accumulator      CH - Flags    }
  { DL - work             DH - Stack    }
  { SI - unused           DI - PC Reg   }
  { BP - used             SP - not used }

  P                   := _P;
  A                   := _A;
  X                   := _X;
  Y                   := _Y;
  S                   := _S;
  Start               := _Start;
//  Move(Mem6502,Game6502.TIA_Regs,SizeOf(Game6502.TIA_Regs));

  { Load locations here }

  Asm
    PUSHAD
    
    JMP   @Fill
@FillStart:
    DD    OFFSET L00
    DD    OFFSET L01
    DD    OFFSET L02
    DD    OFFSET L03
    DD    OFFSET L04
    DD    OFFSET L05
    DD    OFFSET L06
    DD    OFFSET L07
    DD    OFFSET L08
    DD    OFFSET L09
    DD    OFFSET L0A
    DD    OFFSET L0B
    DD    OFFSET L0C
    DD    OFFSET L0D
    DD    OFFSET L0E
    DD    OFFSET L0F

    DD    OFFSET L10
    DD    OFFSET L11
    DD    OFFSET DoNothing
    DD    OFFSET L13
    DD    OFFSET L14
    DD    OFFSET L15
    DD    OFFSET L16
    DD    OFFSET L17
    DD    OFFSET L18
    DD    OFFSET L19
    DD    OFFSET DoNothing
    DD    OFFSET L1B
    DD    OFFSET L1C
    DD    OFFSET L1D
    DD    OFFSET L1E
    DD    OFFSET L1F

    DD    OFFSET L20
    DD    OFFSET L21
    DD    OFFSET DoNothing
    DD    OFFSET L23
    DD    OFFSET L24
    DD    OFFSET L25
    DD    OFFSET L26
    DD    OFFSET L27
    DD    OFFSET L28
    DD    OFFSET L29
    DD    OFFSET L2A
    DD    OFFSET L2B
    DD    OFFSET L2C
    DD    OFFSET L2D
    DD    OFFSET L2E
    DD    OFFSET L2F

    DD    OFFSET L30
    DD    OFFSET L31
    DD    OFFSET DoNothing
    DD    OFFSET L33
    DD    OFFSET L34
    DD    OFFSET L35
    DD    OFFSET L36
    DD    OFFSET L37
    DD    OFFSET L38
    DD    OFFSET L39
    DD    OFFSET DoNothing
    DD    OFFSET L3B
    DD    OFFSET L3C
    DD    OFFSET L3D
    DD    OFFSET L3E
    DD    OFFSET L3F

    DD    OFFSET L40
    DD    OFFSET L41
    DD    OFFSET DoNothing
    DD    OFFSET L43
    DD    OFFSET L44
    DD    OFFSET L45
    DD    OFFSET L46
    DD    OFFSET L47
    DD    OFFSET L48
    DD    OFFSET L49
    DD    OFFSET L4A
    DD    OFFSET L4B
    DD    OFFSET L4C
    DD    OFFSET L4D
    DD    OFFSET L4E
    DD    OFFSET L4F

    DD    OFFSET L50
    DD    OFFSET L51
    DD    OFFSET DoNothing
    DD    OFFSET L53
    DD    OFFSET L54
    DD    OFFSET L55
    DD    OFFSET L56
    DD    OFFSET L57
    DD    OFFSET L58
    DD    OFFSET L59
    DD    OFFSET DoNothing
    DD    OFFSET L5B
    DD    OFFSET L5C
    DD    OFFSET L5D
    DD    OFFSET L5E
    DD    OFFSET L5F

    DD    OFFSET L60
    DD    OFFSET L61
    DD    OFFSET DoNothing
    DD    OFFSET L63
    DD    OFFSET L64
    DD    OFFSET L65
    DD    OFFSET L66
    DD    OFFSET L67
    DD    OFFSET L68
    DD    OFFSET L69
    DD    OFFSET L6A
    DD    OFFSET L6B
    DD    OFFSET L6C
    DD    OFFSET L6D
    DD    OFFSET L6E
    DD    OFFSET L6F

    DD    OFFSET L70
    DD    OFFSET L71
    DD    OFFSET DoNothing
    DD    OFFSET L73
    DD    OFFSET L74
    DD    OFFSET L75
    DD    OFFSET L76
    DD    OFFSET L77
    DD    OFFSET L78
    DD    OFFSET L79
    DD    OFFSET DoNothing
    DD    OFFSET L7B
    DD    OFFSET L7C
    DD    OFFSET L7D
    DD    OFFSET L7E
    DD    OFFSET L7F

    DD    OFFSET L80
    DD    OFFSET L81
    DD    OFFSET L82
    DD    OFFSET L83
    DD    OFFSET L84
    DD    OFFSET L85
    DD    OFFSET L86
    DD    OFFSET L87
    DD    OFFSET L88
    DD    OFFSET DoNothing
    DD    OFFSET L8A
    DD    OFFSET L8B
    DD    OFFSET L8C
    DD    OFFSET L8D
    DD    OFFSET L8E
    DD    OFFSET L8F

    DD    OFFSET L90
    DD    OFFSET L91
    DD    OFFSET DoNothing
    DD    OFFSET L93
    DD    OFFSET L94
    DD    OFFSET L95
    DD    OFFSET L96
    DD    OFFSET L97
    DD    OFFSET L98
    DD    OFFSET L99
    DD    OFFSET L9A
    DD    OFFSET L9B
    DD    OFFSET L9C
    DD    OFFSET L9D
    DD    OFFSET L9E
    DD    OFFSET L9F

    DD    OFFSET LA0
    DD    OFFSET LA1
    DD    OFFSET LA2
    DD    OFFSET LA3
    DD    OFFSET LA4
    DD    OFFSET LA5
    DD    OFFSET LA6
    DD    OFFSET LA7
    DD    OFFSET LA8
    DD    OFFSET LA9
    DD    OFFSET LAA
    DD    OFFSET LAB
    DD    OFFSET LAC
    DD    OFFSET LAD
    DD    OFFSET LAE
    DD    OFFSET LAF

    DD    OFFSET LB0
    DD    OFFSET LB1
    DD    OFFSET DoNothing
    DD    OFFSET LB3
    DD    OFFSET LB4
    DD    OFFSET LB5
    DD    OFFSET LB6
    DD    OFFSET LB7
    DD    OFFSET LB8
    DD    OFFSET LB9
    DD    OFFSET LBA
    DD    OFFSET LBB
    DD    OFFSET LBC
    DD    OFFSET LBD
    DD    OFFSET LBE
    DD    OFFSET LBF

    DD    OFFSET LC0
    DD    OFFSET LC1
    DD    OFFSET LC2
    DD    OFFSET LC3
    DD    OFFSET LC4
    DD    OFFSET LC5
    DD    OFFSET LC6
    DD    OFFSET LC7
    DD    OFFSET LC8
    DD    OFFSET LC9
    DD    OFFSET LCA
    DD    OFFSET LCB
    DD    OFFSET LCC
    DD    OFFSET LCD
    DD    OFFSET LCE
    DD    OFFSET LCF

    DD    OFFSET LD0
    DD    OFFSET LD1
    DD    OFFSET DoNothing
    DD    OFFSET LD3
    DD    OFFSET LD4
    DD    OFFSET LD5
    DD    OFFSET LD6
    DD    OFFSET LD7
    DD    OFFSET LD8
    DD    OFFSET LD9
    DD    OFFSET DoNothing
    DD    OFFSET LDB
    DD    OFFSET LDC
    DD    OFFSET LDD
    DD    OFFSET LDE
    DD    OFFSET LDF

    DD    OFFSET LE0
    DD    OFFSET LE1
    DD    OFFSET LE2
    DD    OFFSET LE3
    DD    OFFSET LE4
    DD    OFFSET LE5
    DD    OFFSET LE6
    DD    OFFSET LE7
    DD    OFFSET LE8
    DD    OFFSET LE9
    DD    OFFSET DoNothing
    DD    OFFSET LEB
    DD    OFFSET LEC
    DD    OFFSET LED
    DD    OFFSET LEE
    DD    OFFSET LEF

    DD    OFFSET LF0
    DD    OFFSET LF1
    DD    OFFSET DoNothing
    DD    OFFSET LF3
    DD    OFFSET LF4
    DD    OFFSET LF5
    DD    OFFSET LF6
    DD    OFFSET LF7
    DD    OFFSET LF8
    DD    OFFSET LF9
    DD    OFFSET DoNothing
    DD    OFFSET LFB
    DD    OFFSET LFC
    DD    OFFSET LFD
    DD    OFFSET LFE
    DD    OFFSET LFF
@Fill:
    TEST  BYTE PTR SetLocations,0FFh
    JNZ   @FillDone

    // Fill the Locations array with opcode code offsets

    MOV   ECX,100h
    SUB   EBX,EBX
    MOV   ESI,OFFSET @FillStart
    CLD
@FillLoop:
    MOV   EAX,DWORD PTR [ESI]
    MOV   DWORD PTR Locations[EBX],EAX
    ADD   ESI,4
    ADD   EBX,4
    LOOP  @FillLoop
    MOV   BYTE PTR SetLocations,1
@FillDone:

    // Load the 6507 register values

    MOVZX EDI,WORD PTR Start
    ADD   EDI,OFFSET Mem6502
    MOV   AL,BYTE PTR X
    MOV   AH,BYTE PTR Y
    MOV   CL,BYTE PTR A
    MOV   CH,BYTE PTR P
    MOV   DH,BYTE PTR S
    JMP   EmulateStart
DoNothing:
    INC   EDI

    // --------------------------------------------------------------
    // Main emulation loop
    // --------------------------------------------------------------

EmulateLoop:
    JMP   L02     // Get out

EmulateStart:

// -------------------------------

    { The write cycle is the last of the instruction cycles; add the }
    { instruction cycles first.                                      }

    MOV   EBX,DWORD PTR Game6502.AddCycle
    LEA   EBX,[EBX + EBX * 2]
    ADD   WORD PTR Game6502.Cycles,BX

    { Get the next instruction here to avoid a Pentium AGI }
    { (Address Generation Interlock)                       }

    MOV   ESI,DWORD PTR [EDI]
    SUB   EBX,EBX                  // Important
    AND   ESI,0FFh
    MOV   DL,BYTE PTR Cycles6502[ESI]
    SHL   ESI,2
    MOV   BYTE PTR Game6502.AddCycle,DL
    JMP   DWORD PTR Locations[ESI]
  End; { Asm }

{ --------------------------- Assembly emulator --------------------------- }

L00:                 { BRK }

  Asm
    DEC    DH
    MOV    BL,DH

    ADD    EDI,2
    SUB    EDI,OFFSET Mem6502

    PUSH   EDI
    MOV    WORD PTR Mem6502[EBX + 100h],DI

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX + 101h]
    MOV    EAX,EBX
    ADD    EAX,101h
    CALL   Handle_IO_Write
    POPAD

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX + 100h]
    MOV    EAX,EBX
    ADD    EAX,100h
    CALL   Handle_IO_Write
    POPAD

    POP    EDI

    ADD    EDI,OFFSET Mem6502

    MOV    WORD PTR Game6502.ResetOfs,-12

    DEC    BL
    MOV    BYTE PTR Mem6502[EBX + 100h],CH

    PUSHAD
    MOVZX  EDX,CH
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPAD

    SUB    DH,2
    OR     CH,014h
    MOV    DI,WORD PTR Mem6502[0CFFEh]    

    ADD    EDI,OFFSET Mem6502
    JMP    EmulateLoop
  End; { Asm }

L01:                 { ORA ind. x }

 Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AL
    MOV    BX,WORD PTR Mem6502[EBX]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    OR     CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L02:                 { Breakpoint instruction }

  Asm
    MOV   BYTE PTR X,AL
    MOV   BYTE PTR Y,AH
    MOV   BYTE PTR A,CL
    MOV   BYTE PTR P,CH
    MOV   BYTE PTR S,DH
    SUB   EDI,OFFSET Mem6502
    MOV   WORD PTR Start,DI
    POPAD
    JMP   GetOut
  End; { Asm }

L03:                 { SLO ind. x - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AL
    MOV    BX,WORD PTR Mem6502[EBX]
    AND    CH,07Ch

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    RCL    DL,1
    JNC    @L2a
    OR     CH,1
  @L2a:
    OR     DL,CL
    MOV    BYTE PTR Mem6502[EBX],DH

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    JZ     @L1
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L04:                 { SKB Quasi-Opcode }

  Asm
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L05:                 { ORA zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    AND    CH,07Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    OR     CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L06:                 { ASL zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SHL    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L07:                 { SLO zero page - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    AND    CH,07Ch

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    RCL    DL,1
    JNC    @L2a
    OR     CH,1
  @L2a:
    OR     DL,CL
    MOV    BYTE PTR Mem6502[EBX],DH

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    JZ     @L1
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L08:                 { PHP }

  Asm
    MOV    BL,DH
    MOV    BYTE PTR Mem6502[EBX + 100h],CH

    PUSHAD
    PUSHF
    MOVZX  EDX,CH
    MOV    EAX,EBX
    ADD    EAX,100h
    CALL   Handle_IO_Write
    POPF
    POPAD

    DEC    DH
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L09:                 { ORA immediate }

  Asm
    OR     CL,BYTE PTR [EDI+1]
    JZ     @L1
    MOV    DL,CL
    AND    CH,7Dh
    AND    DL,80h
    ADD    EDI,2
    ADD    CH,DL
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    OR     CH,02h
    JMP    EmulateLoop
  End; { Asm }

L0A:                 { ASL accum. }

  Asm
    OR     CH,3
    ADD    CL,CL
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    CH,7Dh
    AND    DL,80h
    INC    EDI
    ADD    CH,DL
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L0B:                 { ANC immediate - UNDOCUMENTED }

  Asm
    AND    CL,BYTE PTR [EDI+1]
    JZ     @L1
    MOV    DL,CL
    AND    CH,7Dh
    AND    DL,80h
    ADD    EDI,2
    ADD    CH,DL
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    OR     CH,02h
    JMP    EmulateLoop
  End; { Asm }

L0C:                 { SKW Quasi-Opcode }

  Asm
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L0D:                { ORA absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    OR     CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L0E:                 { ASL absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SHL    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L0F:                 { SLO absolute - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    AND    CH,07Ch

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    RCL    DL,1
    JNC    @L2a
    OR     CH,1
  @L2a:
    OR     DL,CL
    MOV    BYTE PTR Mem6502[EBX],DH

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    JZ     @L1
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L10:                 { BPL }

  Asm
    TEST   CH,80h
    JNZ    @L1
    MOVSX  EBX,BYTE PTR [EDI+1]
    ADD    EDI,2
    PUSH   EAX
    SUB    EDI,OFFSET Mem6502
    MOV    EAX,EDI
    ADD    EDI,EBX
    INC    DWORD PTR Game6502.AddCycle
    MOV    EBX,EDI
    ADD    EDI,OFFSET Mem6502
    CMP    BH,AH
    JE     @L2
    INC    DWORD PTR Game6502.AddCycle
@L2:
    POP    EAX
    JMP    EmulateLoop
@L1:
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L11:                 { ORA ind. y }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    OR     CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L12:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L13:                 { SLO ind. y - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    MOV    BL,BYTE PTR [EDI+1]
    AND    CH,07Ch

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    RCL    DL,1
    JNC    @L2a
    OR     CH,1
  @L2a:
    OR     DL,CL
    MOV    BYTE PTR Mem6502[EBX],DH

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    JZ     @L1
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L14:                 { SKB Quasi-Opcode }

  Asm
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L15:                 { ORA z. page x }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    OR     CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L16:                 { ASL z. page x }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SHL    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L17:                 { SLO z. page x - UNDOCUMENTED }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    RCL    DL,1
    JNC    @L2a
    OR     CH,1
  @L2a:
    OR     DL,CL
    MOV    BYTE PTR Mem6502[EBX],DH

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    JZ     @L1
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L18:                 { CLC }

  Asm
    AND    CH,0FEh
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L19:                 { ORA abs. y }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    OR     CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L1A:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L1B:                 { SLO abs. y - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    AND    CH,07Ch

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    RCL    DL,1
    JNC    @L2a
    OR     CH,1
  @L2a:
    OR     DL,CL
    MOV    BYTE PTR Mem6502[EBX],DH

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    JZ     @L1
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L1C:                 { SKW Quasi-Opcode }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    SETC   DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L1D:                 { ORA abs. x }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    OR     CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L1E:                 { ASL abs. x }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    ADC    BH,0

    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SHL    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L3:
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L1F:                 { SLO abs. x - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    AND    CH,07Ch

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    RCL    DL,1
    JNC    @L2a
    OR     CH,1
@L2a:
    OR     DL,CL
    MOV    BYTE PTR Mem6502[EBX],DH

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    JZ     @L1
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L20:                 { JSR }

  Asm
    DEC    DH
    MOV    BL,DH

    PUSH   EDI
    SUB    EDI,OFFSET Mem6502
    MOV    WORD PTR Mem6502[EBX + 100h],DI
    ADD    WORD PTR Mem6502[EBX + 100h],2

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX + 100h]
    MOV    EAX,EBX
    ADD    EAX,100h
    CALL   Handle_IO_Write
    POPF
    POPAD

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX + 101h]
    MOV    EAX,EBX
    ADD    EAX,101h
    CALL   Handle_IO_Write
    POPF
    POPAD

    POP    EDI
    DEC    DH
    MOVZX  EDI,WORD PTR [EDI+1]
    ADD    EDI,OFFSET Mem6502
    JMP    EmulateLoop
  End; { Asm }

L21:                 { AND ind. x }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AL
    MOV    BX,WORD PTR Mem6502[EBX]
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    AND    CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End;{ Asm }

L22:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L23:                 { RLA ind. x - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AL
    MOV    BX,WORD PTR Mem6502[EBX]
    AND    CH,7Dh
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    RCL    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    AND    CL,DL
    MOV    DL,CL
    OR     DL,DL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L24:                 { BIT zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    BL,BYTE PTR Mem6502[EBX]
    MOV    DL,BL
    AND    DL,CL
    JZ     @L1
    AND    CH,3Dh
    AND    BL,0C0h
    OR     CH,BL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    AND    CH,3Fh
    AND    BL,0C0h
    OR     CH,BL
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L25:                 { AND zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    AND    CH,7Dh
    AND    CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L26:                 { ROL zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPF
    POPAD

    RCL    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L27:                 { RLA zero page - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    RCL    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    AND    CL,DL
    MOV    DL,CL
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L28:                 { PLP }

  Asm
    INC    DH
    MOV    BL,DH

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX + 100h]
    MOV    EAX,EBX
    ADD    EAX,100h
    CALL   Handle_IO_Read
    POPAD

    MOV    CH,BYTE PTR Mem6502[EBX + 100h]
    OR     CH,20h
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L29:                 { AND immediate }

  Asm
    AND    CL,BYTE PTR [EDI+1]
    JZ     @L1
    MOV    DL,CL
    AND    CH,7Dh
    AND    DL,80h
    ADD    EDI,2
    ADD    CH,DL
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    OR     CH,02h
    JMP    EmulateLoop
  End; { Asm }

L2A:                 { ROL accum. }

  Asm
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1
    RCL    CL,1
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    CH,7Dh
    AND    DL,80h
    INC    EDI
    ADD    CH,DL
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L2B:                 { ANC immediate - UNDOCUMENTED }

  Asm
    AND    CL,BYTE PTR [EDI+1]
    JZ     @L1
    MOV    DL,CL
    AND    CH,7Dh
    AND    DL,80h
    ADD    EDI,2
    ADD    CH,DL
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    OR     CH,02h
    JMP    EmulateLoop
  End; { Asm }

L2C:                 { BIT absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    BL,BYTE PTR Mem6502[EBX]
    MOV    DL,BL
    AND    DL,CL
    JZ     @L1
    AND    CH,3Dh
    AND    BL,0C0h
    OR     CH,BL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    AND    CH,3Fh
    AND    BL,0C0h
    OR     CH,BL
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L2D:                 { AND absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    AND    CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L2E:                 { ROL absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPF
    POPAD

    RCL    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L2F:                 { RLA absolute - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    RCL    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    AND    CL,DL
    MOV    DL,CL
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L30:                 { BMI }

  Asm
    TEST   CH,80h
    JZ     @L1
    MOVSX  EBX,BYTE PTR [EDI+1] 
    ADD    EDI,2
    PUSH   EAX
    SUB    EDI,OFFSET Mem6502
    MOV    EAX,EDI
    ADD    EDI,EBX
    INC    DWORD PTR Game6502.AddCycle
    MOV    EBX,EDI
    ADD    EDI,OFFSET Mem6502
    CMP    BH,AH
    JE     @L2
    INC    DWORD PTR Game6502.AddCycle
@L2:
    POP    EAX
    JMP    EmulateLoop
@L1:
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L31:                 { AND ind. y }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    AND    CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L32:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L33:                 { RLA ind. y - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    AND    CH,7Dh
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    RCL    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    AND    CL,DL
    MOV    DL,CL
    OR     DL,DL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L34:                 { SKB Quasi-Opcode }

  Asm
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L35:                 { AND z. page x }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    AND    CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L36:                 { ROL z. page x }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPF
    POPAD

    RCL    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L37:                 { RLA z. page x - UNDOCUMENTED }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    RCL    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    AND    CL,DL
    MOV    DL,CL
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L38:                 { SEC }

  Asm
    OR     CH,01h
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L39:                 { AND abs. y }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    AND    CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L3A:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L3B:                 { RLA abs. y - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    AND    CH,7Dh
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    RCL    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    AND    CL,DL
    MOV    DL,CL
    OR     DL,DL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L3C:                 { SKW Quasi-Opcode }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    SETC   DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L3D:                 { AND abs. x }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    AND    CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L3E:                 { ROL abs. x }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    ADC    BH,0
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPF
    POPAD

    RCL    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L3F:                 { RLA abs. x - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    ADC    BH,0
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    RCL    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    AND    CL,DL
    MOV    DL,CL
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L40:                 { RTI }

  Asm
    INC    DH
    MOV    BL,DH

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX + 100h]
    MOV    EAX,EBX
    ADD    EAX,100h
    CALL   Handle_IO_Read
    POPAD

    MOV    CH,BYTE PTR Mem6502[EBX + 100h]
    OR     CH,20h
    AND    CH,0FBh
    INC    BL

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX + 100h]
    MOV    EAX,EBX
    ADD    EAX,100h
    CALL   Handle_IO_Read
    POPAD

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX + 101h]
    MOV    EAX,EBX
    ADD    EAX,101h
    CALL   Handle_IO_Read
    POPAD

    MOV    DI,WORD PTR Mem6502[EBX + 100h]
    ADD    EDI,OFFSET Mem6502
    ADD    DH,2
    JMP    EmulateLoop
  End; { Asm }

L41:                 { EOR ind. x }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AL
    MOV    BX,WORD PTR Mem6502[EBX]
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    XOR    CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L42:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L43:                 { SRE ind. x - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AL
    MOV    BX,WORD PTR Mem6502[EBX]
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SHR    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    XOR    CL,DL
    OR     CL,CL
    JZ     @L1
    AND    CH,7Dh
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L44:                 { SKB Quasi-Opcode }

  Asm
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L45:                 { EOR zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    AND    CH,07Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    XOR    CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L46:                 { LSR zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SHR    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L47:                 { SRE zero page - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SHR    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    XOR    CL,DL
    OR     CL,CL
    JZ     @L1
    AND    CH,7Dh
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L48:                 { PHA }

  Asm
    MOV    BL,DH
    MOV    BYTE PTR Mem6502[EBX + 100h],CL

    PUSHAD
    PUSHF
    MOVZX  EDX,CH
    MOV    EAX,EBX
    ADD    EAX,100h
    CALL   Handle_IO_Write
    POPF
    POPAD

    DEC    DH
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L49:                 { EOR immediate }

  Asm
    XOR    CL,BYTE PTR [EDI+1]
    JZ     @L1
    MOV    DL,CL
    AND    CH,7Dh
    AND    DL,80h
    ADD    EDI,2
    ADD    CH,DL
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    OR     CH,02h
    JMP    EmulateLoop
  End; { Asm }

L4A:                 { LSR accum. }

  Asm
    OR     CH,3
    SHR    CL,1
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     CL,CL
    JZ     @L1
    AND    CH,7Dh
    INC    EDI
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L4B:                 { ASR immediate - UNDOCUMENTED }

  Asm
    XOR    CL,BYTE PTR [EDI+1]
    OR     CH,3
    SHR    CL,1
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    CH,7Dh
    AND    DL,80h
    ADD    EDI,2
    ADD    CH,DL
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    OR     CH,02h
    JMP    EmulateLoop
  End; { Asm }

L4C:                 { JMP absolute }

  Asm
    MOV    DI,WORD PTR [EDI+1]
    ADD    EDI,OFFSET Mem6502
    JMP    EmulateLoop
  End; { Asm }

L4D:                 { EOR absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    XOR    CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L4E:                 { LSR absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SHR    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L3:
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L4F:                 { SRE absolute - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SHR    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    XOR    CL,DL
    MOV    Dl,CL
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L50:                 { BVC }

  Asm
    TEST   CH,040h
    JNZ    @L1
    MOVSX  EBX,BYTE PTR [EDI+1]
    ADD    EDI,2
    PUSH   EAX
    SUB    EDI,OFFSET Mem6502
    MOV    EAX,EDI
    ADD    EDI,EBX
    INC    DWORD PTR Game6502.AddCycle
    MOV    EBX,EDI
    ADD    EDI,OFFSET Mem6502
    CMP    BH,AH
    JE     @L2
    INC    DWORD PTR Game6502.AddCycle
@L2:
    POP    EAX
    JMP    EmulateLoop
@L1:
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L51:                 { EOR ind. y }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    XOR    CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L52:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L53:                 { SRE ind. y - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SHR    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    XOR    CL,DL
    OR     CL,CL
    JZ     @L1
    AND    CH,7Dh
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L54:                 { SKB Quasi-Opcode }

  Asm
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L55:                 { EOR z. page x }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    XOR    CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L56:                 { LSR z. page x }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SHR    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L57:                 { SRE z. page x - UNDOCUMENTED }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SHR    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    XOR    CL,DL
    OR     CL,CL
    JZ     @L1
    AND    CH,7Dh
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L58:                 { CLI }

  Asm
    AND    CH,0FBh
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L59:                 { EOR abs. y }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    XOR    CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L5A:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L5B:                 { SRE abs. y - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SHR    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    XOR    CL,DL
    MOV    DL,CL
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L5C:                 { SKW Quasi-Opcode }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    SETC   DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L5D:                 { EOR abs. x }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    XOR    CL,BYTE PTR Mem6502[EBX]
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L5E:                 { LSR abs. x }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    ADC    BH,0
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SHR    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L5F:                 { SRE abs. x - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    ADC    BH,0
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SHR    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    XOR    CL,DL
    MOV    DL,CL
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L60:                 { RTS }

  Asm
    MOV    ESI,EDI
    INC    DH
    MOV    BL,DH

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX + 100h]
    MOV    EAX,EBX
    ADD    EAX,100h
    CALL   Handle_IO_Read
    POPAD

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX + 101h]
    MOV    EAX,EBX
    ADD    EAX,101h
    CALL   Handle_IO_Read
    POPAD

    MOVZX  EDI,WORD PTR Mem6502[EBX + 100h]
    INC    EDI
    ADD    EDI,OFFSET Mem6502
    INC    DH
    JMP    EmulateLoop
  End; { Asm }

L61:                 { ADC ind. x }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AL
    MOV    BX,WORD PTR Mem6502[EBX]
    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF
    OR     CH,43h

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    ADC    CL,BYTE PTR Mem6502[EBX]
    PUSH   EAX
    LAHF
    JO     @L1a
    AND    CH,0BFh
@L1a:
    MOV    DL,AH
    AND    CH,7Ch
    AND    AH,81h
    SHR    DL,5
    OR     CH,AH
    AND    DL,2
    OR     CH,DL
    POP    EAX
    ADD    EDI,2
    JMP    EmulateLoop
  @BCD:
    MOV    DL,CH
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF
    
    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF

    MOV    DL,BYTE PTR Mem6502[EBX]
    CALL   ADC_BCD
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L62:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L63:                 { RRA ind. x - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AL
    MOV    BX,WORD PTR Mem6502[EBX]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L4:
    MOV    ESI,EBX
    MOV    BL,DL
    RCR    DL,1
    MOV    BH,BL                 { Set the overflow flag  }
    XOR    BH,DL                 { V=(New OR Old) AND 40h }
    AND    BH,40h
    AND    CH,0BFh
    OR     CH,BH
    TEST   CH,8                  { See if we're in decimal mode }
    JNZ    @BCD
    ROL    BL,1                  { Set carry flag = (Old AND 80h) }
    AND    BL,1
    AND    CH,0FEh
    OR     CH,BL
    MOV    BYTE PTR Mem6502[ESI],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[ESI]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
@BCD:
    MOV    BH,BL                 { BCD fixup 1 }
    AND    BH,0Fh
    CMP    BH,4
    JLE    @BCD1
    MOV    BH,DL
    ADD    BH,6
    AND    BH,0Fh
    AND    DL,0F0h
    OR     DL,BH
@BCD1:
    AND    CH,0FEh
    CMP    BL,4Fh
    JLE    @BCD2
    ADD    DL,60h
    OR     CH,1
@BCD2:
    MOV    BYTE PTR Mem6502[ESI],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[ESI]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L64:                 { SKB Quasi-Opcode }

  Asm
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L65:                 { ADC zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF
    OR     CH,43h

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    ADC    CL,BYTE PTR Mem6502[EBX]

    PUSH   EAX
    LAHF
    JO     @L1a
    AND    CH,0BFh
@L1a:
    MOV    DL,AH
    AND    CH,7Ch
    AND    AH,81h
    SHR    DL,5
    OR     CH,AH
    AND    DL,2
    OR     CH,DL
    POP    EAX
    ADD    EDI,2
    JMP    EmulateLoop
  @BCD:
    MOV    DL,CH
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    MOV    DL,BYTE PTR Mem6502[EBX]
    CALL   ADC_BCD
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L66:                 { ROR zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPF
    POPAD

    RCR    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L67:                 { RRA zero page - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L4:
    MOV    ESI,EBX
    MOV    BL,DL
    RCR    DL,1
    MOV    BH,BL                 { Set the overflow flag  }
    XOR    BH,DL                 { V=(New OR Old) AND 40h }
    AND    BH,40h
    AND    CH,0BFh
    OR     CH,BH
    TEST   CH,8                  { See if we're in decimal mode }
    JNZ    @BCD
    ROL    BL,1                  { Set carry flag = (Old AND 80h) }
    AND    BL,1
    AND    CH,0FEh
    OR     CH,BL
    MOV    BYTE PTR Mem6502[ESI],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[ESI]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
@BCD:
    MOV    BH,BL                 { BCD fixup 1 }
    AND    BH,0Fh
    CMP    BH,4
    JLE    @BCD1
    MOV    BH,DL
    ADD    BH,6
    AND    BH,0Fh
    AND    DL,0F0h
    OR     DL,BH
@BCD1:
    AND    CH,0FEh
    CMP    BL,4Fh
    JLE    @BCD2
    ADD    DL,60h
    OR     CH,1
@BCD2:
    MOV    BYTE PTR Mem6502[ESI],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[ESI]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L68:                 { PLA }

  Asm
    INC    DH
    AND    CH,7Dh
    MOV    BL,DH

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX + 100h]
    MOV    EAX,EBX
    ADD    EAX,100h
    CALL   Handle_IO_Read
    POPAD

    MOV    CL,BYTE PTR Mem6502[EBX + 100h]
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    INC    EDI
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L69:                 { ADC immediate }

  Asm
    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    OR     CH,43h
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    ADC    CL,BYTE PTR [EDI+1]
    PUSH   EAX
    LAHF
    JO     @L1
    AND    CH,0BFh
@L1:
    MOV    DL,AH
    AND    CH,7Ch
    AND    AH,81h
    SHR    DL,5
    OR     CH,AH
    AND    DL,2
    OR     CH,DL
    POP    EAX
    ADD    EDI,2
    JMP    EmulateLoop
  @BCD:
    MOV    DL,CH
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }

    MOV    DL,BYTE PTR [EDI+1]
    CALL   ADC_BCD
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L6A:                 { ROR accum. }

  Asm
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1
    RCR    CL,1
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    CH,7Dh
    AND    DL,80h
    INC    EDI
    ADD    CH,DL
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L6B:                 { ARR immediate - UNDOCUMENTED }

  Asm
    TEST   CH,8
    JNZ    @BCD
    AND    CH,3Ch
    AND    CL,BYTE PTR [EDI+1]
    RCR    CL,1
    TEST   CL,CL     { Set the zero flag }
    JNZ    @L1
    OR     CH,2
@L1:
    MOV    DL,CL     { Set the negative flag }
    AND    DL,80h
    OR     CH,DL
    MOV    DL,CL     { Set the carry flag }
    SHR    DL,6
    AND    DL,1
    OR     CH,DL
    MOV    DL,CL     { Set the overflow flag }
    SHL    DL,1
    XOR    DL,CL
    AND    DL,40h
    OR     CH,DL
    INC    EDI
    JMP    EmulateLoop
@BCD:
    AND    CH,3Ch
    MOV    DL,CL
    AND    DL,BYTE PTR [EDI+1]
    MOV    BL,CH     { Set the negative flag }
    ROR    BL,1
    AND    BL,80h
    OR     CH,BL
    MOV    BH,DL     { Set the zero flag -- note that it's reversed }
    SHR    BH,1
    OR     BH,BL
    MOV    CL,BH
    TEST   CL,CL
    JZ     @L2
    OR     CH,2
@L2:
    MOV    BL,DL     { Set the overflow flag }
    XOR    BL,CL
    AND    BL,40h
    OR     CH,BL

    MOV    BH,CL     { BCD fixup 1 -- low nibble }
    MOV    BL,CL
    AND    BX,0F01h
    ADD    BL,BH
    CMP    BL,5
    JLE    @L3
    AND    CL,0F0h
    ADD    BH,6
    AND    BH,0Fh
    OR     CL,BH
@L3:
    MOV    BH,CL     { BCD fixup 2 -- high nibble }
    MOV    BL,CL
    AND    BX,0F010h
    ADD    BL,BH
    CMP    BL,50h
    JLE    @L4
    OR     CH,1
    ADD    CL,60h
@L4:
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L6C:                 { JMP indirect }

  Asm
    MOV    BX,WORD PTR [EDI+1]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    INC    BL

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    BH,BYTE PTR Mem6502[EBX]
    MOV    BL,DL
    MOV    DI,BX
    ADD    EDI,OFFSET Mem6502
    JMP    EmulateLoop
  End; { Asm }

L6D:                 { ADC absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF
    OR     CH,43h

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    ADC    CL,BYTE PTR Mem6502[EBX]
    PUSH   EAX
    LAHF
    JO     @L1a
    AND    CH,0BFh
@L1a:
    MOV    DL,AH
    AND    CH,7Ch
    AND    AH,81h
    SHR    DL,5
    OR     CH,AH
    AND    DL,2
    OR     CH,DL
    POP    EAX
    ADD    EDI,3
    JMP    EmulateLoop
  @BCD:
    MOV    DL,CH
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    MOV    DL,BYTE PTR Mem6502[EBX]
    CALL   ADC_BCD
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L6E:                 { ROR absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPF
    POPAD

    RCR    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L4:
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L6F:                 { RRA absolute - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L4:
    MOV    ESI,EBX
    MOV    BL,DL
    RCR    DL,1
    MOV    BH,BL                 { Set the overflow flag  }
    XOR    BH,DL                 { V=(New OR Old) AND 40h }
    AND    BH,40h
    AND    CH,0BFh
    OR     CH,BH
    TEST   CH,8                  { See if we're in decimal mode }
    JNZ    @BCD
    ROL    BL,1                  { Set carry flag = (Old AND 80h) }
    AND    BL,1
    AND    CH,0FEh
    OR     CH,BL
    MOV    BYTE PTR Mem6502[ESI],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[ESI]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,3
    JMP    EmulateLoop
@BCD:
    MOV    BH,BL                 { BCD fixup 1 }
    AND    BH,0Fh
    CMP    BH,4
    JLE    @BCD1
    MOV    BH,DL
    ADD    BH,6
    AND    BH,0Fh
    AND    DL,0F0h
    OR     DL,BH
@BCD1:
    AND    CH,0FEh
    CMP    BL,4Fh
    JLE    @BCD2
    ADD    DL,60h
    OR     CH,1
@BCD2:
    MOV    BYTE PTR Mem6502[ESI],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[ESI]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L70:                 { BVS }

  Asm
    TEST   CH,40h
    JZ     @L1
    MOVSX  EBX,BYTE PTR [EDI+1]
    ADD    EDI,2
    PUSH   EAX
    SUB    EDI,OFFSET Mem6502
    MOV    EAX,EDI
    ADD    EDI,EBX
    INC    DWORD PTR Game6502.AddCycle
    MOV    EBX,EDI
    ADD    EDI,OFFSET Mem6502
    CMP    BH,AH
    JE     @L2
    INC    DWORD PTR Game6502.AddCycle
@L2:
    POP    EAX
    JMP    EmulateLoop
@L1:
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L71:                 { ADC ind. y }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF
    OR     CH,43h

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    ADC    CL,BYTE PTR Mem6502[EBX]

    PUSH   EAX
    LAHF
    JO     @L1a
    AND    CH,0BFh
@L1a:
    MOV    DL,AH
    AND    CH,7Ch
    AND    AH,81h
    SHR    DL,5
    OR     CH,AH
    AND    DL,2
    OR     CH,DL
    POP    EAX
    ADD    EDI,2
    JMP    EmulateLoop
  @BCD:
    MOV    DL,CH
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    MOV    DL,BYTE PTR Mem6502[EBX]
    CALL   ADC_BCD
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L72:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L73:                 { RRA ind. y - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L4:
    MOV    ESI,EBX
    MOV    BL,DL
    RCR    DL,1
    MOV    BH,BL                 { Set the overflow flag  }
    XOR    BH,DL                 { V=(New OR Old) AND 40h }
    AND    BH,40h
    AND    CH,0BFh
    OR     CH,BH
    TEST   CH,8                  { See if we're in decimal mode }
    JNZ    @BCD
    ROL    BL,1                  { Set carry flag = (Old AND 80h) }
    AND    BL,1
    AND    CH,0FEh
    OR     CH,BL
    MOV    BYTE PTR Mem6502[ESI],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[ESI]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
@BCD:
    MOV    BH,BL                 { BCD fixup 1 }
    AND    BH,0Fh
    CMP    BH,4
    JLE    @BCD1
    MOV    BH,DL
    ADD    BH,6
    AND    BH,0Fh
    AND    DL,0F0h
    OR     DL,BH
@BCD1:
    AND    CH,0FEh
    CMP    BL,4Fh
    JLE    @BCD2
    ADD    DL,60h
    OR     CH,1
@BCD2:
    MOV    BYTE PTR Mem6502[ESI],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[ESI]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L74:                 { SKB Quasi-Opcode }

  Asm
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L75:                 { ADC z. page x }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF
    OR     CH,43h

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    ADC    CL,BYTE PTR Mem6502[EBX]
    PUSH   EAX
    LAHF
    JO     @L1a
    AND    CH,0BFh
@L1a:
    MOV    DL,AH
    AND    CH,7Ch
    AND    AH,81h
    SHR    DL,5
    OR     CH,AH
    AND    DL,2
    OR     CH,DL
    POP    EAX
    ADD    EDI,2
    JMP    EmulateLoop
  @BCD:
    MOV    DL,CH
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    MOV    DL,BYTE PTR Mem6502[EBX]
    CALL   ADC_BCD
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L76:                 { ROR z. page x }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPF
    POPAD

    RCR    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L77:                 { RRA z. page x - UNDOCUMENTED }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L4:
    MOV    ESI,EBX
    MOV    BL,DL
    RCR    DL,1
    MOV    BH,BL                 { Set the overflow flag  }
    XOR    BH,DL                 { V=(New OR Old) AND 40h }
    AND    BH,40h
    AND    CH,0BFh
    OR     CH,BH
    TEST   CH,8                  { See if we're in decimal mode }
    JNZ    @BCD
    ROL    BL,1                  { Set carry flag = (Old AND 80h) }
    AND    BL,1
    AND    CH,0FEh
    OR     CH,BL
    MOV    BYTE PTR Mem6502[ESI],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[ESI]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
@BCD:
    MOV    BH,BL                 { BCD fixup 1 }
    AND    BH,0Fh
    CMP    BH,4
    JLE    @BCD1
    MOV    BH,DL
    ADD    BH,6
    AND    BH,0Fh
    AND    DL,0F0h
    OR     DL,BH
@BCD1:
    AND    CH,0FEh
    CMP    BL,4Fh
    JLE    @BCD2
    ADD    DL,60h
    OR     CH,1
@BCD2:
    MOV    BYTE PTR Mem6502[ESI],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[ESI]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L78:                 { SEI }

  Asm
    OR     CH,04h
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L79:                 { ADC abs. y }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF
    OR     CH,43h

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    ADC    CL,BYTE PTR Mem6502[EBX]
    PUSH   EAX
    LAHF
    JO     @L1a
    AND    CH,0BFh
@L1a:
    MOV    DL,AH
    AND    CH,7Ch
    AND    AH,81h
    SHR    DL,5
    OR     CH,AH
    AND    DL,2
    OR     CH,DL
    POP    EAX
    ADD    EDI,3
    JMP    EmulateLoop
  @BCD:
    MOV    DL,CH
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    MOV    DL,BYTE PTR Mem6502[EBX]
    CALL   ADC_BCD
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L7A:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L7B:                 { RRA abs. y - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    ADC    BH,0
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L4:
    MOV    ESI,EBX
    MOV    BL,DL
    RCR    DL,1
    MOV    BH,BL                 { Set the overflow flag  }
    XOR    BH,DL                 { V=(New OR Old) AND 40h }
    AND    BH,40h
    AND    CH,0BFh
    OR     CH,BH
    TEST   CH,8                  { See if we're in decimal mode }
    JNZ    @BCD
    ROL    BL,1                  { Set carry flag = (Old AND 80h) }
    AND    BL,1
    AND    CH,0FEh
    OR     CH,BL
    MOV    BYTE PTR Mem6502[ESI],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[ESI]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,3
    JMP    EmulateLoop
@BCD:
    MOV    BH,BL                 { BCD fixup 1 }
    AND    BH,0Fh
    CMP    BH,4
    JLE    @BCD1
    MOV    BH,DL
    ADD    BH,6
    AND    BH,0Fh
    AND    DL,0F0h
    OR     DL,BH
@BCD1:
    AND    CH,0FEh
    CMP    BL,4Fh
    JLE    @BCD2
    ADD    DL,60h
    OR     CH,1
@BCD2:
    MOV    BYTE PTR Mem6502[ESI],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[ESI]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }


L7C:                 { SKW Quasi-Opcode }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    SETC   DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L7D:                 { ADC abs. x }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF
    OR     CH,43h

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    ADC    CL,BYTE PTR Mem6502[EBX]
    PUSH   EAX
    LAHF
    JO     @L1a
    AND    CH,0BFh
@L1a:
    MOV    DL,AH
    AND    CH,7Ch
    AND    AH,81h
    SHR    DL,5
    OR     CH,AH
    AND    DL,2
    OR     CH,DL
    POP    EAX
    ADD    EDI,3
    JMP    EmulateLoop
  @BCD:
    MOV    DL,CH
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    MOV    DL,BYTE PTR Mem6502[EBX]
    CALL   ADC_BCD
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L7E:                 { ROR abs. x }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    ADC    BH,0
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPF
    POPAD

    RCR    BYTE PTR Mem6502[EBX],1

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
    JC     @L2
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L7F:                 { RRA abs. x - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    ADC    BH,0
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L4:
    MOV    ESI,EBX
    MOV    BL,DL
    RCR    DL,1
    MOV    BH,BL                 { Set the overflow flag  }
    XOR    BH,DL                 { V=(New OR Old) AND 40h }
    AND    BH,40h
    AND    CH,0BFh
    OR     CH,BH
    TEST   CH,8                  { See if we're in decimal mode }
    JNZ    @BCD
    ROL    BL,1                  { Set carry flag = (Old AND 80h) }
    AND    BL,1
    AND    CH,0FEh
    OR     CH,BL
    MOV    BYTE PTR Mem6502[ESI],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[ESI]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,3
    JMP    EmulateLoop
@BCD:
    MOV    BH,BL                 { BCD fixup 1 }
    AND    BH,0Fh
    CMP    BH,4
    JLE    @BCD1
    MOV    BH,DL
    ADD    BH,6
    AND    BH,0Fh
    AND    DL,0F0h
    OR     DL,BH
@BCD1:
    AND    CH,0FEh
    CMP    BL,4Fh
    JLE    @BCD2
    ADD    DL,60h
    OR     CH,1
@BCD2:
    MOV    BYTE PTR Mem6502[ESI],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[ESI]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L80:                 { SKB Quasi-Opcode }

  Asm
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L81:                 { STA ind. x }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AL
    MOV    BX,WORD PTR Mem6502[EBX]
    MOV    BYTE PTR Mem6502[EBX],CL
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L82:                 { SKB Quasi-Opcode }

  Asm
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L83:                 { SAX ind. x - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AL
    MOV    BX,WORD PTR Mem6502[EBX]
    MOV    DL,CL
    AND    DL,AL
    MOV    BYTE PTR Mem6502[EBX],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L84:                 { STY zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BYTE PTR Mem6502[EBX],AH

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L85:                 { STA zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BYTE PTR Mem6502[EBX],CL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L86:                 { STX zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BYTE PTR Mem6502[EBX],AL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L87:                 { SAX zero page - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    DL,CL
    AND    DL,AL
    MOV    BYTE PTR Mem6502[EBX],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L88:                 { DEY }

  Asm
    DEC    AH
    JZ     @L1
    MOV    DL,AH
    AND    CH,7Dh
    AND    DL,80h
    INC    EDI
    ADD    CH,DL
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    INC    EDI
    OR     CH,2
    JMP    EmulateLoop
  End; { Asm }

L89:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L8A:                 { TXA }

  Asm
    MOV    CL,AL
    OR     BH,AL   { BH = 0 at start }
    JZ     @L1
    AND    BH,80h
    AND    CH,7Dh
    ADD    CH,BH
    INC    EDI
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    INC    EDI
    OR     CH,2
    JMP    EmulateLoop
  End; { Asm }

L8B:                 { ANE immediate - UNDOCUMENTED }

  Asm
    OR     CL,0EEh
    AND    CL,AL
    AND    CL,BYTE PTR [EDI+1]
    AND    CH,7Dh
    OR     BH,CL
    JZ     @L1
    AND    BH,80h
    ADD    EDI,2
    ADD    CH,BH
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L8C:                 { STY absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    MOV    BYTE PTR Mem6502[EBX],AH

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L8D:                 { STA absolute }
  Asm
    MOV    BX,WORD PTR [EDI+1]
    MOV    BYTE PTR Mem6502[EBX],CL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L8E:                 { STX absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    MOV    BYTE PTR Mem6502[EBX],AL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L8F:                 { SAX absolute - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    MOV    DL,CL
    AND    DL,AL
    MOV    BYTE PTR Mem6502[EBX],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L90:                 { BCC }

  Asm
    TEST   CH,01
    JNZ    @L1
    MOVSX  EBX,BYTE PTR [EDI+1]
    ADD    EDI,2
    PUSH   EAX
    SUB    EDI,OFFSET Mem6502
    MOV    EAX,EDI
    ADD    EDI,EBX
    INC    DWORD PTR Game6502.AddCycle
    MOV    EBX,EDI
    ADD    EDI,OFFSET Mem6502
    CMP    BH,AH
    JE     @L2
    INC    DWORD PTR Game6502.AddCycle
@L2:
    POP    EAX
    JMP    EmulateLoop
@L1:
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L91:                 { STA ind. y }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    MOV    BYTE PTR Mem6502[EBX],CL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L92:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L93:                 { SHA ind. y - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    MOV    DL,BH
    INC    DL
    AND    DL,AL
    AND    DL,CL
    JNC    @L1
    INC    BYTE PTR Game6502.AddCycle
    MOV    BH,DL
@L1:
    MOV    BYTE PTR Mem6502[EBX],CL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L94:                 { STY z. page x }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    MOV    BYTE PTR Mem6502[EBX],AH

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L95:                 { STA z. page x }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    MOV    BYTE PTR Mem6502[EBX],CL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L96:                 { STX z. page y }

  Asm
    MOV    BL,AH
    ADD    BL,BYTE PTR [EDI+1]
    MOV    BYTE PTR Mem6502[EBX],AL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L97:                 { SAX z. page y - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AH
    MOV    DL,CL
    AND    DL,AL
    MOV    BYTE PTR Mem6502[EBX],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L98:                 { TYA }

  Asm
    MOV    CL,AH
    OR     BH,AH   { BH = 0 at start }
    JZ     @L1
    AND    BH,80h
    AND    CH,7Dh
    ADD    CH,BH
    INC    EDI
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    INC    EDI
    OR     CH,2
    JMP    EmulateLoop
  End; { Asm }

L99:                 { STA abs. y }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    ADC    BH,0
    MOV    BYTE PTR Mem6502[EBX],CL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L9A:                 { TXS }

  Asm
    MOV    DH,AL
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

L9B:                 { SHS ind. y - UNDOCUMENTED }

  Asm
    MOV    DH,AL
    AND    DH,CL
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    MOV    DL,BH
    INC    DL
    AND    DL,DH
    JNC    @L1
    INC    BYTE PTR Game6502.AddCycle
    MOV    BH,DL
@L1:
    MOV    BYTE PTR Mem6502[EBX],CL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

L9C:                 { SHY abs. x - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    MOV    DL,BH
    INC    DL
    AND    DL,AH
    JNC    @L1
    INC    BYTE PTR Game6502.AddCycle
    MOV    BH,DL
@L1:
    MOV    BYTE PTR Mem6502[EBX],CL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L9D:                 { STA abs. x }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    ADC    BH,0
    MOV    BYTE PTR Mem6502[EBX],CL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L9E:                 { SHX abs. y - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    MOV    DL,BH
    INC    DL
    AND    DL,AL
    JNC    @L1
    INC    BYTE PTR Game6502.AddCycle
    MOV    BH,DL
@L1:
    MOV    BYTE PTR Mem6502[EBX],CL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

L9F:                 { SHA abs. y - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    MOV    DL,BH
    INC    DL
    AND    DL,AL
    AND    DL,CL
    JNC    @L1
    INC    BYTE PTR Game6502.AddCycle
    MOV    BH,DL
@L1:
    MOV    BYTE PTR Mem6502[EBX],CL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LA0:                 { LDY immediate }

  Asm
    MOV    AH,BYTE PTR [EDI+1]
    AND    CH,7Dh
    OR     BH,AH
    JZ     @L1
    AND    BH,80h
    ADD    EDI,2
    ADD    CH,BH
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LA1:                 { LDA ind. x }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AL
    MOV    BX,WORD PTR Mem6502[EBX]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    CL,BYTE PTR Mem6502[EBX]
    AND    CH,7Dh
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LA2:                 { LDX immediate }

  Asm
    MOV    AL,BYTE PTR [EDI+1]
    AND    CH,7Dh
    OR     BH,AL
    JZ     @L1
    AND    BH,80h
    ADD    EDI,2
    ADD    CH,BH
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LA3:                 { LAX ind. x - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AL
    MOV    BX,WORD PTR Mem6502[EBX]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    CL,BYTE PTR Mem6502[EBX]
    MOV    AL,CL    
    AND    CH,7Dh
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LA4:                 { LDY zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    AH,BYTE PTR Mem6502[EBX]
    AND    CH,7Dh
    OR     AH,AH
    JZ     @L1
    MOV    DL,AH
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LA5:                 { LDA zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    CL,BYTE PTR Mem6502[EBX]
    AND    CH,7Dh
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LA6:                 { LDX zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    AL,BYTE PTR Mem6502[EBX]
    AND    CH,7Dh
    OR     AL,AL
    JZ     @L1
    MOV    DL,AL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LA7:                 { LAX zero page - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    CL,BYTE PTR Mem6502[EBX]
    MOV    AL,CL    
    AND    CH,7Dh
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LA8:                 { TAY }

  Asm
    MOV    AH,CL
    AND    CH,7Dh
    OR     BH,AH
    JZ     @L1
    AND    BH,80h
    INC    EDI
    ADD    CH,BH
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

LA9:                 { LDA immediate }

  Asm
    MOV    CL,BYTE PTR [EDI+1]
    AND    CH,7Dh
    OR     BH,CL
    JZ     @L1
    AND    BH,80h
    ADD    EDI,2
    ADD    CH,BH
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LAA:                 { TAX }

  Asm
    MOV    AL,CL
    AND    CH,7Dh
    OR     BH,AL
    JZ     @L1
    AND    BH,80h
    INC    EDI
    ADD    CH,BH
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

LAB:                 { LXA immed + a - UNDOCUMENTED }

  Asm
    ADD    CL,BYTE PTR [EDI+1]
    MOV    AL,CL
    AND    CH,7Dh
    OR     BH,CL
    JZ     @L1
    AND    BH,80h
    ADD    EDI,2
    ADD    CH,BH
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LAC:                 { LDY absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    AH,BYTE PTR Mem6502[EBX]
    AND    CH,7Dh
    OR     AH,AH
    JZ     @L1
    MOV    DL,AH
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LAD:                 { LDA absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    CL,BYTE PTR Mem6502[EBX]
    AND    CH,7Dh
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LAE:                 { LDX absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    AL,BYTE PTR Mem6502[EBX]
    AND    CH,7Dh
    OR     AL,AL
    JZ     @L1
    MOV    DL,AL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LAF:                 { LAX absolute - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    CL,BYTE PTR Mem6502[EBX]
    MOV    AL,CL    
    AND    CH,7Dh
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LB0:                 { BCS }

  Asm
    TEST   CH,01
    JZ     @L1
    MOVSX  EBX,BYTE PTR [EDI+1]
    ADD    EDI,2
    PUSH   EAX
    SUB    EDI,OFFSET Mem6502
    MOV    EAX,EDI
    ADD    EDI,EBX
    INC    DWORD PTR Game6502.AddCycle
    MOV    EBX,EDI
    ADD    EDI,OFFSET Mem6502
    CMP    BH,AH
    JE     @L2
    INC    DWORD PTR Game6502.AddCycle
@L2:
    POP    EAX
    JMP    EmulateLoop
@L1:
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LB1:                 { LDA ind. y }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    PUSHF
    ADC    BH,0

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    ADC    DWORD PTR Game6502.AddCycle,0
    MOV    CL,BYTE PTR Mem6502[EBX]
    AND    CH,7Dh
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LB2:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

LB3:                 { LAX ind. y - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    PUSHF
    ADC    BH,0

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    ADC    DWORD PTR Game6502.AddCycle,0
    MOV    CL,BYTE PTR Mem6502[EBX]
    MOV    AL,CL    
    AND    CH,7Dh
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LB4:                 { LDY z. page x }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    AH,BYTE PTR Mem6502[EBX]
    AND    CH,7Dh
    OR     AH,AH
    JZ     @L1
    MOV    DL,AH
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LB5:                 { LDA z. page x }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    CL,BYTE PTR Mem6502[EBX]
    AND    CH,7Dh
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LB6:                 { LDX z. page y }

  Asm
    MOV    BL,AH
    ADD    BL,BYTE PTR [EDI+1]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    AL,BYTE PTR Mem6502[EBX]
    AND    CH,7Dh
    OR     AL,AL
    JZ     @L1
    MOV    DL,AL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LB7:                 { LAX z. page y - UNDOCUMENTED }

  Asm
    MOV    BL,AH
    ADD    BL,BYTE PTR [EDI+1]

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    CL,BYTE PTR Mem6502[EBX]
    MOV    AL,CL    
    AND    CH,7Dh
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LB8:                 { CLV }

  Asm
    AND    CH,0BFh
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

LB9:                 { LDA abs. y }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    CL,BYTE PTR Mem6502[EBX]
    AND    CH,7Dh
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LBA:                 { TSX }

  Asm
    MOV    AL,DH
    AND    CH,7Dh
    OR     BH,AL
    JZ     @L1
    AND    BH,80h
    INC    EDI
    ADD    CH,BH
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

LBB:                 { LAS (abs. y) and s - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    CL,BYTE PTR Mem6502[EBX]
    AND    CH,7Dh
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LBC:                 { LDY abs. x }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    AH,BYTE PTR Mem6502[EBX]
    AND    CH,7Dh
    OR     AH,AH
    JZ     @L1
    MOV    DL,AH
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LBD:                 { LDA abs. x }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    CL,BYTE PTR Mem6502[EBX]
    AND    CH,7Dh
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LBE:                 { LDX abs. y }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    AL,BYTE PTR Mem6502[EBX]
    AND    CH,7Dh
    OR     AL,AL
    JZ     @L1
    MOV    DL,AL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LBF:                 { LAX abs. y }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    CL,BYTE PTR Mem6502[EBX]
    MOV    AL,CL
    AND    CH,7Dh
    OR     CL,CL
    JZ     @L1
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LC0:                 { CPY immediate }

  Asm
    MOV    DL,AH
    OR     CH,3
    SUB    DL,BYTE PTR [EDI+1]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LC1:                 { CMP ind. x }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AL
    MOV    BX,WORD PTR Mem6502[EBX]
    MOV    DL,CL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LC2:                 { SKB Quasi-Opcode }

  Asm
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LC3:                 { DCP ind. x - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AL
    MOV    BX,WORD PTR Mem6502[EBX]
    MOV    DL,CL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    DEC    BYTE PTR Mem6502[EBX]

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LC4:                 { CPY zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    DL,AH
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LC5:                 { CMP zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    DL,CL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LC6:                 { DEC zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    DEC    BYTE PTR Mem6502[EBX]

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD
    
    JZ     @L1
    MOV    DL,BYTE PTR Mem6502[EBX]
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LC7:                 { DCP zero page - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    DL,CL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    DEC    BYTE PTR Mem6502[EBX]

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LC8:                 { INY }

  Asm
    INC    AH
    JZ     @L1
    MOV    DL,AH
    AND    CH,7Dh
    AND    DL,80h
    INC    EDI
    ADD    CH,DL
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    INC    EDI
    OR     CH,2
    JMP    EmulateLoop
  End; { Asm }

LC9:                 { CMP immediate }

  Asm
    MOV    DL,CL
    OR     CH,3
    SUB    DL,BYTE PTR [EDI+1]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LCA:                 { DEX }

  Asm
    DEC    AL
    JZ     @L1
    MOV    DL,AL
    AND    CH,7Dh
    AND    DL,80h
    INC    EDI
    ADD    CH,DL
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    INC    EDI
    OR     CH,2
    JMP    EmulateLoop
  End; { Asm }

LCB:                 { SBX immediate - UNDOCUMENTED }

  Asm
    MOV    DL,CL
    AND    DL,AL
    OR     CH,3
    SUB    DL,BYTE PTR [EDI+1]
    MOV    AL,DL
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LCC:                 { CPY absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    MOV    DL,AH
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LCD:                 { CMP absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    MOV    DL,CL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LCE:                 { DEC absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    DEC    BYTE PTR Mem6502[EBX]

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    JZ     @L1
    MOV    DL,BYTE PTR Mem6502[EBX]
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LCF:                 { DCP absolute - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    MOV    DL,CL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    DEC    BYTE PTR Mem6502[EBX]

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LD0:                 { BNE }

  Asm
    TEST   CH,02
    JNZ    @L1
    MOVSX  EBX,BYTE PTR [EDI+1]
    ADD    EDI,2
    PUSH   EAX
    SUB    EDI,OFFSET Mem6502
    MOV    EAX,EDI
    ADD    EDI,EBX
    INC    DWORD PTR Game6502.AddCycle
    MOV    EBX,EDI
    ADD    EDI,OFFSET Mem6502
    CMP    BH,AH
    JE     @L2
    INC    DWORD PTR Game6502.AddCycle
@L2:
    POP    EAX
    JMP    EmulateLoop
@L1:
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LD1:                 { CMP ind. y }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    PUSHF
    ADC    BH,0
    POPF
    ADC    DWORD PTR Game6502.AddCycle,0
    MOV    DL,CL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LD2:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

LD3:                 { DCP ind. y - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    PUSHF
    ADC    BH,0
    POPF
    ADC    DWORD PTR Game6502.AddCycle,0
    MOV    DL,CL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    DEC    BYTE PTR Mem6502[EBX]

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LD4:                 { SKB Quasi-Opcode }

  Asm
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LD5:                 { CMP z. page x }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    MOV    DL,CL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LD6:                 { DEC z. page x }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    DEC    BYTE PTR Mem6502[EBX]

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD
    
    JZ     @L1
    MOV    DL,BYTE PTR Mem6502[EBX]
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LD7:                 { DCP z. page x - UNDOCUMENTED }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    MOV    DL,CL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    DEC    BYTE PTR Mem6502[EBX]

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LD8:                 { CLD }

  Asm
    AND    CH,0F7h
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

LD9:                 { CMP abs. y }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    MOV    DL,CL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LDA:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

LDB:                 { DCP abs. y - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    MOV    DL,CL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    DEC    BYTE PTR Mem6502[EBX]

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LDC:                 { SKW Quasi-Opcode }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    SETC   DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LDD:                 { CMP abs. x }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    MOV    DL,CL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LDE:                 { DEC abs. x }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    ADC    BH,0
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    DEC    BYTE PTR Mem6502[EBX]

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    JZ     @L1
    MOV    DL,BYTE PTR Mem6502[EBX]
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LDF:                 { DCP abs. x - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    MOV    DL,CL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    DEC    BYTE PTR Mem6502[EBX]

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LE0:                 { CPX immediate }

  Asm
    MOV    DL,AL
    OR     CH,3
    SUB    DL,BYTE PTR [EDI+1]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LE1:                 { SBC ind. x }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AL
    MOV    BX,WORD PTR Mem6502[EBX]
    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    XOR    DL,1
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    SBB    CL,BYTE PTR Mem6502[EBX]
    PUSHF
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     CH,40h
    POPF
    JO     @L4
    AND    CH,0BFh
@L4:
    OR     CL,CL
    JZ     @L1
    AND    CH,7Dh
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  @BCD:
    MOV    DL,CH
    XOR    DL,1
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF

    MOV    DL,BYTE PTR Mem6502[EBX]
    CALL   SBC_BCD
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LE2:                 { SKB Quasi-Opcode }

  Asm
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LE3:                 { ISB ind. x - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    ADD    BL,AL
    MOV    BX,WORD PTR Mem6502[EBX]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L4:
    AND    CH,03Ch         { Turn sign, overflow, and zero bits off }
    INC    DL
    MOV    BYTE PTR Mem6502[EBX],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    PUSH   EAX
    SUB    EAX,EAX

    MOV    AL,CL
    SUB    AL,DL
    SBB    AH,0
    MOV    BL,CH
    AND    BL,1
    XOR    BL,1
    SUB    AL,BL
    SBB    AH,0
    JNZ    @L1
    OR     CH,2
@L1:
    MOV    BL,AL
    AND    BL,80h
    OR     CH,BL

    MOV    BL,AL
    XOR    BL,CL
    TEST   BL,80h
    JZ     @L2
    MOV    BL,DL
    XOR    BL,CL
    TEST   BL,80h
    JZ     @L2
    OR     CH,40h
@L2:
    TEST   CH,8
    JZ     @NotBCD

    PUSH   ECX
    MOV    BL,CL
    AND    BL,0Fh
    AND    CH,1
    ADD    BL,CH
    MOV    CH,DL
    AND    CH,0Fh
    CMP    BL,CH
    JGE    @L5
    SUB    AX,6
@L5:
    POP    ECX
    CMP    AX,99h
    JLE    @NotBCD
    SUB    AX,60h
@NotBCD:
    TEST   AH,AH
    JNZ    @L6
    OR     CH,1
@L6:
    MOV    CL,AL
    POP    EAX
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LE4:                 { CPX zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    DL,AL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LE5:                 { SBC zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]

    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    XOR    DL,1
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    SBB    CL,BYTE PTR Mem6502[EBX]
    PUSHF
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     CH,40h
    POPF
    JO     @L4
    AND    CH,0BFh
@L4:
    OR     CL,CL
    JZ     @L1
    AND    CH,7Dh
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  @BCD:
    MOV    DL,CH
    XOR    DL,1
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF

    MOV    DL,BYTE PTR Mem6502[EBX]
    CALL   SBC_BCD
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LE6:                 { INC zero page }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    INC    BYTE PTR Mem6502[EBX]

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    JZ     @L1
    MOV    DL,BYTE PTR Mem6502[EBX]
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LE7:                 { ISB zero page - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L4:
    AND    CH,03Ch         { Turn sign, overflow, and zero bits off }
    INC    DL
    MOV    BYTE PTR Mem6502[EBX],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    PUSH   EAX
    SUB    EAX,EAX

    MOV    AL,CL
    SUB    AL,DL
    SBB    AH,0
    MOV    BL,CH
    AND    BL,1
    XOR    BL,1
    SUB    AL,BL
    SBB    AH,0
    JNZ    @L1
    OR     CH,2
@L1:
    MOV    BL,AL
    AND    BL,80h
    OR     CH,BL

    MOV    BL,AL
    XOR    BL,CL
    TEST   BL,80h
    JZ     @L2
    MOV    BL,DL
    XOR    BL,CL
    TEST   BL,80h
    JZ     @L2
    OR     CH,40h
@L2:
    TEST   CH,8
    JZ     @NotBCD

    PUSH   ECX
    MOV    BL,CL
    AND    BL,0Fh
    AND    CH,1
    ADD    BL,CH
    MOV    CH,DL
    AND    CH,0Fh
    CMP    BL,CH
    JGE    @L5
    SUB    AX,6
@L5:
    POP    ECX
    CMP    AX,99h
    JLE    @NotBCD
    SUB    AX,60h
@NotBCD:
    TEST   AH,AH
    JNZ    @L6
    OR     CH,1
@L6:
    MOV    CL,AL
    POP    EAX
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LE8:                 { INX }

  Asm
    INC    AL
    JZ     @L1
    MOV    DL,AL
    AND    CH,7Dh
    AND    DL,80h
    INC    EDI
    ADD    CH,DL
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    INC    EDI
    OR     CH,2
    JMP    EmulateLoop
  End; { Asm }

LE9:                 { SBC immediate }
  Asm
    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    XOR    DL,1
    OR     CH,3
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    SBB    CL,BYTE PTR [EDI+1]
    PUSHF
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     CH,40h
    POPF
    JO     @L4
    AND    CH,0BFh
@L4:
    OR     CL,CL
    JZ     @L1
    AND    CH,7Dh
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  @BCD:
    MOV    DL,CH
    XOR    DL,1
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }

    MOV    DL,BYTE PTR [EDI+1]
    CALL   SBC_BCD
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LEA:                 { NOP }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

LEB:                 { SBC immediate - UNDOCUMENTED }

  Asm
    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    XOR    DL,1
    OR     CH,3
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    SBB    CL,BYTE PTR [EDI+1]
    PUSHF
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     CH,40h
    POPF
    JO     @L4
    AND    CH,0BFh
@L4:
    OR     CL,CL
    JZ     @L1
    AND    CH,7Dh
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  @BCD:
    MOV    DL,CH
    XOR    DL,1
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }

    MOV    DL,BYTE PTR [EDI+1]
    CALL   SBC_BCD
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LEC:                 { CPX absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    MOV    DL,AL
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SUB    DL,BYTE PTR Mem6502[EBX]
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     DL,DL
    JZ     @L1
    AND    CH,7Dh
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LED:                 { SBC absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]

    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    XOR    DL,1
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    SBB    CL,BYTE PTR Mem6502[EBX]
    PUSHF
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     CH,40h
    POPF
    JO     @L4
    AND    CH,0BFh
@L4:
    OR     CL,CL
    JZ     @L1
    AND    CH,7Dh
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  @BCD:
    MOV    DL,CH
    XOR    DL,1
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF

    MOV    DL,BYTE PTR Mem6502[EBX]
    CALL   SBC_BCD
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LEE:                 { INC absolute }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    INC    BYTE PTR Mem6502[EBX]

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    JZ     @L1
    MOV    DL,BYTE PTR Mem6502[EBX]
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,2
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LEF:                 { ISB absolute - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L4:
    AND    CH,03Ch         { Turn sign, overflow, and zero bits off }
    INC    DL
    MOV    BYTE PTR Mem6502[EBX],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    PUSH   EAX
    SUB    EAX,EAX

    MOV    AL,CL
    SUB    AL,DL
    SBB    AH,0
    MOV    BL,CH
    AND    BL,1
    XOR    BL,1
    SUB    AL,BL
    SBB    AH,0
    JNZ    @L1
    OR     CH,2
@L1:
    MOV    BL,AL
    AND    BL,80h
    OR     CH,BL

    MOV    BL,AL
    XOR    BL,CL
    TEST   BL,80h
    JZ     @L2
    MOV    BL,DL
    XOR    BL,CL
    TEST   BL,80h
    JZ     @L2
    OR     CH,40h
@L2:
    TEST   CH,8
    JZ     @NotBCD

    PUSH   ECX
    MOV    BL,CL
    AND    BL,0Fh
    AND    CH,1
    ADD    BL,CH
    MOV    CH,DL
    AND    CH,0Fh
    CMP    BL,CH
    JGE    @L5
    SUB    AX,6
@L5:
    POP    ECX
    CMP    AX,99h
    JLE    @NotBCD
    SUB    AX,60h
@NotBCD:
    TEST   AH,AH
    JNZ    @L6
    OR     CH,1
@L6:
    MOV    CL,AL
    POP    EAX
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LF0:                 { BEQ }

  Asm
    TEST   CH,02
    JZ     @L1
    MOVSX  EBX,BYTE PTR [EDI+1]
    ADD    EDI,2
    PUSH   EAX
    SUB    EDI,OFFSET Mem6502
    MOV    EAX,EDI
    ADD    EDI,EBX
    INC    DWORD PTR Game6502.AddCycle
    MOV    EBX,EDI
    ADD    EDI,OFFSET Mem6502
    CMP    BH,AH
    JE     @L2
    INC    DWORD PTR Game6502.AddCycle
@L2:
    POP    EAX
    JMP    EmulateLoop
@L1:
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LF1:                 { SBC ind. y }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    PUSHF
    ADC    BH,0
    POPF
    ADC    DWORD PTR Game6502.AddCycle,0

    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    XOR    DL,1
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    SBB    CL,BYTE PTR Mem6502[EBX]
    PUSHF
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     CH,40h
    POPF
    JO     @L4
    AND    CH,0BFh
@L4:
    OR     CL,CL
    JZ     @L1
    AND    CH,7Dh
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  @BCD:
    MOV    DL,CH
    XOR    DL,1
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF

    MOV    DL,BYTE PTR Mem6502[EBX]
    CALL   SBC_BCD
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LF2:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

LF3:                 { ISB ind. Y - UNDOCUMENTED }

  Asm
    MOV    BL,BYTE PTR [EDI+1]
    MOV    BX,WORD PTR Mem6502[EBX]
    ADD    BL,AH
    PUSHF
    ADC    BH,0
    POPF
    ADC    DWORD PTR Game6502.AddCycle,0
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L4:
    AND    CH,03Ch         { Turn sign, overflow, and zero bits off }
    INC    DL
    MOV    BYTE PTR Mem6502[EBX],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    PUSH   EAX
    SUB    EAX,EAX

    MOV    AL,CL
    SUB    AL,DL
    SBB    AH,0
    MOV    BL,CH
    AND    BL,1
    XOR    BL,1
    SUB    AL,BL
    SBB    AH,0
    JNZ    @L1
    OR     CH,2
@L1:
    MOV    BL,AL
    AND    BL,80h
    OR     CH,BL

    MOV    BL,AL
    XOR    BL,CL
    TEST   BL,80h
    JZ     @L2
    MOV    BL,DL
    XOR    BL,CL
    TEST   BL,80h
    JZ     @L2
    OR     CH,40h
@L2:
    TEST   CH,8
    JZ     @NotBCD

    PUSH   ECX
    MOV    BL,CL
    AND    BL,0Fh
    AND    CH,1
    ADD    BL,CH
    MOV    CH,DL
    AND    CH,0Fh
    CMP    BL,CH
    JGE    @L5
    SUB    AX,6
@L5:
    POP    ECX
    CMP    AX,99h
    JLE    @NotBCD
    SUB    AX,60h
@NotBCD:
    TEST   AH,AH
    JNZ    @L6
    OR     CH,1
@L6:
    MOV    CL,AL
    POP    EAX
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LF4:                 { SKB Quasi-Opcode }

  Asm
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LF5:                 { SBC z. page x }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    XOR    DL,1
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    SBB    CL,BYTE PTR Mem6502[EBX]
    PUSHF
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     CH,40h
    POPF
    JO     @L4
    AND    CH,0BFh
@L4:
    OR     CL,CL
    JZ     @L1
    AND    CH,7Dh
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,2
    JMP    EmulateLoop
  @BCD:
    MOV    DL,CH
    XOR    DL,1
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF

    MOV    DL,BYTE PTR Mem6502[EBX]
    CALL   SBC_BCD
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LF6:                 { INC z. page x }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    INC    BYTE PTR Mem6502[EBX]

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    JZ     @L1
    MOV    DL,BYTE PTR Mem6502[EBX]
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,2
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LF7:                 { ISB z. page x - UNDOCUMENTED }

  Asm
    MOV    BL,AL
    ADD    BL,BYTE PTR [EDI+1]
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L4:
    AND    CH,03Ch         { Turn sign, overflow, and zero bits off }
    INC    DL
    MOV    BYTE PTR Mem6502[EBX],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    PUSH   EAX
    SUB    EAX,EAX

    MOV    AL,CL
    SUB    AL,DL
    SBB    AH,0
    MOV    BL,CH
    AND    BL,1
    XOR    BL,1
    SUB    AL,BL
    SBB    AH,0
    JNZ    @L1
    OR     CH,2
@L1:
    MOV    BL,AL
    AND    BL,80h
    OR     CH,BL

    MOV    BL,AL
    XOR    BL,CL
    TEST   BL,80h
    JZ     @L2
    MOV    BL,DL
    XOR    BL,CL
    TEST   BL,80h
    JZ     @L2
    OR     CH,40h
@L2:
    TEST   CH,8
    JZ     @NotBCD

    PUSH   ECX
    MOV    BL,CL
    AND    BL,0Fh
    AND    CH,1
    ADD    BL,CH
    MOV    CH,DL
    AND    CH,0Fh
    CMP    BL,CH
    JGE    @L5
    SUB    AX,6
@L5:
    POP    ECX
    CMP    AX,99h
    JLE    @NotBCD
    SUB    AX,60h
@NotBCD:
    TEST   AH,AH
    JNZ    @L6
    OR     CH,1
@L6:
    MOV    CL,AL
    POP    EAX
    ADD    EDI,2
    JMP    EmulateLoop
  End; { Asm }

LF8:                 { SED }

  Asm
    OR     CH,08h
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

LF9:                 { SBC abs. y }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL

    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    XOR    DL,1
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF
    SBB    CL,BYTE PTR Mem6502[EBX]
    PUSHF
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     CH,40h
    POPF
    JO     @L4
    AND    CH,0BFh
@L4:
    OR     CL,CL
    JZ     @L1
    AND    CH,7Dh
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  @BCD:

    MOV    DL,CH
    XOR    DL,1
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF

    MOV    DL,BYTE PTR Mem6502[EBX]
    CALL   SBC_BCD

    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LFA:                 { Nothing }

  Asm
    INC    EDI
    JMP    EmulateLoop
  End; { Asm }

LFB:                 { ISB abs. y - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AH
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L4:
    AND    CH,03Ch         { Turn sign, overflow, and zero bits off }
    INC    DL
    MOV    BYTE PTR Mem6502[EBX],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    PUSH   EAX
    SUB    EAX,EAX

    MOV    AL,CL
    SUB    AL,DL
    SBB    AH,0
    MOV    BL,CH
    AND    BL,1
    XOR    BL,1
    SUB    AL,BL
    SBB    AH,0
    JNZ    @L1
    OR     CH,2
@L1:
    MOV    BL,AL
    AND    BL,80h
    OR     CH,BL

    MOV    BL,AL
    XOR    BL,CL
    TEST   BL,80h
    JZ     @L2
    MOV    BL,DL
    XOR    BL,CL
    TEST   BL,80h
    JZ     @L2
    OR     CH,40h
@L2:
    TEST   CH,8
    JZ     @NotBCD

    PUSH   ECX
    MOV    BL,CL
    AND    BL,0Fh
    AND    CH,1
    ADD    BL,CH
    MOV    CH,DL
    AND    CH,0Fh
    CMP    BL,CH
    JGE    @L5
    SUB    AX,6
@L5:
    POP    ECX
    CMP    AX,99h
    JLE    @NotBCD
    SUB    AX,60h
@NotBCD:
    TEST   AH,AH
    JNZ    @L6
    OR     CH,1
@L6:
    MOV    CL,AL
    POP    EAX
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LFC:                 { SKW Quasi-Opcode }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    SETC   DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LFD:                 { SBC abs. x }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    SETC   DL
    ADD    BH,DL
    ADD    BYTE PTR Game6502.AddCycle,DL
    TEST   CH,8
    JNZ    @BCD
    MOV    DL,CH
    XOR    DL,1
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    SBB    CL,0
    OR     CH,3

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    SUB    CL,BYTE PTR Mem6502[EBX]
    PUSHF
    JNC    @L2               { Note the difference! }
    AND    CH,0FEh
@L2:
    OR     CH,40h
    POPF
    JO     @L4
    AND    CH,0BFh
@L4:
    OR     CL,CL
    JZ     @L1
    AND    CH,7Dh
    MOV    DL,CL
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    AND    CH,7Fh
    ADD    EDI,3
    JMP    EmulateLoop
  @BCD:

    MOV    DL,CH
    XOR    DL,1
    DB     0C0h,0EAh,1       { SHR   DL,imm8 is only 2 cycles on 486 }
    PUSHF

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    POPF

    MOV    DL,BYTE PTR Mem6502[EBX]
    CALL   SBC_BCD
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LFE:                 { INC abs. x }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    ADC    BH,0
    AND    CH,7Dh

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    INC    BYTE PTR Mem6502[EBX]

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    JZ     @L1
    MOV    DL,BYTE PTR Mem6502[EBX]
    AND    DL,80h
    ADD    CH,DL
    ADD    EDI,3
    JMP    EmulateLoop
@L1:
    OR     CH,02h
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

LFF:                 { ISB abs. X - UNDOCUMENTED }

  Asm
    MOV    BX,WORD PTR [EDI+1]
    ADD    BL,AL
    MOV    DL,CH
    OR     CH,3
    SHR    DL,1

    PUSHAD
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Read
    POPAD

    MOV    DL,BYTE PTR Mem6502[EBX]
@L4:
    AND    CH,03Ch         { Turn sign, overflow, and zero bits off }
    INC    DL
    MOV    BYTE PTR Mem6502[EBX],DL

    PUSHAD
    PUSHF
    MOVZX  EDX,BYTE PTR Mem6502[EBX]
    MOV    EAX,EBX
    CALL   Handle_IO_Write
    POPF
    POPAD

    PUSH   EAX
    SUB    EAX,EAX

    MOV    AL,CL
    SUB    AL,DL
    SBB    AH,0
    MOV    BL,CH
    AND    BL,1
    XOR    BL,1
    SUB    AL,BL
    SBB    AH,0
    JNZ    @L1
    OR     CH,2
@L1:
    MOV    BL,AL
    AND    BL,80h
    OR     CH,BL

    MOV    BL,AL
    XOR    BL,CL
    TEST   BL,80h
    JZ     @L2
    MOV    BL,DL
    XOR    BL,CL
    TEST   BL,80h
    JZ     @L2
    OR     CH,40h
@L2:
    TEST   CH,8
    JZ     @NotBCD

    PUSH   ECX
    MOV    BL,CL
    AND    BL,0Fh
    AND    CH,1
    ADD    BL,CH
    MOV    CH,DL
    AND    CH,0Fh
    CMP    BL,CH
    JGE    @L5
    SUB    AX,6
@L5:
    POP    ECX
    CMP    AX,99h
    JLE    @NotBCD
    SUB    AX,60h
@NotBCD:
    TEST   AH,AH
    JNZ    @L6
    OR     CH,1
@L6:
    MOV    CL,AL
    POP    EAX
    ADD    EDI,3
    JMP    EmulateLoop
  End; { Asm }

GetOut:
  _P     := P;
  _A     := A;
  _X     := X;
  _Y     := Y;
  _S     := S;
  _Start := Start;

  Game6502.PC := Start;
  Game6502.P  := P;
  Game6502.A  := A;
  Game6502.X  := X;
  Game6502.Y  := Y;
  Game6502.S  := S;
End; { Interpret }

Initialization
  SetLocations := False;
end.

// ----------------------------------------------------------------------
// IntvWin - Mattel Intellivision Emulator
// Copyright (C) 2000 John Dullea
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
// ----------------------------------------------------------------------
