Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libgambatte/src/mem/rtc.h
2 views
1
/***************************************************************************
2
* Copyright (C) 2007 by Sindre Aamås *
3
* [email protected] *
4
* *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License version 2 as *
7
* published by the Free Software Foundation. *
8
* *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License version 2 for more details. *
13
* *
14
* You should have received a copy of the GNU General Public License *
15
* version 2 along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18
***************************************************************************/
19
#ifndef RTC_H
20
#define RTC_H
21
22
#include <cstdint>
23
#include "newstate.h"
24
25
namespace gambatte {
26
27
struct SaveState;
28
29
class Rtc {
30
private:
31
unsigned char *activeData;
32
void (Rtc::*activeSet)(unsigned);
33
std::uint32_t baseTime;
34
std::uint32_t haltTime;
35
unsigned char index;
36
unsigned char dataDh;
37
unsigned char dataDl;
38
unsigned char dataH;
39
unsigned char dataM;
40
unsigned char dataS;
41
bool enabled;
42
bool lastLatchData;
43
std::uint32_t (*timeCB)();
44
45
void doLatch();
46
void doSwapActive();
47
void setDh(unsigned new_dh);
48
void setDl(unsigned new_lowdays);
49
void setH(unsigned new_hours);
50
void setM(unsigned new_minutes);
51
void setS(unsigned new_seconds);
52
53
public:
54
Rtc();
55
56
const unsigned char* getActive() const { return activeData; }
57
std::uint32_t getBaseTime() const { return baseTime; }
58
59
void setBaseTime(const std::uint32_t baseTime) {
60
this->baseTime = baseTime;
61
// doLatch();
62
}
63
64
void latch(const unsigned data) {
65
if (!lastLatchData && data == 1)
66
doLatch();
67
68
lastLatchData = data;
69
}
70
71
void loadState(const SaveState &state);
72
73
void set(const bool enabled, unsigned bank) {
74
bank &= 0xF;
75
bank -= 8;
76
77
this->enabled = enabled;
78
this->index = bank;
79
80
doSwapActive();
81
}
82
83
void write(const unsigned data) {
84
// if (activeSet)
85
(this->*activeSet)(data);
86
*activeData = data;
87
}
88
89
void setRTCCallback(std::uint32_t (*callback)()) {
90
timeCB = callback;
91
}
92
93
template<bool isReader>void SyncState(NewState *ns);
94
};
95
96
}
97
98
#endif
99
100