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 
11 CXX_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 
19 extern const int GBSIOCyclesPerTransfer[2];
20 
21 mLOG_DECLARE_CATEGORY(GB_SIO);
22 
23 struct GB;
24 struct GBSIODriver;
25 struct 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 
38 DECL_BITFIELD(GBRegisterSC, uint8_t);
39 DECL_BIT(GBRegisterSC, ShiftClock, 0);
40 DECL_BIT(GBRegisterSC, ClockSpeed, 1);
41 DECL_BIT(GBRegisterSC, Enable, 7);
42 
43 void GBSIOInit(struct GBSIO* sio);
44 void GBSIOReset(struct GBSIO* sio);
45 void GBSIODeinit(struct GBSIO* sio);
46 void GBSIOSetDriver(struct GBSIO* sio, struct GBSIODriver* driver);
47 void GBSIOWriteSC(struct GBSIO* sio, uint8_t sc);
48 void GBSIOWriteSB(struct GBSIO* sio, uint8_t sb);
49 
50 CXX_GUARD_END
51 
52 #endif
53