Skip to content

Commit

Permalink
Merge pull request #73 from retro-wertz/libretro_cleanup
Browse files Browse the repository at this point in the history
Libretro cleanup and MBC3 RTC update
  • Loading branch information
hizzlekizzle committed Aug 10, 2019
2 parents 1ef0912 + 82e723a commit 36f3a73
Show file tree
Hide file tree
Showing 5 changed files with 404 additions and 359 deletions.
21 changes: 19 additions & 2 deletions src/gb/GB.cpp
Expand Up @@ -195,6 +195,7 @@ int gbSynchronizeTicks = GBSYNCHRONIZE_CLOCK_TICKS;
// emulator features
int gbBattery = 0;
int gbRumble = 0;
int gbRTCPresent = 0;
bool gbBatteryError = false;
int gbCaptureNumber = 0;
bool gbCapture = false;
Expand Down Expand Up @@ -4360,8 +4361,6 @@ bool gbUpdateSizes()
memset(gbRam, gbRamFill, gbRamSize);
}

gbBattery = gbRumble = 0;

switch (gbRomType) {
case 0x03:
case 0x06:
Expand All @@ -4377,13 +4376,31 @@ bool gbUpdateSizes()
case 0xff:
gbBattery = 1;
break;
default:
gbBattery = 0;
break;
}

switch (gbRomType) {
case 0x1c:
case 0x1d:
case 0x1e:
gbRumble = 1;
break;
default:
gbRumble = 0;
break;
}

switch (gbRomType) {
case 0x0f:
case 0x10: // mbc3
case 0xfd: // tama5
gbRTCPresent = 1;
break;
default:
gbRTCPresent = 0;
break;
}

gbInit();
Expand Down
1 change: 1 addition & 0 deletions src/gb/gb.h
Expand Up @@ -62,6 +62,7 @@ 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 struct EmulatedSystem GBSystem;

Expand Down
62 changes: 32 additions & 30 deletions src/gb/gbMemory.cpp
Expand Up @@ -389,24 +389,26 @@ void mapperMBC3ROM(uint16_t address, uint8_t value)
gbDataMBC3.mapperRAMBank = value;
gbDataMBC3.mapperRAMAddress = tmpAddress;
} else {
if (gbDataMBC3.mapperRAMEnable) {
if (gbRTCPresent && gbDataMBC3.mapperRAMEnable) {
gbDataMBC3.mapperRAMBank = -1;

gbDataMBC3.mapperClockRegister = value;
}
}
break;
case 0x6000: // clock latch
if (gbDataMBC3.mapperClockLatch == 0 && value == 1) {
memoryUpdateMBC3Clock();
gbDataMBC3.mapperLSeconds = gbDataMBC3.mapperSeconds;
gbDataMBC3.mapperLMinutes = gbDataMBC3.mapperMinutes;
gbDataMBC3.mapperLHours = gbDataMBC3.mapperHours;
gbDataMBC3.mapperLDays = gbDataMBC3.mapperDays;
gbDataMBC3.mapperLControl = gbDataMBC3.mapperControl;
if (gbRTCPresent) {
if (gbDataMBC3.mapperClockLatch == 0 && value == 1) {
memoryUpdateMBC3Clock();
gbDataMBC3.mapperLSeconds = gbDataMBC3.mapperSeconds;
gbDataMBC3.mapperLMinutes = gbDataMBC3.mapperMinutes;
gbDataMBC3.mapperLHours = gbDataMBC3.mapperHours;
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;
}
}
Expand All @@ -415,12 +417,12 @@ void mapperMBC3ROM(uint16_t address, uint8_t value)
void mapperMBC3RAM(uint16_t address, uint8_t value)
{
if (gbDataMBC3.mapperRAMEnable) {
if (gbDataMBC3.mapperRAMBank != -1) {
if (gbDataMBC3.mapperRAMBank >= 0) {
if (gbRamSize) {
gbMemoryMap[address >> 12][address & 0x0fff] = value;
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
}
} else {
} else if (gbRTCPresent) {
time(&gbDataMBC3.mapperLastTime);
switch (gbDataMBC3.mapperClockRegister) {
case 0x08:
Expand Down Expand Up @@ -450,25 +452,25 @@ void mapperMBC3RAM(uint16_t address, uint8_t value)
uint8_t mapperMBC3ReadRAM(uint16_t address)
{
if (gbDataMBC3.mapperRAMEnable) {
if (gbDataMBC3.mapperRAMBank != -1) {
if (gbDataMBC3.mapperRAMBank >= 0) {
return gbMemoryMap[address >> 12][address & 0x0fff];
}

switch (gbDataMBC3.mapperClockRegister) {
case 0x08:
return gbDataMBC3.mapperLSeconds;
break;
case 0x09:
return gbDataMBC3.mapperLMinutes;
break;
case 0x0a:
return gbDataMBC3.mapperLHours;
break;
case 0x0b:
return gbDataMBC3.mapperLDays;
break;
case 0x0c:
return gbDataMBC3.mapperLControl;
} else if (gbRTCPresent) {
switch (gbDataMBC3.mapperClockRegister) {
case 0x08:
return gbDataMBC3.mapperLSeconds;
break;
case 0x09:
return gbDataMBC3.mapperLMinutes;
break;
case 0x0a:
return gbDataMBC3.mapperLHours;
break;
case 0x0b:
return gbDataMBC3.mapperLDays;
break;
case 0x0c:
return gbDataMBC3.mapperLControl;
}
}
}

Expand Down

0 comments on commit 36f3a73

Please sign in to comment.