all repos — mgba @ f7ac90d74eba6bc556b609bb788e5a9d84926968

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