all repos — mgba @ 8118c94c8128a4aaf5cef83d87dab1e4b09bd646

mGBA Game Boy Advance Emulator

src/gba/gba-sio.h (view raw)

 1/* Copyright (c) 2013-2014 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#ifndef GBA_SIO_H
 7#define GBA_SIO_H
 8
 9#include "util/common.h"
10
11enum GBASIOMode {
12	SIO_NORMAL_8 = 0,
13	SIO_NORMAL_32 = 1,
14	SIO_MULTI = 2,
15	SIO_UART = 3,
16	SIO_GPIO = 8,
17	SIO_JOYBUS = 12
18};
19
20enum {
21	RCNT_INITIAL = 0x8000
22};
23
24struct GBASIO;
25
26struct GBASIODriver {
27	struct GBASIO* p;
28
29	int (*init)(struct GBASIODriver* driver);
30	void (*deinit)(struct GBASIODriver* driver);
31	int (*load)(struct GBASIODriver* driver);
32	int (*unload)(struct GBASIODriver* driver);
33	int (*writeRegister)(struct GBASIODriver* driver, uint32_t address, uint16_t value);
34	int32_t (*processEvents)(struct GBASIODriver* driver, int32_t cycles);
35};
36
37struct GBASIODriverSet {
38	struct GBASIODriver* normal;
39	struct GBASIODriver* multiplayer;
40	struct GBASIODriver* joybus;
41};
42
43struct GBASIO {
44	struct GBA* p;
45
46	enum GBASIOMode mode;
47	struct GBASIODriverSet drivers;
48	struct GBASIODriver* activeDriver;
49
50	uint16_t rcnt;
51	union {
52		struct {
53			unsigned sc : 1;
54			unsigned internalSc : 1;
55			unsigned si : 1;
56			unsigned idleSo : 1;
57			unsigned : 4;
58			unsigned start : 1;
59			unsigned : 3;
60			unsigned length : 1;
61			unsigned : 1;
62			unsigned irq : 1;
63			unsigned : 1;
64		} normalControl;
65
66		struct {
67			unsigned baud : 2;
68			unsigned slave : 1;
69			unsigned ready : 1;
70			unsigned id : 2;
71			unsigned error : 1;
72			unsigned busy : 1;
73			unsigned : 6;
74			unsigned irq : 1;
75			unsigned : 1;
76		} multiplayerControl;
77
78		uint16_t siocnt;
79	};
80};
81
82void GBASIOInit(struct GBASIO* sio);
83void GBASIODeinit(struct GBASIO* sio);
84
85void GBASIOSetDriverSet(struct GBASIO* sio, struct GBASIODriverSet* drivers);
86void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASIOMode mode);
87
88void GBASIOWriteRCNT(struct GBASIO* sio, uint16_t value);
89void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value);
90void GBASIOWriteSIOMLT_SEND(struct GBASIO* sio, uint16_t value);
91
92int32_t GBASIOProcessEvents(struct GBASIO* sio, int32_t cycles);
93
94#endif