home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / misc / emu / z80 / std_instr.i < prev    next >
Encoding:
Text File  |  1993-12-21  |  36.5 KB  |  2,397 lines

  1. ** The non-implementation-dependent Z80 instructions
  2.  
  3. ** -----------------------------------------------------------------------
  4.  
  5. ** The address register named Work points to a longword called Workspace,
  6. ** which is used for fast temporary storage and byte swaps.
  7.  
  8. ** In order for the parity test to work, bits 8-15 of the tested register
  9. ** must be zero. The V flag (bit 1 of d6) must be clear before executing
  10. ** the macro.
  11.  
  12. ** -----------------------------------------------------------------------
  13.  
  14. ** Following opcodes exactly follow Zaks' "Programming the Z80".
  15. **
  16. **     n  = 8-bit number
  17. **     nn = 16-bit number
  18. **     e  = 8-bit relative jump offset
  19. **     d  = 8-bit displacement
  20. **     pq = 16-bit address
  21. **     p  = 8-bit address
  22. **
  23. ** Label notation:    Underscore used for SPACE, comma and +
  24. **
  25. **             1 (one) used for ( and )
  26.  
  27. ** =======================================================================
  28.  
  29.     IFD VERBOSE
  30.     LIST
  31. ** Compiling the std_instr.i file.
  32.     NOLIST
  33.     ENDC
  34.  
  35.  
  36. adc_A_r     MACRO
  37. Adc_A_\1
  38.     IFD BCDFLAGS
  39.         move.b    A,Z80_BCD_A(TableB)        ;BCD_A=A
  40.         move.b    \1,Z80_BCD_B(TableB)       ;BCD_B=r
  41.         move.w    d6,Z80_BCD_C(TableB)       ;BCD_C=carry
  42.         move.w    #OP_ADC,Z80_BCD_OP(TableB)   ;BCD_OP=adc
  43.     ENDC
  44.         lsr.w    #1,d6    ;carry to X
  45.         ori    #4,CCR    ;set Z
  46.         addx.b    \1,A
  47.         putsr    d6
  48.         next
  49.         ENDM
  50.     do_r adc_A_r
  51. ** --
  52. Adc_A_H     move.w    HL,(Work)
  53.         move.b    (Work),d7
  54.     IFD BCDFLAGS
  55.         move.b    A,Z80_BCD_A(TableB)
  56.         move.b    d7,Z80_BCD_B(TableB)
  57.         move.w    d6,Z80_BCD_C(TableB)
  58.         move.w    #OP_ADC,Z80_BCD_OP(TableB)
  59.     ENDC
  60.         lsr.w    #1,d6
  61.         ori    #4,CCR
  62.         addx.b    d7,A
  63.         putsr    d6
  64.         next
  65. ** --
  66. Adc_A_n     getRPC
  67.         getz    d7,d7
  68.     IFD BCDFLAGS
  69.         move.b    A,Z80_BCD_A(TableB)
  70.         move.b    d7,Z80_BCD_B(TableB)
  71.         move.w    d6,Z80_BCD_C(TableB)
  72.         move.w    #OP_ADC,Z80_BCD_OP(TableB)
  73.     ENDC
  74.         lsr.w    #1,d6
  75.         ori    #4,CCR
  76.         addx.b    d7,A
  77.         putsr    d6
  78.         skip 1
  79.         next
  80. ** --
  81. Adc_A_1HL1    getz    HL,d7
  82.     IFD BCDFLAGS
  83.         move.b    A,Z80_BCD_A(TableB)
  84.         move.b    d7,Z80_BCD_B(TableB)
  85.         move.w    d6,Z80_BCD_C(TableB)
  86.         move.w    #OP_ADC,Z80_BCD_OP(TableB)
  87.     ENDC
  88.         lsr.w    #1,d6
  89.         ori    #4,CCR
  90.         addx.b    d7,A
  91.         putsr    d6
  92.         next
  93. ** --
  94. adc_A_1xy1    MACRO
  95. Adc_A_1I\1_d1    opcode_2_bytes
  96.         index    \1
  97.         getz    d7,d7
  98.     IFD BCDFLAGS
  99.         move.b    A,Z80_BCD_A(TableB)
  100.         move.b    d7,Z80_BCD_B(TableB)
  101.         move.w    d6,Z80_BCD_C(TableB)
  102.         move.w    #OP_ADC,Z80_BCD_OP(TableB)
  103.     ENDC
  104.         lsr.w    #1,d6
  105.         ori    #4,CCR
  106.         addx.b    d7,A
  107.         putsr    d6
  108.         skip 2
  109.         next
  110.         ENDM
  111.     do_xy adc_A_1xy1
  112. ** --
  113. adc_HL_ss    MACRO
  114. Adc_HL_\1\2    opcode_2_bytes
  115.         join    \1,\2
  116.         lsr.w    #1,d6
  117.         ori    #4,CCR
  118.         addx.w    d7,HL
  119.         putsr    d6
  120.         skip 1
  121.         next
  122.         ENDM
  123.     do_ss adc_HL_ss
  124. ** --
  125. Adc_HL_HL    opcode_2_bytes
  126.         lsr.w    #1,d6
  127.         ori    #4,CCR
  128.         addx.w    HL,HL
  129.         putsr    d6
  130.         skip 1
  131.         next
  132. ** --
  133. Adc_HL_SP    opcode_2_bytes
  134.         move.w    ZSP,d7
  135.         lsr.w    #1,d6
  136.         ori    #4,CCR
  137.         addx.w    d7,HL
  138.         putsr    d6
  139.         skip 1
  140.         next
  141. ** --
  142. add_A_r     MACRO
  143. Add_A_\1
  144.     IFD BCDFLAGS
  145.         move.b    A,Z80_BCD_A(TableB)
  146.         move.b    \1,Z80_BCD_B(TableB)
  147.         clr.w    Z80_BCD_OP(TableB)
  148.     ENDC
  149.         add.b    \1,A
  150.         putsr    d6
  151.         next
  152.         ENDM
  153.     do_r add_A_r
  154. ** --
  155. Add_A_H     move.w    HL,(Work)
  156.         move.b    (Work),d7
  157.     IFD BCDFLAGS
  158.         move.b    A,Z80_BCD_A(TableB)
  159.         move.b    d7,Z80_BCD_B(TableB)
  160.         clr.w    Z80_BCD_OP(TableB)
  161.     ENDC
  162.         add.b    d7,A
  163.         putsr    d6
  164.         next
  165. ** --
  166. Add_A_n     getRPC
  167.         getz    d7,d7
  168.     IFD BCDFLAGS
  169.         move.b    A,Z80_BCD_A(TableB)
  170.         move.b    d7,Z80_BCD_B(TableB)
  171.         clr.w    Z80_BCD_OP(TableB)
  172.     ENDC
  173.         add.b    d7,A
  174.         putsr    d6
  175.         skip 1
  176.         next
  177. ** --
  178. Add_A_1HL1    getz    HL,d7
  179.     IFD BCDFLAGS
  180.         move.b    A,Z80_BCD_A(TableB)
  181.         move.b    d7,Z80_BCD_B(TableB)
  182.         clr.w    Z80_BCD_OP(TableB)
  183.     ENDC
  184.         add.b    d7,A
  185.         putsr    d6
  186.         next
  187. ** --
  188. add_A_1xy1    MACRO
  189. Add_A_1I\1_d1    opcode_2_bytes
  190.         index    \1
  191.         getz    d7,d7
  192.     IFD BCDFLAGS
  193.         move.b    A,Z80_BCD_A(TableB)
  194.         move.b    d7,Z80_BCD_B(TableB)
  195.         clr.w    Z80_BCD_OP(TableB)
  196.     ENDC
  197.         add.b    d7,A
  198.         putsr    d6
  199.         skip 2
  200.         next
  201.         ENDM
  202.     do_xy add_A_1xy1
  203. ** --
  204. add_HL_ss    MACRO
  205. Add_HL_\1\2    join    \1,\2
  206.         and.w    #%1110,d6
  207.         add.w    d7,HL
  208.         bcc.s    .cc
  209.         or.w    #1,d6
  210. .cc        next
  211.         ENDM
  212.     do_ss add_HL_ss
  213. ** --
  214. Add_HL_HL    and.w    #%1110,d6
  215.         add.w    HL,HL
  216.         bcc.s    .cc
  217.         or.w    #1,d6
  218. .cc        next
  219. ** --
  220. Add_HL_SP    and.w    #%1110,d6
  221.         add.w    ZSP,HL
  222.         bcc.s    .cc
  223.         or.w    #1,d6
  224. .cc        next
  225. ** --
  226. add_xy_ss    MACRO
  227. Add_I\1_\2\3    opcode_2_bytes
  228.         join    \2,\3
  229.         and.w    #%1110,d6
  230.         add.w    Z80_I\1(TableB),d7
  231.         bcc.s    .cc
  232.         or.w    #1,d6
  233. .cc        move.w    d7,Z80_I\1(TableB)
  234.         skip 1
  235.         next
  236.         ENDM
  237.  
  238. add_xy_xy    MACRO
  239. Add_I\1_I\1    opcode_2_bytes
  240.         and.w    #%1110,d6
  241.         move.w    Z80_I\1(TableB),d7
  242.         add.w    d7,d7
  243.         bcc.s    .cc
  244.         or.w    #1,d6
  245. .cc        move.w    d7,Z80_I\1(TableB)
  246.         skip 1
  247.         next
  248.         ENDM
  249.  
  250. add_xy_SP    MACRO
  251. Add_I\1_SP    opcode_2_bytes
  252.         and.w    #%1110,d6
  253.         move.w    Z80_I\1(TableB),d7
  254.         add.w    ZSP,d7
  255.         bcc.s    .cc
  256.         or.w    #1,d6
  257. .cc        move.w    d7,Z80_I\1(TableB)
  258.         skip 1
  259.         next
  260.         ENDM
  261.  
  262. addxy_xy    MACRO
  263.         add_xy_ss \1,B,C
  264.         add_xy_ss \1,D,E
  265.         add_xy_xy \1
  266.         add_xy_SP \1
  267.         ENDM
  268.     do_xy addxy_xy
  269. ** --
  270. and_r        MACRO
  271. And_\1        and.b    \1,A    ;V is cleared
  272.         putsr    d6
  273.         parity    A
  274.         next
  275.         ENDM
  276.     do_r and_r
  277. ** --
  278. And_H        move.w    HL,(Work)
  279.         and.b    (Work),A
  280.         putsr    d6
  281.         parity    A
  282.         next
  283. ** --
  284. And_n        getRPC
  285.         and.b    (Z0,d7.w),A
  286.         putsr    d6
  287.         parity    A
  288.         skip 1
  289.         next
  290. ** --
  291. And_1HL1    and.b    (Z0,HL.w),A
  292.         putsr    d6
  293.         parity    A
  294.         next
  295. ** --
  296. and_1xy1    MACRO
  297. And_1I\1_d1    opcode_2_bytes
  298.         index    \1
  299.         and.b    (Z0,d7.w),A
  300.         putsr    d6
  301.         parity    A
  302.         skip 2
  303.         next
  304.         ENDM
  305.     do_xy and_1xy1
  306. ** --
  307. bit_b_r     MACRO
  308. Bit_\1_\2    opcode_2_bytes
  309.         or.w    #%0100,d6
  310.         btst    #\1,\2
  311.         beq.s    .z
  312.         and.w    #%1011,d6
  313. .z        skip 1
  314.         next
  315.         ENDM
  316.  
  317. bit_b_H     MACRO
  318. Bit_\1_H    opcode_2_bytes
  319.         or.w    #%0100,d6
  320.         btst    #8+\1,HL
  321.         beq.s    .z
  322.         and.w    #%1011,d6
  323. .z        skip 1
  324.         next
  325.         ENDM
  326.  
  327. bit_b_HL    MACRO
  328. Bit_\1_1HL1    opcode_2_bytes
  329.         or.w    #%0100,d6
  330.         btst    #\1,(Z0,HL.w)
  331.         beq.s    .z
  332.         and.w    #%1011,d6
  333. .z        skip 1
  334.         next
  335.         ENDM
  336.  
  337. bit_b_1xy1    MACRO
  338. Bit_\1_1I\2_d1    opcode_3_bytes
  339.         index    \2
  340.         or.w    #%0100,d6
  341.         btst    #\1,(Z0,d7.w)
  342.         beq.s    .z
  343.         and.w    #%1011,d6
  344. .z        skip 3
  345.         next
  346.         ENDM
  347.  
  348. bit_b        MACRO
  349.     bit_b_r \1,A
  350.     bit_b_r \1,B
  351.     bit_b_r \1,C
  352.     bit_b_r \1,D
  353.     bit_b_r \1,E
  354.     bit_b_r \1,L
  355.     bit_b_H \1
  356.     bit_b_HL \1
  357.     bit_b_1xy1 \1,X
  358.     bit_b_1xy1 \1,Y
  359.         ENDM
  360.  
  361.     bit_b 0
  362.     bit_b 1
  363.     bit_b 2
  364.     bit_b 3
  365.     bit_b 4
  366.     bit_b 5
  367.     bit_b 6
  368.     bit_b 7
  369. ** --
  370. call_cc_pq    MACRO
  371. Call_\1_pq    skip 2
  372.         getsr
  373.         b\2.s    101$    ; 'exit' label in testreq macro
  374.         getRPC
  375.         move.w    d7,(Work)
  376.         decw    ZSP
  377.         putz    (Work),ZSP
  378.         decw    ZSP
  379.         putz    d7,ZSP,2 ;2nd use
  380.         decw    d7
  381.         getz    d7,(Work)
  382.         decw    d7
  383.         getz    d7,1(Work)
  384.         move.w    (Work),d7
  385.         makePPC
  386.         testreq
  387.         ENDM
  388.     call_cc_pq NZ,eq
  389.     call_cc_pq  Z,ne
  390.     call_cc_pq NC,cs
  391.     call_cc_pq  C,cc
  392.     call_cc_pq PO,vs
  393.     call_cc_pq PE,vc
  394.     call_cc_pq  P,mi
  395.     call_cc_pq  M,pl
  396. ** --
  397. Call_pq     getRPC
  398.         addq.w    #2,d7
  399.         move.w    d7,(Work)
  400.         decw    ZSP
  401.         putz    (Work),ZSP
  402.         decw    ZSP
  403.         putz    d7,ZSP,2 ;2nd use
  404.         decw    d7
  405.         getz    d7,(Work)
  406.         decw    d7
  407.         getz    d7,1(Work)
  408.         move.w    (Work),d7
  409.         makePPC
  410.         testreq
  411. ** --
  412. Ccf        eori.w    #1,d6
  413.         next
  414. ** --
  415. cp_r        MACRO
  416. Cp_\1        cmp.b    \1,A
  417.         putsr    d6
  418.         next
  419.         ENDM
  420.     do_r cp_r
  421. ** --
  422. Cp_H        move.w    HL,(Work)
  423.         cmp.b    (Work),A
  424.         putsr    d6
  425.         next
  426. ** --
  427. Cp_n        getRPC
  428.         cmp.b    (Z0,d7.w),A
  429.         putsr    d6
  430.         skip 1
  431.         next
  432. ** --
  433. Cp_1HL1     cmp.b    (Z0,HL.w),A
  434.         putsr    d6
  435.         next
  436. ** --
  437. cp_1xy1     MACRO
  438. Cp_1I\1_d1    opcode_2_bytes
  439.         index    \1
  440.         cmp.b    (Z0,d7.w),A
  441.         putsr    d6
  442.         skip 2
  443.         next
  444.         ENDM
  445.     do_xy cp_1xy1
  446. ** --
  447. Cpd        opcode_2_bytes
  448.         cmp.b    (Z0,HL.w),A
  449.         putsr    d7
  450.         eor.w    d7,d6    ;Join old carry and
  451.         and.w    #1,d6    ; new sign and zero
  452.         eor.w    d7,d6
  453.         or.w    #%0010,d6    ;V set if BC not zero
  454.         decw    HL    ;dec HL
  455.         decb    C
  456.         beq.s    .Cz
  457.         bcc.s    .BCnz    ;if carry, decrement B
  458.         decb    B
  459.         bra.s    .BCnz    ;C<>0, so BC<>0
  460.  
  461. .Cz        tst.b    B
  462.         bne.s    .BCnz
  463.         and.w    #%1101,d6    ;V reset if BC zero
  464. .BCnz        skip 1
  465.         next
  466. ** --
  467. Cpi        opcode_2_bytes
  468.         cmp.b    (Z0,HL.w),A
  469.         putsr    d7
  470.         eor.w    d7,d6    ;Join old carry and
  471.         and.w    #1,d6    ; new sign and zero
  472.         eor.w    d7,d6
  473.         or.w    #%0010,d6    ;V set if BC not zero
  474.         incw    HL    ;dec HL
  475.         decb    C
  476.         beq.s    .Cz
  477.         bcc.s    .BCnz    ;if carry, decrement B
  478.         decb    B
  479.         bra.s    .BCnz    ;C<>0, so BC<>0
  480.  
  481. .Cz        tst.b    B
  482.         bne.s    .BCnz
  483.         and.w    #%1101,d6    ;V reset if BC zero
  484. .BCnz        skip 1
  485.         next
  486. ** --
  487. Cpdr        opcode_2_bytes
  488.         move.b    B,(Work)
  489.         move.w    (Work),B
  490.         move.b    C,B    ;use B (word) as counter
  491. .loop        cmp.b    (Z0,HL.w),A
  492.         putsr    d7
  493.         beq.s    .eq
  494.         decw    HL    ;dec pointer
  495.         decw    B    ;dec counter
  496.         bne.s    .loop
  497. .BCz        and.w    #%1101,d7    ;BC zero, so reset V
  498. .end        eor.w    d7,d6        ;join old carry
  499.         and.w    #1,d6        ; with new N, Z & V
  500.         eor.w    d7,d6
  501.         move.b    B,C    ;BC=counter
  502.         lsr.w    #8,B    ;restore B, zeroing bits 15-8
  503.         skip 1
  504.         next
  505.  
  506. .eq        decw    HL    ;one last dec pointer
  507.         decw    B    ; and dec counter
  508.         beq.s    .BCz
  509.         or.w    #%0010,d7    ;BC not zero, so set V
  510.         bra.s    .end
  511. ** --
  512. Cpir        opcode_2_bytes
  513.         move.b    B,(Work)
  514.         move.w    (Work),B
  515.         move.b    C,B    ;use B (word) as counter
  516. .loop        cmp.b    (Z0,HL.w),A
  517.         putsr    d7
  518.         beq.s    .eq
  519.         incw    HL    ;dec pointer
  520.         decw    B    ;dec counter
  521.         bne.s    .loop
  522. .BCz        and.w    #%1101,d7    ;BC zero, so reset V
  523. .end        eor.w    d7,d6        ;join old carry
  524.         and.w    #1,d6        ; with new N, Z & V
  525.         eor.w    d7,d6
  526.         move.b    B,C    ;BC=counter
  527.         lsr.w    #8,B    ;restore B, zeroing bits 15-8
  528.         skip 1
  529.         next
  530.  
  531. .eq        incw    HL    ;one last dec pointer
  532.         decw    B    ; and dec counter
  533.         beq.s    .BCz
  534.         or.w    #%0010,d7    ;BC not zero, so set V
  535.         bra.s    .end
  536. ** --
  537. Cpl        not.b    A
  538.         next
  539. ** --
  540.  
  541. Daa
  542.     ;bit 15 of BCD_OP is 1 for adc/sbc, otherwise 0.
  543.     ;bit 14 is 0 for add and 1 for sub.
  544.  
  545. OP_ADD = 0    ;clr.w is used in several places
  546. OP_SUB = $4000
  547. OP_ADC = $8000
  548. OP_SBC = $C000
  549.  
  550.     IFD BCDFLAGS
  551.         move.b    Z80_BCD_A(TableB),A        ;get destination
  552.         move.b    Z80_BCD_B(TableB),d7       ;get source
  553.         move.w    Z80_BCD_OP(TableB),d6      ;get operation
  554.         add.w    d6,d6        ;bit 15 to carry, bit 14 to 15
  555.         bcs.s    .c        ;include C if it was set
  556.         move.w    #0,CCR        ;else clear X
  557. .op        tst.w    d6        ;test add/sub bit (X unaffected)
  558.         bmi.s    .sub        ;sub if it was set
  559.         Abcd    d7,A        ;else add (with extend)
  560. .end        putsr    d6
  561.         and.w    #1,d6        ;keep only C (others useless)
  562.         parity    A        ;V of d6 = parity
  563.         tst.b    A        ;V & C of CCR cleared
  564.         putsr    d7
  565.         or.w    d7,d6
  566.         next
  567.  
  568. .sub        Sbcd    d7,A        ;sub (with extend)
  569.         bra.s    .end
  570.  
  571. .c        lsr    Z80_BCD_C(TableB)  ;C to X
  572.         bra.s    .op
  573.     ELSE
  574.         move.w    #-1,Z80_BCD_OP(TableB)    ;"Daa used" marker
  575.         next
  576.     ENDC
  577. ** --
  578. dec_r        MACRO
  579. Dec_\1        decb    \1
  580.         putsr    d7
  581.         eor.w    d7,d6
  582.         and.w    #1,d6    ;keep old carry
  583.         eor.w    d7,d6
  584.         next
  585.         ENDM
  586.     do_r dec_r
  587. ** --
  588. Dec_H        move.w    HL,(Work)
  589.         decb    (Work)
  590.         putsr    d7
  591.         move.w    (Work),HL
  592.         eor.w    d7,d6
  593.         and.w    #1,d6
  594.         eor.w    d7,d6
  595.         next
  596. ** --
  597. Dec_1HL1
  598.     IFD    Z80_MEMCHECK
  599.         getz    HL,(Work)
  600.         subq.b    #1,(Work)
  601.         putsr    d7    ;flags first
  602.         eor.w    d7,d6
  603.         and.w    #1,d6
  604.         eor.w    d7,d6
  605.         putz    (Work),HL       ;then write
  606.     ELSE
  607.         subq.b    #1,(Z0,HL.w)
  608.         putsr    d7
  609.         eor.w    d7,d6
  610.         and.w    #1,d6
  611.         eor.w    d7,d6
  612.     ENDC
  613.         next
  614. ** --
  615. Dec_1xy1    MACRO
  616. Dec_1I\1_d1    opcode_2_bytes
  617.         index    \1
  618.     IFD    Z80_MEMCHECK
  619.         move.w    d7,-(sp)
  620.         getz    d7,(Work)
  621.         subq.b    #1,(Work)
  622.         putsr    d7
  623.         eor.w    d7,d6
  624.         and.w    #1,d6
  625.         eor.w    d7,d6
  626.         move.w    (sp)+,d7
  627.         putz    (Work),d7
  628.     ELSE
  629.         subq.b    #1,(Z0,d7.w)
  630.         putsr    d7
  631.         eor.w    d7,d6
  632.         and.w    #1,d6
  633.         eor.w    d7,d6
  634.     ENDC
  635.         skip 2
  636.         next
  637.         ENDM
  638.     do_xy Dec_1xy1
  639. ** --
  640. dec_rr        MACRO
  641. Dec_\1\2    decb    \2
  642.         bcc.s    .cc
  643.         decb    \1
  644. .cc        next
  645.         ENDM
  646.     do_ss dec_rr
  647. ** --
  648. Dec_HL        decw    HL
  649.         next
  650. ** --
  651. Dec_SP        decw    ZSP
  652.         next
  653. ** --
  654. dec_xy        MACRO
  655. Dec_I\1     opcode_2_bytes
  656.         decw    Z80_I\1(TableB)
  657.         skip 1
  658.         next
  659.         ENDM
  660.     do_xy dec_xy
  661. ** --
  662. Di        clr.b    Z80_IFF(TableB)    ;clear IFF
  663.         next
  664. ** --
  665. Djnz_e        decb    B
  666.         beq.s    .end
  667.         getRPC
  668.         move.w    d7,PPC    ;can't rotate addr.reg.
  669.         getz    PPC,d7
  670.         ext.w    d7
  671.         add.w    PPC,d7
  672.         makePPC
  673. .end        skip 1
  674.         testreq
  675. ** --
  676. Ei        move.b    #$C0,Z80_IFF(TableB)       ;set IFF2 and IFF1
  677.         next
  678. ** --
  679. Ex_AF_AF    move.w    d6,d7
  680.         move.w    Z80_alt_CCR(TableB),d6
  681.         move.w    d7,Z80_alt_CCR(TableB)
  682.         swap    A
  683.         next
  684. ** --
  685. Ex_DE_HL    move.w    HL,d7
  686.         move.b    D,(Work)
  687.         move.w    (Work),HL
  688.         move.b    E,HL
  689.         move.w    d7,(Work)
  690.         move.b    (Work),D
  691.         move.b    d7,E
  692.         next
  693. ** --
  694. Ex_1SP1_HL    getz    ZSP,1(Work)
  695.         incw    ZSP
  696.         getz    ZSP,(Work)
  697.         move.w    (Work),d7
  698.         move.w    HL,(Work)
  699.         putz    (Work),ZSP
  700.         decw    ZSP
  701.         putz    L,ZSP,2 ;2nd use
  702.         move.w    d7,HL
  703.         next
  704. ** --
  705. ex_1SP1_xy    MACRO
  706. Ex_1SP1_I\1    opcode_2_bytes
  707.         getz    ZSP,1(Work)
  708.         incw    ZSP
  709.         getz    ZSP,(Work)
  710.         move.w    (Work),d7
  711.         move.w    Z80_I\1(TableB),(Work)
  712.         putz    (Work),ZSP
  713.         decw    ZSP
  714.         putz    1(Work),ZSP,2 ;2nd use
  715.         move.w    d7,Z80_I\1(TableB)
  716.         skip 1
  717.         next
  718.         ENDM
  719.     do_xy ex_1SP1_xy
  720. ** --
  721. Exx        swap    B
  722.         swap    C
  723.         swap    D
  724.         swap    E
  725.         move.w    Z80_alt_HL(TableB),d7
  726.         move.w    HL,Z80_alt_HL(TableB)
  727.         move.w    d7,HL
  728.         next
  729. ** --
  730. Halt        move.w    Z80_Request(TableB),d7
  731.         beq.s    Halt        ;busy-wait for interrupt
  732.         jmp    (InstrB,d7.w)
  733. ** --
  734. Im_0        opcode_2_bytes
  735.         move.b    #-1,Z80_INTMOD(TableB)    ;Intmode=0
  736.         skip 1
  737.         next
  738. ** --
  739. Im_1        opcode_2_bytes
  740.         clr.b    Z80_INTMOD(TableB)        ;Intmode=1
  741.         skip 1
  742.         next
  743. ** --
  744. Im_2        opcode_2_bytes
  745.         move.b    #1,Z80_INTMOD(TableB)     ;Intmode=2
  746.         skip 1
  747.         next
  748. ** --
  749.  
  750. ** In r,(C) is in 'impldept.a'
  751.  
  752. ** In A,(n) is in 'impldept.a'
  753.  
  754. ** --
  755. inc_r        MACRO
  756. Inc_\1        incb    \1
  757.         putsr    d7
  758.         eor.w    d7,d6
  759.         and.w    #1,d6
  760.         eor.w    d7,d6
  761.         next
  762.         ENDM
  763.     do_r inc_r
  764. ** --
  765. Inc_H        move.w    HL,(Work)
  766.         incb    (Work)
  767.         putsr    d7
  768.         move.w    (Work),HL
  769.         eor.w    d7,d6
  770.         and.w    #1,d6
  771.         eor.w    d7,d6
  772.         next
  773. ** --
  774. Inc_1HL1
  775.     IFD    Z80_MEMCHECK
  776.         getz    HL,(Work)
  777.         addq.b    #1,(Work)
  778.         putsr    d7
  779.         eor.w    d7,d6
  780.         and.w    #1,d6
  781.         eor.w    d7,d6
  782.         putz    (Work),HL
  783.     ELSE
  784.         addq.b    #1,(Z0,HL.w)
  785.         putsr    d7
  786.         eor.w    d7,d6
  787.         and.w    #1,d6
  788.         eor.w    d7,d6
  789.     ENDC
  790.         next
  791. ** --
  792. inc_1xy1    MACRO
  793. Inc_1I\1_d1    opcode_2_bytes
  794.         index    \1
  795.     IFD    Z80_MEMCHECK
  796.         move.w    d7,-(sp)
  797.         getz    d7,(Work)
  798.         addq.b    #1,(Work)
  799.         putsr    d7
  800.         eor.w    d7,d6
  801.         and.w    #1,d6
  802.         eor.w    d7,d6
  803.         move.w    (sp)+,d7
  804.         putz    (Work),d7
  805.     ELSE
  806.         addq.b    #1,(Z0,d7.w)
  807.         putsr    d7
  808.         eor.w    d7,d6
  809.         and.w    #1,d6
  810.         eor.w    d7,d6
  811.     ENDC
  812.         skip 2
  813.         next
  814.         ENDM
  815.     do_xy inc_1xy1
  816. ** --
  817. inc_rr        MACRO
  818. Inc_\1\2    incb    \2
  819.         bcc.s    .cc
  820.         incb    \1
  821. .cc        next
  822.         ENDM
  823.     do_ss inc_rr
  824. ** --
  825. Inc_HL        incw    HL
  826.         next
  827. ** --
  828. Inc_SP        incw    ZSP
  829.         next
  830. ** --
  831. inc_xy        MACRO
  832. Inc_I\1     opcode_2_bytes
  833.         incw    Z80_I\1(TableB)
  834.         skip 1
  835.         next
  836.         ENDM
  837.     do_xy inc_xy
  838. ** --
  839.  
  840. ** Ind, Ini, Indr and Inir are in 'impldept.a'
  841.  
  842. ** --
  843. jp_cc_pq    MACRO
  844. Jp_\1_pq    skip 2
  845.         getsr
  846.         b\2.s    101$    ;label in testreq macro
  847.         getRPC
  848.         decw    d7
  849.         getz    d7,(Work)
  850.         decw    d7
  851.         getz    d7,1(Work)
  852.         move.w    (Work),d7
  853.         makePPC
  854.         testreq
  855.         ENDM
  856.     jp_cc_pq NZ,eq
  857.     jp_cc_pq  Z,ne
  858.     jp_cc_pq NC,cs
  859.     jp_cc_pq  C,cc
  860.     jp_cc_pq PO,vs
  861.     jp_cc_pq PE,vc
  862.     jp_cc_pq  P,mi
  863.     jp_cc_pq  M,pl
  864. ** --
  865. Jp_pq        getRPC
  866.         getz    d7,1(Work)
  867.         incw    d7
  868.         getz    d7,(Work)
  869.         move.w    (Work),d7
  870.         makePPC
  871.         testreq
  872. ** --
  873. Jp_1HL1     lea    (CacheB,HL.w),PPC
  874.         add.w    HL,PPC
  875.         testreq
  876. ** --
  877. jp_1xy1        MACRO
  878. Jp_1I\11    opcode_2_bytes
  879.         move.w    Z80_I\1(TableB),d7
  880.         lea    (CacheB,d7.w),PPC
  881.         add.w    d7,PPC
  882.         testreq
  883.         ENDM
  884.     do_xy jp_1xy1
  885. ** --
  886. jr_cc_e     MACRO
  887. Jr_\1_e     getsr
  888.         b\2.s    .end
  889.         getRPC
  890.         move.w    d7,PPC
  891.         getz    PPC,d7
  892.         ext.w    d7
  893.         add.w    PPC,d7
  894.         makePPC
  895. .end        skip 1
  896.         testreq
  897.         ENDM
  898.     jr_cc_e NZ,eq
  899.     jr_cc_e  Z,ne
  900.     jr_cc_e NC,cs
  901.     jr_cc_e  C,cc
  902. ** --
  903. Jr_e        getRPC
  904.         move.w    d7,PPC
  905.         getz    PPC,d7
  906.         incw    PPC
  907.         ext.w    d7
  908.         add.w    PPC,d7
  909.         makePPC
  910.         testreq
  911. ** --
  912. ld_dd_1nn1    MACRO
  913. Ld_\1\2_1nn1    opcode_2_bytes
  914.         getRPC
  915.         incw    d7
  916.         getz    d7,1(Work)
  917.         incw    d7
  918.         getz    d7,(Work)
  919.         move.w    (Work),d7
  920.         getz    d7,\2
  921.         incw    d7
  922.         getz    d7,\1
  923.         skip 3
  924.         next
  925.         ENDM
  926.     do_ss ld_dd_1nn1
  927. ** --
  928. ED_Ld_HL_1nn1    opcode_2_bytes
  929.         getRPC
  930.         incw    d7
  931.         getz    d7,1(Work)
  932.         incw    d7
  933.         getz    d7,(Work)
  934.         move.w    (Work),d7
  935.         getz    d7,1(Work)
  936.         incw    d7
  937.         getz    d7,(Work)
  938.         move.w    (Work),HL
  939.         skip 3
  940.         next
  941. ** --
  942. Ld_SP_1nn1    opcode_2_bytes
  943.         getRPC
  944.         incw    d7
  945.         getz    d7,1(Work)
  946.         incw    d7
  947.         getz    d7,(Work)
  948.         move.w    (Work),d7
  949.         getz    d7,1(Work)
  950.         incw    d7
  951.         getz    d7,(Work)
  952.         move.w    (Work),ZSP
  953.         skip 3
  954.         next
  955. ** --
  956. ld_dd_nn    MACRO
  957. Ld_\1\2_nn    getRPC
  958.         getz    d7,\2
  959.         incw    d7
  960.         getz    d7,\1
  961.         skip 2
  962.         next
  963.         ENDM
  964.     do_ss ld_dd_nn
  965. ** --
  966. Ld_HL_nn    getRPC
  967.         getz    d7,1(Work)
  968.         incw    d7
  969.         getz    d7,(Work)
  970.         move.w    (Work),HL
  971.         skip 2
  972.         next
  973. ** --
  974. Ld_SP_nn    getRPC
  975.         getz    d7,1(Work)
  976.         incw    d7
  977.         getz    d7,(Work)
  978.         move.w    (Work),ZSP
  979.         skip 2
  980.         next
  981. ** --
  982. ld_r_n        MACRO
  983. Ld_\1_n     getRPC
  984.         getz    d7,\1
  985.         skip 1
  986.         next
  987.         ENDM
  988.     do_r ld_r_n
  989. ** --
  990. Ld_H_n        getRPC
  991.         move.w    HL,(Work)
  992.         getz    d7,(Work)
  993.         move.w    (Work),HL
  994.         skip 1
  995.         next
  996. ** --
  997. ld_r_r        MACRO        ;(Not from/to H)
  998. Ld_\1_\2    move.b    \2,\1
  999.         next
  1000.         ENDM
  1001.  
  1002. ld_r_H        MACRO        ;(Not to H)
  1003. Ld_\1_H     move.w    HL,(Work)
  1004.         move.b    (Work),\1
  1005.         next
  1006.         ENDM
  1007.  
  1008. ldrr_r        MACRO
  1009.     ld_r_r    \1,A
  1010.     ld_r_r    \1,B
  1011.     ld_r_r    \1,C
  1012.     ld_r_r    \1,D
  1013.     ld_r_r    \1,E
  1014.     ld_r_r    \1,L
  1015.     ld_r_H    \1
  1016.         ENDM
  1017.     do_r ldrr_r
  1018.  
  1019. ld_H_regs    MACRO        ;(Not from H)
  1020. Ld_H_\1     move.w    HL,(Work)
  1021.         move.b    \1,(Work)
  1022.         move.w    (Work),HL
  1023.         next
  1024.         ENDM
  1025.     do_r ld_H_regs
  1026.  
  1027. Ld_H_H        next    ;Well, I want to have the label there.
  1028. ** --
  1029. Ld_1BC1_A    join    B,C
  1030.         putz    A,d7
  1031.         next
  1032. ** --
  1033. Ld_1DE1_A    join    D,E
  1034.         putz    A,d7
  1035.         next
  1036. ** --
  1037. Ld_1HL1_n    getRPC
  1038.         putz    <(Z0,d7.w)>,HL
  1039.         skip 1
  1040.         next
  1041. ** --
  1042. ld_1HL1_r    MACRO        ;(Not from H)
  1043. Ld_1HL1_\1    putz    \1,HL
  1044.         next
  1045.         ENDM
  1046.     do_r ld_1HL1_r
  1047. ** --
  1048. Ld_1HL1_H    move.w    HL,(Work)
  1049.         putz    (Work),HL
  1050.         next
  1051. ** --
  1052. ldrxy_r_1xy1    MACRO        ;(Not to H)
  1053. Ld_\1_1I\2_d1    index    \2
  1054.         getz    d7,\1
  1055.         skip 2
  1056.         next
  1057.         ENDM
  1058.  
  1059. ldrxy_H_1xy1    MACRO
  1060. Ld_H_1I\1_d1    opcode_2_bytes
  1061.         index    \1
  1062.         move.w    HL,(Work)
  1063.         getz    d7,(Work)
  1064.         move.w    (Work),HL
  1065.         skip 2
  1066.         next
  1067.         ENDM
  1068.  
  1069. ldrxy_1xy1     MACRO
  1070.     ldrxy_r_1xy1 A,\1
  1071.     ldrxy_r_1xy1 B,\1
  1072.     ldrxy_r_1xy1 C,\1
  1073.     ldrxy_r_1xy1 D,\1
  1074.     ldrxy_r_1xy1 E,\1
  1075.     ldrxy_r_1xy1 L,\1
  1076.     ldrxy_H_1xy1 \1
  1077.         ENDM
  1078.     do_xy ldrxy_1xy1
  1079. ** --
  1080. ld_1xy1_n    MACRO
  1081. Ld_1I\1_d1_n    opcode_2_bytes
  1082.         getRPC
  1083.         addq.w    #2,d7
  1084.         getz    d7,(Work)       ;get data
  1085.         decw    d7
  1086.         getz    d7,d7    ;get offset
  1087.         ext.w    d7
  1088.         add.w    Z80_I\1(TableB),d7
  1089.         putz    (Work),d7
  1090.         skip 3
  1091.         next
  1092.         ENDM
  1093.     do_xy ld_1xy1_n
  1094. ** --
  1095. ldxyr_1xy1_r    MACRO        ;(Not from H)
  1096. Ld_1I\2_d1_\1    opcode_2_bytes
  1097.         index    \2
  1098.         putz    \1,d7
  1099.         skip 2
  1100.         next
  1101.         ENDM
  1102.  
  1103. ldxyr_1xy1_H    MACRO
  1104. Ld_1I\1_d1_H    opcode_2_bytes
  1105.         index    \1
  1106.         move.w    HL,(Work)
  1107.         putz    (Work),d7
  1108.         skip 2
  1109.         next
  1110.         ENDM
  1111.  
  1112. ldxyr_1xy1    MACRO
  1113.     ldxyr_1xy1_r A,\1
  1114.     ldxyr_1xy1_r B,\1
  1115.     ldxyr_1xy1_r C,\1
  1116.     ldxyr_1xy1_r D,\1
  1117.     ldxyr_1xy1_r E,\1
  1118.     ldxyr_1xy1_r L,\1
  1119.     ldxyr_1xy1_H \1
  1120.         ENDM
  1121.     do_xy ldxyr_1xy1
  1122. ** --
  1123. Ld_A_1nn1    getRPC
  1124.         getz    d7,1(Work)
  1125.         incw    d7
  1126.         getz    d7,(Work)
  1127.         move.w    (Work),d7
  1128.         getz    d7,A
  1129.         skip 2
  1130.         next
  1131. ** --
  1132. Ld_1nn1_A    getRPC
  1133.         getz    d7,1(Work)
  1134.         incw    d7
  1135.         getz    d7,(Work)
  1136.         move.w    (Work),d7
  1137.         putz    A,d7
  1138.         skip 2
  1139.         next
  1140. ** --
  1141. ld_1nn1_dd    MACRO
  1142. Ld_1nn1_\1\2    opcode_2_bytes
  1143.         getRPC
  1144.         incw    d7
  1145.         getz    d7,1(Work)
  1146.         incw    d7
  1147.         getz    d7,(Work)
  1148.         move.w    (Work),d7
  1149.         putz    \2,d7
  1150.         incw    d7
  1151.         putz    \1,d7,2 ;2nd use
  1152.         skip 3
  1153.         next
  1154.         ENDM
  1155.     do_ss ld_1nn1_dd
  1156. ** --
  1157. ED_Ld_1nn1_HL    opcode_2_bytes
  1158.         getRPC
  1159.         incw    d7
  1160.         getz    d7,1(Work)
  1161.         incw    d7
  1162.         getz    d7,(Work)
  1163.         move.w    (Work),d7
  1164.         move.w    HL,(Work)
  1165.         putz    HL,d7
  1166.         incw    d7
  1167.         putz    (Work),d7,2 ;2nd use
  1168.         skip 3
  1169.         next
  1170. ** --
  1171. Ld_1nn1_SP    opcode_2_bytes
  1172.         getRPC
  1173.         incw    d7
  1174.         getz    d7,1(Work)
  1175.         incw    d7
  1176.         getz    d7,(Work)
  1177.         move.w    (Work),d7
  1178.         move.w    ZSP,(Work)
  1179.         putz    1(Work),d7
  1180.         incw    d7
  1181.         putz    (Work),d7,2 ;2nd use
  1182.         skip 3
  1183.         next
  1184. ** --
  1185. Ld_1nn1_HL    getRPC        ;the prefixed kind is called ED_Ld_1nn1_HL
  1186.         getz    d7,1(Work)
  1187.         incw    d7
  1188.         getz    d7,(Work)
  1189.         move.w    (Work),d7
  1190.         move.w    HL,(Work)
  1191.         putz    HL,d7
  1192.         incw    d7
  1193.         putz    (Work),d7,2 ;2nd use
  1194.         skip 2
  1195.         next
  1196. ** --
  1197. ld_1nn1_xy    MACRO
  1198. Ld_1nn1_I\1    opcode_2_bytes
  1199.         getRPC
  1200.         getz    d7,1(Work)
  1201.         incw    d7
  1202.         getz    d7,(Work)
  1203.         move.w    (Work),d7
  1204.         move.w    Z80_I\1(TableB),(Work)
  1205.         putz    1(Work),d7
  1206.         incw    d7
  1207.         putz    (Work),d7,2 ;2nd use
  1208.         skip 3
  1209.         next
  1210.         ENDM
  1211.     do_xy ld_1nn1_xy
  1212. ** --
  1213. Ld_A_1BC1    join    B,C
  1214.         getz    d7,A
  1215.         next
  1216. ** --
  1217. Ld_A_1DE1    join    D,E
  1218.         getz    d7,A
  1219.         next
  1220. ** --
  1221. Ld_A_I        opcode_2_bytes
  1222.         move.b    Z80_I(TableB),A    ;V is cleared, Z and N tested.
  1223.         putsr    d7
  1224.         eor.w    d7,d6
  1225.         and.w    #1,d6    ;keep old carry
  1226.         eor.w    d7,d6
  1227.         tst.b    Z80_IFF(TableB)    ;test IFF2
  1228.         bpl.s    .clear
  1229.         or.w    #%0010,d6    ;set V if IFF2 set
  1230. .clear        skip 1
  1231.         next
  1232. ** --
  1233. Ld_I_A        opcode_2_bytes
  1234.         move.b    A,Z80_I(TableB)
  1235.         skip 1
  1236.         next
  1237. ** --
  1238.  
  1239. ** Ld A,R is in 'impldept.a'
  1240.  
  1241. ** --
  1242. Ld_HL_1nn1    getRPC        ;the prefixed kind is called ED_Ld_HL_1nn1
  1243.         getz    d7,1(Work)
  1244.         incw    d7
  1245.         getz    d7,(Work)
  1246.         move.w    (Work),d7
  1247.         incw    d7
  1248.         getz    d7,(Work)
  1249.         move.w    (Work),HL
  1250.         decw    d7
  1251.         getz    d7,HL
  1252.         skip 2
  1253.         next
  1254. ** --
  1255. ld_xy_nn    MACRO
  1256. Ld_I\1_nn    opcode_2_bytes
  1257.         getRPC
  1258.         incw    d7
  1259.         getz    d7,1(Work)
  1260.         incw    d7
  1261.         getz    d7,(Work)
  1262.         move.w    (Work),Z80_I\1(TableB)
  1263.         skip 3
  1264.         next
  1265.         ENDM
  1266.     do_xy ld_xy_nn
  1267. ** --
  1268. ld_xy_1nn1    MACRO
  1269. Ld_I\1_1nn1    opcode_2_bytes
  1270.         getRPC
  1271.         incw    d7
  1272.         getz    d7,1(Work)
  1273.         incw    d7
  1274.         getz    d7,(Work)
  1275.         move.w    (Work),d7
  1276.         getz    d7,1(Work)
  1277.         incw    d7
  1278.         getz    d7,(Work)
  1279.         move.w    (Work),Z80_I\1(TableB)
  1280.         skip 3
  1281.         next
  1282.         ENDM
  1283.     do_xy ld_xy_1nn1
  1284. ** --
  1285.  
  1286. ** Ld R,A is in 'impldept.a'
  1287.  
  1288. ** --
  1289. Ld_SP_HL    move.w    HL,ZSP
  1290.         next
  1291. ** --
  1292. ld_SP_xy    MACRO
  1293. Ld_SP_I\1    opcode_2_bytes
  1294.         move.w    Z80_I\1(TableB),ZSP
  1295.         skip 1
  1296.         next
  1297.         ENDM
  1298.     do_xy ld_SP_xy
  1299. ** --
  1300. Ldd        opcode_2_bytes
  1301.         or.w    #%0010,d6    ;set V
  1302.         join    D,E
  1303.         putz    <(Z0,HL.w)>,d7  ;(HL) -> (DE)
  1304.         decb    E    ;dec DE
  1305.         bcc.s    .nc
  1306.         decb    D
  1307. .nc        decw    HL    ;dec HL
  1308.         decb    C
  1309.         beq.s    .Cz
  1310.         bcc.s    .end
  1311.         decb    B
  1312. .end        skip 1
  1313.         next
  1314.  
  1315. .Cz        tst.b    B
  1316.         bne.s    .end
  1317.         and.w    #%1101,d6    ;BC=0 -> clear V
  1318.         bra.s    .end
  1319. ** --
  1320. Ldi        opcode_2_bytes
  1321.         or.w    #%0010,d6    ;set V
  1322.         join    D,E
  1323.         putz    <(Z0,HL.w)>,d7  ;(HL) -> (DE)
  1324.         incb    E    ;inc DE
  1325.         bcc.s    .nc
  1326.         incb    D
  1327. .nc        incw    HL    ;inc HL
  1328.         decb    C
  1329.         beq.s    .Cz
  1330.         bcc.s    .end
  1331.         decb    B
  1332. .end        skip 1
  1333.         next
  1334.  
  1335. .Cz        tst.b    B
  1336.         bne.s    .end
  1337.         and.w    #%1101,d6    ;BC=0 -> clear V
  1338.         bra.s    .end
  1339. ** --
  1340. Lddr        opcode_2_bytes
  1341.         and.w    #%1101,d6    ;Clear V
  1342.         join    D,E        ;d7 as destination pointer
  1343.         move.b    B,(Work)
  1344.         move.w    (Work),B        ;B (word) as counter
  1345.         move.b    C,B
  1346. .loop        putz    <(Z0,HL.w)>,d7
  1347.         decw    d7    ;dec dest.
  1348.         decw    HL    ;dec source
  1349.         decw    B
  1350.         bne.s    .loop
  1351.         clr.w    C    ;low word of B already 0
  1352.         move.b    d7,E    ;dest. back to D and E
  1353.         move.w    d7,(Work)
  1354.         move.b    (Work),D
  1355.         skip 1
  1356.         next
  1357. ** --
  1358. Ldir        opcode_2_bytes
  1359.         and.w    #%1101,d6    ;Clear V
  1360.         join    D,E        ;d7 as destination pointer
  1361.         move.b    B,(Work)
  1362.         move.w    (Work),B        ;B (word) as counter
  1363.         move.b    C,B
  1364. .loop        putz    <(Z0,HL.w)>,d7
  1365.         incw    d7    ;inc dest.
  1366.         incw    HL    ;inc source
  1367.         decw    B
  1368.         bne.s    .loop
  1369.         clr.w    C    ;low word of B already 0
  1370.         move.b    d7,E    ;dest. back to D and E
  1371.         move.w    d7,(Work)
  1372.         move.b    (Work),D
  1373.         skip 1
  1374.         next
  1375. ** --
  1376. ld_r_1HL1    MACRO        ;(Not to H)
  1377. Ld_\1_1HL1    getz    HL,\1
  1378.         next
  1379.         ENDM
  1380.     do_r ld_r_1HL1
  1381. ** --
  1382. Ld_H_1HL1    move.w    HL,(Work)
  1383.         getz    HL,(Work)
  1384.         move.w    (Work),HL
  1385.         next
  1386. ** --
  1387. Neg        opcode_2_bytes
  1388.     IFD BCDFLAGS
  1389.         clr.b    Z80_BCD_A(TableB)        ;BCD_A=0
  1390.         move.b    A,Z80_BCD_B(TableB)        ;BCD_B=A
  1391.         move.w    #OP_SUB,Z80_BCD_OP(TableB)    ;BCD_OP=sub
  1392.     ENDC
  1393.         neg.b    A
  1394.         putsr    d6
  1395.         skip 1
  1396.         next
  1397. ** --
  1398. Nop        nop    ;Well, why not?
  1399.         next
  1400. ** --
  1401. or_r        MACRO
  1402. Or_\1        or.b    \1,A    ;C and V are reset
  1403.         putsr    d6
  1404.         parity    A
  1405.         next
  1406.         ENDM
  1407.     do_r or_r
  1408. ** --
  1409. Or_H        move.w    HL,(Work)
  1410.         or.b    (Work),A
  1411.         putsr    d6
  1412.         parity    A
  1413.         next
  1414. ** --
  1415. Or_n        getRPC
  1416.         or.b    (Z0,d7.w),A
  1417.         putsr    d6
  1418.         parity    A
  1419.         skip 1
  1420.         next
  1421. ** --
  1422. Or_1HL1     or.b    (Z0,HL.w),A
  1423.         putsr    d6
  1424.         parity    A
  1425.         next
  1426. ** --
  1427. or_1xy1     MACRO
  1428. Or_1I\1_d1    opcode_2_bytes
  1429.         index    \1
  1430.         or.b    (Z0,d7.w),A
  1431.         putsr    d6
  1432.         parity    A
  1433.         skip 2
  1434.         next
  1435.         ENDM
  1436.     do_xy or_1xy1
  1437. ** --
  1438.  
  1439. ** Otdr and Otir are in 'impldept.a'
  1440.  
  1441. ** --
  1442.  
  1443. ** Out (C),r is in 'impldept.a'
  1444.  
  1445. ** Out (n),A is in 'impldept.a'
  1446.  
  1447. ** -
  1448.  
  1449. ** Outd and Outi are in 'impldept.a'
  1450.  
  1451. ** --
  1452. pop_qq        MACRO
  1453. Pop_\1\2    getz    ZSP,\2
  1454.         incw    ZSP
  1455.         getz    ZSP,\1
  1456.         incw    ZSP
  1457.         next
  1458.         ENDM
  1459.     do_ss pop_qq
  1460. ** --
  1461. Pop_HL        getz    ZSP,1(Work)
  1462.         incw    ZSP
  1463.         getz    ZSP,(Work)
  1464.         incw    ZSP
  1465.         move.w    (Work),HL
  1466.         next
  1467. ** --
  1468.     ;Z80 VnCSZ (F) to 680x0 XNZVC (CCR) translation table.
  1469.     ;  N = S.  n (BCD negative) maps to X.
  1470.  
  1471.             ;0, Z,   S,    SZ,  C, CZ,  CS,   CSZ,
  1472. Pop_AF_table    dc.b     0,%100,%1000,%1100,1,%101,%1001,%1101
  1473.         ;n,     nZ,    nS,    nSZ,   nC,    nCZ,   nCS,   nCSZ
  1474.     dc.b    %10000,%10100,%11000,%11100,%10001,%10101,%11001,%11101
  1475.         ;V,  VZ,  VS,   VSZ,  VC, VCZ, VCS,  VCSZ,
  1476.     dc.b    %10,%110,%1010,%1110,%11,%111,%1011,%1111
  1477.         ;Vn,    VnZ,   VnS,   VnSZ,  VnC,   VnCZ,  VnCS,  VnCSZ
  1478.     dc.b    %10010,%10110,%11010,%11110,%10011,%10111,%11011,%11111
  1479.  
  1480. Pop_AF        getz    ZSP,d6
  1481.     IFND AFPUSHPOP_CCR
  1482.     ;Popped was Z80 F format, so remap to CCR-format.
  1483.     ;No information must be lost!
  1484.     ;V=P/V, N=S, n is Z80 BCD negative. h is Z80 bcd half-carry.
  1485.         rol.b    #2,d6    ;SZ-h-VnC -> -h-VnCSZ
  1486.         move.b    d6,d7
  1487.         and.w    #$001F,d7            ;d7 = 000VnCSZ
  1488.         and.w    #%11100000,d6            ;d6 = -h-00000
  1489.         or.b    Pop_AF_table(pc,d7.w),d6    ;d6 = -h-XNZVC
  1490.     ENDC
  1491.         incw    ZSP
  1492.         getz    ZSP,A
  1493.         incw    ZSP
  1494.     IFD BCDFLAGS
  1495.     IFD AFPUSHPOP_BCD
  1496.     ;Stack grows in positive direction. Data size is 6 bytes.
  1497.     ;Pop decrements, then reads.
  1498.         move.w    Z80_BCD_SP(TableB),d7
  1499.         subq.w    #6,d7
  1500.         bcc.s    .nowrap
  1501.         move.w    #6*(Z80_BCDSTACKSIZE-1),d7
  1502. .nowrap        move.w    d7,Z80_BCD_SP(TableB)
  1503.         move.l    Z80_BCDstack(TableB,d7.w),Z80_BCD_DATA(TableB)
  1504.         move.w    Z80_BCDstack+4(TableB,d7.w),Z80_BCD_DATA+4(TableB)
  1505.     ENDC ;IFD AFPUSHPOP_BCD
  1506.     ENDC ;IFD BCDFLAGS
  1507.         next
  1508. ** --
  1509. pop_xy        MACRO
  1510. Pop_I\1     opcode_2_bytes
  1511.         getz    ZSP,1(Work)
  1512.         incw    ZSP
  1513.         getz    ZSP,(Work)
  1514.         incw    ZSP
  1515.         move.w    (Work),Z80_I\1(TableB)
  1516.         skip 1
  1517.         next
  1518.         ENDM
  1519.     do_xy pop_xy
  1520. ** --
  1521. push_qq     MACRO
  1522. Push_\1\2    decw    ZSP
  1523.         putz    \1,ZSP
  1524.         decw    ZSP
  1525.         putz    \2,ZSP,2 ;2nd use
  1526.         next
  1527.         ENDM
  1528.     do_ss push_qq
  1529. ** --
  1530. Push_HL     move.w    HL,(Work)
  1531.         decw    ZSP
  1532.         putz    (Work),ZSP
  1533.         decw    ZSP
  1534.         putz    HL,ZSP,2 ;2nd use
  1535.         next
  1536. ** --
  1537.     ;680x0 XNZVC (CCR) to Z80 VnCSZ (F) translation table.
  1538.     ;  S = N.  X maps to n (BCD negative).
  1539.  
  1540.             ;0,C,   V,     VC,   Z, ZC,  ZV,    ZVC,
  1541. Push_AF_table    dc.b    0,%100,%10000,%10100,1,%101,%10001,%10101
  1542.         ;N, NC,   NV,    NVC,   NZ, NZC, NZV,   NZVC,
  1543.     dc.b    %10,%110,%10010,%10110,%11,%111,%10011,%10111
  1544.         ;X,    XC,   XV,    XVC,   XZ,   XZC,  XZV,   XZVC,
  1545.     dc.b    %1000,%1100,%11000,%11100,%1001,%1101,%11001,%11101
  1546.         ;XN,   XNC,  XNV,   XNVC,  XNZ,  XNZC, XNZV,  XNZVC,
  1547.     dc.b    %1010,%1110,%11010,%11110,%1011,%1111,%11011,%11111
  1548.  
  1549. Push_AF     decw    ZSP
  1550.         putz    A,ZSP
  1551.         decw    ZSP
  1552.     IFND AFPUSHPOP_CCR
  1553.     ;Remap CCR form in d6 to Z80 F-format before pushing.
  1554.     ;No information must be lost!
  1555.     ;V=P/V, N=S, n is Z80 BCD negative. h is Z80 bcd half-carry.
  1556.         move.w    d6,d7
  1557.         swap    d6    ;don't destroy CCR flags
  1558.         move.w    d7,d6
  1559.         and.w    #%11100000,d6            ;d6 = ---00000
  1560.         and.w    #$001F,d7            ;d7 = 000XNZVC
  1561.         or.b    Push_AF_table(pc,d7.w),d6    ;d6 = ---VnCSZ
  1562.         ror.b    #2,d6                ;d6 = SZ---VnC
  1563.         putz    d6,ZSP,2 ;2nd use    ;push F
  1564.         swap    d6    ;restore CCR form
  1565.     ELSE
  1566.     ;Push the CCR directly.
  1567.         putz    d6,ZSP,2 ;2nd use
  1568.     ENDC
  1569.     IFD BCDFLAGS
  1570.     IFD AFPUSHPOP_BCD
  1571.     ;Stack grows in positive direction. Data size is 6 bytes.
  1572.     ;Push stores, then increments.
  1573.         move.w    Z80_BCD_SP(TableB),d7
  1574.         move.l    Z80_BCD_DATA(TableB),Z80_BCDstack(TableB,d7.w)
  1575.         move.w    Z80_BCD_DATA+4(TableB),Z80_BCDstack+4(TableB,d7.w)
  1576.         addq.w    #6,d7
  1577.         cmp.w    #6*Z80_BCDSTACKSIZE,d7
  1578.         blt.s    .nowrap
  1579.         clr.w    d7
  1580. .nowrap        move.w    d7,Z80_BCD_SP(TableB)
  1581.     ENDC ;IFD AFPUSHPOP_BCD
  1582.     ENDC ;IFD BCDFLAGS
  1583.         next
  1584. ** --
  1585. push_xy     MACRO
  1586. Push_I\1    opcode_2_bytes
  1587.         move.w    Z80_I\1(TableB),(Work)
  1588.         decw    ZSP
  1589.         putz    (Work),ZSP
  1590.         decw    ZSP
  1591.         putz    1(Work),ZSP,2 ;2nd use
  1592.         skip 1
  1593.         next
  1594.         ENDM
  1595.     do_xy push_xy
  1596. ** --
  1597. res_b_r     MACRO
  1598. Res_\1_\2    opcode_2_bytes
  1599.         bclr    #\1,\2
  1600.         skip 1
  1601.         next
  1602.         ENDM
  1603.  
  1604. res_b_H     MACRO
  1605. Res_\1_H    opcode_2_bytes
  1606.         bclr    #8+(\1),HL
  1607.         skip 1
  1608.         next
  1609.         ENDM
  1610.  
  1611. res_b_1HL1    MACRO
  1612. Res_\1_1HL1    opcode_2_bytes
  1613.     IFD    Z80_MEMCHECK
  1614.         getz    HL,d7
  1615.         bclr    #\1,d7
  1616.         putz    d7,HL
  1617.     ELSE
  1618.         bclr    #\1,(Z0,HL.w)
  1619.     ENDC
  1620.         skip 1
  1621.         next
  1622.         ENDM
  1623.  
  1624. res_b_1xy1    MACRO
  1625. Res_\1_1I\2_d1    opcode_3_bytes
  1626.         index    \2
  1627.     IFD    Z80_MEMCHECK
  1628.         getz    d7,(Work)
  1629.         bclr    #\1,(Work)
  1630.         putz    (Work),d7
  1631.     ELSE
  1632.         bclr    #\1,(Z0,d7.w)
  1633.     ENDC
  1634.         skip 3
  1635.         next
  1636.         ENDM
  1637.  
  1638. res_b        MACRO
  1639.     res_b_r \1,A
  1640.     res_b_r \1,B
  1641.     res_b_r \1,C
  1642.     res_b_r \1,D
  1643.     res_b_r \1,E
  1644.     res_b_r \1,L
  1645.     res_b_H \1
  1646.     res_b_1HL1 \1
  1647.     res_b_1xy1 \1,X
  1648.     res_b_1xy1 \1,Y
  1649.         ENDM
  1650.  
  1651.     res_b 0
  1652.     res_b 1
  1653.     res_b 2
  1654.     res_b 3
  1655.     res_b 4
  1656.     res_b 5
  1657.     res_b 6
  1658.     res_b 7
  1659. ** --
  1660. Ret        getz    ZSP,1(Work)
  1661.         incw    ZSP
  1662.         getz    ZSP,(Work)
  1663.         incw    ZSP
  1664.         move.w    (Work),d7
  1665.         makePPC
  1666.         testreq
  1667. ** --
  1668. ret_cc        MACRO
  1669. Ret_\1        getsr
  1670.         b\2.s    101$    ;label in testreq macro
  1671.         getz    ZSP,1(Work)
  1672.         incw    ZSP
  1673.         getz    ZSP,(Work)
  1674.         incw    ZSP
  1675.         move.w    (Work),d7
  1676.         makePPC
  1677.         testreq
  1678.         ENDM
  1679.     ret_cc NZ,eq
  1680.     ret_cc    Z,ne
  1681.     ret_cc NC,cs
  1682.     ret_cc    C,cc
  1683.     ret_cc PO,vs
  1684.     ret_cc PE,vc
  1685.     ret_cc    P,mi
  1686.     ret_cc    M,pl
  1687. ** --
  1688.  
  1689. ** Reti and Retn are in 'impldept.a'
  1690.  
  1691. ** --
  1692. rl_r        MACRO
  1693. Rl_\1        opcode_2_bytes
  1694.         lsr.w    #1,d6    ;carry to X
  1695.         roxl.b    #1,\1    ;V cleared
  1696.         putsr    d6
  1697.         parity    \1
  1698.         skip 1
  1699.         next
  1700.         ENDM
  1701.     do_r rl_r
  1702. ** --
  1703. Rl_H        opcode_2_bytes
  1704.         move.w    HL,(Work)
  1705.         clr.w    d7    ;for parity index
  1706.         move.b    (Work),d7
  1707.         lsr.w    #1,d6
  1708.         roxl.b    #1,d7
  1709.         putsr    d6
  1710.         parity    d7
  1711.         move.b    d7,(Work)
  1712.         move.w    (Work),HL
  1713.         skip 1
  1714.         next
  1715. ** --
  1716. Rl_1HL1     opcode_2_bytes
  1717.         clr.w    d7
  1718.         getz    HL,d7
  1719.         lsr.w    #1,d6
  1720.         roxl.b    #1,d7
  1721.         putsr    d6
  1722.         parity    d7
  1723.         putz    d7,HL
  1724.         skip 1
  1725.         next
  1726. ** --
  1727. rl_1xy1     MACRO
  1728. Rl_1I\1_d1    opcode_3_bytes
  1729.         index    \1
  1730.         move.w    A,(Work)
  1731.         getz    d7,A    ;bits 15-8 already clear
  1732.         lsr.w    #1,d6
  1733.         roxl.b    #1,A
  1734.         putsr    d6
  1735.         parity    A
  1736.         putz    A,d7
  1737.         move.w    (Work),A
  1738.         skip 3
  1739.         next
  1740.         ENDM
  1741.     do_xy rl_1xy1
  1742. ** --
  1743. Rla        move.w    d6,d7
  1744.         or.w    #1,d6
  1745.         lsr.w    #1,d7
  1746.         roxl.b    #1,A
  1747.         bcs.s    .cs
  1748.         and.w    #%1110,d6
  1749. .cs        next
  1750. ** --
  1751. Rlca        or.w    #1,d6
  1752.         rol.b    #1,A
  1753.         bcs.s    .cs
  1754.         and.w    #%1110,d6
  1755. .cs        next
  1756. ** --
  1757. rlc_r        MACRO
  1758. Rlc_\1        opcode_2_bytes
  1759.         rol.b    #1,\1    ;V is cleared
  1760.         putsr    d6
  1761.         parity    \1
  1762.         skip 1
  1763.         next
  1764.         ENDM
  1765.     do_r rlc_r
  1766. ** --
  1767. Rlc_H        opcode_2_bytes
  1768.         move.w    HL,(Work)
  1769.         clr.w    d7    ;for parity index
  1770.         move.b    (Work),d7
  1771.         rol.b    #1,d7
  1772.         putsr    d6
  1773.         parity    d7
  1774.         move.b    d7,(Work)
  1775.         move.w    (Work),HL
  1776.         skip 1
  1777.         next
  1778. ** --
  1779. Rlc_1HL1    opcode_2_bytes
  1780.         clr.w    d7
  1781.         getz    HL,d7
  1782.         rol.b    #1,d7
  1783.         putsr    d6
  1784.         parity    d7
  1785.         putz    d7,HL
  1786.         skip 1
  1787.         next
  1788. ** --
  1789. rlc_1xy1    MACRO
  1790. Rlc_1I\1_d1    opcode_3_bytes
  1791.         index    \1
  1792.         move.w    A,(Work)
  1793.         getz    d7,A
  1794.         rol.b    #1,A
  1795.         putsr    d6
  1796.         parity    A
  1797.         putz    A,d7
  1798.         move.w    (Work),A
  1799.         skip 3
  1800.         next
  1801.         ENDM
  1802.     do_xy rlc_1xy1
  1803. ** --
  1804. Rld        opcode_2_bytes
  1805.         swap    d6
  1806.         getz    HL,d6
  1807.         rol.b    #4,d6    ;swap nibbles of (HL)
  1808.         move.b    d6,d7    ;save this
  1809.         eor.b    A,d6    ;insert low nibble of A
  1810.         and.b    #$f0,d6
  1811.         eor.b    A,d6
  1812.         putz    d6,HL    ;store result in (HL)
  1813.         eor.b    d7,A    ;low nibble of saved byte to A
  1814.         and.b    #$f0,A
  1815.         eor.b    d7,A    ;V reset, N & Z tested
  1816.         putsr    d7
  1817.         swap    d6
  1818.         eor.w    d7,d6    ;join old carry with
  1819.         and.w    #1,d6    ; new Z & N and the cleared V.
  1820.         eor.w    d7,d6
  1821.         parity    A    ;parity to V
  1822.         skip 1
  1823.         next
  1824. ** --
  1825. rr_r        MACRO
  1826. Rr_\1        opcode_2_bytes
  1827.         lsr.w    #1,d6    ;carry to extend
  1828.         roxr.b    #1,\1    ;V cleared
  1829.         putsr    d6
  1830.         parity    \1
  1831.         skip 1
  1832.         next
  1833.         ENDM
  1834.     do_r rr_r
  1835. ** --
  1836. Rr_H        opcode_2_bytes
  1837.         move.w    HL,(Work)
  1838.         clr.w    d7
  1839.         move.b    (Work),d7
  1840.         lsr.w    #1,d6
  1841.         roxr.b    #1,d7
  1842.         putsr    d6
  1843.         parity    d7
  1844.         move.b    d7,(Work)
  1845.         move.w    (Work),HL
  1846.         skip 1
  1847.         next
  1848. ** --
  1849. Rr_1HL1     opcode_2_bytes
  1850.         clr.w    d7
  1851.         getz    HL,d7
  1852.         lsr.w    #1,d6
  1853.         roxr.b    #1,d7
  1854.         putsr    d6
  1855.         parity    d7
  1856.         putz    d7,HL
  1857.         skip 1
  1858.         next
  1859. ** --
  1860. rr_1xy1     MACRO
  1861. Rr_1I\1_d1    opcode_3_bytes
  1862.         index    \1
  1863.         move.w    A,(Work)
  1864.         getz    d7,A
  1865.         lsr.w    #1,d6
  1866.         roxr.b    #1,A
  1867.         putsr    d6
  1868.         parity    A
  1869.         putz    A,d7
  1870.         move.w    (Work),A
  1871.         skip 3
  1872.         next
  1873.         ENDM
  1874.     do_xy rr_1xy1
  1875. ** --
  1876. Rra        move.w    d6,d7
  1877.         or.w    #1,d6
  1878.         lsr.w    #1,d7
  1879.         roxr.b    #1,A
  1880.         bcs.s    .cs
  1881.         and.w    #%1110,d6
  1882. .cs        next
  1883. ** --
  1884. rrc_r        MACRO
  1885. Rrc_\1        opcode_2_bytes
  1886.         ror.b    #1,\1
  1887.         putsr    d6
  1888.         parity    \1
  1889.         skip 1
  1890.         next
  1891.         ENDM
  1892.     do_r rrc_r
  1893. ** --
  1894. Rrc_H        opcode_2_bytes
  1895.         move.w    HL,(Work)
  1896.         clr.w    d7
  1897.         move.b    (Work),d7
  1898.         ror.b    #1,d7
  1899.         putsr    d6
  1900.         parity    d7
  1901.         move.b    d7,(Work)
  1902.         move.w    (Work),HL
  1903.         skip 1
  1904.         next
  1905. ** --
  1906. Rrc_1HL1    opcode_2_bytes
  1907.         clr.w    d7
  1908.         getz    HL,d7
  1909.         ror.b    #1,d7
  1910.         putsr    d6
  1911.         parity    d7
  1912.         putz    d7,HL
  1913.         skip 1
  1914.         next
  1915. ** --
  1916. rrc_1xy1    MACRO
  1917. Rrc_1I\1_d1    opcode_3_bytes
  1918.         index    \1
  1919.         move.w    A,(Work)
  1920.         getz    d7,A
  1921.         ror.b    #1,A
  1922.         putsr    d6
  1923.         parity    A
  1924.         putz    A,d7
  1925.         move.w    (Work),A
  1926.         skip 3
  1927.         next
  1928.         ENDM
  1929.     do_xy rrc_1xy1
  1930. ** --
  1931. Rrca        or.w    #1,d6
  1932.         ror.b    #1,A
  1933.         bcs.s    .cs
  1934.         and.w    #%1110,d6
  1935. .cs        next
  1936. ** --
  1937. Rrd        opcode_2_bytes
  1938.         swap    d6
  1939.         getz    HL,d6
  1940.         move.b    A,d7    ;save A
  1941.         eor.b    d6,A    ;low nibble of (HL) to A
  1942.         and.b    #$f0,A
  1943.         eor.b    d6,A
  1944.         eor.b    d7,d6    ;low nibble of saved A to (HL)
  1945.         and.b    #$f0,d6
  1946.         eor.b    d7,d6
  1947.         rol.b    #4,d6    ;swap nibbles of (HL)
  1948.         putz    d6,HL
  1949.         tst.b    A    ;test N & Z, clear V
  1950.         putsr    d7
  1951.         swap    d6
  1952.         eor.w    d7,d6    ;join old carry with
  1953.         and.w    #1,d6    ; new Z & N and the cleared V.
  1954.         eor.w    d7,d6
  1955.         parity    A    ;parity to V
  1956.         skip 1
  1957.         next
  1958. ** --
  1959. rst_p        MACRO
  1960. Rst_\1        getRPC
  1961.         move.w    d7,(Work)
  1962.         decw    ZSP
  1963.         putz    (Work),ZSP
  1964.         decw    ZSP
  1965.         putz    d7,ZSP,2 ;2nd use
  1966.         moveq    #\1,d7
  1967.         makePPC
  1968.         testreq
  1969.         ENDM
  1970.     rst_p    0
  1971.     rst_p    8
  1972.     rst_p    16
  1973.     rst_p    24
  1974.     rst_p    32
  1975.     rst_p    40
  1976.     rst_p    48
  1977.     rst_p    56
  1978. ** --
  1979. sbc_A_r     MACRO
  1980. Sbc_A_\1
  1981.     IFD BCDFLAGS
  1982.         move.b    A,Z80_BCD_A(TableB)        ;BCD_A=A
  1983.         move.b    \1,Z80_BCD_B(TableB)        ;BCD_B=r
  1984.         move.w    d6,Z80_BCD_C(TableB)        ;BCD_C=flags
  1985.         move.w    #OP_SBC,Z80_BCD_OP(TableB)    ;BCD_OP=sbc
  1986.     ENDC
  1987.         lsr.w    #1,d6    ;carry to X
  1988.         ori    #4,CCR    ;set Z
  1989.         subx.b    \1,A
  1990.         putsr    d6
  1991.         next
  1992.         ENDM
  1993.     do_r sbc_A_r
  1994. ** --
  1995. Sbc_A_H     move.w    HL,(Work)
  1996.         move.b    (Work),d7
  1997.     IFD BCDFLAGS
  1998.         move.b    A,Z80_BCD_A(TableB)
  1999.         move.b    d7,Z80_BCD_B(TableB)
  2000.         move.w    d6,Z80_BCD_C(TableB)
  2001.         move.w    #OP_SBC,Z80_BCD_OP(TableB)
  2002.     ENDC
  2003.         lsr.w    #1,d6
  2004.         ori    #4,CCR
  2005.         subx.b    d7,A
  2006.         putsr    d6
  2007.         next
  2008. ** --
  2009. Sbc_A_n     getRPC
  2010.         getz    d7,d7
  2011.     IFD BCDFLAGS
  2012.         move.b    A,Z80_BCD_A(TableB)
  2013.         move.b    d7,Z80_BCD_B(TableB)
  2014.         move.w    d6,Z80_BCD_C(TableB)
  2015.         move.w    #OP_SBC,Z80_BCD_OP(TableB)
  2016.     ENDC
  2017.         lsr.w    #1,d6
  2018.         ori    #4,CCR
  2019.         subx.b    d7,A
  2020.         putsr    d6
  2021.         skip 1
  2022.         next
  2023. ** --
  2024. Sbc_A_1HL1    getz    HL,d7
  2025.     IFD BCDFLAGS
  2026.         move.b    A,Z80_BCD_A(TableB)
  2027.         move.b    d7,Z80_BCD_B(TableB)
  2028.         move.w    d6,Z80_BCD_C(TableB)
  2029.         move.w    #OP_SBC,Z80_BCD_OP(TableB)
  2030.     ENDC
  2031.         lsr.w    #1,d6
  2032.         ori    #4,CCR
  2033.         subx.b    d7,A
  2034.         putsr    d6
  2035.         next
  2036. ** --
  2037. sbc_A_1xy1    MACRO
  2038. Sbc_A_1I\1_d1    opcode_2_bytes
  2039.         index    \1
  2040.         getz    d7,d7
  2041.     IFD BCDFLAGS
  2042.         move.b    A,Z80_BCD_A(TableB)
  2043.         move.b    d7,Z80_BCD_B(TableB)
  2044.         move.w    d6,Z80_BCD_C(TableB)
  2045.         move.w    #OP_SBC,Z80_BCD_OP(TableB)
  2046.     ENDC
  2047.         lsr.w    #1,d6
  2048.         ori    #4,CCR
  2049.         subx.b    d7,A
  2050.         putsr    d6
  2051.         skip 2
  2052.         next
  2053.         ENDM
  2054.     do_xy sbc_A_1xy1
  2055. ** --
  2056. sbc_HL_ss    MACRO
  2057. Sbc_HL_\1\2    opcode_2_bytes
  2058.         join    \1,\2
  2059.         lsr.w    #1,d6
  2060.         ori    #4,CCR
  2061.         subx.w    d7,HL
  2062.         putsr    d6
  2063.         skip 1
  2064.         next
  2065.         ENDM
  2066.     do_ss sbc_HL_ss
  2067. ** --
  2068. Sbc_HL_HL    opcode_2_bytes
  2069.         lsr.w    #1,d6
  2070.         ori    #4,CCR
  2071.         subx.w    HL,HL
  2072.         putsr    d6
  2073.         skip 1
  2074.         next
  2075. ** --
  2076. Sbc_HL_SP    opcode_2_bytes
  2077.         move.w    ZSP,d7
  2078.         lsr    #1,d6
  2079.         ori    #4,CCR
  2080.         subx.w    d7,HL
  2081.         putsr    d6
  2082.         skip 1
  2083.         next
  2084. ** --
  2085. Scf        or.w    #1,d6
  2086.         next
  2087. ** --
  2088. set_b_r        MACRO
  2089. Set_\1_\2    opcode_2_bytes
  2090.         bset    #\1,\2
  2091.         skip 1
  2092.         next
  2093.         ENDM
  2094.  
  2095. set_b_H     MACRO
  2096. Set_\1_H    opcode_2_bytes
  2097.         bset    #8+\1,HL
  2098.         skip 1
  2099.         next
  2100.         ENDM
  2101.  
  2102. set_b_1HL1    MACRO
  2103. Set_\1_1HL1    opcode_2_bytes
  2104.     IFD    Z80_MEMCHECK
  2105.         getz    HL,d7
  2106.         bset    #\1,d7
  2107.         putz    d7,HL
  2108.     ELSE
  2109.         bset    #\1,(Z0,HL.w)
  2110.     ENDC
  2111.         skip 1
  2112.         next
  2113.         ENDM
  2114.  
  2115. set_b_1xy1    MACRO
  2116. Set_\1_1I\2_d1    opcode_3_bytes
  2117.         index    \2
  2118.     IFD    Z80_MEMCHECK
  2119.         getz    d7,(Work)
  2120.         bset    #\1,(Work)
  2121.         putz    (Work),d7
  2122.     ELSE
  2123.         bset    #\1,(Z0,d7.w)
  2124.     ENDC
  2125.         skip 3
  2126.         next
  2127.         ENDM
  2128.  
  2129. set_b        MACRO
  2130.     set_b_r \1,A
  2131.     set_b_r \1,B
  2132.     set_b_r \1,C
  2133.     set_b_r \1,D
  2134.     set_b_r \1,E
  2135.     set_b_r \1,L
  2136.     set_b_H \1
  2137.     set_b_1HL1 \1
  2138.     set_b_1xy1 \1,X
  2139.     set_b_1xy1 \1,Y
  2140.         ENDM
  2141.  
  2142.     set_b 0
  2143.     set_b 1
  2144.     set_b 2
  2145.     set_b 3
  2146.     set_b 4
  2147.     set_b 5
  2148.     set_b 6
  2149.     set_b 7
  2150. ** --
  2151. sla_r        MACRO
  2152. Sla_\1        opcode_2_bytes
  2153.         lsl.b    #1,\1    ;V is cleared (it's not with Asl!)
  2154.         putsr    d6
  2155.         parity    \1
  2156.         skip 1
  2157.         next
  2158.         ENDM
  2159.     do_r sla_r
  2160. ** --
  2161. Sla_H        opcode_2_bytes
  2162.         move.w    HL,(Work)
  2163.         clr.w    d7    ;for parity index
  2164.         move.b    (Work),d7
  2165.         lsl.b    #1,d7
  2166.         putsr    d6
  2167.         parity    d7
  2168.         move.b    d7,(Work)
  2169.         move.w    (Work),HL
  2170.         skip 1
  2171.         next
  2172. ** --
  2173. Sla_1HL1    opcode_2_bytes
  2174.         clr.w    d7
  2175.         getz    HL,d7
  2176.         lsl.b    #1,d7
  2177.         putsr    d6
  2178.         parity    d7
  2179.         putz    d7,HL
  2180.         skip 1
  2181.         next
  2182. ** --
  2183. sla_1xy1    MACRO
  2184. Sla_1I\1_d1    opcode_3_bytes
  2185.         index    \1
  2186.         move.w    A,(Work)
  2187.         getz    d7,A
  2188.         lsl.b    #1,A
  2189.         putsr    d6
  2190.         parity    A
  2191.         putz    A,d7
  2192.         move.w    (Work),A
  2193.         skip 3
  2194.         next
  2195.         ENDM
  2196.     do_xy sla_1xy1
  2197. ** --
  2198. sra_r        MACRO
  2199. Sra_\1        opcode_2_bytes
  2200.         asr.b    #1,\1    ;V is reset, since sign doesn't change.
  2201.         putsr    d6
  2202.         parity    \1
  2203.         skip 1
  2204.         next
  2205.         ENDM
  2206.     do_r sra_r
  2207. ** --
  2208. Sra_H        opcode_2_bytes
  2209.         move.w    HL,(Work)
  2210.         clr.w    d7
  2211.         move.b    (Work),d7
  2212.         asr.b    #1,d7
  2213.         putsr    d6
  2214.         parity    d7
  2215.         move.b    d7,(Work)
  2216.         move.w    (Work),HL
  2217.         skip 1
  2218.         next
  2219. ** --
  2220. Sra_1HL1    opcode_2_bytes
  2221.         clr.w    d7
  2222.         getz    HL,d7
  2223.         asr.b    #1,d7
  2224.         putsr    d6
  2225.         parity    d7
  2226.         putz    d7,HL
  2227.         skip 1
  2228.         next
  2229. ** --
  2230. sra_1xy1    MACRO
  2231. Sra_1I\1_d1    opcode_3_bytes
  2232.         index    \1
  2233.         move.w    A,(Work)
  2234.         getz    d7,A
  2235.         asr.b    #1,A
  2236.         putsr    d6
  2237.         parity    A
  2238.         putz    A,d7
  2239.         move.w    (Work),A
  2240.         skip 3
  2241.         next
  2242.         ENDM
  2243.     do_xy sra_1xy1
  2244. ** --
  2245. srl_r        MACRO
  2246. Srl_\1        opcode_2_bytes
  2247.         lsr.b    #1,\1    ;V is cleared
  2248.         putsr    d6
  2249.         parity    \1
  2250.         skip 1
  2251.         next
  2252.         ENDM
  2253.     do_r srl_r
  2254. ** --
  2255. Srl_H        opcode_2_bytes
  2256.         move.w    HL,(Work)
  2257.         clr.w    d7
  2258.         move.b    (Work),d7
  2259.         lsr.b    #1,d7
  2260.         putsr    d6
  2261.         parity    d7
  2262.         move.b    d7,(Work)
  2263.         move.w    (Work),HL
  2264.         skip 1
  2265.         next
  2266. ** --
  2267. Srl_1HL1    opcode_2_bytes
  2268.         clr.w    d7
  2269.         getz    HL,d7
  2270.         lsr.b    #1,d7
  2271.         putsr    d6
  2272.         parity    d7
  2273.         putz    d7,HL
  2274.         skip 1
  2275.         next
  2276. ** --
  2277. srl_1xy1    MACRO
  2278. Srl_1I\1_d1    opcode_3_bytes
  2279.         index    \1
  2280.         move.w    A,(Work)
  2281.         getz    d7,A
  2282.         lsr.b    #1,A
  2283.         putsr    d6
  2284.         parity    A
  2285.         putz    A,d7
  2286.         move.w    (Work),A
  2287.         skip 3
  2288.         next
  2289.         ENDM
  2290.     do_xy srl_1xy1
  2291. ** --
  2292. sub_r        MACRO
  2293. Sub_\1
  2294.     IFD BCDFLAGS
  2295.         move.b    A,Z80_BCD_A(TableB)        ;BCD_A=A
  2296.         move.b    \1,Z80_BCD_B(TableB)        ;BCD_B=r
  2297.         move.w    #OP_SUB,Z80_BCD_OP(TableB)    ;BCD_OP=sub
  2298.     ENDC
  2299.         sub.b    \1,A
  2300.         putsr    d6
  2301.         next
  2302.         ENDM
  2303.     do_r sub_r
  2304. ** --
  2305. Sub_H        move.w    HL,(Work)
  2306.     IFD BCDFLAGS
  2307.         move.b    A,Z80_BCD_A(TableB)
  2308.         move.b    (Work),Z80_BCD_B(TableB)
  2309.         move.w    #OP_SUB,Z80_BCD_OP(TableB)
  2310.     ENDC
  2311.         sub.b    (Work),A
  2312.         putsr    d6
  2313.         next
  2314. ** --
  2315. Sub_n        getRPC
  2316.         getz    d7,d7
  2317.     IFD BCDFLAGS
  2318.         move.b    A,Z80_BCD_A(TableB)
  2319.         move.b    d7,Z80_BCD_B(TableB)
  2320.         move.w    #OP_SUB,Z80_BCD_OP(TableB)
  2321.     ENDC
  2322.         sub.b    d7,A
  2323.         putsr    d6
  2324.         skip 1
  2325.         next
  2326. ** --
  2327. Sub_1HL1    getz    HL,d7
  2328.     IFD BCDFLAGS
  2329.         move.b    A,Z80_BCD_A(TableB)
  2330.         move.b    d7,Z80_BCD_B(TableB)
  2331.         move.w    #OP_SUB,Z80_BCD_OP(TableB)
  2332.     ENDC
  2333.         sub.b    d7,A
  2334.         putsr    d6
  2335.         next
  2336. ** --
  2337. sub_1xy1    MACRO
  2338. Sub_1I\1_d1    opcode_2_bytes
  2339.         index    \1
  2340.         getz    d7,d7
  2341.     IFD BCDFLAGS
  2342.         move.b    A,Z80_BCD_A(TableB)
  2343.         move.b    d7,Z80_BCD_B(TableB)
  2344.         move.w    #OP_SUB,Z80_BCD_OP(TableB)
  2345.     ENDC
  2346.         sub.b    d7,A
  2347.         putsr    d6
  2348.         skip 2
  2349.         next
  2350.         ENDM
  2351.     do_xy sub_1xy1
  2352. ** --
  2353. xor_r        MACRO
  2354. Xor_\1        eor.b    \1,A    ;V and C are reset
  2355.         putsr    d6
  2356.         parity    A
  2357.         next
  2358.         ENDM
  2359.     do_r xor_r
  2360. ** --
  2361. Xor_H        move.w    HL,(Work)
  2362.         move.b    (Work),d7
  2363.         eor.b    d7,A
  2364.         putsr    d6
  2365.         parity    A
  2366.         next
  2367. ** --
  2368. Xor_n        getRPC
  2369.         getz    d7,d7
  2370.         eor.b    d7,A
  2371.         putsr    d6
  2372.         parity    A
  2373.         skip 1
  2374.         next
  2375. ** --
  2376. Xor_1HL1    getz    HL,d7
  2377.         eor.b    d7,A
  2378.         putsr    d6
  2379.         parity    A
  2380.         next
  2381. ** --
  2382. xor_1xy1    MACRO
  2383. Xor_1I\1_d1    opcode_2_bytes
  2384.         index    \1
  2385.         getz    d7,d7
  2386.         eor.b    d7,A
  2387.         putsr    d6
  2388.         parity    A
  2389.         skip 2
  2390.         next
  2391.         ENDM
  2392.     do_xy xor_1xy1
  2393.  
  2394. ** =====================================================================
  2395.  
  2396. ** Why stop now, just when I'm hating it?
  2397.