home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 18
/
aminetcdnumber181997.iso
/
Aminet
/
misc
/
emu
/
gbuk.lha
/
src
/
Z80.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-09-17
|
15KB
|
428 lines
/*** VGB: portable GameBoy emulator ***************************/
/** **/
/** Z80.c **/
/** **/
/** This file contains implementation for the GameBoy CPU. **/
/** See Z80.h for the relevant definitions. Please, note **/
/** that this code can not be used to emulate a generic Z80 **/
/** because the GameBoy version of it differs from Z80 in **/
/** many ways. **/
/** **/
/** 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. **/
/*************************************************************/
#include "GB.h"
#include <stdio.h>
/*** Registers ***********************************************/
/*** Z80 registers and running flag. ***/
/*************************************************************/
reg R;
byte CPURunning;
/*** Interrupts **********************************************/
/*** Interrupt-related variables. ***/
/*************************************************************/
int IPeriod = 10000; /* Number of cmds between int. intrpts */
byte IntSync = 1; /* 1 to generate internal interrupts */
byte IFlag = 0; /* If IFlag==1, gen. int. and set to 0 */
int ICount; /* Variable used to count CPU cycles */
/*** Trace and Trap ******************************************/
/*** Switches to turn tracing on and off in DEBUG mode. ***/
/*************************************************************/
#ifdef DEBUG
byte Trace=0; /* Tracing is on if Trace==1 */
word Trap=0xFFFF; /* When PC==Trap, set Trace=1 */
#endif
/*** TrapBadOps **********************************************/
/*** When 1, print warnings of illegal Z80 instructions. ***/
/*************************************************************/
byte TrapBadOps=0;
#define S(Fl) R.AF.B.l|=Fl
#define R(Fl) R.AF.B.l&=~(Fl)
#define FLAGS(Rg,Fl) R.AF.B.l=Fl|(Rg? 0:Z_FLAG)|(Rg&S_FLAG)
#define M_RLC(Rg) \
R.AF.B.l=Rg&0x80? C_FLAG:0;Rg=(Rg<<1)|R.AF.B.l; \
R.AF.B.l|=(Rg? 0:Z_FLAG)|(Rg&S_FLAG)
#define M_R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R.Rg.B.l=M_RDMEM(R.SP.W++);R.Rg.B.h=M_RDMEM(R.SP.W++);
#define M_PUSH(Rg) \
M_WRMEM(--R.SP.W,R.Rg.B.h);M_WRMEM(--R.SP.W,R.Rg.B.l)
#define M_CALL \
J.B.l=M_RDMEM(R.PC.W++);J.B.h=M_RDMEM(R.PC.W++); \
M_WRMEM(--R.SP.W,R.PC.B.h);M_WRMEM(--R.SP.W,R.PC.B.l); \
R.PC.W=J.W
#define M_JP J.B.l=M_RDMEM(R.PC.W++);J.B.h=M_RDMEM(R.PC.W);R.PC.W=J.W
#define M_JR R.PC.W+=(offset)M_RDMEM(R.PC.W)+1
#define M_RET R.PC.B.l=M_RDMEM(R.SP.W++);R.PC.B.h=M_RDMEM(R.SP.W++)
#define M_RST(Ad) \
M_WRMEM(--R.SP.W,R.PC.B.h);M_WRMEM(--R.SP.W,R.PC.B.l);R.PC.W=Ad
#define M_LDWORD(Rg) \
R.Rg.B.l=M_RDMEM(R.PC.W++);R.Rg.B.h=M_RDMEM(R.PC.W++)
#define M_ADD(Rg) \
J.W=R.AF.B.h+Rg; \
R.AF.B.l= \
J.B.h|(J.B.l? 0:Z_FLAG)|(J.B.l&S_FLAG)| \
((R.AF.B.h^Rg^J.B.l)&H_FLAG); \
R.AF.B.h=J.B.l
#define M_SUB(Rg) \
J.W=R.AF.B.h-Rg; \
R.AF.B.l= \
N_FLAG|-J.B.h|(J.B.l? 0:Z_FLAG)|(J.B.l&S_FLAG)| \
((R.AF.B.h^Rg^J.B.l)&H_FLAG); \
R.AF.B.h=J.B.l
#define M_ADC(Rg) \
J.W=R.AF.B.h+Rg+(R.AF.B.l&C_FLAG); \
R.AF.B.l= \
J.B.h|(J.B.l? 0:Z_FLAG)|(J.B.l&S_FLAG)| \
((R.AF.B.h^Rg^J.B.l)&H_FLAG); \
R.AF.B.h=J.B.l
#define M_SBC(Rg) \
J.W=R.AF.B.h-Rg-(R.AF.B.l&C_FLAG); \
R.AF.B.l= \
N_FLAG|-J.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_L,RES4_xHL,RES4_A,
RES5_B,RES5_C,RES5_D,RES5_E,RES5_H,RES5_L,RES5_xHL,RES5_A,
RES6_B,RES6_C,RES6_D,RES6_E,RES6_H,RES6_L,RES6_xHL,RES6_A,
RES7_B,RES7_C,RES7_D,RES7_E,RES7_H,RES7_L,RES7_xHL,RES7_A,
SET0_B,SET0_C,SET0_D,SET0_E,SET0_H,SET0_L,SET0_xHL,SET0_A,
SET1_B,SET1_C,SET1_D,SET1_E,SET1_H,SET1_L,SET1_xHL,SET1_A,
SET2_B,SET2_C,SET2_D,SET2_E,SET2_H,SET2_L,SET2_xHL,SET2_A,
SET3_B,SET3_C,SET3_D,SET3_E,SET3_H,SET3_L,SET3_xHL,SET3_A,
SET4_B,SET4_C,SET4_D,SET4_E,SET4_H,SET4_L,SET4_xHL,SET4_A,
SET5_B,SET5_C,SET5_D,SET5_E,SET5_H,SET5_L,SET5_xHL,SET5_A,
SET6_B,SET6_C,SET6_D,SET6_E,SET6_H,SET6_L,SET6_xHL,SET6_A,
SET7_B,SET7_C,SET7_D,SET7_E,SET7_H,SET7_L,SET7_xHL,SET7_A
};
enum CodesED
{
DB_00,DB_01,DB_02,DB_03,DB_04,DB_05,DB_06,DB_07,
DB_08,DB_09,DB_0A,DB_0B,DB_0C,DB_0D,DB_0E,DB_0F,
DB_10,DB_11,DB_12,DB_13,DB_14,DB_15,DB_16,DB_17,
DB_18,DB_19,DB_1A,DB_1B,DB_1C,DB_1D,DB_1E,DB_1F,
DB_20,DB_21,DB_22,DB_23,DB_24,DB_25,DB_26,DB_27,
DB_28,DB_29,DB_2A,DB_2B,DB_2C,DB_2D,DB_2E,DB_2F,
DB_30,DB_31,DB_32,DB_33,DB_34,DB_35,DB_36,DB_37,
DB_38,DB_39,DB_3A,DB_3B,DB_3C,DB_3D,DB_3E,DB_3F,
IN_B_xC,OUT_xC_B,SBC_HL_BC,LD_xWORDe_BC,NEG,RETN,IM_0,LD_I_A,
IN_C_xC,OUT_xC_C,ADC_HL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C,DB_ED,DB_EE,DB_EF,
DB_F0,DB_F1,DB_F2,DB_F3,DB_F4,DB_F5,DB_F6,DB_F7,
DB_F8,DB_F9,DB_FA,DB_FB,DB_FC,DB_FD,DB_FE,DB_FF
};
void CodesCB(void)
{
register byte I;
switch(M_RDMEM(R.PC.W++))
{
#include "CodesCB.h"
default:
if(TrapBadOps)
printf
(
"Unrecognized instruction: CB %X at PC=%hX\n",
M_RDMEM(R.PC.W-1),R.PC.W-2
);
}
}
void CodesED(void)
{
register byte I;
register pair J;
switch(M_RDMEM(R.PC.W++))
{
#include "CodesED.h"
case PFX_ED:
#ifdef INTERRUPTS
ICount++;
#endif
R.PC.W--;break;
default:
if(TrapBadOps)
printf
(
"Unrecognized instruction: ED %X at PC=%hX\n",
M_RDMEM(R.PC.W-1),R.PC.W-2
);
}
}
/*** 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)
{
Regs->PC.W=0x0100;Regs->SP.W=0xF000;
Regs->AF.W=Regs->BC.W=Regs->DE.W=Regs->HL.W=0x0000;
Regs->I=0x00;Regs->IFF=0x00;
}
/*** Interpret Z80 code: **********************************/
/*** Registers have initial values from Regs. PC value ***/
/*** at which emulation stopped is returned by this ***/
/*** function. ***/
/**********************************************************/
word Z80(reg Regs)
{
register byte I;
register pair J;
R=Regs;ICount=IPeriod;CPURunning=1;
while (1)
{
LCDSTAT=(LCDSTAT&0xFC)|((ICount>>4)&0x03);
#ifdef DEBUG
if(R.PC.W==Trap) Trace=1; /*** Turn tracing on if trapped ***/
if(Trace) Debug(&R); /*** Call single-step debugger ***/
#endif
switch(M_RDMEM(R.PC.W++))
{
#include "Codes.h"
case PFX_CB: CodesCB();break;
case PFX_ED: CodesED();break;
case 0x10:
case HALT:
R.PC.W--;R.IFF|=0x80;break;
default:
if(TrapBadOps)
printf
(
"Unrecognized instruction: %X at PC=%hX\n",
M_RDMEM(R.PC.W-1),R.PC.W-1
);
}
if(!ICount--)
{
if(!CPURunning) break;
ICount=IPeriod;
/*
if(IntSync) IFlag=1;
}
if(IFlag)
{
IFlag=0;
*/
J.W=Interrupt();
if((J.W!=0xFFFF)&&(R.IFF&0x81))
{
if(R.IFF&0x80) R.PC.W++;
IFLAGS&=~IMask;R.IFF&=0x7E;
M_PUSH(PC);R.PC.W=J.W;
}
}
}
return(R.PC.W);
}