Skip to content

Commit

Permalink
fix more shit
Browse files Browse the repository at this point in the history
now it doesn't shit itself on startup if the BIOS paths are wrong
  • Loading branch information
Arisotura committed Oct 24, 2024
1 parent 13b4cea commit 1787235
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 61 deletions.
38 changes: 37 additions & 1 deletion src/frontend/qt_sdl/EmuInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ EmuInstance::~EmuInstance()

audioDeInit();
inputDeInit();

NDS::Current = nullptr;
if (nds)
{
saveRTCData();
delete nds;
}
}


Expand Down Expand Up @@ -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()
{
QDateTime hosttime = QDateTime::currentDateTime();
Expand Down Expand Up @@ -1238,7 +1269,11 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGB
if ((!nds) || (consoleType != nds->ConsoleType))
{
NDS::Current = nullptr;
if (nds) delete nds;
if (nds)
{
saveRTCData();
delete nds;
}

if (consoleType == 1)
nds = new DSi(std::move(dsiargs.value()), this);
Expand All @@ -1247,6 +1282,7 @@ bool EmuInstance::updateConsole(UpdateConsoleNDSArgs&& _ndsargs, UpdateConsoleGB

NDS::Current = nds;
nds->Reset();
loadRTCData();
//emuThread->updateVideoRenderer(); // not actually needed?
}
else
Expand Down
5 changes: 4 additions & 1 deletion src/frontend/qt_sdl/EmuInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ class EmuInstance
std::optional<melonDS::FATStorageArgs> getSDCardArgs(const std::string& key) noexcept;
std::optional<melonDS::FATStorage> loadSDCard(const std::string& key) noexcept;
void setBatteryLevels();
void setDateTime();
void reset();
bool bootToMenu();
melonDS::u32 decompressROM(const melonDS::u8* inContent, const melonDS::u32 inSize, std::unique_ptr<melonDS::u8[]>& outContent);
Expand Down Expand Up @@ -223,6 +222,10 @@ class EmuInstance
bool hotkeyPressed(int id) { return hotkeyPress & (1<<id); }
bool hotkeyReleased(int id) { return hotkeyRelease & (1<<id); }

void loadRTCData();
void saveRTCData();
void setDateTime();

bool deleting;

int instanceID;
Expand Down
28 changes: 4 additions & 24 deletions src/frontend/qt_sdl/EmuThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,16 @@ void EmuThread::run()
{
Config::Table& globalCfg = emuInstance->getGlobalConfig();
u32 mainScreenPos[3];
Platform::FileHandle* file;

emuInstance->updateConsole(nullptr, nullptr);
//emuInstance->updateConsole(nullptr, nullptr);
// No carts are inserted when melonDS first boots

mainScreenPos[0] = 0;
mainScreenPos[1] = 0;
mainScreenPos[2] = 0;
autoScreenSizing = 0;

videoSettingsDirty = false;
//videoSettingsDirty = false;

if (emuInstance->usesOpenGL())
{
Expand All @@ -127,7 +126,8 @@ void EmuThread::run()
videoRenderer = 0;
}

updateRenderer();
//updateRenderer();
videoSettingsDirty = true;

u32 nframes = 0;
double perfCountsSec = 1.0 / SDL_GetPerformanceFrequency();
Expand All @@ -138,15 +138,6 @@ void EmuThread::run()
u32 winUpdateCount = 0, winUpdateFreq = 1;
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];

bool fastforward = false;
Expand Down Expand Up @@ -453,17 +444,6 @@ void EmuThread::run()

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)
Expand Down
71 changes: 36 additions & 35 deletions src/frontend/qt_sdl/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,9 +947,6 @@ void ScreenPanelGL::drawScreenGL()
{
if (!glContext) return;

auto nds = emuInstance->getNDS();
if (!nds) return;

auto emuThread = emuInstance->getEmuThread();

glContext->MakeCurrent();
Expand All @@ -968,49 +965,53 @@ void ScreenPanelGL::drawScreenGL()

glViewport(0, 0, w, h);

glUseProgram(screenShaderProgram);
glUniform2f(screenShaderScreenSizeULoc, w / factor, h / factor);
if (emuThread->emuIsActive())
{
auto nds = emuInstance->getNDS();

int frontbuf = emuThread->FrontBuffer;
glActiveTexture(GL_TEXTURE0);
glUseProgram(screenShaderProgram);
glUniform2f(screenShaderScreenSizeULoc, w / factor, h / factor);

int frontbuf = emuThread->FrontBuffer;
glActiveTexture(GL_TEXTURE0);

#ifdef OGLRENDERER_ENABLED
if (nds->GPU.GetRenderer3D().Accelerated)
{
// hardware-accelerated render
nds->GPU.GetRenderer3D().BindOutputTexture(frontbuf);
}
else
if (nds->GPU.GetRenderer3D().Accelerated)
{
// hardware-accelerated render
nds->GPU.GetRenderer3D().BindOutputTexture(frontbuf);
} else
#endif
{
// regular render
glBindTexture(GL_TEXTURE_2D, screenTexture);

if (nds->GPU.Framebuffer[frontbuf][0] && nds->GPU.Framebuffer[frontbuf][1])
{
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 192, GL_RGBA,
GL_UNSIGNED_BYTE, nds->GPU.Framebuffer[frontbuf][0].get());
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192+2, 256, 192, GL_RGBA,
GL_UNSIGNED_BYTE, nds->GPU.Framebuffer[frontbuf][1].get());
// regular render
glBindTexture(GL_TEXTURE_2D, screenTexture);

if (nds->GPU.Framebuffer[frontbuf][0] && nds->GPU.Framebuffer[frontbuf][1])
{
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, 192, GL_RGBA,
GL_UNSIGNED_BYTE, nds->GPU.Framebuffer[frontbuf][0].get());
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192 + 2, 256, 192, GL_RGBA,
GL_UNSIGNED_BYTE, nds->GPU.Framebuffer[frontbuf][1].get());
}
}
}

screenSettingsLock.lock();
screenSettingsLock.lock();

GLint filter = this->filter ? GL_LINEAR : GL_NEAREST;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
GLint filter = this->filter ? GL_LINEAR : GL_NEAREST;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);

glBindBuffer(GL_ARRAY_BUFFER, screenVertexBuffer);
glBindVertexArray(screenVertexArray);
glBindBuffer(GL_ARRAY_BUFFER, screenVertexBuffer);
glBindVertexArray(screenVertexArray);

for (int i = 0; i < numScreens; i++)
{
glUniformMatrix2x3fv(screenShaderTransformULoc, 1, GL_TRUE, screenMatrix[i]);
glDrawArrays(GL_TRIANGLES, screenKind[i] == 0 ? 0 : 2*3, 2*3);
}
for (int i = 0; i < numScreens; i++)
{
glUniformMatrix2x3fv(screenShaderTransformULoc, 1, GL_TRUE, screenMatrix[i]);
glDrawArrays(GL_TRIANGLES, screenKind[i] == 0 ? 0 : 2 * 3, 2 * 3);
}

screenSettingsLock.unlock();
screenSettingsLock.unlock();
}

osdUpdate();
if (osdEnabled)
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/qt_sdl/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,9 @@ bool MainWindow::verifySetup()

bool MainWindow::preloadROMs(QStringList file, QStringList gbafile, bool boot)
{
if (file.isEmpty() && gbafile.isEmpty())
return false;

if (!verifySetup())
{
return false;
Expand Down

0 comments on commit 1787235

Please sign in to comment.