src/gb/memory.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_MEMORY_H
7#define GB_MEMORY_H
8
9#include "util/common.h"
10
11#include "lr35902/lr35902.h"
12
13struct GB;
14
15enum {
16 GB_BASE_CART_BANK0 = 0x0000,
17 GB_BASE_CART_BANK1 = 0x4000,
18 GB_BASE_VRAM = 0x8000,
19 GB_BASE_EXTERNAL_RAM = 0xA000,
20 GB_BASE_WORKING_RAM_BANK0 = 0xC000,
21 GB_BASE_WORKING_RAM_BANK1 = 0xD000,
22 GB_BASE_OAM = 0xFE00,
23 GB_BASE_IO = 0xFF00,
24 GB_BASE_HRAM = 0xFF80,
25 GB_BASE_IE = 0xFFFF
26};
27
28enum {
29 GB_REGION_CART_BANK0 = 0x0,
30 GB_REGION_CART_BANK1 = 0x4,
31 GB_REGION_VRAM = 0x8,
32 GB_REGION_EXTERNAL_RAM = 0xA,
33 GB_REGION_WORKING_RAM_BANK0 = 0xC,
34 GB_REGION_WORKING_RAM_BANK1 = 0xD,
35 GB_REGION_WORKING_RAM_BANK1_MIRROR = 0xE,
36 GB_REGION_OTHER = 0xF,
37};
38
39enum {
40 GB_SIZE_CART_BANK0 = 0x4000,
41 GB_SIZE_VRAM = 0x2000,
42 GB_SIZE_EXTERNAL_RAM = 0x2000,
43 GB_SIZE_WORKING_RAM = 0x8000,
44 GB_SIZE_WORKING_RAM_BANK0 = 0x1000,
45 GB_SIZE_OAM = 0xA0,
46 GB_SIZE_IO = 0x80,
47 GB_SIZE_HRAM = 0x7F,
48};
49
50struct GBMemory {
51 uint8_t* rom;
52 uint8_t* romBank;
53
54 uint8_t* wram;
55 uint8_t* wramBank;
56
57 uint8_t io[GB_SIZE_IO];
58 bool ime;
59 uint8_t ie;
60
61 uint8_t hram[GB_SIZE_HRAM];
62
63 size_t romSize;
64};
65
66void GBMemoryInit(struct GB* gb);
67void GBMemoryDeinit(struct GB* gb);
68
69void GBMemoryReset(struct GB* gb);
70
71uint16_t GBLoad16(struct LR35902Core* cpu, uint16_t address);
72uint8_t GBLoad8(struct LR35902Core* cpu, uint16_t address);
73
74void GBStore16(struct LR35902Core* cpu, uint16_t address, int16_t value);
75void GBStore8(struct LR35902Core* cpu, uint16_t address, int8_t value);
76
77uint16_t GBView16(struct LR35902Core* cpu, uint16_t address);
78uint8_t GBView8(struct LR35902Core* cpu, uint16_t address);
79
80void GBPatch16(struct LR35902Core* cpu, uint16_t address, int16_t value, int16_t* old);
81void GBPatch8(struct LR35902Core* cpu, uint16_t address, int8_t value, int8_t* old);
82
83#endif