include/mgba/internal/gb/io.h (view raw)
1/* Copyright (c) 2013-2016 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 GB_IO_H
7#define GB_IO_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba/core/log.h>
14
15mLOG_DECLARE_CATEGORY(GB_IO);
16
17enum GBIORegisters {
18 REG_JOYP = 0x00,
19 REG_SB = 0x01,
20 REG_SC = 0x02,
21
22 // Timing
23 REG_DIV = 0x04,
24 REG_TIMA = 0x05,
25 REG_TMA = 0x06,
26 REG_TAC = 0x07,
27
28 // Interrupts
29 REG_IF = 0x0F,
30 REG_IE = 0xFF,
31
32 // Audio
33 REG_NR10 = 0x10,
34 REG_NR11 = 0x11,
35 REG_NR12 = 0x12,
36 REG_NR13 = 0x13,
37 REG_NR14 = 0x14,
38 REG_NR21 = 0x16,
39 REG_NR22 = 0x17,
40 REG_NR23 = 0x18,
41 REG_NR24 = 0x19,
42 REG_NR30 = 0x1A,
43 REG_NR31 = 0x1B,
44 REG_NR32 = 0x1C,
45 REG_NR33 = 0x1D,
46 REG_NR34 = 0x1E,
47 REG_NR41 = 0x20,
48 REG_NR42 = 0x21,
49 REG_NR43 = 0x22,
50 REG_NR44 = 0x23,
51 REG_NR50 = 0x24,
52 REG_NR51 = 0x25,
53 REG_NR52 = 0x26,
54
55 REG_WAVE_0 = 0x30,
56 REG_WAVE_1 = 0x31,
57 REG_WAVE_2 = 0x32,
58 REG_WAVE_3 = 0x33,
59 REG_WAVE_4 = 0x34,
60 REG_WAVE_5 = 0x35,
61 REG_WAVE_6 = 0x36,
62 REG_WAVE_7 = 0x37,
63 REG_WAVE_8 = 0x38,
64 REG_WAVE_9 = 0x39,
65 REG_WAVE_A = 0x3A,
66 REG_WAVE_B = 0x3B,
67 REG_WAVE_C = 0x3C,
68 REG_WAVE_D = 0x3D,
69 REG_WAVE_E = 0x3E,
70 REG_WAVE_F = 0x3F,
71
72 // Video
73 REG_LCDC = 0x40,
74 REG_STAT = 0x41,
75 REG_SCY = 0x42,
76 REG_SCX = 0x43,
77 REG_LY = 0x44,
78 REG_LYC = 0x45,
79 REG_DMA = 0x46,
80 REG_BGP = 0x47,
81 REG_OBP0 = 0x48,
82 REG_OBP1 = 0x49,
83 REG_WY = 0x4A,
84 REG_WX = 0x4B,
85
86 // CGB
87 REG_KEY0 = 0x4C,
88 REG_KEY1 = 0x4D,
89 REG_VBK = 0x4F,
90 REG_HDMA1 = 0x51,
91 REG_HDMA2 = 0x52,
92 REG_HDMA3 = 0x53,
93 REG_HDMA4 = 0x54,
94 REG_HDMA5 = 0x55,
95 REG_RP = 0x56,
96 REG_BCPS = 0x68,
97 REG_BCPD = 0x69,
98 REG_OCPS = 0x6A,
99 REG_OCPD = 0x6B,
100 REG_OPRI = 0x6C,
101 REG_SVBK = 0x70,
102 REG_UNK72 = 0x72,
103 REG_UNK73 = 0x73,
104 REG_UNK74 = 0x74,
105 REG_UNK75 = 0x75,
106 REG_PCM12 = 0x76,
107 REG_PCM34 = 0x77,
108 REG_MAX = 0x100
109};
110
111extern MGBA_EXPORT const char* const GBIORegisterNames[];
112
113struct GB;
114void GBIOInit(struct GB* gb);
115void GBIOReset(struct GB* gb);
116
117void GBIOWrite(struct GB* gb, unsigned address, uint8_t value);
118uint8_t GBIORead(struct GB* gb, unsigned address);
119
120struct GBSerializedState;
121void GBIOSerialize(const struct GB* gb, struct GBSerializedState* state);
122void GBIODeserialize(struct GB* gb, const struct GBSerializedState* state);
123
124CXX_GUARD_END
125
126#endif