From ed045a72b20894437e799efe047a4d3fd5680f7c Mon Sep 17 00:00:00 2001 From: Riyyi Date: Thu, 1 Sep 2022 00:47:30 +0200 Subject: [PATCH] Emulator: Prepare for running blargg's test ROMs --- src/cpu-prefix.cpp | 2 +- src/cpu.cpp | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/cpu-prefix.cpp b/src/cpu-prefix.cpp index 01bd05f..f60885f 100644 --- a/src/cpu-prefix.cpp +++ b/src/cpu-prefix.cpp @@ -19,7 +19,7 @@ void CPU::prefix() // Read next opcode uint8_t opcode = read(m_pc); - print("running opcode: {:#04x} @ ({:#06x})\n", opcode, m_pc); + // print("running opcode: {:#04x} @ ({:#06x})\n", opcode, m_pc); if (opcode <= 0x07) { rlc(); } diff --git a/src/cpu.cpp b/src/cpu.cpp index 06f4b8f..a1ab3eb 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -58,15 +58,20 @@ CPU::~CPU() void CPU::update() { m_wait_cycles--; + // TODO: convert to early-return if (m_wait_cycles <= 0) { // print(ruc::format::Emphasis::Underline | ruc::format::Emphasis::Bold | fg(ruc::format::TerminalColor::Blue), "{:#06x}\n", *this); // Read next opcode uint8_t opcode = read(m_pc); - print("running opcode: {:#04x} @ ({:#06x})\n", opcode, m_pc); + // print("running opcode: {:#04x} @ ({:#06x})\n", opcode, m_pc); switch (opcode) { + case 0x10: /* TODO */ m_pc += 2; break; + case 0xf3: /* TODO */ m_pc += 1; break; + case 0xfb: /* TODO */ m_pc += 1; break; + case 0x00: nop(); break; case 0x01: ldi16(); break; case 0x02: ldr8(); break; @@ -281,6 +286,7 @@ void CPU::update() case 0xd6: sub8(); break; case 0xd7: rst(); break; case 0xd8: ret(); break; + case 0xd9: ret(); break; case 0xda: jp16(); break; case 0xdc: call(); break; case 0xde: sbc8(); break; @@ -1525,7 +1531,12 @@ void CPU::ret() case 0xc9: /* RET i16 */ function_return(true); break; case 0xd0: /* RET NC,i16 */ function_return(!m_cf); break; case 0xd8: /* RET C,i16 */ function_return(m_cf); break; - // case 0xd9: /* RETI */ FIXME break; + case 0xd9: /* RETI */ { + // Return from subroutine + // TODO: and enable interrupts. + function_return(true); + break; + } default: VERIFY_NOT_REACHED(); } @@ -1641,7 +1652,8 @@ void CPU::write(uint32_t address, uint32_t value) uint32_t CPU::read(uint32_t address) { - return Emu::the().readMemory(address) & 0xff; + // FIXME: Figure out where HL gets set to above 0xffff + return Emu::the().readMemory(address & 0xffff) & 0xff; } void CPU::ffWrite(uint32_t address, uint32_t value)