all repos — mgba @ c9ede88332bf9d1def0b3af005ad4d29456289e9

mGBA Game Boy Advance Emulator

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
24	uint16_t multiRecv[MAX_GBAS];
25	enum GBASIOLockstepPhase transferActive;
26	int32_t transferCycles;
27
28	uint32_t waitMask;
29	uint32_t waiting[MAX_GBAS];
30
31	void (*signal)(struct GBASIOLockstep*, int id);
32	void (*wait)(struct GBASIOLockstep*, int id);
33	void* context;
34#ifndef NDEBUG
35	int transferId;
36#endif
37};
38
39struct GBASIOLockstepNode {
40	struct GBASIODriver d;
41	struct GBASIOLockstep* p;
42
43	int32_t nextEvent;
44	int32_t eventDiff;
45	bool normalSO;
46	bool needsToWait;
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