all repos — mgba @ 9d351d4a5835da48fd7a4ed24f7cba27adf0ce74

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
 10extern const 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 GBARotationSource;
 58
 59struct GBABoard {
 60	struct ARMBoard d;
 61	struct GBA* p;
 62};
 63
 64struct GBA {
 65	struct ARMCore cpu;
 66	struct GBABoard board;
 67	struct GBAMemory memory;
 68	struct GBAVideo video;
 69	struct GBAAudio audio;
 70
 71	struct GBASync* sync;
 72
 73	struct ARMDebugger* debugger;
 74
 75	int timersEnabled;
 76	struct GBATimer {
 77		uint16_t reload;
 78		uint16_t oldReload;
 79		int32_t lastEvent;
 80		int32_t nextEvent;
 81		int32_t overflowInterval;
 82		unsigned prescaleBits : 4;
 83		unsigned countUp : 1;
 84		unsigned doIrq : 1;
 85		unsigned enable : 1;
 86	} timers[4];
 87
 88	int springIRQ;
 89	uint32_t biosChecksum;
 90	int* keySource;
 91	struct GBARotationSource* rotationSource;
 92	struct GBARumble* rumble;
 93
 94	const char* activeFile;
 95	const char* savefile;
 96	int logLevel;
 97};
 98
 99struct GBACartridge {
100	uint32_t entry;
101	uint8_t logo[156];
102	char title[12];
103	uint32_t id;
104	uint16_t maker;
105	uint8_t type;
106	uint8_t unit;
107	uint8_t device;
108	uint8_t reserved[7];
109	uint8_t version;
110	uint8_t checksum;
111	// And ROM data...
112};
113
114void GBAInit(struct GBA* gba);
115void GBADeinit(struct GBA* gba);
116
117void GBAMemoryInit(struct GBAMemory* memory);
118void GBAMemoryDeinit(struct GBAMemory* memory);
119
120void GBABoardInit(struct GBABoard* board);
121void GBABoardReset(struct ARMBoard* board);
122
123void GBATimerUpdateRegister(struct GBA* gba, int timer);
124void GBATimerWriteTMCNT_LO(struct GBA* gba, int timer, uint16_t value);
125void GBATimerWriteTMCNT_HI(struct GBA* gba, int timer, uint16_t value);
126
127void GBAWriteIE(struct GBA* gba, uint16_t value);
128void GBAWriteIME(struct GBA* gba, uint16_t value);
129void GBARaiseIRQ(struct GBA* gba, enum GBAIRQ irq);
130void GBATestIRQ(struct ARMBoard* board);
131int GBAWaitForIRQ(struct GBA* gba);
132int GBAHalt(struct GBA* gba);
133
134void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger);
135
136void GBALoadROM(struct GBA* gba, int fd, const char* fname);
137void GBALoadBIOS(struct GBA* gba, int fd);
138
139__attribute__((format (printf, 3, 4)))
140void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...);
141
142#endif