Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBC3 RTC fixes #64

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions libgambatte/src/mem/rtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,43 +116,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::time_t seconds = time(cc);
std::time_t seconds = (dataDh_ & 0x40) ? haltTime_ : time(cc);
std::time_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::time_t seconds = time(cc);
std::time_t seconds = (dataDh_ & 0x40) ? haltTime_ : time(cc);
std::time_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::time_t seconds = time(cc);
std::time_t seconds = (dataDh_ & 0x40) ? haltTime_ : time(cc);
std::time_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::time_t seconds = time(cc);
std::time_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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting for whenever this gets picked up: the else block body in setS needs to stay as time_.reset(seconds, cc) to pass the subsecond writes tests.

}

}