-using cfg-loader entry point now, its a bit lower ;)

-clearing screen properly now, no green screens or things like this
-added a few more low mem settings, fixed a missing flush in set
video mode (thanks dimok)
-partially clearing mem1 too now, using the code of cfg-loader for that
(thanks)
-using asm volatile instead of __asm__ to really call what we want
(thanks dimok for explaination)
-deiniting usb device properly
-shutting down system properly now on game boot, games should boot
more often now, its still not fully fixed
This commit is contained in:
fix94.1 2012-05-15 21:33:53 +00:00
parent a728a96480
commit 08a298b0b7
12 changed files with 134 additions and 163 deletions

View File

@ -73,7 +73,7 @@ ios := 249
CFLAGS = -g -Os -Wall -Wextra -Wno-multichar $(MACHDEP) $(INCLUDE) -DHAVE_CONFIG_H CFLAGS = -g -Os -Wall -Wextra -Wno-multichar $(MACHDEP) $(INCLUDE) -DHAVE_CONFIG_H
CXXFLAGS = $(CFLAGS) CXXFLAGS = $(CFLAGS)
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80B00000,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80A80000,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project # any extra libraries we wish to link with the project

View File

@ -229,6 +229,15 @@ void CVideo::cleanup(void)
if(m_aaBuffer[i].get()) if(m_aaBuffer[i].get())
m_aaBuffer[i].release(); m_aaBuffer[i].release();
} }
GX_AbortFrame();
GX_Flush();
VIDEO_SetBlack(TRUE);
VIDEO_Flush();
VIDEO_WaitVSync();
if (m_rmode->viTVMode & VI_NON_INTERLACE)
VIDEO_WaitVSync();
//MEM1_free(m_fifo); //MEM1_free(m_fifo);
} }
@ -507,9 +516,9 @@ void CVideo::hideWaitMessage()
wiiLightOff(); wiiLightOff();
} }
void CVideo::CheckWaitThread() void CVideo::CheckWaitThread(bool force)
{ {
if (!m_showingWaitMessages && waitThread != LWP_THREAD_NULL) if ((!m_showingWaitMessages && waitThread != LWP_THREAD_NULL) || force)
{ {
m_showWaitMessage = false; m_showWaitMessage = false;
gprintf("Thread running. Stop it\n"); gprintf("Thread running. Stop it\n");

View File

@ -70,7 +70,7 @@ public:
void waitMessage(float delay); void waitMessage(float delay);
void waitMessage(const vector<STexture> &tex, float delay, bool useWiiLight = true); void waitMessage(const vector<STexture> &tex, float delay, bool useWiiLight = true);
void waitMessage(const STexture &tex); void waitMessage(const STexture &tex);
void CheckWaitThread(); void CheckWaitThread(bool force = false);
s32 TakeScreenshot(const char *); s32 TakeScreenshot(const char *);
void shiftViewPort(float x, float y); void shiftViewPort(float x, float y);
private: private:

View File

@ -3,6 +3,7 @@
#include <string.h> #include <string.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <unistd.h> #include <unistd.h>
#include <ogc/lwp_threads.h>
#include <ogc/lwp_watchdog.h> #include <ogc/lwp_watchdog.h>
#include "wiiuse/wpad.h" #include "wiiuse/wpad.h"
#include <ogc/machine/processor.h> #include <ogc/machine/processor.h>
@ -41,15 +42,19 @@ GXRModeObj *vmode = NULL;
u32 vmode_reg = 0; u32 vmode_reg = 0;
static u8 Tmd_Buffer[0x49e4 + 0x1C] ALIGNED(32); static u8 Tmd_Buffer[0x49e4 + 0x1C] ALIGNED(32);
extern void __exception_closeall();
void __Disc_SetLowMem() void __Disc_SetLowMem()
{ {
/* Setup low memory */ /* Setup low memory */
*(vu32 *)0x80000030 = 0x00000000; // Arena Low
*(vu32 *)0x80000060 = 0x38A00040; *(vu32 *)0x80000060 = 0x38A00040;
*(vu32 *)0x800000E4 = 0x80431A80; *(vu32 *)0x800000E4 = 0x80431A80;
*(vu32 *)0x800000EC = 0x81800000; // Dev Debugger Monitor Address *(vu32 *)0x800000EC = 0x81800000; // Dev Debugger Monitor Address
*(vu32 *)0x800000F0 = 0x01800000; // Simulated Memory Size *(vu32 *)0x800000F0 = 0x01800000; // Simulated Memory Size
*(vu32 *)0x800000F4 = 0x817E5480;
*(vu32 *)0x800000F8 = 0x0E7BE2C0; // bus speed
*(vu32 *)0x800000FC = 0x2B73A840; // cpu speed
*(vu32 *)0xCD00643C = 0x00000000; // 32Mhz on Bus *(vu32 *)0xCD00643C = 0x00000000; // 32Mhz on Bus
/* Copy disc ID (online check) */ /* Copy disc ID (online check) */
@ -172,18 +177,18 @@ void __Disc_SetVMode(void)
{ {
/* Set video mode register */ /* Set video mode register */
*(vu32 *)0x800000CC = vmode_reg; *(vu32 *)0x800000CC = vmode_reg;
DCFlushRange((void *)(0x800000CC), 4);
ICInvalidateRange((void *)(0x800000CC), 4);
/* Set video mode */ /* Set video mode */
if (vmode != 0) if (disc_vmode != 0)
VIDEO_Configure(vmode); VIDEO_Configure(disc_vmode);
/* Setup video */ /* Setup video */
VIDEO_SetBlack(TRUE); VIDEO_SetBlack(TRUE);
VIDEO_Flush(); VIDEO_Flush();
VIDEO_WaitVSync(); VIDEO_WaitVSync();
if (vmode->viTVMode & VI_NON_INTERLACE) if(disc_vmode->viTVMode & VI_NON_INTERLACE)
VIDEO_WaitVSync();
else while (VIDEO_GetNextField())
VIDEO_WaitVSync(); VIDEO_WaitVSync();
} }
@ -193,7 +198,7 @@ void __Disc_SetTime(void)
settime(secs_to_ticks(time(NULL) - 946684800)); settime(secs_to_ticks(time(NULL) - 946684800));
} }
s32 __Disc_FindPartition(u64 *outbuf) s32 Disc_FindPartition(u64 *outbuf)
{ {
u64 offset = 0; u64 offset = 0;
u32 cnt; u32 cnt;
@ -344,46 +349,13 @@ s32 Disc_IsGC(void)
return Disc_Type(1); return Disc_Type(1);
} }
s32 Disc_BootPartition(u64 offset, u8 vidMode, bool vipatch, bool countryString, u8 patchVidMode, bool disableIOSreload, int aspectRatio) s32 Disc_BootPartition()
{ {
entry_point p_entry;
if (disableIOSreload)
IOSReloadBlock(IOS_GetVersion(), false);
else
IOSReloadBlock(IOS_GetVersion(), true);
s32 ret = WDVD_OpenPartition(offset, 0, 0, 0, Tmd_Buffer);
if (ret < 0)
return ret;
/* Greenscreen Fix */
VIDEO_SetBlack(TRUE);
VIDEO_Flush();
VIDEO_WaitVSync();
/* Clear memory */
MEM2_clear();
/* Setup low memory */;
__Disc_SetLowMem();
/* Select an appropriate video mode */
__Disc_SelectVMode(vidMode, 0);
/* Run apploader */
ret = Apploader_Run(&p_entry, vidMode, vmode, vipatch, countryString, patchVidMode, aspectRatio);
if (ret < 0)
return ret;
free_wip(); free_wip();
if (hooktype != 0) if (hooktype != 0)
ocarina_do_code(); ocarina_do_code();
gprintf("\n\nEntry Point is: 0x%08x\n", p_entry);
appentrypoint = (u32)p_entry;
/* Set time */ /* Set time */
__Disc_SetTime(); __Disc_SetTime();
@ -393,16 +365,18 @@ s32 Disc_BootPartition(u64 offset, u8 vidMode, bool vipatch, bool countryString,
usleep(100 * 1000); usleep(100 * 1000);
/* Shutdown IOS subsystems */ /* Shutdown IOS subsystems */
Sys_Shutdown(); u32 level = IRQ_Disable();
__IOS_ShutdownSubsystems();
__exception_closeall();
/* Originally from tueidj - taken from NeoGamma (thx) */ /* Originally from tueidj - taken from NeoGamma (thx) */
*(vu32*)0xCC003024 = 1; *(vu32*)0xCC003024 = 1;
gprintf("Jumping to entrypoint\n"); gprintf("Jumping to entry point\n");
if (hooktype != 0) if (hooktype != 0)
{ {
__asm__( asm volatile (
"lis %r3, appentrypoint@h\n" "lis %r3, appentrypoint@h\n"
"ori %r3, %r3, appentrypoint@l\n" "ori %r3, %r3, appentrypoint@l\n"
"lwz %r3, 0(%r3)\n" "lwz %r3, 0(%r3)\n"
@ -416,7 +390,7 @@ s32 Disc_BootPartition(u64 offset, u8 vidMode, bool vipatch, bool countryString,
} }
else else
{ {
__asm__( asm volatile (
"lis %r3, appentrypoint@h\n" "lis %r3, appentrypoint@h\n"
"ori %r3, %r3, appentrypoint@l\n" "ori %r3, %r3, appentrypoint@l\n"
"lwz %r3, 0(%r3)\n" "lwz %r3, 0(%r3)\n"
@ -425,21 +399,44 @@ s32 Disc_BootPartition(u64 offset, u8 vidMode, bool vipatch, bool countryString,
); );
} }
IRQ_Restore(level);
return 0; return 0;
} }
s32 Disc_WiiBoot(u8 vidMode, bool vipatch, bool countryString, u8 patchVidModes, bool disableIOSreload, int aspectRatio) s32 Disc_WiiBoot(u32 AppEntryPoint)
{ {
u64 offset; appentrypoint = AppEntryPoint;
/* Find game partition offset */
s32 ret = __Disc_FindPartition(&offset);
if (ret < 0)
{
gprintf("Game Partition not found!\n");
return ret;
}
/* Boot partition */ /* Boot partition */
return Disc_BootPartition(offset, vidMode, vipatch, countryString, patchVidModes, disableIOSreload, aspectRatio); return Disc_BootPartition();
}
u32 RunApploader(u64 offset, u8 vidMode, bool vipatch, bool countryString, u8 patchVidMode, bool disableIOSreload, int aspectRatio)
{
gprintf("Running Apploader...\n");
entry_point p_entry;
if (disableIOSreload)
IOSReloadBlock(IOS_GetVersion(), false);
else
IOSReloadBlock(IOS_GetVersion(), true);
s32 ret = WDVD_OpenPartition(offset, 0, 0, 0, Tmd_Buffer);
if (ret < 0)
return ret;
/* Setup low memory */;
__Disc_SetLowMem();
/* Select an appropriate video mode */
__Disc_SelectVMode(vidMode, 0);
/* Run apploader */
ret = Apploader_Run(&p_entry, vidMode, vmode, vipatch, countryString, patchVidMode, aspectRatio);
if (ret < 0)
return ret;
return (u32)p_entry;
} }

View File

@ -102,8 +102,11 @@ s32 Disc_ReadGCHeader(void *);
s32 Disc_Type(bool); s32 Disc_Type(bool);
s32 Disc_IsWii(void); s32 Disc_IsWii(void);
s32 Disc_IsGC(void); s32 Disc_IsGC(void);
s32 Disc_BootPartition(u64, u8, bool, bool, u8, bool, int); s32 Disc_BootPartition();
s32 Disc_WiiBoot(u8, bool, bool, u8, bool, int); s32 Disc_WiiBoot(u32);
s32 Disc_FindPartition(u64 *outbuf);
u32 RunApploader(u64 offset, u8 vidMode, bool vipatch, bool countryString, u8 patchVidMode, bool disableIOSreload, int aspectRatio);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -26,10 +26,6 @@ static bool return_to_priiloader = false;
static bool return_to_disable = false; static bool return_to_disable = false;
static bool return_to_bootmii = false; static bool return_to_bootmii = false;
extern void __exception_closeall();
static vu16* const _dspReg = (u16*)0xCC005000;
extern u32 __PADDisableRecalibration(s32 disable);
void __Wpad_PowerCallback() void __Wpad_PowerCallback()
{ {
/* Poweroff console */ /* Poweroff console */
@ -142,39 +138,3 @@ 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
} }
static void __dsp_shutdown()
{
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);
}
//Modified libogc call
void Sys_Shutdown(void)
{
Close_Inputs();
__dsp_shutdown();
u32 ret = __PADDisableRecalibration(TRUE);
__IOS_ShutdownSubsystems();
__exception_closeall();
LCDisable();
__lwp_thread_closeall();
__PADDisableRecalibration(ret);
}

View File

@ -18,17 +18,6 @@ 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);

View File

@ -36,7 +36,7 @@ extern "C"
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
__exception_setreload(5); __exception_setreload(5);
MEM2_init(52); 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);

View File

@ -47,6 +47,7 @@ void MEM1_free(void *p)
void MEM2_init(unsigned int mem2Size) void MEM2_init(unsigned int mem2Size)
{ {
g_mem2gp.init(mem2Size); g_mem2gp.init(mem2Size);
g_mem2gp.clear();
} }
void MEM2_cleanup(void) void MEM2_cleanup(void)

View File

@ -481,6 +481,7 @@ void CMenu::cleanup(bool ios_reload)
if(!m_reload) if(!m_reload)
m_vid.cleanup(); m_vid.cleanup();
wiiLightOff();
if (!ios_reload) if (!ios_reload)
{ {
@ -488,15 +489,11 @@ void CMenu::cleanup(bool ios_reload)
m_mutex = 0; m_mutex = 0;
} }
DeviceHandler::DestroyInstance();
if (!ios_reload) if (!ios_reload)
_cleanupDefaultFont(); _cleanupDefaultFont();
if (!ios_reload || (!m_use_wifi_gecko && ios_reload)) if (!ios_reload || (!m_use_wifi_gecko && ios_reload))
_deinitNetwork(); _deinitNetwork();
wiiLightOff();
gprintf(" \nMemory cleaned up\n"); gprintf(" \nMemory cleaned up\n");
} }

View File

@ -1,5 +1,4 @@
#include "menu.hpp" #include "menu.hpp"
#include "loader/patchcode.h" #include "loader/patchcode.h"
@ -8,6 +7,7 @@
#include "loader/alt_ios.h" #include "loader/alt_ios.h"
#include "loader/playlog.h" #include "loader/playlog.h"
#include <ogc/machine/processor.h> #include <ogc/machine/processor.h>
#include <ogc/lwp_threads.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include "network/http.h" #include "network/http.h"
@ -33,6 +33,7 @@
#include "homebrew.h" #include "homebrew.h"
#include "defines.h" #include "defines.h"
#include "gc/gc.h" #include "gc/gc.h"
#include "gekko.h"
extern const u8 btngamecfg_png[]; extern const u8 btngamecfg_png[];
extern const u8 btngamecfgs_png[]; extern const u8 btngamecfgs_png[];
@ -1278,20 +1279,34 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
} }
} }
while(net_get_status() == -EBUSY); while(net_get_status() == -EBUSY)
usleep(100);
m_vid.CheckWaitThread(true);
cleanup(); cleanup();
// wifi-gecko can no longer function after cleanup // wifi-gecko can no longer function after cleanup
Close_Inputs(); Close_Inputs();
USBStorage_Deinit();
if(currentPartition == 0) if(currentPartition == 0)
SDHC_Init(); SDHC_Init();
// Stop wait message thread // clear mem1 main
m_vid.hideWaitMessage(); u32 size = (u32)0x80a00000 - (u32)0x80004000;
usleep(100 * 1000); memset((void*)0x80004000, 0, size);
DCFlushRange((void*)0x80004000, size);
gprintf("Booting game\n"); gprintf("Booting game\n");
if (Disc_WiiBoot(videoMode, vipatch, countryPatch, patchVidMode, disableIOSreload, aspectRatio) < 0)
/* Find game partition offset */
u64 offset;
Disc_FindPartition(&offset);
u32 AppEntryPoint = RunApploader(offset, videoMode, vipatch, countryPatch, patchVidMode, disableIOSreload, aspectRatio);
DeviceHandler::DestroyInstance();
USBStorage_Deinit();
MEM2_clear();
gprintf("\n\nEntry Point is: 0x%08x\n", AppEntryPoint);
if (Disc_WiiBoot(AppEntryPoint) < 0)
Sys_LoadMenu(); Sys_LoadMenu();
} }

