diff options
author | Arisotura <thetotalworm@gmail.com> | 2020-05-17 04:37:44 +0200 |
---|---|---|
committer | Arisotura <thetotalworm@gmail.com> | 2020-05-17 04:37:44 +0200 |
commit | 17d30e91f01ea015caf5e28afe8ddca4aede45b1 (patch) | |
tree | 60e0742f5081b878adba2581f7fc99baa1f7bff1 /src | |
parent | 60ba163f08e0af4272c8de6141583238eb283fe8 (diff) |
actually hook this up
Diffstat (limited to 'src')
-rw-r--r-- | src/Config.cpp | 8 | ||||
-rw-r--r-- | src/Config.h | 4 | ||||
-rw-r--r-- | src/NDS.cpp | 4 | ||||
-rw-r--r-- | src/SPI.cpp | 16 | ||||
-rw-r--r-- | src/frontend/qt_sdl/EmuSettingsDialog.cpp | 49 | ||||
-rw-r--r-- | src/frontend/qt_sdl/EmuSettingsDialog.h | 2 | ||||
-rw-r--r-- | src/frontend/qt_sdl/PlatformConfig.cpp | 8 | ||||
-rw-r--r-- | src/frontend/qt_sdl/PlatformConfig.h | 4 |
8 files changed, 75 insertions, 20 deletions
diff --git a/src/Config.cpp b/src/Config.cpp index f558ef6..7604785 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -28,6 +28,10 @@ namespace Config const char* kConfigFile = "melonDS.ini"; +char BIOS9Path[1024]; +char BIOS7Path[1024]; +char FirmwarePath[1024]; + int _3DRenderer; int Threaded3D; @@ -36,6 +40,10 @@ int GL_Antialias; ConfigEntry ConfigFile[] = { + {"BIOS9Path", 1, BIOS9Path, 0, "", 1023}, + {"BIOS7Path", 1, BIOS7Path, 0, "", 1023}, + {"FirmwarePath", 1, FirmwarePath, 0, "", 1023}, + {"3DRenderer", 0, &_3DRenderer, 1, NULL, 0}, {"Threaded3D", 0, &Threaded3D, 1, NULL, 0}, diff --git a/src/Config.h b/src/Config.h index 0aeab85..05b9b8b 100644 --- a/src/Config.h +++ b/src/Config.h @@ -42,6 +42,10 @@ bool HasConfigFile(const char* fileName); void Load(); void Save(); +extern char BIOS9Path[1024]; +extern char BIOS7Path[1024]; +extern char FirmwarePath[1024]; + extern int _3DRenderer; extern int Threaded3D; diff --git a/src/NDS.cpp b/src/NDS.cpp index a2ab6ce..1d425a8 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -416,7 +416,7 @@ void Reset() RunningGame = false; LastSysClockCycles = 0; - f = Platform::OpenLocalFile("bios9.bin", "rb"); + f = Platform::OpenLocalFile(Config::BIOS9Path, "rb"); if (!f) { printf("ARM9 BIOS not found\n"); @@ -433,7 +433,7 @@ void Reset() fclose(f); } - f = Platform::OpenLocalFile("bios7.bin", "rb"); + f = Platform::OpenLocalFile(Config::BIOS7Path, "rb"); if (!f) { printf("ARM7 BIOS not found\n"); diff --git a/src/SPI.cpp b/src/SPI.cpp index 1a5873e..056e8d5 100644 --- a/src/SPI.cpp +++ b/src/SPI.cpp @@ -28,6 +28,7 @@ namespace SPI_Firmware { +char FirmwarePath[1024]; u8* Firmware; u32 FirmwareLength; u32 FirmwareMask; @@ -76,6 +77,7 @@ bool VerifyCRC16(u32 start, u32 offset, u32 len, u32 crcoffset) bool Init() { + memset(FirmwarePath, 0, sizeof(FirmwarePath)); Firmware = NULL; return true; } @@ -90,10 +92,12 @@ void Reset() if (Firmware) delete[] Firmware; Firmware = NULL; - FILE* f = Platform::OpenLocalFile("firmware.bin", "rb"); + strncpy(FirmwarePath, Config::FirmwarePath, 1023); + + FILE* f = Platform::OpenLocalFile(FirmwarePath, "rb"); if (!f) { - printf("firmware.bin not found\n"); + printf("Firmware not found\n"); // TODO: generate default firmware return; @@ -129,7 +133,11 @@ void Reset() fclose(f); // take a backup - const char* firmbkp = "firmware.bin.bak"; + char firmbkp[1028]; + int fplen = strlen(FirmwarePath); + strncpy(&firmbkp[0], FirmwarePath, fplen); + strncpy(&firmbkp[fplen], ".bak", 1028-fplen); + firmbkp[fplen+4] = '\0'; f = Platform::OpenLocalFile(firmbkp, "rb"); if (f) fclose(f); else @@ -325,7 +333,7 @@ void Write(u8 val, u32 hold) if (!hold && (CurCmd == 0x02 || CurCmd == 0x0A)) { - FILE* f = Platform::OpenLocalFile("firmware.bin", "r+b"); + FILE* f = Platform::OpenLocalFile(FirmwarePath, "r+b"); if (f) { u32 cutoff = 0x7FA00 & FirmwareMask; diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.cpp b/src/frontend/qt_sdl/EmuSettingsDialog.cpp index 34cafb5..bce5513 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.cpp +++ b/src/frontend/qt_sdl/EmuSettingsDialog.cpp @@ -16,9 +16,12 @@ with melonDS. If not, see http://www.gnu.org/licenses/. */ +#include <stdio.h> #include <QFileDialog> +#include <QMessageBox> #include "types.h" +#include "Platform.h" #include "Config.h" #include "PlatformConfig.h" @@ -47,8 +50,52 @@ EmuSettingsDialog::~EmuSettingsDialog() delete ui; } +void EmuSettingsDialog::verifyFirmware() +{ + // verify the firmware + // + // there are dumps of an old hacked firmware floating around on the internet + // and those are problematic + // the hack predates WFC, and, due to this, any game that alters the WFC + // access point data will brick that firmware due to it having critical + // data in the same area. it has the same problem on hardware. + // + // but this should help stop users from reporting that issue over and over + // again, when the issue is not from melonDS but from their firmware dump. + // + // I don't know about all the firmware hacks in existence, but the one I + // looked at has 0x180 bytes from the header repeated at 0x3FC80, but + // bytes 0x0C-0x14 are different. + + char filename[1024]; + strncpy(filename, ui->txtFirmwarePath->text().toStdString().c_str(), 1023); filename[1023] = '\0'; + FILE* f = Platform::OpenLocalFile(filename, "rb"); + u8 chk1[0x180], chk2[0x180]; + + fseek(f, 0, SEEK_SET); + fread(chk1, 1, 0x180, f); + fseek(f, -0x380, SEEK_END); + fread(chk2, 1, 0x180, f); + + memset(&chk1[0x0C], 0, 8); + memset(&chk2[0x0C], 0, 8); + + fclose(f); + + if (!memcmp(chk1, chk2, 0x180)) + { + QMessageBox::warning(this, + "Problematic firmware dump", + "You are using an old hacked firmware dump.\n" + "Firmware boot will stop working if you run any game that alters WFC settings.\n\n" + "Note that the issue is not from melonDS, it would also happen on an actual DS."); + } +} + void EmuSettingsDialog::on_EmuSettingsDialog_accepted() { + verifyFirmware(); + strncpy(Config::BIOS9Path, ui->txtBIOS9Path->text().toStdString().c_str(), 1023); Config::BIOS9Path[1023] = '\0'; strncpy(Config::BIOS7Path, ui->txtBIOS7Path->text().toStdString().c_str(), 1023); Config::BIOS7Path[1023] = '\0'; strncpy(Config::FirmwarePath, ui->txtFirmwarePath->text().toStdString().c_str(), 1023); Config::FirmwarePath[1023] = '\0'; @@ -95,7 +142,5 @@ void EmuSettingsDialog::on_btnFirmwareBrowse_clicked() if (file.isEmpty()) return; - // TODO: check for shitty hacked firmware here? - ui->txtFirmwarePath->setText(file); } diff --git a/src/frontend/qt_sdl/EmuSettingsDialog.h b/src/frontend/qt_sdl/EmuSettingsDialog.h index 471e0fb..ce64145 100644 --- a/src/frontend/qt_sdl/EmuSettingsDialog.h +++ b/src/frontend/qt_sdl/EmuSettingsDialog.h @@ -58,6 +58,8 @@ private slots: void on_btnFirmwareBrowse_clicked(); private: + void verifyFirmware(); + Ui::EmuSettingsDialog* ui; }; diff --git a/src/frontend/qt_sdl/PlatformConfig.cpp b/src/frontend/qt_sdl/PlatformConfig.cpp index fba649c..1f6a873 100644 --- a/src/frontend/qt_sdl/PlatformConfig.cpp +++ b/src/frontend/qt_sdl/PlatformConfig.cpp @@ -64,10 +64,6 @@ char MicWavPath[1024]; char LastROMFolder[1024]; -char BIOS9Path[1024]; -char BIOS7Path[1024]; -char FirmwarePath[1024]; - ConfigEntry PlatformConfigFile[] = { @@ -149,10 +145,6 @@ ConfigEntry PlatformConfigFile[] = {"LastROMFolder", 1, LastROMFolder, 0, "", 1023}, - {"BIOS9Path", 1, BIOS9Path, 0, "", 1023}, - {"BIOS7Path", 1, BIOS7Path, 0, "", 1023}, - {"FirmwarePath", 1, FirmwarePath, 0, "", 1023}, - {"", -1, NULL, 0, NULL, 0} }; diff --git a/src/frontend/qt_sdl/PlatformConfig.h b/src/frontend/qt_sdl/PlatformConfig.h index e104015..3704d14 100644 --- a/src/frontend/qt_sdl/PlatformConfig.h +++ b/src/frontend/qt_sdl/PlatformConfig.h @@ -77,10 +77,6 @@ extern char MicWavPath[1024]; extern char LastROMFolder[1024]; -extern char BIOS9Path[1024]; -extern char BIOS7Path[1024]; -extern char FirmwarePath[1024]; - } #endif // PLATFORMCONFIG_H |