diff --git a/src/emu.cpp b/src/emu.cpp new file mode 100644 index 0000000..610b192 --- /dev/null +++ b/src/emu.cpp @@ -0,0 +1,19 @@ +#include "emu.h" + +void Emu::update() { + for (auto unit : m_processing_units) { + if (m_cycle % int(m_frequency / unit.frequency()) == 0) { + unit.update(); + } + } +} + +void Emu::addProcessingUnit(ProcessingUnit processing_unit) { + m_processing_units.push_back(processing_unit); +} + +void Emu::addMemorySpace(const char* name, int size) { + std::vector memory; + memory.reserve(size); + m_memory_spaces.emplace(name, memory); +} \ No newline at end of file diff --git a/src/emu.h b/src/emu.h index 799c5a5..b20b0c8 100644 --- a/src/emu.h +++ b/src/emu.h @@ -2,6 +2,7 @@ #include #include +#include #include "processing-unit.h" #include "ruc/singleton.h" @@ -10,21 +11,23 @@ class Emu final : public ruc::Singleton { public: Emu(s) {} - void WriteRAM(int location, int length); - void WriteVRAM(int location, int length); - void WriteROM(int location, int length); + void update(); - void ReadRAM(int location, int length); - void ReadVRAM(int location, int length); - void ReadROM(int location, int length); + void addProcessingUnit(ProcessingUnit processing_unit); + void addMemorySpace(const char* name, int size); + + void writeRAM(const char* memory_space, int location); + void writeVRAM(const char* memory_space, int location); + void writeROM(const char* memory_space, int location); + + uint8_t readRAM(const char* memory_space, int location); + uint8_t readVRAM(const char* memory_space, int location); + uint8_t readROM(const char* memory_space, int location); private: float m_frequency; int m_cycle = 0; - uint8_t m_ram[1024]; - uint8_t m_vram[1024]; - uint8_t m_rom[1024]; - std::vector m_processing_units; + std::unordered_map> m_memory_spaces; }; diff --git a/src/processing-unit.cpp b/src/processing-unit.cpp index 851c7b8..4026a82 100644 --- a/src/processing-unit.cpp +++ b/src/processing-unit.cpp @@ -5,12 +5,16 @@ * SPDX-License-Identifier: MIT */ -#include "processingunit.h" +#include "processing-unit.h" -ProcessingUnit::ProcessingUnit() +ProcessingUnit::ProcessingUnit(float frequency) : m_frequency(frequency) { } ProcessingUnit::~ProcessingUnit() { } + +float ProcessingUnit::frequency() { + return m_frequency; +} \ No newline at end of file diff --git a/src/processing-unit.h b/src/processing-unit.h index d43d5dd..97d6c11 100644 --- a/src/processing-unit.h +++ b/src/processing-unit.h @@ -9,6 +9,13 @@ class ProcessingUnit { public: - ProcessingUnit(); + ProcessingUnit(float frequency); virtual ~ProcessingUnit(); + + virtual void update(); + + float frequency(); + +private: +float m_frequency; };