From 96368989fdfcfd912b50c29fb31d440fb0616899 Mon Sep 17 00:00:00 2001 From: Abdelali221 <196317120+abdelali221@users.noreply.github.com> Date: Wed, 1 Oct 2025 20:24:16 +0100 Subject: [PATCH 1/6] exception : made some major improvements 1 - It's now possible to see the last frame rendered by the software. 2 - The way the exception details are displayed was changed, it's more tight now (as per blackb0x's request). 3 - Changed control mapping (as per blackb0x's request as well). 4 - Fixed a bug with the GameCube controller not working if PAD_Init() wasn't called by the software (thanks to DacoTaco who pointed the potential issue). --- libogc/exception.c | 81 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 17 deletions(-) diff --git a/libogc/exception.c b/libogc/exception.c index 8773e417..7ad2f0b9 100644 --- a/libogc/exception.c +++ b/libogc/exception.c @@ -61,11 +61,14 @@ typedef struct _framerec { } frame_rec, *frame_rec_t; static void *exception_xfb = (void*)0xC1700000; //we use a static address above ArenaHi. +static void *lookup_xfb = NULL; static int reload_timer = -1; void __exception_sethandler(u32 nExcept, void (*pHndl)(frame_context*)); extern void udelay(int us); +extern s32 CONF_GetEuRGB60(void); +extern s32 CONF_GetProgressiveScan(void); extern void fpu_exceptionhandler(frame_context*); extern void irq_exceptionhandler(frame_context*); extern void dec_exceptionhandler(frame_context*); @@ -198,40 +201,76 @@ void __exception_setreload(int t) reload_timer = t*50; } +void __exception_setlookupxfb(void *xfb) { + lookup_xfb = (u32 *)xfb; +} + +static void __toggleframebuffer() { + static bool currfb = false; + if(currfb) { + currfb = false; + VIDEO_SetFramebuffer(exception_xfb); + } else { + currfb = true; + VIDEO_SetFramebuffer(lookup_xfb); + } +} + static void waitForReload(void) { u32 level; - + PAD_Init(); - kprintf("\n\n\tPress RESET, or Z on a GameCube Controller, to reload\n\n"); + VIDEO_WaitVSync(); // For VI/PAD_Interface Timing + + kprintf("\n\tRESET / A: Reset, B: Reload"); + if (lookup_xfb) { + kprintf(", START: Show the previous XFB\n"); + } else { + kprintf("\n"); + } while ( 1 ) { if(reload_timer > 0) { kprintf("\x1b[2K\r\tReloading in %d seconds", reload_timer/50); } + PAD_ScanPads(); + + // Checks all controller ports because why not + int buttonsDown = PAD_ButtonsDown(0) | PAD_ButtonsDown(1) | PAD_ButtonsDown(2) | PAD_ButtonsDown(3); - int buttonsDown = PAD_ButtonsDown(0); - - if( (buttonsDown & PAD_TRIGGER_Z) || SYS_ResetButtonDown() || reload_timer == 0 ) + if( (buttonsDown & PAD_BUTTON_B) || reload_timer == 0 ) { - kprintf("\n\tReload\n\n\n"); + // Clears the screen because the added text + // could interfere with the ability of showing the full stack + consoleClear(); + kprintf("\tReloading..."); _CPU_ISR_Disable(level); __reload (); } - if ( buttonsDown & PAD_BUTTON_A ) + if ( (buttonsDown & PAD_BUTTON_START) && lookup_xfb ) { + reload_timer--; + __toggleframebuffer(); + VIDEO_WaitVSync(); + } + + if ( buttonsDown & PAD_BUTTON_A || SYS_ResetButtonDown() ) { - kprintf("\n\tReset\n\n\n"); + // Clears the screen because the added text + // could interfere with the ability of showing the full stack + consoleClear(); + kprintf("\tResetting..."); #if defined(HW_DOL) - SYS_ResetSystem(SYS_HOTRESET,0,FALSE); + SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); #else __reload (); #endif } - + VIDEO_WaitVSync(); udelay(20000); if(reload_timer > 0) reload_timer--; @@ -240,17 +279,26 @@ static void waitForReload(void) //just implement core for unrecoverable exceptions. void c_default_exceptionhandler(frame_context *pCtx) -{ - const u16 console_height = 680; - const u16 console_width = 574; +{ + // Default values are for 576i + u16 console_height = 680; + u16 console_width = 574; + u8 Yoffset = 48; + + if (CONF_GetEuRGB60() > 0 || ((CONF_GetProgressiveScan() > 0) && VIDEO_HaveComponentCable())) { + // Changes to 480i/p values + console_height = 640; + console_width = 480; + Yoffset = 32; + } GX_AbortFrame(); VIDEO_SetFramebuffer(exception_xfb); __VIClearFramebuffer(exception_xfb, console_height * console_width * VI_DISPLAY_PIX_SZ, COLOR_BLACK); - __console_init(exception_xfb, 20, 20, console_height-40, console_width-40, 1280); + __console_init(exception_xfb, 16, Yoffset, console_height-16, console_width-Yoffset, 1280); CON_EnableGecko(1, true); - kprintf("\n\n\n\tException (%s) occurred!\n", exception_name[pCtx->EXCPT_Number]); + kprintf("\tException (%s) occurred!\n", exception_name[pCtx->EXCPT_Number]); kprintf("\tGPR00 %08X GPR08 %08X GPR16 %08X GPR24 %08X\n",pCtx->GPR[0], pCtx->GPR[8], pCtx->GPR[16], pCtx->GPR[24]); kprintf("\tGPR01 %08X GPR09 %08X GPR17 %08X GPR25 %08X\n",pCtx->GPR[1], pCtx->GPR[9], pCtx->GPR[17], pCtx->GPR[25]); @@ -275,5 +323,4 @@ void c_default_exceptionhandler(frame_context *pCtx) } waitForReload(); -} - +} \ No newline at end of file From 4d1f55e25ac2f0a76c9c95d05a0a0b922b0603f9 Mon Sep 17 00:00:00 2001 From: Abdelali Date: Tue, 23 Dec 2025 08:37:12 +0100 Subject: [PATCH 2/6] Get lookup_xfb before calling VIDEO_SetFramebuffer --- libogc/exception.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libogc/exception.c b/libogc/exception.c index 7ad2f0b9..519d2ad6 100644 --- a/libogc/exception.c +++ b/libogc/exception.c @@ -201,10 +201,6 @@ void __exception_setreload(int t) reload_timer = t*50; } -void __exception_setlookupxfb(void *xfb) { - lookup_xfb = (u32 *)xfb; -} - static void __toggleframebuffer() { static bool currfb = false; if(currfb) { @@ -293,6 +289,7 @@ void c_default_exceptionhandler(frame_context *pCtx) } GX_AbortFrame(); + lookup_xfb = VIDEO_GetNextFramebuffer(); VIDEO_SetFramebuffer(exception_xfb); __VIClearFramebuffer(exception_xfb, console_height * console_width * VI_DISPLAY_PIX_SZ, COLOR_BLACK); __console_init(exception_xfb, 16, Yoffset, console_height-16, console_width-Yoffset, 1280); From d1120ba65bad06c06d21a3f884393e909d42c151 Mon Sep 17 00:00:00 2001 From: Abdelali <196317120+abdelali221@users.noreply.github.com> Date: Tue, 23 Dec 2025 10:04:32 +0100 Subject: [PATCH 3/6] Remove extern functions + Add WaitVSync call to fix a small bug. --- libogc/exception.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libogc/exception.c b/libogc/exception.c index 519d2ad6..5091e805 100644 --- a/libogc/exception.c +++ b/libogc/exception.c @@ -67,8 +67,6 @@ static int reload_timer = -1; void __exception_sethandler(u32 nExcept, void (*pHndl)(frame_context*)); extern void udelay(int us); -extern s32 CONF_GetEuRGB60(void); -extern s32 CONF_GetProgressiveScan(void); extern void fpu_exceptionhandler(frame_context*); extern void irq_exceptionhandler(frame_context*); extern void dec_exceptionhandler(frame_context*); @@ -281,15 +279,15 @@ void c_default_exceptionhandler(frame_context *pCtx) u16 console_width = 574; u8 Yoffset = 48; - if (CONF_GetEuRGB60() > 0 || ((CONF_GetProgressiveScan() > 0) && VIDEO_HaveComponentCable())) { + if (SYS_GetEuRGB60() > 0 || ((SYS_GetProgressiveScan() > 0) && VIDEO_HaveComponentCable())) { // Changes to 480i/p values console_height = 640; console_width = 480; Yoffset = 32; } - - GX_AbortFrame(); lookup_xfb = VIDEO_GetNextFramebuffer(); + VIDEO_WaitVSync(); + GX_AbortFrame(); VIDEO_SetFramebuffer(exception_xfb); __VIClearFramebuffer(exception_xfb, console_height * console_width * VI_DISPLAY_PIX_SZ, COLOR_BLACK); __console_init(exception_xfb, 16, Yoffset, console_height-16, console_width-Yoffset, 1280); @@ -310,10 +308,12 @@ void c_default_exceptionhandler(frame_context *pCtx) _cpu_print_stack((void*)pCtx->SRR0,(void*)pCtx->LR,(void*)pCtx->GPR[1]); + kprintf("\n"); + if((pCtx->EXCPT_Number==EX_DSI) || (pCtx->EXCPT_Number==EX_FP)) { u32 i; u32 *pAdd = (u32*)pCtx->SRR0; - kprintf("\n\n\tCODE DUMP:\n"); + kprintf("\n\tCODE DUMP:\n"); for (i=0; i<12; i+=4) kprintf("\t%p: %08X %08X %08X %08X\n", &(pAdd[i]),pAdd[i], pAdd[i+1], pAdd[i+2], pAdd[i+3]); From fa11b0d25556ded6bc24d3d3a42d53f58b4cc77b Mon Sep 17 00:00:00 2001 From: Abdelali <196317120+abdelali221@users.noreply.github.com> Date: Tue, 23 Dec 2025 10:12:12 +0100 Subject: [PATCH 4/6] Remove Video res logic. --- libogc/exception.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/libogc/exception.c b/libogc/exception.c index 5091e805..4736617f 100644 --- a/libogc/exception.c +++ b/libogc/exception.c @@ -274,23 +274,15 @@ static void waitForReload(void) //just implement core for unrecoverable exceptions. void c_default_exceptionhandler(frame_context *pCtx) { - // Default values are for 576i - u16 console_height = 680; - u16 console_width = 574; - u8 Yoffset = 48; - - if (SYS_GetEuRGB60() > 0 || ((SYS_GetProgressiveScan() > 0) && VIDEO_HaveComponentCable())) { - // Changes to 480i/p values - console_height = 640; - console_width = 480; - Yoffset = 32; - } + const u16 console_height = 680; + const u16 console_width = 574; + lookup_xfb = VIDEO_GetNextFramebuffer(); VIDEO_WaitVSync(); GX_AbortFrame(); VIDEO_SetFramebuffer(exception_xfb); __VIClearFramebuffer(exception_xfb, console_height * console_width * VI_DISPLAY_PIX_SZ, COLOR_BLACK); - __console_init(exception_xfb, 16, Yoffset, console_height-16, console_width-Yoffset, 1280); + __console_init(exception_xfb, 16, 32, console_height-16, console_width-32, 1280); CON_EnableGecko(1, true); kprintf("\tException (%s) occurred!\n", exception_name[pCtx->EXCPT_Number]); From e13e35c6fcf54fef9af7e42d0aa912b13bd83351 Mon Sep 17 00:00:00 2001 From: Abdelali <196317120+abdelali221@users.noreply.github.com> Date: Tue, 23 Dec 2025 10:19:19 +0100 Subject: [PATCH 5/6] Reverted SYS_ResetSystem change and modified it instead for RVL. --- libogc/exception.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libogc/exception.c b/libogc/exception.c index 4736617f..99793488 100644 --- a/libogc/exception.c +++ b/libogc/exception.c @@ -259,9 +259,9 @@ static void waitForReload(void) consoleClear(); kprintf("\tResetting..."); #if defined(HW_DOL) - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + SYS_ResetSystem(SYS_HOTRESET,0,FALSE); #else - __reload (); + SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); #endif } VIDEO_WaitVSync(); From 8dfe115689c080360eac21761249aea18ab0fa4b Mon Sep 17 00:00:00 2001 From: Abdelali <196317120+abdelali221@users.noreply.github.com> Date: Wed, 24 Dec 2025 12:56:46 +0100 Subject: [PATCH 6/6] Change __toggleframebuffer(). --- libogc/exception.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libogc/exception.c b/libogc/exception.c index 99793488..d9b04643 100644 --- a/libogc/exception.c +++ b/libogc/exception.c @@ -200,14 +200,12 @@ void __exception_setreload(int t) } static void __toggleframebuffer() { - static bool currfb = false; - if(currfb) { - currfb = false; - VIDEO_SetFramebuffer(exception_xfb); - } else { - currfb = true; + if(VIDEO_GetCurrentFramebuffer() == exception_xfb) { VIDEO_SetFramebuffer(lookup_xfb); + } else { + VIDEO_SetFramebuffer(exception_xfb); } + VIDEO_Flush(); } static void waitForReload(void) @@ -250,6 +248,7 @@ static void waitForReload(void) reload_timer--; __toggleframebuffer(); VIDEO_WaitVSync(); + udelay(20000); } if ( buttonsDown & PAD_BUTTON_A || SYS_ResetButtonDown() ) @@ -281,6 +280,7 @@ void c_default_exceptionhandler(frame_context *pCtx) VIDEO_WaitVSync(); GX_AbortFrame(); VIDEO_SetFramebuffer(exception_xfb); + VIDEO_Flush(); __VIClearFramebuffer(exception_xfb, console_height * console_width * VI_DISPLAY_PIX_SZ, COLOR_BLACK); __console_init(exception_xfb, 16, 32, console_height-16, console_width-32, 1280); CON_EnableGecko(1, true);