src/gba/gba-sio.h (view raw)
1#ifndef GBA_SIO_H
2#define GBA_SIO_H
3
4#include <stdint.h>
5
6enum GBASIOMode {
7 SIO_NORMAL_8 = 0,
8 SIO_NORMAL_32 = 1,
9 SIO_MULTI = 2,
10 SIO_UART = 3,
11 SIO_GPIO = 8,
12 SIO_JOYBUS = 12
13};
14
15enum {
16 RCNT_INITIAL = 0x8000
17};
18
19struct GBASIO;
20
21struct GBASIODriver {
22 struct GBASIO* p;
23
24 int (*init)(struct GBASIODriver* driver);
25 void (*deinit)(struct GBASIODriver* driver);
26 int (*load)(struct GBASIODriver* driver);
27 int (*unload)(struct GBASIODriver* driver);
28 int (*writeRegister)(struct GBASIODriver* driver, uint32_t address, uint16_t value);
29 int32_t (*processEvents)(struct GBASIODriver* driver, int32_t cycles);
30};
31
32struct GBASIODriverSet {
33 struct GBASIODriver* normal;
34 struct GBASIODriver* multiplayer;
35 struct GBASIODriver* joybus;
36};
37
38struct GBASIO {
39 struct GBA* p;
40
41 enum GBASIOMode mode;
42 struct GBASIODriverSet drivers;
43 struct GBASIODriver* activeDriver;
44
45 uint16_t rcnt;
46 union {
47 struct {
48 unsigned sc : 1;
49 unsigned internalSc : 1;
50 unsigned si : 1;
51 unsigned idleSo : 1;
52 unsigned : 4;
53 unsigned start : 1;
54 unsigned : 3;
55 unsigned length : 1;
56 unsigned : 1;
57 unsigned irq : 1;
58 unsigned : 1;
59 } normalControl;
60
61 struct {
62 unsigned baud : 2;
63 unsigned slave : 1;
64 unsigned ready : 1;
65 unsigned id : 2;
66 unsigned error : 1;
67 unsigned busy : 1;
68 unsigned : 6;
69 unsigned irq : 1;
70 unsigned : 1;
71 } multiplayerControl;
72
73 uint16_t siocnt;
74 };
75};
76
77void GBASIOInit(struct GBASIO* sio);
78void GBASIODeinit(struct GBASIO* sio);
79
80void GBASIOSetDriverSet(struct GBASIO* sio, struct GBASIODriverSet* drivers);
81void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASIOMode mode);
82
83void GBASIOWriteRCNT(struct GBASIO* sio, uint16_t value);
84void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value);
85void GBASIOWriteSIOMLT_SEND(struct GBASIO* sio, uint16_t value);
86
87int32_t GBASIOProcessEvents(struct GBASIO* sio, int32_t cycles);
88
89#endif