2015-11-14 00:52:51 +00:00
|
|
|
auto EpsonRTC::irq(uint2 period) -> void {
|
Update to v089r06 release.
[Yes, the release number is re-used. -Ed.]
byuu says:
I had some bugs in r07 that I couldn't track down, DKJM2's clock was
getting all out of sync.
So I just reverted to r05, blew away both RTCs entirely, and wrote them
cleanly from scratch (obviously looking off the old code.) A bit
extreme, but it worked.
I believe I found the error in the process, day and month were resetting
the counter to 0 instead of 1, it wasn't handling leap year, etc.
While I was at it, I fixed the day-of-week calculation. The SharpRTC
epoch is actually 1000-01-01, and not 1900-01-01.
I'm sure you guys will be really happy that if it ever becomes 1000AD
again and you're playing a ROM hack that uses the SharpRTC and relies on
its weekday value that it will show the correct day now ...
Kind of a pain to compute, but nothing compared to the seventh circle of
hell that was my IBM dBase III Julian<>Gregorian conversion functions :/
Also found a few bugs in the Epson code this way. And I moved the round
seconds actions and flag clear to +125us after flag set.
So, if you had the old r06 or r07, please delete those.
Unfortunately, this took all of my energy today, so the file names
inside manifest changes will have to be in the next WIP.
EDIT: ran a diff against old r07 and new r06.
- added if(days == 31) case twice in EpsonRTC::tick_day()
- forgot weekday = 0; in SharpRTC::load()
- need to move the cartridge+cheat objects up in sfc/Makefile again
- System::init() needs assert(interface != nullptr /* not 0 */)
2012-05-24 23:26:06 +00:00
|
|
|
if(stop || pause) return;
|
2012-05-23 11:27:45 +00:00
|
|
|
|
2012-05-22 12:10:00 +00:00
|
|
|
if(period == irqperiod) irqflag = 1;
|
|
|
|
}
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto EpsonRTC::duty() -> void {
|
2012-05-22 12:10:00 +00:00
|
|
|
if(irqduty) irqflag = 0;
|
|
|
|
}
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto EpsonRTC::round_seconds() -> void {
|
Update to v089r06 release.
[Yes, the release number is re-used. -Ed.]
byuu says:
I had some bugs in r07 that I couldn't track down, DKJM2's clock was
getting all out of sync.
So I just reverted to r05, blew away both RTCs entirely, and wrote them
cleanly from scratch (obviously looking off the old code.) A bit
extreme, but it worked.
I believe I found the error in the process, day and month were resetting
the counter to 0 instead of 1, it wasn't handling leap year, etc.
While I was at it, I fixed the day-of-week calculation. The SharpRTC
epoch is actually 1000-01-01, and not 1900-01-01.
I'm sure you guys will be really happy that if it ever becomes 1000AD
again and you're playing a ROM hack that uses the SharpRTC and relies on
its weekday value that it will show the correct day now ...
Kind of a pain to compute, but nothing compared to the seventh circle of
hell that was my IBM dBase III Julian<>Gregorian conversion functions :/
Also found a few bugs in the Epson code this way. And I moved the round
seconds actions and flag clear to +125us after flag set.
So, if you had the old r06 or r07, please delete those.
Unfortunately, this took all of my energy today, so the file names
inside manifest changes will have to be in the next WIP.
EDIT: ran a diff against old r07 and new r06.
- added if(days == 31) case twice in EpsonRTC::tick_day()
- forgot weekday = 0; in SharpRTC::load()
- need to move the cartridge+cheat objects up in sfc/Makefile again
- System::init() needs assert(interface != nullptr /* not 0 */)
2012-05-24 23:26:06 +00:00
|
|
|
if(roundseconds == 0) return;
|
|
|
|
roundseconds = 0;
|
|
|
|
|
|
|
|
if(secondhi >= 3) tick_minute();
|
|
|
|
secondlo = 0;
|
|
|
|
secondhi = 0;
|
|
|
|
}
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto EpsonRTC::tick() -> void {
|
Update to v089r06 release.
[Yes, the release number is re-used. -Ed.]
byuu says:
I had some bugs in r07 that I couldn't track down, DKJM2's clock was
getting all out of sync.
So I just reverted to r05, blew away both RTCs entirely, and wrote them
cleanly from scratch (obviously looking off the old code.) A bit
extreme, but it worked.
I believe I found the error in the process, day and month were resetting
the counter to 0 instead of 1, it wasn't handling leap year, etc.
While I was at it, I fixed the day-of-week calculation. The SharpRTC
epoch is actually 1000-01-01, and not 1900-01-01.
I'm sure you guys will be really happy that if it ever becomes 1000AD
again and you're playing a ROM hack that uses the SharpRTC and relies on
its weekday value that it will show the correct day now ...
Kind of a pain to compute, but nothing compared to the seventh circle of
hell that was my IBM dBase III Julian<>Gregorian conversion functions :/
Also found a few bugs in the Epson code this way. And I moved the round
seconds actions and flag clear to +125us after flag set.
So, if you had the old r06 or r07, please delete those.
Unfortunately, this took all of my energy today, so the file names
inside manifest changes will have to be in the next WIP.
EDIT: ran a diff against old r07 and new r06.
- added if(days == 31) case twice in EpsonRTC::tick_day()
- forgot weekday = 0; in SharpRTC::load()
- need to move the cartridge+cheat objects up in sfc/Makefile again
- System::init() needs assert(interface != nullptr /* not 0 */)
2012-05-24 23:26:06 +00:00
|
|
|
if(stop || pause) return;
|
2012-05-23 11:27:45 +00:00
|
|
|
|
|
|
|
if(hold) {
|
Update to v089r06 release.
[Yes, the release number is re-used. -Ed.]
byuu says:
I had some bugs in r07 that I couldn't track down, DKJM2's clock was
getting all out of sync.
So I just reverted to r05, blew away both RTCs entirely, and wrote them
cleanly from scratch (obviously looking off the old code.) A bit
extreme, but it worked.
I believe I found the error in the process, day and month were resetting
the counter to 0 instead of 1, it wasn't handling leap year, etc.
While I was at it, I fixed the day-of-week calculation. The SharpRTC
epoch is actually 1000-01-01, and not 1900-01-01.
I'm sure you guys will be really happy that if it ever becomes 1000AD
again and you're playing a ROM hack that uses the SharpRTC and relies on
its weekday value that it will show the correct day now ...
Kind of a pain to compute, but nothing compared to the seventh circle of
hell that was my IBM dBase III Julian<>Gregorian conversion functions :/
Also found a few bugs in the Epson code this way. And I moved the round
seconds actions and flag clear to +125us after flag set.
So, if you had the old r06 or r07, please delete those.
Unfortunately, this took all of my energy today, so the file names
inside manifest changes will have to be in the next WIP.
EDIT: ran a diff against old r07 and new r06.
- added if(days == 31) case twice in EpsonRTC::tick_day()
- forgot weekday = 0; in SharpRTC::load()
- need to move the cartridge+cheat objects up in sfc/Makefile again
- System::init() needs assert(interface != nullptr /* not 0 */)
2012-05-24 23:26:06 +00:00
|
|
|
holdtick = 1;
|
2012-05-23 11:27:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-05-22 12:10:00 +00:00
|
|
|
|
Update to v089r06 release.
[Yes, the release number is re-used. -Ed.]
byuu says:
I had some bugs in r07 that I couldn't track down, DKJM2's clock was
getting all out of sync.
So I just reverted to r05, blew away both RTCs entirely, and wrote them
cleanly from scratch (obviously looking off the old code.) A bit
extreme, but it worked.
I believe I found the error in the process, day and month were resetting
the counter to 0 instead of 1, it wasn't handling leap year, etc.
While I was at it, I fixed the day-of-week calculation. The SharpRTC
epoch is actually 1000-01-01, and not 1900-01-01.
I'm sure you guys will be really happy that if it ever becomes 1000AD
again and you're playing a ROM hack that uses the SharpRTC and relies on
its weekday value that it will show the correct day now ...
Kind of a pain to compute, but nothing compared to the seventh circle of
hell that was my IBM dBase III Julian<>Gregorian conversion functions :/
Also found a few bugs in the Epson code this way. And I moved the round
seconds actions and flag clear to +125us after flag set.
So, if you had the old r06 or r07, please delete those.
Unfortunately, this took all of my energy today, so the file names
inside manifest changes will have to be in the next WIP.
EDIT: ran a diff against old r07 and new r06.
- added if(days == 31) case twice in EpsonRTC::tick_day()
- forgot weekday = 0; in SharpRTC::load()
- need to move the cartridge+cheat objects up in sfc/Makefile again
- System::init() needs assert(interface != nullptr /* not 0 */)
2012-05-24 23:26:06 +00:00
|
|
|
resync = 1;
|
2012-05-22 12:10:00 +00:00
|
|
|
tick_second();
|
|
|
|
}
|
|
|
|
|
2012-05-23 11:27:45 +00:00
|
|
|
//below code provides bit-perfect emulation of invalid BCD values on the RTC-4513
|
Update to v089r06 release.
[Yes, the release number is re-used. -Ed.]
byuu says:
I had some bugs in r07 that I couldn't track down, DKJM2's clock was
getting all out of sync.
So I just reverted to r05, blew away both RTCs entirely, and wrote them
cleanly from scratch (obviously looking off the old code.) A bit
extreme, but it worked.
I believe I found the error in the process, day and month were resetting
the counter to 0 instead of 1, it wasn't handling leap year, etc.
While I was at it, I fixed the day-of-week calculation. The SharpRTC
epoch is actually 1000-01-01, and not 1900-01-01.
I'm sure you guys will be really happy that if it ever becomes 1000AD
again and you're playing a ROM hack that uses the SharpRTC and relies on
its weekday value that it will show the correct day now ...
Kind of a pain to compute, but nothing compared to the seventh circle of
hell that was my IBM dBase III Julian<>Gregorian conversion functions :/
Also found a few bugs in the Epson code this way. And I moved the round
seconds actions and flag clear to +125us after flag set.
So, if you had the old r06 or r07, please delete those.
Unfortunately, this took all of my energy today, so the file names
inside manifest changes will have to be in the next WIP.
EDIT: ran a diff against old r07 and new r06.
- added if(days == 31) case twice in EpsonRTC::tick_day()
- forgot weekday = 0; in SharpRTC::load()
- need to move the cartridge+cheat objects up in sfc/Makefile again
- System::init() needs assert(interface != nullptr /* not 0 */)
2012-05-24 23:26:06 +00:00
|
|
|
//code makes extensive use of variable-length integers (see epsonrtc.hpp for sizes)
|
2012-05-23 11:27:45 +00:00
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto EpsonRTC::tick_second() -> void {
|
2012-05-22 12:10:00 +00:00
|
|
|
if(secondlo <= 8 || secondlo == 12) {
|
|
|
|
secondlo++;
|
|
|
|
} else {
|
|
|
|
secondlo = 0;
|
|
|
|
if(secondhi < 5) {
|
|
|
|
secondhi++;
|
|
|
|
} else {
|
|
|
|
secondhi = 0;
|
|
|
|
tick_minute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto EpsonRTC::tick_minute() -> void {
|
2012-05-22 12:10:00 +00:00
|
|
|
if(minutelo <= 8 || minutelo == 12) {
|
|
|
|
minutelo++;
|
|
|
|
} else {
|
|
|
|
minutelo = 0;
|
|
|
|
if(minutehi < 5) {
|
|
|
|
minutehi++;
|
|
|
|
} else {
|
|
|
|
minutehi = 0;
|
|
|
|
tick_hour();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto EpsonRTC::tick_hour() -> void {
|
2012-05-22 12:10:00 +00:00
|
|
|
if(atime) {
|
|
|
|
if(hourhi < 2) {
|
|
|
|
if(hourlo <= 8 || hourlo == 12) {
|
|
|
|
hourlo++;
|
|
|
|
} else {
|
|
|
|
hourlo = !(hourlo & 1);
|
|
|
|
hourhi++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(hourlo != 3 && !(hourlo & 4)) {
|
|
|
|
if(hourlo <= 8 || hourlo >= 12) {
|
|
|
|
hourlo++;
|
|
|
|
} else {
|
|
|
|
hourlo = !(hourlo & 1);
|
|
|
|
hourhi++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
hourlo = !(hourlo & 1);
|
|
|
|
hourhi = 0;
|
|
|
|
tick_day();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(hourhi == 0) {
|
|
|
|
if(hourlo <= 8 || hourlo == 12) {
|
|
|
|
hourlo++;
|
|
|
|
} else {
|
|
|
|
hourlo = !(hourlo & 1);
|
|
|
|
hourhi ^= 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(hourlo & 1) meridian ^= 1;
|
|
|
|
if(hourlo < 2 || hourlo == 4 || hourlo == 5 || hourlo == 8 || hourlo == 12) {
|
|
|
|
hourlo++;
|
|
|
|
} else {
|
|
|
|
hourlo = !(hourlo & 1);
|
|
|
|
hourhi ^= 1;
|
|
|
|
}
|
|
|
|
if(meridian == 0 && !(hourlo & 1)) tick_day();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto EpsonRTC::tick_day() -> void {
|
Update to v089r06 release.
[Yes, the release number is re-used. -Ed.]
byuu says:
I had some bugs in r07 that I couldn't track down, DKJM2's clock was
getting all out of sync.
So I just reverted to r05, blew away both RTCs entirely, and wrote them
cleanly from scratch (obviously looking off the old code.) A bit
extreme, but it worked.
I believe I found the error in the process, day and month were resetting
the counter to 0 instead of 1, it wasn't handling leap year, etc.
While I was at it, I fixed the day-of-week calculation. The SharpRTC
epoch is actually 1000-01-01, and not 1900-01-01.
I'm sure you guys will be really happy that if it ever becomes 1000AD
again and you're playing a ROM hack that uses the SharpRTC and relies on
its weekday value that it will show the correct day now ...
Kind of a pain to compute, but nothing compared to the seventh circle of
hell that was my IBM dBase III Julian<>Gregorian conversion functions :/
Also found a few bugs in the Epson code this way. And I moved the round
seconds actions and flag clear to +125us after flag set.
So, if you had the old r06 or r07, please delete those.
Unfortunately, this took all of my energy today, so the file names
inside manifest changes will have to be in the next WIP.
EDIT: ran a diff against old r07 and new r06.
- added if(days == 31) case twice in EpsonRTC::tick_day()
- forgot weekday = 0; in SharpRTC::load()
- need to move the cartridge+cheat objects up in sfc/Makefile again
- System::init() needs assert(interface != nullptr /* not 0 */)
2012-05-24 23:26:06 +00:00
|
|
|
if(calendar == 0) return;
|
2012-05-22 12:10:00 +00:00
|
|
|
weekday = (weekday + 1) + (weekday == 6);
|
|
|
|
|
|
|
|
//January - December = 0x01 - 0x09; 0x10 - 0x12
|
2015-11-14 00:52:51 +00:00
|
|
|
static const uint daysinmonth[32] = {
|
2012-05-22 12:10:00 +00:00
|
|
|
30, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 30, 31, 30,
|
|
|
|
31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30,
|
|
|
|
};
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
uint days = daysinmonth[monthhi << 4 | monthlo];
|
2012-05-22 12:10:00 +00:00
|
|
|
if(days == 28) {
|
|
|
|
//add one day for leap years
|
|
|
|
if((yearhi & 1) == 0 && ((yearlo - 0) & 3) == 0) days++;
|
|
|
|
if((yearhi & 1) == 1 && ((yearlo - 2) & 3) == 0) days++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(days == 28 && (dayhi == 3 || (dayhi == 2 && daylo >= 8))) {
|
|
|
|
daylo = 1;
|
|
|
|
dayhi = 0;
|
|
|
|
return tick_month();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(days == 29 && (dayhi == 3 || (dayhi == 2 && (daylo > 8 && daylo != 12)))) {
|
|
|
|
daylo = 1;
|
|
|
|
dayhi = 0;
|
|
|
|
return tick_month();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(days == 30 && (dayhi == 3 || (dayhi == 2 && (daylo == 10 || daylo == 14)))) {
|
|
|
|
daylo = 1;
|
|
|
|
dayhi = 0;
|
|
|
|
return tick_month();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(days == 31 && (dayhi == 3 && (daylo & 3))) {
|
|
|
|
daylo = 1;
|
|
|
|
dayhi = 0;
|
|
|
|
return tick_month();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(daylo <= 8 || daylo == 12) {
|
|
|
|
daylo++;
|
|
|
|
} else {
|
|
|
|
daylo = !(daylo & 1);
|
|
|
|
dayhi++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto EpsonRTC::tick_month() -> void {
|
2012-05-22 12:10:00 +00:00
|
|
|
if(monthhi == 0 || !(monthlo & 2)) {
|
|
|
|
if(monthlo <= 8 || monthlo == 12) {
|
|
|
|
monthlo++;
|
|
|
|
} else {
|
|
|
|
monthlo = !(monthlo & 1);
|
|
|
|
monthhi ^= 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
monthlo = !(monthlo & 1);
|
|
|
|
monthhi = 0;
|
|
|
|
tick_year();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto EpsonRTC::tick_year() -> void {
|
2012-05-22 12:10:00 +00:00
|
|
|
if(yearlo <= 8 || yearlo == 12) {
|
|
|
|
yearlo++;
|
|
|
|
} else {
|
|
|
|
yearlo = !(yearlo & 1);
|
|
|
|
if(yearhi <= 8 || yearhi == 12) {
|
|
|
|
yearhi++;
|
|
|
|
} else {
|
|
|
|
yearhi = !(yearhi & 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|