Remove global variables for ROM data

These can be accessed via the global gbCartData object. In addition,
this cleans up gbMemory to remove dead code that was used as a
workaround for ROM hacks.
This commit is contained in:
Fabrice de Gans 2023-04-17 18:43:11 -07:00 committed by Fabrice de Gans
parent 0e29be8735
commit 1f57d5f797
10 changed files with 202 additions and 252 deletions

View File

@ -338,15 +338,8 @@ bool gbInitializeRom(size_t romSize) {
std::fill(gbRom + romSize, gbRom + romHeaderSize, (uint8_t)0); std::fill(gbRom + romSize, gbRom + romHeaderSize, (uint8_t)0);
} }
// Set up globals for compatibility. // Override for compatibility.
gbRomType = g_gbCartData.mapper_flag();
gbRom[0x147] = g_gbCartData.mapper_flag(); 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. // The initial RAM byte value.
uint8_t gbRamFill = 0xff; uint8_t gbRamFill = 0xff;
@ -571,7 +564,6 @@ int clockTicks = 0;
bool gbSystemMessage = false; bool gbSystemMessage = false;
int gbGBCColorType = 0; int gbGBCColorType = 0;
int gbHardware = 0; int gbHardware = 0;
int gbRomType = 0;
int gbRemainingClockTicks = 0; int gbRemainingClockTicks = 0;
int gbOldClockTicks = 0; int gbOldClockTicks = 0;
int gbIntBreak = 0; int gbIntBreak = 0;
@ -649,8 +641,6 @@ int gbFrameSkipCount = 0;
uint32_t gbLastTime = 0; uint32_t gbLastTime = 0;
int gbSynchronizeTicks = GBSYNCHRONIZE_CLOCK_TICKS; int gbSynchronizeTicks = GBSYNCHRONIZE_CLOCK_TICKS;
// emulator features // emulator features
int gbBattery = 0;
int gbRTCPresent = 0;
int gbCaptureNumber = 0; int gbCaptureNumber = 0;
bool gbCapture = false; bool gbCapture = false;
bool gbCapturePrevious = 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 // 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... // but now its sram test fails, as the it expects 8kb and not 2kb...
// So use the 'genericflashcard' option to fix it). // So use the 'genericflashcard' option to fix it).
if (address <= (0xa000 + gbRamSizeMask)) { if (address <= (0xa000 + g_gbCartData.ram_mask())) {
if (g_mapperReadRAM) { if (g_mapperReadRAM) {
return g_mapperReadRAM(address); return g_mapperReadRAM(address);
} }
@ -2975,7 +2965,8 @@ void gbReset()
inBios = true; inBios = true;
} else if (gbHardware & 0xa) { } else if (gbHardware & 0xa) {
// Set compatibility mode if it is a DMG ROM. // 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; gbLine99Ticks = 1;
@ -3604,7 +3595,7 @@ static bool gbReadSaveState(gzFile gzFile)
gbSoundReadGame(version, gzFile); gbSoundReadGame(version, gzFile);
if (gbCgbMode && gbSgbMode) { if (gbCgbMode && gbSgbMode) {
gbSgbMode = 0; gbSgbMode = false;
} }
if (gbBorderOn && !gbSgbMask) { if (gbBorderOn && !gbSgbMask) {
@ -5218,7 +5209,7 @@ bool gbReadSaveState(const uint8_t* data)
gbSoundReadGame(data); gbSoundReadGame(data);
if (gbCgbMode && gbSgbMode) { if (gbCgbMode && gbSgbMode) {
gbSgbMode = 0; gbSgbMode = false;
} }
if (gbBorderOn && !gbSgbMask) { if (gbBorderOn && !gbSgbMask) {

View File

@ -63,9 +63,6 @@ void setColorizerHack(bool value);
bool allowColorizerHack(void); bool allowColorizerHack(void);
extern int gbHardware; 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 gbCartData g_gbCartData;
extern struct EmulatedSystem GBSystem; extern struct EmulatedSystem GBSystem;

View File

@ -3,11 +3,6 @@
uint8_t* gbMemoryMap[16]; uint8_t* gbMemoryMap[16];
int gbRomSizeMask = 0;
int gbRomSize = 0;
int gbRamSizeMask = 0;
int gbRamSize = 0;
uint8_t* gbMemory = nullptr; uint8_t* gbMemory = nullptr;
uint8_t* gbVram = nullptr; uint8_t* gbVram = nullptr;
uint8_t* gbRom = 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 }; uint8_t gbObp1[4] = { 0, 1, 2, 3 };
int gbWindowLine = -1; int gbWindowLine = -1;
bool genericflashcardEnable = false;
int gbCgbMode = 0;
uint16_t gbColorFilter[32768]; uint16_t gbColorFilter[32768];
uint32_t gbEmulatorType = 0; uint32_t gbEmulatorType = 0;
uint32_t gbPaletteOption = 0; uint32_t gbPaletteOption = 0;
@ -34,6 +26,8 @@ int gbBorderColumnSkip = 0;
int gbDmaTicks = 0; int gbDmaTicks = 0;
bool gbBorderAutomatic = false; bool gbBorderAutomatic = false;
bool gbBorderOn = false; bool gbBorderOn = false;
bool gbCgbMode = false;
bool gbSgbMode = false;
bool gbColorOption = false; bool gbColorOption = false;
uint8_t (*gbSerialFunction)(uint8_t) = NULL; uint8_t (*gbSerialFunction)(uint8_t) = NULL;

View File

@ -3,11 +3,6 @@
#include "../common/Types.h" #include "../common/Types.h"
extern int gbRomSizeMask;
extern int gbRomSize;
extern int gbRamSize;
extern int gbRamSizeMask;
extern uint8_t* bios; extern uint8_t* bios;
extern uint8_t* gbRom; extern uint8_t* gbRom;
@ -24,8 +19,8 @@ extern int gbFrameSkip;
extern uint16_t gbColorFilter[32768]; extern uint16_t gbColorFilter[32768];
extern uint32_t gbEmulatorType; extern uint32_t gbEmulatorType;
extern uint32_t gbPaletteOption; extern uint32_t gbPaletteOption;
extern int gbCgbMode; extern bool gbCgbMode;
extern int gbSgbMode; extern bool gbSgbMode;
extern int gbWindowLine; extern int gbWindowLine;
extern int gbSpeed; extern int gbSpeed;
extern uint8_t gbBgp[4]; extern uint8_t gbBgp[4];
@ -58,7 +53,6 @@ extern uint8_t register_VBK;
extern uint8_t oldRegister_WY; extern uint8_t oldRegister_WY;
extern int emulating; extern int emulating;
extern bool genericflashcardEnable;
extern int gbBorderLineSkip; extern int gbBorderLineSkip;
extern int gbBorderRowSkip; extern int gbBorderRowSkip;

View File

@ -1,10 +1,10 @@
#include "gbMemory.h" #include "gbMemory.h"
#include "../System.h" #include "../System.h"
#include "../common/Port.h" #include "../common/Port.h"
#include "../common/sizes.h"
#include "gb.h" #include "gb.h"
#include "gbGlobals.h" #include "gbGlobals.h"
uint8_t gbDaysinMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 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 int gbGBCColorType;
extern gbRegister PC; extern gbRegister PC;
@ -48,7 +48,7 @@ void mapperMBC1ROM(uint16_t address, uint8_t value)
tmpAddress |= (gbDataMBC1.mapperROMHighAddress & 3) << 19; tmpAddress |= (gbDataMBC1.mapperROMHighAddress & 3) << 19;
} }
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbDataMBC1.mapperROMBank = value; gbDataMBC1.mapperROMBank = value;
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
@ -57,11 +57,11 @@ void mapperMBC1ROM(uint16_t address, uint8_t value)
break; break;
case 0x4000: // RAM bank select case 0x4000: // RAM bank select
if (gbDataMBC1.mapperMemoryModel == 1) { if (gbDataMBC1.mapperMemoryModel == 1) {
if (!gbRamSize) { if (!g_gbCartData.HasRam()) {
if (gbDataMBC1.mapperRomBank0Remapping == 3) { if (gbDataMBC1.mapperRomBank0Remapping == 3) {
gbDataMBC1.mapperROMHighAddress = value & 0x03; gbDataMBC1.mapperROMHighAddress = value & 0x03;
tmpAddress = (gbDataMBC1.mapperROMHighAddress) << 18; tmpAddress = (gbDataMBC1.mapperROMHighAddress) << 18;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x00] = &gbRom[tmpAddress]; gbMemoryMap[0x00] = &gbRom[tmpAddress];
gbMemoryMap[0x01] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x01] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x02] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x02] = &gbRom[tmpAddress + 0x2000];
@ -78,8 +78,8 @@ void mapperMBC1ROM(uint16_t address, uint8_t value)
if (value == gbDataMBC1.mapperRAMBank) if (value == gbDataMBC1.mapperRAMBank)
break; break;
tmpAddress = value << 13; tmpAddress = value << 13;
tmpAddress &= gbRamSizeMask; tmpAddress &= g_gbCartData.ram_mask();
if (gbRamSize) { if (g_gbCartData.HasRam()) {
gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0a] = &gbRam[tmpAddress];
gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000];
} }
@ -93,12 +93,12 @@ void mapperMBC1ROM(uint16_t address, uint8_t value)
gbDataMBC1.mapperROMHighAddress = value & 0x03; gbDataMBC1.mapperROMHighAddress = value & 0x03;
tmpAddress = gbDataMBC1.mapperROMBank << 14; tmpAddress = gbDataMBC1.mapperROMBank << 14;
tmpAddress |= (gbDataMBC1.mapperROMHighAddress) << 19; tmpAddress |= (gbDataMBC1.mapperROMHighAddress) << 19;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
if (gbRamSize) { if (g_gbCartData.HasRam()) {
gbMemoryMap[0x0a] = &gbRam[0]; gbMemoryMap[0x0a] = &gbRam[0];
gbMemoryMap[0x0b] = &gbRam[0x1000]; gbMemoryMap[0x0b] = &gbRam[0x1000];
} }
@ -114,8 +114,8 @@ void mapperMBC1ROM(uint16_t address, uint8_t value)
value = gbDataMBC1.mapperRAMBank & 0x03; value = gbDataMBC1.mapperRAMBank & 0x03;
tmpAddress = value << 13; tmpAddress = value << 13;
tmpAddress &= gbRamSizeMask; tmpAddress &= g_gbCartData.ram_mask();
if (gbRamSize) { if (g_gbCartData.HasRam()) {
gbMemoryMap[0x0a] = &gbRam[gbDataMBC1.mapperRAMAddress]; gbMemoryMap[0x0a] = &gbRam[gbDataMBC1.mapperRAMAddress];
gbMemoryMap[0x0b] = &gbRam[gbDataMBC1.mapperRAMAddress + 0x1000]; gbMemoryMap[0x0b] = &gbRam[gbDataMBC1.mapperRAMAddress + 0x1000];
gbDataMBC1.mapperRomBank0Remapping = 0; gbDataMBC1.mapperRomBank0Remapping = 0;
@ -127,7 +127,7 @@ void mapperMBC1ROM(uint16_t address, uint8_t value)
tmpAddress = gbDataMBC1.mapperROMBank << 14; tmpAddress = gbDataMBC1.mapperROMBank << 14;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
@ -138,12 +138,12 @@ void mapperMBC1ROM(uint16_t address, uint8_t value)
tmpAddress = gbDataMBC1.mapperROMBank << 14; tmpAddress = gbDataMBC1.mapperROMBank << 14;
tmpAddress |= (gbDataMBC1.mapperROMHighAddress) << 19; tmpAddress |= (gbDataMBC1.mapperROMHighAddress) << 19;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
if (gbRamSize) { if (g_gbCartData.HasRam()) {
gbMemoryMap[0x0a] = &gbRam[0]; gbMemoryMap[0x0a] = &gbRam[0];
gbMemoryMap[0x0b] = &gbRam[0x1000]; gbMemoryMap[0x0b] = &gbRam[0x1000];
} }
@ -156,7 +156,7 @@ void mapperMBC1ROM(uint16_t address, uint8_t value)
void mapperMBC1RAM(uint16_t address, uint8_t value) void mapperMBC1RAM(uint16_t address, uint8_t value)
{ {
if (gbDataMBC1.mapperRAMEnable) { if (gbDataMBC1.mapperRAMEnable) {
if (gbRamSize) { if (g_gbCartData.HasRam()) {
gbMemoryMap[address >> 12][address & 0x0fff] = value; gbMemoryMap[address >> 12][address & 0x0fff] = value;
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
} }
@ -170,23 +170,7 @@ uint8_t mapperMBC1ReadRAM(uint16_t address)
if (gbDataMBC1.mapperRAMEnable) if (gbDataMBC1.mapperRAMEnable)
return gbMemoryMap[address >> 12][address & 0x0fff]; return gbMemoryMap[address >> 12][address & 0x0fff];
if (!genericflashcardEnable) return 0xff;
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];
} }
void memoryUpdateMapMBC1() void memoryUpdateMapMBC1()
@ -196,7 +180,7 @@ void memoryUpdateMapMBC1()
// check current model // check current model
if (gbDataMBC1.mapperRomBank0Remapping == 3) { if (gbDataMBC1.mapperRomBank0Remapping == 3) {
tmpAddress = (gbDataMBC1.mapperROMHighAddress & 3) << 18; tmpAddress = (gbDataMBC1.mapperROMHighAddress & 3) << 18;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x00] = &gbRom[tmpAddress]; gbMemoryMap[0x00] = &gbRom[tmpAddress];
gbMemoryMap[0x01] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x01] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x02] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x02] = &gbRom[tmpAddress + 0x2000];
@ -213,14 +197,14 @@ void memoryUpdateMapMBC1()
tmpAddress |= (gbDataMBC1.mapperROMHighAddress & 3) << 19; tmpAddress |= (gbDataMBC1.mapperROMHighAddress & 3) << 19;
} }
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
} }
if (gbRamSize) { if (g_gbCartData.HasRam()) {
if (gbDataMBC1.mapperMemoryModel == 1) { if (gbDataMBC1.mapperMemoryModel == 1) {
gbMemoryMap[0x0a] = &gbRam[gbDataMBC1.mapperRAMAddress]; gbMemoryMap[0x0a] = &gbRam[gbDataMBC1.mapperRAMAddress];
gbMemoryMap[0x0b] = &gbRam[gbDataMBC1.mapperRAMAddress + 0x1000]; gbMemoryMap[0x0b] = &gbRam[gbDataMBC1.mapperRAMAddress + 0x1000];
@ -256,7 +240,7 @@ void mapperMBC2ROM(uint16_t address, uint8_t value)
int tmpAddress = value << 14; int tmpAddress = value << 14;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; 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) void mapperMBC2RAM(uint16_t address, uint8_t value)
{ {
if (gbDataMBC2.mapperRAMEnable) { if (gbDataMBC2.mapperRAMEnable) {
if (gbRamSize && address < 0xa200) { if (g_gbCartData.ram_size() && address < 0xa200) {
gbMemoryMap[address >> 12][address & 0x0fff] = value; gbMemoryMap[address >> 12][address & 0x0fff] = value;
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
} }
@ -283,7 +267,7 @@ void memoryUpdateMapMBC2()
{ {
int tmpAddress = gbDataMBC2.mapperROMBank << 14; int tmpAddress = gbDataMBC2.mapperROMBank << 14;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
@ -362,7 +346,7 @@ void mapperMBC3ROM(uint16_t address, uint8_t value)
gbDataMBC3.mapperRAMEnable = ((value & 0x0a) == 0x0a ? 1 : 0); gbDataMBC3.mapperRAMEnable = ((value & 0x0a) == 0x0a ? 1 : 0);
break; break;
case 0x2000: { // ROM bank select case 0x2000: { // ROM bank select
if (gbRomSize != 0x00400000) if (g_gbCartData.rom_size() != k4MiB)
value = value & 0x7f; // Assume 2MiB, unless MBC30. value = value & 0x7f; // Assume 2MiB, unless MBC30.
if (value == 0) if (value == 0)
@ -372,7 +356,7 @@ void mapperMBC3ROM(uint16_t address, uint8_t value)
tmpAddress = value << 14; tmpAddress = value << 14;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbDataMBC3.mapperROMBank = value; gbDataMBC3.mapperROMBank = value;
@ -388,13 +372,13 @@ void mapperMBC3ROM(uint16_t address, uint8_t value)
if (value == gbDataMBC3.mapperRAMBank) if (value == gbDataMBC3.mapperRAMBank)
break; break;
tmpAddress = value << 13; tmpAddress = value << 13;
tmpAddress &= gbRamSizeMask; tmpAddress &= g_gbCartData.ram_mask();
gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0a] = &gbRam[tmpAddress];
gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000];
gbDataMBC3.mapperRAMBank = value; gbDataMBC3.mapperRAMBank = value;
gbDataMBC3.mapperRAMAddress = tmpAddress; gbDataMBC3.mapperRAMAddress = tmpAddress;
} else { } else {
if (gbRTCPresent && gbDataMBC3.mapperRAMEnable) { if (g_gbCartData.has_rtc() && gbDataMBC3.mapperRAMEnable) {
gbDataMBC3.mapperRAMBank = -1; gbDataMBC3.mapperRAMBank = -1;
gbDataMBC3.mapperClockRegister = value; gbDataMBC3.mapperClockRegister = value;
@ -402,7 +386,7 @@ void mapperMBC3ROM(uint16_t address, uint8_t value)
} }
break; break;
case 0x6000: // clock latch case 0x6000: // clock latch
if (gbRTCPresent) { if (g_gbCartData.has_rtc()) {
if (gbDataMBC3.mapperClockLatch == 0 && value == 1) { if (gbDataMBC3.mapperClockLatch == 0 && value == 1) {
memoryUpdateMBC3Clock(); memoryUpdateMBC3Clock();
gbDataMBC3.mapperLSeconds = gbDataMBC3.mapperSeconds; gbDataMBC3.mapperLSeconds = gbDataMBC3.mapperSeconds;
@ -423,11 +407,11 @@ void mapperMBC3RAM(uint16_t address, uint8_t value)
{ {
if (gbDataMBC3.mapperRAMEnable) { if (gbDataMBC3.mapperRAMEnable) {
if (gbDataMBC3.mapperRAMBank >= 0) { if (gbDataMBC3.mapperRAMBank >= 0) {
if (gbRamSize) { if (g_gbCartData.ram_size()) {
gbMemoryMap[address >> 12][address & 0x0fff] = value; gbMemoryMap[address >> 12][address & 0x0fff] = value;
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
} }
} else if (gbRTCPresent) { } else if (g_gbCartData.has_rtc()) {
time(&gbDataMBC3.mapperLastTime); time(&gbDataMBC3.mapperLastTime);
switch (gbDataMBC3.mapperClockRegister) { switch (gbDataMBC3.mapperClockRegister) {
case 0x08: case 0x08:
@ -459,7 +443,7 @@ uint8_t mapperMBC3ReadRAM(uint16_t address)
if (gbDataMBC3.mapperRAMEnable) { if (gbDataMBC3.mapperRAMEnable) {
if (gbDataMBC3.mapperRAMBank >= 0) { if (gbDataMBC3.mapperRAMBank >= 0) {
return gbMemoryMap[address >> 12][address & 0x0fff]; return gbMemoryMap[address >> 12][address & 0x0fff];
} else if (gbRTCPresent) { } else if (g_gbCartData.has_rtc()) {
switch (gbDataMBC3.mapperClockRegister) { switch (gbDataMBC3.mapperClockRegister) {
case 0x08: case 0x08:
return gbDataMBC3.mapperLSeconds; return gbDataMBC3.mapperLSeconds;
@ -479,39 +463,23 @@ uint8_t mapperMBC3ReadRAM(uint16_t address)
} }
} }
if (!genericflashcardEnable) return 0xff;
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];
} }
void memoryUpdateMapMBC3() void memoryUpdateMapMBC3()
{ {
int tmpAddress = gbDataMBC3.mapperROMBank << 14; int tmpAddress = gbDataMBC3.mapperROMBank << 14;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
if (gbDataMBC3.mapperRAMBank >= 0 && gbRamSize) { if (gbDataMBC3.mapperRAMBank >= 0 && g_gbCartData.HasRam()) {
tmpAddress = gbDataMBC3.mapperRAMBank << 13; tmpAddress = gbDataMBC3.mapperRAMBank << 13;
tmpAddress &= gbRamSizeMask; tmpAddress &= g_gbCartData.ram_mask();
gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0a] = &gbRam[tmpAddress];
gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000];
} }
@ -544,7 +512,7 @@ void mapperMBC5ROM(uint16_t address, uint8_t value)
tmpAddress = (value << 14) | (gbDataMBC5.mapperROMHighAddress << 22); tmpAddress = (value << 14) | (gbDataMBC5.mapperROMHighAddress << 22);
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbDataMBC5.mapperROMBank = value; gbDataMBC5.mapperROMBank = value;
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
@ -558,7 +526,7 @@ void mapperMBC5ROM(uint16_t address, uint8_t value)
tmpAddress = (gbDataMBC5.mapperROMBank << 14) | (value << 22); tmpAddress = (gbDataMBC5.mapperROMBank << 14) | (value << 22);
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbDataMBC5.mapperROMHighAddress = value; gbDataMBC5.mapperROMHighAddress = value;
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
@ -575,8 +543,8 @@ void mapperMBC5ROM(uint16_t address, uint8_t value)
if (value == gbDataMBC5.mapperRAMBank) if (value == gbDataMBC5.mapperRAMBank)
break; break;
tmpAddress = value << 13; tmpAddress = value << 13;
tmpAddress &= gbRamSizeMask; tmpAddress &= g_gbCartData.ram_mask();
if (gbRamSize) { if (g_gbCartData.HasRam()) {
gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0a] = &gbRam[tmpAddress];
gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; 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) void mapperMBC5RAM(uint16_t address, uint8_t value)
{ {
if (gbDataMBC5.mapperRAMEnable) { if (gbDataMBC5.mapperRAMEnable) {
if (gbRamSize) { if (g_gbCartData.HasRam()) {
gbMemoryMap[address >> 12][address & 0x0fff] = value; gbMemoryMap[address >> 12][address & 0x0fff] = value;
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
} }
@ -605,38 +573,22 @@ uint8_t mapperMBC5ReadRAM(uint16_t address)
if (gbDataMBC5.mapperRAMEnable) if (gbDataMBC5.mapperRAMEnable)
return gbMemoryMap[address >> 12][address & 0x0fff]; return gbMemoryMap[address >> 12][address & 0x0fff];
if (!genericflashcardEnable) return 0xff;
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];
} }
void memoryUpdateMapMBC5() void memoryUpdateMapMBC5()
{ {
int tmpAddress = (gbDataMBC5.mapperROMBank << 14) | (gbDataMBC5.mapperROMHighAddress << 22); int tmpAddress = (gbDataMBC5.mapperROMBank << 14) | (gbDataMBC5.mapperROMHighAddress << 22);
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
if (gbRamSize) { if (g_gbCartData.HasRam()) {
tmpAddress = gbDataMBC5.mapperRAMBank << 13; tmpAddress = gbDataMBC5.mapperRAMBank << 13;
tmpAddress &= gbRamSizeMask; tmpAddress &= g_gbCartData.ram_mask();
gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0a] = &gbRam[tmpAddress];
gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000];
} }
@ -677,7 +629,7 @@ void mapperMBC7ROM(uint16_t address, uint8_t value)
tmpAddress = (value << 14); tmpAddress = (value << 14);
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbDataMBC7.mapperROMBank = value; gbDataMBC7.mapperROMBank = value;
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
@ -687,7 +639,7 @@ void mapperMBC7ROM(uint16_t address, uint8_t value)
case 0x4000: // RAM bank select/enable case 0x4000: // RAM bank select/enable
if (value < 8) { if (value < 8) {
tmpAddress = (value & 3) << 13; tmpAddress = (value & 3) << 13;
tmpAddress &= gbRamSizeMask; tmpAddress &= g_gbCartData.ram_mask();
gbMemoryMap[0x0a] = &gbMemory[0xa000]; gbMemoryMap[0x0a] = &gbMemory[0xa000];
gbMemoryMap[0x0b] = &gbMemory[0xb000]; gbMemoryMap[0x0b] = &gbMemory[0xb000];
@ -726,23 +678,7 @@ uint8_t mapperMBC7ReadRAM(uint16_t address)
return gbDataMBC7.value; return gbDataMBC7.value;
} }
if (!genericflashcardEnable) return 0xff;
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];
} }
// MBC7 RAM write // MBC7 RAM write
@ -892,7 +828,7 @@ void memoryUpdateMapMBC7()
{ {
int tmpAddress = (gbDataMBC7.mapperROMBank << 14); int tmpAddress = (gbDataMBC7.mapperROMBank << 14);
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
@ -926,7 +862,7 @@ void mapperHuC1ROM(uint16_t address, uint8_t value)
tmpAddress = value << 14; tmpAddress = value << 14;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbDataHuC1.mapperROMBank = value; gbDataHuC1.mapperROMBank = value;
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
@ -940,7 +876,7 @@ void mapperHuC1ROM(uint16_t address, uint8_t value)
if (value == gbDataHuC1.mapperRAMBank) if (value == gbDataHuC1.mapperRAMBank)
break; break;
tmpAddress = value << 13; tmpAddress = value << 13;
tmpAddress &= gbRamSizeMask; tmpAddress &= g_gbCartData.ram_mask();
gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0a] = &gbRam[tmpAddress];
gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000];
gbDataHuC1.mapperRAMBank = value; gbDataHuC1.mapperRAMBank = value;
@ -950,7 +886,7 @@ void mapperHuC1ROM(uint16_t address, uint8_t value)
gbDataHuC1.mapperROMHighAddress = value & 0x03; gbDataHuC1.mapperROMHighAddress = value & 0x03;
tmpAddress = gbDataHuC1.mapperROMBank << 14; tmpAddress = gbDataHuC1.mapperROMBank << 14;
tmpAddress |= (gbDataHuC1.mapperROMHighAddress) << 19; tmpAddress |= (gbDataHuC1.mapperROMHighAddress) << 19;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; 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) void mapperHuC1RAM(uint16_t address, uint8_t value)
{ {
if (gbDataHuC1.mapperRAMEnable) { if (gbDataHuC1.mapperRAMEnable) {
if (gbRamSize) { if (g_gbCartData.HasRam()) {
gbMemoryMap[address >> 12][address & 0x0fff] = value; gbMemoryMap[address >> 12][address & 0x0fff] = value;
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
} }
@ -978,16 +914,16 @@ void memoryUpdateMapHuC1()
{ {
int tmpAddress = gbDataHuC1.mapperROMBank << 14; int tmpAddress = gbDataHuC1.mapperROMBank << 14;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
if (gbRamSize) { if (g_gbCartData.HasRam()) {
tmpAddress = gbDataHuC1.mapperRAMBank << 13; tmpAddress = gbDataHuC1.mapperRAMBank << 13;
tmpAddress &= gbRamSizeMask; tmpAddress &= g_gbCartData.ram_mask();
gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0a] = &gbRam[tmpAddress];
gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000];
} }
@ -1012,7 +948,7 @@ mapperHuC3 gbDataHuC3 = {
}; };
mapperHuC3RTC gbRTCHuC3 = { mapperHuC3RTC gbRTCHuC3 = {
0, // lastTime {0}, // lastTime
0, // DateTime 0, // DateTime
0, // WritingTime 0, // WritingTime
0, // ModeFlag 0, // ModeFlag
@ -1058,7 +994,7 @@ void mapperHuC3ROM(uint16_t address, uint8_t value)
tmpAddress = value << 14; tmpAddress = value << 14;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbDataHuC3.mapperROMBank = value; gbDataHuC3.mapperROMBank = value;
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
@ -1070,7 +1006,7 @@ void mapperHuC3ROM(uint16_t address, uint8_t value)
if (value == gbDataHuC3.mapperRAMBank) if (value == gbDataHuC3.mapperRAMBank)
break; break;
tmpAddress = value << 13; tmpAddress = value << 13;
tmpAddress &= gbRamSizeMask; tmpAddress &= g_gbCartData.ram_mask();
gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0a] = &gbRam[tmpAddress];
gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000];
gbDataHuC3.mapperRAMBank = value; gbDataHuC3.mapperRAMBank = value;
@ -1099,7 +1035,7 @@ void mapperHuC3RAM(uint16_t address, uint8_t value)
if (gbDataHuC3.mapperRAMFlag < 0x0b || gbDataHuC3.mapperRAMFlag > 0x0e) { if (gbDataHuC3.mapperRAMFlag < 0x0b || gbDataHuC3.mapperRAMFlag > 0x0e) {
if (gbDataHuC3.mapperRAMEnable) { if (gbDataHuC3.mapperRAMEnable) {
if (gbRamSize) { if (g_gbCartData.ram_size()) {
gbMemoryMap[address >> 12][address & 0x0fff] = value; gbMemoryMap[address >> 12][address & 0x0fff] = value;
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
} }
@ -1196,15 +1132,15 @@ void memoryUpdateMapHuC3()
{ {
int tmpAddress = gbDataHuC3.mapperROMBank << 14; int tmpAddress = gbDataHuC3.mapperROMBank << 14;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
if (gbRamSize) { if (g_gbCartData.ram_size()) {
tmpAddress = gbDataHuC3.mapperRAMBank << 13; tmpAddress = gbDataHuC3.mapperRAMBank << 13;
tmpAddress &= gbRamSizeMask; tmpAddress &= g_gbCartData.ram_mask();
gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0a] = &gbRam[tmpAddress];
gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000];
} }
@ -1333,7 +1269,7 @@ void mapperTAMA5RAM(uint16_t address, uint8_t value)
int tmpAddress = (gbDataTAMA5.mapperROMBank << 14); int tmpAddress = (gbDataTAMA5.mapperROMBank << 14);
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
@ -1492,7 +1428,7 @@ void mapperTAMA5RAM(uint16_t address, uint8_t value)
} else { } else {
if (gbDataTAMA5.mapperRAMEnable) { if (gbDataTAMA5.mapperRAMEnable) {
if (gbDataTAMA5.mapperRAMBank != -1) { if (gbDataTAMA5.mapperRAMBank != -1) {
if (gbRamSize) { if (g_gbCartData.HasRam()) {
gbMemoryMap[address >> 12][address & 0x0fff] = value; gbMemoryMap[address >> 12][address & 0x0fff] = value;
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
} }
@ -1511,15 +1447,15 @@ void memoryUpdateMapTAMA5()
{ {
int tmpAddress = (gbDataTAMA5.mapperROMBank << 14); int tmpAddress = (gbDataTAMA5.mapperROMBank << 14);
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
if (gbRamSize) { if (g_gbCartData.HasRam()) {
tmpAddress = 0 << 13; tmpAddress = 0 << 13;
tmpAddress &= gbRamSizeMask; tmpAddress &= g_gbCartData.ram_mask();
gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0a] = &gbRam[tmpAddress];
gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000];
} }
@ -1561,7 +1497,7 @@ void mapperMMM01ROM(uint16_t address, uint8_t value)
} else } else
tmpAddress |= gbDataMMM01.mapperRomBank0Remapping << 18; tmpAddress |= gbDataMMM01.mapperRomBank0Remapping << 18;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbDataMMM01.mapperROMBank = value; gbDataMMM01.mapperROMBank = value;
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
@ -1575,7 +1511,7 @@ void mapperMMM01ROM(uint16_t address, uint8_t value)
if (value == gbDataMBC1.mapperRAMBank) if (value == gbDataMBC1.mapperRAMBank)
break; break;
tmpAddress = value << 13; tmpAddress = value << 13;
tmpAddress &= gbRamSizeMask; tmpAddress &= g_gbCartData.ram_mask();
gbMemoryMap[0x0a] = &gbRam[tmpAddress]; gbMemoryMap[0x0a] = &gbRam[tmpAddress];
gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000]; gbMemoryMap[0x0b] = &gbRam[tmpAddress + 0x1000];
gbDataMMM01.mapperRAMBank = value; gbDataMMM01.mapperRAMBank = value;
@ -1585,7 +1521,7 @@ void mapperMMM01ROM(uint16_t address, uint8_t value)
gbDataMMM01.mapperROMHighAddress = value & 0x03; gbDataMMM01.mapperROMHighAddress = value & 0x03;
tmpAddress = gbDataMMM01.mapperROMBank << 14; tmpAddress = gbDataMMM01.mapperROMBank << 14;
tmpAddress |= (gbDataMMM01.mapperROMHighAddress) << 19; tmpAddress |= (gbDataMMM01.mapperROMHighAddress) << 19;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; 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; gbDataMMM01.mapperRomBank0Remapping = ((value << 1) | (value & 0x40 ? 1 : 0)) & 0xff;
tmpAddress = gbDataMMM01.mapperRomBank0Remapping << 18; tmpAddress = gbDataMMM01.mapperRomBank0Remapping << 18;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x00] = &gbRom[tmpAddress]; gbMemoryMap[0x00] = &gbRom[tmpAddress];
gbMemoryMap[0x01] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x01] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x02] = &gbRom[tmpAddress + 0x2000]; 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) void mapperMMM01RAM(uint16_t address, uint8_t value)
{ {
if (gbDataMMM01.mapperRAMEnable) { if (gbDataMMM01.mapperRAMEnable) {
if (gbRamSize) { if (g_gbCartData.HasRam()) {
gbMemoryMap[address >> 12][address & 0x0fff] = value; gbMemoryMap[address >> 12][address & 0x0fff] = value;
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
} }
@ -1627,20 +1563,20 @@ void memoryUpdateMapMMM01()
tmpAddress |= (gbDataMMM01.mapperROMHighAddress) << 19; tmpAddress |= (gbDataMMM01.mapperROMHighAddress) << 19;
} }
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000]; gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
tmpAddress = gbDataMMM01.mapperRomBank0Remapping << 18; tmpAddress = gbDataMMM01.mapperRomBank0Remapping << 18;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbMemoryMap[0x00] = &gbRom[tmpAddress]; gbMemoryMap[0x00] = &gbRom[tmpAddress];
gbMemoryMap[0x01] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x01] = &gbRom[tmpAddress + 0x1000];
gbMemoryMap[0x02] = &gbRom[tmpAddress + 0x2000]; gbMemoryMap[0x02] = &gbRom[tmpAddress + 0x2000];
gbMemoryMap[0x03] = &gbRom[tmpAddress + 0x3000]; gbMemoryMap[0x03] = &gbRom[tmpAddress + 0x3000];
if (gbRamSize) { if (g_gbCartData.HasRam()) {
gbMemoryMap[0x0a] = &gbRam[gbDataMMM01.mapperRAMAddress]; gbMemoryMap[0x0a] = &gbRam[gbDataMMM01.mapperRAMAddress];
gbMemoryMap[0x0b] = &gbRam[gbDataMMM01.mapperRAMAddress + 0x1000]; gbMemoryMap[0x0b] = &gbRam[gbDataMMM01.mapperRAMAddress + 0x1000];
} }
@ -1685,7 +1621,7 @@ void mapperGS3ROM(uint16_t address, uint8_t value)
break; break;
tmpAddress = value << 13; tmpAddress = value << 13;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
gbDataGS3.mapperROMBank = value; gbDataGS3.mapperROMBank = value;
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
@ -1699,7 +1635,7 @@ void memoryUpdateMapGS3()
{ {
int tmpAddress = gbDataGS3.mapperROMBank << 13; int tmpAddress = gbDataGS3.mapperROMBank << 13;
tmpAddress &= gbRomSizeMask; tmpAddress &= g_gbCartData.rom_mask();
// GS can only change a half ROM bank // GS can only change a half ROM bank
gbMemoryMap[0x04] = &gbRom[tmpAddress]; gbMemoryMap[0x04] = &gbRom[tmpAddress];
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000]; gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];

View File

@ -20,7 +20,6 @@ uint8_t* gbSgbBorder = NULL;
int gbSgbCGBSupport = 0; int gbSgbCGBSupport = 0;
int gbSgbMask = 0; int gbSgbMask = 0;
int gbSgbMode = 0;
int gbSgbPacketState = GBSGB_NONE; int gbSgbPacketState = GBSGB_NONE;
int gbSgbBit = 0; int gbSgbBit = 0;
int gbSgbPacketTimeout = 0; int gbSgbPacketTimeout = 0;
@ -328,7 +327,7 @@ void gbSgbPicture()
if (gbSgbMode && gbCgbMode && gbSgbCGBSupport > 4) { if (gbSgbMode && gbCgbMode && gbSgbCGBSupport > 4) {
gbSgbCGBSupport = 0; gbSgbCGBSupport = 0;
gbSgbMode = 0; gbSgbMode = false;
gbSgbMask = 0; gbSgbMask = 0;
gbSgbRenderBorder(); gbSgbRenderBorder();
gbReset(); gbReset();
@ -672,7 +671,7 @@ void gbSgbChrTransfer()
if (gbSgbMode && gbCgbMode && gbSgbCGBSupport == 7) { if (gbSgbMode && gbCgbMode && gbSgbCGBSupport == 7) {
gbSgbCGBSupport = 0; gbSgbCGBSupport = 0;
gbSgbMode = 0; gbSgbMode = false;
gbSgbMask = 0; gbSgbMask = 0;
gbSgbRenderBorder(); gbSgbRenderBorder();
gbReset(); gbReset();

View File

@ -17,7 +17,6 @@ void gbSgbReadGame(gzFile, int version);
#endif #endif
extern uint8_t gbSgbATF[20 * 18]; extern uint8_t gbSgbATF[20 * 18];
extern int gbSgbMode;
extern int gbSgbMask; extern int gbSgbMask;
extern int gbSgbMultiplayer; extern int gbSgbMultiplayer;
extern uint8_t gbSgbNextController; extern uint8_t gbSgbNextController;

View File

@ -16,6 +16,7 @@
#include "../apu/Gb_Apu.h" #include "../apu/Gb_Apu.h"
#include "../apu/Gb_Oscs.h" #include "../apu/Gb_Oscs.h"
#include "../common/Port.h" #include "../common/Port.h"
#include "../common/sizes.h"
#include "../gba/Cheats.h" #include "../gba/Cheats.h"
#include "../gba/EEprom.h" #include "../gba/EEprom.h"
#include "../gba/Flash.h" #include "../gba/Flash.h"
@ -165,28 +166,56 @@ static void set_gbPalette(void)
static void* gb_rtcdata_prt(void) static void* gb_rtcdata_prt(void)
{ {
switch (gbRomType) { switch (g_gbCartData.mapper_type()) {
case 0x0f: case gbCartData::MapperType::kMbc3:
case 0x10: // MBC3 + extended
return &gbDataMBC3.mapperSeconds; return &gbDataMBC3.mapperSeconds;
case 0xfd: // TAMA5 + extended case gbCartData::MapperType::kTama5:
return &gbDataTAMA5.mapperSeconds; return &gbDataTAMA5.mapperSeconds;
case 0xfe: // HuC3 + Clock case gbCartData::MapperType::kHuC3:
return &gbRTCHuC3.mapperLastTime; 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) static size_t gb_rtcdata_size(void)
{ {
switch (gbRomType) { switch (g_gbCartData.mapper_type()) {
case 0x0f: case gbCartData::MapperType::kMbc3:
case 0x10: // MBC3 + extended
return MBC3_RTC_DATA_SIZE; return MBC3_RTC_DATA_SIZE;
case 0xfd: // TAMA5 + extended case gbCartData::MapperType::kTama5:
return TAMA5_RTC_DATA_SIZE; return TAMA5_RTC_DATA_SIZE;
case 0xfe: // HuC3 + Clock case gbCartData::MapperType::kHuC3:
return sizeof(gbRTCHuC3.mapperLastTime); 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; return 0;
} }
@ -198,9 +227,8 @@ static void gbInitRTC(void)
time(&rawtime); time(&rawtime);
lt = localtime(&rawtime); lt = localtime(&rawtime);
switch (gbRomType) { switch (g_gbCartData.mapper_type()) {
case 0x0f: case gbCartData::MapperType::kMbc3:
case 0x10:
gbDataMBC3.mapperSeconds = lt->tm_sec; gbDataMBC3.mapperSeconds = lt->tm_sec;
gbDataMBC3.mapperMinutes = lt->tm_min; gbDataMBC3.mapperMinutes = lt->tm_min;
gbDataMBC3.mapperHours = lt->tm_hour; 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.mapperControl = (gbDataMBC3.mapperControl & 0xfe) | (lt->tm_yday > 255 ? 1 : 0);
gbDataMBC3.mapperLastTime = rawtime; gbDataMBC3.mapperLastTime = rawtime;
break; break;
case 0xfd: { case gbCartData::MapperType::kTama5: {
uint8_t gbDaysinMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; uint8_t gbDaysinMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int days = lt->tm_yday + 365 * 3; int days = lt->tm_yday + 365 * 3;
gbDataTAMA5.mapperSeconds = lt->tm_sec; gbDataTAMA5.mapperSeconds = lt->tm_sec;
@ -237,9 +265,24 @@ static void gbInitRTC(void)
gbDataTAMA5.mapperControl = (gbDataTAMA5.mapperControl & 0xfe) | (lt->tm_yday > 255 ? 1 : 0); gbDataTAMA5.mapperControl = (gbDataTAMA5.mapperControl & 0xfe) | (lt->tm_yday > 255 ? 1 : 0);
} }
break; break;
case 0xfe: case gbCartData::MapperType::kHuC3:
gbRTCHuC3.mapperLastTime = rawtime; gbRTCHuC3.mapperLastTime = rawtime;
break; 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: case IMAGE_GB:
switch (id) { switch (id) {
case RETRO_MEMORY_SAVE_RAM: case RETRO_MEMORY_SAVE_RAM:
if (gbBattery) if (g_gbCartData.has_battery())
data = gbRam; data = gbRam;
break; break;
case RETRO_MEMORY_SYSTEM_RAM: case RETRO_MEMORY_SYSTEM_RAM:
@ -307,7 +350,7 @@ void* retro_get_memory_data(unsigned id)
data = (gbCgbMode ? gbVram : (gbMemory + 0x8000)); data = (gbCgbMode ? gbVram : (gbMemory + 0x8000));
break; break;
case RETRO_MEMORY_RTC: case RETRO_MEMORY_RTC:
if (gbRTCPresent) if (g_gbCartData.has_rtc())
data = gb_rtcdata_prt(); data = gb_rtcdata_prt();
break; break;
} }
@ -345,8 +388,8 @@ size_t retro_get_memory_size(unsigned id)
case IMAGE_GB: case IMAGE_GB:
switch (id) { switch (id) {
case RETRO_MEMORY_SAVE_RAM: case RETRO_MEMORY_SAVE_RAM:
if (gbBattery) if (g_gbCartData.has_battery())
size = gbRamSize; size = g_gbCartData.ram_size();
break; break;
case RETRO_MEMORY_SYSTEM_RAM: case RETRO_MEMORY_SYSTEM_RAM:
size = gbCgbMode ? 0x8000 : 0x2000; size = gbCgbMode ? 0x8000 : 0x2000;
@ -355,7 +398,7 @@ size_t retro_get_memory_size(unsigned id)
size = gbCgbMode ? 0x4000 : 0x2000; size = gbCgbMode ? 0x4000 : 0x2000;
break; break;
case RETRO_MEMORY_RTC: case RETRO_MEMORY_RTC:
if (gbRTCPresent) if (g_gbCartData.has_rtc())
size = gb_rtcdata_size(); size = gb_rtcdata_size();
break; break;
} }
@ -610,7 +653,7 @@ static const char *gbGetCartridgeType(void)
{ {
const char *type = "Unknown"; const char *type = "Unknown";
switch (gbRom[0x147]) { switch (g_gbCartData.mapper_flag()) {
case 0x00: case 0x00:
type = "ROM"; type = "ROM";
break; break;
@ -701,24 +744,33 @@ static const char *gbGetSaveRamSize(void)
{ {
const char *type = "Unknown"; const char *type = "Unknown";
switch (gbRom[0x149]) { switch (g_gbCartData.ram_size()) {
case 0: case 0:
type = "None"; type = "None";
break; break;
case 1: case k256B:
type = "256B";
break;
case k512B:
type = "512B";
break;
case k2KiB:
type = "2K"; type = "2K";
break; break;
case 2: case k8KiB:
type = "8K"; type = "8K";
break; break;
case 3: case k32KiB:
type = "32K"; type = "32K";
break; break;
case 4: case k64KiB:
type = "64K";
break;
case k128KiB:
type = "128K"; type = "128K";
break; break;
case 5: default:
type = "64K"; type = "Unknown";
break; break;
} }
@ -904,33 +956,19 @@ static void gb_init(void)
gbReset(); // also resets sound; gbReset(); // also resets sound;
set_gbPalette(); set_gbPalette();
log("Rom size : %02x (%dK)\n", gbRom[0x148], (romSize + 1023) / 1024); log("Rom size : %02x (%dK)\n", g_gbCartData.rom_flag(), (romSize + 1023) / 1024);
log("Cartridge type : %02x (%s)\n", gbRom[0x147], gbGetCartridgeType()); log("Cartridge type : %02x (%s)\n", g_gbCartData.mapper_flag(), gbGetCartridgeType());
log("Ram size : %02x (%s)\n", gbRom[0x149], gbGetSaveRamSize()); 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; if (g_gbCartData.has_battery())
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)
log("Game supports battery save ram.\n"); log("Game supports battery save ram.\n");
if (gbRom[0x143] == 0xc0) if (g_gbCartData.RequiresCGB())
log("Game works on CGB only\n"); 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"); log("Game supports GBC functions, GB compatible.\n");
if (gbRom[0x146] == 0x03) if (g_gbCartData.sgb_support())
log("Game supports SGB functions\n"); log("Game supports SGB functions\n");
} }
@ -1399,22 +1437,36 @@ void retro_run(void)
firstrun = false; firstrun = false;
/* Check if GB game has RTC data. Has to be check here since this is where the data will be /* 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. */ * available when using libretro api. */
if ((type == IMAGE_GB) && gbRTCPresent) { if ((type == IMAGE_GB) && g_gbCartData.has_rtc()) {
switch (gbRomType) { switch (g_gbCartData.mapper_type()) {
case 0x0f: case gbCartData::MapperType::kMbc3:
case 0x10:
/* Check if any RTC has been loaded, zero value means nothing has been loaded. */ /* Check if any RTC has been loaded, zero value means nothing has been loaded. */
if (!gbDataMBC3.mapperLastTime) if (!gbDataMBC3.mapperLastTime)
initRTC = true; initRTC = true;
break; break;
case 0xfd: case gbCartData::MapperType::kTama5:
if (!gbDataTAMA5.mapperLastTime) if (!gbDataTAMA5.mapperLastTime)
initRTC = true; initRTC = true;
break; break;
case 0xfe: case gbCartData::MapperType::kHuC3:
if (!gbRTCHuC3.mapperLastTime) if (!gbRTCHuC3.mapperLastTime)
initRTC = true; initRTC = true;
break; 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 */ /* Initialize RTC using local time if needed */
if (initRTC) if (initRTC)

View File

@ -751,21 +751,9 @@ EVT_HANDLER_MASK(RomInformation, "ROM information...", CMDEN_GB | CMDEN_GBA)
setblab("DestCode", gbRom[0x14a]); setblab("DestCode", gbRom[0x14a]);
setblab("LicCode", gbRom[0x14b]); setblab("LicCode", gbRom[0x14b]);
setblab("Version", gbRom[0x14c]); setblab("Version", gbRom[0x14c]);
uint8_t crc = 25; s.Printf(wxT("%02x (%02x)"), g_gbCartData.actual_header_checksum(), g_gbCartData.header_checksum());
for (int i = 0x134; i < 0x14d; i++)
crc += gbRom[i];
crc = 256 - crc;
s.Printf(wxT("%02x (%02x)"), crc, gbRom[0x14d]);
setlab("CRC"); setlab("CRC");
uint16_t crc16 = 0; s.Printf(wxT("%04x (%04x)"), g_gbCartData.actual_global_checksum(), g_gbCartData.global_checksum());
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]);
setlab("Checksum"); setlab("Checksum");
dlg->Fit(); dlg->Fit();
ShowModal(dlg); ShowModal(dlg);

View File

@ -946,9 +946,9 @@ public:
else else
block->data = &gbMemory[0xa000]; block->data = &gbMemory[0xa000];
block->saved = (uint8_t*)malloc(gbRamSize); block->saved = (uint8_t*)malloc(g_gbCartData.ram_size());
block->size = gbRamSize; block->size = g_gbCartData.ram_size();
block->bits = (uint8_t*)malloc(gbRamSize >> 3); block->bits = (uint8_t*)malloc(g_gbCartData.ram_size() >> 3);
if (gbCgbMode) { if (gbCgbMode) {
block++; block++;