Emulator+Test: Store ProcessingUnits as std::shared_ptr
This commit is contained in:
+1
-1
@@ -39,7 +39,7 @@ void Emu::update()
|
||||
}
|
||||
}
|
||||
|
||||
void Emu::addProcessingUnit(std::string_view name, ProcessingUnit* processing_unit)
|
||||
void Emu::addProcessingUnit(std::string_view name, std::shared_ptr<ProcessingUnit> processing_unit)
|
||||
{
|
||||
m_processing_units.emplace(name, processing_unit);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint> // uint32_t
|
||||
#include <memory> // std::shared_ptr
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
@@ -34,7 +35,7 @@ public:
|
||||
|
||||
void update();
|
||||
|
||||
void addProcessingUnit(std::string_view name, ProcessingUnit* processing_unit);
|
||||
void addProcessingUnit(std::string_view name, std::shared_ptr<ProcessingUnit> processing_unit);
|
||||
void addMemorySpace(std::string_view name, uint32_t start_address, uint32_t end_address, uint32_t amount_of_banks = 1);
|
||||
void removeMemorySpace(std::string_view name);
|
||||
|
||||
@@ -43,7 +44,7 @@ public:
|
||||
|
||||
// -------------------------------------
|
||||
|
||||
ProcessingUnit* processingUnit(std::string_view name) const { return m_processing_units.at(name); }
|
||||
std::shared_ptr<ProcessingUnit> processingUnit(std::string_view name) const { return m_processing_units.at(name); }
|
||||
MemorySpace memorySpace(std::string_view name) { return m_memory_spaces[name]; }
|
||||
|
||||
private:
|
||||
@@ -55,6 +56,6 @@ private:
|
||||
|
||||
ruc::Timer m_timer;
|
||||
|
||||
std::unordered_map<std::string_view, ProcessingUnit*> m_processing_units;
|
||||
std::unordered_map<std::string_view, std::shared_ptr<ProcessingUnit>> m_processing_units;
|
||||
std::unordered_map<std::string_view, MemorySpace> m_memory_spaces;
|
||||
};
|
||||
|
||||
+5
-4
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <cstddef> // size_t
|
||||
#include <cstdint> // uint32_t
|
||||
#include <memory> // std::make_shared
|
||||
|
||||
#include "cpu.h"
|
||||
#include "emu.h"
|
||||
@@ -44,11 +45,11 @@ void Loader::init()
|
||||
|
||||
Emu::the().init(8000000);
|
||||
|
||||
CPU cpu(8000000);
|
||||
PPU ppu(4000000);
|
||||
auto cpu = std::make_shared<CPU>(8000000);
|
||||
auto ppu = std::make_shared<PPU>(4000000);
|
||||
|
||||
Emu::the().addProcessingUnit("cpu", &cpu);
|
||||
Emu::the().addProcessingUnit("ppu", &ppu);
|
||||
Emu::the().addProcessingUnit("CPU", cpu);
|
||||
Emu::the().addProcessingUnit("PPU", ppu);
|
||||
|
||||
// https://gbdev.io/pandocs/Memory_Map.html
|
||||
// https://gbdev.io/pandocs/Power_Up_Sequence.html
|
||||
|
||||
Reference in New Issue
Block a user