src/gba/io.h (view raw)
1/* Copyright (c) 2013-2015 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef GBA_IO_H
7#define GBA_IO_H
8
9#include "util/common.h"
10
11#include "gba/gba.h"
12
13enum GBAIORegisters {
14 // Video
15 REG_DISPCNT = 0x000,
16 REG_GREENSWP = 0x002,
17 REG_DISPSTAT = 0x004,
18 REG_VCOUNT = 0x006,
19 REG_BG0CNT = 0x008,
20 REG_BG1CNT = 0x00A,
21 REG_BG2CNT = 0x00C,
22 REG_BG3CNT = 0x00E,
23 REG_BG0HOFS = 0x010,
24 REG_BG0VOFS = 0x012,
25 REG_BG1HOFS = 0x014,
26 REG_BG1VOFS = 0x016,
27 REG_BG2HOFS = 0x018,
28 REG_BG2VOFS = 0x01A,
29 REG_BG3HOFS = 0x01C,
30 REG_BG3VOFS = 0x01E,
31 REG_BG2PA = 0x020,
32 REG_BG2PB = 0x022,
33 REG_BG2PC = 0x024,
34 REG_BG2PD = 0x026,
35 REG_BG2X_LO = 0x028,
36 REG_BG2X_HI = 0x02A,
37 REG_BG2Y_LO = 0x02C,
38 REG_BG2Y_HI = 0x02E,
39 REG_BG3PA = 0x030,
40 REG_BG3PB = 0x032,
41 REG_BG3PC = 0x034,
42 REG_BG3PD = 0x036,
43 REG_BG3X_LO = 0x038,
44 REG_BG3X_HI = 0x03A,
45 REG_BG3Y_LO = 0x03C,
46 REG_BG3Y_HI = 0x03E,
47 REG_WIN0H = 0x040,
48 REG_WIN1H = 0x042,
49 REG_WIN0V = 0x044,
50 REG_WIN1V = 0x046,
51 REG_WININ = 0x048,
52 REG_WINOUT = 0x04A,
53 REG_MOSAIC = 0x04C,
54 REG_BLDCNT = 0x050,
55 REG_BLDALPHA = 0x052,
56 REG_BLDY = 0x054,
57
58 // Sound
59 REG_SOUND1CNT_LO = 0x060,
60 REG_SOUND1CNT_HI = 0x062,
61 REG_SOUND1CNT_X = 0x064,
62 REG_SOUND2CNT_LO = 0x068,
63 REG_SOUND2CNT_HI = 0x06C,
64 REG_SOUND3CNT_LO = 0x070,
65 REG_SOUND3CNT_HI = 0x072,
66 REG_SOUND3CNT_X = 0x074,
67 REG_SOUND4CNT_LO = 0x078,
68 REG_SOUND4CNT_HI = 0x07C,
69 REG_SOUNDCNT_LO = 0x080,
70 REG_SOUNDCNT_HI = 0x082,
71 REG_SOUNDCNT_X = 0x084,
72 REG_SOUNDBIAS = 0x088,
73 REG_WAVE_RAM0_LO = 0x090,
74 REG_WAVE_RAM0_HI = 0x092,
75 REG_WAVE_RAM1_LO = 0x094,
76 REG_WAVE_RAM1_HI = 0x096,
77 REG_WAVE_RAM2_LO = 0x098,
78 REG_WAVE_RAM2_HI = 0x09A,
79 REG_WAVE_RAM3_LO = 0x09C,
80 REG_WAVE_RAM3_HI = 0x09E,
81 REG_FIFO_A_LO = 0x0A0,
82 REG_FIFO_A_HI = 0x0A2,
83 REG_FIFO_B_LO = 0x0A4,
84 REG_FIFO_B_HI = 0x0A6,
85
86 // DMA
87 REG_DMA0SAD_LO = 0x0B0,
88 REG_DMA0SAD_HI = 0x0B2,
89 REG_DMA0DAD_LO = 0x0B4,
90 REG_DMA0DAD_HI = 0x0B6,
91 REG_DMA0CNT_LO = 0x0B8,
92 REG_DMA0CNT_HI = 0x0BA,
93 REG_DMA1SAD_LO = 0x0BC,
94 REG_DMA1SAD_HI = 0x0BE,
95 REG_DMA1DAD_LO = 0x0C0,
96 REG_DMA1DAD_HI = 0x0C2,
97 REG_DMA1CNT_LO = 0x0C4,
98 REG_DMA1CNT_HI = 0x0C6,
99 REG_DMA2SAD_LO = 0x0C8,
100 REG_DMA2SAD_HI = 0x0CA,
101 REG_DMA2DAD_LO = 0x0CC,
102 REG_DMA2DAD_HI = 0x0CE,
103 REG_DMA2CNT_LO = 0x0D0,
104 REG_DMA2CNT_HI = 0x0D2,
105 REG_DMA3SAD_LO = 0x0D4,
106 REG_DMA3SAD_HI = 0x0D6,
107 REG_DMA3DAD_LO = 0x0D8,
108 REG_DMA3DAD_HI = 0x0DA,
109 REG_DMA3CNT_LO = 0x0DC,
110 REG_DMA3CNT_HI = 0x0DE,
111
112 // Timers
113 REG_TM0CNT_LO = 0x100,
114 REG_TM0CNT_HI = 0x102,
115 REG_TM1CNT_LO = 0x104,
116 REG_TM1CNT_HI = 0x106,
117 REG_TM2CNT_LO = 0x108,
118 REG_TM2CNT_HI = 0x10A,
119 REG_TM3CNT_LO = 0x10C,
120 REG_TM3CNT_HI = 0x10E,
121
122 // SIO (note: some of these are repeated)
123 REG_SIODATA32_LO = 0x120,
124 REG_SIOMULTI0 = 0x120,
125 REG_SIODATA32_HI = 0x122,
126 REG_SIOMULTI1 = 0x122,
127 REG_SIOMULTI2 = 0x124,
128 REG_SIOMULTI3 = 0x126,
129 REG_SIOCNT = 0x128,
130 REG_SIOMLT_SEND = 0x12A,
131 REG_SIODATA8 = 0x12A,
132 REG_RCNT = 0x134,
133 REG_JOYCNT = 0x140,
134 REG_JOY_RECV = 0x150,
135 REG_JOY_TRANS = 0x154,
136 REG_JOYSTAT = 0x158,
137
138 // Keypad
139 REG_KEYINPUT = 0x130,
140 REG_KEYCNT = 0x132,
141
142 // Interrupts, etc
143 REG_IE = 0x200,
144 REG_IF = 0x202,
145 REG_WAITCNT = 0x204,
146 REG_IME = 0x208,
147
148 REG_MAX = 0x20A,
149
150 REG_POSTFLG = 0x300,
151 REG_HALTCNT = 0x301
152};
153
154extern const char* GBAIORegisterNames[];
155
156void GBAIOInit(struct GBA* gba);
157void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t value);
158void GBAIOWrite8(struct GBA* gba, uint32_t address, uint8_t value);
159void GBAIOWrite32(struct GBA* gba, uint32_t address, uint32_t value);
160uint16_t GBAIORead(struct GBA* gba, uint32_t address);
161
162struct GBASerializedState;
163void GBAIOSerialize(struct GBA* gba, struct GBASerializedState* state);
164void GBAIODeserialize(struct GBA* gba, const struct GBASerializedState* state);
165
166#endif