all repos — mgba @ ecc4775c311cb2c9cef70c8d4a4dc53fedeb2a38

mGBA Game Boy Advance Emulator

src/gba/gba-memory.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 GBAMemoryBase {
24	BASE_BIOS = 0x00000000,
25	BASE_WORKING_RAM = 0x02000000,
26	BASE_WORKING_IRAM = 0x03000000,
27	BASE_IO = 0x04000000,
28	BASE_PALETTE_RAM = 0x05000000,
29	BASE_VRAM = 0x06000000,
30	BASE_OAM = 0x07000000,
31	BASE_CART0 = 0x08000000,
32	BASE_CART0_EX = 0x09000000,
33	BASE_CART1 = 0x0A000000,
34	BASE_CART1_EX = 0x0B000000,
35	BASE_CART2 = 0x0C000000,
36	BASE_CART2_EX = 0x0D000000,
37	BASE_CART_SRAM = 0x0E000000
38};
39
40enum {
41	SIZE_BIOS = 0x00004000,
42	SIZE_WORKING_RAM = 0x00040000,
43	SIZE_WORKING_IRAM = 0x00008000,
44	SIZE_IO = 0x00000400,
45	SIZE_PALETTE_RAM = 0x00000400,
46	SIZE_VRAM = 0x00018000,
47	SIZE_OAM = 0x00000400,
48	SIZE_CART0 = 0x02000000,
49	SIZE_CART1 = 0x02000000,
50	SIZE_CART2 = 0x02000000,
51	SIZE_CART_SRAM = 0x00008000,
52	SIZE_CART_FLASH512 = 0x00010000,
53	SIZE_CART_FLASH1M = 0x00020000,
54	SIZE_CART_EEPROM = 0x00002000
55};
56
57enum {
58	OFFSET_MASK = 0x00FFFFFF,
59	BASE_OFFSET = 24
60};
61
62struct GBAMemory {
63	struct ARMMemory d;
64	struct GBA* p;
65
66	uint32_t* bios;
67	uint32_t* wram;
68	uint32_t* iwram;
69	uint32_t* rom;
70	uint16_t io[SIZE_IO >> 1];
71
72	char waitstates32[256];
73	char waitstates16[256];
74	char waitstatesSeq32[256];
75	char waitstatesSeq16[256];
76};
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