diff --git a/source/gui/video.cpp b/source/gui/video.cpp index 7ab74514..547f8894 100644 --- a/source/gui/video.cpp +++ b/source/gui/video.cpp @@ -3,6 +3,7 @@ #include #include "Gekko.h" #include "gecko.h" +#include "utils.h" #define DEFAULT_FIFO_SIZE (256 * 1024) @@ -145,7 +146,7 @@ void CVideo::init(void) VIDEO_WaitVSync(); if (m_rmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); - m_fifo = MEM1_memalign(32, DEFAULT_FIFO_SIZE); + m_fifo = MEM1_alloc(ALIGN32(DEFAULT_FIFO_SIZE)); memset(m_fifo, 0, DEFAULT_FIFO_SIZE); GX_Init(m_fifo, DEFAULT_FIFO_SIZE); GX_SetCopyClear(CColor(0), 0x00FFFFFF); @@ -177,7 +178,7 @@ void CVideo::init(void) render(); VIDEO_SetBlack(FALSE); VIDEO_Flush(); - m_stencil = MEM1_memalign(32, CVideo::_stencilWidth * CVideo::_stencilHeight); + m_stencil = MEM1_alloc(ALIGN32(CVideo::_stencilWidth * CVideo::_stencilHeight)); memset(m_stencil, 0, CVideo::_stencilWidth * CVideo::_stencilHeight); } diff --git a/source/list/list.cpp b/source/list/list.cpp index 2f18393c..905e3218 100644 --- a/source/list/list.cpp +++ b/source/list/list.cpp @@ -46,8 +46,13 @@ void CList::GetPaths(vector &pathlist, string containing, string dire bool FoundDMLgame; for(vector::iterator templist = temp_pathlist.begin(); templist != temp_pathlist.end(); templist++) { + if((*templist).size() == 0) + continue; + dir_itr = opendir((*templist).c_str()); - if (!dir_itr) continue; + if(!dir_itr) + continue; + FoundDMLgame = false; /* Read secondary entries */ diff --git a/source/loader/frag.c b/source/loader/frag.c index ddee94ca..549c9254 100644 --- a/source/loader/frag.c +++ b/source/loader/frag.c @@ -241,7 +241,7 @@ int get_frag_list(u8 *id, char *path, const u32 hdd_sector_size) frag_concat(fa, fs); } - frag_list = MEM1_memalign(32, ALIGN32(sizeof(FragList))); + frag_list = MEM1_alloc(ALIGN32(sizeof(FragList))); if(frag_list == NULL) goto out; diff --git a/source/main.cpp b/source/main.cpp index f9fb6834..b234e60c 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -36,6 +36,7 @@ extern "C" int main(int argc, char **argv) { __exception_setreload(5); + MEM1_init((void*)0x80003f00, (void*)0x80b00000); // Init video CVideo vid; diff --git a/source/memory/mem2.cpp b/source/memory/mem2.cpp index 2c0a3161..601fa40f 100644 --- a/source/memory/mem2.cpp +++ b/source/memory/mem2.cpp @@ -10,6 +10,7 @@ // Forbid the use of MEM2 through malloc u32 MALLOC_MEM2 = 0; +static CMEM2Alloc g_mem1gp; static CMEM2Alloc g_mem2gp; extern "C" @@ -22,25 +23,35 @@ extern __typeof(memalign) __real_memalign; extern __typeof(free) __real_free; extern __typeof(malloc_usable_size) __real_malloc_usable_size; +void MEM1_init(void *addr, void *end) +{ + g_mem1gp.init(addr, end); + g_mem1gp.clear(); +} + +void MEM1_cleanup(void) +{ + g_mem1gp.cleanup(); +} + +void MEM1_clear(void) +{ + g_mem1gp.clear(); +} void *MEM1_alloc(unsigned int s) { - return __real_malloc(s); -} - -void *MEM1_memalign(unsigned int a, unsigned int s) -{ - return __real_memalign(a, s); + return g_mem1gp.allocate(s); } void *MEM1_realloc(void *p, unsigned int s) { - return __real_realloc(p, s); + return g_mem1gp.reallocate(p, s); } void MEM1_free(void *p) { - __real_free(p); + g_mem1gp.release(p); } diff --git a/source/memory/mem2.hpp b/source/memory/mem2.hpp index 80aafee1..ae390dde 100644 --- a/source/memory/mem2.hpp +++ b/source/memory/mem2.hpp @@ -12,8 +12,10 @@ extern "C" #define MAX_MEM1_ARENA_LO ((void *)(0x81700000-size)) #define MEM2_PRIORITY_SIZE 0x1000 +void MEM1_init(void *addr, void *end); +void MEM1_cleanup(void); +void MEM1_clear(void); void *MEM1_alloc(unsigned int s); -void *MEM1_memalign(unsigned int a, unsigned int s); void *MEM1_realloc(void *p, unsigned int s); void MEM1_free(void *p); diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index 48976d23..0c4023ca 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -1294,6 +1294,10 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) if(currentPartition == 0) SDHC_Init(); + /* Clear Memory */ + MEM1_clear(); + MEM2_clear(); + /* Find game partition offset */ u64 offset; s32 ret = Disc_FindPartition(&offset); @@ -1438,7 +1442,7 @@ void CMenu::_playGameSound(void) CheckGameSoundThread(); if(!gameSoundThreadStack.get()) - gameSoundThreadStack = smartMem1Alloc(gameSoundThreadStackSize); + gameSoundThreadStack = smartAnyAlloc(gameSoundThreadStackSize); LWP_CreateThread(&m_gameSoundThread, (void *(*)(void *))CMenu::_gameSoundThread, (void *)this, gameSoundThreadStack.get(), gameSoundThreadStackSize, 60); } diff --git a/source/music/BufferCircle.cpp b/source/music/BufferCircle.cpp index 09727f3d..37724137 100644 --- a/source/music/BufferCircle.cpp +++ b/source/music/BufferCircle.cpp @@ -52,7 +52,7 @@ void BufferCircle::SetBufferBlockSize(int size) { if(SoundBuffer[i] != NULL) MEM1_free(SoundBuffer[i]); - SoundBuffer[i] = (u8 *)MEM1_memalign(32, ALIGN32(BufferBlockSize)); + SoundBuffer[i] = (u8 *)MEM1_alloc(ALIGN32(BufferBlockSize)); BufferSize[i] = 0; BufferReady[i] = false; } @@ -72,7 +72,7 @@ void BufferCircle::Resize(int size) for(int i = oldSize; i < Size(); i++) { if(BufferBlockSize > 0) - SoundBuffer[i] = (u8 *)MEM1_memalign(32, ALIGN32(BufferBlockSize)); + SoundBuffer[i] = (u8 *)MEM1_alloc(ALIGN32(BufferBlockSize)); else SoundBuffer[i] = NULL; BufferSize[i] = 0; diff --git a/source/music/SoundHandler.cpp b/source/music/SoundHandler.cpp index 6d4ec5fc..6342e2f6 100644 --- a/source/music/SoundHandler.cpp +++ b/source/music/SoundHandler.cpp @@ -43,7 +43,7 @@ SoundHandler::SoundHandler() for(u32 i = 0; i < MAX_DECODERS; ++i) DecoderList[i] = NULL; - ThreadStack = (u8 *)MEM1_memalign(32, 32768); + ThreadStack = (u8 *)MEM1_alloc(32768); if(!ThreadStack) return;