mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-06-06 02:58:18 -04:00
4df8ccc871
* Reorganize files into libs/{dolphin,JSystem,PowerPC_EABI_Support,revolution,TRK_MINNOW_DOLPHIN}
* Update configure.py and project.py for new libs structure
* Refactor `#include <dolphin/x.h>` -> `<x.h>`
* Remove `__REVOLUTION_SDK__` forwards from dolphin
* Fix dolphin/ references in revolution
* Wrap `#include <dolphin.h>` in `!__REVOLUTION_SDK__`
* Always build TRK against dolphin headers
* Resolve revolution SDK header resolution issues
71 lines
1.9 KiB
C
71 lines
1.9 KiB
C
#include <dolphin/dolphin.h>
|
|
#include <dolphin/os.h>
|
|
|
|
void OSInitMessageQueue(OSMessageQueue* mq, void* msgArray, s32 msgCount) {
|
|
OSInitThreadQueue(&mq->queueSend);
|
|
OSInitThreadQueue(&mq->queueReceive);
|
|
mq->msgArray = msgArray;
|
|
mq->msgCount = msgCount;
|
|
mq->firstIndex = 0;
|
|
mq->usedCount = 0;
|
|
}
|
|
|
|
int OSSendMessage(OSMessageQueue* mq, void* msg, s32 flags) {
|
|
BOOL enabled;
|
|
s32 lastIndex;
|
|
|
|
enabled = OSDisableInterrupts();
|
|
while(mq->msgCount <= mq->usedCount) {
|
|
if (!(flags & 1)) {
|
|
OSRestoreInterrupts(enabled);
|
|
return 0;
|
|
}
|
|
OSSleepThread(&mq->queueSend);
|
|
}
|
|
lastIndex = (mq->firstIndex + mq->usedCount) % mq->msgCount;
|
|
((u32*)mq->msgArray)[lastIndex] = (u32)msg;
|
|
mq->usedCount++;
|
|
OSWakeupThread(&mq->queueReceive);
|
|
OSRestoreInterrupts(enabled);
|
|
return 1;
|
|
}
|
|
|
|
int OSReceiveMessage(OSMessageQueue* mq, void* msg, s32 flags) {
|
|
BOOL enabled = OSDisableInterrupts();
|
|
|
|
while(mq->usedCount == 0) {
|
|
if (!(flags & 1)) {
|
|
OSRestoreInterrupts(enabled);
|
|
return 0;
|
|
}
|
|
OSSleepThread(&mq->queueReceive);
|
|
}
|
|
if(msg != NULL) {
|
|
*(u32*)msg = ((u32*)mq->msgArray)[mq->firstIndex];
|
|
}
|
|
|
|
mq->firstIndex = (mq->firstIndex + 1) % mq->msgCount;
|
|
mq->usedCount--;
|
|
OSWakeupThread(&mq->queueSend);
|
|
OSRestoreInterrupts(enabled);
|
|
return 1;
|
|
}
|
|
|
|
int OSJamMessage(OSMessageQueue* mq, void* msg, s32 flags) {
|
|
BOOL enabled = OSDisableInterrupts();
|
|
|
|
while(mq->msgCount <= mq->usedCount) {
|
|
if(!(flags & 1)) {
|
|
OSRestoreInterrupts(enabled);
|
|
return 0;
|
|
}
|
|
OSSleepThread(&mq->queueSend);
|
|
}
|
|
mq->firstIndex = (mq->firstIndex + mq->msgCount - 1) % mq->msgCount;
|
|
((u32*)mq->msgArray)[mq->firstIndex] = (u32)msg;
|
|
mq->usedCount++;
|
|
OSWakeupThread(&mq->queueReceive);
|
|
OSRestoreInterrupts(enabled);
|
|
return 1;
|
|
}
|