Remove service handle parameter from GSPGPU IPC wrappers

This commit is contained in:
fincs 2015-09-06 18:04:03 +02:00
parent 053c71ad08
commit 1817f90c6d
6 changed files with 94 additions and 125 deletions

View File

@ -44,7 +44,7 @@ typedef enum
* *
* @note You should always call @ref gfxExit once done to free the memory and services * @note You should always call @ref gfxExit once done to free the memory and services
*/ */
void gfxInitDefault(); void gfxInitDefault(void);
/** /**
* @brief Initializes the LCD framebuffers * @brief Initializes the LCD framebuffers
@ -66,7 +66,7 @@ void gfxInit(GSP_FramebufferFormats topFormat, GSP_FramebufferFormats bottomForm
* *
* Just call it when you're done. * Just call it when you're done.
*/ */
void gfxExit(); void gfxExit(void);
///@} ///@}
///@name Control ///@name Control
@ -108,7 +108,7 @@ void gfxSetDoubleBuffering(gfxScreen_t screen, bool doubleBuffering);
* Use this if the data within your framebuffers changes a lot and that you want to make sure everything was updated correctly. * Use this if the data within your framebuffers changes a lot and that you want to make sure everything was updated correctly.
* This shouldn't be needed and has a significant overhead. * This shouldn't be needed and has a significant overhead.
*/ */
void gfxFlushBuffers(); void gfxFlushBuffers(void);
/** /**
* @brief Swaps the buffers and sets the gsp state * @brief Swaps the buffers and sets the gsp state
@ -117,7 +117,7 @@ void gfxFlushBuffers();
* LCD rendering should start as soon as the gsp state is set. * LCD rendering should start as soon as the gsp state is set.
* When using the GPU, call @ref gfxSwapBuffers instead. * When using the GPU, call @ref gfxSwapBuffers instead.
*/ */
void gfxSwapBuffers(); void gfxSwapBuffers(void);
/** /**
* @brief Swaps the framebuffers * @brief Swaps the framebuffers
@ -125,7 +125,7 @@ void gfxSwapBuffers();
* This is the version to be used with the GPU since the GPU will use the gsp shared memory, * This is the version to be used with the GPU since the GPU will use the gsp shared memory,
* so the gsp state mustn't be set directly by the user. * so the gsp state mustn't be set directly by the user.
*/ */
void gfxSwapBuffersGpu(); void gfxSwapBuffersGpu(void);
///@} ///@}

View File

