fix more shit

now it doesn't shit itself on startup if the BIOS paths are wrong
This commit is contained in:
Arisotura 2024-10-24 17:20:14 +02:00
parent 13b4cea171
commit 1787235e09
5 changed files with 89 additions and 66 deletions

View File

@ -154,6 +154,13 @@ EmuInstance::~EmuInstance()
audioDeInit(); audioDeInit();
inputDeInit(); inputDeInit();
NDS::Current = nullptr;
if (nds)
{
saveRTCData();
delete nds;
}
} }
@ -1105,6 +1112,30 @@ void EmuInstance::setBatteryLevels()
} }
} }
void EmuInstance::loadRTCData()
{
auto file = Platform::OpenLocalFile("rtc.bin", Platform::FileMode::Read);
if (file)
{
RTC::StateData state;
Platform::FileRead(&state, sizeof(state), 1, file);
Platform::CloseFile(file);
nds->RTC.SetState(state);
}
}
void EmuInstance::saveRTCData()
{
auto file = Platform::OpenLocalFile("rtc.bin", Platform::FileMode::Write);
if (file)
{
RTC::StateData state;
nds->RTC.GetState(state);
Platform::FileWrite(&state, sizeof(state), 1, file);
Platform::CloseFile(file);
}
}
void EmuInstance::setDateTime() void EmuInstance::setDateTime()
{ {
QDateTime hosttime = QDateTime::currentDateTime(); QDateTime hosttime = QDateTime::currentDateTime();
@ -1238,7 +1269,11 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGB
if ((!nds) || (consoleType != nds->ConsoleType)) if ((!nds) || (consoleType != nds->ConsoleType))
{ {
NDS::Current = nullptr; NDS::Current = nullptr;
if (nds) delete nds; if (nds)
{
saveRTCData();
delete nds;
}
if (consoleType == 1) if (consoleType == 1)
nds = new DSi(std::move(dsiargs.value()), this); nds = new DSi(std::move(dsiargs.value()), this);
@ -1247,6 +1282,7 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGB
NDS::Current = nds; NDS::Current = nds;
nds->Reset(); nds->Reset();
loadRTCData();
//emuThread->updateVideoRenderer(); // not actually needed? //emuThread->updateVideoRenderer(); // not actually needed?
} }
else else

View File

@ -168,7 +168,6 @@ private:
std::optional<melonDS::FATStorageArgs> getSDCardArgs(const std::string& key) noexcept; std::optional<melonDS::FATStorageArgs> getSDCardArgs(const std::string& key) noexcept;
std::optional<melonDS::FATStorage> loadSDCard(const std::string& key) noexcept; std::optional<melonDS::FATStorage> loadSDCard(const std::string& key) noexcept;
void setBatteryLevels(); void setBatteryLevels();
void setDateTime();
void reset(); void reset();
bool bootToMenu(); bool bootToMenu();
melonDS::u32 decompressROM(const melonDS::u8* inContent, const melonDS::u32 inSize, std::unique_ptr<melonDS::u8[]>& outContent); melonDS::u32 decompressROM(const melonDS::u8* inContent, const melonDS::u32 inSize, std::unique_ptr<melonDS::u8[]>& outContent);
@ -223,6 +222,10 @@ private:
bool hotkeyPressed(int id) { return hotkeyPress & (1<<id); } bool hotkeyPressed(int id) { return hotkeyPress & (1<<id); }
bool hotkeyReleased(int id) { return hotkeyRelease & (1<<id); } bool hotkeyReleased(int id) { return hotkeyRelease & (1<<id); }
void loadRTCData();
void saveRTCData();
void setDateTime();
bool deleting; bool deleting;
int instanceID; int instanceID;

View File

@ -102,9 +102,8 @@ void EmuThread::run()
{ {
Config::Table& globalCfg = emuInstance->getGlobalConfig(); Config::Table& globalCfg = emuInstance->getGlobalConfig();
u32 mainScreenPos[3]; u32 mainScreenPos[3];
Platform::FileHandle* file;
emuInstance->updateConsole(nullptr, nullptr); //emuInstance->updateConsole(nullptr, nullptr);
// No carts are inserted when melonDS first boots // No carts are inserted when melonDS first boots
mainScreenPos[0] = 0; mainScreenPos[0] = 0;
@ -112,7 +111,7 @@ void EmuThread::run()
mainScreenPos[2] = 0; mainScreenPos[2] = 0;
autoScreenSizing = 0; autoScreenSizing = 0;
videoSettingsDirty = false; //videoSettingsDirty = false;
if (emuInstance->usesOpenGL()) if (emuInstance->usesOpenGL())
{ {
@ -127,7 +126,8 @@ void EmuThread::run()
videoRenderer = 0; videoRenderer = 0;
} }
updateRenderer(); //updateRenderer();
videoSettingsDirty = true;
u32 nframes = 0; u32 nframes = 0;
double perfCountsSec = 1.0 / SDL_GetPerformanceFrequency(); double perfCountsSec = 1.0 / SDL_GetPerformanceFrequency();
@ -138,15 +138,6 @@ void EmuThread::run()
u32 winUpdateCount = 0, winUpdateFreq = 1; u32 winUpdateCount = 0, winUpdateFreq = 1;
u8 dsiVolumeLevel = 0x1F; u8 dsiVolumeLevel = 0x1F;
file = Platform::OpenLocalFile("rtc.bin", Platform::FileMode::Read);
if (file)
{
RTC::StateData state;
Platform::FileRead(&state, sizeof(state), 1, file);
Platform::CloseFile(file);
emuInstance->nds->RTC.SetState(state);
}
char melontitle[100]; char melontitle[100];
bool fastforward = false; bool fastforward = false;
@ -453,17 +444,6 @@ void EmuThread::run()
handleMessages(); handleMessages();
} }
file = Platform::OpenLocalFile("rtc.bin", Platform::FileMode::Write);
if (file)
{
RTC::StateData state;
emuInstance->nds->RTC.GetState(state);
Platform::FileWrite(&state, sizeof(state), 1, file);
Platform::CloseFile(file);
}
NDS::Current = nullptr;
} }
void EmuThread::sendMessage(Message msg) void EmuThread::sendMessage(Message msg)

