Skip to content

Commit

Permalink
Merge pull request #3 from TiKevin83/feature/mbc3-rtc-fixes
Browse files Browse the repository at this point in the history
porting Mbc3 RTC fixes from upstream pokemon-speedrunning#64
  • Loading branch information
TiKevin83 authored Nov 23, 2020
2 parents 56e11e6 + 41d482d commit fe86ec7
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions libgambatte/src/mem/rtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,43 +107,51 @@ void Rtc::setDh(unsigned const newDh, unsigned const long cc) {
seconds += ((newDh & 0x1) << 8) * 86400;
time_.set(seconds, cc);

if ((dataDh_ ^ newDh) & 0x40) {
if (newDh & 0x40)
haltTime_ = seconds;
else
time_.set(haltTime_, cc);
}
if (newDh & 0x40)
haltTime_ = seconds;
}

void Rtc::setDl(unsigned const newLowdays, unsigned const long cc) {
std::uint32_t seconds = time(cc);
std::uint32_t seconds = (dataDh_ & 0x40) ? haltTime_ : time(cc);
std::uint32_t const oldLowdays = (seconds / 86400) & 0xFF;
seconds -= oldLowdays * 86400;
seconds += newLowdays * 86400;
time_.set(seconds, cc);
if (dataDh_ & 0x40)
haltTime_ = seconds;
else
time_.set(seconds, cc);
}

void Rtc::setH(unsigned const newHours, unsigned const long cc) {
std::uint32_t seconds = time(cc);
std::uint32_t seconds = (dataDh_ & 0x40) ? haltTime_ : time(cc);
std::uint32_t const oldHours = (seconds / 3600) % 24;
seconds -= oldHours * 3600;
seconds += newHours * 3600;
time_.set(seconds, cc);
if (dataDh_ & 0x40)
haltTime_ = seconds;
else
time_.set(seconds, cc);
}

void Rtc::setM(unsigned const newMinutes, unsigned const long cc) {
std::uint32_t seconds = time(cc);
std::uint32_t seconds = (dataDh_ & 0x40) ? haltTime_ : time(cc);
std::uint32_t const oldMinutes = (seconds / 60) % 60;
seconds -= oldMinutes * 60;
seconds += newMinutes * 60;
time_.set(seconds, cc);
if (dataDh_ & 0x40)
haltTime_ = seconds;
else
time_.set(seconds, cc);
}

void Rtc::setS(unsigned const newSeconds, unsigned const long cc) {
std::uint32_t seconds = time(cc);
std::uint32_t seconds = (dataDh_ & 0x40) ? haltTime_ : time(cc);
seconds -= seconds % 60;
seconds += newSeconds;
time_.reset(seconds, cc);
if (dataDh_ & 0x40)
haltTime_ = seconds;
else
time_.set(seconds, cc);
}

SYNCFUNC(Rtc)
Expand Down

0 comments on commit fe86ec7

Please sign in to comment.