From f8d1d08e9c13d39ccb6d0c50ae74e7bbe9ed52c8 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sat, 15 Aug 2020 00:14:05 +0200 Subject: (finally) build the goddamn cheat interface --- src/Config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Config.cpp') diff --git a/src/Config.cpp b/src/Config.cpp index de1c70d..d198093 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -104,7 +104,7 @@ void Load() while (!feof(f)) { fgets(linebuf, 1024, f); - int ret = sscanf(linebuf, "%31[A-Za-z_0-9]=%[^\t\n]", entryname, entryval); + int ret = sscanf(linebuf, "%31[A-Za-z_0-9]=%[^\t\r\n]", entryname, entryval); entryname[31] = '\0'; if (ret < 2) continue; -- cgit v1.2.3 From abccc44eecb943720993c5d3e89234f435770aee Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 24 Aug 2020 19:19:41 +0200 Subject: make MAC randomization optional --- src/Config.cpp | 2 + src/Config.h | 2 + src/SPI.cpp | 25 +++++++------ src/frontend/qt_sdl/WifiSettingsDialog.cpp | 59 ++++++++++++++++++++---------- src/frontend/qt_sdl/WifiSettingsDialog.h | 7 ++-- src/frontend/qt_sdl/WifiSettingsDialog.ui | 12 +++++- src/frontend/qt_sdl/main.cpp | 7 +++- 7 files changed, 77 insertions(+), 37 deletions(-) (limited to 'src/Config.cpp') diff --git a/src/Config.cpp b/src/Config.cpp index d198093..2a98935 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -56,6 +56,8 @@ ConfigEntry ConfigFile[] = {"DSiFirmwarePath", 1, DSiFirmwarePath, 0, "", 1023}, {"DSiNANDPath", 1, DSiNANDPath, 0, "", 1023}, + {"RandomizeMAC", 0, &RandomizeMAC, 0, NULL, 0}, + #ifdef JIT_ENABLED {"JIT_Enable", 0, &JIT_Enable, 0, NULL, 0}, {"JIT_MaxBlockSize", 0, &JIT_MaxBlockSize, 32, NULL, 0}, diff --git a/src/Config.h b/src/Config.h index 5916b4a..a0f09dc 100644 --- a/src/Config.h +++ b/src/Config.h @@ -51,6 +51,8 @@ extern char DSiBIOS7Path[1024]; extern char DSiFirmwarePath[1024]; extern char DSiNANDPath[1024]; +extern int RandomizeMAC; + #ifdef JIT_ENABLED extern int JIT_Enable; extern int JIT_MaxBlockSize; diff --git a/src/SPI.cpp b/src/SPI.cpp index 1c88b58..2ba5e66 100644 --- a/src/SPI.cpp +++ b/src/SPI.cpp @@ -179,24 +179,25 @@ void Reset() //Firmware[userdata+0x64] &= 0xBF; *(u16*)&Firmware[userdata+0x72] = CRC16(&Firmware[userdata], 0x70, 0xFFFF); + + if (Config::RandomizeMAC) + { + // replace MAC address with random address + Firmware[0x36] = 0x00; + Firmware[0x37] = 0x09; + Firmware[0x38] = 0xBF; + Firmware[0x39] = rand()&0xFF; + Firmware[0x3A] = rand()&0xFF; + Firmware[0x3B] = rand()&0xFF; + + *(u16*)&Firmware[0x2A] = CRC16(&Firmware[0x2C], *(u16*)&Firmware[0x2C], 0x0000); + } } -#if 0 - // replace MAC address with random address - // TODO: make optional? - Firmware[0x36] = 0x00; - Firmware[0x37] = 0x09; - Firmware[0x38] = 0xBF; - Firmware[0x39] = rand()&0xFF; - Firmware[0x3A] = rand()&0xFF; - Firmware[0x3B] = rand()&0xFF; -#endif printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", Firmware[0x36], Firmware[0x37], Firmware[0x38], Firmware[0x39], Firmware[0x3A], Firmware[0x3B]); - //*(u16*)&Firmware[0x2A] = CRC16(&Firmware[0x2C], *(u16*)&Firmware[0x2C], 0x0000); - // verify shit printf("FW: WIFI CRC16 = %s\n", VerifyCRC16(0x0000, 0x2C, *(u16*)&Firmware[0x2C], 0x2A)?"GOOD":"BAD"); printf("FW: AP1 CRC16 = %s\n", VerifyCRC16(0x0000, 0x7FA00&FirmwareMask, 0xFE, 0x7FAFE&FirmwareMask)?"GOOD":"BAD"); diff --git a/src/frontend/qt_sdl/WifiSettingsDialog.cpp b/src/frontend/qt_sdl/WifiSettingsDialog.cpp index 457a78d..67297ad 100644 --- a/src/frontend/qt_sdl/WifiSettingsDialog.cpp +++ b/src/frontend/qt_sdl/WifiSettingsDialog.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include #include "types.h" #include "Platform.h" @@ -41,6 +41,10 @@ WifiSettingsDialog* WifiSettingsDialog::currentDlg = nullptr; +bool WifiSettingsDialog::needsReset = false; + +extern bool RunningSomething; + WifiSettingsDialog::WifiSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::WifiSettingsDialog) { @@ -53,6 +57,7 @@ WifiSettingsDialog::WifiSettingsDialog(QWidget* parent) : QDialog(parent), ui(ne ui->cbDirectMode->setText("Direct mode (requires " PCAP_NAME " and ethernet connection)"); ui->cbBindAnyAddr->setChecked(Config::SocketBindAnyAddr != 0); + ui->cbRandomizeMAC->setChecked(Config::RandomizeMAC != 0); int sel = 0; for (int i = 0; i < LAN_PCap::NumAdapters; i++) @@ -77,33 +82,49 @@ WifiSettingsDialog::~WifiSettingsDialog() delete ui; } -void WifiSettingsDialog::on_WifiSettingsDialog_accepted() +void WifiSettingsDialog::done(int r) { - Config::SocketBindAnyAddr = ui->cbBindAnyAddr->isChecked() ? 1:0; - Config::DirectLAN = ui->cbDirectMode->isChecked() ? 1:0; + needsReset = false; - int sel = ui->cbxDirectAdapter->currentIndex(); - if (sel < 0 || sel >= LAN_PCap::NumAdapters) sel = 0; - if (LAN_PCap::NumAdapters < 1) - { - Config::LANDevice[0] = '\0'; - } - else + if (r == QDialog::Accepted) { - strncpy(Config::LANDevice, LAN_PCap::Adapters[sel].DeviceName, 127); - Config::LANDevice[127] = '\0'; + int randommac = ui->cbRandomizeMAC->isChecked() ? 1:0; + + if (randommac != Config::RandomizeMAC) + { + if (RunningSomething + && QMessageBox::warning(this, "Reset necessary to apply changes", + "The emulation will be reset for the changes to take place.", + QMessageBox::Ok, QMessageBox::Cancel) != QMessageBox::Ok) + return; + } + + Config::SocketBindAnyAddr = ui->cbBindAnyAddr->isChecked() ? 1:0; + Config::RandomizeMAC = randommac; + Config::DirectLAN = ui->cbDirectMode->isChecked() ? 1:0; + + int sel = ui->cbxDirectAdapter->currentIndex(); + if (sel < 0 || sel >= LAN_PCap::NumAdapters) sel = 0; + if (LAN_PCap::NumAdapters < 1) + { + Config::LANDevice[0] = '\0'; + } + else + { + strncpy(Config::LANDevice, LAN_PCap::Adapters[sel].DeviceName, 127); + Config::LANDevice[127] = '\0'; + } + + Config::Save(); + + needsReset = true; } - Config::Save(); + QDialog::done(r); closeDlg(); } -void WifiSettingsDialog::on_WifiSettingsDialog_rejected() -{ - closeDlg(); -} - void WifiSettingsDialog::on_cbDirectMode_stateChanged(int state) { updateAdapterControls(); diff --git a/src/frontend/qt_sdl/WifiSettingsDialog.h b/src/frontend/qt_sdl/WifiSettingsDialog.h index f8aad1b..6c1f863 100644 --- a/src/frontend/qt_sdl/WifiSettingsDialog.h +++ b/src/frontend/qt_sdl/WifiSettingsDialog.h @@ -42,7 +42,7 @@ public: } currentDlg = new WifiSettingsDialog(parent); - currentDlg->show(); + currentDlg->open(); return currentDlg; } static void closeDlg() @@ -50,9 +50,10 @@ public: currentDlg = nullptr; } + static bool needsReset; + private slots: - void on_WifiSettingsDialog_accepted(); - void on_WifiSettingsDialog_rejected(); + void done(int r); void on_cbDirectMode_stateChanged(int state); void on_cbxDirectAdapter_currentIndexChanged(int sel); diff --git a/src/frontend/qt_sdl/WifiSettingsDialog.ui b/src/frontend/qt_sdl/WifiSettingsDialog.ui index bfee1fd..6668d88 100644 --- a/src/frontend/qt_sdl/WifiSettingsDialog.ui +++ b/src/frontend/qt_sdl/WifiSettingsDialog.ui @@ -7,7 +7,7 @@ 0 0 479 - 217 + 240 @@ -39,6 +39,16 @@ + + + + <html><head/><body><p>Randomizes the console's MAC address upon reset. Required for local multiplayer if each melonDS instance uses the same firmware file.</p></body></html> + + + Randomize MAC address + + + diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index f91f879..0228399 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -1747,14 +1747,14 @@ void MainWindow::onAudioSettingsFinished(int res) void MainWindow::onOpenWifiSettings() { + emuThread->emuPause(); + WifiSettingsDialog* dlg = WifiSettingsDialog::openDlg(this); connect(dlg, &WifiSettingsDialog::finished, this, &MainWindow::onWifiSettingsFinished); } void MainWindow::onWifiSettingsFinished(int res) { - emuThread->emuPause(); - if (Wifi::MPInited) { Platform::MP_DeInit(); @@ -1764,6 +1764,9 @@ void MainWindow::onWifiSettingsFinished(int res) Platform::LAN_DeInit(); Platform::LAN_Init(); + if (WifiSettingsDialog::needsReset) + onReset(); + emuThread->emuUnpause(); } -- cgit v1.2.3 From e7025abcdc81f558706204375b753aad77490147 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Mon, 24 Aug 2020 19:32:07 +0200 Subject: * fix build error * make betterer polygon splitting an option * add GL_LEQUAL depth test for 'equal' mode, might help --- src/Config.cpp | 2 ++ src/GPU.h | 1 + src/GPU3D_OpenGL.cpp | 27 +++++++++++++++++++-------- src/frontend/qt_sdl/PlatformConfig.cpp | 4 ++-- src/frontend/qt_sdl/PlatformConfig.h | 2 +- src/frontend/qt_sdl/VideoSettingsDialog.cpp | 7 +++++++ src/frontend/qt_sdl/VideoSettingsDialog.h | 1 + src/frontend/qt_sdl/VideoSettingsDialog.ui | 12 +++++++++++- src/frontend/qt_sdl/main.cpp | 3 +++ 9 files changed, 47 insertions(+), 12 deletions(-) (limited to 'src/Config.cpp') diff --git a/src/Config.cpp b/src/Config.cpp index 2a98935..949c1bf 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -37,6 +37,8 @@ char DSiBIOS7Path[1024]; char DSiFirmwarePath[1024]; char DSiNANDPath[1024]; +int RandomizeMAC; + #ifdef JIT_ENABLED int JIT_Enable = false; int JIT_MaxBlockSize = 32; diff --git a/src/GPU.h b/src/GPU.h index 039e065..c7d25ec 100644 --- a/src/GPU.h +++ b/src/GPU.h @@ -79,6 +79,7 @@ typedef struct bool Soft_Threaded; int GL_ScaleFactor; + bool GL_BetterPolygons; } RenderSettings; diff --git a/src/GPU3D_OpenGL.cpp b/src/GPU3D_OpenGL.cpp index ba77a0c..658b261 100644 --- a/src/GPU3D_OpenGL.cpp +++ b/src/GPU3D_OpenGL.cpp @@ -113,7 +113,7 @@ GLuint TexMemID; GLuint TexPalMemID; int ScaleFactor; -bool Antialias; +bool BetterPolygons; int ScreenW, ScreenH; GLuint FramebufferTex[8]; @@ -405,6 +405,7 @@ void SetRenderSettings(GPU::RenderSettings& settings) int scale = settings.GL_ScaleFactor; ScaleFactor = scale; + BetterPolygons = settings.GL_BetterPolygons; ScreenW = 256 * scale; ScreenH = 192 * scale; @@ -635,7 +636,7 @@ void BuildPolygons(RendererPolygon* polygons, int npolys) { rp->PrimType = GL_TRIANGLES; - if (false) + if (!BetterPolygons) { // regular triangle-splitting @@ -835,6 +836,10 @@ void RenderSceneChunk(int y, int h) GLboolean fogenable = (RenderDispCnt & (1<<7)) ? GL_TRUE : GL_FALSE; + // TODO: proper 'equal' depth test! + // (has margin of +-0x200 in Z-buffer mode, +-0xFF in W-buffer mode) + // for now we're using GL_LEQUAL to make it work to some extent + // pass 1: opaque pixels UseRenderShader(flags); @@ -853,8 +858,10 @@ void RenderSceneChunk(int y, int h) if (rp->PolyData->IsShadowMask) { i++; continue; } - // zorp - glDepthFunc(GL_LESS); + if (rp->PolyData->Attr & (1<<14)) + glDepthFunc(GL_LEQUAL); + else + glDepthFunc(GL_LESS); u32 polyattr = rp->PolyData->Attr; u32 polyid = (polyattr >> 24) & 0x3F; @@ -939,8 +946,10 @@ void RenderSceneChunk(int y, int h) { UseRenderShader(flags | RenderFlag_Trans); - // zorp - glDepthFunc(GL_LESS); + if (rp->PolyData->Attr & (1<<14)) + glDepthFunc(GL_LEQUAL); + else + glDepthFunc(GL_LESS); u32 polyattr = rp->PolyData->Attr; u32 polyid = (polyattr >> 24) & 0x3F; @@ -1030,8 +1039,10 @@ void RenderSceneChunk(int y, int h) if (!(polyattr & (1<<15))) transfog = fogenable; else transfog = GL_FALSE; - // zorp - glDepthFunc(GL_LESS); + if (rp->PolyData->Attr & (1<<14)) + glDepthFunc(GL_LEQUAL); + else + glDepthFunc(GL_LESS); if (rp->PolyData->IsShadow) { diff --git a/src/frontend/qt_sdl/PlatformConfig.cpp b/src/frontend/qt_sdl/PlatformConfig.cpp index 76c5f4b..0628eaa 100644 --- a/src/frontend/qt_sdl/PlatformConfig.cpp +++ b/src/frontend/qt_sdl/PlatformConfig.cpp @@ -51,7 +51,7 @@ int _3DRenderer; int Threaded3D; int GL_ScaleFactor; -int GL_Antialias; +int GL_BetterPolygons; int LimitFPS; int AudioSync; @@ -143,7 +143,7 @@ ConfigEntry PlatformConfigFile[] = {"Threaded3D", 0, &Threaded3D, 1, NULL, 0}, {"GL_ScaleFactor", 0, &GL_ScaleFactor, 1, NULL, 0}, - {"GL_Antialias", 0, &GL_Antialias, 0, NULL, 0}, + {"GL_BetterPolygons", 0, &GL_BetterPolygons, 0, NULL, 0}, {"LimitFPS", 0, &LimitFPS, 0, NULL, 0}, {"AudioSync", 0, &AudioSync, 1, NULL, 0}, diff --git a/src/frontend/qt_sdl/PlatformConfig.h b/src/frontend/qt_sdl/PlatformConfig.h index bc9bba4..9deee7f 100644 --- a/src/frontend/qt_sdl/PlatformConfig.h +++ b/src/frontend/qt_sdl/PlatformConfig.h @@ -64,7 +64,7 @@ extern int _3DRenderer; extern int Threaded3D; extern int GL_ScaleFactor; -extern int GL_Antialias; +extern int GL_BetterPolygons; extern int LimitFPS; extern int AudioSync; diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.cpp b/src/frontend/qt_sdl/VideoSettingsDialog.cpp index ba433c3..ac1ed7a 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.cpp +++ b/src/frontend/qt_sdl/VideoSettingsDialog.cpp @@ -167,3 +167,10 @@ void VideoSettingsDialog::on_cbxGLResolution_currentIndexChanged(int idx) emit updateVideoSettings(false); } + +void VideoSettingsDialog::on_cbBetterPolygons_stateChanged(int state) +{ + Config::GL_BetterPolygons = (state != 0); + + emit updateVideoSettings(false); +} diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.h b/src/frontend/qt_sdl/VideoSettingsDialog.h index 2311d4d..f18793c 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.h +++ b/src/frontend/qt_sdl/VideoSettingsDialog.h @@ -64,6 +64,7 @@ private slots: void on_sbVSyncInterval_valueChanged(int val); void on_cbxGLResolution_currentIndexChanged(int idx); + void on_cbBetterPolygons_stateChanged(int state); void on_cbSoftwareThreaded_stateChanged(int state); diff --git a/src/frontend/qt_sdl/VideoSettingsDialog.ui b/src/frontend/qt_sdl/VideoSettingsDialog.ui index 6cdd5d8..6985304 100644 --- a/src/frontend/qt_sdl/VideoSettingsDialog.ui +++ b/src/frontend/qt_sdl/VideoSettingsDialog.ui @@ -7,7 +7,7 @@ 0 0 482 - 237 + 244 @@ -43,6 +43,16 @@ + + + + <html><head/><body><p>Enabling this may help reduce distortion on quads and more complex polygons, but may also reduce performance.</p></body></html> + + + Improved polygon splitting + + + diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 0228399..1e7e4a6 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -405,8 +405,11 @@ void EmuThread::run() videoRenderer = hasOGL ? Config::_3DRenderer : 0; videoSettingsDirty = false; + videoSettings.Soft_Threaded = Config::Threaded3D != 0; videoSettings.GL_ScaleFactor = Config::GL_ScaleFactor; + videoSettings.GL_BetterPolygons = Config::GL_BetterPolygons; + GPU::SetRenderSettings(videoRenderer, videoSettings); } -- cgit v1.2.3 From 4be68aafe081ffbd254c2e14b85ed0cb9faa6e6c Mon Sep 17 00:00:00 2001 From: Arisotura Date: Tue, 25 Aug 2020 00:34:57 +0200 Subject: make SD support actually be a thing --- src/Config.cpp | 4 ++ src/Config.h | 2 + src/DSi_SD.cpp | 22 ++++--- src/frontend/qt_sdl/EmuSettingsDialog.cpp | 22 ++++++- src/frontend/qt_sdl/EmuSettingsDialog.h | 1 + src/frontend/qt_sdl/EmuSettingsDialog.ui | 101 +++++++++++++++++++----------- 6 files changed, 108 insertions(+), 44 deletions(-) (limited to 'src/Config.cpp') diff --git a/src/Config.cpp b/src/Config.cpp index 949c1bf..ea8dec7 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -36,6 +36,8 @@ char DSiBIOS9Path[1024]; char DSiBIOS7Path[1024]; char DSiFirmwarePath[1024]; char DSiNANDPath[1024]; +int DSiSDEnable; +char DSiSDPath[1024]; int RandomizeMAC; @@ -57,6 +59,8 @@ ConfigEntry ConfigFile[] = {"DSiBIOS7Path", 1, DSiBIOS7Path, 0, "", 1023}, {"DSiFirmwarePath", 1, DSiFirmwarePath, 0, "", 1023}, {"DSiNANDPath", 1, DSiNANDPath, 0, "", 1023}, + {"DSiSDEnable", 0, &DSiSDEnable, 0, NULL, 0}, + {"DSiSDPath", 1, DSiSDPath, 0, "", 1023}, {"RandomizeMAC", 0, &RandomizeMAC, 0, NULL, 0}, diff --git a/src/Config.h b/src/Config.h index a0f09dc..23db647 100644 --- a/src/Config.h +++ b/src/Config.h @@ -50,6 +50,8 @@ extern char DSiBIOS9Path[1024]; extern char DSiBIOS7Path[1024]; extern char DSiFirmwarePath[1024]; extern char DSiNANDPath[1024]; +extern int DSiSDEnable; +extern char DSiSDPath[1024]; extern int RandomizeMAC; diff --git a/src/DSi_SD.cpp b/src/DSi_SD.cpp index def7a33..45a597b 100644 --- a/src/DSi_SD.cpp +++ b/src/DSi_SD.cpp @@ -117,13 +117,19 @@ void DSi_SDHost::Reset() if (Num == 0) { - // TODO: eventually pull from host filesystem - /*DSi_MMCStorage* sd = new DSi_MMCStorage(this, false, "sd.bin"); - u8 sd_cid[16] = {0xBD, 0x12, 0x34, 0x56, 0x78, 0x03, 0x4D, 0x30, 0x30, 0x46, 0x50, 0x41, 0x00, 0x00, 0x15, 0x00}; - sd->SetCID(sd_cid);*/ - DSi_MMCStorage* sd = NULL; + DSi_MMCStorage* sd; + DSi_MMCStorage* mmc; - DSi_MMCStorage* mmc = new DSi_MMCStorage(this, true, Config::DSiNANDPath); + if (Config::DSiSDEnable) + { + sd = new DSi_MMCStorage(this, false, Config::DSiSDPath); + u8 sd_cid[16] = {0xBD, 0x12, 0x34, 0x56, 0x78, 0x03, 0x4D, 0x30, 0x30, 0x46, 0x50, 0x41, 0x00, 0x00, 0x15, 0x00}; + sd->SetCID(sd_cid); + } + else + sd = nullptr; + + mmc = new DSi_MMCStorage(this, true, Config::DSiNANDPath); mmc->SetCID(DSi::eMMC_CID); Ports[0] = sd; @@ -429,14 +435,14 @@ u16 DSi_SDHost::Read(u32 addr) if (!Num) { if (Ports[0]) // basic check of whether the SD card is inserted - ret |= 0x0030; + ret |= 0x00B0; else ret |= 0x0008; } else { // SDIO wifi is always inserted, I guess - ret |= 0x0030; + ret |= 0x00B0; } return ret; } diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.cpp b/src/frontend/qt_sdl/EmuSettingsDialog.cpp index dc7eaf5..483ce34 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.cpp +++ b/src/frontend/qt_sdl/EmuSettingsDialog.cpp @@ -49,6 +49,8 @@ EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new ui->txtDSiBIOS7Path->setText(Config::DSiBIOS7Path); ui->txtDSiFirmwarePath->setText(Config::DSiFirmwarePath); ui->txtDSiNANDPath->setText(Config::DSiNANDPath); + ui->cbDSiSDEnable->setChecked(Config::DSiSDEnable != 0); + ui->txtDSiSDPath->setText(Config::DSiSDPath); ui->cbxConsoleType->addItem("DS"); ui->cbxConsoleType->addItem("DSi (experimental)"); @@ -145,6 +147,8 @@ void EmuSettingsDialog::done(int r) std::string dsiBios7Path = ui->txtDSiBIOS7Path->text().toStdString(); std::string dsiFirmwarePath = ui->txtDSiFirmwarePath->text().toStdString(); std::string dsiNANDPath = ui->txtDSiNANDPath->text().toStdString(); + int dsiSDEnable = ui->cbDSiSDEnable->isChecked() ? 1:0; + std::string dsiSDPath = ui->txtDSiSDPath->text().toStdString(); if (consoleType != Config::ConsoleType || directBoot != Config::DirectBoot @@ -161,7 +165,9 @@ void EmuSettingsDialog::done(int r) || strcmp(Config::DSiBIOS9Path, dsiBios9Path.c_str()) != 0 || strcmp(Config::DSiBIOS7Path, dsiBios7Path.c_str()) != 0 || strcmp(Config::DSiFirmwarePath, dsiFirmwarePath.c_str()) != 0 - || strcmp(Config::DSiNANDPath, dsiNANDPath.c_str()) != 0) + || strcmp(Config::DSiNANDPath, dsiNANDPath.c_str()) != 0 + || dsiSDEnable != Config::DSiSDEnable + || strcmp(Config::DSiSDPath, dsiSDPath.c_str()) != 0) { if (RunningSomething && QMessageBox::warning(this, "Reset necessary to apply changes", @@ -177,6 +183,8 @@ void EmuSettingsDialog::done(int r) strncpy(Config::DSiBIOS7Path, dsiBios7Path.c_str(), 1023); Config::DSiBIOS7Path[1023] = '\0'; strncpy(Config::DSiFirmwarePath, dsiFirmwarePath.c_str(), 1023); Config::DSiFirmwarePath[1023] = '\0'; strncpy(Config::DSiNANDPath, dsiNANDPath.c_str(), 1023); Config::DSiNANDPath[1023] = '\0'; + Config::DSiSDEnable = dsiSDEnable; + strncpy(Config::DSiSDPath, dsiSDPath.c_str(), 1023); Config::DSiSDPath[1023] = '\0'; #ifdef JIT_ENABLED Config::JIT_Enable = jitEnable; @@ -284,6 +292,18 @@ void EmuSettingsDialog::on_btnDSiNANDBrowse_clicked() ui->txtDSiNANDPath->setText(file); } +void EmuSettingsDialog::on_btnDSiSDBrowse_clicked() +{ + QString file = QFileDialog::getOpenFileName(this, + "Select DSi SD image...", + EmuDirectory, + "Image files (*.bin *.rom *.img);;Any file (*.*)"); + + if (file.isEmpty()) return; + + ui->txtDSiSDPath->setText(file); +} + void EmuSettingsDialog::on_chkEnableJIT_toggled() { bool disabled = !ui->chkEnableJIT->isChecked(); diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.h b/src/frontend/qt_sdl/EmuSettingsDialog.h index 1a16ebc..5814141 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.h +++ b/src/frontend/qt_sdl/EmuSettingsDialog.h @@ -63,6 +63,7 @@ private slots: void on_btnDSiBIOS7Browse_clicked(); void on_btnDSiFirmwareBrowse_clicked(); void on_btnDSiNANDBrowse_clicked(); + void on_btnDSiSDBrowse_clicked(); void on_chkEnableJIT_toggled(); diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.ui b/src/frontend/qt_sdl/EmuSettingsDialog.ui index 11d48cc..5b1bed5 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.ui +++ b/src/frontend/qt_sdl/EmuSettingsDialog.ui @@ -7,7 +7,7 @@ 0 0 514 - 359 + 407 @@ -191,13 +191,47 @@ DSi mode - - + + + + DSi NAND: + + + + + + + + 0 + 0 + + + + <html><head/><body><p>DSi-mode ARM9 BIOS</p><p><br/></p><p>Size should be 64 KB</p></body></html> + + + + + Browse... + + + + <html><head/><body><p>DSi-mode firmware (used for DS-mode backwards compatibility)</p><p><br/></p><p>Size should be 128 KB</p></body></html> + + + + + + + <html><head/><body><p>DSi-mode ARM7 BIOS</p><p><br/></p><p>Size should be 64 KB</p></body></html> + + + @@ -205,24 +239,24 @@ - - + + Browse... - - + + - <html><head/><body><p>DSi-mode ARM7 BIOS</p><p><br/></p><p>Size should be 64 KB</p></body></html> + <html><head/><body><p>DSi NAND dump</p><p><br/></p><p>Should have 'nocash footer' at the end</p></body></html> - - - - <html><head/><body><p>DSi-mode firmware (used for DS-mode backwards compatibility)</p><p><br/></p><p>Size should be 128 KB</p></body></html> + + + + DSi SD card: @@ -233,49 +267,46 @@ - - + + - DSi firmware: + Browse... - - + + Browse... - - - - - 0 - 0 - - - - <html><head/><body><p>DSi-mode ARM9 BIOS</p><p><br/></p><p>Size should be 64 KB</p></body></html> + + + + DSi firmware: - - + + + + <html><head/><body><p>Simulate a SD card being inserted in the DSi's SD slot. Requires a SD card image.</p></body></html> + - DSi NAND: + Enable DSi SD card - - + + - <html><head/><body><p>DSi NAND dump</p><p><br/></p><p>Should have 'nocash footer' at the end</p></body></html> + <html><head/><body><p>SD image file for emulating the DSi's SD card</p></body></html> - - + + Browse... -- cgit v1.2.3 From 5431c469c3b3444d4ae0dc7677bb3a0588c5f88f Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 3 Sep 2020 20:28:07 +0200 Subject: actually add DLDI. bahahahhh --- src/CMakeLists.txt | 1 + src/Config.cpp | 4 + src/Config.h | 2 + src/NDS.cpp | 7 +- src/NDSCart.cpp | 281 +++++++++++----- src/NDSCart.h | 1 + src/frontend/qt_sdl/EmuSettingsDialog.cpp | 20 ++ src/frontend/qt_sdl/EmuSettingsDialog.h | 1 + src/frontend/qt_sdl/EmuSettingsDialog.ui | 522 ++++++++++++++++-------------- 9 files changed, 508 insertions(+), 331 deletions(-) (limited to 'src/Config.cpp') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 24a7ecf..8839fc2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,6 +33,7 @@ add_library(core STATIC GPU3D_OpenGL.cpp GPU3D_OpenGL_shaders.h GPU3D_Soft.cpp + melonDLDI.h NDS.cpp NDSCart.cpp OpenGLSupport.cpp diff --git a/src/Config.cpp b/src/Config.cpp index ea8dec7..2c5fd2c 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -31,6 +31,8 @@ const char* kConfigFile = "melonDS.ini"; char BIOS9Path[1024]; char BIOS7Path[1024]; char FirmwarePath[1024]; +int DLDIEnable; +char DLDISDPath[1024]; char DSiBIOS9Path[1024]; char DSiBIOS7Path[1024]; @@ -54,6 +56,8 @@ ConfigEntry ConfigFile[] = {"BIOS9Path", 1, BIOS9Path, 0, "", 1023}, {"BIOS7Path", 1, BIOS7Path, 0, "", 1023}, {"FirmwarePath", 1, FirmwarePath, 0, "", 1023}, + {"DLDIEnable", 0, &DLDIEnable, 0, NULL, 0}, + {"DLDISDPath", 1, DLDISDPath, 0, "", 1023}, {"DSiBIOS9Path", 1, DSiBIOS9Path, 0, "", 1023}, {"DSiBIOS7Path", 1, DSiBIOS7Path, 0, "", 1023}, diff --git a/src/Config.h b/src/Config.h index 23db647..9fd7488 100644 --- a/src/Config.h +++ b/src/Config.h @@ -45,6 +45,8 @@ void Save(); extern char BIOS9Path[1024]; extern char BIOS7Path[1024]; extern char FirmwarePath[1024]; +extern int DLDIEnable; +extern char DLDISDPath[1024]; extern char DSiBIOS9Path[1024]; extern char DSiBIOS7Path[1024]; diff --git a/src/NDS.cpp b/src/NDS.cpp index a23772c..f926399 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -2537,7 +2537,8 @@ void ARM7Write8(u32 addr, u8 val) return; } - printf("unknown arm7 write8 %08X %02X @ %08X\n", addr, val, ARM7->R[15]); + if (ARM7->R[15] > 0x00002F30) // ARM7 BIOS bug + printf("unknown arm7 write8 %08X %02X @ %08X\n", addr, val, ARM7->R[15]); } void ARM7Write16(u32 addr, u16 val) @@ -3455,6 +3456,10 @@ void ARM9IOWrite32(u32 addr, u32 val) PowerControl9 = val & 0x820F; GPU::SetPowerCnt(PowerControl9); return; + + case 0x04100010: + NDSCart::WriteROMData(val); + return; } if (addr >= 0x04000000 && addr < 0x04000060) diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index a5e0f41..6abfc7c 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -25,7 +25,9 @@ #include "CRC32.h" #include "DSi_AES.h" #include "Platform.h" +#include "Config.h" #include "ROMList.h" +#include "melonDLDI.h" namespace NDSCart_SRAM @@ -464,11 +466,13 @@ u16 SPICnt; u32 ROMCnt; u8 ROMCommand[8]; -u32 ROMDataOut; +u32 ROMData; -u8 DataOut[0x4000]; -u32 DataOutPos; -u32 DataOutLen; +u8 TransferData[0x4000]; +u32 TransferPos; +u32 TransferLen; +u32 TransferDir; +u8 TransferCmd[8]; bool CartInserted; u8* CartROM; @@ -478,6 +482,8 @@ u32 CartID; bool CartIsHomebrew; bool CartIsDSi; +FILE* CartSD; + u32 CmdEncMode; u32 DataEncMode; @@ -489,6 +495,7 @@ u64 Key2_Y; void ROMCommand_Retail(u8* cmd); void ROMCommand_RetailNAND(u8* cmd); +void ROMCommand_Homebrew(u8* cmd); void (*ROMCommandHandler)(u8* cmd); @@ -615,6 +622,8 @@ bool Init() CartROM = NULL; + CartSD = NULL; + return true; } @@ -622,6 +631,8 @@ void DeInit() { if (CartROM) delete[] CartROM; + if (CartSD) fclose(CartSD); + NDSCart_SRAM::DeInit(); } @@ -635,6 +646,9 @@ void Reset() CartIsHomebrew = false; CartIsDSi = false; + if (CartSD) fclose(CartSD); + CartSD = NULL; + ROMCommandHandler = NULL; NDSCart_SRAM::Reset(); @@ -650,11 +664,13 @@ void DoSavestate(Savestate* file) file->Var32(&ROMCnt); file->VarArray(ROMCommand, 8); - file->Var32(&ROMDataOut); + file->Var32(&ROMData); - file->VarArray(DataOut, 0x4000); - file->Var32(&DataOutPos); - file->Var32(&DataOutLen); + file->VarArray(TransferData, 0x4000); + file->Var32(&TransferPos); + file->Var32(&TransferLen); + file->Var32(&TransferDir); + file->VarArray(TransferCmd, 8); // cart inserted/len/ROM/etc should be already populated // savestate should be loaded after the right game is loaded @@ -670,10 +686,8 @@ void DoSavestate(Savestate* file) } -void ApplyDLDIPatch() +void ApplyDLDIPatch(const u8* patch, u32 len) { - // TODO: embed patches? let the user choose? default to some builtin driver? - u32 offset = *(u32*)&CartROM[0x20]; u32 size = *(u32*)&CartROM[0x2C]; @@ -696,23 +710,7 @@ void ApplyDLDIPatch() return; } - printf("DLDI shit found at %08X (%08X)\n", dldioffset, offset+dldioffset); - - FILE* f = fopen("dldi.bin", "rb"); - if (!f) - { - printf("no DLDI patch available. oh well\n"); - return; - } - - u32 dldisize; - fseek(f, 0, SEEK_END); - dldisize = ftell(f); - fseek(f, 0, SEEK_SET); - - u8* patch = new u8[dldisize]; - fread(patch, dldisize, 1, f); - fclose(f); + printf("DLDI structure found at %08X (%08X)\n", dldioffset, offset+dldioffset); if (*(u32*)&patch[0] != 0xBF8DA5ED || *(u32*)&patch[4] != 0x69684320 || @@ -743,7 +741,7 @@ void ApplyDLDIPatch() u32 patchsize = 1 << patch[0x0D]; u32 patchend = patchbase + patchsize; - memcpy(&binary[dldioffset], patch, dldisize); + memcpy(&binary[dldioffset], patch, len); *(u32*)&binary[dldioffset+0x40] += delta; *(u32*)&binary[dldioffset+0x44] += delta; @@ -807,7 +805,6 @@ void ApplyDLDIPatch() memset(&binary[dldioffset+fixstart], 0, fixend-fixstart); } - delete[] patch; printf("applied DLDI patch\n"); } @@ -987,11 +984,13 @@ bool LoadROM(const char* path, const char* sram, bool direct) Key1_Encrypt((u32*)&CartROM[arm9base]); } } - else - { - CartIsHomebrew = true; - //ApplyDLDIPatch(); - } + } + + if ((arm9base < 0x4000) || (gamecode == 0x23232323)) + { + CartIsHomebrew = true; + if (Config::DLDIEnable) + ApplyDLDIPatch(melonDLDI, sizeof(melonDLDI)); } if (direct) @@ -1005,7 +1004,9 @@ bool LoadROM(const char* path, const char* sram, bool direct) CartInserted = true; // TODO: support more fancy cart types (homebrew?, flashcarts, etc) - if (CartID & 0x08000000) + if (CartIsHomebrew) + ROMCommandHandler = ROMCommand_Homebrew; + else if (CartID & 0x08000000) ROMCommandHandler = ROMCommand_RetailNAND; else ROMCommandHandler = ROMCommand_Retail; @@ -1017,6 +1018,13 @@ bool LoadROM(const char* path, const char* sram, bool direct) printf("Save file: %s\n", sram); NDSCart_SRAM::LoadSave(sram, romparams.SaveMemType); + if (CartIsHomebrew && Config::DLDIEnable) + { + CartSD = Platform::OpenLocalFile(Config::DLDISDPath, "r+b"); + } + else + CartSD = NULL; + return true; } @@ -1034,14 +1042,17 @@ void ResetCart() ROMCnt = 0; memset(ROMCommand, 0, 8); - ROMDataOut = 0; + ROMData = 0; Key2_X = 0; Key2_Y = 0; - memset(DataOut, 0, 0x4000); - DataOutPos = 0; - DataOutLen = 0; + memset(TransferData, 0, 0x4000); + TransferPos = 0; + TransferLen = 0; + TransferDir = 0; + memset(TransferCmd, 0, 8); + TransferCmd[0] = 0xFF; CmdEncMode = 0; DataEncMode = 0; @@ -1055,7 +1066,7 @@ void ReadROM(u32 addr, u32 len, u32 offset) if ((addr+len) > CartROMSize) len = CartROMSize - addr; - memcpy(DataOut+offset, CartROM+addr, len); + memcpy(TransferData+offset, CartROM+addr, len); } void ReadROM_B7(u32 addr, u32 len, u32 offset) @@ -1069,7 +1080,7 @@ void ReadROM_B7(u32 addr, u32 len, u32 offset) addr = 0x8000 + (addr & 0x1FF); } - memcpy(DataOut+offset, CartROM+addr, len); + memcpy(TransferData+offset, CartROM+addr, len); } @@ -1079,16 +1090,41 @@ void ROMEndTransfer(u32 param) if (SPICnt & (1<<14)) NDS::SetIRQ((NDS::ExMemCnt[0]>>11)&0x1, NDS::IRQ_CartSendDone); + + if (TransferDir == 1) + { + // finish a write + + u8* cmd = TransferCmd; + switch (cmd[0]) + { + case 0xC1: + { + u32 sector = (cmd[1]<<24) | (cmd[2]<<16) | (cmd[3]<<8) | cmd[4]; + u64 addr = sector * 0x200ULL; + + if (CartSD) + { + fseek(CartSD, addr, SEEK_SET); + fwrite(TransferData, TransferLen, 1, CartSD); + } + } + break; + } + } } void ROMPrepareData(u32 param) { - if (DataOutPos >= DataOutLen) - ROMDataOut = 0; - else - ROMDataOut = *(u32*)&DataOut[DataOutPos]; + if (TransferDir == 0) + { + if (TransferPos >= TransferLen) + ROMData = 0; + else + ROMData = *(u32*)&TransferData[TransferPos]; - DataOutPos += 4; + TransferPos += 4; + } ROMCnt |= (1<<23); @@ -1106,16 +1142,16 @@ void ROMCommand_Retail(u8* cmd) case 0xB7: { u32 addr = (cmd[1]<<24) | (cmd[2]<<16) | (cmd[3]<<8) | cmd[4]; - memset(DataOut, 0, DataOutLen); + memset(TransferData, 0, TransferLen); - if (((addr + DataOutLen - 1) >> 12) != (addr >> 12)) + if (((addr + TransferLen - 1) >> 12) != (addr >> 12)) { u32 len1 = 0x1000 - (addr & 0xFFF); ReadROM_B7(addr, len1, 0); - ReadROM_B7(addr+len1, DataOutLen-len1, len1); + ReadROM_B7(addr+len1, TransferLen-len1, len1); } else - ReadROM_B7(addr, DataOutLen, 0); + ReadROM_B7(addr, TransferLen, 0); } break; @@ -1136,8 +1172,8 @@ void ROMCommand_RetailNAND(u8* cmd) // Jam with the Band stores words 6-9 of this at 0x02131BB0 // it doesn't seem to use those anywhere later - for (u32 pos = 0; pos < DataOutLen; pos += 4) - *(u32*)&DataOut[pos] = 0; + for (u32 pos = 0; pos < TransferLen; pos += 4) + *(u32*)&TransferData[pos] = 0; } break; @@ -1150,16 +1186,16 @@ void ROMCommand_RetailNAND(u8* cmd) case 0xB7: { u32 addr = (cmd[1]<<24) | (cmd[2]<<16) | (cmd[3]<<8) | cmd[4]; - memset(DataOut, 0, DataOutLen); + memset(TransferData, 0, TransferLen); - if (((addr + DataOutLen - 1) >> 12) != (addr >> 12)) + if (((addr + TransferLen - 1) >> 12) != (addr >> 12)) { u32 len1 = 0x1000 - (addr & 0xFFF); ReadROM_B7(addr, len1, 0); - ReadROM_B7(addr+len1, DataOutLen-len1, len1); + ReadROM_B7(addr+len1, TransferLen-len1, len1); } else - ReadROM_B7(addr, DataOutLen, 0); + ReadROM_B7(addr, TransferLen, 0); } break; @@ -1169,13 +1205,59 @@ void ROMCommand_RetailNAND(u8* cmd) // * bit7: busy? error? // * bit5: accessing savemem - for (u32 pos = 0; pos < DataOutLen; pos += 4) - *(u32*)&DataOut[pos] = NDSCart_SRAM::StatusReg * 0x01010101; + for (u32 pos = 0; pos < TransferLen; pos += 4) + *(u32*)&TransferData[pos] = NDSCart_SRAM::StatusReg * 0x01010101; + } + break; + + default: + printf("unknown NAND command %02X %04Xn", cmd[0], TransferLen); + break; + } +} + +void ROMCommand_Homebrew(u8* cmd) +{ + switch (cmd[0]) + { + case 0xB7: + { + u32 addr = (cmd[1]<<24) | (cmd[2]<<16) | (cmd[3]<<8) | cmd[4]; + memset(TransferData, 0, TransferLen); + + if (((addr + TransferLen - 1) >> 12) != (addr >> 12)) + { + u32 len1 = 0x1000 - (addr & 0xFFF); + ReadROM_B7(addr, len1, 0); + ReadROM_B7(addr+len1, TransferLen-len1, len1); + } + else + ReadROM_B7(addr, TransferLen, 0); + } + break; + + case 0xC0: // SD read + { + u32 sector = (cmd[1]<<24) | (cmd[2]<<16) | (cmd[3]<<8) | cmd[4]; + u64 addr = sector * 0x200ULL; + + if (CartSD) + { + fseek(CartSD, addr, SEEK_SET); + fread(TransferData, TransferLen, 1, CartSD); + } + } + break; + + case 0xC1: // SD write + { + TransferDir = 1; + memcpy(TransferCmd, cmd, 8); } break; default: - printf("unknown NAND command %02X %04Xn", cmd[0], DataOutLen); + printf("unknown homebrew cart command %02X\n", cmd[0]); break; } } @@ -1215,8 +1297,8 @@ void WriteROMCnt(u32 val) else if (datasize > 0) datasize = 0x100 << datasize; - DataOutPos = 0; - DataOutLen = datasize; + TransferPos = 0; + TransferLen = datasize; // handle KEY1 encryption as needed. // KEY2 encryption is implemented in hardware and doesn't need to be handled. @@ -1242,28 +1324,32 @@ void WriteROMCnt(u32 val) cmd[4], cmd[5], cmd[6], cmd[7], datasize);*/ + // default is read + // commands that do writes will change this + TransferDir = 0; + switch (cmd[0]) { case 0x9F: - memset(DataOut, 0xFF, DataOutLen); + memset(TransferData, 0xFF, TransferLen); break; case 0x00: - memset(DataOut, 0, DataOutLen); - if (DataOutLen > 0x1000) + memset(TransferData, 0, TransferLen); + if (TransferLen > 0x1000) { ReadROM(0, 0x1000, 0); - for (u32 pos = 0x1000; pos < DataOutLen; pos += 0x1000) - memcpy(DataOut+pos, DataOut, 0x1000); + for (u32 pos = 0x1000; pos < TransferLen; pos += 0x1000) + memcpy(TransferData+pos, TransferData, 0x1000); } else - ReadROM(0, DataOutLen, 0); + ReadROM(0, TransferLen, 0); break; case 0x90: case 0xB8: - for (u32 pos = 0; pos < DataOutLen; pos += 4) - *(u32*)&DataOut[pos] = CartID; + for (u32 pos = 0; pos < TransferLen; pos += 4) + *(u32*)&TransferData[pos] = CartID; break; case 0x3C: @@ -1292,8 +1378,8 @@ void WriteROMCnt(u32 val) break; case 0x10: - for (u32 pos = 0; pos < DataOutLen; pos += 4) - *(u32*)&DataOut[pos] = CartID; + for (u32 pos = 0; pos < TransferLen; pos += 4) + *(u32*)&TransferData[pos] = CartID; break; case 0x20: @@ -1343,29 +1429,52 @@ void WriteROMCnt(u32 val) NDS::ScheduleEvent(NDS::Event_ROMTransfer, false, xfercycle*(cmddelay+4), ROMPrepareData, 0); } +void AdvanceROMTransfer() +{ + ROMCnt &= ~(1<<23); + + if (TransferPos < TransferLen) + { + u32 xfercycle = (ROMCnt & (1<<27)) ? 8 : 5; + u32 delay = 4; + if (!(ROMCnt & (1<<30))) + { + if (!(TransferPos & 0x1FF)) + delay += ((ROMCnt >> 16) & 0x3F); + } + + NDS::ScheduleEvent(NDS::Event_ROMTransfer, false, xfercycle*delay, ROMPrepareData, 0); + } + else + ROMEndTransfer(0); +} + u32 ReadROMData() { if (ROMCnt & (1<<23)) { - ROMCnt &= ~(1<<23); + AdvanceROMTransfer(); + } + + return ROMData; +} - if (DataOutPos < DataOutLen) +void WriteROMData(u32 val) +{ + ROMData = val; + + if (ROMCnt & (1<<23)) + { + if (TransferDir == 1) { - u32 xfercycle = (ROMCnt & (1<<27)) ? 8 : 5; - u32 delay = 4; - if (!(ROMCnt & (1<<30))) - { - if (!(DataOutPos & 0x1FF)) - delay += ((ROMCnt >> 16) & 0x3F); - } + if (TransferPos < TransferLen) + *(u32*)&TransferData[TransferPos] = ROMData; - NDS::ScheduleEvent(NDS::Event_ROMTransfer, false, xfercycle*delay, ROMPrepareData, 0); + TransferPos += 4; } - else - ROMEndTransfer(0); - } - return ROMDataOut; + AdvanceROMTransfer(); + } } diff --git a/src/NDSCart.h b/src/NDSCart.h index adc821f..a759c15 100644 --- a/src/NDSCart.h +++ b/src/NDSCart.h @@ -52,6 +52,7 @@ void ResetCart(); void WriteROMCnt(u32 val); u32 ReadROMData(); +void WriteROMData(u32 val); void WriteSPICnt(u16 val); u8 ReadSPIData(); diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.cpp b/src/frontend/qt_sdl/EmuSettingsDialog.cpp index 483ce34..79ce5ed 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.cpp +++ b/src/frontend/qt_sdl/EmuSettingsDialog.cpp @@ -44,6 +44,8 @@ EmuSettingsDialog::EmuSettingsDialog(QWidget* parent) : QDialog(parent), ui(new ui->txtBIOS9Path->setText(Config::BIOS9Path); ui->txtBIOS7Path->setText(Config::BIOS7Path); ui->txtFirmwarePath->setText(Config::FirmwarePath); + ui->cbDLDIEnable->setChecked(Config::DLDIEnable != 0); + ui->txtDLDISDPath->setText(Config::DLDISDPath); ui->txtDSiBIOS9Path->setText(Config::DSiBIOS9Path); ui->txtDSiBIOS7Path->setText(Config::DSiBIOS7Path); @@ -143,6 +145,8 @@ void EmuSettingsDialog::done(int r) std::string bios9Path = ui->txtBIOS9Path->text().toStdString(); std::string bios7Path = ui->txtBIOS7Path->text().toStdString(); std::string firmwarePath = ui->txtFirmwarePath->text().toStdString(); + int dldiEnable = ui->cbDLDIEnable->isChecked() ? 1:0; + std::string dldiSDPath = ui->txtDLDISDPath->text().toStdString(); std::string dsiBios9Path = ui->txtDSiBIOS9Path->text().toStdString(); std::string dsiBios7Path = ui->txtDSiBIOS7Path->text().toStdString(); std::string dsiFirmwarePath = ui->txtDSiFirmwarePath->text().toStdString(); @@ -162,6 +166,8 @@ void EmuSettingsDialog::done(int r) || strcmp(Config::BIOS9Path, bios9Path.c_str()) != 0 || strcmp(Config::BIOS7Path, bios7Path.c_str()) != 0 || strcmp(Config::FirmwarePath, firmwarePath.c_str()) != 0 + || dldiEnable != Config::DLDIEnable + || strcmp(Config::DLDISDPath, dldiSDPath.c_str()) != 0 || strcmp(Config::DSiBIOS9Path, dsiBios9Path.c_str()) != 0 || strcmp(Config::DSiBIOS7Path, dsiBios7Path.c_str()) != 0 || strcmp(Config::DSiFirmwarePath, dsiFirmwarePath.c_str()) != 0 @@ -178,6 +184,8 @@ void EmuSettingsDialog::done(int r) strncpy(Config::BIOS9Path, bios9Path.c_str(), 1023); Config::BIOS9Path[1023] = '\0'; strncpy(Config::BIOS7Path, bios7Path.c_str(), 1023); Config::BIOS7Path[1023] = '\0'; strncpy(Config::FirmwarePath, firmwarePath.c_str(), 1023); Config::FirmwarePath[1023] = '\0'; + Config::DLDIEnable = dldiEnable; + strncpy(Config::DLDISDPath, dldiSDPath.c_str(), 1023); Config::DLDISDPath[1023] = '\0'; strncpy(Config::DSiBIOS9Path, dsiBios9Path.c_str(), 1023); Config::DSiBIOS9Path[1023] = '\0'; strncpy(Config::DSiBIOS7Path, dsiBios7Path.c_str(), 1023); Config::DSiBIOS7Path[1023] = '\0'; @@ -268,6 +276,18 @@ void EmuSettingsDialog::on_btnDSiBIOS7Browse_clicked() ui->txtDSiBIOS7Path->setText(file); } +void EmuSettingsDialog::on_btnDLDISDBrowse_clicked() +{ + QString file = QFileDialog::getOpenFileName(this, + "Select DLDI SD image...", + EmuDirectory, + "Image files (*.bin *.rom *.img);;Any file (*.*)"); + + if (file.isEmpty()) return; + + ui->txtDLDISDPath->setText(file); +} + void EmuSettingsDialog::on_btnDSiFirmwareBrowse_clicked() { QString file = QFileDialog::getOpenFileName(this, diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.h b/src/frontend/qt_sdl/EmuSettingsDialog.h index 5814141..158793c 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.h +++ b/src/frontend/qt_sdl/EmuSettingsDialog.h @@ -58,6 +58,7 @@ private slots: void on_btnBIOS9Browse_clicked(); void on_btnBIOS7Browse_clicked(); void on_btnFirmwareBrowse_clicked(); + void on_btnDLDISDBrowse_clicked(); void on_btnDSiBIOS9Browse_clicked(); void on_btnDSiBIOS7Browse_clicked(); diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.ui b/src/frontend/qt_sdl/EmuSettingsDialog.ui index 5b1bed5..ac5506f 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.ui +++ b/src/frontend/qt_sdl/EmuSettingsDialog.ui @@ -6,8 +6,8 @@ 0 0 - 514 - 407 + 575 + 254 @@ -86,240 +86,242 @@ - BIOS Files + DS-mode - - - - - DS mode - - - - - - DS firmware: - - - - - - - <html><head/><body><p>DS-mode firmware</p><p><br/></p><p>Possible firmwares:</p><p>* 128 KB: DS-mode firmware from a DSi or 3DS. Not bootable.</p><p>* 256 KB: regular DS firmware.</p><p>* 512 KB: iQue DS firmware.</p></body></html> - - - - - - - <html><head/><body><p>DS-mode ARM7 BIOS</p><p>Size should be 16 KB</p></body></html> - - - - - - - - 0 - 0 - - - - Browse... - - - true - - - - - - - Browse... - - - - - - - DS ARM7 BIOS: - - - - - - - DS ARM9 BIOS: - - - - - - - Browse... - - - - - - - - 0 - 0 - - - - - 290 - 0 - - - - - - - <html><head/><body><p>DS-mode ARM9 BIOS</p><p>Size should be 4 KB</p></body></html> - - - - - - - - - - DSi mode - - - - - - DSi NAND: - - - - - - - - 0 - 0 - - - - <html><head/><body><p>DSi-mode ARM9 BIOS</p><p><br/></p><p>Size should be 64 KB</p></body></html> - - - - - - - Browse... - - - - - - - <html><head/><body><p>DSi-mode firmware (used for DS-mode backwards compatibility)</p><p><br/></p><p>Size should be 128 KB</p></body></html> - - - - - - - <html><head/><body><p>DSi-mode ARM7 BIOS</p><p><br/></p><p>Size should be 64 KB</p></body></html> - - - - - - - DSi ARM9 BIOS: - - - - - - - Browse... - - - - - - - <html><head/><body><p>DSi NAND dump</p><p><br/></p><p>Should have 'nocash footer' at the end</p></body></html> - - - - - - - DSi SD card: - - - - - - - DSi ARM7 BIOS: - - - - - - - Browse... - - - - - - - Browse... - - - - - - - DSi firmware: - - - - - - - <html><head/><body><p>Simulate a SD card being inserted in the DSi's SD slot. Requires a SD card image.</p></body></html> - - - Enable DSi SD card - - - - - - - <html><head/><body><p>SD image file for emulating the DSi's SD card</p></body></html> - - - - - - - Browse... - - - - + + + + + <html><head/><body><p>DS-mode ARM7 BIOS</p><p>Size should be 16 KB</p></body></html> + + + + + + + <html><head/><body><p>DS-mode firmware</p><p><br/></p><p>Possible firmwares:</p><p>* 128 KB: DS-mode firmware from a DSi or 3DS. Not bootable.</p><p>* 256 KB: regular DS firmware.</p><p>* 512 KB: iQue DS firmware.</p></body></html> + + + + + + + DS firmware: + + + + + + + DS ARM7 BIOS: + + + + + + + Browse... + + + + + + + Browse... + + + + + + + + 0 + 0 + + + + Browse... + + + true + + + + + + + DS ARM9 BIOS: + + + + + + + + 0 + 0 + + + + + 290 + 0 + + + + + + + <html><head/><body><p>DS-mode ARM9 BIOS</p><p>Size should be 4 KB</p></body></html> + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + DSi-mode + + + + + + <html><head/><body><p>DSi-mode ARM7 BIOS</p><p><br/></p><p>Size should be 64 KB</p></body></html> + + + + + + + Browse... + + + + + + + DSi NAND: + + + + + + + Browse... + + + + + + + DSi ARM7 BIOS: + + + + + + + Browse... + + + + + + + <html><head/><body><p>DSi NAND dump</p><p><br/></p><p>Should have 'nocash footer' at the end</p></body></html> + + + + + + + Browse... + + + + + + + DSi SD card: + + + + + + + + 0 + 0 + + + + <html><head/><body><p>DSi-mode ARM9 BIOS</p><p><br/></p><p>Size should be 64 KB</p></body></html> + + + + + + + DSi firmware: + + + + + + + DSi ARM9 BIOS: + + + + + + + <html><head/><body><p>DSi-mode firmware (used for DS-mode backwards compatibility)</p><p><br/></p><p>Size should be 128 KB</p></body></html> + + + + + + + <html><head/><body><p>SD image file for emulating the DSi's SD card</p></body></html> + + + + + + + <html><head/><body><p>Simulate a SD card being inserted in the DSi's SD slot. Requires a SD card image.</p></body></html> + + + Enable DSi SD card + + + + + + + Browse... + - CPU Emulation + CPU emulation @@ -385,6 +387,53 @@ + + + DLDI + + + + + + <html><head/><body><p>Enable the built-in DLDI driver, to let homebrew access files from a given SD image.</p></body></html> + + + Enable DLDI (for homebrew) + + + + + + + Browse... + + + + + + + + + + DLDI SD card: + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + @@ -400,23 +449,8 @@ - tabWidget cbxConsoleType chkDirectBoot - txtBIOS9Path - txtBIOS7Path - txtFirmwarePath - txtDSiBIOS9Path - txtDSiBIOS7Path - txtDSiFirmwarePath - txtDSiNANDPath - btnBIOS9Browse - btnBIOS7Browse - btnFirmwareBrowse - btnDSiBIOS9Browse - btnDSiBIOS7Browse - btnDSiFirmwareBrowse - btnDSiNANDBrowse chkEnableJIT spnJITMaximumBlockSize -- cgit v1.2.3 From 0d845c9e69e19046f351ce396da8eec150243387 Mon Sep 17 00:00:00 2001 From: Valeri Date: Thu, 1 Oct 2020 14:44:09 +0300 Subject: Random minor fixes (#757) * Fix incorrect/questionable assert() usage Originally reported by https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2159000700, but also includes a bunch of other fixes. * Fix some `printf` warnings Rule https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2160310550 * Remove useless check It is never passed thanks to `if (num_in < 1) {...; return}` before Rule https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2154840804 * Add missing header guard, rename other to avoid conflicts Rule https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2163210746 * Make DSi_SDDevice destructor virtual Rule https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2158670642 * Use thread-safe localtime_r, assign `time` result directly Rule https://lgtm.com/projects/g/Arisotura/melonDS/?mode=tree&ruleFocus=2154840805 * Fix MinGW build It needs _POSIX_THREAD_SAFE_FUNCTIONS to export `localtime_r` --- src/ARMJIT_A64/ARMJIT_Compiler.h | 6 ++--- src/ARMJIT_A64/ARMJIT_LoadStore.cpp | 4 +-- src/ARMJIT_Compiler.h | 7 +++++- src/ARMJIT_RegisterCache.h | 3 ++- src/ARMJIT_x64/ARMJIT_ALU.cpp | 7 +++--- src/ARMJIT_x64/ARMJIT_Compiler.h | 6 ++--- src/ARMJIT_x64/ARMJIT_LoadStore.cpp | 4 +-- src/Config.cpp | 2 +- src/DSi_SD.h | 2 +- src/RTC.cpp | 41 ++++++++++++++++--------------- src/frontend/qt_sdl/InputConfigDialog.cpp | 2 +- src/frontend/qt_sdl/main.cpp | 1 - 12 files changed, 46 insertions(+), 39 deletions(-) (limited to 'src/Config.cpp') diff --git a/src/ARMJIT_A64/ARMJIT_Compiler.h b/src/ARMJIT_A64/ARMJIT_Compiler.h index 0e7d54c..af7497a 100644 --- a/src/ARMJIT_A64/ARMJIT_Compiler.h +++ b/src/ARMJIT_A64/ARMJIT_Compiler.h @@ -1,5 +1,5 @@ -#ifndef ARMJIT_COMPILER_H -#define ARMJIT_COMPILER_H +#ifndef ARMJIT_A64_COMPILER_H +#define ARMJIT_A64_COMPILER_H #include "../ARM.h" #include "../ARMJIT.h" @@ -266,4 +266,4 @@ public: } -#endif \ No newline at end of file +#endif diff --git a/src/ARMJIT_A64/ARMJIT_LoadStore.cpp b/src/ARMJIT_A64/ARMJIT_LoadStore.cpp index 14aa847..86e257a 100644 --- a/src/ARMJIT_A64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_A64/ARMJIT_LoadStore.cpp @@ -42,7 +42,7 @@ s64 Compiler::RewriteMemAccess(u64 pc) return patch.PatchOffset; } printf("this is a JIT bug! %08x\n", __builtin_bswap32(*(u32*)pc)); - assert(false); + abort(); } bool Compiler::Comp_MemLoadLiteral(int size, bool signExtend, int rd, u32 addr) @@ -807,4 +807,4 @@ void Compiler::T_Comp_LDMIA_STMIA() } } -} \ No newline at end of file +} diff --git a/src/ARMJIT_Compiler.h b/src/ARMJIT_Compiler.h index 513c103..25a0210 100644 --- a/src/ARMJIT_Compiler.h +++ b/src/ARMJIT_Compiler.h @@ -1,3 +1,6 @@ +#ifndef ARMJIT_COMPILER_H +#define ARMJIT_COMPILER_H + #if defined(__x86_64__) #include "ARMJIT_x64/ARMJIT_Compiler.h" #elif defined(__aarch64__) @@ -9,4 +12,6 @@ namespace ARMJIT { extern Compiler* JITCompiler; -} \ No newline at end of file +} + +#endif diff --git a/src/ARMJIT_RegisterCache.h b/src/ARMJIT_RegisterCache.h index feb2d35..b11255e 100644 --- a/src/ARMJIT_RegisterCache.h +++ b/src/ARMJIT_RegisterCache.h @@ -61,7 +61,8 @@ public: } } - assert("Welp!"); + printf("this is a JIT bug! LoadRegister failed\n"); + abort(); } void PutLiteral(int reg, u32 val) diff --git a/src/ARMJIT_x64/ARMJIT_ALU.cpp b/src/ARMJIT_x64/ARMJIT_ALU.cpp index 24d22ed..511b3b1 100644 --- a/src/ARMJIT_x64/ARMJIT_ALU.cpp +++ b/src/ARMJIT_x64/ARMJIT_ALU.cpp @@ -209,7 +209,8 @@ void Compiler::A_Comp_Arith() Comp_ArithTriOp(&Compiler::AND, rd, rn, op2, carryUsed, sFlag|opSymmetric|opInvertOp2); break; default: - assert("unimplemented"); + printf("this is a JIT bug! %04x\n", op); + abort(); } if (CurInstr.A_Reg(12) == 15) @@ -566,7 +567,7 @@ OpArg Compiler::Comp_RegShiftImm(int op, int amount, OpArg rm, bool S, bool& car return R(RSCRATCH); } - assert(false); + abort(); } void Compiler::T_Comp_ShiftImm() @@ -779,4 +780,4 @@ void Compiler::T_Comp_RelAddr() MOV(32, rd, Imm32((R15 & ~2) + offset)); } -} \ No newline at end of file +} diff --git a/src/ARMJIT_x64/ARMJIT_Compiler.h b/src/ARMJIT_x64/ARMJIT_Compiler.h index 9a64d09..3e900c3 100644 --- a/src/ARMJIT_x64/ARMJIT_Compiler.h +++ b/src/ARMJIT_x64/ARMJIT_Compiler.h @@ -1,5 +1,5 @@ -#ifndef ARMJIT_COMPILER_H -#define ARMJIT_COMPILER_H +#ifndef ARMJIT_X64_COMPILER_H +#define ARMJIT_X64_COMPILER_H #include "../dolphin/x64Emitter.h" @@ -252,4 +252,4 @@ public: } -#endif \ No newline at end of file +#endif diff --git a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp index 1be6608..8b4e8fe 100644 --- a/src/ARMJIT_x64/ARMJIT_LoadStore.cpp +++ b/src/ARMJIT_x64/ARMJIT_LoadStore.cpp @@ -39,7 +39,7 @@ s32 Compiler::RewriteMemAccess(u64 pc) return patch.Offset; } - printf("this is a JIT bug %x\n", pc); + printf("this is a JIT bug %llx\n", pc); abort(); } @@ -819,4 +819,4 @@ void Compiler::T_Comp_LDMIA_STMIA() ADD(32, rb, Imm8(offset)); } -} \ No newline at end of file +} diff --git a/src/Config.cpp b/src/Config.cpp index 2c5fd2c..8bda9ae 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -169,7 +169,7 @@ void Save() if (entry->Type == 0) fprintf(f, "%s=%d\n", entry->Name, *(int*)entry->Value); else - fprintf(f, "%s=%s\n", entry->Name, entry->Value); + fprintf(f, "%s=%s\n", entry->Name, (char*)entry->Value); entry++; } diff --git a/src/DSi_SD.h b/src/DSi_SD.h index 30da6c7..43f5a98 100644 --- a/src/DSi_SD.h +++ b/src/DSi_SD.h @@ -103,7 +103,7 @@ class DSi_SDDevice { public: DSi_SDDevice(DSi_SDHost* host) { Host = host; IRQ = false; } - ~DSi_SDDevice() {} + virtual ~DSi_SDDevice() {} virtual void Reset() = 0; diff --git a/src/RTC.cpp b/src/RTC.cpp index ba51dff..aff3dd3 100644 --- a/src/RTC.cpp +++ b/src/RTC.cpp @@ -16,6 +16,9 @@ with melonDS. If not, see http://www.gnu.org/licenses/. */ +// Required by MinGW to enable localtime_r in time.h +#define _POSIX_THREAD_SAFE_FUNCTIONS + #include #include #include @@ -125,31 +128,29 @@ void ByteIn(u8 val) case 0x20: { - time_t timestamp; - struct tm* timedata; - time(×tamp); - timedata = localtime(×tamp); - - Output[0] = BCD(timedata->tm_year - 100); - Output[1] = BCD(timedata->tm_mon + 1); - Output[2] = BCD(timedata->tm_mday); - Output[3] = BCD(timedata->tm_wday); - Output[4] = BCD(timedata->tm_hour); - Output[5] = BCD(timedata->tm_min); - Output[6] = BCD(timedata->tm_sec); + time_t timestamp = time(NULL); + struct tm timedata; + localtime_r(×tamp, &timedata); + + Output[0] = BCD(timedata.tm_year - 100); + Output[1] = BCD(timedata.tm_mon + 1); + Output[2] = BCD(timedata.tm_mday); + Output[3] = BCD(timedata.tm_wday); + Output[4] = BCD(timedata.tm_hour); + Output[5] = BCD(timedata.tm_min); + Output[6] = BCD(timedata.tm_sec); } break; case 0x60: { - time_t timestamp; - struct tm* timedata; - time(×tamp); - timedata = localtime(×tamp); - - Output[0] = BCD(timedata->tm_hour); - Output[1] = BCD(timedata->tm_min); - Output[2] = BCD(timedata->tm_sec); + time_t timestamp = time(NULL); + struct tm timedata; + localtime_r(×tamp, &timedata); + + Output[0] = BCD(timedata.tm_hour); + Output[1] = BCD(timedata.tm_min); + Output[2] = BCD(timedata.tm_sec); } break; diff --git a/src/frontend/qt_sdl/InputConfigDialog.cpp b/src/frontend/qt_sdl/InputConfigDialog.cpp index 2292441..522b16c 100644 --- a/src/frontend/qt_sdl/InputConfigDialog.cpp +++ b/src/frontend/qt_sdl/InputConfigDialog.cpp @@ -228,7 +228,7 @@ void KeyMapButton::keyPressEvent(QKeyEvent* event) { if (!isChecked()) return QPushButton::keyPressEvent(event); - printf("KEY PRESSED = %08X %08X | %08X %08X %08X\n", event->key(), event->modifiers(), event->nativeVirtualKey(), event->nativeModifiers(), event->nativeScanCode()); + printf("KEY PRESSED = %08X %08X | %08X %08X %08X\n", event->key(), (int)event->modifiers(), event->nativeVirtualKey(), event->nativeModifiers(), event->nativeScanCode()); int key = event->key(); int mod = event->modifiers(); diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index e0c12e3..3a735fb 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -115,7 +115,6 @@ void audioCallback(void* data, Uint8* stream, int len) if (num_in < len_in-margin) { int last = num_in-1; - if (last < 0) last = 0; for (int i = num_in; i < len_in-margin; i++) ((u32*)buf_in)[i] = ((u32*)buf_in)[last]; -- cgit v1.2.3 From 65be1840f02a7499fa08178abcefddfefec6d9b0 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Thu, 15 Oct 2020 05:59:22 +0200 Subject: change JIT branch optimisations default to 1 branch linking is dead --- src/Config.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Config.cpp') diff --git a/src/Config.cpp b/src/Config.cpp index 8bda9ae..341b14c 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -46,7 +46,7 @@ int RandomizeMAC; #ifdef JIT_ENABLED int JIT_Enable = false; int JIT_MaxBlockSize = 32; -int JIT_BranchOptimisations = 2; +int JIT_BranchOptimisations = true; int JIT_LiteralOptimisations = true; int JIT_FastMemory = true; #endif @@ -71,7 +71,7 @@ ConfigEntry ConfigFile[] = #ifdef JIT_ENABLED {"JIT_Enable", 0, &JIT_Enable, 0, NULL, 0}, {"JIT_MaxBlockSize", 0, &JIT_MaxBlockSize, 32, NULL, 0}, - {"JIT_BranchOptimisations", 0, &JIT_BranchOptimisations, 2, NULL, 0}, + {"JIT_BranchOptimisations", 0, &JIT_BranchOptimisations, 1, NULL, 0}, {"JIT_LiteralOptimisations", 0, &JIT_LiteralOptimisations, 1, NULL, 0}, {"JIT_FastMemory", 0, &JIT_FastMemory, 1, NULL, 0}, #endif -- cgit v1.2.3