@ -48,11 +48,11 @@ typedef enum
GSPEVENT_MAX, // 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(void);
void gspExit(); void gspExit(void);
Result gspInitEventHandler(Handle gspEvent, vu8* gspSharedMem, u8 gspThreadId); Result gspInitEventHandler(Handle gspEvent, vu8* gspSharedMem, u8 gspThreadId);
void gspExitEventHandler(); void gspExitEventHandler(void);
void gspWaitForEvent(GSP_Event id, bool nextEvent); void gspWaitForEvent(GSP_Event id, bool nextEvent);
#define gspWaitForPSC0() gspWaitForEvent(GSPEVENT_PSC0, false) #define gspWaitForPSC0() gspWaitForEvent(GSPEVENT_PSC0, false)
#define gspWaitForPSC1() gspWaitForEvent(GSPEVENT_PSC1, false) #define gspWaitForPSC1() gspWaitForEvent(GSPEVENT_PSC1, false)
@ -63,19 +63,19 @@ void gspWaitForEvent(GSP_Event id, bool nextEvent);
#define gspWaitForP3D() gspWaitForEvent(GSPEVENT_P3D, false) #define gspWaitForP3D() gspWaitForEvent(GSPEVENT_P3D, false)
#define gspWaitForDMA() gspWaitForEvent(GSPEVENT_DMA, false) #define gspWaitForDMA() gspWaitForEvent(GSPEVENT_DMA, false)
Result GSPGPU_AcquireRight(Handle *handle, u8 flags); Result GSPGPU_AcquireRight(u8 flags);
Result GSPGPU_ReleaseRight(Handle *handle); Result GSPGPU_ReleaseRight(void);
Result GSPGPU_ImportDisplayCaptureInfo(Handle* handle, GSP_CaptureInfo *captureinfo); Result GSPGPU_ImportDisplayCaptureInfo(GSP_CaptureInfo *captureinfo);
Result GSPGPU_SaveVramSysArea(Handle* handle); Result GSPGPU_SaveVramSysArea(void);
Result GSPGPU_RestoreVramSysArea(Handle* handle); Result GSPGPU_RestoreVramSysArea(void);
Result GSPGPU_SetLcdForceBlack(Handle *handle, u8 flags); Result GSPGPU_SetLcdForceBlack(u8 flags);
Result GSPGPU_SetBufferSwap(Handle* handle, u32 screenid, GSP_FramebufferInfo *framebufinfo); Result GSPGPU_SetBufferSwap(u32 screenid, GSP_FramebufferInfo *framebufinfo);
Result GSPGPU_FlushDataCache(Handle *handle, u8* adr, u32 size); Result GSPGPU_FlushDataCache(const void* adr, u32 size);
Result GSPGPU_InvalidateDataCache(Handle* handle, u8* adr, u32 size); Result GSPGPU_InvalidateDataCache(const void* adr, u32 size);
Result GSPGPU_WriteHWRegs(Handle *handle, u32 regAddr, u32* data, u8 size); Result GSPGPU_WriteHWRegs(u32 regAddr, u32* data, u8 size);
Result GSPGPU_WriteHWRegsWithMask(Handle* handle, u32 regAddr, u32* data, u8 datasize, u32* maskdata, u8 masksize); Result GSPGPU_WriteHWRegsWithMask(u32 regAddr, u32* data, u8 datasize, u32* maskdata, u8 masksize);
Result GSPGPU_ReadHWRegs(Handle *handle, u32 regAddr, u32* data, u8 size); Result GSPGPU_ReadHWRegs(u32 regAddr, u32* data, u8 size);
Result GSPGPU_RegisterInterruptRelayQueue(Handle *handle, Handle eventHandle, u32 flags, Handle* outMemHandle, u8* threadID); Result GSPGPU_RegisterInterruptRelayQueue(Handle eventHandle, u32 flags, Handle* outMemHandle, u8* threadID);
Result GSPGPU_UnregisterInterruptRelayQueue(Handle* handle); Result GSPGPU_UnregisterInterruptRelayQueue(void);
Result GSPGPU_TriggerCmdReqQueue(Handle *handle); Result GSPGPU_TriggerCmdReqQueue(void);
Result GSPGPU_SubmitGxCommand(u32* sharedGspCmdBuf, u32 gxCommand[0x8], Handle* handle); Result GSPGPU_SubmitGxCommand(u32* sharedGspCmdBuf, u32 gxCommand[0x8]);

View File

