From 1d1e0acb5b4494f7c1b041e24e5de4f0614a150b Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 23 Apr 2023 08:24:31 +0800 Subject: Updated Z80 emulation --- source/z80.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'source/z80.c') diff --git a/source/z80.c b/source/z80.c index e5f6c92..d18640a 100644 --- a/source/z80.c +++ b/source/z80.c @@ -50,6 +50,8 @@ static void InitTables() static void Z80_CheckInterrupt(Z80 *cpu) { + Z80Word vector; + /* Check interrupts */ if (PRIV->raise) @@ -68,6 +70,7 @@ static void Z80_CheckInterrupt(Z80 *cpu) PRIV->nmi=FALSE; PUSH(cpu->PC); cpu->PC=0x66; + PRIV->memptr.w=cpu->PC; } else if (cpu->IFF1) { @@ -95,11 +98,14 @@ static void Z80_CheckInterrupt(Z80 *cpu) case 1: PUSH(cpu->PC); cpu->PC=0x38; + PRIV->memptr.w=cpu->PC; break; case 2: PUSH(cpu->PC); - cpu->PC=(Z80Word)cpu->I*256+PRIV->devbyte; + vector=(Z80Word)cpu->I*256+PRIV->devbyte; + cpu->PC=PEEKW(vector); + PRIV->memptr.w=cpu->PC; break; } } @@ -170,6 +176,10 @@ Z80 *Z80Init(Z80ReadMemory read_memory, void Z80Reset(Z80 *cpu) { PRIV->cycle=0; + PRIV->timer[Z80_TIMER_1]=0; + PRIV->timer[Z80_TIMER_2]=0; + PRIV->timer[Z80_TIMER_3]=0; + cpu->PC=0; cpu->AF.w=0xffff; @@ -194,6 +204,8 @@ void Z80Reset(Z80 *cpu) PRIV->raise=FALSE; PRIV->nmi=FALSE; + + PRIV->memptr.w = 0x0000; } @@ -209,6 +221,18 @@ void Z80ResetCycles(Z80 *cpu, Z80Val cycles) } +Z80Val Z80GetTimer(Z80 *cpu, Z80Timer timer) +{ + return PRIV->timer[timer]; +} + + +void Z80SetTimer(Z80 *cpu, Z80Timer timer, Z80Val cycles) +{ + PRIV->timer[timer] = cycles; +} + + int Z80LodgeCallback(Z80 *cpu, Z80CallbackReason reason, Z80Callback callback) { int f; -- cgit v1.2.3