From f94e65a54df6d036ab4e3d6f675644387e95aefa Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Thu, 17 May 2012 12:47:27 +0000 Subject: [PATCH] -proper cleanup of video now, no more greenscreens should come on game booting -moved partition read buffer on game boot to mem1, faster --- source/gui/video.cpp | 40 ++++-- source/loader/disc.c | 17 +-- source/memory/smartptr.hpp | 4 +- source/menu/menu.cpp | 9 +- source/menu/menu_game.cpp | 3 +- source/music/SoundHandler.cpp | 224 +++++++++++++++++----------------- 6 files changed, 155 insertions(+), 142 deletions(-) diff --git a/source/gui/video.cpp b/source/gui/video.cpp index 92ae0b21..12201fb6 100644 --- a/source/gui/video.cpp +++ b/source/gui/video.cpp @@ -225,19 +225,21 @@ void CVideo::prepare(void) void CVideo::cleanup(void) { gprintf("Cleaning up video...\n"); - GX_InvVtxCache(); - GX_InvalidateTexAll(); - VIDEO_ClearFrameBuffer(m_rmode, m_frameBuf[0], COLOR_BLACK); - VIDEO_ClearFrameBuffer(m_rmode, m_frameBuf[1], COLOR_BLACK); + VIDEO_ClearFrameBuffer(m_rmode, m_frameBuf[m_curFB], COLOR_BLACK); + render(); + VIDEO_ClearFrameBuffer(m_rmode, m_frameBuf[m_curFB], COLOR_BLACK); + render(); + + GX_DrawDone(); + GX_AbortFrame(); + + VIDEO_SetBlack(TRUE); VIDEO_Flush(); VIDEO_WaitVSync(); if(m_rmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); - GX_AbortFrame(); - GX_Flush(); - for(u8 i = 0; i < sizeof m_aaBuffer / sizeof m_aaBuffer[0]; ++i) { if(m_aaBuffer[i].get()) @@ -248,10 +250,26 @@ void CVideo::cleanup(void) if(m_defaultWaitMessages[i].data.get()) m_defaultWaitMessages[i].data.release(); } - free(MEM_K1_TO_K0(m_frameBuf[0])); - free(MEM_K1_TO_K0(m_frameBuf[1])); - MEM1_free(m_stencil); - MEM1_free(m_fifo); + if(m_frameBuf[0] != NULL) + { + free(MEM_K1_TO_K0(m_frameBuf[0])); + m_frameBuf[0] = NULL; + } + if(m_frameBuf[1] != NULL) + { + free(MEM_K1_TO_K0(m_frameBuf[1])); + m_frameBuf[0] = NULL; + } + if(m_stencil != NULL) + { + MEM1_free(m_stencil); + m_stencil = NULL; + } + if(m_fifo != NULL) + { + MEM1_free(m_fifo); + m_fifo = NULL; + } } void CVideo::prepareAAPass(int aaStep) diff --git a/source/loader/disc.c b/source/loader/disc.c index 667d2f91..cdccd738 100644 --- a/source/loader/disc.c +++ b/source/loader/disc.c @@ -167,13 +167,6 @@ void __Disc_SetVMode(void) /* Set video mode */ if (disc_vmode != 0) VIDEO_Configure(disc_vmode); - - /* Setup video */ - VIDEO_SetBlack(TRUE); - VIDEO_Flush(); - VIDEO_WaitVSync(); - if(disc_vmode->viTVMode & VI_NON_INTERLACE) - VIDEO_WaitVSync(); } void __Disc_SetTime(void) @@ -187,7 +180,7 @@ s32 Disc_FindPartition(u64 *outbuf) u64 offset = 0; u32 cnt; - u32 *TMP_Buffer = (u32*)MEM2_alloc(0x20); + u32 *TMP_Buffer = (u32*)MEM1_alloc(0x20); if(!TMP_Buffer) return -1; @@ -195,7 +188,7 @@ s32 Disc_FindPartition(u64 *outbuf) s32 ret = WDVD_UnencryptedRead(TMP_Buffer, 0x20, PTABLE_OFFSET); if(ret < 0) { - MEM2_free(TMP_Buffer); + MEM1_free(TMP_Buffer); return ret; } @@ -205,7 +198,7 @@ s32 Disc_FindPartition(u64 *outbuf) if(nb_partitions > 8) { - MEM2_free(TMP_Buffer); + MEM1_free(TMP_Buffer); return -1; } @@ -215,7 +208,7 @@ s32 Disc_FindPartition(u64 *outbuf) ret = WDVD_UnencryptedRead(TMP_Buffer, 0x20, table_offset); if (ret < 0) { - MEM2_free(TMP_Buffer); + MEM1_free(TMP_Buffer); return ret; } @@ -228,7 +221,7 @@ s32 Disc_FindPartition(u64 *outbuf) if(!type) offset = TMP_Buffer[cnt * 2] << 2; } - MEM2_free(TMP_Buffer); + MEM1_free(TMP_Buffer); /* No game partition found */ if (!offset) diff --git a/source/memory/smartptr.hpp b/source/memory/smartptr.hpp index b0ac4b4c..1e1635a9 100644 --- a/source/memory/smartptr.hpp +++ b/source/memory/smartptr.hpp @@ -21,9 +21,9 @@ public: T *get(void) const { return m_p; } virtual void release(void) { - if (m_refcount != NULL && --*m_refcount == 0) + if (m_p != NULL && m_refcount != NULL && --*m_refcount == 0) { - switch (m_srcAlloc) + switch(m_srcAlloc) { case SRCALL_NEW: delete m_p; diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index b8b586ed..b23fed42 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -479,13 +479,14 @@ void CMenu::cleanup(bool ios_reload) MusicPlayer::DestroyInstance(); SoundHandler::DestroyInstance(); soundDeinit(); - __dsp_shutdown(); - - DeviceHandler::DestroyInstance(); if(!m_reload) + { + DeviceHandler::DestroyInstance(); + __dsp_shutdown(); m_vid.cleanup(); - wiiLightOff(); + wiiLightOff(); + } if (!ios_reload) { diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index 5b6948eb..f8429bb5 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -1421,7 +1421,8 @@ void CMenu::_gameSoundThread(CMenu *m) if (soundBin == NULL || (((IMD5Header *)soundBin)->fcc != 'IMD5' && ((IMD5Header *)soundBin)->fcc != 'RIFF')) { gprintf("Failed to load banner sound!\n\n"); - delete soundBin; + if(soundBin != NULL) + delete soundBin; return; } diff --git a/source/music/SoundHandler.cpp b/source/music/SoundHandler.cpp index a5882e13..6d4ec5fc 100644 --- a/source/music/SoundHandler.cpp +++ b/source/music/SoundHandler.cpp @@ -38,17 +38,17 @@ SoundHandler * SoundHandler::instance = NULL; SoundHandler::SoundHandler() { - Decoding = false; - ExitRequested = false; + Decoding = false; + ExitRequested = false; for(u32 i = 0; i < MAX_DECODERS; ++i) - DecoderList[i] = NULL; + DecoderList[i] = NULL; - ThreadStack = (u8 *)MEM1_memalign(32, 32768); + ThreadStack = (u8 *)MEM1_memalign(32, 32768); if(!ThreadStack) - return; + return; LWP_CreateThread(&SoundThread, UpdateThread, this, ThreadStack, 32768, 80); - //gprintf("SHND: Running sound thread\n"); + gprintf("SHND: Running sound thread\n"); } SoundHandler::~SoundHandler() @@ -131,123 +131,123 @@ void SoundHandler::ClearDecoderList() static inline bool CheckMP3Signature(const u8 * buffer) { - const char MP3_Magic[][3] = - { - {'I', 'D', '3'}, //'ID3' - {0xff, 0xfe}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'), - {0xff, 0xff}, //'MPEG ADTS, layer III, v1.0', 'mp3', 'audio/mpeg'), - {0xff, 0xfa}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'), - {0xff, 0xfb}, //'MPEG ADTS, layer III, v1.0', 'mp3', 'audio/mpeg'), - {0xff, 0xf2}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'), - {0xff, 0xf3}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'), - {0xff, 0xf4}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'), - {0xff, 0xf5}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'), - {0xff, 0xf6}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'), - {0xff, 0xf7}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'), - {0xff, 0xe2}, //'MPEG ADTS, layer III, v2.5 [protected]', 'mp3', 'audio/mpeg'), - {0xff, 0xe3}, //'MPEG ADTS, layer III, v2.5', 'mp3', 'audio/mpeg'), - }; + const char MP3_Magic[][3] = + { + {'I', 'D', '3'}, //'ID3' + {0xff, 0xfe}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'), + {0xff, 0xff}, //'MPEG ADTS, layer III, v1.0', 'mp3', 'audio/mpeg'), + {0xff, 0xfa}, //'MPEG ADTS, layer III, v1.0 [protected]', 'mp3', 'audio/mpeg'), + {0xff, 0xfb}, //'MPEG ADTS, layer III, v1.0', 'mp3', 'audio/mpeg'), + {0xff, 0xf2}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'), + {0xff, 0xf3}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'), + {0xff, 0xf4}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'), + {0xff, 0xf5}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'), + {0xff, 0xf6}, //'MPEG ADTS, layer III, v2.0 [protected]', 'mp3', 'audio/mpeg'), + {0xff, 0xf7}, //'MPEG ADTS, layer III, v2.0', 'mp3', 'audio/mpeg'), + {0xff, 0xe2}, //'MPEG ADTS, layer III, v2.5 [protected]', 'mp3', 'audio/mpeg'), + {0xff, 0xe3}, //'MPEG ADTS, layer III, v2.5', 'mp3', 'audio/mpeg'), + }; - if(buffer[0] == MP3_Magic[0][0] && buffer[1] == MP3_Magic[0][1] && - buffer[2] == MP3_Magic[0][2]) - { - return true; - } + if(buffer[0] == MP3_Magic[0][0] && buffer[1] == MP3_Magic[0][1] && + buffer[2] == MP3_Magic[0][2]) + { + return true; + } - for(int i = 1; i < 13; i++) - { - if(buffer[0] == MP3_Magic[i][0] && buffer[1] == MP3_Magic[i][1]) - return true; - } + for(int i = 1; i < 13; i++) + { + if(buffer[0] == MP3_Magic[i][0] && buffer[1] == MP3_Magic[i][1]) + return true; + } - return false; + return false; } SoundDecoder * SoundHandler::GetSoundDecoder(const char * filepath) { - u32 magic; - CFile f(filepath, "rb"); - if(f.size() == 0) - return NULL; + u32 magic; + CFile f(filepath, "rb"); + if(f.size() == 0) + return NULL; - do - { - f.read((u8 *) &magic, 1); - } - while(((u8 *) &magic)[0] == 0 && f.tell() < f.size()); + do + { + f.read((u8 *) &magic, 1); + } + while(((u8 *) &magic)[0] == 0 && f.tell() < f.size()); - if(f.tell() == f.size()) - return NULL; + if(f.tell() == f.size()) + return NULL; - f.seek(f.tell()-1, SEEK_SET); - f.read((u8 *) &magic, 4); - f.close(); + f.seek(f.tell()-1, SEEK_SET); + f.read((u8 *) &magic, 4); + f.close(); /* gprintf("SHND: Searching decoder for magic\n"); ghexdump((u8 *) &magic, 4); */ - if(magic == 'OggS') - { - return new OggDecoder(filepath); - } - else if(magic == 'RIFF') - { - return new WavDecoder(filepath); - } - else if(magic == 'BNS ') - { - return new BNSDecoder(filepath); - } - else if(magic == 'FORM') - { - return new AifDecoder(filepath); - } - else if(CheckMP3Signature((u8 *) &magic) == true) - { - return new Mp3Decoder(filepath); - } + if(magic == 'OggS') + { + return new OggDecoder(filepath); + } + else if(magic == 'RIFF') + { + return new WavDecoder(filepath); + } + else if(magic == 'BNS ') + { + return new BNSDecoder(filepath); + } + else if(magic == 'FORM') + { + return new AifDecoder(filepath); + } + else if(CheckMP3Signature((u8 *) &magic) == true) + { + return new Mp3Decoder(filepath); + } - return new SoundDecoder(filepath); + return new SoundDecoder(filepath); } SoundDecoder * SoundHandler::GetSoundDecoder(const u8 * sound, int length) { - const u8 * check = sound; - int counter = 0; + const u8 * check = sound; + int counter = 0; - while(check[0] == 0 && counter < length) - { - check++; - counter++; - } + while(check[0] == 0 && counter < length) + { + check++; + counter++; + } - if(counter >= length) - return NULL; + if(counter >= length) + return NULL; - u32 * magic = (u32 *) check; + u32 * magic = (u32 *) check; - if(magic[0] == 'OggS') - { - return new OggDecoder(sound, length); - } - else if(magic[0] == 'RIFF') - { - return new WavDecoder(sound, length); - } - else if(magic[0] == 'BNS ') - { - return new BNSDecoder(sound, length); - } - else if(magic[0] == 'FORM') - { - return new AifDecoder(sound, length); - } - else if(CheckMP3Signature(check) == true) - { - return new Mp3Decoder(sound, length); - } + if(magic[0] == 'OggS') + { + return new OggDecoder(sound, length); + } + else if(magic[0] == 'RIFF') + { + return new WavDecoder(sound, length); + } + else if(magic[0] == 'BNS ') + { + return new BNSDecoder(sound, length); + } + else if(magic[0] == 'FORM') + { + return new AifDecoder(sound, length); + } + else if(CheckMP3Signature(check) == true) + { + return new Mp3Decoder(sound, length); + } - return new SoundDecoder(sound, length); + return new SoundDecoder(sound, length); } void * SoundHandler::UpdateThread(void *arg) @@ -258,22 +258,22 @@ void * SoundHandler::UpdateThread(void *arg) void SoundHandler::InternalSoundUpdates() { - u16 i = 0; + u16 i = 0; LWP_InitQueue(&ThreadQueue); - while (!ExitRequested) + while(!ExitRequested) { - LWP_ThreadSleep(ThreadQueue); + LWP_ThreadSleep(ThreadQueue); - for(i = 0; i < MAX_DECODERS; ++i) - { - if(DecoderList[i] == NULL) - continue; + for(i = 0; i < MAX_DECODERS; ++i) + { + if(DecoderList[i] == NULL) + continue; - Decoding = true; - DecoderList[i]->Decode(); - } - Decoding = false; + Decoding = true; + DecoderList[i]->Decode(); + } + Decoding = false; } - LWP_CloseQueue(ThreadQueue); - ThreadQueue = LWP_TQUEUE_NULL; + LWP_CloseQueue(ThreadQueue); + ThreadQueue = LWP_TQUEUE_NULL; }