cpu/cpu - Treat a call to an ISR as a step

This commit is contained in:
madmaurice 2023-08-29 13:45:17 +02:00
parent e15630fb80
commit 7aa1af40fb
2 changed files with 12 additions and 4 deletions

View file

@ -1,4 +1,5 @@
#include "cpu.h" #include "cpu.h"
#include "panic.h"
void Cpu_state::setAF(u16 v) void Cpu_state::setAF(u16 v)
{ {
@ -26,9 +27,11 @@ Cpu::Cpu(Mem_device* bus)
void Cpu::step() void Cpu::step()
{ {
handleInterrupts(); if(!handleInterrupts()) // if no isr has been called, decode an instruction
{
executeInstruction(); executeInstruction();
} }
}
void Cpu::reset() void Cpu::reset()
{ {
@ -185,7 +188,7 @@ void Cpu::aluop8(AluOp op, u8 lhs, u8 rhs, u8& out, bool update_carry)
out = res; out = res;
} }
void Cpu::handleInterrupts() bool Cpu::handleInterrupts()
{ {
// servicable interrupts (assuming IME is on) // servicable interrupts (assuming IME is on)
u8 si = state.IE & state.IF & INT_MASK; 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_Timer) { it = INT_Timer; isr = 0x50; }
else if (si & INT_Serial) { it = INT_Serial; isr = 0x58; } else if (si & INT_Serial) { it = INT_Serial; isr = 0x58; }
else if (si & INT_Joypad) { it = INT_Joypad; isr = 0x60; } 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.IME = IME_OFF; // Disable IME
state.IF &= ~it; // clear interrupt in IF state.IF &= ~it; // clear interrupt in IF
doCall(isr); // Call interrupt service routine doCall(isr); // Call interrupt service routine
processed_mcycles += 5; processed_mcycles += 5;
return true;
} }
return false;
} }

View file

@ -119,7 +119,7 @@ private:
bool decodeCond(u8 cc); bool decodeCond(u8 cc);
void handleInterrupts(); bool handleInterrupts();
void executeInstruction(); void executeInstruction();
void reset(); void reset();