all repos — mgba @ 4429435071ef1924e1e4aa4b092bc6607811fc7b

mGBA Game Boy Advance Emulator

src/gba/gba.h (view raw)

  1#ifndef GBA_H
  2#define GBA_H
  3
  4#include "arm.h"
  5
  6#include "gba-memory.h"
  7#include "gba-video.h"
  8#include "gba-audio.h"
  9
 10const uint32_t GBA_ARM7TDMI_FREQUENCY;
 11
 12enum GBAIRQ {
 13	IRQ_VBLANK = 0x0,
 14	IRQ_HBLANK = 0x1,
 15	IRQ_VCOUNTER = 0x2,
 16	IRQ_TIMER0 = 0x3,
 17	IRQ_TIMER1 = 0x4,
 18	IRQ_TIMER2 = 0x5,
 19	IRQ_TIMER3 = 0x6,
 20	IRQ_SIO = 0x7,
 21	IRQ_DMA0 = 0x8,
 22	IRQ_DMA1 = 0x9,
 23	IRQ_DMA2 = 0xA,
 24	IRQ_DMA3 = 0xB,
 25	IRQ_KEYPAD = 0xC,
 26	IRQ_GAMEPAK = 0xD
 27};
 28
 29enum GBAError {
 30	GBA_NO_ERROR = 0,
 31	GBA_OUT_OF_MEMORY = -1
 32};
 33
 34enum GBALogLevel {
 35	GBA_LOG_STUB = 0x01,
 36	GBA_LOG_DEBUG = 0x02,
 37	GBA_LOG_INFO = 0x04,
 38	GBA_LOG_WARN = 0x08,
 39	GBA_LOG_ERROR = 0x10,
 40
 41	GBA_LOG_GAME_ERROR = 0x100
 42};
 43
 44enum GBAKey {
 45	GBA_KEY_A = 0,
 46	GBA_KEY_B = 1,
 47	GBA_KEY_SELECT = 2,
 48	GBA_KEY_START = 3,
 49	GBA_KEY_RIGHT = 4,
 50	GBA_KEY_LEFT = 5,
 51	GBA_KEY_UP = 6,
 52	GBA_KEY_DOWN = 7,
 53	GBA_KEY_R = 8,
 54	GBA_KEY_L = 9
 55};
 56
 57struct GBABoard {
 58	struct ARMBoard d;
 59	struct GBA* p;
 60};
 61
 62struct GBA {
 63	struct ARMCore cpu;
 64	struct GBABoard board;
 65	struct GBAMemory memory;
 66	struct GBAVideo video;
 67	struct GBAAudio audio;
 68
 69	struct GBASync* sync;
 70
 71	struct ARMDebugger* debugger;
 72
 73	int timersEnabled;
 74	struct GBATimer {
 75		uint16_t reload;
 76		uint16_t oldReload;
 77		int32_t lastEvent;
 78		int32_t nextEvent;
 79		int32_t overflowInterval;
 80		unsigned prescaleBits : 4;
 81		unsigned countUp : 1;
 82		unsigned doIrq : 1;
 83		unsigned enable : 1;
 84	} timers[4];
 85
 86	int springIRQ;
 87	int* keySource;
 88
 89	const char* activeFile;
 90	const char* savefile;
 91	enum GBAError errno;
 92	const char* errstr;
 93	int logLevel;
 94};
 95
 96struct GBACartridge {
 97	uint32_t entry;
 98	uint8_t logo[156];
 99	char title[12];
100	uint32_t id;
101	uint16_t maker;
102	uint8_t type;
103	uint8_t unit;
104	uint8_t device;
105	uint8_t reserved[7];
106	uint8_t version;
107	uint8_t checksum;
108	// And ROM data...
109};
110
111void GBAInit(struct GBA* gba);
112void GBADeinit(struct GBA* gba);
113
114void GBAMemoryInit(struct GBAMemory* memory);
115void GBAMemoryDeinit(struct GBAMemory* memory);
116
117void GBABoardInit(struct GBABoard* board);
118void GBABoardReset(struct ARMBoard* board);
119
120void GBATimerUpdateRegister(struct GBA* gba, int timer);
121void GBATimerWriteTMCNT_LO(struct GBA* gba, int timer, uint16_t value);
122void GBATimerWriteTMCNT_HI(struct GBA* gba, int timer, uint16_t value);
123
124void GBAWriteIE(struct GBA* gba, uint16_t value);
125void GBAWriteIME(struct GBA* gba, uint16_t value);
126void GBARaiseIRQ(struct GBA* gba, enum GBAIRQ irq);
127void GBATestIRQ(struct ARMBoard* board);
128int GBAWaitForIRQ(struct GBA* gba);
129int GBAHalt(struct GBA* gba);
130
131void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger);
132
133void GBALoadROM(struct GBA* gba, int fd, const char* fname);
134void GBALoadBIOS(struct GBA* gba, int fd);
135
136__attribute__((format (printf, 3, 4)))
137void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...);
138
139#endif