{ .$DEFINE OLD_IN }
unit Computer.CPU.Z80;

interface

uses Computer;

const // öffentlich für alle sichbar
  Z80_NMI = $66;
  I8080_NMI = $10;
  INT_RST00 = $C7; // RST 00h                    //
  INT_RST08 = $CF; // RST 08h                    //
  INT_RST10 = $D7; // RST 10h                    //
  INT_RST18 = $DF; // RST 18h                    //
  INT_RST20 = $E7; // RST 20h                    //
  INT_RST28 = $EF; // RST 28h                    //
  INT_RST30 = $F7; // RST 30h                    //
  INT_RST38 = $FF; // RST 38h                    //

type
  TCPUTable = array [0 .. 255] of byte;

  TIrqInfo = record
    Kind: byte;
    Interrupt: byte;
  end;

  TZ80CPU = class
  private
    FRegister: TZ80Register;
    FHardware: IHardware;
    FNMIInt: byte;
    FRSTMode: byte;

    in_table: TCPUTable;
    add8_table: TCPUTable;
    sub8_table: TCPUTable;
    cpsub8_table: TCPUTable;
    FAddr: Word;

    function Z80Instr(const op: byte): integer;
    function Z80Instr_IX(const op: byte): integer;
    function Z80Instr_IY(const op: byte): integer;
    function Z80Instr_CB(const op: byte): integer;
    function Z80Instr_ED(const op: byte): integer;

    function nxtpcb: integer;

    function inB(const Addr: Word): byte;
    procedure outb(const Addr: Word; const Value: byte);
    function peekb(const Addr: integer): byte;
    procedure pokeb(const Addr: integer; const val: byte);

    function EIInterrupt: integer;

  public
    constructor Create(const AHardware: IHardware);
    destructor Destroy; override;

    procedure pop(out wpval: Word);
    procedure push(const wpval: Word);

    procedure pokew(const Addr: integer; const val: Word);
    function peekw(const Addr: Word): Word;

    procedure Execute(var local_tstates: integer;
      const StatesPerInterrupt: integer);

    procedure NMI(const Value: byte);

    property Register: TZ80Register read FRegister;
  end;

var
  Z80CPU: TZ80CPU;

implementation

uses Sysutils;

