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

  1.     IFND Z80_STRUCT_I
  2. Z80_STRUCT_I SET 1
  3. ** The Z80 emulator control structure.
  4. ** Could be allocated in public memory, and shared between
  5. ** an emulating process and one or several supervising processes.
  6. **
  7. ** Define Z80_ENV_SIZE in 'user.i' if you want that added to the
  8. ** structure size, otherwise it will be defined to 0. See the bottom
  9. ** of this file for more details.
  10.  
  11. ** ------------
  12.  
  13.     IFD VERBOSE
  14.     LIST
  15. ** Compiling the Z80_struct.i file.
  16.     NOLIST
  17.     ENDC
  18.  
  19.     IFND Z80_INCLUDE
  20.     INCLUDE Z80.i
  21.     ENDC
  22.  
  23. ** Macro definitions for creating structure offsets:
  24.  
  25. Z80_STRUCT    MACRO        ;Begin structure.
  26. Z80_OFFSET    SET    0
  27.         ENDM
  28.  
  29. Z80_BYTE    MACRO    ;label
  30. \1        EQU    Z80_OFFSET
  31. Z80_OFFSET    SET    Z80_OFFSET+1
  32.         ENDM
  33.  
  34. Z80_WORD    MACRO    ;label        ;not auto-aligned!
  35. \1        EQU    Z80_OFFSET
  36. Z80_OFFSET    SET    Z80_OFFSET+2
  37.         ENDM
  38.  
  39. Z80_LONG    MACRO    ;label        ;not auto-aligned!
  40. \1        EQU    Z80_OFFSET
  41. Z80_OFFSET    SET    Z80_OFFSET+4
  42.         ENDM
  43.  
  44. Z80_BYTEARR    MACRO    ;name,size    ;array of bytes
  45. \1        EQU    Z80_OFFSET
  46. Z80_OFFSET    SET    Z80_OFFSET+\2
  47.         ENDM
  48.  
  49.     ;Set label without bumping the offset
  50. Z80_LABEL    MACRO    ;label
  51. \1        EQU    Z80_OFFSET
  52.         ENDM
  53.  
  54.     ;Bump offset without setting a label
  55. Z80_BUMP    MACRO    ;nbytes
  56. Z80_OFFSET    SET    Z80_OFFSET+\1
  57.         ENDM
  58.  
  59.     ;Set label to distance from other offset to current
  60. Z80_SIZE    MACRO    ;label,from_offs
  61. \1        EQU    Z80_OFFSET-\2
  62.         ENDM
  63.  
  64. Z80_ALIGN_W    MACRO            ;word-align
  65. Z80_OFFSET    SET    (Z80_OFFSET+1)&$fffffffe
  66.         ENDM
  67.  
  68. ** ============
  69. ** The entries begin here:
  70.  
  71.     Z80_STRUCT
  72.  
  73.     ;The base address is referred to as TableBase from now on.
  74.  
  75. ** This longword is for temporary storage, byte swapping and so on.
  76. ** Presently, it must be at TableBase, since Work and TableB are the
  77. ** same register.
  78.  
  79.     Z80_LONG    Z80_Workspace
  80.  
  81. ** ------------
  82. ** Index-accessed stuff. OFFSET FROM TABLEBASE MUST NEVER BE > +127 !
  83.  
  84. ** Public:
  85.     Z80_BYTEARR    Z80_AccessCnt,4*Z80_MEM_CNTNUM
  86.         ;Memory write access counters (longwords).
  87.  
  88.     ;private:
  89. Z80_BCDSTACKSIZE EQU 7        ;BCD stack (must be word-aligned!)
  90.     Z80_BYTEARR    Z80_BCDstack,6*Z80_BCDSTACKSIZE
  91.  
  92. ** Public:
  93.     Z80_BYTEARR    Z80_CntType,Z80_MEM_CNTNUM
  94.         ;Counter type designations (bytes).
  95.         ;Zero for write, nonzero for no write.
  96.  
  97.     Z80_BYTEARR    Z80_Parity,256    ;Parity translation table
  98.  
  99.     IFNE    Z80_Parity>127
  100.     FAIL    Bad offset for indexed object (parity table).
  101.     ENDC
  102.  
  103. ** end of index-accessed stuff.
  104. ** ------------
  105.  
  106.     Z80_ALIGN_W
  107.  
  108.     IFD Z80_MAIN
  109.     Z80_LABEL PROT_FIELDS    ;Start of stuff that survives coldstart.
  110.     ENDC
  111.  
  112. ** Public:
  113.     Z80_LONG Z80_Memory    ;Pointer to the Z80 address space memory
  114.     Z80_LONG Z80_Cachemem    ;Pointer to the cache memory
  115.  
  116. ** Public:
  117.     Z80_LONG Z80_Flagmem    ;Pointer to the flag memory
  118.     Z80_LONG Z80_MemHandler ;Pointer to User Memory Exception Handler
  119.  
  120.     Z80_ALIGN_W
  121.  
  122.     IFD Z80_MAIN
  123.     Z80_SIZE PROT_SIZE,PROT_FIELDS    ;End of survive-coldstart stuff
  124.     ENDC
  125.  
  126. ** Public (read-only):
  127.     Z80_LONG Z80_zero    ;Pointer to Z80 address 0. The (signed)
  128.                 ;word-sized Z80 registers (like Z80_HL)
  129.                 ;can be used as offsets from this base
  130.                 ;to access the Z80 memory space.
  131.     Z80_LONG Z80_cachezero    ;Corresponds to Z80_Zero in the cache.
  132.     Z80_LONG Z80_flagzero    ;Corresponds to Z80_zero in flag memory.
  133.  
  134. ** Public (read-only):
  135.     Z80_WORD Z80_Running    ;Nonzero if running, zero if not
  136.  
  137.     ; Private:
  138.     Z80_WORD Z80_Request    ;Request pointer (offset from InstrBase).
  139.     Z80_WORD Z80_ReqLvl    ;Current request priority level.
  140.     Z80_WORD Z80_alt_CCR    ;This is the internal F' in CCR format
  141.     Z80_WORD Z80_BCD_SP    ;Stack pointer for the BCD stack.
  142.  
  143. ** ------------
  144.  
  145.     ;The CPU status structure begins here.
  146.     ;(All offsets still relative to TableBase.)
  147.  
  148. ** The public fields:
  149. **
  150. ** The label naming conventions are simple: Z80_<register>
  151. ** The alternative registers are referred to as Z80_alt_<register>
  152. ** <register> here is one of:
  153. **    byte-valued    A, B, C, D, E, H, L, F, I, R
  154. **    word-valued    HL, IX, IY, SP, PC
  155. **    special     IFF, INTMOD
  156. ** Accessing HL will affect H and L and vice versa (HL is an 'alias').
  157. ** Only the word-valued entries are guaranteed to also be word-aligned.
  158. ** IFF and INTMOD are byte-sized, and should be interpreted as follows:
  159. **    IFF    Bit 7 holds IFF2. Bit 6 holds IFF1. Bits 5-0 are zero.
  160. **    INTMOD    The values in the range -1 to 1 correspond to interrupt
  161. **        modes 0 to 2, respectively.
  162.  
  163. ** None of these entries should be written to (and rather not read either)
  164. ** unless the emulator is stopped, since their contents are then undefined.
  165. ** Most are never updated or read from except upon exiting and continuing.
  166.  
  167.     Z80_ALIGN_W
  168.     Z80_LABEL    Z80_CpuStatus    ;offset of substructure start
  169.  
  170.     ;Storage area for 680x0 registers at exit. Remember to change
  171.     ;these labels if you rearrange the register usage.
  172.     ;Movem is of course used to write and restore, therefore it MUST
  173.     ;be at least word-aligned.
  174.     Z80_LABEL    Z80_RegStorage
  175.     Z80_BUMP 1        ;d0, high word
  176.     Z80_BYTE Z80_alt_A
  177.     Z80_BUMP 1        ;d0, low word
  178.     Z80_BYTE Z80_A
  179.     Z80_BUMP 1        ;d1, high word
  180.     Z80_BYTE Z80_alt_B
  181.     Z80_BUMP 1        ;d1, low word
  182.     Z80_BYTE Z80_B
  183.     Z80_BUMP 1        ;d2, high word
  184.     Z80_BYTE Z80_alt_C
  185.     Z80_BUMP 1        ;d2, low word
  186.     Z80_BYTE Z80_C
  187.     Z80_BUMP 1        ;d3, high word
  188.     Z80_BYTE Z80_alt_D
  189.     Z80_BUMP 1        ;d3, low word
  190.     Z80_BYTE Z80_D
  191.     Z80_BUMP 1        ;d4, high word
  192.     Z80_BYTE Z80_alt_E
  193.     Z80_BUMP 1        ;d4, low word
  194.     Z80_BYTE Z80_E
  195.     Z80_BUMP 2        ;d5, high word (garbage)
  196.     Z80_LABEL Z80_HL     ;HL (for word-access)
  197.     Z80_BYTE Z80_H        ;d5, low word
  198.     Z80_BYTE Z80_L
  199.  
  200.     ;d6 (current flags on CCR form) is recalculated at continue.
  201.     ;d7 holds nothing between instructions.
  202.     ;a0 (TableB) always comes as a parameter.
  203.     ;a1 (Pseudo-PC) is recalculated at Continue.
  204.  
  205.     Z80_BUMP 2        ;a2, high word
  206.     Z80_WORD Z80_SP     ;a2, low word
  207.  
  208.     ;Private fields
  209.     Z80_LONG Z80_Z0     ;a3
  210.     Z80_LONG Z80_CacheB    ;a4
  211.     Z80_LONG Z80_FlagsB    ;a5
  212.     Z80_BUMP 4        ;a6 (holds InstrB)
  213.     ;a7 (user sp) is never stored.
  214.  
  215.     ;End of 680x0 register storage
  216.  
  217.     Z80_LABEL Z80_IX     ;IX (for word-access)
  218.     Z80_BYTE Z80_XH        ;high byte
  219.     Z80_BYTE Z80_XL        ;low byte
  220.     
  221.     Z80_LABEL Z80_IY     ;IY (for word-access)
  222.     Z80_BYTE Z80_YH        ;high byte
  223.     Z80_BYTE Z80_YL        ;low byte
  224.  
  225.     Z80_LABEL Z80_alt_HL    ;H'L' (for word-access)
  226.     Z80_BYTE Z80_alt_H    ;H'
  227.     Z80_BYTE Z80_alt_L    ;L'
  228.  
  229.     Z80_WORD Z80_PC     ;PC (written/read only at exit/continue)
  230.  
  231.     Z80_BYTE Z80_F        ;These flags are calculated upon exit.
  232.     Z80_BYTE Z80_alt_F    ; During emulation, they are unused.
  233.  
  234.     Z80_BYTE Z80_IFF    ;IFF2 in bit 7, IFF1 in bit 6
  235.     Z80_BYTE Z80_INTMOD    ;Interruptmode (-1 to 1) = (modes 0 to 2)
  236.     Z80_BYTE Z80_I        ;Interrupt register
  237.     Z80_BYTE Z80_R        ;Refresh register
  238.     ;word aligned here
  239.  
  240.     ;These could be inspected. If nonzero, a request has been
  241.     ;received but not yet served.
  242.     Z80_WORD Z80_INT_FF    ;INTreq status
  243.     Z80_WORD Z80_NMI_FF    ;NMIreq status
  244.     Z80_WORD Z80_RES_FF    ;RESETreq status
  245.  
  246.     ;Private fields
  247.     Z80_LABEL Z80_BCD_DATA    ;BCD data size is fixed: 6 bytes.
  248.     Z80_WORD Z80_BCD_OP    ;BCD operation
  249.     Z80_WORD Z80_BCD_C    ;BCD carry in bit 0. Word-sized for shifts.
  250.     Z80_BYTE Z80_BCD_A    ;BCD destination
  251.     Z80_BYTE Z80_BCD_B    ;BCD source
  252.  
  253.     Z80_SIZE    Z80_CpuStatusSize,Z80_CpuStatus
  254.  
  255.     ;The CPU status structure ends here.
  256.  
  257. ** ------------
  258. ** Beginning of user environment data area. It is word-aligned,
  259. ** and has the size (in bytes) defined in Z80_ENV_SIZE, which could
  260. ** be just about anything, including zero. No entries follow it.
  261. ** It is intended mainly for accessing from the environment-specific
  262. ** instructions (see 'impldept.i' and 'generic_macs.i').
  263.  
  264.     Z80_ALIGN_W
  265.  
  266.     IFND Z80_ENV_SIZE
  267. Z80_ENV_SIZE EQU 0
  268.     ENDC
  269.  
  270.     Z80_BYTEARR    Z80_Envdata,Z80_ENV_SIZE
  271.  
  272.     IFNE    Z80_Envdata>$7fff
  273.     FAIL    Environment data is beyond word-sized offset from TableBase.
  274.     ENDC
  275.  
  276. ** ------------
  277. ** The table entries end here.
  278.  
  279.     Z80_LABEL    Z80_StructSize
  280.  
  281. ** ======================================================================
  282.     ENDC ;IFD Z80_STRUCT_I
  283.