Skip to content

Commit

Permalink
systemKill now checks for DOSBaase before printing, don't depend on p…
Browse files Browse the repository at this point in the history
…rintf

this saves 2k of executable size if rest of game doesn't use printf
  • Loading branch information
tehKaiN committed Nov 20, 2022
1 parent acd78de commit 7f82b99
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/ace/managers/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,12 @@ static void systemFlushIo() {
}

void systemKill(const char *szMsg) {
printf("ERR: SYSKILL: '%s'", szMsg);
logWrite("ERR: SYSKILL: '%s'", szMsg);
logWrite("ERR: ACE SYSKILL: '%s'", szMsg);
if(DOSBase) {
BPTR lOut = Output();
Write(lOut, "ERR: ACE SYSKILL: ", sizeof("ERR: ACE SYSKILL: "));
Write(lOut, (char*)szMsg, strlen(szMsg));
}

if(GfxBase) {
CloseLibrary((struct Library *) GfxBase);
Expand All @@ -466,26 +470,28 @@ void systemCreate(void) {
SysBase = *((struct ExecBase**)4UL);
#endif

GfxBase = (struct GfxBase *)OpenLibrary((CONST_STRPTR)"graphics.library", 0L);
if (!GfxBase) {
systemKill("Can't open Gfx Library!\n");
return;
}

DOSBase = (struct DosLibrary*)OpenLibrary((CONST_STRPTR)"dos.library", 0);
if (!DOSBase) {
systemKill("Can't open DOS Library!\n");
return;
}

GfxBase = (struct GfxBase *)OpenLibrary((CONST_STRPTR)"graphics.library", 0L);
if (!GfxBase) {
systemKill("Can't open Gfx Library!\n");
return;
}

// Determine original stack size
s_pProcess = (struct Process *)FindTask(NULL);
char *pStackLower = (char *)s_pProcess->pr_Task.tc_SPLower;
#if defined(ACE_DEBUG)
ULONG ulStackSize = (char *)s_pProcess->pr_Task.tc_SPUpper - pStackLower;
if(s_pProcess->pr_CLI) {
ulStackSize = *(ULONG *)s_pProcess->pr_ReturnAddr;
}
logWrite("Stack size: %lu\n", ulStackSize);
#endif
*pStackLower = SYSTEM_STACK_CANARY;

// Reserve all audio channels - apparantly this allows for int flag polling
Expand Down

0 comments on commit 7f82b99

Please sign in to comment.