diff --git a/external/unarr b/external/unarr index 569ffdb0..c5f94235 160000 --- a/external/unarr +++ b/external/unarr @@ -1 +1 @@ -Subproject commit 569ffdb063ce8a76ab069444af175e5953d90c93 +Subproject commit c5f9423568ac047aed9aebe2b1e404961ef7d2b3 diff --git a/src/backend/Core.cpp b/src/backend/Core.cpp index 6a6bd509..2a44ebb5 100644 --- a/src/backend/Core.cpp +++ b/src/backend/Core.cpp @@ -2,46 +2,49 @@ #include namespace n64 { -Core::Core() : cpu{new Interpreter} { +Core::Core() { if(SDL_GameControllerAddMappingsFromFile("resources/gamecontrollerdb.txt") < 0) { Util::warn("Failed to load game controller DB"); } } void Core::Stop() { - cpu->Reset(); - cpu->mem.Reset(); + cpu.Reset(); + cpu.mem.Reset(); pause = true; romLoaded = false; } void Core::LoadROM(const std::string& rom_) { rom = rom_; - cpu->Reset(); + cpu.Reset(); pause = false; romLoaded = true; auto extension = fs::path(rom).extension().string(); + bool isArchive = false; + for(const auto i : ARCHIVE_TYPES) { + if(extension == i) { + isArchive = true; + break; + } + } - bool isArchive = std::any_of(std::begin(ARCHIVE_TYPES), std::end(ARCHIVE_TYPES), [&](auto i) { - return extension == i; - }); - - cpu->mem.LoadROM(isArchive, rom); - GameDB::match(cpu->mem); - cpu->mem.mmio.vi.isPal = cpu->mem.IsROMPAL(); - cpu->mem.mmio.si.pif.InitDevices(cpu->mem.saveType); - cpu->mem.mmio.si.pif.LoadMempak(rom); - cpu->mem.mmio.si.pif.LoadEeprom(cpu->mem.saveType, rom); - cpu->mem.flash.Load(cpu->mem.saveType, rom); - cpu->mem.LoadSRAM(cpu->mem.saveType, rom); - PIF::ExecutePIF(cpu->mem, cpu->regs); + cpu.mem.LoadROM(isArchive, rom); + GameDB::match(cpu.mem); + cpu.mem.mmio.vi.isPal = cpu.mem.IsROMPAL(); + cpu.mem.mmio.si.pif.InitDevices(cpu.mem.saveType); + cpu.mem.mmio.si.pif.LoadMempak(rom); + cpu.mem.mmio.si.pif.LoadEeprom(cpu.mem.saveType, rom); + cpu.mem.flash.Load(cpu.mem.saveType, rom); + cpu.mem.LoadSRAM(cpu.mem.saveType, rom); + PIF::ExecutePIF(cpu.mem, cpu.regs); } void Core::Run(float volumeL, float volumeR) { - Mem& mem = cpu->mem; + Mem& mem = cpu.mem; MMIO& mmio = mem.mmio; - Registers& regs = cpu->regs; + Registers& regs = cpu.regs; for (int field = 0; field < mmio.vi.numFields; field++) { int frameCycles = 0; @@ -53,7 +56,7 @@ void Core::Run(float volumeL, float volumeR) { } for(; cycles < mem.mmio.vi.cyclesPerHalfline; cycles++, frameCycles++) { - int taken = cpu->Step(); + int taken = cpu.Step(); static int cpuSteps = 0; cpuSteps += taken; if(mmio.rsp.spStatus.halt) { @@ -83,7 +86,7 @@ void Core::Run(float volumeL, float volumeR) { InterruptRaise(mmio.mi, regs, Interrupt::VI); } - mmio.ai.Step(cpu->mem, regs, frameCycles, volumeL, volumeR); + mmio.ai.Step(cpu.mem, regs, frameCycles, volumeL, volumeR); scheduler.tick(frameCycles, mem, regs); } } diff --git a/src/backend/Core.hpp b/src/backend/Core.hpp index 83955f6a..099a41eb 100644 --- a/src/backend/Core.hpp +++ b/src/backend/Core.hpp @@ -8,13 +8,13 @@ struct Window; namespace n64 { struct Core { - ~Core() { Stop(); delete cpu; } + ~Core() { Stop(); } Core(); void Stop(); void LoadROM(const std::string&); void Run(float volumeL, float volumeR); void TogglePause() { pause = !pause; } - [[nodiscard]] VI& GetVI() const { return cpu->mem.mmio.vi; } + [[nodiscard]] VI& GetVI() { return cpu.mem.mmio.vi; } u32 breakpoint = 0; @@ -22,6 +22,6 @@ struct Core { int cycles = 0; bool romLoaded = false; std::string rom; - Interpreter* cpu = nullptr; + Interpreter cpu; }; } diff --git a/src/frontend/App.cpp b/src/frontend/App.cpp index 46464e0a..b3f1959d 100644 --- a/src/frontend/App.cpp +++ b/src/frontend/App.cpp @@ -9,7 +9,7 @@ App::App() : window(core) { void App::Run() { SDL_EventState(SDL_DROPFILE, SDL_ENABLE); - n64::SI& si = core.cpu->mem.mmio.si; + n64::SI& si = core.cpu.mem.mmio.si; while (!window.done) { if(core.romLoaded) { diff --git a/src/frontend/imgui/Window.cpp b/src/frontend/imgui/Window.cpp index f101327a..5814b08f 100644 --- a/src/frontend/imgui/Window.cpp +++ b/src/frontend/imgui/Window.cpp @@ -11,7 +11,7 @@ namespace fs = std::filesystem; Window::Window(n64::Core& core) : settings() { InitSDL(); - InitParallelRDP(core.cpu->mem.GetRDRAM(), window); + InitParallelRDP(core.cpu.mem.GetRDRAM(), window); InitImgui(); NFD::Init(); } @@ -152,7 +152,7 @@ ImDrawData* Window::Present(n64::Core& core) { void Window::LoadROM(n64::Core& core, const std::string &path) { if(!path.empty()) { core.LoadROM(path); - gameName = core.cpu->mem.rom.gameNameDB; + gameName = core.cpu.mem.rom.gameNameDB; if(gameName.empty()) { gameName = fs::path(path).stem().string(); @@ -181,13 +181,13 @@ void Window::RenderMainMenuBar(n64::Core &core) { } } if (ImGui::MenuItem("Dump RDRAM")) { - core.cpu->mem.DumpRDRAM(); + core.cpu.mem.DumpRDRAM(); } if (ImGui::MenuItem("Dump IMEM")) { - core.cpu->mem.DumpIMEM(); + core.cpu.mem.DumpIMEM(); } if (ImGui::MenuItem("Dump DMEM")) { - core.cpu->mem.DumpDMEM(); + core.cpu.mem.DumpDMEM(); } if (ImGui::MenuItem("Exit")) { done = true; @@ -232,8 +232,8 @@ void Window::Render(n64::Core& core) { static u32 lastFrame = 0; if(!core.pause && lastFrame < ticks - 1000) { lastFrame = ticks; - windowTitle += fmt::format(" | {:02d} VI/s", core.cpu->mem.mmio.vi.swaps); - core.cpu->mem.mmio.vi.swaps = 0; + windowTitle += fmt::format(" | {:02d} VI/s", core.cpu.mem.mmio.vi.swaps); + core.cpu.mem.mmio.vi.swaps = 0; SDL_SetWindowTitle(window, windowTitle.c_str()); windowTitle = shadowWindowTitle; } diff --git a/src/main.cpp b/src/main.cpp index e58e1a29..1881fd42 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,16 +2,18 @@ #include int main(int argc, char** argv) { - App app; + App* app = new App; if(argc > 1) { if(argc > 2) { LoadTAS(argv[2]); } - app.LoadROM(argv[1]); + app->LoadROM(argv[1]); } - app.Run(); + app->Run(); + + delete app; return 0; } \ No newline at end of file