Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmeteor/include/ameteor/clock.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 __CLOCK_H__
18
#define __CLOCK_H__
19
20
#include <stdint.h>
21
#include <climits>
22
#include <vector>
23
#include <istream>
24
#include <ostream>
25
26
namespace AMeteor
27
{
28
class Clock
29
{
30
public :
31
Clock ()
32
{
33
Reset();
34
}
35
36
void Reset ();
37
38
void ResetCounter()
39
{
40
m_count = 0;
41
}
42
unsigned int GetCounter() const
43
{
44
return m_count;
45
}
46
47
void TimePass (unsigned short cycles)
48
{
49
m_cycles += cycles;
50
}
51
void Commit ();
52
void WaitForNext ();
53
54
void AddLcd (uint32_t cycles)
55
{
56
// The lcd clock is always enabled
57
m_lcd += cycles;
58
SetFirst();
59
}
60
61
void AddTimer (uint8_t num, uint32_t cycles)
62
{
63
if (m_timer[num] == INT_MAX)
64
m_timer[num] = cycles;
65
else
66
m_timer[num] += cycles;
67
SetFirst();
68
}
69
void SetTimer (uint8_t num, uint32_t cycles)
70
{
71
m_timer[num] = cycles;
72
SetFirst();
73
}
74
void DisableTimer (uint8_t num)
75
{
76
m_timer[num] = INT_MAX;
77
SetFirst();
78
}
79
int GetTimer (uint8_t num)
80
{
81
return m_timer[num];
82
}
83
84
//void SetBattery (uint32_t cycles)
85
//{
86
// m_battery = cycles;
87
//}
88
//void DisableBattery ()
89
//{
90
// m_battery = INT_MAX;
91
// no need to SetFirst since battery will be disabled only in TimeEvent
92
//}
93
94
bool SaveState (std::ostream& stream);
95
bool LoadState (std::istream& stream);
96
97
private :
98
// XXX freq
99
static const int SOUND_PERIOD = 380;
100
101
unsigned short m_cycles;
102
unsigned short m_first;
103
int m_lcd, m_timer[4], m_sound;//, m_battery;
104
105
unsigned int m_count;
106
107
void SetFirst ();
108
};
109
}
110
111
#endif
112
113