all repos — mgba @ f836a67863e66499c812c8d963d37ff56ad10638

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