Match the GameBoy code to the updated handling of reset (etc.) interrupts.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2018-08-25 01:57:22 +01:00
parent 6d4223c368
commit 17c46264e9
2 changed files with 22 additions and 15 deletions

View File

@ -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;

View File

@ -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) {