-forgot to clear gecko sd file buffer on exit, could make problems

-moved this stupid now hide wait message debug print to less annoying
place
-wiiflow wants the dsp shutdown back, so I'll leave it in
-we shouldnt try to alloc mem1 after running apploader, just some
good advice before booting a game, should prevent codedumps
-sd file buffer can be mem1 too, we have enough left
-set mem2 usage to 49mb, thats everything we get anyways
-banner sounds should load faster now, also banner sound
in emulator coverflow when switching game should work again
-forcing check wait thread now on boot, not that the thread
is still working without noticing ;)
This commit is contained in:
fix94.1 2012-05-19 12:29:24 +00:00
parent 55f8c0bf95
commit 71064e3f77
13 changed files with 93 additions and 37 deletions

View File

@ -68,6 +68,14 @@ static void USBGeckoOutput()
devoptab_list[STD_ERR] = &gecko_out; devoptab_list[STD_ERR] = &gecko_out;
} }
void ClearLogBuffer()
{
if(tmpfilebuffer == NULL)
return;
MEM1_free(tmpfilebuffer);
tmpfilebuffer = NULL;
}
void WriteToFile(char* tmp) void WriteToFile(char* tmp)
{ {
if(tmpfilebuffer == NULL) if(tmpfilebuffer == NULL)
@ -80,7 +88,7 @@ void WriteToFile(char* tmp)
} }
else else
{ {
MEM2_free(tmpfilebuffer); MEM1_free(tmpfilebuffer);
tmpfilebuffer = NULL; tmpfilebuffer = NULL;
return; return;
} }
@ -160,7 +168,7 @@ bool InitGecko()
USBGeckoOutput(); USBGeckoOutput();
tmpfilebuffer = (char*)MEM2_alloc(filebuffer + 1 * sizeof(char)); tmpfilebuffer = (char*)MEM1_alloc(filebuffer + 1 * sizeof(char));
if(tmpfilebuffer != NULL) if(tmpfilebuffer != NULL)
memset(tmpfilebuffer, 0, sizeof(tmpfilebuffer)); memset(tmpfilebuffer, 0, sizeof(tmpfilebuffer));

View File