const
  PARITY: TCPUTable = (4, 0, 0, 4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4, 0, 4, 4,
    0, 4, 0, 0, 4, 4, 0, 0, 4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4, 4, 0, 0, 4,
    0, 4, 4, 0, 4, 0, 0, 4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4, 0, 4, 4, 0, 4,
    0, 0, 4, 4, 0, 0, 4, 0, 4, 4, 0, 4, 0, 0, 4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0,
    0, 4, 4, 0, 0, 4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4, 0, 4, 4, 0, 4, 0, 0,
    4, 4, 0, 0, 4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4, 4, 0, 0, 4, 0, 4, 4, 0,
    4, 0, 0, 4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4, 4, 0, 0, 4, 0, 4, 4, 0, 0,
    4, 4, 0, 4, 0, 0, 4, 0, 4, 4, 0, 4, 0, 0, 4, 4, 0, 0, 4, 0, 4, 4, 0, 4, 0,
    0, 4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4, 0, 4, 4, 0, 4, 0, 0, 4, 4, 0, 0,
    4, 0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4, 4, 0, 0, 4, 0, 4, 4, 0, 4, 0, 0, 4,
    0, 4, 4, 0, 0, 4, 4, 0, 4, 0, 0, 4);

  RRA_F: TCPUTable = ($00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00,
    $01, $00, $01, $00, $01, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09,
    $08, $09, $08, $09, $08, $09, $00, $01, $00, $01, $00, $01, $00, $01, $00,
    $01, $00, $01, $00, $01, $00, $01, $08, $09, $08, $09, $08, $09, $08, $09,
    $08, $09, $08, $09, $08, $09, $08, $09, $20, $21, $20, $21, $20, $21, $20,
    $21, $20, $21, $20, $21, $20, $21, $20, $21, $28, $29, $28, $29, $28, $29,
    $28, $29, $28, $29, $28, $29, $28, $29, $28, $29, $20, $21, $20, $21, $20,
    $21, $20, $21, $20, $21, $20, $21, $20, $21, $20, $21, $28, $29, $28, $29,
    $28, $29, $28, $29, $28, $29, $28, $29, $28, $29, $28, $29, $00, $01, $00,
    $01, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $08, $09,
    $08, $09, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09, $00,
    $01, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01,
    $08, $09, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09, $08,
    $09, $20, $21, $20, $21, $20, $21, $20, $21, $20, $21, $20, $21, $20, $21,
    $20, $21, $28, $29, $28, $29, $28, $29, $28, $29, $28, $29, $28, $29, $28,
    $29, $28, $29, $20, $21, $20, $21, $20, $21, $20, $21, $20, $21, $20, $21,
    $20, $21, $20, $21, $28, $29, $28, $29, $28, $29, $28, $29, $28, $29, $28,
    $29, $28, $29, $28, $29);

  RLCR_F: TCPUTable = ($44, $00, $00, $04, $08, $0C, $0C, $08, $00, $04, $04,
    $00, $0C, $08, $08, $0C, $20, $24, $24, $20, $2C, $28, $28, $2C, $24, $20,
    $20, $24, $28, $2C, $2C, $28, $00, $04, $04, $00, $0C, $08, $08, $0C, $04,
    $00, $00, $04, $08, $0C, $0C, $08, $24, $20, $20, $24, $28, $2C, $2C, $28,
    $20, $24, $24, $20, $2C, $28, $28, $2C, $80, $84, $84, $80, $8C, $88, $88,
    $8C, $84, $80, $80, $84, $88, $8C, $8C, $88, $A4, $A0, $A0, $A4, $A8, $AC,
    $AC, $A8, $A0, $A4, $A4, $A0, $AC, $A8, $A8, $AC, $84, $80, $80, $84, $88,
    $8C, $8C, $88, $80, $84, $84, $80, $8C, $88, $88, $8C, $A0, $A4, $A4, $A0,
    $AC, $A8, $A8, $AC, $A4, $A0, $A0, $A4, $A8, $AC, $AC, $A8, $01, $05, $05,
    $01, $0D, $09, $09, $0D, $05, $01, $01, $05, $09, $0D, $0D, $09, $25, $21,
    $21, $25, $29, $2D, $2D, $29, $21, $25, $25, $21, $2D, $29, $29, $2D, $05,
    $01, $01, $05, $09, $0D, $0D, $09, $01, $05, $05, $01, $0D, $09, $09, $0D,
    $21, $25, $25, $21, $2D, $29, $29, $2D, $25, $21, $21, $25, $29, $2D, $2D,
    $29, $85, $81, $81, $85, $89, $8D, $8D, $89, $81, $85, $85, $81, $8D, $89,
    $89, $8D, $A1, $A5, $A5, $A1, $AD, $A9, $A9, $AD, $A5, $A1, $A1, $A5, $A9,
    $AD, $AD, $A9, $81, $85, $85, $81, $8D, $89, $89, $8D, $85, $81, $81, $85,
    $89, $8D, $8D, $89, $A5, $A1, $A1, $A5, $A9, $AD, $AD, $A9, $A1, $A5, $A5,
    $A1, $AD, $A9, $A9, $AD);

  RLCR_A: TCPUTable = ($00, $02, $04, $06, $08, $0A, $0C, $0E, $10, $12, $14,
    $16, $18, $1A, $1C, $1E, $20, $22, $24, $26, $28, $2A, $2C, $2E, $30, $32,
    $34, $36, $38, $3A, $3C, $3E, $40, $42, $44, $46, $48, $4A, $4C, $4E, $50,
    $52, $54, $56, $58, $5A, $5C, $5E, $60, $62, $64, $66, $68, $6A, $6C, $6E,
    $70, $72, $74, $76, $78, $7A, $7C, $7E, $80, $82, $84, $86, $88, $8A, $8C,
    $8E, $90, $92, $94, $96, $98, $9A, $9C, $9E, $A0, $A2, $A4, $A6, $A8, $AA,
    $AC, $AE, $B0, $B2, $B4, $B6, $B8, $BA, $BC, $BE, $C0, $C2, $C4, $C6, $C8,
    $CA, $CC, $CE, $D0, $D2, $D4, $D6, $D8, $DA, $DC, $DE, $E0, $E2, $E4, $E6,
    $E8, $EA, $EC, $EE, $F0, $F2, $F4, $F6, $F8, $FA, $FC, $FE, $01, $03, $05,
    $07, $09, $0B, $0D, $0F, $11, $13, $15, $17, $19, $1B, $1D, $1F, $21, $23,
    $25, $27, $29, $2B, $2D, $2F, $31, $33, $35, $37, $39, $3B, $3D, $3F, $41,
    $43, $45, $47, $49, $4B, $4D, $4F, $51, $53, $55, $57, $59, $5B, $5D, $5F,
    $61, $63, $65, $67, $69, $6B, $6D, $6F, $71, $73, $75, $77, $79, $7B, $7D,
    $7F, $81, $83, $85, $87, $89, $8B, $8D, $8F, $91, $93, $95, $97, $99, $9B,
    $9D, $9F, $A1, $A3, $A5, $A7, $A9, $AB, $AD, $AF, $B1, $B3, $B5, $B7, $B9,
    $BB, $BD, $BF, $C1, $C3, $C5, $C7, $C9, $CB, $CD, $CF, $D1, $D3, $D5, $D7,
    $D9, $DB, $DD, $DF, $E1, $E3, $E5, $E7, $E9, $EB, $ED, $EF, $F1, $F3, $F5,
    $F7, $F9, $FB, $FD, $FF);

  SLA_F: TCPUTable = ($44, $00, $00, $04, $08, $0C, $0C, $08, $00, $04, $04,
    $00, $0C, $08, $08, $0C, $20, $24, $24, $20, $2C, $28, $28, $2C, $24, $20,
    $20, $24, $28, $2C, $2C, $28, $00, $04, $04, $00, $0C, $08, $08, $0C, $04,
    $00, $00, $04, $08, $0C, $0C, $08, $24, $20, $20, $24, $28, $2C, $2C, $28,
    $20, $24, $24, $20, $2C, $28, $28, $2C, $80, $84, $84, $80, $8C, $88, $88,
    $8C, $84, $80, $80, $84, $88, $8C, $8C, $88, $A4, $A0, $A0, $A4, $A8, $AC,
    $AC, $A8, $A0, $A4, $A4, $A0, $AC, $A8, $A8, $AC, $84, $80, $80, $84, $88,
    $8C, $8C, $88, $80, $84, $84, $80, $8C, $88, $88, $8C, $A0, $A4, $A4, $A0,
    $AC, $A8, $A8, $AC, $A4, $A0, $A0, $A4, $A8, $AC, $AC, $A8, $45, $01, $01,
    $05, $09, $0D, $0D, $09, $01, $05, $05, $01, $0D, $09, $09, $0D, $21, $25,
    $25, $21, $2D, $29, $29, $2D, $25, $21, $21, $25, $29, $2D, $2D, $29, $01,
    $05, $05, $01, $0D, $09, $09, $0D, $05, $01, $01, $05, $09, $0D, $0D, $09,
    $25, $21, $21, $25, $29, $2D, $2D, $29, $21, $25, $25, $21, $2D, $29, $29,
    $2D, $81, $85, $85, $81, $8D, $89, $89, $8D, $85, $81, $81, $85, $89, $8D,
    $8D, $89, $A5, $A1, $A1, $A5, $A9, $AD, $AD, $A9, $A1, $A5, $A5, $A1, $AD,
    $A9, $A9, $AD, $85, $81, $81, $85, $89, $8D, $8D, $89, $81, $85, $85, $81,
    $8D, $89, $89, $8D, $A1, $A5, $A5, $A1, $AD, $A9, $A9, $AD, $A5, $A1, $A1,
    $A5, $A9, $AD, $AD, $A9);

  SRA_F: TCPUTable = ($44, $45, $00, $01, $00, $01, $04, $05, $00, $01, $04,
    $05, $04, $05, $00, $01, $08, $09, $0C, $0D, $0C, $0D, $08, $09, $0C, $0D,
    $08, $09, $08, $09, $0C, $0D, $00, $01, $04, $05, $04, $05, $00, $01, $04,
    $05, $00, $01, $00, $01, $04, $05, $0C, $0D, $08, $09, $08, $09, $0C, $0D,
    $08, $09, $0C, $0D, $0C, $0D, $08, $09, $20, $21, $24, $25, $24, $25, $20,
    $21, $24, $25, $20, $21, $20, $21, $24, $25, $2C, $2D, $28, $29, $28, $29,
    $2C, $2D, $28, $29, $2C, $2D, $2C, $2D, $28, $29, $24, $25, $20, $21, $20,
    $21, $24, $25, $20, $21, $24, $25, $24, $25, $20, $21, $28, $29, $2C, $2D,
    $2C, $2D, $28, $29, $2C, $2D, $28, $29, $28, $29, $2C, $2D, $84, $85, $80,
    $81, $80, $81, $84, $85, $80, $81, $84, $85, $84, $85, $80, $81, $88, $89,
    $8C, $8D, $8C, $8D, $88, $89, $8C, $8D, $88, $89, $88, $89, $8C, $8D, $80,
    $81, $84, $85, $84, $85, $80, $81, $84, $85, $80, $81, $80, $81, $84, $85,
    $8C, $8D, $88, $89, $88, $89, $8C, $8D, $88, $89, $8C, $8D, $8C, $8D, $88,
    $89, $A0, $A1, $A4, $A5, $A4, $A5, $A0, $A1, $A4, $A5, $A0, $A1, $A0, $A1,
    $A4, $A5, $AC, $AD, $A8, $A9, $A8, $A9, $AC, $AD, $A8, $A9, $AC, $AD, $AC,
    $AD, $A8, $A9, $A4, $A5, $A0, $A1, $A0, $A1, $A4, $A5, $A0, $A1, $A4, $A5,
    $A4, $A5, $A0, $A1, $A8, $A9, $AC, $AD, $AC, $AD, $A8, $A9, $AC, $AD, $A8,
    $A9, $A8, $A9, $AC, $AD);

  SRA_A: TCPUTable = ($00, $00, $01, $01, $02, $02, $03, $03, $04, $04, $05,
    $05, $06, $06, $07, $07, $08, $08, $09, $09, $0A, $0A, $0B, $0B, $0C, $0C,
    $0D, $0D, $0E, $0E, $0F, $0F, $10, $10, $11, $11, $12, $12, $13, $13, $14,
    $14, $15, $15, $16, $16, $17, $17, $18, $18, $19, $19, $1A, $1A, $1B, $1B,
    $1C, $1C, $1D, $1D, $1E, $1E, $1F, $1F, $20, $20, $21, $21, $22, $22, $23,
    $23, $24, $24, $25, $25, $26, $26, $27, $27, $28, $28, $29, $29, $2A, $2A,
    $2B, $2B, $2C, $2C, $2D, $2D, $2E, $2E, $2F, $2F, $30, $30, $31, $31, $32,
    $32, $33, $33, $34, $34, $35, $35, $36, $36, $37, $37, $38, $38, $39, $39,
    $3A, $3A, $3B, $3B, $3C, $3C, $3D, $3D, $3E, $3E, $3F, $3F, $C0, $C0, $C1,
    $C1, $C2, $C2, $C3, $C3, $C4, $C4, $C5, $C5, $C6, $C6, $C7, $C7, $C8, $C8,
    $C9, $C9, $CA, $CA, $CB, $CB, $CC, $CC, $CD, $CD, $CE, $CE, $CF, $CF, $D0,
    $D0, $D1, $D1, $D2, $D2, $D3, $D3, $D4, $D4, $D5, $D5, $D6, $D6, $D7, $D7,
    $D8, $D8, $D9, $D9, $DA, $DA, $DB, $DB, $DC, $DC, $DD, $DD, $DE, $DE, $DF,
    $DF, $E0, $E0, $E1, $E1, $E2, $E2, $E3, $E3, $E4, $E4, $E5, $E5, $E6, $E6,
    $E7, $E7, $E8, $E8, $E9, $E9, $EA, $EA, $EB, $EB, $EC, $EC, $ED, $ED, $EE,
    $EE, $EF, $EF, $F0, $F0, $F1, $F1, $F2, $F2, $F3, $F3, $F4, $F4, $F5, $F5,
    $F6, $F6, $F7, $F7, $F8, $F8, $F9, $F9, $FA, $FA, $FB, $FB, $FC, $FC, $FD,
    $FD, $FE, $FE, $FF, $FF);

  SLL_F: TCPUTable = ($00, $04, $04, $00, $0C, $08, $08, $0C, $04, $00, $00,
    $04, $08, $0C, $0C, $08, $24, $20, $20, $24, $28, $2C, $2C, $28, $20, $24,
    $24, $20, $2C, $28, $28, $2C, $04, $00, $00, $04, $08, $0C, $0C, $08, $00,
    $04, $04, $00, $0C, $08, $08, $0C, $20, $24, $24, $20, $2C, $28, $28, $2C,
    $24, $20, $20, $24, $28, $2C, $2C, $28, $84, $80, $80, $84, $88, $8C, $8C,
    $88, $80, $84, $84, $80, $8C, $88, $88, $8C, $A0, $A4, $A4, $A0, $AC, $A8,
    $A8, $AC, $A4, $A0, $A0, $A4, $A8, $AC, $AC, $A8, $80, $84, $84, $80, $8C,
    $88, $88, $8C, $84, $80, $80, $84, $88, $8C, $8C, $88, $A4, $A0, $A0, $A4,
    $A8, $AC, $AC, $A8, $A0, $A4, $A4, $A0, $AC, $A8, $A8, $AC, $01, $05, $05,
    $01, $0D, $09, $09, $0D, $05, $01, $01, $05, $09, $0D, $0D, $09, $25, $21,
    $21, $25, $29, $2D, $2D, $29, $21, $25, $25, $21, $2D, $29, $29, $2D, $05,
    $01, $01, $05, $09, $0D, $0D, $09, $01, $05, $05, $01, $0D, $09, $09, $0D,
    $21, $25, $25, $21, $2D, $29, $29, $2D, $25, $21, $21, $25, $29, $2D, $2D,
    $29, $85, $81, $81, $85, $89, $8D, $8D, $89, $81, $85, $85, $81, $8D, $89,
    $89, $8D, $A1, $A5, $A5, $A1, $AD, $A9, $A9, $AD, $A5, $A1, $A1, $A5, $A9,
    $AD, $AD, $A9, $81, $85, $85, $81, $8D, $89, $89, $8D, $85, $81, $81, $85,
    $89, $8D, $8D, $89, $A5, $A1, $A1, $A5, $A9, $AD, $AD, $A9, $A1, $A5, $A5,
    $A1, $AD, $A9, $A9, $AD);

  SLL_A: TCPUTable = ($01, $03, $05, $07, $09, $0B, $0D, $0F, $11, $13, $15,
    $17, $19, $1B, $1D, $1F, $21, $23, $25, $27, $29, $2B, $2D, $2F, $31, $33,
    $35, $37, $39, $3B, $3D, $3F, $41, $43, $45, $47, $49, $4B, $4D, $4F, $51,
    $53, $55, $57, $59, $5B, $5D, $5F, $61, $63, $65, $67, $69, $6B, $6D, $6F,
    $71, $73, $75, $77, $79, $7B, $7D, $7F, $81, $83, $85, $87, $89, $8B, $8D,
    $8F, $91, $93, $95, $97, $99, $9B, $9D, $9F, $A1, $A3, $A5, $A7, $A9, $AB,
    $AD, $AF, $B1, $B3, $B5, $B7, $B9, $BB, $BD, $BF, $C1, $C3, $C5, $C7, $C9,
    $CB, $CD, $CF, $D1, $D3, $D5, $D7, $D9, $DB, $DD, $DF, $E1, $E3, $E5, $E7,
    $E9, $EB, $ED, $EF, $F1, $F3, $F5, $F7, $F9, $FB, $FD, $FF, $01, $03, $05,
    $07, $09, $0B, $0D, $0F, $11, $13, $15, $17, $19, $1B, $1D, $1F, $21, $23,
    $25, $27, $29, $2B, $2D, $2F, $31, $33, $35, $37, $39, $3B, $3D, $3F, $41,
    $43, $45, $47, $49, $4B, $4D, $4F, $51, $53, $55, $57, $59, $5B, $5D, $5F,
    $61, $63, $65, $67, $69, $6B, $6D, $6F, $71, $73, $75, $77, $79, $7B, $7D,
    $7F, $81, $83, $85, $87, $89, $8B, $8D, $8F, $91, $93, $95, $97, $99, $9B,
    $9D, $9F, $A1, $A3, $A5, $A7, $A9, $AB, $AD, $AF, $B1, $B3, $B5, $B7, $B9,
    $BB, $BD, $BF, $C1, $C3, $C5, $C7, $C9, $CB, $CD, $CF, $D1, $D3, $D5, $D7,
    $D9, $DB, $DD, $DF, $E1, $E3, $E5, $E7, $E9, $EB, $ED, $EF, $F1, $F3, $F5,
    $F7, $F9, $FB, $FD, $FF);

  SRL_F: TCPUTable = ($44, $45, $00, $01, $00, $01, $04, $05, $00, $01, $04,
    $05, $04, $05, $00, $01, $08, $09, $0C, $0D, $0C, $0D, $08, $09, $0C, $0D,
    $08, $09, $08, $09, $0C, $0D, $00, $01, $04, $05, $04, $05, $00, $01, $04,
    $05, $00, $01, $00, $01, $04, $05, $0C, $0D, $08, $09, $08, $09, $0C, $0D,
    $08, $09, $0C, $0D, $0C, $0D, $08, $09, $20, $21, $24, $25, $24, $25, $20,
    $21, $24, $25, $20, $21, $20, $21, $24, $25, $2C, $2D, $28, $29, $28, $29,
    $2C, $2D, $28, $29, $2C, $2D, $2C, $2D, $28, $29, $24, $25, $20, $21, $20,
    $21, $24, $25, $20, $21, $24, $25, $24, $25, $20, $21, $28, $29, $2C, $2D,
    $2C, $2D, $28, $29, $2C, $2D, $28, $29, $28, $29, $2C, $2D, $00, $01, $04,
    $05, $04, $05, $00, $01, $04, $05, $00, $01, $00, $01, $04, $05, $0C, $0D,
    $08, $09, $08, $09, $0C, $0D, $08, $09, $0C, $0D, $0C, $0D, $08, $09, $04,
    $05, $00, $01, $00, $01, $04, $05, $00, $01, $04, $05, $04, $05, $00, $01,
    $08, $09, $0C, $0D, $0C, $0D, $08, $09, $0C, $0D, $08, $09, $08, $09, $0C,
    $0D, $24, $25, $20, $21, $20, $21, $24, $25, $20, $21, $24, $25, $24, $25,
    $20, $21, $28, $29, $2C, $2D, $2C, $2D, $28, $29, $2C, $2D, $28, $29, $28,
    $29, $2C, $2D, $20, $21, $24, $25, $24, $25, $20, $21, $24, $25, $20, $21,
    $20, $21, $24, $25, $2C, $2D, $28, $29, $28, $29, $2C, $2D, $28, $29, $2C,
    $2D, $2C, $2D, $28, $29);

  SRL_A: TCPUTable = ($00, $00, $01, $01, $02, $02, $03, $03, $04, $04, $05,
    $05, $06, $06, $07, $07, $08, $08, $09, $09, $0A, $0A, $0B, $0B, $0C, $0C,
    $0D, $0D, $0E, $0E, $0F, $0F, $10, $10, $11, $11, $12, $12, $13, $13, $14,
    $14, $15, $15, $16, $16, $17, $17, $18, $18, $19, $19, $1A, $1A, $1B, $1B,
    $1C, $1C, $1D, $1D, $1E, $1E, $1F, $1F, $20, $20, $21, $21, $22, $22, $23,
    $23, $24, $24, $25, $25, $26, $26, $27, $27, $28, $28, $29, $29, $2A, $2A,
    $2B, $2B, $2C, $2C, $2D, $2D, $2E, $2E, $2F, $2F, $30, $30, $31, $31, $32,
    $32, $33, $33, $34, $34, $35, $35, $36, $36, $37, $37, $38, $38, $39, $39,
    $3A, $3A, $3B, $3B, $3C, $3C, $3D, $3D, $3E, $3E, $3F, $3F, $40, $40, $41,
    $41, $42, $42, $43, $43, $44, $44, $45, $45, $46, $46, $47, $47, $48, $48,
    $49, $49, $4A, $4A, $4B, $4B, $4C, $4C, $4D, $4D, $4E, $4E, $4F, $4F, $50,
    $50, $51, $51, $52, $52, $53, $53, $54, $54, $55, $55, $56, $56, $57, $57,
    $58, $58, $59, $59, $5A, $5A, $5B, $5B, $5C, $5C, $5D, $5D, $5E, $5E, $5F,
    $5F, $60, $60, $61, $61, $62, $62, $63, $63, $64, $64, $65, $65, $66, $66,
    $67, $67, $68, $68, $69, $69, $6A, $6A, $6B, $6B, $6C, $6C, $6D, $6D, $6E,
    $6E, $6F, $6F, $70, $70, $71, $71, $72, $72, $73, $73, $74, $74, $75, $75,
    $76, $76, $77, $77, $78, $78, $79, $79, $7A, $7A, $7B, $7B, $7C, $7C, $7D,
    $7D, $7E, $7E, $7F, $7F);

  SLA_A: TCPUTable = ($00, $02, $04, $06, $08, $0A, $0C, $0E, $10, $12, $14,
    $16, $18, $1A, $1C, $1E, $20, $22, $24, $26, $28, $2A, $2C, $2E, $30, $32,
    $34, $36, $38, $3A, $3C, $3E, $40, $42, $44, $46, $48, $4A, $4C, $4E, $50,
    $52, $54, $56, $58, $5A, $5C, $5E, $60, $62, $64, $66, $68, $6A, $6C, $6E,
    $70, $72, $74, $76, $78, $7A, $7C, $7E, $80, $82, $84, $86, $88, $8A, $8C,
    $8E, $90, $92, $94, $96, $98, $9A, $9C, $9E, $A0, $A2, $A4, $A6, $A8, $AA,
    $AC, $AE, $B0, $B2, $B4, $B6, $B8, $BA, $BC, $BE, $C0, $C2, $C4, $C6, $C8,
    $CA, $CC, $CE, $D0, $D2, $D4, $D6, $D8, $DA, $DC, $DE, $E0, $E2, $E4, $E6,
    $E8, $EA, $EC, $EE, $F0, $F2, $F4, $F6, $F8, $FA, $FC, $FE, $00, $02, $04,
    $06, $08, $0A, $0C, $0E, $10, $12, $14, $16, $18, $1A, $1C, $1E, $20, $22,
    $24, $26, $28, $2A, $2C, $2E, $30, $32, $34, $36, $38, $3A, $3C, $3E, $40,
    $42, $44, $46, $48, $4A, $4C, $4E, $50, $52, $54, $56, $58, $5A, $5C, $5E,
    $60, $62, $64, $66, $68, $6A, $6C, $6E, $70, $72, $74, $76, $78, $7A, $7C,
    $7E, $80, $82, $84, $86, $88, $8A, $8C, $8E, $90, $92, $94, $96, $98, $9A,
    $9C, $9E, $A0, $A2, $A4, $A6, $A8, $AA, $AC, $AE, $B0, $B2, $B4, $B6, $B8,
    $BA, $BC, $BE, $C0, $C2, $C4, $C6, $C8, $CA, $CC, $CE, $D0, $D2, $D4, $D6,
    $D8, $DA, $DC, $DE, $E0, $E2, $E4, $E6, $E8, $EA, $EC, $EE, $F0, $F2, $F4,
    $F6, $F8, $FA, $FC, $FE);

  RRCR_F: TCPUTable = ($44, $81, $00, $85, $00, $85, $04, $81, $00, $85, $04,
    $81, $04, $81, $00, $85, $08, $8D, $0C, $89, $0C, $89, $08, $8D, $0C, $89,
    $08, $8D, $08, $8D, $0C, $89, $00, $85, $04, $81, $04, $81, $00, $85, $04,
    $81, $00, $85, $00, $85, $04, $81, $0C, $89, $08, $8D, $08, $8D, $0C, $89,
    $08, $8D, $0C, $89, $0C, $89, $08, $8D, $20, $A5, $24, $A1, $24, $A1, $20,
    $A5, $24, $A1, $20, $A5, $20, $A5, $24, $A1, $2C, $A9, $28, $AD, $28, $AD,
    $2C, $A9, $28, $AD, $2C, $A9, $2C, $A9, $28, $AD, $24, $A1, $20, $A5, $20,
    $A5, $24, $A1, $20, $A5, $24, $A1, $24, $A1, $20, $A5, $28, $AD, $2C, $A9,
    $2C, $A9, $28, $AD, $2C, $A9, $28, $AD, $28, $AD, $2C, $A9, $00, $85, $04,
    $81, $04, $81, $00, $85, $04, $81, $00, $85, $00, $85, $04, $81, $0C, $89,
    $08, $8D, $08, $8D, $0C, $89, $08, $8D, $0C, $89, $0C, $89, $08, $8D, $04,
    $81, $00, $85, $00, $85, $04, $81, $00, $85, $04, $81, $04, $81, $00, $85,
    $08, $8D, $0C, $89, $0C, $89, $08, $8D, $0C, $89, $08, $8D, $08, $8D, $0C,
    $89, $24, $A1, $20, $A5, $20, $A5, $24, $A1, $20, $A5, $24, $A1, $24, $A1,
    $20, $A5, $28, $AD, $2C, $A9, $2C, $A9, $28, $AD, $2C, $A9, $28, $AD, $28,
    $AD, $2C, $A9, $20, $A5, $24, $A1, $24, $A1, $20, $A5, $24, $A1, $20, $A5,
    $20, $A5, $24, $A1, $2C, $A9, $28, $AD, $28, $AD, $2C, $A9, $28, $AD, $2C,
    $A9, $2C, $A9, $28, $AD);

  RRCR_A: TCPUTable = ($00, $80, $01, $81, $02, $82, $03, $83, $04, $84, $05,
    $85, $06, $86, $07, $87, $08, $88, $09, $89, $0A, $8A, $0B, $8B, $0C, $8C,
    $0D, $8D, $0E, $8E, $0F, $8F, $10, $90, $11, $91, $12, $92, $13, $93, $14,
    $94, $15, $95, $16, $96, $17, $97, $18, $98, $19, $99, $1A, $9A, $1B, $9B,
    $1C, $9C, $1D, $9D, $1E, $9E, $1F, $9F, $20, $A0, $21, $A1, $22, $A2, $23,
    $A3, $24, $A4, $25, $A5, $26, $A6, $27, $A7, $28, $A8, $29, $A9, $2A, $AA,
    $2B, $AB, $2C, $AC, $2D, $AD, $2E, $AE, $2F, $AF, $30, $B0, $31, $B1, $32,
    $B2, $33, $B3, $34, $B4, $35, $B5, $36, $B6, $37, $B7, $38, $B8, $39, $B9,
    $3A, $BA, $3B, $BB, $3C, $BC, $3D, $BD, $3E, $BE, $3F, $BF, $40, $C0, $41,
    $C1, $42, $C2, $43, $C3, $44, $C4, $45, $C5, $46, $C6, $47, $C7, $48, $C8,
    $49, $C9, $4A, $CA, $4B, $CB, $4C, $CC, $4D, $CD, $4E, $CE, $4F, $CF, $50,
    $D0, $51, $D1, $52, $D2, $53, $D3, $54, $D4, $55, $D5, $56, $D6, $57, $D7,
    $58, $D8, $59, $D9, $5A, $DA, $5B, $DB, $5C, $DC, $5D, $DD, $5E, $DE, $5F,
    $DF, $60, $E0, $61, $E1, $62, $E2, $63, $E3, $64, $E4, $65, $E5, $66, $E6,
    $67, $E7, $68, $E8, $69, $E9, $6A, $EA, $6B, $EB, $6C, $EC, $6D, $ED, $6E,
    $EE, $6F, $EF, $70, $F0, $71, $F1, $72, $F2, $73, $F3, $74, $F4, $75, $F5,
    $76, $F6, $77, $F7, $78, $F8, $79, $F9, $7A, $FA, $7B, $FB, $7C, $FC, $7D,
    $FD, $7E, $FE, $7F, $FF);

  INC_F: TCPUTable = ($00, $00, $00, $00, $00, $00, $00, $08, $08, $08, $08,
    $08, $08, $08, $08, $10, $00, $00, $00, $00, $00, $00, $00, $08, $08, $08,
    $08, $08, $08, $08, $08, $30, $20, $20, $20, $20, $20, $20, $20, $28, $28,
    $28, $28, $28, $28, $28, $28, $30, $20, $20, $20, $20, $20, $20, $20, $28,
    $28, $28, $28, $28, $28, $28, $28, $10, $00, $00, $00, $00, $00, $00, $00,
    $08, $08, $08, $08, $08, $08, $08, $08, $10, $00, $00, $00, $00, $00, $00,
    $00, $08, $08, $08, $08, $08, $08, $08, $08, $30, $20, $20, $20, $20, $20,
    $20, $20, $28, $28, $28, $28, $28, $28, $28, $28, $30, $20, $20, $20, $20,
    $20, $20, $20, $28, $28, $28, $28, $28, $28, $28, $28, $94, $80, $80, $80,
    $80, $80, $80, $80, $88, $88, $88, $88, $88, $88, $88, $88, $90, $80, $80,
    $80, $80, $80, $80, $80, $88, $88, $88, $88, $88, $88, $88, $88, $B0, $A0,
    $A0, $A0, $A0, $A0, $A0, $A0, $A8, $A8, $A8, $A8, $A8, $A8, $A8, $A8, $B0,
    $A0, $A0, $A0, $A0, $A0, $A0, $A0, $A8, $A8, $A8, $A8, $A8, $A8, $A8, $A8,
    $90, $80, $80, $80, $80, $80, $80, $80, $88, $88, $88, $88, $88, $88, $88,
    $88, $90, $80, $80, $80, $80, $80, $80, $80, $88, $88, $88, $88, $88, $88,
    $88, $88, $B0, $A0, $A0, $A0, $A0, $A0, $A0, $A0, $A8, $A8, $A8, $A8, $A8,
    $A8, $A8, $A8, $B0, $A0, $A0, $A0, $A0, $A0, $A0, $A0, $A8, $A8, $A8, $A8,
    $A8, $A8, $A8, $A8, $50);

  DEC_F: TCPUTable = ($BA, $42, $02, $02, $02, $02, $02, $02, $02, $0A, $0A,
    $0A, $0A, $0A, $0A, $0A, $1A, $02, $02, $02, $02, $02, $02, $02, $02, $0A,
    $0A, $0A, $0A, $0A, $0A, $0A, $1A, $22, $22, $22, $22, $22, $22, $22, $22,
    $2A, $2A, $2A, $2A, $2A, $2A, $2A, $3A, $22, $22, $22, $22, $22, $22, $22,
    $22, $2A, $2A, $2A, $2A, $2A, $2A, $2A, $3A, $02, $02, $02, $02, $02, $02,
    $02, $02, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $1A, $02, $02, $02, $02, $02,
    $02, $02, $02, $0A, $0A, $0A, $0A, $0A, $0A, $0A, $1A, $22, $22, $22, $22,
    $22, $22, $22, $22, $2A, $2A, $2A, $2A, $2A, $2A, $2A, $3A, $22, $22, $22,
    $22, $22, $22, $22, $22, $2A, $2A, $2A, $2A, $2A, $2A, $2A, $3E, $82, $82,
    $82, $82, $82, $82, $82, $82, $8A, $8A, $8A, $8A, $8A, $8A, $8A, $9A, $82,
    $82, $82, $82, $82, $82, $82, $82, $8A, $8A, $8A, $8A, $8A, $8A, $8A, $9A,
    $A2, $A2, $A2, $A2, $A2, $A2, $A2, $A2, $AA, $AA, $AA, $AA, $AA, $AA, $AA,
    $BA, $A2, $A2, $A2, $A2, $A2, $A2, $A2, $A2, $AA, $AA, $AA, $AA, $AA, $AA,
    $AA, $BA, $82, $82, $82, $82, $82, $82, $82, $82, $8A, $8A, $8A, $8A, $8A,
    $8A, $8A, $9A, $82, $82, $82, $82, $82, $82, $82, $82, $8A, $8A, $8A, $8A,
    $8A, $8A, $8A, $9A, $A2, $A2, $A2, $A2, $A2, $A2, $A2, $A2, $AA, $AA, $AA,
    $AA, $AA, $AA, $AA, $BA, $A2, $A2, $A2, $A2, $A2, $A2, $A2, $A2, $AA, $AA,
    $AA, $AA, $AA, $AA, $AA);

  BIT_F0: TCPUTable = ($54, $10, $54, $10, $54, $10, $54, $10, $5C, $18, $5C,
    $18, $5C, $18, $5C, $18, $54, $10, $54, $10, $54, $10, $54, $10, $5C, $18,
    $5C, $18, $5C, $18, $5C, $18, $74, $30, $74, $30, $74, $30, $74, $30, $7C,
    $38, $7C, $38, $7C, $38, $7C, $38, $74, $30, $74, $30, $74, $30, $74, $30,
    $7C, $38, $7C, $38, $7C, $38, $7C, $38, $54, $10, $54, $10, $54, $10, $54,
    $10, $5C, $18, $5C, $18, $5C, $18, $5C, $18, $54, $10, $54, $10, $54, $10,
    $54, $10, $5C, $18, $5C, $18, $5C, $18, $5C, $18, $74, $30, $74, $30, $74,
    $30, $74, $30, $7C, $38, $7C, $38, $7C, $38, $7C, $38, $74, $30, $74, $30,
    $74, $30, $74, $30, $7C, $38, $7C, $38, $7C, $38, $7C, $38, $54, $10, $54,
    $10, $54, $10, $54, $10, $5C, $18, $5C, $18, $5C, $18, $5C, $18, $54, $10,
    $54, $10, $54, $10, $54, $10, $5C, $18, $5C, $18, $5C, $18, $5C, $18, $74,
    $30, $74, $30, $74, $30, $74, $30, $7C, $38, $7C, $38, $7C, $38, $7C, $38,
    $74, $30, $74, $30, $74, $30, $74, $30, $7C, $38, $7C, $38, $7C, $38, $7C,
    $38, $54, $10, $54, $10, $54, $10, $54, $10, $5C, $18, $5C, $18, $5C, $18,
    $5C, $18, $54, $10, $54, $10, $54, $10, $54, $10, $5C, $18, $5C, $18, $5C,
    $18, $5C, $18, $74, $30, $74, $30, $74, $30, $74, $30, $7C, $38, $7C, $38,
    $7C, $38, $7C, $38, $74, $30, $74, $30, $74, $30, $74, $30, $7C, $38, $7C,
    $38, $7C, $38, $7C, $38);

  BIT_F1: TCPUTable = ($54, $54, $10, $10, $54, $54, $10, $10, $5C, $5C, $18,
    $18, $5C, $5C, $18, $18, $54, $54, $10, $10, $54, $54, $10, $10, $5C, $5C,
    $18, $18, $5C, $5C, $18, $18, $74, $74, $30, $30, $74, $74, $30, $30, $7C,
    $7C, $38, $38, $7C, $7C, $38, $38, $74, $74, $30, $30, $74, $74, $30, $30,
    $7C, $7C, $38, $38, $7C, $7C, $38, $38, $54, $54, $10, $10, $54, $54, $10,
    $10, $5C, $5C, $18, $18, $5C, $5C, $18, $18, $54, $54, $10, $10, $54, $54,
    $10, $10, $5C, $5C, $18, $18, $5C, $5C, $18, $18, $74, $74, $30, $30, $74,
    $74, $30, $30, $7C, $7C, $38, $38, $7C, $7C, $38, $38, $74, $74, $30, $30,
    $74, $74, $30, $30, $7C, $7C, $38, $38, $7C, $7C, $38, $38, $54, $54, $10,
    $10, $54, $54, $10, $10, $5C, $5C, $18, $18, $5C, $5C, $18, $18, $54, $54,
    $10, $10, $54, $54, $10, $10, $5C, $5C, $18, $18, $5C, $5C, $18, $18, $74,
    $74, $30, $30, $74, $74, $30, $30, $7C, $7C, $38, $38, $7C, $7C, $38, $38,
    $74, $74, $30, $30, $74, $74, $30, $30, $7C, $7C, $38, $38, $7C, $7C, $38,
    $38, $54, $54, $10, $10, $54, $54, $10, $10, $5C, $5C, $18, $18, $5C, $5C,
    $18, $18, $54, $54, $10, $10, $54, $54, $10, $10, $5C, $5C, $18, $18, $5C,
    $5C, $18, $18, $74, $74, $30, $30, $74, $74, $30, $30, $7C, $7C, $38, $38,
    $7C, $7C, $38, $38, $74, $74, $30, $30, $74, $74, $30, $30, $7C, $7C, $38,
    $38, $7C, $7C, $38, $38);

  BIT_F2: TCPUTable = ($54, $54, $54, $54, $10, $10, $10, $10, $5C, $5C, $5C,
    $5C, $18, $18, $18, $18, $54, $54, $54, $54, $10, $10, $10, $10, $5C, $5C,
    $5C, $5C, $18, $18, $18, $18, $74, $74, $74, $74, $30, $30, $30, $30, $7C,
    $7C, $7C, $7C, $38, $38, $38, $38, $74, $74, $74, $74, $30, $30, $30, $30,
    $7C, $7C, $7C, $7C, $38, $38, $38, $38, $54, $54, $54, $54, $10, $10, $10,
    $10, $5C, $5C, $5C, $5C, $18, $18, $18, $18, $54, $54, $54, $54, $10, $10,
    $10, $10, $5C, $5C, $5C, $5C, $18, $18, $18, $18, $74, $74, $74, $74, $30,
    $30, $30, $30, $7C, $7C, $7C, $7C, $38, $38, $38, $38, $74, $74, $74, $74,
    $30, $30, $30, $30, $7C, $7C, $7C, $7C, $38, $38, $38, $38, $54, $54, $54,
    $54, $10, $10, $10, $10, $5C, $5C, $5C, $5C, $18, $18, $18, $18, $54, $54,
    $54, $54, $10, $10, $10, $10, $5C, $5C, $5C, $5C, $18, $18, $18, $18, $74,
    $74, $74, $74, $30, $30, $30, $30, $7C, $7C, $7C, $7C, $38, $38, $38, $38,
    $74, $74, $74, $74, $30, $30, $30, $30, $7C, $7C, $7C, $7C, $38, $38, $38,
    $38, $54, $54, $54, $54, $10, $10, $10, $10, $5C, $5C, $5C, $5C, $18, $18,
    $18, $18, $54, $54, $54, $54, $10, $10, $10, $10, $5C, $5C, $5C, $5C, $18,
    $18, $18, $18, $74, $74, $74, $74, $30, $30, $30, $30, $7C, $7C, $7C, $7C,
    $38, $38, $38, $38, $74, $74, $74, $74, $30, $30, $30, $30, $7C, $7C, $7C,
    $7C, $38, $38, $38, $38);

  BIT_F3: TCPUTable = ($54, $54, $54, $54, $54, $54, $54, $54, $18, $18, $18,
    $18, $18, $18, $18, $18, $54, $54, $54, $54, $54, $54, $54, $54, $18, $18,
    $18, $18, $18, $18, $18, $18, $74, $74, $74, $74, $74, $74, $74, $74, $38,
    $38, $38, $38, $38, $38, $38, $38, $74, $74, $74, $74, $74, $74, $74, $74,
    $38, $38, $38, $38, $38, $38, $38, $38, $54, $54, $54, $54, $54, $54, $54,
    $54, $18, $18, $18, $18, $18, $18, $18, $18, $54, $54, $54, $54, $54, $54,
    $54, $54, $18, $18, $18, $18, $18, $18, $18, $18, $74, $74, $74, $74, $74,
    $74, $74, $74, $38, $38, $38, $38, $38, $38, $38, $38, $74, $74, $74, $74,
    $74, $74, $74, $74, $38, $38, $38, $38, $38, $38, $38, $38, $54, $54, $54,
    $54, $54, $54, $54, $54, $18, $18, $18, $18, $18, $18, $18, $18, $54, $54,
    $54, $54, $54, $54, $54, $54, $18, $18, $18, $18, $18, $18, $18, $18, $74,
    $74, $74, $74, $74, $74, $74, $74, $38, $38, $38, $38, $38, $38, $38, $38,
    $74, $74, $74, $74, $74, $74, $74, $74, $38, $38, $38, $38, $38, $38, $38,
    $38, $54, $54, $54, $54, $54, $54, $54, $54, $18, $18, $18, $18, $18, $18,
    $18, $18, $54, $54, $54, $54, $54, $54, $54, $54, $18, $18, $18, $18, $18,
    $18, $18, $18, $74, $74, $74, $74, $74, $74, $74, $74, $38, $38, $38, $38,
    $38, $38, $38, $38, $74, $74, $74, $74, $74, $74, $74, $74, $38, $38, $38,
    $38, $38, $38, $38, $38);

  BIT_F4: TCPUTable = ($54, $54, $54, $54, $54, $54, $54, $54, $5C, $5C, $5C,
    $5C, $5C, $5C, $5C, $5C, $10, $10, $10, $10, $10, $10, $10, $10, $18, $18,
    $18, $18, $18, $18, $18, $18, $74, $74, $74, $74, $74, $74, $74, $74, $7C,
    $7C, $7C, $7C, $7C, $7C, $7C, $7C, $30, $30, $30, $30, $30, $30, $30, $30,
    $38, $38, $38, $38, $38, $38, $38, $38, $54, $54, $54, $54, $54, $54, $54,
    $54, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $10, $10, $10, $10, $10, $10,
    $10, $10, $18, $18, $18, $18, $18, $18, $18, $18, $74, $74, $74, $74, $74,
    $74, $74, $74, $7C, $7C, $7C, $7C, $7C, $7C, $7C, $7C, $30, $30, $30, $30,
    $30, $30, $30, $30, $38, $38, $38, $38, $38, $38, $38, $38, $54, $54, $54,
    $54, $54, $54, $54, $54, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $10, $10,
    $10, $10, $10, $10, $10, $10, $18, $18, $18, $18, $18, $18, $18, $18, $74,
    $74, $74, $74, $74, $74, $74, $74, $7C, $7C, $7C, $7C, $7C, $7C, $7C, $7C,
    $30, $30, $30, $30, $30, $30, $30, $30, $38, $38, $38, $38, $38, $38, $38,
    $38, $54, $54, $54, $54, $54, $54, $54, $54, $5C, $5C, $5C, $5C, $5C, $5C,
    $5C, $5C, $10, $10, $10, $10, $10, $10, $10, $10, $18, $18, $18, $18, $18,
    $18, $18, $18, $74, $74, $74, $74, $74, $74, $74, $74, $7C, $7C, $7C, $7C,
    $7C, $7C, $7C, $7C, $30, $30, $30, $30, $30, $30, $30, $30, $38, $38, $38,
    $38, $38, $38, $38, $38);

  BIT_F5: TCPUTable = ($54, $54, $54, $54, $54, $54, $54, $54, $5C, $5C, $5C,
    $5C, $5C, $5C, $5C, $5C, $54, $54, $54, $54, $54, $54, $54, $54, $5C, $5C,
    $5C, $5C, $5C, $5C, $5C, $5C, $30, $30, $30, $30, $30, $30, $30, $30, $38,
    $38, $38, $38, $38, $38, $38, $38, $30, $30, $30, $30, $30, $30, $30, $30,
    $38, $38, $38, $38, $38, $38, $38, $38, $54, $54, $54, $54, $54, $54, $54,
    $54, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $54, $54, $54, $54, $54, $54,
    $54, $54, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $30, $30, $30, $30, $30,
    $30, $30, $30, $38, $38, $38, $38, $38, $38, $38, $38, $30, $30, $30, $30,
    $30, $30, $30, $30, $38, $38, $38, $38, $38, $38, $38, $38, $54, $54, $54,
    $54, $54, $54, $54, $54, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $54, $54,
    $54, $54, $54, $54, $54, $54, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $30,
    $30, $30, $30, $30, $30, $30, $30, $38, $38, $38, $38, $38, $38, $38, $38,
    $30, $30, $30, $30, $30, $30, $30, $30, $38, $38, $38, $38, $38, $38, $38,
    $38, $54, $54, $54, $54, $54, $54, $54, $54, $5C, $5C, $5C, $5C, $5C, $5C,
    $5C, $5C, $54, $54, $54, $54, $54, $54, $54, $54, $5C, $5C, $5C, $5C, $5C,
    $5C, $5C, $5C, $30, $30, $30, $30, $30, $30, $30, $30, $38, $38, $38, $38,
    $38, $38, $38, $38, $30, $30, $30, $30, $30, $30, $30, $30, $38, $38, $38,
    $38, $38, $38, $38, $38);

  BIT_F6: TCPUTable = ($54, $54, $54, $54, $54, $54, $54, $54, $5C, $5C, $5C,
    $5C, $5C, $5C, $5C, $5C, $54, $54, $54, $54, $54, $54, $54, $54, $5C, $5C,
    $5C, $5C, $5C, $5C, $5C, $5C, $74, $74, $74, $74, $74, $74, $74, $74, $7C,
    $7C, $7C, $7C, $7C, $7C, $7C, $7C, $74, $74, $74, $74, $74, $74, $74, $74,
    $7C, $7C, $7C, $7C, $7C, $7C, $7C, $7C, $10, $10, $10, $10, $10, $10, $10,
    $10, $18, $18, $18, $18, $18, $18, $18, $18, $10, $10, $10, $10, $10, $10,
    $10, $10, $18, $18, $18, $18, $18, $18, $18, $18, $30, $30, $30, $30, $30,
    $30, $30, $30, $38, $38, $38, $38, $38, $38, $38, $38, $30, $30, $30, $30,
    $30, $30, $30, $30, $38, $38, $38, $38, $38, $38, $38, $38, $54, $54, $54,
    $54, $54, $54, $54, $54, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $54, $54,
    $54, $54, $54, $54, $54, $54, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $74,
    $74, $74, $74, $74, $74, $74, $74, $7C, $7C, $7C, $7C, $7C, $7C, $7C, $7C,
    $74, $74, $74, $74, $74, $74, $74, $74, $7C, $7C, $7C, $7C, $7C, $7C, $7C,
    $7C, $10, $10, $10, $10, $10, $10, $10, $10, $18, $18, $18, $18, $18, $18,
    $18, $18, $10, $10, $10, $10, $10, $10, $10, $10, $18, $18, $18, $18, $18,
    $18, $18, $18, $30, $30, $30, $30, $30, $30, $30, $30, $38, $38, $38, $38,
    $38, $38, $38, $38, $30, $30, $30, $30, $30, $30, $30, $30, $38, $38, $38,
    $38, $38, $38, $38, $38);

  BIT_F7: TCPUTable = ($54, $54, $54, $54, $54, $54, $54, $54, $5C, $5C, $5C,
    $5C, $5C, $5C, $5C, $5C, $54, $54, $54, $54, $54, $54, $54, $54, $5C, $5C,
    $5C, $5C, $5C, $5C, $5C, $5C, $74, $74, $74, $74, $74, $74, $74, $74, $7C,
    $7C, $7C, $7C, $7C, $7C, $7C, $7C, $74, $74, $74, $74, $74, $74, $74, $74,
    $7C, $7C, $7C, $7C, $7C, $7C, $7C, $7C, $54, $54, $54, $54, $54, $54, $54,
    $54, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $54, $54, $54, $54, $54, $54,
    $54, $54, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $5C, $74, $74, $74, $74, $74,
    $74, $74, $74, $7C, $7C, $7C, $7C, $7C, $7C, $7C, $7C, $74, $74, $74, $74,
    $74, $74, $74, $74, $7C, $7C, $7C, $7C, $7C, $7C, $7C, $7C, $90, $90, $90,
    $90, $90, $90, $90, $90, $98, $98, $98, $98, $98, $98, $98, $98, $90, $90,
    $90, $90, $90, $90, $90, $90, $98, $98, $98, $98, $98, $98, $98, $98, $B0,
    $B0, $B0, $B0, $B0, $B0, $B0, $B0, $B8, $B8, $B8, $B8, $B8, $B8, $B8, $B8,
    $B0, $B0, $B0, $B0, $B0, $B0, $B0, $B0, $B8, $B8, $B8, $B8, $B8, $B8, $B8,
    $B8, $90, $90, $90, $90, $90, $90, $90, $90, $98, $98, $98, $98, $98, $98,
    $98, $98, $90, $90, $90, $90, $90, $90, $90, $90, $98, $98, $98, $98, $98,
    $98, $98, $98, $B0, $B0, $B0, $B0, $B0, $B0, $B0, $B0, $B8, $B8, $B8, $B8,
    $B8, $B8, $B8, $B8, $B0, $B0, $B0, $B0, $B0, $B0, $B0, $B0, $B8, $B8, $B8,
    $B8, $B8, $B8, $B8, $B8);

  RRA_A: array [0 .. 1, 0 .. 255] of byte = (($00, $00, $01, $01, $02, $02, $03,
    $03, $04, $04, $05, $05, $06, $06, $07, $07, $08, $08, $09, $09, $0A, $0A,
    $0B, $0B, $0C, $0C, $0D, $0D, $0E, $0E, $0F, $0F, $10, $10, $11, $11, $12,
    $12, $13, $13, $14, $14, $15, $15, $16, $16, $17, $17, $18, $18, $19, $19,
    $1A, $1A, $1B, $1B, $1C, $1C, $1D, $1D, $1E, $1E, $1F, $1F, $20, $20, $21,
    $21, $22, $22, $23, $23, $24, $24, $25, $25, $26, $26, $27, $27, $28, $28,
    $29, $29, $2A, $2A, $2B, $2B, $2C, $2C, $2D, $2D, $2E, $2E, $2F, $2F, $30,
    $30, $31, $31, $32, $32, $33, $33, $34, $34, $35, $35, $36, $36, $37, $37,
    $38, $38, $39, $39, $3A, $3A, $3B, $3B, $3C, $3C, $3D, $3D, $3E, $3E, $3F,
    $3F, $40, $40, $41, $41, $42, $42, $43, $43, $44, $44, $45, $45, $46, $46,
    $47, $47, $48, $48, $49, $49, $4A, $4A, $4B, $4B, $4C, $4C, $4D, $4D, $4E,
    $4E, $4F, $4F, $50, $50, $51, $51, $52, $52, $53, $53, $54, $54, $55, $55,
    $56, $56, $57, $57, $58, $58, $59, $59, $5A, $5A, $5B, $5B, $5C, $5C, $5D,
    $5D, $5E, $5E, $5F, $5F, $60, $60, $61, $61, $62, $62, $63, $63, $64, $64,
    $65, $65, $66, $66, $67, $67, $68, $68, $69, $69, $6A, $6A, $6B, $6B, $6C,
    $6C, $6D, $6D, $6E, $6E, $6F, $6F, $70, $70, $71, $71, $72, $72, $73, $73,
    $74, $74, $75, $75, $76, $76, $77, $77, $78, $78, $79, $79, $7A, $7A, $7B,
    $7B, $7C, $7C, $7D, $7D, $7E, $7E, $7F, $7F), ($80, $80, $81, $81, $82, $82,
    $83, $83, $84, $84, $85, $85, $86, $86, $87, $87, $88, $88, $89, $89, $8A,
    $8A, $8B, $8B, $8C, $8C, $8D, $8D, $8E, $8E, $8F, $8F, $90, $90, $91, $91,
    $92, $92, $93, $93, $94, $94, $95, $95, $96, $96, $97, $97, $98, $98, $99,
    $99, $9A, $9A, $9B, $9B, $9C, $9C, $9D, $9D, $9E, $9E, $9F, $9F, $A0, $A0,
    $A1, $A1, $A2, $A2, $A3, $A3, $A4, $A4, $A5, $A5, $A6, $A6, $A7, $A7, $A8,
    $A8, $A9, $A9, $AA, $AA, $AB, $AB, $AC, $AC, $AD, $AD, $AE, $AE, $AF, $AF,
    $B0, $B0, $B1, $B1, $B2, $B2, $B3, $B3, $B4, $B4, $B5, $B5, $B6, $B6, $B7,
    $B7, $B8, $B8, $B9, $B9, $BA, $BA, $BB, $BB, $BC, $BC, $BD, $BD, $BE, $BE,
    $BF, $BF, $C0, $C0, $C1, $C1, $C2, $C2, $C3, $C3, $C4, $C4, $C5, $C5, $C6,
    $C6, $C7, $C7, $C8, $C8, $C9, $C9, $CA, $CA, $CB, $CB, $CC, $CC, $CD, $CD,
    $CE, $CE, $CF, $CF, $D0, $D0, $D1, $D1, $D2, $D2, $D3, $D3, $D4, $D4, $D5,
    $D5, $D6, $D6, $D7, $D7, $D8, $D8, $D9, $D9, $DA, $DA, $DB, $DB, $DC, $DC,
    $DD, $DD, $DE, $DE, $DF, $DF, $E0, $E0, $E1, $E1, $E2, $E2, $E3, $E3, $E4,
    $E4, $E5, $E5, $E6, $E6, $E7, $E7, $E8, $E8, $E9, $E9, $EA, $EA, $EB, $EB,
    $EC, $EC, $ED, $ED, $EE, $EE, $EF, $EF, $F0, $F0, $F1, $F1, $F2, $F2, $F3,
    $F3, $F4, $F4, $F5, $F5, $F6, $F6, $F7, $F7, $F8, $F8, $F9, $F9, $FA, $FA,
    $FB, $FB, $FC, $FC, $FD, $FD, $FE, $FE, $FF, $FF));

  RLCA_F: array [0 .. 1, 0 .. 255] of byte = (($00, $00, $00, $00, $08, $08,
    $08, $08, $00, $00, $00, $00, $08, $08, $08, $08, $20, $20, $20, $20, $28,
    $28, $28, $28, $20, $20, $20, $20, $28, $28, $28, $28, $00, $00, $00, $00,
    $08, $08, $08, $08, $00, $00, $00, $00, $08, $08, $08, $08, $20, $20, $20,
    $20, $28, $28, $28, $28, $20, $20, $20, $20, $28, $28, $28, $28, $00, $00,
    $00, $00, $08, $08, $08, $08, $00, $00, $00, $00, $08, $08, $08, $08, $20,
    $20, $20, $20, $28, $28, $28, $28, $20, $20, $20, $20, $28, $28, $28, $28,
    $00, $00, $00, $00, $08, $08, $08, $08, $00, $00, $00, $00, $08, $08, $08,
    $08, $20, $20, $20, $20, $28, $28, $28, $28, $20, $20, $20, $20, $28, $28,
    $28, $28, $01, $01, $01, $01, $09, $09, $09, $09, $01, $01, $01, $01, $09,
    $09, $09, $09, $21, $21, $21, $21, $29, $29, $29, $29, $21, $21, $21, $21,
    $29, $29, $29, $29, $01, $01, $01, $01, $09, $09, $09, $09, $01, $01, $01,
    $01, $09, $09, $09, $09, $21, $21, $21, $21, $29, $29, $29, $29, $21, $21,
    $21, $21, $29, $29, $29, $29, $01, $01, $01, $01, $09, $09, $09, $09, $01,
    $01, $01, $01, $09, $09, $09, $09, $21, $21, $21, $21, $29, $29, $29, $29,
    $21, $21, $21, $21, $29, $29, $29, $29, $01, $01, $01, $01, $09, $09, $09,
    $09, $01, $01, $01, $01, $09, $09, $09, $09, $21, $21, $21, $21, $29, $29,
    $29, $29, $21, $21, $21, $21, $29, $29, $29, $29),
    ($00, $00, $00, $00, $08, $08, $08, $08, $00, $00, $00, $00, $08, $08, $08,
    $08, $20, $20, $20, $20, $28, $28, $28, $28, $20, $20, $20, $20, $28, $28,
    $28, $28, $00, $00, $00, $00, $08, $08, $08, $08, $00, $00, $00, $00, $08,
    $08, $08, $08, $20, $20, $20, $20, $28, $28, $28, $28, $20, $20, $20, $20,
    $28, $28, $28, $28, $00, $00, $00, $00, $08, $08, $08, $08, $00, $00, $00,
    $00, $08, $08, $08, $08, $20, $20, $20, $20, $28, $28, $28, $28, $20, $20,
    $20, $20, $28, $28, $28, $28, $00, $00, $00, $00, $08, $08, $08, $08, $00,
    $00, $00, $00, $08, $08, $08, $08, $20, $20, $20, $20, $28, $28, $28, $28,
    $20, $20, $20, $20, $28, $28, $28, $28, $01, $01, $01, $01, $09, $09, $09,
    $09, $01, $01, $01, $01, $09, $09, $09, $09, $21, $21, $21, $21, $29, $29,
    $29, $29, $21, $21, $21, $21, $29, $29, $29, $29, $01, $01, $01, $01, $09,
    $09, $09, $09, $01, $01, $01, $01, $09, $09, $09, $09, $21, $21, $21, $21,
    $29, $29, $29, $29, $21, $21, $21, $21, $29, $29, $29, $29, $01, $01, $01,
    $01, $09, $09, $09, $09, $01, $01, $01, $01, $09, $09, $09, $09, $21, $21,
    $21, $21, $29, $29, $29, $29, $21, $21, $21, $21, $29, $29, $29, $29, $01,
    $01, $01, $01, $09, $09, $09, $09, $01, $01, $01, $01, $09, $09, $09, $09,
    $21, $21, $21, $21, $29, $29, $29, $29, $21, $21, $21, $21, $29, $29,
    $29, $29));

  RLCA_A: array [0 .. 1, 0 .. 255] of byte = (($00, $02, $04, $06, $08, $0A,
    $0C, $0E, $10, $12, $14, $16, $18, $1A, $1C, $1E, $20, $22, $24, $26, $28,
    $2A, $2C, $2E, $30, $32, $34, $36, $38, $3A, $3C, $3E, $40, $42, $44, $46,
    $48, $4A, $4C, $4E, $50, $52, $54, $56, $58, $5A, $5C, $5E, $60, $62, $64,
    $66, $68, $6A, $6C, $6E, $70, $72, $74, $76, $78, $7A, $7C, $7E, $80, $82,
    $84, $86, $88, $8A, $8C, $8E, $90, $92, $94, $96, $98, $9A, $9C, $9E, $A0,
    $A2, $A4, $A6, $A8, $AA, $AC, $AE, $B0, $B2, $B4, $B6, $B8, $BA, $BC, $BE,
    $C0, $C2, $C4, $C6, $C8, $CA, $CC, $CE, $D0, $D2, $D4, $D6, $D8, $DA, $DC,
    $DE, $E0, $E2, $E4, $E6, $E8, $EA, $EC, $EE, $F0, $F2, $F4, $F6, $F8, $FA,
    $FC, $FE, $01, $03, $05, $07, $09, $0B, $0D, $0F, $11, $13, $15, $17, $19,
    $1B, $1D, $1F, $21, $23, $25, $27, $29, $2B, $2D, $2F, $31, $33, $35, $37,
    $39, $3B, $3D, $3F, $41, $43, $45, $47, $49, $4B, $4D, $4F, $51, $53, $55,
    $57, $59, $5B, $5D, $5F, $61, $63, $65, $67, $69, $6B, $6D, $6F, $71, $73,
    $75, $77, $79, $7B, $7D, $7F, $81, $83, $85, $87, $89, $8B, $8D, $8F, $91,
    $93, $95, $97, $99, $9B, $9D, $9F, $A1, $A3, $A5, $A7, $A9, $AB, $AD, $AF,
    $B1, $B3, $B5, $B7, $B9, $BB, $BD, $BF, $C1, $C3, $C5, $C7, $C9, $CB, $CD,
    $CF, $D1, $D3, $D5, $D7, $D9, $DB, $DD, $DF, $E1, $E3, $E5, $E7, $E9, $EB,
    $ED, $EF, $F1, $F3, $F5, $F7, $F9, $FB, $FD, $FF),
    ($00, $02, $04, $06, $08, $0A, $0C, $0E, $10, $12, $14, $16, $18, $1A, $1C,
    $1E, $20, $22, $24, $26, $28, $2A, $2C, $2E, $30, $32, $34, $36, $38, $3A,
    $3C, $3E, $40, $42, $44, $46, $48, $4A, $4C, $4E, $50, $52, $54, $56, $58,
    $5A, $5C, $5E, $60, $62, $64, $66, $68, $6A, $6C, $6E, $70, $72, $74, $76,
    $78, $7A, $7C, $7E, $80, $82, $84, $86, $88, $8A, $8C, $8E, $90, $92, $94,
    $96, $98, $9A, $9C, $9E, $A0, $A2, $A4, $A6, $A8, $AA, $AC, $AE, $B0, $B2,
    $B4, $B6, $B8, $BA, $BC, $BE, $C0, $C2, $C4, $C6, $C8, $CA, $CC, $CE, $D0,
    $D2, $D4, $D6, $D8, $DA, $DC, $DE, $E0, $E2, $E4, $E6, $E8, $EA, $EC, $EE,
    $F0, $F2, $F4, $F6, $F8, $FA, $FC, $FE, $01, $03, $05, $07, $09, $0B, $0D,
    $0F, $11, $13, $15, $17, $19, $1B, $1D, $1F, $21, $23, $25, $27, $29, $2B,
    $2D, $2F, $31, $33, $35, $37, $39, $3B, $3D, $3F, $41, $43, $45, $47, $49,
    $4B, $4D, $4F, $51, $53, $55, $57, $59, $5B, $5D, $5F, $61, $63, $65, $67,
    $69, $6B, $6D, $6F, $71, $73, $75, $77, $79, $7B, $7D, $7F, $81, $83, $85,
    $87, $89, $8B, $8D, $8F, $91, $93, $95, $97, $99, $9B, $9D, $9F, $A1, $A3,
    $A5, $A7, $A9, $AB, $AD, $AF, $B1, $B3, $B5, $B7, $B9, $BB, $BD, $BF, $C1,
    $C3, $C5, $C7, $C9, $CB, $CD, $CF, $D1, $D3, $D5, $D7, $D9, $DB, $DD, $DF,
    $E1, $E3, $E5, $E7, $E9, $EB, $ED, $EF, $F1, $F3, $F5, $F7, $F9, $FB,
    $FD, $FF));

  RRCA_F: array [0 .. 1, 0 .. 255] of byte = (($00, $01, $00, $01, $00, $01,
    $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $08, $09, $08, $09, $08,
    $09, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09, $00, $01, $00, $01,
    $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $08, $09, $08,
    $09, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09, $20, $21,
    $20, $21, $20, $21, $20, $21, $20, $21, $20, $21, $20, $21, $20, $21, $28,
    $29, $28, $29, $28, $29, $28, $29, $28, $29, $28, $29, $28, $29, $28, $29,
    $20, $21, $20, $21, $20, $21, $20, $21, $20, $21, $20, $21, $20, $21, $20,
    $21, $28, $29, $28, $29, $28, $29, $28, $29, $28, $29, $28, $29, $28, $29,
    $28, $29, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00,
    $01, $00, $01, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09,
    $08, $09, $08, $09, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00,
    $01, $00, $01, $00, $01, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09,
    $08, $09, $08, $09, $08, $09, $20, $21, $20, $21, $20, $21, $20, $21, $20,
    $21, $20, $21, $20, $21, $20, $21, $28, $29, $28, $29, $28, $29, $28, $29,
    $28, $29, $28, $29, $28, $29, $28, $29, $20, $21, $20, $21, $20, $21, $20,
    $21, $20, $21, $20, $21, $20, $21, $20, $21, $28, $29, $28, $29, $28, $29,
    $28, $29, $28, $29, $28, $29, $28, $29, $28, $29),
    ($00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00,
    $01, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09,
    $08, $09, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $00,
    $01, $00, $01, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09,
    $08, $09, $08, $09, $20, $21, $20, $21, $20, $21, $20, $21, $20, $21, $20,
    $21, $20, $21, $20, $21, $28, $29, $28, $29, $28, $29, $28, $29, $28, $29,
    $28, $29, $28, $29, $28, $29, $20, $21, $20, $21, $20, $21, $20, $21, $20,
    $21, $20, $21, $20, $21, $20, $21, $28, $29, $28, $29, $28, $29, $28, $29,
    $28, $29, $28, $29, $28, $29, $28, $29, $00, $01, $00, $01, $00, $01, $00,
    $01, $00, $01, $00, $01, $00, $01, $00, $01, $08, $09, $08, $09, $08, $09,
    $08, $09, $08, $09, $08, $09, $08, $09, $08, $09, $00, $01, $00, $01, $00,
    $01, $00, $01, $00, $01, $00, $01, $00, $01, $00, $01, $08, $09, $08, $09,
    $08, $09, $08, $09, $08, $09, $08, $09, $08, $09, $08, $09, $20, $21, $20,
    $21, $20, $21, $20, $21, $20, $21, $20, $21, $20, $21, $20, $21, $28, $29,
    $28, $29, $28, $29, $28, $29, $28, $29, $28, $29, $28, $29, $28, $29, $20,
    $21, $20, $21, $20, $21, $20, $21, $20, $21, $20, $21, $20, $21, $20, $21,
    $28, $29, $28, $29, $28, $29, $28, $29, $28, $29, $28, $29, $28, $29,
    $28, $29));

  RRCA_A: array [0 .. 1, 0 .. 255] of byte = (($00, $80, $01, $81, $02, $82,
    $03, $83, $04, $84, $05, $85, $06, $86, $07, $87, $08, $88, $09, $89, $0A,
    $8A, $0B, $8B, $0C, $8C, $0D, $8D, $0E, $8E, $0F, $8F, $10, $90, $11, $91,
    $12, $92, $13, $93, $14, $94, $15, $95, $16, $96, $17, $97, $18, $98, $19,
    $99, $1A, $9A, $1B, $9B, $1C, $9C, $1D, $9D, $1E, $9E, $1F, $9F, $20, $A0,
    $21, $A1, $22, $A2, $23, $A3, $24, $A4, $25, $A5, $26, $A6, $27, $A7, $28,
    $A8, $29, $A9, $2A, $AA, $2B, $AB, $2C, $AC, $2D, $AD, $2E, $AE, $2F, $AF,
    $30, $B0, $31, $B1, $32, $B2, $33, $B3, $34, $B4, $35, $B5, $36, $B6, $37,
    $B7, $38, $B8, $39, $B9, $3A, $BA, $3B, $BB, $3C, $BC, $3D, $BD, $3E, $BE,
    $3F, $BF, $40, $C0, $41, $C1, $42, $C2, $43, $C3, $44, $C4, $45, $C5, $46,
    $C6, $47, $C7, $48, $C8, $49, $C9, $4A, $CA, $4B, $CB, $4C, $CC, $4D, $CD,
    $4E, $CE, $4F, $CF, $50, $D0, $51, $D1, $52, $D2, $53, $D3, $54, $D4, $55,
    $D5, $56, $D6, $57, $D7, $58, $D8, $59, $D9, $5A, $DA, $5B, $DB, $5C, $DC,
    $5D, $DD, $5E, $DE, $5F, $DF, $60, $E0, $61, $E1, $62, $E2, $63, $E3, $64,
    $E4, $65, $E5, $66, $E6, $67, $E7, $68, $E8, $69, $E9, $6A, $EA, $6B, $EB,
    $6C, $EC, $6D, $ED, $6E, $EE, $6F, $EF, $70, $F0, $71, $F1, $72, $F2, $73,
    $F3, $74, $F4, $75, $F5, $76, $F6, $77, $F7, $78, $F8, $79, $F9, $7A, $FA,
    $7B, $FB, $7C, $FC, $7D, $FD, $7E, $FE, $7F, $FF),
    ($00, $80, $01, $81, $02, $82, $03, $83, $04, $84, $05, $85, $06, $86, $07,
    $87, $08, $88, $09, $89, $0A, $8A, $0B, $8B, $0C, $8C, $0D, $8D, $0E, $8E,
    $0F, $8F, $10, $90, $11, $91, $12, $92, $13, $93, $14, $94, $15, $95, $16,
    $96, $17, $97, $18, $98, $19, $99, $1A, $9A, $1B, $9B, $1C, $9C, $1D, $9D,
    $1E, $9E, $1F, $9F, $20, $A0, $21, $A1, $22, $A2, $23, $A3, $24, $A4, $25,
    $A5, $26, $A6, $27, $A7, $28, $A8, $29, $A9, $2A, $AA, $2B, $AB, $2C, $AC,
    $2D, $AD, $2E, $AE, $2F, $AF, $30, $B0, $31, $B1, $32, $B2, $33, $B3, $34,
    $B4, $35, $B5, $36, $B6, $37, $B7, $38, $B8, $39, $B9, $3A, $BA, $3B, $BB,
    $3C, $BC, $3D, $BD, $3E, $BE, $3F, $BF, $40, $C0, $41, $C1, $42, $C2, $43,
    $C3, $44, $C4, $45, $C5, $46, $C6, $47, $C7, $48, $C8, $49, $C9, $4A, $CA,
    $4B, $CB, $4C, $CC, $4D, $CD, $4E, $CE, $4F, $CF, $50, $D0, $51, $D1, $52,
    $D2, $53, $D3, $54, $D4, $55, $D5, $56, $D6, $57, $D7, $58, $D8, $59, $D9,
    $5A, $DA, $5B, $DB, $5C, $DC, $5D, $DD, $5E, $DE, $5F, $DF, $60, $E0, $61,
    $E1, $62, $E2, $63, $E3, $64, $E4, $65, $E5, $66, $E6, $67, $E7, $68, $E8,
    $69, $E9, $6A, $EA, $6B, $EB, $6C, $EC, $6D, $ED, $6E, $EE, $6F, $EF, $70,
    $F0, $71, $F1, $72, $F2, $73, $F3, $74, $F4, $75, $F5, $76, $F6, $77, $F7,
    $78, $F8, $79, $F9, $7A, $FA, $7B, $FB, $7C, $FC, $7D, $FD, $7E, $FE,
    $7F, $FF));

  RLA_F: array [0 .. 1, 0 .. 255] of byte = (($00, $00, $00, $00, $08, $08, $08,
    $08, $00, $00, $00, $00, $08, $08, $08, $08, $20, $20, $20, $20, $28, $28,
    $28, $28, $20, $20, $20, $20, $28, $28, $28, $28, $00, $00, $00, $00, $08,
    $08, $08, $08, $00, $00, $00, $00, $08, $08, $08, $08, $20, $20, $20, $20,
    $28, $28, $28, $28, $20, $20, $20, $20, $28, $28, $28, $28, $00, $00, $00,
    $00, $08, $08, $08, $08, $00, $00, $00, $00, $08, $08, $08, $08, $20, $20,
    $20, $20, $28, $28, $28, $28, $20, $20, $20, $20, $28, $28, $28, $28, $00,
    $00, $00, $00, $08, $08, $08, $08, $00, $00, $00, $00, $08, $08, $08, $08,
    $20, $20, $20, $20, $28, $28, $28, $28, $20, $20, $20, $20, $28, $28, $28,
    $28, $01, $01, $01, $01, $09, $09, $09, $09, $01, $01, $01, $01, $09, $09,
    $09, $09, $21, $21, $21, $21, $29, $29, $29, $29, $21, $21, $21, $21, $29,
    $29, $29, $29, $01, $01, $01, $01, $09, $09, $09, $09, $01, $01, $01, $01,
    $09, $09, $09, $09, $21, $21, $21, $21, $29, $29, $29, $29, $21, $21, $21,
    $21, $29, $29, $29, $29, $01, $01, $01, $01, $09, $09, $09, $09, $01, $01,
    $01, $01, $09, $09, $09, $09, $21, $21, $21, $21, $29, $29, $29, $29, $21,
    $21, $21, $21, $29, $29, $29, $29, $01, $01, $01, $01, $09, $09, $09, $09,
    $01, $01, $01, $01, $09, $09, $09, $09, $21, $21, $21, $21, $29, $29, $29,
    $29, $21, $21, $21, $21, $29, $29, $29, $29), ($00, $00, $00, $00, $08, $08,
    $08, $08, $00, $00, $00, $00, $08, $08, $08, $08, $20, $20, $20, $20, $28,
    $28, $28, $28, $20, $20, $20, $20, $28, $28, $28, $28, $00, $00, $00, $00,
    $08, $08, $08, $08, $00, $00, $00, $00, $08, $08, $08, $08, $20, $20, $20,
    $20, $28, $28, $28, $28, $20, $20, $20, $20, $28, $28, $28, $28, $00, $00,
    $00, $00, $08, $08, $08, $08, $00, $00, $00, $00, $08, $08, $08, $08, $20,
    $20, $20, $20, $28, $28, $28, $28, $20, $20, $20, $20, $28, $28, $28, $28,
    $00, $00, $00, $00, $08, $08, $08, $08, $00, $00, $00, $00, $08, $08, $08,
    $08, $20, $20, $20, $20, $28, $28, $28, $28, $20, $20, $20, $20, $28, $28,
    $28, $28, $01, $01, $01, $01, $09, $09, $09, $09, $01, $01, $01, $01, $09,
    $09, $09, $09, $21, $21, $21, $21, $29, $29, $29, $29, $21, $21, $21, $21,
    $29, $29, $29, $29, $01, $01, $01, $01, $09, $09, $09, $09, $01, $01, $01,
    $01, $09, $09, $09, $09, $21, $21, $21, $21, $29, $29, $29, $29, $21, $21,
    $21, $21, $29, $29, $29, $29, $01, $01, $01, $01, $09, $09, $09, $09, $01,
    $01, $01, $01, $09, $09, $09, $09, $21, $21, $21, $21, $29, $29, $29, $29,
    $21, $21, $21, $21, $29, $29, $29, $29, $01, $01, $01, $01, $09, $09, $09,
    $09, $01, $01, $01, $01, $09, $09, $09, $09, $21, $21, $21, $21, $29, $29,
    $29, $29, $21, $21, $21, $21, $29, $29, $29, $29));

  RLA_A: array [0 .. 1, 0 .. 255] of byte = (($00, $02, $04, $06, $08, $0A, $0C,
    $0E, $10, $12, $14, $16, $18, $1A, $1C, $1E, $20, $22, $24, $26, $28, $2A,
    $2C, $2E, $30, $32, $34, $36, $38, $3A, $3C, $3E, $40, $42, $44, $46, $48,
    $4A, $4C, $4E, $50, $52, $54, $56, $58, $5A, $5C, $5E, $60, $62, $64, $66,
    $68, $6A, $6C, $6E, $70, $72, $74, $76, $78, $7A, $7C, $7E, $80, $82, $84,
    $86, $88, $8A, $8C, $8E, $90, $92, $94, $96, $98, $9A, $9C, $9E, $A0, $A2,
    $A4, $A6, $A8, $AA, $AC, $AE, $B0, $B2, $B4, $B6, $B8, $BA, $BC, $BE, $C0,
    $C2, $C4, $C6, $C8, $CA, $CC, $CE, $D0, $D2, $D4, $D6, $D8, $DA, $DC, $DE,
    $E0, $E2, $E4, $E6, $E8, $EA, $EC, $EE, $F0, $F2, $F4, $F6, $F8, $FA, $FC,
    $FE, $00, $02, $04, $06, $08, $0A, $0C, $0E, $10, $12, $14, $16, $18, $1A,
    $1C, $1E, $20, $22, $24, $26, $28, $2A, $2C, $2E, $30, $32, $34, $36, $38,
    $3A, $3C, $3E, $40, $42, $44, $46, $48, $4A, $4C, $4E, $50, $52, $54, $56,
    $58, $5A, $5C, $5E, $60, $62, $64, $66, $68, $6A, $6C, $6E, $70, $72, $74,
    $76, $78, $7A, $7C, $7E, $80, $82, $84, $86, $88, $8A, $8C, $8E, $90, $92,
    $94, $96, $98, $9A, $9C, $9E, $A0, $A2, $A4, $A6, $A8, $AA, $AC, $AE, $B0,
    $B2, $B4, $B6, $B8, $BA, $BC, $BE, $C0, $C2, $C4, $C6, $C8, $CA, $CC, $CE,
    $D0, $D2, $D4, $D6, $D8, $DA, $DC, $DE, $E0, $E2, $E4, $E6, $E8, $EA, $EC,
    $EE, $F0, $F2, $F4, $F6, $F8, $FA, $FC, $FE), ($01, $03, $05, $07, $09, $0B,
    $0D, $0F, $11, $13, $15, $17, $19, $1B, $1D, $1F, $21, $23, $25, $27, $29,
    $2B, $2D, $2F, $31, $33, $35, $37, $39, $3B, $3D, $3F, $41, $43, $45, $47,
    $49, $4B, $4D, $4F, $51, $53, $55, $57, $59, $5B, $5D, $5F, $61, $63, $65,
    $67, $69, $6B, $6D, $6F, $71, $73, $75, $77, $79, $7B, $7D, $7F, $81, $83,
    $85, $87, $89, $8B, $8D, $8F, $91, $93, $95, $97, $99, $9B, $9D, $9F, $A1,
    $A3, $A5, $A7, $A9, $AB, $AD, $AF, $B1, $B3, $B5, $B7, $B9, $BB, $BD, $BF,
    $C1, $C3, $C5, $C7, $C9, $CB, $CD, $CF, $D1, $D3, $D5, $D7, $D9, $DB, $DD,
    $DF, $E1, $E3, $E5, $E7, $E9, $EB, $ED, $EF, $F1, $F3, $F5, $F7, $F9, $FB,
    $FD, $FF, $01, $03, $05, $07, $09, $0B, $0D, $0F, $11, $13, $15, $17, $19,
    $1B, $1D, $1F, $21, $23, $25, $27, $29, $2B, $2D, $2F, $31, $33, $35, $37,
    $39, $3B, $3D, $3F, $41, $43, $45, $47, $49, $4B, $4D, $4F, $51, $53, $55,
    $57, $59, $5B, $5D, $5F, $61, $63, $65, $67, $69, $6B, $6D, $6F, $71, $73,
    $75, $77, $79, $7B, $7D, $7F, $81, $83, $85, $87, $89, $8B, $8D, $8F, $91,
    $93, $95, $97, $99, $9B, $9D, $9F, $A1, $A3, $A5, $A7, $A9, $AB, $AD, $AF,
    $B1, $B3, $B5, $B7, $B9, $BB, $BD, $BF, $C1, $C3, $C5, $C7, $C9, $CB, $CD,
    $CF, $D1, $D3, $D5, $D7, $D9, $DB, $DD, $DF, $E1, $E3, $E5, $E7, $E9, $EB,
    $ED, $EF, $F1, $F3, $F5, $F7, $F9, $FB, $FD, $FF));

  RLR_F: array [0 .. 1, 0 .. 255] of byte = (($44, $00, $00, $04, $08, $0C, $0C,
    $08, $00, $04, $04, $00, $0C, $08, $08, $0C, $20, $24, $24, $20, $2C, $28,
    $28, $2C, $24, $20, $20, $24, $28, $2C, $2C, $28, $00, $04, $04, $00, $0C,
    $08, $08, $0C, $04, $00, $00, $04, $08, $0C, $0C, $08, $24, $20, $20, $24,
    $28, $2C, $2C, $28, $20, $24, $24, $20, $2C, $28, $28, $2C, $80, $84, $84,
    $80, $8C, $88, $88, $8C, $84, $80, $80, $84, $88, $8C, $8C, $88, $A4, $A0,
    $A0, $A4, $A8, $AC, $AC, $A8, $A0, $A4, $A4, $A0, $AC, $A8, $A8, $AC, $84,
    $80, $80, $84, $88, $8C, $8C, $88, $80, $84, $84, $80, $8C, $88, $88, $8C,
    $A0, $A4, $A4, $A0, $AC, $A8, $A8, $AC, $A4, $A0, $A0, $A4, $A8, $AC, $AC,
    $A8, $45, $01, $01, $05, $09, $0D, $0D, $09, $01, $05, $05, $01, $0D, $09,
    $09, $0D, $21, $25, $25, $21, $2D, $29, $29, $2D, $25, $21, $21, $25, $29,
    $2D, $2D, $29, $01, $05, $05, $01, $0D, $09, $09, $0D, $05, $01, $01, $05,
    $09, $0D, $0D, $09, $25, $21, $21, $25, $29, $2D, $2D, $29, $21, $25, $25,
    $21, $2D, $29, $29, $2D, $81, $85, $85, $81, $8D, $89, $89, $8D, $85, $81,
    $81, $85, $89, $8D, $8D, $89, $A5, $A1, $A1, $A5, $A9, $AD, $AD, $A9, $A1,
    $A5, $A5, $A1, $AD, $A9, $A9, $AD, $85, $81, $81, $85, $89, $8D, $8D, $89,
    $81, $85, $85, $81, $8D, $89, $89, $8D, $A1, $A5, $A5, $A1, $AD, $A9, $A9,
    $AD, $A5, $A1, $A1, $A5, $A9, $AD, $AD, $A9), ($00, $04, $04, $00, $0C, $08,
    $08, $0C, $04, $00, $00, $04, $08, $0C, $0C, $08, $24, $20, $20, $24, $28,
    $2C, $2C, $28, $20, $24, $24, $20, $2C, $28, $28, $2C, $04, $00, $00, $04,
    $08, $0C, $0C, $08, $00, $04, $04, $00, $0C, $08, $08, $0C, $20, $24, $24,
    $20, $2C, $28, $28, $2C, $24, $20, $20, $24, $28, $2C, $2C, $28, $84, $80,
    $80, $84, $88, $8C, $8C, $88, $80, $84, $84, $80, $8C, $88, $88, $8C, $A0,
    $A4, $A4, $A0, $AC, $A8, $A8, $AC, $A4, $A0, $A0, $A4, $A8, $AC, $AC, $A8,
    $80, $84, $84, $80, $8C, $88, $88, $8C, $84, $80, $80, $84, $88, $8C, $8C,
    $88, $A4, $A0, $A0, $A4, $A8, $AC, $AC, $A8, $A0, $A4, $A4, $A0, $AC, $A8,
    $A8, $AC, $01, $05, $05, $01, $0D, $09, $09, $0D, $05, $01, $01, $05, $09,
    $0D, $0D, $09, $25, $21, $21, $25, $29, $2D, $2D, $29, $21, $25, $25, $21,
    $2D, $29, $29, $2D, $05, $01, $01, $05, $09, $0D, $0D, $09, $01, $05, $05,
    $01, $0D, $09, $09, $0D, $21, $25, $25, $21, $2D, $29, $29, $2D, $25, $21,
    $21, $25, $29, $2D, $2D, $29, $85, $81, $81, $85, $89, $8D, $8D, $89, $81,
    $85, $85, $81, $8D, $89, $89, $8D, $A1, $A5, $A5, $A1, $AD, $A9, $A9, $AD,
    $A5, $A1, $A1, $A5, $A9, $AD, $AD, $A9, $81, $85, $85, $81, $8D, $89, $89,
    $8D, $85, $81, $81, $85, $89, $8D, $8D, $89, $A5, $A1, $A1, $A5, $A9, $AD,
    $AD, $A9, $A1, $A5, $A5, $A1, $AD, $A9, $A9, $AD));

  RLR_A: array [0 .. 1, 0 .. 255] of byte = (($00, $02, $04, $06, $08, $0A, $0C,
    $0E, $10, $12, $14, $16, $18, $1A, $1C, $1E, $20, $22, $24, $26, $28, $2A,
    $2C, $2E, $30, $32, $34, $36, $38, $3A, $3C, $3E, $40, $42, $44, $46, $48,
    $4A, $4C, $4E, $50, $52, $54, $56, $58, $5A, $5C, $5E, $60, $62, $64, $66,
    $68, $6A, $6C, $6E, $70, $72, $74, $76, $78, $7A, $7C, $7E, $80, $82, $84,
    $86, $88, $8A, $8C, $8E, $90, $92, $94, $96, $98, $9A, $9C, $9E, $A0, $A2,
    $A4, $A6, $A8, $AA, $AC, $AE, $B0, $B2, $B4, $B6, $B8, $BA, $BC, $BE, $C0,
    $C2, $C4, $C6, $C8, $CA, $CC, $CE, $D0, $D2, $D4, $D6, $D8, $DA, $DC, $DE,
    $E0, $E2, $E4, $E6, $E8, $EA, $EC, $EE, $F0, $F2, $F4, $F6, $F8, $FA, $FC,
    $FE, $00, $02, $04, $06, $08, $0A, $0C, $0E, $10, $12, $14, $16, $18, $1A,
    $1C, $1E, $20, $22, $24, $26, $28, $2A, $2C, $2E, $30, $32, $34, $36, $38,
    $3A, $3C, $3E, $40, $42, $44, $46, $48, $4A, $4C, $4E, $50, $52, $54, $56,
    $58, $5A, $5C, $5E, $60, $62, $64, $66, $68, $6A, $6C, $6E, $70, $72, $74,
    $76, $78, $7A, $7C, $7E, $80, $82, $84, $86, $88, $8A, $8C, $8E, $90, $92,
    $94, $96, $98, $9A, $9C, $9E, $A0, $A2, $A4, $A6, $A8, $AA, $AC, $AE, $B0,
    $B2, $B4, $B6, $B8, $BA, $BC, $BE, $C0, $C2, $C4, $C6, $C8, $CA, $CC, $CE,
    $D0, $D2, $D4, $D6, $D8, $DA, $DC, $DE, $E0, $E2, $E4, $E6, $E8, $EA, $EC,
    $EE, $F0, $F2, $F4, $F6, $F8, $FA, $FC, $FE), ($01, $03, $05, $07, $09, $0B,
    $0D, $0F, $11, $13, $15, $17, $19, $1B, $1D, $1F, $21, $23, $25, $27, $29,
    $2B, $2D, $2F, $31, $33, $35, $37, $39, $3B, $3D, $3F, $41, $43, $45, $47,
    $49, $4B, $4D, $4F, $51, $53, $55, $57, $59, $5B, $5D, $5F, $61, $63, $65,
    $67, $69, $6B, $6D, $6F, $71, $73, $75, $77, $79, $7B, $7D, $7F, $81, $83,
    $85, $87, $89, $8B, $8D, $8F, $91, $93, $95, $97, $99, $9B, $9D, $9F, $A1,
    $A3, $A5, $A7, $A9, $AB, $AD, $AF, $B1, $B3, $B5, $B7, $B9, $BB, $BD, $BF,
    $C1, $C3, $C5, $C7, $C9, $CB, $CD, $CF, $D1, $D3, $D5, $D7, $D9, $DB, $DD,
    $DF, $E1, $E3, $E5, $E7, $E9, $EB, $ED, $EF, $F1, $F3, $F5, $F7, $F9, $FB,
    $FD, $FF, $01, $03, $05, $07, $09, $0B, $0D, $0F, $11, $13, $15, $17, $19,
    $1B, $1D, $1F, $21, $23, $25, $27, $29, $2B, $2D, $2F, $31, $33, $35, $37,
    $39, $3B, $3D, $3F, $41, $43, $45, $47, $49, $4B, $4D, $4F, $51, $53, $55,
    $57, $59, $5B, $5D, $5F, $61, $63, $65, $67, $69, $6B, $6D, $6F, $71, $73,
    $75, $77, $79, $7B, $7D, $7F, $81, $83, $85, $87, $89, $8B, $8D, $8F, $91,
    $93, $95, $97, $99, $9B, $9D, $9F, $A1, $A3, $A5, $A7, $A9, $AB, $AD, $AF,
    $B1, $B3, $B5, $B7, $B9, $BB, $BD, $BF, $C1, $C3, $C5, $C7, $C9, $CB, $CD,
    $CF, $D1, $D3, $D5, $D7, $D9, $DB, $DD, $DF, $E1, $E3, $E5, $E7, $E9, $EB,
    $ED, $EF, $F1, $F3, $F5, $F7, $F9, $FB, $FD, $FF));

  RRR_F: array [0 .. 1, 0 .. 255] of byte = (($44, $45, $00, $01, $00, $01, $04,
    $05, $00, $01, $04, $05, $04, $05, $00, $01, $08, $09, $0C, $0D, $0C, $0D,
    $08, $09, $0C, $0D, $08, $09, $08, $09, $0C, $0D, $00, $01, $04, $05, $04,
    $05, $00, $01, $04, $05, $00, $01, $00, $01, $04, $05, $0C, $0D, $08, $09,
    $08, $09, $0C, $0D, $08, $09, $0C, $0D, $0C, $0D, $08, $09, $20, $21, $24,
    $25, $24, $25, $20, $21, $24, $25, $20, $21, $20, $21, $24, $25, $2C, $2D,
    $28, $29, $28, $29, $2C, $2D, $28, $29, $2C, $2D, $2C, $2D, $28, $29, $24,
    $25, $20, $21, $20, $21, $24, $25, $20, $21, $24, $25, $24, $25, $20, $21,
    $28, $29, $2C, $2D, $2C, $2D, $28, $29, $2C, $2D, $28, $29, $28, $29, $2C,
    $2D, $00, $01, $04, $05, $04, $05, $00, $01, $04, $05, $00, $01, $00, $01,
    $04, $05, $0C, $0D, $08, $09, $08, $09, $0C, $0D, $08, $09, $0C, $0D, $0C,
    $0D, $08, $09, $04, $05, $00, $01, $00, $01, $04, $05, $00, $01, $04, $05,
    $04, $05, $00, $01, $08, $09, $0C, $0D, $0C, $0D, $08, $09, $0C, $0D, $08,
    $09, $08, $09, $0C, $0D, $24, $25, $20, $21, $20, $21, $24, $25, $20, $21,
    $24, $25, $24, $25, $20, $21, $28, $29, $2C, $2D, $2C, $2D, $28, $29, $2C,
    $2D, $28, $29, $28, $29, $2C, $2D, $20, $21, $24, $25, $24, $25, $20, $21,
    $24, $25, $20, $21, $20, $21, $24, $25, $2C, $2D, $28, $29, $28, $29, $2C,
    $2D, $28, $29, $2C, $2D, $2C, $2D, $28, $29), ($80, $81, $84, $85, $84, $85,
    $80, $81, $84, $85, $80, $81, $80, $81, $84, $85, $8C, $8D, $88, $89, $88,
    $89, $8C, $8D, $88, $89, $8C, $8D, $8C, $8D, $88, $89, $84, $85, $80, $81,
    $80, $81, $84, $85, $80, $81, $84, $85, $84, $85, $80, $81, $88, $89, $8C,
    $8D, $8C, $8D, $88, $89, $8C, $8D, $88, $89, $88, $89, $8C, $8D, $A4, $A5,
    $A0, $A1, $A0, $A1, $A4, $A5, $A0, $A1, $A4, $A5, $A4, $A5, $A0, $A1, $A8,
    $A9, $AC, $AD, $AC, $AD, $A8, $A9, $AC, $AD, $A8, $A9, $A8, $A9, $AC, $AD,
    $A0, $A1, $A4, $A5, $A4, $A5, $A0, $A1, $A4, $A5, $A0, $A1, $A0, $A1, $A4,
    $A5, $AC, $AD, $A8, $A9, $A8, $A9, $AC, $AD, $A8, $A9, $AC, $AD, $AC, $AD,
    $A8, $A9, $84, $85, $80, $81, $80, $81, $84, $85, $80, $81, $84, $85, $84,
    $85, $80, $81, $88, $89, $8C, $8D, $8C, $8D, $88, $89, $8C, $8D, $88, $89,
    $88, $89, $8C, $8D, $80, $81, $84, $85, $84, $85, $80, $81, $84, $85, $80,
    $81, $80, $81, $84, $85, $8C, $8D, $88, $89, $88, $89, $8C, $8D, $88, $89,
    $8C, $8D, $8C, $8D, $88, $89, $A0, $A1, $A4, $A5, $A4, $A5, $A0, $A1, $A4,
    $A5, $A0, $A1, $A0, $A1, $A4, $A5, $AC, $AD, $A8, $A9, $A8, $A9, $AC, $AD,
    $A8, $A9, $AC, $AD, $AC, $AD, $A8, $A9, $A4, $A5, $A0, $A1, $A0, $A1, $A4,
    $A5, $A0, $A1, $A4, $A5, $A4, $A5, $A0, $A1, $A8, $A9, $AC, $AD, $AC, $AD,
    $A8, $A9, $AC, $AD, $A8, $A9, $A8, $A9, $AC, $AD));

  RRR_A: array [0 .. 1, 0 .. 255] of byte = (($00, $00, $01, $01, $02, $02, $03,
    $03, $04, $04, $05, $05, $06, $06, $07, $07, $08, $08, $09, $09, $0A, $0A,
    $0B, $0B, $0C, $0C, $0D, $0D, $0E, $0E, $0F, $0F, $10, $10, $11, $11, $12,
    $12, $13, $13, $14, $14, $15, $15, $16, $16, $17, $17, $18, $18, $19, $19,
    $1A, $1A, $1B, $1B, $1C, $1C, $1D, $1D, $1E, $1E, $1F, $1F, $20, $20, $21,
    $21, $22, $22, $23, $23, $24, $24, $25, $25, $26, $26, $27, $27, $28, $28,
    $29, $29, $2A, $2A, $2B, $2B, $2C, $2C, $2D, $2D, $2E, $2E, $2F, $2F, $30,
    $30, $31, $31, $32, $32, $33, $33, $34, $34, $35, $35, $36, $36, $37, $37,
    $38, $38, $39, $39, $3A, $3A, $3B, $3B, $3C, $3C, $3D, $3D, $3E, $3E, $3F,
    $3F, $40, $40, $41, $41, $42, $42, $43, $43, $44, $44, $45, $45, $46, $46,
    $47, $47, $48, $48, $49, $49, $4A, $4A, $4B, $4B, $4C, $4C, $4D, $4D, $4E,
    $4E, $4F, $4F, $50, $50, $51, $51, $52, $52, $53, $53, $54, $54, $55, $55,
    $56, $56, $57, $57, $58, $58, $59, $59, $5A, $5A, $5B, $5B, $5C, $5C, $5D,
    $5D, $5E, $5E, $5F, $5F, $60, $60, $61, $61, $62, $62, $63, $63, $64, $64,
    $65, $65, $66, $66, $67, $67, $68, $68, $69, $69, $6A, $6A, $6B, $6B, $6C,
    $6C, $6D, $6D, $6E, $6E, $6F, $6F, $70, $70, $71, $71, $72, $72, $73, $73,
    $74, $74, $75, $75, $76, $76, $77, $77, $78, $78, $79, $79, $7A, $7A, $7B,
    $7B, $7C, $7C, $7D, $7D, $7E, $7E, $7F, $7F), ($80, $80, $81, $81, $82, $82,
    $83, $83, $84, $84, $85, $85, $86, $86, $87, $87, $88, $88, $89, $89, $8A,
    $8A, $8B, $8B, $8C, $8C, $8D, $8D, $8E, $8E, $8F, $8F, $90, $90, $91, $91,
    $92, $92, $93, $93, $94, $94, $95, $95, $96, $96, $97, $97, $98, $98, $99,
    $99, $9A, $9A, $9B, $9B, $9C, $9C, $9D, $9D, $9E, $9E, $9F, $9F, $A0, $A0,
    $A1, $A1, $A2, $A2, $A3, $A3, $A4, $A4, $A5, $A5, $A6, $A6, $A7, $A7, $A8,
    $A8, $A9, $A9, $AA, $AA, $AB, $AB, $AC, $AC, $AD, $AD, $AE, $AE, $AF, $AF,
    $B0, $B0, $B1, $B1, $B2, $B2, $B3, $B3, $B4, $B4, $B5, $B5, $B6, $B6, $B7,
    $B7, $B8, $B8, $B9, $B9, $BA, $BA, $BB, $BB, $BC, $BC, $BD, $BD, $BE, $BE,
    $BF, $BF, $C0, $C0, $C1, $C1, $C2, $C2, $C3, $C3, $C4, $C4, $C5, $C5, $C6,
    $C6, $C7, $C7, $C8, $C8, $C9, $C9, $CA, $CA, $CB, $CB, $CC, $CC, $CD, $CD,
    $CE, $CE, $CF, $CF, $D0, $D0, $D1, $D1, $D2, $D2, $D3, $D3, $D4, $D4, $D5,
    $D5, $D6, $D6, $D7, $D7, $D8, $D8, $D9, $D9, $DA, $DA, $DB, $DB, $DC, $DC,
    $DD, $DD, $DE, $DE, $DF, $DF, $E0, $E0, $E1, $E1, $E2, $E2, $E3, $E3, $E4,
    $E4, $E5, $E5, $E6, $E6, $E7, $E7, $E8, $E8, $E9, $E9, $EA, $EA, $EB, $EB,
    $EC, $EC, $ED, $ED, $EE, $EE, $EF, $EF, $F0, $F0, $F1, $F1, $F2, $F2, $F3,
    $F3, $F4, $F4, $F5, $F5, $F6, $F6, $F7, $F7, $F8, $F8, $F9, $F9, $FA, $FA,
    $FB, $FB, $FC, $FC, $FD, $FD, $FE, $FE, $FF, $FF));

  DAA_F: array [0 .. 7, 0 .. 255] of byte = (($44, $00, $00, $04, $00, $04, $04,
    $00, $08, $0C, $10, $14, $14, $10, $14, $10, $00, $04, $04, $00, $04, $00,
    $00, $04, $0C, $08, $30, $34, $34, $30, $34, $30, $20, $24, $24, $20, $24,
    $20, $20, $24, $2C, $28, $34, $30, $30, $34, $30, $34, $24, $20, $20, $24,
    $20, $24, $24, $20, $28, $2C, $10, $14, $14, $10, $14, $10, $00, $04, $04,
    $00, $04, $00, $00, $04, $0C, $08, $14, $10, $10, $14, $10, $14, $04, $00,
    $00, $04, $00, $04, $04, $00, $08, $0C, $34, $30, $30, $34, $30, $34, $24,
    $20, $20, $24, $20, $24, $24, $20, $28, $2C, $30, $34, $34, $30, $34, $30,
    $20, $24, $24, $20, $24, $20, $20, $24, $2C, $28, $90, $94, $94, $90, $94,
    $90, $80, $84, $84, $80, $84, $80, $80, $84, $8C, $88, $94, $90, $90, $94,
    $90, $94, $84, $80, $80, $84, $80, $84, $84, $80, $88, $8C, $55, $11, $11,
    $15, $11, $15, $45, $01, $01, $05, $01, $05, $05, $01, $09, $0D, $11, $15,
    $15, $11, $15, $11, $01, $05, $05, $01, $05, $01, $01, $05, $0D, $09, $31,
    $35, $35, $31, $35, $31, $21, $25, $25, $21, $25, $21, $21, $25, $2D, $29,
    $35, $31, $31, $35, $31, $35, $25, $21, $21, $25, $21, $25, $25, $21, $29,
    $2D, $11, $15, $15, $11, $15, $11, $01, $05, $05, $01, $05, $01, $01, $05,
    $0D, $09, $15, $11, $11, $15, $11, $15, $05, $01, $01, $05, $01, $05, $05,
    $01, $09, $0D, $35, $31, $31, $35, $31, $35), ($25, $21, $21, $25, $21, $25,
    $25, $21, $29, $2D, $31, $35, $35, $31, $35, $31, $21, $25, $25, $21, $25,
    $21, $21, $25, $2D, $29, $91, $95, $95, $91, $95, $91, $81, $85, $85, $81,
    $85, $81, $81, $85, $8D, $89, $95, $91, $91, $95, $91, $95, $85, $81, $81,
    $85, $81, $85, $85, $81, $89, $8D, $B5, $B1, $B1, $B5, $B1, $B5, $A5, $A1,
    $A1, $A5, $A1, $A5, $A5, $A1, $A9, $AD, $B1, $B5, $B5, $B1, $B5, $B1, $A1,
    $A5, $A5, $A1, $A5, $A1, $A1, $A5, $AD, $A9, $95, $91, $91, $95, $91, $95,
    $85, $81, $81, $85, $81, $85, $85, $81, $89, $8D, $91, $95, $95, $91, $95,
    $91, $81, $85, $85, $81, $85, $81, $81, $85, $8D, $89, $B1, $B5, $B5, $B1,
    $B5, $B1, $A1, $A5, $A5, $A1, $A5, $A1, $A1, $A5, $AD, $A9, $B5, $B1, $B1,
    $B5, $B1, $B5, $A5, $A1, $A1, $A5, $A1, $A5, $A5, $A1, $A9, $AD, $55, $11,
    $11, $15, $11, $15, $45, $01, $01, $05, $01, $05, $05, $01, $09, $0D, $11,
    $15, $15, $11, $15, $11, $01, $05, $05, $01, $05, $01, $01, $05, $0D, $09,
    $31, $35, $35, $31, $35, $31, $21, $25, $25, $21, $25, $21, $21, $25, $2D,
    $29, $35, $31, $31, $35, $31, $35, $25, $21, $21, $25, $21, $25, $25, $21,
    $29, $2D, $11, $15, $15, $11, $15, $11, $01, $05, $05, $01, $05, $01, $01,
    $05, $0D, $09, $15, $11, $11, $15, $11, $15, $05, $01, $01, $05, $01, $05,
    $05, $01, $09, $0D, $35, $31, $31, $35, $31, $35),
    ($46, $02, $02, $06, $02, $06, $06, $02, $0A, $0E, $02, $06, $06, $02, $0A,
    $0E, $02, $06, $06, $02, $06, $02, $02, $06, $0E, $0A, $06, $02, $02, $06,
    $0E, $0A, $22, $26, $26, $22, $26, $22, $22, $26, $2E, $2A, $26, $22, $22,
    $26, $2E, $2A, $26, $22, $22, $26, $22, $26, $26, $22, $2A, $2E, $22, $26,
    $26, $22, $2A, $2E, $02, $06, $06, $02, $06, $02, $02, $06, $0E, $0A, $06,
    $02, $02, $06, $0E, $0A, $06, $02, $02, $06, $02, $06, $06, $02, $0A, $0E,
    $02, $06, $06, $02, $0A, $0E, $26, $22, $22, $26, $22, $26, $26, $22, $2A,
    $2E, $22, $26, $26, $22, $2A, $2E, $22, $26, $26, $22, $26, $22, $22, $26,
    $2E, $2A, $26, $22, $22, $26, $2E, $2A, $82, $86, $86, $82, $86, $82, $82,
    $86, $8E, $8A, $86, $82, $82, $86, $8E, $8A, $86, $82, $82, $86, $82, $86,
    $86, $82, $8A, $8E, $23, $27, $27, $23, $2B, $2F, $03, $07, $07, $03, $07,
    $03, $03, $07, $0F, $0B, $07, $03, $03, $07, $0F, $0B, $07, $03, $03, $07,
    $03, $07, $07, $03, $0B, $0F, $03, $07, $07, $03, $0B, $0F, $27, $23, $23,
    $27, $23, $27, $27, $23, $2B, $2F, $23, $27, $27, $23, $2B, $2F, $23, $27,
    $27, $23, $27, $23, $23, $27, $2F, $2B, $27, $23, $23, $27, $2F, $2B, $83,
    $87, $87, $83, $87, $83, $83, $87, $8F, $8B, $87, $83, $83, $87, $8F, $8B,
    $87, $83, $83, $87, $83, $87, $87, $83, $8B, $8F, $83, $87, $87, $83, $8B,
    $8F), ($A7, $A3, $A3, $A7, $A3, $A7, $A7, $A3, $AB, $AF, $A3, $A7, $A7, $A3,
    $AB, $AF, $A3, $A7, $A7, $A3, $A7, $A3, $A3, $A7, $AF, $AB, $A7, $A3, $A3,
    $A7, $AF, $AB, $87, $83, $83, $87, $83, $87, $87, $83, $8B, $8F, $83, $87,
    $87, $83, $8B, $8F, $83, $87, $87, $83, $87, $83, $83, $87, $8F, $8B, $87,
    $83, $83, $87, $8F, $8B, $A3, $A7, $A7, $A3, $A7, $A3, $A3, $A7, $AF, $AB,
    $A7, $A3, $A3, $A7, $AF, $AB, $A7, $A3, $A3, $A7, $A3, $A7, $A7, $A3, $AB,
    $AF, $A3, $A7, $A7, $A3, $AB, $AF, $47, $03, $03, $07, $03, $07, $07, $03,
    $0B, $0F, $03, $07, $07, $03, $0B, $0F, $03, $07, $07, $03, $07, $03, $03,
    $07, $0F, $0B, $07, $03, $03, $07, $0F, $0B, $23, $27, $27, $23, $27, $23,
    $23, $27, $2F, $2B, $27, $23, $23, $27, $2F, $2B, $27, $23, $23, $27, $23,
    $27, $27, $23, $2B, $2F, $23, $27, $27, $23, $2B, $2F, $03, $07, $07, $03,
    $07, $03, $03, $07, $0F, $0B, $07, $03, $03, $07, $0F, $0B, $07, $03, $03,
    $07, $03, $07, $07, $03, $0B, $0F, $03, $07, $07, $03, $0B, $0F, $27, $23,
    $23, $27, $23, $27, $27, $23, $2B, $2F, $23, $27, $27, $23, $2B, $2F, $23,
    $27, $27, $23, $27, $23, $23, $27, $2F, $2B, $27, $23, $23, $27, $2F, $2B,
    $83, $87, $87, $83, $87, $83, $83, $87, $8F, $8B, $87, $83, $83, $87, $8F,
    $8B, $87, $83, $83, $87, $83, $87, $87, $83, $8B, $8F, $83, $87, $87, $83,
    $8B, $8F), ($04, $00, $08, $0C, $0C, $08, $0C, $08, $08, $0C, $10, $14, $14,
    $10, $14, $10, $00, $04, $0C, $08, $08, $0C, $08, $0C, $0C, $08, $30, $34,
    $34, $30, $34, $30, $20, $24, $2C, $28, $28, $2C, $28, $2C, $2C, $28, $34,
    $30, $30, $34, $30, $34, $24, $20, $28, $2C, $2C, $28, $2C, $28, $28, $2C,
    $10, $14, $14, $10, $14, $10, $00, $04, $0C, $08, $08, $0C, $08, $0C, $0C,
    $08, $14, $10, $10, $14, $10, $14, $04, $00, $08, $0C, $0C, $08, $0C, $08,
    $08, $0C, $34, $30, $30, $34, $30, $34, $24, $20, $28, $2C, $2C, $28, $2C,
    $28, $28, $2C, $30, $34, $34, $30, $34, $30, $20, $24, $2C, $28, $28, $2C,
    $28, $2C, $2C, $28, $90, $94, $94, $90, $94, $90, $80, $84, $8C, $88, $88,
    $8C, $88, $8C, $8C, $88, $94, $90, $90, $94, $90, $94, $84, $80, $88, $8C,
    $8C, $88, $8C, $88, $88, $8C, $55, $11, $11, $15, $11, $15, $05, $01, $09,
    $0D, $0D, $09, $0D, $09, $09, $0D, $11, $15, $15, $11, $15, $11, $01, $05,
    $0D, $09, $09, $0D, $09, $0D, $0D, $09, $31, $35, $35, $31, $35, $31, $21,
    $25, $2D, $29, $29, $2D, $29, $2D, $2D, $29, $35, $31, $31, $35, $31, $35,
    $25, $21, $29, $2D, $2D, $29, $2D, $29, $29, $2D, $11, $15, $15, $11, $15,
    $11, $01, $05, $0D, $09, $09, $0D, $09, $0D, $0D, $09, $15, $11, $11, $15,
    $11, $15, $05, $01, $09, $0D, $0D, $09, $0D, $09, $09, $0D, $35, $31, $31,
    $35, $31, $35), ($25, $21, $29, $2D, $2D, $29, $2D, $29, $29, $2D, $31, $35,
    $35, $31, $35, $31, $21, $25, $2D, $29, $29, $2D, $29, $2D, $2D, $29, $91,
    $95, $95, $91, $95, $91, $81, $85, $8D, $89, $89, $8D, $89, $8D, $8D, $89,
    $95, $91, $91, $95, $91, $95, $85, $81, $89, $8D, $8D, $89, $8D, $89, $89,
    $8D, $B5, $B1, $B1, $B5, $B1, $B5, $A5, $A1, $A9, $AD, $AD, $A9, $AD, $A9,
    $A9, $AD, $B1, $B5, $B5, $B1, $B5, $B1, $A1, $A5, $AD, $A9, $A9, $AD, $A9,
    $AD, $AD, $A9, $95, $91, $91, $95, $91, $95, $85, $81, $89, $8D, $8D, $89,
    $8D, $89, $89, $8D, $91, $95, $95, $91, $95, $91, $81, $85, $8D, $89, $89,
    $8D, $89, $8D, $8D, $89, $B1, $B5, $B5, $B1, $B5, $B1, $A1, $A5, $AD, $A9,
    $A9, $AD, $A9, $AD, $AD, $A9, $B5, $B1, $B1, $B5, $B1, $B5, $A5, $A1, $A9,
    $AD, $AD, $A9, $AD, $A9, $A9, $AD, $55, $11, $11, $15, $11, $15, $05, $01,
    $09, $0D, $0D, $09, $0D, $09, $09, $0D, $11, $15, $15, $11, $15, $11, $01,
    $05, $0D, $09, $09, $0D, $09, $0D, $0D, $09, $31, $35, $35, $31, $35, $31,
    $21, $25, $2D, $29, $29, $2D, $29, $2D, $2D, $29, $35, $31, $31, $35, $31,
    $35, $25, $21, $29, $2D, $2D, $29, $2D, $29, $29, $2D, $11, $15, $15, $11,
    $15, $11, $01, $05, $0D, $09, $09, $0D, $09, $0D, $0D, $09, $15, $11, $11,
    $15, $11, $15, $05, $01, $09, $0D, $0D, $09, $0D, $09, $09, $0D, $35, $31,
    $31, $35, $31, $35), ($BE, $BA, $BE, $BA, $BA, $BE, $46, $02, $02, $06, $02,
    $06, $06, $02, $0A, $0E, $1E, $1A, $1E, $1A, $1A, $1E, $02, $06, $06, $02,
    $06, $02, $02, $06, $0E, $0A, $1A, $1E, $1A, $1E, $1E, $1A, $22, $26, $26,
    $22, $26, $22, $22, $26, $2E, $2A, $3A, $3E, $3A, $3E, $3E, $3A, $26, $22,
    $22, $26, $22, $26, $26, $22, $2A, $2E, $3E, $3A, $3E, $3A, $3A, $3E, $02,
    $06, $06, $02, $06, $02, $02, $06, $0E, $0A, $1A, $1E, $1A, $1E, $1E, $1A,
    $06, $02, $02, $06, $02, $06, $06, $02, $0A, $0E, $1E, $1A, $1E, $1A, $1A,
    $1E, $26, $22, $22, $26, $22, $26, $26, $22, $2A, $2E, $3E, $3A, $3E, $3A,
    $3A, $3E, $22, $26, $26, $22, $26, $22, $22, $26, $2E, $2A, $3A, $3E, $3A,
    $3E, $3E, $3A, $82, $86, $86, $82, $86, $82, $82, $86, $8E, $8A, $9A, $9E,
    $9A, $9E, $9E, $9A, $86, $82, $82, $86, $23, $27, $27, $23, $2B, $2F, $3F,
    $3B, $3F, $3B, $3B, $3F, $03, $07, $07, $03, $07, $03, $03, $07, $0F, $0B,
    $1B, $1F, $1B, $1F, $1F, $1B, $07, $03, $03, $07, $03, $07, $07, $03, $0B,
    $0F, $1F, $1B, $1F, $1B, $1B, $1F, $27, $23, $23, $27, $23, $27, $27, $23,
    $2B, $2F, $3F, $3B, $3F, $3B, $3B, $3F, $23, $27, $27, $23, $27, $23, $23,
    $27, $2F, $2B, $3B, $3F, $3B, $3F, $3F, $3B, $83, $87, $87, $83, $87, $83,
    $83, $87, $8F, $8B, $9B, $9F, $9B, $9F, $9F, $9B, $87, $83, $83, $87, $83,
    $87, $87, $83, $8B, $8F), ($9F, $9B, $9F, $9B, $9B, $9F, $A7, $A3, $A3, $A7,
    $A3, $A7, $A7, $A3, $AB, $AF, $BF, $BB, $BF, $BB, $BB, $BF, $A3, $A7, $A7,
    $A3, $A7, $A3, $A3, $A7, $AF, $AB, $BB, $BF, $BB, $BF, $BF, $BB, $87, $83,
    $83, $87, $83, $87, $87, $83, $8B, $8F, $9F, $9B, $9F, $9B, $9B, $9F, $83,
    $87, $87, $83, $87, $83, $83, $87, $8F, $8B, $9B, $9F, $9B, $9F, $9F, $9B,
    $A3, $A7, $A7, $A3, $A7, $A3, $A3, $A7, $AF, $AB, $BB, $BF, $BB, $BF, $BF,
    $BB, $A7, $A3, $A3, $A7, $A3, $A7, $A7, $A3, $AB, $AF, $BF, $BB, $BF, $BB,
    $BB, $BF, $47, $03, $03, $07, $03, $07, $07, $03, $0B, $0F, $1F, $1B, $1F,
    $1B, $1B, $1F, $03, $07, $07, $03, $07, $03, $03, $07, $0F, $0B, $1B, $1F,
    $1B, $1F, $1F, $1B, $23, $27, $27, $23, $27, $23, $23, $27, $2F, $2B, $3B,
    $3F, $3B, $3F, $3F, $3B, $27, $23, $23, $27, $23, $27, $27, $23, $2B, $2F,
    $3F, $3B, $3F, $3B, $3B, $3F, $03, $07, $07, $03, $07, $03, $03, $07, $0F,
    $0B, $1B, $1F, $1B, $1F, $1F, $1B, $07, $03, $03, $07, $03, $07, $07, $03,
    $0B, $0F, $1F, $1B, $1F, $1B, $1B, $1F, $27, $23, $23, $27, $23, $27, $27,
    $23, $2B, $2F, $3F, $3B, $3F, $3B, $3B, $3F, $23, $27, $27, $23, $27, $23,
    $23, $27, $2F, $2B, $3B, $3F, $3B, $3F, $3F, $3B, $83, $87, $87, $83, $87,
    $83, $83, $87, $8F, $8B, $9B, $9F, $9B, $9F, $9F, $9B, $87, $83, $83, $87,
    $83, $87, $87, $83, $8B, $8F));

  DAA_A: array [0 .. 7, 0 .. 255] of byte = (($00, $01, $02, $03, $04, $05, $06,
    $07, $08, $09, $10, $11, $12, $13, $14, $15, $10, $11, $12, $13, $14, $15,
    $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $20, $21, $22, $23, $24,
    $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $30, $31, $32, $33,
    $34, $35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45, $40, $41, $42,
    $43, $44, $45, $46, $47, $48, $49, $50, $51, $52, $53, $54, $55, $50, $51,
    $52, $53, $54, $55, $56, $57, $58, $59, $60, $61, $62, $63, $64, $65, $60,
    $61, $62, $63, $64, $65, $66, $67, $68, $69, $70, $71, $72, $73, $74, $75,
    $70, $71, $72, $73, $74, $75, $76, $77, $78, $79, $80, $81, $82, $83, $84,
    $85, $80, $81, $82, $83, $84, $85, $86, $87, $88, $89, $90, $91, $92, $93,
    $94, $95, $90, $91, $92, $93, $94, $95, $96, $97, $98, $99, $00, $01, $02,
    $03, $04, $05, $00, $01, $02, $03, $04, $05, $06, $07, $08, $09, $10, $11,
    $12, $13, $14, $15, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20,
    $21, $22, $23, $24, $25, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29,
    $30, $31, $32, $33, $34, $35, $30, $31, $32, $33, $34, $35, $36, $37, $38,
    $39, $40, $41, $42, $43, $44, $45, $40, $41, $42, $43, $44, $45, $46, $47,
    $48, $49, $50, $51, $52, $53, $54, $55, $50, $51, $52, $53, $54, $55, $56,
    $57, $58, $59, $60, $61, $62, $63, $64, $65), ($60, $61, $62, $63, $64, $65,
    $66, $67, $68, $69, $70, $71, $72, $73, $74, $75, $70, $71, $72, $73, $74,
    $75, $76, $77, $78, $79, $80, $81, $82, $83, $84, $85, $80, $81, $82, $83,
    $84, $85, $86, $87, $88, $89, $90, $91, $92, $93, $94, $95, $90, $91, $92,
    $93, $94, $95, $96, $97, $98, $99, $A0, $A1, $A2, $A3, $A4, $A5, $A0, $A1,
    $A2, $A3, $A4, $A5, $A6, $A7, $A8, $A9, $B0, $B1, $B2, $B3, $B4, $B5, $B0,
    $B1, $B2, $B3, $B4, $B5, $B6, $B7, $B8, $B9, $C0, $C1, $C2, $C3, $C4, $C5,
    $C0, $C1, $C2, $C3, $C4, $C5, $C6, $C7, $C8, $C9, $D0, $D1, $D2, $D3, $D4,
    $D5, $D0, $D1, $D2, $D3, $D4, $D5, $D6, $D7, $D8, $D9, $E0, $E1, $E2, $E3,
    $E4, $E5, $E0, $E1, $E2, $E3, $E4, $E5, $E6, $E7, $E8, $E9, $F0, $F1, $F2,
    $F3, $F4, $F5, $F0, $F1, $F2, $F3, $F4, $F5, $F6, $F7, $F8, $F9, $00, $01,
    $02, $03, $04, $05, $00, $01, $02, $03, $04, $05, $06, $07, $08, $09, $10,
    $11, $12, $13, $14, $15, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19,
    $20, $21, $22, $23, $24, $25, $20, $21, $22, $23, $24, $25, $26, $27, $28,
    $29, $30, $31, $32, $33, $34, $35, $30, $31, $32, $33, $34, $35, $36, $37,
    $38, $39, $40, $41, $42, $43, $44, $45, $40, $41, $42, $43, $44, $45, $46,
    $47, $48, $49, $50, $51, $52, $53, $54, $55, $50, $51, $52, $53, $54, $55,
    $56, $57, $58, $59, $60, $61, $62, $63, $64, $65),
    ($00, $01, $02, $03, $04, $05, $06, $07, $08, $09, $04, $05, $06, $07, $08,
    $09, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $14, $15, $16, $17,
    $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $24, $25, $26,
    $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $34, $35,
    $36, $37, $38, $39, $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $44,
    $45, $46, $47, $48, $49, $50, $51, $52, $53, $54, $55, $56, $57, $58, $59,
    $54, $55, $56, $57, $58, $59, $60, $61, $62, $63, $64, $65, $66, $67, $68,
    $69, $64, $65, $66, $67, $68, $69, $70, $71, $72, $73, $74, $75, $76, $77,
    $78, $79, $74, $75, $76, $77, $78, $79, $80, $81, $82, $83, $84, $85, $86,
    $87, $88, $89, $84, $85, $86, $87, $88, $89, $90, $91, $92, $93, $94, $95,
    $96, $97, $98, $99, $34, $35, $36, $37, $38, $39, $40, $41, $42, $43, $44,
    $45, $46, $47, $48, $49, $44, $45, $46, $47, $48, $49, $50, $51, $52, $53,
    $54, $55, $56, $57, $58, $59, $54, $55, $56, $57, $58, $59, $60, $61, $62,
    $63, $64, $65, $66, $67, $68, $69, $64, $65, $66, $67, $68, $69, $70, $71,
    $72, $73, $74, $75, $76, $77, $78, $79, $74, $75, $76, $77, $78, $79, $80,
    $81, $82, $83, $84, $85, $86, $87, $88, $89, $84, $85, $86, $87, $88, $89,
    $90, $91, $92, $93, $94, $95, $96, $97, $98, $99, $94, $95, $96, $97, $98,
    $99), ($A0, $A1, $A2, $A3, $A4, $A5, $A6, $A7, $A8, $A9, $A4, $A5, $A6, $A7,
    $A8, $A9, $B0, $B1, $B2, $B3, $B4, $B5, $B6, $B7, $B8, $B9, $B4, $B5, $B6,
    $B7, $B8, $B9, $C0, $C1, $C2, $C3, $C4, $C5, $C6, $C7, $C8, $C9, $C4, $C5,
    $C6, $C7, $C8, $C9, $D0, $D1, $D2, $D3, $D4, $D5, $D6, $D7, $D8, $D9, $D4,
    $D5, $D6, $D7, $D8, $D9, $E0, $E1, $E2, $E3, $E4, $E5, $E6, $E7, $E8, $E9,
    $E4, $E5, $E6, $E7, $E8, $E9, $F0, $F1, $F2, $F3, $F4, $F5, $F6, $F7, $F8,
    $F9, $F4, $F5, $F6, $F7, $F8, $F9, $00, $01, $02, $03, $04, $05, $06, $07,
    $08, $09, $04, $05, $06, $07, $08, $09, $10, $11, $12, $13, $14, $15, $16,
    $17, $18, $19, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25,
    $26, $27, $28, $29, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34,
    $35, $36, $37, $38, $39, $34, $35, $36, $37, $38, $39, $40, $41, $42, $43,
    $44, $45, $46, $47, $48, $49, $44, $45, $46, $47, $48, $49, $50, $51, $52,
    $53, $54, $55, $56, $57, $58, $59, $54, $55, $56, $57, $58, $59, $60, $61,
    $62, $63, $64, $65, $66, $67, $68, $69, $64, $65, $66, $67, $68, $69, $70,
    $71, $72, $73, $74, $75, $76, $77, $78, $79, $74, $75, $76, $77, $78, $79,
    $80, $81, $82, $83, $84, $85, $86, $87, $88, $89, $84, $85, $86, $87, $88,
    $89, $90, $91, $92, $93, $94, $95, $96, $97, $98, $99, $94, $95, $96, $97,
    $98, $99), ($06, $07, $08, $09, $0A, $0B, $0C, $0D, $0E, $0F, $10, $11, $12,
    $13, $14, $15, $16, $17, $18, $19, $1A, $1B, $1C, $1D, $1E, $1F, $20, $21,
    $22, $23, $24, $25, $26, $27, $28, $29, $2A, $2B, $2C, $2D, $2E, $2F, $30,
    $31, $32, $33, $34, $35, $36, $37, $38, $39, $3A, $3B, $3C, $3D, $3E, $3F,
    $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $4A, $4B, $4C, $4D, $4E,
    $4F, $50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $5A, $5B, $5C, $5D,
    $5E, $5F, $60, $61, $62, $63, $64, $65, $66, $67, $68, $69, $6A, $6B, $6C,
    $6D, $6E, $6F, $70, $71, $72, $73, $74, $75, $76, $77, $78, $79, $7A, $7B,
    $7C, $7D, $7E, $7F, $80, $81, $82, $83, $84, $85, $86, $87, $88, $89, $8A,
    $8B, $8C, $8D, $8E, $8F, $90, $91, $92, $93, $94, $95, $96, $97, $98, $99,
    $9A, $9B, $9C, $9D, $9E, $9F, $00, $01, $02, $03, $04, $05, $06, $07, $08,
    $09, $0A, $0B, $0C, $0D, $0E, $0F, $10, $11, $12, $13, $14, $15, $16, $17,
    $18, $19, $1A, $1B, $1C, $1D, $1E, $1F, $20, $21, $22, $23, $24, $25, $26,
    $27, $28, $29, $2A, $2B, $2C, $2D, $2E, $2F, $30, $31, $32, $33, $34, $35,
    $36, $37, $38, $39, $3A, $3B, $3C, $3D, $3E, $3F, $40, $41, $42, $43, $44,
    $45, $46, $47, $48, $49, $4A, $4B, $4C, $4D, $4E, $4F, $50, $51, $52, $53,
    $54, $55, $56, $57, $58, $59, $5A, $5B, $5C, $5D, $5E, $5F, $60, $61, $62,
    $63, $64, $65), ($66, $67, $68, $69, $6A, $6B, $6C, $6D, $6E, $6F, $70, $71,
    $72, $73, $74, $75, $76, $77, $78, $79, $7A, $7B, $7C, $7D, $7E, $7F, $80,
    $81, $82, $83, $84, $85, $86, $87, $88, $89, $8A, $8B, $8C, $8D, $8E, $8F,
    $90, $91, $92, $93, $94, $95, $96, $97, $98, $99, $9A, $9B, $9C, $9D, $9E,
    $9F, $A0, $A1, $A2, $A3, $A4, $A5, $A6, $A7, $A8, $A9, $AA, $AB, $AC, $AD,
    $AE, $AF, $B0, $B1, $B2, $B3, $B4, $B5, $B6, $B7, $B8, $B9, $BA, $BB, $BC,
    $BD, $BE, $BF, $C0, $C1, $C2, $C3, $C4, $C5, $C6, $C7, $C8, $C9, $CA, $CB,
    $CC, $CD, $CE, $CF, $D0, $D1, $D2, $D3, $D4, $D5, $D6, $D7, $D8, $D9, $DA,
    $DB, $DC, $DD, $DE, $DF, $E0, $E1, $E2, $E3, $E4, $E5, $E6, $E7, $E8, $E9,
    $EA, $EB, $EC, $ED, $EE, $EF, $F0, $F1, $F2, $F3, $F4, $F5, $F6, $F7, $F8,
    $F9, $FA, $FB, $FC, $FD, $FE, $FF, $00, $01, $02, $03, $04, $05, $06, $07,
    $08, $09, $0A, $0B, $0C, $0D, $0E, $0F, $10, $11, $12, $13, $14, $15, $16,
    $17, $18, $19, $1A, $1B, $1C, $1D, $1E, $1F, $20, $21, $22, $23, $24, $25,
    $26, $27, $28, $29, $2A, $2B, $2C, $2D, $2E, $2F, $30, $31, $32, $33, $34,
    $35, $36, $37, $38, $39, $3A, $3B, $3C, $3D, $3E, $3F, $40, $41, $42, $43,
    $44, $45, $46, $47, $48, $49, $4A, $4B, $4C, $4D, $4E, $4F, $50, $51, $52,
    $53, $54, $55, $56, $57, $58, $59, $5A, $5B, $5C, $5D, $5E, $5F, $60, $61,
    $62, $63, $64, $65), ($FA, $FB, $FC, $FD, $FE, $FF, $00, $01, $02, $03, $04,
    $05, $06, $07, $08, $09, $0A, $0B, $0C, $0D, $0E, $0F, $10, $11, $12, $13,
    $14, $15, $16, $17, $18, $19, $1A, $1B, $1C, $1D, $1E, $1F, $20, $21, $22,
    $23, $24, $25, $26, $27, $28, $29, $2A, $2B, $2C, $2D, $2E, $2F, $30, $31,
    $32, $33, $34, $35, $36, $37, $38, $39, $3A, $3B, $3C, $3D, $3E, $3F, $40,
    $41, $42, $43, $44, $45, $46, $47, $48, $49, $4A, $4B, $4C, $4D, $4E, $4F,
    $50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $5A, $5B, $5C, $5D, $5E,
    $5F, $60, $61, $62, $63, $64, $65, $66, $67, $68, $69, $6A, $6B, $6C, $6D,
    $6E, $6F, $70, $71, $72, $73, $74, $75, $76, $77, $78, $79, $7A, $7B, $7C,
    $7D, $7E, $7F, $80, $81, $82, $83, $84, $85, $86, $87, $88, $89, $8A, $8B,
    $8C, $8D, $8E, $8F, $90, $91, $92, $93, $34, $35, $36, $37, $38, $39, $3A,
    $3B, $3C, $3D, $3E, $3F, $40, $41, $42, $43, $44, $45, $46, $47, $48, $49,
    $4A, $4B, $4C, $4D, $4E, $4F, $50, $51, $52, $53, $54, $55, $56, $57, $58,
    $59, $5A, $5B, $5C, $5D, $5E, $5F, $60, $61, $62, $63, $64, $65, $66, $67,
    $68, $69, $6A, $6B, $6C, $6D, $6E, $6F, $70, $71, $72, $73, $74, $75, $76,
    $77, $78, $79, $7A, $7B, $7C, $7D, $7E, $7F, $80, $81, $82, $83, $84, $85,
    $86, $87, $88, $89, $8A, $8B, $8C, $8D, $8E, $8F, $90, $91, $92, $93, $94,
    $95, $96, $97, $98, $99), ($9A, $9B, $9C, $9D, $9E, $9F, $A0, $A1, $A2, $A3,
    $A4, $A5, $A6, $A7, $A8, $A9, $AA, $AB, $AC, $AD, $AE, $AF, $B0, $B1, $B2,
    $B3, $B4, $B5, $B6, $B7, $B8, $B9, $BA, $BB, $BC, $BD, $BE, $BF, $C0, $C1,
    $C2, $C3, $C4, $C5, $C6, $C7, $C8, $C9, $CA, $CB, $CC, $CD, $CE, $CF, $D0,
    $D1, $D2, $D3, $D4, $D5, $D6, $D7, $D8, $D9, $DA, $DB, $DC, $DD, $DE, $DF,
    $E0, $E1, $E2, $E3, $E4, $E5, $E6, $E7, $E8, $E9, $EA, $EB, $EC, $ED, $EE,
    $EF, $F0, $F1, $F2, $F3, $F4, $F5, $F6, $F7, $F8, $F9, $FA, $FB, $FC, $FD,
    $FE, $FF, $00, $01, $02, $03, $04, $05, $06, $07, $08, $09, $0A, $0B, $0C,
    $0D, $0E, $0F, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $1A, $1B,
    $1C, $1D, $1E, $1F, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $2A,
    $2B, $2C, $2D, $2E, $2F, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39,
    $3A, $3B, $3C, $3D, $3E, $3F, $40, $41, $42, $43, $44, $45, $46, $47, $48,
    $49, $4A, $4B, $4C, $4D, $4E, $4F, $50, $51, $52, $53, $54, $55, $56, $57,
    $58, $59, $5A, $5B, $5C, $5D, $5E, $5F, $60, $61, $62, $63, $64, $65, $66,
    $67, $68, $69, $6A, $6B, $6C, $6D, $6E, $6F, $70, $71, $72, $73, $74, $75,
    $76, $77, $78, $79, $7A, $7B, $7C, $7D, $7E, $7F, $80, $81, $82, $83, $84,
    $85, $86, $87, $88, $89, $8A, $8B, $8C, $8D, $8E, $8F, $90, $91, $92, $93,
    $94, $95, $96, $97, $98, $99));

