Skip to content

Commit

Permalink
Improved the SYS_die function. (#366)
Browse files Browse the repository at this point in the history
Thanks for your contribution :)
  • Loading branch information
Leur68 authored Nov 6, 2024
1 parent c3eec5a commit 2623943
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
13 changes: 7 additions & 6 deletions inc/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -489,10 +489,11 @@ bool SYS_isChecksumOk(void);
/**
* \brief
* Die with the specified error message.<br>
* Program execution is interrupted.
*
* Program execution is interrupted.<br>
* 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_
24 changes: 19 additions & 5 deletions src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 2623943

Please sign in to comment.