home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / misc / emu / z80 / generic_macs.i < prev    next >
Text File  |  1993-12-21  |  7KB  |  311 lines

  1. ** The generic versions of the macros for the implementation-dependent
  2. ** Z80 instructions.
  3.  
  4. ** The file Z80_coding.i contains the definitions of the macros and
  5. ** register aliases used in the instruction emulation routines.
  6. ** If your assembler does not handle register aliasing, you will have to
  7. ** translate the aliases used below to the corresponding register names,
  8. ** as defined in the include file. Take great care when doing this.
  9.  
  10. ** ======================================================================
  11.  
  12. ** Notes on the refresh register
  13. **
  14. ** The real behaviour of the R register seems impossible to emulate at a
  15. ** reasonable speed, since it increments at certain intervals providing
  16. ** certain parts of the CPU are free. Usually once per instruction, but
  17. ** sometimes twice. (If anybody finds a complete description of this,
  18. ** please send me a copy).
  19. **
  20. **  The R register is not incremented after each instruction; instead when
  21. **  Ld A,R is executed the bits 0-6 have to be made up from some counter
  22. **  like the Pseudo-PC or the system clock. Bit 7 is taken from the last
  23. **  stored R.
  24. **
  25. **  When Ld R,A is executed, only bit 7 must be safely stored in the
  26. **  Z80_R field of the control structure. Bits 0-6 may be treated in any
  27. **  way by the implementer.
  28. **
  29. **  The file generic_macs.i provides a version of Ld A,R which uses the
  30. **  Pseudo-PC to 'approximate R' as a non-machine specific way to do it.
  31.  
  32. ** ---------------------------------------------------------------------
  33.  
  34.     IFD VERBOSE
  35.     LIST
  36. ** Using the generic macros for the implementation-dependent routines.
  37.     NOLIST
  38.     ENDC
  39.  
  40.  
  41. ** The In instructions "read" a fixed value:
  42. DEFAULT_IN = 00
  43.  
  44.  
  45.     /* Macros can't be nested, so we do it like this: */
  46.  
  47. In_r_1C1_subm    MACRO    ;Parameter: register
  48.         move.b    #DEFAULT_IN,\1 ;this is where you "read" the value
  49.         tst.b    \1    ;V is cleared, N and Z tested
  50.         putsr    d7
  51.         eor.b    d7,d6
  52.         and.w    #1,d6
  53.         eor.b    d7,d6    ;keep old carry
  54.         parity    \1
  55.         skip 1
  56.         next
  57.         ENDM
  58. In_A_1C1_mac    MACRO
  59.         In_r_1C1_subm    A
  60.         ENDM
  61. In_B_1C1_mac    MACRO
  62.         In_r_1C1_subm    B
  63.         ENDM
  64. In_C_1C1_mac    MACRO
  65.         In_r_1C1_subm    C
  66.         ENDM
  67. In_D_1C1_mac    MACRO
  68.         In_r_1C1_subm    D
  69.         ENDM
  70. In_E_1C1_mac    MACRO
  71.         In_r_1C1_subm    E
  72.         ENDM
  73. In_L_1C1_mac    MACRO
  74.         In_r_1C1_subm    L
  75.         ENDM
  76.  
  77. In_H_1C1_mac    MACRO
  78.         swap d6        ;save flags
  79.         move.b    #DEFAULT_IN,d6    ;"read" the value
  80.         move.w    HL,(Work)
  81.         move.b    d6,(Work)       ;V is cleared, N & Z tested
  82.         putsr    d7
  83.         or.b    Z80_Parity(TableB,d6.w),d7 ;set parity in d7
  84.         move.w    (Work),HL
  85.         swap    d6    ;old flags back
  86.         eor.b    d7,d6
  87.         and.w    #1,d6
  88.         eor.b    d7,d6    ;keep old carry
  89.         skip 1
  90.         next
  91.         ENDM
  92.  
  93.     ;"Undocumented" instruction. Reads from the port but does not
  94.     ;store the value. Flags are affected by the read value as usual,
  95.     ;and this instruction is sometimes named "In F,(C)". The name
  96.     ;"In (HL),(C)" would be symmetric, but is not correct.
  97. In_xx_1C1_mac    MACRO
  98.         swap d6        ;save flags
  99.         move.b    #DEFAULT_IN,d6    ;"read" the value
  100.         tst.b    d6    ;V is cleared, N & Z tested
  101.         putsr    d7
  102.         or.b    Z80_Parity(TableB,d6.w),d7 ;set parity in d7
  103.         swap    d6    ;forget the value, old flags back
  104.         eor.b    d7,d6
  105.         and.w    #1,d6
  106.         eor.b    d7,d6    ;keep old carry
  107.         skip 1
  108.         next
  109.         ENDM
  110. ** ----
  111. In_A_1n1_mac    MACRO
  112.         getRPC    ;d7="Real PC" is addressing the immediate data
  113.         getz    d7,d7    ;transfer the byte to d7
  114.     ;Now, the port address is formed from A (bits 15-8)
  115.     ;and d7 (bits 7-0).
  116.         move.b    #DEFAULT_IN,A    ;"read" the value.
  117.         skip 1
  118.         next
  119.         ENDM
  120. ** ----
  121.  
  122. Ind_mac     MACRO
  123.         move.b    #DEFAULT_IN,d7
  124.         putz    d7,HL
  125.         decw    HL
  126.         and.w    #%1011,d6
  127.         decb    B
  128.         bne.s    01$    ;jump if not zero
  129.         or.w    #%0100,d6
  130. 01$        skip 1
  131.         next
  132.         ENDM
  133. ** ----
  134. Indr_mac    MACRO
  135.         move.b    #DEFAULT_IN,d7
  136. 01$        putz    d7,HL
  137.         decw    HL
  138.         decb    B
  139.         bne.s    01$    ;loop
  140.         or.w    #%0100,d6
  141.         skip 1
  142.         next
  143.         ENDM
  144. ** ----
  145. Ini_mac     MACRO
  146.         move.b    #DEFAULT_IN,d7
  147.         putz    d7,HL
  148.         incw    HL
  149.         and.w    #%1011,d6
  150.         decb    B
  151.         bne.s    01$    ;jump if not zero
  152.         or.w    #%0100,d6
  153. 01$        skip 1
  154.         next
  155.         ENDM
  156. ** ----
  157. Inir_mac    MACRO
  158.         move.b    #DEFAULT_IN,d7
  159. 01$        putz    d7,HL
  160.         incw    HL
  161.         decb    B
  162.         bne.s    01$    ;loop
  163.         or.w    #%0100,d6
  164.         skip 1
  165.         next
  166.         ENDM
  167. ** ----
  168. Ld_A_R_mac    MACRO
  169.         getRPC    ;take bits from RPC (since PPC is always even)
  170.         move.b    Z80_R(TableB),A
  171.         eor.w    d7,d6
  172.         and.w    #80,d6    ;keep bit 7 of stored R
  173.         eor.w    d7,d6    ;V is cleared, Z and N tested.
  174.         putsr    d7
  175.         eor.w    d7,d6
  176.         and.w    #1,d6    ;keep old carry
  177.         eor.w    d7,d6
  178.         tst.b    Z80_IFF(TableB)    ;test IFF2
  179.         beq.s    01$    ;jump if IFF2 clear
  180.         or.w    #%0010,d6    ;set V if IFF2 set
  181. 01$        skip 1
  182.         next
  183.         ENDM
  184. ** ----
  185. Ld_R_A_mac    MACRO
  186.         move.b    A,Z80_R(TableB)    ;(the bits 6-0 are never reused)
  187.         skip 1
  188.         next
  189.         ENDM
  190. ** ----
  191.  
  192. ** The Out instructions don't "output" anything, but merely change
  193. ** registers and flags as needed.
  194.  
  195. ** It is OK for Otir and Otdr to be a bit inefficient. The real Z80
  196. ** instruction does a complete re-execution each time it loops.
  197. ** If that is done here as well, the block output timing will be nicer.
  198.  
  199. Otdr_mac    MACRO
  200. 01$        getz    HL,d7
  201.         ;d7 holds the byte to be output,
  202.         ;BC the port address.
  203.         ;place "output" here
  204.         decw    HL
  205.         decb    B
  206.         bne.s    01$    ;loop
  207.         or.w    #%0100,d6    ;Set Z
  208.         skip 1
  209.         next
  210.         ENDM
  211. ** ----
  212. Otir_mac    MACRO
  213. 01$        getz    HL,d7
  214.         ;d7 holds the byte to be output,
  215.         ;BC the port address.
  216.         ;place "output" here
  217.         incw    HL
  218.         decb    B
  219.         bne.s    01$    ;loop
  220.         or.w    #%0100,d6    ;Set Z
  221.         skip 1
  222.         next
  223.         ENDM
  224. ** ----
  225. Out_1C1_r_mac    MACRO    ;Parameter: register
  226.         ;"output" to BC
  227.         skip 1
  228.         next
  229.         ENDM
  230.  
  231. Out_1C1_H_mac    MACRO
  232.         ;"output" to BC
  233.         skip 1
  234.         next
  235.         ENDM
  236. ** ----
  237.     ;"Undocumented" instruction. Seems to output a zero value
  238.     ;to the port. The name "Out (C),(HL)" would be symmetric,
  239.     ;but is not correct.
  240. Out_1C1_xx_mac    MACRO
  241.         ;"output" a zero to port BC
  242.         skip 1
  243.         next
  244.         ENDM
  245. ** ----
  246. Out_1n1_A_mac    MACRO
  247.         getRPC
  248.         getz    d7,d7    ;get immediate data to d7
  249.         ;"output" A to address given by d7 (bits 7-0)
  250.         ;(bits 15-8 seem tobe undefined)
  251.         skip 1
  252.         next
  253.         ENDM
  254. ** ----
  255. Outd_mac    MACRO
  256.         getz    HL,d7
  257.         ;"output" value in d7 to BC
  258.         decw    HL
  259.         and.w    #%1011,d6    ;Clear Z
  260.         decb    B
  261.         bne.s    01$    ;jump if not zero
  262.         or.w    #%0100,d6    ;Set Z
  263. $01        skip 1
  264.         next
  265.         ENDM
  266. ** ----
  267. Outi_mac    MACRO
  268.         getz    HL,d7
  269.         ;"output" value in d7 to BC
  270.         incw    HL
  271.         and.w    #%1011,d6    ;Clear Z
  272.         decb    B
  273.         bne.s    01$    ;jump if not zero
  274.         or.w    #%0100,d6    ;Set Z
  275. 01$        skip 1
  276.         next
  277.         ENDM
  278. ** ----
  279.  
  280. ** The Reti and Retn instructions do not themselves cause any signalling,
  281. ** but interrupt-controlling hardware could be watching the bus to see
  282. ** when an interrupt finishes.
  283.  
  284. Reti_mac    MACRO
  285.         ;Do any "hardware" emulation first.
  286.         getz    ZSP,1(Work)
  287.         incw    ZSP
  288.         getz    ZSP,(Work)
  289.         incw    ZSP
  290.         move.w    (Work),d7
  291.         makePPC
  292.         testreq
  293.         ENDM
  294. ** ----
  295. Retn_mac    MACRO
  296.         ;Do any "hardware" emulation first.
  297.         getz    ZSP,1(Work)
  298.         incw    ZSP
  299.         getz    ZSP,(Work)
  300.         incw    ZSP
  301.         move.w    (Work),d7
  302.         makePPC
  303.         move.b    Z80_IFF(TableB),d7
  304.         asr.b    #1,d7        ;IFF2 -> IFF1 -> bit 5
  305.         and.b    #$C0,d7     ;reset bits 5-0
  306.         move.b    d7,Z80_IFF(TableB)
  307.         testreq
  308.         ENDM
  309.  
  310. ** ======================================================================
  311.