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
11#include "util/threading.h"
12
13enum LockstepState {
14 LOCKSTEP_IDLE = 0,
15 LOCKSTEP_STARTED = 1,
16 LOCKSTEP_FINISHED = 2
17};
18
19struct GBASIOLockstep {
20 struct GBASIOLockstepNode* players[MAX_GBAS];
21 int attached;
22 int loadedMulti;
23 int loadedNormal;
24
25 uint16_t multiRecv[MAX_GBAS];
26 bool transferActive;
27 int32_t transferCycles;
28 int32_t nextEvent;
29
30 int waiting;
31 Mutex mutex;
32 Condition barrier;
33};
34
35struct GBASIOLockstepNode {
36 struct GBASIODriver d;
37 struct GBASIOLockstep* p;
38
39 int32_t nextEvent;
40 uint16_t multiSend;
41 bool normalSO;
42 enum LockstepState state;
43 int id;
44 enum GBASIOMode mode;
45};
46
47void GBASIOLockstepInit(struct GBASIOLockstep*);
48void GBASIOLockstepDeinit(struct GBASIOLockstep*);
49
50void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode*);
51
52bool GBASIOLockstepAttachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*);
53void GBASIOLockstepDetachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*);
54
55#endif