From f1767d50828f428513225509c62ea6ebe1c1b912 Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Fri, 7 Sep 2012 18:13:04 +0000 Subject: [PATCH] -changed version to Beta 4.0.2 -increased usable mem for about 11mb by using mem1_lo (10mb) and no mem1_hi limit (1mb) --- source/defines.h | 2 +- source/gui/coverflow.cpp | 2 +- source/gui/coverflow.hpp | 2 +- source/gui/text.cpp | 4 +-- source/gui/text.hpp | 2 +- source/main.cpp | 2 +- source/memory/mem2.cpp | 73 +++++++++++++++++++++++++++++++-------- source/memory/mem2.hpp | 8 +++-- source/menu/menu.cpp | 41 +++++++++++++--------- source/menu/menu.hpp | 4 ++- source/menu/menu_game.cpp | 8 ++--- 11 files changed, 100 insertions(+), 48 deletions(-) diff --git a/source/defines.h b/source/defines.h index 073fbf72..98b40c0f 100644 --- a/source/defines.h +++ b/source/defines.h @@ -1,5 +1,5 @@ #define APP_NAME "WiiFlow" -#define APP_VERSION "4.0.1" +#define APP_VERSION "Beta 4.0.2" #define APPDATA_DIR "wiiflow" #define APPDATA_DIR2 "apps/wiiflow" diff --git a/source/gui/coverflow.cpp b/source/gui/coverflow.cpp index 296ad914..f8820480 100644 --- a/source/gui/coverflow.cpp +++ b/source/gui/coverflow.cpp @@ -227,7 +227,7 @@ CCoverFlow::CCoverFlow(void) LWP_MutexInit(&m_mutex, 0); } -bool CCoverFlow::init(const SmartBuf &font, u32 font_size, bool vid_50hz) +bool CCoverFlow::init(u8 *font, u32 font_size, bool vid_50hz) { // Load font m_font.fromBuffer(font, font_size, TITLEFONT); diff --git a/source/gui/coverflow.hpp b/source/gui/coverflow.hpp index 36d62b32..8dbadc2e 100644 --- a/source/gui/coverflow.hpp +++ b/source/gui/coverflow.hpp @@ -40,7 +40,7 @@ public: CCoverFlow(void); ~CCoverFlow(void); // - bool init(const SmartBuf &font, u32 font_size, bool vid_50hz); + bool init(u8 *font, u32 font_size, bool vid_50hz); // Cover list management void clear(void); void shutdown(void); diff --git a/source/gui/text.cpp b/source/gui/text.cpp index e0d3f8be..fb328c26 100644 --- a/source/gui/text.cpp +++ b/source/gui/text.cpp @@ -178,7 +178,7 @@ vector stringToVector(const wstringEx &text, char sep) return v; } -bool SFont::fromBuffer(const SmartBuf &buffer, u32 bufferSize, u32 size, u32 lspacing, u32 w, u32 idx, const char *) +bool SFont::fromBuffer(u8 *buffer, u32 bufferSize, u32 size, u32 lspacing, u32 w, u32 idx, const char *) { if (!buffer || !font) return false; @@ -192,7 +192,7 @@ bool SFont::fromBuffer(const SmartBuf &buffer, u32 bufferSize, u32 size, u32 lsp data = smartMem2Alloc(bufferSize); if(!data) return false; - memcpy(data.get(), buffer.get(), bufferSize); + memcpy(data.get(), buffer, bufferSize); dataSize = bufferSize; font->loadFont(data.get(), dataSize, size, weight, index, false); diff --git a/source/gui/text.hpp b/source/gui/text.hpp index f6fd9b48..3919635c 100644 --- a/source/gui/text.hpp +++ b/source/gui/text.hpp @@ -21,7 +21,7 @@ struct SFont u32 weight; u32 index; public: - bool fromBuffer(const SmartBuf &buffer, u32 bufferSize, u32 size, u32 lspacing, u32 w = 0, u32 idx = 0, const char *genKey = NULL); + bool fromBuffer(u8 *buffer, u32 bufferSize, u32 size, u32 lspacing, u32 w = 0, u32 idx = 0, const char *genKey = NULL); bool fromFile(const char *filename, u32 size, u32 lspacing, u32 w = 0, u32 idx = 0); SFont(void) : data(SmartBuf(NULL, SmartBuf::SRCALL_MEM2)), dataSize(0), font(SmartPtr(new FreeTypeGX)), lineSpacing(0), weight(0), index(0) { } ~SFont(void) { } diff --git a/source/main.cpp b/source/main.cpp index 8f2ca561..bdd135bb 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -35,7 +35,7 @@ int main(int argc, char **argv) vid.init(); Nand::Instance()->Init_ISFS(); - MEM2_init(47); //Should be safe to use + MEM_init(); //Inits both mem1lo and mem2 gprintf(" \nWelcome to %s (%s-r%s)!\nThis is the debug output.\n", APP_NAME, APP_VERSION, SVN_REV); char *gameid = NULL; diff --git a/source/memory/mem2.cpp b/source/memory/mem2.cpp index 0d57bc41..89bb0881 100644 --- a/source/memory/mem2.cpp +++ b/source/memory/mem2.cpp @@ -8,9 +8,18 @@ #include "gecko/gecko.h" #include "loader/utils.h" +#define MEM2_PRIORITY_SIZE 0x1000 + // Forbid the use of MEM2 through malloc u32 MALLOC_MEM2 = 0; +void *MEM1_lo_start = (void*)0x80004000; +void *MEM1_lo_end = (void*)0x80A00000; + +void *MEM2_start = (void*)0x90200000; +void *MEM2_end = (void*)0x93100000; + +static CMEM2Alloc g_mem1lo; static CMEM2Alloc g_mem2gp; extern "C" @@ -23,24 +32,60 @@ extern __typeof(memalign) __real_memalign; extern __typeof(free) __real_free; extern __typeof(malloc_usable_size) __real_malloc_usable_size; +void MEM_init() +{ + g_mem1lo.init(MEM1_lo_start, MEM1_lo_end); //about 10mb + g_mem1lo.clear(); + + g_mem2gp.init(MEM2_start, MEM2_end); //about 47mb + g_mem2gp.clear(); +} + +void *MEM1_lo_alloc(unsigned int s) +{ + return g_mem1lo.allocate(s); +} + +void MEM1_lo_free(void *p) +{ + if(!p) + return; + g_mem1lo.release(p); +} + void *MEM1_alloc(unsigned int s) { - return __real_malloc(s); + void *p = g_mem1lo.allocate(s); + if(!p) + p = __real_malloc(s); + return p; } void *MEM1_memalign(unsigned int a, unsigned int s) { - return __real_memalign(a, s); + void *p = g_mem1lo.allocate(s); + if(!p) + p = __real_memalign(a, s); + return p; } void *MEM1_realloc(void *p, unsigned int s) { + if(!p) + return NULL; + if((u32)p > (u32)MEM1_lo_start && (u32)p < (u32)MEM1_lo_end) + return g_mem1lo.reallocate(p, s); return __real_realloc(p, s); } void MEM1_free(void *p) { - __real_free(p); + if(!p) + return; + if((u32)p > (u32)MEM1_lo_start && (u32)p < (u32)MEM1_lo_end) + g_mem1lo.release(p); + else + __real_free(p); } unsigned int MEM1_freesize() @@ -48,12 +93,6 @@ unsigned int MEM1_freesize() return SYS_GetArena1Size(); } -void MEM2_init(unsigned int mem2Size) -{ - g_mem2gp.init(mem2Size); - g_mem2gp.clear(); -} - void MEM2_cleanup(void) { g_mem2gp.cleanup(); @@ -66,6 +105,8 @@ void MEM2_clear(void) void MEM2_free(void *p) { + if(!p) + return; g_mem2gp.release(p); } @@ -82,11 +123,15 @@ void *MEM2_memalign(unsigned int /* alignment */, unsigned int s) void *MEM2_realloc(void *p, unsigned int s) { + if(!p) + return NULL; return g_mem2gp.reallocate(p, s); } unsigned int MEM2_usableSize(void *p) { + if(!p) + return 0; return g_mem2gp.usableSize(p); } @@ -98,11 +143,11 @@ unsigned int MEM2_freesize() void *__wrap_malloc(size_t size) { void *p; - if(SYS_GetArena1Lo() >= MAX_MEM1_ARENA_LO || size >= MEM2_PRIORITY_SIZE) + if(size >= MEM2_PRIORITY_SIZE) { p = g_mem2gp.allocate(size); if(p != 0) - return p; + return p; return __real_malloc(size); } p = __real_malloc(size); @@ -114,7 +159,7 @@ void *__wrap_malloc(size_t size) void *__wrap_calloc(size_t n, size_t size) { void *p; - if(SYS_GetArena1Lo() >= MAX_MEM1_ARENA_LO || (n * size) >= MEM2_PRIORITY_SIZE) + if((n * size) >= MEM2_PRIORITY_SIZE) { p = g_mem2gp.allocate(n * size); if (p != 0) @@ -137,7 +182,7 @@ void *__wrap_calloc(size_t n, size_t size) void *__wrap_memalign(size_t a, size_t size) { void *p; - if(SYS_GetArena1Lo() >= MAX_MEM1_ARENA_LO || size >= MEM2_PRIORITY_SIZE) + if(size >= MEM2_PRIORITY_SIZE) { if(a <= 32 && 32 % a == 0) { @@ -162,7 +207,7 @@ void __wrap_free(void *p) if(((u32)p & 0x10000000) != 0) g_mem2gp.release(p); else - __real_free(p); + MEM1_free(p); } void *__wrap_realloc(void *p, size_t size) diff --git a/source/memory/mem2.hpp b/source/memory/mem2.hpp index af8c1cf0..11c33937 100644 --- a/source/memory/mem2.hpp +++ b/source/memory/mem2.hpp @@ -9,15 +9,17 @@ extern "C" { #endif -#define MAX_MEM1_ARENA_LO ((void *)(0x81700000-size)) -#define MEM2_PRIORITY_SIZE 0x1000 +void MEM_init(); + +void *MEM1_lo_alloc(unsigned int s); +void MEM1_lo_free(void *p); 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); unsigned int MEM1_freesize(); -void MEM2_init(unsigned int mem2Size); + void MEM2_cleanup(void); void MEM2_clear(void); void MEM2_free(void *p); diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index 48064f20..3ba2bf88 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -112,9 +112,6 @@ extern const u8 checkboxs_png[]; extern const u8 checkboxhid_png[]; extern const u8 checkboxreq_png[]; -SmartBuf m_wbf1_font; -SmartBuf m_wbf2_font; - CMenu::CMenu(CVideo &vid) : m_vid(vid) { @@ -142,7 +139,10 @@ CMenu::CMenu(CVideo &vid) : m_reload = false; m_gamesound_changed = false; m_video_playing = false; + m_base_font = NULL; m_base_font_size = 0; + m_wbf1_font = NULL; + m_wbf2_font = NULL; m_current_view = COVERFLOW_USB; m_Emulator_boot = false; m_banner = new BannerWindow; @@ -872,7 +872,7 @@ void CMenu::_loadCFLayout(int version, bool forceAA, bool otherScrnFmt) void CMenu::_buildMenus(void) { - if(!m_base_font.get()) + if(!m_base_font) _loadDefaultFont(CONF_GetLanguage() == CONF_LANG_KOREAN); // Default fonts @@ -2406,10 +2406,12 @@ retry: { const u8 *font_file = u8_get_file_by_index(u8_font_archive, 1, &size); // There is only one file in that app //gprintf("Extracted font: %d\n", size); - m_base_font = smartMem2Alloc(size); - memcpy(m_base_font.get(), font_file, size); - if(!!m_base_font) - m_base_font_size = size; + if(m_base_font) + MEM1_free(m_base_font); + m_base_font = (u8*)MEM1_alloc(size); + memcpy(m_base_font, font_file, size); + DCFlushRange(m_base_font, size); + m_base_font_size = size; free(u8_font_archive); } break; @@ -2424,12 +2426,18 @@ retry: if(u8_font_archive != NULL) { const u8 *font_file1 = u8_get_file(u8_font_archive, "wbf1.brfna", &size); - m_wbf1_font = smartMem2Alloc(size); - memcpy(m_wbf1_font.get(), font_file1, size); - + if(m_wbf1_font) + MEM1_lo_free(m_wbf1_font); + m_wbf1_font = (u8*)MEM1_lo_alloc(size); + memcpy(m_wbf1_font, font_file1, size); + DCFlushRange(m_wbf1_font, size); + const u8 *font_file2 = u8_get_file(u8_font_archive, "wbf2.brfna", &size); - m_wbf2_font = smartMem2Alloc(size); - memcpy(m_wbf2_font.get(), font_file2, size); + if(m_wbf2_font) + MEM1_lo_free(m_wbf2_font); + m_wbf2_font = (u8*)MEM1_lo_alloc(size); + memcpy(m_wbf2_font, font_file2, size); + DCFlushRange(m_wbf2_font, size); free(u8_font_archive); } @@ -2447,11 +2455,10 @@ retry: void CMenu::_cleanupDefaultFont() { - m_base_font.release(); + MEM1_lo_free(m_base_font); m_base_font_size = 0; - - m_wbf1_font.release(); - m_wbf2_font.release(); + MEM1_lo_free(m_wbf1_font); + MEM1_lo_free(m_wbf2_font); } const char *CMenu::_domainFromView() diff --git a/source/menu/menu.hpp b/source/menu/menu.hpp index eb3224eb..300195d1 100644 --- a/source/menu/menu.hpp +++ b/source/menu/menu.hpp @@ -67,8 +67,10 @@ private: Config m_version; Plugin m_plugin; vector m_homebrewArgs; - SmartBuf m_base_font; + u8 *m_base_font; u32 m_base_font_size; + u8 *m_wbf1_font; + u8 *m_wbf2_font; u8 m_aa; bool m_bnr_settings; bool m_directLaunch; diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index c08332ba..63484ed9 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -1533,10 +1533,6 @@ void CMenu::_gameSoundThread(CMenu *m) m->m_gameSoundHdr = NULL; return; } - - extern SmartBuf m_wbf1_font; - extern SmartBuf m_wbf2_font; - bool custom = false; u8 *custom_bnr_file = NULL; u32 custom_bnr_size = 0; @@ -1580,7 +1576,7 @@ void CMenu::_gameSoundThread(CMenu *m) disc.init(m->m_cf.getHdr()->path); u8 *opening_bnr = disc.GetGameCubeBanner(); if(opening_bnr != NULL) - m_banner->CreateGCBanner(opening_bnr, &m->m_vid, m_wbf1_font.get(), m_wbf2_font.get(), m->m_cf.getHdr()->title); + m_banner->CreateGCBanner(opening_bnr, &m->m_vid, m->m_wbf1_font, m->m_wbf2_font, m->m_cf.getHdr()->title); m->m_gameSound.Load(gc_ogg, gc_ogg_size, false); m->m_gamesound_changed = true; m->m_gameSoundHdr = NULL; @@ -1615,7 +1611,7 @@ void CMenu::_gameSoundThread(CMenu *m) _extractChannelBnr(TITLE_ID(m->m_gameSoundHdr->settings[0],m->m_gameSoundHdr->settings[1])) : NULL))); if(banner != NULL && banner->IsValid()) { - m_banner->LoadBanner(banner, &m->m_vid, m_wbf1_font.get(), m_wbf2_font.get()); + m_banner->LoadBanner(banner, &m->m_vid, m->m_wbf1_font, m->m_wbf2_font); soundBin = banner->GetFile((char *)"sound.bin", &sndSize); } else