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