@ -15,6 +15,7 @@ extern "C" {
void gprintf(const char *format, ...); void gprintf(const char *format, ...);
void ghexdump(void *d, int len); void ghexdump(void *d, int len);
bool InitGecko(); bool InitGecko();
void ClearLogBuffer();
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -547,7 +547,6 @@ void CVideo::_showWaitMessages(CVideo *m)
void CVideo::hideWaitMessage() void CVideo::hideWaitMessage()
{ {
gprintf("Now hide wait message\n");
m_showWaitMessage = false; m_showWaitMessage = false;
CheckWaitThread(); CheckWaitThread();
wiiLightOff(); wiiLightOff();
@ -558,7 +557,7 @@ void CVideo::CheckWaitThread(bool force)
if ((!m_showingWaitMessages && waitThread != LWP_THREAD_NULL) || force) if ((!m_showingWaitMessages && waitThread != LWP_THREAD_NULL) || force)
{ {
m_showWaitMessage = false; m_showWaitMessage = false;
gprintf("Thread running. Stop it\n"); gprintf("Now hide wait message\n");
if(LWP_ThreadIsSuspended(waitThread)) if(LWP_ThreadIsSuspended(waitThread))
LWP_ResumeThread(waitThread); LWP_ResumeThread(waitThread);

View File

@ -102,7 +102,8 @@ void Sys_ExitTo(int option)
void Sys_Exit(void) void Sys_Exit(void)
{ {
if(return_to_disable) return; if(return_to_disable)
return;
/* Shutdown Inputs */ /* Shutdown Inputs */
Close_Inputs(); Close_Inputs();
@ -129,7 +130,6 @@ void __Sys_PowerCallback(void)
shutdown = true; shutdown = true;
} }
void Sys_Init(void) void Sys_Init(void)
{ {
/* Set RESET/POWER button callback */ /* Set RESET/POWER button callback */
@ -142,3 +142,23 @@ void Sys_LoadMenu(void)
/* Return to the Wii system menu */ /* Return to the Wii system menu */
WII_ReturnToMenu(); //SYS_ResetSystem doesnt work properly with new libogc WII_ReturnToMenu(); //SYS_ResetSystem doesnt work properly with new libogc
} }
void __dsp_shutdown(void)
{
u32 tick;
_dspReg[5] = (DSPCR_DSPRESET|DSPCR_HALT);
_dspReg[27] &= ~0x8000;
while(_dspReg[5]&0x400);
while(_dspReg[5]&0x200);
_dspReg[5] = (DSPCR_DSPRESET|DSPCR_DSPINT|DSPCR_ARINT|DSPCR_AIINT|DSPCR_HALT);
_dspReg[0] = 0;
while((_SHIFTL(_dspReg[2],16,16)|(_dspReg[3]&0xffff))&0x80000000);
tick = gettick();
while((gettick()-tick)<44);
_dspReg[5] |= DSPCR_RES;
while(_dspReg[5]&DSPCR_RES);
}

View File

@ -18,6 +18,17 @@ extern "C" {
#define EXIT_TO_DISABLE 4 #define EXIT_TO_DISABLE 4
#define EXIT_TO_BOOTMII 5 #define EXIT_TO_BOOTMII 5
// DSPCR bits
#define DSPCR_DSPRESET 0x0800 // Reset DSP
#define DSPCR_DSPINT 0x0080 // * interrupt active (RWC)
#define DSPCR_ARINT 0x0020
#define DSPCR_AIINT 0x0008
#define DSPCR_HALT 0x0004 // halt DSP
#define DSPCR_RES 0x0001 // reset DSP
#define _SHIFTL(v, s, w) \
((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s)))
/* Prototypes */ /* Prototypes */
void Sys_Init(void); void Sys_Init(void);
void Sys_LoadMenu(void); void Sys_LoadMenu(void);
@ -25,6 +36,7 @@ extern "C" {
void Sys_Test(void); void Sys_Test(void);
void Sys_Exit(void); void Sys_Exit(void);
void Sys_ExitTo(int); void Sys_ExitTo(int);
void __dsp_shutdown(void);
void Open_Inputs(void); void Open_Inputs(void);
void Close_Inputs(void); void Close_Inputs(void);

View File

@ -42,9 +42,9 @@ int main(int argc, char **argv)
CVideo vid; CVideo vid;
vid.init(); vid.init();
MEM2_init(52);
geckoinit = InitGecko(); geckoinit = InitGecko();
gprintf(" \nWelcome to %s (%s-r%s)!\nThis is the debug output.\n", APP_NAME, APP_VERSION, SVN_REV); gprintf(" \nWelcome to %s (%s-r%s)!\nThis is the debug output.\n", APP_NAME, APP_VERSION, SVN_REV);
MEM2_init(49); //Thats everything we can get anyways
vid.waitMessage(0.2f); vid.waitMessage(0.2f);
char *gameid = NULL; char *gameid = NULL;

View File

@ -14,6 +14,8 @@ u32 MALLOC_MEM2 = 0;
static CMEM2Alloc g_mem1gp; static CMEM2Alloc g_mem1gp;
static CMEM2Alloc g_mem2gp; static CMEM2Alloc g_mem2gp;
bool WrapMEM1 = true;
extern "C" extern "C"
{ {
@ -60,6 +62,11 @@ void MEM1_free(void *p)
g_mem1gp.release(p); g_mem1gp.release(p);
} }
void MEM1_wrap(unsigned int enable)
{
WrapMEM1 = enable;
}
unsigned int MEM1_usableSize(void *p) unsigned int MEM1_usableSize(void *p)
{ {
return g_mem1gp.usableSize(p); return g_mem1gp.usableSize(p);
@ -120,7 +127,7 @@ unsigned int MEM2_freesize()
void *__wrap_malloc(size_t size) void *__wrap_malloc(size_t size)
{ {
void *p; void *p;
if ((SYS_GetArena1Lo() >= MAX_MEM1_ARENA_LO) || size >= MEM2_PRIORITY_SIZE) if(SYS_GetArena1Lo() >= MAX_MEM1_ARENA_LO || size >= MEM2_PRIORITY_SIZE || !WrapMEM1)
{ {
p = g_mem2gp.allocate(size); p = g_mem2gp.allocate(size);
if(p != 0) if(p != 0)
@ -136,7 +143,7 @@ void *__wrap_malloc(size_t size)
void *__wrap_calloc(size_t n, size_t size) void *__wrap_calloc(size_t n, size_t size)
{ {
void *p; void *p;
if ((SYS_GetArena1Lo() >= MAX_MEM1_ARENA_LO) || (n * size) >= MEM2_PRIORITY_SIZE) if(SYS_GetArena1Lo() >= MAX_MEM1_ARENA_LO || (n * size) >= MEM2_PRIORITY_SIZE || !WrapMEM1)
{ {
p = g_mem2gp.allocate(n * size); p = g_mem2gp.allocate(n * size);
if (p != 0) if (p != 0)
@ -159,20 +166,17 @@ void *__wrap_calloc(size_t n, size_t size)
void *__wrap_memalign(size_t a, size_t size) void *__wrap_memalign(size_t a, size_t size)
{ {
void *p; void *p;
if ((SYS_GetArena1Lo() >= MAX_MEM1_ARENA_LO) || size >= MEM2_PRIORITY_SIZE) if(SYS_GetArena1Lo() >= MAX_MEM1_ARENA_LO || size >= MEM2_PRIORITY_SIZE || !WrapMEM1)
{ {
if (a <= 32 && 32 % a == 0) p = MEM2_memalign(a, size);
{
p = g_mem2gp.allocate(size);
if (p != 0) if (p != 0)
return p; return p;
}
return __real_memalign(a, size); return __real_memalign(a, size);
} }
p = __real_memalign(a, size); p = __real_memalign(a, size);
if(p != 0) if(p != 0)
return p; return p;
return g_mem2gp.allocate(size); return MEM2_memalign(a, size);
} }
void __wrap_free(void *p) void __wrap_free(void *p)
@ -182,6 +186,8 @@ void __wrap_free(void *p)
if(((u32)p & 0x10000000) != 0) if(((u32)p & 0x10000000) != 0)
g_mem2gp.release(p); g_mem2gp.release(p);
else if((u32)p < (u32)0x80b00000 && (u32)p >= (u32)0x80003f00)
g_mem1gp.release(p);
else else
__real_free(p); __real_free(p);
} }

View File

@ -19,6 +19,7 @@ void *MEM1_alloc(unsigned int s);
void *MEM1_memalign(unsigned int a, unsigned int s); void *MEM1_memalign(unsigned int a, unsigned int s);
void *MEM1_realloc(void *p, unsigned int s); void *MEM1_realloc(void *p, unsigned int s);
void MEM1_free(void *p); void MEM1_free(void *p);
void MEM1_wrap(unsigned int enable);
unsigned int MEM1_usableSize(void *p); unsigned int MEM1_usableSize(void *p);
unsigned int MEM1_freesize(); unsigned int MEM1_freesize();

View File

@ -25,14 +25,11 @@ public:
{ {
switch(m_srcAlloc) switch(m_srcAlloc)
{ {
case SRCALL_MEM1: case SRCALL_NEW:
MEM1_free(m_p); delete m_p;
break;
case SRCALL_MEM2:
MEM2_free(m_p);
break; break;
default: default:
delete m_p; free(m_p);
break; break;
} }
delete m_refcount; delete m_refcount;

View File

@ -468,6 +468,7 @@ void CMenu::cleanup(bool ios_reload)
{ {
m_cf.stopCoverLoader(); m_cf.stopCoverLoader();
m_cf.clear(); m_cf.clear();
ClearGameSoundThreadStack();
m_plugin.Cleanup(); m_plugin.Cleanup();
@ -485,6 +486,7 @@ void CMenu::cleanup(bool ios_reload)
DeviceHandler::DestroyInstance(); DeviceHandler::DestroyInstance();
m_vid.cleanup(); m_vid.cleanup();
wiiLightOff(); wiiLightOff();
__dsp_shutdown();
} }
if (!ios_reload) if (!ios_reload)
@ -498,6 +500,8 @@ void CMenu::cleanup(bool ios_reload)
if (!ios_reload || (!m_use_wifi_gecko && ios_reload)) if (!ios_reload || (!m_use_wifi_gecko && ios_reload))
_deinitNetwork(); _deinitNetwork();
ClearLogBuffer();
gprintf(" \nMemory cleaned up\n"); gprintf(" \nMemory cleaned up\n");
} }
@ -1749,7 +1753,7 @@ void CMenu::_mainLoopCommon(bool withCF, bool blockReboot, bool adjusting)
m_gamesound_changed = false; m_gamesound_changed = false;
} }
else if(!m_gameSelected) else if(!m_gameSelected)
m_gameSound.FreeMemory(); m_gameSound.Stop();
CheckThreads(); CheckThreads();

View File

@ -1092,6 +1092,7 @@ private:
void _playGameSound(void); void _playGameSound(void);
void CheckGameSoundThread(void); void CheckGameSoundThread(void);
void ClearGameSoundThreadStack(void);
void CheckThreads(void); void CheckThreads(void);
static void _gameSoundThread(CMenu *m); static void _gameSoundThread(CMenu *m);

View File

@ -382,6 +382,7 @@ void CMenu::_game(bool launch)
{ {
m_gameSound.FreeMemory(); m_gameSound.FreeMemory();
CheckGameSoundThread(); CheckGameSoundThread();
ClearGameSoundThreadStack();
break; break;
} }
else if (BTN_PLUS_PRESSED && m_GameTDBLoaded) else if (BTN_PLUS_PRESSED && m_GameTDBLoaded)
@ -1288,7 +1289,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
m_vid.CheckWaitThread(true); m_vid.CheckWaitThread(true);
cleanup(); cleanup();
// wifi-gecko can no longer function after cleanup // wifi and sd gecko doesnt work anymore after cleanup
Close_Inputs(); Close_Inputs();
USBStorage_Deinit(); USBStorage_Deinit();
if(currentPartition == 0) if(currentPartition == 0)
@ -1296,6 +1297,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
/* Clear Memory */ /* Clear Memory */
MEM1_clear(); MEM1_clear();
MEM1_wrap(0);
MEM2_clear(); MEM2_clear();
/* Find game partition offset */ /* Find game partition offset */
@ -1453,9 +1455,13 @@ void CMenu::CheckGameSoundThread()
LWP_ResumeThread(m_gameSoundThread); LWP_ResumeThread(m_gameSoundThread);
LWP_JoinThread(m_gameSoundThread, NULL); LWP_JoinThread(m_gameSoundThread, NULL);
m_gameSoundThread = LWP_THREAD_NULL;
}
void CMenu::ClearGameSoundThreadStack()
{
if(gameSoundThreadStack.get()) if(gameSoundThreadStack.get())
gameSoundThreadStack.release(); gameSoundThreadStack.release();
m_gameSoundThread = LWP_THREAD_NULL;
} }
void CMenu::CheckThreads() void CMenu::CheckThreads()

View File

@ -263,6 +263,7 @@ int CMenu::main(void)
} }
_showMain(); _showMain();
m_vid.CheckWaitThread(true);
m_curGameId.clear(); m_curGameId.clear();
_initCF(); _initCF();