home *** CD-ROM | disk | FTP | other *** search
- /* Init.c: Init emulation.
- *
- * Copyright 1996 Rui Fernando Ferreira Ribeiro.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- /*
- * History:
- * 4th April 96:
- * . Added R_BIT7 for new handling of R register
- */
-
- #include <windows.h>
- #include "z80.h"
- #include "iglobal.h"
-
- /* vars to keep states of options for emulator */
- unsigned char bModel3 = 1; /* Model 3 or Model 2 */
- unsigned char bFlashOn = 1; /* Flash on or off */
- unsigned char bSoundOn = 1; /* Sound on or off */
- unsigned char Scale = 1; /* Scale of main window */
-
- /* vars needed to keep track of state of emulator */
- unsigned char WindowDirty = 1; /* Have we to redraw window? */
- unsigned char FlashState = 1; /* Are colours inverted or normal? */
- unsigned char ScreenUpdate = 2; /* Screen update: 50 fps/ScreenUpdate */
- unsigned short DelayEmVal = 0; /* Configurable delay to slow down
- emulation
- */
-
- /* Main registers */
- union Z80Regs Z80Regs;
-
- /* Alternative registers */
- union Z80Regs Z80Regs2;
-
- union Z80IX Z80IX;
- union Z80IY Z80IY;
-
- USHORT PC;
-
-
- USHORT SP;
- UCHAR R_BIT7, R, I;
-
- struct CPU_flags flags;
-
- /* 'ticks' counter ; SPECTRUM Z80A - 3,5469MHz - 70938 ticks between each INT */
- unsigned long clock_ticks;
-
- /* Interrupt mode - 0, 1 or 2 */
- UCHAR _IM;
-
- /* Interrupt flag & copy
- */
- UCHAR IFF1, IFF2;
-
- /* Used in DDCB and FDCB to keep a indice for IX and IY */
- UCHAR lastbyte;
-
- /* Memory 64k */
- UCHAR FAR * mem;
-
- /* ROM flag:
- * 0 : 16k of ROM, 48k of RAM
- * 1 : 64k of RAM
- */
- UCHAR WriteRom = 1;
-
- /* TraceOn defined in z80debug/z80debug.c & z80/ndebgz80.c
- */
- static UCHAR inited = 0;
-
- static HGLOBAL hglb = 0L;
-
- /*=========================================================================*
- * Init_Z80Emu *
- *=========================================================================*/
- void Init_Z80Emu()
- {
- if(inited++)
- {
- Warning("Z80 emulation already inited");
- }
- else
- {
- /* Alloc mem for emulation --- allways 64Kb, so do
- not have to test 'out-of-bounds' reading and
- writing memory
- i.e. PC = unsigned short (0-65535) ;
- */
-
-
- hglb = GlobalAlloc(GHND , 65536);
- mem = (UCHAR FAR *)GlobalLock( hglb );
- }
- }
-
- /*=========================================================================*
- * Close_Z80Emu *
- *=========================================================================*/
- void Close_Z80Emu()
- {
- if(inited)
- {
- /* close emulation */
- if(hglb != 0L) // free memory used
- {
- GlobalUnlock(hglb);
- GlobalFree(hglb);
- }
- inited--;
- }
- }
-
- USHORT parity_table[256] =
- {
- 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0,
- 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1,
- 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1,
- 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0,
- 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1,
- 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0,
- 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1,
- 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1,
- 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0,
- 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0,
- 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1,
- 0, 0, 1
- };
-
- /* EOF: Init.C */
-
-