Path: blob/master/libsnes/lsnes_patches/0001-Don-t-use-time-in-emulating-chips.patch
2 views
From 22205d4d339cfa11f6d53e644eae1c859a56d349 Mon Sep 17 00:00:00 20011From: Ilari Liusvaara <[email protected]>2Date: Wed, 9 Nov 2011 00:37:44 +02003Subject: [PATCH 1/4] Don't use time() in emulating chips45Instead of using time() in chip emulation, create new interface method6currentTime(), defaulting to time(0). This way frontend can cleanly7override the current time bsnes is using.8---9snes/chip/bsx/satellaview/satellaview.cpp | 2 +-10snes/chip/spc7110/spc7110.cpp | 2 +-11snes/chip/srtc/srtc.cpp | 2 +-12snes/interface/interface.cpp | 5 +++++13snes/interface/interface.hpp | 1 +145 files changed, 9 insertions(+), 3 deletions(-)1516diff --git a/snes/chip/bsx/satellaview/satellaview.cpp b/snes/chip/bsx/satellaview/satellaview.cpp17index 386fb62..3c98019 10075518--- snes/chip/bsx/satellaview/satellaview.cpp19+++ snes/chip/bsx/satellaview/satellaview.cpp20@@ -38,7 +38,7 @@ uint8 BSXSatellaview::mmio_read(unsigned addr) {2122if(counter == 0) {23time_t rawtime;24- time(&rawtime);25+ rawtime = SNES::interface->currentTime();26tm *t = localtime(&rawtime);2728regs.r2192_hour = t->tm_hour;29diff --git a/snes/chip/spc7110/spc7110.cpp b/snes/chip/spc7110/spc7110.cpp30index 27b8b77..061aa5e 10075531--- snes/chip/spc7110/spc7110.cpp32+++ snes/chip/spc7110/spc7110.cpp33@@ -101,7 +101,7 @@ void SPC7110::set_data_adjust(unsigned addr) { r4814 = addr; r4815 = addr >> 8;3435void SPC7110::update_time(int offset) {36time_t rtc_time = (rtc[16] << 0) | (rtc[17] << 8) | (rtc[18] << 16) | (rtc[19] << 24);37- time_t current_time = time(0) - offset;38+ time_t current_time = SNES::interface->currentTime() - offset;3940//sizeof(time_t) is platform-dependent; though rtc[] needs to be platform-agnostic.41//yet platforms with 32-bit signed time_t will overflow every ~68 years. handle this by42diff --git a/snes/chip/srtc/srtc.cpp b/snes/chip/srtc/srtc.cpp43index 0044113..725e891 10075544--- snes/chip/srtc/srtc.cpp45+++ snes/chip/srtc/srtc.cpp46@@ -31,7 +31,7 @@ void SRTC::reset() {4748void SRTC::update_time() {49time_t rtc_time = (rtc[16] << 0) | (rtc[17] << 8) | (rtc[18] << 16) | (rtc[19] << 24);50- time_t current_time = time(0);51+ time_t current_time = SNES::interface->currentTime();5253//sizeof(time_t) is platform-dependent; though rtc[] needs to be platform-agnostic.54//yet platforms with 32-bit signed time_t will overflow every ~68 years. handle this by55diff --git a/snes/interface/interface.cpp b/snes/interface/interface.cpp56index a0e3a81..b3017c9 10075557--- snes/interface/interface.cpp58+++ snes/interface/interface.cpp59@@ -18,4 +18,9 @@ void Interface::message(const string &text) {60print(text, "\n");61}6263+time_t Interface::currentTime()64+{65+ return time(0);66+}67+68}69diff --git a/snes/interface/interface.hpp b/snes/interface/interface.hpp70index f1a48c0..df975e8 10075571--- snes/interface/interface.hpp72+++ snes/interface/interface.hpp73@@ -5,6 +5,7 @@ struct Interface {7475virtual string path(Cartridge::Slot slot, const string &hint) = 0;76virtual void message(const string &text);77+ virtual time_t currentTime();78};7980extern Interface *interface;81--821.7.9.48.g85da4d83848586