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

View File

@ -229,6 +229,15 @@ void CVideo::cleanup(void)
if(m_aaBuffer[i].get())
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);
}
@ -507,9 +516,9 @@ void CVideo::hideWaitMessage()
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;
gprintf("Thread running. Stop it\n");

View File

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

View File

@ -3,6 +3,7 @@
#include <string.h>
#include <ogcsys.h>
#include <unistd.h>
#include <ogc/lwp_threads.h>
#include <ogc/lwp_watchdog.h>
#include "wiiuse/wpad.h"
#include <ogc/machine/processor.h>
@ -41,15 +42,19 @@ GXRModeObj *vmode = NULL;
u32 vmode_reg = 0;
static u8 Tmd_Buffer[0x49e4 + 0x1C] ALIGNED(32);
extern void __exception_closeall();
void __Disc_SetLowMem()
{
/* Setup low memory */
*(vu32 *)0x80000030 = 0x00000000; // Arena Low
*(vu32 *)0x80000060 = 0x38A00040;
*(vu32 *)0x800000E4 = 0x80431A80;
*(vu32 *)0x800000EC = 0x81800000; // Dev Debugger Monitor Address
*(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
/* Copy disc ID (online check) */
@ -172,18 +177,18 @@ void __Disc_SetVMode(void)
{
/* Set video mode register */
*(vu32 *)0x800000CC = vmode_reg;
DCFlushRange((void *)(0x800000CC), 4);
ICInvalidateRange((void *)(0x800000CC), 4);
/* Set video mode */
if (vmode != 0)
VIDEO_Configure(vmode);
if (disc_vmode != 0)
VIDEO_Configure(disc_vmode);
/* Setup video */
VIDEO_SetBlack(TRUE);
VIDEO_Flush();
VIDEO_WaitVSync();
if (vmode->viTVMode & VI_NON_INTERLACE)
VIDEO_WaitVSync();
else while (VIDEO_GetNextField())
if(disc_vmode->viTVMode & VI_NON_INTERLACE)
VIDEO_WaitVSync();
}
@ -193,7 +198,7 @@ void __Disc_SetTime(void)
settime(secs_to_ticks(time(NULL) - 946684800));
}
s32 __Disc_FindPartition(u64 *outbuf)
s32 Disc_FindPartition(u64 *outbuf)
{
u64 offset = 0;
u32 cnt;
@ -344,46 +349,13 @@ s32 Disc_IsGC(void)
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();
if (hooktype != 0)
ocarina_do_code();
gprintf("\n\nEntry Point is: 0x%08x\n", p_entry);
appentrypoint = (u32)p_entry;
/* Set time */
__Disc_SetTime();
@ -393,7 +365,9 @@ s32 Disc_BootPartition(u64 offset, u8 vidMode, bool vipatch, bool countryString,
usleep(100 * 1000);
/* Shutdown IOS subsystems */
Sys_Shutdown();
u32 level = IRQ_Disable();
__IOS_ShutdownSubsystems();
__exception_closeall();
/* Originally from tueidj - taken from NeoGamma (thx) */
*(vu32*)0xCC003024 = 1;
@ -402,7 +376,7 @@ s32 Disc_BootPartition(u64 offset, u8 vidMode, bool vipatch, bool countryString,
if (hooktype != 0)
{
__asm__(
asm volatile (
"lis %r3, appentrypoint@h\n"
"ori %r3, %r3, appentrypoint@l\n"
"lwz %r3, 0(%r3)\n"
@ -416,7 +390,7 @@ s32 Disc_BootPartition(u64 offset, u8 vidMode, bool vipatch, bool countryString,
}
else
{
__asm__(
asm volatile (
"lis %r3, appentrypoint@h\n"
"ori %r3, %r3, appentrypoint@l\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;
}
s32 Disc_WiiBoot(u8 vidMode, bool vipatch, bool countryString, u8 patchVidModes, bool disableIOSreload, int aspectRatio)
s32 Disc_WiiBoot(u32 AppEntryPoint)
{
u64 offset;
/* Find game partition offset */
s32 ret = __Disc_FindPartition(&offset);
if (ret < 0)
{
gprintf("Game Partition not found!\n");
return ret;
}
appentrypoint = AppEntryPoint;
/* 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_IsWii(void);
s32 Disc_IsGC(void);
s32 Disc_BootPartition(u64, u8, bool, bool, u8, bool, int);
s32 Disc_WiiBoot(u8, bool, bool, u8, bool, int);
s32 Disc_BootPartition();
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
}

View File

@ -26,10 +26,6 @@ static bool return_to_priiloader = false;
static bool return_to_disable = 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()
{
/* Poweroff console */
@ -142,39 +138,3 @@ void Sys_LoadMenu(void)
/* Return to the Wii system menu */
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_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 */
void Sys_Init(void);
void Sys_LoadMenu(void);

View File

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

View File

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

View File

@ -1,5 +1,4 @@
#include "menu.hpp"
#include "loader/patchcode.h"
@ -8,6 +7,7 @@
#include "loader/alt_ios.h"
#include "loader/playlog.h"
#include <ogc/machine/processor.h>
#include <ogc/lwp_threads.h>
#include <unistd.h>
#include <time.h>
#include "network/http.h"
@ -33,6 +33,7 @@
#include "homebrew.h"
#include "defines.h"
#include "gc/gc.h"
#include "gekko.h"
extern const u8 btngamecfg_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();
// wifi-gecko can no longer function after cleanup
Close_Inputs();
USBStorage_Deinit();
if(currentPartition == 0)
SDHC_Init();
// Stop wait message thread
m_vid.hideWaitMessage();
usleep(100 * 1000);
// clear mem1 main
u32 size = (u32)0x80a00000 - (u32)0x80004000;
memset((void*)0x80004000, 0, size);
DCFlushRange((void*)0x80004000, size);
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();
}