Open
Description
Originally posted on Stardot but for some reason I never opened a bug here 🤦♂️
I've recently acquired a Master 128 so have been poking around in Master 128 emulation for the first time and (re)discovered a Y2K issue, that was presumably masked before by the "Y2K adjust" option.
Was the aim of the Y2K adjust to keep dates in the 21st century, but after the 80s for old software's sake? If so it needs updating now!
The following modified code would seem to work to me for reading and setting the time, but maybe I'm missing something about how the RTC is supposed to work.
/*-------------------------------------------------------------------------*/
time_t CMOSConvertClock()
{
struct tm *CurTime = localtime(&SysTime);
struct tm Base;
Base.tm_sec = BCDToBin(CMOSRAM[0]);
Base.tm_min = BCDToBin(CMOSRAM[2]);
Base.tm_hour = BCDToBin(CMOSRAM[4]);
Base.tm_mday = BCDToBin(CMOSRAM[7]);
Base.tm_mon = BCDToBin(CMOSRAM[8])-1;
Base.tm_year = BCDToBin(CMOSRAM[9]);
Base.tm_wday = -1;
Base.tm_yday = -1;
Base.tm_isdst = -1;
Base.tm_year += (CurTime->tm_year / 100) * 100;
return mktime(&Base);
}
/*-------------------------------------------------------------------------*/
void RTCInit()
{
time(&SysTime);
struct tm *CurTime = localtime(&SysTime);
CMOSRAM[0] = BCD(static_cast<unsigned char>(CurTime->tm_sec));
CMOSRAM[2] = BCD(static_cast<unsigned char>(CurTime->tm_min));
CMOSRAM[4] = BCD(static_cast<unsigned char>(CurTime->tm_hour));
CMOSRAM[6] = BCD(static_cast<unsigned char>(CurTime->tm_wday + 1));
CMOSRAM[7] = BCD(static_cast<unsigned char>(CurTime->tm_mday));
CMOSRAM[8] = BCD(static_cast<unsigned char>(CurTime->tm_mon + 1));
CMOSRAM[9] = BCD(static_cast<unsigned char>((CurTime->tm_year - (RTCY2KAdjust ? 20 : 0)) % 100));
RTCTimeOffset = SysTime - CMOSConvertClock();
}
/*-------------------------------------------------------------------------*/
void RTCUpdate()
{
time(&SysTime);
SysTime -= RTCTimeOffset;
struct tm *CurTime = localtime(&SysTime);
CMOSRAM[0] = BCD(static_cast<unsigned char>(CurTime->tm_sec));
CMOSRAM[2] = BCD(static_cast<unsigned char>(CurTime->tm_min));
CMOSRAM[4] = BCD(static_cast<unsigned char>(CurTime->tm_hour));
CMOSRAM[6] = BCD(static_cast<unsigned char>(CurTime->tm_wday + 1));
CMOSRAM[7] = BCD(static_cast<unsigned char>(CurTime->tm_mday));
CMOSRAM[8] = BCD(static_cast<unsigned char>(CurTime->tm_mon + 1));
CMOSRAM[9] = BCD(static_cast<unsigned char>(CurTime->tm_year % 100));
}
Metadata
Metadata
Assignees
Labels
No labels
Activity