From 6c3da8eb6516d25e97b46d97fb0d3d24ca9ecfd0 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Wed, 9 Nov 2011 00:37:44 +0200 Subject: [PATCH 1/8] 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. --- snes/chip/bsx/satellaview/satellaview.cpp | 2 +- snes/chip/spc7110/spc7110.cpp | 2 +- snes/chip/srtc/srtc.cpp | 2 +- snes/interface/interface.cpp | 5 +++++ snes/interface/interface.hpp | 1 + 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/snes/chip/bsx/satellaview/satellaview.cpp b/snes/chip/bsx/satellaview/satellaview.cpp index 386fb62..3c98019 100755 --- a/snes/chip/bsx/satellaview/satellaview.cpp +++ b/snes/chip/bsx/satellaview/satellaview.cpp @@ -38,7 +38,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; diff --git a/snes/chip/spc7110/spc7110.cpp b/snes/chip/spc7110/spc7110.cpp index d2dc640..74a817a 100755 --- a/snes/chip/spc7110/spc7110.cpp +++ b/snes/chip/spc7110/spc7110.cpp @@ -101,7 +101,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 diff --git a/snes/chip/srtc/srtc.cpp b/snes/chip/srtc/srtc.cpp index 1b2fd2a..78fc4c1 100755 --- a/snes/chip/srtc/srtc.cpp +++ b/snes/chip/srtc/srtc.cpp @@ -31,7 +31,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 diff --git a/snes/interface/interface.cpp b/snes/interface/interface.cpp index a0e3a81..b3017c9 100755 --- a/snes/interface/interface.cpp +++ b/snes/interface/interface.cpp @@ -18,4 +18,9 @@ void Interface::message(const string &text) { print(text, "\n"); } +time_t Interface::currentTime() +{ + return time(0); +} + } diff --git a/snes/interface/interface.hpp b/snes/interface/interface.hpp index f1a48c0..df975e8 100755 --- a/snes/interface/interface.hpp +++ b/snes/interface/interface.hpp @@ -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; -- 1.8.4.4