home *** CD-ROM | disk | FTP | other *** search
/ PC Shareware 1996 December / PC_Shareware-1996-12.iso / windows / spectrum / sources / env.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-25  |  5.4 KB  |  193 lines

  1.  
  2. /* Env.h : Z80 global environment.
  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. /*
  22.  *      History:
  23.  *              . added RBIT_7 for R register improved handling
  24.  *
  25.  *      5th April 96:
  26.  *              . modified for new IX/IY handling
  27.  */
  28.  
  29. #include <windows.h>
  30. #include "z80.h"
  31. #include "iglobal.h"
  32.  
  33. #define BEGIN_RAM   16384
  34. #define BEGIN_VIDEO BEGIN_RAM
  35.  
  36. /* Len of description of Z80 files */
  37. #define LEN_DESCRIPT 30
  38.  
  39. /* For external declarations, see INIT.C */
  40.  
  41. /* vars to keep states of options for emulator */
  42. extern unsigned char         bModel3;    /* Model 3 or Model 2   */
  43. extern unsigned char        bFlashOn;   /* Flash on or off      */
  44. extern unsigned char        bSoundOn;   /* Sound on or off      */
  45. extern unsigned char        Scale;      /* Scale of main window */
  46. extern unsigned char        ScreenUpdate;/* Screen update: 50 fps
  47.                           /ScreenUpdate
  48.                       */
  49. extern unsigned short       DelayEmVal;  /* Configurable delay to slow down
  50.                               emulation
  51.                           */
  52.  
  53. /* vars needed to keep track of state of emulator */
  54. extern unsigned char WindowDirty;      /* Have we to redraw window?         */
  55. extern unsigned char FlashState;       /* Are colours inverted or normal?   */
  56.  
  57.  
  58. /* Main registers        */
  59. extern union Z80Regs  Z80Regs;
  60.  
  61. /* Alternative registers */
  62. extern union Z80Regs  Z80Regs2;
  63.  
  64. extern union Z80IX Z80IX;
  65. extern union Z80IY Z80IY;
  66.  
  67. extern USHORT PC;
  68.  
  69. extern USHORT  SP;
  70. extern UCHAR   R, R_BIT7,  I;
  71.  
  72. extern struct CPU_flags  flags;
  73.  
  74. /* 'ticks' counter ; SPECTRUM Z80A - 3,5469MHz -
  75.   70938 'ticks' between each int (50 per second)
  76. */
  77. extern unsigned long  clock_ticks;
  78.  
  79. /* Interrupt mode - 0, 1 or 2 */
  80. extern UCHAR _IM;
  81.  
  82. /* interrupt 'switch' interrupts and copy
  83.  *
  84.  *            IFF1  IFF2
  85.  *  ----------------------
  86.  *  | RESET  |  0  |  0  |
  87.  *  |--------+-----+-----|
  88.  *  | DI     |  0  |  0  |
  89.  *  |--------+-----+-----|
  90.  *  | EI     |  1  |  1  |
  91.  *  |--------+-----+-----|
  92.  *  | LD A,I |  .  |  .  | - P/V = IFF2
  93.  *  |--------+-----+-----|
  94.  *  | LD A,R |  .  |  .  | - P/V = IFF2
  95.  *  |--------+-----+-----|
  96.  *  | NMI    |  0  |  .  |
  97.  *  |--------+-----+-----|
  98.  *  | RETN   | IFF2|  .  |
  99.  *  |--------+-----+-----|
  100.  *  | INT    |  0  |  0  |
  101.  *  |--------+-----+-----|
  102.  *  | RETI   |  .  |  .  | - same as RET. (This instruction only exists
  103.  *  ----------------------              to be recognized by external
  104.  *                                      devices, so they know int is over)
  105.  */
  106. extern UCHAR IFF1, IFF2;
  107.  
  108. /* Used in DDCB or FDCB to keep shift of IX or IY
  109.  */
  110. extern UCHAR lastbyte;
  111.  
  112. /* 64k Mem
  113.  */
  114. extern UCHAR FAR * mem;
  115.  
  116. /* 'flag' WriteRom :
  117.  *  0 : 16k of ROM, 48k of RAM
  118.  *  1 : 64k of RAM
  119.  */
  120. extern UCHAR WriteRom;
  121.  
  122. /* 'flag' trace
  123.  */
  124. extern UCHAR TraceOn;
  125.  
  126. extern USHORT parity_table[256];
  127.  
  128. #define ResetTickCounter() clock_ticks = 0L;
  129. #define int_time() (clock_ticks >= INT_TIME)
  130. #define Force_interrupt() (clock_ticks = INT_TIME+1)
  131.  
  132. /* Increment counter by (cycles)
  133.  */
  134. #define T(cycles) (clock_ticks += cycles)
  135.  
  136. /* Decrement counter by (cycles)
  137.  */
  138. #define dT(cycles) (clock_ticks -= cycles)
  139.  
  140. /* Macro to put adress in PC
  141.  */
  142. #define PutPC(adress) PC = (USHORT)(adress)
  143.  
  144. /*  memory adressing - readbyte()
  145.  */
  146. #define readbyte(adress) (*(mem+(USHORT)(adress)))
  147.  
  148. /* read word pointed to PC and sum 2 to PC
  149.  */
  150. #define Getnextword() (PC += 2, readword((USHORT)(PC - 2)) )
  151.  
  152.  
  153. /* read byte pointed to PC and increment it
  154.  */
  155. #define Getnextbyte() readbyte(PC++)
  156.  
  157. /* Convert unsigned char to signed short (with signal extension)
  158.  */
  159. #define ucharToUshort(uchar) ((signed short)((signed char)(uchar)))
  160.  
  161. #define pIX   (IX+ucharToUshort(Getnextbyte()))
  162. #define pIY   (IY+ucharToUshort(Getnextbyte()))
  163. #define pCBIX (IX+ucharToUshort(lastbyte))
  164. #define pCBIY (IY+ucharToUshort(lastbyte))
  165.  
  166. /* build F from interpreter flags when needed
  167.  */
  168. #define build_F() F = (flags._C != 0) | ((flags._N != 0) << 1) | \
  169. ((flags._P != 0) << 2) | ((flags._Y != 0) << 3)| ((flags._H != 0) << 4) | \
  170. ((flags._X != 0) << 5) | ((flags._Z != 0) << 6) | ((flags._S != 0) << 7);
  171.  
  172. /* build interpreter flags from F
  173.  */
  174. #define read_F() flags._S=F & (UCHAR)BIT_7, flags._Z=F & (UCHAR)BIT_6, \
  175. flags._X=F & (UCHAR)BIT_5, flags._H=F & (UCHAR)BIT_4, flags._Y=F & \
  176. (UCHAR)BIT_3, flags._P=F & (UCHAR)BIT_2, flags._N = F & (UCHAR)BIT_1, \
  177. flags._C =F & (UCHAR)BIT_0;
  178.  
  179.  
  180.  
  181.  
  182. /* stack management - push and pop
  183.  */
  184. #define push(value) writeword((USHORT)(SP -=2), value)
  185. #define pop() (SP += 2, (USHORT)readbyte(SP - 2) | \
  186.           (((USHORT)readbyte(SP - 1)) << 8)  )
  187.  
  188. /* instead of a function, now we have a array
  189.  */
  190. #define   parity(x) (parity_table[x])
  191.  
  192. /* EOF: Env.h */
  193.