summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--z80_decode.c146
1 files changed, 80 insertions, 66 deletions
diff --git a/z80_decode.c b/z80_decode.c
index 901760c..0a9ba00 100644
--- a/z80_decode.c
+++ b/z80_decode.c
@@ -244,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)
@@ -253,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)]; \
@@ -440,12 +440,26 @@ do { \
#define BIT(REG,B) \
do { \
- cpu->AF.b.lo&=CARRY; \
+ cpu->AF.b.lo&=C_Z80; \
if ((REG)&(1<<B)) \
{ \
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; \
+ cpu->AF.b.lo|=(REG & (B3_Z80|B5_Z80)); \
+ } \
+ else \
+ { \
+ cpu->AF.b.lo|=Z_Z80; \
+ cpu->AF.b.lo|=P_Z80; \
+ } \
+} while(0)
+
+#define BIT_MEMPTR(REG,B) \
+do { \
+ cpu->AF.b.lo&=C_Z80; \
+ if ((REG)&(1<<B)) \
+ { \
+ if (B==7) cpu->AF.b.lo|=S_Z80; \
+ cpu->AF.b.lo|=(PRIV->memptr.b.hi & (B3_Z80|B5_Z80)); \
} \
else \
{ \
@@ -832,7 +846,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); \
@@ -863,9 +877,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 */ \
@@ -917,7 +931,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); \
@@ -948,9 +962,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 */ \
@@ -1430,7 +1444,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode)
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 */
@@ -1705,32 +1719,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)
}
}
@@ -1745,17 +1759,17 @@ 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... */
break;
}
- PRIV->memptr.w=addr;
-
switch(opcode)
{
SHIFTED_CB_ALU_BLOCK(0x00,RLC)
@@ -1767,32 +1781,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,BIT_MEMPTR,0)
+ SHIFTED_CB_BITMANIP_BLOCK(0x48,BIT,BIT_MEMPTR,1)
+ SHIFTED_CB_BITMANIP_BLOCK(0x50,BIT,BIT_MEMPTR,2)
+ SHIFTED_CB_BITMANIP_BLOCK(0x58,BIT,BIT_MEMPTR,3)
+ SHIFTED_CB_BITMANIP_BLOCK(0x60,BIT,BIT_MEMPTR,4)
+ SHIFTED_CB_BITMANIP_BLOCK(0x68,BIT,BIT_MEMPTR,5)
+ SHIFTED_CB_BITMANIP_BLOCK(0x70,BIT,BIT_MEMPTR,6)
+ SHIFTED_CB_BITMANIP_BLOCK(0x78,BIT,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)
}
}