move some memory to high MEM2 for performance boost

This commit is contained in:
dborth 2010-07-17 06:54:28 +00:00
parent 64686c5b62
commit 238d32ec71
5 changed files with 79 additions and 12 deletions

View File

@ -35,7 +35,7 @@
#define THREAD_SLEEP 100 #define THREAD_SLEEP 100
unsigned char savebuffer[SAVEBUFFERSIZE] ATTRIBUTE_ALIGN(32); unsigned char *savebuffer;
static mutex_t bufferLock = LWP_MUTEX_NULL; static mutex_t bufferLock = LWP_MUTEX_NULL;
FILE * file; // file pointer - the only one we should ever use! FILE * file; // file pointer - the only one we should ever use!
bool unmountRequired[7] = { false, false, false, false, false, false, false }; bool unmountRequired[7] = { false, false, false, false, false, false, false };

View File

@ -40,7 +40,7 @@ size_t LoadSzFile(char * filepath, unsigned char * rbuffer);
size_t SaveFile(char * buffer, char *filepath, size_t datasize, bool silent); size_t SaveFile(char * buffer, char *filepath, size_t datasize, bool silent);
size_t SaveFile(char * filepath, size_t datasize, bool silent); size_t SaveFile(char * filepath, size_t datasize, bool silent);
extern unsigned char savebuffer[]; extern unsigned char *savebuffer;
extern FILE * file; extern FILE * file;
extern bool unmountRequired[]; extern bool unmountRequired[];
extern bool isMounted[]; extern bool isMounted[];

43
source/mem2.cpp Normal file
View File

@ -0,0 +1,43 @@
/****************************************************************************
* Visual Boy Advance GX
*
* Tantric 2010
*
* mem2.cpp
*
* MEM2 memory allocator
***************************************************************************/
#ifdef HW_RVL
#include <ogc/machine/asm.h>
#include <ogc/lwp_heap.h>
#include <ogc/system.h>
#include <ogc/machine/processor.h>
static heap_cntrl mem2_heap;
u32 InitMem2Manager ()
{
int size = (36*1024*1024);
u32 level;
_CPU_ISR_Disable(level);
size &= ~0x1f; // round down, because otherwise we may exceed the area
void *mem2_heap_ptr = (void *)((u32)SYS_GetArena2Hi()-size);
SYS_SetArena2Hi(mem2_heap_ptr);
_CPU_ISR_Restore(level);
size = __lwp_heap_init(&mem2_heap, mem2_heap_ptr, size, 32);
return size;
}
void* mem2_malloc(u32 size)
{
return __lwp_heap_allocate(&mem2_heap, size);
}
bool mem2_free(void *ptr)
{
return __lwp_heap_free(&mem2_heap, ptr);
}
#endif

22
source/mem2.h Normal file
View File

@ -0,0 +1,22 @@
/****************************************************************************
* Visual Boy Advance GX
*
* Tantric 2010
*
* mem2.h
*
* MEM2 memory allocator
***************************************************************************/
#ifdef HW_RVL
#ifndef _MEM2MANAGER_H_
#define _MEM2MANAGER_H_
u32 InitMem2Manager ();
void* mem2_malloc(u32 size);
bool mem2_free(void *ptr);
#endif
#endif

View File

@ -32,6 +32,7 @@
#include "input.h" #include "input.h"
#include "video.h" #include "video.h"
#include "gamesettings.h" #include "gamesettings.h"
#include "mem2.h"
#include "utils/usb2storage.h" #include "utils/usb2storage.h"
#include "utils/mload.h" #include "utils/mload.h"
#include "utils/FreeTypeGX.h" #include "utils/FreeTypeGX.h"
@ -377,20 +378,21 @@ int main(int argc, char *argv[])
InitialiseSound(); InitialiseSound();
InitialisePalette(); InitialisePalette();
DefaultSettings (); // Set defaults DefaultSettings (); // Set defaults
InitFreeType((u8*)font_ttf, font_ttf_size); // Initialize font system
// Initialize font system
InitFreeType((u8*)font_ttf, font_ttf_size);
gameScreenPng = (u8 *)malloc(512*1024);
browserList = (BROWSERENTRY *)malloc(sizeof(BROWSERENTRY)*MAX_BROWSER_SIZE);
InitGUIThreads();
// store path app was loaded from
#ifdef HW_RVL #ifdef HW_RVL
if(argc > 0 && argv[0] != NULL) if(argc > 0 && argv[0] != NULL)
CreateAppPath(argv[0]); CreateAppPath(argv[0]); // store path app was loaded from
rom = (u8 *)malloc(1024*1024*32); // allocate 32 MB to GBA ROM InitMem2Manager();
savebuffer = (unsigned char *)mem2_malloc(SAVEBUFFERSIZE);
browserList = (BROWSERENTRY *)mem2_malloc(sizeof(BROWSERENTRY)*MAX_BROWSER_SIZE);
rom = (u8 *)mem2_malloc(1024*1024*32); // allocate 32 MB to GBA ROM
#else
savebuffer = (unsigned char *)malloc(SAVEBUFFERSIZE);
browserList = (BROWSERENTRY *)malloc(sizeof(BROWSERENTRY)*MAX_BROWSER_SIZE);
#endif #endif
gameScreenPng = (u8 *)malloc(512*1024);
InitGUIThreads();
while(1) // main loop while(1) // main loop
{ {