all repos — mgba @ 764b3fce10c6efe989c5107f249e880cebef26d8

mGBA Game Boy Advance Emulator

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* multiplayer;
34	struct GBASIODriver* joybus;
35};
36
37struct GBASIO {
38	struct GBA* p;
39
40	enum GBASIOMode mode;
41	struct GBASIODriverSet drivers;
42	struct GBASIODriver* activeDriver;
43
44	uint16_t rcnt;
45	union {
46		struct {
47			unsigned sc : 1;
48			unsigned internalSc : 1;
49			unsigned si : 1;
50			unsigned idleSo : 1;
51			unsigned : 4;
52			unsigned start : 1;
53			unsigned : 3;
54			unsigned length : 1;
55			unsigned : 1;
56			unsigned irq : 1;
57			unsigned : 1;
58		} normalControl;
59
60		struct {
61			unsigned baud : 2;
62			unsigned slave : 1;
63			unsigned ready : 1;
64			unsigned id : 2;
65			unsigned error : 1;
66			unsigned busy : 1;
67			unsigned : 6;
68			unsigned irq : 1;
69			unsigned : 1;
70		} multiplayerControl;
71
72		uint16_t siocnt;
73	};
74};
75
76void GBASIOInit(struct GBASIO* sio);
77void GBASIODeinit(struct GBASIO* sio);
78
79void GBASIOSetDriverSet(struct GBASIO* sio, struct GBASIODriverSet* drivers);
80void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASIOMode mode);
81
82void GBASIOWriteRCNT(struct GBASIO* sio, uint16_t value);
83void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value);
84void GBASIOWriteSIOMLT_SEND(struct GBASIO* sio, uint16_t value);
85
86int32_t GBASIOProcessEvents(struct GBASIO* sio, int32_t cycles);
87
88#endif