Huge refactor: Make Core a singleton
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
#include <Core.hpp>
|
||||
#include <ParallelRDPWrapper.hpp>
|
||||
#include <Scheduler.hpp>
|
||||
#include <Options.hpp>
|
||||
|
||||
namespace n64 {
|
||||
Core::Core(CPUType cpuType) {
|
||||
switch (cpuType) {
|
||||
case Interpreted: cpu = std::make_unique<Interpreter>(parallel); break;
|
||||
Core::Core() {
|
||||
auto cpuType = Options::GetInstance().GetValue<std::string>("cpu", "type");
|
||||
if (cpuType == "interpreter") {
|
||||
cpu = std::make_unique<Interpreter>(parallel);
|
||||
} else if(cpuType == "jit") {
|
||||
#ifndef __aarch64__
|
||||
case DynamicRecompiler: cpu = std::make_unique<JIT>(parallel); break;
|
||||
cpu = std::make_unique<JIT>(parallel);
|
||||
#else
|
||||
panic("JIT currently unsupported on aarch64");
|
||||
#endif
|
||||
default: panic("Unimplemented CPU type\n");
|
||||
} else {
|
||||
panic("Unimplemented CPU type");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +37,7 @@ void Core::LoadROM(const std::string &rom_) {
|
||||
const bool isArchive = std::ranges::any_of(archive_types, [&extension](const auto &e) { return e == extension; });
|
||||
|
||||
cpu->GetMem().LoadROM(isArchive, rom);
|
||||
GameDB::match(cpu->GetMem());
|
||||
GameDB::match();
|
||||
if (cpu->GetMem().rom.gameNameDB.empty()) {
|
||||
cpu->GetMem().rom.gameNameDB = fs::path(rom).stem().string();
|
||||
}
|
||||
@@ -82,7 +88,7 @@ void Core::Run(float volumeL, float volumeR) {
|
||||
|
||||
cycles += taken;
|
||||
frameCycles += taken;
|
||||
Scheduler::GetInstance().Tick(taken, mem);
|
||||
Scheduler::GetInstance().Tick(taken);
|
||||
}
|
||||
|
||||
cycles -= mmio.vi.cyclesPerHalfline;
|
||||
@@ -93,32 +99,7 @@ void Core::Run(float volumeL, float volumeR) {
|
||||
}
|
||||
|
||||
mmio.ai.Step(frameCycles, volumeL, volumeR);
|
||||
Scheduler::GetInstance().Tick(frameCycles, mem);
|
||||
Scheduler::GetInstance().Tick(frameCycles);
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Serialize() {
|
||||
auto sMEM = cpu->GetMem().Serialize();
|
||||
auto sCPU = cpu->Serialize();
|
||||
auto sVER = std::vector<u8>{KAIZEN_VERSION >> 8, KAIZEN_VERSION >> 4, KAIZEN_VERSION & 0xFF};
|
||||
memSize = sMEM.size();
|
||||
cpuSize = sCPU.size();
|
||||
verSize = sVER.size();
|
||||
serialized[slot].insert(serialized[slot].begin(), sVER.begin(), sVER.end());
|
||||
serialized[slot].insert(serialized[slot].end(), sMEM.begin(), sMEM.end());
|
||||
serialized[slot].insert(serialized[slot].end(), sCPU.begin(), sCPU.end());
|
||||
}
|
||||
|
||||
void Core::Deserialize() {
|
||||
std::vector dVER(serialized[slot].begin(), serialized[slot].begin() + verSize);
|
||||
if (dVER[0] != (KAIZEN_VERSION >> 8) || dVER[1] != (KAIZEN_VERSION >> 4) || dVER[2] != (KAIZEN_VERSION & 0xFF)) {
|
||||
panic("PROBLEMI!");
|
||||
}
|
||||
|
||||
cpu->GetMem().Deserialize(
|
||||
std::vector(serialized[slot].begin() + verSize, serialized[slot].begin() + verSize + memSize));
|
||||
cpu->Deserialize(
|
||||
std::vector(serialized[slot].begin() + verSize + memSize, serialized[slot].begin() + verSize + memSize + cpuSize));
|
||||
serialized[slot].erase(serialized[slot].begin(), serialized[slot].end());
|
||||
}
|
||||
} // namespace n64
|
||||
|
||||
Reference in New Issue
Block a user