src/gba.h (view raw)
1#ifndef GBA_MEMORY_H
2#define GBA_MEMORY_H
3
4#include "arm.h"
5
6enum GBAError {
7 GBA_NO_ERROR = 0,
8 GBA_OUT_OF_MEMORY = -1
9};
10
11enum GBAMemoryRegion {
12 REGION_BIOS = 0x0,
13 REGION_WORKING_RAM = 0x2,
14 REGION_WORKING_IRAM = 0x3,
15 REGION_IO = 0x4,
16 REGION_PALETTE_RAM = 0x5,
17 REGION_VRAM = 0x6,
18 REGION_OAM = 0x7,
19 REGION_CART0 = 0x8,
20 REGION_CART0_EX = 0x9,
21 REGION_CART1 = 0xA,
22 REGION_CART1_EX = 0xB,
23 REGION_CART2 = 0xC,
24 REGION_CART2_EX = 0xD,
25 REGION_CART_SRAM = 0xE
26};
27
28enum {
29 SIZE_BIOS = 0x00004000,
30 SIZE_WORKING_RAM = 0x00040000,
31 SIZE_WORKING_IRAM = 0x00008000,
32 SIZE_IO = 0x00000400,
33 SIZE_PALETTE_RAM = 0x00000400,
34 SIZE_VRAM = 0x00018000,
35 SIZE_OAM = 0x00000400,
36 SIZE_CART0 = 0x02000000,
37 SIZE_CART1 = 0x02000000,
38 SIZE_CART2 = 0x02000000,
39 SIZE_CART_SRAM = 0x00008000,
40 SIZE_CART_FLASH512 = 0x00010000,
41 SIZE_CART_FLASH1M = 0x00020000,
42 SIZE_CART_EEPROM = 0x00002000
43};
44
45enum {
46 OFFSET_MASK = 0x00FFFFFF
47};
48
49struct GBAMemory {
50 struct ARMMemory d;
51 struct GBA* p;
52
53 int32_t* bios;
54 int32_t* wram;
55 int32_t* iwram;
56 int32_t* rom;
57};
58
59struct GBABoard {
60 struct ARMBoard board;
61};
62
63struct GBA {
64 struct ARMCore cpu;
65 struct GBABoard board;
66 struct GBAMemory memory;
67
68 enum GBAError errno;
69 const char* errstr;
70};
71
72void GBAInit(struct GBA* gba);
73void GBADeinit(struct GBA* gba);
74
75void GBAMemoryInit(struct GBAMemory* memory);
76void GBAMemoryDeinit(struct GBAMemory* memory);
77
78int32_t GBALoad32(struct ARMMemory* memory, uint32_t address);
79int16_t GBALoad16(struct ARMMemory* memory, uint32_t address);
80uint16_t GBALoadU16(struct ARMMemory* memory, uint32_t address);
81int8_t GBALoad8(struct ARMMemory* memory, uint32_t address);
82uint8_t GBALoadU8(struct ARMMemory* memory, uint32_t address);
83
84void GBAStore32(struct ARMMemory* memory, uint32_t address, int32_t value);
85void GBAStore16(struct ARMMemory* memory, uint32_t address, int16_t value);
86void GBAStore8(struct ARMMemory* memory, uint32_t address, int8_t value);
87
88#endif