all repos — mgba @ e9a2b2a57c4f478fb3600fe9d87e1b97804d73de

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