GB: Fix timer edge conditions

This commit is contained in:
Jeffrey Pfau 2016-09-17 01:00:21 -07:00
parent e82c9aadea
commit c280d8efa6
1 changed files with 19 additions and 4 deletions

View File

@ -183,18 +183,33 @@ static void _latchRtc(struct mRTCSource* rtc, uint8_t* rtcRegs, time_t* rtcLastL
t -= *rtcLastLatch;
*rtcLastLatch = currentLatch;
unsigned diff;
int64_t diff;
diff = rtcRegs[0] + t % 60;
if (diff < 0) {
diff += 60;
t -= 60;
}
rtcRegs[0] = diff % 60;
t = t / 60 + diff / 60;
t /= 60;
t += diff / 60;
diff = rtcRegs[1] + t % 60;
if (diff < 0) {
diff += 60;
t -= 60;
}
rtcRegs[1] = diff % 60;
t = t / 60 + diff / 60;
t /= 60;
t += diff / 60;
diff = rtcRegs[2] + t % 24;
if (diff < 0) {
diff += 24;
t -= 24;
}
rtcRegs[2] = diff % 24;
t = t / 24 + diff / 24;
t /= 24;
t += diff / 24;
diff = rtcRegs[3] + ((rtcRegs[4] & 1) << 8) + (t & 0x1FF);
rtcRegs[3] = diff;