procedure add16(regs: TZ80Register; var first: Word; second: Word); inline;
var
  qtemp: TQuadruple;
begin
  with regs do
  begin
    qtemp.Q := Longint(first) + Longint(second);
    first := qtemp.w1;
    af.l := (af.l and $C4) or (qtemp.b2 and $38);
    if qtemp.b3 = 0 then
      af.l := af.l and 254 (* reset Cf *)
    else
      af.l := af.l or 1; (* set Cf *)
  end;
end;

procedure adc16(regs: TZ80Register; first, second: Word); inline;
var
  qtemp: TQuadruple;
begin
  with regs do
  begin
    qtemp.Q := Longint(first) + Longint(second) + (af.l and 1);
    af.l := (qtemp.b2 and $B8);
    if qtemp.b3 = 0 then
      af.l := af.l and 254 (* reset Cf *)
    else
      af.l := af.l or 1; (* set Cf *)
    if qtemp.w1 > 0 then
      af.l := af.l and 191 (* reset Zf *)
    else
      af.l := af.l or 64; (* set Zf *)
    if ((first xor qtemp.w1) shr 15 > 0) and ((first xor second) shr 15 = 0)
    then
      af.l := af.l or 4 (* set Pf *)
    else
      af.l := af.l and 251; (* reset Pf *)
    hl.W := qtemp.w1;
  end;
