From 7aa1af40fb0868f413cb1f73a31df163a0caa372 Mon Sep 17 00:00:00 2001 From: MadMaurice Date: Tue, 29 Aug 2023 13:45:17 +0200 Subject: [PATCH] cpu/cpu - Treat a call to an ISR as a step --- cpu/cpu.cpp | 14 +++++++++++--- cpu/cpu.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cpu/cpu.cpp b/cpu/cpu.cpp index 310a077..90784ce 100644 --- a/cpu/cpu.cpp +++ b/cpu/cpu.cpp @@ -1,4 +1,5 @@ #include "cpu.h" +#include "panic.h" void Cpu_state::setAF(u16 v) { @@ -26,8 +27,10 @@ Cpu::Cpu(Mem_device* bus) void Cpu::step() { - handleInterrupts(); - executeInstruction(); + if(!handleInterrupts()) // if no isr has been called, decode an instruction + { + executeInstruction(); + } } void Cpu::reset() @@ -185,7 +188,7 @@ void Cpu::aluop8(AluOp op, u8 lhs, u8 rhs, u8& out, bool update_carry) out = res; } -void Cpu::handleInterrupts() +bool Cpu::handleInterrupts() { // servicable interrupts (assuming IME is on) u8 si = state.IE & state.IF & INT_MASK; @@ -202,11 +205,16 @@ void Cpu::handleInterrupts() else if (si & INT_Timer) { it = INT_Timer; isr = 0x50; } else if (si & INT_Serial) { it = INT_Serial; isr = 0x58; } else if (si & INT_Joypad) { it = INT_Joypad; isr = 0x60; } + else panic("Can't find pending interrupt IE=%02x IF=%02x\n", state.IE, state.IF); state.IME = IME_OFF; // Disable IME state.IF &= ~it; // clear interrupt in IF doCall(isr); // Call interrupt service routine processed_mcycles += 5; + + return true; } + + return false; } diff --git a/cpu/cpu.h b/cpu/cpu.h index 8aff385..a566f1f 100644 --- a/cpu/cpu.h +++ b/cpu/cpu.h @@ -119,7 +119,7 @@ private: bool decodeCond(u8 cc); - void handleInterrupts(); + bool handleInterrupts(); void executeInstruction(); void reset();