diff --git a/source/channel/channel_launcher.c b/source/channel/channel_launcher.c index abeaf0db..d150167d 100644 --- a/source/channel/channel_launcher.c +++ b/source/channel/channel_launcher.c @@ -21,9 +21,7 @@ type *name = (type*)(((u32)(_al__##name)) + ((alignment) - (( \ (u32)(_al__##name))&((alignment)-1)))) -GXRModeObj * __Disc_SelectVMode(u8 videoselected, u64 chantitle); void __Disc_SetLowMem(void); -void __Disc_SetVMode(void); void __Disc_SetTime(void); void _unstub_start(); u32 entryPoint; @@ -49,7 +47,8 @@ s32 BootChannel(u32 entry, u64 chantitle, u32 ios, u8 vidMode, bool vipatch, boo entryPoint = entry; /* Select an appropriate video mode */ - GXRModeObj * vmode = __Disc_SelectVMode(vidMode, chantitle); + u32 vmode_reg = 0; + GXRModeObj *vmode = Disc_SelectVMode(vidMode, chantitle, &vmode_reg); /* Set time */ __Disc_SetTime(); @@ -65,7 +64,7 @@ s32 BootChannel(u32 entry, u64 chantitle, u32 ios, u8 vidMode, bool vipatch, boo entrypoint appJump = (entrypoint)entryPoint; /* Set an appropriate video mode */ - __Disc_SetVMode(); + Disc_SetVMode(vmode, vmode_reg); // IOS Version Check *(vu32*)0x80003140 = ((ios << 16)) | 0xFFFF; diff --git a/source/gc/gc.c b/source/gc/gc.c index 876db8bb..a36b4f9b 100644 --- a/source/gc/gc.c +++ b/source/gc/gc.c @@ -8,6 +8,7 @@ #include "fileOps.h" #include "utils.h" #include "memory/mem2.hpp" +#include "loader/disc.h" // for directory parsing and low-level file I/O #include @@ -262,8 +263,8 @@ void GC_SetVideoMode(u8 videomode, u8 videoSetting) { syssram *sram; sram = __SYS_LockSram(); - static GXRModeObj *rmode; - int memflag = 0; + GXRModeObj *vmode = VIDEO_GetPreferredMode(0); + int vmode_reg = 0; if((VIDEO_HaveComponentCable() && (CONF_GetProgressiveScan() > 0)) || videomode > 3) sram->flags |= 0x80; //set progressive flag @@ -272,7 +273,7 @@ void GC_SetVideoMode(u8 videomode, u8 videoSetting) if(videomode == 1 || videomode == 3 || videomode == 5) { - memflag = 1; + vmode_reg = 1; sram->flags |= 0x01; // Set bit 0 to set the video mode to PAL sram->ntd |= 0x40; //set pal60 flag } @@ -286,52 +287,40 @@ void GC_SetVideoMode(u8 videomode, u8 videoSetting) { if(DMLCfg != NULL && videoSetting == 2) DMLCfg->VideoMode |= DML_VID_FORCE_PAL50; - rmode = &TVPal528IntDf; + vmode = &TVPal528IntDf; } else if(videomode == 2) { if(DMLCfg != NULL && videoSetting == 2) DMLCfg->VideoMode |= DML_VID_FORCE_NTSC; - rmode = &TVNtsc480IntDf; + vmode = &TVNtsc480IntDf; } else if(videomode == 3) { if(DMLCfg != NULL && videoSetting == 2) DMLCfg->VideoMode |= DML_VID_FORCE_PAL60; - rmode = &TVEurgb60Hz480IntDf; - memflag = 5; + vmode = &TVEurgb60Hz480IntDf; + vmode_reg = 5; } else if(videomode == 4 ||videomode == 6) { if(DMLCfg != NULL && videoSetting == 2) DMLCfg->VideoMode |= DML_VID_FORCE_PROG; - rmode = &TVNtsc480Prog; + vmode = &TVNtsc480Prog; } else if(videomode == 5 || videomode == 7) { if(DMLCfg != NULL && videoSetting == 2) DMLCfg->VideoMode |= DML_VID_FORCE_PROG; - rmode = &TVNtsc480Prog; - memflag = 5; + vmode = &TVNtsc480Prog; + vmode_reg = 5; } __SYS_UnlockSram(1); // 1 -> write changes while(!__SYS_SyncSram()); - /* Set video mode register */ - *(vu32 *)0x800000CC = memflag; - DCFlushRange((void *)(0x800000CC), 4); - - /* Set video mode */ - if (rmode != 0) - VIDEO_Configure(rmode); - - /* Setup video */ - VIDEO_SetBlack(TRUE); - VIDEO_Flush(); - VIDEO_WaitVSync(); - if(rmode->viTVMode & VI_NON_INTERLACE) - VIDEO_WaitVSync(); + /* Set an appropriate video mode */ + Disc_SetVMode(vmode, vmode_reg); } u8 get_wii_language() diff --git a/source/loader/disc.c b/source/loader/disc.c index b90762c1..712db0af 100644 --- a/source/loader/disc.c +++ b/source/loader/disc.c @@ -65,9 +65,9 @@ void __Disc_SetLowMem() memcpy((void *)Online_Check, (void *)Disc_ID, 4); } -GXRModeObj * __Disc_SelectVMode(u8 videoselected, u64 chantitle) +GXRModeObj *Disc_SelectVMode(u8 videoselected, u64 chantitle, u32 *rmode_reg) { - vmode = VIDEO_GetPreferredMode(0); + GXRModeObj *rmode = VIDEO_GetPreferredMode(0); /* Get video mode configuration */ bool progressive = (CONF_GetProgressiveScan() > 0) && VIDEO_HaveComponentCable(); @@ -78,19 +78,19 @@ GXRModeObj * __Disc_SelectVMode(u8 videoselected, u64 chantitle) case CONF_VIDEO_PAL: if (CONF_GetEuRGB60() > 0) { - vmode_reg = VI_EURGB60; - vmode = progressive ? &TVNtsc480Prog : &TVEurgb60Hz480IntDf; + *rmode_reg = VI_EURGB60; + rmode = progressive ? &TVNtsc480Prog : &TVEurgb60Hz480IntDf; } else - vmode_reg = VI_PAL; + *rmode_reg = VI_PAL; break; case CONF_VIDEO_MPAL: - vmode_reg = VI_MPAL; + *rmode_reg = VI_MPAL; break; case CONF_VIDEO_NTSC: - vmode_reg = VI_NTSC; + *rmode_reg = VI_NTSC; break; } @@ -116,8 +116,8 @@ GXRModeObj * __Disc_SelectVMode(u8 videoselected, u64 chantitle) case 'Y': if(CONF_GetVideo() != CONF_VIDEO_PAL) { - vmode_reg = VI_PAL; - vmode = progressive ? &TVNtsc480Prog : &TVNtsc480IntDf; + *rmode_reg = VI_PAL; + rmode = progressive ? &TVNtsc480Prog : &TVNtsc480IntDf; } break; // NTSC @@ -126,8 +126,8 @@ GXRModeObj * __Disc_SelectVMode(u8 videoselected, u64 chantitle) default: if(CONF_GetVideo() != CONF_VIDEO_NTSC) { - vmode_reg = VI_NTSC; - vmode = progressive ? &TVNtsc480Prog : &TVEurgb60Hz480IntDf; + *rmode_reg = VI_NTSC; + rmode = progressive ? &TVNtsc480Prog : &TVEurgb60Hz480IntDf; } break; } @@ -135,43 +135,51 @@ GXRModeObj * __Disc_SelectVMode(u8 videoselected, u64 chantitle) case 1: // SYSTEM break; case 2: // PAL50 - vmode = &TVPal528IntDf; - vmode_reg = vmode->viTVMode >> 2; + rmode = &TVPal528IntDf; + *rmode_reg = rmode->viTVMode >> 2; break; case 3: // PAL60 - vmode = progressive ? &TVNtsc480Prog : &TVEurgb60Hz480IntDf; - vmode_reg = progressive ? TVEurgb60Hz480Prog.viTVMode >> 2 : vmode->viTVMode >> 2; + rmode = progressive ? &TVNtsc480Prog : &TVEurgb60Hz480IntDf; + *rmode_reg = progressive ? TVEurgb60Hz480Prog.viTVMode >> 2 : rmode->viTVMode >> 2; break; case 4: // NTSC - vmode = progressive ? &TVNtsc480Prog : &TVNtsc480IntDf; - vmode_reg = vmode->viTVMode >> 2; + rmode = progressive ? &TVNtsc480Prog : &TVNtsc480IntDf; + *rmode_reg = rmode->viTVMode >> 2; break; case 5: // PROGRESSIVE 480P - vmode = &TVNtsc480Prog; - vmode_reg = Region == 'P' ? TVEurgb60Hz480Prog.viTVMode >> 2 : vmode->viTVMode >> 2; + rmode = &TVNtsc480Prog; + *rmode_reg = Region == 'P' ? TVEurgb60Hz480Prog.viTVMode >> 2 : rmode->viTVMode >> 2; break; default: break; } - - return vmode; + return rmode; } -void __Disc_SetVMode(void) +void Disc_SetVMode(GXRModeObj *rmode, u32 rmode_reg) { /* Set video mode register */ - *(vu32 *)0x800000CC = vmode_reg; - DCFlushRange((void *)(0x800000CC), 4); + *Video_Mode = rmode_reg; + DCFlushRange((void*)Video_Mode, 4); /* Set video mode */ - if(vmode != 0) - VIDEO_Configure(vmode); + if(rmode != 0) + VIDEO_Configure(rmode); /* Setup video */ + VIDEO_SetBlack(FALSE); + VIDEO_Flush(); + VIDEO_WaitVSync(); + if(rmode->viTVMode & VI_NON_INTERLACE) + VIDEO_WaitVSync(); + else while(VIDEO_GetNextField()) + VIDEO_WaitVSync(); + + /* Set black and flush */ VIDEO_SetBlack(TRUE); VIDEO_Flush(); VIDEO_WaitVSync(); - if(vmode->viTVMode & VI_NON_INTERLACE) + if(rmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); else while(VIDEO_GetNextField()) VIDEO_WaitVSync(); @@ -363,7 +371,7 @@ s32 Disc_BootPartition() __Disc_SetTime(); /* Set an appropriate video mode */ - __Disc_SetVMode(); + Disc_SetVMode(vmode, vmode_reg); /* Shutdown IOS subsystems */ u32 level = IRQ_Disable(); @@ -411,7 +419,7 @@ void RunApploader(u64 offset, u8 vidMode, bool vipatch, bool countryString, u8 p __Disc_SetLowMem(); /* Select an appropriate video mode */ - __Disc_SelectVMode(vidMode, 0); + vmode = Disc_SelectVMode(vidMode, 0, &vmode_reg); /* Run apploader */ Apploader_Run(&p_entry, vidMode, vmode, vipatch, countryString, patchVidMode, aspectRatio, returnTo); diff --git a/source/loader/disc.h b/source/loader/disc.h index fb895814..9a06b9c2 100644 --- a/source/loader/disc.h +++ b/source/loader/disc.h @@ -106,6 +106,9 @@ s32 Disc_IsGC(void); s32 Disc_BootPartition(); s32 Disc_FindPartition(u64 *outbuf); +GXRModeObj *Disc_SelectVMode(u8 videoselected, u64 chantitle, u32 *rmode_reg); +void Disc_SetVMode(GXRModeObj *rmode, u32 rmode_reg); + void RunApploader(u64 offset, u8 vidMode, bool vipatch, bool countryString, u8 patchVidMode, int aspectRatio, u32 returnTo); #ifdef __cplusplus