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 11 CXX_GUARD_START 12 13 #include <mgba/core/log.h> 14 15 mLOG_DECLARE_CATEGORY(GB_IO); 16 17 enum GBIORegisters { 18 GB_REG_JOYP = 0x00, 19 GB_REG_SB = 0x01, 20 GB_REG_SC = 0x02, 21 22 // Timing 23 GB_REG_DIV = 0x04, 24 GB_REG_TIMA = 0x05, 25 GB_REG_TMA = 0x06, 26 GB_REG_TAC = 0x07, 27 28 // Interrupts 29 GB_REG_IF = 0x0F, 30 GB_REG_IE = 0xFF, 31 32 // Audio 33 GB_REG_NR10 = 0x10, 34 GB_REG_NR11 = 0x11, 35 GB_REG_NR12 = 0x12, 36 GB_REG_NR13 = 0x13, 37 GB_REG_NR14 = 0x14, 38 GB_REG_NR21 = 0x16, 39 GB_REG_NR22 = 0x17, 40 GB_REG_NR23 = 0x18, 41 GB_REG_NR24 = 0x19, 42 GB_REG_NR30 = 0x1A, 43 GB_REG_NR31 = 0x1B, 44 GB_REG_NR32 = 0x1C, 45 GB_REG_NR33 = 0x1D, 46 GB_REG_NR34 = 0x1E, 47 GB_REG_NR41 = 0x20, 48 GB_REG_NR42 = 0x21, 49 GB_REG_NR43 = 0x22, 50 GB_REG_NR44 = 0x23, 51 GB_REG_NR50 = 0x24, 52 GB_REG_NR51 = 0x25, 53 GB_REG_NR52 = 0x26, 54 55 GB_REG_WAVE_0 = 0x30, 56 GB_REG_WAVE_1 = 0x31, 57 GB_REG_WAVE_2 = 0x32, 58 GB_REG_WAVE_3 = 0x33, 59 GB_REG_WAVE_4 = 0x34, 60 GB_REG_WAVE_5 = 0x35, 61 GB_REG_WAVE_6 = 0x36, 62 GB_REG_WAVE_7 = 0x37, 63 GB_REG_WAVE_8 = 0x38, 64 GB_REG_WAVE_9 = 0x39, 65 GB_REG_WAVE_A = 0x3A, 66 GB_REG_WAVE_B = 0x3B, 67 GB_REG_WAVE_C = 0x3C, 68 GB_REG_WAVE_D = 0x3D, 69 GB_REG_WAVE_E = 0x3E, 70 GB_REG_WAVE_F = 0x3F, 71 72 // Video 73 GB_REG_LCDC = 0x40, 74 GB_REG_STAT = 0x41, 75 GB_REG_SCY = 0x42, 76 GB_REG_SCX = 0x43, 77 GB_REG_LY = 0x44, 78 GB_REG_LYC = 0x45, 79 GB_REG_DMA = 0x46, 80 GB_REG_BGP = 0x47, 81 GB_REG_OBP0 = 0x48, 82 GB_REG_OBP1 = 0x49, 83 GB_REG_WY = 0x4A, 84 GB_REG_WX = 0x4B, 85 86 // CGB 87 GB_REG_KEY0 = 0x4C, 88 GB_REG_KEY1 = 0x4D, 89 GB_REG_VBK = 0x4F, 90 GB_REG_BANK = 0x50, 91 GB_REG_HDMA1 = 0x51, 92 GB_REG_HDMA2 = 0x52, 93 GB_REG_HDMA3 = 0x53, 94 GB_REG_HDMA4 = 0x54, 95 GB_REG_HDMA5 = 0x55, 96 GB_REG_RP = 0x56, 97 GB_REG_BCPS = 0x68, 98 GB_REG_BCPD = 0x69, 99 GB_REG_OCPS = 0x6A, 100 GB_REG_OCPD = 0x6B, 101 GB_REG_OPRI = 0x6C, 102 GB_REG_SVBK = 0x70, 103 GB_REG_UNK72 = 0x72, 104 GB_REG_UNK73 = 0x73, 105 GB_REG_UNK74 = 0x74, 106 GB_REG_UNK75 = 0x75, 107 GB_REG_PCM12 = 0x76, 108 GB_REG_PCM34 = 0x77, 109 GB_REG_MAX = 0x100 110 }; 111 112 extern MGBA_EXPORT const char* const GBIORegisterNames[]; 113 114 struct GB; 115 void GBIOInit(struct GB* gb); 116 void GBIOReset(struct GB* gb); 117 118 void GBIOWrite(struct GB* gb, unsigned address, uint8_t value); 119 uint8_t GBIORead(struct GB* gb, unsigned address); 120 121 struct GBSerializedState; 122 void GBIOSerialize(const struct GB* gb, struct GBSerializedState* state); 123 void GBIODeserialize(struct GB* gb, const struct GBSerializedState* state); 124 125 CXX_GUARD_END 126 127 #endif 128