@ -45,7 +45,7 @@ GSP_FramebufferFormats gfxGetScreenFormat(gfxScreen_t screen) {
return botFormat; return botFormat;
} }
void gfxSetDoubleBuffering( gfxScreen_t screen, bool doubleBuffering) { void gfxSetDoubleBuffering(gfxScreen_t screen, bool doubleBuffering) {
doubleBuf[screen] = doubleBuffering ? 1 : 0; // make sure they're the integer values '1' and '0' doubleBuf[screen] = doubleBuffering ? 1 : 0; // make sure they're the integer values '1' and '0'
} }
@ -119,11 +119,11 @@ void gfxInit(GSP_FramebufferFormats topFormat, GSP_FramebufferFormats bottomForm
gfxSharedMemory=(u8*)0x10002000; gfxSharedMemory=(u8*)0x10002000;
GSPGPU_AcquireRight(NULL, 0x0); GSPGPU_AcquireRight(0x0);
//setup our gsp shared mem section //setup our gsp shared mem section
svcCreateEvent(&gspEvent, 0x0); svcCreateEvent(&gspEvent, 0x0);
GSPGPU_RegisterInterruptRelayQueue(NULL, gspEvent, 0x1, &gspSharedMemHandle, &gfxThreadID); GSPGPU_RegisterInterruptRelayQueue(gspEvent, 0x1, &gspSharedMemHandle, &gfxThreadID);
svcMapMemoryBlock(gspSharedMemHandle, (u32)gfxSharedMemory, 0x3, 0x10000000); svcMapMemoryBlock(gspSharedMemHandle, (u32)gfxSharedMemory, 0x3, 0x10000000);
// default gspHeap configuration : // default gspHeap configuration :
@ -164,16 +164,16 @@ void gfxInit(GSP_FramebufferFormats topFormat, GSP_FramebufferFormats bottomForm
gspInitEventHandler(gspEvent, (vu8*)gfxSharedMemory, gfxThreadID); gspInitEventHandler(gspEvent, (vu8*)gfxSharedMemory, gfxThreadID);
gspWaitForVBlank(); gspWaitForVBlank();
GSPGPU_SetLcdForceBlack(NULL, 0x0); GSPGPU_SetLcdForceBlack(0x0);
} }
void gfxInitDefault() { void gfxInitDefault(void) {
gfxInit(GSP_BGR8_OES,GSP_BGR8_OES,false); gfxInit(GSP_BGR8_OES,GSP_BGR8_OES,false);
} }
void gfxExit() void gfxExit(void)
{ {
if (screenFree == NULL ) return; if (screenFree == NULL) return;
// Exit event handler // Exit event handler
gspExitEventHandler(); gspExitEventHandler();
@ -189,12 +189,12 @@ void gfxExit()
//unmap GSP shared mem //unmap GSP shared mem
svcUnmapMemoryBlock(gspSharedMemHandle, 0x10002000); svcUnmapMemoryBlock(gspSharedMemHandle, 0x10002000);
GSPGPU_UnregisterInterruptRelayQueue(NULL); GSPGPU_UnregisterInterruptRelayQueue();
svcCloseHandle(gspSharedMemHandle); svcCloseHandle(gspSharedMemHandle);
svcCloseHandle(gspEvent); svcCloseHandle(gspEvent);
GSPGPU_ReleaseRight(NULL); GSPGPU_ReleaseRight();
gspExit(); gspExit();
@ -215,27 +215,27 @@ u8* gfxGetFramebuffer(gfxScreen_t screen, gfx3dSide_t side, u16* width, u16* hei
} }
} }
void gfxFlushBuffers() void gfxFlushBuffers(void)
{ {
u32 topSize = 400 * 240 * __get_bytes_per_pixel(gfxGetScreenFormat(GFX_TOP)); u32 topSize = 400 * 240 * __get_bytes_per_pixel(gfxGetScreenFormat(GFX_TOP));
u32 bottomSize = 320 * 240 * __get_bytes_per_pixel(gfxGetScreenFormat(GFX_BOTTOM)); u32 bottomSize = 320 * 240 * __get_bytes_per_pixel(gfxGetScreenFormat(GFX_BOTTOM));
GSPGPU_FlushDataCache(NULL, gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), topSize); GSPGPU_FlushDataCache(gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), topSize);
if(enable3d)GSPGPU_FlushDataCache(NULL, gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL), topSize); if(enable3d)GSPGPU_FlushDataCache(gfxGetFramebuffer(GFX_TOP, GFX_RIGHT, NULL, NULL), topSize);
GSPGPU_FlushDataCache(NULL, gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL), bottomSize); GSPGPU_FlushDataCache(gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL), bottomSize);
} }
void gfxSwapBuffers() void gfxSwapBuffers(void)
{ {
currentBuffer[0]^=doubleBuf[0]; currentBuffer[0]^=doubleBuf[0];
currentBuffer[1]^=doubleBuf[1]; currentBuffer[1]^=doubleBuf[1];
gfxSetFramebufferInfo(GFX_TOP, currentBuffer[0]); gfxSetFramebufferInfo(GFX_TOP, currentBuffer[0]);
gfxSetFramebufferInfo(GFX_BOTTOM, currentBuffer[1]); gfxSetFramebufferInfo(GFX_BOTTOM, currentBuffer[1]);
GSPGPU_SetBufferSwap(NULL, GFX_TOP, &topFramebufferInfo); GSPGPU_SetBufferSwap(GFX_TOP, &topFramebufferInfo);
GSPGPU_SetBufferSwap(NULL, GFX_BOTTOM, &bottomFramebufferInfo); GSPGPU_SetBufferSwap(GFX_BOTTOM, &bottomFramebufferInfo);
} }
void gfxSwapBuffersGpu() void gfxSwapBuffersGpu(void)
{ {
currentBuffer[0]^=doubleBuf[0]; currentBuffer[0]^=doubleBuf[0];
currentBuffer[1]^=doubleBuf[1]; currentBuffer[1]^=doubleBuf[1];

View File

@ -20,7 +20,7 @@ Result GX_RequestDma(u32* src, u32* dst, u32 length)
gxCommand[3]=length; //size gxCommand[3]=length; //size
gxCommand[4]=gxCommand[5]=gxCommand[6]=gxCommand[7]=0x0; gxCommand[4]=gxCommand[5]=gxCommand[6]=gxCommand[7]=0x0;
return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand, NULL); return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand);
} }
Result GX_SetCommandList_Last(u32* buf0a, u32 buf0s, u8 flags) Result GX_SetCommandList_Last(u32* buf0a, u32 buf0s, u8 flags)
@ -33,7 +33,7 @@ Result GX_SetCommandList_Last(u32* buf0a, u32 buf0s, u8 flags)
gxCommand[4]=gxCommand[5]=gxCommand[6]=0x0; gxCommand[4]=gxCommand[5]=gxCommand[6]=0x0;
gxCommand[7]=(flags>>1)&1; //when non-zero, call svcFlushProcessDataCache() with the specified buffer gxCommand[7]=(flags>>1)&1; //when non-zero, call svcFlushProcessDataCache() with the specified buffer
return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand, NULL); return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand);
} }
Result GX_SetMemoryFill(u32* buf0a, u32 buf0v, u32* buf0e, u16 control0, u32* buf1a, u32 buf1v, u32* buf1e, u16 control1) Result GX_SetMemoryFill(u32* buf0a, u32 buf0v, u32* buf0e, u16 control0, u32* buf1a, u32 buf1v, u32* buf1e, u16 control1)
@ -49,7 +49,7 @@ Result GX_SetMemoryFill(u32* buf0a, u32 buf0v, u32* buf0e, u16 control0, u32* bu
gxCommand[6]=(u32)buf1e; //buf1 end addr gxCommand[6]=(u32)buf1e; //buf1 end addr
gxCommand[7]=(control0)|(control1<<16); gxCommand[7]=(control0)|(control1<<16);
return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand, NULL); return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand);
} }
// Flags, for applications this is 0x1001000 for the main screen, and 0x1000 for the sub screen. // Flags, for applications this is 0x1001000 for the main screen, and 0x1000 for the sub screen.
@ -64,7 +64,7 @@ Result GX_SetDisplayTransfer(u32* inadr, u32 indim, u32* outadr, u32 outdim, u32
gxCommand[5]=flags; gxCommand[5]=flags;
gxCommand[6]=gxCommand[7]=0x0; gxCommand[6]=gxCommand[7]=0x0;
return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand, NULL); return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand);
} }
Result GX_SetTextureCopy(u32* inadr, u32 indim, u32* outadr, u32 outdim, u32 size, u32 flags) Result GX_SetTextureCopy(u32* inadr, u32 indim, u32* outadr, u32 outdim, u32 size, u32 flags)
@ -79,7 +79,7 @@ Result GX_SetTextureCopy(u32* inadr, u32 indim, u32* outadr, u32 outdim, u32 siz
gxCommand[6]=flags; gxCommand[6]=flags;
gxCommand[7]=0x0; gxCommand[7]=0x0;
return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand, NULL); return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand);
} }
Result GX_SetCommandList_First(u32* buf0a, u32 buf0s, u32* buf1a, u32 buf1s, u32* buf2a, u32 buf2s) Result GX_SetCommandList_First(u32* buf0a, u32 buf0s, u32* buf1a, u32 buf1s, u32* buf2a, u32 buf2s)
@ -94,5 +94,5 @@ Result GX_SetCommandList_First(u32* buf0a, u32 buf0s, u32* buf1a, u32 buf1s, u32
gxCommand[6]=(u32)buf2s; //buf2 size gxCommand[6]=(u32)buf2s; //buf2 size
gxCommand[7]=0x0; gxCommand[7]=0x0;
return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand, NULL); return GSPGPU_SubmitGxCommand(gxCmdBuf, gxCommand);
} }

