📄 z80.h
字号:
/** VGB: portable GameBoy emulator ***************************/
/** **/
/** Z80.h **/
/** **/
/** This file contains declarations relevant to emulation **/
/** of Z80 CPU. See GB.h for #defines related to drivers **/
/** and GameBoy emulation. **/
/** **/
/** Copyright (C) Marat Fayzullin 1994,1995,1996 **/
/** Marcel de Kogel 1996 **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
/*************************************************************/
/* #define DEBUG */ /* Compile debugging version */
#define LSB_FIRST /* Compile for low-endian CPU */
#define FAST_MEM /* Inline M_RDMEM() and M_WRMEM() */
/* These are not correct, but make calculations easier
Conversion to GB flag register format is done in the PUSH AF
and POP AF opcode emulations */
#define Z_FLAG 0x40
#define H_FLAG 0x10
#define N_FLAG 0x02
#define C_FLAG 0x01
/**********************************************************/
/*** NOTICE: sizeof(byte)=1 and sizeof(word)=2 ***/
/**********************************************************/
typedef unsigned char byte;
typedef unsigned short word;
typedef signed char offset;
/**********************************************************/
/*** #define LSB_FIRST for machines where least ***/
/*** signifcant byte goes first. ***/
/**********************************************************/
typedef union
{
#ifdef LSB_FIRST
struct { byte l,h,h1,h2; } B;
#else
struct { byte h2,h1,h,l; } B;
#endif
word W,W1;
unsigned D;
} pair;
typedef struct
{
pair AF,BC,DE,HL,PC,SP;
byte IFF,I;
} reg;
extern reg R;
/*** Interrupts *******************************************/
/*** Interrupt-related variables. ***/
/**********************************************************/
extern int IPeriod; /* Number of cycles between interrupts times 256 */
extern int ICount;
/*** Trace and Trap ***************************************/
/*** Switches to turn tracing on and off in DEBUG mode. ***/
/**********************************************************/
#ifdef DEBUG
extern byte Trace; /* Tracing is on if Trace==1 */
extern word Trap; /* When PC==Trap, set Trace=1 */
#endif
/*** TrapBadOps *******************************************/
/*** When 1, print warnings of illegal Z80 instructions.***/
/**********************************************************/
extern byte TrapBadOps;
/*** CPURunning *******************************************/
/*** When 0, execution terminates. ***/
/**********************************************************/
extern byte CPURunning;
/*** Reset Z80 registers: *********************************/
/*** This function can be used to reset the register ***/
/*** file before starting execution with Z80(). It sets ***/
/*** the registers to their initial values. ***/
/**********************************************************/
void ResetZ80(reg *Regs);
/*** Interpret Z80 code: **********************************/
/*** Registers have initial values from Regs. PC value ***/
/*** at which emulation stopped is returned by this ***/
/*** function. ***/
/**********************************************************/
/*** Interpret Z80 code: **********************************/
/*** Registers have initial values from Regs. PC value ***/
/*** at which emulation stopped is returned by this ***/
/*** function. ***/
/**********************************************************/
word Z80(reg Regs);
#ifdef DEBUG
/*** Single-step debugger *********************************/
/*** This function should exist if DEBUG is #defined. ***/
/*** If Trace==1 it is called after each command ***/
/*** executed by the CPU and given a pointer to the ***/
/*** register file. ***/
/**********************************************************/
void Debug(reg *R);
#endif
/*** Interrupt handler ************************************/
/*** This function should exist if INTERRUPTS is ***/
/*** #defined. It is called on each attempted interrupt ***/
/*** and should return an interrupt address to proceed ***/
/*** with interrupt or 0xFFFF to continue execution. ***/
/**********************************************************/
word Interrupt(void);
/**********************************************************/
/*** These functions are called when read or write to ***/
/*** RAM occurs. They perform actual reads abd writes. ***/
/**********************************************************/
typedef void (*WriteMemFn) (unsigned A,byte V) __attribute__ ((regparm(3)));
extern WriteMemFn WriteMemFnTable[256];
extern byte *RAM,*Page[8];
#ifndef FAST_MEM
void M_WRMEM(unsigned A,byte V) __attribute__ ((regparm(3)));
byte M_RDMEM(unsigned A) __attribute__ ((regparm(3)));
byte M_RDMEM_OPCODE(void);
#else
extern __inline__ byte M_RDMEM (unsigned A)
{
return(Page[A>>13][A&0x1FFF]);
}
extern __inline__ void M_WRMEM (unsigned A,byte V)
{
(*WriteMemFnTable[A>>8])(A,V);
}
extern __inline__ byte M_RDMEM_OPCODE (void)
{
byte V;
V=M_RDMEM (R.PC.D);
R.PC.W++;
return V;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -