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