all repos — mgba @ 5b40951c05baa28ac43c84ffacfec6bd99692ed3

mGBA Game Boy Advance Emulator

GBA SIO: Build up lockstep driver a bit more
Jeffrey Pfau jeffrey@endrift.com
Thu, 26 Feb 2015 00:07:12 -0800
commit

5b40951c05baa28ac43c84ffacfec6bd99692ed3

parent

1e912abf4b77f9cce67ac844e3bcc6eab4a68b2b

2 files changed, 22 insertions(+), 0 deletions(-)

jump to
M src/gba/sio/lockstep.csrc/gba/sio/lockstep.c

@@ -21,10 +21,12 @@ lockstep->players[2] = 0;

lockstep->players[3] = 0; lockstep->attached = 0; ConditionInit(&lockstep->barrier); + MutexInit(&lockstep->mutex); } void GBASIOLockstepDeinit(struct GBASIOLockstep* lockstep) { ConditionDeinit(&lockstep->barrier); + MutexDeinit(&lockstep->mutex); } void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode* node) {

@@ -43,6 +45,23 @@ }

lockstep->players[lockstep->attached] = node; ++lockstep->attached; 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) {
M src/gba/sio/lockstep.hsrc/gba/sio/lockstep.h

@@ -15,6 +15,7 @@ struct GBASIOLockstepNode* players[MAX_GBAS];

int attached; uint16_t data[MAX_GBAS]; + Mutex mutex; Condition barrier; };

@@ -27,6 +28,8 @@ void GBASIOLockstepInit(struct GBASIOLockstep*);

void GBASIOLockstepDeinit(struct GBASIOLockstep*); void GBASIOLockstepNodeCreate(struct GBASIOLockstepNode*); + bool GBASIOLockstepAttachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*); +void GBASIOLockstepDetachNode(struct GBASIOLockstep*, struct GBASIOLockstepNode*); #endif