all repos — mgba @ 2ce017b555088fc84fa5e37f81762c5c2a6e5d92

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