all repos — mgba @ 0dd69e827325a28b74f2a2d997bae7eb7ae48db3

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 ARMDebugger* debugger;
 70
 71	int timersEnabled;
 72	struct GBATimer {
 73		uint16_t reload;
 74		uint16_t oldReload;
 75		int32_t lastEvent;
 76		int32_t nextEvent;
 77		int32_t overflowInterval;
 78		unsigned prescaleBits : 4;
 79		unsigned countUp : 1;
 80		unsigned doIrq : 1;
 81		unsigned enable : 1;
 82	} timers[4];
 83
 84	int springIRQ;
 85	int* keySource;
 86
 87	const char* activeFile;
 88	const char* savefile;
 89	enum GBAError errno;
 90	const char* errstr;
 91	int logLevel;
 92};
 93
 94void GBAInit(struct GBA* gba);
 95void GBADeinit(struct GBA* gba);
 96
 97void GBAMemoryInit(struct GBAMemory* memory);
 98void GBAMemoryDeinit(struct GBAMemory* memory);
 99
100void GBABoardInit(struct GBABoard* board);
101void GBABoardReset(struct ARMBoard* board);
102
103void GBATimerUpdateRegister(struct GBA* gba, int timer);
104void GBATimerWriteTMCNT_LO(struct GBA* gba, int timer, uint16_t value);
105void GBATimerWriteTMCNT_HI(struct GBA* gba, int timer, uint16_t value);
106
107void GBAWriteIE(struct GBA* gba, uint16_t value);
108void GBAWriteIME(struct GBA* gba, uint16_t value);
109void GBARaiseIRQ(struct GBA* gba, enum GBAIRQ irq);
110int GBATestIRQ(struct GBA* gba);
111int GBAWaitForIRQ(struct GBA* gba);
112int GBAHalt(struct GBA* gba);
113
114void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger);
115
116void GBALoadROM(struct GBA* gba, int fd, const char* fname);
117
118__attribute__((format (printf, 3, 4)))
119void GBALog(struct GBA* gba, enum GBALogLevel level, const char* format, ...);
120
121#endif