From 17c46264e9d9d243cdd83483cbefa010e767b1a7 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Sat, 25 Aug 2018 01:57:22 +0100 Subject: [PATCH] Match the GameBoy code to the updated handling of reset (etc.) interrupts. Signed-off-by: Adrian Conlon --- LR35902/inc/LR35902.h | 4 +++- LR35902/src/LR35902.cpp | 33 +++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/LR35902/inc/LR35902.h b/LR35902/inc/LR35902.h index 376510d..3cae322 100644 --- a/LR35902/inc/LR35902.h +++ b/LR35902/inc/LR35902.h @@ -40,10 +40,12 @@ namespace EightBit { virtual register16_t& HL() final { return hl; } protected: - virtual void reset() final; virtual int execute(uint8_t opcode) final; virtual int step() final; + virtual void handleRESET() override; + virtual void handleINT() override; + private: Bus& m_bus; diff --git a/LR35902/src/LR35902.cpp b/LR35902/src/LR35902.cpp index abe05ff..a3e68a1 100644 --- a/LR35902/src/LR35902.cpp +++ b/LR35902/src/LR35902.cpp @@ -9,11 +9,19 @@ EightBit::GameBoy::LR35902::LR35902(Bus& memory) m_bus(memory) { } -void EightBit::GameBoy::LR35902::reset() { - IntelProcessor::reset(); +void EightBit::GameBoy::LR35902::handleRESET() { + Processor::handleRESET(); di(); SP() = Mask16 - 1; - m_prefixCB = false; + addCycles(4); +} + +void EightBit::GameBoy::LR35902::handleINT() { + Processor::handleINT(); + raise(HALT()); + di(); + restart(BUS().DATA()); + addCycles(4); } void EightBit::GameBoy::LR35902::di() { @@ -282,7 +290,6 @@ int EightBit::GameBoy::LR35902::step() { ExecutingInstruction.fire(*this); m_prefixCB = false; resetCycles(); - int ran = 0; if (LIKELY(powered())) { const auto interruptEnable = BUS().peek(IoRegisters::BASE + IoRegisters::IE); @@ -301,24 +308,22 @@ int EightBit::GameBoy::LR35902::step() { } } - if (UNLIKELY(lowered(INT()))) { - raise(HALT()); - raise(INT()); - di(); - restart(BUS().DATA()); - ran = 4; + if (UNLIKELY(lowered(RESET()))) { + handleRESET(); + } else if (UNLIKELY(lowered(INT()))) { + handleINT(); } else if (UNLIKELY(lowered(HALT()))) { - ran = execute(0); // NOP + execute(0); // NOP } else { - ran = execute(fetchByte()); + execute(fetchByte()); } - m_bus.IO().checkTimers(ran); + m_bus.IO().checkTimers(clockCycles()); m_bus.IO().transferDma(); } ExecutedInstruction.fire(*this); - return ran; + return clockCycles(); } int EightBit::GameBoy::LR35902::execute(uint8_t opcode) {