cpu/cpu - Treat a call to an ISR as a step
This commit is contained in:
parent
e15630fb80
commit
7aa1af40fb
2 changed files with 12 additions and 4 deletions
12
cpu/cpu.cpp
12
cpu/cpu.cpp
|
@ -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,8 +27,10 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue