all repos — mgba @ f6755a6e1b7b0cf2b944cd8ca842746f11d6bf82

mGBA Game Boy Advance Emulator

include/mgba/core/lockstep.h (view raw)

 1/* Copyright (c) 2013-2016 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 <mgba-util/common.h>
10
11CXX_GUARD_START
12
13enum mLockstepPhase {
14	TRANSFER_IDLE = 0,
15	TRANSFER_STARTING,
16	TRANSFER_STARTED,
17	TRANSFER_FINISHING,
18	TRANSFER_FINISHED
19};
20
21struct mLockstep {
22	int attached;
23	enum mLockstepPhase transferActive;
24	int32_t transferCycles;
25
26	void (*lock)(struct mLockstep*);
27	void (*unlock)(struct mLockstep*);
28
29	bool (*signal)(struct mLockstep*, unsigned mask);
30	bool (*wait)(struct mLockstep*, unsigned mask);
31	void (*addCycles)(struct mLockstep*, int id, int32_t cycles);
32	int32_t (*useCycles)(struct mLockstep*, int id, int32_t cycles);
33	int32_t (*unusedCycles)(struct mLockstep*, int id);
34	void (*unload)(struct mLockstep*, int id);
35	void* context;
36#ifndef NDEBUG
37	int transferId;
38#endif
39};
40
41void mLockstepInit(struct mLockstep*);
42void mLockstepDeinit(struct mLockstep*);
43
44static inline void mLockstepLock(struct mLockstep* lockstep) {
45	if (lockstep->lock) {
46		lockstep->lock(lockstep);
47	}
48}
49
50static inline void mLockstepUnlock(struct mLockstep* lockstep) {
51	if (lockstep->unlock) {
52		lockstep->unlock(lockstep);
53	}
54}
55
56CXX_GUARD_END
57
58#endif