From 26239432a0695f23113ebc95c83e5418c0bbd4d5 Mon Sep 17 00:00:00 2001 From: Lemur42332543632 <120027513+Lemur42332543632@users.noreply.github.com> Date: Thu, 7 Nov 2024 02:31:34 +0300 Subject: [PATCH] Improved the SYS_die function. (#366) Thanks for your contribution :) --- inc/sys.h | 13 +++++++------ src/sys.c | 24 +++++++++++++++++++----- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/inc/sys.h b/inc/sys.h index 272ad369..e86a1162 100644 --- a/inc/sys.h +++ b/inc/sys.h @@ -41,13 +41,13 @@ /** * \brief - * Put function in .data (RAM) instead of the default .text + * Put function in .data (RAM) instead of the default .text */ -#define RAM_SECT __attribute__((section(".ramprog"))) +#define RAM_SECT __attribute__((section(".ramprog"))) /** * \brief - * Declare function for the hint callback (generate a RTE to return from interrupt instead of RTS) + * Declare function for the hint callback (generate a RTE to return from interrupt instead of RTS) */ #define HINTERRUPT_CALLBACK __attribute__ ((interrupt)) void @@ -489,10 +489,11 @@ bool SYS_isChecksumOk(void); /** * \brief * Die with the specified error message.
- * Program execution is interrupted. - * + * Program execution is interrupted.
+ * Accepts a list of strings. The list must end with a NULL value. + * * This actually display an error message and program ends execution. */ -void SYS_die(char *err); +void SYS_die(char *err, ...); #endif // _SYS_H_ diff --git a/src/sys.c b/src/sys.c index cdf367a9..92a6fd6a 100644 --- a/src/sys.c +++ b/src/sys.c @@ -1042,13 +1042,27 @@ bool SYS_isChecksumOk() } -void SYS_die(char *err) +void SYS_die(char *err, ...) { SYS_setInterruptMaskLevel(7); VDP_init(); - VDP_drawText("A fatal error occured !", 2, 2); - VDP_drawText("cannot continue...", 4, 3); - if (err) VDP_drawText(err, 0, 5); + VDP_setBackgroundColor(63); + VDP_drawText("A fatal error occured!", 9, 2); + VDP_drawText("cannot continue...", 11, 3); + + u8 y = 5; + va_list argptr; + va_start(argptr, err); + + const char* str = err; + while (str != NULL) + { + VDP_drawText(str, 1, y); + str = va_arg(argptr, const char*); + y++; + } + va_end(argptr); + while(1); -} +} \ No newline at end of file