Don't use time() in emulating chips

Instead of using time() in chip emulation, create new interface method
currentTime(), defaulting to time(0). This way frontend can cleanly
override the current time bsnes is using.
This commit is contained in:
Ilari Liusvaara 2011-11-09 00:37:44 +02:00
parent df7851648e
commit b481e3d161
5 changed files with 9 additions and 3 deletions

View file

@ -39,7 +39,7 @@ uint8 BSXSatellaview::mmio_read(unsigned addr) {
if(counter == 0) {
time_t rawtime;
time(&rawtime);
rawtime = SNES::interface->currentTime();
tm *t = localtime(&rawtime);
regs.r2192_hour = t->tm_hour;

View file

@ -102,7 +102,7 @@ void SPC7110::set_data_adjust(unsigned addr) { r4814 = addr; r4815 = addr >> 8;
void SPC7110::update_time(int offset) {
time_t rtc_time = (rtc[16] << 0) | (rtc[17] << 8) | (rtc[18] << 16) | (rtc[19] << 24);
time_t current_time = time(0) - offset;
time_t current_time = SNES::interface->currentTime() - offset;
//sizeof(time_t) is platform-dependent; though rtc[] needs to be platform-agnostic.
//yet platforms with 32-bit signed time_t will overflow every ~68 years. handle this by

View file

@ -32,7 +32,7 @@ void SRTC::reset() {
void SRTC::update_time() {
time_t rtc_time = (rtc[16] << 0) | (rtc[17] << 8) | (rtc[18] << 16) | (rtc[19] << 24);
time_t current_time = time(0);
time_t current_time = SNES::interface->currentTime();
//sizeof(time_t) is platform-dependent; though rtc[] needs to be platform-agnostic.
//yet platforms with 32-bit signed time_t will overflow every ~68 years. handle this by

View file

@ -18,4 +18,9 @@ void Interface::message(const string &text) {
print(text, "\n");
}
time_t Interface::currentTime()
{
return time(0);
}
}

View file

@ -5,6 +5,7 @@ struct Interface {
virtual string path(Cartridge::Slot slot, const string &hint) = 0;
virtual void message(const string &text);
virtual time_t currentTime();
};
extern Interface *interface;