diff --git a/src/gb/GB.cpp b/src/gb/GB.cpp index 1d100944..88acaa3a 100644 --- a/src/gb/GB.cpp +++ b/src/gb/GB.cpp @@ -338,15 +338,8 @@ bool gbInitializeRom(size_t romSize) { std::fill(gbRom + romSize, gbRom + romHeaderSize, (uint8_t)0); } - // Set up globals for compatibility. - gbRomType = g_gbCartData.mapper_flag(); + // Override for compatibility. gbRom[0x147] = g_gbCartData.mapper_flag(); - gbRomSize = g_gbCartData.rom_size(); - gbRomSizeMask = g_gbCartData.rom_mask(); - gbRamSize = g_gbCartData.ram_size(); - gbRamSizeMask = g_gbCartData.ram_mask(); - gbBattery = g_gbCartData.has_battery(); - gbRTCPresent = g_gbCartData.has_rtc(); // The initial RAM byte value. uint8_t gbRamFill = 0xff; @@ -571,7 +564,6 @@ int clockTicks = 0; bool gbSystemMessage = false; int gbGBCColorType = 0; int gbHardware = 0; -int gbRomType = 0; int gbRemainingClockTicks = 0; int gbOldClockTicks = 0; int gbIntBreak = 0; @@ -649,8 +641,6 @@ int gbFrameSkipCount = 0; uint32_t gbLastTime = 0; int gbSynchronizeTicks = GBSYNCHRONIZE_CLOCK_TICKS; // emulator features -int gbBattery = 0; -int gbRTCPresent = 0; int gbCaptureNumber = 0; bool gbCapture = false; bool gbCapturePrevious = false; @@ -2182,7 +2172,7 @@ uint8_t gbReadMemory(uint16_t address) // for the 2kb ram limit (fixes crash in shawu's story // but now its sram test fails, as the it expects 8kb and not 2kb... // So use the 'genericflashcard' option to fix it). - if (address <= (0xa000 + gbRamSizeMask)) { + if (address <= (0xa000 + g_gbCartData.ram_mask())) { if (g_mapperReadRAM) { return g_mapperReadRAM(address); } @@ -2975,7 +2965,8 @@ void gbReset() inBios = true; } else if (gbHardware & 0xa) { // Set compatibility mode if it is a DMG ROM. - gbMemory[0xff6c] = 0xfe | (uint8_t) !(gbRom[0x143] & 0x80); + const uint8_t gbcFlag = g_gbCartData.SupportsCGB() ? 0x80 : 0x00; + gbMemory[0xff6c] = 0xfe | gbcFlag; } gbLine99Ticks = 1; @@ -3604,7 +3595,7 @@ static bool gbReadSaveState(gzFile gzFile) gbSoundReadGame(version, gzFile); if (gbCgbMode && gbSgbMode) { - gbSgbMode = 0; + gbSgbMode = false; } if (gbBorderOn && !gbSgbMask) { @@ -5218,7 +5209,7 @@ bool gbReadSaveState(const uint8_t* data) gbSoundReadGame(data); if (gbCgbMode && gbSgbMode) { - gbSgbMode = 0; + gbSgbMode = false; } if (gbBorderOn && !gbSgbMask) { diff --git a/src/gb/gb.h b/src/gb/gb.h index 6536fa84..d2aa8a03 100644 --- a/src/gb/gb.h +++ b/src/gb/gb.h @@ -63,9 +63,6 @@ void setColorizerHack(bool value); bool allowColorizerHack(void); extern int gbHardware; -extern int gbRomType; // gets type from header 0x147 -extern int gbBattery; // enabled when gbRamSize != 0 -extern int gbRTCPresent; // gbROM has RTC support extern gbCartData g_gbCartData; extern struct EmulatedSystem GBSystem; diff --git a/src/gb/gbGlobals.cpp b/src/gb/gbGlobals.cpp index 2564ba71..837652fb 100644 --- a/src/gb/gbGlobals.cpp +++ b/src/gb/gbGlobals.cpp @@ -3,11 +3,6 @@ uint8_t* gbMemoryMap[16]; -int gbRomSizeMask = 0; -int gbRomSize = 0; -int gbRamSizeMask = 0; -int gbRamSize = 0; - uint8_t* gbMemory = nullptr; uint8_t* gbVram = nullptr; uint8_t* gbRom = nullptr; @@ -22,9 +17,6 @@ uint8_t gbObp0[4] = { 0, 1, 2, 3 }; uint8_t gbObp1[4] = { 0, 1, 2, 3 }; int gbWindowLine = -1; -bool genericflashcardEnable = false; -int gbCgbMode = 0; - uint16_t gbColorFilter[32768]; uint32_t gbEmulatorType = 0; uint32_t gbPaletteOption = 0; @@ -34,6 +26,8 @@ int gbBorderColumnSkip = 0; int gbDmaTicks = 0; bool gbBorderAutomatic = false; bool gbBorderOn = false; +bool gbCgbMode = false; +bool gbSgbMode = false; bool gbColorOption = false; uint8_t (*gbSerialFunction)(uint8_t) = NULL; diff --git a/src/gb/gbGlobals.h b/src/gb/gbGlobals.h index 210c37d8..28cdda58 100644 --- a/src/gb/gbGlobals.h +++ b/src/gb/gbGlobals.h @@ -3,11 +3,6 @@ #include "../common/Types.h" -extern int gbRomSizeMask; -extern int gbRomSize; -extern int gbRamSize; -extern int gbRamSizeMask; - extern uint8_t* bios; extern uint8_t* gbRom; @@ -24,8 +19,8 @@ extern int gbFrameSkip; extern uint16_t gbColorFilter[32768]; extern uint32_t gbEmulatorType; extern uint32_t gbPaletteOption; -extern int gbCgbMode; -extern int gbSgbMode; +extern bool gbCgbMode; +extern bool gbSgbMode; extern int gbWindowLine; extern int gbSpeed; extern uint8_t gbBgp[4]; @@ -58,7 +53,6 @@ extern uint8_t register_VBK; extern uint8_t oldRegister_WY; extern int emulating; -extern bool genericflashcardEnable; extern int gbBorderLineSkip; extern int gbBorderRowSkip; diff --git a/src/gb/gbMemory.cpp b/src/gb/gbMemory.cpp index 9d1d8d9e..cd4f7cd5 100644 --- a/src/gb/gbMemory.cpp +++ b/src/gb/gbMemory.cpp @@ -1,10 +1,10 @@ #include "gbMemory.h" #include "../System.h" #include "../common/Port.h" +#include "../common/sizes.h" #include "gb.h" #include "gbGlobals.h" uint8_t gbDaysinMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; -const uint8_t gbDisabledRam[8] = { 0x80, 0xff, 0xf0, 0x00, 0x30, 0xbf, 0xbf, 0xbf }; extern int gbGBCColorType; extern gbRegister PC; @@ -48,7 +48,7 @@ void mapperMBC1ROM(uint16_t address, uint8_t value) tmpAddress |= (gbDataMBC1.mapperROMHighAddress & 3) << 19; } - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbDataMBC1.mapperROMBank = value; gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; @@ -57,11 +57,11 @@ void mapperMBC1ROM(uint16_t address, uint8_t value) break; case 0x4000: // RAM bank select if (gbDataMBC1.mapperMemoryModel == 1) { - if (!gbRamSize) { + if (!g_gbCartData.HasRam()) { if (gbDataMBC1.mapperRomBank0Remapping == 3) { gbDataMBC1.mapperROMHighAddress = value & 0x03; tmpAddress = (gbDataMBC1.mapperROMHighAddress) << 18; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x00] = &gbRom[tmpAddress]; gbMemoryMap[0x01] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x02] = &gbRom[tmpAddress + 0x2000]; @@ -78,8 +78,8 @@ void mapperMBC1ROM(uint16_t address, uint8_t value) if (value == gbDataMBC1.mapperRAMBank) break; tmpAddress = value << 13; - tmpAddress &= gbRamSizeMask; - if (gbRamSize) { + tmpAddress &= g_gbCartData.ram_mask(); + if (g_gbCartData.HasRam()) { gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; } @@ -93,12 +93,12 @@ void mapperMBC1ROM(uint16_t address, uint8_t value) gbDataMBC1.mapperROMHighAddress = value & 0x03; tmpAddress = gbDataMBC1.mapperROMBank << 14; tmpAddress |= (gbDataMBC1.mapperROMHighAddress) << 19; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; - if (gbRamSize) { + if (g_gbCartData.HasRam()) { gbMemoryMap[0x0a] = &gbRam[0]; gbMemoryMap[0x0b] = &gbRam[0x1000]; } @@ -114,8 +114,8 @@ void mapperMBC1ROM(uint16_t address, uint8_t value) value = gbDataMBC1.mapperRAMBank & 0x03; tmpAddress = value << 13; - tmpAddress &= gbRamSizeMask; - if (gbRamSize) { + tmpAddress &= g_gbCartData.ram_mask(); + if (g_gbCartData.HasRam()) { gbMemoryMap[0x0a] = &gbRam[gbDataMBC1.mapperRAMAddress]; gbMemoryMap[0x0b] = &gbRam[gbDataMBC1.mapperRAMAddress + 0x1000]; gbDataMBC1.mapperRomBank0Remapping = 0; @@ -127,7 +127,7 @@ void mapperMBC1ROM(uint16_t address, uint8_t value) tmpAddress = gbDataMBC1.mapperROMBank << 14; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; @@ -138,12 +138,12 @@ void mapperMBC1ROM(uint16_t address, uint8_t value) tmpAddress = gbDataMBC1.mapperROMBank << 14; tmpAddress |= (gbDataMBC1.mapperROMHighAddress) << 19; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; - if (gbRamSize) { + if (g_gbCartData.HasRam()) { gbMemoryMap[0x0a] = &gbRam[0]; gbMemoryMap[0x0b] = &gbRam[0x1000]; } @@ -156,7 +156,7 @@ void mapperMBC1ROM(uint16_t address, uint8_t value) void mapperMBC1RAM(uint16_t address, uint8_t value) { if (gbDataMBC1.mapperRAMEnable) { - if (gbRamSize) { + if (g_gbCartData.HasRam()) { gbMemoryMap[address >> 12][address & 0x0fff] = value; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; } @@ -170,23 +170,7 @@ uint8_t mapperMBC1ReadRAM(uint16_t address) if (gbDataMBC1.mapperRAMEnable) return gbMemoryMap[address >> 12][address & 0x0fff]; - if (!genericflashcardEnable) - return 0xff; - else if ((address & 0x1000) >= 0x1000) { - // The value returned when reading RAM while it's disabled - // is constant, exept for the GBASP hardware. - // (actually, is the address that read is out of the ROM, the returned value if 0xff...) - if (PC.W >= 0xff80) - return 0xff; - else if ((gbHardware & 0x08) && (gbGBCColorType == 2)) { - if (address & 1) - return 0xfb; - else - return 0x7a; - } else - return 0x0a; - } else - return gbDisabledRam[address & 7]; + return 0xff; } void memoryUpdateMapMBC1() @@ -196,7 +180,7 @@ void memoryUpdateMapMBC1() // check current model if (gbDataMBC1.mapperRomBank0Remapping == 3) { tmpAddress = (gbDataMBC1.mapperROMHighAddress & 3) << 18; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x00] = &gbRom[tmpAddress]; gbMemoryMap[0x01] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x02] = &gbRom[tmpAddress + 0x2000]; @@ -213,14 +197,14 @@ void memoryUpdateMapMBC1() tmpAddress |= (gbDataMBC1.mapperROMHighAddress & 3) << 19; } - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; } - if (gbRamSize) { + if (g_gbCartData.HasRam()) { if (gbDataMBC1.mapperMemoryModel == 1) { gbMemoryMap[0x0a] = &gbRam[gbDataMBC1.mapperRAMAddress]; gbMemoryMap[0x0b] = &gbRam[gbDataMBC1.mapperRAMAddress + 0x1000]; @@ -256,7 +240,7 @@ void mapperMBC2ROM(uint16_t address, uint8_t value) int tmpAddress = value << 14; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; @@ -272,7 +256,7 @@ void mapperMBC2ROM(uint16_t address, uint8_t value) void mapperMBC2RAM(uint16_t address, uint8_t value) { if (gbDataMBC2.mapperRAMEnable) { - if (gbRamSize && address < 0xa200) { + if (g_gbCartData.ram_size() && address < 0xa200) { gbMemoryMap[address >> 12][address & 0x0fff] = value; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; } @@ -283,7 +267,7 @@ void memoryUpdateMapMBC2() { int tmpAddress = gbDataMBC2.mapperROMBank << 14; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; @@ -362,7 +346,7 @@ void mapperMBC3ROM(uint16_t address, uint8_t value) gbDataMBC3.mapperRAMEnable = ((value & 0x0a) == 0x0a ? 1 : 0); break; case 0x2000: { // ROM bank select - if (gbRomSize != 0x00400000) + if (g_gbCartData.rom_size() != k4MiB) value = value & 0x7f; // Assume 2MiB, unless MBC30. if (value == 0) @@ -372,7 +356,7 @@ void mapperMBC3ROM(uint16_t address, uint8_t value) tmpAddress = value << 14; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbDataMBC3.mapperROMBank = value; @@ -388,13 +372,13 @@ void mapperMBC3ROM(uint16_t address, uint8_t value) if (value == gbDataMBC3.mapperRAMBank) break; tmpAddress = value << 13; - tmpAddress &= gbRamSizeMask; + tmpAddress &= g_gbCartData.ram_mask(); gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; gbDataMBC3.mapperRAMBank = value; gbDataMBC3.mapperRAMAddress = tmpAddress; } else { - if (gbRTCPresent && gbDataMBC3.mapperRAMEnable) { + if (g_gbCartData.has_rtc() && gbDataMBC3.mapperRAMEnable) { gbDataMBC3.mapperRAMBank = -1; gbDataMBC3.mapperClockRegister = value; @@ -402,7 +386,7 @@ void mapperMBC3ROM(uint16_t address, uint8_t value) } break; case 0x6000: // clock latch - if (gbRTCPresent) { + if (g_gbCartData.has_rtc()) { if (gbDataMBC3.mapperClockLatch == 0 && value == 1) { memoryUpdateMBC3Clock(); gbDataMBC3.mapperLSeconds = gbDataMBC3.mapperSeconds; @@ -423,11 +407,11 @@ void mapperMBC3RAM(uint16_t address, uint8_t value) { if (gbDataMBC3.mapperRAMEnable) { if (gbDataMBC3.mapperRAMBank >= 0) { - if (gbRamSize) { + if (g_gbCartData.ram_size()) { gbMemoryMap[address >> 12][address & 0x0fff] = value; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; } - } else if (gbRTCPresent) { + } else if (g_gbCartData.has_rtc()) { time(&gbDataMBC3.mapperLastTime); switch (gbDataMBC3.mapperClockRegister) { case 0x08: @@ -459,7 +443,7 @@ uint8_t mapperMBC3ReadRAM(uint16_t address) if (gbDataMBC3.mapperRAMEnable) { if (gbDataMBC3.mapperRAMBank >= 0) { return gbMemoryMap[address >> 12][address & 0x0fff]; - } else if (gbRTCPresent) { + } else if (g_gbCartData.has_rtc()) { switch (gbDataMBC3.mapperClockRegister) { case 0x08: return gbDataMBC3.mapperLSeconds; @@ -479,39 +463,23 @@ uint8_t mapperMBC3ReadRAM(uint16_t address) } } - if (!genericflashcardEnable) - return 0xff; - else if ((address & 0x1000) >= 0x1000) { - // The value returned when reading RAM while it's disabled - // is constant, exept for the GBASP hardware. - // (actually, is the address that read is out of the ROM, the returned value if 0xff...) - if (PC.W >= 0xff80) - return 0xff; - else if ((gbHardware & 0x08) && (gbGBCColorType == 2)) { - if (address & 1) - return 0xfb; - else - return 0x7a; - } else - return 0x0a; - } else - return gbDisabledRam[address & 7]; + return 0xff; } void memoryUpdateMapMBC3() { int tmpAddress = gbDataMBC3.mapperROMBank << 14; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; - if (gbDataMBC3.mapperRAMBank >= 0 && gbRamSize) { + if (gbDataMBC3.mapperRAMBank >= 0 && g_gbCartData.HasRam()) { tmpAddress = gbDataMBC3.mapperRAMBank << 13; - tmpAddress &= gbRamSizeMask; + tmpAddress &= g_gbCartData.ram_mask(); gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; } @@ -544,7 +512,7 @@ void mapperMBC5ROM(uint16_t address, uint8_t value) tmpAddress = (value << 14) | (gbDataMBC5.mapperROMHighAddress << 22); - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbDataMBC5.mapperROMBank = value; gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; @@ -558,7 +526,7 @@ void mapperMBC5ROM(uint16_t address, uint8_t value) tmpAddress = (gbDataMBC5.mapperROMBank << 14) | (value << 22); - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbDataMBC5.mapperROMHighAddress = value; gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; @@ -575,8 +543,8 @@ void mapperMBC5ROM(uint16_t address, uint8_t value) if (value == gbDataMBC5.mapperRAMBank) break; tmpAddress = value << 13; - tmpAddress &= gbRamSizeMask; - if (gbRamSize) { + tmpAddress &= g_gbCartData.ram_mask(); + if (g_gbCartData.HasRam()) { gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; @@ -591,7 +559,7 @@ void mapperMBC5ROM(uint16_t address, uint8_t value) void mapperMBC5RAM(uint16_t address, uint8_t value) { if (gbDataMBC5.mapperRAMEnable) { - if (gbRamSize) { + if (g_gbCartData.HasRam()) { gbMemoryMap[address >> 12][address & 0x0fff] = value; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; } @@ -605,38 +573,22 @@ uint8_t mapperMBC5ReadRAM(uint16_t address) if (gbDataMBC5.mapperRAMEnable) return gbMemoryMap[address >> 12][address & 0x0fff]; - if (!genericflashcardEnable) - return 0xff; - else if ((address & 0x1000) >= 0x1000) { - // The value returned when reading RAM while it's disabled - // is constant, exept for the GBASP hardware. - // (actually, is the address that read is out of the ROM, the returned value if 0xff...) - if (PC.W >= 0xff80) - return 0xff; - else if ((gbHardware & 0x08) && (gbGBCColorType == 2)) { - if (address & 1) - return 0xfb; - else - return 0x7a; - } else - return 0x0a; - } else - return gbDisabledRam[address & 7]; + return 0xff; } void memoryUpdateMapMBC5() { int tmpAddress = (gbDataMBC5.mapperROMBank << 14) | (gbDataMBC5.mapperROMHighAddress << 22); - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; - if (gbRamSize) { + if (g_gbCartData.HasRam()) { tmpAddress = gbDataMBC5.mapperRAMBank << 13; - tmpAddress &= gbRamSizeMask; + tmpAddress &= g_gbCartData.ram_mask(); gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; } @@ -677,7 +629,7 @@ void mapperMBC7ROM(uint16_t address, uint8_t value) tmpAddress = (value << 14); - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbDataMBC7.mapperROMBank = value; gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; @@ -687,7 +639,7 @@ void mapperMBC7ROM(uint16_t address, uint8_t value) case 0x4000: // RAM bank select/enable if (value < 8) { tmpAddress = (value & 3) << 13; - tmpAddress &= gbRamSizeMask; + tmpAddress &= g_gbCartData.ram_mask(); gbMemoryMap[0x0a] = &gbMemory[0xa000]; gbMemoryMap[0x0b] = &gbMemory[0xb000]; @@ -726,23 +678,7 @@ uint8_t mapperMBC7ReadRAM(uint16_t address) return gbDataMBC7.value; } - if (!genericflashcardEnable) - return 0xff; - else if ((address & 0x1000) >= 0x1000) { - // The value returned when reading RAM while it's disabled - // is constant, exept for the GBASP hardware. - // (actually, is the address that read is out of the ROM, the returned value if 0xff...) - if (PC.W >= 0xff80) - return 0xff; - else if ((gbHardware & 0x08) && (gbGBCColorType == 2)) { - if (address & 1) - return 0xfb; - else - return 0x7a; - } else - return 0x0a; - } else - return gbDisabledRam[address & 7]; + return 0xff; } // MBC7 RAM write @@ -892,7 +828,7 @@ void memoryUpdateMapMBC7() { int tmpAddress = (gbDataMBC7.mapperROMBank << 14); - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; @@ -926,7 +862,7 @@ void mapperHuC1ROM(uint16_t address, uint8_t value) tmpAddress = value << 14; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbDataHuC1.mapperROMBank = value; gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; @@ -940,7 +876,7 @@ void mapperHuC1ROM(uint16_t address, uint8_t value) if (value == gbDataHuC1.mapperRAMBank) break; tmpAddress = value << 13; - tmpAddress &= gbRamSizeMask; + tmpAddress &= g_gbCartData.ram_mask(); gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; gbDataHuC1.mapperRAMBank = value; @@ -950,7 +886,7 @@ void mapperHuC1ROM(uint16_t address, uint8_t value) gbDataHuC1.mapperROMHighAddress = value & 0x03; tmpAddress = gbDataHuC1.mapperROMBank << 14; tmpAddress |= (gbDataHuC1.mapperROMHighAddress) << 19; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; @@ -967,7 +903,7 @@ void mapperHuC1ROM(uint16_t address, uint8_t value) void mapperHuC1RAM(uint16_t address, uint8_t value) { if (gbDataHuC1.mapperRAMEnable) { - if (gbRamSize) { + if (g_gbCartData.HasRam()) { gbMemoryMap[address >> 12][address & 0x0fff] = value; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; } @@ -978,16 +914,16 @@ void memoryUpdateMapHuC1() { int tmpAddress = gbDataHuC1.mapperROMBank << 14; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; - if (gbRamSize) { + if (g_gbCartData.HasRam()) { tmpAddress = gbDataHuC1.mapperRAMBank << 13; - tmpAddress &= gbRamSizeMask; + tmpAddress &= g_gbCartData.ram_mask(); gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; } @@ -1012,7 +948,7 @@ mapperHuC3 gbDataHuC3 = { }; mapperHuC3RTC gbRTCHuC3 = { - 0, // lastTime + {0}, // lastTime 0, // DateTime 0, // WritingTime 0, // ModeFlag @@ -1058,7 +994,7 @@ void mapperHuC3ROM(uint16_t address, uint8_t value) tmpAddress = value << 14; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbDataHuC3.mapperROMBank = value; gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; @@ -1070,7 +1006,7 @@ void mapperHuC3ROM(uint16_t address, uint8_t value) if (value == gbDataHuC3.mapperRAMBank) break; tmpAddress = value << 13; - tmpAddress &= gbRamSizeMask; + tmpAddress &= g_gbCartData.ram_mask(); gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; gbDataHuC3.mapperRAMBank = value; @@ -1099,7 +1035,7 @@ void mapperHuC3RAM(uint16_t address, uint8_t value) if (gbDataHuC3.mapperRAMFlag < 0x0b || gbDataHuC3.mapperRAMFlag > 0x0e) { if (gbDataHuC3.mapperRAMEnable) { - if (gbRamSize) { + if (g_gbCartData.ram_size()) { gbMemoryMap[address >> 12][address & 0x0fff] = value; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; } @@ -1196,15 +1132,15 @@ void memoryUpdateMapHuC3() { int tmpAddress = gbDataHuC3.mapperROMBank << 14; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; - if (gbRamSize) { + if (g_gbCartData.ram_size()) { tmpAddress = gbDataHuC3.mapperRAMBank << 13; - tmpAddress &= gbRamSizeMask; + tmpAddress &= g_gbCartData.ram_mask(); gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; } @@ -1333,7 +1269,7 @@ void mapperTAMA5RAM(uint16_t address, uint8_t value) int tmpAddress = (gbDataTAMA5.mapperROMBank << 14); - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; @@ -1492,7 +1428,7 @@ void mapperTAMA5RAM(uint16_t address, uint8_t value) } else { if (gbDataTAMA5.mapperRAMEnable) { if (gbDataTAMA5.mapperRAMBank != -1) { - if (gbRamSize) { + if (g_gbCartData.HasRam()) { gbMemoryMap[address >> 12][address & 0x0fff] = value; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; } @@ -1511,15 +1447,15 @@ void memoryUpdateMapTAMA5() { int tmpAddress = (gbDataTAMA5.mapperROMBank << 14); - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; - if (gbRamSize) { + if (g_gbCartData.HasRam()) { tmpAddress = 0 << 13; - tmpAddress &= gbRamSizeMask; + tmpAddress &= g_gbCartData.ram_mask(); gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; } @@ -1561,7 +1497,7 @@ void mapperMMM01ROM(uint16_t address, uint8_t value) } else tmpAddress |= gbDataMMM01.mapperRomBank0Remapping << 18; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbDataMMM01.mapperROMBank = value; gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; @@ -1575,7 +1511,7 @@ void mapperMMM01ROM(uint16_t address, uint8_t value) if (value == gbDataMBC1.mapperRAMBank) break; tmpAddress = value << 13; - tmpAddress &= gbRamSizeMask; + tmpAddress &= g_gbCartData.ram_mask(); gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; gbDataMMM01.mapperRAMBank = value; @@ -1585,7 +1521,7 @@ void mapperMMM01ROM(uint16_t address, uint8_t value) gbDataMMM01.mapperROMHighAddress = value & 0x03; tmpAddress = gbDataMMM01.mapperROMBank << 14; tmpAddress |= (gbDataMMM01.mapperROMHighAddress) << 19; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; @@ -1593,7 +1529,7 @@ void mapperMMM01ROM(uint16_t address, uint8_t value) gbDataMMM01.mapperRomBank0Remapping = ((value << 1) | (value & 0x40 ? 1 : 0)) & 0xff; tmpAddress = gbDataMMM01.mapperRomBank0Remapping << 18; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x00] = &gbRom[tmpAddress]; gbMemoryMap[0x01] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x02] = &gbRom[tmpAddress + 0x2000]; @@ -1610,7 +1546,7 @@ void mapperMMM01ROM(uint16_t address, uint8_t value) void mapperMMM01RAM(uint16_t address, uint8_t value) { if (gbDataMMM01.mapperRAMEnable) { - if (gbRamSize) { + if (g_gbCartData.HasRam()) { gbMemoryMap[address >> 12][address & 0x0fff] = value; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; } @@ -1627,20 +1563,20 @@ void memoryUpdateMapMMM01() tmpAddress |= (gbDataMMM01.mapperROMHighAddress) << 19; } - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; tmpAddress = gbDataMMM01.mapperRomBank0Remapping << 18; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbMemoryMap[0x00] = &gbRom[tmpAddress]; gbMemoryMap[0x01] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x02] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x03] = &gbRom[tmpAddress + 0x3000]; - if (gbRamSize) { + if (g_gbCartData.HasRam()) { gbMemoryMap[0x0a] = &gbRam[gbDataMMM01.mapperRAMAddress]; gbMemoryMap[0x0b] = &gbRam[gbDataMMM01.mapperRAMAddress + 0x1000]; } @@ -1685,7 +1621,7 @@ void mapperGS3ROM(uint16_t address, uint8_t value) break; tmpAddress = value << 13; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); gbDataGS3.mapperROMBank = value; gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; @@ -1699,7 +1635,7 @@ void memoryUpdateMapGS3() { int tmpAddress = gbDataGS3.mapperROMBank << 13; - tmpAddress &= gbRomSizeMask; + tmpAddress &= g_gbCartData.rom_mask(); // GS can only change a half ROM bank gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; diff --git a/src/gb/gbSGB.cpp b/src/gb/gbSGB.cpp index e88d9ba0..a371da38 100644 --- a/src/gb/gbSGB.cpp +++ b/src/gb/gbSGB.cpp @@ -20,7 +20,6 @@ uint8_t* gbSgbBorder = NULL; int gbSgbCGBSupport = 0; int gbSgbMask = 0; -int gbSgbMode = 0; int gbSgbPacketState = GBSGB_NONE; int gbSgbBit = 0; int gbSgbPacketTimeout = 0; @@ -328,7 +327,7 @@ void gbSgbPicture() if (gbSgbMode && gbCgbMode && gbSgbCGBSupport > 4) { gbSgbCGBSupport = 0; - gbSgbMode = 0; + gbSgbMode = false; gbSgbMask = 0; gbSgbRenderBorder(); gbReset(); @@ -672,7 +671,7 @@ void gbSgbChrTransfer() if (gbSgbMode && gbCgbMode && gbSgbCGBSupport == 7) { gbSgbCGBSupport = 0; - gbSgbMode = 0; + gbSgbMode = false; gbSgbMask = 0; gbSgbRenderBorder(); gbReset(); diff --git a/src/gb/gbSGB.h b/src/gb/gbSGB.h index 069b08ea..567087ca 100644 --- a/src/gb/gbSGB.h +++ b/src/gb/gbSGB.h @@ -17,7 +17,6 @@ void gbSgbReadGame(gzFile, int version); #endif extern uint8_t gbSgbATF[20 * 18]; -extern int gbSgbMode; extern int gbSgbMask; extern int gbSgbMultiplayer; extern uint8_t gbSgbNextController; diff --git a/src/libretro/libretro.cpp b/src/libretro/libretro.cpp index 855c8a76..e7b70ae4 100644 --- a/src/libretro/libretro.cpp +++ b/src/libretro/libretro.cpp @@ -16,6 +16,7 @@ #include "../apu/Gb_Apu.h" #include "../apu/Gb_Oscs.h" #include "../common/Port.h" +#include "../common/sizes.h" #include "../gba/Cheats.h" #include "../gba/EEprom.h" #include "../gba/Flash.h" @@ -165,28 +166,56 @@ static void set_gbPalette(void) static void* gb_rtcdata_prt(void) { - switch (gbRomType) { - case 0x0f: - case 0x10: // MBC3 + extended + switch (g_gbCartData.mapper_type()) { + case gbCartData::MapperType::kMbc3: return &gbDataMBC3.mapperSeconds; - case 0xfd: // TAMA5 + extended + case gbCartData::MapperType::kTama5: return &gbDataTAMA5.mapperSeconds; - case 0xfe: // HuC3 + Clock + case gbCartData::MapperType::kHuC3: return &gbRTCHuC3.mapperLastTime; + case gbCartData::MapperType::kNone: + case gbCartData::MapperType::kMbc1: + case gbCartData::MapperType::kMbc2: + case gbCartData::MapperType::kMbc5: + case gbCartData::MapperType::kMbc6: + case gbCartData::MapperType::kMbc7: + case gbCartData::MapperType::kPocketCamera: + case gbCartData::MapperType::kMmm01: + case gbCartData::MapperType::kHuC1: + case gbCartData::MapperType::kGameGenie: + case gbCartData::MapperType::kGameShark: + case gbCartData::MapperType::kUnknown: + // Unreachable. + assert(false); + return nullptr; } - return NULL; + return nullptr; } static size_t gb_rtcdata_size(void) { - switch (gbRomType) { - case 0x0f: - case 0x10: // MBC3 + extended + switch (g_gbCartData.mapper_type()) { + case gbCartData::MapperType::kMbc3: return MBC3_RTC_DATA_SIZE; - case 0xfd: // TAMA5 + extended + case gbCartData::MapperType::kTama5: return TAMA5_RTC_DATA_SIZE; - case 0xfe: // HuC3 + Clock + case gbCartData::MapperType::kHuC3: return sizeof(gbRTCHuC3.mapperLastTime); + case gbCartData::MapperType::kNone: + case gbCartData::MapperType::kMbc1: + case gbCartData::MapperType::kMbc2: + case gbCartData::MapperType::kMbc5: + case gbCartData::MapperType::kMbc6: + case gbCartData::MapperType::kMbc7: + case gbCartData::MapperType::kPocketCamera: + case gbCartData::MapperType::kMmm01: + case gbCartData::MapperType::kHuC1: + case gbCartData::MapperType::kGameGenie: + case gbCartData::MapperType::kGameShark: + case gbCartData::MapperType::kUnknown: + // Unreachable. + assert(false); + break; } return 0; } @@ -198,9 +227,8 @@ static void gbInitRTC(void) time(&rawtime); lt = localtime(&rawtime); - switch (gbRomType) { - case 0x0f: - case 0x10: + switch (g_gbCartData.mapper_type()) { + case gbCartData::MapperType::kMbc3: gbDataMBC3.mapperSeconds = lt->tm_sec; gbDataMBC3.mapperMinutes = lt->tm_min; gbDataMBC3.mapperHours = lt->tm_hour; @@ -208,7 +236,7 @@ static void gbInitRTC(void) gbDataMBC3.mapperControl = (gbDataMBC3.mapperControl & 0xfe) | (lt->tm_yday > 255 ? 1 : 0); gbDataMBC3.mapperLastTime = rawtime; break; - case 0xfd: { + case gbCartData::MapperType::kTama5: { uint8_t gbDaysinMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int days = lt->tm_yday + 365 * 3; gbDataTAMA5.mapperSeconds = lt->tm_sec; @@ -237,9 +265,24 @@ static void gbInitRTC(void) gbDataTAMA5.mapperControl = (gbDataTAMA5.mapperControl & 0xfe) | (lt->tm_yday > 255 ? 1 : 0); } break; - case 0xfe: + case gbCartData::MapperType::kHuC3: gbRTCHuC3.mapperLastTime = rawtime; break; + case gbCartData::MapperType::kNone: + case gbCartData::MapperType::kMbc1: + case gbCartData::MapperType::kMbc2: + case gbCartData::MapperType::kMbc5: + case gbCartData::MapperType::kMbc6: + case gbCartData::MapperType::kMbc7: + case gbCartData::MapperType::kPocketCamera: + case gbCartData::MapperType::kMmm01: + case gbCartData::MapperType::kHuC1: + case gbCartData::MapperType::kGameGenie: + case gbCartData::MapperType::kGameShark: + case gbCartData::MapperType::kUnknown: + // Unreachable. + assert(false); + break; } } @@ -297,7 +340,7 @@ void* retro_get_memory_data(unsigned id) case IMAGE_GB: switch (id) { case RETRO_MEMORY_SAVE_RAM: - if (gbBattery) + if (g_gbCartData.has_battery()) data = gbRam; break; case RETRO_MEMORY_SYSTEM_RAM: @@ -307,7 +350,7 @@ void* retro_get_memory_data(unsigned id) data = (gbCgbMode ? gbVram : (gbMemory + 0x8000)); break; case RETRO_MEMORY_RTC: - if (gbRTCPresent) + if (g_gbCartData.has_rtc()) data = gb_rtcdata_prt(); break; } @@ -345,8 +388,8 @@ size_t retro_get_memory_size(unsigned id) case IMAGE_GB: switch (id) { case RETRO_MEMORY_SAVE_RAM: - if (gbBattery) - size = gbRamSize; + if (g_gbCartData.has_battery()) + size = g_gbCartData.ram_size(); break; case RETRO_MEMORY_SYSTEM_RAM: size = gbCgbMode ? 0x8000 : 0x2000; @@ -355,7 +398,7 @@ size_t retro_get_memory_size(unsigned id) size = gbCgbMode ? 0x4000 : 0x2000; break; case RETRO_MEMORY_RTC: - if (gbRTCPresent) + if (g_gbCartData.has_rtc()) size = gb_rtcdata_size(); break; } @@ -610,7 +653,7 @@ static const char *gbGetCartridgeType(void) { const char *type = "Unknown"; - switch (gbRom[0x147]) { + switch (g_gbCartData.mapper_flag()) { case 0x00: type = "ROM"; break; @@ -701,24 +744,33 @@ static const char *gbGetSaveRamSize(void) { const char *type = "Unknown"; - switch (gbRom[0x149]) { + switch (g_gbCartData.ram_size()) { case 0: type = "None"; break; - case 1: + case k256B: + type = "256B"; + break; + case k512B: + type = "512B"; + break; + case k2KiB: type = "2K"; break; - case 2: + case k8KiB: type = "8K"; break; - case 3: + case k32KiB: type = "32K"; break; - case 4: + case k64KiB: + type = "64K"; + break; + case k128KiB: type = "128K"; break; - case 5: - type = "64K"; + default: + type = "Unknown"; break; } @@ -904,33 +956,19 @@ static void gb_init(void) gbReset(); // also resets sound; set_gbPalette(); - log("Rom size : %02x (%dK)\n", gbRom[0x148], (romSize + 1023) / 1024); - log("Cartridge type : %02x (%s)\n", gbRom[0x147], gbGetCartridgeType()); - log("Ram size : %02x (%s)\n", gbRom[0x149], gbGetSaveRamSize()); + log("Rom size : %02x (%dK)\n", g_gbCartData.rom_flag(), (romSize + 1023) / 1024); + log("Cartridge type : %02x (%s)\n", g_gbCartData.mapper_flag(), gbGetCartridgeType()); + log("Ram size : %02x (%s)\n", g_gbCartData.ram_flag(), gbGetSaveRamSize()); + log("CRC : %02x (%02x)\n", g_gbCartData.header_checksum(), g_gbCartData.actual_header_checksum()); + log("Checksum : %04x (%04x)\n", g_gbCartData.global_checksum(), g_gbCartData.actual_global_checksum()); - int i = 0; - uint8_t crc = 25; - - for (i = 0x134; i < 0x14d; i++) - crc += gbRom[i]; - crc = 256 - crc; - log("CRC : %02x (%02x)\n", crc, gbRom[0x14d]); - - uint16_t crc16 = 0; - - for (i = 0; i < gbRomSize; i++) - crc16 += gbRom[i]; - - crc16 -= gbRom[0x14e] + gbRom[0x14f]; - log("Checksum : %04x (%04x)\n", crc16, gbRom[0x14e] * 256 + gbRom[0x14f]); - - if (gbBattery) + if (g_gbCartData.has_battery()) log("Game supports battery save ram.\n"); - if (gbRom[0x143] == 0xc0) + if (g_gbCartData.RequiresCGB()) log("Game works on CGB only\n"); - else if (gbRom[0x143] == 0x80) + else if (g_gbCartData.SupportsCGB()) log("Game supports GBC functions, GB compatible.\n"); - if (gbRom[0x146] == 0x03) + if (g_gbCartData.sgb_support()) log("Game supports SGB functions\n"); } @@ -1399,22 +1437,36 @@ void retro_run(void) firstrun = false; /* Check if GB game has RTC data. Has to be check here since this is where the data will be * available when using libretro api. */ - if ((type == IMAGE_GB) && gbRTCPresent) { - switch (gbRomType) { - case 0x0f: - case 0x10: + if ((type == IMAGE_GB) && g_gbCartData.has_rtc()) { + switch (g_gbCartData.mapper_type()) { + case gbCartData::MapperType::kMbc3: /* Check if any RTC has been loaded, zero value means nothing has been loaded. */ if (!gbDataMBC3.mapperLastTime) initRTC = true; break; - case 0xfd: + case gbCartData::MapperType::kTama5: if (!gbDataTAMA5.mapperLastTime) initRTC = true; break; - case 0xfe: + case gbCartData::MapperType::kHuC3: if (!gbRTCHuC3.mapperLastTime) initRTC = true; break; + case gbCartData::MapperType::kNone: + case gbCartData::MapperType::kMbc1: + case gbCartData::MapperType::kMbc2: + case gbCartData::MapperType::kMbc5: + case gbCartData::MapperType::kMbc6: + case gbCartData::MapperType::kMbc7: + case gbCartData::MapperType::kPocketCamera: + case gbCartData::MapperType::kMmm01: + case gbCartData::MapperType::kHuC1: + case gbCartData::MapperType::kGameGenie: + case gbCartData::MapperType::kGameShark: + case gbCartData::MapperType::kUnknown: + // Unreachable. + assert(false); + break; } /* Initialize RTC using local time if needed */ if (initRTC) diff --git a/src/wx/cmdevents.cpp b/src/wx/cmdevents.cpp index 29a7c723..ad387622 100644 --- a/src/wx/cmdevents.cpp +++ b/src/wx/cmdevents.cpp @@ -751,21 +751,9 @@ EVT_HANDLER_MASK(RomInformation, "ROM information...", CMDEN_GB | CMDEN_GBA) setblab("DestCode", gbRom[0x14a]); setblab("LicCode", gbRom[0x14b]); setblab("Version", gbRom[0x14c]); - uint8_t crc = 25; - - for (int i = 0x134; i < 0x14d; i++) - crc += gbRom[i]; - - crc = 256 - crc; - s.Printf(wxT("%02x (%02x)"), crc, gbRom[0x14d]); + s.Printf(wxT("%02x (%02x)"), g_gbCartData.actual_header_checksum(), g_gbCartData.header_checksum()); setlab("CRC"); - uint16_t crc16 = 0; - - for (int i = 0; i < gbRomSize; i++) - crc16 += gbRom[i]; - - crc16 -= gbRom[0x14e] + gbRom[0x14f]; - s.Printf(wxT("%04x (%04x)"), crc16, gbRom[0x14e] * 256 + gbRom[0x14f]); + s.Printf(wxT("%04x (%04x)"), g_gbCartData.actual_global_checksum(), g_gbCartData.global_checksum()); setlab("Checksum"); dlg->Fit(); ShowModal(dlg); diff --git a/src/wx/guiinit.cpp b/src/wx/guiinit.cpp index 394ba362..77a21b93 100644 --- a/src/wx/guiinit.cpp +++ b/src/wx/guiinit.cpp @@ -946,9 +946,9 @@ public: else block->data = &gbMemory[0xa000]; - block->saved = (uint8_t*)malloc(gbRamSize); - block->size = gbRamSize; - block->bits = (uint8_t*)malloc(gbRamSize >> 3); + block->saved = (uint8_t*)malloc(g_gbCartData.ram_size()); + block->size = g_gbCartData.ram_size(); + block->bits = (uint8_t*)malloc(g_gbCartData.ram_size() >> 3); if (gbCgbMode) { block++;