From dc052c19eef829038afde1ff14abd400b4d261a0 Mon Sep 17 00:00:00 2001 From: plutoo Date: Mon, 25 Aug 2014 23:11:53 +0200 Subject: [PATCH] gsp: Added gspAllocLinear() to allocate from LINEAR heap Required by CSND, for example --- libctru/include/3ds/CSND.h | 13 +++++++++++++ libctru/include/3ds/gfx.h | 1 + libctru/source/gfx.c | 33 +++++++++++++++++++++++++-------- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/libctru/include/3ds/CSND.h b/libctru/include/3ds/CSND.h index 3909cdc..6ac0b89 100644 --- a/libctru/include/3ds/CSND.h +++ b/libctru/include/3ds/CSND.h @@ -3,6 +3,19 @@ #define CSND_SHAREDMEM_DEFAULT 0x10004000 +typedef enum{ + CSND_LOOP_DISABLE, + CSND_LOOP_ENABLE +} CSND_LOOPING; + +typedef enum{ + CSND_ENCODING_PCM8, + CSND_ENCODING_PCM16, + CSND_ENCODING_IMA_ADPCM, + CSND_ENCODING_PSG//"3 = PSG, similar to DS?" +} CSND_ENCODING; + + //See here regarding CSND shared-mem commands, etc: http://3dbrew.org/wiki/CSND_Shared_Memory Result CSND_initialize(u32* sharedMem); diff --git a/libctru/include/3ds/gfx.h b/libctru/include/3ds/gfx.h index 27f941b..4f8c650 100644 --- a/libctru/include/3ds/gfx.h +++ b/libctru/include/3ds/gfx.h @@ -27,6 +27,7 @@ void gfxSwapBuffers(); //helper stuff u8* gfxGetFramebuffer(gfxScreen_t screen, gfx3dSide_t side, u16* width, u16* height); +void* gfxAllocLinear(size_t size); //global variables extern u8* gfxTopLeftFramebuffers[2]; diff --git a/libctru/source/gfx.c b/libctru/source/gfx.c index 0b5422d..fa6fa78 100644 --- a/libctru/source/gfx.c +++ b/libctru/source/gfx.c @@ -21,6 +21,25 @@ Handle gspEvent, gspSharedMemHandle; u8* gspHeap; u32* gxCmdBuf; +extern u32 __gsp_heap_size; + + + +// TODO: this function is not thread-safe and you cannot 'free' this memory. +void* gfxAllocLinear(size_t size) +{ + static size_t currentOffset = 0; + size_t free = __gsp_heap_size - currentOffset; + + if(free >= size) + { + currentOffset += size; + return (void*) &gspHeap[currentOffset - size]; + } + + return NULL; +} + void gfxSet3D(bool enable) { @@ -51,8 +70,6 @@ void gfxSetFramebufferInfo(gfxScreen_t screen, u8 id) } } -extern u32 __gsp_heap_size; - void gfxInit() { gspInit(); @@ -78,12 +95,12 @@ void gfxInit() // topright1 0x000FD200-0x00143700 // topright2 0x00143700-0x00189C00 - gfxTopLeftFramebuffers[0]=(u8*)gspHeap; - gfxTopLeftFramebuffers[1]=gfxTopLeftFramebuffers[0]+0x46500; - gfxBottomFramebuffers[0]=gfxTopLeftFramebuffers[1]+0x46500; - gfxBottomFramebuffers[1]=gfxBottomFramebuffers[0]+0x38400; - gfxTopRightFramebuffers[0]=gfxBottomFramebuffers[1]+0x38400; - gfxTopRightFramebuffers[1]=gfxTopRightFramebuffers[0]+0x46500; + gfxTopLeftFramebuffers[0]=gfxAllocLinear(0x46500); + gfxTopLeftFramebuffers[1]=gfxAllocLinear(0x46500); + gfxBottomFramebuffers[0]=gfxAllocLinear(0x38400); + gfxBottomFramebuffers[1]=gfxAllocLinear(0x38400); + gfxTopRightFramebuffers[0]=gfxAllocLinear(0x46500); + gfxTopRightFramebuffers[1]=gfxAllocLinear(0x46500); enable3d=false; //initialize framebuffer info structures