Emu: Add functionality to add Memory and PUs
This commit is contained in:
+19
@@ -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<uint8_t> memory;
|
||||
memory.reserve(size);
|
||||
m_memory_spaces.emplace(name, memory);
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "processing-unit.h"
|
||||
#include "ruc/singleton.h"
|
||||
@@ -10,21 +11,23 @@ class Emu final : public ruc::Singleton<Emu> {
|
||||
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<ProcessingUnit> m_processing_units;
|
||||
std::unordered_map<const char*, std::vector<uint8_t>> m_memory_spaces;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -9,6 +9,13 @@
|
||||
|
||||
class ProcessingUnit {
|
||||
public:
|
||||
ProcessingUnit();
|
||||
ProcessingUnit(float frequency);
|
||||
virtual ~ProcessingUnit();
|
||||
|
||||
virtual void update();
|
||||
|
||||
float frequency();
|
||||
|
||||
private:
|
||||
float m_frequency;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user