gspWaitForEvent(): add nextEvent parameter; GSPEVENT_count -> '_MAX

This commit is contained in:
fincs 2014-08-21 00:24:24 +02:00
parent 0d3ed55b88
commit af93d8e10c
2 changed files with 19 additions and 15 deletions

View File

@ -36,7 +36,8 @@ typedef enum
GSPEVENT_PPF, GSPEVENT_PPF,
GSPEVENT_P3D, GSPEVENT_P3D,
GSPEVENT_DMA, GSPEVENT_DMA,
GSPEVENT_count, // used to know how many events there are
GSPEVENT_MAX, // used to know how many events there are
} GSP_Event; } GSP_Event;
Result gspInit(); Result gspInit();
@ -44,15 +45,15 @@ void gspExit();
Result gspInitEventHandler(Handle gspEvent, vu8* gspSharedMem, u8 gspThreadId); Result gspInitEventHandler(Handle gspEvent, vu8* gspSharedMem, u8 gspThreadId);
void gspExitEventHandler(); void gspExitEventHandler();
void gspWaitForEvent(GSP_Event id); void gspWaitForEvent(GSP_Event id, bool nextEvent);
#define gspWaitForPSC0() gspWaitForEvent(GSPEVENT_PSC0) #define gspWaitForPSC0() gspWaitForEvent(GSPEVENT_PSC0, false)
#define gspWaitForPSC1() gspWaitForEvent(GSPEVENT_PSC1) #define gspWaitForPSC1() gspWaitForEvent(GSPEVENT_PSC1, false)
#define gspWaitForVBlank() gspWaitForVBlank0() #define gspWaitForVBlank() gspWaitForVBlank0()
#define gspWaitForVBlank0() gspWaitForEvent(GSPEVENT_VBlank0) #define gspWaitForVBlank0() gspWaitForEvent(GSPEVENT_VBlank0, true)
#define gspWaitForVBlank1() gspWaitForEvent(GSPEVENT_VBlank1) #define gspWaitForVBlank1() gspWaitForEvent(GSPEVENT_VBlank1, true)
#define gspWaitForPPF() gspWaitForEvent(GSPEVENT_PPF) #define gspWaitForPPF() gspWaitForEvent(GSPEVENT_PPF, false)
#define gspWaitForP3D() gspWaitForEvent(GSPEVENT_P3D) #define gspWaitForP3D() gspWaitForEvent(GSPEVENT_P3D, false)
#define gspWaitForDMA() gspWaitForEvent(GSPEVENT_DMA) #define gspWaitForDMA() gspWaitForEvent(GSPEVENT_DMA, false)
Result GSPGPU_AcquireRight(Handle *handle, u8 flags); Result GSPGPU_AcquireRight(Handle *handle, u8 flags);
Result GSPGPU_ReleaseRight(Handle *handle); Result GSPGPU_ReleaseRight(Handle *handle);

View File

@ -8,7 +8,7 @@
#define GSP_EVENT_STACK_SIZE 0x1000 #define GSP_EVENT_STACK_SIZE 0x1000
Handle gspGpuHandle=0; Handle gspGpuHandle=0;
Handle gspEvents[GSPEVENT_count]; Handle gspEvents[GSPEVENT_MAX];
u64 gspEventStack[GSP_EVENT_STACK_SIZE/sizeof(u64)]; //u64 so that it's 8-byte aligned u64 gspEventStack[GSP_EVENT_STACK_SIZE/sizeof(u64)]; //u64 so that it's 8-byte aligned
volatile bool gspRunEvents; volatile bool gspRunEvents;
Handle gspEventThread; Handle gspEventThread;
@ -32,7 +32,7 @@ Result gspInitEventHandler(Handle _gspEvent, vu8* _gspSharedMem, u8 gspThreadId)
{ {
// Create events // Create events
int i; int i;
for (i = 0; i < GSPEVENT_count; i ++) for (i = 0; i < GSPEVENT_MAX; i ++)
{ {
Result rc = svcCreateEvent(&gspEvents[i], 0); Result rc = svcCreateEvent(&gspEvents[i], 0);
if (rc != 0) if (rc != 0)
@ -60,14 +60,17 @@ void gspExitEventHandler()
// Free events // Free events
int i; int i;
for (i = 0; i < GSPEVENT_count; i ++) for (i = 0; i < GSPEVENT_MAX; i ++)
svcCloseHandle(gspEvents[i]); svcCloseHandle(gspEvents[i]);
} }
void gspWaitForEvent(GSP_Event id) void gspWaitForEvent(GSP_Event id, bool nextEvent)
{ {
svcClearEvent(gspEvents[id]); if (nextEvent)
svcClearEvent(gspEvents[id]);
svcWaitSynchronization(gspEvents[id], U64_MAX); svcWaitSynchronization(gspEvents[id], U64_MAX);
if (!nextEvent)
svcClearEvent(gspEvents[id]);
} }
void gspEventThreadMain(u32 arg) void gspEventThreadMain(u32 arg)
@ -87,7 +90,7 @@ void gspEventThreadMain(u32 arg)
int curEvt = gspEventData[0xC + cur]; int curEvt = gspEventData[0xC + cur];
cur --; cur --;
if (cur < 0) cur += 0x34; if (cur < 0) cur += 0x34;
if (curEvt >= GSPEVENT_count) continue; if (curEvt >= GSPEVENT_MAX) continue;
svcSignalEvent(gspEvents[curEvt]); svcSignalEvent(gspEvents[curEvt]);
} }