From 8557bd0205814e50e5ae993d993111f0430ab0b4 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 17 Jan 2025 18:49:36 +1100 Subject: [PATCH] Dreamcast: Display crash screen --- .github/workflows/build_dreamcast.yml | 6 +++ src/Platform_Dreamcast.c | 62 ++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_dreamcast.yml b/.github/workflows/build_dreamcast.yml index 49093089f..831ced6b5 100644 --- a/.github/workflows/build_dreamcast.yml +++ b/.github/workflows/build_dreamcast.yml @@ -43,6 +43,12 @@ jobs: SOURCE_FILE: 'ClassiCube-dc.cdi' DEST_NAME: 'ClassiCube-dc.cdi' + - uses: ./.github/actions/upload_build + if: ${{ always() && steps.compile.outcome == 'success' }} + with: + SOURCE_FILE: 'ClassiCube-dc.iso' + DEST_NAME: 'ClassiCube-dc.iso' + - uses: ./.github/actions/upload_build if: ${{ always() && steps.compile.outcome == 'success' }} with: diff --git a/src/Platform_Dreamcast.c b/src/Platform_Dreamcast.c index f4dc88d93..99252e130 100644 --- a/src/Platform_Dreamcast.c +++ b/src/Platform_Dreamcast.c @@ -53,7 +53,10 @@ cc_uint64 Stopwatch_Measure(void) { } static uint32 str_offset; +static cc_bool log_debugger = true; +static cc_bool log_timestamp = true; extern cc_bool window_inited; + #define MAX_ONSCREEN_LINES 17 #define ONSCREEN_LINE_HEIGHT (24 + 2) // 8 * 3 text, plus 2 pixel padding #define Onscreen_LineOffset(y) ((10 + y + (str_offset * ONSCREEN_LINE_HEIGHT)) * vid_mode->width) @@ -72,17 +75,23 @@ static void LogOnscreen(const char* msg, int len) { timer_ms_gettime(&secs, &ms); String_InitArray(str, buffer); - String_Format2(&str, "[%p2.%p3] ", &secs, &ms); + if (log_timestamp) String_Format2(&str, "[%p2.%p3] ", &secs, &ms); String_AppendAll(&str, msg, len); - sq_set16(vram_s + Onscreen_LineOffset(0), 0, ONSCREEN_LINE_HEIGHT * 2 * vid_mode->width); + short* dst = vram_s + Onscreen_LineOffset(0); + int num_pixels = ONSCREEN_LINE_HEIGHT * 2 * vid_mode->width; + for (int i = 0; i < num_pixels; i++) dst[i] = 0; + //sq_set16(vram_s + Onscreen_LineOffset(0), 0, ONSCREEN_LINE_HEIGHT * 2 * vid_mode->width); + FallbackFont_Plot(&str, PlotOnscreen, 3, NULL); str_offset = (str_offset + 1) % MAX_ONSCREEN_LINES; } void Platform_Log(const char* msg, int len) { - dbgio_write_buffer_xlat(msg, len); - dbgio_write_buffer_xlat("\n", 1); + if (log_debugger) { + dbgio_write_buffer_xlat(msg, len); + dbgio_write_buffer_xlat("\n", 1); + } if (window_inited) return; // Log details on-screen for initial modem initing etc @@ -120,7 +129,48 @@ void DateTime_CurrentLocal(struct cc_datetime* t) { /*########################################################################################################################* *-------------------------------------------------------Crash handling----------------------------------------------------* *#########################################################################################################################*/ -void CrashHandler_Install(void) { } +static void HandleCrash(irq_t evt, irq_context_t* ctx, void* data) { + uint32_t code = evt; + log_timestamp = false; + window_inited = false; + str_offset = 0; + + for (;;) + { + Platform_LogConst("** CLASSICUBE FATALLY CRASHED **"); + Platform_Log2("PC: %h, error: %h", + &ctx->pc, &code); + Platform_LogConst(""); + + static const char* const regNames[] = { + "R0 ", "R1 ", "R2 ", "R3 ", "R4 ", "R5 ", "R6 ", "R7 ", + "R8 ", "R9 ", "R10", "R11", "R12", "R13", "R14", "R15" + }; + + for (int i = 0; i < 8; i++) { + Platform_Log4(" %c: %h %c: %h", + regNames[i], &ctx->r[i], + regNames[i + 8], &ctx->r[i + 8]); + } + + Platform_Log4(" %c : %h %c : %h", + "SR", &ctx->sr, + "PR", &ctx->pr); + + Platform_LogConst(""); + Platform_LogConst("Please report on ClassiCube Discord or forums"); + Platform_LogConst(""); + Platform_LogConst("You will need to restart your Dreamcast"); + Platform_LogConst(""); + + // Only log to serial/emu console first time + log_debugger = false; + } +} + +void CrashHandler_Install(void) { + irq_set_handler(EXC_UNHANDLED_EXC, HandleCrash, NULL); +} void Process_Abort2(cc_result result, const char* raw_msg) { Logger_DoAbort(result, raw_msg, NULL); @@ -690,4 +740,4 @@ static cc_result GetMachineID(cc_uint32* key) { Mem_Copy(key, MACHINE_KEY, sizeof(MACHINE_KEY) - 1); return 0; } -#endif +#endif \ No newline at end of file