summaryrefslogtreecommitdiff
path: root/z80_decode.c
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2022-12-24 21:26:38 +0000
committerIan C <ianc@noddybox.co.uk>2022-12-24 21:26:38 +0000
commit51f4e96faabb862c10924ea92e4137e8fcf57d37 (patch)
tree1636aaa697908c3d8b6c4fbf3123b1eb46847edb /z80_decode.c
parent2be063571c837ed5dd11a3be1211cb8182d4312d (diff)
Added MEMPTR setting.
Diffstat (limited to 'z80_decode.c')
-rw-r--r--z80_decode.c146
1 files changed, 113 insertions, 33 deletions
diff --git a/z80_decode.c b/z80_decode.c
index e19f593..901760c 100644
--- a/z80_decode.c
+++ b/z80_decode.c
@@ -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; \
@@ -437,12 +440,12 @@ do { \
#define BIT(REG,B) \
do { \
- cpu->AF.b.lo=CARRY|H_Z80; \
+ cpu->AF.b.lo&=CARRY; \
if ((REG)&(1<<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; \
+ if (B==7) cpu->AF.b.lo|=S_Z80; \
+ if (B==5) cpu->AF.b.lo|=B5_Z80; \
+ if (B==3) cpu->AF.b.lo|=B3_Z80; \
} \
else \
{ \
@@ -518,7 +521,8 @@ do { \
#define RST(ADDR) \
TSTATE(11); \
PUSH(cpu->PC); \
- cpu->PC=ADDR
+ cpu->PC=ADDR; \
+ cpu->priv->memptr.w=ADDR
/* ---------------------------------------- BLOCK OPERATIONS
*/
@@ -732,7 +736,7 @@ do { \
\
case BASE+6: /* LD DEST,(HL) */ \
TSTATE(7); \
- OFFSET(off); \
+ OFFSET(*HL,off); \
DEST2=PEEK(*HL+off); \
break; \
\
@@ -774,7 +778,7 @@ do { \
\
case BASE+6: /* OP A,(HL) */ \
TSTATE(7); \
- OFFSET(off); \
+ OFFSET(*HL,off); \
OP_ON_MEM(OP,*HL+off); \
break; \
\
@@ -1028,9 +1032,13 @@ 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 */
{
@@ -1087,9 +1095,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 */
{
@@ -1147,9 +1159,13 @@ 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 */
{
@@ -1206,9 +1222,13 @@ 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 */
{
@@ -1265,9 +1285,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 +1317,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 +1331,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,9 +1360,13 @@ 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 */
{
@@ -1363,12 +1392,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 +1406,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,7 +1426,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
cpu->AF.b.lo=CARRY|PSZtable[b];
SETHIDDEN(b);
break;
- }
+ }
case 0x71: /* OUT (C) */
TSTATE(12);
@@ -1454,12 +1484,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 */
@@ -1508,16 +1540,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,21 +1563,31 @@ 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);
+
+ if (cpu->BC.w!=1)
+ {
+ PRIV->memptr.w=cpu->PC-2;
+ }
+
LDI;
+
if (cpu->BC.w)
{
TSTATE(5);
@@ -1553,15 +1598,18 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0xb1: /* CPIR */
TSTATE(16);
CPI;
+ PRIV->memptr.w=cpu->PC-1;
if (cpu->BC.w && !IS_Z)
{
TSTATE(5);
cpu->PC-=2;
+ PRIV->memptr.w++;
}
break;
case 0xb2: /* INIR */
TSTATE(16);
+ PRIV->memptr.w = cpu->BC.w + 1;
INI;
if (cpu->BC.w)
{
@@ -1573,6 +1621,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,7 +1631,14 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0xb8: /* LDDR */
TSTATE(16);
+
+ if (cpu->BC.w!=1)
+ {
+ PRIV->memptr.w=cpu->PC-1;
+ }
+
LDD;
+
if (cpu->BC.w)
{
TSTATE(5);
@@ -1593,15 +1649,18 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
case 0xb9: /* CPDR */
TSTATE(16);
CPD;
+ PRIV->memptr.w=cpu->PC-1;
if (cpu->BC.w && !IS_Z)
{
TSTATE(5);
cpu->PC-=2;
+ PRIV->memptr.w++;
}
break;
case 0xba: /* INDR */
TSTATE(16);
+ PRIV->memptr.w = cpu->BC.w-1;
IND;
if (cpu->BC.w)
{
@@ -1613,6 +1672,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);
@@ -1694,6 +1754,8 @@ static void ShiftedDecodeCB(Z80 *cpu, Z80Byte opcode, Z80Relative offset)
break;
}
+ PRIV->memptr.w=addr;
+
switch(opcode)
{
SHIFTED_CB_ALU_BLOCK(0x00,RLC)
@@ -1779,6 +1841,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 +1883,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 +1932,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 +1974,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 +2093,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 +2109,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 +2142,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 +2193,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 +2239,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 +2358,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 +2407,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 +2448,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);