View File

@ -46,45 +46,45 @@ enum
class SoundDecoder class SoundDecoder
{ {
public: public:
SoundDecoder(); SoundDecoder();
SoundDecoder(const char * filepath); SoundDecoder(const char * filepath);
SoundDecoder(const u8 * buffer, int size); SoundDecoder(const u8 * buffer, int size);
~SoundDecoder(); ~SoundDecoder();
virtual int Read(u8 * buffer, int buffer_size, int pos); virtual int Read(u8 * buffer, int buffer_size, int pos);
virtual int Tell() { return CurPos; }; virtual int Tell() { return CurPos; };
virtual int Seek(int pos) { CurPos = pos; return file_fd->seek(CurPos, SEEK_SET); }; virtual int Seek(int pos) { CurPos = pos; return file_fd->seek(CurPos, SEEK_SET); };
virtual int Rewind(); virtual int Rewind();
virtual int GetFormat() { return VOICE_STEREO_16BIT; }; virtual int GetFormat() { return VOICE_STEREO_16BIT; };
virtual int GetSampleRate() { return 48000; }; virtual int GetSampleRate() { return 48000; };
virtual void Decode(); virtual void Decode();
virtual u32 GetBufferSize() { return SoundBuffer.GetBufferSize(); }; virtual u32 GetBufferSize() { return SoundBuffer.GetBufferSize(); };
virtual u8 * GetBuffer() { return SoundBuffer.GetBuffer(); }; virtual u8 * GetBuffer() { return SoundBuffer.GetBuffer(); };
virtual u8 * GetNextBuffer() { return SoundBuffer.GetNextBuffer(); }; virtual u8 * GetNextBuffer() { return SoundBuffer.GetNextBuffer(); };
virtual u8 * GetLastBuffer() { return SoundBuffer.GetLastBuffer(); }; virtual u8 * GetLastBuffer() { return SoundBuffer.GetLastBuffer(); };
virtual void LoadNext() { SoundBuffer.LoadNext(); }; virtual void LoadNext() { SoundBuffer.LoadNext(); };
virtual bool IsBufferReady() { return SoundBuffer.IsBufferReady(); }; virtual bool IsBufferReady() { return SoundBuffer.IsBufferReady(); };
virtual bool IsNextBufferReady() { return SoundBuffer.IsNextBufferReady(); }; virtual bool IsNextBufferReady() { return SoundBuffer.IsNextBufferReady(); };
virtual bool IsLastBufferReady() { return SoundBuffer.IsLastBufferReady(); }; virtual bool IsLastBufferReady() { return SoundBuffer.IsLastBufferReady(); };
virtual bool IsEOF() { return EndOfFile; }; virtual bool IsEOF() { return EndOfFile; };
virtual void SetLoop(bool l) { Loop = l; }; virtual void SetLoop(bool l) { Loop = l; };
virtual u8 GetSoundType() { return SoundType; }; virtual u8 GetSoundType() { return SoundType; };
virtual void ClearBuffer() { SoundBuffer.ClearBuffer(); }; virtual void ClearBuffer() { SoundBuffer.ClearBuffer(); };
virtual bool IsStereo() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_STEREO_8BIT); }; virtual bool IsStereo() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_STEREO_8BIT); };
virtual bool Is16Bit() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_MONO_16BIT); }; virtual bool Is16Bit() { return (GetFormat() == VOICE_STEREO_16BIT || GetFormat() == VOICE_MONO_16BIT); };
protected: protected:
void Init(); void Init();
CFile * file_fd; CFile * file_fd;
BufferCircle SoundBuffer; BufferCircle SoundBuffer;
u8 SoundType; u8 SoundType;
u16 SoundBlocks; u16 SoundBlocks;
int SoundBlockSize; int SoundBlockSize;
int CurPos; int CurPos;
bool Loop; bool Loop;
bool EndOfFile; bool EndOfFile;
bool Decoding; bool Decoding;
bool ExitRequested; bool ExitRequested;
}; };
#endif #endif