diff --git a/source/config/config.cpp b/source/config/config.cpp index 93cb7ad1..4fe729ec 100644 --- a/source/config/config.cpp +++ b/source/config/config.cpp @@ -202,6 +202,7 @@ void Config::save(bool unload) { if (m_changed) { + //gprintf("changed:%d\n",m_changed); ofstream file(m_filename.c_str(), ios::out | ios::binary); for (Config::DomainMap::iterator k = m_domains.begin(); k != m_domains.end(); ++k) { @@ -227,6 +228,7 @@ bool Config::has(const std::string &domain, const std::string &key) const void Config::setWString(const string &domain, const string &key, const wstringEx &val) { if (domain.empty() || key.empty()) return; + //gprintf("setWString %s\n", val.toUTF8().c_str()); m_changed = true; m_domains[upperCase(domain)][lowerCase(key)] = val.toUTF8(); } @@ -234,6 +236,7 @@ void Config::setWString(const string &domain, const string &key, const wstringEx void Config::setString(const string &domain, const string &key, const string &val) { if (domain.empty() || key.empty()) return; + //gprintf("setString %s\n", val.c_str()); m_changed = true; m_domains[upperCase(domain)][lowerCase(key)] = val; } @@ -241,6 +244,7 @@ void Config::setString(const string &domain, const string &key, const string &va void Config::setBool(const string &domain, const string &key, bool val) { if (domain.empty() || key.empty()) return; + //gprintf("setBool %d\n", val); m_changed = true; m_domains[upperCase(domain)][lowerCase(key)] = val ? "yes" : "no"; } @@ -248,6 +252,7 @@ void Config::setBool(const string &domain, const string &key, bool val) void Config::remove(const string &domain, const string &key) { if (domain.empty() || key.empty()) return; + //gprintf("remove %s\n", key.c_str()); m_changed = true; m_domains[upperCase(domain)].erase(lowerCase(key)); } @@ -255,6 +260,7 @@ void Config::remove(const string &domain, const string &key) void Config::setOptBool(const string &domain, const string &key, int val) { if (domain.empty() || key.empty()) return; + //gprintf("setOptBool %d\n", val); m_changed = true; switch (val) { @@ -272,6 +278,7 @@ void Config::setOptBool(const string &domain, const string &key, int val) void Config::setInt(const string &domain, const string &key, int val) { if (domain.empty() || key.empty()) return; + //gprintf("setInt %i\n", val); m_changed = true; m_domains[upperCase(domain)][lowerCase(key)] = sfmt("%i", val); } @@ -279,6 +286,7 @@ void Config::setInt(const string &domain, const string &key, int val) void Config::setUInt(const std::string &domain, const std::string &key, unsigned int val) { if (domain.empty() || key.empty()) return; + //gprintf("setUInt %u\n", val); m_changed = true; m_domains[upperCase(domain)][lowerCase(key)] = sfmt("%u", val); } @@ -286,6 +294,7 @@ void Config::setUInt(const std::string &domain, const std::string &key, unsigned void Config::setFloat(const string &domain, const string &key, float val) { if (domain.empty() || key.empty()) return; + //gprintf("setFloat %f\n", val); m_changed = true; m_domains[upperCase(domain)][lowerCase(key)] = sfmt("%.*g", g_floatPrecision, val); } @@ -293,6 +302,7 @@ void Config::setFloat(const string &domain, const string &key, float val) void Config::setVector3D(const std::string &domain, const std::string &key, const Vector3D &val) { if (domain.empty() || key.empty()) return; + //gprintf("setVector3D\n"); m_changed = true; m_domains[upperCase(domain)][lowerCase(key)] = sfmt("%.*g, %.*g, %.*g", g_floatPrecision, val.x, g_floatPrecision, val.y, g_floatPrecision, val.z); } @@ -300,6 +310,7 @@ void Config::setVector3D(const std::string &domain, const std::string &key, cons void Config::setColor(const std::string &domain, const std::string &key, const CColor &val) { if (domain.empty() || key.empty()) return; + //gprintf("setColor\n"); m_changed = true; m_domains[upperCase(domain)][lowerCase(key)] = sfmt("#%.2X%.2X%.2X%.2X", val.r, val.g, val.b, val.a); } @@ -311,6 +322,7 @@ wstringEx Config::getWString(const string &domain, const string &key, const wstr if (data.empty()) { data = defVal.toUTF8(); + //gprintf("getWString %s\n", defVal.toUTF8().c_str()); m_changed = true; return defVal; } @@ -327,6 +339,7 @@ string Config::getString(const string &domain, const string &key, const string & if(data.empty()) { data = defVal; + //gprintf("setString %s\n", defVal.c_str()); m_changed = true; } return data; @@ -387,6 +400,7 @@ bool Config::getBool(const string &domain, const string &key, bool defVal) if (data.empty()) { data = defVal ? "yes" : "no"; + //gprintf("getBool %d\n", defVal); m_changed = true; return defVal; } @@ -427,6 +441,7 @@ int Config::getOptBool(const string &domain, const string &key, int defVal) default: data = "default"; } + //gprintf("getOptBool %s\n", data.c_str()); m_changed = true; return defVal; } @@ -445,6 +460,7 @@ int Config::getInt(const string &domain, const string &key, int defVal) if (data.empty()) { data = sfmt("%i", defVal); + //gprintf("getInt %i\n", defVal); m_changed = true; return defVal; } @@ -467,6 +483,7 @@ unsigned int Config::getUInt(const string &domain, const string &key, unsigned i if (data.empty()) { data = sfmt("%u", defVal); + //gprintf("getUInt %u\n", defVal); m_changed = true; return defVal; } @@ -480,6 +497,7 @@ float Config::getFloat(const string &domain, const string &key, float defVal) if (data.empty()) { data = sfmt("%.*g", g_floatPrecision, defVal); + //gprintf("getFloat %s\n", data.c_str()); m_changed = true; return defVal; } @@ -497,6 +515,7 @@ Vector3D Config::getVector3D(const std::string &domain, const std::string &key, if (j == string::npos) { data = sfmt("%.*g, %.*g, %.*g", g_floatPrecision, defVal.x, g_floatPrecision, defVal.y, g_floatPrecision, defVal.z); + //gprintf("getVector3D\n"); m_changed = true; return defVal; } @@ -528,6 +547,7 @@ CColor Config::getColor(const std::string &domain, const std::string &key, const } } data = sfmt("#%.2X%.2X%.2X%.2X", defVal.r, defVal.g, defVal.b, defVal.a); + //gprintf("getColor\n"); m_changed = true; return defVal; } \ No newline at end of file diff --git a/source/gui/WiiMovie.cpp b/source/gui/WiiMovie.cpp index 4917e7b8..b43294a2 100644 --- a/source/gui/WiiMovie.cpp +++ b/source/gui/WiiMovie.cpp @@ -26,7 +26,7 @@ * for WiiXplorer 2010 ***************************************************************************/ #include -#include +#include "memory/mem2.hpp" #include "WiiMovie.hpp" #include "gecko/gecko.hpp" @@ -73,7 +73,7 @@ void WiiMovie::DeInit() } if(ThreadStack != NULL) { - free(ThreadStack); + MEM2_lo_free(ThreadStack); ThreadStack = NULL; } @@ -88,7 +88,7 @@ bool WiiMovie::Play(TexData *Background, bool loop) if(!vFile) return false; - ThreadStack = (u8 *)malloc(32768); + ThreadStack = (u8*)MEM2_lo_alloc(32768); if(!ThreadStack) return false; @@ -99,7 +99,7 @@ bool WiiMovie::Play(TexData *Background, bool loop) PlayTime.reset(); Playing = true; - LWP_CreateThread (&ReadThread, UpdateThread, this, ThreadStack, 32768, LWP_PRIO_HIGHEST); + LWP_CreateThread(&ReadThread, UpdateThread, this, ThreadStack, 32768, LWP_PRIO_HIGHEST); gprintf("Reading frames thread started\n"); return true; } diff --git a/source/gui/coverflow.cpp b/source/gui/coverflow.cpp index 3d3bb80b..773e8a6d 100644 --- a/source/gui/coverflow.cpp +++ b/source/gui/coverflow.cpp @@ -46,6 +46,9 @@ static inline int loopNum(int i, int s) CCoverFlow CoverFlow; +u8 CCoverFlow::coverThreadStack[32768] ATTRIBUTE_ALIGN(32); +const u32 CCoverFlow::coverThreadStackSize = 32768; + CCoverFlow::CCover::CCover(void) { index = 0; @@ -651,7 +654,8 @@ void CCoverFlow::startCoverLoader(void) m_loadingCovers = true; m_moved = true; - LWP_CreateThread(&coverLoaderThread, (void*(*)(void*))CCoverFlow::_coverLoader, (void*)this, NULL, 0, 30); + LWP_CreateThread(&coverLoaderThread, (void*(*)(void*))CCoverFlow::_coverLoader, + (void*)this, coverThreadStack, coverThreadStackSize, 30); //gprintf("Coverflow started!\n"); } diff --git a/source/gui/coverflow.hpp b/source/gui/coverflow.hpp index 0b19054b..83572663 100644 --- a/source/gui/coverflow.hpp +++ b/source/gui/coverflow.hpp @@ -310,6 +310,9 @@ private: u8 m_aniso; bool m_edgeLOD; Sorting m_sorting; + //thread stack + static u8 coverThreadStack[32768]; + static const u32 coverThreadStackSize; private: void _draw(DrawMode dm = CFDR_NORMAL, bool mirror = false, bool blend = true); u32 _currentPos(void) const; diff --git a/source/gui/video.cpp b/source/gui/video.cpp index 5da08811..8b465488 100644 --- a/source/gui/video.cpp +++ b/source/gui/video.cpp @@ -84,6 +84,10 @@ const int CVideo::_stencilHeight = 128; static lwp_t waitThread = LWP_THREAD_NULL; CVideo m_vid; + +u8 CVideo::waitMessageStack[2048] ATTRIBUTE_ALIGN(32); +const u32 CVideo::waitMessageStackSize = 2048; + CVideo::CVideo(void) : m_rmode(NULL), m_frameBuf(), m_curFB(0), m_fifo(NULL), m_yScale(0.0f), m_xfbHeight(0), m_wide(false), @@ -560,9 +564,6 @@ void CVideo::_showWaitMessages(CVideo *m) m->m_showingWaitMessages = false; } -u32 waitMessageStackSize = 1024; -u8 *waitMessageStack = NULL; - void CVideo::hideWaitMessage() { m_showWaitMessage = false; @@ -574,9 +575,6 @@ void CVideo::hideWaitMessage() while(m_showingWaitMessages) usleep(50); LWP_JoinThread(waitThread, NULL); - if(waitMessageStack != NULL) - MEM2_free(waitMessageStack); - waitMessageStack = NULL; /* end light thread */ wiiLightEndThread(); m_WaitThreadRunning = false; @@ -628,8 +626,6 @@ void CVideo::waitMessage(const vector &tex, float delay) wiiLightStartThread(); /* onscreen animation */ m_showWaitMessage = true; - if(waitMessageStack == NULL) - waitMessageStack = (u8*)MEM2_memalign(32, waitMessageStackSize); LWP_CreateThread(&waitThread, (void *(*)(void *))_showWaitMessages, (void*)this, waitMessageStack, waitMessageStackSize, LWP_PRIO_HIGHEST); } diff --git a/source/gui/video.hpp b/source/gui/video.hpp index 391f2fda..3abc0aef 100644 --- a/source/gui/video.hpp +++ b/source/gui/video.hpp @@ -113,6 +113,9 @@ private: static const float _jitter5[5][2]; static const float _jitter6[6][2]; static const float _jitter8[8][2]; + //thread stack + static u8 waitMessageStack[2048]; + static const u32 waitMessageStackSize; private: void _drawAASceneWithAlpha(float w, float h); void _setViewPort(float x, float y, float w, float h); diff --git a/source/main.cpp b/source/main.cpp index c348ebc4..573e9aa1 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -21,7 +21,6 @@ #include "menu/menu.hpp" #include "memory/memory.h" -CMenu mainMenu; bool useMainIOS = false; volatile bool NANDemuView = false; volatile bool networkInit = false; diff --git a/source/memory/mem2.cpp b/source/memory/mem2.cpp index 99b4e902..4669f474 100644 --- a/source/memory/mem2.cpp +++ b/source/memory/mem2.cpp @@ -16,19 +16,19 @@ u32 MALLOC_MEM2 = 0; u8 *MEM1_lo_start = (u8*)0x80004000; u8 *MEM1_lo_end = (u8*)0x8061ff00; -u8 *MEM1_lo_list = (u8*)0x932B0000; +u8 *MEM1_lo_list = (u8*)0x90080800; u8 *MEM2_lo_start = (u8*)0x90200000; u8 *MEM2_lo_end = (u8*)0x905fff00; -u8 *MEM2_lo_list = (u8*)0x932D0000; +u8 *MEM2_lo_list = (u8*)0x900a0800; u8 *MEM2_start = (u8*)0x90600000; -u8 *MEM2_end = (u8*)0x931fff00; -u8 *MEM2_list = (u8*)0x93200000; +u8 *MEM2_end = (u8*)0x932fff00; +u8 *MEM2_list = (u8*)0x90000800; -MemManager g_mem1lo; -MemManager g_mem2lo; -MemManager g_mem2gp; +static MemManager g_mem1lo; +static MemManager g_mem2lo; +static MemManager g_mem2gp; extern "C" { @@ -42,15 +42,13 @@ extern __typeof(malloc_usable_size) __real_malloc_usable_size; void MEM_init() { - MemMutexInit(); - g_mem1lo.Init(MEM1_lo_start, MEM1_lo_list, (u32)(MEM1_lo_end-MEM1_lo_start)); //about 6mb g_mem1lo.ClearMem(); g_mem2lo.Init(MEM2_lo_start, MEM2_lo_list, (u32)(MEM2_lo_end-MEM2_lo_start)); //about 4mb g_mem2lo.ClearMem(); - g_mem2gp.Init(MEM2_start, MEM2_list, (u32)(MEM2_end-MEM2_start)); //about 44mb + g_mem2gp.Init(MEM2_start, MEM2_list, (u32)(MEM2_end-MEM2_start)); //about 45mb g_mem2gp.ClearMem(); } diff --git a/source/memory/mem_manager.cpp b/source/memory/mem_manager.cpp index dab70a03..34b949a9 100644 --- a/source/memory/mem_manager.cpp +++ b/source/memory/mem_manager.cpp @@ -20,19 +20,7 @@ #include "gecko/gecko.hpp" #include "loader/utils.h" -static mutex_t memMutex = 0; -static const u32 MEM_BLOCK_SIZE = 128; - -void MemMutexInit() -{ - LWP_MutexInit(&memMutex, 0); -} - -void MemMutexDestroy() -{ - LWP_MutexDestroy(memMutex); - memset(&memMutex, 0, sizeof(mutex_t)); -} +static const u32 MEM_BLOCK_SIZE = 0x80; MemManager::MemManager() { @@ -40,6 +28,12 @@ MemManager::MemManager() memList = NULL; memListEnd = NULL; memSize = 0; + LWP_MutexInit(&memMutex, 0); +} + +MemManager::~MemManager() +{ + LWP_MutexDestroy(memMutex); } void MemManager::Init(u8 *start, u8 *list, u32 size) @@ -51,10 +45,8 @@ void MemManager::Init(u8 *start, u8 *list, u32 size) memList = list; memSize = ALIGN(MEM_BLOCK_SIZE, size) / MEM_BLOCK_SIZE; memListEnd = list + memSize; - ICInvalidateRange(memList, memSize+1); memset(memList, MEM_FREE , memSize); memset(memListEnd, MEM_END, 1); //thats the +1 - DCFlushRange(memList, memSize+1); LWP_MutexUnlock(memMutex); } @@ -65,9 +57,7 @@ void MemManager::ClearMem() //gprintf("ClearMem %x %i\n", startAddr, memSize * MEM_BLOCK_SIZE); u32 MemFull = memSize * MEM_BLOCK_SIZE; - ICInvalidateRange(startAddr, MemFull); memset(startAddr, 0, MemFull); - DCFlushRange(startAddr, MemFull); LWP_MutexUnlock(memMutex); } @@ -92,10 +82,8 @@ void *MemManager::Alloc(u32 size) if(blocksFree == size) { u8 *addr = (u8*)block; - ICInvalidateRange(addr, blocksFree); memset(addr, ALLOC_USED, blocksFree - 1); //start blocks memset(addr + blocksFree - 1, ALLOC_END, 1); //end block - DCFlushRange(addr, blocksFree); void *ptr = (void*)(startAddr + ((addr - memList)*MEM_BLOCK_SIZE)); //gprintf("Alloc %x mem, %i blocks\n", ptr, blocksFree); LWP_MutexUnlock(memMutex); @@ -126,9 +114,7 @@ void MemManager::Free(void *mem) size++; u8 *addr = (u8*)blockUsed; - ICInvalidateRange(addr, size); memset(addr, MEM_FREE, size); - DCFlushRange(addr, size); LWP_MutexUnlock(memMutex); } diff --git a/source/memory/mem_manager.hpp b/source/memory/mem_manager.hpp index 96fd4de1..7c31723f 100644 --- a/source/memory/mem_manager.hpp +++ b/source/memory/mem_manager.hpp @@ -31,6 +31,7 @@ enum mem_states class MemManager { public: MemManager(); + ~MemManager(); void Init(u8 *start, u8 *list, u32 size); void ClearMem(); void *Alloc(u32 size); @@ -39,13 +40,11 @@ public: u32 FreeSize(); void *ReAlloc(void *mem, u32 size); private: + mutex_t memMutex; u8 *startAddr; u8 *memList; u8 *memListEnd; u32 memSize; }; -void MemMutexInit(); -void MemMutexDestroy(); - #endif diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index 25fbf450..8970824d 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -36,6 +36,11 @@ extern const u32 hover_wav_size; extern const u8 camera_wav[]; extern const u32 camera_wav_size; +CMenu mainMenu; + +u8 CMenu::downloadStack[8192] ATTRIBUTE_ALIGN(32); +const u32 CMenu::downloadStackSize = 8192; + CMenu::CMenu() { m_aa = 0; diff --git a/source/menu/menu.hpp b/source/menu/menu.hpp index 380cb107..e0627c0e 100644 --- a/source/menu/menu.hpp +++ b/source/menu/menu.hpp @@ -1190,6 +1190,9 @@ private: static const SCFParamDesc _cfParams[]; static const int _nbCfgPages; static const u32 SVN_REV_NUM; + //thread stack + static u8 downloadStack[8192]; + static const u32 downloadStackSize; }; extern CMenu mainMenu; diff --git a/source/menu/menu_cheat.cpp b/source/menu/menu_cheat.cpp index 4cd8dd17..f920eb74 100644 --- a/source/menu/menu_cheat.cpp +++ b/source/menu/menu_cheat.cpp @@ -178,7 +178,8 @@ void CMenu::_CheatSettings() m_thrdWorking = true; lwp_t thread = LWP_THREAD_NULL; - LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_downloadCheatFileAsync, (void *)this, 0, 8192, 40); + LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_downloadCheatFileAsync, + (void *)this, downloadStack, downloadStackSize, 40); while(m_thrdWorking) { _mainLoopCommon(); diff --git a/source/menu/menu_download.cpp b/source/menu/menu_download.cpp index aeb4c83c..f596bedb 100644 --- a/source/menu/menu_download.cpp +++ b/source/menu/menu_download.cpp @@ -1234,9 +1234,11 @@ void CMenu::_download(string gameId) m_thrdWorking = true; gameId.clear(); if (dlAll) - LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_coverDownloaderAll, (void *)this, 0, 8192, 40); + LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_coverDownloaderAll, + (void *)this, downloadStack, downloadStackSize, 40); else - LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_coverDownloaderMissing, (void *)this, 0, 8192, 40); + LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_coverDownloaderMissing, + (void *)this, downloadStack, downloadStackSize, 40); } else if (m_btnMgr.selected(m_downloadBtnPrioM) && !m_thrdWorking) { @@ -1456,7 +1458,8 @@ void CMenu::_download(string gameId) _updateGametdb = true; - LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_gametdbDownloader, (void *)this, 0, 8192, 40); + LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_gametdbDownloader, + (void *)this, downloadStack, downloadStackSize, 40); } else if (m_btnMgr.selected(m_downloadBtnCancel)) { @@ -2121,7 +2124,8 @@ void CMenu::_downloadBnr(const char *gameID) m_thrdWorking = true; lwp_t thread = LWP_THREAD_NULL; - LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_downloadBannerAsync, (void *)this, 0, 8192, 40); + LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_downloadBannerAsync, + (void *)this, downloadStack, downloadStackSize, 40); wstringEx prevMsg; while(m_thrdWorking) @@ -2203,7 +2207,8 @@ void CMenu::_downloadUrl(const char *url, u8 **dl_file, u32 *dl_size) m_thrdWorking = true; lwp_t thread = LWP_THREAD_NULL; - LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_downloadUrlAsync, (void *)this, 0, 8192, 40); + LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_downloadUrlAsync, + (void *)this, downloadStack, downloadStackSize, 40); wstringEx prevMsg; while(m_thrdWorking) diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index e9421f59..fac308c3 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -359,7 +359,6 @@ void CMenu::_game(bool launch) m_gameSelected = true; } - if(m_banner.GetZoomSetting() != m_zoom_banner) m_banner.ToogleZoom(); @@ -1753,7 +1752,7 @@ void CMenu::_playGameSound(void) if(m_gameSoundThread != LWP_THREAD_NULL) CheckGameSoundThread(); - GameSoundStack = (u8*)MEM2_alloc(GameSoundSize); + GameSoundStack = (u8*)MEM2_lo_alloc(GameSoundSize); LWP_CreateThread(&m_gameSoundThread, (void *(*)(void *))CMenu::_gameSoundThread, (void*)this, GameSoundStack, GameSoundSize, 60); } @@ -1766,12 +1765,12 @@ void CMenu::CheckGameSoundThread() LWP_ResumeThread(m_gameSoundThread); while(m_soundThrdBusy) - usleep(50); + usleep(500); LWP_JoinThread(m_gameSoundThread, NULL); m_gameSoundThread = LWP_THREAD_NULL; if(GameSoundStack) - free(GameSoundStack); + MEM2_lo_free(GameSoundStack); GameSoundStack = NULL; } diff --git a/source/menu/menu_system.cpp b/source/menu/menu_system.cpp index da4d341e..24e8d04f 100644 --- a/source/menu/menu_system.cpp +++ b/source/menu/menu_system.cpp @@ -47,7 +47,8 @@ void CMenu::_system() m_btnMgr.setProgress(m_downloadPBar, 0.f); m_thrdStop = false; m_thrdWorking = true; - LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_versionTxtDownloaderInit, (void *)this, 0, 8192, 40); + LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_versionTxtDownloaderInit, + (void *)this, downloadStack, downloadStackSize, 40); } if (m_showtimer > 0 && !m_thrdWorking) { @@ -112,7 +113,8 @@ void CMenu::_system() m_data_update_url = fmt("%s/r%i/data.zip", m_version.getString("GENERAL", "update_url", "http://open-wiiflow-mod.googlecode.com/files").c_str(), newVer); m_showtimer = 120; - LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_versionDownloaderInit, (void *)this, 0, 8192, 40); + LWP_CreateThread(&thread, (void *(*)(void *))CMenu::_versionDownloaderInit, + (void *)this, downloadStack, downloadStackSize, 40); if (m_exit && !m_thrdWorking) { m_thrdStop = true; diff --git a/source/music/SoundHandler.cpp b/source/music/SoundHandler.cpp index c8775b7a..b6c0d338 100644 --- a/source/music/SoundHandler.cpp +++ b/source/music/SoundHandler.cpp @@ -36,6 +36,9 @@ SoundHandler SoundHandle; +u8 SoundHandler::SoundStack[32768] ATTRIBUTE_ALIGN(32); +const u32 SoundHandler::SoundStackSize = 32768; + void SoundHandler::Init() { Decoding = false; @@ -43,11 +46,7 @@ void SoundHandler::Init() for(u32 i = 0; i < MAX_DECODERS; ++i) DecoderList[i] = NULL; - ThreadStack = (u8 *)MEM2_memalign(32, 32768); - if(!ThreadStack) - return; - - LWP_CreateThread(&SoundThread, UpdateThread, this, ThreadStack, 32768, LWP_PRIO_HIGHEST); + LWP_CreateThread(&SoundThread, UpdateThread, this, SoundStack, SoundStackSize, LWP_PRIO_HIGHEST); gprintf("SHND: Running sound thread\n"); } @@ -59,11 +58,6 @@ void SoundHandler::Cleanup() ThreadSignal(); LWP_JoinThread(SoundThread, NULL); SoundThread = LWP_THREAD_NULL; - if(ThreadStack != NULL) - { - MEM2_free(ThreadStack); - ThreadStack = NULL; - } ClearDecoderList(); gprintf("SHND: Stopped sound thread\n"); diff --git a/source/music/SoundHandler.hpp b/source/music/SoundHandler.hpp index 43224049..643e47aa 100644 --- a/source/music/SoundHandler.hpp +++ b/source/music/SoundHandler.hpp @@ -46,6 +46,9 @@ public: SoundDecoder *Decoder(int i) { return ((i < 0 || i >= MAX_DECODERS) ? NULL : DecoderList[i]); }; void ThreadSignal() { LWP_ThreadSignal(ThreadQueue); }; bool IsDecoding() { return Decoding; }; +private: //thread stack + static u8 SoundStack[32768]; + static const u32 SoundStackSize; protected: static void *UpdateThread(void *arg); void InternalSoundUpdates(); @@ -53,7 +56,6 @@ protected: SoundDecoder *GetSoundDecoder(const char *filepath); SoundDecoder *GetSoundDecoder(const u8 *sound, int length); - u8 *ThreadStack; lwp_t SoundThread; lwpq_t ThreadQueue; bool Decoding;