gsp: Added gspAllocLinear() to allocate from LINEAR heap

Required by CSND, for example
This commit is contained in:
plutoo 2014-08-25 23:11:53 +02:00
parent fa18d4750b
commit dc052c19ee
3 changed files with 39 additions and 8 deletions

View File

@ -3,6 +3,19 @@
#define CSND_SHAREDMEM_DEFAULT 0x10004000 #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 //See here regarding CSND shared-mem commands, etc: http://3dbrew.org/wiki/CSND_Shared_Memory
Result CSND_initialize(u32* sharedMem); Result CSND_initialize(u32* sharedMem);

View File

@ -27,6 +27,7 @@ void gfxSwapBuffers();
//helper stuff //helper stuff
u8* gfxGetFramebuffer(gfxScreen_t screen, gfx3dSide_t side, u16* width, u16* height); u8* gfxGetFramebuffer(gfxScreen_t screen, gfx3dSide_t side, u16* width, u16* height);
void* gfxAllocLinear(size_t size);
//global variables //global variables
extern u8* gfxTopLeftFramebuffers[2]; extern u8* gfxTopLeftFramebuffers[2];

View File

@ -21,6 +21,25 @@ Handle gspEvent, gspSharedMemHandle;
u8* gspHeap; u8* gspHeap;
u32* gxCmdBuf; 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) void gfxSet3D(bool enable)
{ {
@ -51,8 +70,6 @@ void gfxSetFramebufferInfo(gfxScreen_t screen, u8 id)
} }
} }
extern u32 __gsp_heap_size;
void gfxInit() void gfxInit()
{ {
gspInit(); gspInit();
@ -78,12 +95,12 @@ void gfxInit()
// topright1 0x000FD200-0x00143700 // topright1 0x000FD200-0x00143700
// topright2 0x00143700-0x00189C00 // topright2 0x00143700-0x00189C00
gfxTopLeftFramebuffers[0]=(u8*)gspHeap; gfxTopLeftFramebuffers[0]=gfxAllocLinear(0x46500);
gfxTopLeftFramebuffers[1]=gfxTopLeftFramebuffers[0]+0x46500; gfxTopLeftFramebuffers[1]=gfxAllocLinear(0x46500);
gfxBottomFramebuffers[0]=gfxTopLeftFramebuffers[1]+0x46500; gfxBottomFramebuffers[0]=gfxAllocLinear(0x38400);
gfxBottomFramebuffers[1]=gfxBottomFramebuffers[0]+0x38400; gfxBottomFramebuffers[1]=gfxAllocLinear(0x38400);
gfxTopRightFramebuffers[0]=gfxBottomFramebuffers[1]+0x38400; gfxTopRightFramebuffers[0]=gfxAllocLinear(0x46500);
gfxTopRightFramebuffers[1]=gfxTopRightFramebuffers[0]+0x46500; gfxTopRightFramebuffers[1]=gfxAllocLinear(0x46500);
enable3d=false; enable3d=false;
//initialize framebuffer info structures //initialize framebuffer info structures