all repos — mgba @ 8132341b75684b1fd69680509ad1d9f6fe9f4d4a

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
 39enum GBAKey {
 40	GBA_KEY_A = 0,
 41	GBA_KEY_B = 1,
 42	GBA_KEY_SELECT = 2,
 43	GBA_KEY_START = 3,
 44	GBA_KEY_RIGHT = 4,
 45	GBA_KEY_LEFT = 5,
 46	GBA_KEY_UP = 6,
 47	GBA_KEY_DOWN = 7,
 48	GBA_KEY_R = 8,
 49	GBA_KEY_L = 9
 50};
 51
 52struct GBABoard {
 53	struct ARMBoard d;
 54	struct GBA* p;
 55};
 56
 57struct GBA {
 58	struct ARMCore cpu;
 59	struct GBABoard board;
 60	struct GBAMemory memory;
 61	struct GBAVideo video;
 62
 63	struct ARMDebugger* debugger;
 64
 65	int timersEnabled;
 66	struct GBATimer {
 67		uint16_t reload;
 68		uint16_t oldReload;
 69		int32_t lastEvent;
 70		int32_t nextEvent;
 71		int32_t overflowInterval;
 72		unsigned prescaleBits : 4;
 73		unsigned countUp : 1;
 74		unsigned doIrq : 1;
 75		unsigned enable : 1;
 76	} timers[4];
 77
 78	int springIRQ;
 79	int* keySource;
 80
 81	const char* activeFile;
 82	const char* savefile;
 83	enum GBAError errno;
 84	const char* errstr;
 85	enum GBALogLevel logLevel;
 86};
 87
 88void GBAInit(struct GBA* gba);
 89void GBADeinit(struct GBA* gba);
 90
 91void GBAMemoryInit(struct GBAMemory* memory);
 92void GBAMemoryDeinit(struct GBAMemory* memory);
 93
 94void GBABoardInit(struct GBABoard* board);
 95void GBABoardReset(struct ARMBoard* board);
 96
 97void GBATimerUpdateRegister(struct GBA* gba, int timer);
 98void GBATimerWriteTMCNT_LO(struct GBA* gba, int timer, uint16_t value);
 99void GBATimerWriteTMCNT_HI(struct GBA* gba, int timer, uint16_t value);
100
101void GBAWriteIE(struct GBA* gba, uint16_t value);
102void GBAWriteIME(struct GBA* gba, uint16_t value);
103void GBARaiseIRQ(struct GBA* gba, enum GBAIRQ irq);
104int GBATestIRQ(struct GBA* gba);
105int GBAWaitForIRQ(struct GBA* gba);
106int GBAHalt(struct GBA* gba);
107
108void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger);
109
110void GBALoadROM(struct GBA* gba, int fd, const char* fname);
111
112__attribute__((format (printf, 3, 4)))
113void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...);
114
115#endif