Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmeteor/include/ameteor/io.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 __IO_H__
18
#define __IO_H__
19
20
#include <stdint.h>
21
#include <istream>
22
#include <ostream>
23
24
namespace AMeteor
25
{
26
class Io
27
{
28
public :
29
enum IoAddress
30
{
31
// LCD I/O Registers
32
DISPCNT = 0x000,
33
DISPSTAT = 0x004,
34
VCOUNT = 0x006,
35
BG0CNT = 0x008,
36
BG1CNT = 0x00A,
37
BG2CNT = 0x00C,
38
BG3CNT = 0x00E,
39
BG0HOFS = 0x010,
40
BG0VOFS = 0x012,
41
BG1HOFS = 0x014,
42
BG1VOFS = 0x016,
43
BG2HOFS = 0x018,
44
BG2VOFS = 0x01A,
45
BG3HOFS = 0x01C,
46
BG3VOFS = 0x01E,
47
BG2PA = 0x020,
48
BG2PB = 0x022,
49
BG2PC = 0x024,
50
BG2PD = 0x026,
51
BG2X_L = 0x028,
52
BG2X_H = 0x02A,
53
BG2Y_L = 0x02C,
54
BG2Y_H = 0x02E,
55
BG3PA = 0x030,
56
BG3PB = 0x032,
57
BG3PC = 0x034,
58
BG3PD = 0x036,
59
BG3X_L = 0x038,
60
BG3X_H = 0x03A,
61
BG3Y_L = 0x03C,
62
BG3Y_H = 0x03E,
63
WIN0H = 0x040,
64
WIN1H = 0x042,
65
WIN0V = 0x044,
66
WIN1V = 0x046,
67
WININ = 0x048,
68
WINOUT = 0x04A,
69
MOSAIC = 0x04C,
70
BLDCNT = 0x050,
71
BLDALPHA = 0x052,
72
BLDY = 0x054,
73
// Sound Registers
74
SOUND1CNT_L = 0x060, NR10 = 0x060,
75
SOUND1CNT_H = 0x062, NR11 = 0x062,
76
NR12 = 0x063,
77
SOUND1CNT_X = 0x064, NR13 = 0x064,
78
NR14 = 0x065,
79
SOUND2CNT_L = 0x068, NR21 = 0x068,
80
NR22 = 0x069,
81
SOUND2CNT_H = 0x06C, NR23 = 0x06C,
82
NR24 = 0x06D,
83
SOUND4CNT_L = 0x078, NR41 = 0x078,
84
NR42 = 0x079,
85
SOUND4CNT_H = 0x07C, NR43 = 0x07C,
86
NR44 = 0x07D,
87
SOUNDCNT_L = 0x080, NR50 = 0x080,
88
NR51 = 0x081,
89
SOUNDCNT_H = 0x082,
90
SOUNDCNT_X = 0x084, NR52 = 0x084,
91
SOUNDBIAS = 0x088,
92
FIFO_A = 0x0A0,
93
FIFO_B = 0x0A4,
94
// DMA Transfer Channels
95
DMA0SAD = 0x0B0,
96
DMA0DAD = 0x0B4,
97
DMA0CNT_L = 0x0B8,
98
DMA0CNT_H = 0x0BA,
99
DMA1SAD = 0x0BC,
100
DMA1DAD = 0x0C0,
101
DMA1CNT_L = 0x0C4,
102
DMA1CNT_H = 0x0C6,
103
DMA2SAD = 0x0C8,
104
DMA2DAD = 0x0CC,
105
DMA2CNT_L = 0x0D0,
106
DMA2CNT_H = 0x0D2,
107
DMA3SAD = 0x0D4,
108
DMA3DAD = 0x0D8,
109
DMA3CNT_L = 0x0DC,
110
DMA3CNT_H = 0x0DE,
111
// Timer Registers
112
TM0CNT_L = 0x100,
113
TM0CNT_H = 0x102,
114
TM1CNT_L = 0x104,
115
TM1CNT_H = 0x106,
116
TM2CNT_L = 0x108,
117
TM2CNT_H = 0x10A,
118
TM3CNT_L = 0x10C,
119
TM3CNT_H = 0x10E,
120
// Keypad Input
121
KEYINPUT = 0x130,
122
KEYCNT = 0x132,
123
// Serial Communication (2)
124
RCNT = 0x134,
125
// Interrupt, WaitState, and Power-Down Control
126
IE = 0x200,
127
IF = 0x202,
128
WAITCNT = 0x204,
129
IME = 0x208,
130
POSTFLG = 0x300,
131
HALTCNT = 0x301,
132
133
DMA_CHANSIZE = 0x00C,
134
TIMER_SIZE = 0x004,
135
// TODO make tests and everything in Write*() functions so that we can
136
// make IO_SIZE 0x804 (don't forget mirrors)
137
IO_SIZE = 0x1000
138
};
139
140
Io ();
141
~Io ();
142
143
void Reset ();
144
void ClearSio ();
145
void ClearSound ();
146
void ClearOthers ();
147
148
uint8_t Read8 (uint32_t add);
149
uint16_t Read16 (uint32_t add);
150
uint32_t Read32 (uint32_t add);
151
152
void Write8 (uint32_t add, uint8_t val);
153
void Write16 (uint32_t add, uint16_t val);
154
void Write32 (uint32_t add, uint32_t val);
155
156
// Direct read and write
157
// Using theses functions will write directly on IO memory without
158
// doing anything else (they won't call Dma::Check for example)
159
// add must be the real address & 0xFFF
160
// No check is done on the memory, these functions may segfault if
161
// you give them wrong values !
162
163
uint8_t DRead8 (uint16_t add)
164
{
165
return m_iomem[add];
166
}
167
168
uint16_t DRead16 (uint16_t add)
169
{
170
return *(uint16_t*)(m_iomem+add);
171
}
172
173
uint32_t DRead32 (uint16_t add)
174
{
175
return *(uint32_t*)(m_iomem+add);
176
}
177
178
void DWrite8 (uint16_t add, uint8_t val)
179
{
180
m_iomem[add] = val;
181
}
182
183
void DWrite16 (uint16_t add, uint16_t val)
184
{
185
*(uint16_t*)(m_iomem+add) = val;
186
}
187
188
void DWrite32 (uint16_t add, uint32_t val)
189
{
190
*(uint32_t*)(m_iomem+add) = val;
191
}
192
193
uint8_t& GetRef8 (uint16_t add)
194
{
195
return m_iomem[add];
196
}
197
198
uint16_t& GetRef16 (uint16_t add)
199
{
200
return *(uint16_t*)(m_iomem+add);
201
}
202
203
uint32_t& GetRef32 (uint16_t add)
204
{
205
return *(uint32_t*)(m_iomem+add);
206
}
207
208
bool SaveState (std::ostream& stream);
209
bool LoadState (std::istream& stream);
210
211
// this should be considered very dangerous to use
212
uint8_t* GetIoPointer() {return m_iomem;}
213
214
private :
215
uint8_t* m_iomem;
216
};
217
}
218
219
#endif
220
221