summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2023-01-02 22:45:18 +0000
committerIan C <ianc@noddybox.co.uk>2023-01-02 22:45:18 +0000
commit5b9ffe70b622cee65ed5678163bee0e22fc0433d (patch)
treeb93acc4b6a9063d8a9bb83536c1658b010389a0b
parent933aa1be6910ef49023716a59f815e679f0b934a (diff)
Updated Z80. Emulator still crashing on most TAP files.
-rw-r--r--include/z80_private.h40
-rw-r--r--source/main.c4
-rw-r--r--source/z80.c5
-rw-r--r--source/z80_decode.c343
4 files changed, 268 insertions, 124 deletions
diff --git a/include/z80_private.h b/include/z80_private.h
index a7022d8..86adaee 100644
--- a/include/z80_private.h
+++ b/include/z80_private.h
@@ -19,14 +19,14 @@
-------------------------------------------------------------------------
- $Id: z80_private.h 13 2006-10-12 16:38:57Z ianc $
+ $Id$
Private macros for Z80
*/
#ifndef Z80_PRIVATE_H
-#define Z80_PRIVATE_H "$Id: z80_private.h 13 2006-10-12 16:38:57Z ianc $"
+#define Z80_PRIVATE_H "$Id$"
#include "z80_config.h"
@@ -71,6 +71,8 @@ struct Z80Private
Z80Callback callback[eZ80_NO_CALLBACK][MAX_PER_CALLBACK];
int last_cb;
+
+ Z80Reg memptr;
};
#define PRIV cpu->priv
@@ -116,6 +118,7 @@ extern Z80Byte Z80_MEMORY[];
#define B3_Z80 0x08
#define B5_Z80 0x20
+#define HIDDEN_Z80 (B3_Z80|B5_Z80)
#define SET(v,b) (v)|=b
@@ -180,7 +183,19 @@ static inline Z80Word PEEKW(Z80Word addr)
#define CARRY IS_C
#define IS_IX_IY (PRIV->shift==0xdd || PRIV->shift==0xfd)
-#define OFFSET(off) off=(IS_IX_IY ? (Z80Relative)FETCH_BYTE:0)
+
+#define OFFSET(base,off) do \
+ { \
+ if (IS_IX_IY) \
+ { \
+ off=(Z80Relative)FETCH_BYTE; \
+ PRIV->memptr.w=base+off; \
+ } \
+ else \
+ { \
+ off=0; \
+ } \
+ } while(0)
#define TSTATE(n) do \
{ \
@@ -228,12 +243,25 @@ static inline Z80Word PEEKW(Z80Word addr)
{ \
PUSH(cpu->PC+2); \
cpu->PC=PEEKW(cpu->PC); \
+ PRIV->memptr.w=cpu->PC; \
} while(0)
#define NOCALL cpu->PC+=2
-#define JP cpu->PC=PEEKW(cpu->PC)
-#define NOJP cpu->PC+=2
-#define JR cpu->PC+=(Z80Relative)PEEK(cpu->PC)+1
+
+#define JP do \
+ { \
+ cpu->PC=PEEKW(cpu->PC); \
+ PRIV->memptr.w=cpu->PC; \
+ } while(0)
+
+#define NOJP NOCALL
+
+#define JR do \
+ { \
+ cpu->PC+=(Z80Relative)PEEK(cpu->PC)+1; \
+ PRIV->memptr.w=cpu->PC; \
+ } while(0)
+
#define NOJR cpu->PC++
#define OUT(P,V) do \
diff --git a/source/main.c b/source/main.c
index 36f3791..b5f9c72 100644
--- a/source/main.c
+++ b/source/main.c
@@ -33,7 +33,7 @@
#include "snapshot.h"
#include "snap.h"
-#define DSSPEC_VERSION "DEVEL"
+#define DSSPEC_VERSION "0.1"
#ifndef TRUE
#define TRUE 1
@@ -109,7 +109,7 @@ static void Splash(void)
" ",
"PRESS A TO CONTINUE",
" ",
- "https://noddybox.co.uk/",
+ "https://deathstation9000.org.uk/",
" ",
NULL
};
diff --git a/source/z80.c b/source/z80.c
index 790aeec..0f1293a 100644
--- a/source/z80.c
+++ b/source/z80.c
@@ -68,6 +68,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 +96,13 @@ 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;
+ PRIV->memptr.w=cpu->PC;
break;
}
}
@@ -198,6 +201,8 @@ void Z80Reset(Z80 *cpu)
PRIV->raise=FALSE;
PRIV->nmi=FALSE;
+
+ PRIV->memptr.w = 0x0000;
}
diff --git a/source/z80_decode.c b/source/z80_decode.c
index da2fee0..dcca2c2 100644
--- a/source/z80_decode.c
+++ b/source/z80_decode.c
@@ -19,7 +19,7 @@
-------------------------------------------------------------------------
- $Id: z80_decode.c 48 2021-08-24 22:11:02Z ianc $
+ $Id$
*/
#include <stdlib.h>
@@ -197,6 +197,7 @@ 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; \
@@ -210,6 +211,7 @@ 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; \
@@ -226,6 +228,7 @@ 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; \
@@ -241,7 +244,7 @@ do { \
#define INC8(REG) \
do { \
(REG)++; \
- cpu->AF.b.lo=CARRY|SZtable[(REG)]; \
+ 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)
@@ -250,7 +253,7 @@ do { \
#define DEC8(REG) \
do { \
(REG)--; \
- cpu->AF.b.lo=N_Z80|CARRY; \
+ 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)]; \
@@ -268,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)
@@ -437,18 +441,34 @@ do { \
#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) \
{ \
- 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(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) \
+ { \
+ cpu->AF.b.lo|=S_Z80&b; \
+ } \
+ else \
+ { \
+ cpu->AF.b.lo|=Z_Z80|P_Z80; \
+ } \
+ SETHIDDEN(PRIV->memptr.b.hi); \
} while(0)
#define BIT_SET(REG,B) (REG)|=(1<<B)
@@ -507,6 +527,7 @@ do { \
{ \
TSTATE(11); \
POP(cpu->PC); \
+ PRIV->memptr.w=cpu->PC; \
} \
else \
{ \
@@ -518,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); \
@@ -540,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); \
@@ -561,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); \
@@ -589,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 \
@@ -732,7 +766,7 @@ do { \
\
case BASE+6: /* LD DEST,(HL) */ \
TSTATE(7); \
- OFFSET(off); \
+ OFFSET(*HL,off); \
DEST2=PEEK(*HL+off); \
break; \
\
@@ -774,7 +808,7 @@ do { \
\
case BASE+6: /* OP A,(HL) */ \
TSTATE(7); \
- OFFSET(off); \
+ OFFSET(*HL,off); \
OP_ON_MEM(OP,*HL+off); \
break; \
\
@@ -828,7 +862,7 @@ do { \
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); \
@@ -859,9 +893,9 @@ do { \
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 */ \
@@ -913,7 +947,7 @@ do { \
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); \
@@ -944,9 +978,9 @@ do { \
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 */ \
@@ -1028,12 +1062,16 @@ 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);
@@ -1042,7 +1080,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
cpu->AF.b.hi=0;
SUB8(b);
break;
- }
+ }
case 0x45: /* RETN */
TSTATE(14);
@@ -1087,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 */
{
@@ -1108,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 */
@@ -1147,12 +1190,16 @@ 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);
@@ -1161,7 +1208,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
cpu->AF.b.hi=0;
SUB8(b);
break;
- }
+ }
case 0x55: /* RETN */
TSTATE(14);
@@ -1206,12 +1253,16 @@ 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);
@@ -1220,7 +1271,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
cpu->AF.b.hi=0;
SUB8(b);
break;
- }
+ }
case 0x5d: /* RETN */
TSTATE(14);
@@ -1265,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 */
{
@@ -1293,12 +1348,13 @@ 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);
@@ -1306,7 +1362,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
cpu->AF.b.lo=CARRY|PSZtable[cpu->AF.b.hi];
SETHIDDEN(cpu->AF.b.hi);
break;
- }
+ }
case 0x68: /* IN L,(C) */
TSTATE(12);
@@ -1335,12 +1391,16 @@ 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);
@@ -1349,7 +1409,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
cpu->AF.b.hi=0;
SUB8(b);
break;
- }
+ }
case 0x6d: /* RETN */
TSTATE(14);
@@ -1363,12 +1423,13 @@ 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);
@@ -1376,10 +1437,10 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
cpu->AF.b.lo=CARRY|PSZtable[cpu->AF.b.hi];
SETHIDDEN(cpu->AF.b.hi);
break;
- }
+ }
case 0x70: /* IN (C) */
- {
+ {
Z80Byte b;
TSTATE(12);
@@ -1396,11 +1457,11 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
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 */
@@ -1414,7 +1475,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
break;
case 0x74: /* NEG */
- {
+ {
Z80Byte b;
TSTATE(8);
@@ -1423,7 +1484,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
cpu->AF.b.hi=0;
SUB8(b);
break;
- }
+ }
case 0x75: /* RETN */
TSTATE(14);
@@ -1454,12 +1515,14 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
}
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);
+ PRIV->memptr.w=cpu->BC.w+1;
break;
case 0x7a: /* ADC HL,SP */
@@ -1473,7 +1536,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
break;
case 0x7c: /* NEG */
- {
+ {
Z80Byte b;
TSTATE(8);
@@ -1482,7 +1545,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
cpu->AF.b.hi=0;
SUB8(b);
break;
- }
+ }
case 0x7d: /* RETN */
TSTATE(14);
@@ -1508,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 */
@@ -1528,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;
@@ -1557,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)
{
@@ -1573,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);
@@ -1582,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;
@@ -1597,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)
{
@@ -1613,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);
@@ -1645,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)
}
}
@@ -1685,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... */
@@ -1705,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)
}
}
@@ -1779,6 +1872,8 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x02: /* LD (BC),A */
TSTATE(7);
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 */
@@ -1819,6 +1914,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x0a: /* LD A,(BC) */
TSTATE(7);
cpu->AF.b.hi=PEEK(cpu->BC.w);
+ cpu->priv->memptr.w=cpu->BC.w+1;
break;
case 0x0b: /* DEC BC */
@@ -1867,6 +1963,8 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x12: /* LD (DE),A */
TSTATE(7);
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 */
@@ -1907,6 +2005,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x1a: /* LD A,(DE) */
TSTATE(7);
cpu->AF.b.hi=PEEK(cpu->DE.w);
+ cpu->priv->memptr.w=cpu->DE.w+1;
break;
case 0x1b: /* DEC DE */
@@ -2025,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);
@@ -2036,19 +2140,19 @@ 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;
@@ -2069,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);
@@ -2116,37 +2224,37 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x70: /* LD (HL),B */
TSTATE(7);
- OFFSET(off);
+ OFFSET(*HL,off);
POKE(*HL+off,cpu->BC.b.hi);
break;
case 0x71: /* LD (HL),C */
TSTATE(7);
- OFFSET(off);
+ OFFSET(*HL,off);
POKE(*HL+off,cpu->BC.b.lo);
break;
case 0x72: /* LD (HL),D */
TSTATE(7);
- OFFSET(off);
+ OFFSET(*HL,off);
POKE(*HL+off,cpu->DE.b.hi);
break;
case 0x73: /* LD (HL),E */
TSTATE(7);
- OFFSET(off);
+ OFFSET(*HL,off);
POKE(*HL+off,cpu->DE.b.lo);
break;
case 0x74: /* LD (HL),H */
TSTATE(7);
- OFFSET(off);
+ OFFSET(*HL,off);
POKE(*HL+off,cpu->HL.b.hi);
break;
case 0x75: /* LD (HL),L */
TSTATE(7);
- OFFSET(off);
+ OFFSET(*HL,off);
POKE(*HL+off,cpu->HL.b.lo);
break;
@@ -2162,7 +2270,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x77: /* LD (HL),A */
TSTATE(7);
- OFFSET(off);
+ OFFSET(*HL,off);
POKE(*HL+off,cpu->AF.b.hi);
break;
@@ -2281,6 +2389,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
port=FETCH_BYTE;
port|=(Z80Word)cpu->AF.b.hi<<8;
+ PRIV->memptr.w=port+1;
PRIV->pwrite(cpu,port,cpu->AF.b.hi);
}
else
@@ -2329,6 +2438,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
port=FETCH_BYTE;
port|=(Z80Word)cpu->AF.b.hi<<8;
cpu->AF.b.hi=PRIV->pread(cpu,port);
+ PRIV->memptr.w=port+1;
}
else
cpu->PC++;
@@ -2369,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);