]> Chaos Git - corbenik/ctrulib.git/commitdiff
gsp: Added gspAllocLinear() to allocate from LINEAR heap
authorplutoo <plutoo@univor.se>
Mon, 25 Aug 2014 21:11:53 +0000 (23:11 +0200)
committerplutoo <plutoo@univor.se>
Mon, 25 Aug 2014 21:11:53 +0000 (23:11 +0200)
Required by CSND, for example

libctru/include/3ds/CSND.h
libctru/include/3ds/gfx.h
libctru/source/gfx.c

index 3909cdcba9fa2aaf52a50993f3eb84973652ed2d..6ac0b89e63fef442a05e8c094f4b799935928c49 100644 (file)
@@ -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);
index 27f941b228a779e2459bdd77ac4616df94747e20..4f8c650b34e199b1057449e4ce246a8e4f7cfa74 100644 (file)
@@ -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];
index 0b5422d0d3ce462daa706448357138e0d10e2b1d..fa6fa78e310022becc07995b7e462211e88afa1d 100644 (file)
@@ -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