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

  1. ** The undocumented Z80 instructions
  2. **
  3. ** (Except "In xx,(C)" and "Out (C),xx" which are in impldept.i, and
  4. ** the rotate/shift/set/reset operations on IX/IY with autocopy to
  5. ** a register are moved to distant.i.)
  6. **
  7. ** ----------------------------------------------------------------------
  8.  
  9.     IFD VERBOSE
  10.     LIST
  11. ** Compiling the undoc_instr.i file.
  12.     NOLIST
  13.     ENDC
  14.  
  15.     IFND    UNDOCINSTR_UNDEF
  16.  
  17.     IFD VERBOSE
  18.     LIST
  19. ** Compiling routines for the "undocumented" instructions.
  20.     NOLIST
  21.     ENDC
  22.  
  23. ** Let the undocumented cases of Neg and Retn use the "real" routines
  24. ** (they all have the same opcode form):
  25. undoc_neg = Neg-InstrBase
  26. undoc_retn = Retn-InstrBase
  27.  
  28. ** Create actual routines for the "undocumented"-labels:
  29.  
  30. adc_A_xyHL    MACRO
  31. Adc_A_\1    opcode_2_bytes
  32.         move.b    Z80_\1(TableB),d7
  33.     IFD BCDFLAGS
  34.         move.b    A,Z80_BCD_A(TableB)    ;BCD_A=A
  35.         move.b    d7,Z80_BCD_B(TableB)    ;BCD_B=register
  36.         move.w    d6,Z80_BCD_C(TableB)    ;BCD_C=carry
  37.         move.w    #OP_ADC,Z80_BCD_OP(TableB)  ;BCD_OP=adc
  38.     ENDC
  39.         lsr.w    #1,d6    ;carry to X
  40.         ori    #4,CCR    ;set Z
  41.         addx.b    d7,A
  42.         putsr    d6
  43.         skip 1
  44.         next
  45.         ENDM
  46.     adc_A_xyHL XH
  47.     adc_A_xyHL XL
  48.     adc_A_xyHL YH
  49.     adc_A_xyHL YL
  50. ** --
  51. add_A_xyHL    MACRO
  52. Add_A_\1    opcode_2_bytes
  53.     IFD BCDFLAGS
  54.         move.b    A,Z80_BCD_A(TableB)
  55.         move.b    Z80_\1(TableB),Z80_BCD_B(TableB)
  56.         clr.w    Z80_BCD_OP(TableB)
  57.     ENDC
  58.         add.b    Z80_\1(TableB),A
  59.         putsr    d6
  60.         skip 1
  61.         next
  62.         ENDM
  63.     add_A_xyHL XH
  64.     add_A_xyHL XL
  65.     add_A_xyHL YH
  66.     add_A_xyHL YL
  67. ** --
  68. and_xyHL     MACRO
  69. And_\1        opcode_2_bytes
  70.         and.b    Z80_\1(TableB),A    ;V is cleared
  71.         putsr    d6
  72.         parity    A
  73.         skip 1
  74.         next
  75.         ENDM
  76.     and_xyHL XH
  77.     and_xyHL XL
  78.     and_xyHL YH
  79.     and_xyHL YL
  80. ** --
  81. cp_xyHL        MACRO
  82. Cp_\1        opcode_2_bytes
  83.         cmp.b    Z80_\1(TableB),A
  84.         putsr    d6
  85.         skip 1
  86.         next
  87.         ENDM
  88.     cp_xyHL XH
  89.     cp_xyHL XL
  90.     cp_xyHL YH
  91.     cp_xyHL YL
  92. ** --
  93. dec_xyHL    MACRO
  94. Dec_\1        opcode_2_bytes
  95.         decb    Z80_\1(TableB)
  96.         putsr    d7
  97.         eor.w    d7,d6
  98.         and.w    #1,d6    ;keep old carry
  99.         eor.w    d7,d6
  100.         skip 1
  101.         next
  102.         ENDM
  103.     dec_xyHL XH
  104.     dec_xyHL XL
  105.     dec_xyHL YH
  106.     dec_xyHL YL
  107. ** --
  108. inc_xyHL    MACRO
  109. Inc_\1        opcode_2_bytes
  110.         incb    Z80_\1(TableB)
  111.         putsr    d7
  112.         eor.w    d7,d6
  113.         and.w    #1,d6    ;keep old carry
  114.         eor.w    d7,d6
  115.         skip 1
  116.         next
  117.         ENDM
  118.     inc_xyHL XH
  119.     inc_xyHL XL
  120.     inc_xyHL YH
  121.     inc_xyHL YL
  122. ** --
  123. ld_xyHL_n    MACRO
  124. Ld_\1_n        opcode_2_bytes
  125.         getRPC
  126.         incw    d7
  127.         getz    d7,Z80_\1(TableB)
  128.         skip 2
  129.         next
  130.         ENDM
  131.     ld_xyHL_n XH
  132.     ld_xyHL_n XL
  133.     ld_xyHL_n YH
  134.     ld_xyHL_n YL
  135. ** --
  136. ld_r_xyHL    MACRO
  137. Ld_\1_\2    opcode_2_bytes
  138.         move.b    Z80_\2(TableB),\1
  139.         skip 1
  140.         next
  141.         ENDM
  142.  
  143. ldrxy_r        MACRO
  144.     ld_r_xyHL \1,XH
  145.     ld_r_xyHL \1,XL
  146.     ld_r_xyHL \1,YH
  147.     ld_r_xyHL \1,YL
  148.         ENDM
  149.  
  150.     ldrxy_r A
  151.     ldrxy_r B
  152.     ldrxy_r C
  153.     ldrxy_r D
  154.     ldrxy_r E
  155.  
  156. ld_xyHL_r    MACRO
  157. Ld_\1_\2    opcode_2_bytes
  158.         move.b    \2,Z80_\1(TableB)
  159.         skip 1
  160.         next
  161.         ENDM
  162.  
  163. ldxyr_r        MACRO
  164.     ld_xyHL_r XH,\1
  165.     ld_xyHL_r XL,\1
  166.     ld_xyHL_r YH,\1
  167.     ld_xyHL_r YL,\1
  168.         ENDM
  169.  
  170.     ldxyr_r A
  171.     ldxyr_r B
  172.     ldxyr_r C
  173.     ldxyr_r D
  174.     ldxyr_r E
  175.  
  176. ldxyxy        MACRO
  177. Ld_\1H_\1H    opcode_2_bytes    ;Ld XH,XH or XL,XL
  178.         skip 1
  179.         next
  180. Ld_\1L_\1L = Ld_\1H_\1H
  181.  
  182. Ld_\1H_\1L    opcode_2_bytes
  183.         move.b    Z80_XL(TableB),Z80_XH(TableB)
  184.         skip 1
  185.         next
  186. Ld_\1L_\1H    opcode_2_bytes
  187.         move.b    Z80_XH(TableB),Z80_XL(TableB)
  188.         skip 1
  189.         next
  190.         ENDM
  191.  
  192.     do_xy ldxyxy
  193. ** --
  194. or_xyHL        MACRO
  195. Or_\1        opcode_2_bytes
  196.         or.b    Z80_\1(TableB),A    ;C and V are reset
  197.         putsr    d6
  198.         parity    A
  199.         skip 1
  200.         next
  201.         ENDM
  202.     or_xyHL XH
  203.     or_xyHL XL
  204.     or_xyHL YH
  205.     or_xyHL YL
  206. ** --
  207. ** Res/Set reg,bit,(IX/IY+d) routines placed in distant.i
  208. rsrbxy_op_r_b MACRO
  209. \1_\2_\3_1IX_d1    jmp    d_\1_\2_\3_1IX_d1
  210. \1_\2_\3_1IY_d1    jmp    d_\1_\2_\3_1IY_d1
  211.     ENDM
  212.  
  213. rsrbxy_op_b    MACRO
  214.     rsrbxy_op_r_b \1,A,\2
  215.     rsrbxy_op_r_b \1,B,\2
  216.     rsrbxy_op_r_b \1,C,\2
  217.     rsrbxy_op_r_b \1,D,\2
  218.     rsrbxy_op_r_b \1,E,\2
  219.     rsrbxy_op_r_b \1,L,\2
  220.     rsrbxy_op_r_b \1,H,\2
  221.     ENDM
  222.  
  223. rsrbxy_op    MACRO
  224.     rsrbxy_op_b \1,0
  225.     rsrbxy_op_b \1,1
  226.     rsrbxy_op_b \1,2
  227.     rsrbxy_op_b \1,3
  228.     rsrbxy_op_b \1,4
  229.     rsrbxy_op_b \1,5
  230.     rsrbxy_op_b \1,6
  231.     rsrbxy_op_b \1,7
  232.     ENDM
  233.  
  234.     rsrbxy_op Res
  235.     rsrbxy_op Set
  236. ** --
  237. ** Rl, Rlc, Rr, Rrc, Sla, Sll, Sra, Srl (IX/IY+d) with copy-to-reg:
  238. ** Routines placed in distant.i
  239. rotxyr_op_r    MACRO
  240. \1_\2_1IX_d1    jmp    d_\1_\2_1IX_d1
  241. \1_\2_1IY_d1    jmp    d_\1_\2_1IY_d1
  242.         ENDM
  243.  
  244. rotxyr_r    MACRO
  245.     rotxyr_op_r Rl,\1
  246.     rotxyr_op_r Rlc,\1
  247.     rotxyr_op_r Rr,\1
  248.     rotxyr_op_r Rrc,\1
  249.     rotxyr_op_r Sla,\1
  250.     rotxyr_op_r Sll,\1
  251.     rotxyr_op_r Sra,\1
  252.     rotxyr_op_r Srl,\1
  253.         ENDM
  254.     do_r rotxyr_r
  255.     rotxyr_r H
  256. ** --
  257. sbc_A_xyHL    MACRO
  258. Sbc_A_\1    opcode_2_bytes
  259.         move.b    Z80_\1(TableB),d7
  260.     IFD BCDFLAGS
  261.         move.b    A,Z80_BCD_A(TableB)    ;BCD_A=A
  262.         move.b    d7,Z80_BCD_B(TableB)    ;BCD_B=register
  263.         move.w    d6,Z80_BCD_C(TableB)    ;BCD_C=flags
  264.         move.w    #OP_SBC,Z80_BCD_OP(TableB)  ;BCD_OP=sbc
  265.     ENDC
  266.         lsr.w    #1,d6    ;carry to X
  267.         ori    #4,CCR    ;set Z
  268.         subx.b    d7,A
  269.         putsr    d6
  270.         skip 1
  271.         next
  272.         ENDM
  273.     sbc_A_xyHL XH
  274.     sbc_A_xyHL XL
  275.     sbc_A_xyHL YH
  276.     sbc_A_xyHL YL
  277. ** --
  278. ** Sll, 'Shift left logically', shifts the byte left, moving a 1(!) into
  279. ** bit 0 and bit 7 to carry. Flag conditions like Srl.
  280. sll_r        MACRO
  281. Sll_\1        opcode_2_bytes
  282.         lsl.b    #1,\1    ;V is cleared, bit 0 reset
  283.         putsr    d6
  284.         incb    \1    ;set bit 0
  285.         parity    \1
  286.         skip 1
  287.         next
  288.         ENDM
  289.     do_r sll_r
  290.  
  291. Sll_H        opcode_2_bytes
  292.         move.w    HL,(Work)
  293.         clr.w    d7    ;for parity index
  294.         move.b    (Work),d7
  295.         lsl.b    #1,d7
  296.         putsr    d6
  297.         incb    d7
  298.         parity    d7
  299.         move.b    d7,(Work)
  300.         move.w    (Work),HL
  301.         skip 1
  302.         next
  303. ** --
  304. Sll_1HL1    opcode_2_bytes
  305.         clr.w    d7
  306.         getz    HL,d7
  307.         lsl.b    #1,d7
  308.         putsr    d6
  309.         incb    d7
  310.         parity    d7
  311.         putz    d7,HL
  312.         skip 1
  313.         next
  314. ** --
  315. sll_1xy1    MACRO
  316. Sll_1I\1_d1    opcode_3_bytes
  317.         index    \1
  318.         move.w    A,(Work)
  319.         getz    d7,A
  320.         lsl.b    #1,A
  321.         putsr    d6
  322.         incb    A
  323.         parity    A
  324.         putz    A,d7
  325.         move.w    (Work),A
  326.         skip 3
  327.         next
  328.         ENDM
  329.     do_xy sll_1xy1
  330. ** --
  331. sub_xyHL    MACRO
  332. Sub_\1        opcode_2_bytes
  333.     IFD BCDFLAGS
  334.         move.b    A,Z80_BCD_A(TableB)    ;BCD_A=A
  335.         move.b    Z80_\1(TableB),Z80_BCD_B(TableB)  ;BCD_B=r
  336.         move.w    #OP_SUB,Z80_BCD_OP(TableB)  ;BCD_OP=sub
  337.     ENDC
  338.         sub.b    Z80_\1(TableB),A
  339.         putsr    d6
  340.         skip 1
  341.         next
  342.         ENDM
  343.     sub_xyHL XH
  344.     sub_xyHL XL
  345.     sub_xyHL YH
  346.     sub_xyHL YL
  347. ** --
  348. xor_xyHL    MACRO
  349. Xor_\1        opcode_2_bytes
  350.         move.b    Z80_\1(TableB),d7 ;can only eor from D-register
  351.         eor.b    d7,A    ;V and C are reset
  352.         putsr    d6
  353.         parity    A
  354.         skip 1
  355.         next
  356.         ENDM
  357.     xor_xyHL XH
  358.     xor_xyHL XL
  359.     xor_xyHL YH
  360.     xor_xyHL YL
  361.  
  362. ** ---------------------------------------------------------------------
  363.  
  364.     ELSE ;IFND UNDOCINSTR_UNDEF
  365.  
  366.     IFD VERBOSE
  367.     LIST
  368. ** Creating fake labels for the "undocumented" instructions, making
  369. **   them all behave as undefined opcodes.
  370.     NOLIST
  371.     ENDC
  372.  
  373. **    Treat the "undocumented" instructions as undefined:
  374.  
  375. ** Let the undocumented cases of Neg and Retn become "normal" undefined
  376. ** opcodes:
  377. undoc_neg    EQU    undef
  378. undoc_retn    EQU    undef
  379.  
  380. ** Create fake labels for the "undocumented"-labels, being equal to
  381. ** the undefined-opcode routines:
  382.  
  383. ** Ld labels:
  384. ldrxy_r_xy    MACRO
  385. Ld_\1_\2H = Undef_Opcode_2
  386. Ld_\1_\2L = Undef_Opcode_2
  387. Ld_\2H_\1 = Undef_Opcode_2
  388. Ld_\2L_\1 = Undef_Opcode_2
  389.         ENDM
  390.  
  391. ldrxy_xy    MACRO
  392.     ldrxy_r_xy A,\1
  393.     ldrxy_r_xy B,\1
  394.     ldrxy_r_xy C,\1
  395.     ldrxy_r_xy D,\1
  396.     ldrxy_r_xy E,\1
  397.         ENDM
  398.  
  399.     ldrxy_xy X
  400.     ldrxy_xy Y
  401.  
  402. Ld_XH_XH = Undef_Opcode_2
  403. Ld_XL_XL = Undef_Opcode_2
  404. Ld_YH_YH = Undef_Opcode_2
  405. Ld_YL_YL = Undef_Opcode_2
  406. Ld_XH_XL = Undef_Opcode_2
  407. Ld_XL_XH = Undef_Opcode_2
  408. Ld_YH_YL = Undef_Opcode_2
  409. Ld_YL_YH = Undef_Opcode_2
  410. ** --
  411. ** Res/Set reg,bit,(IX/IY+d) labels:
  412. rsrbxy_op_r_b MACRO
  413. \1_\2_\3_1IX_d1 = Undef_Opcode_3
  414. \1_\2_\3_1IY_d1 = Undef_Opcode_3
  415.     ENDM
  416.  
  417. rsrbxy_op_b    MACRO
  418.     rsrbxy_op_r_b \1,A,\2
  419.     rsrbxy_op_r_b \1,B,\2
  420.     rsrbxy_op_r_b \1,C,\2
  421.     rsrbxy_op_r_b \1,D,\2
  422.     rsrbxy_op_r_b \1,E,\2
  423.     rsrbxy_op_r_b \1,L,\2
  424.     rsrbxy_op_r_b \1,H,\2
  425.     ENDM
  426.  
  427. rsrbxy_op    MACRO
  428.     rsrbxy_op_b \1,0
  429.     rsrbxy_op_b \1,1
  430.     rsrbxy_op_b \1,2
  431.     rsrbxy_op_b \1,3
  432.     rsrbxy_op_b \1,4
  433.     rsrbxy_op_b \1,5
  434.     rsrbxy_op_b \1,6
  435.     rsrbxy_op_b \1,7
  436.     ENDM
  437.  
  438.     rsrbxy_op Res
  439.     rsrbxy_op Set
  440. ** --
  441. ** Rl, Rlc, Rr, Rrc, Sla, Sll, Sra, Srl (IX/IY+d) with copy-to-reg:
  442. rotxyr_op_r    MACRO
  443. \1_\2_1IX_d1 = Undef_Opcode_3
  444. \1_\2_1IY_d1 = Undef_Opcode_3
  445.         ENDM
  446.  
  447. rotxyr_r     MACRO
  448.     rotxyr_op_r Rl,\1
  449.     rotxyr_op_r Rlc,\1
  450.     rotxyr_op_r Rr,\1
  451.     rotxyr_op_r Rrc,\1
  452.     rotxyr_op_r Sla,\1
  453.     rotxyr_op_r Sll,\1
  454.     rotxyr_op_r Sra,\1
  455.     rotxyr_op_r Srl,\1
  456.         ENDM
  457.     do_r rotxyr_r
  458.     rotxyr_r H
  459. ** --
  460. sll_r        MACRO
  461. Sll_\1 = Undef_Opcode_2
  462.         ENDM
  463.     do_r sll_r
  464.  
  465. Sll_H = Undef_Opcode_2
  466. Sll_1HL1 = Undef_Opcode_2
  467. Sll_1IX_d1 = Undef_Opcode_3
  468. Sll_1IY_d1 = Undef_Opcode_3
  469. ** --
  470. ** Byte operations using IX/IY H and L:
  471. byteop_xyHL     MACRO
  472.  
  473. Adc_A_\1H = Undef_Opcode_2
  474. Adc_A_\1L = Undef_Opcode_2
  475.  
  476. Add_A_\1H = Undef_Opcode_2
  477. Add_A_\1L = Undef_Opcode_2
  478.  
  479. And_\1H = Undef_Opcode_2
  480. And_\1L = Undef_Opcode_2
  481.  
  482. Cp_\1H = Undef_Opcode_2
  483. Cp_\1L = Undef_Opcode_2
  484.  
  485. Dec_\1H = Undef_Opcode_2
  486. Dec_\1L = Undef_Opcode_2
  487.  
  488. Inc_\1H = Undef_Opcode_2
  489. Inc_\1L = Undef_Opcode_2
  490.  
  491. Ld_\1H_n = Undef_Opcode_2
  492. Ld_\1L_n = Undef_Opcode_2
  493.  
  494. Or_\1H = Undef_Opcode_2
  495. Or_\1L = Undef_Opcode_2
  496.  
  497. Sbc_A_\1H = Undef_Opcode_2
  498. Sbc_A_\1L = Undef_Opcode_2
  499.  
  500. Sub_\1H = Undef_Opcode_2
  501. Sub_\1L = Undef_Opcode_2
  502.  
  503. Xor_\1H = Undef_Opcode_2
  504. Xor_\1L = Undef_Opcode_2
  505.  
  506.         ENDM
  507.  
  508.     do_xy byteop_xyHL
  509.  
  510.     ENDC ;IFND UNDOCINSTR_UNDEF
  511.  
  512. ** ======================================================================
  513.