From d10b5f8b8ab85f53e150ca47f52a99b1d26236be Mon Sep 17 00:00:00 2001 From: Arisotura Date: Wed, 15 May 2024 01:00:41 +0200 Subject: [PATCH] more work feuhqdskfqejlmdsjjjvwdccccccccccccccccccccccccccccccccccc --- src/DSi.cpp | 20 ++ src/DSi.h | 1 + src/frontend/qt_sdl/EmuInstance.cpp | 277 +++++++++++----------------- 3 files changed, 129 insertions(+), 169 deletions(-) diff --git a/src/DSi.cpp b/src/DSi.cpp index c929c6d2..4d0be81d 100644 --- a/src/DSi.cpp +++ b/src/DSi.cpp @@ -70,6 +70,26 @@ const u32 NDMAModes[] = 0xFF, // wifi / GBA cart slot (TODO) }; +/*DSi::DSi() noexcept : + DSi( + DSiArgs { + NDSArgs { + nullptr, + nullptr, + bios_arm9_bin, + bios_arm7_bin, + Firmware(0), + }, + nullptr, + nullptr, + nullptr, + nullptr, + false + } + ) +{ +}*/ + DSi::DSi(DSiArgs&& args) noexcept : NDS(std::move(args), 1), NDMAs { diff --git a/src/DSi.h b/src/DSi.h index 1d010e0f..6590ca60 100644 --- a/src/DSi.h +++ b/src/DSi.h @@ -131,6 +131,7 @@ public: public: DSi(DSiArgs&& args) noexcept; + //DSi() noexcept; ~DSi() noexcept override; DSi(const DSi&) = delete; DSi& operator=(const DSi&) = delete; diff --git a/src/frontend/qt_sdl/EmuInstance.cpp b/src/frontend/qt_sdl/EmuInstance.cpp index b1a44499..a5949ac6 100644 --- a/src/frontend/qt_sdl/EmuInstance.cpp +++ b/src/frontend/qt_sdl/EmuInstance.cpp @@ -899,107 +899,20 @@ void EmuInstance::setDateTime() time.time().hour(), time.time().minute(), time.time().second()); } -/*std::unique_ptr EmuInstance::createConsole( - std::unique_ptr&& ndscart, - std::unique_ptr&& gbacart -) noexcept -{ - auto arm7bios = ROMManager::LoadARM7BIOS(); - if (!arm7bios) - return nullptr; - - auto arm9bios = ROMManager::LoadARM9BIOS(); - if (!arm9bios) - return nullptr; - - auto firmware = ROMManager::LoadFirmware(Config::ConsoleType); - if (!firmware) - return nullptr; - -#ifdef JIT_ENABLED - JITArgs jitargs { - static_cast(Config::JIT_MaxBlockSize), - Config::JIT_LiteralOptimisations, - Config::JIT_BranchOptimisations, - Config::JIT_FastMemory, - }; -#endif - -#ifdef GDBSTUB_ENABLED - GDBArgs gdbargs { - static_cast(Config::GdbPortARM7), - static_cast(Config::GdbPortARM9), - Config::GdbARM7BreakOnStartup, - Config::GdbARM9BreakOnStartup, - }; -#endif - - NDSArgs ndsargs { - std::move(ndscart), - std::move(gbacart), - *arm9bios, - *arm7bios, - std::move(*firmware), -#ifdef JIT_ENABLED - Config::JIT_Enable ? std::make_optional(jitargs) : std::nullopt, -#else - std::nullopt, -#endif - static_cast(Config::AudioBitDepth), - static_cast(Config::AudioInterp), -#ifdef GDBSTUB_ENABLED - Config::GdbEnabled ? std::make_optional(gdbargs) : std::nullopt, -#else - std::nullopt, -#endif - }; - - if (Config::ConsoleType == 1) - { - auto arm7ibios = ROMManager::LoadDSiARM7BIOS(); - if (!arm7ibios) - return nullptr; - - auto arm9ibios = ROMManager::LoadDSiARM9BIOS(); - if (!arm9ibios) - return nullptr; - - auto nand = ROMManager::LoadNAND(*arm7ibios); - if (!nand) - return nullptr; - - auto sdcard = ROMManager::LoadDSiSDCard(); - DSiArgs args { - std::move(ndsargs), - *arm9ibios, - *arm7ibios, - std::move(*nand), - std::move(sdcard), - Config::DSiFullBIOSBoot, - }; - - args.GBAROM = nullptr; - - return std::make_unique(std::move(args)); - } - - return std::make_unique(std::move(ndsargs)); -}*/ - -bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& ndsargs, UpdateConsoleGBAArgs&& gbaargs) noexcept +bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGBAArgs&& _gbaargs) noexcept { // Let's get the cart we want to use; // if we wnat to keep the cart, we'll eject it from the existing console first. std::unique_ptr nextndscart; - if (std::holds_alternative(ndsargs)) + if (std::holds_alternative(_ndsargs)) { // If we want to keep the existing cart (if any)... nextndscart = nds ? nds->EjectCart() : nullptr; - ndsargs = {}; + _ndsargs = {}; } - else if (const auto ptr = std::get_if>(&ndsargs)) + else if (const auto ptr = std::get_if>(&_ndsargs)) { nextndscart = std::move(*ptr); - ndsargs = {}; + _ndsargs = {}; } if (auto* cartsd = dynamic_cast(nextndscart.get())) @@ -1010,49 +923,19 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& ndsargs, UpdateConsoleGBA } std::unique_ptr nextgbacart; - if (std::holds_alternative(gbaargs)) + if (std::holds_alternative(_gbaargs)) { nextgbacart = nds ? nds->EjectGBACart() : nullptr; } - else if (const auto ptr = std::get_if>(&gbaargs)) + else if (const auto ptr = std::get_if>(&_gbaargs)) { nextgbacart = std::move(*ptr); - gbaargs = {}; + _gbaargs = {}; } + int consoletype = globalCfg.GetInt("Emu.ConsoleType"); - if (!nds || nds->ConsoleType != consoletype) - { // If we're switching between DS and DSi mode, or there's no console... - // To ensure the destructor is called before a new one is created, - // as the presence of global signal handlers still complicates things a bit - /*NDS = nullptr; - NDS::Current = nullptr; - - NDS = CreateConsole(std::move(nextndscart), std::move(nextgbacart)); - - if (NDS == nullptr) - return false; - - NDS->Reset(); - NDS::Current = NDS.get(); - - return true;*/ - - delete nds; - - if (consoletype == 1) - { - nds = new DSi(); - } - else if (consoletype == 0) - { - nds = new NDS(); - } - - nds->Reset(); - } - auto arm9bios = loadARM9BIOS(); if (!arm9bios) return false; @@ -1065,60 +948,116 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& ndsargs, UpdateConsoleGBA if (!firmware) return false; - if (consoletype == 1) - { // If the console we're updating is a DSi... - DSi* dsi = static_cast(nds); - - auto arm9ibios = loadDSiARM9BIOS(); - if (!arm9ibios) - return false; - - auto arm7ibios = loadDSiARM7BIOS(); - if (!arm7ibios) - return false; - - auto nandimage = loadNAND(*arm7ibios); - if (!nandimage) - return false; - - auto dsisdcard = loadSDCard("DSi.SD"); - - dsi->SetFullBIOSBoot(globalCfg.GetBool("DSi.FullBIOSBoot")); - dsi->ARM7iBIOS = *arm7ibios; - dsi->ARM9iBIOS = *arm9ibios; - dsi->SetNAND(std::move(*nandimage)); - dsi->SetSDCard(std::move(dsisdcard)); - // We're moving the optional, not the card - // (inserting std::nullopt here is okay, it means no card) - - dsi->EjectGBACart(); - } - else if (consoletype == 0) - { - nds->SetGBACart(std::move(nextgbacart)); - } - #ifdef JIT_ENABLED Config::Table jitopt = globalCfg.GetTable("JIT"); - JITArgs jitargs { + JITArgs _jitargs { static_cast(jitopt.GetInt("MaxBlockSize")), jitopt.GetBool("LiteralOptimisations"), jitopt.GetBool("BranchOptimisations"), jitopt.GetBool("FastMemory"), }; - nds->SetJITArgs(jitopt.GetBool("Enable") ? std::make_optional(jitargs) : std::nullopt); + auto jitargs = jitopt.GetBool("Enable") ? std::make_optional(_jitargs) : std::nullopt; +#else + optional jitargs = std::nullopt; #endif - // TODO GDB stub shit +#ifdef GDBSTUB_ENABLED + Config::Table gdbopt = globalCfg.GetTable("Gdb"); + GDBArgs _gdbargs { + static_cast(gdbopt.GetInt("ARM7.Port")), + static_cast(gdbopt.GetInt("ARM9.Port")), + gdbopt.GetBool("ARM7.BreakOnStartup"), + gdbopt.GetBool("ARM9.BreakOnStartup"), + }; + auto gdbargs = gdbopt.GetBool("Enable") ? std::make_optional(_gdbargs) : std::nullopt; +#else + optional gdbargs = std::nullopt; +#endif - nds->SetARM7BIOS(*arm7bios); - nds->SetARM9BIOS(*arm9bios); - nds->SetFirmware(std::move(*firmware)); - nds->SetNDSCart(std::move(nextndscart)); - nds->SPU.SetInterpolation(static_cast(Config::AudioInterp)); - nds->SPU.SetDegrade10Bit(static_cast(Config::AudioBitDepth)); + NDSArgs ndsargs { + std::move(nextndscart), + std::move(nextgbacart), + *arm9bios, + *arm7bios, + std::move(*firmware), + jitargs, + static_cast(Config::AudioBitDepth), + static_cast(Config::AudioInterp), + gdbargs, + }; - NDS::Current = nds; // REMOVEME + std::optional dsiargs = std::nullopt; + if (consoletype == 1) + { + ndsargs.GBAROM = nullptr; + + auto arm7ibios = loadDSiARM7BIOS(); + if (!arm7ibios) + return false; + + auto arm9ibios = loadDSiARM9BIOS(); + if (!arm9ibios) + return false; + + auto nand = loadNAND(*arm7ibios); + if (!nand) + return false; + + auto sdcard = loadSDCard("DSi.SD"); + + DSiArgs args { + std::move(ndsargs), + *arm9ibios, + *arm7ibios, + std::move(*nand), + std::move(sdcard), + globalCfg.GetBool("DSi.FullBIOSBoot"), + }; + + dsiargs = std::move(args); + } + + + if (consoletype != nds->ConsoleType) + { + NDS::Current = nullptr; + delete nds; + + if (consoletype == 1) + nds = new DSi(std::move(dsiargs.value())); + else + nds = new NDS(std::move(ndsargs)); + + NDS::Current = nds; + nds->Reset(); + } + else + { + nds->SetARM7BIOS(ndsargs.ARM7BIOS); + nds->SetARM9BIOS(ndsargs.ARM9BIOS); + nds->SetFirmware(std::move(ndsargs.Firmware)); + nds->SetNDSCart(std::move(ndsargs.NDSROM)); + nds->SetJITArgs(ndsargs.JIT); + // TODO GDB stub shit + nds->SPU.SetInterpolation(ndsargs.Interpolation); + nds->SPU.SetDegrade10Bit(ndsargs.BitDepth); + + if (consoletype == 1) + { + DSi* dsi = (DSi*)nds; + DSiArgs& args = dsiargs.value(); + + dsi->SetFullBIOSBoot(args.FullBIOSBoot); + dsi->ARM7iBIOS = args.ARM7iBIOS; + dsi->ARM9iBIOS = args.ARM9iBIOS; + dsi->SetNAND(std::move(args.NANDImage)); + dsi->SetSDCard(std::move(args.DSiSDCard)); + // We're moving the optional, not the card + // (inserting std::nullopt here is okay, it means no card) + + dsi->EjectGBACart(); + } + } return true; }