home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / EXTRA-ST / APPLE-II / APPLE2-V.TAR / apple2 / apple2.S < prev    next >
Encoding:
Text File  |  1994-10-09  |  61.8 KB  |  3,311 lines

  1. #include "defs.H"
  2.     
  3.     /* ********************************************************************
  4.      *  Apple II emulator by Alexander Jean-Claude Bottema (C) 1994
  5.      *
  6.      * ***************************************************************** */
  7.  
  8.     /* --------------------------------------------------------------------
  9.        ....................................................................
  10.         Memory documentation
  11.       
  12.         I use two jump tables; one for get_memory and one for set_memory
  13.         respectively. The jump tables contain exactly 64k entries to
  14.             avoid unnecessary range checking. Furthermore, special access
  15.         or to serve memory mapped I/O services are easily obtained by
  16.         patching the jump table with various routines.
  17.       
  18.         Apple 64k address space:
  19.       
  20.         (Two byte addresses are represented with least significant
  21.          byte first, e.g. address FA59 is represented as 59 FA)
  22.       
  23.         Address        Description
  24.       
  25.         0000 - 00FF       Zero page RAM
  26.         0100 - 01FF        Stack
  27.         0200 - 03EF        RAM
  28.         03F0 - 03F1        Address for BRK instruction
  29.                             (normally 59 FA = FA59)
  30.         03F2 - 03F3         Soft entry vector (normally BF 9D = 9DBF)
  31.         03F4                Power-up byte
  32.         03F5 - 03F7         Jump instruction to the subroutine which
  33.                             handles Applesoft II &-commands
  34.                    (normally 4C 58 FF = JMP FF58)
  35.         03F8 - 03FA        Jump instruction to the subroutine which
  36.                             handles User CTRL-Y commands
  37.                             (normally 4C 65 FF = JMP FF65)
  38.         03FB - 03FD        Jump instruction to the subroutine which
  39.                             handles Non-Maskable Interrupts (NMI)
  40.                             (normally 4C 65 FF = JMP FF65)
  41.         03FE - 03FF         Address of the subroutine which handles
  42.                             Interrupt ReQuests (IRQ)
  43.                             (normally 65 FF = FF65)
  44.         0400 - 07FF         Basically primary video text page
  45.         0478 - 047F        I/O Scratchpad RAM Addresses for Slot 0 - 7
  46.         04F8 - 04FF                       - " " -
  47.         0578 - 057F                       - " " -
  48.         05F8 - 05FF                       - " " -
  49.         0678 - 067F                       - " " -
  50.         06F8 - 06FF                       - " " -
  51.         0778 - 077F                       - " " -
  52.         07F8 - 07FF                       - " " -
  53.         ----- These two addresses are pretty strange; the values
  54.               provided were inconsistent at least on my Apple II
  55.         05F8        Holds the slot number of the disk
  56.                   controller card from which DOS was
  57.                             booted.
  58.         07F8        Holds the slot number (CX, X = Slot #)
  59.                             of the slot that is currently active.
  60.       
  61.         0800 - 0BFF        Basically secondary video text page
  62.       
  63.         0C00 - 1FFF        Plain RAM
  64.         2000 - 3FFF        Primary video Hi-res page (RAM)
  65.         4000 - 5FFF         Secondary video Hi-Res page (RAM)
  66.         6000 - BFFF        Plain RAM
  67.                             (Normally the operating system is
  68.                              loaded into ~= 9C00 - BFFF)
  69.         C000 - C00F        Keyboard data
  70.                             (C00X contains the character ASCII
  71.                              code of the pressed key. The
  72.                              value is available at any C00X
  73.                              address)
  74.         C010 - C01F         Clear Keyboard strobe
  75.         C020 - C02F         Cassette output toggle
  76.         C030 - C03F         Speaker toggle
  77.         C040 - C04F         Utility strobe
  78.         C050        Set graphics mode
  79.         C051        Set text mode
  80.         C052        Set all text or graphics
  81.         C053        Mix text and graphics
  82.         C054        Display primary page
  83.         C055        Display secondary page
  84.         C056        Display low-res graphics
  85.         C057        Display hi-res graphics
  86.         C058 - C05F        Annunciator outputs
  87.         C060        Cassette input
  88.         C061 - C063        Pushbutton inputs (button 1, 2 and 3)
  89.         C064 - C067        Game controller inputs
  90.         C068 - C06F        Same as C060 - C067
  91.         C070 - C07F        Game controller strobe
  92.         C080 - C08F        Slot 0 I/O space (usually a language card)
  93.                             --- If language card
  94.         C080            Reset language card
  95.                                 Read mode enabled
  96.                       Write mode disabled
  97.                                 Read from language card
  98.                       Write to ROM (impossible of course)
  99.         C081        --- First access
  100.                       Read mode disabled
  101.                                 Read from ROM
  102.                   --- On second access
  103.                                 Write mode enabled
  104.                       Write to language card
  105.         C082        --- (Disable language card)
  106.                                 Read mode disabled
  107.                                 Write mode disabled
  108.                                 Read from ROM
  109.                                 Write to ROM
  110.         C083        --- First access
  111.                                 Read mode enabled
  112.                       Read from language card
  113.                    --- On second access
  114.                       Write mode enabled
  115.                       Write to language card
  116.         C088 - C08B        Same as C080 - C083, but
  117.                   switch to second bank, i.e.
  118.                   map addresses D000-DFFF to
  119.                   other 4k area.
  120.         C100 - C1FF        Slot 1 PROM
  121.         C200 - C2FF        Slot 2 PROM
  122.         C300 - C3FF        Slot 3 PROM
  123.         C400 - C4FF        Slot 4 PROM
  124.         C500 - C5FF        Slot 5 PROM
  125.         C600 - C6FF        Slot 6 PROM
  126.         C700 - C7FF        Slot 7 PROM
  127.         C800 - CFFF        Expansion ROM (for peripheral cards)
  128.         CFFF        Disable access to expansion ROM for
  129.                   ALL peripheral cards.
  130.         D000 - DFFF        ROM or 4k RAM if language card is
  131.                   enabled. However, there are TWO 4k
  132.                   banks that can be mapped onto addresses
  133.                   D000 - DFFF. See C088 - C08B.
  134.         E000 - FFFF        ROM or 8k RAM if language card is
  135.                   enabled.
  136.        ----------------------------------------------------------------- */
  137.  
  138.     .align 4
  139. table_opcodes:
  140.     .long        op_BRK            # 00
  141.     .long        op_ORA_ind_x        # 01
  142.     .long        op_HANG            # 02
  143.     .long        op_LOR_ind_x        # 03
  144.     .long        op_NOP_2        # 04
  145.     .long        op_ORA_zpage        # 05
  146.     .long        op_ASL_zpage        # 06
  147.     .long        op_LOR_zpage        # 07
  148.     .long        op_PHP            # 08
  149.     .long        op_ORA_imm        # 09
  150.     .long        op_ASL_acc        # 0A
  151.     .long        op_ANA_imm        # 0B
  152.     .long        op_NOP_3        # 0C
  153.     .long        op_ORA_abs        # 0D
  154.     .long        op_ASL_abs        # 0E
  155.     .long        op_LOR_abs        # 0F
  156.     .long        op_BPL            # 10
  157.     .long        op_ORA_ind_y        # 11
  158.     .long        op_HANG            # 12
  159.     .long        op_LOR_ind_y        # 13
  160.     .long        op_NOP_2        # 14
  161.     .long        op_ORA_zpage_x        # 15
  162.     .long        op_ASL_zpage_x        # 16
  163.     .long        op_LOR_zpage_x        # 17
  164.     .long        op_CLC            # 18
  165.     .long        op_ORA_abs_y        # 19
  166.     .long        op_NOP            # 1A
  167.     .long        op_LOR_abs_y        # 1B
  168.     .long        op_NOP_3        # 1C
  169.     .long        op_ORA_abs_x        # 1D
  170.     .long        op_ASL_abs_x        # 1E
  171.     .long        op_LOR_abs_x        # 1F
  172.     .long        op_JSR            # 20
  173.     .long        op_AND_ind_x        # 21
  174.     .long        op_HANG            # 22
  175.     .long        op_LAN_ind_x        # 23
  176.     .long        op_BIT_zpage        # 24
  177.     .long        op_AND_zpage        # 25
  178.     .long        op_ROL_zpage        # 26
  179.     .long        op_LAN_zpage        # 27
  180.     .long        op_PLP            # 28
  181.     .long        op_AND_imm        # 29
  182.     .long        op_ROL_acc        # 2A
  183.     .long        op_ANB_imm        # 2B
  184.     .long        op_BIT_abs        # 2C
  185.     .long        op_AND_abs        # 2D
  186.     .long        op_ROL_abs        # 2E
  187.     .long        op_LAN_abs        # 2F
  188.     .long        op_BMI            # 30
  189.     .long        op_AND_ind_y        # 31
  190.     .long        op_HANG            # 32
  191.     .long        op_LAN_ind_y        # 33
  192.     .long        op_NOP_2        # 34
  193.     .long        op_AND_zpage_x        # 35
  194.     .long        op_ROL_zpage_x        # 36
  195.     .long        op_LAN_zpage_x        # 37
  196.     .long        op_SEC            # 38
  197.     .long        op_AND_abs_y        # 39
  198.     .long        op_NOP            # 3A
  199.     .long        op_LAN_abs_y        # 3B
  200.     .long        op_NOP_3        # 3C
  201.     .long        op_AND_abs_x        # 3D
  202.     .long        op_ROL_abs_x        # 3E
  203.     .long        op_LAN_abs_x        # 3F
  204.     .long        op_RTI            # 40
  205.     .long        op_EOR_ind_x        # 41
  206.     .long        op_HANG            # 42
  207.     .long        op_REO_ind_x        # 43
  208.     .long        op_NOP_2        # 44
  209.     .long        op_EOR_zpage        # 45
  210.     .long        op_LSR_zpage        # 46
  211.     .long        op_REO_zpage        # 47
  212.     .long        op_PHA            # 48
  213.     .long        op_EOR_imm        # 49
  214.     .long        op_LSR_acc        # 4A
  215.     .long        op_RAM_imm        # 4B
  216.     .long        op_JMP_abs        # 4C
  217.     .long        op_EOR_abs        # 4D
  218.     .long        op_LSR_abs        # 4E
  219.     .long        op_REO_abs        # 4F
  220.     .long        op_BVC            # 50
  221.     .long        op_EOR_ind_y        # 51
  222.     .long        op_HANG            # 52
  223.     .long        op_REO_ind_y        # 53
  224.     .long        op_NOP_2        # 54
  225.     .long        op_EOR_zpage_x        # 55
  226.     .long        op_LSR_zpage_x        # 56
  227.     .long        op_REO_zpage_x        # 57
  228.     .long        op_CLI            # 58
  229.     .long        op_EOR_abs_y        # 59
  230.     .long        op_NOP            # 5A
  231.     .long        op_REO_abs_y        # 5B
  232.     .long        op_NOP_3        # 5C
  233.     .long        op_EOR_abs_x        # 5D
  234.     .long        op_LSR_abs_x        # 5E
  235.     .long        op_REO_abs_x        # 5F
  236.     .long        op_RTS            # 60
  237.     .long        op_ADC_ind_x        # 61
  238.     .long        op_HANG            # 62
  239.     .long        op_RAD_ind_x        # 63
  240.     .long        op_NOP_2        # 64
  241.     .long        op_ADC_zpage        # 65
  242.     .long        op_ROR_zpage        # 66
  243.     .long        op_RAD_zpage        # 67
  244.     .long        op_PLA            # 68
  245.     .long        op_ADC_imm        # 69
  246.     .long        op_ROR_acc        # 6A
  247.     .long        op_RBM_imm        # 6B
  248.     .long        op_JMP_ind        # 6C
  249.     .long        op_ADC_abs        # 6D
  250.     .long        op_ROR_abs        # 6E
  251.     .long        op_RAD_abs        # 6F
  252.     .long        op_BVS            # 70
  253.     .long        op_ADC_ind_y        # 71
  254.     .long        op_HANG            # 72
  255.     .long        op_RAD_ind_y        # 73
  256.     .long        op_NOP_2        # 74
  257.     .long        op_ADC_zpage_x        # 75
  258.     .long        op_ROR_zpage_x        # 76
  259.     .long        op_RAD_zpage_x        # 77
  260.     .long        op_SEI            # 78
  261.     .long        op_ADC_abs_y        # 79
  262.     .long        op_NOP            # 7A
  263.     .long        op_RAD_abs_y        # 7B
  264.     .long        op_NOP_3        # 7C
  265.     .long        op_ADC_abs_x        # 7D
  266.     .long        op_ROR_abs_x        # 7E
  267.     .long        op_RAD_abs_x        # 7F
  268.     .long        op_NOP_2        # 80
  269.     .long        op_STA_ind_x        # 81
  270.     .long        op_NOP_2        # 82
  271.     .long        op_AAX_ind_x        # 83
  272.     .long        op_STY_zpage        # 84
  273.     .long        op_STA_zpage        # 85
  274.     .long        op_STX_zpage        # 86
  275.     .long        op_AAX_zpage        # 87
  276.     .long        op_DEY            # 88
  277.     .long        op_NOP_2        # 89
  278.     .long        op_TXA            # 8A
  279.     .long        op_XMA_imm        # 8B
  280.     .long        op_STY_abs        # 8C
  281.     .long        op_STA_abs        # 8D
  282.     .long        op_STX_abs        # 8E
  283.     .long        op_AAX_abs        # 8F
  284.     .long        op_BCC            # 90
  285.     .long        op_STA_ind_y        # 91
  286.     .long        op_HANG            # 92
  287.     .long        op_AAX_ind_y        # 93
  288.     .long        op_STY_zpage_x        # 94
  289.     .long        op_STA_zpage_x        # 95
  290.     .long        op_STX_zpage_y        # 96
  291.     .long        op_AAX_zpage_y        # 97
  292.     .long        op_TYA            # 98
  293.     .long        op_STA_abs_y        # 99
  294.     .long        op_TXS            # 9A
  295.     .long        op_AXS_abs_y        # 9B
  296.     .long        op_TEY_abs_x        # 9C
  297.     .long        op_STA_abs_x        # 9D
  298.     .long        op_TEX_abs_y        # 9E
  299.     .long        op_TEA_abs_y        # 9F
  300.     .long        op_LDY_imm        # A0
  301.     .long        op_LDA_ind_x        # A1
  302.     .long        op_LDX_imm        # A2
  303.     .long        op_LAX_ind_x        # A3
  304.     .long        op_LDY_zpage        # A4
  305.     .long        op_LDA_zpage        # A5
  306.     .long        op_LDX_zpage        # A6
  307.     .long        op_LAX_zpage        # A7
  308.     .long        op_TAY            # A8
  309.     .long        op_LDA_imm        # A9
  310.     .long        op_TAX            # AA
  311.     .long        op_AMA_imm        # AB
  312.     .long        op_LDY_abs        # AC
  313.     .long        op_LDA_abs        # AD
  314.     .long        op_LDX_abs        # AE
  315.     .long        op_LAX_abs        # AF
  316.     .long        op_BCS            # B0
  317.     .long        op_LDA_ind_y        # B1
  318.     .long        op_HANG            # B2
  319.     .long        op_LAX_ind_y        # B3
  320.     .long        op_LDY_zpage_x        # B4
  321.     .long        op_LDA_zpage_x        # B5
  322.     .long        op_LDX_zpage_y        # B6
  323.     .long        op_LAX_zpage_y        # B7
  324.     .long        op_CLV            # B8
  325.     .long        op_LDA_abs_y        # B9
  326.     .long        op_TSX            # BA
  327.     .long        op_LAS_abs_y        # BB
  328.     .long        op_LDY_abs_x        # BC
  329.     .long        op_LDA_abs_x        # BD
  330.     .long        op_LDX_abs_y        # BE
  331.     .long        op_LAX_abs_y        # BF
  332.     .long        op_CPY_imm        # C0
  333.     .long        op_CMP_ind_x        # C1
  334.     .long        op_NOP_2        # C2
  335.     .long        op_DCP_ind_x        # C3
  336.     .long        op_CPY_zpage        # C4
  337.     .long        op_CMP_zpage        # C5
  338.     .long        op_DEC_zpage        # C6
  339.     .long        op_DCP_zpage        # C7
  340.     .long        op_INY            # C8
  341.     .long        op_CMP_imm        # C9
  342.     .long        op_DEX            # CA
  343.     .long        op_AXM_imm        # CB
  344.     .long        op_CPY_abs        # CC
  345.     .long        op_CMP_abs        # CD
  346.     .long        op_DEC_abs        # CE
  347.     .long        op_DCP_abs        # CF
  348.     .long        op_BNE            # D0
  349.     .long        op_CMP_ind_y        # D1
  350.     .long        op_HANG            # D2
  351.     .long        op_DCP_ind_y        # D3
  352.     .long        op_NOP_2        # D4
  353.     .long        op_CMP_zpage_x        # D5
  354.     .long        op_DEC_zpage_x        # D6
  355.     .long        op_DCP_zpage_x        # D7
  356.     .long        op_CLD            # D8
  357.     .long        op_CMP_abs_y        # D9
  358.     .long        op_NOP            # DA
  359.     .long        op_DCP_abs_y        # DB
  360.     .long        op_NOP_3        # DC
  361.     .long        op_CMP_abs_x        # DD
  362.     .long        op_DEC_abs_x        # DE
  363.     .long        op_DCP_abs_x        # DF
  364.     .long        op_CPX_imm        # E0
  365.     .long        op_SBC_ind_x        # E1
  366.     .long        op_NOP_2        # E2
  367.     .long        op_ISB_ind_x        # E3
  368.     .long        op_CPX_zpage        # E4
  369.     .long        op_SBC_zpage        # E5
  370.     .long        op_INC_zpage        # E6
  371.     .long        op_ISB_zpage        # E7
  372.     .long        op_INX            # E8
  373.     .long        op_SBC_imm        # E9
  374.     .long        op_NOP            # EA
  375.     .long        op_ZBC_imm        # EB
  376.     .long        op_CPX_abs        # EC
  377.     .long        op_SBC_abs        # ED
  378.     .long        op_INC_abs        # EE
  379.     .long        op_ISB_abs        # EF
  380.     .long        op_BEQ            # F0
  381.     .long        op_SBC_ind_y        # F1
  382.     .long        op_HANG            # F2
  383.     .long        op_ISB_ind_y        # F3
  384.     .long        op_NOP_2        # F4
  385.     .long        op_SBC_zpage_x        # F5
  386.     .long        op_INC_zpage_x        # F6
  387.     .long        op_ISB_zpage_x        # F7
  388.     .long        op_SED            # F8
  389.     .long        op_SBC_abs_y        # F9
  390.     .long        op_NOP            # FA
  391.     .long        op_ISB_abs_y        # FB
  392.     .long        op_NOP_3        # FC
  393.     .long        op_SBC_abs_x        # FD
  394.     .long        op_INC_abs_x        # FE
  395.     .long        op_ISB_abs_x        # FF
  396.  
  397.     /* --------------------------------------------------------------------
  398.         Routine    : cpu6502
  399.        ----------------------------------------------------------------- */
  400.  
  401.     .align 4
  402.     .globl _cpu6502
  403. _cpu6502:
  404.         xorl    %eax, %eax
  405.         call    set_page
  406.         
  407.         xorl    %eax, %eax        # Clear registers
  408.         xorl    %ebx, %ebx
  409.         xorl    %ecx, %ecx
  410.         xorl    %edx, %edx
  411.         xorl    %esi, %esi
  412.         xorl    %edi, %edi
  413.  
  414.         movl    $0xFA62, %esi        # For now
  415.         # movl    $0xFF59, %esi
  416.         xorb    X_Reg, X_Reg        # Clear X register
  417.         xorb    Y_Reg, Y_Reg        # Clear Y register
  418.         xorb    A_Reg, A_Reg        # Clear A register
  419.         xorb    F_Reg, F_Reg        # Clear flags
  420.         movl    $0x1FF, SP_Reg        # Stack pointer
  421.         cld                # Clear direction flag
  422.  
  423.         Continue
  424.  
  425.    /* ----------------------------------
  426.        ADC instructions
  427.       ---------------------------------- */
  428.  
  429. op_ADC_imm:
  430.         GetImm
  431.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  432.         jc    op_ADC_imm_dec        # Yes, jump to decimal version
  433.         DoADC_b
  434.         Continue
  435. op_ADC_imm_dec:
  436.         DoADC_d
  437.         Continue
  438.  
  439. op_ADC_zpage:
  440.         GetZPage
  441.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  442.         jc    op_ADC_zpage_dec    # Yes, jump to decimal version
  443.         DoADC_b
  444.         Continue
  445. op_ADC_zpage_dec:
  446.         DoADC_d
  447.         Continue
  448. op_ADC_zpage_x:
  449.         GetZPage_X
  450.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  451.         jc    op_ADC_zpage_x_dec    # Yes, jump to decimal version
  452.         DoADC_b
  453.         Continue
  454. op_ADC_zpage_x_dec:
  455.         DoADC_d
  456.         Continue
  457.  
  458. op_ADC_abs:
  459.         GetAbs
  460.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  461.         jc    op_ADC_abs_dec        # Yes, jump to decimal version
  462.         DoADC_b
  463.         Continue
  464. op_ADC_abs_dec:
  465.         DoADC_d
  466.         Continue
  467.  
  468. op_ADC_abs_x:
  469.         GetAbs_X
  470.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  471.         jc    op_ADC_abs_x_dec    # Yes, jump to decimal version
  472.         DoADC_b
  473.         Continue
  474. op_ADC_abs_x_dec:
  475.         DoADC_d
  476.         Continue
  477.  
  478. op_ADC_abs_y:
  479.         GetAbs_Y
  480.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  481.         jc    op_ADC_abs_y_dec    # Yes, jump to decimal version
  482.         DoADC_b
  483.         Continue
  484. op_ADC_abs_y_dec:
  485.         DoADC_d
  486.         Continue
  487.  
  488. op_ADC_ind_x:
  489.         GetIndZPage_X
  490.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  491.         jc    op_ADC_ind_x_dec    # Yes, jump to decimal version
  492.         DoADC_b
  493.         Continue
  494. op_ADC_ind_x_dec:
  495.         DoADC_d
  496.         Continue
  497.  
  498. op_ADC_ind_y:
  499.         GetIndZPage_Y
  500.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  501.         jc    op_ADC_ind_y_dec    # Yes, jump to decimal version
  502.         DoADC_b
  503.         Continue
  504. op_ADC_ind_y_dec:
  505.         DoADC_d
  506.         Continue
  507.  
  508.    /* ----------------------------------
  509.        AND instructions
  510.       ---------------------------------- */
  511.  
  512. op_AND_imm:
  513.         GetImm
  514.         DoAND
  515.         Continue
  516.  
  517. op_AND_zpage:
  518.         GetZPage
  519.         DoAND
  520.         Continue
  521.  
  522. op_AND_zpage_x:
  523.         GetZPage_X
  524.         DoAND
  525.         Continue
  526.  
  527. op_AND_abs:
  528.         GetAbs
  529.         DoAND
  530.         Continue
  531.  
  532. op_AND_abs_x:
  533.         GetAbs_X
  534.         DoAND
  535.         Continue
  536.  
  537. op_AND_abs_y:
  538.         GetAbs_Y
  539.         DoAND
  540.         Continue
  541.  
  542. op_AND_ind_x:
  543.         GetIndZPage_X
  544.         DoAND
  545.         Continue
  546.  
  547. op_AND_ind_y:
  548.         GetIndZPage_Y
  549.         DoAND
  550.         Continue
  551.  
  552.    /* ----------------------------------
  553.        ASL instructions
  554.       ---------------------------------- */
  555.  
  556. op_ASL_acc:
  557.         shlb    $1, A_Reg
  558.         FlagNZC
  559.         Continue
  560.  
  561. op_ASL_zpage:
  562.         GetZPage
  563.         DoASL
  564.         Continue
  565.  
  566. op_ASL_zpage_x:
  567.         GetZPage_X
  568.         DoASL
  569.         Continue
  570.  
  571. op_ASL_abs:
  572.         GetAbs
  573.         DoASL
  574.         Continue
  575.  
  576. op_ASL_abs_x:
  577.         GetAbs_X
  578.         DoASL
  579.         Continue
  580.  
  581.    /* ----------------------------------
  582.        BCC instruction
  583.       ---------------------------------- */
  584.  
  585. op_BCC:
  586.         GetFromPC_B
  587.         bt    C_Flag_Bit, FF_Reg
  588.         jc    op_BCC_not
  589.         cbw
  590.         addw    %ax, PC_Reg
  591. op_BCC_not:
  592.         Continue
  593.  
  594.    /* ----------------------------------
  595.        BCS instruction
  596.       ---------------------------------- */
  597.  
  598. op_BCS:
  599.         GetFromPC_B
  600.         bt    C_Flag_Bit, FF_Reg
  601.         jnc    op_BCS_not
  602.         cbw
  603.         addw    %ax, PC_Reg
  604. op_BCS_not:
  605.         Continue
  606.  
  607.    /* ----------------------------------
  608.        BEQ instruction
  609.       ---------------------------------- */
  610.  
  611. op_BEQ:
  612.         GetFromPC_B
  613.         bt    Z_Flag_Bit, FF_Reg
  614.         jnc    op_BEQ_not
  615.         cbw
  616.         addw    %ax, PC_Reg
  617. op_BEQ_not:
  618.         Continue
  619.  
  620.    /* ----------------------------------
  621.        BIT instructions
  622.       ---------------------------------- */
  623.  
  624. op_BIT_zpage:
  625.         GetZPage
  626.         DoBIT
  627.         Continue
  628.  
  629. op_BIT_abs:
  630.         GetAbs
  631.         DoBIT
  632.         Continue
  633.  
  634.    /* ----------------------------------
  635.        BMI instruction
  636.       ---------------------------------- */
  637.  
  638. op_BMI:
  639.         GetFromPC_B
  640.         bt    N_Flag_Bit, FF_Reg
  641.         jnc    op_BMI_not
  642.         cbw
  643.         addw    %ax, PC_Reg
  644. op_BMI_not:
  645.         Continue
  646.  
  647.    /* ----------------------------------
  648.        BNE instruction
  649.       ---------------------------------- */
  650.  
  651. op_BNE:
  652.         GetFromPC_B
  653.         bt    Z_Flag_Bit, FF_Reg
  654.         jc    op_BNE_not
  655.         cbw
  656.         addw    %ax, PC_Reg
  657. op_BNE_not:
  658.         Continue
  659.  
  660.    /* ----------------------------------
  661.        BPL instruction
  662.       ---------------------------------- */
  663.  
  664. op_BPL:
  665.         GetFromPC_B
  666.         bt    N_Flag_Bit, FF_Reg
  667.         jc    op_BPL_not
  668.         cbw
  669.         addw    %ax, PC_Reg
  670. op_BPL_not:
  671.         Continue
  672.  
  673.    /* ----------------------------------
  674.        BRK instruction
  675.       ---------------------------------- */
  676.  
  677. op_BRK:
  678.         incw    PC_Reg
  679.         movw    PC_Reg, %ax
  680.         Push(%ah)
  681.         Push(%al)
  682.         movb    F_Reg, %al
  683.         bts    B_Flag_Bit, %eax
  684.         bts    X_Flag_Bit, %eax
  685.         xorb    %ah, %ah
  686.         movb    _table_encode_flags(,%eax,1), %al
  687.         Push(%al)
  688.         bts    I_Flag_Bit, FF_Reg
  689.         movw    _apple_ii_64k+0xFFFE, PC_Reg
  690.         Continue
  691.  
  692.    /* ----------------------------------
  693.        BVC instruction
  694.       ---------------------------------- */
  695.  
  696. op_BVC:
  697.         GetFromPC_B
  698.         bt    V_Flag_Bit, FF_Reg
  699.         jc    op_BVC_not
  700.         cbw
  701.         addw    %ax, PC_Reg
  702. op_BVC_not:
  703.         Continue
  704.  
  705.    /* ----------------------------------
  706.        BVS instruction
  707.       ---------------------------------- */
  708.  
  709. op_BVS:
  710.         GetFromPC_B
  711.         bt    V_Flag_Bit, FF_Reg
  712.         jnc    op_BVS_not
  713.         cbw
  714.         addw    %ax, PC_Reg
  715. op_BVS_not:
  716.         Continue
  717.  
  718.    /* ----------------------------------
  719.        CLC instruction
  720.       ---------------------------------- */
  721.  
  722. op_CLC:
  723.         btr    C_Flag_Bit, FF_Reg
  724.         Continue
  725.  
  726.    /* ----------------------------------
  727.        CLD instruction
  728.       ---------------------------------- */
  729.  
  730. op_CLD:
  731.         btr    D_Flag_Bit, FF_Reg
  732.         Continue
  733.  
  734.    /* ----------------------------------
  735.        CLI instruction
  736.       ---------------------------------- */
  737.  
  738. op_CLI:
  739.         btr    I_Flag_Bit, FF_Reg
  740.         Continue
  741.  
  742.    /* ----------------------------------
  743.        CLV instruction
  744.       ---------------------------------- */
  745.  
  746. op_CLV:
  747.         btr    V_Flag_Bit, FF_Reg
  748.         Continue
  749.  
  750.    /* ----------------------------------
  751.        CMP instructions
  752.       ---------------------------------- */
  753.  
  754. op_CMP_imm:
  755.         GetImm
  756.         DoCMP
  757.         Continue
  758.  
  759. op_CMP_zpage:
  760.         GetZPage
  761.         DoCMP
  762.         Continue
  763.  
  764. op_CMP_zpage_x:
  765.         GetZPage_X
  766.         DoCMP
  767.         Continue
  768.  
  769. op_CMP_abs:
  770.         GetAbs
  771.         DoCMP
  772.         Continue
  773.  
  774. op_CMP_abs_x:
  775.         GetAbs_X
  776.         DoCMP
  777.         Continue
  778.  
  779. op_CMP_abs_y:
  780.         GetAbs_Y
  781.         DoCMP
  782.         Continue
  783.  
  784. op_CMP_ind_x:
  785.         GetIndZPage_X
  786.         DoCMP
  787.         Continue
  788.  
  789. op_CMP_ind_y:
  790.         GetIndZPage_Y
  791.         DoCMP
  792.         Continue
  793.  
  794.    /* ----------------------------------
  795.        CPX instructions
  796.       ---------------------------------- */
  797.  
  798. op_CPX_imm:
  799.         GetImm
  800.         DoCPX
  801.         Continue
  802.  
  803. op_CPX_zpage:
  804.         GetZPage
  805.         DoCPX
  806.         Continue
  807.  
  808. op_CPX_abs:
  809.         GetAbs
  810.         DoCPX
  811.         Continue
  812.  
  813.    /* ----------------------------------
  814.        CPY instructions
  815.       ---------------------------------- */
  816.  
  817. op_CPY_imm:
  818.         GetImm
  819.         DoCPY
  820.         Continue
  821.  
  822. op_CPY_zpage:
  823.         GetZPage
  824.         DoCPY
  825.         Continue
  826.  
  827. op_CPY_abs:
  828.         GetAbs
  829.         DoCPY
  830.         Continue
  831.  
  832.    /* ----------------------------------
  833.        DEC instructions
  834.       ---------------------------------- */
  835.  
  836. op_DEC_zpage:
  837.         GetZPage
  838.         DoDEC
  839.         Continue
  840.  
  841. op_DEC_zpage_x:
  842.         GetZPage_X
  843.         DoDEC
  844.         Continue
  845.  
  846. op_DEC_abs:
  847.         GetAbs
  848.         DoDEC
  849.         Continue
  850.  
  851. op_DEC_abs_x:
  852.         GetAbs_X
  853.         DoDEC
  854.         Continue
  855.  
  856.    /* ----------------------------------
  857.        DEX instruction
  858.       ---------------------------------- */
  859.  
  860. op_DEX:
  861.         decb    X_Reg
  862.         FlagNZ
  863.         Continue
  864.  
  865.    /* ----------------------------------
  866.        DEY instruction
  867.       ---------------------------------- */
  868.  
  869. op_DEY:
  870.         decb    Y_Reg
  871.         FlagNZ
  872.         Continue
  873.  
  874.    /* ----------------------------------
  875.        EOR instructions
  876.       ---------------------------------- */
  877.  
  878. op_EOR_imm:
  879.         GetImm
  880.         DoEOR
  881.         Continue
  882.  
  883. op_EOR_zpage:
  884.         GetZPage
  885.         DoEOR
  886.         Continue
  887.  
  888. op_EOR_zpage_x:
  889.         GetZPage_X
  890.         DoEOR
  891.         Continue
  892.  
  893. op_EOR_abs:
  894.         GetAbs
  895.         DoEOR
  896.         Continue
  897.  
  898. op_EOR_abs_x:
  899.         GetAbs_X
  900.         DoEOR
  901.         Continue
  902.  
  903. op_EOR_abs_y:
  904.         GetAbs_Y
  905.         DoEOR
  906.         Continue
  907.  
  908. op_EOR_ind_x:
  909.         GetIndZPage_X
  910.         DoEOR
  911.         Continue
  912.  
  913. op_EOR_ind_y:
  914.         GetIndZPage_Y
  915.         DoEOR
  916.         Continue
  917.  
  918.    /* ----------------------------------
  919.        INC instructions
  920.       ---------------------------------- */
  921.  
  922. op_INC_zpage:
  923.         GetZPage
  924.         DoINC
  925.         Continue
  926.  
  927. op_INC_zpage_x:
  928.         GetZPage_X
  929.         DoINC
  930.         Continue
  931.  
  932. op_INC_abs:
  933.         GetAbs
  934.         DoINC
  935.         Continue
  936.  
  937. op_INC_abs_x:
  938.         GetAbs_X
  939.         DoINC
  940.         Continue
  941.  
  942.    /* ----------------------------------
  943.        INX instruction
  944.       ---------------------------------- */
  945.  
  946. op_INX:
  947.         incb    X_Reg
  948.         FlagNZ
  949.         Continue
  950.  
  951.    /* ----------------------------------
  952.        INY instruction
  953.       ---------------------------------- */
  954.  
  955. op_INY:
  956.         incb    Y_Reg
  957.         FlagNZ
  958.         Continue
  959.  
  960.    /* ----------------------------------
  961.        JMP instructions
  962.       ---------------------------------- */
  963.  
  964. op_JMP_abs:
  965.         GetAbs
  966.         DoJMP
  967.         Continue
  968.  
  969. op_JMP_ind:
  970.         movb    _apple_ii_64k(,PC_Reg_E,1), %al
  971.         cmpb    $0xFF, %al
  972.         je    special_case
  973.         incw    PC_Reg
  974.         movb    _apple_ii_64k(,PC_Reg_E,1), %ah
  975.         movw    _apple_ii_64k(,%eax,1), PC_Reg
  976.         Continue
  977. special_case:
  978.         incw    PC_Reg
  979.         movb    _apple_ii_64k(,PC_Reg_E,1), %ah
  980.         pushl    %ebx
  981.         movb    _apple_ii_64k(,%eax,1), %bl
  982.         incb    %al
  983.         movb    _apple_ii_64k(,%eax,1), %bh
  984.         movw    %bx, PC_Reg
  985.         popl    %ebx
  986.         Continue
  987.  
  988.    /* ----------------------------------
  989.        JSR instruction
  990.       ---------------------------------- */
  991.  
  992. op_JSR:
  993.         GetAbs
  994.         DoJSR
  995.         Continue
  996.  
  997.    /* ----------------------------------
  998.        LDA instructions
  999.       ---------------------------------- */
  1000.  
  1001. op_LDA_imm:
  1002.         GetImm
  1003.         DoLDA
  1004.         Continue
  1005.  
  1006. op_LDA_zpage:
  1007.         GetZPage
  1008.         DoLDA
  1009.         Continue
  1010.  
  1011. op_LDA_zpage_x:
  1012.         GetZPage_X
  1013.         DoLDA
  1014.         Continue
  1015.  
  1016. op_LDA_abs:
  1017.         GetAbs
  1018.         DoLDA
  1019.         Continue
  1020.  
  1021. op_LDA_abs_x:
  1022.         GetAbs_X
  1023.         DoLDA
  1024.         Continue
  1025.  
  1026. op_LDA_abs_y:
  1027.         GetAbs_Y
  1028.         DoLDA
  1029.         Continue
  1030.  
  1031. op_LDA_ind_x:
  1032.         GetIndZPage_X
  1033.         DoLDA
  1034.         Continue
  1035.  
  1036. op_LDA_ind_y:
  1037.         GetIndZPage_Y
  1038.         DoLDA
  1039.         Continue
  1040.  
  1041.    /* ----------------------------------
  1042.        LDX instructions
  1043.       ---------------------------------- */
  1044.  
  1045. op_LDX_imm:
  1046.         GetImm
  1047.         DoLDX
  1048.         Continue
  1049.  
  1050. op_LDX_zpage:
  1051.         GetZPage
  1052.         DoLDX
  1053.         Continue
  1054.  
  1055. op_LDX_zpage_y:
  1056.         GetZPage_Y
  1057.         DoLDX
  1058.         Continue
  1059.  
  1060. op_LDX_abs:
  1061.         GetAbs
  1062.         DoLDX
  1063.         Continue
  1064.  
  1065. op_LDX_abs_y:
  1066.         GetAbs_Y
  1067.         DoLDX
  1068.         Continue
  1069.  
  1070.    /* ----------------------------------
  1071.        LDY instructions
  1072.       ---------------------------------- */
  1073.  
  1074. op_LDY_imm:
  1075.         GetImm
  1076.         DoLDY
  1077.         Continue
  1078.  
  1079. op_LDY_zpage:
  1080.         GetZPage
  1081.         DoLDY
  1082.         Continue
  1083.  
  1084. op_LDY_zpage_x:
  1085.         GetZPage_X
  1086.         DoLDY
  1087.         Continue
  1088.  
  1089. op_LDY_abs:
  1090.         GetAbs
  1091.         DoLDY
  1092.         Continue
  1093.  
  1094. op_LDY_abs_x:
  1095.         GetAbs_X
  1096.         DoLDY
  1097.         Continue
  1098.  
  1099.    /* ----------------------------------
  1100.        LSR instructions
  1101.       ---------------------------------- */
  1102.  
  1103. op_LSR_acc:
  1104.         shrb    $1, A_Reg
  1105.         FlagNZC
  1106.         Continue
  1107.  
  1108. op_LSR_zpage:
  1109.         GetZPage
  1110.         DoLSR
  1111.         Continue
  1112.  
  1113. op_LSR_zpage_x:
  1114.         GetZPage_X
  1115.         DoLSR
  1116.         Continue
  1117.  
  1118. op_LSR_abs:
  1119.         GetAbs
  1120.         DoLSR
  1121.         Continue
  1122.  
  1123. op_LSR_abs_x:
  1124.         GetAbs_X
  1125.         DoLSR
  1126.         Continue
  1127.  
  1128.    /* ----------------------------------
  1129.        NOP instruction
  1130.       ---------------------------------- */
  1131.  
  1132. op_NOP:
  1133.         Continue
  1134.  
  1135.    /* ----------------------------------
  1136.        ORA instructions
  1137.       ---------------------------------- */
  1138.  
  1139. op_ORA_imm:
  1140.         GetImm
  1141.         DoORA
  1142.         Continue
  1143.  
  1144. op_ORA_zpage:
  1145.         GetZPage
  1146.         DoORA
  1147.         Continue
  1148.  
  1149. op_ORA_zpage_x:
  1150.         GetZPage_X
  1151.         DoORA
  1152.         Continue
  1153.  
  1154. op_ORA_abs:
  1155.         GetAbs
  1156.         DoORA
  1157.         Continue
  1158.  
  1159. op_ORA_abs_x:
  1160.         GetAbs_X
  1161.         DoORA
  1162.         Continue
  1163.  
  1164. op_ORA_abs_y:
  1165.         GetAbs_Y
  1166.         DoORA
  1167.         Continue
  1168.  
  1169. op_ORA_ind_x:
  1170.         GetIndZPage_X
  1171.         DoORA
  1172.         Continue
  1173.  
  1174. op_ORA_ind_y:
  1175.         GetIndZPage_Y
  1176.         DoORA
  1177.         Continue
  1178.  
  1179.    /* ----------------------------------
  1180.        PHA instruction
  1181.       ---------------------------------- */
  1182.  
  1183. op_PHA:
  1184.         Push(A_Reg)
  1185.         Continue
  1186.  
  1187.    /* ----------------------------------
  1188.        PHP instruction
  1189.       ---------------------------------- */
  1190.  
  1191. op_PHP:
  1192.         movb    F_Reg, %al
  1193.         bts    X_Flag_Bit, %eax
  1194.         xorb    %ah, %ah
  1195.         movb    _table_encode_flags(,%eax,1), %al
  1196.         Push(%al)
  1197.         Continue
  1198.  
  1199.    /* ----------------------------------
  1200.        PLA instruction
  1201.       ---------------------------------- */
  1202.  
  1203. op_PLA:
  1204.         Pop(A_Reg)
  1205.         orb    A_Reg, A_Reg
  1206.         FlagNZ
  1207.         Continue
  1208.  
  1209.    /* ----------------------------------
  1210.        PLP instruction
  1211.       ---------------------------------- */
  1212.         
  1213. op_PLP:
  1214.         Pop(%al)
  1215.         btr    X_Flag_Bit, %eax
  1216.         xorb    %ah, %ah
  1217.         movb    _table_decode_flags(,%eax,1), F_Reg
  1218.         Continue
  1219.  
  1220.    /* ----------------------------------
  1221.        ROL instructions
  1222.       ---------------------------------- */
  1223.  
  1224. op_ROL_acc:
  1225.         bt    C_Flag_Bit, FF_Reg
  1226.         rclb    $1, A_Reg
  1227.         jc    op_ROL_acc_carry
  1228.         orb    A_Reg, A_Reg
  1229.         clc
  1230.         FlagNZC
  1231.         Continue
  1232. op_ROL_acc_carry:
  1233.         orb    A_Reg, A_Reg
  1234.         stc
  1235.         FlagNZC
  1236.         Continue
  1237.  
  1238. op_ROL_zpage:
  1239.         GetZPage
  1240.         DoROL(rol_zpage, Continue)
  1241.  
  1242. op_ROL_zpage_x:
  1243.         GetZPage_X
  1244.         DoROL(rol_zpage_x, Continue)
  1245.  
  1246. op_ROL_abs:
  1247.         GetAbs
  1248.         DoROL(rol_abs, Continue)
  1249.  
  1250. op_ROL_abs_x:
  1251.         GetAbs_X
  1252.         DoROL(rol_abs_x, Continue)
  1253.  
  1254.    /* ----------------------------------
  1255.        ROR instructions
  1256.       ---------------------------------- */
  1257.  
  1258. op_ROR_acc:
  1259.         bt    C_Flag_Bit, FF_Reg
  1260.         rcrb    $1, A_Reg
  1261.         jc    op_ROR_acc_carry
  1262.         orb    A_Reg, A_Reg
  1263.         clc
  1264.         FlagNZC
  1265.         Continue
  1266. op_ROR_acc_carry:
  1267.         orb    A_Reg, A_Reg
  1268.         stc
  1269.         FlagNZC
  1270.         Continue
  1271.  
  1272. op_ROR_zpage:
  1273.         GetZPage
  1274.         DoROR(ror_zpage, Continue)
  1275.  
  1276. op_ROR_zpage_x:
  1277.         GetZPage_X
  1278.         DoROR(ror_zpage_x, Continue)
  1279.  
  1280. op_ROR_abs:
  1281.         GetAbs
  1282.         DoROR(ror_abs, Continue)
  1283.  
  1284. op_ROR_abs_x:
  1285.         GetAbs_X
  1286.         DoROR(ror_abs_x, Continue)
  1287.  
  1288.    /* ----------------------------------
  1289.        RTI instruction
  1290.       ---------------------------------- */
  1291.  
  1292. op_RTI:
  1293.         Pop(%al)
  1294.         btr    X_Flag_Bit, %eax
  1295.         xorb    %ah, %ah
  1296.         movb    _table_decode_flags(,%eax,1), %al
  1297.         movb    %al, F_Reg
  1298.         Pop(%al)
  1299.         Pop(%ah)
  1300.         movw    %ax, PC_Reg
  1301.         Continue
  1302.  
  1303.    /* ----------------------------------
  1304.        RTS instruction
  1305.       ---------------------------------- */
  1306.  
  1307. op_RTS:
  1308.         Pop(%al)
  1309.         Pop(%ah)
  1310.         incw    %ax
  1311.         movw    %ax, PC_Reg
  1312.         Continue
  1313.  
  1314.    /* ----------------------------------
  1315.        SBC instructions
  1316.       ---------------------------------- */
  1317.  
  1318. op_SBC_imm:
  1319.         GetImm
  1320.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1321.         jc    op_SBC_imm_dec        # Yes, jump to decimal version
  1322.         DoSBC_b
  1323.         Continue
  1324. op_SBC_imm_dec:
  1325.         DoSBC_d
  1326.         Continue
  1327.  
  1328. op_SBC_zpage:
  1329.         GetZPage
  1330.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1331.         jc    op_SBC_zpage_dec    # Yes, jump to decimal version
  1332.         DoSBC_b
  1333.         Continue
  1334. op_SBC_zpage_dec:
  1335.         DoSBC_d
  1336.         Continue
  1337.  
  1338. op_SBC_zpage_x:
  1339.         GetZPage_X
  1340.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1341.         jc    op_SBC_zpage_x_dec    # Yes, jump to decimal version
  1342.         DoSBC_b
  1343.         Continue
  1344. op_SBC_zpage_x_dec:
  1345.         DoSBC_d
  1346.         Continue
  1347.  
  1348. op_SBC_abs:
  1349.         GetAbs
  1350.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1351.         jc    op_SBC_abs_dec        # Yes, jump to decimal version
  1352.         DoSBC_b
  1353.         Continue
  1354. op_SBC_abs_dec:
  1355.         DoSBC_d
  1356.         Continue
  1357.  
  1358. op_SBC_abs_x:
  1359.         GetAbs_X
  1360.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1361.         jc    op_SBC_abs_x_dec    # Yes, jump to decimal version
  1362.         DoSBC_b
  1363.         Continue
  1364. op_SBC_abs_x_dec:
  1365.         DoSBC_d
  1366.         Continue
  1367.  
  1368. op_SBC_abs_y:
  1369.         GetAbs_Y
  1370.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1371.         jc    op_SBC_abs_y_dec    # Yes, jump to decimal version
  1372.         DoSBC_b
  1373.         Continue
  1374. op_SBC_abs_y_dec:
  1375.         DoSBC_d
  1376.         Continue
  1377.  
  1378. op_SBC_ind_x:
  1379.         GetIndZPage_X
  1380.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1381.         jc    op_SBC_ind_x_dec    # Yes, jump to decimal version
  1382.         DoSBC_b
  1383.         Continue
  1384. op_SBC_ind_x_dec:
  1385.         DoSBC_d
  1386.         Continue
  1387.  
  1388. op_SBC_ind_y:
  1389.         GetIndZPage_Y
  1390.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1391.         jc    op_SBC_ind_y_dec    # Yes, jump to decimal version
  1392.         DoSBC_b
  1393.         Continue
  1394. op_SBC_ind_y_dec:
  1395.         DoSBC_d
  1396.         Continue
  1397.  
  1398.    /* ----------------------------------
  1399.        SEC instruction
  1400.       ---------------------------------- */
  1401.  
  1402. op_SEC:
  1403.         bts    C_Flag_Bit, FF_Reg
  1404.         Continue
  1405.  
  1406.    /* ----------------------------------
  1407.        SED instruction
  1408.       ---------------------------------- */
  1409.  
  1410. op_SED:
  1411.         bts    D_Flag_Bit, FF_Reg
  1412.         Continue
  1413.  
  1414.    /* ----------------------------------
  1415.        SEI instruction
  1416.       ---------------------------------- */
  1417.  
  1418. op_SEI:
  1419.         bts    I_Flag_Bit, FF_Reg
  1420.         Continue
  1421.  
  1422.    /* ----------------------------------
  1423.        STA instructions
  1424.       ---------------------------------- */
  1425.  
  1426. op_STA_imm:
  1427.         GetImm
  1428.         DoSTA
  1429.         Continue
  1430.  
  1431. op_STA_zpage:
  1432.         GetZPage
  1433.         DoSTA
  1434.         Continue
  1435.  
  1436. op_STA_zpage_x:
  1437.         GetZPage_X
  1438.         DoSTA
  1439.         Continue
  1440.  
  1441. op_STA_abs:
  1442.         GetAbs
  1443.         DoSTA
  1444.         Continue
  1445.  
  1446. op_STA_abs_x:
  1447.         GetAbs_X
  1448.         DoSTA
  1449.         Continue
  1450.  
  1451. op_STA_abs_y:
  1452.         GetAbs_Y
  1453.         DoSTA
  1454.         Continue
  1455.  
  1456. op_STA_ind_x:
  1457.         GetIndZPage_X
  1458.         DoSTA
  1459.         Continue
  1460.  
  1461. op_STA_ind_y:
  1462.         GetIndZPage_Y
  1463.         DoSTA
  1464.         Continue
  1465.  
  1466.    /* ----------------------------------
  1467.        STX instructions
  1468.       ---------------------------------- */
  1469.  
  1470. op_STX_zpage:
  1471.         GetZPage
  1472.         DoSTX
  1473.         Continue
  1474.  
  1475. op_STX_zpage_y:
  1476.         GetZPage_Y
  1477.         DoSTX
  1478.         Continue
  1479.  
  1480. op_STX_abs:
  1481.         GetAbs
  1482.         DoSTX
  1483.         Continue
  1484.  
  1485.    /* ----------------------------------
  1486.        STY instructions
  1487.       ---------------------------------- */
  1488.  
  1489. op_STY_zpage:
  1490.         GetZPage
  1491.         DoSTY
  1492.         Continue
  1493.  
  1494. op_STY_zpage_x:
  1495.         GetZPage_X
  1496.         DoSTY
  1497.         Continue
  1498.  
  1499. op_STY_abs:
  1500.         GetAbs
  1501.         DoSTY
  1502.         Continue
  1503.  
  1504.    /* ----------------------------------
  1505.        TAX instruction
  1506.       ---------------------------------- */
  1507.  
  1508. op_TAX:
  1509.         movb    A_Reg, X_Reg
  1510.         orb    X_Reg, X_Reg
  1511.         FlagNZ
  1512.         Continue
  1513.  
  1514.    /* ----------------------------------
  1515.        TAY instruction
  1516.       ---------------------------------- */
  1517.  
  1518. op_TAY:
  1519.         movb    A_Reg, Y_Reg
  1520.         orb    Y_Reg, Y_Reg
  1521.         FlagNZ
  1522.         Continue
  1523.  
  1524.    /* ----------------------------------
  1525.        TSX instruction
  1526.       ---------------------------------- */
  1527.  
  1528. op_TSX:
  1529.         movb    SP_Reg_L, X_Reg
  1530.         orb    X_Reg, X_Reg
  1531.         FlagNZ
  1532.         Continue
  1533.  
  1534.    /* ----------------------------------
  1535.        TXA instruction
  1536.       ---------------------------------- */
  1537.  
  1538. op_TXA:
  1539.         movb    X_Reg, A_Reg
  1540.         orb    A_Reg, A_Reg
  1541.         FlagNZ
  1542.         Continue
  1543.  
  1544.    /* ----------------------------------
  1545.        TXS instruction
  1546.       ---------------------------------- */
  1547.  
  1548. op_TXS:
  1549.         movb    X_Reg, SP_Reg_L
  1550.         Continue
  1551.  
  1552.    /* ----------------------------------
  1553.        TYA instruction
  1554.       ---------------------------------- */
  1555.  
  1556. op_TYA:
  1557.         movb    Y_Reg, A_Reg
  1558.         orb    A_Reg, A_Reg
  1559.         FlagNZ
  1560.         Continue
  1561.  
  1562.    /* ----------------------------------------------------------------------
  1563.        Undocumented 6502 (Illegal instructions)
  1564.       ---------------------------------------------------------------------- */
  1565.  
  1566.    /* ----------------------------------
  1567.        HANG instruction
  1568.       ---------------------------------- */
  1569.  
  1570. op_HANG:
  1571.         decb    PC_Reg
  1572.         Continue
  1573.  
  1574.    /* ----------------------------------
  1575.        NOP_2 instruction
  1576.       ---------------------------------- */
  1577.  
  1578. op_NOP_2:
  1579.         incb    PC_Reg
  1580.         Continue
  1581.  
  1582.    /* ----------------------------------
  1583.        NOP_3 instruction
  1584.       ---------------------------------- */
  1585.  
  1586. op_NOP_3:
  1587.         addw    $2, PC_Reg
  1588.         Continue
  1589.  
  1590.    /* ----------------------------------
  1591.        AAX instructions
  1592.       ---------------------------------- */
  1593.  
  1594. op_AAX_abs:
  1595.         GetAbs
  1596.         DoAAX
  1597.         Continue
  1598.  
  1599. op_AAX_zpage:
  1600.         GetZPage
  1601.         DoAAX
  1602.         Continue
  1603.  
  1604. op_AAX_zpage_y:
  1605.         GetZPage_Y
  1606.         DoAAX
  1607.         Continue
  1608.  
  1609. op_AAX_ind_x:
  1610.         GetIndZPage_X
  1611.         DoAAX
  1612.         Continue
  1613.  
  1614. op_AAX_ind_y:
  1615.         GetIndZPage_Y
  1616.         DoAAX
  1617.         Continue
  1618.  
  1619.    /* ----------------------------------
  1620.        AMA instruction
  1621.       ---------------------------------- */
  1622.  
  1623. op_AMA_imm:
  1624.         GetImm
  1625.         DoAMA
  1626.         Continue
  1627.  
  1628.    /* ----------------------------------
  1629.        ANA instruction
  1630.       ---------------------------------- */
  1631.  
  1632. op_ANA_imm:
  1633.         GetImm
  1634.         DoANA(Continue)
  1635.  
  1636.    /* ----------------------------------
  1637.        ANB instruction
  1638.       ---------------------------------- */
  1639.  
  1640. op_ANB_imm:
  1641.         GetImm
  1642.         DoANB(Continue)
  1643.  
  1644.    /* ----------------------------------
  1645.        AXM instruction
  1646.       ---------------------------------- */
  1647.  
  1648. op_AXM_imm:
  1649.         GetImm
  1650.         DoAXM
  1651.         Continue
  1652.  
  1653.    /* ----------------------------------
  1654.        AXS instruction
  1655.       ---------------------------------- */
  1656.  
  1657. op_AXS_abs_y:
  1658.         GetAbs_Y
  1659.         DoAXS
  1660.         Continue
  1661.  
  1662.    /* ----------------------------------
  1663.        DCP instructions
  1664.       ---------------------------------- */
  1665.  
  1666. op_DCP_zpage:
  1667.         GetZPage
  1668.         DoDCP
  1669.         Continue
  1670.  
  1671. op_DCP_zpage_x:
  1672.         GetZPage_X
  1673.         DoDCP
  1674.         Continue
  1675.  
  1676. op_DCP_abs:
  1677.         GetAbs
  1678.         DoDCP
  1679.         Continue
  1680.  
  1681. op_DCP_abs_x:
  1682.         GetAbs_X
  1683.         DoDCP
  1684.         Continue
  1685.  
  1686. op_DCP_abs_y:
  1687.         GetAbs_Y
  1688.         DoDCP
  1689.         Continue
  1690.  
  1691. op_DCP_ind_x:
  1692.         GetIndZPage_X
  1693.         DoDCP
  1694.         Continue
  1695.  
  1696. op_DCP_ind_y:
  1697.         GetIndZPage_Y
  1698.         DoDCP
  1699.         Continue
  1700.  
  1701.    /* ----------------------------------
  1702.        ISB instructions
  1703.       ---------------------------------- */
  1704.  
  1705. op_ISB_dec:
  1706.         DoISB_d
  1707.         Continue
  1708.  
  1709. op_ISB_zpage:
  1710.         GetZPage
  1711.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1712.         jc    op_ISB_dec        # Yes, jump to decimal version
  1713.         DoISB_b
  1714.         Continue
  1715.  
  1716. op_ISB_zpage_x:
  1717.         GetZPage_X
  1718.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1719.         jc    op_ISB_dec        # Yes, jump to decimal version
  1720.         DoISB_b
  1721.         Continue
  1722.  
  1723.  
  1724. op_ISB_abs:
  1725.         GetAbs
  1726.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1727.         jc    op_ISB_dec        # Yes, jump to decimal version
  1728.         DoISB_b
  1729.         Continue
  1730.  
  1731. op_ISB_abs_x:
  1732.         GetAbs_X
  1733.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1734.         jc    op_ISB_dec        # Yes, jump to decimal version
  1735.         DoISB_b
  1736.         Continue
  1737.  
  1738. op_ISB_abs_y:
  1739.         GetAbs_Y
  1740.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1741.         jc    op_ISB_dec        # Yes, jump to decimal version
  1742.         DoISB_b
  1743.         Continue
  1744.  
  1745. op_ISB_ind_x:
  1746.         GetIndZPage_X
  1747.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1748.         jc    op_ISB_dec        # Yes, jump to decimal version
  1749.         DoISB_b
  1750.         Continue
  1751.  
  1752. op_ISB_ind_y:
  1753.         GetIndZPage_Y
  1754.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1755.         jc    op_ISB_dec        # Yes, jump to decimal version
  1756.         DoISB_b
  1757.         Continue
  1758.  
  1759.    /* ----------------------------------
  1760.        LAN instructions
  1761.       ---------------------------------- */
  1762.  
  1763. op_LAN_zpage:
  1764.         GetZPage
  1765.         DoLAN(Continue)
  1766.  
  1767. op_LAN_zpage_x:
  1768.         GetZPage_X
  1769.         DoLAN(Continue)
  1770.  
  1771. op_LAN_abs:
  1772.         GetAbs
  1773.         DoLAN(Continue)
  1774.  
  1775. op_LAN_abs_x:
  1776.         GetAbs_X
  1777.         DoLAN(Continue)
  1778.  
  1779. op_LAN_abs_y:
  1780.         GetAbs_Y
  1781.         DoLAN(Continue)
  1782.  
  1783. op_LAN_ind_x:
  1784.         GetIndZPage_X
  1785.         DoLAN(Continue)
  1786.  
  1787. op_LAN_ind_y:
  1788.         GetIndZPage_Y
  1789.         DoLAN(Continue)
  1790.  
  1791.    /* ----------------------------------
  1792.        LAS instruction
  1793.       ---------------------------------- */
  1794.  
  1795. op_LAS_abs_y:
  1796.         GetAbs_Y
  1797.         DoLAS
  1798.         Continue
  1799.  
  1800.    /* ----------------------------------
  1801.        LAX instructions
  1802.       ---------------------------------- */
  1803.  
  1804. op_LAX_zpage:
  1805.         GetZPage
  1806.         DoLAX
  1807.         Continue
  1808.  
  1809. op_LAX_zpage_y:
  1810.         GetZPage_Y
  1811.         DoLAX
  1812.         Continue
  1813.  
  1814. op_LAX_abs:
  1815.         GetAbs
  1816.         DoLAX
  1817.         Continue
  1818.  
  1819. op_LAX_abs_y:
  1820.         GetAbs_Y
  1821.         DoLAX
  1822.         Continue
  1823.  
  1824. op_LAX_ind_x:
  1825.         GetIndZPage_X
  1826.         DoLAX
  1827.         Continue
  1828.  
  1829. op_LAX_ind_y:
  1830.         GetIndZPage_Y
  1831.         DoLAX
  1832.         Continue
  1833.  
  1834.    /* ----------------------------------
  1835.        LOR instructions
  1836.       ---------------------------------- */
  1837.  
  1838. op_LOR_zpage:
  1839.         GetZPage
  1840.         DoLOR
  1841.         Continue
  1842.  
  1843. op_LOR_zpage_x:
  1844.         GetZPage_X
  1845.         DoLOR
  1846.         Continue
  1847.  
  1848. op_LOR_abs:
  1849.         GetAbs
  1850.         DoLOR
  1851.         Continue
  1852.  
  1853. op_LOR_abs_x:
  1854.         GetAbs_X
  1855.         DoLOR
  1856.         Continue
  1857.  
  1858. op_LOR_abs_y:
  1859.         GetAbs_Y
  1860.         DoLOR
  1861.         Continue
  1862.  
  1863. op_LOR_ind_x:
  1864.         GetIndZPage_X
  1865.         DoLOR
  1866.         Continue
  1867.  
  1868. op_LOR_ind_y:
  1869.         GetIndZPage_Y
  1870.         DoLOR
  1871.         Continue
  1872.  
  1873.    /* ----------------------------------
  1874.        RAD instructions
  1875.       ---------------------------------- */
  1876.  
  1877. op_RAD_dec:
  1878.         DoRAD_d
  1879.         Continue
  1880.  
  1881. op_RAD_zpage:
  1882.         GetZPage
  1883.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1884.         jc    op_RAD_dec        # Yes, jump to decimal version
  1885.         DoRAD_b
  1886.         Continue
  1887.  
  1888. op_RAD_zpage_x:
  1889.         GetZPage_X
  1890.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1891.         jc    op_RAD_dec        # Yes, jump to decimal version
  1892.         DoRAD_b
  1893.         Continue
  1894.  
  1895.  
  1896. op_RAD_abs:
  1897.         GetAbs
  1898.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1899.         jc    op_RAD_dec        # Yes, jump to decimal version
  1900.         DoRAD_b
  1901.         Continue
  1902.  
  1903. op_RAD_abs_x:
  1904.         GetAbs_X
  1905.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1906.         jc    op_RAD_dec        # Yes, jump to decimal version
  1907.         DoRAD_b
  1908.         Continue
  1909.  
  1910. op_RAD_abs_y:
  1911.         GetAbs_Y
  1912.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1913.         jc    op_RAD_dec        # Yes, jump to decimal version
  1914.         DoRAD_b
  1915.         Continue
  1916.  
  1917. op_RAD_ind_x:
  1918.         GetIndZPage_X
  1919.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1920.         jc    op_RAD_dec        # Yes, jump to decimal version
  1921.         DoRAD_b
  1922.         Continue
  1923.  
  1924. op_RAD_ind_y:
  1925.         GetIndZPage_Y
  1926.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1927.         jc    op_RAD_dec        # Yes, jump to decimal version
  1928.         DoRAD_b
  1929.         Continue
  1930.  
  1931.    /* ----------------------------------
  1932.        RAM instruction
  1933.       ---------------------------------- */
  1934.  
  1935. op_RAM_imm:
  1936.         GetImm
  1937.         DoRAM
  1938.         Continue
  1939.  
  1940.    /* ----------------------------------
  1941.        RBM instruction
  1942.       ---------------------------------- */
  1943.  
  1944. op_RBM_imm:
  1945.         GetImm
  1946.         DoRBM
  1947.         Continue
  1948.  
  1949.    /* ----------------------------------
  1950.        REO instructions
  1951.       ---------------------------------- */
  1952.  
  1953. op_REO_zpage:
  1954.         GetZPage
  1955.         DoREO
  1956.         Continue
  1957.  
  1958. op_REO_zpage_x:
  1959.         GetZPage_X
  1960.         DoREO
  1961.         Continue
  1962.  
  1963. op_REO_abs:
  1964.         GetAbs
  1965.         DoREO
  1966.         Continue
  1967.  
  1968. op_REO_abs_x:
  1969.         GetAbs_X
  1970.         DoREO
  1971.         Continue
  1972.  
  1973. op_REO_abs_y:
  1974.         GetAbs_Y
  1975.         DoREO
  1976.         Continue
  1977.  
  1978. op_REO_ind_x:
  1979.         GetIndZPage_X
  1980.         DoREO
  1981.         Continue
  1982.  
  1983. op_REO_ind_y:
  1984.         GetIndZPage_Y
  1985.         DoREO
  1986.         Continue
  1987.  
  1988.    /* ----------------------------------
  1989.        ZBC instruction
  1990.       ---------------------------------- */
  1991.  
  1992. op_ZBC_imm:
  1993.         GetImm
  1994.         bt    D_Flag_Bit, FF_Reg    # Decimal mode?
  1995.         jc    op_ZBC_dec        # Yes, jump to decimal version
  1996.         DoZBC_b
  1997.         Continue
  1998. op_ZBC_dec:
  1999.         DoZBC_d
  2000.         Continue
  2001.  
  2002.    /* ----------------------------------
  2003.        TEA instruction
  2004.       ---------------------------------- */
  2005.  
  2006. op_TEA_abs_y:
  2007.         GetAbs_Y
  2008.         DoTEA
  2009.         Continue
  2010.  
  2011.    /* ----------------------------------
  2012.        TEX instruction
  2013.       ---------------------------------- */
  2014.  
  2015. op_TEX_abs_y:
  2016.         GetAbs_Y
  2017.         DoTEX
  2018.         Continue
  2019.  
  2020.    /* ----------------------------------
  2021.        TEY instruction
  2022.       ---------------------------------- */
  2023.  
  2024. op_TEY_abs_x:
  2025.         GetAbs_X
  2026.         DoTEY
  2027.         Continue
  2028.  
  2029.    /* ----------------------------------
  2030.        XMA instruction
  2031.       ---------------------------------- */
  2032.  
  2033. op_XMA_imm:
  2034.         GetImm
  2035.         DoXMA
  2036.         Continue
  2037.  
  2038.     /* -----------------------------------------------------------------
  2039.         Routine    : update_video_screen
  2040.         Output    : Update video screen
  2041.         Comment    : Scan through entire video memory and call the
  2042.               partial updating routines.
  2043.        ----------------------------------------------------------------- */
  2044.  
  2045.         .globl    _update_video_screen
  2046.         .align 4
  2047. _update_video_screen:
  2048.         pushal
  2049.  
  2050.         call    _c_wait_menu_buf_empty
  2051.         call    _c_lock_menu_mode_on
  2052.  
  2053.         xorl    %eax, %eax
  2054.         xorl    %edi, %edi
  2055.  
  2056.         movl    $23, %ebx
  2057. update_rows_0:
  2058.         movl    $39, %ecx
  2059.         movw    _video_line_offset(,%ebx,2), %di
  2060.         addw    $0x427, %di
  2061. update_columns_0:
  2062.         movb    _apple_ii_64k(,%edi,1), %al
  2063.         cmpb    $19, %bl
  2064.         jg    update_mixed_0
  2065.         call    _write_ram_text_page0
  2066.         jmp    update_cont_0
  2067. update_mixed_0:
  2068.         call    _write_ram_text_mixed0
  2069. update_cont_0:
  2070.         decw    %di
  2071.         decb    %cl
  2072.         jns    update_columns_0
  2073.         decb    %bl
  2074.         jns    update_rows_0
  2075.  
  2076.         movl    $23, %ebx
  2077. update_rows_1:
  2078.         movl    $39, %ecx
  2079.         movw    _video_line_offset(,%ebx,2), %di
  2080.         addw    $0x827, %di
  2081. update_columns_1:
  2082.         movb    _apple_ii_64k(,%edi,1), %al
  2083.         cmpb    $19, %ebx
  2084.         jg    update_mixed_1
  2085.         call    _write_ram_text_page1
  2086.         jmp    update_cont_1
  2087. update_mixed_1:
  2088.         call    _write_ram_text_mixed1
  2089. update_cont_1:
  2090.         decw    %edi
  2091.         decb    %cl
  2092.         jns    update_columns_1
  2093.         decb    %bl
  2094.         jns    update_rows_1
  2095.  
  2096.         movl    $191, %ebx
  2097. update_hires_rows_0:
  2098.         movl    $20, %ecx
  2099.         movl    %ebx, %edx
  2100.         shrb    $3, %dl
  2101.         movw    _video_line_offset(,%edx,2), %di
  2102.         movl    %ebx, %edx
  2103.         andb    $0x7, %dl
  2104.         shlw    $10, %dx
  2105.         addw    $0x2027, %dx
  2106.         addw    %dx, %di
  2107. update_hires_columns_0:
  2108.         movb    _apple_ii_64k(,%edi,1), %al
  2109.         cmpw    $159, %bx
  2110.         jg    update_hires_mixed_0
  2111.         call    _write_ram_hires_page0_odd
  2112.         decw    %di
  2113.         movb    _apple_ii_64k(,%edi,1), %al
  2114.         call    _write_ram_hires_page0_even
  2115.         jmp    update_hires_cont_0
  2116. update_hires_mixed_0:
  2117.         call    _write_ram_hires_mixed0_odd
  2118.         decw    %di
  2119.         movb    _apple_ii_64k(,%edi,1), %al
  2120.         call    _write_ram_hires_mixed0_even
  2121. update_hires_cont_0:
  2122.         decw    %di
  2123.         decb    %cl
  2124.         jnz    update_hires_columns_0
  2125.         decw    %bx
  2126.         jns    update_hires_rows_0
  2127.  
  2128.         movl    $191, %ebx
  2129. update_hires_rows_1:
  2130.         movl    $20, %ecx
  2131.         movl    %ebx, %edx
  2132.         shrb    $3, %dl
  2133.         movw    _video_line_offset(,%edx,2), %di
  2134.         movl    %ebx, %edx
  2135.         andb    $0x7, %dl
  2136.         shlw    $10, %dx
  2137.         addw    $0x4027, %dx
  2138.         addw    %dx, %di
  2139. update_hires_columns_1:
  2140.         movb    _apple_ii_64k(,%edi,1), %al
  2141.         cmpw    $159, %bx
  2142.         jg    update_hires_mixed_1
  2143.         call    _write_ram_hires_page1_odd
  2144.         decw    %di
  2145.         movb    _apple_ii_64k(,%edi,1), %al
  2146.         call    _write_ram_hires_page1_even
  2147.         jmp    update_hires_cont_1
  2148. update_hires_mixed_1:
  2149.         call    _write_ram_hires_mixed1_odd
  2150.         decw    %di
  2151.         movb    _apple_ii_64k(,%edi,1), %al
  2152.         call    _write_ram_hires_mixed1_even
  2153. update_hires_cont_1:
  2154.         decw    %di
  2155.         decb    %cl
  2156.         jnz    update_hires_columns_1
  2157.         decw    %bx
  2158.         jns    update_hires_rows_1
  2159.  
  2160.         call    _c_lock_menu_mode_off
  2161.  
  2162.         popal
  2163.         ret
  2164.  
  2165.     /* --------------------------------------------------------------------
  2166.         Routine    : set_page
  2167.         Input    : AL = Page number (0 or 1)
  2168.         Output    : Current active page bit in video register is set
  2169.               appropriately. EAX destroyed.
  2170.         Usage    : call set_page (with appropriate content in AL).
  2171.         Comment    : The set_page routine sets the appropriate 64K SVGA
  2172.               video write page and updates GM (Graph Memory base
  2173.               address).
  2174.        ----------------------------------------------------------------- */
  2175.  
  2176.         .align 4
  2177. set_page:
  2178.         orb    %al, %al        # Check content of AL
  2179.         movb    %al, _vmode_active
  2180.         jnz    set_page_1        # AL = 1 ?
  2181. set_page_0:
  2182.         pushal
  2183.         pushl    $0
  2184. set_page_01:    call    _c_setpage
  2185.         addl    $4, %esp
  2186.         popal
  2187.         ret
  2188. set_page_1:
  2189.         pushal
  2190.         pushl    $1
  2191.         jmp    set_page_01
  2192.  
  2193.     /* --------------------------------------------------------------------
  2194.         Routine    : read_memory
  2195.         Input    : EffectiveAddr (Currently EDI)
  2196.         Output    : AL = Byte value at 6502 address EffectiveAddr
  2197.                 All other registers are unaffected
  2198.         Usage    : call get_memory (with appropriate content in ESI)
  2199.         Comment    : The get_memory routine uses a jump table (thus
  2200.                       avoiding range checking of particular address areas)
  2201.                       to jump to the appropriate routine given the address.
  2202.                 Hence, the jump table is consisted of 64k addresses
  2203.               (this consumes 256k of memory).
  2204.        ----------------------------------------------------------------- */
  2205.         .align 4
  2206. read_memory:
  2207.         jmp    *_table_read_memory(,EffectiveAddr_E,4)
  2208.  
  2209.     /* --------------------------------------------------------------------
  2210.         Routine    : set_memory
  2211.         Input    : EffectiveAddr (Currently EDI)
  2212.         Output    : AL = Byte value
  2213.                 All other registers are unaffected
  2214.         Usage    : call set_memory (with appropriate content in EDI and
  2215.               AL)
  2216.         Comment    : The set_memory routine uses a jump table (thus
  2217.                       avoiding range checking of particular address areas)
  2218.                       to jump to the appropriate routine given the address.
  2219.                 Hence, the jump table is consisted of 64k addresses
  2220.               (this consumes 256k of memory).
  2221.        ----------------------------------------------------------------- */
  2222.         .align 4
  2223. write_memory:
  2224.         jmp    *_table_write_memory(,EffectiveAddr_E,4)
  2225.  
  2226.         .globl _ram_nop
  2227.         .align 4
  2228. _ram_nop:
  2229.         ret
  2230.  
  2231.         .globl _read_ram_default
  2232.         .align 4
  2233. _read_ram_default:
  2234.         movb    _apple_ii_64k(,EffectiveAddr_E,1), %al
  2235.         ret
  2236.  
  2237.         .globl _write_ram_default
  2238.         .align 4
  2239. _write_ram_default:
  2240.         movb    %al, _apple_ii_64k(,EffectiveAddr_E,1)
  2241.         ret
  2242.  
  2243.         .globl _write_ram_lc
  2244.         .align 4
  2245. _write_ram_lc:
  2246.         subw    $0xE000, EffectiveAddr
  2247.         movb    %al, _language_card(,EffectiveAddr_E,1)
  2248.         ret
  2249.  
  2250.         .globl _write_ram_bank0
  2251.         .align 4
  2252. _write_ram_bank0:
  2253.         subw    $0xD000, EffectiveAddr
  2254.         movb    %al, _language_bank0(,EffectiveAddr_E,1)
  2255.         ret
  2256.  
  2257.         .globl _write_ram_bank1
  2258.         .align 4
  2259. _write_ram_bank1:
  2260.         subw    $0xD000, EffectiveAddr
  2261.         movb    %al, _language_bank1(,EffectiveAddr_E,1)
  2262.         ret
  2263.  
  2264.         .globl _write_ram_text_page0
  2265.         .align 4
  2266. _write_ram_text_page0:
  2267.         movb    %al, _apple_ii_64k(,EffectiveAddr_E,1)
  2268.         testb    $0xFF, _vmode_text # Text mode?
  2269.         jnz    plot_character0
  2270.         testb    $0xFF, _vmode_hires # Hi-res mode?
  2271.         jz    plot_block0
  2272.         ret
  2273.  
  2274.         .globl _write_ram_text_page1
  2275.         .align 4
  2276. _write_ram_text_page1:
  2277.         movb    %al, _apple_ii_64k(,EffectiveAddr_E,1)
  2278.         testb    $0xFF, _vmode_text # Text mode?
  2279.         jnz    plot_character1
  2280.         testb    $0xFF, _vmode_hires # Hi-res mode?
  2281.         jz    plot_block1
  2282.         ret
  2283.  
  2284.         .globl _write_ram_text_mixed0
  2285.         .align 4
  2286. _write_ram_text_mixed0:
  2287.         movb    %al, _apple_ii_64k(,EffectiveAddr_E,1)
  2288.         testb    $0xFF, _vmode_text # Text mode?
  2289.         jnz    plot_character0
  2290.         testb    $0xFF, _vmode_mixed # Mixed mode?
  2291.         jnz    plot_character0
  2292.         testb    $0xFF, _vmode_hires # Not Hi-res mode?
  2293.         jz    plot_block0
  2294.         ret
  2295.  
  2296.         .globl _write_ram_text_mixed1
  2297.         .align 4
  2298. _write_ram_text_mixed1:
  2299.         movb    %al, _apple_ii_64k(,EffectiveAddr_E,1)
  2300.         testb    $0xFF, _vmode_text # Text mode?
  2301.         jnz    plot_character1
  2302.         testb    $0xFF, _vmode_mixed # Mixed mode?
  2303.         jnz    plot_character1
  2304.         testb    $0xFF, _vmode_mixed # Not Hi-res mode?
  2305.         jz    plot_block1
  2306.         ret
  2307.  
  2308.         .globl _write_ram_hires_page0_even
  2309.         .align 4
  2310. _write_ram_hires_page0_even:
  2311.         movb    %al, _apple_ii_64k(,EffectiveAddr_E,1)
  2312.         testb    $0xFF, _vmode_text # Text mode?
  2313.         jnz    no_hires_page0_even_exit
  2314.         testb    $0xFF, _vmode_hires # Hi-res mode?
  2315.         jnz    plot_even_byte0
  2316. no_hires_page0_even_exit:
  2317.         ret
  2318.  
  2319.         .globl _write_ram_hires_mixed0_even
  2320.         .align 4
  2321. _write_ram_hires_mixed0_even:
  2322.         movb    %al, _apple_ii_64k(,EffectiveAddr_E,1)
  2323.         testb    $0xFF, _vmode_text # Text mode?
  2324.         jnz    no_hires_mixed0_even_exit
  2325.         testb    $0xFF, _vmode_mixed # Mixed mode?
  2326.         jnz    no_hires_mixed0_even_exit
  2327.         testb    $0xFF, _vmode_hires # Hi-res mode?
  2328.         jnz    plot_even_byte0
  2329. no_hires_mixed0_even_exit:
  2330.         ret
  2331.  
  2332.         .globl _write_ram_hires_page0_odd
  2333.         .align 4
  2334. _write_ram_hires_page0_odd:
  2335.         movb    %al, _apple_ii_64k(,EffectiveAddr_E,1)
  2336.         testb    $0xFF, _vmode_text # Text mode?
  2337.         jnz    no_hires_page0_odd_exit
  2338.         testb    $0xFF, _vmode_hires # Hi-res mode?
  2339.         jnz    plot_odd_byte0
  2340. no_hires_page0_odd_exit:
  2341.         ret
  2342.  
  2343.         .globl _write_ram_hires_mixed0_odd
  2344.         .align 4
  2345. _write_ram_hires_mixed0_odd:
  2346.         movb    %al, _apple_ii_64k(,EffectiveAddr_E,1)
  2347.         testb    $0xFF, _vmode_text # Text mode?
  2348.         jnz    no_hires_mixed0_odd_exit
  2349.         testb    $0xFF, _vmode_mixed # Mixed mode?
  2350.         jnz    no_hires_mixed0_odd_exit
  2351.         testb    $0xFF, _vmode_hires # Hi-res mode?
  2352.         jnz    plot_odd_byte0
  2353. no_hires_mixed0_odd_exit:
  2354.         ret
  2355.  
  2356.         .globl _write_ram_hires_page1_even
  2357.         .align 4
  2358. _write_ram_hires_page1_even:
  2359.         movb    %al, _apple_ii_64k(,EffectiveAddr_E,1)
  2360.         testb    $0xFF, _vmode_text # Text mode?
  2361.         jnz    no_hires_page1_even_exit
  2362.         testb    $0xFF, _vmode_hires # Hi-res mode?
  2363.         jnz    plot_even_byte1
  2364. no_hires_page1_even_exit:
  2365.         ret
  2366.  
  2367.         .globl _write_ram_hires_mixed1_even
  2368.         .align 4
  2369. _write_ram_hires_mixed1_even:
  2370.         movb    %al, _apple_ii_64k(,EffectiveAddr_E,1)
  2371.         testb    $0xFF, _vmode_text # Text mode?
  2372.         jnz    no_hires_mixed1_even_exit
  2373.         testb    $0xFF, _vmode_mixed # Mixed mode?
  2374.         jnz    no_hires_mixed1_even_exit
  2375.         testb    $0xFF, _vmode_hires # Hi-res mode?
  2376.         jnz    plot_even_byte1
  2377. no_hires_mixed1_even_exit:
  2378.         ret
  2379.  
  2380.         .globl _write_ram_hires_page1_odd
  2381.         .align 4
  2382. _write_ram_hires_page1_odd:
  2383.         movb    %al, _apple_ii_64k(,EffectiveAddr_E,1)
  2384.         testb    $0xFF, _vmode_text # Text mode?
  2385.         jnz    no_hires_page1_odd_exit
  2386.         testb    $0xFF, _vmode_hires # Hi-res mode?
  2387.         jnz    plot_odd_byte1
  2388. no_hires_page1_odd_exit:
  2389.         ret
  2390.  
  2391.         .globl _write_ram_hires_mixed1_odd
  2392.         .align 4
  2393. _write_ram_hires_mixed1_odd:
  2394.         movb    %al, _apple_ii_64k(,EffectiveAddr_E,1)
  2395.         testb    $0xFF, _vmode_text # Text mode?
  2396.         jnz    no_hires_mixed1_odd_exit
  2397.         testb    $0xFF, _vmode_mixed # Mixed mode?
  2398.         jnz    no_hires_mixed1_odd_exit
  2399.         testb    $0xFF, _vmode_hires # Hi-res mode?
  2400.         jnz    plot_odd_byte1
  2401. no_hires_mixed1_odd_exit:
  2402.         ret
  2403.  
  2404.         .align 4
  2405. plot_character0:
  2406.         pushal                    # Save everything
  2407.         xorb    %ah, %ah
  2408.         movl    %eax, %esi            # ESI = EAX = Chr code
  2409.         subw    $0x400, EffectiveAddr        # Normalize screen addr
  2410.         testb    $0xFF, _vmode_active        # Current SVGA page
  2411.         jz    plot_character0_correct_page
  2412.         xorl    %eax, %eax            # Choose page 0
  2413.         call    set_page            # Set page 0
  2414. plot_character0_correct_page:
  2415.         xorl    %eax, %eax
  2416.         movb    _text_page_rows(,EffectiveAddr_E,1), %al  # Compute row
  2417.         leal    (%eax,%eax,4),%eax
  2418.         sall    $9, %eax            # * 2560
  2419.         addl    $1300, %eax            # Adjust to screen
  2420.         xorl    %edx, %edx
  2421.         xorl    %ecx, %ecx
  2422.         movb    _text_page_cols(,EffectiveAddr_E,1), %cl  # Add column
  2423.         movb    %cl, %dl
  2424.         sall    $3, %edx
  2425.         subl    %ecx, %edx
  2426.         addl    %edx, %eax
  2427.         addl    _GM, %eax            # Graphic addr
  2428.         sall    $6, %esi            # * 64
  2429.         addl    $_expanded_font, %esi        # Font addr
  2430.  
  2431.         movl    (%esi), %ecx            # Draw row 0 of chr
  2432.         movl    %ecx, (%eax)
  2433.         addl    $4, %esi
  2434.         addl    $4, %eax
  2435.         movw    (%esi), %cx
  2436.         movw    %cx, (%eax)
  2437.         addl    $2, %esi
  2438.         addl    $2, %eax
  2439.         movb    (%esi), %cl
  2440.         movb    %cl, (%eax)
  2441.         addl    $2, %esi
  2442.         addl    $314, %eax            # Go to next row
  2443.  
  2444.         movl    (%esi), %ecx            # Draw row 1 of chr
  2445.         movl    %ecx, (%eax)
  2446.         addl    $4, %esi
  2447.         addl    $4, %eax
  2448.         movw    (%esi), %cx
  2449.         movw    %cx, (%eax)
  2450.         addl    $2, %esi
  2451.         addl    $2, %eax
  2452.         movb    (%esi), %cl
  2453.         movb    %cl, (%eax)
  2454.         addl    $2, %esi
  2455.         addl    $314, %eax            # Go to next row
  2456.  
  2457.         movl    (%esi), %ecx            # Draw row 2 of chr
  2458.         movl    %ecx, (%eax)
  2459.         addl    $4, %esi
  2460.         addl    $4, %eax
  2461.         movw    (%esi), %cx
  2462.         movw    %cx, (%eax)
  2463.         addl    $2, %esi
  2464.         addl    $2, %eax
  2465.         movb    (%esi), %cl
  2466.         movb    %cl, (%eax)
  2467.         addl    $2, %esi
  2468.         addl    $314, %eax            # Go to next row
  2469.  
  2470.         movl    (%esi), %ecx            # Draw row 3 of chr
  2471.         movl    %ecx, (%eax)
  2472.         addl    $4, %esi
  2473.         addl    $4, %eax
  2474.         movw    (%esi), %cx
  2475.         movw    %cx, (%eax)
  2476.         addl    $2, %esi
  2477.         addl    $2, %eax
  2478.         movb    (%esi), %cl
  2479.         movb    %cl, (%eax)
  2480.         addl    $2, %esi
  2481.         addl    $314, %eax            # Go to next row
  2482.  
  2483.         movl    (%esi), %ecx            # Draw row 4 of chr
  2484.         movl    %ecx, (%eax)
  2485.         addl    $4, %esi
  2486.         addl    $4, %eax
  2487.         movw    (%esi), %cx
  2488.         movw    %cx, (%eax)
  2489.         addl    $2, %esi
  2490.         addl    $2, %eax
  2491.         movb    (%esi), %cl
  2492.         movb    %cl, (%eax)
  2493.         addl    $2, %esi
  2494.         addl    $314, %eax            # Go to next row
  2495.  
  2496.         movl    (%esi), %ecx            # Draw row 5 of chr
  2497.         movl    %ecx, (%eax)
  2498.         addl    $4, %esi
  2499.         addl    $4, %eax
  2500.         movw    (%esi), %cx
  2501.         movw    %cx, (%eax)
  2502.         addl    $2, %esi
  2503.         addl    $2, %eax
  2504.         movb    (%esi), %cl
  2505.         movb    %cl, (%eax)
  2506.         addl    $2, %esi
  2507.         addl    $314, %eax            # Go to next row
  2508.  
  2509.         movl    (%esi), %ecx            # Draw row 6 of chr
  2510.         movl    %ecx, (%eax)
  2511.         addl    $4, %esi
  2512.         addl    $4, %eax
  2513.         movw    (%esi), %cx
  2514.         movw    %cx, (%eax)
  2515.         addl    $2, %esi
  2516.         addl    $2, %eax
  2517.         movb    (%esi), %cl
  2518.         movb    %cl, (%eax)
  2519.         addl    $2, %esi
  2520.         addl    $314, %eax            # Go to next row
  2521.  
  2522.         movl    (%esi), %ecx            # Draw row 7 of chr
  2523.         movl    %ecx, (%eax)
  2524.         addl    $4, %esi
  2525.         addl    $4, %eax
  2526.         movw    (%esi), %cx
  2527.         movw    %cx, (%eax)
  2528.         addl    $2, %esi
  2529.         addl    $2, %eax
  2530.         movb    (%esi), %cl
  2531.         movb    %cl, (%eax)
  2532.         addl    $2, %esi
  2533.  
  2534.         popal
  2535.  
  2536.         ret
  2537.  
  2538.         .align 4
  2539. plot_character1:
  2540.         pushal
  2541.         xorb    %ah, %ah
  2542.         movl    %eax, %esi            # ESI = EAX = Chr Code
  2543.         subw    $0x800, EffectiveAddr        # Normalize screen addr
  2544.         testb    $0xFF, _vmode_active        # Current SVGA page
  2545.         jnz    plot_character0_correct_page
  2546.         movl    $1, %eax
  2547.         call    set_page
  2548.         jmp    plot_character0_correct_page
  2549. plot_block0:
  2550.         pushal                    # Save everything
  2551.         xorb    %ah, %ah
  2552.         movl    %eax, %esi            # ESI = EAX = Chr code
  2553.         subw    $0x400, EffectiveAddr        # Normalize screen addr
  2554.         testb    $0xFF, _vmode_active        # Current SVGA page
  2555.         jz    plot_block0_correct_page
  2556.         xorl    %eax, %eax            # Choose page 0
  2557.         call    set_page            # Set page 0
  2558. plot_block0_correct_page:
  2559.         xorl    %eax, %eax
  2560.         movb    _text_page_rows(,EffectiveAddr_E,1), %al  # Compute row
  2561.         leal    (%eax,%eax,4),%eax
  2562.         sall    $9, %eax            # * 2560
  2563.         addl    $1300, %eax            # Adjust to screen
  2564.         xorl    %edx, %edx
  2565.         xorl    %ecx, %ecx
  2566.         movb    _text_page_cols(,EffectiveAddr_E,1), %cl  # Add column
  2567.         movb    %cl, %dl
  2568.         sall    $3, %edx
  2569.         subl    %ecx, %edx
  2570.         addl    %edx, %eax
  2571.         addl    _GM, %eax            # Graphic addr
  2572.  
  2573.         movl    %esi, %edx            # Compute color
  2574.         andl    $0x0F, %edx
  2575.         movb    %dl, %dh
  2576.         shll    $16, %edx
  2577.         movw    %si, %dx
  2578.         andw    $0x0F, %dx
  2579.         movb    %dl, %dh
  2580.  
  2581.         movl    %edx, (%eax)            # Draw row 0 of blk
  2582.         addl    $4, %eax
  2583.         movw    %dx, (%eax)
  2584.         addl    $2, %eax
  2585.         movb    %dl, (%eax)
  2586.         addl    $314, %eax            # Go to next row
  2587.  
  2588.         movl    %edx, (%eax)            # Draw row 1 of blk
  2589.         addl    $4, %eax
  2590.         movw    %dx, (%eax)
  2591.         addl    $2, %eax
  2592.         movb    %dl, (%eax)
  2593.         addl    $314, %eax            # Go to next row
  2594.  
  2595.         movl    %edx, (%eax)            # Draw row 2 of blk
  2596.         addl    $4, %eax
  2597.         movw    %dx, (%eax)
  2598.         addl    $2, %eax
  2599.         movb    %dl, (%eax)
  2600.         addl    $314, %eax            # Go to next row
  2601.  
  2602.         movl    %edx, (%eax)            # Draw row 3 of blk
  2603.         addl    $4, %eax
  2604.         movw    %dx, (%eax)
  2605.         addl    $2, %eax
  2606.         movb    %dl, (%eax)
  2607.         addl    $314, %eax            # Go to next row
  2608.  
  2609.         movl    %esi, %edx            # Compute color
  2610.         andl    $0xF0, %edx
  2611.         shrb    $4, %dl
  2612.         movb    %dl, %dh
  2613.         shll    $16, %edx
  2614.         movw    %si, %dx
  2615.         andw    $0xF0, %dx
  2616.         shrb    $4, %dl
  2617.         movb    %dl, %dh
  2618.  
  2619.         movl    %edx, (%eax)            # Draw row 4 of blk
  2620.         addl    $4, %eax
  2621.         movw    %dx, (%eax)
  2622.         addl    $2, %eax
  2623.         movb    %dl, (%eax)
  2624.         addl    $314, %eax            # Go to next row
  2625.  
  2626.         movl    %edx, (%eax)            # Draw row 5 of blk
  2627.         addl    $4, %eax
  2628.         movw    %dx, (%eax)
  2629.         addl    $2, %eax
  2630.         movb    %dl, (%eax)
  2631.         addl    $314, %eax            # Go to next row
  2632.  
  2633.         movl    %edx, (%eax)            # Draw row 6 of blk
  2634.         addl    $4, %eax
  2635.         movw    %dx, (%eax)
  2636.         addl    $2, %eax
  2637.         movb    %dl, (%eax)
  2638.         addl    $314, %eax            # Go to next row
  2639.  
  2640.         movl    %edx, (%eax)            # Draw row 7 of blk
  2641.         addl    $4, %eax
  2642.         movw    %dx, (%eax)
  2643.         addl    $2, %eax
  2644.         movb    %dl, (%eax)
  2645.  
  2646.         popal
  2647.         ret
  2648.  
  2649.         .align 4
  2650. plot_block1:    ret
  2651.  
  2652.         .align 4
  2653. plot_even_byte0:
  2654.         testb    $0xFF, _vmode_active        # Current SVGA page
  2655.         jz    plot_even_byte0_correct_page
  2656.         pushal
  2657.         xorl    %eax, %eax            # Choose page 0
  2658.         call    set_page            # Set page 0
  2659.         popal
  2660. plot_even_byte0_correct_page:
  2661.         pushl    %eax
  2662.         pushl    %ebx
  2663.         pushl    %ecx
  2664.  
  2665.         xorb    %ah, %ah
  2666.         leal    _expanded_col_highres_even(,%eax,8), %ebx
  2667.         movl    EffectiveAddr_E, %ecx
  2668.         subw    $0x2000, EffectiveAddr
  2669.         movw    _hires_page_offset(,EffectiveAddr_E,2), %ax
  2670.         movl    %ecx, EffectiveAddr_E
  2671.         addl    _GM, %eax            # Graphic addr
  2672.  
  2673.         movl    (%ebx), %ecx
  2674.         movl    %ecx, (%eax)
  2675.         addl    $4, %eax
  2676.         addl    $4, %ebx
  2677.         movw    (%ebx), %cx
  2678.         movw    %cx, (%eax)
  2679.         addl    $2, %eax
  2680.         addl    $2, %ebx
  2681.         movb    (%ebx), %cl
  2682.         movb    %cl, (%eax)
  2683.  
  2684.         popl    %ecx
  2685.         popl    %ebx
  2686.         popl    %eax
  2687.  
  2688.         ret
  2689.  
  2690.         .align 4
  2691. plot_odd_byte0:
  2692.         testb    $0xFF, _vmode_active        # Current SVGA page
  2693.         jz    plot_odd_byte0_correct_page
  2694.         pushal
  2695.         xorl    %eax, %eax            # Choose page 0
  2696.         call    set_page            # Set page 0
  2697.         popal
  2698. plot_odd_byte0_correct_page:
  2699.         pushl    %eax
  2700.         pushl    %ebx
  2701.         pushl    %ecx
  2702.  
  2703.         xorb    %ah, %ah
  2704.         leal    _expanded_col_highres_odd(,%eax,8), %ebx
  2705.         movl    EffectiveAddr_E, %ecx
  2706.         subw    $0x2000, EffectiveAddr
  2707.         movw    _hires_page_offset(,EffectiveAddr_E,2), %ax
  2708.         movl    %ecx, EffectiveAddr_E
  2709.         addl    _GM, %eax            # Graphic addr
  2710.  
  2711.         movl    (%ebx), %ecx
  2712.         movl    %ecx, (%eax)
  2713.         addl    $4, %eax
  2714.         addl    $4, %ebx
  2715.         movw    (%ebx), %cx
  2716.         movw    %cx, (%eax)
  2717.         addl    $2, %eax
  2718.         addl    $2, %ebx
  2719.         movb    (%ebx), %cl
  2720.         movb    %cl, (%eax)
  2721.  
  2722.         popl    %ecx
  2723.         popl    %ebx
  2724.         popl    %eax
  2725.  
  2726.         ret
  2727.  
  2728.         .align 4
  2729. plot_even_byte1:
  2730.         testb    $0xFF, _vmode_active        # Current SVGA page
  2731.         jnz    plot_even_byte1_correct_page
  2732.         pushal
  2733.         movl    $1, %eax            # Choose page 1
  2734.         call    set_page            # Set page 0
  2735.         popal
  2736. plot_even_byte1_correct_page:
  2737.         pushl    %eax
  2738.         pushl    %ebx
  2739.         pushl    %ecx
  2740.  
  2741.         xorb    %ah, %ah
  2742.         leal    _expanded_col_highres_even(,%eax,8), %ebx
  2743.         movl    EffectiveAddr_E, %ecx
  2744.         subw    $0x4000, EffectiveAddr
  2745.         movw    _hires_page_offset(,EffectiveAddr_E,2), %ax
  2746.         movl    %ecx, EffectiveAddr_E
  2747.         addl    _GM, %eax            # Graphic addr
  2748.  
  2749.         movl    (%ebx), %ecx
  2750.         movl    %ecx, (%eax)
  2751.         addl    $4, %eax
  2752.         addl    $4, %ebx
  2753.         movw    (%ebx), %cx
  2754.         movw    %cx, (%eax)
  2755.         addl    $2, %eax
  2756.         addl    $2, %ebx
  2757.         movb    (%ebx), %cl
  2758.         movb    %cl, (%eax)
  2759.  
  2760.         popl    %ecx
  2761.         popl    %ebx
  2762.         popl    %eax
  2763.  
  2764.         ret
  2765.  
  2766.         .align 4
  2767. plot_odd_byte1:
  2768.         testb    $0xFF, _vmode_active        # Current SVGA page
  2769.         jnz    plot_odd_byte1_correct_page
  2770.         pushal
  2771.         movl    $1, %eax            # Choose page 1
  2772.         call    set_page            # Set page 0
  2773.         popal
  2774. plot_odd_byte1_correct_page:
  2775.         pushl    %eax
  2776.         pushl    %ebx
  2777.         pushl    %ecx
  2778.  
  2779.         xorb    %ah, %ah
  2780.         leal    _expanded_col_highres_odd(,%eax,8), %ebx
  2781.         movl    EffectiveAddr_E, %ecx
  2782.         subw    $0x4000, EffectiveAddr
  2783.         movw    _hires_page_offset(,EffectiveAddr_E,2), %ax
  2784.         movl    %ecx, EffectiveAddr_E
  2785.         addl    _GM, %eax            # Graphic addr
  2786.  
  2787.         movl    (%ebx), %ecx
  2788.         movl    %ecx, (%eax)
  2789.         addl    $4, %eax
  2790.         addl    $4, %ebx
  2791.         movw    (%ebx), %cx
  2792.         movw    %cx, (%eax)
  2793.         addl    $2, %eax
  2794.         addl    $2, %ebx
  2795.         movb    (%ebx), %cl
  2796.         movb    %cl, (%eax)
  2797.  
  2798.         popl    %ecx
  2799.         popl    %ebx
  2800.         popl    %eax
  2801.  
  2802.         ret
  2803.  
  2804.         .globl _read_keyboard
  2805.         .align 4
  2806. _read_keyboard:
  2807.         movb    _apple_ii_64k+0xC000, %al
  2808.             ret
  2809.  
  2810.         .globl _read_keyboard_strobe
  2811.         .align 4
  2812. _read_keyboard_strobe:
  2813.         btr    $7, _apple_ii_64k+0xC000
  2814.         movb    _apple_ii_64k+0xC000, %al
  2815.         ret
  2816.  
  2817.         .globl _read_random
  2818.         .align 4
  2819. _read_random:
  2820.         pushal
  2821.         call    _c_read_random
  2822.         popal
  2823.         movb    _random_value, %al
  2824.         ret
  2825.  
  2826.         .globl _read_speaker_toggle_pc
  2827.         .align 4
  2828. _read_speaker_toggle_pc:
  2829.         inb    $0x61, %al
  2830.         xorb    $0x2, %al
  2831.         outb    %al, $0x61
  2832.         ret
  2833.  
  2834.         .globl _read_switch_primary_page
  2835.         .align 4
  2836. _read_switch_primary_page:
  2837.         testb    $0xFF, _vmode_page2
  2838.         jnz    _read_switch_primary
  2839.         ret
  2840. _read_switch_primary:
  2841.         movb    $0, _vmode_page2
  2842.         pushal
  2843.         pushl    $0x0
  2844.         call    _c_setscreen
  2845.         addl    $4, %esp
  2846.         popal
  2847.         ret
  2848.  
  2849.         .globl _read_switch_secondary_page
  2850.         .align 4
  2851. _read_switch_secondary_page:
  2852.         testb    $0xFF, _vmode_page2
  2853.         jz    _read_switch_secondary
  2854.         ret
  2855. _read_switch_secondary:
  2856.         movb    $1, _vmode_page2
  2857.         pushal
  2858.         pushl    $1
  2859.         call    _c_setscreen
  2860.         addl    $4, %esp
  2861.         popal
  2862.         ret
  2863.  
  2864.         .globl _read_switch_graphics
  2865.         .align 4
  2866. _read_switch_graphics:
  2867.         testb    $0xFF, _vmode_text
  2868.         jz    switch_graphics_exit
  2869.         movb    $0, _vmode_text
  2870.         call    _update_video_screen
  2871. switch_graphics_exit:
  2872.         ret        
  2873.  
  2874.         .globl _read_switch_text
  2875.         .align 4
  2876. _read_switch_text:
  2877.         testb    $0xFF, _vmode_text
  2878.         jnz    switch_text_exit
  2879.         movb    $1, _vmode_text
  2880.         call    _update_video_screen
  2881. switch_text_exit:
  2882.         ret
  2883.  
  2884.         .globl _read_switch_no_mixed
  2885.         .align 4
  2886. _read_switch_no_mixed:
  2887.         testb    $0xFF, _vmode_mixed
  2888.         jz    switch_no_mixed_exit
  2889.         movb    $0, _vmode_mixed
  2890.         call    _update_video_screen
  2891. switch_no_mixed_exit:
  2892.         ret        
  2893.  
  2894.         .globl _read_switch_mixed
  2895.         .align 4
  2896. _read_switch_mixed:
  2897.         testb    $0xFF, _vmode_mixed
  2898.         jnz    switch_mixed_exit
  2899.         movb    $1, _vmode_mixed
  2900.         call    _update_video_screen
  2901. switch_mixed_exit:
  2902.         ret
  2903.  
  2904.         .globl _read_switch_lores
  2905.         .align 4
  2906. _read_switch_lores:
  2907.         testb    $0xFF, _vmode_hires
  2908.         jz    switch_lores_exit
  2909.         movb    $0, _vmode_hires
  2910.         call    _update_video_screen
  2911. switch_lores_exit:
  2912.         ret
  2913.  
  2914.         .globl _read_switch_hires
  2915.         .align 4
  2916. _read_switch_hires:
  2917.         testb    $0xFF, _vmode_hires
  2918.         jnz    switch_hires_exit
  2919.         movb    $1, _vmode_hires
  2920.         call    _update_video_screen
  2921. switch_hires_exit:
  2922.         ret
  2923.  
  2924.         .globl _read_button0
  2925.         .align 4
  2926. _read_button0:
  2927.         movb    _joy_button0, %al
  2928.         ret
  2929.  
  2930.         .globl _read_button1
  2931.         .align 4
  2932. _read_button1:
  2933.         movb    _joy_button1, %al
  2934.         ret
  2935.  
  2936.         .globl _read_button2
  2937.         .align 4
  2938. _read_button2:
  2939.         movb    _joy_button2, %al
  2940.         ret
  2941.  
  2942.         .globl _read_gc0
  2943.         .align 4
  2944. _read_gc0:
  2945.         cmpw    $0xFF, joy_trigger0
  2946.         je    read_gc0_cont
  2947.         incw    joy_trigger0
  2948. read_gc0_cont:
  2949.         movw    joy_trigger0, %ax
  2950.         cmpw    %ax, _joy_x
  2951.         jg    read_gc0_ff
  2952.         movb    $0, %al
  2953.         ret
  2954. read_gc0_ff:
  2955.         movb    $0xFF, %al
  2956.         ret
  2957.  
  2958.         .globl _read_gc1
  2959.         .align 4
  2960. _read_gc1:
  2961.         cmpw    $0xFF, joy_trigger1
  2962.         je    read_gc1_cont
  2963.         incw    joy_trigger1
  2964. read_gc1_cont:
  2965.         movw    joy_trigger1, %ax
  2966.         cmpw    %ax, _joy_y
  2967.         jg    read_gc1_ff
  2968.         movb    $0, %al
  2969.         ret
  2970. read_gc1_ff:
  2971.         movb    $0xFF, %al
  2972.         ret
  2973.  
  2974.         .globl _read_gc_strobe
  2975.         .align 4
  2976. _read_gc_strobe:
  2977.         movb    $0, joy_trigger0
  2978.         movb    $0, joy_trigger1
  2979.         movb    $0, joy_trigger2
  2980.         movb    $0, joy_trigger3
  2981.         ret
  2982.  
  2983.         .globl _lc_c080
  2984.         .align 4
  2985. _lc_c080:
  2986.         movb    $0, _language_card_second
  2987.         cmpb    $0, _language_card_write
  2988.         jz    lc_c080_cont
  2989.         pushal
  2990.         LC_Write_Off
  2991.         movb    $0, _language_card_write
  2992.         popal
  2993. lc_c080_cont:
  2994.         cmpb    $0, _language_card_read
  2995.         jnz    lc_c080_check_bank
  2996.         pushal
  2997.         LC_In
  2998.         LC_Bank0_In
  2999.         movb    $1, _language_card_read
  3000.         movb    $0, _language_current_bank
  3001.         popal
  3002.         ret
  3003. lc_c080_check_bank:
  3004.         cmpb    $0, _language_current_bank
  3005.         jz    lc_c080_bank_ok
  3006.         pushal
  3007.         LC_Bank1_Out
  3008.         LC_Bank0_In
  3009.         movb    $0, _language_current_bank
  3010.         popal
  3011. lc_c080_bank_ok:
  3012.         ret
  3013.  
  3014.         .globl _lc_c081
  3015.         .align 4
  3016. _lc_c081:
  3017.         cmpb    $0, _language_card_read
  3018.         jz    lc_c081_cont
  3019.         movb    $0, _language_card_read
  3020.         pushal
  3021.         LC_Out
  3022.         cmpb    $0, _language_current_bank
  3023.         jnz    lc_c081_bank1
  3024.         LC_Bank0_Out
  3025.         ROM_In
  3026.         popal
  3027.         jmp    lc_c081_cont
  3028. lc_c081_bank1:
  3029.         LC_Bank1_Out
  3030.         ROM_In
  3031.         popal
  3032. lc_c081_cont:
  3033.         cmpb    $0, _language_card_second
  3034.         jz    lc_c081_exit
  3035.         cmpb    $2, _language_card_write
  3036.         je    lc_c081_check_bank
  3037.         pushal
  3038.         LC_Write_Only
  3039.         LC_Write_Only0
  3040.         popal
  3041.         movb    $0, _language_current_bank
  3042.         movb    $2, _language_card_write
  3043.         jmp    lc_c081_exit
  3044. lc_c081_check_bank:
  3045.         cmpb    $0, _language_current_bank
  3046.         jz    lc_c081_exit
  3047.         pushal
  3048.         LC_Write_Only0
  3049.         popal
  3050.         movb    $0, _language_current_bank
  3051. lc_c081_exit:
  3052.         movb    $1, _language_card_second
  3053.         ret
  3054.  
  3055.         .globl _lc_c082
  3056.         .align 4
  3057. _lc_c082:
  3058.         movb    $0, _language_card_second
  3059.         cmpb    $0, _language_card_read
  3060.         jz    lc_c082_cont
  3061.         movb    $0, _language_card_read
  3062.         pushal
  3063.         LC_Out
  3064.         cmpb    $0, _language_current_bank
  3065.         jnz    lc_c082_bank1
  3066.         LC_Bank0_Out
  3067.         ROM_In
  3068.         popal
  3069.         jmp    lc_c082_cont
  3070. lc_c082_bank1:
  3071.         LC_Bank1_Out
  3072.         ROM_In
  3073.         popal
  3074. lc_c082_cont:
  3075.         cmpb    $0, _language_card_write
  3076.         jz    lc_c082_exit
  3077.         pushal
  3078.         LC_Write_Off
  3079.         popal
  3080.         movb    $0, _language_card_write
  3081. lc_c082_exit:
  3082.         ret
  3083.  
  3084.         .globl _lc_c083
  3085.         .align 4
  3086. _lc_c083:
  3087.         cmpb    $0, _language_card_read
  3088.         jnz    lc_c083_check_bank
  3089.         pushal
  3090.         LC_In
  3091.         LC_Bank0_In
  3092.         movb    $1, _language_card_read
  3093.         movb    $0, _language_current_bank
  3094.         popal
  3095.         jmp    lc_c083_cont
  3096. lc_c083_check_bank:
  3097.         cmpb    $0, _language_current_bank
  3098.         jz    lc_c083_cont
  3099.         pushal
  3100.         LC_Bank1_Out
  3101.         LC_Bank0_In
  3102.         movb    $0, _language_current_bank
  3103.         popal
  3104. lc_c083_cont:
  3105.         cmpb    $0, _language_card_second
  3106.         jz    lc_c083_exit
  3107.         cmpb    $1, _language_card_write
  3108.         je    lc_c083_exit
  3109.         pushal
  3110.         LC_Write_On
  3111.         movb    $1, _language_card_write
  3112.         popal
  3113. lc_c083_exit:
  3114.         movb    $1, _language_card_second
  3115.         ret
  3116.  
  3117.         .globl _lc_c088
  3118.         .align 4
  3119. _lc_c088:
  3120.         movb    $0, _language_card_second
  3121.         cmpb    $0, _language_card_write
  3122.         jz    lc_c088_cont
  3123.         pushal
  3124.         LC_Write_Off
  3125.         movb    $0, _language_card_write
  3126.         popal
  3127. lc_c088_cont:
  3128.         cmpb    $0, _language_card_read
  3129.         jnz    lc_c088_check_bank
  3130.         pushal
  3131.         LC_In
  3132.         LC_Bank1_In
  3133.         movb    $1, _language_card_read
  3134.         movb    $1, _language_current_bank
  3135.         popal
  3136.         ret
  3137. lc_c088_check_bank:
  3138.         cmpb    $1, _language_current_bank
  3139.         je    lc_c088_bank_ok
  3140.         pushal
  3141.         LC_Bank0_Out
  3142.         LC_Bank1_In
  3143.         movb    $1, _language_current_bank
  3144.         popal
  3145. lc_c088_bank_ok:
  3146.         ret
  3147.  
  3148.         .globl _lc_c089
  3149.         .align 4
  3150. _lc_c089:
  3151.         cmpb    $0, _language_card_read
  3152.         jz    lc_c089_cont
  3153.         movb    $0, _language_card_read
  3154.         pushal
  3155.         LC_Out
  3156.         cmpb    $0, _language_current_bank
  3157.         jnz    lc_c089_bank1
  3158.         LC_Bank0_Out
  3159.         ROM_In
  3160.         popal
  3161.         jmp    lc_c089_cont
  3162. lc_c089_bank1:
  3163.         LC_Bank1_Out
  3164.         ROM_In
  3165.         popal
  3166. lc_c089_cont:
  3167.         cmpb    $0, _language_card_second
  3168.         jz    lc_c089_exit
  3169.         cmpb    $2, _language_card_write
  3170.         je    lc_c089_check_bank
  3171.         pushal
  3172.         LC_Write_Only
  3173.         LC_Write_Only1
  3174.         popal
  3175.         movb    $1, _language_current_bank
  3176.         movb    $2, _language_card_write
  3177.         jmp    lc_c089_exit
  3178. lc_c089_check_bank:
  3179.         cmpb    $1, _language_current_bank
  3180.         je    lc_c089_exit
  3181.         pushal
  3182.         LC_Write_Only1
  3183.         popal
  3184.         movb    $1, _language_current_bank
  3185. lc_c089_exit:
  3186.         movb    $1, _language_card_second
  3187.         ret
  3188.  
  3189.         .globl _lc_c08a
  3190.         .align 4
  3191. _lc_c08a:
  3192.         movb    $0, _language_card_second
  3193.         cmpb    $0, _language_card_read
  3194.         jz    lc_c08a_cont
  3195.         movb    $0, _language_card_read
  3196.         pushal
  3197.         LC_Out
  3198.         cmpb    $0, _language_current_bank
  3199.         jnz    lc_c08a_bank1
  3200.         LC_Bank0_Out
  3201.         ROM_In
  3202.         popal
  3203.         jmp    lc_c08a_cont
  3204. lc_c08a_bank1:
  3205.         LC_Bank1_Out
  3206.         ROM_In
  3207.         popal
  3208. lc_c08a_cont:
  3209.         cmpb    $0, _language_card_write
  3210.         jz    lc_c08a_exit
  3211.         pushal
  3212.         LC_Write_Off
  3213.         popal
  3214.         movb    $0, _language_card_write
  3215. lc_c08a_exit:
  3216.         ret
  3217.  
  3218.         .globl _lc_c08b
  3219.         .align 4
  3220. _lc_c08b:
  3221.         cmpb    $0, _language_card_read
  3222.         jnz    lc_c08b_check_bank
  3223.         pushal
  3224.         LC_In
  3225.         LC_Bank1_In
  3226.         movb    $1, _language_card_read
  3227.         movb    $1, _language_current_bank
  3228.         popal
  3229.         jmp    lc_c08b_cont
  3230. lc_c08b_check_bank:
  3231.         cmpb    $1, _language_current_bank
  3232.         je    lc_c08b_cont
  3233.         pushal
  3234.         LC_Bank0_Out
  3235.         LC_Bank1_In
  3236.         movb    $1, _language_current_bank
  3237.         popal
  3238. lc_c08b_cont:
  3239.         cmpb    $0, _language_card_second
  3240.         jz    lc_c08b_exit
  3241.         cmpb    $1, _language_card_write
  3242.         je    lc_c08b_exit
  3243.         pushal
  3244.         LC_Write_On
  3245.         movb    $1, _language_card_write
  3246.         popal
  3247. lc_c08b_exit:
  3248.         movb    $1, _language_card_second
  3249.         ret
  3250.  
  3251.  
  3252. .comm        joy_trigger0, 2
  3253. .comm        joy_trigger1, 2
  3254. .comm        joy_trigger2, 2
  3255. .comm        joy_trigger3, 2
  3256.  
  3257.         .globl _test_read_memory
  3258.         .align 4
  3259. _test_read_memory:
  3260.         popl    %edi
  3261.         call    read_memory
  3262.         ret
  3263.  
  3264.         .globl _test_write_memory
  3265.         .align 4
  3266. _test_write_memory:
  3267.         addl    $4, %esp
  3268.         popl    %edi
  3269.         popl    %eax
  3270.         subl    $12, %esp
  3271.         call    write_memory
  3272.         ret
  3273.  
  3274. debug:
  3275.         pushal
  3276.  
  3277.         pushl    %edi
  3278.         pushl    %esi
  3279.         pushl    %edx
  3280.         pushl    %ecx
  3281.         pushl    %ebx
  3282.         pushl    %eax
  3283.  
  3284.         call    _debug
  3285.  
  3286.         addl    $24, %esp
  3287.  
  3288.         popal
  3289.  
  3290.         ret
  3291.  
  3292. z_debug:
  3293.         pushal
  3294.  
  3295.         pushl    %esp
  3296.         pushl    %edi
  3297.         pushl    %esi
  3298.         pushl    %edx
  3299.         pushl    %ecx
  3300.         pushl    %ebx
  3301.         pushl    %eax
  3302.  
  3303.         call    _z_debug
  3304.  
  3305.         addl    $28, %esp
  3306.  
  3307.         popal
  3308.  
  3309.         ret
  3310.  
  3311.