end;

procedure sbc16(regs: TZ80Register; first, second: Word); inline;
var
  qtemp: TQuadruple;
begin
  with regs do
  begin
    qtemp.Q := Longint(first) - Longint(second) - (af.l and 1);
    af.l := (qtemp.b2 and $B8) or 2;
    if qtemp.b4 = 0 then
      af.l := af.l and 254 (* reset Cf *)
    else
      af.l := af.l or 1; (* set Cf *)
    if qtemp.w1 > 0 then
      af.l := af.l and 191 (* reset Zf *)
    else
      af.l := af.l or 64; (* set Zf *)
    if ((first xor qtemp.w1) shr 15 > 0) and ((second xor qtemp.w1) shr 15 = 0)
    then
      af.l := af.l or 4 (* set Pf *)
    else
      af.l := af.l and 251; (* reset Pf *)
    hl.W := qtemp.w1;
  end;
end;

procedure add8(regs: TZ80Register; Lo, Pls: byte); inline;
var
  ptemp: TPair;
begin
  with regs do
  begin
    ptemp.W := Lo + Pls;
    if ptemp.h = 0 then
    begin
      ptemp.h := ptemp.l;
      ptemp.l := ptemp.l and 254; (* reset Cf *)
    end
    else
    begin
      ptemp.h := ptemp.l;
      ptemp.l := ptemp.l or 1; (* set Cf *)
    end;
    ptemp.l := ptemp.l and 253; (* reset Nf *)
    if ptemp.h > 0 then
      ptemp.l := ptemp.l and 191 (* reset Zf *)
    else
      ptemp.l := ptemp.l or 64; (* set Zf *)
    if ((Lo xor Pls xor ptemp.h) and 16 > 0) then
      ptemp.l := ptemp.l or 16 (* set Hf *)
    else
      ptemp.l := ptemp.l and 239; (* reset Hf *)
    if ((Lo xor ptemp.h) shr 7 > 0) and ((Lo xor Pls) shr 7 = 0) then
      ptemp.l := ptemp.l or 4 (* set Pf *)
    else
      ptemp.l := ptemp.l and 251; (* reset Pf *)
    af.W := ptemp.W;
  end;
end;

procedure sub8(regs: TZ80Register; Lo, Mns: byte); inline;
var
  ptemp: TPair;
begin
  with regs do
  begin
    ptemp.W := Lo - Mns;
    if ptemp.h = 0 then
    begin
      ptemp.h := ptemp.l;
      ptemp.l := ptemp.l and 254; (* reset Cf *)
    end
    else
    begin
      ptemp.h := ptemp.l;
      ptemp.l := ptemp.l or 1; (* set Cf *)
    end;
    ptemp.l := ptemp.l or 2; (* set Nf *)
    if ptemp.h > 0 then
      ptemp.l := ptemp.l and 191 (* reset Zf *)
    else
      ptemp.l := ptemp.l or 64; (* set Zf *)
    if (Lo xor Mns xor ptemp.h) and 16 > 0 then
      ptemp.l := ptemp.l or 16 (* set Hf *)
    else
      ptemp.l := ptemp.l and 239; (* reset Hf *)
    if ((Lo xor ptemp.h) shr 7 > 0) and ((Mns xor ptemp.h) shr 7 = 0) then
      ptemp.l := ptemp.l or 4 (* set Pf *)
    else
      ptemp.l := ptemp.l and 251; (* reset Pf *)
    af.W := ptemp.W;
  end;
end;

procedure adc8(regs: TZ80Register; Lo, Pls: byte); inline;
var
  ptemp: TPair;
begin
  with regs do
  begin
    ptemp.W := Lo + Pls + (af.l and 1);
    if ptemp.h = 0 then
    begin
      ptemp.h := ptemp.l;
      ptemp.l := ptemp.l and 254; (* reset Cf *)
    end
    else
    begin
      ptemp.h := ptemp.l;
      ptemp.l := ptemp.l or 1; (* set Cf *)
    end;
    ptemp.l := ptemp.l and 253; (* reset Nf *)
    if ptemp.h > 0 then
      ptemp.l := ptemp.l and 191 (* reset Zf *)
    else
      ptemp.l := ptemp.l or 64; (* set Zf *)
    if (Lo xor Pls xor ptemp.h) and 16 > 0 then
      ptemp.l := ptemp.l or 16 (* set Hf *)
    else
      ptemp.l := ptemp.l and 239; (* reset Hf *)
    if ((Lo xor ptemp.h) shr 7 > 0) and ((Lo xor Pls) shr 7 = 0) then
      ptemp.l := ptemp.l or 4 (* set Pf *)
    else
      ptemp.l := ptemp.l and 251; (* reset Pf *)
    af.W := ptemp.W;
  end;
end;

procedure sbc8(regs: TZ80Register; Lo, Mns: byte); inline;
var
  ptemp: TPair;
