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