(mem/rtc) Update variable names

This commit is contained in:
twinaphex 2015-02-18 02:49:51 +01:00
parent 4c3f81d46d
commit 8fbd2169fa
2 changed files with 100 additions and 100 deletions

View File

@ -23,152 +23,152 @@ namespace gambatte
{
Rtc::Rtc()
: activeData(NULL),
activeSet(NULL),
baseTime(0),
haltTime(0),
index(5),
dataDh(0),
dataDl(0),
dataH(0),
dataM(0),
dataS(0),
enabled(false),
lastLatchData(false)
: activeData_(NULL),
activeSet_(NULL),
baseTime_(0),
haltTime_(0),
index_(5),
dataDh_(0),
dataDl_(0),
dataH_(0),
dataM_(0),
dataS_(0),
enabled_(false),
lastLatchData_(false)
{
}
void Rtc::doLatch()
{
uint64_t tmp = ((dataDh & 0x40) ? haltTime : std::time(0)) - baseTime;
uint64_t tmp = ((dataDh_ & 0x40) ? haltTime_ : std::time(0)) - baseTime_;
while (tmp > 0x1FF * 86400)
{
baseTime += 0x1FF * 86400;
baseTime_ += 0x1FF * 86400;
tmp -= 0x1FF * 86400;
dataDh |= 0x80;
dataDh_ |= 0x80;
}
dataDl = (tmp / 86400) & 0xFF;
dataDh &= 0xFE;
dataDh |= ((tmp / 86400) & 0x100) >> 8;
dataDl_ = (tmp / 86400) & 0xFF;
dataDh_ &= 0xFE;
dataDh_ |= ((tmp / 86400) & 0x100) >> 8;
tmp %= 86400;
dataH = tmp / 3600;
dataH_ = tmp / 3600;
tmp %= 3600;
dataM = tmp / 60;
dataM_ = tmp / 60;
tmp %= 60;
dataS = tmp;
dataS_ = tmp;
}
void Rtc::doSwapActive()
{
if (!enabled || index > 4)
if (!enabled_ || index_ > 4)
{
activeData = NULL;
activeSet = NULL;
activeData_ = NULL;
activeSet_ = NULL;
}
else switch (index)
else switch (index_)
{
case 0x00:
activeData = &dataS;
activeSet = &Rtc::setS;
activeData_ = &dataS_;
activeSet_ = &Rtc::setS;
break;
case 0x01:
activeData = &dataM;
activeSet = &Rtc::setM;
activeData_ = &dataM_;
activeSet_ = &Rtc::setM;
break;
case 0x02:
activeData = &dataH;
activeSet = &Rtc::setH;
activeData_ = &dataH_;
activeSet_ = &Rtc::setH;
break;
case 0x03:
activeData = &dataDl;
activeSet = &Rtc::setDl;
activeData_ = &dataDl_;
activeSet_ = &Rtc::setDl;
break;
case 0x04:
activeData = &dataDh;
activeSet = &Rtc::setDh;
activeData_ = &dataDh_;
activeSet_ = &Rtc::setDh;
break;
}
}
void Rtc::saveState(SaveState &state) const
{
state.rtc.baseTime = baseTime;
state.rtc.haltTime = haltTime;
state.rtc.index = index;
state.rtc.dataDh = dataDh;
state.rtc.dataDl = dataDl;
state.rtc.dataH = dataH;
state.rtc.dataM = dataM;
state.rtc.dataS = dataS;
state.rtc.lastLatchData = lastLatchData;
state.rtc.baseTime = baseTime_;
state.rtc.haltTime = haltTime_;
state.rtc.index = index_;
state.rtc.dataDh = dataDh_;
state.rtc.dataDl = dataDl_;
state.rtc.dataH = dataH_;
state.rtc.dataM = dataM_;
state.rtc.dataS = dataS_;
state.rtc.lastLatchData = lastLatchData_;
}
void Rtc::loadState(const SaveState &state, const bool enabled)
{
this->enabled = enabled;
enabled_ = enabled;
baseTime = state.rtc.baseTime;
haltTime = state.rtc.haltTime;
index = state.rtc.index;
dataDh = state.rtc.dataDh;
dataDl = state.rtc.dataDl;
dataH = state.rtc.dataH;
dataM = state.rtc.dataM;
dataS = state.rtc.dataS;
lastLatchData = state.rtc.lastLatchData;
baseTime_ = state.rtc.baseTime;
haltTime_ = state.rtc.haltTime;
index_ = state.rtc.index;
dataDh_ = state.rtc.dataDh;
dataDl_ = state.rtc.dataDl;
dataH_ = state.rtc.dataH;
dataM_ = state.rtc.dataM;
dataS_ = state.rtc.dataS;
lastLatchData_ = state.rtc.lastLatchData;
doSwapActive();
}
void Rtc::setDh(const unsigned new_dh)
{
const uint64_t unixtime = (dataDh & 0x40) ? haltTime : std::time(0);
const uint64_t old_highdays = ((unixtime - baseTime) / 86400) & 0x100;
baseTime += old_highdays * 86400;
baseTime -= ((new_dh & 0x1) << 8) * 86400;
const uint64_t unixtime = (dataDh_ & 0x40) ? haltTime_ : std::time(0);
const uint64_t old_highdays = ((unixtime - baseTime_) / 86400) & 0x100;
baseTime_ += old_highdays * 86400;
baseTime_ -= ((new_dh & 0x1) << 8) * 86400;
if ((dataDh ^ new_dh) & 0x40)
if ((dataDh_ ^ new_dh) & 0x40)
{
if (new_dh & 0x40)
haltTime = std::time(0);
haltTime_ = std::time(0);
else
baseTime += std::time(0) - haltTime;
baseTime_ += std::time(0) - haltTime_;
}
}
void Rtc::setDl(const unsigned new_lowdays)
{
const uint64_t unixtime = (dataDh & 0x40) ? haltTime : std::time(0);
const uint64_t old_lowdays = ((unixtime - baseTime) / 86400) & 0xFF;
baseTime += old_lowdays * 86400;
baseTime -= new_lowdays * 86400;
const uint64_t unixtime = (dataDh_ & 0x40) ? haltTime_ : std::time(0);
const uint64_t old_lowdays = ((unixtime - baseTime_) / 86400) & 0xFF;
baseTime_ += old_lowdays * 86400;
baseTime_ -= new_lowdays * 86400;
}
void Rtc::setH(const unsigned new_hours)
{
const uint64_t unixtime = (dataDh & 0x40) ? haltTime : std::time(0);
const uint64_t old_hours = ((unixtime - baseTime) / 3600) % 24;
baseTime += old_hours * 3600;
baseTime -= new_hours * 3600;
const uint64_t unixtime = (dataDh_ & 0x40) ? haltTime_ : std::time(0);
const uint64_t old_hours = ((unixtime - baseTime_) / 3600) % 24;
baseTime_ += old_hours * 3600;
baseTime_ -= new_hours * 3600;
}
void Rtc::setM(const unsigned new_minutes)
{
const uint64_t unixtime = (dataDh & 0x40) ? haltTime : std::time(0);
const uint64_t old_minutes = ((unixtime - baseTime) / 60) % 60;
baseTime += old_minutes * 60;
baseTime -= new_minutes * 60;
const uint64_t unixtime = (dataDh_ & 0x40) ? haltTime_ : std::time(0);
const uint64_t old_minutes = ((unixtime - baseTime_) / 60) % 60;
baseTime_ += old_minutes * 60;
baseTime_ -= new_minutes * 60;
}
void Rtc::setS(const unsigned new_seconds)
{
const uint64_t unixtime = (dataDh & 0x40) ? haltTime : std::time(0);
baseTime += (unixtime - baseTime) % 60;
baseTime -= new_seconds;
const uint64_t unixtime = (dataDh_ & 0x40) ? haltTime_ : std::time(0);
baseTime_ += (unixtime - baseTime_) % 60;
baseTime_ -= new_seconds;
}
}

