summaryrefslogtreecommitdiff
path: root/z80.c
diff options
context:
space:
mode:
Diffstat (limited to 'z80.c')
-rw-r--r--z80.c190
1 files changed, 73 insertions, 117 deletions
diff --git a/z80.c b/z80.c
index 6745fe1..11e466b 100644
--- a/z80.c
+++ b/z80.c
@@ -28,19 +28,14 @@
Z80
*/
+#include <stdlib.h>
+
#include "z80.h"
#include "z80_private.h"
static const char ident[]="$Id$";
-
-
-/* ---------------------------------------- LIBRARY VARIABLES
-*/
-static Z80Byte PSZtable[512];
-static Z80Byte SZtable[512];
-static Z80Byte Ptable[512];
-static Z80Byte Stable[512];
-static Z80Byte Ztable[512];
+static const char ident_z80_header[]=Z80_H;
+static const char ident_z80_private_header[]=Z80_PRIVATE_H;
/* ---------------------------------------- PRIVATE FUNCTIONS
@@ -48,54 +43,13 @@ static Z80Byte Ztable[512];
static void InitTables()
{
static int init=FALSE;
- Z80Reg r;
- Z80Word f;
if (init)
return;
init=TRUE;
- /* Initialise flag tables
- */
- for(f=0;f<256;f++)
- {
- Z80Byte p,z,s;
- int b;
-
- p=0;
-
- for(b=0;b<8;b++)
- if (f&(1<<b))
- p++;
-
- if (p&1)
- p=0;
- else
- p=P_Z80;
-
- if (f)
- z=0;
- else
- z=Z_Z80;
-
- if (f&0x80)
- s=S_Z80;
- else
- s=0;
-
- Ptable[f]=p;
- Stable[f]=s;
- Ztable[f]=z;
- SZtable[f]=z|s;
- PSZtable[f]=z|s|p;
-
- Ptable[f+256]=Ptable[f]|C_Z80;
- Stable[f+256]=Stable[f]|C_Z80;
- Ztable[f+256]=Ztable[f]|C_Z80;
- SZtable[f+256]=SZtable[f]|C_Z80;
- PSZtable[f+256]=PSZtable[f]|C_Z80;
- }
+ Z80_InitialiseInternals();
}
static void Z80_CheckInterrupt(Z80 *cpu)
@@ -116,7 +70,7 @@ static void Z80_CheckInterrupt(Z80 *cpu)
TSTATE(2);
cpu->IFF1=0;
cpu->nmi=FALSE;
- PUSH(PC);
+ PUSH(cpu->PC);
cpu->PC=0x66;
}
else if (cpu->IFF1)
@@ -140,12 +94,12 @@ static void Z80_CheckInterrupt(Z80 *cpu)
break;
case 1:
- PUSH(PC);
+ PUSH(cpu->PC);
cpu->PC=0x38;
break;
case 2:
- PUSH(PC);
+ PUSH(cpu->PC);
cpu->PC=(Z80Word)cpu->I*256+cpu->devbyte;
break;
}
@@ -170,7 +124,7 @@ Z80 *Z80Init(Z80Memory memory,
InitTables();
- if (!write_byte || !read_byte || !write_word || !read_word)
+ if (!memory || !memcontrol)
return NULL;
cpu=malloc(sizeof *cpu);
@@ -198,18 +152,17 @@ void Z80Reset(Z80 *cpu)
cpu->cycle=0;
cpu->PC=0;
- cpu->A=0xff;
- cpu->F=0xff;
- cpu->BC=0xffff;
- cpu->DE=0xffff;
- cpu->HL=0xffff;
- cpu->AF_=0xffff;
- cpu->BC_=0xffff;
- cpu->DE_=0xffff;
- cpu->HL_=0xffff;
+ cpu->AF.w=0xffff;
+ cpu->BC.w=0xffff;
+ cpu->DE.w=0xffff;
+ cpu->HL.w=0xffff;
+ cpu->AF_.w=0xffff;
+ cpu->BC_.w=0xffff;
+ cpu->DE_.w=0xffff;
+ cpu->HL_.w=0xffff;
- cpu->IX=0xffff;
- cpu->IY=0xffff;
+ cpu->IX.w=0xffff;
+ cpu->IY.w=0xffff;
cpu->SP=0xffff;
cpu->IFF1=0;
@@ -297,66 +250,57 @@ void Z80Exec(Z80 *cpu)
void Z80GetState(Z80 *cpu, Z80State *state)
{
-#define COPY(a) state->a=cpu->a
- COPY(cycle);
+ state->cycle= cpu->cycle;
- SET_HI(state->AF,cpu->A);
- SET_LO(state->AF,cpu->F);
+ state->AF = cpu->AF.w;
+ state->BC = cpu->BC.w;
+ state->DE = cpu->DE.w;
+ state->HL = cpu->HL.w;
- COPY(BC);
- COPY(DE);
- COPY(HL);
+ state->AF_ = cpu->AF_.w;
+ state->BC_ = cpu->BC_.w;
+ state->DE_ = cpu->DE_.w;
+ state->HL_ = cpu->HL_.w;
- COPY(AF_);
- COPY(BC_);
- COPY(DE_);
- COPY(HL_);
+ state->IX = cpu->IX.w;
+ state->IY = cpu->IY.w;
- COPY(IX);
- COPY(IY);
+ state->SP = cpu->SP;
+ state->PC = cpu->PC;
- COPY(SP);
- COPY(PC);
-
- COPY(IFF1);
- COPY(IFF2);
- COPY(IM);
- COPY(I);
- COPY(R);
-#undef COPY
+ state->IFF1 = cpu->IFF1;
+ state->IFF2 = cpu->IFF2;
+ state->IM = cpu->IM;
+ state->I = cpu->I;
+ state->R = cpu->R;
}
-void Z80SetState(Z80 *cpu, Z80State *state)
+void Z80SetState(Z80 *cpu, const Z80State *state)
{
-#define COPY(a) cpu->a=state->a
- COPY(cycle);
-
- cpu->A=GET_HI(state->AF);
- cpu->F=GET_LO(state->AF);
-
- COPY(AF);
- COPY(BC);
- COPY(DE);
- COPY(HL);
-
- COPY(AF_);
- COPY(BC_);
- COPY(DE_);
- COPY(HL_);
-
- COPY(IX);
- COPY(IY);
-
- COPY(SP);
- COPY(PC);
-
- COPY(IFF1);
- COPY(IFF2);
- COPY(IM);
- COPY(I);
- COPY(R);
-#undef COPY
+ cpu->cycle = state->cycle;
+
+ cpu->AF.w = state->AF;
+ cpu->BC.w = state->BC;
+ cpu->DE.w = state->DE;
+ cpu->HL.w = state->HL;
+
+ cpu->AF_.w = state->AF_;
+ cpu->BC_.w = state->BC_;
+ cpu->DE_.w = state->DE_;
+ cpu->HL_.w = state->HL_;
+
+ cpu->IX.w = state->IX;
+ cpu->IY.w = state->IY;
+
+ cpu->SP = state->SP;
+ cpu->PC = state->PC;
+
+ cpu->IFF1 = state->IFF1;
+ cpu->IFF2 = state->IFF2;
+ cpu->IM = state->IM;
+ cpu->I = state->I;
+ cpu->R = state->R;
}
@@ -365,4 +309,16 @@ Z80Val Z80Cycles(Z80 *cpu)
return cpu->cycle;
}
+
+const char *Z80Disassemble(Z80 *cpu, Z80Word *addr)
+{
+#ifdef Z80_DISASSEMBLER_ENABLED
+ (*addr)+=4;
+ return "NO DISASSEMBLER";
+#else
+ (*addr)+=4;
+ return "NO DISASSEMBLER";
+#endif
+}
+
/* END OF FILE */