diff --git a/src/cpu.cpp b/src/cpu.cpp index ca7547e..d9b770a 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -13,6 +13,16 @@ CPU::CPU(uint32_t frequency) : ProcessingUnit(frequency) { + m_shared_registers.emplace("a", &m_a); + m_shared_registers.emplace("bc", &m_bc); + m_shared_registers.emplace("de", &m_de); + m_shared_registers.emplace("hl", &m_hl); + m_shared_registers.emplace("sp", &m_sp); + m_shared_registers.emplace("pc", &m_pc); + m_shared_registers.emplace("z", &m_z); + m_shared_registers.emplace("n", &m_n); + m_shared_registers.emplace("h", &m_h); + m_shared_registers.emplace("c", &m_c); } CPU::~CPU() @@ -26,7 +36,10 @@ void CPU::update() // Read next opcode } - print("This is an update from the CPU\n"); + m_a = 6; + m_bc = 732; + + // print("This is an update from the CPU\n"); } void CPU::add(uint8_t opcode, uint8_t immediate) diff --git a/src/emu.h b/src/emu.h index 56ff81f..dd7556d 100644 --- a/src/emu.h +++ b/src/emu.h @@ -22,6 +22,10 @@ public: void writeMemory(const char* memory_space, uint32_t location, uint32_t value); uint32_t readMemory(const char* memory_space, uint32_t location); + // ------------------------------------- + + ProcessingUnit* processingUnit(const char* name) const { return m_processing_units.at(name); } + private: uint32_t m_frequency { 0 }; double m_timestep { 0 }; diff --git a/src/main.cpp b/src/main.cpp index c6b342e..36bdae0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,13 +3,17 @@ #include "cpu.h" #include "emu.h" #include "ppu.h" +#include "ruc/format/print.h" #include "ruc/timer.h" int main(int argc, char* argv[]) { + (void)argc; + (void)argv; + ruc::Timer t; - printf("%fms\n", t.elapsedNanoseconds() / 1000000.0); + print("{}ms\n", t.elapsedNanoseconds() / 1000000.0); Emu::the().init(8000000); @@ -24,6 +28,11 @@ int main(int argc, char* argv[]) Emu::the().addMemorySpace("ROM", 1024); 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")); + while (true) { Emu::the().update(); } diff --git a/src/ppu.cpp b/src/ppu.cpp index 5ffe542..c7c3569 100644 --- a/src/ppu.cpp +++ b/src/ppu.cpp @@ -20,5 +20,5 @@ PPU ::~PPU() void PPU::update() { - print("ppu update\n"); + // print("ppu update\n"); } diff --git a/src/processing-unit.cpp b/src/processing-unit.cpp index 935e6c4..47887c4 100644 --- a/src/processing-unit.cpp +++ b/src/processing-unit.cpp @@ -17,8 +17,3 @@ ProcessingUnit::ProcessingUnit(uint32_t frequency) ProcessingUnit::~ProcessingUnit() { } - -uint32_t ProcessingUnit::frequency() -{ - return m_frequency; -} diff --git a/src/processing-unit.h b/src/processing-unit.h index 09509e8..24435fd 100644 --- a/src/processing-unit.h +++ b/src/processing-unit.h @@ -8,6 +8,7 @@ #pragma once #include // uint32_t +#include class ProcessingUnit { public: @@ -16,8 +17,12 @@ public: virtual void update() = 0; - uint32_t frequency(); + // ------------------------------------- -private: + uint32_t frequency() const { return m_frequency; }; + uint32_t* sharedRegister(const char* shared_register) const { return m_shared_registers.at(shared_register); } + +protected: uint32_t m_frequency { 0 }; + std::unordered_map m_shared_registers; };