all repos — mgba @ 74fc29fc68e7ae84f0c27130d1d98299434ce6f2

mGBA Game Boy Advance Emulator

src/gba/sio.h (view raw)

 1/* Copyright (c) 2013-2015 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#include "gba/interface.h"
12
13#define MAX_GBAS 4
14
15extern const int GBASIOCyclesPerTransfer[4][MAX_GBAS];
16
17enum {
18	RCNT_INITIAL = 0x8000
19};
20
21struct GBASIODriverSet {
22	struct GBASIODriver* normal;
23	struct GBASIODriver* multiplayer;
24	struct GBASIODriver* joybus;
25};
26
27struct GBASIO {
28	struct GBA* p;
29
30	enum GBASIOMode mode;
31	struct GBASIODriverSet drivers;
32	struct GBASIODriver* activeDriver;
33
34	uint16_t rcnt;
35	// TODO: Convert to bitfields
36	union {
37		struct {
38			unsigned sc : 1;
39			unsigned internalSc : 1;
40			unsigned si : 1;
41			unsigned idleSo : 1;
42			unsigned : 4;
43			unsigned start : 1;
44			unsigned : 3;
45			unsigned length : 1;
46			unsigned : 1;
47			unsigned irq : 1;
48			unsigned : 1;
49		} normalControl;
50
51		struct {
52			unsigned baud : 2;
53			unsigned slave : 1;
54			unsigned ready : 1;
55			unsigned id : 2;
56			unsigned error : 1;
57			unsigned busy : 1;
58			unsigned : 6;
59			unsigned irq : 1;
60			unsigned : 1;
61		} multiplayerControl;
62
63		uint16_t siocnt;
64	};
65};
66
67void GBASIOInit(struct GBASIO* sio);
68void GBASIODeinit(struct GBASIO* sio);
69void GBASIOReset(struct GBASIO* sio);
70
71void GBASIOSetDriverSet(struct GBASIO* sio, struct GBASIODriverSet* drivers);
72void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASIOMode mode);
73
74void GBASIOWriteRCNT(struct GBASIO* sio, uint16_t value);
75void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value);
76void GBASIOWriteSIOMLT_SEND(struct GBASIO* sio, uint16_t value);
77
78int32_t GBASIOProcessEvents(struct GBASIO* sio, int32_t cycles);
79
80#endif