src/gba/sio/lockstep.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 SIO_LOCKSTEP_H
7#define SIO_LOCKSTEP_H
8
9#include "gba/sio.h"
10
11enum GBASIOLockstepPhase {
12 TRANSFER_IDLE = 0,
13 TRANSFER_STARTING,
14 TRANSFER_STARTED,
15 TRANSFER_FINISHING,
16 TRANSFER_FINISHED
17};
18
19struct GBASIOLockstep {
20 struct GBASIOLockstepNode* players[MAX_GBAS];
21 int attached;
22 int attachedMulti;
23 int attachedNormal;
24
25 uint16_t multiRecv[MAX_GBAS];
26 uint32_t normalRecv[MAX_GBAS];
27 enum GBASIOLockstepPhase transferActive;
28 int32_t transferCycles;
29
30 uint32_t masterWaiting;
31
32 void (*signal)(struct GBASIOLockstep*, int id);
33 void (*wait)(struct GBASIOLockstep*, int id);
34 void* context;
35#ifndef NDEBUG
36 int transferId;
37#endif
38};
39
40struct GBASIOLockstepNode {
41 struct GBASIODriver d;
42 struct GBASIOLockstep* p;
43
44 volatile int32_t nextEvent;
45 int32_t eventDiff;
46 bool normalSO;
47 int id;
48 enum GBASIOMode mode;
49 bool transferFinished;
50#ifndef NDEBUG
51 int transferId;
52 enum GBASIOLockstepPhase phase;
53#endif
54};
55
56void GBASIOLockstepInit(struct GBASIOLockstep*);
57void GBASIOLockstepDeinit(struct GBASIOLockstep*);
58
59void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode*);
60
61bool GBASIOLockstepAttachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*);
62void GBASIOLockstepDetachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*);
63
64#endif