lsnes/bsnes-patches/v084/0003-Don-t-use-time-in-emulating-chips.patch
2013-11-30 10:39:32 +02:00

84 lines
3.2 KiB
Diff

From b481e3d161d924cc5a4449329393c8d9f23b27ec Mon Sep 17 00:00:00 2001
From: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Date: Wed, 9 Nov 2011 00:37:44 +0200
Subject: [PATCH 03/10] 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 7bfd13f..b2565ea 100755
--- a/snes/chip/bsx/satellaview/satellaview.cpp
+++ b/snes/chip/bsx/satellaview/satellaview.cpp
@@ -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;
diff --git a/snes/chip/spc7110/spc7110.cpp b/snes/chip/spc7110/spc7110.cpp
index 835ddbb..f5463e5 100755
--- a/snes/chip/spc7110/spc7110.cpp
+++ b/snes/chip/spc7110/spc7110.cpp
@@ -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
diff --git a/snes/chip/srtc/srtc.cpp b/snes/chip/srtc/srtc.cpp
index 1dd8f86..b11b756 100755
--- a/snes/chip/srtc/srtc.cpp
+++ b/snes/chip/srtc/srtc.cpp
@@ -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
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