Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/lsnes_patches/0001-Don-t-use-time-in-emulating-chips.patch
2 views
1
From 22205d4d339cfa11f6d53e644eae1c859a56d349 Mon Sep 17 00:00:00 2001
2
From: Ilari Liusvaara <[email protected]>
3
Date: Wed, 9 Nov 2011 00:37:44 +0200
4
Subject: [PATCH 1/4] Don't use time() in emulating chips
5
6
Instead of using time() in chip emulation, create new interface method
7
currentTime(), defaulting to time(0). This way frontend can cleanly
8
override the current time bsnes is using.
9
---
10
snes/chip/bsx/satellaview/satellaview.cpp | 2 +-
11
snes/chip/spc7110/spc7110.cpp | 2 +-
12
snes/chip/srtc/srtc.cpp | 2 +-
13
snes/interface/interface.cpp | 5 +++++
14
snes/interface/interface.hpp | 1 +
15
5 files changed, 9 insertions(+), 3 deletions(-)
16
17
diff --git a/snes/chip/bsx/satellaview/satellaview.cpp b/snes/chip/bsx/satellaview/satellaview.cpp
18
index 386fb62..3c98019 100755
19
--- snes/chip/bsx/satellaview/satellaview.cpp
20
+++ snes/chip/bsx/satellaview/satellaview.cpp
21
@@ -38,7 +38,7 @@ uint8 BSXSatellaview::mmio_read(unsigned addr) {
22
23
if(counter == 0) {
24
time_t rawtime;
25
- time(&rawtime);
26
+ rawtime = SNES::interface->currentTime();
27
tm *t = localtime(&rawtime);
28
29
regs.r2192_hour = t->tm_hour;
30
diff --git a/snes/chip/spc7110/spc7110.cpp b/snes/chip/spc7110/spc7110.cpp
31
index 27b8b77..061aa5e 100755
32
--- snes/chip/spc7110/spc7110.cpp
33
+++ snes/chip/spc7110/spc7110.cpp
34
@@ -101,7 +101,7 @@ void SPC7110::set_data_adjust(unsigned addr) { r4814 = addr; r4815 = addr >> 8;
35
36
void SPC7110::update_time(int offset) {
37
time_t rtc_time = (rtc[16] << 0) | (rtc[17] << 8) | (rtc[18] << 16) | (rtc[19] << 24);
38
- time_t current_time = time(0) - offset;
39
+ time_t current_time = SNES::interface->currentTime() - offset;
40
41
//sizeof(time_t) is platform-dependent; though rtc[] needs to be platform-agnostic.
42
//yet platforms with 32-bit signed time_t will overflow every ~68 years. handle this by
43
diff --git a/snes/chip/srtc/srtc.cpp b/snes/chip/srtc/srtc.cpp
44
index 0044113..725e891 100755
45
--- snes/chip/srtc/srtc.cpp
46
+++ snes/chip/srtc/srtc.cpp
47
@@ -31,7 +31,7 @@ void SRTC::reset() {
48
49
void SRTC::update_time() {
50
time_t rtc_time = (rtc[16] << 0) | (rtc[17] << 8) | (rtc[18] << 16) | (rtc[19] << 24);
51
- time_t current_time = time(0);
52
+ time_t current_time = SNES::interface->currentTime();
53
54
//sizeof(time_t) is platform-dependent; though rtc[] needs to be platform-agnostic.
55
//yet platforms with 32-bit signed time_t will overflow every ~68 years. handle this by
56
diff --git a/snes/interface/interface.cpp b/snes/interface/interface.cpp
57
index a0e3a81..b3017c9 100755
58
--- snes/interface/interface.cpp
59
+++ snes/interface/interface.cpp
60
@@ -18,4 +18,9 @@ void Interface::message(const string &text) {
61
print(text, "\n");
62
}
63
64
+time_t Interface::currentTime()
65
+{
66
+ return time(0);
67
+}
68
+
69
}
70
diff --git a/snes/interface/interface.hpp b/snes/interface/interface.hpp
71
index f1a48c0..df975e8 100755
72
--- snes/interface/interface.hpp
73
+++ snes/interface/interface.hpp
74
@@ -5,6 +5,7 @@ struct Interface {
75
76
virtual string path(Cartridge::Slot slot, const string &hint) = 0;
77
virtual void message(const string &text);
78
+ virtual time_t currentTime();
79
};
80
81
extern Interface *interface;
82
--
83
1.7.9.48.g85da4d
84
85
86