MBC3: Update mapper to check if RTC is present before running RTC functions

This commit is contained in:
retro-wertz 2019-08-10 19:01:10 +08:00
parent 03184dd513
commit 82e723a528
1 changed files with 32 additions and 30 deletions

View File

@ -389,7 +389,7 @@ void mapperMBC3ROM(uint16_t address, uint8_t value)
gbDataMBC3.mapperRAMBank = value; gbDataMBC3.mapperRAMBank = value;
gbDataMBC3.mapperRAMAddress = tmpAddress; gbDataMBC3.mapperRAMAddress = tmpAddress;
} else { } else {
if (gbDataMBC3.mapperRAMEnable) { if (gbRTCPresent && gbDataMBC3.mapperRAMEnable) {
gbDataMBC3.mapperRAMBank = -1; gbDataMBC3.mapperRAMBank = -1;
gbDataMBC3.mapperClockRegister = value; gbDataMBC3.mapperClockRegister = value;
@ -397,16 +397,18 @@ void mapperMBC3ROM(uint16_t address, uint8_t value)
} }
break; break;
case 0x6000: // clock latch case 0x6000: // clock latch
if (gbDataMBC3.mapperClockLatch == 0 && value == 1) { if (gbRTCPresent) {
memoryUpdateMBC3Clock(); if (gbDataMBC3.mapperClockLatch == 0 && value == 1) {
gbDataMBC3.mapperLSeconds = gbDataMBC3.mapperSeconds; memoryUpdateMBC3Clock();
gbDataMBC3.mapperLMinutes = gbDataMBC3.mapperMinutes; gbDataMBC3.mapperLSeconds = gbDataMBC3.mapperSeconds;
gbDataMBC3.mapperLHours = gbDataMBC3.mapperHours; gbDataMBC3.mapperLMinutes = gbDataMBC3.mapperMinutes;
gbDataMBC3.mapperLDays = gbDataMBC3.mapperDays; gbDataMBC3.mapperLHours = gbDataMBC3.mapperHours;
gbDataMBC3.mapperLControl = gbDataMBC3.mapperControl; gbDataMBC3.mapperLDays = gbDataMBC3.mapperDays;
gbDataMBC3.mapperLControl = gbDataMBC3.mapperControl;
}
if (value == 0x00 || value == 0x01)
gbDataMBC3.mapperClockLatch = value;
} }
if (value == 0x00 || value == 0x01)
gbDataMBC3.mapperClockLatch = value;
break; break;
} }
} }
@ -415,12 +417,12 @@ void mapperMBC3ROM(uint16_t address, uint8_t value)
void mapperMBC3RAM(uint16_t address, uint8_t value) void mapperMBC3RAM(uint16_t address, uint8_t value)
{ {
if (gbDataMBC3.mapperRAMEnable) { if (gbDataMBC3.mapperRAMEnable) {
if (gbDataMBC3.mapperRAMBank != -1) { if (gbDataMBC3.mapperRAMBank >= 0) {
if (gbRamSize) { if (gbRamSize) {
gbMemoryMap[address >> 12][address & 0x0fff] = value; gbMemoryMap[address >> 12][address & 0x0fff] = value;
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
} }
} else { } else if (gbRTCPresent) {
time(&gbDataMBC3.mapperLastTime); time(&gbDataMBC3.mapperLastTime);
switch (gbDataMBC3.mapperClockRegister) { switch (gbDataMBC3.mapperClockRegister) {
case 0x08: case 0x08:
@ -450,25 +452,25 @@ void mapperMBC3RAM(uint16_t address, uint8_t value)
uint8_t mapperMBC3ReadRAM(uint16_t address) uint8_t mapperMBC3ReadRAM(uint16_t address)
{ {
if (gbDataMBC3.mapperRAMEnable) { if (gbDataMBC3.mapperRAMEnable) {
if (gbDataMBC3.mapperRAMBank != -1) { if (gbDataMBC3.mapperRAMBank >= 0) {
return gbMemoryMap[address >> 12][address & 0x0fff]; return gbMemoryMap[address >> 12][address & 0x0fff];
} } else if (gbRTCPresent) {
switch (gbDataMBC3.mapperClockRegister) {
switch (gbDataMBC3.mapperClockRegister) { case 0x08:
case 0x08: return gbDataMBC3.mapperLSeconds;
return gbDataMBC3.mapperLSeconds; break;
break; case 0x09:
case 0x09: return gbDataMBC3.mapperLMinutes;
return gbDataMBC3.mapperLMinutes; break;
break; case 0x0a:
case 0x0a: return gbDataMBC3.mapperLHours;
return gbDataMBC3.mapperLHours; break;
break; case 0x0b:
case 0x0b: return gbDataMBC3.mapperLDays;
return gbDataMBC3.mapperLDays; break;
break; case 0x0c:
case 0x0c: return gbDataMBC3.mapperLControl;
return gbDataMBC3.mapperLControl; }
} }
} }