From 11f454390e6305c60bf1fdbd51808dce7f3933d4 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sun, 3 Dec 2023 10:50:00 +0100 Subject: [PATCH] Add HEAPCHECK --- README.md | 6 ++++++ include/crt.c | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/README.md b/README.md index 3ab4eff..eaf2675 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,12 @@ The compiler is command line driven, and creates an executable .prg file. A list of source files can be provided. +### Run time library defines + +* -dNOLONG : no support for long in printf +* -dNOFLOAT : no float in printf +* -dHEAPCHECK : check heap allocate and free and jam if heap full or free out of range + #### Supported target machines * c64 : Commodore C64, (0x0800..0xa000) diff --git a/include/crt.c b/include/crt.c index 5bb41d8..f1a96ed 100644 --- a/include/crt.c +++ b/include/crt.c @@ -4214,6 +4214,9 @@ loop: hempty: // no more heap blocks +#ifdef HEAPCHECK + byt $02 +#endif rts avail: @@ -4316,6 +4319,25 @@ __asm free rts notnull: +#ifdef HEAPCHECK + lda accu + 1 + ldx accu + + cmp #>HeapStart + bcc hfail + bne hchk1 + cpx #HeapEnd + bcc hchk2 + bne hfail + cpx #