begin
  with regs do
  begin
    ptemp.W := Lo - Mns - (af.l and 1);
    if ptemp.h = 0 then
    begin
      ptemp.h := ptemp.l;
      ptemp.l := ptemp.l and 254; (* reset Cf *)
    end
    else
    begin
      ptemp.h := ptemp.l;
      ptemp.l := ptemp.l or 1; (* set Cf *)
    end;
    ptemp.l := ptemp.l or 2; (* set Nf *)
    if ptemp.h > 0 then
      ptemp.l := ptemp.l and 191 (* reset Zf *)
    else
      ptemp.l := ptemp.l or 64; (* set Zf *)
    if (Lo xor Mns xor ptemp.h) and 16 > 0 then
      ptemp.l := ptemp.l or 16 (* set Hf *)
    else
      ptemp.l := ptemp.l and 239; (* reset Hf *)
    if ((Lo xor ptemp.h) shr 7 > 0) and ((Mns xor ptemp.h) shr 7 = 0) then
      ptemp.l := ptemp.l or 4 (* set Pf *)
    else
      ptemp.l := ptemp.l and 251; (* reset Pf *)
    af.W := ptemp.W;
  end;
end;

procedure cp_sub8(regs: TZ80Register; Lo, Mns: byte); inline;
var
  ptemp: TPair;

begin
  with regs do
  begin
    ptemp.W := Lo - Mns;
    af.l := (Mns and 40) or (ptemp.l and 215) or 2;
    if ptemp.l > 0 then
      af.l := af.l and 191 (* reset Zf *)
    else
      af.l := af.l or 64; (* set Zf *)
    if ptemp.h = 0 then
      af.l := af.l and 254 (* reset Cf *)
    else
      af.l := af.l or 1; (* set Cf *)
    if (Lo xor Mns xor ptemp.l) and 16 > 0 then
      af.l := af.l or 16 (* set Hf *)
    else
      af.l := af.l and 239; (* reset Hf *)

    if ((Lo xor ptemp.l) shr 7 > 0) and ((Mns xor ptemp.l) shr 7 = 0) then
      af.l := af.l or 4 (* set Pf *)
    else
      af.l := af.l and 251; (* reset Pf *)
  end;
end;

procedure anda(regs: TZ80Register; bval: byte); inline;
begin
  with regs do
  begin
    af.h := af.h and bval;
    af.l := 16 or (af.h and 236) or PARITY[af.h];
    if af.h = 0 then
      af.l := af.l or 64
    else
      af.l := af.l and 191;
  end;
end;

procedure ora(regs: TZ80Register; bval: byte); inline;
begin
  with regs do
  begin
    af.h := af.h or bval;
    af.l := (af.h and 236) or PARITY[af.h];
    if af.h = 0 then
      af.l := af.l or 64
    else
      af.l := af.l and 191;
  end;
end;

procedure xora(regs: TZ80Register; bval: byte); inline;
begin
  with regs do
  begin
    af.h := af.h xor bval;
    af.l := (af.h and 236) or PARITY[af.h];
    if af.h = 0 then
      af.l := af.l or 64
    else
      af.l := af.l and 191;
  end;
end;

procedure copy_b53(regs: TZ80Register; btemp: Word); inline;
begin
  with regs do
    af.l := (af.l and 215) or (btemp and 40);
end;

{ TZ80CPU }

constructor TZ80CPU.Create(const AHardware: IHardware);
var
  i, j: byte;
