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
36struct GBABoard {
37 struct ARMBoard d;
38 struct GBA* p;
39};
40
41struct GBA {
42 struct ARMCore cpu;
43 struct GBABoard board;
44 struct GBAMemory memory;
45 struct GBAVideo video;
46
47 struct ARMDebugger* debugger;
48
49 int timersEnabled;
50 struct GBATimer {
51 uint16_t reload;
52 uint16_t oldReload;
53 int32_t lastEvent;
54 int32_t nextEvent;
55 int32_t overflowInterval;
56 unsigned prescaleBits : 4;
57 unsigned countUp : 1;
58 unsigned doIrq : 1;
59 unsigned enable : 1;
60 } timers[4];
61
62 int springIRQ;
63
64 enum GBAError errno;
65 const char* errstr;
66};
67
68void GBAInit(struct GBA* gba);
69void GBADeinit(struct GBA* gba);
70
71void GBAMemoryInit(struct GBAMemory* memory);
72void GBAMemoryDeinit(struct GBAMemory* memory);
73
74void GBABoardInit(struct GBABoard* board);
75void GBABoardReset(struct ARMBoard* board);
76
77void GBATimerUpdateRegister(struct GBA* gba, int timer);
78void GBATimerWriteTMCNT_LO(struct GBA* gba, int timer, uint16_t value);
79void GBATimerWriteTMCNT_HI(struct GBA* gba, int timer, uint16_t value);
80
81void GBAWriteIE(struct GBA* gba, uint16_t value);
82void GBAWriteIME(struct GBA* gba, uint16_t value);
83void GBARaiseIRQ(struct GBA* gba, enum GBAIRQ irq);
84int GBATestIRQ(struct GBA* gba);
85int GBAWaitForIRQ(struct GBA* gba);
86int GBAHalt(struct GBA* gba);
87
88void GBAAttachDebugger(struct GBA* gba, struct ARMDebugger* debugger);
89
90void GBALoadROM(struct GBA* gba, int fd);
91
92void GBALog(int level, const char* format, ...);
93
94#endif