summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2006-09-19 23:39:18 +0000
committerIan C <ianc@noddybox.co.uk>2006-09-19 23:39:18 +0000
commitba407390c6ae965fe217ca7ee2a8cffdd701b623 (patch)
tree596e8b455c1376ddb223bc951e8568f80132d337
parent18dd4ce5aa11515ecd54b01bc33ea5ce848b6990 (diff)
Changed interface so that Z80 registers are exposed publicly -- using a
Set/Get interface was too ponderous for emulation needs.
-rw-r--r--emma.c139
-rw-r--r--gemma.c184
-rw-r--r--z80.c162
-rw-r--r--z80.h103
-rw-r--r--z80_decode.c81
-rw-r--r--z80_dis.c8
-rw-r--r--z80_private.h60
7 files changed, 310 insertions, 427 deletions
diff --git a/emma.c b/emma.c
index 89a70de..a719885 100644
--- a/emma.c
+++ b/emma.c
@@ -207,17 +207,19 @@ static const char *FlagString(Z80Byte flag)
static void DisplayState(void)
{
- Z80State s;
-
- Z80GetState(z80,&s);
-
- Log("A=%2.2x F=%s ",s.AF>>8,FlagString(s.AF&0xff));
- Log("BC=%4.4x DE=%4.4x HL=%4.4x ",s.BC,s.DE,s.HL);
- Log("IX=%4.4x IY=%4.4x SP=%4.4x\n",s.IX,s.IY,s.SP);
- Log("I=%2.2x IM=%2.2x R=%2.2x ",s.I,s.IM,s.R);
- Log("IFF1=%2.2x IFF2=%2.2x CYCLES=%lu\n",s.IFF1,s.IFF2,s.cycle);
- Log("%4.4x: ",s.PC);
- Log("%s\n",Disassemble(&s.PC));
+ Z80Word pc;
+
+ pc=z80->PC;
+
+ Log("A=%2.2x F=%s ",
+ z80->AF.b[Z80_HI_WORD],FlagString(z80->AF.b[Z80_LO_WORD]));
+ Log("BC=%4.4x DE=%4.4x HL=%4.4x ",z80->BC.w,z80->DE.w,z80->HL.w);
+ Log("IX=%4.4x IY=%4.4x SP=%4.4x\n",z80->IX.w,z80->IY.w,z80->SP);
+ Log("I=%2.2x IM=%2.2x R=%2.2x ",z80->I,z80->IM,z80->R);
+ Log("IFF1=%2.2x IFF2=%2.2x CYCLES=%lu\n",
+ z80->IFF1,z80->IFF2,Z80Cycles(z80));
+ Log("%4.4x: ",pc);
+ Log("%s\n",Disassemble(&pc));
}
@@ -238,75 +240,72 @@ static int StrEq(const char *a, const char *b)
static int Expand(void *client, const char *p, long *res)
{
- Z80State s;
int ok=TRUE;
- Z80GetState(z80,&s);
-
if (StrEq(p,"AF"))
- *res=s.AF;
+ *res=z80->AF.w;
else if (StrEq(p,"BC"))
- *res=s.BC;
+ *res=z80->BC.w;
else if (StrEq(p,"DE"))
- *res=s.DE;
+ *res=z80->DE.w;
else if (StrEq(p,"HL"))
- *res=s.HL;
+ *res=z80->HL.w;
else if (StrEq(p,"IX"))
- *res=s.IX;
+ *res=z80->IX.w;
else if (StrEq(p,"IY"))
- *res=s.IY;
+ *res=z80->IY.w;
else if (StrEq(p,"SP"))
- *res=s.SP;
+ *res=z80->SP;
else if (StrEq(p,"PC"))
- *res=s.PC;
+ *res=z80->PC;
else if (StrEq(p,"A"))
- *res=HI(s.AF);
+ *res=HI(z80->AF.w);
else if (StrEq(p,"F"))
- *res=LO(s.AF);
+ *res=LO(z80->AF.w);
else if (StrEq(p,"B"))
- *res=HI(s.BC);
+ *res=HI(z80->BC.w);
else if (StrEq(p,"C"))
- *res=LO(s.BC);
+ *res=LO(z80->BC.w);
else if (StrEq(p,"D"))
- *res=HI(s.DE);
+ *res=HI(z80->DE.w);
else if (StrEq(p,"E"))
- *res=LO(s.DE);
+ *res=LO(z80->DE.w);
else if (StrEq(p,"H"))
- *res=HI(s.HL);
+ *res=HI(z80->HL.w);
else if (StrEq(p,"L"))
- *res=LO(s.HL);
+ *res=LO(z80->HL.w);
else if (StrEq(p,"AF_"))
- *res=s.AF_;
+ *res=z80->AF_;
else if (StrEq(p,"BC_"))
- *res=s.BC_;
+ *res=z80->BC_;
else if (StrEq(p,"DE_"))
- *res=s.DE_;
+ *res=z80->DE_;
else if (StrEq(p,"HL_"))
- *res=s.HL_;
+ *res=z80->HL_;
else if (StrEq(p,"A_"))
- *res=HI(s.AF_);
+ *res=HI(z80->AF_);
else if (StrEq(p,"F_"))
- *res=LO(s.AF_);
+ *res=LO(z80->AF_);
else if (StrEq(p,"B_"))
- *res=HI(s.BC_);
+ *res=HI(z80->BC_);
else if (StrEq(p,"C_"))
- *res=LO(s.BC_);
+ *res=LO(z80->BC_);
else if (StrEq(p,"D_"))
- *res=HI(s.DE_);
+ *res=HI(z80->DE_);
else if (StrEq(p,"E_"))
- *res=LO(s.DE_);
+ *res=LO(z80->DE_);
else if (StrEq(p,"H_"))
- *res=HI(s.HL_);
+ *res=HI(z80->HL_);
else if (StrEq(p,"L_"))
- *res=LO(s.HL_);
+ *res=LO(z80->HL_);
else if (StrEq(p,"IM"))
- *res=s.IM;
+ *res=z80->IM;
else if (StrEq(p,"R"))
- *res=s.R;
+ *res=z80->R;
else if (StrEq(p,"IFF1"))
- *res=s.IFF1;
+ *res=z80->IFF1;
else if (StrEq(p,"IFF2"))
- *res=s.IFF2;
+ *res=z80->IFF2;
else if (p[0]=='@')
{
Z80Word n;
@@ -709,20 +708,14 @@ static void DoStep(int no, const char *arg[])
static void DoSetPC(int no, const char *arg[])
{
- Z80State s;
-
- Z80GetState(z80,&s);
-
if (no<2)
{
- s.PC=MK(Z80_MEMORY[s.SP+1],Z80_MEMORY[s.SP]);
- s.SP+=2;
+ z80->PC=MK(Z80_MEMORY[z80->SP+1],Z80_MEMORY[z80->SP]);
+ z80->SP+=2;
DisplayState();
}
else
- s.PC=Address(arg[1]);
-
- Z80SetState(z80,&s);
+ z80->PC=Address(arg[1]);
}
@@ -730,11 +723,7 @@ static void DoRun(int no, const char *arg[])
{
if (no>1)
{
- Z80State s;
-
- Z80GetState(z80,&s);
- s.PC=Address(arg[1]);
- Z80SetState(z80,&s);
+ z80->PC=Address(arg[1]);
}
while(!stop)
@@ -766,11 +755,7 @@ static void DoUntil(int no, const char *arg[])
if (no>2)
{
- Z80State s;
-
- Z80GetState(z80,&s);
- s.PC=Address(arg[2]);
- Z80SetState(z80,&s);
+ z80->PC=Address(arg[2]);
}
while(!stop)
@@ -976,12 +961,9 @@ static Z80Byte ReadPort(Z80 *z80, Z80Word addr)
{
Z80Byte b=0xff;
Z80Word ptr;
- Z80State s;
char expr[1024];
char *p;
- Z80GetState(z80,&s);
-
switch(addr&0xff)
{
case 0x80:
@@ -1001,7 +983,7 @@ static Z80Byte ReadPort(Z80 *z80, Z80Word addr)
break;
case 0x81:
- ptr=s.DE;
+ ptr=z80->DE.w;
p=expr;
@@ -1025,9 +1007,9 @@ static Z80Byte ReadPort(Z80 *z80, Z80Word addr)
static void WritePort(Z80 *z80, Z80Word addr, Z80Byte val)
{
- Z80State s;
+ Z80Word de;
- Z80GetState(z80,&s);
+ de=z80->DE.w;
switch(addr&0xff)
{
@@ -1042,21 +1024,22 @@ static void WritePort(Z80 *z80, Z80Word addr, Z80Byte val)
break;
case 0x82:
- while(Z80_MEMORY[s.DE]!='$')
+ while(Z80_MEMORY[de]!='$')
{
- if (isspace(Z80_MEMORY[s.DE]) || isprint(Z80_MEMORY[s.DE]))
- Log("%c",Z80_MEMORY[s.DE]);
+ if (isspace(Z80_MEMORY[de]) ||
+ isprint(Z80_MEMORY[de]))
+ Log("%c",Z80_MEMORY[de]);
- s.DE++;
+ de++;
}
fflush(stdout);
break;
case 0x83:
- while(Z80_MEMORY[s.DE])
+ while(Z80_MEMORY[de])
{
- Log("%c",Z80_MEMORY[s.DE]);
- s.DE++;
+ Log("%c",Z80_MEMORY[de]);
+ de++;
}
fflush(stdout);
break;
diff --git a/gemma.c b/gemma.c
index c0fcf43..ec05b5d 100644
--- a/gemma.c
+++ b/gemma.c
@@ -93,7 +93,7 @@ static Z80Word Get_PC(int back)
static void Step(void)
{
- pc_buffer[pc_head]=Z80GetPC(z80);
+ pc_buffer[pc_head]=z80->PC;
if (pc_head)
pc_head--;
@@ -197,75 +197,72 @@ static int StrEq(const char *a, const char *b)
static int Expand(void *client, const char *p, long *res)
{
- Z80State s;
int ok=TRUE;
- Z80GetState(z80,&s);
-
if (StrEq(p,"AF"))
- *res=s.AF;
+ *res=z80->AF.w;
else if (StrEq(p,"BC"))
- *res=s.BC;
+ *res=z80->BC.w;
else if (StrEq(p,"DE"))
- *res=s.DE;
+ *res=z80->DE.w;
else if (StrEq(p,"HL"))
- *res=s.HL;
+ *res=z80->HL.w;
else if (StrEq(p,"IX"))
- *res=s.IX;
+ *res=z80->IX.w;
else if (StrEq(p,"IY"))
- *res=s.IY;
+ *res=z80->IY.w;
else if (StrEq(p,"SP"))
- *res=s.SP;
+ *res=z80->SP;
else if (StrEq(p,"PC"))
- *res=s.PC;
+ *res=z80->PC;
else if (StrEq(p,"A"))
- *res=HI(s.AF);
+ *res=HI(z80->AF.w);
else if (StrEq(p,"F"))
- *res=LO(s.AF);
+ *res=LO(z80->AF.w);
else if (StrEq(p,"B"))
- *res=HI(s.BC);
+ *res=HI(z80->BC.w);
else if (StrEq(p,"C"))
- *res=LO(s.BC);
+ *res=LO(z80->BC.w);
else if (StrEq(p,"D"))
- *res=HI(s.DE);
+ *res=HI(z80->DE.w);
else if (StrEq(p,"E"))
- *res=LO(s.DE);
+ *res=LO(z80->DE.w);
else if (StrEq(p,"H"))
- *res=HI(s.HL);
+ *res=HI(z80->HL.w);
else if (StrEq(p,"L"))
- *res=LO(s.HL);
+ *res=LO(z80->HL.w);
else if (StrEq(p,"AF_"))
- *res=s.AF_;
+ *res=z80->AF_;
else if (StrEq(p,"BC_"))
- *res=s.BC_;
+ *res=z80->BC_;
else if (StrEq(p,"DE_"))
- *res=s.DE_;
+ *res=z80->DE_;
else if (StrEq(p,"HL_"))
- *res=s.HL_;
+ *res=z80->HL_;
else if (StrEq(p,"A_"))
- *res=HI(s.AF_);
+ *res=HI(z80->AF_);
else if (StrEq(p,"F_"))
- *res=LO(s.AF_);
+ *res=LO(z80->AF_);
else if (StrEq(p,"B_"))
- *res=HI(s.BC_);
+ *res=HI(z80->BC_);
else if (StrEq(p,"C_"))
- *res=LO(s.BC_);
+ *res=LO(z80->BC_);
else if (StrEq(p,"D_"))
- *res=HI(s.DE_);
+ *res=HI(z80->DE_);
else if (StrEq(p,"E_"))
- *res=LO(s.DE_);
+ *res=LO(z80->DE_);
else if (StrEq(p,"H_"))
- *res=HI(s.HL_);
+ *res=HI(z80->HL_);
else if (StrEq(p,"L_"))
- *res=LO(s.HL_);
+ *res=LO(z80->HL_);
else if (StrEq(p,"IM"))
- *res=s.IM;
+ *res=z80->IM;
else if (StrEq(p,"R"))
- *res=s.R;
+ *res=z80->R;
else if (StrEq(p,"IFF1"))
- *res=s.IFF1;
+ *res=z80->IFF1;
else if (StrEq(p,"IFF2"))
- *res=s.IFF2;
+ *res=z80->IFF2;
else if (p[0]=='@')
{
Z80Word n;
@@ -428,12 +425,9 @@ static Z80Byte ReadPort(Z80 *z80, Z80Word addr)
{
Z80Byte b=0xff;
Z80Word ptr;
- Z80State s;
char expr[1024];
char *p;
- Z80GetState(z80,&s);
-
switch(addr&0xff)
{
case 0x80:
@@ -453,7 +447,7 @@ static Z80Byte ReadPort(Z80 *z80, Z80Word addr)
break;
case 0x81:
- ptr=s.DE;
+ ptr=z80->DE.w;
p=expr;
@@ -477,50 +471,47 @@ static Z80Byte ReadPort(Z80 *z80, Z80Word addr)
static void WritePort(Z80 *z80, Z80Word addr, Z80Byte val)
{
- Z80State s;
- DString ds;
+ Z80Word de;
- ds=DSInit();
- Z80GetState(z80,&s);
+ de=z80->DE.w;
switch(addr&0xff)
{
case 0x80:
- DSAddChar(ds,val);
+ Log("%c",val);
+ fflush(stdout);
break;
case 0x81:
- DSAdd(ds,"Stop requested via OUT(0x81)\n");
+ Log("Stop requested\n");
stop=TRUE;
break;
case 0x82:
- while(Z80_MEMORY[s.DE]!='$')
+ while(Z80_MEMORY[de]!='$')
{
- if (isspace(Z80_MEMORY[s.DE]) || isprint(Z80_MEMORY[s.DE]))
- {
- DSAddChar(ds,Z80_MEMORY[s.DE]);
- }
+ if (isspace(Z80_MEMORY[de]) ||
+ isprint(Z80_MEMORY[de]))
+ Log("%c",Z80_MEMORY[de]);
- s.DE++;
+ de++;
}
+ fflush(stdout);
break;
case 0x83:
- while(Z80_MEMORY[s.DE])
+ while(Z80_MEMORY[de])
{
- DSAddChar(ds,Z80_MEMORY[s.DE]);
- s.DE++;
+ Log("%c",Z80_MEMORY[de]);
+ de++;
}
+ fflush(stdout);
break;
default:
Log("Wrote 0x%2.2x to port 0x%4.4x\n",(int)val,(int)addr);
- return;
+ break;
}
-
- Log(ds->text);
- DSFree(ds);
}
@@ -538,10 +529,6 @@ static int Halt(Z80 *z80, Z80Val v)
*/
void GEMMA_UpdateDisplay(GEMMA_View view)
{
- Z80State reg;
-
- Z80GetState(z80,&reg);
-
if (view&UPDATE_ASSEM_VIEW)
{
Z80Word pc;
@@ -562,7 +549,7 @@ void GEMMA_UpdateDisplay(GEMMA_View view)
DSAddChar(ds,'\n');
}
- pc=Z80GetPC(z80);
+ pc=z80->PC;
for(f=0;f<12;f++)
{
@@ -593,65 +580,65 @@ void GEMMA_UpdateDisplay(GEMMA_View view)
if (view&UPDATE_REG_VIEW)
{
static int reg_once=FALSE;
- static Z80State last_reg;
+ static Z80 last_reg;
DString ds;
ds=DSInit();
if (!reg_once)
{
- last_reg=reg;
+ last_reg=*z80;
reg_once=TRUE;
}
DSAdd(ds,"<tt>");
- DisplayState(ds,"A ",2,HI(reg.AF),HI(last_reg.AF));
+ DisplayState(ds,"A ",2,HI(z80->AF.w),HI(last_reg.AF.w));
DSAdd(ds," ");
- FlagString(ds,LO(reg.AF),LO(last_reg.AF));
+ FlagString(ds,LO(z80->AF.w),LO(last_reg.AF.w));
DSAdd(ds,"\n");
- DisplayState(ds,"BC ",4,reg.BC,last_reg.BC);
+ DisplayState(ds,"BC ",4,z80->BC.w,last_reg.BC.w);
DSAdd(ds," ");
- DisplayState(ds,"DE ",4,reg.DE,last_reg.DE);
+ DisplayState(ds,"DE ",4,z80->DE.w,last_reg.DE.w);
DSAdd(ds," ");
- DisplayState(ds,"HL ",4,reg.HL,last_reg.HL);
+ DisplayState(ds,"HL ",4,z80->HL.w,last_reg.HL.w);
DSAdd(ds,"\n");
- DisplayState(ds,"SP ",4,reg.SP,last_reg.SP);
+ DisplayState(ds,"SP ",4,z80->SP,last_reg.SP);
DSAdd(ds," ");
- DisplayState(ds,"IX ",4,reg.IX,last_reg.IX);
+ DisplayState(ds,"IX ",4,z80->IX.w,last_reg.IX.w);
DSAdd(ds," ");
- DisplayState(ds,"IY ",4,reg.IY,last_reg.IY);
+ DisplayState(ds,"IY ",4,z80->IY.w,last_reg.IY.w);
DSAdd(ds,"\n\n");
- DisplayState(ds,"A' ",2,HI(reg.AF_),HI(last_reg.AF_));
+ DisplayState(ds,"A' ",2,HI(z80->AF_),HI(last_reg.AF_));
DSAdd(ds," ");
- FlagString(ds,LO(reg.AF_),LO(last_reg.AF_));
+ FlagString(ds,LO(z80->AF_),LO(last_reg.AF_));
DSAdd(ds,"\n");
- DisplayState(ds,"BC'",4,reg.BC_,last_reg.BC_);
+ DisplayState(ds,"BC'",4,z80->BC_,last_reg.BC_);
DSAdd(ds," ");
- DisplayState(ds,"DE'",4,reg.DE_,last_reg.DE_);
+ DisplayState(ds,"DE'",4,z80->DE_,last_reg.DE_);
DSAdd(ds," ");
- DisplayState(ds,"HL'",4,reg.HL_,last_reg.HL_);
+ DisplayState(ds,"HL'",4,z80->HL_,last_reg.HL_);
DSAdd(ds,"\n\n");
- DisplayState(ds,"PC ",4,reg.PC,last_reg.PC);
+ DisplayState(ds,"PC ",4,z80->PC,last_reg.PC);
DSAdd(ds," ");
- DisplayState(ds,"CYCLE",8,reg.cycle,last_reg.cycle);
+ DisplayState(ds,"CYCLE",8,Z80Cycles(z80),0);
DSAdd(ds,"\n\n");
- DisplayState(ds,"R ",2,reg.R,last_reg.R);
+ DisplayState(ds,"R ",2,z80->R,last_reg.R);
DSAdd(ds," ");
- DisplayState(ds,"IFF1",1,reg.IFF1,last_reg.IFF1);
+ DisplayState(ds,"IFF1",1,z80->IFF1,last_reg.IFF1);
DSAdd(ds," ");
- DisplayState(ds,"IFF2",1,reg.IFF2,last_reg.IFF2);
+ DisplayState(ds,"IFF2",1,z80->IFF2,last_reg.IFF2);
DSAdd(ds,"\n");
- DisplayState(ds,"IM ",1,reg.IM,last_reg.IM);
+ DisplayState(ds,"IM ",1,z80->IM,last_reg.IM);
DSAdd(ds," ");
- DisplayState(ds,"I",1,reg.I,last_reg.I);
+ DisplayState(ds,"I",1,z80->I,last_reg.I);
DSAdd(ds,"\n");
DSAdd(ds,"</tt>");
@@ -660,7 +647,7 @@ void GEMMA_UpdateDisplay(GEMMA_View view)
DSFree(ds);
- last_reg=reg;
+ last_reg=*z80;
}
if (view&UPDATE_MEM_VIEW)
@@ -678,26 +665,26 @@ void GEMMA_UpdateDisplay(GEMMA_View view)
switch(gtk_combo_box_get_active(GTK_COMBO_BOX(memview_combo)))
{
case 0:
- addr=reg.HL;
+ addr=z80->HL.w;
break;
case 1:
- addr=reg.SP;
+ addr=z80->SP;
as_words=TRUE;
break;
case 2:
- addr=reg.IX;
+ addr=z80->IX.w;
break;
case 3:
- addr=reg.IY;
+ addr=z80->IY.w;
break;
case 4:
- addr=reg.BC;
+ addr=z80->BC.w;
break;
case 5:
- addr=reg.DE;
+ addr=z80->DE.w;
break;
default:
- addr=reg.PC;
+ addr=z80->PC;
break;
}
@@ -896,20 +883,17 @@ void GEMMA_Step(void)
void GEMMA_StepOver(void)
{
Z80Word next;
- Z80State reg;
stop=FALSE;
- Z80GetState(z80,&reg);
- next=reg.PC;
+ next=z80->PC;
Z80Disassemble(z80,&next);
RUNNING(TRUE);
- while(reg.PC!=next && !stop)
+ while(z80->PC!=next && !stop)
{
Step();
- Z80GetState(z80,&reg);
gtk_main_iteration_do(FALSE);
}
@@ -986,7 +970,7 @@ void GEMMA_Init(GtkWidget *top)
#else
z80=Z80Init(Peek,Poke,ReadPort,WritePort,Peek);
#endif
- Z80SetPC(z80,0x100);
+ z80->PC=0x100;
if (!z80)
{
diff --git a/z80.c b/z80.c
index 3a15a22..be50494 100644
--- a/z80.c
+++ b/z80.c
@@ -55,28 +55,28 @@ static void Z80_CheckInterrupt(Z80 *cpu)
{
/* Check interrupts
*/
- if (cpu->raise)
+ if (PRIV->raise)
{
- if (cpu->nmi)
+ if (PRIV->nmi)
{
- if (cpu->halt)
+ if (PRIV->halt)
{
- cpu->halt=FALSE;
+ PRIV->halt=FALSE;
CALLBACK(eZ80_Halt,0);
cpu->PC++;
}
TSTATE(2);
cpu->IFF1=0;
- cpu->nmi=FALSE;
+ PRIV->nmi=FALSE;
PUSH(cpu->PC);
cpu->PC=0x66;
}
else if (cpu->IFF1)
{
- if (cpu->halt)
+ if (PRIV->halt)
{
- cpu->halt=FALSE;
+ PRIV->halt=FALSE;
CALLBACK(eZ80_Halt,0);
cpu->PC++;
}
@@ -88,7 +88,7 @@ static void Z80_CheckInterrupt(Z80 *cpu)
default:
case 0:
INC_R;
- Z80_Decode(cpu,cpu->devbyte);
+ Z80_Decode(cpu,PRIV->devbyte);
return;
break;
@@ -99,12 +99,12 @@ static void Z80_CheckInterrupt(Z80 *cpu)
case 2:
PUSH(cpu->PC);
- cpu->PC=(Z80Word)cpu->I*256+cpu->devbyte;
+ cpu->PC=(Z80Word)cpu->I*256+PRIV->devbyte;
break;
}
}
- cpu->raise=FALSE;
+ PRIV->raise=FALSE;
}
}
@@ -138,19 +138,29 @@ Z80 *Z80Init(Z80ReadMemory read_memory,
if (cpu)
{
+ cpu->priv=malloc(sizeof *cpu->priv);
+
+ if (cpu->priv)
+ {
#ifndef ENABLE_ARRAY_MEMORY
- cpu->mread=read_memory;
- cpu->mwrite=write_memory;
- cpu->disread=read_for_disassem;
+ PRIV->mread=read_memory;
+ PRIV->mwrite=write_memory;
+ PRIV->disread=read_for_disassem;
#endif
- cpu->pread=read_port;
- cpu->pwrite=write_port;
+ PRIV->pread=read_port;
+ PRIV->pwrite=write_port;
- for(f=0;f<eZ80_NO_CALLBACK;f++)
- for(r=0;r<MAX_PER_CALLBACK;r++)
- cpu->callback[f][r]=NULL;
+ for(f=0;f<eZ80_NO_CALLBACK;f++)
+ for(r=0;r<MAX_PER_CALLBACK;r++)
+ PRIV->callback[f][r]=NULL;
- Z80Reset(cpu);
+ Z80Reset(cpu);
+ }
+ else
+ {
+ free(cpu);
+ cpu=NULL;
+ }
}
return cpu;
@@ -159,7 +169,7 @@ Z80 *Z80Init(Z80ReadMemory read_memory,
void Z80Reset(Z80 *cpu)
{
- cpu->cycle=0;
+ PRIV->cycle=0;
cpu->PC=0;
cpu->AF.w=0xffff;
@@ -180,28 +190,22 @@ void Z80Reset(Z80 *cpu)
cpu->IM=0;
cpu->I=0;
cpu->R=0;
- cpu->halt=0;
+ PRIV->halt=0;
- cpu->raise=FALSE;
- cpu->nmi=FALSE;
+ PRIV->raise=FALSE;
+ PRIV->nmi=FALSE;
}
-void Z80SetPC(Z80 *cpu,Z80Word PC)
-{
- cpu->PC=PC;
-}
-
-
-Z80Word Z80GetPC(Z80 *cpu)
+Z80Val Z80Cycles(Z80 *cpu)
{
- return cpu->PC;
+ return PRIV->cycle;
}
void Z80ResetCycles(Z80 *cpu, Z80Val cycles)
{
- cpu->cycle=cycles;
+ PRIV->cycle=cycles;
}
@@ -211,9 +215,9 @@ int Z80LodgeCallback(Z80 *cpu, Z80CallbackReason reason, Z80Callback callback)
for(f=0;f<MAX_PER_CALLBACK;f++)
{
- if (!cpu->callback[reason][f])
+ if (!PRIV->callback[reason][f])
{
- cpu->callback[reason][f]=callback;
+ PRIV->callback[reason][f]=callback;
return TRUE;
}
}
@@ -227,23 +231,27 @@ void Z80RemoveCallback(Z80 *cpu, Z80CallbackReason reason, Z80Callback callback)
int f;
for(f=0;f<MAX_PER_CALLBACK;f++)
- if (cpu->callback[reason][f]==callback)
- cpu->callback[reason][f]=NULL;
+ {
+ if (PRIV->callback[reason][f]==callback)
+ {
+ PRIV->callback[reason][f]=NULL;
+ }
+ }
}
void Z80Interrupt(Z80 *cpu, Z80Byte devbyte)
{
- cpu->raise=TRUE;
- cpu->devbyte=devbyte;
- cpu->nmi=FALSE;
+ PRIV->raise=TRUE;
+ PRIV->devbyte=devbyte;
+ PRIV->nmi=FALSE;
}
void Z80NMI(Z80 *cpu)
{
- cpu->raise=TRUE;
- cpu->nmi=TRUE;
+ PRIV->raise=TRUE;
+ PRIV->nmi=TRUE;
}
@@ -251,12 +259,12 @@ int Z80SingleStep(Z80 *cpu)
{
Z80Byte opcode;
- cpu->last_cb=TRUE;
- cpu->shift=0;
+ PRIV->last_cb=TRUE;
+ PRIV->shift=0;
Z80_CheckInterrupt(cpu);
- CALLBACK(eZ80_Instruction,cpu->cycle);
+ CALLBACK(eZ80_Instruction,PRIV->cycle);
INC_R;
@@ -264,7 +272,7 @@ int Z80SingleStep(Z80 *cpu)
Z80_Decode(cpu,opcode);
- return cpu->last_cb;
+ return PRIV->last_cb;
}
@@ -274,68 +282,6 @@ void Z80Exec(Z80 *cpu)
}
-void Z80GetState(Z80 *cpu, Z80State *state)
-{
- state->cycle= cpu->cycle;
-
- state->AF = cpu->AF.w;
- state->BC = cpu->BC.w;
- state->DE = cpu->DE.w;
- state->HL = cpu->HL.w;
-
- state->AF_ = cpu->AF_;
- state->BC_ = cpu->BC_;
- state->DE_ = cpu->DE_;
- state->HL_ = cpu->HL_;
-
- state->IX = cpu->IX.w;
- state->IY = cpu->IY.w;
-
- state->SP = cpu->SP;
- state->PC = cpu->PC;
-
- state->IFF1 = cpu->IFF1;
- state->IFF2 = cpu->IFF2;
- state->IM = cpu->IM;
- state->I = cpu->I;
- state->R = cpu->R;
-}
-
-
-void Z80SetState(Z80 *cpu, const Z80State *state)
-{
- cpu->cycle = state->cycle;
-
- cpu->AF.w = state->AF;
- cpu->BC.w = state->BC;
- cpu->DE.w = state->DE;
- cpu->HL.w = state->HL;
-
- cpu->AF_ = state->AF_;
- cpu->BC_ = state->BC_;
- cpu->DE_ = state->DE_;
- cpu->HL_ = state->HL_;
-
- cpu->IX.w = state->IX;
- cpu->IY.w = state->IY;
-
- cpu->SP = state->SP;
- cpu->PC = state->PC;
-
- cpu->IFF1 = state->IFF1;
- cpu->IFF2 = state->IFF2;
- cpu->IM = state->IM;
- cpu->I = state->I;
- cpu->R = state->R;
-}
-
-
-Z80Val Z80Cycles(Z80 *cpu)
-{
- return cpu->cycle;
-}
-
-
void Z80SetLabels(Z80Label labels[])
{
z80_labels=labels;
@@ -364,7 +310,7 @@ const char *Z80Disassemble(Z80 *cpu, Z80Word *pc)
#ifdef ENABLE_ARRAY_MEMORY
strcat(s,Z80_Dis_Printf(" %.2x",(int)Z80_MEMORY[opc++]));
#else
- strcat(s,Z80_Dis_Printf(" %.2x",(int)cpu->disread(cpu,opc++)));
+ strcat(s,Z80_Dis_Printf(" %.2x",(int)PRIV->disread(cpu,opc++)));
#endif
}
diff --git a/z80.h b/z80.h
index f6bc041..000b950 100644
--- a/z80.h
+++ b/z80.h
@@ -35,12 +35,6 @@
/* ---------------------------------------- TYPES
*/
-/* The processor
-*/
-struct Z80;
-typedef struct Z80 Z80;
-
-
/* Large unsigned type
*/
typedef unsigned long Z80Val;
@@ -61,6 +55,53 @@ typedef signed char Z80Relative;
typedef unsigned short Z80Word;
+/* A Z80 16-bit register. To access the HI/LO component use the indexes
+ Z80_HI_WORD and Z80_LO_WORD which will be initialised once Z80Init has been
+ called.
+*/
+typedef union
+{
+ Z80Word w;
+ Z80Byte b[2];
+} Z80Reg;
+
+extern int Z80_HI_WORD;
+extern int Z80_LO_WORD;
+
+
+/* The processor
+*/
+struct Z80Private;
+
+typedef struct
+{
+ Z80Word PC;
+
+ Z80Reg AF;
+ Z80Reg BC;
+ Z80Reg DE;
+ Z80Reg HL;
+
+ Z80Word AF_;
+ Z80Word BC_;
+ Z80Word DE_;
+ Z80Word HL_;
+
+ Z80Reg IX;
+ Z80Reg IY;
+
+ Z80Word SP;
+
+ Z80Byte IFF1;
+ Z80Byte IFF2;
+ Z80Byte IM;
+ Z80Byte I;
+ Z80Byte R;
+
+ struct Z80Private *priv;
+} Z80;
+
+
/* Interfaces used to handle memory
*/
typedef Z80Byte (*Z80ReadMemory)(Z80 *cpu, Z80Word address);
@@ -100,36 +141,6 @@ typedef enum
} Z80CallbackReason;
-/* Get/settable state of the Z80
-*/
-typedef struct
-{
- Z80Word PC;
- Z80Word SP;
-
- Z80Val cycle;
-
- Z80Word AF;
- Z80Word BC;
- Z80Word DE;
- Z80Word HL;
-
- Z80Word AF_; /* Alternate registers */
- Z80Word BC_;
- Z80Word DE_;
- Z80Word HL_;
-
- Z80Word IX;
- Z80Word IY;
-
- Z80Byte IFF1;
- Z80Byte IFF2;
- Z80Byte IM;
- Z80Byte I;
- Z80Byte R;
-} Z80State;
-
-
/* Flags in the F register
*/
typedef enum
@@ -179,21 +190,6 @@ Z80 *Z80Init(Z80ReadMemory read_memory,
void Z80Reset(Z80 *cpu);
-/* Sets the PC
-*/
-void Z80SetPC(Z80 *cpu, Z80Word PC);
-
-
-/* Gets the PC
-*/
-Z80Word Z80GetPC(Z80 *cpu);
-
-
-/* Sets the cycle count to the specified count
-*/
-void Z80ResetCycles(Z80 *cpu, Z80Val cycles);
-
-
/* Lodge a callback to be invoked after special events. Returns FALSE
if the callback couldn't be lodged (there is a max of 10 callbacks per
reason).
@@ -233,11 +229,10 @@ int Z80SingleStep(Z80 *cpu);
void Z80Exec(Z80 *cpu);
-/* Interrogate the state of the Z80
+/* Manipulate the cylce count of the Z80
*/
Z80Val Z80Cycles(Z80 *cpu);
-void Z80GetState(Z80 *cpu, Z80State *state);
-void Z80SetState(Z80 *cpu, const Z80State *state);
+void Z80ResetCycles(Z80 *cpu, Z80Val cycles);
/* Set address to label mappings for the disassembler
diff --git a/z80_decode.c b/z80_decode.c
index c134b7b..a8f66ca 100644
--- a/z80_decode.c
+++ b/z80_decode.c
@@ -40,8 +40,11 @@ static Z80Byte Stable[512];
static Z80Byte Ztable[512];
-static int HI;
-static int LO;
+int Z80_HI_WORD;
+int Z80_LO_WORD;
+
+#define HI Z80_HI_WORD
+#define LO Z80_LO_WORD
/* ---------------------------------------- MISC FUNCTIONS
*/
@@ -127,8 +130,8 @@ static Z80Word FPEEKW(Z80 *cpu, Z80Word addr)
static void FPOKEW(Z80 *cpu, Z80Word addr, Z80Word val)
{
- cpu->mwrite(cpu,addr,val);
- cpu->mwrite(cpu,addr+1,val>>8);
+ PRIV->mwrite(cpu,addr,val);
+ PRIV->mwrite(cpu,addr+1,val>>8);
}
#endif
@@ -1020,9 +1023,9 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x40: /* IN B,(C) */
TSTATE(12);
- if (cpu->pread)
+ if (PRIV->pread)
{
- cpu->BC.b[HI]=cpu->pread(cpu,cpu->BC.w);
+ cpu->BC.b[HI]=PRIV->pread(cpu,cpu->BC.w);
}
else
{
@@ -1035,7 +1038,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x41: /* OUT (C),B */
TSTATE(12);
- if (cpu->pwrite) cpu->pwrite(cpu,cpu->BC.w,cpu->BC.b[HI]);
+ if (PRIV->pwrite) PRIV->pwrite(cpu,cpu->BC.w,cpu->BC.b[HI]);
break;
case 0x42: /* SBC HL,BC */
@@ -1079,9 +1082,9 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x48: /* IN C,(C) */
TSTATE(12);
- if (cpu->pread)
+ if (PRIV->pread)
{
- cpu->BC.b[LO]=cpu->pread(cpu,cpu->BC.w);
+ cpu->BC.b[LO]=PRIV->pread(cpu,cpu->BC.w);
}
else
{
@@ -1094,7 +1097,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x49: /* OUT (C),C */
TSTATE(12);
- if (cpu->pwrite) cpu->pwrite(cpu,cpu->BC.w,cpu->BC.b[LO]);
+ if (PRIV->pwrite) PRIV->pwrite(cpu,cpu->BC.w,cpu->BC.b[LO]);
break;
case 0x4a: /* ADC HL,BC */
@@ -1139,9 +1142,9 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x50: /* IN D,(C) */
TSTATE(12);
- if (cpu->pread)
+ if (PRIV->pread)
{
- cpu->DE.b[HI]=cpu->pread(cpu,cpu->BC.w);
+ cpu->DE.b[HI]=PRIV->pread(cpu,cpu->BC.w);
}
else
{
@@ -1154,7 +1157,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x51: /* OUT (C),D */
TSTATE(12);
- if (cpu->pwrite) cpu->pwrite(cpu,cpu->BC.w,cpu->DE.b[HI]);
+ if (PRIV->pwrite) PRIV->pwrite(cpu,cpu->BC.w,cpu->DE.b[HI]);
break;
case 0x52: /* SBC HL,DE */
@@ -1198,9 +1201,9 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x58: /* IN E,(C) */
TSTATE(12);
- if (cpu->pread)
+ if (PRIV->pread)
{
- cpu->DE.b[LO]=cpu->pread(cpu,cpu->BC.w);
+ cpu->DE.b[LO]=PRIV->pread(cpu,cpu->BC.w);
}
else
{
@@ -1213,7 +1216,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x59: /* OUT (C),E */
TSTATE(12);
- if (cpu->pwrite) cpu->pwrite(cpu,cpu->BC.w,cpu->DE.b[LO]);
+ if (PRIV->pwrite) PRIV->pwrite(cpu,cpu->BC.w,cpu->DE.b[LO]);
break;
case 0x5a: /* ADC HL,DE */
@@ -1257,9 +1260,9 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x60: /* IN H,(C) */
TSTATE(12);
- if (cpu->pread)
+ if (PRIV->pread)
{
- cpu->HL.b[HI]=cpu->pread(cpu,cpu->BC.w);
+ cpu->HL.b[HI]=PRIV->pread(cpu,cpu->BC.w);
}
else
{
@@ -1272,7 +1275,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x61: /* OUT (C),H */
TSTATE(12);
- if (cpu->pwrite) cpu->pwrite(cpu,cpu->BC.w,cpu->HL.b[HI]);
+ if (PRIV->pwrite) PRIV->pwrite(cpu,cpu->BC.w,cpu->HL.b[HI]);
break;
case 0x62: /* SBC HL,HL */
@@ -1327,9 +1330,9 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x68: /* IN L,(C) */
TSTATE(12);
- if (cpu->pread)
+ if (PRIV->pread)
{
- cpu->HL.b[LO]=cpu->pread(cpu,cpu->BC.w);
+ cpu->HL.b[LO]=PRIV->pread(cpu,cpu->BC.w);
}
else
{
@@ -1342,7 +1345,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x69: /* OUT (C),L */
TSTATE(12);
- if (cpu->pwrite) cpu->pwrite(cpu,cpu->BC.w,cpu->HL.b[LO]);
+ if (PRIV->pwrite) PRIV->pwrite(cpu,cpu->BC.w,cpu->HL.b[LO]);
break;
case 0x6a: /* ADC HL,HL */
@@ -1400,9 +1403,9 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
TSTATE(12);
- if (cpu->pread)
+ if (PRIV->pread)
{
- b=cpu->pread(cpu,cpu->BC.w);
+ b=PRIV->pread(cpu,cpu->BC.w);
}
else
{
@@ -1416,7 +1419,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x71: /* OUT (C) */
TSTATE(12);
- if (cpu->pwrite) cpu->pwrite(cpu,cpu->BC.w,0);
+ if (PRIV->pwrite) PRIV->pwrite(cpu,cpu->BC.w,0);
break;
case 0x72: /* SBC HL,SP */
@@ -1460,9 +1463,9 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x78: /* IN A,(C) */
TSTATE(12);
- if (cpu->pread)
+ if (PRIV->pread)
{
- cpu->AF.b[HI]=cpu->pread(cpu,cpu->BC.w);
+ cpu->AF.b[HI]=PRIV->pread(cpu,cpu->BC.w);
}
else
{
@@ -1475,7 +1478,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x79: /* OUT (C),A */
TSTATE(12);
- if (cpu->pwrite) cpu->pwrite(cpu,cpu->BC.w,cpu->AF.b[HI]);
+ if (PRIV->pwrite) PRIV->pwrite(cpu,cpu->BC.w,cpu->AF.b[HI]);
break;
case 0x7a: /* ADC HL,SP */
@@ -1697,7 +1700,7 @@ static void ShiftedDecodeCB(Z80 *cpu, Z80Byte opcode, Z80Relative offset)
/* See if we've come here from a IX/IY shift.
*/
- switch (cpu->shift)
+ switch (PRIV->shift)
{
case 0xdd:
addr=cpu->IX.w+offset;
@@ -1762,7 +1765,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
/* See if we've come here from a IX/IY shift
*/
- switch (cpu->shift)
+ switch (PRIV->shift)
{
case 0xdd:
HL=&(cpu->IX.w);
@@ -2168,10 +2171,10 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
TSTATE(4);
cpu->PC--;
- if (!cpu->halt)
+ if (!PRIV->halt)
CALLBACK(eZ80_Halt,1);
- cpu->halt=TRUE;
+ PRIV->halt=TRUE;
break;
case 0x77: /* LD (HL),A */
@@ -2244,7 +2247,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
/* Check for previous IX/IY shift.
*/
- if (cpu->shift!=0)
+ if (PRIV->shift!=0)
{
Z80Relative cb_offset;
@@ -2289,13 +2292,13 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0xd3: /* OUT (n),A */
TSTATE(11);
- if (cpu->pwrite)
+ if (PRIV->pwrite)
{
Z80Word port;
port=FETCH_BYTE;
port|=(Z80Word)cpu->AF.b[HI]<<8;
- cpu->pwrite(cpu,port,cpu->AF.b[HI]);
+ PRIV->pwrite(cpu,port,cpu->AF.b[HI]);
}
else
cpu->PC++;
@@ -2336,13 +2339,13 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0xdb: /* IN A,(n) */
TSTATE(11);
- if (cpu->pread)
+ if (PRIV->pread)
{
Z80Word port;
port=FETCH_BYTE;
port|=(Z80Word)cpu->AF.b[HI]<<8;
- cpu->AF.b[HI]=cpu->pread(cpu,port);
+ cpu->AF.b[HI]=PRIV->pread(cpu,port);
}
else
cpu->PC++;
@@ -2356,7 +2359,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
TSTATE(4);
INC_R;
- cpu->shift=opcode;
+ PRIV->shift=opcode;
Z80_Decode(cpu,FETCH_BYTE);
break;
@@ -2510,7 +2513,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
TSTATE(4);
INC_R;
- cpu->shift=opcode;
+ PRIV->shift=opcode;
Z80_Decode(cpu,FETCH_BYTE);
break;
diff --git a/z80_dis.c b/z80_dis.c
index 6204f0d..8a8ade8 100644
--- a/z80_dis.c
+++ b/z80_dis.c
@@ -67,7 +67,7 @@ Z80Byte Z80_Dis_FetchByte(Z80 *cpu, Z80Word *pc)
#ifdef ENABLE_ARRAY_MEMORY
return Z80_MEMORY[(*pc)++];
#else
- return cpu->disread(cpu,(*pc)++);
+ return cpu->priv->disread(cpu,(*pc)++);
#endif
}
@@ -1463,7 +1463,7 @@ static void DIS_DJNZ (Z80 *z80, Z80Byte op, Z80Word *pc)
#ifdef ENABLE_ARRAY_MEMORY
new=*pc+(Z80Relative)Z80_MEMORY[*pc]+1;
#else
- new=*pc+(Z80Relative)z80->disread(z80,*pc)+1;
+ new=*pc+(Z80Relative)z80->priv->disread(z80,*pc)+1;
#endif
(*pc)++;
Z80_Dis_Set("djnz",Z80_Dis_Printf("$%.4x",new));
@@ -1482,7 +1482,7 @@ static void DIS_JR (Z80 *z80, Z80Byte op, Z80Word *pc)
#ifdef ENABLE_ARRAY_MEMORY
new=*pc+(Z80Relative)Z80_MEMORY[*pc]+1;
#else
- new=*pc+(Z80Relative)z80->disread(z80,*pc)+1;
+ new=*pc+(Z80Relative)z80->priv->disread(z80,*pc)+1;
#endif
(*pc)++;
@@ -1507,7 +1507,7 @@ static void DIS_JR_CO (Z80 *z80, Z80Byte op, Z80Word *pc)
#ifdef ENABLE_ARRAY_MEMORY
new=*pc+(Z80Relative)Z80_MEMORY[*pc]+1;
#else
- new=*pc+(Z80Relative)z80->disread(z80,*pc)+1;
+ new=*pc+(Z80Relative)z80->priv->disread(z80,*pc)+1;
#endif
(*pc)++;
diff --git a/z80_private.h b/z80_private.h
index d031497..be45e56 100644
--- a/z80_private.h
+++ b/z80_private.h
@@ -45,40 +45,10 @@
/* ---------------------------------------- TYPES
*/
-typedef signed short sword;
-
-typedef union
-{
- Z80Word w;
- Z80Byte b[2];
-} Z80Reg;
-
-struct Z80
+struct Z80Private
{
Z80Val cycle;
- Z80Word PC;
-
- Z80Reg AF;
- Z80Reg BC;
- Z80Reg DE;
- Z80Reg HL;
-
- Z80Word AF_;
- Z80Word BC_;
- Z80Word DE_;
- Z80Word HL_;
-
- Z80Reg IX;
- Z80Reg IY;
-
- Z80Word SP;
-
- Z80Byte IFF1;
- Z80Byte IFF2;
- Z80Byte IM;
- Z80Byte I;
- Z80Byte R;
int halt;
Z80Byte shift;
@@ -102,6 +72,8 @@ struct Z80
int last_cb;
};
+#define PRIV cpu->priv
+
/* ---------------------------------------- ARRAY MEMORY
*/
@@ -126,9 +98,9 @@ extern Z80Byte Z80_MEMORY[];
int f; \
\
for(f=0;f<MAX_PER_CALLBACK;f++) \
- if (cpu->callback[r][f]) \
- cpu->last_cb &= \
- cpu->callback[r][f](cpu,d); \
+ if (PRIV->callback[r][f]) \
+ PRIV->last_cb &= \
+ PRIV->callback[r][f](cpu,d);\
} while(0)
/* Flag register
@@ -183,13 +155,13 @@ static inline Z80Word PEEKW(Z80Word addr)
#else
-#define PEEK(addr) (cpu->mread(cpu,addr))
+#define PEEK(addr) (PRIV->mread(cpu,addr))
#define PEEKW(addr) FPEEKW(cpu,addr)
-#define POKE(addr,val) cpu->mwrite(cpu,addr,val)
+#define POKE(addr,val) PRIV->mwrite(cpu,addr,val)
#define POKEW(addr,val) FPOKEW(cpu,addr,val)
-#define FETCH_BYTE (cpu->mread(cpu,cpu->PC++))
+#define FETCH_BYTE (PRIV->mread(cpu,cpu->PC++))
#define FETCH_WORD (cpu->PC+=2,FPEEKW(cpu,cpu->PC-2))
#endif
@@ -204,10 +176,10 @@ static inline Z80Word PEEKW(Z80Word addr)
#define CARRY IS_C
-#define IS_IX_IY (cpu->shift==0xdd || cpu->shift==0xfd)
+#define IS_IX_IY (PRIV->shift==0xdd || PRIV->shift==0xfd)
#define OFFSET(off) off=(IS_IX_IY ? (Z80Relative)FETCH_BYTE:0)
-#define TSTATE(n) cpu->cycle+=n
+#define TSTATE(n) PRIV->cycle+=n
#define ADD_R(v) cpu->R=((cpu->R&0x80)|((cpu->R+(v))&0x7f))
#define INC_R ADD_R(1)
@@ -228,8 +200,8 @@ static inline Z80Word PEEKW(Z80Word addr)
{ \
Z80Word pushv=REG; \
cpu->SP-=2; \
- cpu->mwrite(cpu,cpu->SP,pushv); \
- cpu->mwrite(cpu,cpu->SP+1,pushv>>8);\
+ PRIV->mwrite(cpu,cpu->SP,pushv); \
+ PRIV->mwrite(cpu,cpu->SP+1,pushv>>8);\
} while(0)
#endif
@@ -257,11 +229,11 @@ static inline Z80Word PEEKW(Z80Word addr)
#define OUT(P,V) do \
{ \
- if (cpu->pwrite) \
- cpu->pwrite(cpu,P,V); \
+ if (PRIV->pwrite) \
+ PRIV->pwrite(cpu,P,V); \
} while(0)
-#define IN(P) (cpu->pread?cpu->pread(cpu,P):0)
+#define IN(P) (PRIV->pread?PRIV->pread(cpu,P):0)