all repos — mgba @ dec8a1223c5199c632b89d659dfc28e7f2bee8fb

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	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	bool (*signal)(struct GBASIOLockstep*, unsigned mask);
31	bool (*wait)(struct GBASIOLockstep*, unsigned mask);
32	void (*addCycles)(struct GBASIOLockstep*, int id, int32_t cycles);
33	int32_t (*useCycles)(struct GBASIOLockstep*, int id, int32_t cycles);
34	void (*unload)(struct GBASIOLockstep*, int id);
35	void* context;
36#ifndef NDEBUG
37	int transferId;
38#endif
39};
40
41struct GBASIOLockstepNode {
42	struct GBASIODriver d;
43	struct GBASIOLockstep* p;
44
45	volatile int32_t nextEvent;
46	int32_t eventDiff;
47	bool normalSO;
48	int id;
49	enum GBASIOMode mode;
50	bool transferFinished;
51#ifndef NDEBUG
52	int transferId;
53	enum GBASIOLockstepPhase phase;
54#endif
55};
56
57void GBASIOLockstepInit(struct GBASIOLockstep*);
58void GBASIOLockstepDeinit(struct GBASIOLockstep*);
59
60void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode*);
61
62bool GBASIOLockstepAttachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*);
63void GBASIOLockstepDetachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*);
64
65#endif