Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmeteor/include/ameteor/timer.hpp
2 views
1
// Meteor - A Nintendo Gameboy Advance emulator
2
// Copyright (C) 2009-2011 Philippe Daouadi
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
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 for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
#ifndef __TIMER_H__
18
#define __TIMER_H__
19
20
#include "clock.hpp"
21
22
#include <stdint.h>
23
#include <istream>
24
#include <ostream>
25
26
namespace AMeteor
27
{
28
class Timer
29
{
30
public :
31
Timer (int8_t num, Timer* next) :
32
m_num(num),
33
m_reload(0),
34
m_count(0),
35
m_control(0),
36
m_next(next)
37
{
38
}
39
40
void Reset ();
41
42
void SetReload (uint16_t rel)
43
{
44
m_reload = rel;
45
}
46
void Reload ();
47
48
uint16_t GetCount () const;
49
50
bool SaveState (std::ostream& stream);
51
bool LoadState (std::istream& stream);
52
53
private :
54
union Control
55
{
56
Control(uint16_t v) :
57
w(v)
58
{ }
59
60
uint16_t w;
61
struct
62
{
63
unsigned int prescaler : 2;
64
unsigned int countup : 1;
65
unsigned int unused1 : 3;
66
unsigned int irq : 1;
67
unsigned int start : 1;
68
unsigned int unused2 : 8;
69
} b;
70
};
71
72
const int8_t m_num;
73
uint16_t m_reload;
74
uint32_t m_count;
75
Control m_control;
76
77
Timer* m_next;
78
79
void TimeEvent ();
80
void Countup ();
81
82
friend void Clock::Commit();
83
};
84
}
85
86
#endif
87
88