diff --git a/src/Util.cpp b/src/Util.cpp index 4e281b95..3cf0c758 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -428,11 +428,9 @@ bool utilWriteBMPFile(const char *fileName, int w, int h, uint8_t *pix) } #endif /* !__LIBRETRO__ */ -extern bool cpuIsMultiBoot; - bool utilIsGBAImage(const char *file) { - cpuIsMultiBoot = false; + coreOptions.cpuIsMultiBoot = false; if (strlen(file) > 4) { const char *p = strrchr(file, '.'); @@ -441,7 +439,7 @@ bool utilIsGBAImage(const char *file) (_stricmp(p, ".bin") == 0) || (_stricmp(p, ".elf") == 0)) return true; if (_stricmp(p, ".mb") == 0) { - cpuIsMultiBoot = true; + coreOptions.cpuIsMultiBoot = true; return true; } } @@ -870,7 +868,7 @@ void utilGBAFindSave(const int size) } rtcEnable(rtcFound); rtcEnableRumble(!rtcFound); - saveType = detectedSaveType; + coreOptions.saveType = detectedSaveType; flashSetSize(flashSize); } diff --git a/src/common/ConfigManager.cpp b/src/common/ConfigManager.cpp index 2bdc7088..cf85f5c8 100644 --- a/src/common/ConfigManager.cpp +++ b/src/common/ConfigManager.cpp @@ -99,11 +99,6 @@ char path[2048]; dictionary* preferences; -bool cpuIsMultiBoot = false; -bool mirroringEnable = true; -bool parseDebug = true; -bool speedHack = false; -bool speedup = false; const char* batteryDir; const char* biosFileNameGB; const char* biosFileNameGBA; @@ -117,36 +112,23 @@ int autoFireMaxCount = 1; int autoFrameSkip = 0; int autoPatch; int captureFormat = 0; -int cheatsEnabled = true; int colorizerHack = 0; -int cpuDisableSfx = false; -int cpuSaveType = 0; int disableStatusMessages = 0; int filter = kStretch2x; int frameSkip = 1; int fullScreen; int ifbType = kIFBNone; -int layerEnable = 0xff00; -int layerSettings = 0xff00; int openGL; int optFlashSize; int optPrintUsage; int pauseWhenInactive = 0; int preparedCheats = 0; int rewindTimer = 0; -int rtcEnabled; -int saveType = GBA_SAVE_AUTO; int showSpeed; int showSpeedTransparent; -int skipBios = 0; -int skipSaveGameBattery = true; -int skipSaveGameCheats = false; -int useBios = 0; -int winGbPrinterEnabled; uint32_t throttle = 100; uint32_t speedup_throttle = 100; uint32_t speedup_frame_skip = 9; -bool speedup_throttle_frame_skip = false; bool allowKeyboardBackgroundInput = false; bool allowJoystickBackgroundInput = true; @@ -179,14 +161,14 @@ struct option argOptions[] = { { "border-on", no_argument, &gbBorderOn, 1 }, { "capture-format", required_argument, 0, OPT_CAPTURE_FORMAT }, { "cheat", required_argument, 0, OPT_CHEAT }, - { "cheats-enabled", no_argument, &cheatsEnabled, 1 }, + { "cheats-enabled", no_argument, &coreOptions.cheatsEnabled, 1 }, { "color-option", no_argument, &gbColorOption, 1 }, { "colorizer-hack", no_argument, &colorizerHack, 1 }, { "config", required_argument, 0, 'c' }, - { "cpu-disable-sfx", no_argument, &cpuDisableSfx, 1 }, + { "cpu-disable-sfx", no_argument, &coreOptions.cpuDisableSfx, 1 }, { "cpu-save-type", required_argument, 0, OPT_CPU_SAVE_TYPE }, { "debug", no_argument, 0, 'd' }, - { "disable-sfx", no_argument, &cpuDisableSfx, 1 }, + { "disable-sfx", no_argument, &coreOptions.cpuDisableSfx, 1 }, { "disable-status-messages", no_argument, &disableStatusMessages, 1 }, { "dotcode-file-name-load", required_argument, 0, OPT_DOTCODE_FILE_NAME_LOAD }, { "dotcode-file-name-save", required_argument, 0, OPT_DOTCODE_FILE_NAME_SAVE }, @@ -202,7 +184,7 @@ struct option argOptions[] = { { "gb-emulator-type", required_argument, 0, OPT_GB_EMULATOR_TYPE }, { "gb-frame-skip", required_argument, 0, OPT_GB_FRAME_SKIP }, { "gb-palette-option", required_argument, 0, OPT_GB_PALETTE_OPTION }, - { "gb-printer", no_argument, &winGbPrinterEnabled, 1 }, + { "gb-printer", no_argument, &coreOptions.winGbPrinterEnabled, 1 }, { "gdb", required_argument, 0, 'G' }, { "help", no_argument, &optPrintUsage, 1 }, { "ifb-filter", required_argument, 0, 'I' }, @@ -213,7 +195,7 @@ struct option argOptions[] = { { "no-opengl", no_argument, &openGL, 0 }, { "no-patch", no_argument, &autoPatch, 0 }, { "no-pause-when-inactive", no_argument, &pauseWhenInactive, 0 }, - { "no-rtc", no_argument, &rtcEnabled, 0 }, + { "no-rtc", no_argument, &coreOptions.rtcEnabled, 0 }, { "no-show-speed", no_argument, &showSpeed, 0 }, { "opengl", required_argument, 0, 'O' }, { "opengl-bilinear", no_argument, &openGL, 2 }, @@ -223,32 +205,32 @@ struct option argOptions[] = { { "pause-when-inactive", no_argument, &pauseWhenInactive, 1 }, { "profile", optional_argument, 0, 'p' }, { "rewind-timer", required_argument, 0, OPT_REWIND_TIMER }, - { "rtc", no_argument, &rtcEnabled, 1 }, + { "rtc", no_argument, &coreOptions.rtcEnabled, 1 }, { "rtc-enabled", required_argument, 0, OPT_RTC_ENABLED }, - { "save-auto", no_argument, &cpuSaveType, 0 }, + { "save-auto", no_argument, &coreOptions.cpuSaveType, 0 }, { "save-dir", required_argument, 0, OPT_SAVE_DIR }, - { "save-eeprom", no_argument, &cpuSaveType, 1 }, - { "save-flash", no_argument, &cpuSaveType, 3 }, - { "save-none", no_argument, &cpuSaveType, 5 }, - { "save-sensor", no_argument, &cpuSaveType, 4 }, - { "save-sram", no_argument, &cpuSaveType, 2 }, + { "save-eeprom", no_argument, &coreOptions.cpuSaveType, 1 }, + { "save-flash", no_argument, &coreOptions.cpuSaveType, 3 }, + { "save-none", no_argument, &coreOptions.cpuSaveType, 5 }, + { "save-sensor", no_argument, &coreOptions.cpuSaveType, 4 }, + { "save-sram", no_argument, &coreOptions.cpuSaveType, 2 }, { "save-type", required_argument, 0, 't' }, { "screen-shot-dir", required_argument, 0, OPT_SCREEN_SHOT_DIR }, { "show-speed", required_argument, 0, OPT_SHOW_SPEED }, { "show-speed-detailed", no_argument, &showSpeed, 2 }, { "show-speed-normal", no_argument, &showSpeed, 1 }, { "show-speed-transparent", required_argument, 0, OPT_SHOW_SPEED_TRANSPARENT }, - { "skip-bios", no_argument, &skipBios, 1 }, - { "skip-save-game-battery", no_argument, &skipSaveGameBattery, 1 }, - { "skip-save-game-cheats", no_argument, &skipSaveGameCheats, 1 }, + { "skip-bios", no_argument, &coreOptions.skipBios, 1 }, + { "skip-save-game-battery", no_argument, &coreOptions.skipSaveGameBattery, 1 }, + { "skip-save-game-cheats", no_argument, &coreOptions.skipSaveGameCheats, 1 }, { "sound-filtering", required_argument, 0, OPT_SOUND_FILTERING }, { "throttle", required_argument, 0, 'T' }, { "speedup-throttle", required_argument, 0, OPT_SPEEDUP_THROTTLE }, { "speedup-frame-skip", required_argument, 0, OPT_SPEEDUP_FRAME_SKIP }, { "no-speedup-throttle-frame-skip", no_argument, 0, OPT_NO_SPEEDUP_THROTTLE_FRAME_SKIP }, - { "use-bios", no_argument, &useBios, 1 }, + { "use-bios", no_argument, &coreOptions.useBios, 1 }, { "verbose", required_argument, 0, 'v' }, - { "win-gb-printer-enabled", no_argument, &winGbPrinterEnabled, 1 }, + { "win-gb-printer-enabled", no_argument, &coreOptions.winGbPrinterEnabled, 1 }, { NULL, no_argument, NULL, 0 } @@ -295,8 +277,8 @@ void ValidateConfig() if (filter < kStretch1x || filter >= kInvalidFilter) filter = kStretch2x; - if (cpuSaveType < 0 || cpuSaveType > 5) - cpuSaveType = 0; + if (coreOptions.cpuSaveType < 0 || coreOptions.cpuSaveType > 5) + coreOptions.cpuSaveType = 0; if (optFlashSize != 0 && optFlashSize != 1) optFlashSize = 0; if (ifbType < kIFBNone || ifbType >= kInvalidIFBFilter) @@ -322,10 +304,10 @@ void LoadConfig() biosFileNameGBA = ReadPrefString("biosFileGBA"); biosFileNameGBC = ReadPrefString("biosFileGBC"); captureFormat = ReadPref("captureFormat", 0); - cheatsEnabled = ReadPref("cheatsEnabled", 0); + coreOptions.cheatsEnabled = ReadPref("cheatsEnabled", 0); colorizerHack = ReadPref("colorizerHack", 0); - cpuDisableSfx = ReadPref("disableSfx", 0); - cpuSaveType = ReadPrefHex("saveType"); + coreOptions.cpuDisableSfx = ReadPref("disableSfx", 0); + coreOptions.cpuSaveType = ReadPrefHex("saveType"); disableStatusMessages = ReadPrefHex("disableStatus"); filter = ReadPref("filter", 0); frameSkip = ReadPref("frameSkip", 0); @@ -347,23 +329,23 @@ void LoadConfig() optFlashSize = ReadPref("flashSize", 0); pauseWhenInactive = ReadPref("pauseWhenInactive", 1); rewindTimer = ReadPref("rewindTimer", 0); - rtcEnabled = ReadPref("rtcEnabled", 0); + coreOptions.rtcEnabled = ReadPref("rtcEnabled", 0); saveDir = ReadPrefString("saveDir"); saveDotCodeFile = ReadPrefString("saveDotCodeFile"); screenShotDir = ReadPrefString("screenShotDir"); showSpeed = ReadPref("showSpeed", 0); showSpeedTransparent = ReadPref("showSpeedTransparent", 1); - skipBios = ReadPref("skipBios", 0); - skipSaveGameBattery = ReadPref("skipSaveGameBattery", 1); - skipSaveGameCheats = ReadPref("skipSaveGameCheats", 0); + coreOptions.skipBios = ReadPref("skipBios", 0); + coreOptions.skipSaveGameBattery = ReadPref("skipSaveGameBattery", 1); + coreOptions.skipSaveGameCheats = ReadPref("skipSaveGameCheats", 0); soundFiltering = (float)ReadPref("gbaSoundFiltering", 50) / 100.0f; soundInterpolation = ReadPref("gbaSoundInterpolation", 1); throttle = ReadPref("throttle", 100); speedup_throttle = ReadPref("speedupThrottle", 100); speedup_frame_skip = ReadPref("speedupFrameSkip", 9); - speedup_throttle_frame_skip = ReadPref("speedupThrottleFrameSkip", 0); - useBios = ReadPrefHex("useBiosGBA"); - winGbPrinterEnabled = ReadPref("gbPrinter", 0); + coreOptions.speedup_throttle_frame_skip = ReadPref("speedupThrottleFrameSkip", 0); + coreOptions.useBios = ReadPrefHex("useBiosGBA"); + coreOptions.winGbPrinterEnabled = ReadPref("gbPrinter", 0); int soundQuality = (ReadPrefHex("soundQuality", 1)); switch (soundQuality) { @@ -400,7 +382,7 @@ void LoadConfig() else flashSetSize(0x20000); - rtcEnable(rtcEnabled ? true : false); + rtcEnable(coreOptions.rtcEnabled ? true : false); agbPrintEnable(agbPrint ? true : false); for (int i = 0; i < 24;) { @@ -677,7 +659,7 @@ int ReadOpts(int argc, char ** argv) autoFireMaxCount = 1; break; case 'b': - useBios = true; + coreOptions.useBios = true; if (optarg == NULL) { log("Missing BIOS file name\n"); break; @@ -752,7 +734,7 @@ int ReadOpts(int argc, char ** argv) break; #endif case 'N': - parseDebug = false; + coreOptions.parseDebug = false; break; case 'F': fullScreen = 1; @@ -809,7 +791,7 @@ int ReadOpts(int argc, char ** argv) int a = atoi(optarg); if (a < 0 || a > 5) a = 0; - cpuSaveType = a; + coreOptions.cpuSaveType = a; } break; case 'v': @@ -863,7 +845,7 @@ int ReadOpts(int argc, char ** argv) case OPT_RTC_ENABLED: // --rtc-enabled if (optarg) { - rtcEnabled = atoi(optarg); + coreOptions.rtcEnabled = atoi(optarg); } break; @@ -949,7 +931,7 @@ int ReadOpts(int argc, char ** argv) case OPT_CPU_SAVE_TYPE: // --cpu-save-type if (optarg) { - cpuSaveType = atoi(optarg); + coreOptions.cpuSaveType = atoi(optarg); } break; @@ -957,8 +939,8 @@ int ReadOpts(int argc, char ** argv) // --opt-flash-size if (optarg) { optFlashSize = atoi(optarg); - if (optFlashSize < 0 || optFlashSize > 1) - optFlashSize = 0; + if (optFlashSize < 0 || optFlashSize > 1) + optFlashSize = 0; } break; @@ -971,17 +953,17 @@ int ReadOpts(int argc, char ** argv) // --dotcode-file-name-save saveDotCodeFile = optarg; break; - case OPT_SPEEDUP_THROTTLE: - if (optarg) - speedup_throttle = atoi(optarg); - break; - case OPT_SPEEDUP_FRAME_SKIP: - if (optarg) - speedup_frame_skip = atoi(optarg); - break; - case OPT_NO_SPEEDUP_THROTTLE_FRAME_SKIP: - speedup_throttle_frame_skip = false; - break; + case OPT_SPEEDUP_THROTTLE: + if (optarg) + speedup_throttle = atoi(optarg); + break; + case OPT_SPEEDUP_FRAME_SKIP: + if (optarg) + speedup_frame_skip = atoi(optarg); + break; + case OPT_NO_SPEEDUP_THROTTLE_FRAME_SKIP: + coreOptions.speedup_throttle_frame_skip = false; + break; } } return op; diff --git a/src/common/ConfigManager.h b/src/common/ConfigManager.h index 4dd8f36d..2f1d0cb7 100644 --- a/src/common/ConfigManager.h +++ b/src/common/ConfigManager.h @@ -20,11 +20,27 @@ #define MAX_CHEATS 16384 -extern bool cpuIsMultiBoot; -extern bool mirroringEnable; -extern bool parseDebug; -extern bool speedHack; -extern bool speedup; +extern struct CoreOptions { + bool cpuIsMultiBoot = false; + bool mirroringEnable = true; + bool parseDebug = true; + bool speedHack = false; + bool speedup = false; + bool speedup_throttle_frame_skip = false; + int cheatsEnabled = 1; + int cpuDisableSfx = 0; + int cpuSaveType = 0; + int layerSettings = 0xff00; + int layerEnable = 0xff00; + int rtcEnabled = 0; + int saveType = 0; + int skipBios = 0; + int skipSaveGameBattery = 1; + int skipSaveGameCheats = 0; + int useBios = 0; + int winGbPrinterEnabled = 1; +} coreOptions; + extern const char *biosFileNameGB; extern const char *biosFileNameGBA; extern const char *biosFileNameGBC; @@ -35,35 +51,22 @@ extern int autoFireMaxCount; extern int autoFrameSkip; extern int autoPatch; extern int captureFormat; -extern int cheatsEnabled; extern int colorizerHack; -extern int cpuDisableSfx; -extern int cpuSaveType; extern int disableStatusMessages; extern int filter; extern int frameSkip; extern int fullScreen; extern int ifbType; -extern int layerEnable; -extern int layerSettings; extern int openGL; extern int optFlashSize; extern int optPrintUsage; extern int pauseWhenInactive; extern int rewindTimer; -extern int rtcEnabled; -extern int saveType; extern int showSpeed; extern int showSpeedTransparent; -extern int skipBios; -extern int skipSaveGameBattery; -extern int skipSaveGameCheats; -extern int useBios; -extern int winGbPrinterEnabled; extern uint32_t throttle; extern uint32_t speedup_throttle; extern uint32_t speedup_frame_skip; -extern bool speedup_throttle_frame_skip; extern bool allowKeyboardBackgroundInput; extern bool allowJoystickBackgroundInput; diff --git a/src/common/SoundSDL.cpp b/src/common/SoundSDL.cpp index 43b532f0..a927a1e8 100644 --- a/src/common/SoundSDL.cpp +++ b/src/common/SoundSDL.cpp @@ -40,7 +40,7 @@ void SoundSDL::soundCallback(void* data, uint8_t* stream, int len) { } bool SoundSDL::should_wait() { - return emulating && !speedup && current_rate && !gba_joybus_active; + return emulating && !coreOptions.speedup && current_rate && !gba_joybus_active; } std::size_t SoundSDL::buffer_size() { diff --git a/src/gb/GB.cpp b/src/gb/GB.cpp index 25eb75af..60c571bd 100644 --- a/src/gb/GB.cpp +++ b/src/gb/GB.cpp @@ -1067,7 +1067,7 @@ void gbWriteMemory(uint16_t address, uint8_t value) EmuReseted = false; gbMemory[0xff02] = value; if (gbSerialOn && (GetLinkMode() == LINK_GAMEBOY_IPC || GetLinkMode() == LINK_GAMEBOY_SOCKET - || GetLinkMode() == LINK_DISCONNECTED || winGbPrinterEnabled)) { + || GetLinkMode() == LINK_DISCONNECTED || coreOptions.winGbPrinterEnabled)) { gbSerialTicks = GBSERIAL_CLOCK_TICKS; @@ -2205,7 +2205,7 @@ void gbCPUInit(const char* biosFileName, bool useBiosFile) if (!(gbHardware & 7)) return; - useBios = false; + coreOptions.useBios = false; if (useBiosFile) { int expectedSize = (gbHardware & 2) ? 0x900 : 0x100; int size = expectedSize; @@ -2214,7 +2214,7 @@ void gbCPUInit(const char* biosFileName, bool useBiosFile) bios, size)) { if (size == expectedSize) - useBios = true; + coreOptions.useBios = true; else systemMessage(MSG_INVALID_BIOS_FILE_SIZE, N_("Invalid BOOTROM file size")); } @@ -2565,7 +2565,7 @@ void gbReset() } // used for the handling of the gb Boot Rom - if ((gbHardware & 7) && (bios != NULL) && useBios && !skipBios) { + if ((gbHardware & 7) && (bios != NULL) && coreOptions.useBios && !coreOptions.skipBios) { if (gbHardware & 5) { memcpy((uint8_t*)(gbMemory), (uint8_t*)(gbRom), 0x1000); memcpy((uint8_t*)(gbMemory), (uint8_t*)(bios), 0x100); @@ -3632,7 +3632,7 @@ static bool gbWriteSaveState(gzFile gzFile) utilGzWrite(gzFile, &gbRom[0x134], 15); - utilWriteInt(gzFile, useBios); + utilWriteInt(gzFile, coreOptions.useBios); utilWriteInt(gzFile, inBios); utilWriteData(gzFile, gbSaveGameStruct); @@ -3749,8 +3749,8 @@ static bool gbReadSaveState(gzFile gzFile) ub = utilReadInt(gzFile) ? true : false; ib = utilReadInt(gzFile) ? true : false; - if ((ub != useBios) && (ib)) { - if (useBios) + if ((ub != coreOptions.useBios) && (ib)) { + if (coreOptions.useBios) systemMessage(MSG_SAVE_GAME_NOT_USING_BIOS, N_("Save game is not using the BIOS files")); else @@ -3806,7 +3806,7 @@ static bool gbReadSaveState(gzFile gzFile) if (version >= 11) { utilGzRead(gzFile, &gbDataTAMA5, sizeof(gbDataTAMA5)); if (gbTAMA5ram != NULL) { - if (skipSaveGameBattery) { + if (coreOptions.skipSaveGameBattery) { utilGzSeek(gzFile, gbTAMA5ramSize, SEEK_CUR); } else { utilGzRead(gzFile, gbTAMA5ram, gbTAMA5ramSize); @@ -3839,14 +3839,14 @@ static bool gbReadSaveState(gzFile gzFile) if (gbRamSize && gbRam) { if (version < 11) - if (skipSaveGameBattery) { + if (coreOptions.skipSaveGameBattery) { utilGzSeek(gzFile, gbRamSize, SEEK_CUR); //skip } else { utilGzRead(gzFile, gbRam, gbRamSize); //read } else { int ramSize = utilReadInt(gzFile); - if (skipSaveGameBattery) { + if (coreOptions.skipSaveGameBattery) { utilGzSeek(gzFile, (gbRamSize > ramSize) ? ramSize : gbRamSize, SEEK_CUR); //skip } else { utilGzRead(gzFile, gbRam, (gbRamSize > ramSize) ? ramSize : gbRamSize); //read @@ -3978,7 +3978,7 @@ static bool gbReadSaveState(gzFile gzFile) systemDrawScreen(); if (version > GBSAVE_GAME_VERSION_1) { - if (skipSaveGameCheats) { + if (coreOptions.skipSaveGameCheats) { gbCheatsReadGameSkip(gzFile, version); } else { gbCheatsReadGame(gzFile, version); @@ -4967,7 +4967,7 @@ void gbEmulate(int ticksToStop) speedup_throttle_set = true; } - if (speedup_throttle_frame_skip) + if (coreOptions.speedup_throttle_frame_skip) framesToSkip += std::ceil(double(speedup_throttle) / 100.0) - 1; } } @@ -5036,10 +5036,10 @@ void gbEmulate(int ticksToStop) newmask = (gbJoymask[0] >> 10); - speedup = false; + coreOptions.speedup = false; if (newmask & 1 && !speedup_throttle_set) - speedup = true; + coreOptions.speedup = true; gbCapture = (newmask & 2) ? true : false; @@ -5201,7 +5201,7 @@ void gbEmulate(int ticksToStop) gbDrawLine(); } else if ((register_LY == 144) && (!systemFrameSkip)) { int framesToSkip = systemFrameSkip; - //if (speedup) + //if (coreOptions.speedup) // framesToSkip = 9; // try 6 FPS during speedup if ((gbFrameSkipCount >= framesToSkip) || (gbWhiteScreen == 1)) { gbWhiteScreen = 2; @@ -5529,7 +5529,7 @@ unsigned int gbWriteSaveState(uint8_t* data) utilWriteMem(data, &gbRom[0x134], 15); - utilWriteIntMem(data, useBios); + utilWriteIntMem(data, coreOptions.useBios); utilWriteIntMem(data, inBios); utilWriteDataMem(data, gbSaveGameStruct); @@ -5616,8 +5616,8 @@ bool gbReadSaveState(const uint8_t* data) ub = utilReadIntMem(data) ? true : false; ib = utilReadIntMem(data) ? true : false; - if ((ub != useBios) && (ib)) { - if (useBios) + if ((ub != coreOptions.useBios) && (ib)) { + if (coreOptions.useBios) systemMessage(MSG_SAVE_GAME_NOT_USING_BIOS, N_("Save game is not using the BIOS files")); else diff --git a/src/gb/gbCheats.cpp b/src/gb/gbCheats.cpp index 5e476dde..bf8207f7 100644 --- a/src/gb/gbCheats.cpp +++ b/src/gb/gbCheats.cpp @@ -434,7 +434,7 @@ bool gbCheatReadGSCodeFile(const char* fileName) // Used to emulated GG codes uint8_t gbCheatRead(uint16_t address) { - if (!cheatsEnabled) + if (!coreOptions.cheatsEnabled) return gbMemoryMap[address >> 12][address & 0xFFF]; for (int i = 0; i < gbCheatNumber; i++) { @@ -456,7 +456,7 @@ uint8_t gbCheatRead(uint16_t address) // Used to emulate GS codes. void gbCheatWrite(bool reboot) { - if (cheatsEnabled) { + if (coreOptions.cheatsEnabled) { uint16_t address = 0; if (gbNextCheat >= gbCheatNumber) diff --git a/src/gb/gbGfx.cpp b/src/gb/gbGfx.cpp index a819d138..c019cbf7 100644 --- a/src/gb/gbGfx.cpp +++ b/src/gb/gbGfx.cpp @@ -1,6 +1,7 @@ #include #include "../Util.h" +#include "../common/ConfigManager.h" #include "gbGlobals.h" #include "gbSGB.h" @@ -42,7 +43,6 @@ uint8_t gbInvertTab[256] = { uint16_t gbLineMix[160]; uint16_t gbWindowColor[160]; extern int inUseRegister_WY; -extern int layerSettings; void gbRenderLine() { @@ -104,7 +104,7 @@ void gbRenderLine() int tile_pattern_address = tile_pattern + tile * 16 + by * 2; if (register_LCDC & 0x80) { - if ((register_LCDC & 0x01 || gbCgbMode) && (layerSettings & 0x0100)) { + if ((register_LCDC & 0x01 || gbCgbMode) && (coreOptions.layerSettings & 0x0100)) { while (x < 160) { uint8_t tile_a = 0; @@ -215,7 +215,7 @@ void gbRenderLine() // LCDC.0 also enables/disables the window in !gbCgbMode ?!?! // (tested on real hardware) // This fixes Last Bible II & Zankurou Musouken - if ((register_LCDC & 0x01 || gbCgbMode) && (register_LCDC & 0x20) && (layerSettings & 0x2000) && (gbWindowLine != -2)) { + if ((register_LCDC & 0x01 || gbCgbMode) && (register_LCDC & 0x20) && (coreOptions.layerSettings & 0x2000) && (gbWindowLine != -2)) { int i = 0; // Fix (accurate emulation) for most of the window display problems // (ie. Zen - Intergalactic Ninja, Urusei Yatsura...). @@ -536,7 +536,7 @@ void gbDrawSprites(bool draw) if (!(register_LCDC & 0x80)) return; - if ((register_LCDC & 2) && (layerSettings & 0x1000)) { + if ((register_LCDC & 2) && (coreOptions.layerSettings & 0x1000)) { int yc = register_LY; int address = 0xfe00; diff --git a/src/gba/Flash.cpp b/src/gba/Flash.cpp index 2da90b82..bee83b19 100644 --- a/src/gba/Flash.cpp +++ b/src/gba/Flash.cpp @@ -85,16 +85,16 @@ uint8_t flashRead(uint32_t address) void flashSaveDecide(uint32_t address, uint8_t byte) { - if (saveType == GBA_SAVE_EEPROM) + if (coreOptions.saveType == GBA_SAVE_EEPROM) return; if (cpuSramEnabled && cpuFlashEnabled) { if (address == 0x0e005555) { - saveType = GBA_SAVE_FLASH; + coreOptions.saveType = GBA_SAVE_FLASH; cpuSramEnabled = false; cpuSaveGameFunc = flashWrite; } else { - saveType = GBA_SAVE_SRAM; + coreOptions.saveType = GBA_SAVE_SRAM; cpuFlashEnabled = false; cpuSaveGameFunc = sramWrite; } @@ -108,7 +108,7 @@ void flashSaveDecide(uint32_t address, uint8_t byte) void flashDelayedWrite(uint32_t address, uint8_t byte) { - saveType = GBA_SAVE_FLASH; + coreOptions.saveType = GBA_SAVE_FLASH; cpuSaveGameFunc = flashWrite; flashWrite(address, byte); } diff --git a/src/gba/GBA-arm.cpp b/src/gba/GBA-arm.cpp index a3923957..318b700b 100644 --- a/src/gba/GBA-arm.cpp +++ b/src/gba/GBA-arm.cpp @@ -2830,7 +2830,7 @@ static void tester(void) { int armExecute() { do { - if (cheatsEnabled) { + if (coreOptions.cheatsEnabled) { cpuMasterCodeCheck(); } diff --git a/src/gba/GBA-thumb.cpp b/src/gba/GBA-thumb.cpp index 781061e4..96dd0a60 100644 --- a/src/gba/GBA-thumb.cpp +++ b/src/gba/GBA-thumb.cpp @@ -2000,7 +2000,7 @@ static insnfunc_t thumbInsnTable[1024] = { int thumbExecute() { do { - if (cheatsEnabled) { + if (coreOptions.cheatsEnabled) { cpuMasterCodeCheck(); } diff --git a/src/gba/GBA.cpp b/src/gba/GBA.cpp index 9b67ab0c..34cb0c4d 100644 --- a/src/gba/GBA.cpp +++ b/src/gba/GBA.cpp @@ -85,7 +85,7 @@ uint8_t freezeOAM[SIZE_OAM]; bool debugger_last; #endif -int lcdTicks = (useBios && !skipBios) ? 1008 : 208; +int lcdTicks = (coreOptions.useBios && !coreOptions.skipBios) ? 1008 : 208; uint8_t timerOnOffDelay = 0; uint16_t timer0Value = 0; bool timer0On = false; @@ -454,7 +454,7 @@ variable_desc saveGameStruct[] = { { &armIrqEnable, sizeof(bool) }, { &armNextPC, sizeof(uint32_t) }, { &armMode, sizeof(int) }, - { &saveType, sizeof(int) }, + { &coreOptions.saveType, sizeof(int) }, { NULL, 0 } }; @@ -579,16 +579,16 @@ extern uint32_t line3[240]; void CPUUpdateRenderBuffers(bool force) { - if (!(layerEnable & 0x0100) || force) { + if (!(coreOptions.layerEnable & 0x0100) || force) { CLEAR_ARRAY(line0); } - if (!(layerEnable & 0x0200) || force) { + if (!(coreOptions.layerEnable & 0x0200) || force) { CLEAR_ARRAY(line1); } - if (!(layerEnable & 0x0400) || force) { + if (!(coreOptions.layerEnable & 0x0400) || force) { CLEAR_ARRAY(line2); } - if (!(layerEnable & 0x0800) || force) { + if (!(coreOptions.layerEnable & 0x0800) || force) { CLEAR_ARRAY(line3); } } @@ -602,7 +602,7 @@ unsigned int CPUWriteState(uint8_t* data) utilWriteIntMem(data, SAVE_GAME_VERSION); utilWriteMem(data, &rom[0xa0], 16); - utilWriteIntMem(data, useBios); + utilWriteIntMem(data, coreOptions.useBios); utilWriteMem(data, ®[0], sizeof(reg)); utilWriteDataMem(data, saveGameStruct); @@ -670,7 +670,7 @@ bool CPUReadState(const uint8_t* data) //// Copypasta stuff ... // set pointers! - layerEnable = layerSettings & DISPCNT; + coreOptions.layerEnable = coreOptions.layerSettings & DISPCNT; CPUUpdateRender(); @@ -684,7 +684,7 @@ bool CPUReadState(const uint8_t* data) CPUUpdateWindow0(); CPUUpdateWindow1(); - SetSaveType(saveType); + SetSaveType(coreOptions.saveType); systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED; if (armState) { @@ -706,7 +706,7 @@ static bool CPUWriteState(gzFile gzFile) utilGzWrite(gzFile, &rom[0xa0], 16); - utilWriteInt(gzFile, useBios); + utilWriteInt(gzFile, coreOptions.useBios); utilGzWrite(gzFile, ®[0], sizeof(reg)); @@ -799,8 +799,8 @@ static bool CPUReadState(gzFile gzFile) bool ub = utilReadInt(gzFile) ? true : false; - if (ub != useBios) { - if (useBios) + if (ub != coreOptions.useBios) { + if (coreOptions.useBios) systemMessage(MSG_SAVE_GAME_NOT_USING_BIOS, N_("Save game is not using the BIOS files")); else @@ -842,7 +842,7 @@ static bool CPUReadState(gzFile gzFile) utilGzRead(gzFile, pix, SIZE_PIX); utilGzRead(gzFile, ioMem, SIZE_IOMEM); - if (skipSaveGameBattery) { + if (coreOptions.skipSaveGameBattery) { // skip eeprom data eepromReadGameSkip(gzFile, version); // skip flash data @@ -854,7 +854,7 @@ static bool CPUReadState(gzFile gzFile) soundReadGame(gzFile, version); if (version > SAVE_GAME_VERSION_1) { - if (skipSaveGameCheats) { + if (coreOptions.skipSaveGameCheats) { // skip cheats list data cheatsReadGameSkip(gzFile, version); } else { @@ -897,14 +897,14 @@ static bool CPUReadState(gzFile gzFile) } // set pointers! - layerEnable = layerSettings & DISPCNT; + coreOptions.layerEnable = coreOptions.layerSettings & DISPCNT; CPUUpdateRender(); CPUUpdateRenderBuffers(true); CPUUpdateWindow0(); CPUUpdateWindow1(); - SetSaveType(saveType); + SetSaveType(coreOptions.saveType); systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED; if (armState) { @@ -971,7 +971,7 @@ bool CPUExportEepromFile(const char* fileName) bool CPUWriteBatteryFile(const char* fileName) { - if ((saveType) && (saveType != GBA_SAVE_NONE)) { + if ((coreOptions.saveType) && (coreOptions.saveType != GBA_SAVE_NONE)) { FILE* file = utilOpenFile(fileName, "wb"); if (!file) { @@ -982,12 +982,12 @@ bool CPUWriteBatteryFile(const char* fileName) // only save if Flash/Sram in use or EEprom in use if (!eepromInUse) { - if (saveType == GBA_SAVE_FLASH) { // save flash type + if (coreOptions.saveType == GBA_SAVE_FLASH) { // save flash type if (fwrite(flashSaveMemory, 1, flashSize, file) != (size_t)flashSize) { fclose(file); return false; } - } else if (saveType == GBA_SAVE_SRAM) { // save sram type + } else if (coreOptions.saveType == GBA_SAVE_SRAM) { // save sram type if (fwrite(flashSaveMemory, 1, 0x8000, file) != 0x8000) { fclose(file); return false; @@ -1154,7 +1154,7 @@ bool CPUWriteGSASnapshot(const char* fileName, fwrite(buffer, 1, 4, file); // notes length fwrite(notes, 1, strlen(notes), file); int saveSize = 0x10000; - if (saveType == GBA_SAVE_FLASH) + if (coreOptions.saveType == GBA_SAVE_FLASH) saveSize = flashSize; int totalSize = saveSize + 0x1c; @@ -1300,7 +1300,7 @@ bool CPUIsZipFile(const char* file) bool CPUIsGBAImage(const char* file) { - cpuIsMultiBoot = false; + coreOptions.cpuIsMultiBoot = false; if (strlen(file) > 4) { const char* p = strrchr(file, '.'); @@ -1314,7 +1314,7 @@ bool CPUIsGBAImage(const char* file) if (_stricmp(p, ".elf") == 0) return true; if (_stricmp(p, ".mb") == 0) { - cpuIsMultiBoot = true; + coreOptions.cpuIsMultiBoot = true; return true; } } @@ -1486,7 +1486,7 @@ int CPULoadRom(const char* szFile) return 0; } - uint8_t* whereToLoad = cpuIsMultiBoot ? workRAM : rom; + uint8_t* whereToLoad = coreOptions.cpuIsMultiBoot ? workRAM : rom; #ifndef NO_DEBUGGER if (CPUIsELF(szFile)) { @@ -1612,7 +1612,7 @@ int CPULoadRomData(const char* data, int size) return 0; } - uint8_t* whereToLoad = cpuIsMultiBoot ? workRAM : rom; + uint8_t* whereToLoad = coreOptions.cpuIsMultiBoot ? workRAM : rom; romSize = size % 2 == 0 ? size : size + 1; memcpy(whereToLoad, data, size); @@ -1747,49 +1747,49 @@ void CPUUpdateRender() { switch (DISPCNT & 7) { case 0: - if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) || cpuDisableSfx) + if ((!fxOn && !windowOn && !(coreOptions.layerEnable & 0x8000)) || coreOptions.cpuDisableSfx) renderLine = mode0RenderLine; - else if (fxOn && !windowOn && !(layerEnable & 0x8000)) + else if (fxOn && !windowOn && !(coreOptions.layerEnable & 0x8000)) renderLine = mode0RenderLineNoWindow; else renderLine = mode0RenderLineAll; break; case 1: - if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) || cpuDisableSfx) + if ((!fxOn && !windowOn && !(coreOptions.layerEnable & 0x8000)) || coreOptions.cpuDisableSfx) renderLine = mode1RenderLine; - else if (fxOn && !windowOn && !(layerEnable & 0x8000)) + else if (fxOn && !windowOn && !(coreOptions.layerEnable & 0x8000)) renderLine = mode1RenderLineNoWindow; else renderLine = mode1RenderLineAll; break; case 2: - if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) || cpuDisableSfx) + if ((!fxOn && !windowOn && !(coreOptions.layerEnable & 0x8000)) || coreOptions.cpuDisableSfx) renderLine = mode2RenderLine; - else if (fxOn && !windowOn && !(layerEnable & 0x8000)) + else if (fxOn && !windowOn && !(coreOptions.layerEnable & 0x8000)) renderLine = mode2RenderLineNoWindow; else renderLine = mode2RenderLineAll; break; case 3: - if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) || cpuDisableSfx) + if ((!fxOn && !windowOn && !(coreOptions.layerEnable & 0x8000)) || coreOptions.cpuDisableSfx) renderLine = mode3RenderLine; - else if (fxOn && !windowOn && !(layerEnable & 0x8000)) + else if (fxOn && !windowOn && !(coreOptions.layerEnable & 0x8000)) renderLine = mode3RenderLineNoWindow; else renderLine = mode3RenderLineAll; break; case 4: - if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) || cpuDisableSfx) + if ((!fxOn && !windowOn && !(coreOptions.layerEnable & 0x8000)) || coreOptions.cpuDisableSfx) renderLine = mode4RenderLine; - else if (fxOn && !windowOn && !(layerEnable & 0x8000)) + else if (fxOn && !windowOn && !(coreOptions.layerEnable & 0x8000)) renderLine = mode4RenderLineNoWindow; else renderLine = mode4RenderLineAll; break; case 5: - if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) || cpuDisableSfx) + if ((!fxOn && !windowOn && !(coreOptions.layerEnable & 0x8000)) || coreOptions.cpuDisableSfx) renderLine = mode5RenderLine; - else if (fxOn && !windowOn && !(layerEnable & 0x8000)) + else if (fxOn && !windowOn && !(coreOptions.layerEnable & 0x8000)) renderLine = mode5RenderLineNoWindow; else renderLine = mode5RenderLineAll; @@ -2042,7 +2042,7 @@ void CPUSoftwareInterrupt(int comment) return; } #endif - if (useBios) { + if (coreOptions.useBios) { #ifdef GBA_LOGGING if (systemVerbose & VERBOSE_SWI) { log("SWI: %08x at %08x (0x%08x,0x%08x,0x%08x,VCOUNT = %2d)\n", comment, @@ -2329,7 +2329,7 @@ void CPUCompareVCOUNT() if (layerEnableDelay > 0) { layerEnableDelay--; if (layerEnableDelay == 1) - layerEnable = layerSettings & DISPCNT; + coreOptions.layerEnable = coreOptions.layerSettings & DISPCNT; } } @@ -2679,13 +2679,13 @@ void CPUUpdateRegister(uint32_t address, uint16_t value) if (changeBGon) { layerEnableDelay = 4; - layerEnable = layerSettings & value & (~changeBGon); + coreOptions.layerEnable = coreOptions.layerSettings & value & (~changeBGon); } else { - layerEnable = layerSettings & value; + coreOptions.layerEnable = coreOptions.layerSettings & value; // CPUUpdateTicks(); } - windowOn = (layerEnable & 0x6000) ? true : false; + windowOn = (coreOptions.layerEnable & 0x6000) ? true : false; if (change && !((value & 0x80))) { if (!(DISPSTAT & 1)) { //lcdTicks = 1008; @@ -3173,7 +3173,7 @@ void CPUUpdateRegister(uint32_t address, uint16_t value) case 0x204: { memoryWait[0x0e] = memoryWaitSeq[0x0e] = gamepakRamWaitState[value & 3]; - if (!speedHack) { + if (!coreOptions.speedHack) { memoryWait[0x08] = memoryWait[0x09] = gamepakWaitState[(value >> 2) & 3]; memoryWaitSeq[0x08] = memoryWaitSeq[0x09] = gamepakWaitState0[(value >> 4) & 1]; @@ -3298,7 +3298,7 @@ void CPUInit(const char* biosFileName, bool useBiosFile) } #endif eepromInUse = 0; - useBios = false; + coreOptions.useBios = false; if (useBiosFile && strlen(biosFileName) > 0) { int size = 0x4000; @@ -3307,13 +3307,13 @@ void CPUInit(const char* biosFileName, bool useBiosFile) bios, size)) { if (size == 0x4000) - useBios = true; + coreOptions.useBios = true; else systemMessage(MSG_INVALID_BIOS_FILE_SIZE, N_("Invalid BIOS file size")); } } - if (!useBios) { + if (!coreOptions.useBios) { memcpy(bios, myROM, sizeof(myROM)); } @@ -3455,7 +3455,7 @@ void CPUReset() DISPCNT = 0x0080; DISPSTAT = 0x0000; - VCOUNT = (useBios && !skipBios) ? 0 : 0x007E; + VCOUNT = (coreOptions.useBios && !coreOptions.skipBios) ? 0 : 0x007E; BG0CNT = 0x0000; BG1CNT = 0x0000; BG2CNT = 0x0000; @@ -3533,7 +3533,7 @@ void CPUReset() armMode = 0x1F; - if (cpuIsMultiBoot) { + if (coreOptions.cpuIsMultiBoot) { reg[13].I = 0x03007F00; reg[15].I = 0x02000000; reg[16].I = 0x00000000; @@ -3541,7 +3541,7 @@ void CPUReset() reg[R13_SVC].I = 0x03007FE0; armIrqEnable = true; } else { - if (useBios && !skipBios) { + if (coreOptions.useBios && !coreOptions.skipBios) { reg[15].I = 0x00000000; armMode = 0x13; armIrqEnable = false; @@ -3582,7 +3582,7 @@ void CPUReset() biosProtected[2] = 0x29; biosProtected[3] = 0xe1; - lcdTicks = (useBios && !skipBios) ? 1008 : 208; + lcdTicks = (coreOptions.useBios && !coreOptions.skipBios) ? 1008 : 208; timer0On = false; timer0Ticks = 0; timer0Reload = 0; @@ -3611,7 +3611,7 @@ void CPUReset() fxOn = false; windowOn = false; frameCount = 0; - layerEnable = DISPCNT & layerSettings; + coreOptions.layerEnable = DISPCNT & coreOptions.layerSettings; CPUUpdateRenderBuffers(true); @@ -3641,19 +3641,19 @@ void CPUReset() CPUUpdateWindow1(); // make sure registers are correctly initialized if not using BIOS - if (!useBios) { - if (cpuIsMultiBoot) + if (!coreOptions.useBios) { + if (coreOptions.cpuIsMultiBoot) BIOS_RegisterRamReset(0xfe); else BIOS_RegisterRamReset(0xff); } else { - if (cpuIsMultiBoot) + if (coreOptions.cpuIsMultiBoot) BIOS_RegisterRamReset(0xfe); } flashReset(); eepromReset(); - SetSaveType(saveType); + SetSaveType(coreOptions.saveType); ARM_PREFETCH; @@ -3834,7 +3834,7 @@ void CPULoop(int ticks) speedup_throttle_set = true; } - if (speedup_throttle_frame_skip) + if (coreOptions.speedup_throttle_frame_skip) framesToSkip += std::ceil(double(speedup_throttle) / 100.0) - 1; } } @@ -3874,13 +3874,13 @@ void CPULoop(int ticks) uint32_t ext = (joy >> 10); // If no (m) code is enabled, apply the cheats at each LCDline - if ((cheatsEnabled) && (mastercode == 0)) + if ((coreOptions.cheatsEnabled) && (mastercode == 0)) remainingTicks += cheatsCheckKeys(P1 ^ 0x3FF, ext); - speedup = false; + coreOptions.speedup = false; if (ext & 1 && !speedup_throttle_set) - speedup = true; + coreOptions.speedup = true; capture = (ext & 2) ? true : false; diff --git a/src/gba/GBAGfx.h b/src/gba/GBAGfx.h index 5d3768c5..4c461ad1 100644 --- a/src/gba/GBAGfx.h +++ b/src/gba/GBAGfx.h @@ -625,7 +625,7 @@ static inline void gfxDrawSprites(uint32_t* lineOBJ) int lineOBJpix = (DISPCNT & 0x20) ? 954 : 1226; int m = 0; gfxClearArray(lineOBJ); - if (layerEnable & 0x1000) { + if (coreOptions.layerEnable & 0x1000) { uint16_t* sprites = (uint16_t*)oam; uint16_t* spritePalette = &((uint16_t*)paletteRAM)[256]; int mosaicY = ((MOSAIC & 0xF000) >> 12) + 1; @@ -674,7 +674,7 @@ static inline void gfxDrawSprites(uint32_t* lineOBJ) int sx = (a1 & 0x1FF); // computes ticks used by OBJ-WIN if OBJWIN is enabled - if (((a0 & 0x0c00) == 0x0800) && (layerEnable & 0x8000)) { + if (((a0 & 0x0c00) == 0x0800) && (coreOptions.layerEnable & 0x8000)) { if ((a0 & 0x0300) == 0x0300) { sizeX <<= 1; sizeY <<= 1; @@ -1142,7 +1142,7 @@ static inline void gfxDrawSprites(uint32_t* lineOBJ) static inline void gfxDrawOBJWin(uint32_t* lineOBJWin) { gfxClearArray(lineOBJWin); - if ((layerEnable & 0x9000) == 0x9000) { + if ((coreOptions.layerEnable & 0x9000) == 0x9000) { uint16_t* sprites = (uint16_t*)oam; // uint16_t *spritePalette = &((uint16_t *)paletteRAM)[256]; for (int x = 0; x < 128; x++) { diff --git a/src/gba/GBAinline.h b/src/gba/GBAinline.h index 3185ea1d..88613945 100644 --- a/src/gba/GBAinline.h +++ b/src/gba/GBAinline.h @@ -796,7 +796,7 @@ static inline void CPUWriteByte(uint32_t address, uint8_t b) goto unwritable; case 14: case 15: - if ((saveType != 5) && ((!eepromInUse) | cpuSramEnabled | cpuFlashEnabled)) { + if ((coreOptions.saveType != 5) && ((!eepromInUse) | cpuSramEnabled | cpuFlashEnabled)) { // if(!cpuEEPROMEnabled && (cpuSramEnabled | cpuFlashEnabled)) { (*cpuSaveGameFunc)(address, b); diff --git a/src/gba/Globals.h b/src/gba/Globals.h index 0759329c..32a7c66f 100644 --- a/src/gba/Globals.h +++ b/src/gba/Globals.h @@ -26,13 +26,8 @@ extern bool armIrqEnable; extern uint32_t armNextPC; extern int armMode; extern uint32_t stop; -extern int saveType; -extern int frameSkip; extern bool gba_joybus_enabled; extern bool gba_joybus_active; -extern int layerSettings; -extern int layerEnable; -extern int cpuSaveType; extern int customBackdropColor; extern uint8_t* bios; diff --git a/src/gba/Mode0.cpp b/src/gba/Mode0.cpp index a0cdbd0e..52c5d9cb 100644 --- a/src/gba/Mode0.cpp +++ b/src/gba/Mode0.cpp @@ -13,19 +13,19 @@ void mode0RenderLine() return; } - if (layerEnable & 0x0100) { + if (coreOptions.layerEnable & 0x0100) { gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0); } - if (layerEnable & 0x0200) { + if (coreOptions.layerEnable & 0x0200) { gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1); } - if (layerEnable & 0x0400) { + if (coreOptions.layerEnable & 0x0400) { gfxDrawTextScreen(BG2CNT, BG2HOFS, BG2VOFS, line2); } - if (layerEnable & 0x0800) { + if (coreOptions.layerEnable & 0x0800) { gfxDrawTextScreen(BG3CNT, BG3HOFS, BG3VOFS, line3); } @@ -125,19 +125,19 @@ void mode0RenderLineNoWindow() return; } - if (layerEnable & 0x0100) { + if (coreOptions.layerEnable & 0x0100) { gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0); } - if (layerEnable & 0x0200) { + if (coreOptions.layerEnable & 0x0200) { gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1); } - if (layerEnable & 0x0400) { + if (coreOptions.layerEnable & 0x0400) { gfxDrawTextScreen(BG2CNT, BG2HOFS, BG2VOFS, line2); } - if (layerEnable & 0x0800) { + if (coreOptions.layerEnable & 0x0800) { gfxDrawTextScreen(BG3CNT, BG3HOFS, BG3VOFS, line3); } @@ -300,7 +300,7 @@ void mode0RenderLineAll() bool inWindow0 = false; bool inWindow1 = false; - if (layerEnable & 0x2000) { + if (coreOptions.layerEnable & 0x2000) { uint8_t v0 = WIN0V >> 8; uint8_t v1 = WIN0V & 255; inWindow0 = ((v0 == v1) && (v0 >= 0xe8)); @@ -309,7 +309,7 @@ void mode0RenderLineAll() else inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); } - if (layerEnable & 0x4000) { + if (coreOptions.layerEnable & 0x4000) { uint8_t v0 = WIN1V >> 8; uint8_t v1 = WIN1V & 255; inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); @@ -319,19 +319,19 @@ void mode0RenderLineAll() inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1); } - if ((layerEnable & 0x0100)) { + if ((coreOptions.layerEnable & 0x0100)) { gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0); } - if ((layerEnable & 0x0200)) { + if ((coreOptions.layerEnable & 0x0200)) { gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1); } - if ((layerEnable & 0x0400)) { + if ((coreOptions.layerEnable & 0x0400)) { gfxDrawTextScreen(BG2CNT, BG2HOFS, BG2VOFS, line2); } - if ((layerEnable & 0x0800)) { + if ((coreOptions.layerEnable & 0x0800)) { gfxDrawTextScreen(BG3CNT, BG3HOFS, BG3VOFS, line3); } diff --git a/src/gba/Mode1.cpp b/src/gba/Mode1.cpp index 8710ce73..1acdb850 100644 --- a/src/gba/Mode1.cpp +++ b/src/gba/Mode1.cpp @@ -14,15 +14,15 @@ void mode1RenderLine() return; } - if (layerEnable & 0x0100) { + if (coreOptions.layerEnable & 0x0100) { gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0); } - if (layerEnable & 0x0200) { + if (coreOptions.layerEnable & 0x0200) { gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1); } - if (layerEnable & 0x0400) { + if (coreOptions.layerEnable & 0x0400) { int changed = gfxBG2Changed; if (gfxLastVCOUNT > VCOUNT) changed = 3; @@ -120,15 +120,15 @@ void mode1RenderLineNoWindow() return; } - if (layerEnable & 0x0100) { + if (coreOptions.layerEnable & 0x0100) { gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0); } - if (layerEnable & 0x0200) { + if (coreOptions.layerEnable & 0x0200) { gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1); } - if (layerEnable & 0x0400) { + if (coreOptions.layerEnable & 0x0400) { int changed = gfxBG2Changed; if (gfxLastVCOUNT > VCOUNT) changed = 3; @@ -280,7 +280,7 @@ void mode1RenderLineAll() bool inWindow0 = false; bool inWindow1 = false; - if (layerEnable & 0x2000) { + if (coreOptions.layerEnable & 0x2000) { uint8_t v0 = WIN0V >> 8; uint8_t v1 = WIN0V & 255; inWindow0 = ((v0 == v1) && (v0 >= 0xe8)); @@ -289,7 +289,7 @@ void mode1RenderLineAll() else inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); } - if (layerEnable & 0x4000) { + if (coreOptions.layerEnable & 0x4000) { uint8_t v0 = WIN1V >> 8; uint8_t v1 = WIN1V & 255; inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); @@ -299,15 +299,15 @@ void mode1RenderLineAll() inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1); } - if (layerEnable & 0x0100) { + if (coreOptions.layerEnable & 0x0100) { gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0); } - if (layerEnable & 0x0200) { + if (coreOptions.layerEnable & 0x0200) { gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1); } - if (layerEnable & 0x0400) { + if (coreOptions.layerEnable & 0x0400) { int changed = gfxBG2Changed; if (gfxLastVCOUNT > VCOUNT) changed = 3; diff --git a/src/gba/Mode2.cpp b/src/gba/Mode2.cpp index aede2990..7c4df8de 100644 --- a/src/gba/Mode2.cpp +++ b/src/gba/Mode2.cpp @@ -14,7 +14,7 @@ void mode2RenderLine() return; } - if (layerEnable & 0x0400) { + if (coreOptions.layerEnable & 0x0400) { int changed = gfxBG2Changed; if (gfxLastVCOUNT > VCOUNT) changed = 3; @@ -24,7 +24,7 @@ void mode2RenderLine() changed, line2); } - if (layerEnable & 0x0800) { + if (coreOptions.layerEnable & 0x0800) { int changed = gfxBG3Changed; if (gfxLastVCOUNT > VCOUNT) changed = 3; @@ -114,7 +114,7 @@ void mode2RenderLineNoWindow() return; } - if (layerEnable & 0x0400) { + if (coreOptions.layerEnable & 0x0400) { int changed = gfxBG2Changed; if (gfxLastVCOUNT > VCOUNT) changed = 3; @@ -124,7 +124,7 @@ void mode2RenderLineNoWindow() changed, line2); } - if (layerEnable & 0x0800) { + if (coreOptions.layerEnable & 0x0800) { int changed = gfxBG3Changed; if (gfxLastVCOUNT > VCOUNT) changed = 3; @@ -262,7 +262,7 @@ void mode2RenderLineAll() bool inWindow0 = false; bool inWindow1 = false; - if (layerEnable & 0x2000) { + if (coreOptions.layerEnable & 0x2000) { uint8_t v0 = WIN0V >> 8; uint8_t v1 = WIN0V & 255; inWindow0 = ((v0 == v1) && (v0 >= 0xe8)); @@ -271,7 +271,7 @@ void mode2RenderLineAll() else inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); } - if (layerEnable & 0x4000) { + if (coreOptions.layerEnable & 0x4000) { uint8_t v0 = WIN1V >> 8; uint8_t v1 = WIN1V & 255; inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); @@ -281,7 +281,7 @@ void mode2RenderLineAll() inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1); } - if (layerEnable & 0x0400) { + if (coreOptions.layerEnable & 0x0400) { int changed = gfxBG2Changed; if (gfxLastVCOUNT > VCOUNT) changed = 3; @@ -291,7 +291,7 @@ void mode2RenderLineAll() changed, line2); } - if (layerEnable & 0x0800) { + if (coreOptions.layerEnable & 0x0800) { int changed = gfxBG3Changed; if (gfxLastVCOUNT > VCOUNT) changed = 3; diff --git a/src/gba/Mode3.cpp b/src/gba/Mode3.cpp index 1bc49cb5..a3f28ce1 100644 --- a/src/gba/Mode3.cpp +++ b/src/gba/Mode3.cpp @@ -14,7 +14,7 @@ void mode3RenderLine() return; } - if (layerEnable & 0x0400) { + if (coreOptions.layerEnable & 0x0400) { int changed = gfxBG2Changed; if (gfxLastVCOUNT > VCOUNT) @@ -96,7 +96,7 @@ void mode3RenderLineNoWindow() return; } - if (layerEnable & 0x0400) { + if (coreOptions.layerEnable & 0x0400) { int changed = gfxBG2Changed; if (gfxLastVCOUNT > VCOUNT) @@ -219,7 +219,7 @@ void mode3RenderLineAll() bool inWindow0 = false; bool inWindow1 = false; - if (layerEnable & 0x2000) { + if (coreOptions.layerEnable & 0x2000) { uint8_t v0 = WIN0V >> 8; uint8_t v1 = WIN0V & 255; inWindow0 = ((v0 == v1) && (v0 >= 0xe8)); @@ -228,7 +228,7 @@ void mode3RenderLineAll() else inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); } - if (layerEnable & 0x4000) { + if (coreOptions.layerEnable & 0x4000) { uint8_t v0 = WIN1V >> 8; uint8_t v1 = WIN1V & 255; inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); @@ -238,7 +238,7 @@ void mode3RenderLineAll() inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1); } - if (layerEnable & 0x0400) { + if (coreOptions.layerEnable & 0x0400) { int changed = gfxBG2Changed; if (gfxLastVCOUNT > VCOUNT) diff --git a/src/gba/Mode4.cpp b/src/gba/Mode4.cpp index 25b2249e..b0034e17 100644 --- a/src/gba/Mode4.cpp +++ b/src/gba/Mode4.cpp @@ -14,7 +14,7 @@ void mode4RenderLine() return; } - if (layerEnable & 0x400) { + if (coreOptions.layerEnable & 0x400) { int changed = gfxBG2Changed; if (gfxLastVCOUNT > VCOUNT) @@ -95,7 +95,7 @@ void mode4RenderLineNoWindow() return; } - if (layerEnable & 0x400) { + if (coreOptions.layerEnable & 0x400) { int changed = gfxBG2Changed; if (gfxLastVCOUNT > VCOUNT) @@ -217,7 +217,7 @@ void mode4RenderLineAll() bool inWindow0 = false; bool inWindow1 = false; - if (layerEnable & 0x2000) { + if (coreOptions.layerEnable & 0x2000) { uint8_t v0 = WIN0V >> 8; uint8_t v1 = WIN0V & 255; inWindow0 = ((v0 == v1) && (v0 >= 0xe8)); @@ -226,7 +226,7 @@ void mode4RenderLineAll() else inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); } - if (layerEnable & 0x4000) { + if (coreOptions.layerEnable & 0x4000) { uint8_t v0 = WIN1V >> 8; uint8_t v1 = WIN1V & 255; inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); @@ -236,7 +236,7 @@ void mode4RenderLineAll() inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1); } - if (layerEnable & 0x400) { + if (coreOptions.layerEnable & 0x400) { int changed = gfxBG2Changed; if (gfxLastVCOUNT > VCOUNT) diff --git a/src/gba/Mode5.cpp b/src/gba/Mode5.cpp index 857c95ad..5e367fb1 100644 --- a/src/gba/Mode5.cpp +++ b/src/gba/Mode5.cpp @@ -14,7 +14,7 @@ void mode5RenderLine() uint16_t* palette = (uint16_t*)paletteRAM; - if (layerEnable & 0x0400) { + if (coreOptions.layerEnable & 0x0400) { int changed = gfxBG2Changed; if (gfxLastVCOUNT > VCOUNT) @@ -96,7 +96,7 @@ void mode5RenderLineNoWindow() uint16_t* palette = (uint16_t*)paletteRAM; - if (layerEnable & 0x0400) { + if (coreOptions.layerEnable & 0x0400) { int changed = gfxBG2Changed; if (gfxLastVCOUNT > VCOUNT) @@ -216,7 +216,7 @@ void mode5RenderLineAll() uint16_t* palette = (uint16_t*)paletteRAM; - if (layerEnable & 0x0400) { + if (coreOptions.layerEnable & 0x0400) { int changed = gfxBG2Changed; if (gfxLastVCOUNT > VCOUNT) @@ -235,7 +235,7 @@ void mode5RenderLineAll() bool inWindow0 = false; bool inWindow1 = false; - if (layerEnable & 0x2000) { + if (coreOptions.layerEnable & 0x2000) { uint8_t v0 = WIN0V >> 8; uint8_t v1 = WIN0V & 255; inWindow0 = ((v0 == v1) && (v0 >= 0xe8)); @@ -244,7 +244,7 @@ void mode5RenderLineAll() else inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); } - if (layerEnable & 0x4000) { + if (coreOptions.layerEnable & 0x4000) { uint8_t v0 = WIN1V >> 8; uint8_t v1 = WIN1V & 255; inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); diff --git a/src/gba/RTC.cpp b/src/gba/RTC.cpp index 768bc9fc..c539ca6f 100644 --- a/src/gba/RTC.cpp +++ b/src/gba/RTC.cpp @@ -217,7 +217,7 @@ bool rtcWrite(uint32_t address, uint16_t value) break; case 0x65: { - if (rtcEnabled) + if (coreOptions.rtcEnabled) SetGBATime(); rtcClockData.dataLen = 7; @@ -232,7 +232,7 @@ bool rtcWrite(uint32_t address, uint16_t value) } break; case 0x67: { - if (rtcEnabled) + if (coreOptions.rtcEnabled) SetGBATime(); rtcClockData.dataLen = 3; diff --git a/src/gba/Sram.cpp b/src/gba/Sram.cpp index 08e06501..39aabaff 100644 --- a/src/gba/Sram.cpp +++ b/src/gba/Sram.cpp @@ -9,7 +9,7 @@ uint8_t sramRead(uint32_t address) } void sramDelayedWrite(uint32_t address, uint8_t byte) { - saveType = GBA_SAVE_SRAM; + coreOptions.saveType = GBA_SAVE_SRAM; cpuSaveGameFunc = sramWrite; sramWrite(address, byte); } diff --git a/src/gba/elf.cpp b/src/gba/elf.cpp index b1099f53..059328d3 100644 --- a/src/gba/elf.cpp +++ b/src/gba/elf.cpp @@ -215,8 +215,6 @@ struct ELFFrameState { int returnAddress; }; -extern bool cpuIsMultiBoot; - Symbol* elfSymbols = NULL; char* elfSymbolsStrTab = NULL; int elfSymbolsCount = 0; @@ -2547,7 +2545,7 @@ bool elfReadProgram(ELFHeader* eh, uint8_t* data, unsigned long data_size, int& int i; if (READ32LE(&eh->e_entry) == 0x2000000) - cpuIsMultiBoot = true; + coreOptions.cpuIsMultiBoot = true; // read program headers... should probably move this code down uint8_t* p = data + READ32LE(&eh->e_phoff); @@ -2572,7 +2570,7 @@ bool elfReadProgram(ELFHeader* eh, uint8_t* data, unsigned long data_size, int& uint8_t* source = data + offset; - if (cpuIsMultiBoot) { + if (coreOptions.cpuIsMultiBoot) { unsigned effective_address = address - 0x2000000; if (effective_address + section_size < SIZE_WRAM) { @@ -2623,7 +2621,7 @@ bool elfReadProgram(ELFHeader* eh, uint8_t* data, unsigned long data_size, int& // sh[i]->flags, sh[i]->addr, sh[i]->offset, sh[i]->size, // sh[i]->link, sh[i]->info); if (READ32LE(&sh[i]->flags) & 2) { // load section - if (cpuIsMultiBoot) { + if (coreOptions.cpuIsMultiBoot) { if (READ32LE(&sh[i]->addr) >= 0x2000000 && READ32LE(&sh[i]->addr) <= 0x203ffff) { memcpy(&workRAM[READ32LE(&sh[i]->addr) & 0x3ffff], data + READ32LE(&sh[i]->offset), READ32LE(&sh[i]->size)); @@ -2714,8 +2712,6 @@ end: return true; } -extern bool parseDebug; - bool elfRead(const char* name, int& siz, FILE* f) { fseek(f, 0, SEEK_END); @@ -2740,7 +2736,7 @@ bool elfRead(const char* name, int& siz, FILE* f) return false; } - if (!elfReadProgram(header, elfFileData, size, siz, parseDebug)) { + if (!elfReadProgram(header, elfFileData, size, siz, coreOptions.parseDebug)) { free(elfFileData); elfFileData = NULL; return false; diff --git a/src/libretro/UtilRetro.cpp b/src/libretro/UtilRetro.cpp index 58eee565..f0022d0e 100644 --- a/src/libretro/UtilRetro.cpp +++ b/src/libretro/UtilRetro.cpp @@ -22,24 +22,6 @@ #define _stricmp strcasecmp #endif // ! _MSC_VER -// Because Configmanager was introduced, this has to be done. -int rtcEnabled = 0; -int cpuDisableSfx = 0; -int skipBios = 0; -int saveType = 0; -int cpuSaveType = 0; -int skipSaveGameBattery = 0; -int skipSaveGameCheats = 0; -int useBios = 0; -int cheatsEnabled = 0; -int layerSettings = 0xff00; -int layerEnable = 0xff00; -bool speedup = false; -bool parseDebug = false; -bool speedHack = false; -bool mirroringEnable = false; -bool cpuIsMultiBoot = false; - const char* loadDotCodeFile; const char* saveDotCodeFile; @@ -57,11 +39,9 @@ void utilPutWord(uint8_t* p, uint16_t value) *p = (value >> 8) & 255; } -extern bool cpuIsMultiBoot; - bool utilIsGBAImage(const char* file) { - cpuIsMultiBoot = false; + coreOptions.cpuIsMultiBoot = false; if (strlen(file) > 4) { const char* p = strrchr(file, '.'); @@ -69,7 +49,7 @@ bool utilIsGBAImage(const char* file) if ((_stricmp(p, ".agb") == 0) || (_stricmp(p, ".gba") == 0) || (_stricmp(p, ".bin") == 0) || (_stricmp(p, ".elf") == 0)) return true; if (_stricmp(p, ".mb") == 0) { - cpuIsMultiBoot = true; + coreOptions.cpuIsMultiBoot = true; return true; } } @@ -205,8 +185,8 @@ void utilGBAFindSave(const int size) if (detectedSaveType == 4) detectedSaveType = 3; - cpuSaveType = detectedSaveType; - rtcEnabled = rtcFound_; + coreOptions.cpuSaveType = detectedSaveType; + coreOptions.rtcEnabled = rtcFound_; flashSize = flashSize_; } diff --git a/src/libretro/libretro.cpp b/src/libretro/libretro.cpp index ae4615ae..e295a9f6 100644 --- a/src/libretro/libretro.cpp +++ b/src/libretro/libretro.cpp @@ -87,6 +87,8 @@ int systemFrameSkip = 0; int systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED; int emulating = 0; +struct CoreOptions coreOptions; + #ifdef BKPT_SUPPORT void (*dbgOutput)(const char* s, uint32_t addr); void (*dbgSignal)(int sig, int number); @@ -278,9 +280,9 @@ void* retro_get_memory_data(unsigned id) case IMAGE_GBA: switch (id) { case RETRO_MEMORY_SAVE_RAM: - if ((saveType == GBA_SAVE_EEPROM) | (saveType == GBA_SAVE_EEPROM_SENSOR)) + if ((coreOptions.saveType == GBA_SAVE_EEPROM) | (coreOptions.saveType == GBA_SAVE_EEPROM_SENSOR)) data = eepromData; - else if ((saveType == GBA_SAVE_SRAM) | (saveType == GBA_SAVE_FLASH)) + else if ((coreOptions.saveType == GBA_SAVE_SRAM) | (coreOptions.saveType == GBA_SAVE_FLASH)) data = flashSaveMemory; break; case RETRO_MEMORY_SYSTEM_RAM: @@ -324,11 +326,11 @@ size_t retro_get_memory_size(unsigned id) case IMAGE_GBA: switch (id) { case RETRO_MEMORY_SAVE_RAM: - if ((saveType == GBA_SAVE_EEPROM) | (saveType == GBA_SAVE_EEPROM_SENSOR)) + if ((coreOptions.saveType == GBA_SAVE_EEPROM) | (coreOptions.saveType == GBA_SAVE_EEPROM_SENSOR)) size = eepromSize; - else if (saveType == GBA_SAVE_FLASH) + else if (coreOptions.saveType == GBA_SAVE_FLASH) size = flashSize; - else if (saveType == GBA_SAVE_SRAM) + else if (coreOptions.saveType == GBA_SAVE_SRAM) size = SIZE_SRAM; break; case RETRO_MEMORY_SYSTEM_RAM: @@ -551,18 +553,25 @@ void retro_get_system_av_info(struct retro_system_av_info *info) void retro_init(void) { - struct retro_log_callback log; - struct retro_rumble_interface rumble; + // The libretro core uses a few different defaults. + coreOptions.mirroringEnable = false; + coreOptions.parseDebug = true; + coreOptions.cheatsEnabled = 0; + coreOptions.skipSaveGameBattery = 0; + coreOptions.winGbPrinterEnabled = 0; - environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &can_dupe); - if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log)) - log_cb = log.log; - else - log_cb = NULL; + struct retro_log_callback log; + struct retro_rumble_interface rumble; - const char* dir = NULL; - if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir) - snprintf(retro_system_directory, sizeof(retro_system_directory), "%s", dir); + environ_cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &can_dupe); + if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log)) + log_cb = log.log; + else + log_cb = NULL; + + const char* dir = NULL; + if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir) + snprintf(retro_system_directory, sizeof(retro_system_directory), "%s", dir); #ifdef FRONTEND_SUPPORTS_RGB565 systemColorDepth = 16; @@ -723,7 +732,7 @@ typedef struct { int saveType; // 0auto 1eeprom 2sram 3flash 4sensor+eeprom 5none int rtcEnabled; int mirroringEnabled; - int useBios; + int useBios; // unused? } ini_t; static const ini_t gbaover[512] = { @@ -749,11 +758,11 @@ static void load_image_preferences(void) unsigned i = 0, found_no = 0; unsigned long romCrc32 = crc32(0, rom, romSize); - cpuSaveType = GBA_SAVE_AUTO; + coreOptions.cpuSaveType = GBA_SAVE_AUTO; flashSize = SIZE_FLASH512; eepromSize = SIZE_EEPROM_512; - rtcEnabled = false; - mirroringEnable = false; + coreOptions.rtcEnabled = false; + coreOptions.mirroringEnable = false; log("File CRC32 : 0x%08X\n", romCrc32); @@ -785,50 +794,50 @@ static void load_image_preferences(void) if (found) { log("Name : %s\n", gbaover[found_no].romtitle); - rtcEnabled = gbaover[found_no].rtcEnabled; - cpuSaveType = gbaover[found_no].saveType; + coreOptions.rtcEnabled = gbaover[found_no].rtcEnabled; + coreOptions.cpuSaveType = gbaover[found_no].saveType; unsigned size = gbaover[found_no].saveSize; - if (cpuSaveType == GBA_SAVE_SRAM) + if (coreOptions.cpuSaveType == GBA_SAVE_SRAM) flashSize = SIZE_SRAM; - else if (cpuSaveType == GBA_SAVE_FLASH) + else if (coreOptions.cpuSaveType == GBA_SAVE_FLASH) flashSize = (size == SIZE_FLASH1M) ? SIZE_FLASH1M : SIZE_FLASH512; - else if ((cpuSaveType == GBA_SAVE_EEPROM) || (cpuSaveType == GBA_SAVE_EEPROM_SENSOR)) + else if ((coreOptions.cpuSaveType == GBA_SAVE_EEPROM) || (coreOptions.cpuSaveType == GBA_SAVE_EEPROM_SENSOR)) eepromSize = (size == SIZE_EEPROM_8K) ? SIZE_EEPROM_8K : SIZE_EEPROM_512; } // gameID that starts with 'F' are classic/famicom games - mirroringEnable = (buffer[0] == 'F') ? true : false; + coreOptions.mirroringEnable = (buffer[0] == 'F') ? true : false; - if (!cpuSaveType) + if (!coreOptions.cpuSaveType) utilGBAFindSave(romSize); - saveType = cpuSaveType; + coreOptions.saveType = coreOptions.cpuSaveType; if (flashSize == SIZE_FLASH512 || flashSize == SIZE_FLASH1M) flashSetSize(flashSize); if (option_forceRTCenable) - rtcEnabled = true; + coreOptions.rtcEnabled = true; - rtcEnable(rtcEnabled); + rtcEnable(coreOptions.rtcEnabled); // game code starting with 'R' or 'V' has rumble support if ((buffer[0] == 'R') || (buffer[0] == 'V')) hasRumble = true; - rtcEnableRumble(!rtcEnabled && hasRumble); + rtcEnableRumble(!coreOptions.rtcEnabled && hasRumble); - doMirroring(mirroringEnable); + doMirroring(coreOptions.mirroringEnable); log("romSize : %dKB\n", (romSize + 1023) / 1024); - log("has RTC : %s.\n", rtcEnabled ? "Yes" : "No"); - log("cpuSaveType : %s.\n", savetype[cpuSaveType]); - if (cpuSaveType == 3) + log("has RTC : %s.\n", coreOptions.rtcEnabled ? "Yes" : "No"); + log("cpuSaveType : %s.\n", savetype[coreOptions.cpuSaveType]); + if (coreOptions.cpuSaveType == 3) log("flashSize : %d.\n", flashSize); - else if (cpuSaveType == 1) + else if (coreOptions.cpuSaveType == 1) log("eepromSize : %d.\n", eepromSize); - log("mirroringEnable : %s.\n", mirroringEnable ? "Yes" : "No"); + log("mirroringEnable : %s.\n", coreOptions.mirroringEnable ? "Yes" : "No"); } #ifdef _WIN32 @@ -987,8 +996,8 @@ static void update_variables(bool startup) disabled_layers |= 0x100 << i; } - layerSettings = 0xFF00 ^ disabled_layers; - layerEnable = DISPCNT & layerSettings; + coreOptions.layerSettings = 0xFF00 ^ disabled_layers; + coreOptions.layerEnable = DISPCNT & coreOptions.layerSettings; CPUUpdateRenderBuffers(false); strcpy(key, "vbam_sound_x"); @@ -1451,7 +1460,7 @@ bool retro_unserialize(const void* data, size_t size) void retro_cheat_reset(void) { - cheatsEnabled = 1; + coreOptions.cheatsEnabled = 1; if (type == IMAGE_GBA) cheatsDeleteAll(false); else if (type == IMAGE_GB) diff --git a/src/sdl/SDL.cpp b/src/sdl/SDL.cpp index a9b699d8..f735b27a 100644 --- a/src/sdl/SDL.cpp +++ b/src/sdl/SDL.cpp @@ -109,6 +109,8 @@ extern void remoteOutput(const char*, uint32_t); extern void remoteSetProtocol(int); extern void remoteSetPort(int); +struct CoreOptions coreOptions; + struct EmulatedSystem emulator = { NULL, NULL, @@ -616,9 +618,9 @@ static void sdlApplyPerImagePreferences() } else if (!strcmp(token, "saveType")) { int save = atoi(value); if (save >= 0 && save <= 5) - cpuSaveType = save; + coreOptions.cpuSaveType = save; } else if (!strcmp(token, "mirroringEnabled")) { - mirroringEnable = (atoi(value) == 0 ? false : true); + coreOptions.mirroringEnable = (atoi(value) == 0 ? false : true); } } } @@ -1110,8 +1112,8 @@ void sdlPollEvents() break; case SDLK_e: if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & KMOD_CTRL)) { - cheatsEnabled = !cheatsEnabled; - systemConsoleMessage(cheatsEnabled ? "Cheats on" : "Cheats off"); + coreOptions.cheatsEnabled = !coreOptions.cheatsEnabled; + systemConsoleMessage(coreOptions.cheatsEnabled ? "Cheats on" : "Cheats off"); } break; @@ -1291,8 +1293,8 @@ void sdlPollEvents() } } else if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & KMOD_CTRL)) { int mask = 0x0100 << (event.key.keysym.sym - SDLK_1); - layerSettings ^= mask; - layerEnable = DISPCNT & layerSettings; + coreOptions.layerSettings ^= mask; + coreOptions.layerEnable = DISPCNT & coreOptions.layerSettings; CPUUpdateRenderBuffers(false); } break; @@ -1302,8 +1304,8 @@ void sdlPollEvents() case SDLK_8: if (!(event.key.keysym.mod & MOD_NOCTRL) && (event.key.keysym.mod & KMOD_CTRL)) { int mask = 0x0100 << (event.key.keysym.sym - SDLK_1); - layerSettings ^= mask; - layerEnable = DISPCNT & layerSettings; + coreOptions.layerSettings ^= mask; + coreOptions.layerEnable = DISPCNT & coreOptions.layerSettings; } break; case SDLK_n: @@ -1561,7 +1563,7 @@ int main(int argc, char** argv) frameSkip = 2; gbBorderOn = 0; - parseDebug = true; + coreOptions.parseDebug = true; gb_effects_config.stereo = 0.0; gb_effects_config.echo = 0.0; @@ -1718,7 +1720,7 @@ int main(int argc, char** argv) // used for the handling of the gb Boot Rom if (gbHardware & 7) - gbCPUInit(biosFileNameGB, useBios); + gbCPUInit(biosFileNameGB, coreOptions.useBios); cartridgeType = IMAGE_GB; emulator = GBSystem; @@ -1738,19 +1740,19 @@ int main(int argc, char** argv) int size = CPULoadRom(szFile); failed = (size == 0); if (!failed) { - if (cpuSaveType == 0) + if (coreOptions.cpuSaveType == 0) utilGBAFindSave(size); else - saveType = cpuSaveType; + coreOptions.saveType = coreOptions.cpuSaveType; sdlApplyPerImagePreferences(); - doMirroring(mirroringEnable); + doMirroring(coreOptions.mirroringEnable); cartridgeType = 0; emulator = GBASystem; - CPUInit(biosFileNameGBA, useBios); + CPUInit(biosFileNameGBA, coreOptions.useBios); int patchnum; for (patchnum = 0; patchnum < patchNum; patchnum++) { fprintf(stdout, "Trying patch %s%s\n", patchNames[patchnum], @@ -1780,7 +1782,7 @@ int main(int argc, char** argv) emulator = GBASystem; - CPUInit(biosFileNameGBA, useBios); + CPUInit(biosFileNameGBA, coreOptions.useBios); CPUReset(); } diff --git a/src/wx/cmdevents.cpp b/src/wx/cmdevents.cpp index f59dc0e6..e81a05e7 100644 --- a/src/wx/cmdevents.cpp +++ b/src/wx/cmdevents.cpp @@ -1800,9 +1800,9 @@ EVT_HANDLER(KeepSaves, "Do not load battery saves (toggle)") { bool menuPress = false; GetMenuOptionBool("KeepSaves", &menuPress); - toggleBitVar(&menuPress, &skipSaveGameBattery, 1); + toggleBitVar(&menuPress, &coreOptions.skipSaveGameBattery, 1); SetMenuOption("KeepSaves", menuPress ? 1 : 0); - GetMenuOptionInt("KeepSaves", &skipSaveGameBattery, 1); + GetMenuOptionInt("KeepSaves", &coreOptions.skipSaveGameBattery, 1); update_opts(); } @@ -1811,9 +1811,9 @@ EVT_HANDLER(KeepCheats, "Do not change cheat list (toggle)") { bool menuPress = false; GetMenuOptionBool("KeepCheats", &menuPress); - toggleBitVar(&menuPress, &skipSaveGameCheats, 1); + toggleBitVar(&menuPress, &coreOptions.skipSaveGameCheats, 1); SetMenuOption("KeepCheats", menuPress ? 1 : 0); - GetMenuOptionInt("KeepCheats", &skipSaveGameCheats, 1); + GetMenuOptionInt("KeepCheats", &coreOptions.skipSaveGameCheats, 1); update_opts(); } @@ -1987,9 +1987,9 @@ EVT_HANDLER(CheatsEnable, "Enable cheats (toggle)") { bool menuPress = false; GetMenuOptionBool("CheatsEnable", &menuPress); - toggleBitVar(&menuPress, &cheatsEnabled, 1); + toggleBitVar(&menuPress, &coreOptions.cheatsEnabled, 1); SetMenuOption("CheatsEnable", menuPress ? 1 : 0); - GetMenuOptionInt("CheatsEnable", &cheatsEnabled, 1); + GetMenuOptionInt("CheatsEnable", &coreOptions.cheatsEnabled, 1); update_opts(); } @@ -2015,10 +2015,10 @@ EVT_HANDLER_MASK(VideoLayersBG0, "Video layer BG0 (toggle)", CMDEN_GB | CMDEN_GB bool menuPress = false; char keyName[] = "VideoLayersBG0"; GetMenuOptionBool(keyName, &menuPress); - toggleBitVar(&menuPress, &layerSettings, (1 << 8)); + toggleBitVar(&menuPress, &coreOptions.layerSettings, (1 << 8)); SetMenuOption(keyName, menuPress ? 1 : 0); - GetMenuOptionInt(keyName, &layerSettings, (1 << 8)); - layerEnable = DISPCNT & layerSettings; + GetMenuOptionInt(keyName, &coreOptions.layerSettings, (1 << 8)); + coreOptions.layerEnable = DISPCNT & coreOptions.layerSettings; CPUUpdateRenderBuffers(false); } @@ -2027,10 +2027,10 @@ EVT_HANDLER_MASK(VideoLayersBG1, "Video layer BG1 (toggle)", CMDEN_GB | CMDEN_GB bool menuPress = false; char keyName[] = "VideoLayersBG1"; GetMenuOptionBool(keyName, &menuPress); - toggleBitVar(&menuPress, &layerSettings, (1 << 9)); + toggleBitVar(&menuPress, &coreOptions.layerSettings, (1 << 9)); SetMenuOption(keyName, menuPress ? 1 : 0); - GetMenuOptionInt(keyName, &layerSettings, (1 << 9)); - layerEnable = DISPCNT & layerSettings; + GetMenuOptionInt(keyName, &coreOptions.layerSettings, (1 << 9)); + coreOptions.layerEnable = DISPCNT & coreOptions.layerSettings; CPUUpdateRenderBuffers(false); } @@ -2039,10 +2039,10 @@ EVT_HANDLER_MASK(VideoLayersBG2, "Video layer BG2 (toggle)", CMDEN_GB | CMDEN_GB bool menuPress = false; char keyName[] = "VideoLayersBG2"; GetMenuOptionBool(keyName, &menuPress); - toggleBitVar(&menuPress, &layerSettings, (1 << 10)); + toggleBitVar(&menuPress, &coreOptions.layerSettings, (1 << 10)); SetMenuOption(keyName, menuPress ? 1 : 0); - GetMenuOptionInt(keyName, &layerSettings, (1 << 10)); - layerEnable = DISPCNT & layerSettings; + GetMenuOptionInt(keyName, &coreOptions.layerSettings, (1 << 10)); + coreOptions.layerEnable = DISPCNT & coreOptions.layerSettings; CPUUpdateRenderBuffers(false); } @@ -2051,10 +2051,10 @@ EVT_HANDLER_MASK(VideoLayersBG3, "Video layer BG3 (toggle)", CMDEN_GB | CMDEN_GB bool menuPress = false; char keyName[] = "VideoLayersBG3"; GetMenuOptionBool(keyName, &menuPress); - toggleBitVar(&menuPress, &layerSettings, (1 << 11)); + toggleBitVar(&menuPress, &coreOptions.layerSettings, (1 << 11)); SetMenuOption(keyName, menuPress ? 1 : 0); - GetMenuOptionInt(keyName, &layerSettings, (1 << 11)); - layerEnable = DISPCNT & layerSettings; + GetMenuOptionInt(keyName, &coreOptions.layerSettings, (1 << 11)); + coreOptions.layerEnable = DISPCNT & coreOptions.layerSettings; CPUUpdateRenderBuffers(false); } @@ -2063,10 +2063,10 @@ EVT_HANDLER_MASK(VideoLayersOBJ, "Video layer OBJ (toggle)", CMDEN_GB | CMDEN_GB bool menuPress = false; char keyName[] = "VideoLayersOBJ"; GetMenuOptionBool(keyName, &menuPress); - toggleBitVar(&menuPress, &layerSettings, (1 << 12)); + toggleBitVar(&menuPress, &coreOptions.layerSettings, (1 << 12)); SetMenuOption(keyName, menuPress ? 1 : 0); - GetMenuOptionInt(keyName, &layerSettings, (1 << 12)); - layerEnable = DISPCNT & layerSettings; + GetMenuOptionInt(keyName, &coreOptions.layerSettings, (1 << 12)); + coreOptions.layerEnable = DISPCNT & coreOptions.layerSettings; CPUUpdateRenderBuffers(false); } @@ -2075,10 +2075,10 @@ EVT_HANDLER_MASK(VideoLayersWIN0, "Video layer WIN0 (toggle)", CMDEN_GB | CMDEN_ bool menuPress = false; char keyName[] = "VideoLayersWIN0"; GetMenuOptionBool(keyName, &menuPress); - toggleBitVar(&menuPress, &layerSettings, (1 << 13)); + toggleBitVar(&menuPress, &coreOptions.layerSettings, (1 << 13)); SetMenuOption(keyName, menuPress ? 1 : 0); - GetMenuOptionInt(keyName, &layerSettings, (1 << 13)); - layerEnable = DISPCNT & layerSettings; + GetMenuOptionInt(keyName, &coreOptions.layerSettings, (1 << 13)); + coreOptions.layerEnable = DISPCNT & coreOptions.layerSettings; CPUUpdateRenderBuffers(false); } @@ -2087,10 +2087,10 @@ EVT_HANDLER_MASK(VideoLayersWIN1, "Video layer WIN1 (toggle)", CMDEN_GB | CMDEN_ bool menuPress = false; char keyName[] = "VideoLayersWIN1"; GetMenuOptionBool(keyName, &menuPress); - toggleBitVar(&menuPress, &layerSettings, (1 << 14)); + toggleBitVar(&menuPress, &coreOptions.layerSettings, (1 << 14)); SetMenuOption(keyName, menuPress ? 1 : 0); - GetMenuOptionInt(keyName, &layerSettings, (1 << 14)); - layerEnable = DISPCNT & layerSettings; + GetMenuOptionInt(keyName, &coreOptions.layerSettings, (1 << 14)); + coreOptions.layerEnable = DISPCNT & coreOptions.layerSettings; CPUUpdateRenderBuffers(false); } @@ -2099,10 +2099,10 @@ EVT_HANDLER_MASK(VideoLayersOBJWIN, "Video layer OBJWIN (toggle)", CMDEN_GB | CM bool menuPress = false; char keyName[] = "VideoLayersOBJWIN"; GetMenuOptionBool(keyName, &menuPress); - toggleBitVar(&menuPress, &layerSettings, (1 << 15)); + toggleBitVar(&menuPress, &coreOptions.layerSettings, (1 << 15)); SetMenuOption(keyName, menuPress ? 1 : 0); - GetMenuOptionInt(keyName, &layerSettings, (1 << 15)); - layerEnable = DISPCNT & layerSettings; + GetMenuOptionInt(keyName, &coreOptions.layerSettings, (1 << 15)); + coreOptions.layerEnable = DISPCNT & coreOptions.layerSettings; CPUUpdateRenderBuffers(false); } @@ -2117,8 +2117,8 @@ EVT_HANDLER_MASK(VideoLayersReset, "Show all video layers", CMDEN_GB | CMDEN_GBA break; \ } \ } while (0) - layerSettings = 0x7f00; - layerEnable = DISPCNT & layerSettings; + coreOptions.layerSettings = 0x7f00; + coreOptions.layerEnable = DISPCNT & coreOptions.layerSettings; set_vl("VideoLayersBG0"); set_vl("VideoLayersBG1"); set_vl("VideoLayersBG2"); @@ -2488,7 +2488,7 @@ EVT_HANDLER(SpeedupConfigure, "Speedup / Turbo options...") unsigned save_speedup_throttle = speedup_throttle; unsigned save_speedup_frame_skip = speedup_frame_skip; - bool save_speedup_throttle_frame_skip = speedup_throttle_frame_skip; + bool save_speedup_throttle_frame_skip = coreOptions.speedup_throttle_frame_skip; if (ShowModal(dlg) == wxID_OK) update_opts(); @@ -2496,7 +2496,7 @@ EVT_HANDLER(SpeedupConfigure, "Speedup / Turbo options...") // Restore values if cancel pressed. speedup_throttle = save_speedup_throttle; speedup_frame_skip = save_speedup_frame_skip; - speedup_throttle_frame_skip = save_speedup_throttle_frame_skip; + coreOptions.speedup_throttle_frame_skip = save_speedup_throttle_frame_skip; } } @@ -2980,7 +2980,7 @@ EVT_HANDLER(RetainAspect, "Retain aspect ratio when resizing") EVT_HANDLER(Printer, "Enable printer emulation") { - GetMenuOptionInt("Printer", &winGbPrinterEnabled, 1); + GetMenuOptionInt("Printer", &coreOptions.winGbPrinterEnabled, 1); #if (defined __WIN32__ || defined _WIN32) #ifndef NO_LINK gbSerialFunction = gbStartLink; @@ -2988,7 +2988,7 @@ EVT_HANDLER(Printer, "Enable printer emulation") gbSerialFunction = NULL; #endif #endif - if (winGbPrinterEnabled) + if (coreOptions.winGbPrinterEnabled) gbSerialFunction = gbPrinterSend; update_opts(); @@ -3126,7 +3126,7 @@ EVT_HANDLER(PauseWhenInactive, "Pause game when main window loses focus") EVT_HANDLER(RTC, "Enable RTC (vba-over.ini override is rtcEnabled") { - GetMenuOptionInt("RTC", &rtcEnabled, 1); + GetMenuOptionInt("RTC", &coreOptions.rtcEnabled, 1); update_opts(); } @@ -3138,7 +3138,7 @@ EVT_HANDLER(Transparent, "Draw on-screen messages transparently") EVT_HANDLER(SkipIntro, "Skip BIOS initialization") { - GetMenuOptionInt("SkipIntro", &skipBios, 1); + GetMenuOptionInt("SkipIntro", &coreOptions.skipBios, 1); update_opts(); } diff --git a/src/wx/config/internal/option-internal.cpp b/src/wx/config/internal/option-internal.cpp index 985b6690..2e396e6e 100644 --- a/src/wx/config/internal/option-internal.cpp +++ b/src/wx/config/internal/option-internal.cpp @@ -15,6 +15,8 @@ #include "config/internal/option-internal.h" #undef VBAM_OPTION_INTERNAL_INCLUDE +struct CoreOptions coreOptions; + namespace config { namespace { @@ -234,14 +236,14 @@ std::array& Option::All() { Option(OptionID::kPrefBorderAutomatic, &gbBorderAutomatic, 0, 1), Option(OptionID::kPrefBorderOn, &gbBorderOn, 0, 1), Option(OptionID::kPrefCaptureFormat, &captureFormat, 0, 1), - Option(OptionID::kPrefCheatsEnabled, &cheatsEnabled, 0, 1), + Option(OptionID::kPrefCheatsEnabled, &coreOptions.cheatsEnabled, 0, 1), Option(OptionID::kPrefDisableStatus, &disableStatusMessages, 0, 1), Option(OptionID::kPrefEmulatorType, &gbEmulatorType, 0, 5), Option(OptionID::kPrefFlashSize, &optFlashSize, 0, 1), Option(OptionID::kPrefFrameSkip, &frameSkip, -1, 9), Option(OptionID::kPrefGBPaletteOption, &gbPaletteOption, 0, 2), - Option(OptionID::kPrefGBPrinter, &winGbPrinterEnabled, 0, 1), + Option(OptionID::kPrefGBPrinter, &coreOptions.winGbPrinterEnabled, 0, 1), Option(OptionID::kPrefGDBBreakOnLoad, &gopts.gdb_break_on_load), Option(OptionID::kPrefGDBPort, &gopts.gdb_port, 0, 65535), #ifndef NO_LINK @@ -250,15 +252,15 @@ std::array& Option::All() { Option(OptionID::kPrefMaxScale, &gopts.max_scale, 0, 100), Option(OptionID::kPrefPauseWhenInactive, &pauseWhenInactive, 0, 1), - Option(OptionID::kPrefRTCEnabled, &rtcEnabled, 0, 1), - Option(OptionID::kPrefSaveType, &cpuSaveType, 0, 5), + Option(OptionID::kPrefRTCEnabled, &coreOptions.rtcEnabled, 0, 1), + Option(OptionID::kPrefSaveType, &coreOptions.cpuSaveType, 0, 5), Option(OptionID::kPrefShowSpeed, &showSpeed, 0, 2), Option(OptionID::kPrefShowSpeedTransparent, &showSpeedTransparent, 0, 1), - Option(OptionID::kPrefSkipBios, &skipBios, 0, 1), - Option(OptionID::kPrefSkipSaveGameCheats, &skipSaveGameCheats, 0, + Option(OptionID::kPrefSkipBios, &coreOptions.skipBios, 0, 1), + Option(OptionID::kPrefSkipSaveGameCheats, &coreOptions.skipSaveGameCheats, 0, 1), - Option(OptionID::kPrefSkipSaveGameBattery, &skipSaveGameBattery, + Option(OptionID::kPrefSkipSaveGameBattery, &coreOptions.skipSaveGameBattery, 0, 1), Option(OptionID::kPrefThrottle, &throttle, 0, 450), Option(OptionID::kPrefSpeedupThrottle, &speedup_throttle, 0, @@ -266,7 +268,7 @@ std::array& Option::All() { Option(OptionID::kPrefSpeedupFrameSkip, &speedup_frame_skip, 0, 300), Option(OptionID::kPrefSpeedupThrottleFrameSkip, - &speedup_throttle_frame_skip), + &coreOptions.speedup_throttle_frame_skip), Option(OptionID::kPrefUseBiosGB, &gopts.use_bios_file_gb), Option(OptionID::kPrefUseBiosGBA, &gopts.use_bios_file_gba), Option(OptionID::kPrefUseBiosGBC, &gopts.use_bios_file_gbc), diff --git a/src/wx/dsound.cpp b/src/wx/dsound.cpp index 5733aeb2..6cd8acc9 100644 --- a/src/wx/dsound.cpp +++ b/src/wx/dsound.cpp @@ -252,7 +252,7 @@ void DirectSound::write(uint16_t* finalWave, int length) LPVOID lpvPtr2; DWORD dwBytes2 = 0; - if (!speedup && throttle && !gba_joybus_active) { + if (!coreOptions.speedup && throttle && !gba_joybus_active) { hr = dsbSecondary->GetStatus(&status); if (status & DSBSTATUS_PLAYING) { diff --git a/src/wx/faudio.cpp b/src/wx/faudio.cpp index 93723ad7..57dd95b6 100644 --- a/src/wx/faudio.cpp +++ b/src/wx/faudio.cpp @@ -544,7 +544,7 @@ void FAudio_Output::write(uint16_t* finalWave, int length) break; } else { // the maximum number of buffers is currently queued - if (!speedup && throttle && !gba_joybus_active) { + if (!coreOptions.speedup && throttle && !gba_joybus_active) { // wait for one buffer to finish playing if (WaitForSingleObject(notify.hBufferEndEvent, 10000) == WAIT_TIMEOUT) { device_changed = true; diff --git a/src/wx/guiinit.cpp b/src/wx/guiinit.cpp index d377b9f2..d0c2e4bb 100644 --- a/src/wx/guiinit.cpp +++ b/src/wx/guiinit.cpp @@ -1513,9 +1513,9 @@ public: (void)ev; // unused params uint32_t sz = wxGetApp().frame->GetPanel()->game_size(); utilGBAFindSave(sz); - type->SetSelection(saveType); + type->SetSelection(coreOptions.saveType); - if (saveType == GBA_SAVE_FLASH) { + if (coreOptions.saveType == GBA_SAVE_FLASH) { size->SetSelection(flashSize == 0x20000 ? 1 : 0); size->Enable(); } else { @@ -2206,7 +2206,7 @@ public: if (val == 0) { speedup_throttle = 0; speedup_frame_skip = 0; - speedup_throttle_frame_skip = false; + coreOptions.speedup_throttle_frame_skip = false; frame_skip_cb->SetValue(false); frame_skip_cb->Disable(); @@ -2223,7 +2223,7 @@ public: } else { // val > 450 speedup_throttle = 100; - speedup_throttle_frame_skip = false; + coreOptions.speedup_throttle_frame_skip = false; unsigned rounded = std::round((double)val / 100) * 100; @@ -2252,7 +2252,7 @@ public: bool checked = frame_skip_cb->GetValue(); - speedup_throttle_frame_skip = prev_frame_skip_cb = checked; + coreOptions.speedup_throttle_frame_skip = prev_frame_skip_cb = checked; } void Init(wxShowEvent& ev) @@ -2264,7 +2264,7 @@ public: } else { speedup_throttle_spin->SetValue(speedup_throttle); - frame_skip_cb->SetValue(speedup_throttle_frame_skip); + frame_skip_cb->SetValue(coreOptions.speedup_throttle_frame_skip); if (speedup_throttle != 0) frame_skip_cb->Enable(); @@ -2275,7 +2275,7 @@ public: ev.Skip(); } private: - bool prev_frame_skip_cb = speedup_throttle_frame_skip; + bool prev_frame_skip_cb = coreOptions.speedup_throttle_frame_skip; } speedup_throttle_ctrl; ///////////////////////////// @@ -2869,19 +2869,19 @@ bool MainFrame::BindControls() MenuOptionIntMask("SoundChannel4", gopts.sound_en, (1 << 3)); MenuOptionIntMask("DirectSoundA", gopts.sound_en, (1 << 8)); MenuOptionIntMask("DirectSoundB", gopts.sound_en, (1 << 9)); - MenuOptionIntMask("VideoLayersBG0", layerSettings, (1 << 8)); - MenuOptionIntMask("VideoLayersBG1", layerSettings, (1 << 9)); - MenuOptionIntMask("VideoLayersBG2", layerSettings, (1 << 10)); - MenuOptionIntMask("VideoLayersBG3", layerSettings, (1 << 11)); - MenuOptionIntMask("VideoLayersOBJ", layerSettings, (1 << 12)); - MenuOptionIntMask("VideoLayersWIN0", layerSettings, (1 << 13)); - MenuOptionIntMask("VideoLayersWIN1", layerSettings, (1 << 14)); - MenuOptionIntMask("VideoLayersOBJWIN", layerSettings, (1 << 15)); + MenuOptionIntMask("VideoLayersBG0", coreOptions.layerSettings, (1 << 8)); + MenuOptionIntMask("VideoLayersBG1", coreOptions.layerSettings, (1 << 9)); + MenuOptionIntMask("VideoLayersBG2", coreOptions.layerSettings, (1 << 10)); + MenuOptionIntMask("VideoLayersBG3", coreOptions.layerSettings, (1 << 11)); + MenuOptionIntMask("VideoLayersOBJ", coreOptions.layerSettings, (1 << 12)); + MenuOptionIntMask("VideoLayersWIN0", coreOptions.layerSettings, (1 << 13)); + MenuOptionIntMask("VideoLayersWIN1", coreOptions.layerSettings, (1 << 14)); + MenuOptionIntMask("VideoLayersOBJWIN", coreOptions.layerSettings, (1 << 15)); MenuOptionBool("CheatsAutoSaveLoad", gopts.autoload_cheats); - MenuOptionIntMask("CheatsEnable", cheatsEnabled, 1); + MenuOptionIntMask("CheatsEnable", coreOptions.cheatsEnabled, 1); SetMenuOption("ColorizerHack", colorizerHack ? 1 : 0); - MenuOptionIntMask("KeepSaves", skipSaveGameBattery, 1); - MenuOptionIntMask("KeepCheats", skipSaveGameCheats, 1); + MenuOptionIntMask("KeepSaves", coreOptions.skipSaveGameBattery, 1); + MenuOptionIntMask("KeepCheats", coreOptions.skipSaveGameCheats, 1); MenuOptionBool("LoadGameAutoLoad", gopts.autoload_state); MenuOptionIntMask("JoypadAutofireA", autofire, KEYM_A); MenuOptionIntMask("JoypadAutofireB", autofire, KEYM_B); @@ -3452,7 +3452,7 @@ bool MainFrame::BindControls() d = LoadXRCropertySheetDialog("GameBoyAdvanceConfig"); { /// System and peripherals - ch = GetValidatedChild(d, "SaveType", wxGenericValidator(&cpuSaveType)); + ch = GetValidatedChild(d, "SaveType", wxGenericValidator(&coreOptions.cpuSaveType)); BatConfigHandler.type = ch; ch = GetValidatedChild(d, "FlashSize", wxGenericValidator(&optFlashSize)); BatConfigHandler.size = ch; diff --git a/src/wx/openal.cpp b/src/wx/openal.cpp index c2a4db7d..d12b4e7e 100644 --- a/src/wx/openal.cpp +++ b/src/wx/openal.cpp @@ -292,7 +292,7 @@ void OpenAL::write(uint16_t* finalWave, int length) } } - if (!speedup && throttle && !gba_joybus_active) { + if (!coreOptions.speedup && throttle && !gba_joybus_active) { // wait until at least one buffer has finished while (nBuffersProcessed == 0) { winlog(" waiting...\n"); diff --git a/src/wx/opts.cpp b/src/wx/opts.cpp index f76624a3..317f8356 100644 --- a/src/wx/opts.cpp +++ b/src/wx/opts.cpp @@ -305,8 +305,7 @@ const std::map> kDefaultBinding wxAcceleratorEntry_v sys_accels; -// This constructor only works with globally allocated gopts. It relies on -// the default value of every non-object to be 0. +// This constructor only works with globally allocated gopts. opts_t::opts_t() { // handle erroneous thread count values appropriately @@ -322,7 +321,6 @@ opts_t::opts_t() // These are globals being set here. frameSkip = -1; autoPatch = true; - skipSaveGameBattery = true; } // FIXME: simulate MakeInstanceFilename(vbam.ini) using subkeys (Slave%d/*) diff --git a/src/wx/panel.cpp b/src/wx/panel.cpp index cd737e03..17c67ff0 100644 --- a/src/wx/panel.cpp +++ b/src/wx/panel.cpp @@ -275,7 +275,7 @@ void GameArea::LoadGame(const wxString& name) gbCPUInit(fn, use_bios); - if (use_bios && !useBios) { + if (use_bios && !coreOptions.useBios) { wxLogError(_("Could not load BIOS %s"), (gbCgbMode ? gopts.gbc_bios : gopts.gb_bios).mb_str()); // could clear use flag & file name now, but better to force // user to do it @@ -322,7 +322,7 @@ void GameArea::LoadGame(const wxString& name) if (cfg->HasGroup(id)) { cfg->SetPath(id); - bool enable_rtc = cfg->Read(wxT("rtcEnabled"), rtcEnabled); + bool enable_rtc = cfg->Read(wxT("rtcEnabled"), coreOptions.rtcEnabled); rtcEnable(enable_rtc); @@ -332,7 +332,7 @@ void GameArea::LoadGame(const wxString& name) fsz = 0x10000 << optFlashSize; flashSetSize(fsz); - ovSaveType = cfg->Read(wxT("saveType"), cpuSaveType); + ovSaveType = cfg->Read(wxT("coreOptions.saveType"), coreOptions.cpuSaveType); if (ovSaveType < 0 || ovSaveType > 5) ovSaveType = 0; @@ -340,26 +340,26 @@ void GameArea::LoadGame(const wxString& name) if (ovSaveType == 0) utilGBAFindSave(rom_size); else - saveType = ovSaveType; + coreOptions.saveType = ovSaveType; - mirroringEnable = cfg->Read(wxT("mirroringEnabled"), (long)1); + coreOptions.mirroringEnable = cfg->Read(wxT("mirroringEnabled"), (long)1); cfg->SetPath(wxT("/")); } else { - rtcEnable(rtcEnabled); + rtcEnable(coreOptions.rtcEnabled); flashSetSize(0x10000 << optFlashSize); - if (cpuSaveType < 0 || cpuSaveType > 5) - cpuSaveType = 0; + if (coreOptions.cpuSaveType < 0 || coreOptions.cpuSaveType > 5) + coreOptions.cpuSaveType = 0; - if (cpuSaveType == 0) + if (coreOptions.cpuSaveType == 0) utilGBAFindSave(rom_size); else - saveType = cpuSaveType; + coreOptions.saveType = coreOptions.cpuSaveType; - mirroringEnable = false; + coreOptions.mirroringEnable = false; } - doMirroring(mirroringEnable); + doMirroring(coreOptions.mirroringEnable); // start sound; this must happen before CPU stuff if (!soundInit()) { wxLogError(_("Could not initialize the sound driver!")); @@ -375,7 +375,7 @@ void GameArea::LoadGame(const wxString& name) CPUInit(UTF8(gopts.gba_bios), gopts.use_bios_file_gba); - if (gopts.use_bios_file_gba && !useBios) { + if (gopts.use_bios_file_gba && !coreOptions.useBios) { wxLogError(_("Could not load BIOS %s"), gopts.gba_bios.mb_str()); // could clear use flag & file name now, but better to force // user to do it @@ -414,7 +414,7 @@ void GameArea::LoadGame(const wxString& name) #endif // probably only need to do this for GB carts - if (winGbPrinterEnabled) + if (coreOptions.winGbPrinterEnabled) gbSerialFunction = gbPrinterSend; // probably only need to do this for GBA carts @@ -430,7 +430,7 @@ void GameArea::LoadGame(const wxString& name) mf->update_state_ts(true); bool did_autoload = gopts.autoload_state ? LoadState() : false; - if (!did_autoload || skipSaveGameBattery) { + if (!did_autoload || coreOptions.skipSaveGameBattery) { wxString bname = loaded_game.GetFullName(); #ifndef NO_LINK // MakeInstanceFilename doesn't do wxString, so just add slave ID here @@ -450,24 +450,24 @@ void GameArea::LoadGame(const wxString& name) msg.Printf(_("Loaded battery %s"), bat.GetFullPath().wc_str()); systemScreenMessage(msg); - if (cpuSaveType == 0 && ovSaveType == 0 && t == IMAGE_GBA) { + if (coreOptions.cpuSaveType == 0 && ovSaveType == 0 && t == IMAGE_GBA) { switch (bat.GetSize().GetValue()) { case 0x200: case 0x2000: - saveType = GBA_SAVE_EEPROM; + coreOptions.saveType = GBA_SAVE_EEPROM; break; case 0x8000: - saveType = GBA_SAVE_SRAM; + coreOptions.saveType = GBA_SAVE_SRAM; break; case 0x10000: - if (saveType == GBA_SAVE_EEPROM || saveType == GBA_SAVE_SRAM) + if (coreOptions.saveType == GBA_SAVE_EEPROM || coreOptions.saveType == GBA_SAVE_SRAM) break; break; case 0x20000: - saveType = GBA_SAVE_FLASH; + coreOptions.saveType = GBA_SAVE_FLASH; flashSetSize(bat.GetSize().GetValue()); break; @@ -475,7 +475,7 @@ void GameArea::LoadGame(const wxString& name) break; } - SetSaveType(saveType); + SetSaveType(coreOptions.saveType); } } @@ -488,9 +488,9 @@ void GameArea::LoadGame(const wxString& name) // do a reset or load from state file when # rewinds == 0 do_rewind = gopts.rewind_interval > 0; // FIXME: backup battery file (useful if game name conflict) - cheats_dirty = (did_autoload && !skipSaveGameCheats) || (loaded == IMAGE_GB ? gbCheatNumber > 0 : cheatsNumber > 0); + cheats_dirty = (did_autoload && !coreOptions.skipSaveGameCheats) || (loaded == IMAGE_GB ? gbCheatNumber > 0 : cheatsNumber > 0); - if (gopts.autoload_cheats && (!did_autoload || skipSaveGameCheats)) { + if (gopts.autoload_cheats && (!did_autoload || coreOptions.skipSaveGameCheats)) { wxFileName cfn = loaded_game; // SetExt may strip something off by accident, so append to text instead cfn.SetFullName(cfn.GetFullName() + wxT(".clt")); diff --git a/src/wx/xaudio2.cpp b/src/wx/xaudio2.cpp index e67e2fad..da1c4565 100644 --- a/src/wx/xaudio2.cpp +++ b/src/wx/xaudio2.cpp @@ -541,7 +541,7 @@ void XAudio2_Output::write(uint16_t* finalWave, int length) break; } else { // the maximum number of buffers is currently queued - if (!speedup && throttle && !gba_joybus_active) { + if (!coreOptions.speedup && throttle && !gba_joybus_active) { // wait for one buffer to finish playing if (WaitForSingleObject(notify.hBufferEndEvent, 10000) == WAIT_TIMEOUT) { device_changed = true;