begin
  FRegister := TZ80Register.Create;
  FHardware := AHardware;
  FRSTMode := $38;

  for i := 0 to 255 do
  begin
    if i = 0 then
      j := 64
    else
      j := 0;
    add8_table[i] := (i and 168) or (j); (* Just HVC to do! *)
    sub8_table[i] := (i and 168) or (j) or 2;
    cpsub8_table[i] := (i and 128) or (j) or 2; (* 5 bits left.. *)

    in_table[i] := (i and 168) or (PARITY[i]);
    in_table[0] := in_table[0] or 64; (* Don't forget to keep old C flag *)
  end;
end;

destructor TZ80CPU.Destroy;
begin
  FRegister.free;
  inherited;
end;

function TZ80CPU.Z80Instr_CB(const op: byte): integer;
var
  btemp: byte;

begin
  result := 0;
  with FRegister do
    case op of
      0:
        begin
          af.l := RLCR_F[bc.h];
          bc.h := RLCR_A[bc.h];
          inc(result, 8);
        end;

      1:
        begin
          af.l := RLCR_F[bc.l];
          bc.l := RLCR_A[bc.l];
          inc(result, 8);
        end;

      2:
        begin
          af.l := RLCR_F[de.h];
          de.h := RLCR_A[de.h];
          inc(result, 8);
        end;

      3:
        begin
          af.l := RLCR_F[de.l];
          de.l := RLCR_A[de.l];
          inc(result, 8);
        end;

      4:
        begin
          af.l := RLCR_F[hl.h];
          hl.h := RLCR_A[hl.h];
          inc(result, 8);
        end;

      5:
        begin
          af.l := RLCR_F[hl.l];
          hl.l := RLCR_A[hl.l];
          inc(result, 8);
        end;

      6:
        begin
          btemp := peekb(FAddr);
          af.l := RLCR_F[btemp];
          pokeb(FAddr, RLCR_A[btemp]);
          inc(result, 23);
        end;

      7:
        begin
          af.l := RLCR_F[af.h];
          af.h := RLCR_A[af.h];
          inc(result, 8);
        end;

      8:
        begin
          af.l := RRCR_F[bc.h];
          bc.h := RRCR_A[bc.h];
          inc(result, 8);
        end;

      9:
        begin
          af.l := RRCR_F[bc.l];
          bc.l := RRCR_A[bc.l];
          inc(result, 8);
        end;

      10:
        begin
          af.l := RRCR_F[de.h];
          de.h := RRCR_A[de.h];
          inc(result, 8);
        end;

      11:
        begin
          af.l := RRCR_F[de.l];
          de.l := RRCR_A[de.l];
          inc(result, 8);
        end;

      12:
        begin
          af.l := RRCR_F[hl.h];
          hl.h := RRCR_A[hl.h];
          inc(result, 8);
        end;

      13:
        begin
          af.l := RRCR_F[hl.l];
          hl.l := RRCR_A[hl.l];
          inc(result, 8);
        end;

      14:

        begin
          btemp := peekb(FAddr);
          af.l := RRCR_F[btemp];
          pokeb(FAddr, RRCR_A[btemp]);
          inc(result, 15);
        end;

      15:
        begin
          af.l := RRCR_F[af.h];
          af.h := RRCR_A[af.h];
          inc(result, 8);
        end;

      16:
        begin
          if af.l and 1 = 0 then
          begin
            af.l := RLR_F[0][bc.h];
            bc.h := RLR_A[0][bc.h];
          end
          else
          begin
            af.l := RLR_F[1][bc.h];
            bc.h := RLR_A[1][bc.h];
          end;
          inc(result, 8);
        end;

      17:
        begin
          if af.l and 1 = 0 then
          begin
            af.l := RLR_F[0][bc.l];
            bc.l := RLR_A[0][bc.l];
          end
          else
          begin
            af.l := RLR_F[1][bc.l];
            bc.l := RLR_A[1][bc.l];
          end;
          inc(result, 8);
        end;

      18:
        begin
          if af.l and 1 = 0 then
          begin
            af.l := RLR_F[0][de.h];
            de.h := RLR_A[0][de.h];
          end
          else
          begin
            af.l := RLR_F[1][de.h];
            de.h := RLR_A[1][de.h];
          end;
          inc(result, 8);
        end;

      19:
        begin
          if af.l and 1 = 0 then
          begin
            af.l := RLR_F[0][de.l];
            de.l := RLR_A[0][de.l];
          end
          else
          begin
            af.l := RLR_F[1][de.l];
            de.l := RLR_A[1][de.l];
          end;
          inc(result, 8);
        end;

      20:
        begin
          if af.l and 1 = 0 then
          begin
            af.l := RLR_F[0][hl.h];
            hl.h := RLR_A[0][hl.h];
          end
          else
          begin
            af.l := RLR_F[1][hl.h];
            hl.h := RLR_A[1][hl.h];
          end;
          inc(result, 8);
        end;

      21:
        begin
          if af.l and 1 = 0 then
          begin
            af.l := RLR_F[0][hl.l];
            hl.l := RLR_A[0][hl.l];
          end
          else
          begin
            af.l := RLR_F[1][hl.l];
            hl.l := RLR_A[1][hl.l];
          end;
          inc(result, 8);
        end;

      22:

        begin
          if af.l and 1 = 0 then
          begin
            btemp := peekb(FAddr);
            af.l := RLR_F[0][btemp];
            pokeb(FAddr, RLR_A[0][btemp]);
          end
          else
          begin
            btemp := peekb(FAddr);
            af.l := RLR_F[1][btemp];
            pokeb(FAddr, RLR_A[1][btemp]);
          end;
          inc(result, 15);
        end;

      23:
        begin
          if af.l and 1 = 0 then
          begin
            af.l := RLR_F[0][af.h];
            af.h := RLR_A[0][af.h];
          end
          else
          begin
            af.l := RLR_F[1][af.h];
            af.h := RLR_A[1][af.h];
          end;
          inc(result, 8);
        end;

      24:
        begin
          if af.l and 1 = 0 then
          begin
            af.l := RRR_F[0][bc.h];
            bc.h := RRR_A[0][bc.h];
          end
          else
          begin
            af.l := RRR_F[1][bc.h];
            bc.h := RRR_A[1][bc.h];
          end;
          inc(result, 8);
        end;

      25:
        begin
          if af.l and 1 = 0 then
          begin
            af.l := RRR_F[0][bc.l];
            bc.l := RRR_A[0][bc.l];
          end
          else
          begin
            af.l := RRR_F[1][bc.l];
            bc.l := RRR_A[1][bc.l];
          end;
          inc(result, 8);
        end;

      26:
        begin
          if af.l and 1 = 0 then
          begin
            af.l := RRR_F[0][de.h];
            de.h := RRR_A[0][de.h];
          end
          else
          begin
            af.l := RRR_F[1][de.h];
            de.h := RRR_A[1][de.h];
          end;
          inc(result, 8);
        end;

      27:
        begin
          if af.l and 1 = 0 then
          begin
            af.l := RRR_F[0][de.l];
            de.l := RRR_A[0][de.l];
          end
          else
          begin
            af.l := RRR_F[1][de.l];
            de.l := RRR_A[1][de.l];
          end;
          inc(result, 8);
        end;

      28:
        begin
          if af.l and 1 = 0 then
          begin
            af.l := RRR_F[0][hl.h];
            hl.h := RRR_A[0][hl.h];
          end
          else
          begin
            af.l := RRR_F[1][hl.h];
            hl.h := RRR_A[1][hl.h];
          end;
          inc(result, 8);
        end;

      29:
        begin
          if af.l and 1 = 0 then
          begin
            af.l := RRR_F[0][hl.l];
            hl.l := RRR_A[0][hl.l];
          end
          else
          begin
            af.l := RRR_F[1][hl.l];
            hl.l := RRR_A[1][hl.l];
          end;
          inc(result, 8);
        end;

      30:

        begin
          if af.l and 1 = 0 then
          begin
            btemp := peekb(FAddr);
            af.l := RRR_F[0][btemp];
            pokeb(FAddr, RRR_A[0][btemp]);
          end
          else
          begin
            btemp := peekb(FAddr);
            af.l := RRR_F[1][btemp];
            pokeb(FAddr, RRR_A[1][btemp]);
          end;
          inc(result, 15);
        end;

      31:
        begin
          if af.l and 1 = 0 then
          begin
            af.l := RRR_F[0][af.h];
            af.h := RRR_A[0][af.h];
          end
          else
          begin
            af.l := RRR_F[1][af.h];
            af.h := RRR_A[1][af.h];
          end;
          inc(result, 8);
        end;

      32:
        begin
          af.l := SLA_F[bc.h];
          bc.h := SLA_A[bc.h];
          inc(result, 8);
        end;

      33:
        begin
          af.l := SLA_F[bc.l];
          bc.l := SLA_A[bc.l];
          inc(result, 8);
        end;

      34:
        begin
          af.l := SLA_F[de.h];
          de.h := SLA_A[de.h];
          inc(result, 8);
        end;

      35:
        begin
          af.l := SLA_F[de.l];
          de.l := SLA_A[de.l];
          inc(result, 8);
        end;

      36:
        begin
          af.l := SLA_F[hl.h];
          hl.h := SLA_A[hl.h];
          inc(result, 8);
        end;

      37:
        begin
          af.l := SLA_F[hl.l];
          hl.l := SLA_A[hl.l];
          inc(result, 8);
        end;

      38:

        begin
          btemp := peekb(FAddr);
          af.l := SLA_F[btemp];
          pokeb(FAddr, SLA_A[btemp]);
          inc(result, 15);
        end;

      39:
        begin
          af.l := SLA_F[af.h];
          af.h := SLA_A[af.h];
          inc(result, 8);
        end;

      40:
        begin
          af.l := SRA_F[bc.h];
          bc.h := SRA_A[bc.h];
          inc(result, 8);
        end;

      41:
        begin
          af.l := SRA_F[bc.l];
          bc.l := SRA_A[bc.l];
          inc(result, 8);
        end;

      42:
        begin
          af.l := SRA_F[de.h];
          de.h := SRA_A[de.h];
          inc(result, 8);
        end;

      43:
        begin
          af.l := SRA_F[de.l];
          de.l := SRA_A[de.l];
          inc(result, 8);
        end;

      44:
        begin
          af.l := SRA_F[hl.h];
          hl.h := SRA_A[hl.h];
          inc(result, 8);
        end;

      45:
        begin
          af.l := SRA_F[hl.l];
          hl.l := SRA_A[hl.l];
          inc(result, 8);
        end;

      46:

        begin
          btemp := peekb(FAddr);
          af.l := SRA_F[btemp];
          pokeb(FAddr, SRA_A[btemp]);
          inc(result, 15);
        end;

      47:
        begin
          af.l := SRA_F[af.h];
          af.h := SRA_A[af.h];
          inc(result, 8);
        end;

      48:
        begin
          af.l := SLL_F[bc.h];
          bc.h := SLL_A[bc.h];
          inc(result, 8);
        end;

      49:
        begin
          af.l := SLL_F[bc.l];
          bc.l := SLL_A[bc.l];
          inc(result, 8);
        end;

      50:
        begin
          af.l := SLL_F[de.h];
          de.h := SLL_A[de.h];
          inc(result, 8);
        end;

      51:
        begin
          af.l := SLL_F[de.l];
          de.l := SLL_A[de.l];
          inc(result, 8);
        end;

      52:
        begin
          af.l := SLL_F[hl.h];
          hl.h := SLL_A[hl.h];
          inc(result, 8);
        end;

      53:
        begin
          af.l := SLL_F[hl.l];
          hl.l := SLL_A[hl.l];
          inc(result, 8);
        end;

      54:

        begin
          btemp := peekb(FAddr);
          af.l := SLL_F[btemp];
          pokeb(FAddr, SLL_A[btemp]);
          inc(result, 15);
        end;

      55:
        begin
          af.l := SLL_F[af.h];
          af.h := SLL_A[af.h];
          inc(result, 8);
        end;

      56:
        begin
          af.l := SRL_F[bc.h];
          bc.h := SRL_A[bc.h];
          inc(result, 8);
        end;

      57:
        begin
          af.l := SRL_F[bc.l];
          bc.l := SRL_A[bc.l];
          inc(result, 8);
        end;

      58:
        begin
          af.l := SRL_F[de.h];
          de.h := SRL_A[de.h];
          inc(result, 8);
        end;

      59:
        begin
          af.l := SRL_F[de.l];
          de.l := SRL_A[de.l];
          inc(result, 8);
        end;

      60:
        begin
          af.l := SRL_F[hl.h];
          hl.h := SRL_A[hl.h];
          inc(result, 8);
        end;

      61:
        begin
          af.l := SRL_F[hl.l];
          hl.l := SRL_A[hl.l];
          inc(result, 8);
        end;

      62:
        begin
          btemp := peekb(FAddr);
          af.l := SRL_F[btemp];
          pokeb(FAddr, SRL_A[btemp]);
          inc(result, 15);
        end;

      63:
        begin
          af.l := SRL_F[af.h];
          af.h := SRL_A[af.h];
          inc(result, 8);
        end;

      64:
        begin
          af.l := BIT_F0[bc.h] or (af.l and 1);
          inc(result, 8);
        end;

      65:
        begin
          af.l := BIT_F0[bc.l] or (af.l and 1);
          inc(result, 8);
        end;

      66:
        begin
          af.l := BIT_F0[de.h] or (af.l and 1);
          inc(result, 8);
        end;

      67:
        begin
          af.l := BIT_F0[de.l] or (af.l and 1);
          inc(result, 8);
        end;

      68:
        begin
          af.l := BIT_F0[hl.h] or (af.l and 1);
          inc(result, 8);
        end;

      69:
        begin
          af.l := BIT_F0[hl.l] or (af.l and 1);
          inc(result, 8);
        end;

      70:
        begin
          af.l := BIT_F0[peekb(FAddr)] or (af.l and 1);
          inc(result, 12);
        end;

      71:
        begin
          af.l := BIT_F0[af.h] or (af.l and 1);
          inc(result, 8);
        end;

      72:
        begin
          af.l := BIT_F1[bc.h] or (af.l and 1);
          inc(result, 8);
        end;

      73:
        begin
          af.l := BIT_F1[bc.l] or (af.l and 1);
          inc(result, 8);
        end;

      74:
        begin
          af.l := BIT_F1[de.h] or (af.l and 1);
          inc(result, 8);
        end;

      75:
        begin
          af.l := BIT_F1[de.l] or (af.l and 1);
          inc(result, 8);
        end;

      76:
        begin
          af.l := BIT_F1[hl.h] or (af.l and 1);
          inc(result, 8);
        end;

      77:
        begin
          af.l := BIT_F1[hl.l] or (af.l and 1);
          inc(result, 8);
        end;

      78:
        begin
          af.l := BIT_F1[peekb(FAddr)] or (af.l and 1);
          inc(result, 12);
        end;

      79:
        begin
          af.l := BIT_F1[af.h] or (af.l and 1);
          inc(result, 8);
        end;

      80:
        begin
          af.l := BIT_F2[bc.h] or (af.l and 1);
          inc(result, 8);
        end;

      81:
        begin
          af.l := BIT_F2[bc.l] or (af.l and 1);
          inc(result, 8);
        end;

      82:
        begin
          af.l := BIT_F2[de.h] or (af.l and 1);
          inc(result, 8);
        end;

      83:
        begin
          af.l := BIT_F2[de.l] or (af.l and 1);
          inc(result, 8);
        end;

      84:
        begin
          af.l := BIT_F2[hl.h] or (af.l and 1);
          inc(result, 8);
        end;

      85:
        begin
          af.l := BIT_F2[hl.l] or (af.l and 1);
          inc(result, 8);
        end;

      86:
        begin
          af.l := BIT_F2[peekb(FAddr)] or (af.l and 1);
          inc(result, 12);
        end;

      87:
        begin
          af.l := BIT_F2[af.h] or (af.l and 1);
          inc(result, 8);
        end;

      88:
        begin
          af.l := BIT_F3[bc.h] or (af.l and 1);
          inc(result, 8);
        end;

      89:
        begin
          af.l := BIT_F3[bc.l] or (af.l and 1);
          inc(result, 8);
        end;

      90:
        begin
          af.l := BIT_F3[de.h] or (af.l and 1);
          inc(result, 8);
        end;

      91:
        begin
          af.l := BIT_F3[de.l] or (af.l and 1);
          inc(result, 8);
        end;

      92:
        begin
          af.l := BIT_F3[hl.h] or (af.l and 1);
          inc(result, 8);
        end;

      93:
        begin
          af.l := BIT_F3[hl.l] or (af.l and 1);
          inc(result, 8);
        end;

      94:
        begin
          af.l := BIT_F3[peekb(FAddr)] or (af.l and 1);
          inc(result, 12);
        end;

      95:
        begin
          af.l := BIT_F3[af.h] or (af.l and 1);
          inc(result, 8);
        end;

      96:
        begin
          af.l := BIT_F4[bc.h] or (af.l and 1);
          inc(result, 8);
        end;

      97:
        begin
          af.l := BIT_F4[bc.l] or (af.l and 1);
          inc(result, 8);
        end;

      98:
        begin
          af.l := BIT_F4[de.h] or (af.l and 1);
          inc(result, 8);
        end;

      99:
        begin
          af.l := BIT_F4[de.l] or (af.l and 1);
          inc(result, 8);
        end;

      100:
        begin
          af.l := BIT_F4[hl.h] or (af.l and 1);
          inc(result, 8);
        end;

      101:
        begin
          af.l := BIT_F4[hl.l] or (af.l and 1);
          inc(result, 8);
        end;

      102:
        begin
          af.l := BIT_F4[peekb(FAddr)] or (af.l and 1);
          inc(result, 12);
        end;

      103:
        begin
          af.l := BIT_F4[af.h] or (af.l and 1);
          inc(result, 8);
        end;

      104:
        begin
          af.l := BIT_F5[bc.h] or (af.l and 1);
          inc(result, 8);
        end;

      105:
        begin
          af.l := BIT_F5[bc.l] or (af.l and 1);
          inc(result, 8);
        end;

      106:
        begin
          af.l := BIT_F5[de.h] or (af.l and 1);
          inc(result, 8);
        end;

      107:
        begin
          af.l := BIT_F5[de.l] or (af.l and 1);
          inc(result, 8);
        end;

      108:
        begin
          af.l := BIT_F5[hl.h] or (af.l and 1);
          inc(result, 8);
        end;

      109:
        begin
          af.l := BIT_F5[hl.l] or (af.l and 1);
          inc(result, 8);
        end;

      110:
        begin
          af.l := BIT_F5[peekb(FAddr)] or (af.l and 1);
          inc(result, 12);
        end;

      111:
        begin
          af.l := BIT_F5[af.h] or (af.l and 1);
          inc(result, 8);
        end;

      112:
        begin
          af.l := BIT_F6[bc.h] or (af.l and 1);
          inc(result, 8);
        end;

      113:
        begin
          af.l := BIT_F6[bc.l] or (af.l and 1);
          inc(result, 8);
        end;

      114:
        begin
          af.l := BIT_F6[de.h] or (af.l and 1);
          inc(result, 8);
        end;

      115:
        begin
          af.l := BIT_F6[de.l] or (af.l and 1);
          inc(result, 8);
        end;

      116:
        begin
          af.l := BIT_F6[hl.h] or (af.l and 1);
          inc(result, 8);
        end;

      117:
        begin
          af.l := BIT_F6[hl.l] or (af.l and 1);
          inc(result, 8);
        end;

      118:
        begin
          af.l := BIT_F6[peekb(FAddr)] or (af.l and 1);
          inc(result, 12);
        end;

      119:
        begin
          af.l := BIT_F6[af.h] or (af.l and 1);
          inc(result, 8);
        end;

      120:
        begin
          af.l := BIT_F7[bc.h] or (af.l and 1);
          inc(result, 8);
        end;

      121:
        begin
          af.l := BIT_F7[bc.l] or (af.l and 1);
          inc(result, 8);
        end;

      122:
        begin
          af.l := BIT_F7[de.h] or (af.l and 1);
          inc(result, 8);
        end;

      123:
        begin
          af.l := BIT_F7[de.l] or (af.l and 1);
          inc(result, 8);
        end;

      124:
        begin
          af.l := BIT_F7[hl.h] or (af.l and 1);
          inc(result, 8);
        end;

      125:
        begin
          af.l := BIT_F7[hl.l] or (af.l and 1);
          inc(result, 8);
        end;

      126:
        begin
          af.l := BIT_F7[peekb(FAddr)] or (af.l and 1);
          inc(result, 12);
        end;

      127:
        begin
          af.l := BIT_F7[af.h] or (af.l and 1);
          inc(result, 8);
        end;

      128:
        begin
          bc.h := bc.h and 254;
          inc(result, 8);
        end;

      129:
        begin
          bc.l := bc.l and 254;
          inc(result, 8);
        end;

      130:
        begin
          de.h := de.h and 254;
          inc(result, 8);
        end;

      131:
        begin
          de.l := de.l and 254;
          inc(result, 8);
        end;

      132:
        begin
          hl.h := hl.h and 254;
          inc(result, 8);
        end;

      133:
        begin
          hl.l := hl.l and 254;
          inc(result, 8);
        end;

      134:
        begin
          pokeb(FAddr, peekb(FAddr) and 254);
          inc(result, 15);
        end;

      135:
        begin
          af.h := af.h and 254;
          inc(result, 8);
        end;

      136:
        begin
          bc.h := bc.h and 253;
          inc(result, 8);
        end;

      137:
        begin
          bc.l := bc.l and 253;
          inc(result, 8);
        end;

      138:
        begin
          de.h := de.h and 253;
          inc(result, 8);
        end;

      139:
        begin
          de.l := de.l and 253;
          inc(result, 8);
        end;

      140:
        begin
          hl.h := hl.h and 253;
          inc(result, 8);
        end;

      141:
        begin
          hl.l := hl.l and 253;
          inc(result, 8);
        end;

      142:
        begin
          pokeb(FAddr, peekb(FAddr) and 253);
          inc(result, 15);
        end;

      143:
        begin
          af.h := af.h and 253;
          inc(result, 8);
        end;

      144:
        begin
          bc.h := bc.h and 251;
          inc(result, 8);
        end;

      145:
        begin
          bc.l := bc.l and 251;
          inc(result, 8);
        end;

      146:
        begin
          de.h := de.h and 251;
          inc(result, 8);
        end;

      147:
        begin
          de.l := de.l and 251;
          inc(result, 8);
        end;

      148:
        begin
          hl.h := hl.h and 251;
          inc(result, 8);
        end;

      149:
        begin
          hl.l := hl.l and 251;
          inc(result, 8);
        end;

      150:
        begin
          pokeb(FAddr, peekb(FAddr) and 251);
          inc(result, 15);
        end;

      151:
        begin
          af.h := af.h and 251;
          inc(result, 8);
        end;

      152:
        begin
          bc.h := bc.h and 247;
          inc(result, 8);
        end;

      153:
        begin
          bc.l := bc.l and 247;
          inc(result, 8);
        end;

      154:
        begin
          de.h := de.h and 247;
          inc(result, 8);
        end;

      155:
        begin
          de.l := de.l and 247;
          inc(result, 8);
        end;

      156:
        begin
          hl.h := hl.h and 247;
          inc(result, 8);
        end;

      157:
        begin
          hl.l := hl.l and 247;
          inc(result, 8);
        end;

      158:
        begin
          pokeb(FAddr, peekb(FAddr) and 247);
          inc(result, 15);
        end;

      159:
        begin
          af.h := af.h and 247;
          inc(result, 8);
        end;

      160:
        begin
          bc.h := bc.h and 239;
          inc(result, 8);
        end;

      161:
        begin
          bc.l := bc.l and 239;
          inc(result, 8);
        end;

      162:
        begin
          de.h := de.h and 239;
          inc(result, 8);
        end;

      163:
        begin
          de.l := de.l and 239;
          inc(result, 8);
        end;

      164:
        begin
          hl.h := hl.h and 239;
          inc(result, 8);
        end;

      165:
        begin
          hl.l := hl.l and 239;
          inc(result, 8);
        end;

      166:
        begin
          pokeb(FAddr, peekb(FAddr) and 239);
          inc(result, 15);
        end;

      167:
        begin
          af.h := af.h and 239;
          inc(result, 8);
        end;

      168:
        begin
          bc.h := bc.h and 223;
          inc(result, 8);
        end;

      169:
        begin
          bc.l := bc.l and 223;
          inc(result, 8);
        end;

      170:
        begin
          de.h := de.h and 223;
          inc(result, 8);
        end;

      171:
        begin
          de.l := de.l and 223;
          inc(result, 8);
        end;

      172:
        begin
          hl.h := hl.h and 223;
          inc(result, 8);
        end;

      173:
        begin
          hl.l := hl.l and 223;
          inc(result, 8);
        end;

      174:
        begin
          pokeb(FAddr, peekb(FAddr) and 223);
          inc(result, 15);
        end;

      175:
        begin
          af.h := af.h and 223;
          inc(result, 8);
        end;

      176:
        begin
          bc.h := bc.h and 191;
          inc(result, 8);
        end;

      177:
        begin
          bc.l := bc.l and 191;
          inc(result, 8);
        end;

      178:
        begin
          de.h := de.h and 191;
          inc(result, 8);
        end;

      179:
        begin
          de.l := de.l and 191;
          inc(result, 8);
        end;

      180:
        begin
          hl.h := hl.h and 191;
          inc(result, 8);
        end;

      181:
        begin
          hl.l := hl.l and 191;
          inc(result, 8);
        end;

      182:
        begin
          pokeb(FAddr, peekb(FAddr) and 191);
          inc(result, 15);
        end;

      183:
        begin
          af.h := af.h and 191;
          inc(result, 8);
        end;

      184:
        begin
          bc.h := bc.h and 127;
          inc(result, 8);
        end;

      185:
        begin
          bc.l := bc.l and 127;
          inc(result, 8);
        end;

      186:
        begin
          de.h := de.h and 127;
          inc(result, 8);
        end;

      187:
        begin
          de.l := de.l and 127;
          inc(result, 8);
        end;

      188:
        begin
          hl.h := hl.h and 127;
          inc(result, 8);
        end;

      189:
        begin
          hl.l := hl.l and 127;
          inc(result, 8);
        end;

      190:
        begin
          pokeb(FAddr, peekb(FAddr) and 127);
          inc(result, 15);
        end;

      191:
        begin
          af.h := af.h and 127;
          inc(result, 8);
        end;

      192:
        begin
          bc.h := bc.h or 1;
          inc(result, 8);
        end;

      193:
        begin
          bc.l := bc.l or 1;
          inc(result, 8);
        end;

      194:
        begin
          de.h := de.h or 1;
          inc(result, 8);
        end;

      195:
        begin
          de.l := de.l or 1;
          inc(result, 8);
        end;

      196:
        begin
          hl.h := hl.h or 1;
          inc(result, 8);
        end;

      197:
        begin
          hl.l := hl.l or 1;
          inc(result, 8);
        end;

      198:
        begin
          pokeb(FAddr, peekb(FAddr) or 1);
          inc(result, 15);
        end;

      199:
        begin
          af.h := af.h or 1;
          inc(result, 8);
        end;

      200:
        begin
          bc.h := bc.h or 2;
          inc(result, 8);
        end;

      201:
        begin
          bc.l := bc.l or 2;
          inc(result, 8);
        end;

      202:
        begin
          de.h := de.h or 2;
          inc(result, 8);
        end;

      203:
        begin
          de.l := de.l or 2;
          inc(result, 8);
        end;

      204:
        begin
          hl.h := hl.h or 2;
          inc(result, 8);
        end;

      205:
        begin
          hl.l := hl.l or 2;
          inc(result, 8);
        end;

      206:
        begin
          pokeb(FAddr, peekb(FAddr) or 2);
          inc(result, 15);
        end;

      207:
        begin
          af.h := af.h or 2;
          inc(result, 8);
        end;

      208:
        begin
          bc.h := bc.h or 4;
          inc(result, 8);
        end;

      209:
        begin
          bc.l := bc.l or 4;
          inc(result, 8);
        end;

      210:
        begin
          de.h := de.h or 4;
          inc(result, 8);
        end;

      211:
        begin
          de.l := de.l or 4;
          inc(result, 8);
        end;

      212:
        begin
          hl.h := hl.h or 4;
          inc(result, 8);
        end;

      213:
        begin
          hl.l := hl.l or 4;
          inc(result, 8);
        end;

      214:
        begin
          pokeb(FAddr, peekb(FAddr) or 4);
          inc(result, 15);
        end;

      215:
        begin
          af.h := af.h or 4;
          inc(result, 8);
        end;

      216:
        begin
          bc.h := bc.h or 8;
          inc(result, 8);
        end;

      217:
        begin
          bc.l := bc.l or 8;
          inc(result, 8);
        end;

      218:
        begin
          de.h := de.h or 8;
          inc(result, 8);
        end;

      219:
        begin
          de.l := de.l or 8;
          inc(result, 8);
        end;

      220:
        begin
          hl.h := hl.h or 8;
          inc(result, 8);
        end;

      221:
        begin
          hl.l := hl.l or 8;
          inc(result, 8);
        end;

      222:
        begin
          pokeb(FAddr, peekb(FAddr) or 8);
          inc(result, 15);
        end;

      223:
        begin
          af.h := af.h or 8;
          inc(result, 8);
        end;

      224:
        begin
          bc.h := bc.h or 16;
          inc(result, 8);
        end;

      225:
        begin
          bc.l := bc.l or 16;
          inc(result, 8);
        end;

      226:
        begin
          de.h := de.h or 16;
          inc(result, 8);
        end;

      227:
        begin
          de.l := de.l or 16;
          inc(result, 8);
        end;

      228:
        begin
          hl.h := hl.h or 16;
          inc(result, 8);
        end;

      229:
        begin
          hl.l := hl.l or 16;
          inc(result, 8);
        end;

      230:
        begin
          pokeb(FAddr, peekb(FAddr) or 16);
          inc(result, 15);
        end;

      231:
        begin
          af.h := af.h or 16;
          inc(result, 8);
        end;

      232:
        begin
          bc.h := bc.h or 32;
          inc(result, 8);
        end;

      233:
        begin
          bc.l := bc.l or 32;
          inc(result, 8);
        end;

      234:
        begin
          de.h := de.h or 32;
          inc(result, 8);
        end;

      235:
        begin
          de.l := de.l or 32;
          inc(result, 8);
        end;

      236:
        begin
          hl.h := hl.h or 32;
          inc(result, 8);
        end;

      237:
        begin
          hl.l := hl.l or 32;
          inc(result, 8);
        end;

      238:
        begin
          pokeb(FAddr, peekb(FAddr) or 32);
          inc(result, 15);
        end;

      239:
        begin
          af.h := af.h or 32;
          inc(result, 8);
        end;

      240:
        begin
          bc.h := bc.h or 64;
          inc(result, 8);
        end;

      241:
        begin
          bc.l := bc.l or 64;
          inc(result, 8);
        end;

      242:
        begin
          de.h := de.h or 64;
          inc(result, 8);
        end;

      243:
        begin
          de.l := de.l or 64;
          inc(result, 8);
        end;

      244:
        begin
          hl.h := hl.h or 64;
          inc(result, 8);
        end;

      245:
        begin
          hl.l := hl.l or 64;
          inc(result, 8);
        end;

      246:
        begin
          pokeb(FAddr, peekb(FAddr) or 64);
          inc(result, 15);
        end;

      247:
        begin
          af.h := af.h or 64;
          inc(result, 8);
        end;

      248:
        begin
          bc.h := bc.h or 128;
          inc(result, 8);
        end;

      249:
        begin
          bc.l := bc.l or 128;
          inc(result, 8);
        end;

      250:
        begin
          de.h := de.h or 128;
          inc(result, 8);
        end;

      251:
        begin
          de.l := de.l or 128;
          inc(result, 8);
        end;

      252:
        begin
          hl.h := hl.h or 128;
          inc(result, 8);
        end;

      253:
        begin
          hl.l := hl.l or 128;
          inc(result, 8);
        end;

      254:
        begin
          pokeb(FAddr, peekb(FAddr) or 128);
          inc(result, 15);
        end;

      255:
        begin
          af.h := af.h or 128;
          inc(result, 8);
        end;

    end;
end;

function TZ80CPU.Z80Instr_ED(const op: byte): integer;
var
  c_hl: byte;
  btemp: byte;
  temp: Word;
begin
  result := 0;
  with FRegister do
    case op of
      0 .. 63:
        begin
          inc(result, 8);
        end;
      64:
        begin
          bc.h := inB(bc.W); (* SZ-H-PNC *)
{$IFDEF OLD_IN}
          af.l := (bc.h and $A8) or (af.l and 1) or (PARITY[bc.h]);
          (* 10101000 *)
          if bc.h > 0 then
            af.l := af.l and 191 (* reset Zf *)
          else
            af.l := af.l or 64 (* set Zf *);
{$ELSE}
          af.l := in_table[bc.h] or (af.l and 1);
{$ENDIF}
          inc(result, 12);
        end;

      65:
        begin
          outb(bc.W, bc.h);
          inc(result, 12);
        end;

      66:
        begin
          sbc16(FRegister, hl.W, bc.W);
          inc(result, 15);
        end;

      67:
        begin
          pokew(peekw(pc.W), bc.W);
          inc(pc.W, 2);
          inc(result, 20);
        end;

      68:
        begin
          sub8(FRegister, 0, af.h);
          inc(result, 8);
        end;

      69:
        begin
          iff1 := iff2;
          pop(pc.W);
          inc(result, 14);
        end;

      70:
        begin
          im := 0;
          inc(result, 8);
        end;

      71:
        begin
          ir.h := af.h;
          inc(result, 9);
        end;

      72:
        begin
          bc.l := inB(bc.W); (* SZ-H-PNC *)
{$IFDEF OLD_IN}
          af.l := (bc.l and $A8) or (af.l and 1) or (PARITY[bc.l]);
          (* 10101000 *)
          if bc.l > 0 then
            af.l := af.l and 191 (* reset Zf *)
          else
            af.l := af.l or 64 (* set Zf *);
{$ELSE}
          af.l := in_table[bc.l] or (af.l and 1);
{$ENDIF}
          inc(result, 12);
        end;

      73:
        begin
          outb(bc.W, bc.l);
          inc(result, 12);
        end;

      74:
        begin
          adc16(FRegister, hl.W, bc.W);
          inc(result, 15);
        end;

      75:
        begin
          bc.W := peekw(peekw(pc.W));
          inc(pc.W, 2);
          inc(result, 20);
        end;

      76:
        begin
          inc(result, 8);
        end;

      77:
        begin
          pop(pc.W);
          inc(result, 14);
        end;

      78:
        begin
          inc(result, 8);
        end;

      79:
        begin
          ir.l := af.h and 127;
          bit7_r := af.h and 128;
          inc(result, 9);
        end;

      80:
        begin
          de.h := inB(bc.W); (* SZ-H-PNC *)
{$IFDEF OLD_IN}
          af.l := (de.h and $A8) or (af.l and 1) or (PARITY[de.h]);
          (* 10101000 *)
          if de.h > 0 then
            af.l := af.l and 191 (* reset Zf *)
          else
            af.l := af.l or 64 (* set Zf *);
{$ELSE}
          af.l := in_table[de.h] or (af.l and 1);
{$ENDIF}
          inc(result, 12);
        end;

      81:
        begin
          outb(bc.W, de.h);
          inc(result, 12);
        end;

      82:
        begin
          sbc16(FRegister, hl.W, de.W);
          inc(result, 15);
        end;

      83:
        begin
          pokew(peekw(pc.W), de.W);
          inc(pc.W, 2);
          inc(result, 20);
        end;

      84:
        begin
          inc(result, 8);
        end;

      85:
        begin
          inc(result, 8);
        end;

      86:
        begin
          im := 1;
          inc(result, 8);
        end;

      87:
        begin
          af.h := ir.h; (* SZ-H-PNC *)
          af.l := (af.h and $A8) or (af.l and 1); (* 10101000 *)
          if af.h > 0 then
            af.l := af.l and 191 (* reset Zf *)
          else
            af.l := af.l or 64 (* set Zf *);
          if iff2 > 0 then
            af.l := af.l or 4 (* set Pf *)
          else
            af.l := af.l and 251 (* reset Pf *);
          inc(result, 9);
        end;

      88:
        begin
          de.l := inB(bc.W); (* SZ-H-PNC *)
{$IFDEF OLD_IN}
          af.l := (de.l and $A8) or (af.l and 1) or (PARITY[de.l]);
          (* 10101000 *)
          if (de.l) > 0 then
            af.l := af.l and 191 (* reset Zf *)
          else
            af.l := af.l or 64 (* set Zf *);
{$ELSE}
          af.l := in_table[de.l] or (af.l and 1);
{$ENDIF}
          inc(result, 12);
        end;

      89:
        begin
          outb(bc.W, de.l);
          inc(result, 12);
        end;

      90:
        begin
          adc16(FRegister, hl.W, de.W);
          inc(result, 15);
        end;

      91:
        begin
          de.W := peekw(peekw(pc.W));
          inc(pc.W, 2);
          inc(result, 20);
        end;

      92:
        begin
          inc(result, 8);
        end;

      93:
        begin
          inc(result, 8);
        end;

      94:
        begin
          im := 2;
          inc(result, 8);
        end;

      95:
        begin
          af.h := bit7_r or (ir.l and 127); (* SZ-H-PNC *)
          af.l := (af.h and $A8) or (af.l and 1); (* 10101000 *)
          if (af.h) > 0 then
            af.l := af.l and 191 (* reset Zf *)
          else
            af.l := af.l or 64 (* set Zf *);
          if (iff2) > 0 then
            af.l := af.l or 4 (* set Pf *)
          else
            af.l := af.l and 251 (* reset Pf *);
          inc(result, 9);
        end;

      96:
        begin
          hl.h := inB(bc.W); (* SZ-H-PNC *)
{$IFDEF OLD_IN}
          af.l := (hl.h and $A8) or (af.l and 1) or (PARITY[hl.h]);
          (* 10101000 *)
          if (hl.h) > 0 then
            af.l := af.l and 191 (* reset Zf *)
          else
            af.l := af.l or 64 (* set Zf *);
{$ELSE}
          af.l := in_table[hl.h] or (af.l and 1);
{$ENDIF}
          inc(result, 12);
        end;

      97:
        begin
          outb(bc.W, hl.h);
          inc(result, 12);
        end;

      98:
        begin
          sbc16(FRegister, hl.W, hl.W);
          inc(result, 15);
        end;

      99:
        begin
          pokew(peekw(pc.W), hl.W);
          inc(pc.W, 2);
          inc(result, 20);
        end;

      100:
        begin
          inc(result, 8);
        end;

      101:
        begin
          inc(result, 8);
        end;

      102:
        begin
          inc(result, 8);
        end;

      103:
        begin
          c_hl := peekb(hl.W);
          pokeb(hl.W, (c_hl shr 4) or (af.h shl 4));
          af.h := (c_hl and $0F) or (af.h and $F0);

          af.l := (af.h and 190) or (af.l and 1); (* Keep Cf and Set Zf to 0 *)
          if af.h = 0 then
            af.l := af.l or 64 (* set Zf *); (* And the Sign flag is used *)
          inc(result, 18);
        end;

      104:
        begin
          hl.l := inB(bc.W); (* SZ-H-PNC *)
{$IFDEF OLD_IN}
          af.l := (hl.l and $A8) or (af.l and 1) or (PARITY[hl.l]);
          (* 10101000 *)
          if (hl.l) > 0 then
            af.l := af.l and 191 (* reset Zf *)
          else
            af.l := af.l or 64 (* set Zf *);
{$ELSE}
          af.l := in_table[hl.l] or (af.l and 1);
{$ENDIF}
          inc(result, 12);
        end;

      105:
        begin
          outb(bc.W, hl.l);
          inc(result, 12);
        end;

      106:
        begin
          adc16(FRegister, hl.W, hl.W);
          inc(result, 15);
        end;

      107:
        begin
          hl.W := peekw(peekw(pc.W));
          inc(pc.W, 2);
          inc(result, 20);
        end;

      108:
        begin
          inc(result, 8);
        end;

      109:
        begin
          inc(result, 8);
        end;

      110:
        begin
          inc(result, 8);
        end;

      111:
        begin
          c_hl := peekb(hl.W);
          pokeb(hl.W, (c_hl shl 4) or (af.h and $0F));
          af.h := (c_hl shr 4) or (af.h and $F0);

          af.l := (af.h and 190) or (af.l and 1); (* Keep Cf and Set Zf to 0 *)
          if af.h = 0 then
            af.l := af.l or 64 (* set Zf *); (* And the Sign flag is used *)
          inc(result, 18);
        end;

      112:
        begin
          af.l := inB(bc.W);
{$IFDEF OLD_IN}
          if (af.l) > 0 then
            af.l := af.l and 191 (* reset Zf *)
          else
            af.l := af.l or 64 (* set Zf *); (* SZ-H-PNC *)
          af.l := (af.l and $E9) or (PARITY[af.l]); (* 11101001 *)
{$ELSE}
          af.l := in_table[af.l] or (af.l and 1);
{$ENDIF}
          inc(result, 12);
        end;

      113:
        begin
          outb(bc.W, 0);
          inc(result, 12);
        end;

      114:
        begin
          sbc16(FRegister, hl.W, sp.W);
          inc(result, 15);
        end;

      115:
        begin
          pokew(peekw(pc.W), sp.W);
          inc(pc.W, 2);
          inc(result, 20);
        end;

      116:
        begin
          inc(result, 8);
        end;

      117:
        begin
          inc(result, 8);
        end;

      118:
        begin
          inc(result, 8);
        end;

      119:
        begin
          inc(result, 8);
        end;

      120:
        begin
          af.h := inB(bc.W); (* SZ-H-PNC *)
{$IFDEF OLD_IN}
          af.l := (af.h and $A8) or (af.l and 1) or (PARITY[af.h]);
          (* 10101000 *)
          if (af.h) > 0 then
            af.l := af.l and 191 (* reset Zf *)
          else
            af.l := af.l or 64 (* set Zf *);
{$ELSE}
          af.l := in_table[af.h] or (af.l and 1);
{$ENDIF}
          inc(result, 12);
        end;

      121:
        begin
          outb(bc.W, af.h);
          inc(result, 12);
        end;

      122:
        begin
          adc16(FRegister, hl.W, sp.W);
          inc(result, 15);
        end;

      123:
        begin
          sp.W := peekw(peekw(pc.W));
          inc(pc.W, 2);
          inc(result, 20);
        end;

      124:
        begin
          inc(result, 8);
        end;

      125:
        begin
          inc(result, 8);
        end;

      126:
        begin
          inc(result, 8);
        end;

      127:
        begin
          inc(result, 8);
        end;

      128:
        begin
          inc(result, 8);
        end;

      129:
        begin
          inc(result, 8);
        end;

      130:
        begin
          inc(result, 8);
        end;

      131:
        begin
          inc(result, 8);
        end;

      132:
        begin
          inc(result, 8);
        end;

      133:
        begin
          inc(result, 8);
        end;

      134:
        begin
          inc(result, 8);
        end;

      135:
        begin
          inc(result, 8);
        end;

      136:
        begin
          inc(result, 8);
        end;

      137:
        begin
          inc(result, 8);
        end;

      138:
        begin
          inc(result, 8);
        end;

      139:
        begin
          inc(result, 8);
        end;

      140:
        begin
          inc(result, 8);
        end;

      141:
        begin
          inc(result, 8);
        end;

      142:
        begin
          inc(result, 8);
        end;

      143:
        begin
          inc(result, 8);
        end;

      144:
        begin
          inc(result, 8);
        end;

      145:
        begin
          inc(result, 8);
        end;

      146:
        begin
          inc(result, 8);
        end;

      147:
        begin
          inc(result, 8);
        end;

      148:
        begin
          inc(result, 8);
        end;

      149:
        begin
          inc(result, 8);
        end;

      150:
        begin
          inc(result, 8);
        end;

      151:
        begin
          inc(result, 8);
        end;

      152:
        begin
          inc(result, 8);
        end;

      153:
        begin
          inc(result, 8);
        end;

      154:
        begin
          inc(result, 8);
        end;

      155:
        begin
          inc(result, 8);
        end;

      156:
        begin
          inc(result, 8);
        end;

      157:
        begin
          inc(result, 8);
        end;

      158:
        begin
          inc(result, 8);
        end;

      159:
        begin
          inc(result, 8);
        end;

      160:
        begin
          pokeb(de.W, peekb(hl.W));
          inc(de.W);
          inc(hl.W);
          dec(bc.W);
          af.l := af.l or 4 (* set Pf *);
          if bc.W = 0 then
            af.l := af.l and 233 (* reset Nf,Hf,Pf *)
          else
            af.l := af.l and 237; (* reset Nf,Hf *)
          inc(result, 16);
        end;

      161:
        begin
          btemp := af.l and 1;
          cp_sub8(FRegister, peekb(hl.W), af.h); (* Keep Cf *)
          af.l := (af.l and 254) or btemp;
          inc(hl.W);
          dec(bc.W);
          if bc.W = 0 then
            af.l := af.l and 251 (* reset Pf *)
          else
            af.l := af.l or 4 (* set Pf *);
          inc(result, 16);
        end;

      162:
        begin
          pokeb(hl.W, inB(bc.W));
          inc(hl.W);
          dec(bc.h);
          if bc.h = 0 then
            af.l := af.l or 64 (* set Zf *)
          else
            af.l := af.l and 191 (* reset Zf *);
          af.l := af.l or 2 (* set Nf *);
          inc(result, 16);
        end;

      163:
        begin
          dec(bc.h); (* Pre-decremented according to some *)
          outb(bc.W, peekb(hl.W));
          inc(hl.W);
          if bc.h = 0 then
            af.l := af.l or 64 (* set Zf *)
          else
            af.l := af.l and 191 (* reset Zf *);
          af.l := af.l or 2 (* set Nf *);
          inc(result, 16);
        end;

      164:
        begin
          inc(result, 8);
        end;

      165:
        begin
          inc(result, 8);
        end;

      166:
        begin
          inc(result, 8);
        end;

      167:
        begin
          inc(result, 8);
        end;

      168:
        begin
          pokeb(de.W, peekb(hl.W));
          dec(de.W);
          dec(hl.W);
          dec(bc.W);
          af.l := af.l or 4 (* set Pf *);
          if bc.W = 0 then
            af.l := af.l and 233 (* reset Nf,Hf,Pf *)
          else
            af.l := af.l and 237; (* reset Nf,Hf *)
          inc(result, 16);
        end;

      169:
        begin
          btemp := af.l and 1;
          cp_sub8(FRegister, peekb(hl.W), af.h); (* Keep Cf *)
          af.l := (af.l and 254) or btemp;
          dec(hl.W);
          dec(bc.W);
          if bc.W = 0 then
            af.l := af.l and 251 (* reset Pf *)
          else
            af.l := af.l or 4 (* set Pf *);
          inc(result, 16);
        end;

      170:
        begin
          pokeb(hl.W, inB(bc.W));
          dec(hl.W);
          dec(bc.h);
          if bc.h = 0 then
            af.l := af.l or 64 (* set Zf *)
          else
            af.l := af.l and 191 (* reset Zf *);
          af.l := af.l or 2 (* set Nf *);
          inc(result, 16);
        end;

      171:
        begin
          dec(bc.h); (* Pre-decremented according to some *)
          outb(bc.W, peekb(hl.W));
          dec(hl.W);
          if bc.h = 0 then
            af.l := af.l or 64 (* set Zf *)
          else
            af.l := af.l and 191 (* reset Zf *);
          af.l := af.l or 2 (* set Nf *);
          inc(result, 16);
        end;

      172:
        begin
          inc(result, 8);
        end;

      173:
        begin
          inc(result, 8);
        end;

      174:
        begin
          inc(result, 8);
        end;

      175:
        begin
          inc(result, 8);
        end;

      176:
        begin
          pokeb(de.W, peekb(hl.W));
          inc(de.W);
          inc(hl.W);
          dec(bc.W);
          af.l := af.l or 4 (* set Pf *);
          if bc.W = 0 then
          begin
            af.l := af.l and 233; (* reset Nf,Hf,Pf *)
            inc(result, 16);
          end
          else
          begin
            af.l := af.l and 237; (* reset Nf,Hf *)
            inc(result, 21);
            dec(pc.W, 2);
          end;
        end;

      177:
        begin
          btemp := af.l and 1;
          cp_sub8(FRegister, peekb(hl.W), af.h); (* Keep Cf *)
          af.l := (af.l and 254) or btemp;
          inc(hl.W);
          dec(bc.W);
          if bc.W = 0 then
          begin
            af.l := af.l and 251 (* reset Pf *);
            inc(result, 16); (* Hmmm *)
            exit; (* Hmmm *)
          end
          else
            af.l := af.l or 4 (* set Pf *);
          if af.l and 64 > 0 then (* Zf:=1 *)
            inc(result, 16)
          else
          begin
            inc(result, 21);
            dec(pc.W, 2);
          end;
        end;

      178:
        begin
          pokeb(hl.W, inB(bc.W));
          inc(hl.W);
          af.l := af.l or 2 (* set Nf *);
          dec(bc.h);
          if bc.h = 0 then
          begin
            af.l := af.l or 64 (* set Zf *);
            inc(result, 16);
          end
          else
          begin
            af.l := af.l and 191 (* reset Zf *);
            inc(result, 21);
            dec(pc.W, 2);
          end;
        end;

      179:
        begin
          dec(bc.h); (* Pre-decremented according to some *)
          outb(bc.W, peekb(hl.W));
          inc(hl.W);
          af.l := af.l or 2 (* set Nf *);
          if bc.h = 0 then
          begin
            af.l := af.l or 64 (* set Zf *);
            inc(result, 16);
          end
          else
          begin
            af.l := af.l and 191 (* reset Zf *);
            inc(result, 21);
            dec(pc.W, 2);
          end;
        end;

      180:
        begin
          inc(result, 8);
        end;

      181:
        begin
          inc(result, 8);
        end;

      182:
        begin
          inc(result, 8);
        end;

      183:
        begin
          inc(result, 8);
        end;

      184:
        begin
          pokeb(de.W, peekb(hl.W));
          dec(de.W);
          dec(hl.W);
          dec(bc.W);
          af.l := af.l or 4 (* set Pf *);
          if bc.W = 0 then
          begin
            af.l := af.l and 233; (* reset Nf,Hf,Pf *)
            inc(result, 16);
          end
          else
          begin
            af.l := af.l and 237; (* reset Nf,Hf *)
            inc(result, 21);
            dec(pc.W, 2);
          end;
        end;

      185:
        begin
          btemp := af.l and 1;
          cp_sub8(FRegister, peekb(hl.W), af.h); (* Keep Cf *)
          af.l := (af.l and 254) or btemp;
          dec(hl.W);
          dec(bc.W);
          if bc.W = 0 then
          begin
            af.l := af.l and 251 (* reset Pf *);
            inc(result, 16);
            exit;
          end
          else
            af.l := af.l or 4 (* set Pf *);

          if (af.l and 64) > 0 then (* Zf:=1 *)
            inc(result, 16)
          else
          begin
            inc(result, 21);
            dec(pc.W, 2);
          end;
        end;

      186:
        begin
          pokeb(hl.W, inB(bc.W));
          dec(hl.W);
          af.l := af.l or 2 (* set Nf *);
          dec(bc.h);
          if bc.h = 0 then
          begin
            af.l := af.l or 64 (* set Zf *);
            inc(result, 16);
          end
          else
          begin
            af.l := af.l and 191 (* reset Zf *);
            inc(result, 21);
            dec(pc.W, 2);
          end;
        end;

      187:
        begin
          dec(bc.h); (* Pre-decremented according to some *)
          outb(bc.W, peekb(hl.W));
          dec(hl.W);
          af.l := af.l or 2 (* set Nf *);
          if bc.h = 0 then
          begin
            af.l := af.l or 64 (* set Zf *);
            inc(result, 16);
          end
          else
          begin
            af.l := af.l and 191 (* reset Zf *);
            inc(result, 21);
            dec(pc.W, 2);
          end;
        end;

      188 .. 255:
        begin
          inc(result, 8);
        end;
    end;
end;

function TZ80CPU.inB(const Addr: Word): byte;
begin
  if assigned(FHardware) then
    FHardware.InByte(Addr, result)
  else
    result := 0;
end;

procedure TZ80CPU.outb(const Addr: Word; const Value: byte);
begin
  if assigned(FHardware) then
    FHardware.OutByte(Addr, Value);
end;

function TZ80CPU.peekb(const Addr: integer): byte;
begin
  if assigned(FHardware) then
    FHardware.PeekByte(Addr, result)
  else
    result := 0;
end;

function TZ80CPU.peekw(const Addr: Word): Word;
begin
  peekw := (peekb(Addr + 1) shl 8) or peekb(Addr);
end;

procedure TZ80CPU.pokeb(const Addr: integer; const val: byte);
begin
  if assigned(FHardware) then
    FHardware.PokeByte(Addr, val);
end;

procedure TZ80CPU.pokew(const Addr: integer; const val: Word);
var
  Value: TPair absolute val;
begin
  pokeb(Addr, Value.l);
  pokeb(Addr + 1, Value.h);
end;

procedure TZ80CPU.pop(out wpval: Word);
begin
  with FRegister do
  begin
    wpval := peekw(sp.W);
    inc(sp.W, 2);
  end;
end;

procedure TZ80CPU.push(const wpval: Word);
begin
  with FRegister do
  begin
    dec(sp.W, 2);
    pokew(sp.W, wpval);
  end;
end;

function TZ80CPU.Z80Instr_IX(const op: byte): integer;
var
  btemp: byte;
  temp: Word;
  daa_select: byte;
  dis: shortint;
  b: byte;
  cbdis: shortint;

begin
  result := 0;
  with FRegister do
    case op of
      0:
        begin
          inc(result, 4);
        end;

      1:
        begin
          bc.W := peekw(pc.W);
          inc(pc.W, 2);
          inc(result, 10);
        end;

      2:
        begin
          pokeb(bc.W, af.h);
          inc(result, 7);
        end;

      3:
        begin
          inc(bc.W);
          inc(result, 6);
        end;

      4:
        begin
          af.l := INC_F[bc.h] or (af.l and 1);
          inc(bc.h);
          inc(result, 4);
        end;

      5:
        begin
          af.l := DEC_F[bc.h] or (af.l and 1);
          dec(bc.h);
          inc(result, 4);
        end;

      6:
        begin
          bc.h := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      7:
        begin
          btemp := af.l and 1;
          af.l := RLCA_F[btemp][af.h] or (af.l and 196);
          af.h := RLCA_A[btemp][af.h];
          inc(result, 4);
        end;

      8:
        begin
          temp := af.W;
          af.W := af2.W;
          af2.W := temp;
          inc(result, 4);
        end;

      9:
        begin
          add16(FRegister, ix.W, bc.W);
          inc(result, 11);
        end;

      10:
        begin
          af.h := peekb(bc.W);
          inc(result, 7);
        end;

      11:
        begin
          dec(bc.W);
          inc(result, 6);
        end;

      12:
        begin
          af.l := INC_F[bc.l] or (af.l and 1);
          inc(bc.l);
          inc(result, 4);
        end;

      13:
        begin
          af.l := DEC_F[bc.l] or (af.l and 1);
          dec(bc.l);
          inc(result, 4);
        end;

      14:
        begin
          bc.l := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      15:

        begin
          btemp := af.l and 1;
          af.l := RRCA_F[btemp][af.h] or (af.l and 196);
          af.h := RRCA_A[btemp][af.h];
          inc(result, 4);
        end;

      16:
        begin
          dec(bc.h);
          if bc.h > 0 then
          begin
            pc.W := pc.W + shortint(peekb(pc.W)) + 1;
            inc(result, 13);
          end
          else
          begin
            inc(pc.W);
            inc(result, 8);
          end
        end;

      17:
        begin
          de.W := peekw(pc.W);
          inc(pc.W, 2);
          inc(result, 10);
        end;

      18:
        begin
          pokeb(de.W, af.h);
          inc(result, 7);
        end;

      19:
        begin
          inc(de.W);
          inc(result, 6);
        end;

      20:
        begin
          af.l := INC_F[de.h] or (af.l and 1);
          inc(de.h);
          inc(result, 4);
        end;

      21:
        begin
          af.l := DEC_F[de.h] or (af.l and 1);
          dec(de.h);
          inc(result, 4);
        end;

      22:
        begin
          de.h := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      23:

        begin
          btemp := af.l and 1;
          af.l := RLA_F[btemp][af.h] or (af.l and 196);
          af.h := RLA_A[btemp][af.h];
          inc(result, 4);
        end;

      24:
        begin
          pc.W := pc.W + shortint(peekb(pc.W)) + 1;
          inc(result, 12);
        end;

      25:
        begin
          add16(FRegister, ix.W, de.W);
          inc(result, 11);
        end;

      26:
        begin
          af.h := peekb(de.W);
          inc(result, 7);
        end;

      27:
        begin
          dec(de.W);
          inc(result, 6);
        end;

      28:
        begin
          af.l := INC_F[de.l] or (af.l and 1);
          inc(de.l);
          inc(result, 4);
        end;

      29:
        begin
          af.l := DEC_F[de.l] or (af.l and 1);
          dec(de.l);
          inc(result, 4);
        end;

      30:
        begin
          de.l := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      31:
        begin
          if af.l and 1 = 0 then
          begin
            af.l := RRA_F[af.h] or (af.l and 196);
            af.h := RRA_A[0][af.h];
          end
          else
          begin
            af.l := RRA_F[af.h] or (af.l and 196);
            af.h := RRA_A[1][af.h];
          end;
          inc(result, 4);
        end;

      32:
        begin
          if af.l and 64 = 0 then
          begin
            pc.W := pc.W + shortint(peekb(pc.W)) + 1;
            inc(result, 12);
          end
          else
          begin
            inc(pc.W);
            inc(result, 7);
          end
        end;

      33:
        begin
          ix.W := peekw(pc.W);
          inc(pc.W, 2);
          inc(result, 10);
        end;

      34:
        begin
          pokew(peekw(pc.W), ix.W);
          inc(pc.W, 2);
          inc(result, 16);
        end;

      35:
        begin
          inc(ix.W);
          inc(result, 6);
        end;

      36:
        begin
          af.l := INC_F[ix.h] or (af.l and 1);
          inc(ix.h);
          inc(result, 4);
        end;

      37:
        begin
          af.l := DEC_F[ix.h] or (af.l and 1);
          dec(ix.h);
          inc(result, 4);
        end;

      38:
        begin
          ix.h := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      39:
        begin
          daa_select := af.l and 19;
          if daa_select and 16 > 0 then
          begin
            af.l := DAA_F[daa_select - 12][af.h];
            af.h := DAA_A[daa_select - 12][af.h];
          end
          else
          begin
            af.l := DAA_F[daa_select][af.h];
            af.h := DAA_A[daa_select][af.h];
          end;
          inc(result, 4);
        end;

      40:
        begin
          if af.l and 64 > 0 then
          begin
            pc.W := pc.W + shortint(peekb(pc.W)) + 1;
            inc(result, 12);
          end
          else
          begin
            inc(pc.W);
            inc(result, 7);
          end
        end;

      41:
        begin
          add16(FRegister, ix.W, ix.W);
          inc(result, 11);
        end;

      42:
        begin
          ix.W := peekw(peekw(pc.W));
          inc(pc.W, 2);
          inc(result, 16);
        end;

      43:
        begin
          dec(ix.W);
          inc(result, 6);
        end;

      44:
        begin
          af.l := INC_F[ix.l] or (af.l and 1);
          inc(ix.l);
          inc(result, 4);
        end;

      45:
        begin
          af.l := DEC_F[ix.l] or (af.l and 1);
          dec(ix.l);
          inc(result, 4);
        end;

      46:
        begin
          ix.l := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      47:
        begin
          af.h := af.h xor 255;
          af.l := af.l or 18;
          copy_b53(FRegister, af.h);
          inc(result, 4);
        end;

      48:
        begin
          if af.l and 1 = 0 then
          begin
            pc.W := pc.W + shortint(peekb(pc.W)) + 1;
            inc(result, 12);
          end
          else
          begin
            inc(pc.W);
            inc(result, 7);
          end
        end;

      49:
        begin
          sp.W := peekw(pc.W);
          inc(pc.W, 2);
          inc(result, 10);
        end;

      50:
        begin
          pokeb(peekw(pc.W), af.h);
          inc(pc.W, 2);
          inc(result, 13);
        end;

      51:
        begin
          inc(sp.W);
          inc(result, 6);
        end;

      52:

        begin
          dis := peekb(pc.W);
          inc(pc.W);
          btemp := peekb(ix.W + dis);
          af.l := INC_F[btemp] or (af.l and 1);
          pokeb(ix.W + dis, btemp + 1);
          inc(result, 19);
        end;

      53:
        begin
          dis := peekb(pc.W);
          inc(pc.W);
          btemp := peekb(ix.W + dis);
          af.l := DEC_F[btemp] or (af.l and 1);
          pokeb(ix.W + dis, btemp - 1);
          inc(result, 19);
        end;

      54:
        begin
          dis := peekb(pc.W);
          inc(pc.W);
          pokeb(ix.W + dis, peekb(pc.W));
          inc(pc.W);
          inc(result, 15);
        end;

      55:
        begin
          af.l := af.l and 237;
          copy_b53(FRegister, af.h);
          af.l := af.l or 1;
          inc(result, 4);
        end;

      56:
        begin
          if af.l and 1 > 0 then
          begin
            pc.W := pc.W + shortint(peekb(pc.W)) + 1;
            inc(result, 12);
          end
          else
          begin
            inc(pc.W);
            inc(result, 7);
          end
        end;

      57:
        begin
          add16(FRegister, ix.W, sp.W);
          inc(result, 11);
        end;

      58:
        begin
          af.h := peekb(peekw(pc.W));
          inc(pc.W, 2);
          inc(result, 13);
        end;

      59:
        begin
          dec(sp.W);
          inc(result, 6);
        end;

      60:
        begin
          af.l := INC_F[af.h] or (af.l and 1);
          inc(af.h);
          inc(result, 4);
        end;

      61:
        begin
          af.l := DEC_F[af.h] or (af.l and 1);
          dec(af.h);
          inc(result, 4);
        end;

      62:
        begin
          af.h := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      63:
        begin
          af.l := af.l xor 1;
          af.l := af.l and 253;
          copy_b53(FRegister, af.h);
          inc(result, 4);
        end;

      64:
        begin
          bc.h := bc.h;
          inc(result, 4);
        end;

      65:
        begin
          bc.h := bc.l;
          inc(result, 4);
        end;

      66:
        begin
          bc.h := de.h;
          inc(result, 4);
        end;

      67:
        begin
          bc.h := de.l;
          inc(result, 4);
        end;

      68:
        begin
          bc.h := ix.h;
          inc(result, 4);
        end;

      69:
        begin
          bc.h := ix.l;
          inc(result, 4);
        end;

      70:
        begin
          bc.h := peekb(ix.W + shortint(peekb(pc.W)));
          inc(pc.W);
          inc(result, 15);
        end;

      71:
        begin
          bc.h := af.h;
          inc(result, 4);
        end;

      72:
        begin
          bc.l := bc.h;
          inc(result, 4);
        end;

      73:
        begin
          bc.l := bc.l;
          inc(result, 4);
        end;

      74:
        begin
          bc.l := de.h;
          inc(result, 4);
        end;

      75:
        begin
          bc.l := de.l;
          inc(result, 4);
        end;

      76:
        begin
          bc.l := ix.h;
          inc(result, 4);
        end;

      77:
        begin
          bc.l := ix.l;
          inc(result, 4);
        end;

      78:
        begin
          bc.l := peekb(ix.W + shortint(peekb(pc.W)));
          inc(pc.W);
          inc(result, 15);
        end;

      79:
        begin
          bc.l := af.h;
          inc(result, 4);
        end;

      80:
        begin
          de.h := bc.h;
          inc(result, 4);
        end;

      81:
        begin
          de.h := bc.l;
          inc(result, 4);
        end;

      82:
        begin
          de.h := de.h;
          inc(result, 4);
        end;

      83:
        begin
          de.h := de.l;
          inc(result, 4);
        end;

      84:
        begin
          de.h := ix.h;
          inc(result, 4);
        end;

      85:
        begin
          de.h := ix.l;
          inc(result, 4);
        end;

      86:
        begin
          de.h := peekb(ix.W + shortint(peekb(pc.W)));
          inc(pc.W);
          inc(result, 15);
        end;

      87:
        begin
          de.h := af.h;
          inc(result, 4);
        end;

      88:
        begin
          de.l := bc.h;
          inc(result, 4);
        end;

      89:
        begin
          de.l := bc.l;
          inc(result, 4);
        end;

      90:
        begin
          de.l := de.h;
          inc(result, 4);
        end;

      91:
        begin
          de.l := de.l;
          inc(result, 4);
        end;

      92:
        begin
          de.l := ix.h;
          inc(result, 4);
        end;

      93:
        begin
          de.l := ix.l;
          inc(result, 4);
        end;

      94:
        begin
          de.l := peekb(ix.W + shortint(peekb(pc.W)));
          inc(pc.W);
          inc(result, 15);
        end;

      95:
        begin
          de.l := af.h;
          inc(result, 4);
        end;

      96:
        begin
          ix.h := bc.h;
          inc(result, 4);
        end;

      97:
        begin
          ix.h := bc.l;
          inc(result, 4);
        end;

      98:
        begin
          ix.h := de.h;
          inc(result, 4);
        end;

      99:
        begin
          ix.h := de.l;
          inc(result, 4);
        end;

      100:
        begin
          ix.h := ix.h;
          inc(result, 4);
        end;

      101:
        begin
          ix.h := ix.l;
          inc(result, 4);
        end;

      102:
        begin
          hl.h := peekb(ix.W + shortint(peekb(pc.W)));
          inc(pc.W);
          inc(result, 15);
        end;

      103:
        begin
          ix.h := af.h;
          inc(result, 4);
        end;

      104:
        begin
          ix.l := bc.h;
          inc(result, 4);
        end;

      105:
        begin
          ix.l := bc.l;
          inc(result, 4);
        end;

      106:
        begin
          ix.l := de.h;
          inc(result, 4);
        end;

      107:
        begin
          ix.l := de.l;
          inc(result, 4);
        end;

      108:
        begin
          ix.l := ix.h;
          inc(result, 4);
        end;

      109:
        begin
          ix.l := ix.l;
          inc(result, 4);
        end;

      110:
        begin
          hl.l := peekb(ix.W + shortint(peekb(pc.W)));
          inc(pc.W);
          inc(result, 15);
        end;

      111:
        begin
          ix.l := af.h;
          inc(result, 4);
        end;

      112:
        begin
          pokeb(ix.W + shortint(peekb(pc.W)), bc.h);
          inc(pc.W);
          inc(result, 15);
        end;

      113:
        begin
          pokeb(ix.W + shortint(peekb(pc.W)), bc.l);
          inc(pc.W);
          inc(result, 15);
        end;

      114:
        begin
          pokeb(ix.W + shortint(peekb(pc.W)), de.h);
          inc(pc.W);
          inc(result, 15);
        end;

      115:
        begin
          pokeb(ix.W + shortint(peekb(pc.W)), de.l);
          inc(pc.W);
          inc(result, 15);
        end;

      116:
        begin
          pokeb(ix.W + shortint(peekb(pc.W)), hl.h);
          inc(pc.W);
          inc(result, 15);
        end;

      117:
        begin
          pokeb(ix.W + shortint(peekb(pc.W)), hl.l);
          inc(pc.W);
          inc(result, 15);
        end;

      118:
        begin
          dec(pc.W); // TODO: Dec
          halt := true;
          inc(result, 4);
        end;

      119:
        begin
          pokeb(ix.W + shortint(peekb(pc.W)), af.h);
          inc(pc.W);
          inc(result, 15);
        end;

      120:
        begin
          af.h := bc.h;
          inc(result, 4);
        end;

      121:
        begin
          af.h := bc.l;
          inc(result, 4);
        end;

      122:
        begin
          af.h := de.h;
          inc(result, 4);
        end;

      123:
        begin
          af.h := de.l;
          inc(result, 4);
        end;

      124:
        begin
          af.h := ix.h;
          inc(result, 4);
        end;

      125:
        begin
          af.h := ix.l;
          inc(result, 4);
        end;

      126:
        begin
          af.h := peekb(ix.W + shortint(peekb(pc.W)));
          inc(pc.W);
          inc(result, 15);
        end;

      127:
        begin
          af.h := af.h;
          inc(result, 4);
        end;

      128:
        begin
          add8(FRegister, af.h, bc.h);
          inc(result, 4);
        end;

      129:
        begin
          add8(FRegister, af.h, bc.l);
          inc(result, 4);
        end;

      130:
        begin
          add8(FRegister, af.h, de.h);
          inc(result, 4);
        end;

      131:
        begin
          add8(FRegister, af.h, de.l);
          inc(result, 4);
        end;

      132:
        begin
          add8(FRegister, af.h, ix.h);
          inc(result, 4);
        end;

      133:
        begin
          add8(FRegister, af.h, ix.l);
          inc(result, 4);
        end;

      134:
        begin
          add8(FRegister, af.h, peekb(ix.W + shortint(peekb(pc.W))));
          inc(pc.W);
          inc(result, 15);
        end;

      135:
        begin
          add8(FRegister, af.h, af.h);
          inc(result, 4);
        end;

      136:
        begin
          adc8(FRegister, af.h, bc.h);
          inc(result, 4);
        end;

      137:
        begin
          adc8(FRegister, af.h, bc.l);
          inc(result, 4);
        end;

      138:
        begin
          adc8(FRegister, af.h, de.h);
          inc(result, 4);
        end;

      139:
        begin
          adc8(FRegister, af.h, de.l);
          inc(result, 4);
        end;

      140:
        begin
          adc8(FRegister, af.h, ix.h);
          inc(result, 4);
        end;

      141:
        begin
          adc8(FRegister, af.h, ix.l);
          inc(result, 4);
        end;

      142:
        begin
          adc8(FRegister, af.h, peekb(ix.W + shortint(peekb(pc.W))));
          inc(pc.W);
          inc(result, 15);
        end;

      143:
        begin
          adc8(FRegister, af.h, af.h);
          inc(result, 4);
        end;

      144:
        begin
          sub8(FRegister, af.h, bc.h);
          inc(result, 4);
        end;

      145:
        begin
          sub8(FRegister, af.h, bc.l);
          inc(result, 4);
        end;

      146:
        begin
          sub8(FRegister, af.h, de.h);
          inc(result, 4);
        end;

      147:
        begin
          sub8(FRegister, af.h, de.l);
          inc(result, 4);
        end;

      148:
        begin
          sub8(FRegister, af.h, ix.h);
          inc(result, 4);
        end;

      149:
        begin
          sub8(FRegister, af.h, ix.l);
          inc(result, 4);
        end;

      150:
        begin
          sub8(FRegister, af.h, peekb(ix.W + shortint(peekb(pc.W))));
          inc(pc.W);
          inc(result, 15);
        end;

      151:
        begin
          sub8(FRegister, af.h, af.h);
          inc(result, 4);
        end;

      152:
        begin
          sbc8(FRegister, af.h, bc.h);
          inc(result, 4);
        end;

      153:
        begin
          sbc8(FRegister, af.h, bc.l);
          inc(result, 4);
        end;

      154:
        begin
          sbc8(FRegister, af.h, de.h);
          inc(result, 4);
        end;

      155:
        begin
          sbc8(FRegister, af.h, de.l);
          inc(result, 4);
        end;

      156:
        begin
          sbc8(FRegister, af.h, ix.h);
          inc(result, 4);
        end;

      157:
        begin
          sbc8(FRegister, af.h, ix.l);
          inc(result, 4);
        end;

      158:
        begin
          sbc8(FRegister, af.h, peekb(ix.W + shortint(peekb(pc.W))));
          inc(pc.W);
          inc(result, 15);
        end;

      159:
        begin
          sbc8(FRegister, af.h, af.h);
          inc(result, 4);
        end;

      160:
        begin
          anda(FRegister, bc.h);
          inc(result, 4);
        end;

      161:
        begin
          anda(FRegister, bc.l);
          inc(result, 4);
        end;

      162:
        begin
          anda(FRegister, de.h);
          inc(result, 4);
        end;

      163:
        begin
          anda(FRegister, de.l);
          inc(result, 4);
        end;

      164:
        begin
          anda(FRegister, ix.h);
          inc(result, 4);
        end;

      165:
        begin
          anda(FRegister, ix.l);
          inc(result, 4);
        end;

      166:
        begin
          anda(FRegister, peekb(ix.W + shortint(peekb(pc.W))));
          inc(pc.W);
          inc(result, 15);
        end;

      167:
        begin
          anda(FRegister, af.h);
          inc(result, 4);
        end;

      168:
        begin
          xora(FRegister, bc.h);
          inc(result, 4);
        end;

      169:
        begin
          xora(FRegister, bc.l);
          inc(result, 4);
        end;

      170:
        begin
          xora(FRegister, de.h);
          inc(result, 4);
        end;

      171:
        begin
          xora(FRegister, de.l);
          inc(result, 4);
        end;

      172:
        begin
          xora(FRegister, ix.h);
          inc(result, 4);
        end;

      173:
        begin
          xora(FRegister, ix.l);
          inc(result, 4);
        end;

      174:
        begin
          xora(FRegister, peekb(ix.W + shortint(peekb(pc.W))));
          inc(pc.W);
          inc(result, 15);
        end;

      175:
        begin
          xora(FRegister, af.h);
          inc(result, 4);
        end;

      176:
        begin
          ora(FRegister, bc.h);
          inc(result, 4);
        end;

      177:
        begin
          ora(FRegister, bc.l);
          inc(result, 4);
        end;

      178:
        begin
          ora(FRegister, de.h);
          inc(result, 4);
        end;

      179:
        begin
          ora(FRegister, de.l);
          inc(result, 4);
        end;

      180:
        begin
          ora(FRegister, ix.h);
          inc(result, 4);
        end;

      181:
        begin
          ora(FRegister, ix.l);
          inc(result, 4);
        end;

      182:
        begin
          ora(FRegister, peekb(ix.W + shortint(peekb(pc.W))));
          inc(pc.W);
          inc(result, 15);
        end;

      183:
        begin
          ora(FRegister, af.h);
          inc(result, 4);
        end;

      184:
        begin
          cp_sub8(FRegister, af.h, bc.h);
          inc(result, 4);
        end;

      185:
        begin
          cp_sub8(FRegister, af.h, bc.l);
          inc(result, 4);
        end;

      186:
        begin
          cp_sub8(FRegister, af.h, de.h);
          inc(result, 4);
        end;

      187:
        begin
          cp_sub8(FRegister, af.h, de.l);
          inc(result, 4);
        end;

      188:
        begin
          cp_sub8(FRegister, af.h, ix.h);
          inc(result, 4);
        end;

      189:
        begin
          cp_sub8(FRegister, af.h, ix.l);
          inc(result, 4);
        end;

      190:
        begin
          cp_sub8(FRegister, af.h, peekb(ix.W + shortint(peekb(pc.W))));
          inc(pc.W);
          inc(result, 15);
        end;

      191:
        begin
          cp_sub8(FRegister, af.h, af.h);
          inc(result, 4);
        end;

      192:
        begin
          if af.l and 64 = 0 then
          begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      193:
        begin
          pop(bc.W);
          inc(result, 10);
        end;

      194:
        begin
          if af.l and 64 = 0 then
          begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      195:
        begin
          pc.W := peekw(pc.W);
          inc(result, 10);
        end;

      196:
        begin
          if af.l and 64 = 0 then
          begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      197:
        begin
          push(bc.W);
          inc(result, 11);
        end;

      198:
        begin
          add8(FRegister, af.h, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      199:
        begin
          push(pc.W);
          pc.W := 0;
          inc(result, 11);
        end;

      200:
        begin
          if af.l and 64 > 0 then
          begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      201:
        begin
          pop(pc.W);
          inc(result, 10);
        end;

      202:
        begin
          if af.l and 64 > 0 then
          begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      203:
        begin
          cbdis := peekb(pc.W);
          inc(pc.W);
          b := peekb(pc.W);
          inc(pc.W);
          FAddr := ix.W + cbdis;
          inc(result, Z80Instr_CB(b) + 8);
        end;

      204:
        begin
          if af.l and 64 > 0 then
          begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      205:
        begin
          push(pc.W + 2);
          pc.W := peekw(pc.W);
          inc(result, 17);
        end;

      206:
        begin
          adc8(FRegister, af.h, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      207:
        begin
          push(pc.W);
          pc.W := 8;
          inc(result, 11);
        end;

      208:
        begin
          if af.l and 1 = 0 then
          begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      209:
        begin
          pop(de.W);
          inc(result, 10);
        end;

      210:
        begin
          if af.l and 1 = 0 then
          begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      211:
        begin
          outb(Word(af.h shl 8) or peekb(pc.W), af.h);
          inc(pc.W);
          inc(result, 11);
        end;

      212:
        begin
          if af.l and 1 = 0 then
          begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      213:
        begin
          push(de.W);
          inc(result, 11);
        end;

      214:
        begin
          sub8(FRegister, af.h, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      215:
        begin
          push(pc.W);
          pc.W := 16;
          inc(result, 11);
        end;

      216:
        begin
          if af.l and 1 > 0 then
          begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      217:
        begin
          { temp:=af.W;af.W:=af2.W;af2.W:=temp; }
          temp := bc.W;
          bc.W := bc2.W;
          bc2.W := temp;
          temp := de.W;
          de.W := de2.W;
          de2.W := temp;
          temp := hl.W;
          hl.W := hl2.W;
          hl2.W := temp;
          inc(result, 4);
        end;

      218:
        begin
          if af.l and 1 > 0 then
          begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      219:
        begin
          af.h := inB(af.h shl 8 + peekb(pc.W));
          inc(pc.W);
          inc(result, 11);
        end;

      220:
        begin
          if af.l and 1 > 0 then
          begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      221:
        begin
          inc(ir.l);
          b := peekb(pc.W);
          inc(pc.W);
          inc(result, Z80Instr_IX(b));
        end;

      222:
        begin
          sbc8(FRegister, af.h, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      223:
        begin
          push(pc.W);
          pc.W := 24;
          inc(result, 11);
        end;

      224:
        begin
          if af.l and 4 = 0 then
          begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      225:
        begin
          pop(ix.W);
          inc(result, 10);
        end;

      226:
        begin
          if af.l and 4 = 0 then
          begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      227:
        begin
          temp := peekw(sp.W);
          pokew(sp.W, ix.W);
          ix.W := temp;
          inc(result, 19);
        end;

      228:
        begin
          if af.l and 4 = 0 then
          begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      229:
        begin
          push(ix.W);
          inc(result, 11);
        end;

      230:
        begin
          anda(FRegister, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      231:
        begin
          push(pc.W);
          pc.W := 32;
          inc(result, 11);
        end;

      232:
        begin
          if af.l and 4 > 0 then
          begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      233:
        begin
          pc.W := ix.W;
          inc(result, 4);
        end;

      234:
        begin
          if af.l and 4 > 0 then
          begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      235:
        begin
          temp := de.W;
          de.W := ix.W;
          ix.W := temp;
          inc(result, 4);
        end;

      236:
        begin
          if af.l and 4 > 0 then
          begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      237:
        begin
          inc(ir.l);
          b := peekb(pc.W);
          inc(pc.W);
          inc(result, Z80Instr_ED(b));
        end;

      238:
        begin
          xora(FRegister, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      239:
        begin
          push(pc.W);
          pc.W := 40;
          inc(result, 11);
        end;

      240:
        begin
          if af.l and 128 = 0 then
          begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      241:
        begin
          pop(af.W);
          inc(result, 10);
        end;

      242:
        begin
          if af.l and 128 = 0 then
          begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      243:
        begin
          iff1 := 0;
          iff2 := 0;
          inc(result, 4);
        end;

      244:
        begin
          if af.l and 128 = 0 then
          begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      245:
        begin
          push(af.W);
          inc(result, 11);
        end;

      246:
        begin
          ora(FRegister, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      247:
        begin
          push(pc.W);
          pc.W := 48;
          inc(result, 11);
        end;

      248:
        begin
          if af.l and 128 > 0 then
          begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      249:
        begin
          sp.W := ix.W;
          inc(result, 6);
        end;

      250:
        begin
          if af.l and 128 > 0 then
          begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      251:
        begin
          iff1 := 1;
          iff2 := 1;
          inc(result, 4);
        end;

      252:
        begin
          if af.l and 128 > 0 then
          begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      253:
        begin
          inc(ir.l);
          b := peekb(pc.W);
          inc(pc.W);
          inc(result, Z80Instr_IY(b));
        end;

      254:
        begin
          cp_sub8(FRegister, af.h, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      255:
        begin
          push(pc.W);
          pc.W := 56;
          inc(result, 11);
        end;

    end;
end;

function TZ80CPU.Z80Instr_IY(const op: byte): integer;
var
  btemp: byte;
  temp: Word;
  daa_select: byte;
  dis: shortint;
  b: byte;
  cbdis: shortint;

begin
  result := 0;
  with FRegister do
    case op of
      0:
        begin
          inc(result, 4);
        end;

      1:
        begin
          bc.W := peekw(pc.W);
          inc(pc.W, 2);
          inc(result, 10);
        end;

      2:
        begin
          pokeb(bc.W, af.h);
          inc(result, 7);
        end;

      3:
        begin
          inc(bc.W);
          inc(result, 6);
        end;

      4:
        begin
          af.l := INC_F[bc.h] or (af.l and 1);
          inc(bc.h);
          inc(result, 4);
        end;

      5:
        begin
          af.l := DEC_F[bc.h] or (af.l and 1);
          dec(bc.h);
          inc(result, 4);
        end;

      6:
        begin
          bc.h := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      7:
        begin
          btemp := af.l and 1;
          af.l := RLCA_F[btemp][af.h] or (af.l and 196);
          af.h := RLCA_A[btemp][af.h];
          inc(result, 4);
        end;

      8:
        begin
          temp := af.W;
          af.W := af2.W;
          af2.W := temp;
          inc(result, 4);
        end;

      9:
        begin
          add16(FRegister, iy.W, bc.W);
          inc(result, 11);
        end;

      10:
        begin
          af.h := peekb(bc.W);
          inc(result, 7);
        end;

      11:
        begin
          dec(bc.W);
          inc(result, 6);
        end;

      12:
        begin
          af.l := INC_F[bc.l] or (af.l and 1);
          inc(bc.l);
          inc(result, 4);
        end;

      13:
        begin
          af.l := DEC_F[bc.l] or (af.l and 1);
          dec(bc.l);
          inc(result, 4);
        end;

      14:
        begin
          bc.l := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      15:

        begin
          btemp := af.l and 1;
          af.l := RRCA_F[btemp][af.h] or (af.l and 196);
          af.h := RRCA_A[btemp][af.h];
          inc(result, 4);
        end;

      16:
        begin
          dec(bc.h);
          if bc.h > 0 then
          begin
            pc.W := pc.W + shortint(peekb(pc.W)) + 1;
            inc(result, 13);
          end
          else
          begin
            inc(pc.W);
            inc(result, 8);
          end
        end;

      17:
        begin
          de.W := peekw(pc.W);
          inc(pc.W, 2);
          inc(result, 10);
        end;

      18:
        begin
          pokeb(de.W, af.h);
          inc(result, 7);
        end;

      19:
        begin
          inc(de.W);
          inc(result, 6);
        end;

      20:
        begin
          af.l := INC_F[de.h] or (af.l and 1);
          inc(de.h);
          inc(result, 4);
        end;

      21:
        begin
          af.l := DEC_F[de.h] or (af.l and 1);
          dec(de.h);
          inc(result, 4);
        end;

      22:
        begin
          de.h := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      23:

        begin
          btemp := af.l and 1;
          af.l := RLA_F[btemp][af.h] or (af.l and 196);
          af.h := RLA_A[btemp][af.h];
          inc(result, 4);
        end;

      24:
        begin
          pc.W := pc.W + shortint(peekb(pc.W)) + 1;
          inc(result, 12);
        end;

      25:
        begin
          add16(FRegister, iy.W, de.W);
          inc(result, 11);
        end;

      26:
        begin
          af.h := peekb(de.W);
          inc(result, 7);
        end;

      27:
        begin
          dec(de.W);
          inc(result, 6);
        end;

      28:
        begin
          af.l := INC_F[de.l] or (af.l and 1);
          inc(de.l);
          inc(result, 4);
        end;

      29:
        begin
          af.l := DEC_F[de.l] or (af.l and 1);
          dec(de.l);
          inc(result, 4);
        end;

      30:
        begin
          de.l := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      31:
        begin
          if af.l and 1 = 0 then
          begin
            af.l := RRA_F[af.h] or (af.l and 196);
            af.h := RRA_A[0][af.h];
          end
          else
          begin
            af.l := RRA_F[af.h] or (af.l and 196);
            af.h := RRA_A[1][af.h];
          end;
          inc(result, 4);
        end;

      32:
        begin
          if af.l and 64 = 0 then
          begin
            pc.W := pc.W + shortint(peekb(pc.W)) + 1;
            inc(result, 12);
          end
          else
          begin
            inc(pc.W);
            inc(result, 7);
          end
        end;

      33:
        begin
          iy.W := peekw(pc.W);
          inc(pc.W, 2);
          inc(result, 10);
        end;

      34:
        begin
          pokew(peekw(pc.W), iy.W);
          inc(pc.W, 2);
          inc(result, 16);
        end;

      35:
        begin
          inc(iy.W);
          inc(result, 6);
        end;

      36:
        begin
          af.l := INC_F[iy.h] or (af.l and 1);
          inc(iy.h);
          inc(result, 4);
        end;

      37:
        begin
          af.l := DEC_F[iy.h] or (af.l and 1);
          dec(iy.h);
          inc(result, 4);
        end;

      38:
        begin
          iy.h := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      39:
        begin
          daa_select := af.l and 19;
          if daa_select and 16 > 0 then
          begin
            af.l := DAA_F[daa_select - 12][af.h];
            af.h := DAA_A[daa_select - 12][af.h];
          end
          else
          begin
            af.l := DAA_F[daa_select][af.h];
            af.h := DAA_A[daa_select][af.h];
          end;
          inc(result, 4);
        end;

      40:
        begin
          if af.l and 64 > 0 then
          begin
            pc.W := pc.W + shortint(peekb(pc.W)) + 1;
            inc(result, 12);
          end
          else
          begin
            inc(pc.W);
            inc(result, 7);
          end
        end;

      41:
        begin
          add16(FRegister, iy.W, iy.W);
          inc(result, 11);
        end;

      42:
        begin
          iy.W := peekw(peekw(pc.W));
          inc(pc.W, 2);
          inc(result, 16);
        end;

      43:
        begin
          dec(iy.W);
          inc(result, 6);
        end;

      44:
        begin
          af.l := INC_F[iy.l] or (af.l and 1);
          inc(iy.l);
          inc(result, 4);
        end;

      45:
        begin
          af.l := DEC_F[iy.l] or (af.l and 1);
          dec(iy.l);
          inc(result, 4);
        end;

      46:
        begin
          iy.l := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      47:
        begin
          af.h := af.h xor 255;
          af.l := af.l or 18;
          copy_b53(FRegister, af.h);
          inc(result, 4);
        end;

      48:
        begin
          if af.l and 1 = 0 then
          begin
            pc.W := pc.W + shortint(peekb(pc.W)) + 1;
            inc(result, 12);
          end
          else
          begin
            inc(pc.W);
            inc(result, 7);
          end
        end;

      49:
        begin
          sp.W := peekw(pc.W);
          inc(pc.W, 2);
          inc(result, 10);
        end;

      50:
        begin
          pokeb(peekw(pc.W), af.h);
          inc(pc.W, 2);
          inc(result, 13);
        end;

      51:
        begin
          inc(sp.W);
          inc(result, 6);
        end;

      52:

        begin

          dis := peekb(pc.W);
          inc(pc.W);
          btemp := peekb(iy.W + dis);
          af.l := INC_F[btemp] or (af.l and 1);
          pokeb(iy.W + dis, btemp + 1);
          inc(result, 19);
        end;

      53:
        begin
          dis := peekb(pc.W);
          inc(pc.W);
          btemp := peekb(iy.W + dis);
          af.l := DEC_F[btemp] or (af.l and 1);
          pokeb(iy.W + dis, btemp - 1);
          inc(result, 19);
        end;

      54:
        begin
          dis := peekb(pc.W);
          inc(pc.W);
          pokeb(iy.W + dis, peekb(pc.W));
          inc(pc.W);
          inc(result, 15);
        end;

      55:
        begin
          af.l := af.l and 237;
          copy_b53(FRegister, af.h);
          af.l := af.l or 1;
          inc(result, 4);
        end;

      56:
        begin
          if af.l and 1 > 0 then
          begin
            pc.W := pc.W + shortint(peekb(pc.W)) + 1;
            inc(result, 12);
          end
          else
          begin
            inc(pc.W);
            inc(result, 7);
          end
        end;

      57:
        begin
          add16(FRegister, iy.W, sp.W);
          inc(result, 11);
        end;

      58:
        begin
          af.h := peekb(peekw(pc.W));
          inc(pc.W, 2);
          inc(result, 13);
        end;

      59:
        begin
          dec(sp.W);
          inc(result, 6);
        end;

      60:
        begin
          af.l := INC_F[af.h] or (af.l and 1);
          inc(af.h);
          inc(result, 4);
        end;

      61:
        begin
          af.l := DEC_F[af.h] or (af.l and 1);
          dec(af.h);
          inc(result, 4);
        end;

      62:
        begin
          af.h := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      63:
        begin
          af.l := af.l xor 1;
          af.l := af.l and 253;
          copy_b53(FRegister, af.h);
          inc(result, 4);
        end;

      64:
        begin
          bc.h := bc.h;
          inc(result, 4);
        end;

      65:
        begin
          bc.h := bc.l;
          inc(result, 4);
        end;

      66:
        begin
          bc.h := de.h;
          inc(result, 4);
        end;

      67:
        begin
          bc.h := de.l;
          inc(result, 4);
        end;

      68:
        begin
          bc.h := iy.h;
          inc(result, 4);
        end;

      69:
        begin
          bc.h := iy.l;
          inc(result, 4);
        end;

      70:
        begin
          bc.h := peekb(iy.W + shortint(peekb(pc.W)));
          inc(pc.W);
          inc(result, 15);
        end;

      71:
        begin
          bc.h := af.h;
          inc(result, 4);
        end;

      72:
        begin
          bc.l := bc.h;
          inc(result, 4);
        end;

      73:
        begin
          bc.l := bc.l;
          inc(result, 4);
        end;

      74:
        begin
          bc.l := de.h;
          inc(result, 4);
        end;

      75:
        begin
          bc.l := de.l;
          inc(result, 4);
        end;

      76:
        begin
          bc.l := iy.h;
          inc(result, 4);
        end;

      77:
        begin
          bc.l := iy.l;
          inc(result, 4);
        end;

      78:
        begin
          bc.l := peekb(iy.W + shortint(peekb(pc.W)));
          inc(pc.W);
          inc(result, 15);
        end;

      79:
        begin
          bc.l := af.h;
          inc(result, 4);
        end;

      80:
        begin
          de.h := bc.h;
          inc(result, 4);
        end;

      81:
        begin
          de.h := bc.l;
          inc(result, 4);
        end;

      82:
        begin
          de.h := de.h;
          inc(result, 4);
        end;

      83:
        begin
          de.h := de.l;
          inc(result, 4);
        end;

      84:
        begin
          de.h := iy.h;
          inc(result, 4);
        end;

      85:
        begin
          de.h := iy.l;
          inc(result, 4);
        end;

      86:
        begin
          de.h := peekb(iy.W + shortint(peekb(pc.W)));
          inc(pc.W);
          inc(result, 15);
        end;

      87:
        begin
          de.h := af.h;
          inc(result, 4);
        end;

      88:
        begin
          de.l := bc.h;
          inc(result, 4);
        end;

      89:
        begin
          de.l := bc.l;
          inc(result, 4);
        end;

      90:
        begin
          de.l := de.h;
          inc(result, 4);
        end;

      91:
        begin
          de.l := de.l;
          inc(result, 4);
        end;

      92:
        begin
          de.l := iy.h;
          inc(result, 4);
        end;

      93:
        begin
          de.l := iy.l;
          inc(result, 4);
        end;

      94:
        begin
          de.l := peekb(iy.W + shortint(peekb(pc.W)));
          inc(pc.W);
          inc(result, 15);
        end;

      95:
        begin
          de.l := af.h;
          inc(result, 4);
        end;

      96:
        begin
          iy.h := bc.h;
          inc(result, 4);
        end;

      97:
        begin
          iy.h := bc.l;
          inc(result, 4);
        end;

      98:
        begin
          iy.h := de.h;
          inc(result, 4);
        end;

      99:
        begin
          iy.h := de.l;
          inc(result, 4);
        end;

      100:
        begin
          iy.h := iy.h;
          inc(result, 4);
        end;

      101:
        begin
          iy.h := iy.l;
          inc(result, 4);
        end;

      102:
        begin
          hl.h := peekb(iy.W + shortint(peekb(pc.W)));
          inc(pc.W);
          inc(result, 15);
        end;

      103:
        begin
          iy.h := af.h;
          inc(result, 4);
        end;

      104:
        begin
          iy.l := bc.h;
          inc(result, 4);
        end;

      105:
        begin
          iy.l := bc.l;
          inc(result, 4);
        end;

      106:
        begin
          iy.l := de.h;
          inc(result, 4);
        end;

      107:
        begin
          iy.l := de.l;
          inc(result, 4);
        end;

      108:
        begin
          iy.l := iy.h;
          inc(result, 4);
        end;

      109:
        begin
          iy.l := iy.l;
          inc(result, 4);
        end;

      110:
        begin
          hl.l := peekb(iy.W + shortint(peekb(pc.W)));
          inc(pc.W);
          inc(result, 15);
        end;

      111:
        begin
          iy.l := af.h;
          inc(result, 4);
        end;

      112:
        begin
          pokeb(iy.W + shortint(peekb(pc.W)), bc.h);
          inc(pc.W);
          inc(result, 15);
        end;

      113:
        begin
          pokeb(iy.W + shortint(peekb(pc.W)), bc.l);
          inc(pc.W);
          inc(result, 15);
        end;

      114:
        begin
          pokeb(iy.W + shortint(peekb(pc.W)), de.h);
          inc(pc.W);
          inc(result, 15);
        end;

      115:
        begin
          pokeb(iy.W + shortint(peekb(pc.W)), de.l);
          inc(pc.W);
          inc(result, 15);
        end;

      116:
        begin
          pokeb(iy.W + shortint(peekb(pc.W)), hl.h);
          inc(pc.W);
          inc(result, 15);
        end;

      117:
        begin
          pokeb(iy.W + shortint(peekb(pc.W)), hl.l);
          inc(pc.W);
          inc(result, 15);
        end;

      118:
        begin
          dec(pc.W); // TODO: Dec
          halt := true;
          inc(result, 4);
        end;

      119:
        begin
          pokeb(iy.W + shortint(peekb(pc.W)), af.h);
          inc(pc.W);
          inc(result, 15);
        end;

      120:
        begin
          af.h := bc.h;
          inc(result, 4);
        end;

      121:
        begin
          af.h := bc.l;
          inc(result, 4);
        end;

      122:
        begin
          af.h := de.h;
          inc(result, 4);
        end;

      123:
        begin
          af.h := de.l;
          inc(result, 4);
        end;

      124:
        begin
          af.h := iy.h;
          inc(result, 4);
        end;

      125:
        begin
          af.h := iy.l;
          inc(result, 4);
        end;

      126:
        begin
          af.h := peekb(iy.W + shortint(peekb(pc.W)));
          inc(pc.W);
          inc(result, 15);
        end;

      127:
        begin
          af.h := af.h;
          inc(result, 4);
        end;

      128:
        begin
          add8(FRegister, af.h, bc.h);
          inc(result, 4);
        end;

      129:
        begin
          add8(FRegister, af.h, bc.l);
          inc(result, 4);
        end;

      130:
        begin
          add8(FRegister, af.h, de.h);
          inc(result, 4);
        end;

      131:
        begin
          add8(FRegister, af.h, de.l);
          inc(result, 4);
        end;

      132:
        begin
          add8(FRegister, af.h, iy.h);
          inc(result, 4);
        end;

      133:
        begin
          add8(FRegister, af.h, iy.l);
          inc(result, 4);
        end;

      134:
        begin
          add8(FRegister, af.h, peekb(iy.W + shortint(peekb(pc.W))));
          inc(pc.W);
          inc(result, 15);
        end;

      135:
        begin
          add8(FRegister, af.h, af.h);
          inc(result, 4);
        end;

      136:
        begin
          adc8(FRegister, af.h, bc.h);
          inc(result, 4);
        end;

      137:
        begin
          adc8(FRegister, af.h, bc.l);
          inc(result, 4);
        end;

      138:
        begin
          adc8(FRegister, af.h, de.h);
          inc(result, 4);
        end;

      139:
        begin
          adc8(FRegister, af.h, de.l);
          inc(result, 4);
        end;

      140:
        begin
          adc8(FRegister, af.h, iy.h);
          inc(result, 4);
        end;

      141:
        begin
          adc8(FRegister, af.h, iy.l);
          inc(result, 4);
        end;

      142:
        begin
          adc8(FRegister, af.h, peekb(iy.W + shortint(peekb(pc.W))));
          inc(pc.W);
          inc(result, 15);
        end;

      143:
        begin
          adc8(FRegister, af.h, af.h);
          inc(result, 4);
        end;

      144:
        begin
          sub8(FRegister, af.h, bc.h);
          inc(result, 4);
        end;

      145:
        begin
          sub8(FRegister, af.h, bc.l);
          inc(result, 4);
        end;

      146:
        begin
          sub8(FRegister, af.h, de.h);
          inc(result, 4);
        end;

      147:
        begin
          sub8(FRegister, af.h, de.l);
          inc(result, 4);
        end;

      148:
        begin
          sub8(FRegister, af.h, iy.h);
          inc(result, 4);
        end;

      149:
        begin
          sub8(FRegister, af.h, iy.l);
          inc(result, 4);
        end;

      150:
        begin
          sub8(FRegister, af.h, peekb(iy.W + shortint(peekb(pc.W))));
          inc(pc.W);
          inc(result, 15);
        end;

      151:
        begin
          sub8(FRegister, af.h, af.h);
          inc(result, 4);
        end;

      152:
        begin
          sbc8(FRegister, af.h, bc.h);
          inc(result, 4);
        end;

      153:
        begin
          sbc8(FRegister, af.h, bc.l);
          inc(result, 4);
        end;

      154:
        begin
          sbc8(FRegister, af.h, de.h);
          inc(result, 4);
        end;

      155:
        begin
          sbc8(FRegister, af.h, de.l);
          inc(result, 4);
        end;

      156:
        begin
          sbc8(FRegister, af.h, iy.h);
          inc(result, 4);
        end;

      157:
        begin
          sbc8(FRegister, af.h, iy.l);
          inc(result, 4);
        end;

      158:
        begin
          sbc8(FRegister, af.h, peekb(iy.W + shortint(peekb(pc.W))));
          inc(pc.W);
          inc(result, 15);
        end;

      159:
        begin
          sbc8(FRegister, af.h, af.h);
          inc(result, 4);
        end;

      160:
        begin
          anda(FRegister, bc.h);
          inc(result, 4);
        end;

      161:
        begin
          anda(FRegister, bc.l);
          inc(result, 4);
        end;

      162:
        begin
          anda(FRegister, de.h);
          inc(result, 4);
        end;

      163:
        begin
          anda(FRegister, de.l);
          inc(result, 4);
        end;

      164:
        begin
          anda(FRegister, iy.h);
          inc(result, 4);
        end;

      165:
        begin
          anda(FRegister, iy.l);
          inc(result, 4);
        end;

      166:
        begin
          anda(FRegister, peekb(iy.W + shortint(peekb(pc.W))));
          inc(pc.W);
          inc(result, 15);
        end;

      167:
        begin
          anda(FRegister, af.h);
          inc(result, 4);
        end;

      168:
        begin
          xora(FRegister, bc.h);
          inc(result, 4);
        end;

      169:
        begin
          xora(FRegister, bc.l);
          inc(result, 4);
        end;

      170:
        begin
          xora(FRegister, de.h);
          inc(result, 4);
        end;

      171:
        begin
          xora(FRegister, de.l);
          inc(result, 4);
        end;

      172:
        begin
          xora(FRegister, iy.h);
          inc(result, 4);
        end;

      173:
        begin
          xora(FRegister, iy.l);
          inc(result, 4);
        end;

      174:
        begin
          xora(FRegister, peekb(iy.W + shortint(peekb(pc.W))));
          inc(pc.W);
          inc(result, 15);
        end;

      175:
        begin
          xora(FRegister, af.h);
          inc(result, 4);
        end;

      176:
        begin
          ora(FRegister, bc.h);
          inc(result, 4);
        end;

      177:
        begin
          ora(FRegister, bc.l);
          inc(result, 4);
        end;

      178:
        begin
          ora(FRegister, de.h);
          inc(result, 4);
        end;

      179:
        begin
          ora(FRegister, de.l);
          inc(result, 4);
        end;

      180:
        begin
          ora(FRegister, iy.h);
          inc(result, 4);
        end;

      181:
        begin
          ora(FRegister, iy.l);
          inc(result, 4);
        end;

      182:
        begin
          ora(FRegister, peekb(iy.W + shortint(peekb(pc.W))));
          inc(pc.W);
          inc(result, 15);
        end;

      183:
        begin
          ora(FRegister, af.h);
          inc(result, 4);
        end;

      184:
        begin
          cp_sub8(FRegister, af.h, bc.h);
          inc(result, 4);
        end;

      185:
        begin
          cp_sub8(FRegister, af.h, bc.l);
          inc(result, 4);
        end;

      186:
        begin
          cp_sub8(FRegister, af.h, de.h);
          inc(result, 4);
        end;

      187:
        begin
          cp_sub8(FRegister, af.h, de.l);
          inc(result, 4);
        end;

      188:
        begin
          cp_sub8(FRegister, af.h, iy.h);
          inc(result, 4);
        end;

      189:
        begin
          cp_sub8(FRegister, af.h, iy.l);
          inc(result, 4);
        end;

      190:
        begin
          cp_sub8(FRegister, af.h, peekb(iy.W + shortint(peekb(pc.W))));
          inc(pc.W);
          inc(result, 15);
        end;

      191:
        begin
          cp_sub8(FRegister, af.h, af.h);
          inc(result, 4);
        end;

      192:
        begin
          if af.l and 64 = 0 then
          begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      193:
        begin
          pop(bc.W);
          inc(result, 10);
        end;

      194:
        begin
          if af.l and 64 = 0 then
          begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      195:
        begin
          pc.W := peekw(pc.W);
          inc(result, 10);
        end;

      196:
        begin
          if af.l and 64 = 0 then
          begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      197:
        begin
          push(bc.W);
          inc(result, 11);
        end;

      198:
        begin
          add8(FRegister, af.h, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      199:
        begin
          push(pc.W);
          pc.W := 0;
          inc(result, 11);
        end;

      200:
        begin
          if af.l and 64 > 0 then
          begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      201:
        begin
          pop(pc.W);
          inc(result, 10);
        end;

      202:
        begin
          if af.l and 64 > 0 then
          begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      203:
        begin
          cbdis := peekb(pc.W);
          inc(pc.W);
          b := peekb(pc.W);
          inc(pc.W);
          FAddr := iy.W + cbdis;
          inc(result, Z80Instr_CB(b) + 8);
        end;

      204:
        begin
          if af.l and 64 > 0 then
          begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      205:
        begin
          push(pc.W + 2);
          pc.W := peekw(pc.W);
          inc(result, 17);
        end;

      206:
        begin
          adc8(FRegister, af.h, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      207:
        begin
          push(pc.W);
          pc.W := 8;
          inc(result, 11);
        end;

      208:
        begin
          if af.l and 1 = 0 then
          begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      209:
        begin
          pop(de.W);
          inc(result, 10);
        end;

      210:
        begin
          if af.l and 1 = 0 then
          begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      211:
        begin
          outb(Word(af.h shl 8) or peekb(pc.W), af.h);
          inc(pc.W);
          inc(result, 11);
        end;

      212:
        begin
          if af.l and 1 = 0 then
          begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      213:
        begin
          push(de.W);
          inc(result, 11);
        end;

      214:
        begin
          sub8(FRegister, af.h, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      215:
        begin
          push(pc.W);
          pc.W := 16;
          inc(result, 11);
        end;

      216:
        begin
          if af.l and 1 > 0 then
          begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      217:
        begin
          { temp:=af.W;af.W:=af2.W;af2.W:=temp; }
          temp := bc.W;
          bc.W := bc2.W;
          bc2.W := temp;
          temp := de.W;
          de.W := de2.W;
          de2.W := temp;
          temp := hl.W;
          hl.W := hl2.W;
          hl2.W := temp;
          inc(result, 4);
        end;

      218:
        begin
          if af.l and 1 > 0 then
          begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      219:
        begin
          af.h := inB(af.h shl 8 + peekb(pc.W));
          inc(pc.W);
          inc(result, 11);
        end;

      220:
        begin
          if af.l and 1 > 0 then
          begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      221:
        begin
          inc(ir.l);
          b := peekb(pc.W);
          inc(pc.W);
          inc(result, Z80Instr_IX(b));
        end;

      222:
        begin
          sbc8(FRegister, af.h, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      223:
        begin
          push(pc.W);
          pc.W := 24;
          inc(result, 11);
        end;

      224:
        begin
          if af.l and 4 = 0 then
          begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      225:
        begin
          pop(iy.W);
          inc(result, 10);
        end;

      226:
        begin
          if af.l and 4 = 0 then
          begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      227:
        begin
          temp := peekw(sp.W);
          pokew(sp.W, iy.W);
          iy.W := temp;
          inc(result, 19);
        end;

      228:
        begin
          if af.l and 4 = 0 then
          begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      229:
        begin
          push(iy.W);
          inc(result, 11);
        end;

      230:
        begin
          anda(FRegister, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      231:
        begin
          push(pc.W);
          pc.W := 32;
          inc(result, 11);
        end;

      232:
        begin
          if af.l and 4 > 0 then
          begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      233:
        begin
          pc.W := iy.W;
          inc(result, 4);
        end;

      234:
        begin
          if af.l and 4 > 0 then
          begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      235:
        begin
          temp := de.W;
          de.W := iy.W;
          iy.W := temp;
          inc(result, 4);
        end;

      236:
        begin
          if af.l and 4 > 0 then
          begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      237:
        begin
          inc(ir.l);
          b := peekb(pc.W);
          inc(pc.W);
          inc(result, Z80Instr_ED(b));
        end;

      238:
        begin
          xora(FRegister, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      239:
        begin
          push(pc.W);
          pc.W := 40;
          inc(result, 11);
        end;

      240:
        begin
          if af.l and 128 = 0 then
          begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      241:
        begin
          pop(af.W);
          inc(result, 10);
        end;

      242:
        begin
          if af.l and 128 = 0 then
          begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      243:
        begin
          iff1 := 0;
          iff2 := 0;
          inc(result, 4);
        end;

      244:
        begin
          if af.l and 128 = 0 then
          begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      245:
        begin
          push(af.W);
          inc(result, 11);
        end;

      246:
        begin
          ora(FRegister, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      247:
        begin
          push(pc.W);
          pc.W := 48;
          inc(result, 11);
        end;

      248:
        begin
          if af.l and 128 > 0 then
          begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      249:
        begin
          sp.W := iy.W;
          inc(result, 6);
        end;

      250:
        begin
          if af.l and 128 > 0 then
          begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      251:
        begin
          iff1 := 1;
          iff2 := 1;
          inc(result, 4);
        end;

      252:
        begin
          if af.l and 128 > 0 then
          begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      253:
        begin
          inc(ir.l);
          b := peekb(pc.W);
          inc(pc.W);
          inc(result, Z80Instr_IY(b));
        end;

      254:
        begin
          cp_sub8(FRegister, af.h, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      255:
        begin
          push(pc.W);
          pc.W := 56;
          inc(result, 11);
        end;

    end;
end;

function TZ80CPU.Z80Instr(const op: byte): integer;
var
  btemp: byte;
  temp: Word;
  daa_select: byte;
  b: byte;
begin
  result := 0;
  with FRegister do
    case op of
      0:
        Begin
          inc(result, 4);
        end;
      1:
        Begin
          bc.W := peekw(pc.W);
          inc(pc.W, 2);
          inc(result, 10);
        end;

      2:
        Begin
          pokeb(bc.W, af.h);
          inc(result, 7);
        end;

      3:
        Begin
          inc(bc.W);
          inc(result, 6);
        end;

      4:
        Begin
          af.l := INC_F[bc.h] or (af.l and 1);
          inc(bc.h);
          inc(result, 4);
        end;

      5:
        Begin
          af.l := DEC_F[bc.h] or (af.l and 1);
          dec(bc.h);
          inc(result, 4);
        end;

      6:
        Begin
          bc.h := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      7:
        Begin
          btemp := af.l and 1;
          af.l := RLCA_F[btemp][af.h] or (af.l and 196);
          af.h := RLCA_A[btemp][af.h];
          inc(result, 4);
        end;

      8:
        Begin
          temp := af.W;
          af.W := af2.W;
          af2.W := temp;
          inc(result, 4);
        end;

      9:
        Begin
          add16(FRegister, hl.W, bc.W);
          inc(result, 11);
        end;

      10:
        Begin
          af.h := peekb(bc.W);
          inc(result, 7);
        end;

      11:
        Begin
          dec(bc.W);
          inc(result, 6);
        end;

      12:
        Begin
          af.l := INC_F[bc.l] or (af.l and 1);
          inc(bc.l);
          inc(result, 4);
        end;

      13:
        Begin
          af.l := DEC_F[bc.l] or (af.l and 1);
          dec(bc.l);
          inc(result, 4);
        end;

      14:
        Begin
          bc.l := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      15:

        Begin
          btemp := af.l and 1;
          af.l := RRCA_F[btemp][af.h] or (af.l and 196);
          af.h := RRCA_A[btemp][af.h];
          inc(result, 4);
        end;

      16:
        Begin
          dec(bc.h);
          if bc.h > 0 then
          Begin
            pc.W := pc.W + shortint(peekb(pc.W)) + 1;
            inc(result, 13);
          end
          else
          Begin
            inc(pc.W);
            inc(result, 8);
          end
        end;

      17:
        Begin
          de.W := peekw(pc.W);
          inc(pc.W, 2);
          inc(result, 10);
        end;

      18:
        Begin
          pokeb(de.W, af.h);
          inc(result, 7);
        end;

      19:
        Begin
          inc(de.W);
          inc(result, 6);
        end;

      20:
        Begin
          af.l := INC_F[de.h] or (af.l and 1);
          inc(de.h);
          inc(result, 4);
        end;

      21:
        Begin
          af.l := DEC_F[de.h] or (af.l and 1);
          dec(de.h);
          inc(result, 4);
        end;

      22:
        Begin
          de.h := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      23:

        Begin
          btemp := af.l and 1;
          af.l := RLA_F[btemp][af.h] or (af.l and 196);
          af.h := RLA_A[btemp][af.h];
          inc(result, 4);
        end;

      24:
        Begin
          pc.W := pc.W + shortint(peekb(pc.W)) + 1;
          inc(result, 12);
        end;

      25:
        Begin
          add16(FRegister, hl.W, de.W);
          inc(result, 11);
        end;

      26:
        Begin
          af.h := peekb(de.W);
          inc(result, 7);
        end;

      27:
        Begin
          dec(de.W);
          inc(result, 6);
        end;

      28:
        Begin
          af.l := INC_F[de.l] or (af.l and 1);
          inc(de.l);
          inc(result, 4);
        end;

      29:
        Begin
          af.l := DEC_F[de.l] or (af.l and 1);
          dec(de.l);
          inc(result, 4);
        end;

      30:
        Begin
          de.l := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      31:
        Begin
          if af.l and 1 = 0 then
          begin
            af.l := RRA_F[af.h] or (af.l and 196);
            af.h := RRA_A[0][af.h];
          end
          else
          begin
            af.l := RRA_F[af.h] or (af.l and 196);
            af.h := RRA_A[1][af.h];
          end;
          inc(result, 4);
        end;

      32:
        Begin
          if af.l and 64 = 0 then
          Begin
            pc.W := pc.W + shortint(peekb(pc.W)) + 1;
            inc(result, 12);
          end
          else
          Begin
            inc(pc.W);
            inc(result, 7);
          end
        end;

      33:
        Begin
          hl.W := peekw(pc.W);
          inc(pc.W, 2);
          inc(result, 10);
        end;

      34:
        Begin
          pokew(peekw(pc.W), hl.W);
          inc(pc.W, 2);
          inc(result, 16);
        end;

      35:
        Begin
          inc(hl.W);
          inc(result, 6);
        end;

      36:
        Begin
          af.l := INC_F[hl.h] or (af.l and 1);
          inc(hl.h);
          inc(result, 4);
        end;

      37:
        Begin
          af.l := DEC_F[hl.h] or (af.l and 1);
          dec(hl.h);
          inc(result, 4);
        end;

      38:
        Begin
          hl.h := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      39:
        Begin
          daa_select := af.l and 19;
          if daa_select and 16 > 0 then
          Begin
            af.l := DAA_F[daa_select - 12][af.h];
            af.h := DAA_A[daa_select - 12][af.h];
          end
          else
          Begin
            af.l := DAA_F[daa_select][af.h];
            af.h := DAA_A[daa_select][af.h];
          end;
          inc(result, 4);
        end;

      40:
        Begin
          if af.l and 64 > 0 then
          Begin
            pc.W := pc.W + shortint(peekb(pc.W)) + 1;
            inc(result, 12);
          end
          else
          Begin
            inc(pc.W);
            inc(result, 7);
          end
        end;

      41:
        Begin
          add16(FRegister, hl.W, hl.W);
          inc(result, 11);
        end;

      42:
        Begin
          hl.W := peekw(peekw(pc.W));
          inc(pc.W, 2);
          inc(result, 16);
        end;

      43:
        Begin
          dec(hl.W);
          inc(result, 6);
        end;

      44:
        Begin
          af.l := INC_F[hl.l] or (af.l and 1);
          inc(hl.l);
          inc(result, 4);
        end;

      45:
        Begin
          af.l := DEC_F[hl.l] or (af.l and 1);
          dec(hl.l);
          inc(result, 4);
        end;

      46:
        Begin
          hl.l := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      47:
        Begin
          af.h := af.h xor 255;
          af.l := af.l or 18;
          copy_b53(FRegister, af.h);
          inc(result, 4);
        end;

      48:
        Begin
          if af.l and 1 = 0 then
          Begin
            pc.W := pc.W + shortint(peekb(pc.W)) + 1;
            inc(result, 12);
          end
          else
          Begin
            inc(pc.W);
            inc(result, 7);
          end
        end;

      49:
        Begin
          sp.W := peekw(pc.W);
          inc(pc.W, 2);
          inc(result, 10);
        end;

      50:
        Begin
          pokeb(peekw(pc.W), af.h);
          inc(pc.W, 2);
          inc(result, 13);
        end;

      51:
        Begin
          inc(sp.W);
          inc(result, 6);
        end;

      52:

        Begin
          btemp := peekb(hl.W);
          af.l := INC_F[btemp] or (af.l and 1);
          pokeb(hl.W, btemp + 1);
          inc(result, 11);
        end;

      53:
        Begin
          btemp := peekb(hl.W);
          af.l := DEC_F[btemp] or (af.l and 1);
          pokeb(hl.W, btemp - 1);
          inc(result, 11);
        end;

      54:
        Begin
          pokeb(hl.W, peekb(pc.W));
          inc(pc.W);
          inc(result, 10);
        end;

      55:
        Begin
          af.l := af.l and 237;
          copy_b53(FRegister, af.h);
          af.l := af.l Or 1;
          inc(result, 4);
        end;

      56:
        Begin
          if af.l and 1 > 0 then
          Begin
            pc.W := pc.W + shortint(peekb(pc.W)) + 1;
            inc(result, 12);
          end
          else
          Begin
            inc(pc.W);
            inc(result, 7);
          end
        end;

      57:
        Begin
          add16(FRegister, hl.W, sp.W);
          inc(result, 11);
        end;

      58:
        Begin
          af.h := peekb(peekw(pc.W));
          inc(pc.W, 2);
          inc(result, 13);
        end;

      59:
        Begin
          dec(sp.W);
          inc(result, 6);
        end;

      60:
        Begin
          af.l := INC_F[af.h] or (af.l and 1);
          inc(af.h);
          inc(result, 4);
        end;

      61:
        Begin
          af.l := DEC_F[af.h] or (af.l and 1);
          dec(af.h);
          inc(result, 4);
        end;

      62:
        Begin
          af.h := peekb(pc.W);
          inc(pc.W);
          inc(result, 7);
        end;

      63:
        Begin
          af.l := af.l xor 1;
          af.l := af.l And 253;
          copy_b53(FRegister, af.h);
          inc(result, 4);
        end;

      64:
        Begin
          bc.h := bc.h;
          inc(result, 4);
        end;

      65:
        Begin
          bc.h := bc.l;
          inc(result, 4);
        end;

      66:
        Begin
          bc.h := de.h;
          inc(result, 4);
        end;

      67:
        Begin
          bc.h := de.l;
          inc(result, 4);
        end;

      68:
        Begin
          bc.h := hl.h;
          inc(result, 4);
        end;

      69:
        Begin
          bc.h := hl.l;
          inc(result, 4);
        end;

      70:
        Begin
          bc.h := peekb(hl.W);
          inc(result, 7);
        end;

      71:
        Begin
          bc.h := af.h;
          inc(result, 4);
        end;

      72:
        Begin
          bc.l := bc.h;
          inc(result, 4);
        end;

      73:
        Begin
          bc.l := bc.l;
          inc(result, 4);
        end;

      74:
        Begin
          bc.l := de.h;
          inc(result, 4);
        end;

      75:
        Begin
          bc.l := de.l;
          inc(result, 4);
        end;

      76:
        Begin
          bc.l := hl.h;
          inc(result, 4);
        end;

      77:
        Begin
          bc.l := hl.l;
          inc(result, 4);
        end;

      78:
        Begin
          bc.l := peekb(hl.W);
          inc(result, 7);
        end;

      79:
        Begin
          bc.l := af.h;
          inc(result, 4);
        end;

      80:
        Begin
          de.h := bc.h;
          inc(result, 4);
        end;

      81:
        Begin
          de.h := bc.l;
          inc(result, 4);
        end;

      82:
        Begin
          de.h := de.h;
          inc(result, 4);
        end;

      83:
        Begin
          de.h := de.l;
          inc(result, 4);
        end;

      84:
        Begin
          de.h := hl.h;
          inc(result, 4);
        end;

      85:
        Begin
          de.h := hl.l;
          inc(result, 4);
        end;

      86:
        Begin
          de.h := peekb(hl.W);
          inc(result, 7);
        end;

      87:
        Begin
          de.h := af.h;
          inc(result, 4);
        end;

      88:
        Begin
          de.l := bc.h;
          inc(result, 4);
        end;

      89:
        Begin
          de.l := bc.l;
          inc(result, 4);
        end;

      90:
        Begin
          de.l := de.h;
          inc(result, 4);
        end;

      91:
        Begin
          de.l := de.l;
          inc(result, 4);
        end;

      92:
        Begin
          de.l := hl.h;
          inc(result, 4);
        end;

      93:
        Begin
          de.l := hl.l;
          inc(result, 4);
        end;

      94:
        Begin
          de.l := peekb(hl.W);
          inc(result, 7);
        end;

      95:
        Begin
          de.l := af.h;
          inc(result, 4);
        end;

      96:
        Begin
          hl.h := bc.h;
          inc(result, 4);
        end;

      97:
        Begin
          hl.h := bc.l;
          inc(result, 4);
        end;

      98:
        Begin
          hl.h := de.h;
          inc(result, 4);
        end;

      99:
        Begin
          hl.h := de.l;
          inc(result, 4);
        end;

      100:
        Begin
          hl.h := hl.h;
          inc(result, 4);
        end;

      101:
        Begin
          hl.h := hl.l;
          inc(result, 4);
        end;

      102:
        Begin
          hl.h := peekb(hl.W);
          inc(result, 7);
        end;

      103:
        Begin
          hl.h := af.h;
          inc(result, 4);
        end;

      104:
        Begin
          hl.l := bc.h;
          inc(result, 4);
        end;

      105:
        Begin
          hl.l := bc.l;
          inc(result, 4);
        end;

      106:
        Begin
          hl.l := de.h;
          inc(result, 4);
        end;

      107:
        Begin
          hl.l := de.l;
          inc(result, 4);
        end;

      108:
        Begin
          hl.l := hl.h;
          inc(result, 4);
        end;

      109:
        Begin
          hl.l := hl.l;
          inc(result, 4);
        end;

      110:
        Begin
          hl.l := peekb(hl.W);
          inc(result, 7);
        end;

      111:
        Begin
          hl.l := af.h;
          inc(result, 4);
        end;

      112:
        Begin
          pokeb(hl.W, bc.h);
          inc(result, 7);
        end;

      113:
        Begin
          pokeb(hl.W, bc.l);
          inc(result, 7);
        end;

      114:
        Begin
          pokeb(hl.W, de.h);
          inc(result, 7);
        end;

      115:
        Begin
          pokeb(hl.W, de.l);
          inc(result, 7);
        end;

      116:
        Begin
          pokeb(hl.W, hl.h);
          inc(result, 7);
        end;

      117:
        Begin
          pokeb(hl.W, hl.l);
          inc(result, 7);
        end;

      118:
        Begin
          halt := true;
          inc(result, 4);
        end;

      119:
        Begin
          pokeb(hl.W, af.h);
          inc(result, 7);
        end;

      120:
        Begin
          af.h := bc.h;
          inc(result, 4);
        end;

      121:
        Begin
          af.h := bc.l;
          inc(result, 4);
        end;

      122:
        Begin
          af.h := de.h;
          inc(result, 4);
        end;

      123:
        Begin
          af.h := de.l;
          inc(result, 4);
        end;

      124:
        Begin
          af.h := hl.h;
          inc(result, 4);
        end;

      125:
        Begin
          af.h := hl.l;
          inc(result, 4);
        end;

      126:
        Begin
          af.h := peekb(hl.W);
          inc(result, 7);
        end;

      127:
        Begin
          af.h := af.h;
          inc(result, 4);
        end;

      128:
        Begin
          add8(FRegister, af.h, bc.h);
          inc(result, 4);
        end;

      129:
        Begin
          add8(FRegister, af.h, bc.l);
          inc(result, 4);
        end;

      130:
        Begin
          add8(FRegister, af.h, de.h);
          inc(result, 4);
        end;

      131:
        Begin
          add8(FRegister, af.h, de.l);
          inc(result, 4);
        end;

      132:
        Begin
          add8(FRegister, af.h, hl.h);
          inc(result, 4);
        end;

      133:
        Begin
          add8(FRegister, af.h, hl.l);
          inc(result, 4);
        end;

      134:
        Begin
          add8(FRegister, af.h, peekb(hl.W));
          inc(result, 7);
        end;

      135:
        Begin
          add8(FRegister, af.h, af.h);
          inc(result, 4);
        end;

      136:
        Begin
          adc8(FRegister, af.h, bc.h);
          inc(result, 4);
        end;

      137:
        Begin
          adc8(FRegister, af.h, bc.l);
          inc(result, 4);
        end;

      138:
        Begin
          adc8(FRegister, af.h, de.h);
          inc(result, 4);
        end;

      139:
        Begin
          adc8(FRegister, af.h, de.l);
          inc(result, 4);
        end;

      140:
        Begin
          adc8(FRegister, af.h, hl.h);
          inc(result, 4);
        end;

      141:
        Begin
          adc8(FRegister, af.h, hl.l);
          inc(result, 4);
        end;

      142:
        Begin
          adc8(FRegister, af.h, peekb(hl.W));
          inc(result, 7);
        end;

      143:
        Begin
          adc8(FRegister, af.h, af.h);
          inc(result, 4);
        end;

      144:
        Begin
          sub8(FRegister, af.h, bc.h);
          inc(result, 4);
        end;

      145:
        Begin
          sub8(FRegister, af.h, bc.l);
          inc(result, 4);
        end;

      146:
        Begin
          sub8(FRegister, af.h, de.h);
          inc(result, 4);
        end;

      147:
        Begin
          sub8(FRegister, af.h, de.l);
          inc(result, 4);
        end;

      148:
        Begin
          sub8(FRegister, af.h, hl.h);
          inc(result, 4);
        end;

      149:
        Begin
          sub8(FRegister, af.h, hl.l);
          inc(result, 4);
        end;

      150:
        Begin
          sub8(FRegister, af.h, peekb(hl.W));
          inc(result, 7);
        end;

      151:
        Begin
          sub8(FRegister, af.h, af.h);
          inc(result, 4);
        end;

      152:
        Begin
          sbc8(FRegister, af.h, bc.h);
          inc(result, 4);
        end;

      153:
        Begin
          sbc8(FRegister, af.h, bc.l);
          inc(result, 4);
        end;

      154:
        Begin
          sbc8(FRegister, af.h, de.h);
          inc(result, 4);
        end;

      155:
        Begin
          sbc8(FRegister, af.h, de.l);
          inc(result, 4);
        end;

      156:
        Begin
          sbc8(FRegister, af.h, hl.h);
          inc(result, 4);
        end;

      157:
        Begin
          sbc8(FRegister, af.h, hl.l);
          inc(result, 4);
        end;

      158:
        Begin
          sbc8(FRegister, af.h, peekb(hl.W));
          inc(result, 7);
        end;

      159:
        Begin
          sbc8(FRegister, af.h, af.h);
          inc(result, 4);
        end;

      160:
        Begin
          anda(FRegister, bc.h);
          inc(result, 4);
        end;

      161:
        Begin
          anda(FRegister, bc.l);
          inc(result, 4);
        end;

      162:
        Begin
          anda(FRegister, de.h);
          inc(result, 4);
        end;

      163:
        Begin
          anda(FRegister, de.l);
          inc(result, 4);
        end;

      164:
        Begin
          anda(FRegister, hl.h);
          inc(result, 4);
        end;

      165:
        Begin
          anda(FRegister, hl.l);
          inc(result, 4);
        end;

      166:
        Begin
          anda(FRegister, peekb(hl.W));
          inc(result, 7);
        end;

      167:
        Begin
          anda(FRegister, af.h);
          inc(result, 4);
        end;

      168:
        Begin
          xora(FRegister, bc.h);
          inc(result, 4);
        end;

      169:
        Begin
          xora(FRegister, bc.l);
          inc(result, 4);
        end;

      170:
        Begin
          xora(FRegister, de.h);
          inc(result, 4);
        end;

      171:
        Begin
          xora(FRegister, de.l);
          inc(result, 4);
        end;

      172:
        Begin
          xora(FRegister, hl.h);
          inc(result, 4);
        end;

      173:
        Begin
          xora(FRegister, hl.l);
          inc(result, 4);
        end;

      174:
        Begin
          xora(FRegister, peekb(hl.W));
          inc(result, 7);
        end;

      175:
        Begin
          xora(FRegister, af.h);
          inc(result, 4);
        end;

      176:
        Begin
          ora(FRegister, bc.h);
          inc(result, 4);
        end;

      177:
        Begin
          ora(FRegister, bc.l);
          inc(result, 4);
        end;

      178:
        Begin
          ora(FRegister, de.h);
          inc(result, 4);
        end;

      179:
        Begin
          ora(FRegister, de.l);
          inc(result, 4);
        end;

      180:
        Begin
          ora(FRegister, hl.h);
          inc(result, 4);
        end;

      181:
        Begin
          ora(FRegister, hl.l);
          inc(result, 4);
        end;

      182:
        Begin
          ora(FRegister, peekb(hl.W));
          inc(result, 7);
        end;

      183:
        Begin
          ora(FRegister, af.h);
          inc(result, 4);
        end;

      184:
        Begin
          cp_sub8(FRegister, af.h, bc.h);
          inc(result, 4);
        end;

      185:
        Begin
          cp_sub8(FRegister, af.h, bc.l);
          inc(result, 4);
        end;

      186:
        Begin
          cp_sub8(FRegister, af.h, de.h);
          inc(result, 4);
        end;

      187:
        Begin
          cp_sub8(FRegister, af.h, de.l);
          inc(result, 4);
        end;

      188:
        Begin
          cp_sub8(FRegister, af.h, hl.h);
          inc(result, 4);
        end;

      189:
        Begin
          cp_sub8(FRegister, af.h, hl.l);
          inc(result, 4);
        end;

      190:
        Begin
          cp_sub8(FRegister, af.h, peekb(hl.W));
          inc(result, 7);
        end;

      191:
        Begin
          cp_sub8(FRegister, af.h, af.h);
          inc(result, 4);
        end;

      192:
        Begin
          if af.l and 64 = 0 then
          Begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      193:
        Begin
          pop(bc.W);
          inc(result, 10);
        end;

      194:
        Begin
          if af.l and 64 = 0 then
          Begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          Begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      195:
        Begin
          pc.W := peekw(pc.W);
          inc(result, 10);
        end;

      196:
        Begin
          if af.l and 64 = 0 then
          Begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          Begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      197:
        Begin
          push(bc.W);
          inc(result, 11);
        end;

      198:
        Begin
          add8(FRegister, af.h, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      199:
        Begin
          push(pc.W);
          pc.W := 0;
          inc(result, 11);
        end;

      200:
        Begin
          if af.l and 64 > 0 then
          Begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      201:
        Begin
          pop(pc.W);
          inc(result, 10);
        end;

      202:
        Begin
          if af.l and 64 > 0 then
          Begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          Begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      203:
        begin
          inc(ir.l);
          b := peekb(pc.W);
          inc(pc.W);
          FAddr := hl.W;
          inc(result, Z80Instr_CB(b));
        end;

      204:
        Begin
          if af.l and 64 > 0 then
          Begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          Begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      205:
        Begin
          push(pc.W + 2);
          pc.W := peekw(pc.W);
          inc(result, 17);
        end;

      206:
        Begin
          adc8(FRegister, af.h, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      207:
        Begin
          push(pc.W);
          pc.W := 8;
          inc(result, 11);
        end;

      208:
        Begin
          if af.l and 1 = 0 then
          Begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      209:
        Begin
          pop(de.W);
          inc(result, 10);
        end;

      210:
        Begin
          if af.l and 1 = 0 then
          Begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          Begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      211:
        Begin
          outb(Word(af.h shl 8) or peekb(pc.W), af.h);
          inc(pc.W);
          inc(result, 11);
        end;

      212:
        Begin
          if af.l and 1 = 0 then
          Begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          Begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      213:
        Begin
          push(de.W);
          inc(result, 11);
        end;

      214:
        Begin
          sub8(FRegister, af.h, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      215:
        Begin
          push(pc.W);
          pc.W := 16;
          inc(result, 11);
        end;

      216:
        Begin
          if af.l and 1 > 0 then
          Begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      217:
        Begin
          { temp:=af.W;af.W:=af2.W;af2.W:=temp; }
          temp := bc.W;
          bc.W := bc2.W;
          bc2.W := temp;
          temp := de.W;
          de.W := de2.W;
          de2.W := temp;
          temp := hl.W;
          hl.W := hl2.W;
          hl2.W := temp;
          inc(result, 4);
        end;

      218:
        Begin
          if af.l and 1 > 0 then
          Begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          Begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      219:
        Begin
          af.h := inB(af.h shl 8 + peekb(pc.W));
          inc(pc.W);
          inc(result, 11);
        end;

      220:
        Begin
          if af.l and 1 > 0 then
          Begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          Begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      221:
        begin
          inc(ir.l);
          b := peekb(pc.W);
          inc(pc.W);
          inc(result, Z80Instr_IX(b));
        end;

      222:
        Begin
          sbc8(FRegister, af.h, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      223:
        Begin
          push(pc.W);
          pc.W := 24;
          inc(result, 11);
        end;

      224:
        Begin
          if af.l and 4 = 0 then
          Begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      225:
        Begin
          pop(hl.W);
          inc(result, 10);
        end;

      226:
        Begin
          if af.l and 4 = 0 then
          Begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          Begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      227:
        Begin
          temp := peekw(sp.W);
          pokew(sp.W, hl.W);
          hl.W := temp;
          inc(result, 4);
        end;

      228:
        Begin
          if af.l and 4 = 0 then
          Begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          Begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      229:
        Begin
          push(hl.W);
          inc(result, 11);
        end;

      230:
        Begin
          anda(FRegister, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      231:
        Begin
          push(pc.W);
          pc.W := 32;
          inc(result, 11);
        end;

      232:
        Begin
          if af.l and 4 > 0 then
          Begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      233:
        Begin
          pc.W := hl.W;
          inc(result, 4);
        end;

      234:
        Begin
          if af.l and 4 > 0 then
          Begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          Begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      235:
        Begin
          temp := de.W;
          de.W := hl.W;
          hl.W := temp;
          inc(result, 4);
        end;

      236:
        Begin
          if af.l and 4 > 0 then
          Begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          Begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      237:
        begin
          inc(ir.l);
          b := peekb(pc.W);
          inc(pc.W);
          inc(result, Z80Instr_ED(b));
        end;

      238:
        Begin
          xora(FRegister, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      239:
        Begin
          push(pc.W);
          pc.W := 40;
          inc(result, 11);
        end;

      240:
        Begin
          if af.l and 128 = 0 then
          Begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      241:
        Begin
          pop(af.W);
          inc(result, 10);
        end;

      242:
        Begin
          if af.l and 128 = 0 then
          Begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          Begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      243:
        Begin
          iff1 := 0;
          iff2 := 0;
          inc(result, 4);
        end;

      244:
        Begin
          if af.l and 128 = 0 then
          Begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          Begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      245:
        Begin
          push(af.W);
          inc(result, 11);
        end;

      246:
        Begin
          ora(FRegister, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      247:
        Begin
          push(pc.W);
          pc.W := 48;
          inc(result, 11);
        end;

      248:
        Begin
          if af.l and 128 > 0 then
          Begin
            pop(pc.W);
            inc(result, 11);
          end
          else
            inc(result, 5);
        end;

      249:
        Begin
          sp.W := hl.W;
          inc(result, 6);
        end;

      250:
        Begin
          if af.l and 128 > 0 then
          Begin
            pc.W := peekw(pc.W);
            inc(result, 10);
          end
          else
          Begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      251:
        Begin
          iff1 := 1;
          iff2 := 1;
          inc(result, 4);
        end;

      252:
        Begin
          if af.l and 128 > 0 then
          Begin
            push(pc.W + 2);
            pc.W := peekw(pc.W);
            inc(result, 17);
          end
          else
          Begin
            inc(pc.W, 2);
            inc(result, 10);
          end
        end;

      253:
        begin
          inc(ir.l);
          b := peekb(pc.W);
          inc(pc.W);
          inc(result, Z80Instr_IY(b));
        end;

      254:
        Begin
          cp_sub8(FRegister, af.h, peekb(pc.W));
          inc(pc.W);
          inc(result, 7);
        end;

      255:
        Begin
          push(pc.W);
          pc.W := 56;
          inc(result, 11);
        end;
    end;
end;

function TZ80CPU.nxtpcb: integer;
var
  dummy: integer;
begin
  with FRegister do
  begin
    inc(ir.l);
    dummy := peekb(pc.W);
    inc(pc.W);
    result := dummy;
  end;
end;

procedure TZ80CPU.Execute(var local_tstates: integer;
  const StatesPerInterrupt: integer);
var
  intCtrTemp: integer;
  t_state: integer;
  opcode: byte;
begin
  if not assigned(FHardware) then
    exit;

  with FRegister do
  begin
    // Execute one interrupt duration
    intCtrTemp := interruptCounter;

    repeat
      if (local_tstates >= 0) then // Trigger an interrupt
        local_tstates := local_tstates - StatesPerInterrupt - EIInterrupt;

      if halt then
        opcode := 0
      else
        opcode := nxtpcb;
      t_state := Z80Instr(opcode);
      inc(local_tstates, t_state);

      FHardware.Instruction(opcode, t_state);
    until (intCtrTemp <> interruptCounter);
  end;
end;

function TZ80CPU.EIInterrupt: integer;
begin
  if assigned(FHardware) then
    FHardware.OnInterrupt;

  with FRegister do
  begin
    if FNMIInt > 0 then
    begin
      iff2 := iff1;
      iff1 := 0;
      inc(ir.l);
      push(pc.W);
      pc.W := FNMIInt;
      FNMIInt := 0;
      result := 11;
    end
    else
    begin
      // If it's a maskable interrupt
      if iff1 = 0 then
        result := 0
      else
      begin
        iff1 := 0;
        iff2 := 0;
        halt := false;

        if peekb(pc.W) = $76 then
          inc(pc.W);
        push(pc.W);

        inc(ir.l);
        if im = 2 then
        begin
          pc.W := peekw((ir.h shl 8) or 255);
          result := 19;
        end
        else
        begin
          pc.W := FRSTMode;
          result := 13;
        end;
      end;
    end;
  end;
end;

procedure TZ80CPU.NMI(const Value: byte);
begin
  FNMIInt := Value;
end;

end.
