summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2023-04-23 08:24:31 +0800
committerIan C <ianc@noddybox.co.uk>2023-04-23 08:24:31 +0800
commit1d1e0acb5b4494f7c1b041e24e5de4f0614a150b (patch)
treef43094ced9e4b3dae4e9912eef606a9c567c635e /source
parentef18a653053c30237a9aff27eea91d38bd308987 (diff)
Updated Z80 emulation
Diffstat (limited to 'source')
-rw-r--r--source/z80.c26
-rw-r--r--source/z80_decode.c873
2 files changed, 510 insertions, 389 deletions
diff --git a/source/z80.c b/source/z80.c
index e5f6c92..d18640a 100644
--- a/source/z80.c
+++ b/source/z80.c
@@ -50,6 +50,8 @@ static void InitTables()
static void Z80_CheckInterrupt(Z80 *cpu)
{
+ Z80Word vector;
+
/* Check interrupts
*/
if (PRIV->raise)
@@ -68,6 +70,7 @@ static void Z80_CheckInterrupt(Z80 *cpu)
PRIV->nmi=FALSE;
PUSH(cpu->PC);
cpu->PC=0x66;
+ PRIV->memptr.w=cpu->PC;
}
else if (cpu->IFF1)
{
@@ -95,11 +98,14 @@ static void Z80_CheckInterrupt(Z80 *cpu)
case 1:
PUSH(cpu->PC);
cpu->PC=0x38;
+ PRIV->memptr.w=cpu->PC;
break;
case 2:
PUSH(cpu->PC);
- cpu->PC=(Z80Word)cpu->I*256+PRIV->devbyte;
+ vector=(Z80Word)cpu->I*256+PRIV->devbyte;
+ cpu->PC=PEEKW(vector);
+ PRIV->memptr.w=cpu->PC;
break;
}
}
@@ -170,6 +176,10 @@ Z80 *Z80Init(Z80ReadMemory read_memory,
void Z80Reset(Z80 *cpu)
{
PRIV->cycle=0;
+ PRIV->timer[Z80_TIMER_1]=0;
+ PRIV->timer[Z80_TIMER_2]=0;
+ PRIV->timer[Z80_TIMER_3]=0;
+
cpu->PC=0;
cpu->AF.w=0xffff;
@@ -194,6 +204,8 @@ void Z80Reset(Z80 *cpu)
PRIV->raise=FALSE;
PRIV->nmi=FALSE;
+
+ PRIV->memptr.w = 0x0000;
}
@@ -209,6 +221,18 @@ void Z80ResetCycles(Z80 *cpu, Z80Val cycles)
}
+Z80Val Z80GetTimer(Z80 *cpu, Z80Timer timer)
+{
+ return PRIV->timer[timer];
+}
+
+
+void Z80SetTimer(Z80 *cpu, Z80Timer timer, Z80Val cycles)
+{
+ PRIV->timer[timer] = cycles;
+}
+
+
int Z80LodgeCallback(Z80 *cpu, Z80CallbackReason reason, Z80Callback callback)
{
int f;
diff --git a/source/z80_decode.c b/source/z80_decode.c
index 614f384..15d0179 100644
--- a/source/z80_decode.c
+++ b/source/z80_decode.c
@@ -19,7 +19,7 @@
-------------------------------------------------------------------------
- $Id: z80_decode.c 4 2006-10-04 23:05:43Z ianc $
+ $Id$
*/
#include <stdlib.h>
@@ -36,13 +36,6 @@ static Z80Byte Ptable[512];
static Z80Byte Stable[512];
static Z80Byte Ztable[512];
-
-int Z80_HI_WORD;
-int Z80_LO_WORD;
-
-#define HI Z80_HI_WORD
-#define LO Z80_LO_WORD
-
/* ---------------------------------------- MISC FUNCTIONS
*/
void Z80_InitialiseInternals(void)
@@ -54,17 +47,7 @@ void Z80_InitialiseInternals(void)
*/
r.w=0x1234;
- if (r.b[0] == 0x12)
- {
- HI=0;
- LO=1;
- }
- else if (r.b[1] == 0x12)
- {
- HI=1;
- LO=0;
- }
- else
+ if (r.b.hi != 0x12 || r.b.lo != 0x34)
{
exit(1);
}
@@ -119,13 +102,13 @@ void Z80_InitialiseInternals(void)
}
#ifndef ENABLE_ARRAY_MEMORY
-static Z80Word FPEEKW(Z80 *cpu, Z80Word addr)
+Z80Word FPEEKW(Z80 *cpu, Z80Word addr)
{
return (PEEK(addr) | (Z80Word)PEEK(addr+1)<<8);
}
-static void FPOKEW(Z80 *cpu, Z80Word addr, Z80Word val)
+void FPOKEW(Z80 *cpu, Z80Word addr, Z80Word val)
{
PRIV->mwrite(cpu,addr,val);
PRIV->mwrite(cpu,addr+1,val>>8);
@@ -150,12 +133,12 @@ do { \
do { \
Z80Byte VAL=ONCE; \
unsigned w; \
- w=cpu->AF.b[HI]+(unsigned)VAL; \
- cpu->AF.b[LO]=SZtable[w]; \
- if ((cpu->AF.b[HI]^w^VAL)&H_Z80) cpu->AF.b[LO]|=H_Z80; \
- if ((VAL^cpu->AF.b[HI]^0x80)&(VAL^w)&0x80) cpu->AF.b[LO]|=P_Z80; \
+ w=cpu->AF.b.hi+(unsigned)VAL; \
+ cpu->AF.b.lo=SZtable[w]; \
+ if ((cpu->AF.b.hi^w^VAL)&H_Z80) cpu->AF.b.lo|=H_Z80; \
+ if ((VAL^cpu->AF.b.hi^0x80)&(VAL^w)&0x80) cpu->AF.b.lo|=P_Z80; \
SETHIDDEN(w); \
- cpu->AF.b[HI]=w; \
+ cpu->AF.b.hi=w; \
} while(0)
@@ -163,12 +146,12 @@ do { \
do { \
Z80Byte VAL=ONCE; \
unsigned w; \
- w=(cpu->AF.b[HI]+(unsigned)VAL+CARRY)&0x1ff; \
- cpu->AF.b[LO]=SZtable[w]; \
- if ((cpu->AF.b[HI]^w^VAL)&H_Z80) cpu->AF.b[LO]|=H_Z80; \
- if ((VAL^cpu->AF.b[HI]^0x80)&(VAL^w)&0x80) cpu->AF.b[LO]|=P_Z80; \
+ w=(cpu->AF.b.hi+(unsigned)VAL+CARRY)&0x1ff; \
+ cpu->AF.b.lo=SZtable[w]; \
+ if ((cpu->AF.b.hi^w^VAL)&H_Z80) cpu->AF.b.lo|=H_Z80; \
+ if ((VAL^cpu->AF.b.hi^0x80)&(VAL^w)&0x80) cpu->AF.b.lo|=P_Z80; \
SETHIDDEN(w); \
- cpu->AF.b[HI]=w; \
+ cpu->AF.b.hi=w; \
} while(0)
@@ -176,12 +159,12 @@ do { \
do { \
Z80Byte VAL=ONCE; \
unsigned w; \
- w=(cpu->AF.b[HI]-(unsigned)VAL)&0x1ff; \
- cpu->AF.b[LO]=SZtable[w]|N_Z80; \
- if ((cpu->AF.b[HI]^w^VAL)&H_Z80) cpu->AF.b[LO]|=H_Z80; \
- if ((VAL^cpu->AF.b[HI])&(cpu->AF.b[HI]^w)&0x80) cpu->AF.b[LO]|=P_Z80; \
+ w=(cpu->AF.b.hi-(unsigned)VAL)&0x1ff; \
+ cpu->AF.b.lo=SZtable[w]|N_Z80; \
+ if ((cpu->AF.b.hi^w^VAL)&H_Z80) cpu->AF.b.lo|=H_Z80; \
+ if ((VAL^cpu->AF.b.hi)&(cpu->AF.b.hi^w)&0x80) cpu->AF.b.lo|=P_Z80; \
SETHIDDEN(w); \
- cpu->AF.b[HI]=w; \
+ cpu->AF.b.hi=w; \
} while(0)
@@ -189,10 +172,10 @@ do { \
do { \
Z80Byte VAL=ONCE; \
unsigned w; \
- w=(cpu->AF.b[HI]-(unsigned)VAL)&0x1ff; \
- cpu->AF.b[LO]=SZtable[w]|N_Z80; \
- if ((cpu->AF.b[HI]^w^VAL)&H_Z80) cpu->AF.b[LO]|=H_Z80; \
- if ((VAL^cpu->AF.b[HI])&(cpu->AF.b[HI]^w)&0x80) cpu->AF.b[LO]|=P_Z80; \
+ w=(cpu->AF.b.hi-(unsigned)VAL)&0x1ff; \
+ cpu->AF.b.lo=SZtable[w]|N_Z80; \
+ if ((cpu->AF.b.hi^w^VAL)&H_Z80) cpu->AF.b.lo|=H_Z80; \
+ if ((VAL^cpu->AF.b.hi)&(cpu->AF.b.hi^w)&0x80) cpu->AF.b.lo|=P_Z80; \
SETHIDDEN(VAL); \
} while(0)
@@ -201,12 +184,12 @@ do { \
do { \
Z80Byte VAL=ONCE; \
unsigned w; \
- w=(cpu->AF.b[HI]-(unsigned)VAL-CARRY)&0x1ff; \
- cpu->AF.b[LO]=SZtable[w]|N_Z80; \
- if ((cpu->AF.b[HI]^w^VAL)&H_Z80) cpu->AF.b[LO]|=H_Z80; \
- if ((VAL^cpu->AF.b[HI])&(cpu->AF.b[HI]^w)&0x80) cpu->AF.b[LO]|=P_Z80; \
+ w=(cpu->AF.b.hi-(unsigned)VAL-CARRY)&0x1ff; \
+ cpu->AF.b.lo=SZtable[w]|N_Z80; \
+ if ((cpu->AF.b.hi^w^VAL)&H_Z80) cpu->AF.b.lo|=H_Z80; \
+ if ((VAL^cpu->AF.b.hi)&(cpu->AF.b.hi^w)&0x80) cpu->AF.b.lo|=P_Z80; \
SETHIDDEN(w); \
- cpu->AF.b[HI]=w; \
+ cpu->AF.b.hi=w; \
} while(0)
@@ -214,10 +197,11 @@ do { \
do { \
Z80Word VAL=ONCE; \
Z80Val w; \
+ cpu->priv->memptr.w=REG+1; \
w=(REG)+(Z80Val)VAL; \
- cpu->AF.b[LO]&=(S_Z80|Z_Z80|V_Z80); \
- if (w>0xffff) cpu->AF.b[LO]|=C_Z80; \
- if (((REG)^w^VAL)&0x1000) cpu->AF.b[LO]|=H_Z80; \
+ cpu->AF.b.lo&=(S_Z80|Z_Z80|V_Z80); \
+ if (w>0xffff) cpu->AF.b.lo|=C_Z80; \
+ if (((REG)^w^VAL)&0x1000) cpu->AF.b.lo|=H_Z80; \
SETHIDDEN(w>>8); \
(REG)=w; \
} while(0)
@@ -227,13 +211,14 @@ do { \
do { \
Z80Word VAL=ONCE; \
Z80Val w; \
+ cpu->priv->memptr.w=REG+1; \
w=(REG)+(Z80Val)VAL+CARRY; \
- cpu->AF.b[LO]=0; \
- if ((w&0xffff)==0) cpu->AF.b[LO]=Z_Z80; \
- if (w&0x8000) cpu->AF.b[LO]|=S_Z80; \
- if (w>0xffff) cpu->AF.b[LO]|=C_Z80; \
- if ((VAL^(REG)^0x8000)&((REG)^w)&0x8000) cpu->AF.b[LO]|=P_Z80; \
- if (((REG)^w^VAL)&0x1000) cpu->AF.b[LO]|=H_Z80; \
+ cpu->AF.b.lo=0; \
+ if ((w&0xffff)==0) cpu->AF.b.lo=Z_Z80; \
+ if (w&0x8000) cpu->AF.b.lo|=S_Z80; \
+ if (w>0xffff) cpu->AF.b.lo|=C_Z80; \
+ if ((VAL^(REG)^0x8000)&((REG)^w)&0x8000) cpu->AF.b.lo|=P_Z80; \
+ if (((REG)^w^VAL)&0x1000) cpu->AF.b.lo|=H_Z80; \
SETHIDDEN(w>>8); \
(REG)=w; \
} while(0)
@@ -243,13 +228,14 @@ do { \
do { \
Z80Word VAL=ONCE; \
Z80Val w; \
+ cpu->priv->memptr.w=REG+1; \
w=(REG)-(Z80Val)VAL-CARRY; \
- cpu->AF.b[LO]=N_Z80; \
- if (w&0x8000) cpu->AF.b[LO]|=S_Z80; \
- if ((w&0xffff)==0) cpu->AF.b[LO]|=Z_Z80; \
- if (w>0xffff) cpu->AF.b[LO]|=C_Z80; \
- if ((VAL^(REG))&((REG)^w)&0x8000) cpu->AF.b[LO]|=P_Z80; \
- if (((REG)^w^VAL)&0x1000) cpu->AF.b[LO]|=H_Z80; \
+ cpu->AF.b.lo=N_Z80; \
+ if (w&0x8000) cpu->AF.b.lo|=S_Z80; \
+ if ((w&0xffff)==0) cpu->AF.b.lo|=Z_Z80; \
+ if (w>0xffff) cpu->AF.b.lo|=C_Z80; \
+ if ((VAL^(REG))&((REG)^w)&0x8000) cpu->AF.b.lo|=P_Z80; \
+ if (((REG)^w^VAL)&0x1000) cpu->AF.b.lo|=H_Z80; \
SETHIDDEN(w>>8); \
(REG)=w; \
} while(0)
@@ -258,19 +244,19 @@ do { \
#define INC8(REG) \
do { \
(REG)++; \
- cpu->AF.b[LO]=CARRY|SZtable[(REG)]; \
- if ((REG)==0x80) cpu->AF.b[LO]|=P_Z80; \
- if (((REG)&0x0f)==0) cpu->AF.b[LO]|=H_Z80; \
+ cpu->AF.b.lo=CARRY|SZtable[(REG)]|((REG)&(B3_Z80|B5_Z80)); \
+ if ((REG)==0x80) cpu->AF.b.lo|=P_Z80; \
+ if (((REG)&0x0f)==0) cpu->AF.b.lo|=H_Z80; \
} while(0)
#define DEC8(REG) \
do { \
(REG)--; \
- cpu->AF.b[LO]=N_Z80|CARRY; \
- if ((REG)==0x7f) cpu->AF.b[LO]|=P_Z80; \
- if (((REG)&0x0f)==0x0f) cpu->AF.b[LO]|=H_Z80; \
- cpu->AF.b[LO]|=SZtable[(REG)]; \
+ cpu->AF.b.lo=N_Z80|CARRY|((REG)&(B3_Z80|B5_Z80)); \
+ if ((REG)==0x7f) cpu->AF.b.lo|=P_Z80; \
+ if (((REG)&0x0f)==0x0f) cpu->AF.b.lo|=H_Z80; \
+ cpu->AF.b.lo|=SZtable[(REG)]; \
} while(0)
@@ -285,6 +271,7 @@ do { \
#define OP_ON_MEM_WITH_ARG(OP,addr,arg) \
do { \
Z80Byte memop=PEEK(addr); \
+ PRIV->memptr.w=addr; \
OP(memop,arg); \
POKE(addr,memop); \
} while(0)
@@ -312,9 +299,9 @@ do { \
*/
#define RRCA \
do { \
- cpu->AF.b[LO]=(cpu->AF.b[LO]&(S_Z80|Z_Z80|P_Z80))|(cpu->AF.b[HI]&C_Z80); \
- cpu->AF.b[HI]=(cpu->AF.b[HI]>>1)|(cpu->AF.b[HI]<<7); \
- SETHIDDEN(cpu->AF.b[HI]); \
+ cpu->AF.b.lo=(cpu->AF.b.lo&(S_Z80|Z_Z80|P_Z80))|(cpu->AF.b.hi&C_Z80); \
+ cpu->AF.b.hi=(cpu->AF.b.hi>>1)|(cpu->AF.b.hi<<7); \
+ SETHIDDEN(cpu->AF.b.hi); \
} while(0)
@@ -322,9 +309,9 @@ do { \
do { \
Z80Byte c; \
c=CARRY; \
- cpu->AF.b[LO]=(cpu->AF.b[LO]&(S_Z80|Z_Z80|P_Z80))|(cpu->AF.b[HI]&C_Z80); \
- cpu->AF.b[HI]=(cpu->AF.b[HI]>>1)|(c<<7); \
- SETHIDDEN(cpu->AF.b[HI]); \
+ cpu->AF.b.lo=(cpu->AF.b.lo&(S_Z80|Z_Z80|P_Z80))|(cpu->AF.b.hi&C_Z80); \
+ cpu->AF.b.hi=(cpu->AF.b.hi>>1)|(c<<7); \
+ SETHIDDEN(cpu->AF.b.hi); \
} while(0)
@@ -333,7 +320,7 @@ do { \
Z80Byte c; \
c=(REG)&C_Z80; \
(REG)=((REG)>>1)|((REG)<<7); \
- cpu->AF.b[LO]=PSZtable[(REG)]|c; \
+ cpu->AF.b.lo=PSZtable[(REG)]|c; \
SETHIDDEN(REG); \
} while(0)
@@ -343,16 +330,16 @@ do { \
Z80Byte c; \
c=(REG)&C_Z80; \
(REG)=((REG)>>1)|(CARRY<<7); \
- cpu->AF.b[LO]=PSZtable[(REG)]|c; \
+ cpu->AF.b.lo=PSZtable[(REG)]|c; \
SETHIDDEN(REG); \
} while(0)
#define RLCA \
do { \
- cpu->AF.b[LO]=(cpu->AF.b[LO]&(S_Z80|Z_Z80|P_Z80))|(cpu->AF.b[HI]>>7); \
- cpu->AF.b[HI]=(cpu->AF.b[HI]<<1)|(cpu->AF.b[HI]>>7); \
- SETHIDDEN(cpu->AF.b[HI]); \
+ cpu->AF.b.lo=(cpu->AF.b.lo&(S_Z80|Z_Z80|P_Z80))|(cpu->AF.b.hi>>7); \
+ cpu->AF.b.hi=(cpu->AF.b.hi<<1)|(cpu->AF.b.hi>>7); \
+ SETHIDDEN(cpu->AF.b.hi); \
} while(0)
@@ -360,9 +347,9 @@ do { \
do { \
Z80Byte c; \
c=CARRY; \
- cpu->AF.b[LO]=(cpu->AF.b[LO]&(S_Z80|Z_Z80|P_Z80))|(cpu->AF.b[HI]>>7); \
- cpu->AF.b[HI]=(cpu->AF.b[HI]<<1)|c; \
- SETHIDDEN(cpu->AF.b[HI]); \
+ cpu->AF.b.lo=(cpu->AF.b.lo&(S_Z80|Z_Z80|P_Z80))|(cpu->AF.b.hi>>7); \
+ cpu->AF.b.hi=(cpu->AF.b.hi<<1)|c; \
+ SETHIDDEN(cpu->AF.b.hi); \
} while(0)
@@ -371,7 +358,7 @@ do { \
Z80Byte c; \
c=(REG)>>7; \
(REG)=((REG)<<1)|c; \
- cpu->AF.b[LO]=PSZtable[(REG)]|c; \
+ cpu->AF.b.lo=PSZtable[(REG)]|c; \
SETHIDDEN(REG); \
} while(0)
@@ -381,7 +368,7 @@ do { \
Z80Byte c; \
c=(REG)>>7; \
(REG)=((REG)<<1)|CARRY; \
- cpu->AF.b[LO]=PSZtable[(REG)]|c; \
+ cpu->AF.b.lo=PSZtable[(REG)]|c; \
SETHIDDEN(REG); \
} while(0)
@@ -391,7 +378,7 @@ do { \
Z80Byte c; \
c=(REG)&C_Z80; \
(REG)>>=1; \
- cpu->AF.b[LO]=PSZtable[(REG)]|c; \
+ cpu->AF.b.lo=PSZtable[(REG)]|c; \
SETHIDDEN(REG); \
} while(0)
@@ -401,7 +388,7 @@ do { \
Z80Byte c; \
c=(REG)&C_Z80; \
(REG)=((REG)>>1)|((REG)&0x80); \
- cpu->AF.b[LO]=PSZtable[(REG)]|c; \
+ cpu->AF.b.lo=PSZtable[(REG)]|c; \
SETHIDDEN(REG); \
} while(0)
@@ -411,7 +398,7 @@ do { \
Z80Byte c; \
c=(REG)>>7; \
(REG)=((REG)<<1)|1; \
- cpu->AF.b[LO]=PSZtable[(REG)]|c; \
+ cpu->AF.b.lo=PSZtable[(REG)]|c; \
SETHIDDEN(REG); \
} while(0)
@@ -421,7 +408,7 @@ do { \
Z80Byte c; \
c=(REG)>>7; \
(REG)=(REG)<<1; \
- cpu->AF.b[LO]=PSZtable[(REG)]|c; \
+ cpu->AF.b.lo=PSZtable[(REG)]|c; \
SETHIDDEN(REG); \
} while(0)
@@ -430,42 +417,58 @@ do { \
*/
#define AND(VAL) \
do { \
- cpu->AF.b[HI]&=VAL; \
- cpu->AF.b[LO]=PSZtable[cpu->AF.b[HI]]|H_Z80; \
- SETHIDDEN(cpu->AF.b[HI]); \
+ cpu->AF.b.hi&=VAL; \
+ cpu->AF.b.lo=PSZtable[cpu->AF.b.hi]|H_Z80; \
+ SETHIDDEN(cpu->AF.b.hi); \
} while(0)
#define OR(VAL) \
do { \
- cpu->AF.b[HI]|=VAL; \
- cpu->AF.b[LO]=PSZtable[cpu->AF.b[HI]]; \
- SETHIDDEN(cpu->AF.b[HI]); \
+ cpu->AF.b.hi|=VAL; \
+ cpu->AF.b.lo=PSZtable[cpu->AF.b.hi]; \
+ SETHIDDEN(cpu->AF.b.hi); \
} while(0)
#define XOR(VAL) \
do { \
- cpu->AF.b[HI]^=VAL; \
- cpu->AF.b[LO]=PSZtable[cpu->AF.b[HI]]; \
- SETHIDDEN(cpu->AF.b[HI]); \
+ cpu->AF.b.hi^=VAL; \
+ cpu->AF.b.lo=PSZtable[cpu->AF.b.hi]; \
+ SETHIDDEN(cpu->AF.b.hi); \
} while(0)
#define BIT(REG,B) \
do { \
- cpu->AF.b[LO]=CARRY|H_Z80; \
- if ((REG)&(1<<B)) \
+ Z80Byte b=(REG)&(1<<B); \
+ cpu->AF.b.lo&=C_Z80; \
+ cpu->AF.b.lo|=H_Z80; \
+ if (b) \
+ { \
+ cpu->AF.b.lo|=S_Z80&b; \
+ } \
+ else \
+ { \
+ cpu->AF.b.lo|=Z_Z80|P_Z80; \
+ } \
+ SETHIDDEN(REG); \
+} while(0)
+
+#define BIT_MEMPTR(REG,B) \
+do { \
+ Z80Byte b=(REG)&(1<<B); \
+ cpu->AF.b.lo&=C_Z80; \
+ cpu->AF.b.lo|=H_Z80; \
+ if (b) \
{ \
- if (B==7 && (REG&S_Z80)) cpu->AF.b[LO]|=S_Z80; \
- if (B==5 && (REG&B5_Z80)) cpu->AF.b[LO]|=B5_Z80; \
- if (B==3 && (REG&B3_Z80)) cpu->AF.b[LO]|=B3_Z80; \
+ cpu->AF.b.lo|=S_Z80&b; \
} \
else \
{ \
- cpu->AF.b[LO]|=Z_Z80; \
- cpu->AF.b[LO]|=P_Z80; \
+ cpu->AF.b.lo|=Z_Z80|P_Z80; \
} \
+ SETHIDDEN(PRIV->memptr.b.hi); \
} while(0)
#define BIT_SET(REG,B) (REG)|=(1<<B)
@@ -524,6 +527,7 @@ do { \
{ \
TSTATE(11); \
POP(cpu->PC); \
+ PRIV->memptr.w=cpu->PC; \
} \
else \
{ \
@@ -535,13 +539,14 @@ do { \
#define RST(ADDR) \
TSTATE(11); \
PUSH(cpu->PC); \
- cpu->PC=ADDR
+ cpu->PC=ADDR; \
+ PRIV->memptr.w=ADDR
/* ---------------------------------------- BLOCK OPERATIONS
*/
#define LDI \
do { \
- Z80Byte b; \
+ Z80Byte b,a1; \
\
b=PEEK(cpu->HL.w); \
POKE(cpu->DE.w,b); \
@@ -557,12 +562,14 @@ do { \
else \
CLRFLAG(P_Z80); \
\
- SETHIDDEN(cpu->AF.b[HI]+b); \
+ a1=cpu->AF.b.hi+b; \
+ if (a1&2) SETFLAG(B5_Z80); else CLRFLAG(B5_Z80); \
+ if (a1&B3_Z80) SETFLAG(B3_Z80); else CLRFLAG(B3_Z80); \
} while(0)
#define LDD \
do { \
- Z80Byte b; \
+ Z80Byte b,a1; \
\
b=PEEK(cpu->HL.w); \
POKE(cpu->DE.w,b); \
@@ -578,17 +585,23 @@ do { \
else \
CLRFLAG(P_Z80); \
\
- SETHIDDEN(cpu->AF.b[HI]+b); \
+ a1=cpu->AF.b.hi+b; \
+ if (a1&2) SETFLAG(B5_Z80); else CLRFLAG(B5_Z80); \
+ if (a1&B3_Z80) SETFLAG(B3_Z80); else CLRFLAG(B3_Z80); \
} while(0)
#define CPI \
do { \
- Z80Byte c,b; \
+ Z80Byte c,b,a1; \
\
c=CARRY; \
b=PEEK(cpu->HL.w); \
\
CMP8(b); \
+ a1=cpu->AF.b.hi-b-(IS_H?1:0); \
+ \
+ if (a1&2) SETFLAG(B5_Z80); else CLRFLAG(B5_Z80); \
+ if (a1&B3_Z80) SETFLAG(B3_Z80); else CLRFLAG(B3_Z80); \
\
if (c) \
SETFLAG(C_Z80); \
@@ -606,13 +619,17 @@ do { \
#define CPD \
do { \
- Z80Byte c,b; \
+ Z80Byte c,b,a1; \
\
c=CARRY; \
b=PEEK(cpu->HL.w); \
\
CMP8(b); \
+ a1=cpu->AF.b.hi-b-(IS_H?1:0); \
\
+ if (a1&2) SETFLAG(B5_Z80); else CLRFLAG(B5_Z80); \
+ if (a1&B3_Z80) SETFLAG(B3_Z80); else CLRFLAG(B3_Z80); \
+\
if (c) \
SETFLAG(C_Z80); \
else \
@@ -635,13 +652,13 @@ do { \
b=IN(cpu->BC.w); \
POKE(cpu->HL.w,b); \
\
- cpu->BC.b[HI]--; \
+ cpu->BC.b.hi--; \
cpu->HL.w++; \
\
- cpu->AF.b[LO]=SZtable[cpu->BC.b[HI]]; \
- SETHIDDEN(cpu->BC.b[HI]); \
+ cpu->AF.b.lo=SZtable[cpu->BC.b.hi]; \
+ SETHIDDEN(cpu->BC.b.hi); \
\
- w=(((Z80Word)cpu->BC.b[LO])&0xff)+b; \
+ w=(((Z80Word)cpu->BC.b.lo)&0xff)+b; \
\
if (b&0x80) \
SETFLAG(N_Z80); \
@@ -666,13 +683,13 @@ do { \
b=IN(cpu->BC.w); \
POKE(cpu->HL.w,b); \
\
- cpu->BC.b[HI]--; \
+ cpu->BC.b.hi--; \
cpu->HL.w--; \
\
- cpu->AF.b[LO]=SZtable[cpu->BC.b[HI]]; \
- SETHIDDEN(cpu->BC.b[HI]); \
+ cpu->AF.b.lo=SZtable[cpu->BC.b.hi]; \
+ SETHIDDEN(cpu->BC.b.hi); \
\
- w=(((Z80Word)cpu->BC.b[LO])&0xff)+b; \
+ w=(((Z80Word)cpu->BC.b.lo)&0xff)+b; \
\
if (b&0x80) \
SETFLAG(N_Z80); \
@@ -694,10 +711,10 @@ do { \
OUT(cpu->BC.w,PEEK(cpu->HL.w)); \
\
cpu->HL.w++; \
- cpu->BC.b[HI]--; \
+ cpu->BC.b.hi--; \
\
- cpu->AF.b[LO]=SZtable[cpu->BC.b[HI]]; \
- SETHIDDEN(cpu->BC.b[HI]); \
+ cpu->AF.b.lo=SZtable[cpu->BC.b.hi]; \
+ SETHIDDEN(cpu->BC.b.hi); \
} while(0)
#define OUTD \
@@ -705,11 +722,11 @@ do { \
OUT(cpu->BC.w,PEEK(cpu->HL.w)); \
\
cpu->HL.w--; \
- cpu->BC.b[HI]--; \
+ cpu->BC.b.hi--; \
\
- cpu->AF.b[LO]=SZtable[cpu->BC.b[HI]]; \
+ cpu->AF.b.lo=SZtable[cpu->BC.b.hi]; \
SETFLAG(N_Z80); \
- SETHIDDEN(cpu->BC.b[HI]); \
+ SETHIDDEN(cpu->BC.b.hi); \
} while(0)
@@ -719,22 +736,22 @@ do { \
#define LD_BLOCK(BASE,DEST,DEST2) \
case BASE: /* LD DEST,B */ \
TSTATE(4); \
- DEST=cpu->BC.b[HI]; \
+ DEST=cpu->BC.b.hi; \
break; \
\
case BASE+1: /* LD DEST,C */ \
TSTATE(4); \
- DEST=cpu->BC.b[LO]; \
+ DEST=cpu->BC.b.lo; \
break; \
\
case BASE+2: /* LD DEST,D */ \
TSTATE(4); \
- DEST=cpu->DE.b[HI]; \
+ DEST=cpu->DE.b.hi; \
break; \
\
case BASE+3: /* LD DEST,E */ \
TSTATE(4); \
- DEST=cpu->DE.b[LO]; \
+ DEST=cpu->DE.b.lo; \
break; \
\
case BASE+4: /* LD DEST,H */ \
@@ -749,34 +766,34 @@ do { \
\
case BASE+6: /* LD DEST,(HL) */ \
TSTATE(7); \
- OFFSET(off); \
+ OFFSET(*HL,off); \
DEST2=PEEK(*HL+off); \
break; \
\
case BASE+7: /* LD DEST,A */ \
TSTATE(4); \
- DEST=cpu->AF.b[HI]; \
+ DEST=cpu->AF.b.hi; \
break;
#define ALU_BLOCK(BASE,OP) \
case BASE: /* OP A,B */ \
TSTATE(4); \
- OP(cpu->BC.b[HI]); \
+ OP(cpu->BC.b.hi); \
break; \
\
case BASE+1: /* OP A,C */ \
TSTATE(4); \
- OP(cpu->BC.b[LO]); \
+ OP(cpu->BC.b.lo); \
break; \
\
case BASE+2: /* OP A,D */ \
TSTATE(4); \
- OP(cpu->DE.b[HI]); \
+ OP(cpu->DE.b.hi); \
break; \
\
case BASE+3: /* OP A,E */ \
TSTATE(4); \
- OP(cpu->DE.b[LO]); \
+ OP(cpu->DE.b.lo); \
break; \
\
case BASE+4: /* OP A,H */ \
@@ -791,13 +808,13 @@ do { \
\
case BASE+6: /* OP A,(HL) */ \
TSTATE(7); \
- OFFSET(off); \
+ OFFSET(*HL,off); \
OP_ON_MEM(OP,*HL+off); \
break; \
\
case BASE+7: /* OP A,A */ \
TSTATE(4); \
- OP(cpu->AF.b[HI]); \
+ OP(cpu->AF.b.hi); \
break;
@@ -807,32 +824,32 @@ do { \
#define CB_ALU_BLOCK(BASE,OP) \
case BASE: /* OP B */ \
TSTATE(8); \
- OP(cpu->BC.b[HI]); \
+ OP(cpu->BC.b.hi); \
break; \
\
case BASE+1: /* OP C */ \
TSTATE(8); \
- OP(cpu->BC.b[LO]); \
+ OP(cpu->BC.b.lo); \
break; \
\
case BASE+2: /* OP D */ \
TSTATE(8); \
- OP(cpu->DE.b[HI]); \
+ OP(cpu->DE.b.hi); \
break; \
\
case BASE+3: /* OP E */ \
TSTATE(8); \
- OP(cpu->DE.b[LO]); \
+ OP(cpu->DE.b.lo); \
break; \
\
case BASE+4: /* OP H */ \
TSTATE(8); \
- OP(cpu->HL.b[HI]); \
+ OP(cpu->HL.b.hi); \
break; \
\
case BASE+5: /* OP L */ \
TSTATE(8); \
- OP(cpu->HL.b[LO]); \
+ OP(cpu->HL.b.lo); \
break; \
\
case BASE+6: /* OP (HL) */ \
@@ -842,48 +859,48 @@ do { \
\
case BASE+7: /* OP A */ \
TSTATE(8); \
- OP(cpu->AF.b[HI]); \
+ OP(cpu->AF.b.hi); \
break;
-#define CB_BITMANIP_BLOCK(BASE,OP,BIT_NO) \
+#define CB_BITMANIP_BLOCK(BASE,OP,OP2,BIT_NO) \
case BASE: /* OP B */ \
TSTATE(8); \
- OP(cpu->BC.b[HI],BIT_NO); \
+ OP(cpu->BC.b.hi,BIT_NO); \
break; \
\
case BASE+1: /* OP C */ \
TSTATE(8); \
- OP(cpu->BC.b[LO],BIT_NO); \
+ OP(cpu->BC.b.lo,BIT_NO); \
break; \
\
case BASE+2: /* OP D */ \
TSTATE(8); \
- OP(cpu->DE.b[HI],BIT_NO); \
+ OP(cpu->DE.b.hi,BIT_NO); \
break; \
\
case BASE+3: /* OP E */ \
TSTATE(8); \
- OP(cpu->DE.b[LO],BIT_NO); \
+ OP(cpu->DE.b.lo,BIT_NO); \
break; \
\
case BASE+4: /* OP H */ \
TSTATE(8); \
- OP(cpu->HL.b[HI],BIT_NO); \
+ OP(cpu->HL.b.hi,BIT_NO); \
break; \
\
case BASE+5: /* OP L */ \
TSTATE(8); \
- OP(cpu->HL.b[LO],BIT_NO); \
+ OP(cpu->HL.b.lo,BIT_NO); \
break; \
\
- case BASE+6: /* OP (HL) */ \
+ case BASE+6: /* OP2 (HL) */ \
TSTATE(12); \
- OP_ON_MEM_WITH_ARG(OP,cpu->HL.w,BIT_NO); \
+ OP_ON_MEM_WITH_ARG(OP2,cpu->HL.w,BIT_NO); \
break; \
\
case BASE+7: /* OP A */ \
TSTATE(8); \
- OP(cpu->AF.b[HI],BIT_NO); \
+ OP(cpu->AF.b.hi,BIT_NO); \
break;
/* ---------------------------------------- SHIFTED CB OPCODE SHORT-HAND BLOCKS
@@ -892,32 +909,32 @@ do { \
#define SHIFTED_CB_ALU_BLOCK(BASE,OP) \
case BASE: /* OP B */ \
TSTATE(8); \
- OP_ON_MEM_WITH_COPY(OP,addr,cpu->BC.b[HI]); \
+ OP_ON_MEM_WITH_COPY(OP,addr,cpu->BC.b.hi); \
break; \
\
case BASE+1: /* OP C */ \
TSTATE(8); \
- OP_ON_MEM_WITH_COPY(OP,addr,cpu->BC.b[LO]); \
+ OP_ON_MEM_WITH_COPY(OP,addr,cpu->BC.b.lo); \
break; \
\
case BASE+2: /* OP D */ \
TSTATE(8); \
- OP_ON_MEM_WITH_COPY(OP,addr,cpu->DE.b[HI]); \
+ OP_ON_MEM_WITH_COPY(OP,addr,cpu->DE.b.hi); \
break; \
\
case BASE+3: /* OP E */ \
TSTATE(8); \
- OP_ON_MEM_WITH_COPY(OP,addr,cpu->DE.b[LO]); \
+ OP_ON_MEM_WITH_COPY(OP,addr,cpu->DE.b.lo); \
break; \
\
case BASE+4: /* OP H */ \
TSTATE(8); \
- OP_ON_MEM_WITH_COPY(OP,addr,cpu->HL.b[HI]); \
+ OP_ON_MEM_WITH_COPY(OP,addr,cpu->HL.b.hi); \
break; \
\
case BASE+5: /* OP L */ \
TSTATE(8); \
- OP_ON_MEM_WITH_COPY(OP,addr,cpu->HL.b[LO]); \
+ OP_ON_MEM_WITH_COPY(OP,addr,cpu->HL.b.lo); \
break; \
\
case BASE+6: /* OP (HL) */ \
@@ -927,48 +944,48 @@ do { \
\
case BASE+7: /* OP A */ \
TSTATE(8); \
- OP_ON_MEM_WITH_COPY(OP,addr,cpu->AF.b[HI]); \
+ OP_ON_MEM_WITH_COPY(OP,addr,cpu->AF.b.hi); \
break;
-#define SHIFTED_CB_BITMANIP_BLOCK(BASE,OP,BIT_NO) \
+#define SHIFTED_CB_BITMANIP_BLOCK(BASE,OP,OP2,BIT_NO) \
case BASE: /* OP B */ \
TSTATE(8); \
- OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->BC.b[HI]); \
+ OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->BC.b.hi); \
break; \
\
case BASE+1: /* OP C */ \
TSTATE(8); \
- OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->BC.b[LO]); \
+ OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->BC.b.lo); \
break; \
\
case BASE+2: /* OP D */ \
TSTATE(8); \
- OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->DE.b[HI]); \
+ OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->DE.b.hi); \
break; \
\
case BASE+3: /* OP E */ \
TSTATE(8); \
- OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->DE.b[LO]); \
+ OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->DE.b.lo); \
break; \
\
case BASE+4: /* OP H */ \
TSTATE(8); \
- OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->HL.b[HI]); \
+ OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->HL.b.hi); \
break; \
\
case BASE+5: /* OP L */ \
TSTATE(8); \
- OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->HL.b[LO]); \
+ OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->HL.b.lo); \
break; \
\
- case BASE+6: /* OP (HL) */ \
+ case BASE+6: /* OP2 (HL) */ \
TSTATE(12); \
- OP_ON_MEM_WITH_ARG(OP,addr,BIT_NO); \
+ OP_ON_MEM_WITH_ARG(OP2,addr,BIT_NO); \
break; \
\
case BASE+7: /* OP A */ \
TSTATE(8); \
- OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->AF.b[HI]); \
+ OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->AF.b.hi); \
break;
/* ---------------------------------------- DAA
@@ -980,35 +997,36 @@ do { \
static void DAA (Z80 *cpu)
{
Z80Byte add=0;
- Z80Byte carry=0;
- Z80Byte nf=cpu->AF.b[LO]&N_Z80;
- Z80Byte acc=cpu->AF.b[HI];
+ Z80Byte carry=cpu->AF.b.lo&C_Z80;
+ Z80Byte nf=cpu->AF.b.lo&N_Z80;
+ Z80Byte acc=cpu->AF.b.hi;
- if (acc>0x99 || IS_C)
+ if (acc > 0x99 || IS_C)
{
add|=0x60;
- carry=C_Z80;
+
+ if (acc > 0x99)
+ {
+ carry=C_Z80;
+ }
}
- if ((acc&0xf)>0x9 || IS_H)
+ if ((acc&0xf) > 0x9 || IS_H)
{
add|=0x06;
}
if (nf)
{
- cpu->AF.b[HI]-=add;
+ SUB8(add);
}
else
{
- cpu->AF.b[HI]+=add;
+ ADD8(add);
}
- cpu->AF.b[LO]=PSZtable[cpu->AF.b[HI]]
- | carry
- | nf
- | ((acc^cpu->AF.b[HI])&H_Z80)
- | (cpu->AF.b[HI]&(B3_Z80|B5_Z80));
+ cpu->AF.b.lo = (cpu->AF.b.lo & ~(C_Z80|P_Z80)) | carry |
+ Ptable[cpu->AF.b.hi];
}
/* ---------------------------------------- HANDLERS FOR ED OPCODES
@@ -1022,20 +1040,20 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
if (PRIV->pread)
{
- cpu->BC.b[HI]=PRIV->pread(cpu,cpu->BC.w);
+ cpu->BC.b.hi=PRIV->pread(cpu,cpu->BC.w);
}
else
{
- cpu->BC.b[HI]=0;
+ cpu->BC.b.hi=0;
}
- cpu->AF.b[LO]=CARRY|PSZtable[cpu->BC.b[HI]];
- SETHIDDEN(cpu->BC.b[HI]);
+ cpu->AF.b.lo=CARRY|PSZtable[cpu->BC.b.hi];
+ SETHIDDEN(cpu->BC.b.hi);
break;
case 0x41: /* OUT (C),B */
TSTATE(12);
- if (PRIV->pwrite) PRIV->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 */
@@ -1044,21 +1062,25 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
break;
case 0x43: /* LD (nnnn),BC */
+ {
+ Z80Word addr=FETCH_WORD;
TSTATE(20);
- POKEW(FETCH_WORD,cpu->BC.w);
+ POKEW(addr,cpu->BC.w);
+ cpu->priv->memptr.w=addr+1;
break;
+ }
case 0x44: /* NEG */
- {
+ {
Z80Byte b;
TSTATE(8);
- b=cpu->AF.b[HI];
- cpu->AF.b[HI]=0;
+ b=cpu->AF.b.hi;
+ cpu->AF.b.hi=0;
SUB8(b);
break;
- }
+ }
case 0x45: /* RETN */
TSTATE(14);
@@ -1073,7 +1095,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x47: /* LD I,A */
TSTATE(9);
- cpu->I=cpu->AF.b[HI];
+ cpu->I=cpu->AF.b.hi;
break;
case 0x48: /* IN C,(C) */
@@ -1081,20 +1103,20 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
if (PRIV->pread)
{
- cpu->BC.b[LO]=PRIV->pread(cpu,cpu->BC.w);
+ cpu->BC.b.lo=PRIV->pread(cpu,cpu->BC.w);
}
else
{
- cpu->BC.b[LO]=0;
+ cpu->BC.b.lo=0;
}
- cpu->AF.b[LO]=CARRY|PSZtable[cpu->BC.b[LO]];
- SETHIDDEN(cpu->BC.b[LO]);
+ cpu->AF.b.lo=CARRY|PSZtable[cpu->BC.b.lo];
+ SETHIDDEN(cpu->BC.b.lo);
break;
case 0x49: /* OUT (C),C */
TSTATE(12);
- if (PRIV->pwrite) PRIV->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 */
@@ -1103,9 +1125,13 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
break;
case 0x4b: /* LD BC,(nnnn) */
+ {
+ Z80Word addr=FETCH_WORD;
TSTATE(20);
- cpu->BC.w=PEEKW(FETCH_WORD);
+ cpu->BC.w=PEEKW(addr);
+ cpu->priv->memptr.w=addr+1;
break;
+ }
case 0x4c: /* NEG */
{
@@ -1113,8 +1139,8 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
TSTATE(8);
- b=cpu->AF.b[HI];
- cpu->AF.b[HI]=0;
+ b=cpu->AF.b.hi;
+ cpu->AF.b.hi=0;
SUB8(b);
break;
}
@@ -1124,6 +1150,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
CALLBACK(eZ80_RETI,0);
cpu->IFF1=cpu->IFF2;
POP(cpu->PC);
+ cpu->priv->memptr.w=cpu->PC;
break;
case 0x4e: /* IM 0/1 */
@@ -1133,7 +1160,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x4f: /* LD R,A */
TSTATE(9);
- cpu->R=cpu->AF.b[HI];
+ cpu->R=cpu->AF.b.hi;
break;
case 0x50: /* IN D,(C) */
@@ -1141,20 +1168,20 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
if (PRIV->pread)
{
- cpu->DE.b[HI]=PRIV->pread(cpu,cpu->BC.w);
+ cpu->DE.b.hi=PRIV->pread(cpu,cpu->BC.w);
}
else
{
- cpu->DE.b[HI]=0;
+ cpu->DE.b.hi=0;
}
- cpu->AF.b[LO]=CARRY|PSZtable[cpu->DE.b[HI]];
- SETHIDDEN(cpu->BC.b[HI]);
+ cpu->AF.b.lo=CARRY|PSZtable[cpu->DE.b.hi];
+ SETHIDDEN(cpu->BC.b.hi);
break;
case 0x51: /* OUT (C),D */
TSTATE(12);
- if (PRIV->pwrite) PRIV->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 */
@@ -1163,21 +1190,25 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
break;
case 0x53: /* LD (nnnn),DE */
+ {
+ Z80Word addr=FETCH_WORD;
TSTATE(20);
- POKEW(FETCH_WORD,cpu->DE.w);
+ POKEW(addr,cpu->DE.w);
+ cpu->priv->memptr.w=addr+1;
break;
+ }
case 0x54: /* NEG */
- {
+ {
Z80Byte b;
TSTATE(8);
- b=cpu->AF.b[HI];
- cpu->AF.b[HI]=0;
+ b=cpu->AF.b.hi;
+ cpu->AF.b.hi=0;
SUB8(b);
break;
- }
+ }
case 0x55: /* RETN */
TSTATE(14);
@@ -1192,7 +1223,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x57: /* LD A,I */
TSTATE(9);
- cpu->AF.b[HI]=cpu->I;
+ cpu->AF.b.hi=cpu->I;
break;
case 0x58: /* IN E,(C) */
@@ -1200,20 +1231,20 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
if (PRIV->pread)
{
- cpu->DE.b[LO]=PRIV->pread(cpu,cpu->BC.w);
+ cpu->DE.b.lo=PRIV->pread(cpu,cpu->BC.w);
}
else
{
- cpu->BC.b[LO]=0;
+ cpu->BC.b.lo=0;
}
- cpu->AF.b[LO]=CARRY|PSZtable[cpu->DE.b[LO]];
- SETHIDDEN(cpu->DE.b[LO]);
+ cpu->AF.b.lo=CARRY|PSZtable[cpu->DE.b.lo];
+ SETHIDDEN(cpu->DE.b.lo);
break;
case 0x59: /* OUT (C),E */
TSTATE(12);
- if (PRIV->pwrite) PRIV->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 */
@@ -1222,21 +1253,25 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
break;
case 0x5b: /* LD DE,(nnnn) */
+ {
+ Z80Word addr=FETCH_WORD;
TSTATE(20);
- cpu->DE.w=PEEKW(FETCH_WORD);
+ cpu->DE.w=PEEKW(addr);
+ cpu->priv->memptr.w=addr+1;
break;
+ }
case 0x5c: /* NEG */
- {
+ {
Z80Byte b;
TSTATE(8);
- b=cpu->AF.b[HI];
- cpu->AF.b[HI]=0;
+ b=cpu->AF.b.hi;
+ cpu->AF.b.hi=0;
SUB8(b);
break;
- }
+ }
case 0x5d: /* RETN */
TSTATE(14);
@@ -1251,7 +1286,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0x5f: /* LD A,R */
TSTATE(9);
- cpu->AF.b[HI]=cpu->R;
+ cpu->AF.b.hi=cpu->R;
break;
case 0x60: /* IN H,(C) */
@@ -1259,20 +1294,20 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
if (PRIV->pread)
{
- cpu->HL.b[HI]=PRIV->pread(cpu,cpu->BC.w);
+ cpu->HL.b.hi=PRIV->pread(cpu,cpu->BC.w);
}
else
{
- cpu->HL.b[HI]=0;
+ cpu->HL.b.hi=0;
}
- cpu->AF.b[LO]=CARRY|PSZtable[cpu->HL.b[HI]];
- SETHIDDEN(cpu->HL.b[HI]);
+ cpu->AF.b.lo=CARRY|PSZtable[cpu->HL.b.hi];
+ SETHIDDEN(cpu->HL.b.hi);
break;
case 0x61: /* OUT (C),H */
TSTATE(12);
- if (PRIV->pwrite) PRIV->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 */
@@ -1281,9 +1316,13 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
break;
case 0x63: /* LD (nnnn),HL */
+ {
+ Z80Word addr=FETCH_WORD;
TSTATE(20);
- POKEW(FETCH_WORD,cpu->HL.w);
+ POKEW(addr,cpu->HL.w);
+ cpu->priv->memptr.w=addr+1;
break;
+ }
case 0x64: /* NEG */
{
@@ -1291,8 +1330,8 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
TSTATE(8);
- b=cpu->AF.b[HI];
- cpu->AF.b[HI]=0;
+ b=cpu->AF.b.hi;
+ cpu->AF.b.hi=0;
SUB8(b);
break;
}
@@ -1309,40 +1348,41 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
break;
case 0x67: /* RRD */
- {
+ {
Z80Byte b;
TSTATE(18);
b=PEEK(cpu->HL.w);
+ cpu->priv->memptr.w=cpu->HL.w+1;
- POKE(cpu->HL.w,(b>>4)|(cpu->AF.b[HI]<<4));
- cpu->AF.b[HI]=(cpu->AF.b[HI]&0xf0)|(b&0x0f);
+ POKE(cpu->HL.w,(b>>4)|(cpu->AF.b.hi<<4));
+ cpu->AF.b.hi=(cpu->AF.b.hi&0xf0)|(b&0x0f);
- cpu->AF.b[LO]=CARRY|PSZtable[cpu->AF.b[HI]];
- SETHIDDEN(cpu->AF.b[HI]);
+ cpu->AF.b.lo=CARRY|PSZtable[cpu->AF.b.hi];
+ SETHIDDEN(cpu->AF.b.hi);
break;
- }
+ }
case 0x68: /* IN L,(C) */
TSTATE(12);
if (PRIV->pread)
{
- cpu->HL.b[LO]=PRIV->pread(cpu,cpu->BC.w);
+ cpu->HL.b.lo=PRIV->pread(cpu,cpu->BC.w);
}
else
{
- cpu->HL.b[LO]=0;
+ cpu->HL.b.lo=0;
}
- cpu->AF.b[LO]=CARRY|PSZtable[cpu->HL.b[LO]];
- SETHIDDEN(cpu->HL.b[LO]);
+ cpu->AF.b.lo=CARRY|PSZtable[cpu->HL.b.lo];
+ SETHIDDEN(cpu->HL.b.lo);
break;
case 0x69: /* OUT (C),L */
TSTATE(12);
- if (PRIV->pwrite) PRIV->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 */
@@ -1351,21 +1391,25 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
break;
case 0x6b: /* LD HL,(nnnn) */
+ {
+ Z80Word addr=FETCH_WORD;
TSTATE(20);
- cpu->HL.w=PEEKW(FETCH_WORD);
+ cpu->HL.w=PEEKW(addr);
+ cpu->priv->memptr.w=addr+1;
break;
+ }
case 0x6c: /* NEG */
- {
+ {
Z80Byte b;
TSTATE(8);
- b=cpu->AF.b[HI];
- cpu->AF.b[HI]=0;
+ b=cpu->AF.b.hi;
+ cpu->AF.b.hi=0;
SUB8(b);
break;
- }
+ }
case 0x6d: /* RETN */
TSTATE(14);
@@ -1379,23 +1423,24 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
break;
case 0x6f: /* RLD */
- {
+ {
Z80Byte b;
TSTATE(18);
b=PEEK(cpu->HL.w);
+ cpu->priv->memptr.w=cpu->HL.w+1;
- POKE(cpu->HL.w,(b<<4)|(cpu->AF.b[HI]&0x0f));
- cpu->AF.b[HI]=(cpu->AF.b[HI]&0xf0)|(b>>4);
+ POKE(cpu->HL.w,(b<<4)|(cpu->AF.b.hi&0x0f));
+ cpu->AF.b.hi=(cpu->AF.b.hi&0xf0)|(b>>4);
- cpu->AF.b[LO]=CARRY|PSZtable[cpu->AF.b[HI]];
- SETHIDDEN(cpu->AF.b[HI]);
+ cpu->AF.b.lo=CARRY|PSZtable[cpu->AF.b.hi];
+ SETHIDDEN(cpu->AF.b.hi);
break;
- }
+ }
case 0x70: /* IN (C) */
- {
+ {
Z80Byte b;
TSTATE(12);
@@ -1409,14 +1454,14 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
b=0;
}
- cpu->AF.b[LO]=CARRY|PSZtable[b];
+ cpu->AF.b.lo=CARRY|PSZtable[b];
SETHIDDEN(b);
break;
- }
+ }
case 0x71: /* OUT (C) */
TSTATE(12);
- if (PRIV->pwrite) PRIV->pwrite(cpu,cpu->BC.w,0);
+ if (PRIV->pwrite) PRIV->pwrite(cpu,cpu->BC.w,255);
break;
case 0x72: /* SBC HL,SP */
@@ -1430,16 +1475,16 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
break;
case 0x74: /* NEG */
- {
+ {
Z80Byte b;
TSTATE(8);
- b=cpu->AF.b[HI];
- cpu->AF.b[HI]=0;
+ b=cpu->AF.b.hi;
+ cpu->AF.b.hi=0;
SUB8(b);
break;
- }
+ }
case 0x75: /* RETN */
TSTATE(14);
@@ -1462,20 +1507,22 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
if (PRIV->pread)
{
- cpu->AF.b[HI]=PRIV->pread(cpu,cpu->BC.w);
+ cpu->AF.b.hi=PRIV->pread(cpu,cpu->BC.w);
}
else
{
- cpu->AF.b[HI]=0;
+ cpu->AF.b.hi=0;
}
- cpu->AF.b[LO]=CARRY|PSZtable[cpu->AF.b[HI]];
- SETHIDDEN(cpu->AF.b[HI]);
+ cpu->AF.b.lo=CARRY|PSZtable[cpu->AF.b.hi];
+ PRIV->memptr.w=cpu->BC.w+1;
+ SETHIDDEN(cpu->AF.b.hi);
break;
case 0x79: /* OUT (C),A */
TSTATE(12);
- if (PRIV->pwrite) PRIV->pwrite(cpu,cpu->BC.w,cpu->AF.b[HI]);
+ if (PRIV->pwrite) PRIV->pwrite(cpu,cpu->BC.w,cpu->AF.b.hi);
+ PRIV->memptr.w=cpu->BC.w+1;
break;
case 0x7a: /* ADC HL,SP */
@@ -1489,16 +1536,16 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
break;
case 0x7c: /* NEG */
- {
+ {
Z80Byte b;
TSTATE(8);
- b=cpu->AF.b[HI];
- cpu->AF.b[HI]=0;
+ b=cpu->AF.b.hi;
+ cpu->AF.b.hi=0;
SUB8(b);
break;
- }
+ }
case 0x7d: /* RETN */
TSTATE(14);
@@ -1524,16 +1571,19 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0xa1: /* CPI */
TSTATE(16);
CPI;
+ PRIV->memptr.w++;
break;
case 0xa2: /* INI */
TSTATE(16);
+ PRIV->memptr.w = cpu->BC.w + 1;
INI;
break;
case 0xa3: /* OUTI */
TSTATE(16);
OUTI;
+ PRIV->memptr.w=cpu->BC.w+1;
break;
case 0xa8: /* LDD */
@@ -1544,25 +1594,32 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0xa9: /* CPD */
TSTATE(16);
CPD;
+ PRIV->memptr.w--;
break;
case 0xaa: /* IND */
TSTATE(16);
+ PRIV->memptr.w = cpu->BC.w - 1;
IND;
break;
case 0xab: /* OUTD */
TSTATE(16);
OUTD;
+ PRIV->memptr.w=cpu->BC.w-1;
break;
case 0xb0: /* LDIR */
TSTATE(16);
+
LDI;
+
if (cpu->BC.w)
{
TSTATE(5);
cpu->PC-=2;
+ SETHIDDEN((cpu->PC)>>8);
+ PRIV->memptr.w=cpu->PC+1;
}
break;
@@ -1573,11 +1630,17 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
{
TSTATE(5);
cpu->PC-=2;
+ PRIV->memptr.w++;
}
+ else
+ {
+ PRIV->memptr.w=cpu->PC-1;
+ }
break;
case 0xb2: /* INIR */
TSTATE(16);
+ PRIV->memptr.w = cpu->BC.w + 1;
INI;
if (cpu->BC.w)
{
@@ -1589,6 +1652,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0xb3: /* OTIR */
TSTATE(16);
OUTI;
+ PRIV->memptr.w=cpu->BC.w+1;
if (cpu->BC.w)
{
TSTATE(5);
@@ -1598,11 +1662,15 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0xb8: /* LDDR */
TSTATE(16);
+
LDD;
+
if (cpu->BC.w)
{
TSTATE(5);
cpu->PC-=2;
+ SETHIDDEN((cpu->PC)>>8);
+ PRIV->memptr.w=cpu->PC+1;
}
break;
@@ -1613,11 +1681,17 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
{
TSTATE(5);
cpu->PC-=2;
+ PRIV->memptr.w++;
}
+ else
+ {
+ PRIV->memptr.w=cpu->PC-1;
+ }
break;
case 0xba: /* INDR */
TSTATE(16);
+ PRIV->memptr.w = cpu->BC.w-1;
IND;
if (cpu->BC.w)
{
@@ -1629,6 +1703,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0xbb: /* OTDR */
TSTATE(16);
OUTD;
+ PRIV->memptr.w=cpu->BC.w-1;
if (cpu->BC.w)
{
TSTATE(5);
@@ -1661,32 +1736,32 @@ static void DecodeCB(Z80 *cpu, Z80Byte opcode)
CB_ALU_BLOCK(0x30,SLL)
CB_ALU_BLOCK(0x38,SRL)
- CB_BITMANIP_BLOCK(0x40,BIT,0)
- CB_BITMANIP_BLOCK(0x48,BIT,1)
- CB_BITMANIP_BLOCK(0x50,BIT,2)
- CB_BITMANIP_BLOCK(0x58,BIT,3)
- CB_BITMANIP_BLOCK(0x60,BIT,4)
- CB_BITMANIP_BLOCK(0x68,BIT,5)
- CB_BITMANIP_BLOCK(0x70,BIT,6)
- CB_BITMANIP_BLOCK(0x78,BIT,7)
-
- CB_BITMANIP_BLOCK(0x80,BIT_RES,0)
- CB_BITMANIP_BLOCK(0x88,BIT_RES,1)
- CB_BITMANIP_BLOCK(0x90,BIT_RES,2)
- CB_BITMANIP_BLOCK(0x98,BIT_RES,3)
- CB_BITMANIP_BLOCK(0xa0,BIT_RES,4)
- CB_BITMANIP_BLOCK(0xa8,BIT_RES,5)
- CB_BITMANIP_BLOCK(0xb0,BIT_RES,6)
- CB_BITMANIP_BLOCK(0xb8,BIT_RES,7)
-
- CB_BITMANIP_BLOCK(0xc0,BIT_SET,0)
- CB_BITMANIP_BLOCK(0xc8,BIT_SET,1)
- CB_BITMANIP_BLOCK(0xd0,BIT_SET,2)
- CB_BITMANIP_BLOCK(0xd8,BIT_SET,3)
- CB_BITMANIP_BLOCK(0xe0,BIT_SET,4)
- CB_BITMANIP_BLOCK(0xe8,BIT_SET,5)
- CB_BITMANIP_BLOCK(0xf0,BIT_SET,6)
- CB_BITMANIP_BLOCK(0xf8,BIT_SET,7)
+ CB_BITMANIP_BLOCK(0x40,BIT,BIT_MEMPTR,0)
+ CB_BITMANIP_BLOCK(0x48,BIT,BIT_MEMPTR,1)
+ CB_BITMANIP_BLOCK(0x50,BIT,BIT_MEMPTR,2)
+ CB_BITMANIP_BLOCK(0x58,BIT,BIT_MEMPTR,3)
+ CB_BITMANIP_BLOCK(0x60,BIT,BIT_MEMPTR,4)
+ CB_BITMANIP_BLOCK(0x68,BIT,BIT_MEMPTR,5)
+ CB_BITMANIP_BLOCK(0x70,BIT,BIT_MEMPTR,6)
+ CB_BITMANIP_BLOCK(0x78,BIT,BIT_MEMPTR,7)
+
+ CB_BITMANIP_BLOCK(0x80,BIT_RES,BIT_RES,0)
+ CB_BITMANIP_BLOCK(0x88,BIT_RES,BIT_RES,1)
+ CB_BITMANIP_BLOCK(0x90,BIT_RES,BIT_RES,2)
+ CB_BITMANIP_BLOCK(0x98,BIT_RES,BIT_RES,3)
+ CB_BITMANIP_BLOCK(0xa0,BIT_RES,BIT_RES,4)
+ CB_BITMANIP_BLOCK(0xa8,BIT_RES,BIT_RES,5)
+ CB_BITMANIP_BLOCK(0xb0,BIT_RES,BIT_RES,6)
+ CB_BITMANIP_BLOCK(0xb8,BIT_RES,BIT_RES,7)
+
+ CB_BITMANIP_BLOCK(0xc0,BIT_SET,BIT_SET,0)
+ CB_BITMANIP_BLOCK(0xc8,BIT_SET,BIT_SET,1)
+ CB_BITMANIP_BLOCK(0xd0,BIT_SET,BIT_SET,2)
+ CB_BITMANIP_BLOCK(0xd8,BIT_SET,BIT_SET,3)
+ CB_BITMANIP_BLOCK(0xe0,BIT_SET,BIT_SET,4)
+ CB_BITMANIP_BLOCK(0xe8,BIT_SET,BIT_SET,5)
+ CB_BITMANIP_BLOCK(0xf0,BIT_SET,BIT_SET,6)
+ CB_BITMANIP_BLOCK(0xf8,BIT_SET,BIT_SET,7)
}
}
@@ -1701,9 +1776,11 @@ static void ShiftedDecodeCB(Z80 *cpu, Z80Byte opcode, Z80Relative offset)
{
case 0xdd:
addr=cpu->IX.w+offset;
+ PRIV->memptr.w=addr;
break;
case 0xfd:
addr=cpu->IY.w+offset;
+ PRIV->memptr.w=addr;
break;
default:
addr=cpu->HL.w; /* Play safe... */
@@ -1721,32 +1798,32 @@ static void ShiftedDecodeCB(Z80 *cpu, Z80Byte opcode, Z80Relative offset)
SHIFTED_CB_ALU_BLOCK(0x30,SLL)
SHIFTED_CB_ALU_BLOCK(0x38,SRL)
- SHIFTED_CB_BITMANIP_BLOCK(0x40,BIT,0)
- SHIFTED_CB_BITMANIP_BLOCK(0x48,BIT,1)
- SHIFTED_CB_BITMANIP_BLOCK(0x50,BIT,2)
- SHIFTED_CB_BITMANIP_BLOCK(0x58,BIT,3)
- SHIFTED_CB_BITMANIP_BLOCK(0x60,BIT,4)
- SHIFTED_CB_BITMANIP_BLOCK(0x68,BIT,5)
- SHIFTED_CB_BITMANIP_BLOCK(0x70,BIT,6)
- SHIFTED_CB_BITMANIP_BLOCK(0x78,BIT,7)
-
- SHIFTED_CB_BITMANIP_BLOCK(0x80,BIT_RES,0)
- SHIFTED_CB_BITMANIP_BLOCK(0x88,BIT_RES,1)
- SHIFTED_CB_BITMANIP_BLOCK(0x90,BIT_RES,2)
- SHIFTED_CB_BITMANIP_BLOCK(0x98,BIT_RES,3)
- SHIFTED_CB_BITMANIP_BLOCK(0xa0,BIT_RES,4)
- SHIFTED_CB_BITMANIP_BLOCK(0xa8,BIT_RES,5)
- SHIFTED_CB_BITMANIP_BLOCK(0xb0,BIT_RES,6)
- SHIFTED_CB_BITMANIP_BLOCK(0xb8,BIT_RES,7)
-
- SHIFTED_CB_BITMANIP_BLOCK(0xc0,BIT_SET,0)
- SHIFTED_CB_BITMANIP_BLOCK(0xc8,BIT_SET,1)
- SHIFTED_CB_BITMANIP_BLOCK(0xd0,BIT_SET,2)
- SHIFTED_CB_BITMANIP_BLOCK(0xd8,BIT_SET,3)
- SHIFTED_CB_BITMANIP_BLOCK(0xe0,BIT_SET,4)
- SHIFTED_CB_BITMANIP_BLOCK(0xe8,BIT_SET,5)
- SHIFTED_CB_BITMANIP_BLOCK(0xf0,BIT_SET,6)
- SHIFTED_CB_BITMANIP_BLOCK(0xf8,BIT_SET,7)
+ SHIFTED_CB_BITMANIP_BLOCK(0x40,BIT_MEMPTR,BIT_MEMPTR,0)
+ SHIFTED_CB_BITMANIP_BLOCK(0x48,BIT_MEMPTR,BIT_MEMPTR,1)
+ SHIFTED_CB_BITMANIP_BLOCK(0x50,BIT_MEMPTR,BIT_MEMPTR,2)
+ SHIFTED_CB_BITMANIP_BLOCK(0x58,BIT_MEMPTR,BIT_MEMPTR,3)
+ SHIFTED_CB_BITMANIP_BLOCK(0x60,BIT_MEMPTR,BIT_MEMPTR,4)
+ SHIFTED_CB_BITMANIP_BLOCK(0x68,BIT_MEMPTR,BIT_MEMPTR,5)
+ SHIFTED_CB_BITMANIP_BLOCK(0x70,BIT_MEMPTR,BIT_MEMPTR,6)
+ SHIFTED_CB_BITMANIP_BLOCK(0x78,BIT_MEMPTR,BIT_MEMPTR,7)
+
+ SHIFTED_CB_BITMANIP_BLOCK(0x80,BIT_RES,BIT_RES,0)
+ SHIFTED_CB_BITMANIP_BLOCK(0x88,BIT_RES,BIT_RES,1)
+ SHIFTED_CB_BITMANIP_BLOCK(0x90,BIT_RES,BIT_RES,2)
+ SHIFTED_CB_BITMANIP_BLOCK(0x98,BIT_RES,BIT_RES,3)
+ SHIFTED_CB_BITMANIP_BLOCK(0xa0,BIT_RES,BIT_RES,4)
+ SHIFTED_CB_BITMANIP_BLOCK(0xa8,BIT_RES,BIT_RES,5)
+ SHIFTED_CB_BITMANIP_BLOCK(0xb0,BIT_RES,BIT_RES,6)
+ SHIFTED_CB_BITMANIP_BLOCK(0xb8,BIT_RES,BIT_RES,7)
+
+ SHIFTED_CB_BITMANIP_BLOCK(0xc0,BIT_SET,BIT_SET,0)
+ SHIFTED_CB_BITMANIP_BLOCK(0xc8,BIT_SET,BIT_SET,1)
+ SHIFTED_CB_BITMANIP_BLOCK(0xd0,BIT_SET,BIT_SET,2)
+ SHIFTED_CB_BITMANIP_BLOCK(0xd8,BIT_SET,BIT_SET,3)
+ SHIFTED_CB_BITMANIP_BLOCK(0xe0,BIT_SET,BIT_SET,4)
+ SHIFTED_CB_BITMANIP_BLOCK(0xe8,BIT_SET,BIT_SET,5)
+ SHIFTED_CB_BITMANIP_BLOCK(0xf0,BIT_SET,BIT_SET,6)
+ SHIFTED_CB_BITMANIP_BLOCK(0xf8,BIT_SET,BIT_SET,7)
}
}
@@ -1766,18 +1843,18 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
{
case 0xdd:
HL=&(cpu->IX.w);
- L=cpu->IX.b+LO;
- H=cpu->IX.b+HI;
+ L=&(cpu->IX.b.lo);
+ H=&(cpu->IX.b.hi);
break;
case 0xfd:
HL=&(cpu->IY.w);
- L=cpu->IY.b+LO;
- H=cpu->IY.b+HI;
+ L=&(cpu->IY.b.lo);
+ H=&(cpu->IY.b.hi);
break;
default:
HL=&(cpu->HL.w);
- L=cpu->HL.b+LO;
- H=cpu->HL.b+HI;
+ L=&(cpu->HL.b.lo);
+ H=&(cpu->HL.b.hi);
break;
}
@@ -1794,7 +1871,9 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x02: /* LD (BC),A */
TSTATE(7);
- POKE(cpu->BC.w,cpu->AF.b[HI]);
+ POKE(cpu->BC.w,cpu->AF.b.hi);
+ cpu->priv->memptr.b.lo=(cpu->BC.w+1)&0xff;
+ cpu->priv->memptr.b.hi=cpu->AF.b.hi;
break;
case 0x03: /* INC BC */
@@ -1804,17 +1883,17 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x04: /* INC B */
TSTATE(4);
- INC8(cpu->BC.b[HI]);
+ INC8(cpu->BC.b.hi);
break;
case 0x05: /* DEC B */
TSTATE(4);
- DEC8(cpu->BC.b[HI]);
+ DEC8(cpu->BC.b.hi);
break;
case 0x06: /* LD B,n */
TSTATE(7);
- cpu->BC.b[HI]=FETCH_BYTE;
+ cpu->BC.b.hi=FETCH_BYTE;
break;
case 0x07: /* RLCA */
@@ -1834,7 +1913,8 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x0a: /* LD A,(BC) */
TSTATE(7);
- cpu->AF.b[HI]=PEEK(cpu->BC.w);
+ cpu->AF.b.hi=PEEK(cpu->BC.w);
+ cpu->priv->memptr.w=cpu->BC.w+1;
break;
case 0x0b: /* DEC BC */
@@ -1844,17 +1924,17 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x0c: /* INC C */
TSTATE(4);
- INC8(cpu->BC.b[LO]);
+ INC8(cpu->BC.b.lo);
break;
case 0x0d: /* DEC C */
TSTATE(4);
- DEC8(cpu->BC.b[LO]);
+ DEC8(cpu->BC.b.lo);
break;
case 0x0e: /* LD C,n */
TSTATE(7);
- cpu->BC.b[LO]=FETCH_BYTE;
+ cpu->BC.b.lo=FETCH_BYTE;
break;
case 0x0f: /* RRCA */
@@ -1863,7 +1943,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
break;
case 0x10: /* DJNZ */
- if (--(cpu->BC.b[HI]))
+ if (--(cpu->BC.b.hi))
{
TSTATE(13);
JR;
@@ -1882,7 +1962,9 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x12: /* LD (DE),A */
TSTATE(7);
- POKE(cpu->DE.w,cpu->AF.b[HI]);
+ POKE(cpu->DE.w,cpu->AF.b.hi);
+ cpu->priv->memptr.b.lo=(cpu->DE.w+1)&0xff;
+ cpu->priv->memptr.b.hi=cpu->AF.b.hi;
break;
case 0x13: /* INC DE */
@@ -1892,17 +1974,17 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x14: /* INC D */
TSTATE(4);
- INC8(cpu->DE.b[HI]);
+ INC8(cpu->DE.b.hi);
break;
case 0x15: /* DEC D */
TSTATE(4);
- DEC8(cpu->DE.b[HI]);
+ DEC8(cpu->DE.b.hi);
break;
case 0x16: /* LD D,n */
TSTATE(7);
- cpu->DE.b[HI]=FETCH_BYTE;
+ cpu->DE.b.hi=FETCH_BYTE;
break;
case 0x17: /* RLA */
@@ -1922,7 +2004,8 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x1a: /* LD A,(DE) */
TSTATE(7);
- cpu->AF.b[HI]=PEEK(cpu->DE.w);
+ cpu->AF.b.hi=PEEK(cpu->DE.w);
+ cpu->priv->memptr.w=cpu->DE.w+1;
break;
case 0x1b: /* DEC DE */
@@ -1932,17 +2015,17 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x1c: /* INC E */
TSTATE(4);
- INC8(cpu->DE.b[LO]);
+ INC8(cpu->DE.b.lo);
break;
case 0x1d: /* DEC E */
TSTATE(4);
- DEC8(cpu->DE.b[LO]);
+ DEC8(cpu->DE.b.lo);
break;
case 0x1e: /* LD E,n */
TSTATE(7);
- cpu->DE.b[LO]=FETCH_BYTE;
+ cpu->DE.b.lo=FETCH_BYTE;
break;
case 0x1f: /* RRA */
@@ -2025,10 +2108,10 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x2f: /* CPL */
TSTATE(4);
- cpu->AF.b[HI]^=0xff;
+ cpu->AF.b.hi^=0xff;
SETFLAG(H_Z80);
SETFLAG(N_Z80);
- SETHIDDEN(cpu->AF.b[HI]);
+ SETHIDDEN(cpu->AF.b.hi);
break;
case 0x30: /* JR NC,d */
@@ -2041,9 +2124,14 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
break;
case 0x32: /* LD (nnnn),A */
+ {
+ Z80Word addr=FETCH_WORD;
TSTATE(13);
- POKE(FETCH_WORD,cpu->AF.b[HI]);
+ POKE(addr,cpu->AF.b.hi);
+ cpu->priv->memptr.b.lo=(addr + 1) & 0xff;
+ cpu->priv->memptr.b.hi=cpu->AF.b.hi;
break;
+ }
case 0x33: /* INC SP */
TSTATE(6);
@@ -2052,27 +2140,27 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x34: /* INC (HL) */
TSTATE(11);
- OFFSET(off);
+ OFFSET(*HL,off);
OP_ON_MEM(INC8,*HL+off);
break;
case 0x35: /* DEC (HL) */
TSTATE(11);
- OFFSET(off);
+ OFFSET(*HL,off);
OP_ON_MEM(DEC8,*HL+off);
break;
case 0x36: /* LD (HL),n */
TSTATE(10);
- OFFSET(off);
+ OFFSET(*HL,off);
POKE(*HL+off,FETCH_BYTE);
break;
case 0x37: /* SCF */
TSTATE(4);
- cpu->AF.b[LO]=(cpu->AF.b[LO]&(S_Z80|Z_Z80|P_Z80))
+ cpu->AF.b.lo=(cpu->AF.b.lo&(S_Z80|Z_Z80|P_Z80))
| C_Z80
- | (cpu->AF.b[HI]&(B3_Z80|B5_Z80));
+ | (cpu->AF.b.hi&(B3_Z80|B5_Z80));
break;
case 0x38: /* JR C,d */
@@ -2085,9 +2173,13 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
break;
case 0x3a: /* LD A,(nnnn) */
+ {
+ Z80Word addr=FETCH_WORD;
TSTATE(13);
- cpu->AF.b[HI]=PEEK(FETCH_WORD);
+ cpu->AF.b.hi=PEEK(addr);
+ cpu->priv->memptr.w=addr + 1;
break;
+ }
case 0x3b: /* DEC SP */
TSTATE(6);
@@ -2096,72 +2188,74 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x3c: /* INC A */
TSTATE(4);
- INC8(cpu->AF.b[HI]);
+ INC8(cpu->AF.b.hi);
break;
case 0x3d: /* DEC A */
TSTATE(4);
- DEC8(cpu->AF.b[HI]);
+ DEC8(cpu->AF.b.hi);
break;
case 0x3e: /* LD A,n */
TSTATE(7);
- cpu->AF.b[HI]=FETCH_BYTE;
+ cpu->AF.b.hi=FETCH_BYTE;
break;
case 0x3f: /* CCF */
TSTATE(4);
+ CLRFLAG(N_Z80);
+
if (CARRY)
SETFLAG(H_Z80);
else
CLRFLAG(H_Z80);
- cpu->AF.b[LO]^=C_Z80;
- SETHIDDEN(cpu->AF.b[HI]);
+ cpu->AF.b.lo^=C_Z80;
+ SETHIDDEN(cpu->AF.b.hi);
break;
- LD_BLOCK(0x40,cpu->BC.b[HI],cpu->BC.b[HI])
- LD_BLOCK(0x48,cpu->BC.b[LO],cpu->BC.b[LO])
- LD_BLOCK(0x50,cpu->DE.b[HI],cpu->DE.b[HI])
- LD_BLOCK(0x58,cpu->DE.b[LO],cpu->DE.b[LO])
- LD_BLOCK(0x60,*H,cpu->HL.b[HI])
- LD_BLOCK(0x68,*L,cpu->HL.b[LO])
+ LD_BLOCK(0x40,cpu->BC.b.hi,cpu->BC.b.hi)
+ LD_BLOCK(0x48,cpu->BC.b.lo,cpu->BC.b.lo)
+ LD_BLOCK(0x50,cpu->DE.b.hi,cpu->DE.b.hi)
+ LD_BLOCK(0x58,cpu->DE.b.lo,cpu->DE.b.lo)
+ LD_BLOCK(0x60,*H,cpu->HL.b.hi)
+ LD_BLOCK(0x68,*L,cpu->HL.b.lo)
case 0x70: /* LD (HL),B */
TSTATE(7);
- OFFSET(off);
- POKE(*HL+off,cpu->BC.b[HI]);
+ OFFSET(*HL,off);
+ POKE(*HL+off,cpu->BC.b.hi);
break;
case 0x71: /* LD (HL),C */
TSTATE(7);
- OFFSET(off);
- POKE(*HL+off,cpu->BC.b[LO]);
+ OFFSET(*HL,off);
+ POKE(*HL+off,cpu->BC.b.lo);
break;
case 0x72: /* LD (HL),D */
TSTATE(7);
- OFFSET(off);
- POKE(*HL+off,cpu->DE.b[HI]);
+ OFFSET(*HL,off);
+ POKE(*HL+off,cpu->DE.b.hi);
break;
case 0x73: /* LD (HL),E */
TSTATE(7);
- OFFSET(off);
- POKE(*HL+off,cpu->DE.b[LO]);
+ OFFSET(*HL,off);
+ POKE(*HL+off,cpu->DE.b.lo);
break;
case 0x74: /* LD (HL),H */
TSTATE(7);
- OFFSET(off);
- POKE(*HL+off,cpu->HL.b[HI]);
+ OFFSET(*HL,off);
+ POKE(*HL+off,cpu->HL.b.hi);
break;
case 0x75: /* LD (HL),L */
TSTATE(7);
- OFFSET(off);
- POKE(*HL+off,cpu->HL.b[LO]);
+ OFFSET(*HL,off);
+ POKE(*HL+off,cpu->HL.b.lo);
break;
case 0x76: /* HALT */
@@ -2176,11 +2270,11 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x77: /* LD (HL),A */
TSTATE(7);
- OFFSET(off);
- POKE(*HL+off,cpu->AF.b[HI]);
+ OFFSET(*HL,off);
+ POKE(*HL+off,cpu->AF.b.hi);
break;
- LD_BLOCK(0x78,cpu->AF.b[HI],cpu->AF.b[HI])
+ LD_BLOCK(0x78,cpu->AF.b.hi,cpu->AF.b.hi)
ALU_BLOCK(0x80,ADD8)
ALU_BLOCK(0x88,ADC8)
@@ -2294,8 +2388,9 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
Z80Word port;
port=FETCH_BYTE;
- port|=(Z80Word)cpu->AF.b[HI]<<8;
- PRIV->pwrite(cpu,port,cpu->AF.b[HI]);
+ port|=(Z80Word)cpu->AF.b.hi<<8;
+ PRIV->memptr.w=port+1;
+ PRIV->pwrite(cpu,port,cpu->AF.b.hi);
}
else
cpu->PC++;
@@ -2341,8 +2436,9 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
Z80Word port;
port=FETCH_BYTE;
- port|=(Z80Word)cpu->AF.b[HI]<<8;
- cpu->AF.b[HI]=PRIV->pread(cpu,port);
+ port|=(Z80Word)cpu->AF.b.hi<<8;
+ cpu->AF.b.hi=PRIV->pread(cpu,port);
+ PRIV->memptr.w=port+1;
}
else
cpu->PC++;
@@ -2383,14 +2479,15 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
break;
case 0xe3: /* EX (SP),HL */
- {
+ {
Z80Word tmp;
TSTATE(19);
POP(tmp);
PUSH(*HL);
*HL=tmp;
- }
+ cpu->priv->memptr.w=tmp;
break;
+ }
case 0xe4: /* CALL PO,nnnn */
CALL_COND(!IS_P);