View File

@ -34,25 +34,25 @@ namespace gambatte
const unsigned char* getActive() const
{
return activeData;
return activeData_;
}
uint64_t& getBaseTime()
{
return baseTime;
return baseTime_;
}
void setBaseTime(const uint64_t baseTime)
{
this->baseTime = baseTime;
baseTime_ = baseTime;
}
void latch(const unsigned data)
{
if (!lastLatchData && data == 1)
if (!lastLatchData_ && data == 1)
doLatch();
lastLatchData = data;
lastLatchData_ = data;
}
void saveState(SaveState &state) const;
@ -60,40 +60,40 @@ namespace gambatte
void setEnabled(const bool enabled)
{
this->enabled = enabled;
enabled_ = enabled;
doSwapActive();
}
void swapActive(unsigned index)
void swapActive(unsigned bank)
{
index &= 0xF;
index -= 8;
bank &= 0xF;
bank -= 8;
this->index = index;
index_ = bank;
doSwapActive();
}
void write(const unsigned data)
{
(this->*activeSet)(data);
*activeData = data;
(this->*activeSet_)(data);
*activeData_ = data;
}
private:
unsigned char *activeData;
void (Rtc::*activeSet)(unsigned);
uint64_t baseTime;
uint64_t haltTime;
unsigned char index;
unsigned char dataDh;
unsigned char dataDl;
unsigned char dataH;
unsigned char dataM;
unsigned char dataS;
bool enabled;
bool lastLatchData;
unsigned char *activeData_;
void (Rtc::*activeSet_)(unsigned);
uint64_t baseTime_;
uint64_t haltTime_;
unsigned char index_;
unsigned char dataDh_;
unsigned char dataDl_;
unsigned char dataH_;
unsigned char dataM_;
unsigned char dataS_;
bool enabled_;
bool lastLatchData_;
void doLatch();
void doSwapActive();