aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArisotura <thetotalworm@gmail.com>2021-11-17 20:42:11 +0100
committerArisotura <thetotalworm@gmail.com>2021-11-17 20:42:11 +0100
commit5bb8f4c9226ec5967bb3a994a37d38435a44223e (patch)
treed7f7de13a433a3b132e1d9f39df582954187b460 /src
parent69715043cad65db6e5adb252746f9ec4c1f61087 (diff)
* remove more Config dependencies from the core
* also use less shitty strings
Diffstat (limited to 'src')
-rw-r--r--src/Config.cpp20
-rw-r--r--src/Config.h10
-rw-r--r--src/DSi.cpp5
-rw-r--r--src/NDS.cpp6
-rw-r--r--src/Platform.h23
-rw-r--r--src/SPI.cpp18
-rw-r--r--src/frontend/SharedConfig.h13
-rw-r--r--src/frontend/qt_sdl/Platform.cpp38
-rw-r--r--src/frontend/qt_sdl/PlatformConfig.cpp22
-rw-r--r--src/frontend/qt_sdl/PlatformConfig.h11
10 files changed, 102 insertions, 64 deletions
diff --git a/src/Config.cpp b/src/Config.cpp
index bdc7237..1163e06 100644
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -28,11 +28,6 @@ namespace Config
const char* kConfigFile = "melonDS.ini";
-int ExternalBIOSEnable;
-char BIOS9Path[1024];
-char BIOS7Path[1024];
-char FirmwarePath[1024];
-
char FirmwareUsername[64];
int FirmwareLanguage;
bool FirmwareOverrideSettings;
@@ -41,21 +36,11 @@ int FirmwareBirthdayDay;
int FirmwareFavouriteColour;
char FirmwareMessage[1024];
-char DSiBIOS9Path[1024];
-char DSiBIOS7Path[1024];
-char DSiFirmwarePath[1024];
-char DSiNANDPath[1024];
-
int RandomizeMAC;
int AudioBitrate;
ConfigEntry ConfigFile[] =
{
- {"ExternalBIOSEnable", 0, &ExternalBIOSEnable, 0, NULL, 0},
- {"BIOS9Path", 1, BIOS9Path, 0, "", 1023},
- {"BIOS7Path", 1, BIOS7Path, 0, "", 1023},
- {"FirmwarePath", 1, FirmwarePath, 0, "", 1023},
-
{"FirmwareUsername", 1, FirmwareUsername, 0, "melonDS", 63},
{"FirmwareLanguage", 0, &FirmwareLanguage, 1, NULL, 0},
{"FirmwareOverrideSettings", 0, &FirmwareOverrideSettings, false, NULL, 0},
@@ -64,11 +49,6 @@ ConfigEntry ConfigFile[] =
{"FirmwareFavouriteColour", 0, &FirmwareFavouriteColour, 0, NULL, 0},
{"FirmwareMessage", 1, FirmwareMessage, 0, "", 1023},
- {"DSiBIOS9Path", 1, DSiBIOS9Path, 0, "", 1023},
- {"DSiBIOS7Path", 1, DSiBIOS7Path, 0, "", 1023},
- {"DSiFirmwarePath", 1, DSiFirmwarePath, 0, "", 1023},
- {"DSiNANDPath", 1, DSiNANDPath, 0, "", 1023},
-
{"RandomizeMAC", 0, &RandomizeMAC, 0, NULL, 0},
{"AudioBitrate", 0, &AudioBitrate, 0, NULL, 0},
diff --git a/src/Config.h b/src/Config.h
index 5948e37..8821be2 100644
--- a/src/Config.h
+++ b/src/Config.h
@@ -41,11 +41,6 @@ bool HasConfigFile(const char* fileName);
void Load();
void Save();
-extern int ExternalBIOSEnable;
-extern char BIOS9Path[1024];
-extern char BIOS7Path[1024];
-extern char FirmwarePath[1024];
-
extern char FirmwareUsername[64];
extern int FirmwareLanguage;
extern bool FirmwareOverrideSettings;
@@ -54,11 +49,6 @@ extern int FirmwareBirthdayDay;
extern int FirmwareFavouriteColour;
extern char FirmwareMessage[1024];
-extern char DSiBIOS9Path[1024];
-extern char DSiBIOS7Path[1024];
-extern char DSiFirmwarePath[1024];
-extern char DSiNANDPath[1024];
-
extern int RandomizeMAC;
extern int AudioBitrate;
diff --git a/src/DSi.cpp b/src/DSi.cpp
index 7560578..88f0265 100644
--- a/src/DSi.cpp
+++ b/src/DSi.cpp
@@ -19,7 +19,6 @@
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
-#include "Config.h"
#include "NDS.h"
#include "DSi.h"
#include "ARM.h"
@@ -605,7 +604,7 @@ bool LoadBIOS()
memset(ARM9iBIOS, 0, 0x10000);
memset(ARM7iBIOS, 0, 0x10000);
- f = Platform::OpenLocalFile(Config::DSiBIOS9Path, "rb");
+ f = Platform::OpenLocalFile(Platform::GetConfigString(Platform::DSi_BIOS9Path), "rb");
if (!f)
{
printf("ARM9i BIOS not found\n");
@@ -622,7 +621,7 @@ bool LoadBIOS()
fclose(f);
}
- f = Platform::OpenLocalFile(Config::DSiBIOS7Path, "rb");
+ f = Platform::OpenLocalFile(Platform::GetConfigString(Platform::DSi_BIOS7Path), "rb");
if (!f)
{
printf("ARM7i BIOS not found\n");
diff --git a/src/NDS.cpp b/src/NDS.cpp
index 7f4cb2d..4ad7aa7 100644
--- a/src/NDS.cpp
+++ b/src/NDS.cpp
@@ -490,9 +490,9 @@ void Reset()
// DS BIOSes are always loaded, even in DSi mode
// we need them for DS-compatible mode
- if (Config::ExternalBIOSEnable)
+ if (Platform::GetConfigBool(Platform::ExternalBIOSEnable))
{
- f = Platform::OpenLocalFile(Config::BIOS9Path, "rb");
+ f = Platform::OpenLocalFile(Platform::GetConfigString(Platform::BIOS9Path), "rb");
if (!f)
{
printf("ARM9 BIOS not found\n");
@@ -509,7 +509,7 @@ void Reset()
fclose(f);
}
- f = Platform::OpenLocalFile(Config::BIOS7Path, "rb");
+ f = Platform::OpenLocalFile(Platform::GetConfigString(Platform::BIOS7Path), "rb");
if (!f)
{
printf("ARM7 BIOS not found\n");
diff --git a/src/Platform.h b/src/Platform.h
index 9b18dc4..2faef50 100644
--- a/src/Platform.h
+++ b/src/Platform.h
@@ -36,11 +36,24 @@ void StopEmu();
enum ConfigEntry
{
+#ifdef JIT_ENABLED
JIT_Enable,
JIT_MaxBlockSize,
JIT_LiteralOptimizations,
JIT_BranchOptimizations,
JIT_FastMemory,
+#endif
+
+ ExternalBIOSEnable,
+
+ BIOS9Path,
+ BIOS7Path,
+ FirmwarePath,
+
+ DSi_BIOS9Path,
+ DSi_BIOS7Path,
+ DSi_FirmwarePath,
+ DSi_NANDPath,
DLDI_Enable,
DLDI_ImagePath,
@@ -79,11 +92,11 @@ std::string GetConfigString(ConfigEntry entry);
// Looks in the user's data directory first, then the system's.
// If on Windows or a portable UNIX build, this simply calls OpenLocalFile().
-FILE* OpenFile(const char* path, const char* mode, bool mustexist=false);
-FILE* OpenLocalFile(const char* path, const char* mode);
-FILE* OpenDataFile(const char* path);
+FILE* OpenFile(std::string path, std::string mode, bool mustexist=false);
+FILE* OpenLocalFile(std::string path, std::string mode);
+FILE* OpenDataFile(std::string path);
-inline bool FileExists(const char* name)
+inline bool FileExists(std::string name)
{
FILE* f = OpenFile(name, "rb");
if (!f) return false;
@@ -91,7 +104,7 @@ inline bool FileExists(const char* name)
return true;
}
-inline bool LocalFileExists(const char* name)
+inline bool LocalFileExists(std::string name)
{
FILE* f = OpenLocalFile(name, "rb");
if (!f) return false;
diff --git a/src/SPI.cpp b/src/SPI.cpp
index 2f990c0..5ae0e21 100644
--- a/src/SPI.cpp
+++ b/src/SPI.cpp
@@ -34,7 +34,7 @@
namespace SPI_Firmware
{
-char FirmwarePath[1024];
+std::string FirmwarePath;
u8* Firmware;
u32 FirmwareLength;
u32 FirmwareMask;
@@ -83,8 +83,8 @@ bool VerifyCRC16(u32 start, u32 offset, u32 len, u32 crcoffset)
bool Init()
{
- memset(FirmwarePath, 0, sizeof(FirmwarePath));
- Firmware = NULL;
+ FirmwarePath = "";
+ Firmware = nullptr;
return true;
}
@@ -147,11 +147,7 @@ void LoadFirmwareFromFile(FILE* f)
fclose(f);
// take a backup
- char fwBackupPath[sizeof(FirmwarePath) + 4];
- int fplen = strlen(FirmwarePath);
- strcpy(&fwBackupPath[0], FirmwarePath);
- strncpy(&fwBackupPath[fplen], ".bak", sizeof(fwBackupPath) - fplen);
- fwBackupPath[fplen+4] = '\0';
+ std::string fwBackupPath = FirmwarePath + ".bak";
f = Platform::OpenLocalFile(fwBackupPath, "rb");
if (!f)
{
@@ -203,9 +199,9 @@ void Reset()
Firmware = NULL;
if (NDS::ConsoleType == 1)
- strncpy(FirmwarePath, Config::DSiFirmwarePath, sizeof(FirmwarePath) - 1);
+ FirmwarePath = Platform::GetConfigString(Platform::DSi_FirmwarePath);
else
- strncpy(FirmwarePath, Config::FirmwarePath, sizeof(FirmwarePath) - 1);
+ FirmwarePath = Platform::GetConfigString(Platform::FirmwarePath);
FILE* f = Platform::OpenLocalFile(FirmwarePath, "rb");
if (!f)
@@ -231,7 +227,7 @@ void Reset()
if (!f || Config::FirmwareOverrideSettings)
LoadUserSettingsFromConfig();
-
+
// fix touchscreen coords
*(u16*)&Firmware[userdata+0x58] = 0;
*(u16*)&Firmware[userdata+0x5A] = 0;
diff --git a/src/frontend/SharedConfig.h b/src/frontend/SharedConfig.h
index 147f042..3598e74 100644
--- a/src/frontend/SharedConfig.h
+++ b/src/frontend/SharedConfig.h
@@ -26,6 +26,17 @@ extern int ConsoleType;
extern int DirectBoot;
extern int SavestateRelocSRAM;
+extern int ExternalBIOSEnable;
+
+extern char BIOS9Path[1024];
+extern char BIOS7Path[1024];
+extern char FirmwarePath[1024];
+
+extern char DSiBIOS9Path[1024];
+extern char DSiBIOS7Path[1024];
+extern char DSiFirmwarePath[1024];
+extern char DSiNANDPath[1024];
+
}
-#endif \ No newline at end of file
+#endif
diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp
index 0d31e27..283b497 100644
--- a/src/frontend/qt_sdl/Platform.cpp
+++ b/src/frontend/qt_sdl/Platform.cpp
@@ -43,6 +43,7 @@
#endif
#include <QStandardPaths>
+#include <QString>
#include <QDir>
#include <QThread>
#include <QSemaphore>
@@ -133,7 +134,9 @@ int GetConfigInt(ConfigEntry entry)
switch (entry)
{
+#ifdef JIT_ENABLED
case JIT_MaxBlockSize: return Config::JIT_MaxBlockSize;
+#endif
case DLDI_ImageSize: return imgsizes[Config::DLDISize];
@@ -147,10 +150,14 @@ bool GetConfigBool(ConfigEntry entry)
{
switch (entry)
{
+#ifdef JIT_ENABLED
case JIT_Enable: return Config::JIT_Enable != 0;
case JIT_LiteralOptimizations: return Config::JIT_LiteralOptimisations != 0;
case JIT_BranchOptimizations: return Config::JIT_BranchOptimisations != 0;
case JIT_FastMemory: return Config::JIT_FastMemory != 0;
+#endif
+
+ case ExternalBIOSEnable: return Config::ExternalBIOSEnable != 0;
case DLDI_Enable: return Config::DLDIEnable != 0;
case DLDI_ReadOnly: return Config::DLDIReadOnly != 0;
@@ -168,6 +175,15 @@ std::string GetConfigString(ConfigEntry entry)
{
switch (entry)
{
+ case BIOS9Path: return Config::BIOS9Path;
+ case BIOS7Path: return Config::BIOS7Path;
+ case FirmwarePath: return Config::FirmwarePath;
+
+ case DSi_BIOS9Path: return Config::DSiBIOS9Path;
+ case DSi_BIOS7Path: return Config::DSiBIOS7Path;
+ case DSi_FirmwarePath: return Config::DSiFirmwarePath;
+ case DSi_NANDPath: return Config::DSiNANDPath;
+
case DLDI_ImagePath: return Config::DLDISDPath;
case DLDI_FolderPath: return Config::DLDIFolderPath;
@@ -179,9 +195,9 @@ std::string GetConfigString(ConfigEntry entry)
}
-FILE* OpenFile(const char* path, const char* mode, bool mustexist)
+FILE* OpenFile(std::string path, std::string mode, bool mustexist)
{
- QFile f(path);
+ QFile f(path.c_str());
if (mustexist && !f.exists())
{
@@ -189,11 +205,11 @@ FILE* OpenFile(const char* path, const char* mode, bool mustexist)
}
QIODevice::OpenMode qmode;
- if (strlen(mode) > 1 && mode[0] == 'r' && mode[1] == '+')
+ if (mode.length() > 1 && mode[0] == 'r' && mode[1] == '+')
{
qmode = QIODevice::OpenModeFlag::ReadWrite;
}
- else if (strlen(mode) > 1 && mode[0] == 'w' && mode[1] == '+')
+ else if (mode.length() > 1 && mode[0] == 'w' && mode[1] == '+')
{
qmode = QIODevice::OpenModeFlag::Truncate | QIODevice::OpenModeFlag::ReadWrite;
}
@@ -207,36 +223,36 @@ FILE* OpenFile(const char* path, const char* mode, bool mustexist)
}
f.open(qmode);
- FILE* file = fdopen(dup(f.handle()), mode);
+ FILE* file = fdopen(dup(f.handle()), mode.c_str());
f.close();
return file;
}
-FILE* OpenLocalFile(const char* path, const char* mode)
+FILE* OpenLocalFile(std::string path, std::string mode)
{
- QDir dir(path);
+ QDir dir(path.c_str());
QString fullpath;
if (dir.isAbsolute())
{
// If it's an absolute path, just open that.
- fullpath = path;
+ fullpath = path.c_str();
}
else
{
#ifdef PORTABLE
- fullpath = QString(EmuDirectory) + QDir::separator() + path;
+ fullpath = QString(EmuDirectory) + QDir::separator() + path.c_str();
#else
// Check user configuration directory
QDir config(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation));
config.mkdir("melonDS");
fullpath = config.absolutePath() + "/melonDS/";
- fullpath.append(path);
+ fullpath.append(path.c_str());
#endif
}
- return OpenFile(fullpath.toUtf8(), mode, mode[0] != 'w');
+ return OpenFile(fullpath.toStdString(), mode, mode[0] != 'w');
}
Thread* Thread_Create(std::function<void()> func)
diff --git a/src/frontend/qt_sdl/PlatformConfig.cpp b/src/frontend/qt_sdl/PlatformConfig.cpp
index a224b66..70fc852 100644
--- a/src/frontend/qt_sdl/PlatformConfig.cpp
+++ b/src/frontend/qt_sdl/PlatformConfig.cpp
@@ -71,6 +71,17 @@ int JIT_LiteralOptimisations = true;
int JIT_FastMemory = true;
#endif
+int ExternalBIOSEnable;
+
+char BIOS9Path[1024];
+char BIOS7Path[1024];
+char FirmwarePath[1024];
+
+char DSiBIOS9Path[1024];
+char DSiBIOS7Path[1024];
+char DSiFirmwarePath[1024];
+char DSiNANDPath[1024];
+
int DLDIEnable;
char DLDISDPath[1024];
int DLDISize;
@@ -206,6 +217,17 @@ ConfigEntry PlatformConfigFile[] =
#endif
#endif
+ {"ExternalBIOSEnable", 0, &ExternalBIOSEnable, 0, NULL, 0},
+
+ {"BIOS9Path", 1, BIOS9Path, 0, "", 1023},
+ {"BIOS7Path", 1, BIOS7Path, 0, "", 1023},
+ {"FirmwarePath", 1, FirmwarePath, 0, "", 1023},
+
+ {"DSiBIOS9Path", 1, DSiBIOS9Path, 0, "", 1023},
+ {"DSiBIOS7Path", 1, DSiBIOS7Path, 0, "", 1023},
+ {"DSiFirmwarePath", 1, DSiFirmwarePath, 0, "", 1023},
+ {"DSiNANDPath", 1, DSiNANDPath, 0, "", 1023},
+
{"DLDIEnable", 0, &DLDIEnable, 0, NULL, 0},
{"DLDISDPath", 1, DLDISDPath, 0, "dldi.bin", 1023},
{"DLDISize", 0, &DLDISize, 0, NULL, 0},
diff --git a/src/frontend/qt_sdl/PlatformConfig.h b/src/frontend/qt_sdl/PlatformConfig.h
index 891606c..0a224e9 100644
--- a/src/frontend/qt_sdl/PlatformConfig.h
+++ b/src/frontend/qt_sdl/PlatformConfig.h
@@ -87,6 +87,17 @@ extern int JIT_LiteralOptimisations;
extern int JIT_FastMemory;
#endif
+extern int ExternalBIOSEnable;
+
+extern char BIOS9Path[1024];
+extern char BIOS7Path[1024];
+extern char FirmwarePath[1024];
+
+extern char DSiBIOS9Path[1024];
+extern char DSiBIOS7Path[1024];
+extern char DSiFirmwarePath[1024];
+extern char DSiNANDPath[1024];
+
extern int DLDIEnable;
extern char DLDISDPath[1024];
extern int DLDISize;