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