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#include <mgba/gb/interface.h>
16
17#define MAX_GBS 2
18
19extern const int GBSIOCyclesPerTransfer[2];
20
21mLOG_DECLARE_CATEGORY(GB_SIO);
22
23struct GB;
24struct GBSIODriver;
25struct GBSIO {
26 struct GB* p;
27
28 struct mTimingEvent event;
29 struct GBSIODriver* driver;
30
31 int32_t nextEvent;
32 int32_t period;
33 int remainingBits;
34
35 uint8_t pendingSB;
36};
37
38DECL_BITFIELD(GBRegisterSC, uint8_t);
39DECL_BIT(GBRegisterSC, ShiftClock, 0);
40DECL_BIT(GBRegisterSC, ClockSpeed, 1);
41DECL_BIT(GBRegisterSC, Enable, 7);
42
43void GBSIOInit(struct GBSIO* sio);
44void GBSIOReset(struct GBSIO* sio);
45void GBSIODeinit(struct GBSIO* sio);
46void GBSIOSetDriver(struct GBSIO* sio, struct GBSIODriver* driver);
47void GBSIOWriteSC(struct GBSIO* sio, uint8_t sc);
48void GBSIOWriteSB(struct GBSIO* sio, uint8_t sb);
49
50CXX_GUARD_END
51
52#endif