diff options
Diffstat (limited to 'source/z80_decode.c')
-rw-r--r-- | source/z80_decode.c | 125 |
1 files changed, 68 insertions, 57 deletions
diff --git a/source/z80_decode.c b/source/z80_decode.c index ced7fbd..a8f66ca 100644 --- a/source/z80_decode.c +++ b/source/z80_decode.c @@ -40,8 +40,11 @@ static Z80Byte Stable[512]; static Z80Byte Ztable[512]; -static int HI; -static int LO; +int Z80_HI_WORD; +int Z80_LO_WORD; + +#define HI Z80_HI_WORD +#define LO Z80_LO_WORD /* ---------------------------------------- MISC FUNCTIONS */ @@ -118,6 +121,7 @@ void Z80_InitialiseInternals(void) } } +#ifndef ENABLE_ARRAY_MEMORY static Z80Word FPEEKW(Z80 *cpu, Z80Word addr) { return (PEEK(addr) | (Z80Word)PEEK(addr+1)<<8); @@ -126,9 +130,10 @@ 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); + PRIV->mwrite(cpu,addr,val); + PRIV->mwrite(cpu,addr+1,val>>8); } +#endif /* ---------------------------------------- GENERAL MACROS @@ -274,35 +279,35 @@ do { \ #define OP_ON_MEM(OP,addr) \ do { \ - Z80Byte memop=cpu->mread(cpu,addr); \ + Z80Byte memop=PEEK(addr); \ OP(memop); \ - cpu->mwrite(cpu,addr,memop); \ + POKE(addr,memop); \ } while(0) #define OP_ON_MEM_WITH_ARG(OP,addr,arg) \ do { \ - Z80Byte memop=cpu->mread(cpu,addr); \ + Z80Byte memop=PEEK(addr); \ OP(memop,arg); \ - cpu->mwrite(cpu,addr,memop); \ + POKE(addr,memop); \ } while(0) #define OP_ON_MEM_WITH_COPY(OP,addr,copy) \ do { \ - Z80Byte memop=cpu->mread(cpu,addr); \ + Z80Byte memop=PEEK(addr); \ OP(memop); \ copy=memop; \ - cpu->mwrite(cpu,addr,memop); \ + POKE(addr,memop); \ } while(0) #define OP_ON_MEM_WITH_ARG_AND_COPY(OP,addr,arg,copy) \ do { \ - Z80Byte memop=cpu->mread(cpu,addr); \ + Z80Byte memop=PEEK(addr); \ OP(memop,arg); \ copy=memop; \ - cpu->mwrite(cpu,addr,memop); \ + POKE(addr,memop); \ } while(0) @@ -748,7 +753,7 @@ do { \ case BASE+6: /* LD DEST,(HL) */ \ TSTATE(7); \ OFFSET(off); \ - DEST2=cpu->mread(cpu,*HL+off); \ + DEST2=PEEK(*HL+off); \ break; \ \ case BASE+7: /* LD DEST,A */ \ @@ -1018,9 +1023,9 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode) case 0x40: /* IN B,(C) */ TSTATE(12); - if (cpu->pread) + if (PRIV->pread) { - cpu->BC.b[HI]=cpu->pread(cpu,cpu->BC.w); + cpu->BC.b[HI]=PRIV->pread(cpu,cpu->BC.w); } else { @@ -1033,7 +1038,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode) case 0x41: /* OUT (C),B */ TSTATE(12); - if (cpu->pwrite) cpu->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 */ @@ -1077,9 +1082,9 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode) case 0x48: /* IN C,(C) */ TSTATE(12); - if (cpu->pread) + if (PRIV->pread) { - cpu->BC.b[LO]=cpu->pread(cpu,cpu->BC.w); + cpu->BC.b[LO]=PRIV->pread(cpu,cpu->BC.w); } else { @@ -1092,7 +1097,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode) case 0x49: /* OUT (C),C */ TSTATE(12); - if (cpu->pwrite) cpu->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 */ @@ -1137,9 +1142,9 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode) case 0x50: /* IN D,(C) */ TSTATE(12); - if (cpu->pread) + if (PRIV->pread) { - cpu->DE.b[HI]=cpu->pread(cpu,cpu->BC.w); + cpu->DE.b[HI]=PRIV->pread(cpu,cpu->BC.w); } else { @@ -1152,7 +1157,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode) case 0x51: /* OUT (C),D */ TSTATE(12); - if (cpu->pwrite) cpu->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 */ @@ -1196,9 +1201,9 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode) case 0x58: /* IN E,(C) */ TSTATE(12); - if (cpu->pread) + if (PRIV->pread) { - cpu->DE.b[LO]=cpu->pread(cpu,cpu->BC.w); + cpu->DE.b[LO]=PRIV->pread(cpu,cpu->BC.w); } else { @@ -1211,7 +1216,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode) case 0x59: /* OUT (C),E */ TSTATE(12); - if (cpu->pwrite) cpu->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 */ @@ -1255,9 +1260,9 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode) case 0x60: /* IN H,(C) */ TSTATE(12); - if (cpu->pread) + if (PRIV->pread) { - cpu->HL.b[HI]=cpu->pread(cpu,cpu->BC.w); + cpu->HL.b[HI]=PRIV->pread(cpu,cpu->BC.w); } else { @@ -1270,7 +1275,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode) case 0x61: /* OUT (C),H */ TSTATE(12); - if (cpu->pwrite) cpu->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 */ @@ -1325,9 +1330,9 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode) case 0x68: /* IN L,(C) */ TSTATE(12); - if (cpu->pread) + if (PRIV->pread) { - cpu->HL.b[LO]=cpu->pread(cpu,cpu->BC.w); + cpu->HL.b[LO]=PRIV->pread(cpu,cpu->BC.w); } else { @@ -1340,7 +1345,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode) case 0x69: /* OUT (C),L */ TSTATE(12); - if (cpu->pwrite) cpu->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 */ @@ -1398,9 +1403,9 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode) TSTATE(12); - if (cpu->pread) + if (PRIV->pread) { - b=cpu->pread(cpu,cpu->BC.w); + b=PRIV->pread(cpu,cpu->BC.w); } else { @@ -1414,7 +1419,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode) case 0x71: /* OUT (C) */ TSTATE(12); - if (cpu->pwrite) cpu->pwrite(cpu,cpu->BC.w,0); + if (PRIV->pwrite) PRIV->pwrite(cpu,cpu->BC.w,0); break; case 0x72: /* SBC HL,SP */ @@ -1458,9 +1463,9 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode) case 0x78: /* IN A,(C) */ TSTATE(12); - if (cpu->pread) + if (PRIV->pread) { - cpu->AF.b[HI]=cpu->pread(cpu,cpu->BC.w); + cpu->AF.b[HI]=PRIV->pread(cpu,cpu->BC.w); } else { @@ -1473,7 +1478,7 @@ static void DecodeED(Z80 *cpu, Z80Byte opcode) case 0x79: /* OUT (C),A */ TSTATE(12); - if (cpu->pwrite) cpu->pwrite(cpu,cpu->BC.w,cpu->AF.b[HI]); + if (PRIV->pwrite) PRIV->pwrite(cpu,cpu->BC.w,cpu->AF.b[HI]); break; case 0x7a: /* ADC HL,SP */ @@ -1695,7 +1700,7 @@ static void ShiftedDecodeCB(Z80 *cpu, Z80Byte opcode, Z80Relative offset) /* See if we've come here from a IX/IY shift. */ - switch (cpu->shift) + switch (PRIV->shift) { case 0xdd: addr=cpu->IX.w+offset; @@ -1760,7 +1765,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode) /* See if we've come here from a IX/IY shift */ - switch (cpu->shift) + switch (PRIV->shift) { case 0xdd: HL=&(cpu->IX.w); @@ -2063,7 +2068,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode) case 0x36: /* LD (HL),n */ TSTATE(10); OFFSET(off); - cpu->mwrite(cpu,*HL+off,FETCH_BYTE); + POKE(*HL+off,FETCH_BYTE); break; case 0x37: /* SCF */ @@ -2084,7 +2089,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode) case 0x3a: /* LD A,(nnnn) */ TSTATE(13); - cpu->AF.b[HI]=cpu->mread(cpu,FETCH_WORD); + cpu->AF.b[HI]=PEEK(FETCH_WORD); break; case 0x3b: /* DEC SP */ @@ -2129,53 +2134,53 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode) case 0x70: /* LD (HL),B */ TSTATE(7); OFFSET(off); - cpu->mwrite(cpu,*HL+off,cpu->BC.b[HI]); + POKE(*HL+off,cpu->BC.b[HI]); break; case 0x71: /* LD (HL),C */ TSTATE(7); OFFSET(off); - cpu->mwrite(cpu,*HL+off,cpu->BC.b[LO]); + POKE(*HL+off,cpu->BC.b[LO]); break; case 0x72: /* LD (HL),D */ TSTATE(7); OFFSET(off); - cpu->mwrite(cpu,*HL+off,cpu->DE.b[HI]); + POKE(*HL+off,cpu->DE.b[HI]); break; case 0x73: /* LD (HL),E */ TSTATE(7); OFFSET(off); - cpu->mwrite(cpu,*HL+off,cpu->DE.b[LO]); + POKE(*HL+off,cpu->DE.b[LO]); break; case 0x74: /* LD (HL),H */ TSTATE(7); OFFSET(off); - cpu->mwrite(cpu,*HL+off,cpu->HL.b[HI]); + POKE(*HL+off,cpu->HL.b[HI]); break; case 0x75: /* LD (HL),L */ TSTATE(7); OFFSET(off); - cpu->mwrite(cpu,*HL+off,cpu->HL.b[LO]); + POKE(*HL+off,cpu->HL.b[LO]); break; case 0x76: /* HALT */ TSTATE(4); cpu->PC--; - if (!cpu->halt) + if (!PRIV->halt) CALLBACK(eZ80_Halt,1); - cpu->halt=TRUE; + PRIV->halt=TRUE; break; case 0x77: /* LD (HL),A */ TSTATE(7); OFFSET(off); - cpu->mwrite(cpu,*HL+off,cpu->AF.b[HI]); + POKE(*HL+off,cpu->AF.b[HI]); break; LD_BLOCK(0x78,cpu->AF.b[HI],cpu->AF.b[HI]) @@ -2242,7 +2247,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode) /* Check for previous IX/IY shift. */ - if (cpu->shift!=0) + if (PRIV->shift!=0) { Z80Relative cb_offset; @@ -2287,8 +2292,14 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode) case 0xd3: /* OUT (n),A */ TSTATE(11); - if (cpu->pwrite) - cpu->pwrite(cpu,FETCH_BYTE,cpu->AF.b[HI]); + if (PRIV->pwrite) + { + Z80Word port; + + port=FETCH_BYTE; + port|=(Z80Word)cpu->AF.b[HI]<<8; + PRIV->pwrite(cpu,port,cpu->AF.b[HI]); + } else cpu->PC++; break; @@ -2328,13 +2339,13 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode) case 0xdb: /* IN A,(n) */ TSTATE(11); - if (cpu->pread) + if (PRIV->pread) { Z80Word port; port=FETCH_BYTE; port|=(Z80Word)cpu->AF.b[HI]<<8; - cpu->AF.b[HI]=cpu->pread(cpu,port); + cpu->AF.b[HI]=PRIV->pread(cpu,port); } else cpu->PC++; @@ -2348,7 +2359,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode) TSTATE(4); INC_R; - cpu->shift=opcode; + PRIV->shift=opcode; Z80_Decode(cpu,FETCH_BYTE); break; @@ -2502,7 +2513,7 @@ void Z80_Decode(Z80 *cpu, Z80Byte opcode) TSTATE(4); INC_R; - cpu->shift=opcode; + PRIV->shift=opcode; Z80_Decode(cpu,FETCH_BYTE); break; |