all repos — mgba @ 9efc945f1b9172d6c0af6ac038ddf5400f63c0d2

mGBA Game Boy Advance Emulator

src/gba.h (view raw)

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