all repos — mgba @ 9a0d14645b1acd3dd67453ccecfc8b074e794518

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 GBAError {
  7	GBA_NO_ERROR = 0,
  8	GBA_OUT_OF_MEMORY = -1
  9};
 10
 11enum GBALogLevel {
 12	GBA_LOG_STUB
 13};
 14
 15enum GBAMemoryRegion {
 16	REGION_BIOS = 0x0,
 17	REGION_WORKING_RAM = 0x2,
 18	REGION_WORKING_IRAM = 0x3,
 19	REGION_IO = 0x4,
 20	REGION_PALETTE_RAM = 0x5,
 21	REGION_VRAM = 0x6,
 22	REGION_OAM = 0x7,
 23	REGION_CART0 = 0x8,
 24	REGION_CART0_EX = 0x9,
 25	REGION_CART1 = 0xA,
 26	REGION_CART1_EX = 0xB,
 27	REGION_CART2 = 0xC,
 28	REGION_CART2_EX = 0xD,
 29	REGION_CART_SRAM = 0xE
 30};
 31
 32enum GBAMemoryBase {
 33	BASE_BIOS = 0x00000000,
 34	BASE_WORKING_RAM = 0x02000000,
 35	BASE_WORKING_IRAM = 0x03000000,
 36	BASE_IO = 0x04000000,
 37	BASE_PALETTE_RAM = 0x05000000,
 38	BASE_VRAM = 0x06000000,
 39	BASE_OAM = 0x07000000,
 40	BASE_CART0 = 0x08000000,
 41	BASE_CART0_EX = 0x09000000,
 42	BASE_CART1 = 0x0A000000,
 43	BASE_CART1_EX = 0x0B000000,
 44	BASE_CART2 = 0x0C000000,
 45	BASE_CART2_EX = 0x0D000000,
 46	BASE_CART_SRAM = 0x0E000000
 47};
 48
 49enum {
 50	SIZE_BIOS = 0x00004000,
 51	SIZE_WORKING_RAM = 0x00040000,
 52	SIZE_WORKING_IRAM = 0x00008000,
 53	SIZE_IO = 0x00000400,
 54	SIZE_PALETTE_RAM = 0x00000400,
 55	SIZE_VRAM = 0x00018000,
 56	SIZE_OAM = 0x00000400,
 57	SIZE_CART0 = 0x02000000,
 58	SIZE_CART1 = 0x02000000,
 59	SIZE_CART2 = 0x02000000,
 60	SIZE_CART_SRAM = 0x00008000,
 61	SIZE_CART_FLASH512 = 0x00010000,
 62	SIZE_CART_FLASH1M = 0x00020000,
 63	SIZE_CART_EEPROM = 0x00002000
 64};
 65
 66enum {
 67	SP_BASE_SYSTEM = 0x03FFFF00,
 68	SP_BASE_IRQ = 0x03FFFFA0,
 69	SP_BASE_SUPERVISOR = 0x03FFFFE0
 70};
 71
 72enum {
 73	OFFSET_MASK = 0x00FFFFFF
 74};
 75
 76struct GBAMemory {
 77	struct ARMMemory d;
 78	struct GBA* p;
 79
 80	int32_t* bios;
 81	int32_t* wram;
 82	int32_t* iwram;
 83	int32_t* rom;
 84};
 85
 86struct GBABoard {
 87	struct ARMBoard d;
 88};
 89
 90struct GBA {
 91	struct ARMCore cpu;
 92	struct GBABoard board;
 93	struct GBAMemory memory;
 94
 95	enum GBAError errno;
 96	const char* errstr;
 97};
 98
 99void GBAInit(struct GBA* gba);
100void GBADeinit(struct GBA* gba);
101
102void GBAMemoryInit(struct GBAMemory* memory);
103void GBAMemoryDeinit(struct GBAMemory* memory);
104
105void GBABoardInit(struct GBABoard* board);
106void GBABoardReset(struct ARMBoard* board);
107
108void GBALoadROM(struct GBA* gba, int fd);
109
110int32_t GBALoad32(struct ARMMemory* memory, uint32_t address);
111int16_t GBALoad16(struct ARMMemory* memory, uint32_t address);
112uint16_t GBALoadU16(struct ARMMemory* memory, uint32_t address);
113int8_t GBALoad8(struct ARMMemory* memory, uint32_t address);
114uint8_t GBALoadU8(struct ARMMemory* memory, uint32_t address);
115
116void GBAStore32(struct ARMMemory* memory, uint32_t address, int32_t value);
117void GBAStore16(struct ARMMemory* memory, uint32_t address, int16_t value);
118void GBAStore8(struct ARMMemory* memory, uint32_t address, int8_t value);
119
120#endif