mirror of https://github.com/mgba-emu/mgba.git
GBA SIO: Build up lockstep driver a bit more
This commit is contained in:
parent
1e912abf4b
commit
5b40951c05
|
@ -21,10 +21,12 @@ void GBASIOLockstepInit(struct GBASIOLockstep* lockstep) {
|
||||||
lockstep->players[3] = 0;
|
lockstep->players[3] = 0;
|
||||||
lockstep->attached = 0;
|
lockstep->attached = 0;
|
||||||
ConditionInit(&lockstep->barrier);
|
ConditionInit(&lockstep->barrier);
|
||||||
|
MutexInit(&lockstep->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASIOLockstepDeinit(struct GBASIOLockstep* lockstep) {
|
void GBASIOLockstepDeinit(struct GBASIOLockstep* lockstep) {
|
||||||
ConditionDeinit(&lockstep->barrier);
|
ConditionDeinit(&lockstep->barrier);
|
||||||
|
MutexDeinit(&lockstep->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode* node) {
|
void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode* node) {
|
||||||
|
@ -45,6 +47,23 @@ bool GBASIOLockstepAttachNode(struct GBASIOLockstep* lockstep, struct GBASIOLock
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GBASIOLockstepDetachNode(struct GBASIOLockstep* lockstep, struct GBASIOLockstepNode* node) {
|
||||||
|
if (lockstep->attached == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < lockstep->attached; ++i) {
|
||||||
|
if (lockstep->players[i] != node) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (++i; i < lockstep->attached; ++i) {
|
||||||
|
lockstep->players[i - 1] = lockstep->players[i];
|
||||||
|
}
|
||||||
|
--lockstep->attached;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool GBASIOLockstepNodeInit(struct GBASIODriver* driver) {
|
bool GBASIOLockstepNodeInit(struct GBASIODriver* driver) {
|
||||||
UNUSED(driver);
|
UNUSED(driver);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -15,6 +15,7 @@ struct GBASIOLockstep {
|
||||||
int attached;
|
int attached;
|
||||||
|
|
||||||
uint16_t data[MAX_GBAS];
|
uint16_t data[MAX_GBAS];
|
||||||
|
Mutex mutex;
|
||||||
Condition barrier;
|
Condition barrier;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,6 +28,8 @@ void GBASIOLockstepInit(struct GBASIOLockstep*);
|
||||||
void GBASIOLockstepDeinit(struct GBASIOLockstep*);
|
void GBASIOLockstepDeinit(struct GBASIOLockstep*);
|
||||||
|
|
||||||
void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode*);
|
void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode*);
|
||||||
|
|
||||||
bool GBASIOLockstepAttachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*);
|
bool GBASIOLockstepAttachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*);
|
||||||
|
void GBASIOLockstepDetachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue