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