include/mgba/internal/gb/sio.h (view raw)
1/* Copyright (c) 2013-2016 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 GB_SIO_H
7#define GB_SIO_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba/core/log.h>
14#include <mgba/core/timing.h>
15
16#define MAX_GBS 2
17
18extern const int GBSIOCyclesPerTransfer[2];
19
20mLOG_DECLARE_CATEGORY(GB_SIO);
21
22struct GB;
23struct GBSIODriver;
24struct GBSIO {
25 struct GB* p;
26
27 struct mTimingEvent event;
28 struct GBSIODriver* driver;
29
30 int32_t nextEvent;
31 int32_t period;
32 int remainingBits;
33
34 uint8_t pendingSB;
35};
36
37struct GBSIODriver {
38 struct GBSIO* p;
39
40 bool (*init)(struct GBSIODriver* driver);
41 void (*deinit)(struct GBSIODriver* driver);
42 void (*writeSB)(struct GBSIODriver* driver, uint8_t value);
43 uint8_t (*writeSC)(struct GBSIODriver* driver, uint8_t value);
44};
45
46DECL_BITFIELD(GBRegisterSC, uint8_t);
47DECL_BIT(GBRegisterSC, ShiftClock, 0);
48DECL_BIT(GBRegisterSC, ClockSpeed, 1);
49DECL_BIT(GBRegisterSC, Enable, 7);
50
51void GBSIOInit(struct GBSIO* sio);
52void GBSIOReset(struct GBSIO* sio);
53void GBSIODeinit(struct GBSIO* sio);
54void GBSIOSetDriver(struct GBSIO* sio, struct GBSIODriver* driver);
55void GBSIOWriteSC(struct GBSIO* sio, uint8_t sc);
56void GBSIOWriteSB(struct GBSIO* sio, uint8_t sb);
57
58CXX_GUARD_END
59
60#endif