home *** CD-ROM | disk | FTP | other *** search
/ PC Shareware 1996 December / PC_Shareware-1996-12.iso / windows / spectrum / sources / z80.h < prev   
Encoding:
C/C++ Source or Header  |  1996-05-12  |  4.8 KB  |  164 lines

  1.  
  2. /* Z80.h : Registers and primitives.
  3.  *
  4.  * Copyright 1996 Rui Fernando Ferreira Ribeiro.
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include "quirks.h"
  22.  
  23. /* Do not change the order!
  24. */
  25. struct Z80word_reg
  26. {
  27.    USHORT bc, de, hl, af;
  28. };
  29.  
  30. struct Z80byte_reg
  31. {
  32. #if !defined (M68000)
  33.    UCHAR c, b, e, d, l, h, f, a;
  34. #else
  35.    UCHAR b, c, d, e, h, l, a, f;
  36. #endif
  37. };
  38.  
  39. union Z80Regs
  40. {
  41.    struct Z80word_reg x;
  42.    struct Z80byte_reg k;
  43.    USHORT wregs[4];
  44.    UCHAR  bregs[8];
  45. };
  46.  
  47.  
  48. /*
  49.  * Flags (F) :   7   6   5   4   3   2   1   0
  50.  *             ---------------------------------
  51.  *             | S | Z | X | H | Y | P | N | C |
  52.  *             ---------------------------------
  53.  */
  54. struct CPU_flags
  55. {
  56.    USHORT  _S;   /* Sign                    */
  57.    USHORT  _Z;   /* Zero                    */
  58.    USHORT  _X;   /* Auxiliary Overflow  ?   */ /* Undocumented */
  59.    USHORT  _H;   /* Half carry              */
  60.    USHORT  _Y;   /* Auxliary Half carry ?   */ /* Undocumented */
  61.    USHORT  _P;   /* Parity - overflow - P/V */
  62.    USHORT  _N;   /* Subtraction             */
  63.    USHORT  _C;   /* Carry                   */
  64. };
  65.  
  66. /* Shortcuts */
  67.  
  68. #define BC   Z80Regs.x.bc     /* Z80Wreg(0) -- BC   */
  69. #define DE   Z80Regs.x.de     /* Z80Wreg(1) -- DE   */
  70. #define HL   Z80Regs.x.hl     /* Z80Wreg(2) -- HL   */
  71. #define AF   Z80Regs.x.af     /* Z80Wreg(3) -- AF   */
  72. #define B    Z80Regs.k.b      /* Z80Breg(0) -- B    */
  73. #define C    Z80Regs.k.c      /* Z80Breg(1) -- C    */
  74. #define D    Z80Regs.k.d      /* Z80Breg(2) -- D    */
  75. #define E    Z80Regs.k.e      /* Z80Breg(3) -- E    */
  76. #define H    Z80Regs.k.h      /* Z80Breg(4) -- H    */
  77. #define L    Z80Regs.k.l      /* Z80Breg(5) -- L    */
  78. #define A    Z80Regs.k.a      /* Z80Breg(6) -- A    */
  79. #define F    Z80Regs.k.f      /* Z80Breg(7) -- F    */
  80.  
  81. /* Note: to use F or AF, first build_F() must be called
  82. */
  83.  
  84. #define Z80Wreg(elem) Z80Regs.wregs[elem]
  85. #if !defined (M68000)
  86. #define Z80Breg(elem) Z80Regs.bregs[(elem)^1]
  87. #else
  88. #define Z80Breg(elem) Z80Regs.bregs[elem]
  89. #endif
  90.  
  91. /* Alternate register set */
  92. /* In the 'real' Z80 there is no acess to the alternate register set as a bytes
  93.   , but they might be needed to debugging purposes
  94. */
  95. #define BC2  Z80Regs2.x.bc    /* Z80Wreg2(0) -- BC' */
  96. #define DE2  Z80Regs2.x.de    /* Z80Wreg2(1) -- DE' */
  97. #define HL2  Z80Regs2.x.hl    /* Z80Wreg2(2) -- HL' */
  98. #define AF2  Z80Regs2.x.af    /* Z80Wreg2(3) -- AF' */
  99. #define B2   Z80Regs2.k.b     /* Z80Breg2(0) -- B'  */
  100. #define C2   Z80Regs2.k.c     /* Z80Breg2(1) -- C'  */
  101. #define D2   Z80Regs2.k.d     /* Z80Breg2(2) -- D'  */
  102. #define E2   Z80Regs2.k.e     /* Z80Breg2(3) -- E'  */
  103. #define H2   Z80Regs2.k.h     /* Z80Breg2(4) -- H'  */
  104. #define L2   Z80Regs2.k.l     /* Z80Breg2(5) -- L'  */
  105. #define A2   Z80Regs2.k.a     /* Z80Breg2(6) -- A'  */
  106. #define F2   Z80Regs2.k.f     /* Z80Breg2(7) -- F'  */
  107.  
  108. #define Z80Wreg2(elem) Z80Regs2.wregs[elem]
  109. #if !defined (M68000)
  110. #define Z80Breg2(elem) Z80Regs2.bregs[(elem)^1]
  111. #else
  112. #define Z80Breg2(elem) Z80Regs2.bregs[elem]
  113. #endif
  114.  
  115. union Z80IX
  116. {
  117.    USHORT IX;
  118.    UCHAR  bregs[2];
  119. };
  120.  
  121. union Z80IY
  122. {
  123.    USHORT IY;
  124.    UCHAR  bregs[2];
  125. };
  126.  
  127. #define IX Z80IX.IX
  128. #define IY Z80IY.IY
  129.  
  130. #if !defined (M68000)
  131. #define HX Z80IX.bregs[1]
  132. #define LX Z80IX.bregs[0]
  133. #define HY Z80IY.bregs[1]
  134. #define LY Z80IY.bregs[0]
  135. #else
  136. #define HX Z80IX.bregs[0]
  137. #define LX Z80IX.bregs[1]
  138. #define HY Z80IY.bregs[0]
  139. #define LY Z80IY.bregs[1]
  140. #endif
  141.  
  142. /* Clock ticks between each interrupt */
  143. #define INT_TIME 69888L         /* Timing provided by Ian Collier */
  144.  
  145. /*
  146.     Z80 Timings:
  147.  
  148.     Condition test       -->  1T
  149.     Inc/Dec 8  bits reg  -->  1T
  150.     Inc/Dec 16 bits reg  -->  2T
  151.     PC+n                 -->  5T
  152.     sum IX+n             -->  5T
  153.     read a memory byte   -->  3T
  154.     read a port   byte   -->  4T (3T + 1T in Wait)
  155.     Nmi int              -->  6T (3T + 3T - push two words in stack)
  156.     Int IM 0             --> 10T (3T + 3T + 4T from data bus read)
  157.     Int IM 1             -->  6T (3T + 3T)
  158.     Int IM 2             --> 16T (3T + 3T + 4T + 3T + 3T -- the last
  159.                 6T being 2 memory acesses to read the pointer
  160.                 built by reg I and the data bus value)
  161. */
  162.  
  163. /* EOF: Z80.h */
  164.