Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libgambatte/src/tima.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 TIMA_H
20
#define TIMA_H
21
22
#include "interruptrequester.h"
23
24
namespace gambatte {
25
26
class TimaInterruptRequester {
27
InterruptRequester &intreq;
28
29
public:
30
explicit TimaInterruptRequester(InterruptRequester &intreq) : intreq(intreq) {}
31
void flagIrq() const { intreq.flagIrq(4); }
32
unsigned long nextIrqEventTime() const { return intreq.eventTime(TIMA); }
33
void setNextIrqEventTime(const unsigned long time) const { intreq.setEventTime<TIMA>(time); }
34
};
35
36
class Tima {
37
unsigned long lastUpdate_;
38
unsigned long tmatime_;
39
40
unsigned char tima_;
41
unsigned char tma_;
42
unsigned char tac_;
43
44
void updateIrq(const unsigned long cc, const TimaInterruptRequester timaIrq) {
45
while (cc >= timaIrq.nextIrqEventTime())
46
doIrqEvent(timaIrq);
47
}
48
49
void updateTima(unsigned long cc);
50
51
public:
52
Tima();
53
void loadState(const SaveState &, TimaInterruptRequester timaIrq);
54
void resetCc(unsigned long oldCc, unsigned long newCc, TimaInterruptRequester timaIrq);
55
56
void setTima(unsigned tima, unsigned long cc, TimaInterruptRequester timaIrq);
57
void setTma(unsigned tma, unsigned long cc, TimaInterruptRequester timaIrq);
58
void setTac(unsigned tac, unsigned long cc, TimaInterruptRequester timaIrq);
59
unsigned tima(unsigned long cc);
60
61
void doIrqEvent(TimaInterruptRequester timaIrq);
62
63
template<bool isReader>void SyncState(NewState *ns);
64
};
65
66
}
67
68
#endif
69
70