From dcc517c28d50d0ca56a1f9fa463b1eb938b9b450 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Fri, 19 Aug 2022 21:09:22 +0200 Subject: [PATCH] Emulator: Set registers for the power-up sequence --- src/cpu.cpp | 18 +++++++++++++++--- src/cpu.h | 2 +- src/main.cpp | 1 - 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/cpu.cpp b/src/cpu.cpp index ab98215..b11dc8b 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -14,6 +14,21 @@ CPU::CPU(uint32_t frequency) : ProcessingUnit(frequency) { + // CGB registers + // https://gbdev.io/pandocs/Power_Up_Sequence.html#cpu-registers + m_a = 0x11; + m_bc = 0x0; // B = 0x0, C = 0x0 + m_de = 0xff56; // D = 0xff, E = 0x56 + m_hl = 0x000d; // H = 0x0, L = 0x0d + m_pc = 0x100; + m_sp = 0xffe; + + // Flags + m_z = 0x1; + m_n = 0x0; + m_h = 0x0; + m_c = 0x0; + m_shared_registers.emplace("a", &m_a); m_shared_registers.emplace("bc", &m_bc); m_shared_registers.emplace("de", &m_de); @@ -37,9 +52,6 @@ void CPU::update() // Read next opcode } - m_a = 6; - m_bc = 732; - // print("This is an update from the CPU\n"); } diff --git a/src/cpu.h b/src/cpu.h index 05e4a7d..990bf4f 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -42,8 +42,8 @@ private: uint32_t m_bc { 0 }; // BC uint32_t m_de { 0 }; // DE uint32_t m_hl { 0 }; // HL - uint32_t m_sp { 0 }; // Stack Pointer uint32_t m_pc { 0 }; // Program Counter + uint32_t m_sp { 0 }; // Stack Pointer // Flags uint32_t m_z { 0 }; // Zero flag diff --git a/src/main.cpp b/src/main.cpp index 36bdae0..08266dc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,7 +29,6 @@ int main(int argc, char* argv[]) Emu::the().addMemorySpace("CARDROM", 1024); // Get shared register - Emu::the().processingUnit("cpu")->update(); print("{}\n", *Emu::the().processingUnit("cpu")->sharedRegister("a")); print("{}\n", *Emu::the().processingUnit("cpu")->sharedRegister("bc"));