all repos — mgba @ 187e099f255a46854bb0b23d8cb062e524ef09a0

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
  9enum GBAIRQ {
 10	IRQ_VBLANK = 0x0,
 11	IRQ_HBLANK = 0x1,
 12	IRQ_VCOUNTER = 0x2,
 13	IRQ_TIMER0 = 0x3,
 14	IRQ_TIMER1 = 0x4,
 15	IRQ_TIMER2 = 0x5,
 16	IRQ_TIMER3 = 0x6,
 17	IRQ_SIO = 0x7,
 18	IRQ_DMA0 = 0x8,
 19	IRQ_DMA1 = 0x9,
 20	IRQ_DMA2 = 0xA,
 21	IRQ_DMA3 = 0xB,
 22	IRQ_KEYPAD = 0xC,
 23	IRQ_GAMEPAK = 0xD
 24};
 25
 26enum GBAError {
 27	GBA_NO_ERROR = 0,
 28	GBA_OUT_OF_MEMORY = -1
 29};
 30
 31enum GBALogLevel {
 32	GBA_LOG_STUB,
 33	GBA_LOG_DEBUG,
 34	GBA_LOG_INFO,
 35	GBA_LOG_WARN,
 36	GBA_LOG_ERROR,
 37
 38	GBA_LOG_GAME_ERROR
 39};
 40
 41enum GBAKey {
 42	GBA_KEY_A = 0,
 43	GBA_KEY_B = 1,
 44	GBA_KEY_SELECT = 2,
 45	GBA_KEY_START = 3,
 46	GBA_KEY_RIGHT = 4,
 47	GBA_KEY_LEFT = 5,
 48	GBA_KEY_UP = 6,
 49	GBA_KEY_DOWN = 7,
 50	GBA_KEY_R = 8,
 51	GBA_KEY_L = 9
 52};
 53
 54struct GBABoard {
 55	struct ARMBoard d;
 56	struct GBA* p;
 57};
 58
 59struct GBA {
 60	struct ARMCore cpu;
 61	struct GBABoard board;
 62	struct GBAMemory memory;
 63	struct GBAVideo video;
 64
 65	struct ARMDebugger* debugger;
 66
 67	int timersEnabled;
 68	struct GBATimer {
 69		uint16_t reload;
 70		uint16_t oldReload;
 71		int32_t lastEvent;
 72		int32_t nextEvent;
 73		int32_t overflowInterval;
 74		unsigned prescaleBits : 4;
 75		unsigned countUp : 1;
 76		unsigned doIrq : 1;
 77		unsigned enable : 1;
 78	} timers[4];
 79
 80	int springIRQ;
 81	int* keySource;
 82
 83	const char* activeFile;
 84	const char* savefile;
 85	enum GBAError errno;
 86	const char* errstr;
 87	enum GBALogLevel logLevel;
 88};
 89
 90void GBAInit(struct GBA* gba);
 91void GBADeinit(struct GBA* gba);
 92
 93void GBAMemoryInit(struct GBAMemory* memory);
 94void GBAMemoryDeinit(struct GBAMemory* memory);
 95
 96void GBABoardInit(struct GBABoard* board);
 97void GBABoardReset(struct ARMBoard* board);
 98
 99void GBATimerUpdateRegister(struct GBA* gba, int timer);
100void GBATimerWriteTMCNT_LO(struct GBA* gba, int timer, uint16_t value);
101void GBATimerWriteTMCNT_HI(struct GBA* gba, int timer, uint16_t value);
102
103void GBAWriteIE(struct GBA* gba, uint16_t value);
104void GBAWriteIME(struct GBA* gba, uint16_t value);
105void GBARaiseIRQ(struct GBA* gba, enum GBAIRQ irq);
106int GBATestIRQ(struct GBA* gba);
107int GBAWaitForIRQ(struct GBA* gba);
108int GBAHalt(struct GBA* gba);
109
110void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger);
111
112void GBALoadROM(struct GBA* gba, int fd, const char* fname);
113
114__attribute__((format (printf, 3, 4)))
115void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...);
116
117#endif