HuC3: Update

- Minor refactoring, some variable name and type changes
- Remove unnecessary checks in clock latch
- Fix stuck in whitescreen after Hudson startup logo
- Fix Gamepak error message at initial load of game without prior rtc
  data available to load
- Save the bare-minimum variable needed for rtc (saves only
  Basetime/lastTime)
This commit is contained in:
negativeExponent 2021-05-27 13:02:22 +08:00
parent 6dca6fe8df
commit c05056ab91
4 changed files with 28 additions and 37 deletions

View File

@ -2764,6 +2764,8 @@ void gbReset()
memset(&gbDataHuC3, 0, sizeof(gbDataHuC3));
gbDataHuC3.mapperROMBank = 1;
gbDataHuC3.mapperRAMValue = 1;
gbRTCHuC3.memoryTimerRead = 1;
memset(&gbDataTAMA5, 0, 26 * sizeof(int));
gbDataTAMA5.mapperROMBank = 1;

View File

@ -1016,19 +1016,16 @@ mapperHuC3RTC gbRTCHuC3 = {
0 // ClockShift
};
void memoryupdateHuC3Latch() {
void memoryUpdateHuC3Latch() {
uint64_t now = time(NULL);
uint64_t diff = now - gbRTCHuC3.mapperLastTime;
unsigned minute = (diff / 60) % 1440;
unsigned day = (diff / 86400) & 0xFFF;
if (diff > 0) {
unsigned minute = (diff / 60) % 1440;
unsigned day = (diff / 86400) & 0xFFF;
gbRTCHuC3.mapperDateTime = (day << 12) | minute;
}
gbRTCHuC3.mapperDateTime = (day << 12) | minute;
}
void memoryupdateHuC3Clock() {
void memoryUpdateHuC3Clock() {
uint64_t now = time(NULL);
unsigned minute = (gbRTCHuC3.mapperWritingTime & 0xFFF) % 1440;
unsigned day = (gbRTCHuC3.mapperWritingTime & 0xFFF000) >> 12;
@ -1105,9 +1102,10 @@ void mapperHuC3RAM(uint16_t address, uint8_t value)
}
} else {
if (gbDataHuC3.mapperRAMFlag == 0x0b) {
if (value == 0x62) {
gbDataHuC3.mapperRAMValue = 1;
} else {
//if (value == 0x62) {
//gbDataHuC3.mapperRAMValue = 1;
//} else
{
switch (value & 0xf0) {
case 0x10:
/*p = &gbDataHuC3.mapperRegister2;
@ -1116,8 +1114,8 @@ void mapperHuC3RAM(uint16_t address, uint8_t value)
gbDataHuC3.mapperRegister1 = 0;*/
// read time
memoryupdateHuC3Latch();
if (gbRTCHuC3.mapperModeFlag == HUC3_READ) {
memoryUpdateHuC3Latch();
if (gbRTCHuC3.memoryTimerRead) {
gbDataHuC3.mapperRAMValue = (gbRTCHuC3.mapperDateTime >> gbRTCHuC3.mapperClockShift) & 0x0F;
gbRTCHuC3.mapperClockShift += 4;
if (gbRTCHuC3.mapperClockShift > 24)
@ -1132,15 +1130,15 @@ void mapperHuC3RAM(uint16_t address, uint8_t value)
gbDataHuC3.mapperAddress = (gbDataHuC3.mapperRegister6 << 24) | (gbDataHuC3.mapperRegister5 << 16) | (gbDataHuC3.mapperRegister4 << 8) | (gbDataHuC3.mapperRegister3 << 4) | (gbDataHuC3.mapperRegister2);*/
// write time
if (gbRTCHuC3.mapperModeFlag == HUC3_WRITE) {
if (!gbRTCHuC3.memoryTimerRead) {
if (gbRTCHuC3.mapperClockShift == 0)
gbRTCHuC3.mapperWritingTime = 0;
if (gbRTCHuC3.mapperClockShift <= 24) {
if (gbRTCHuC3.mapperClockShift < 24) {
gbRTCHuC3.mapperWritingTime |= (value & 0x0F) << gbRTCHuC3.mapperClockShift;
gbRTCHuC3.mapperClockShift += 4;
if (gbRTCHuC3.mapperClockShift == 24) {
memoryupdateHuC3Clock();
gbRTCHuC3.mapperModeFlag = HUC3_READ;
memoryUpdateHuC3Clock();
gbRTCHuC3.memoryTimerRead = 1;
}
}
}
@ -1164,11 +1162,11 @@ void mapperHuC3RAM(uint16_t address, uint8_t value)
break;
case 0x3:
// write time?
gbRTCHuC3.mapperModeFlag = HUC3_WRITE;
gbRTCHuC3.memoryTimerRead = 0;
gbRTCHuC3.mapperClockShift = 0;
break;
case 0x7:
gbRTCHuC3.mapperModeFlag = HUC3_READ;
gbRTCHuC3.memoryTimerRead = 1;
gbRTCHuC3.mapperClockShift = 0;
break;
// others are unimplemented so far
@ -1178,8 +1176,8 @@ void mapperHuC3RAM(uint16_t address, uint8_t value)
//gbDataHuC3.mapperRegister1 = (gbDataHuC3.mapperRegister1 & 0x0f) | ((value << 4) & 0x0f);
break;
case 0x60:
gbRTCHuC3.mapperModeFlag = HUC3_READ; // ???
gbDataHuC3.mapperRAMValue = 1;
gbRTCHuC3.memoryTimerRead = 1; // ???
//gbDataHuC3.mapperRAMValue = 1;
break;
default:
//gbDataHuC3.mapperRAMValue = 1;

View File

@ -95,21 +95,16 @@ struct mapperHuC3 {
int mapperRegister8;
};
enum {
HUC3_READ = 0,
HUC3_WRITE = 1,
HUC3_NONE = 2
};
struct mapperHuC3RTC {
union {
time_t mapperLastTime;
uint64_t _time_pad; /* so that 32bit and 64bit saves are compatible */
};
uint32_t mapperDateTime;
uint32_t mapperWritingTime;
uint32_t mapperModeFlag;
uint32_t mapperClockShift;
unsigned mapperDateTime;
unsigned mapperWritingTime;
unsigned memoryTimerRead;
unsigned mapperClockShift;
unsigned reserved[4];
};
struct mapperTAMA5 {

View File

@ -161,9 +161,6 @@ static void set_gbPalette(void)
}
}
extern void memoryupdateHuC3Clock();
extern void memoryupdateHuC3Latch();
static void* gb_rtcdata_prt(void)
{
switch (gbRomType) {
@ -187,7 +184,7 @@ static size_t gb_rtcdata_size(void)
case 0xfd: // TAMA5 + extended
return TAMA5_RTC_DATA_SIZE;
case 0xfe: // HuC3 + Clock
return sizeof(gbRTCHuC3);
return sizeof(gbRTCHuC3.mapperLastTime);
}
return 0;
}
@ -239,8 +236,7 @@ static void gbInitRTC(void)
}
break;
case 0xfe:
//memoryupdateHuC3Clock();
memoryupdateHuC3Latch();
gbRTCHuC3.mapperLastTime = rawtime;
break;
}
}