View File

@ -947,9 +947,6 @@ void ScreenPanelGL::drawScreenGL()
{ {
if (!glContext) return; if (!glContext) return;
auto nds = emuInstance->getNDS();
if (!nds) return;
auto emuThread = emuInstance->getEmuThread(); auto emuThread = emuInstance->getEmuThread();
glContext->MakeCurrent(); glContext->MakeCurrent();
@ -968,6 +965,10 @@ void ScreenPanelGL::drawScreenGL()
glViewport(0, 0, w, h); glViewport(0, 0, w, h);
if (emuThread->emuIsActive())
{
auto nds = emuInstance->getNDS();
glUseProgram(screenShaderProgram); glUseProgram(screenShaderProgram);
glUniform2f(screenShaderScreenSizeULoc, w / factor, h / factor); glUniform2f(screenShaderScreenSizeULoc, w / factor, h / factor);
@ -979,8 +980,7 @@ void ScreenPanelGL::drawScreenGL()
{ {
// hardware-accelerated render // hardware-accelerated render
nds->GPU.GetRenderer3D().BindOutputTexture(frontbuf); nds->GPU.GetRenderer3D().BindOutputTexture(frontbuf);
} } else
else
#endif #endif
{ {
// regular render // regular render
@ -1011,6 +1011,7 @@ void ScreenPanelGL::drawScreenGL()
} }
screenSettingsLock.unlock(); screenSettingsLock.unlock();
}
osdUpdate(); osdUpdate();
if (osdEnabled) if (osdEnabled)

View File

@ -1009,6 +1009,9 @@ bool MainWindow::verifySetup()
bool MainWindow::preloadROMs(QStringList file, QStringList gbafile, bool boot) bool MainWindow::preloadROMs(QStringList file, QStringList gbafile, bool boot)
{ {
if (file.isEmpty() && gbafile.isEmpty())
return false;
if (!verifySetup()) if (!verifySetup())
{ {
return false; return false;