View File

@ -106,7 +106,7 @@ void aptInitCaptureInfo(u32 *ns_capinfo)
memset(&gspcapinfo, 0, sizeof(GSP_CaptureInfo)); memset(&gspcapinfo, 0, sizeof(GSP_CaptureInfo));
// Get display-capture info from GSP. // Get display-capture info from GSP.
GSPGPU_ImportDisplayCaptureInfo(NULL, &gspcapinfo); GSPGPU_ImportDisplayCaptureInfo(&gspcapinfo);
// Fill in display-capture info for NS. // Fill in display-capture info for NS.
if(gspcapinfo.screencapture[0].framebuf0_vaddr != gspcapinfo.screencapture[0].framebuf1_vaddr)ns_capinfo[1] = 1; if(gspcapinfo.screencapture[0].framebuf0_vaddr != gspcapinfo.screencapture[0].framebuf1_vaddr)ns_capinfo[1] = 1;
@ -212,7 +212,7 @@ void aptReturnToMenu(void)
aptCloseSession(); aptCloseSession();
// Save Vram // Save Vram
GSPGPU_SaveVramSysArea(NULL); GSPGPU_SaveVramSysArea();
// Capture screen. // Capture screen.
memset(__ns_capinfo, 0, 0x20); memset(__ns_capinfo, 0, 0x20);
@ -231,7 +231,7 @@ void aptReturnToMenu(void)
aptCloseSession(); aptCloseSession();
// Release GSP module. // Release GSP module.
GSPGPU_ReleaseRight(NULL); GSPGPU_ReleaseRight();
// Jump to menu! // Jump to menu!
aptOpenSession(); aptOpenSession();
@ -296,8 +296,8 @@ void aptAppletClosed(void)
{ {
aptAppletUtility_Exit_RetToApp(1); aptAppletUtility_Exit_RetToApp(1);
GSPGPU_AcquireRight(NULL, 0x0); GSPGPU_AcquireRight(0x0);
GSPGPU_RestoreVramSysArea(NULL); GSPGPU_RestoreVramSysArea();
svcClearEvent(aptStatusEvent); svcClearEvent(aptStatusEvent);
aptSetStatus(APP_RUNNING); aptSetStatus(APP_RUNNING);
@ -361,7 +361,7 @@ static void __handle_notification(void) {
case APTSIGNAL_WAKEUP: case APTSIGNAL_WAKEUP:
if(aptGetStatus() == APP_SLEEPMODE) if(aptGetStatus() == APP_SLEEPMODE)
{ {
if(aptStatusBeforeSleep == APP_RUNNING)GSPGPU_SetLcdForceBlack(NULL, 0); if(aptStatusBeforeSleep == APP_RUNNING)GSPGPU_SetLcdForceBlack(0);
// Restore old aptStatus. // Restore old aptStatus.
aptSetStatus(aptStatusBeforeSleep); aptSetStatus(aptStatusBeforeSleep);
@ -397,8 +397,8 @@ static bool __handle_incoming_parameter(void) {
case 0xB: // Just returned from menu. case 0xB: // Just returned from menu.
if (aptStatusMutex) if (aptStatusMutex)
{ {
GSPGPU_AcquireRight(NULL, 0x0); GSPGPU_AcquireRight(0x0);
GSPGPU_RestoreVramSysArea(NULL); GSPGPU_RestoreVramSysArea();
aptAppletUtility_Exit_RetToApp(0); aptAppletUtility_Exit_RetToApp(0);
aptSetStatus(APP_RUNNING); aptSetStatus(APP_RUNNING);
} else } else
@ -1230,7 +1230,7 @@ Result APT_LaunchLibraryApplet(NS_APPID appID, Handle inhandle, u32 *parambuf, u
aptSetStatus(APP_SUSPENDED); aptSetStatus(APP_SUSPENDED);
// Save Vram // Save Vram
GSPGPU_SaveVramSysArea(NULL); GSPGPU_SaveVramSysArea();
// Capture screen. // Capture screen.
memset(__ns_capinfo, 0, 0x20); memset(__ns_capinfo, 0, 0x20);
@ -1243,7 +1243,7 @@ Result APT_LaunchLibraryApplet(NS_APPID appID, Handle inhandle, u32 *parambuf, u
aptCloseSession(); aptCloseSession();
// Release GSP module. // Release GSP module.
GSPGPU_ReleaseRight(NULL); GSPGPU_ReleaseRight();
return 0; return 0;
} }

View File

@ -23,13 +23,12 @@ static vu8* gspEventData;
static void gspEventThreadMain(void *arg); static void gspEventThreadMain(void *arg);
Result gspInit(void)
Result gspInit()
{ {
return srvGetServiceHandle(&gspGpuHandle, "gsp::Gpu"); return srvGetServiceHandle(&gspGpuHandle, "gsp::Gpu");
} }
void gspExit() void gspExit(void)
{ {
if(gspGpuHandle)svcCloseHandle(gspGpuHandle); if(gspGpuHandle)svcCloseHandle(gspGpuHandle);
} }
@ -58,7 +57,7 @@ Result gspInitEventHandler(Handle _gspEvent, vu8* _gspSharedMem, u8 gspThreadId)
return svcCreateThread(&gspEventThread, gspEventThreadMain, 0x0, (u32*)((char*)gspEventStack + sizeof(gspEventStack)), 0x31, 0xfffffffe); return svcCreateThread(&gspEventThread, gspEventThreadMain, 0x0, (u32*)((char*)gspEventStack + sizeof(gspEventStack)), 0x31, 0xfffffffe);
} }
void gspExitEventHandler() void gspExitEventHandler(void)
{ {
// Stop event thread // Stop event thread
gspRunEvents = false; gspRunEvents = false;
@ -111,10 +110,8 @@ void gspEventThreadMain(void *arg)
svcExitThread(); svcExitThread();
} }
Result GSPGPU_WriteHWRegs(Handle* handle, u32 regAddr, u32* data, u8 size) Result GSPGPU_WriteHWRegs(u32 regAddr, u32* data, u8 size)
{ {
if(!handle)handle=&gspGpuHandle;
if(size>0x80 || !data)return -1; if(size>0x80 || !data)return -1;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
@ -125,15 +122,13 @@ Result GSPGPU_WriteHWRegs(Handle* handle, u32 regAddr, u32* data, u8 size)
cmdbuf[4]=(u32)data; cmdbuf[4]=(u32)data;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result GSPGPU_WriteHWRegsWithMask(Handle* handle, u32 regAddr, u32* data, u8 datasize, u32* maskdata, u8 masksize) Result GSPGPU_WriteHWRegsWithMask(u32 regAddr, u32* data, u8 datasize, u32* maskdata, u8 masksize)
{ {
if(!handle)handle=&gspGpuHandle;
if(datasize>0x80 || !data)return -1; if(datasize>0x80 || !data)return -1;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
@ -146,15 +141,13 @@ Result GSPGPU_WriteHWRegsWithMask(Handle* handle, u32 regAddr, u32* data, u8 dat
cmdbuf[6]=(u32)maskdata; cmdbuf[6]=(u32)maskdata;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result GSPGPU_ReadHWRegs(Handle* handle, u32 regAddr, u32* data, u8 size) Result GSPGPU_ReadHWRegs(u32 regAddr, u32* data, u8 size)
{ {
if(!handle)handle=&gspGpuHandle;
if(size>0x80 || !data)return -1; if(size>0x80 || !data)return -1;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
@ -165,31 +158,27 @@ Result GSPGPU_ReadHWRegs(Handle* handle, u32 regAddr, u32* data, u8 size)
cmdbuf[0x40+1]=(u32)data; cmdbuf[0x40+1]=(u32)data;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result GSPGPU_SetBufferSwap(Handle* handle, u32 screenid, GSP_FramebufferInfo *framebufinfo) Result GSPGPU_SetBufferSwap(u32 screenid, GSP_FramebufferInfo *framebufinfo)
{ {
Result ret=0;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
if(!handle)handle=&gspGpuHandle;
cmdbuf[0] = 0x00050200; cmdbuf[0] = 0x00050200;
cmdbuf[1] = screenid; cmdbuf[1] = screenid;
memcpy(&cmdbuf[2], framebufinfo, sizeof(GSP_FramebufferInfo)); memcpy(&cmdbuf[2], framebufinfo, sizeof(GSP_FramebufferInfo));
if((ret=svcSendSyncRequest(*handle)))return ret; Result ret=0;
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result GSPGPU_FlushDataCache(Handle* handle, u8* adr, u32 size) Result GSPGPU_FlushDataCache(const void* adr, u32 size)
{ {
if(!handle)handle=&gspGpuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x00080082; //request header code cmdbuf[0]=0x00080082; //request header code
cmdbuf[1]=(u32)adr; cmdbuf[1]=(u32)adr;
@ -198,60 +187,52 @@ Result GSPGPU_FlushDataCache(Handle* handle, u8* adr, u32 size)
cmdbuf[4]=0xffff8001; cmdbuf[4]=0xffff8001;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result GSPGPU_InvalidateDataCache(Handle* handle, u8* adr, u32 size) Result GSPGPU_InvalidateDataCache(const void* adr, u32 size)
{ {
Result ret=0;
u32 *cmdbuf = getThreadCommandBuffer(); u32 *cmdbuf = getThreadCommandBuffer();
if(!handle)handle=&gspGpuHandle;
cmdbuf[0] = 0x00090082; cmdbuf[0] = 0x00090082;
cmdbuf[1] = (u32)adr; cmdbuf[1] = (u32)adr;
cmdbuf[2] = size; cmdbuf[2] = size;
cmdbuf[3] = 0; cmdbuf[3] = 0;
cmdbuf[4] = 0xFFFF8001; cmdbuf[4] = 0xFFFF8001;
if((ret=svcSendSyncRequest(*handle)))return ret; Result ret=0;
if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result GSPGPU_SetLcdForceBlack(Handle* handle, u8 flags) Result GSPGPU_SetLcdForceBlack(u8 flags)
{ {
if(!handle)handle=&gspGpuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x000B0040; //request header code cmdbuf[0]=0x000B0040; //request header code
cmdbuf[1]=flags; cmdbuf[1]=flags;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result GSPGPU_TriggerCmdReqQueue(Handle* handle) Result GSPGPU_TriggerCmdReqQueue(void)
{ {
if(!handle)handle=&gspGpuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x000C0000; //request header code cmdbuf[0]=0x000C0000; //request header code
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result GSPGPU_RegisterInterruptRelayQueue(Handle* handle, Handle eventHandle, u32 flags, Handle* outMemHandle, u8* threadID) Result GSPGPU_RegisterInterruptRelayQueue(Handle eventHandle, u32 flags, Handle* outMemHandle, u8* threadID)
{ {
if(!handle)handle=&gspGpuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x00130042; //request header code cmdbuf[0]=0x00130042; //request header code
cmdbuf[1]=flags; cmdbuf[1]=flags;
@ -259,7 +240,7 @@ Result GSPGPU_RegisterInterruptRelayQueue(Handle* handle, Handle eventHandle, u3
cmdbuf[3]=eventHandle; cmdbuf[3]=eventHandle;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
if(threadID)*threadID=cmdbuf[2]; if(threadID)*threadID=cmdbuf[2];
if(outMemHandle)*outMemHandle=cmdbuf[4]; if(outMemHandle)*outMemHandle=cmdbuf[4];
@ -267,23 +248,19 @@ Result GSPGPU_RegisterInterruptRelayQueue(Handle* handle, Handle eventHandle, u3
return cmdbuf[1]; return cmdbuf[1];
} }
Result GSPGPU_UnregisterInterruptRelayQueue(Handle* handle) Result GSPGPU_UnregisterInterruptRelayQueue(void)
{ {
if(!handle)handle=&gspGpuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x00140000; //request header code cmdbuf[0]=0x00140000; //request header code
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result GSPGPU_AcquireRight(Handle* handle, u8 flags) Result GSPGPU_AcquireRight(u8 flags)
{ {
if(!handle)handle=&gspGpuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x160042; //request header code cmdbuf[0]=0x160042; //request header code
cmdbuf[1]=flags; cmdbuf[1]=flags;
@ -291,33 +268,29 @@ Result GSPGPU_AcquireRight(Handle* handle, u8 flags)
cmdbuf[3]=0xffff8001; cmdbuf[3]=0xffff8001;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result GSPGPU_ReleaseRight(Handle* handle) Result GSPGPU_ReleaseRight(void)
{ {
if(!handle)handle=&gspGpuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x170000; //request header code cmdbuf[0]=0x170000; //request header code
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result GSPGPU_ImportDisplayCaptureInfo(Handle* handle, GSP_CaptureInfo *captureinfo) Result GSPGPU_ImportDisplayCaptureInfo(GSP_CaptureInfo *captureinfo)
{ {
if(!handle)handle=&gspGpuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x00180000; //request header code cmdbuf[0]=0x00180000; //request header code
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
ret = cmdbuf[1]; ret = cmdbuf[1];
@ -329,28 +302,24 @@ Result GSPGPU_ImportDisplayCaptureInfo(Handle* handle, GSP_CaptureInfo *capturei
return ret; return ret;
} }
Result GSPGPU_SaveVramSysArea(Handle* handle) Result GSPGPU_SaveVramSysArea(void)
{ {
if(!handle)handle=&gspGpuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x00190000; //request header code cmdbuf[0]=0x00190000; //request header code
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result GSPGPU_RestoreVramSysArea(Handle* handle) Result GSPGPU_RestoreVramSysArea(void)
{ {
if(!handle)handle=&gspGpuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x001A0000; //request header code cmdbuf[0]=0x001A0000; //request header code
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(gspGpuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
@ -358,7 +327,7 @@ Result GSPGPU_RestoreVramSysArea(Handle* handle)
//essentially : get commandIndex and totalCommands, calculate offset of new command, copy command and update totalCommands //essentially : get commandIndex and totalCommands, calculate offset of new command, copy command and update totalCommands
//use LDREX/STREX because this data may also be accessed by the GSP module and we don't want to break stuff //use LDREX/STREX because this data may also be accessed by the GSP module and we don't want to break stuff
//(mostly, we could overwrite the buffer header with wrong data and make the GSP module reexecute old commands) //(mostly, we could overwrite the buffer header with wrong data and make the GSP module reexecute old commands)
Result GSPGPU_SubmitGxCommand(u32* sharedGspCmdBuf, u32 gxCommand[0x8], Handle* handle) Result GSPGPU_SubmitGxCommand(u32* sharedGspCmdBuf, u32 gxCommand[0x8])
{ {
if(!sharedGspCmdBuf || !gxCommand)return -1; if(!sharedGspCmdBuf || !gxCommand)return -1;
@ -390,6 +359,6 @@ Result GSPGPU_SubmitGxCommand(u32* sharedGspCmdBuf, u32 gxCommand[0x8], Handle*
cmdBufHeader=((cmdBufHeader)&0xFFFF00FF)|((totalCommands<<8)&0xFF00); cmdBufHeader=((cmdBufHeader)&0xFFFF00FF)|((totalCommands<<8)&0xFF00);
} }
if(totalCommands==1)return GSPGPU_TriggerCmdReqQueue(handle); if(totalCommands==1)return GSPGPU_TriggerCmdReqQueue();
return 0; return 0;
} }