all repos — mgba @ a47bc8455c826a6618089207e96864f78e461c96

mGBA Game Boy Advance Emulator

include/mgba/internal/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 <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba/gba/interface.h>
14#include <mgba/core/log.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
36DECL_BITFIELD(GBASIONormal, uint16_t);
37DECL_BIT(GBASIONormal, Sc, 0);
38DECL_BIT(GBASIONormal, InternalSc, 1);
39DECL_BIT(GBASIONormal, Si, 2);
40DECL_BIT(GBASIONormal, IdleSo, 3);
41DECL_BIT(GBASIONormal, Start, 7);
42DECL_BIT(GBASIONormal, Length, 12);
43DECL_BIT(GBASIONormal, Irq, 14);
44DECL_BITFIELD(GBASIOMultiplayer, uint16_t);
45DECL_BITS(GBASIOMultiplayer, Baud, 0, 2);
46DECL_BIT(GBASIOMultiplayer, Slave, 2);
47DECL_BIT(GBASIOMultiplayer, Ready, 3);
48DECL_BITS(GBASIOMultiplayer, Id, 4, 2);
49DECL_BIT(GBASIOMultiplayer, Error, 6);
50DECL_BIT(GBASIOMultiplayer, Busy, 8);
51DECL_BIT(GBASIOMultiplayer, Irq, 14);
52
53struct GBASIODriverSet {
54	struct GBASIODriver* normal;
55	struct GBASIODriver* multiplayer;
56	struct GBASIODriver* joybus;
57};
58
59struct GBASIO {
60	struct GBA* p;
61
62	enum GBASIOMode mode;
63	struct GBASIODriverSet drivers;
64	struct GBASIODriver* activeDriver;
65
66	uint16_t rcnt;
67	uint16_t siocnt;
68};
69
70void GBASIOInit(struct GBASIO* sio);
71void GBASIODeinit(struct GBASIO* sio);
72void GBASIOReset(struct GBASIO* sio);
73
74void GBASIOSetDriverSet(struct GBASIO* sio, struct GBASIODriverSet* drivers);
75void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASIOMode mode);
76
77void GBASIOWriteRCNT(struct GBASIO* sio, uint16_t value);
78void GBASIOWriteSIOCNT(struct GBASIO* sio, uint16_t value);
79uint16_t GBASIOWriteRegister(struct GBASIO* sio, uint32_t address, uint16_t value);
80
81CXX_GUARD_END
82
83#endif