all repos — mgba @ 463ce997397850e6ea5ca27fb5c806e2edca4e89

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
26enum {
27	JOY_CMD_RESET = 0xFF,
28	JOY_CMD_POLL = 0x00,
29	JOY_CMD_TRANS = 0x14,
30	JOY_CMD_RECV = 0x15,
31
32	JOYSTAT_TRANS_BIT = 8,
33	JOYSTAT_RECV_BIT = 2,
34};
35
36struct GBASIODriverSet {
37	struct GBASIODriver* normal;
38	struct GBASIODriver* multiplayer;
39	struct GBASIODriver* joybus;
40};
41
42struct GBASIO {
43	struct GBA* p;
44
45	enum GBASIOMode mode;
46	struct GBASIODriverSet drivers;
47	struct GBASIODriver* activeDriver;
48
49	uint16_t rcnt;
50	// TODO: Convert to bitfields
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);
84void GBASIOReset(struct GBASIO* sio);
85
86void GBASIOSetDriverSet(struct GBASIO* sio, struct GBASIODriverSet* drivers);
87void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASIOMode mode);
88
89void GBASIOWriteRCNT(struct GBASIO* sio, uint16_t value);
90void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value);
91uint16_t GBASIOWriteRegister(struct GBASIO* sio, uint32_t address, uint16_t value);
92
93CXX_GUARD_END
94
95#endif