summaryrefslogtreecommitdiff
path: root/z80_decode.c
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2006-09-06 23:35:58 +0000
committerIan C <ianc@noddybox.co.uk>2006-09-06 23:35:58 +0000
commit3e2e62d3966f4620674e51a424c7c2e734e05235 (patch)
treed32da044922666a28cf5b587b1493324b7c14525 /z80_decode.c
parent3261fd65167abc52aefa288ac71a1dc14b82ad16 (diff)
Updated to use a function-based memory interface.
Diffstat (limited to 'z80_decode.c')
-rw-r--r--z80_decode.c117
1 files changed, 72 insertions, 45 deletions
diff --git a/z80_decode.c b/z80_decode.c
index c94f092..e78206c 100644
--- a/z80_decode.c
+++ b/z80_decode.c
@@ -124,6 +124,13 @@ 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);
+}
+
+
/* ---------------------------------------- GENERAL MACROS
*/
#define SWAP(A,B) \
@@ -265,6 +272,40 @@ do { \
} while(0)
+#define OP_ON_MEM(OP,addr) \
+do { \
+ Z80Byte memop=cpu->mread(cpu,addr); \
+ OP(memop); \
+ cpu->mwrite(cpu,addr,memop); \
+} while(0)
+
+
+#define OP_ON_MEM_WITH_ARG(OP,addr,arg) \
+do { \
+ Z80Byte memop=cpu->mread(cpu,addr); \
+ OP(memop,arg); \
+ cpu->mwrite(cpu,addr,memop); \
+} while(0)
+
+
+#define OP_ON_MEM_WITH_COPY(OP,addr,copy) \
+do { \
+ Z80Byte memop=cpu->mread(cpu,addr); \
+ OP(memop); \
+ copy=memop; \
+ cpu->mwrite(cpu,addr,memop); \
+} while(0)
+
+
+#define OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,arg,copy) \
+do { \
+ Z80Byte memop=cpu->mread(cpu,addr); \
+ OP(memop,arg); \
+ copy=memop; \
+ cpu->mwrite(cpu,addr,memop); \
+} while(0)
+
+
/* ---------------------------------------- ROTATE AND SHIFT OPS
*/
#define RRCA \
@@ -707,7 +748,7 @@ do { \
case BASE+6: /* LD DEST,(HL) */ \
TSTATE(7); \
OFFSET(off); \
- DEST2=cpu->memory[*HL+off]; \
+ DEST2=cpu->mread(cpu,*HL+off); \
break; \
\
case BASE+7: /* LD DEST,A */ \
@@ -749,7 +790,7 @@ do { \
case BASE+6: /* OP A,(HL) */ \
TSTATE(7); \
OFFSET(off); \
- OP(cpu->memory[*HL+off]); \
+ OP_ON_MEM(OP,*HL+off); \
break; \
\
case BASE+7: /* OP A,A */ \
@@ -794,7 +835,7 @@ do { \
\
case BASE+6: /* OP (HL) */ \
TSTATE(15); \
- OP(cpu->memory[cpu->HL.w]); \
+ OP_ON_MEM(OP,cpu->HL.w); \
break; \
\
case BASE+7: /* OP A */ \
@@ -835,7 +876,7 @@ do { \
\
case BASE+6: /* OP (HL) */ \
TSTATE(12); \
- OP(cpu->memory[cpu->HL.w],BIT_NO); \
+ OP_ON_MEM_WITH_ARG(OP,cpu->HL.w,BIT_NO); \
break; \
\
case BASE+7: /* OP A */ \
@@ -849,97 +890,83 @@ do { \
#define SHIFTED_CB_ALU_BLOCK(BASE,OP) \
case BASE: /* OP B */ \
TSTATE(8); \
- OP(cpu->memory[addr]); \
- cpu->BC.b[HI]=cpu->memory[addr]; \
+ OP_ON_MEM_WITH_COPY(OP,addr,cpu->BC.b[HI]); \
break; \
\
case BASE+1: /* OP C */ \
TSTATE(8); \
- OP(cpu->memory[addr]); \
- cpu->BC.b[LO]=cpu->memory[addr]; \
+ OP_ON_MEM_WITH_COPY(OP,addr,cpu->BC.b[LO]); \
break; \
\
case BASE+2: /* OP D */ \
TSTATE(8); \
- OP(cpu->memory[addr]); \
- cpu->DE.b[HI]=cpu->memory[addr]; \
+ OP_ON_MEM_WITH_COPY(OP,addr,cpu->DE.b[HI]); \
break; \
\
case BASE+3: /* OP E */ \
TSTATE(8); \
- OP(cpu->memory[addr]); \
- cpu->DE.b[LO]=cpu->memory[addr]; \
+ OP_ON_MEM_WITH_COPY(OP,addr,cpu->DE.b[LO]); \
break; \
\
case BASE+4: /* OP H */ \
TSTATE(8); \
- OP(cpu->memory[addr]); \
- cpu->HL.b[HI]=cpu->memory[addr]; \
+ OP_ON_MEM_WITH_COPY(OP,addr,cpu->HL.b[HI]); \
break; \
\
case BASE+5: /* OP L */ \
TSTATE(8); \
- OP(cpu->memory[addr]); \
- cpu->HL.b[LO]=cpu->memory[addr]; \
+ OP_ON_MEM_WITH_COPY(OP,addr,cpu->HL.b[LO]); \
break; \
\
case BASE+6: /* OP (HL) */ \
TSTATE(15); \
- OP(cpu->memory[addr]); \
+ OP_ON_MEM(OP,addr); \
break; \
\
case BASE+7: /* OP A */ \
TSTATE(8); \
- OP(cpu->memory[addr]); \
- cpu->AF.b[HI]=cpu->memory[addr]; \
+ OP_ON_MEM_WITH_COPY(OP,addr,cpu->AF.b[HI]); \
break;
#define SHIFTED_CB_BITMANIP_BLOCK(BASE,OP,BIT_NO) \
case BASE: /* OP B */ \
TSTATE(8); \
- OP(cpu->memory[addr],BIT_NO); \
- cpu->BC.b[HI]=cpu->memory[addr]; \
+ OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->BC.b[HI]); \
break; \
\
case BASE+1: /* OP C */ \
TSTATE(8); \
- OP(cpu->memory[addr],BIT_NO); \
- cpu->BC.b[LO]=cpu->memory[addr]; \
+ OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->BC.b[LO]); \
break; \
\
case BASE+2: /* OP D */ \
TSTATE(8); \
- OP(cpu->memory[addr],BIT_NO); \
- cpu->DE.b[HI]=cpu->memory[addr]; \
+ OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->DE.b[HI]); \
break; \
\
case BASE+3: /* OP E */ \
TSTATE(8); \
- OP(cpu->memory[addr],BIT_NO); \
- cpu->DE.b[LO]=cpu->memory[addr]; \
+ OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->DE.b[LO]); \
break; \
\
case BASE+4: /* OP H */ \
TSTATE(8); \
- OP(cpu->memory[addr],BIT_NO); \
- cpu->HL.b[HI]=cpu->memory[addr]; \
+ OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->HL.b[HI]); \
break; \
\
case BASE+5: /* OP L */ \
TSTATE(8); \
- OP(cpu->memory[addr],BIT_NO); \
- cpu->HL.b[LO]=cpu->memory[addr]; \
+ OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->HL.b[LO]); \
break; \
\
case BASE+6: /* OP (HL) */ \
TSTATE(12); \
- OP(cpu->memory[addr],BIT_NO); \
+ OP_ON_MEM_WITH_ARG(OP,addr,BIT_NO); \
break; \
\
case BASE+7: /* OP A */ \
TSTATE(8); \
- OP(cpu->memory[addr],BIT_NO); \
- cpu->AF.b[HI]=cpu->memory[addr]; \
+ OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,BIT_NO,cpu->AF.b[HI]); \
break;
/* ---------------------------------------- DAA
@@ -2024,19 +2051,19 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x34: /* INC (HL) */
TSTATE(11);
OFFSET(off);
- INC8(cpu->memory[*HL+off]);
+ OP_ON_MEM(INC8,*HL+off);
break;
case 0x35: /* DEC (HL) */
TSTATE(11);
OFFSET(off);
- DEC8(cpu->memory[*HL+off]);
+ OP_ON_MEM(DEC8,*HL+off);
break;
case 0x36: /* LD (HL),n */
TSTATE(10);
OFFSET(off);
- cpu->memory[*HL+off]=FETCH_BYTE;
+ cpu->mwrite(cpu,*HL+off,FETCH_BYTE);
break;
case 0x37: /* SCF */
@@ -2057,7 +2084,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x3a: /* LD A,(nnnn) */
TSTATE(13);
- cpu->AF.b[HI]=cpu->memory[FETCH_WORD];
+ cpu->AF.b[HI]=cpu->mread(cpu,FETCH_WORD);
break;
case 0x3b: /* DEC SP */
@@ -2102,37 +2129,37 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x70: /* LD (HL),B */
TSTATE(7);
OFFSET(off);
- cpu->memory[*HL+off]=cpu->BC.b[HI];
+ cpu->mwrite(cpu,*HL+off,cpu->BC.b[HI]);
break;
case 0x71: /* LD (HL),C */
TSTATE(7);
OFFSET(off);
- cpu->memory[*HL+off]=cpu->BC.b[LO];
+ cpu->mwrite(cpu,*HL+off,cpu->BC.b[LO]);
break;
case 0x72: /* LD (HL),D */
TSTATE(7);
OFFSET(off);
- cpu->memory[*HL+off]=cpu->DE.b[HI];
+ cpu->mwrite(cpu,*HL+off,cpu->DE.b[HI]);
break;
case 0x73: /* LD (HL),E */
TSTATE(7);
OFFSET(off);
- cpu->memory[*HL+off]=cpu->DE.b[LO];
+ cpu->mwrite(cpu,*HL+off,cpu->DE.b[LO]);
break;
case 0x74: /* LD (HL),H */
TSTATE(7);
OFFSET(off);
- cpu->memory[*HL+off]=cpu->HL.b[HI];
+ cpu->mwrite(cpu,*HL+off,cpu->HL.b[HI]);
break;
case 0x75: /* LD (HL),L */
TSTATE(7);
OFFSET(off);
- cpu->memory[*HL+off]=cpu->HL.b[LO];
+ cpu->mwrite(cpu,*HL+off,cpu->HL.b[LO]);
break;
case 0x76: /* HALT */
@@ -2148,7 +2175,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode)
case 0x77: /* LD (HL),A */
TSTATE(7);
OFFSET(off);
- cpu->memory[*HL+off]=cpu->AF.b[HI];
+ cpu->mwrite(cpu,*HL+off,cpu->AF.b[HI]);
break;
LD_BLOCK(0x78,cpu->AF.b[HI],cpu->AF.b[HI])