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 GBAMemoryBase {
29 BASE_BIOS = 0x00000000,
30 BASE_WORKING_RAM = 0x02000000,
31 BASE_WORKING_IRAM = 0x03000000,
32 BASE_IO = 0x04000000,
33 BASE_PALETTE_RAM = 0x05000000,
34 BASE_VRAM = 0x06000000,
35 BASE_OAM = 0x07000000,
36 BASE_CART0 = 0x08000000,
37 BASE_CART0_EX = 0x09000000,
38 BASE_CART1 = 0x0A000000,
39 BASE_CART1_EX = 0x0B000000,
40 BASE_CART2 = 0x0C000000,
41 BASE_CART2_EX = 0x0D000000,
42 BASE_CART_SRAM = 0x0E000000
43};
44enum {
45 SIZE_BIOS = 0x00004000,
46 SIZE_WORKING_RAM = 0x00040000,
47 SIZE_WORKING_IRAM = 0x00008000,
48 SIZE_IO = 0x00000400,
49 SIZE_PALETTE_RAM = 0x00000400,
50 SIZE_VRAM = 0x00018000,
51 SIZE_OAM = 0x00000400,
52 SIZE_CART0 = 0x02000000,
53 SIZE_CART1 = 0x02000000,
54 SIZE_CART2 = 0x02000000,
55 SIZE_CART_SRAM = 0x00008000,
56 SIZE_CART_FLASH512 = 0x00010000,
57 SIZE_CART_FLASH1M = 0x00020000,
58 SIZE_CART_EEPROM = 0x00002000
59};
60
61enum {
62 OFFSET_MASK = 0x00FFFFFF
63};
64
65struct GBAMemory {
66 struct ARMMemory d;
67 struct GBA* p;
68
69 int32_t* bios;
70 int32_t* wram;
71 int32_t* iwram;
72 int32_t* rom;
73};
74
75struct GBABoard {
76 struct ARMBoard board;
77};
78
79struct GBA {
80 struct ARMCore cpu;
81 struct GBABoard board;
82 struct GBAMemory memory;
83
84 enum GBAError errno;
85 const char* errstr;
86};
87
88void GBAInit(struct GBA* gba);
89void GBADeinit(struct GBA* gba);
90
91void GBAMemoryInit(struct GBAMemory* memory);
92void GBAMemoryDeinit(struct GBAMemory* memory);
93
94void GBALoadROM(struct GBA* gba, int fd);
95
96int32_t GBALoad32(struct ARMMemory* memory, uint32_t address);
97int16_t GBALoad16(struct ARMMemory* memory, uint32_t address);
98uint16_t GBALoadU16(struct ARMMemory* memory, uint32_t address);
99int8_t GBALoad8(struct ARMMemory* memory, uint32_t address);
100uint8_t GBALoadU8(struct ARMMemory* memory, uint32_t address);
101
102void GBAStore32(struct ARMMemory* memory, uint32_t address, int32_t value);
103void GBAStore16(struct ARMMemory* memory, uint32_t address, int16_t value);
104void GBAStore8(struct ARMMemory* memory, uint32_t address, int8_t value);
105
106#endif