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

  1. /* Init.c: Init emulation.
  2.  *
  3.  * Copyright 1996 Rui Fernando Ferreira Ribeiro.
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. /*
  21.  * History:
  22.  *         4th April 96:
  23.  *              . Added R_BIT7 for new handling of R register
  24.  */
  25.  
  26. #include <windows.h>
  27. #include "z80.h"
  28. #include "iglobal.h"
  29.  
  30. /* vars to keep states of options for emulator */
  31. unsigned char          bModel3 = 1;   /* Model 3 or Model 2   */
  32. unsigned char        bFlashOn = 1;  /* Flash on or off      */
  33. unsigned char        bSoundOn = 1;  /* Sound on or off      */
  34. unsigned char        Scale = 1;     /* Scale of main window */
  35.  
  36. /* vars needed to keep track of state of emulator */
  37. unsigned char  WindowDirty  = 1;     /* Have we to redraw window?          */
  38. unsigned char  FlashState   = 1;     /* Are colours inverted or normal?    */
  39. unsigned char  ScreenUpdate = 2;     /* Screen update: 50 fps/ScreenUpdate */
  40. unsigned short DelayEmVal   = 0;     /* Configurable delay to slow down
  41.                        emulation
  42.                       */
  43.  
  44. /* Main registers   */
  45. union Z80Regs  Z80Regs;
  46.  
  47. /* Alternative registers */
  48. union Z80Regs  Z80Regs2;
  49.  
  50. union Z80IX    Z80IX;
  51. union Z80IY    Z80IY;
  52.  
  53. USHORT PC;
  54.  
  55.  
  56. USHORT  SP;
  57. UCHAR   R_BIT7, R,  I;
  58.  
  59. struct CPU_flags  flags;
  60.  
  61. /* 'ticks' counter ; SPECTRUM Z80A - 3,5469MHz - 70938 ticks between each INT */
  62. unsigned long clock_ticks;
  63.  
  64. /* Interrupt mode - 0, 1 or 2 */
  65. UCHAR _IM;
  66.  
  67. /* Interrupt flag & copy
  68.  */
  69. UCHAR IFF1, IFF2;
  70.  
  71. /* Used in DDCB and FDCB to keep a indice for IX and IY */
  72. UCHAR lastbyte;
  73.  
  74. /* Memory 64k */
  75. UCHAR FAR * mem;
  76.  
  77. /* ROM flag:
  78.  *  0 : 16k of ROM, 48k of RAM
  79.  *  1 : 64k of RAM
  80.  */
  81. UCHAR WriteRom = 1;
  82.  
  83. /* TraceOn defined in z80debug/z80debug.c & z80/ndebgz80.c
  84.  */
  85. static UCHAR inited = 0;
  86.  
  87. static HGLOBAL hglb = 0L;
  88.  
  89. /*=========================================================================*
  90.  *                            Init_Z80Emu                                  *
  91.  *=========================================================================*/
  92. void Init_Z80Emu()
  93. {
  94.     if(inited++)
  95.     {
  96.       Warning("Z80 emulation already inited");
  97.     }
  98.     else
  99.         {
  100.     /* Alloc mem for emulation --- allways 64Kb, so do
  101.      not have to test 'out-of-bounds' reading and
  102.      writing memory
  103.     i.e. PC = unsigned short (0-65535) ;
  104.     */
  105.  
  106.  
  107.       hglb = GlobalAlloc(GHND       , 65536);
  108.       mem =  (UCHAR FAR *)GlobalLock( hglb  );
  109.     }
  110. }
  111.  
  112. /*=========================================================================*
  113.  *                            Close_Z80Emu                                 *
  114.  *=========================================================================*/
  115. void Close_Z80Emu()
  116. {
  117.    if(inited)
  118.    {
  119.       /* close emulation */
  120.       if(hglb != 0L) // free memory used
  121.       {
  122.          GlobalUnlock(hglb);
  123.      GlobalFree(hglb);
  124.       }
  125.       inited--;
  126.    }
  127. }
  128.  
  129. USHORT parity_table[256] =
  130. {
  131. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0,
  132. 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1,
  133. 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1,
  134. 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0,
  135. 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1,
  136. 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0,
  137. 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1,
  138. 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1,
  139. 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0,
  140. 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0,
  141. 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1,
  142. 0, 0, 1
  143. };
  144.  
  145. /* EOF: Init.C */
  146.  
  147.