2014-07-28 21:41:48 +02:00
|
|
|
#include <3ds/types.h>
|
|
|
|
#include <3ds/srv.h>
|
|
|
|
#include <3ds/svc.h>
|
2014-10-27 01:08:55 +01:00
|
|
|
#include <3ds/gpu/gx.h>
|
|
|
|
#include <3ds/services/apt.h>
|
|
|
|
#include <3ds/services/gsp.h>
|
|
|
|
#include <3ds/services/hid.h>
|
|
|
|
#include <3ds/services/fs.h>
|
2014-01-24 23:33:46 +01:00
|
|
|
#include "costable.h"
|
|
|
|
|
|
|
|
u8* gspHeap;
|
|
|
|
u32* gxCmdBuf;
|
|
|
|
|
|
|
|
u8 currentBuffer;
|
|
|
|
u8* topLeftFramebuffers[2];
|
|
|
|
|
2014-02-03 18:06:58 +01:00
|
|
|
Handle gspEvent, gspSharedMemHandle;
|
|
|
|
|
2014-01-24 23:33:46 +01:00
|
|
|
void gspGpuInit()
|
|
|
|
{
|
2014-02-01 00:23:59 +01:00
|
|
|
gspInit();
|
2014-01-24 23:33:46 +01:00
|
|
|
|
2014-02-01 00:23:59 +01:00
|
|
|
GSPGPU_AcquireRight(NULL, 0x0);
|
|
|
|
GSPGPU_SetLcdForceBlack(NULL, 0x0);
|
2014-01-24 23:33:46 +01:00
|
|
|
|
|
|
|
//set subscreen to blue
|
|
|
|
u32 regData=0x01FF0000;
|
2014-03-02 16:06:34 +01:00
|
|
|
GSPGPU_WriteHWRegs(NULL, 0x202A04, ®Data, 4);
|
2014-01-24 23:33:46 +01:00
|
|
|
|
|
|
|
//grab main left screen framebuffer addresses
|
2014-03-02 16:06:34 +01:00
|
|
|
GSPGPU_ReadHWRegs(NULL, 0x400468, (u32*)&topLeftFramebuffers, 8);
|
2014-01-24 23:33:46 +01:00
|
|
|
|
|
|
|
//convert PA to VA (assuming FB in VRAM)
|
|
|
|
topLeftFramebuffers[0]+=0x7000000;
|
|
|
|
topLeftFramebuffers[1]+=0x7000000;
|
|
|
|
|
|
|
|
//setup our gsp shared mem section
|
|
|
|
u8 threadID;
|
2014-07-28 20:58:47 +02:00
|
|
|
svcCreateEvent(&gspEvent, 0x0);
|
2014-02-01 00:23:59 +01:00
|
|
|
GSPGPU_RegisterInterruptRelayQueue(NULL, gspEvent, 0x1, &gspSharedMemHandle, &threadID);
|
2014-07-28 20:58:47 +02:00
|
|
|
svcMapMemoryBlock(gspSharedMemHandle, 0x10002000, 0x3, 0x10000000);
|
2014-01-24 23:33:46 +01:00
|
|
|
|
|
|
|
//map GSP heap
|
2014-07-28 20:58:47 +02:00
|
|
|
svcControlMemory((u32*)&gspHeap, 0x0, 0x0, 0x2000000, 0x10003, 0x3);
|
2014-01-24 23:33:46 +01:00
|
|
|
|
|
|
|
//wait until we can write stuff to it
|
2014-10-27 01:08:55 +01:00
|
|
|
svcWaitSynchronization(gspEvent, 0x55bcb0);
|
2014-01-24 23:33:46 +01:00
|
|
|
|
|
|
|
//GSP shared mem : 0x2779F000
|
|
|
|
gxCmdBuf=(u32*)(0x10002000+0x800+threadID*0x200);
|
|
|
|
|
|
|
|
currentBuffer=0;
|
|
|
|
}
|
|
|
|
|
2014-02-03 18:06:58 +01:00
|
|
|
void gspGpuExit()
|
|
|
|
{
|
|
|
|
GSPGPU_UnregisterInterruptRelayQueue(NULL);
|
|
|
|
|
|
|
|
//unmap GSP shared mem
|
2014-07-28 20:58:47 +02:00
|
|
|
svcUnmapMemoryBlock(gspSharedMemHandle, 0x10002000);
|
|
|
|
svcCloseHandle(gspSharedMemHandle);
|
|
|
|
svcCloseHandle(gspEvent);
|
2014-02-03 18:06:58 +01:00
|
|
|
|
|
|
|
gspExit();
|
|
|
|
|
|
|
|
//free GSP heap
|
2014-07-28 20:58:47 +02:00
|
|
|
svcControlMemory((u32*)&gspHeap, (u32)gspHeap, 0x0, 0x2000000, MEMOP_FREE, 0x0);
|
2014-02-03 18:06:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-24 23:33:46 +01:00
|
|
|
void swapBuffers()
|
|
|
|
{
|
|
|
|
u32 regData;
|
2014-03-02 16:06:34 +01:00
|
|
|
GSPGPU_ReadHWRegs(NULL, 0x400478, ®Data, 4);
|
2014-01-24 23:33:46 +01:00
|
|
|
regData^=1;
|
|
|
|
currentBuffer=regData&1;
|
2014-03-02 16:06:34 +01:00
|
|
|
GSPGPU_WriteHWRegs(NULL, 0x400478, ®Data, 4);
|
2014-01-24 23:33:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void copyBuffer()
|
|
|
|
{
|
|
|
|
//copy topleft FB
|
|
|
|
u8 copiedBuffer=currentBuffer^1;
|
|
|
|
u8* bufAdr=&gspHeap[0x46500*copiedBuffer];
|
2014-02-01 00:23:59 +01:00
|
|
|
GSPGPU_FlushDataCache(NULL, bufAdr, 0x46500);
|
2014-03-02 16:11:04 +01:00
|
|
|
|
|
|
|
GX_RequestDma(gxCmdBuf, (u32*)bufAdr, (u32*)topLeftFramebuffers[copiedBuffer], 0x46500);
|
2014-01-24 23:33:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
s32 pcCos(u16 v)
|
|
|
|
{
|
|
|
|
return costable[v&0x1FF];
|
|
|
|
}
|
|
|
|
|
|
|
|
void renderEffect()
|
|
|
|
{
|
|
|
|
u8* bufAdr=&gspHeap[0x46500*currentBuffer];
|
|
|
|
|
|
|
|
if(!currentBuffer)return;
|
|
|
|
int i, j;
|
|
|
|
for(i=1;i<400;i++)
|
|
|
|
{
|
|
|
|
for(j=1;j<240;j++)
|
|
|
|
{
|
|
|
|
u32 v=(j+i*240)*3;
|
|
|
|
bufAdr[v]=(pcCos(i)+4096)/32;
|
|
|
|
bufAdr[v+1]=0x00;
|
|
|
|
bufAdr[v+2]=0xFF*currentBuffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2014-07-28 23:23:24 +02:00
|
|
|
srvInit();
|
2014-01-28 23:43:59 +01:00
|
|
|
|
2014-02-01 19:56:36 +01:00
|
|
|
aptInit(APPID_APPLICATION);
|
2014-01-24 23:33:46 +01:00
|
|
|
|
|
|
|
gspGpuInit();
|
|
|
|
|
2014-02-03 18:21:17 +01:00
|
|
|
hidInit(NULL);
|
2014-01-24 23:33:46 +01:00
|
|
|
|
|
|
|
Handle fsuHandle;
|
2014-07-28 23:23:24 +02:00
|
|
|
srvGetServiceHandle(&fsuHandle, "fs:USER");
|
2014-01-24 23:33:46 +01:00
|
|
|
FSUSER_Initialize(fsuHandle);
|
|
|
|
|
|
|
|
Handle fileHandle;
|
|
|
|
u32 bytesRead;
|
2014-10-27 15:59:14 +01:00
|
|
|
FS_archive sdmcArchive=(FS_archive){ARCH_SDMC, (FS_path){PATH_EMPTY, 1, (u8*)""}};
|
2014-01-24 23:33:46 +01:00
|
|
|
FS_path filePath=(FS_path){PATH_CHAR, 10, (u8*)"/test.bin"};
|
|
|
|
FSUSER_OpenFileDirectly(fsuHandle, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE);
|
|
|
|
FSFILE_Read(fileHandle, &bytesRead, 0x0, (u32*)gspHeap, 0x46500);
|
2014-02-03 18:06:58 +01:00
|
|
|
FSFILE_Close(fileHandle);
|
2014-02-01 00:23:59 +01:00
|
|
|
|
2014-05-20 21:49:03 +02:00
|
|
|
APP_STATUS status;
|
|
|
|
while((status=aptGetStatus())!=APP_EXITING)
|
2014-01-24 23:33:46 +01:00
|
|
|
{
|
2014-05-20 21:49:03 +02:00
|
|
|
if(status==APP_RUNNING)
|
|
|
|
{
|
|
|
|
u32 PAD=hidSharedMem[7];
|
|
|
|
renderEffect();
|
|
|
|
swapBuffers();
|
|
|
|
copyBuffer();
|
|
|
|
u32 regData=PAD|0x01000000;
|
|
|
|
GSPGPU_WriteHWRegs(NULL, 0x202A04, ®Data, 4);
|
2014-07-28 20:58:47 +02:00
|
|
|
svcSleepThread(1000000000);
|
2014-05-20 21:49:03 +02:00
|
|
|
}
|
|
|
|
else if(status == APP_SUSPENDING)
|
|
|
|
{
|
|
|
|
aptReturnToMenu();
|
|
|
|
}
|
|
|
|
else if(status == APP_SLEEPMODE)
|
|
|
|
{
|
|
|
|
aptWaitStatusEvent();
|
|
|
|
}
|
2014-01-24 23:33:46 +01:00
|
|
|
}
|
|
|
|
|
2014-07-28 20:58:47 +02:00
|
|
|
svcCloseHandle(fsuHandle);
|
2014-02-03 18:06:58 +01:00
|
|
|
hidExit();
|
2014-05-20 21:49:03 +02:00
|
|
|
gspGpuExit();
|
2014-02-01 13:27:52 +01:00
|
|
|
aptExit();
|
2014-07-28 20:58:47 +02:00
|
|
|
svcExitProcess();
|
2014-01-24 23:33:46 +01:00
|
|
|
return 0;
|
|
|
|
}
|