-proper cleanup of video now, no more greenscreens should come

on game booting
-moved partition read buffer on game boot to mem1, faster
This commit is contained in:
fix94.1 2012-05-17 12:47:27 +00:00
parent 0a90ae532e
commit f94e65a54d
6 changed files with 155 additions and 142 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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;

View File

@ -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)
{

View File

@ -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;
}

View File

@ -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;
}