From f3b93741ab513c83c232c316b2800ce051c136d0 Mon Sep 17 00:00:00 2001 From: cuz Date: Wed, 22 Nov 2000 22:19:09 +0000 Subject: [PATCH] Use the condes feature git-svn-id: svn://svn.cc65.org/cc65/trunk@470 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/apple2/Makefile | 2 -- libsrc/apple2/crt0.s | 28 +++++++++++++++------------- libsrc/atari/Makefile | 2 -- libsrc/atari/crt0.s | 25 ++++++++++++++----------- libsrc/c128/Makefile | 2 -- libsrc/c128/crt0.s | 13 +++++++------ libsrc/c64/Makefile | 2 -- libsrc/c64/crt0.s | 17 ++++++----------- libsrc/cbm/Makefile | 2 -- libsrc/cbm610/Makefile | 2 -- libsrc/cbm610/crt0.s | 15 ++++++++++----- libsrc/common/Makefile | 2 -- libsrc/common/_heap.s | 14 ++++---------- libsrc/conio/Makefile | 2 -- libsrc/dbg/Makefile | 2 -- libsrc/geos/devel/Makefile | 3 +-- libsrc/geos/devel/crt0.s | 18 ++++++++++-------- libsrc/geos/disk/Makefile | 5 ++--- libsrc/geos/dlgbox/Makefile | 3 +-- libsrc/geos/file/Makefile | 5 ++--- libsrc/geos/graph/Makefile | 3 +-- libsrc/geos/memory/Makefile | 3 +-- libsrc/geos/menuicon/Makefile | 3 +-- libsrc/geos/mousesprite/Makefile | 3 +-- libsrc/geos/process/Makefile | 3 +-- libsrc/geos/system/Makefile | 3 +-- libsrc/pet/Makefile | 2 -- libsrc/pet/crt0.s | 15 +++++++++------ libsrc/plus4/Makefile | 2 -- libsrc/plus4/crt0.s | 16 ++++++++++------ libsrc/runtime/Makefile | 2 -- libsrc/runtime/condes.s | 14 +++++++------- 32 files changed, 104 insertions(+), 129 deletions(-) diff --git a/libsrc/apple2/Makefile b/libsrc/apple2/Makefile index cad5da42f..17813f44d 100644 --- a/libsrc/apple2/Makefile +++ b/libsrc/apple2/Makefile @@ -5,12 +5,10 @@ .SUFFIXES: .o .s .c %.o: %.c - @echo $< @$(CC) $(CFLAGS) $< @$(AS) -o $@ $(AFLAGS) $(*).s %.o: %.s - @echo $< @$(AS) -g -o $@ $(AFLAGS) $< C_OBJS = diff --git a/libsrc/apple2/crt0.s b/libsrc/apple2/crt0.s index 7cc6cd72f..f7ef6f39e 100644 --- a/libsrc/apple2/crt0.s +++ b/libsrc/apple2/crt0.s @@ -5,8 +5,8 @@ ; .export _exit - .import __hinit - .import zerobss, push0, doatexit + .import initlib, donelib + .import zerobss, push0 .import _main .include "apple2.inc" @@ -66,9 +66,9 @@ L1: lda sp,x lda #>TOPMEM sta sp+1 ; Set argument stack ptr -; Initialize the heap +; Call module constructors - jsr __hinit + jsr initlib ; Initialize conio stuff @@ -77,22 +77,24 @@ L1: lda sp,x ; Set up to use Apple ROM $C000-$CFFF - ;; sta USEROM + ;; sta USEROM ; Pass an empty command line - jsr push0 ; argc - jsr push0 ; argv + jsr push0 ; argc + jsr push0 ; argv - ldy #4 ; Argument size - jsr _main ; call the users code + ldy #4 ; Argument size + jsr _main ; call the users code -; fall thru to exit... +; Call module destructors. This is also the _exit entry. -_exit: lda #$ff - sta TEXTTYP +_exit: jsr donelib + +; Restore system stuff - jsr doatexit ; call exit functions + lda #$ff ; Reset text mode + sta TEXTTYP ldx spsave txs ; Restore stack pointer diff --git a/libsrc/atari/Makefile b/libsrc/atari/Makefile index 4833aee05..bc8dfd80e 100644 --- a/libsrc/atari/Makefile +++ b/libsrc/atari/Makefile @@ -8,12 +8,10 @@ ATARIDEFS = -DNUMDRVS=4 .SUFFIXES: .o .s .c %.o: %.c - @echo $< @$(CC) $(CFLAGS) $(ATARIDEFS) $< @$(AS) -o $@ $(AFLAGS) $(*).s %.o: %.s - @echo $< @$(AS) -g -o $@ $(AFLAGS) $(ATARIDEFS) $< C_OBJS = diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index 7cb180c93..3937f0fb0 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -15,8 +15,9 @@ RESERVE_MOUSE_MEMORY = 1 ; for P/M .export mouse_pm0 .endif .export _exit - .import getargs, argc, argv - .import __hinit, initconio, zerobss, pushax, doatexit + .import getargs, argc, argv + .import initlib, donelib + .import initconio, zerobss, pushax .import _main,__filetab,getfd .import __CODE_LOAD__, __BSS_LOAD__ .import __graphmode_used @@ -117,9 +118,9 @@ L1: lda sp,x stx old_shflok sta SHFLOK -; Initialize the heap +; Call module constructors - jsr __hinit + jsr initlib ; Initialize conio stuff @@ -146,20 +147,22 @@ L1: lda sp,x lda argc ldx argc+1 - jsr pushax ; argc + jsr pushax ; argc lda #argv - jsr pushax ; argv + jsr pushax ; argv - ldy #4 ; Argument size - jsr _main ; call the users code + ldy #4 ; Argument size + jsr _main ; call the users code -; fall thru to exit... +; Call module destructors. This is also the _exit entry. -_exit: jsr doatexit ; call exit functions +_exit: jsr donelib ; Run module destructors + +; Restore system stuff ldx spsave - txs ; Restore stack pointer + txs ; Restore stack pointer ; restore left margin diff --git a/libsrc/c128/Makefile b/libsrc/c128/Makefile index a75150b1f..2ae36d881 100644 --- a/libsrc/c128/Makefile +++ b/libsrc/c128/Makefile @@ -5,12 +5,10 @@ .SUFFIXES: .o .s .c %.o: %.c - @echo $< @$(CC) $(CFLAGS) $< @$(AS) -o $@ $(AFLAGS) $(*).s %.o: %.s - @echo $< @$(AS) -g -o $@ $(AFLAGS) $< C_OBJS = diff --git a/libsrc/c128/crt0.s b/libsrc/c128/crt0.s index 404bb8427..cabef41da 100644 --- a/libsrc/c128/crt0.s +++ b/libsrc/c128/crt0.s @@ -5,8 +5,9 @@ ; .export _exit - .import __hinit, initconio, doneconio, zerobss - .import push0, doatexit, _main + .import initlib, donelib + .import initconio, doneconio, zerobss + .import push0, _main .include "c128.inc" .include "../cbm/cbm.inc" @@ -93,9 +94,9 @@ L1: lda sp,x lda #>$C000 sta sp+1 -; Initialize the heap +; Call module constructors - jsr __hinit + jsr initlib ; Initialize conio stuff @@ -109,9 +110,9 @@ L1: lda sp,x ldy #4 ; Argument size jsr _main ; call the users code -; fall thru to exit... +; Call module destructors. This is also the _exit entry. -_exit: jsr doatexit ; call exit functions +_exit: jsr donelib ; Run module destructors ; Reset the conio stuff diff --git a/libsrc/c64/Makefile b/libsrc/c64/Makefile index 15806f5bc..5a69bdfed 100644 --- a/libsrc/c64/Makefile +++ b/libsrc/c64/Makefile @@ -5,12 +5,10 @@ .SUFFIXES: .o .s .c %.o: %.c - @echo $< @$(CC) $(CFLAGS) $< @$(AS) -o $@ $(AFLAGS) $(*).s %.o: %.s - @echo $< @$(AS) -g -o $@ $(AFLAGS) $< C_OBJS = diff --git a/libsrc/c64/crt0.s b/libsrc/c64/crt0.s index 5730fd758..3f57be7ae 100644 --- a/libsrc/c64/crt0.s +++ b/libsrc/c64/crt0.s @@ -5,12 +5,10 @@ ; .export _exit - .import __hinit, initconio, zerobss, push0, condes + .import initlib, donelib + .import initconio, zerobss, push0 .import _main - .import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__ - .import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__ - .include "c64.inc" .include "../cbm/cbm.inc" @@ -92,9 +90,9 @@ L1: lda sp,x lda #>$D000 sta sp+1 ; Set argument stack ptr -; Initialize the heap +; Call module constructors - jsr __hinit + jsr initlib ; Initialize conio stuff @@ -108,12 +106,9 @@ L1: lda sp,x ldy #4 ; Argument size jsr _main ; call the users code -; Call module destructors +; Call module destructors. This is also the _exit entry. -_exit: lda #<__DESTRUCTOR_TABLE__ - ldx #>__DESTRUCTOR_TABLE__ - ldy #<(__DESTRUCTOR_COUNT__*2) - jsr condes +_exit: jsr donelib ; Run module destructors ; Restore system stuff diff --git a/libsrc/cbm/Makefile b/libsrc/cbm/Makefile index 552a8af88..5a3e258c5 100644 --- a/libsrc/cbm/Makefile +++ b/libsrc/cbm/Makefile @@ -5,12 +5,10 @@ .SUFFIXES: .o .s .c %.o: %.c - @echo $< @$(CC) $(CFLAGS) $< @$(AS) -o $@ $(AFLAGS) $(*).s %.o: %.s - @echo $< @$(AS) -g -o $@ $(AFLAGS) $< C_OBJS = diff --git a/libsrc/cbm610/Makefile b/libsrc/cbm610/Makefile index 433e5555d..1077641eb 100644 --- a/libsrc/cbm610/Makefile +++ b/libsrc/cbm610/Makefile @@ -5,12 +5,10 @@ .SUFFIXES: .o .s .c %.o: %.c - @echo $< @$(CC) $(CFLAGS) $< @$(AS) -o $@ $(AFLAGS) $(*).s %.o: %.s - @echo $< @$(AS) -g -o $@ $(AFLAGS) $< C_OBJS = diff --git a/libsrc/cbm610/crt0.s b/libsrc/cbm610/crt0.s index 5a9a9011b..3c18b6bf4 100644 --- a/libsrc/cbm610/crt0.s +++ b/libsrc/cbm610/crt0.s @@ -5,7 +5,8 @@ ; .export _exit - .import __hinit, push0, doatexit, _main + .import initlib, donelib + .import push0, _main .import initconio .import __BSS_RUN__, __BSS_SIZE__ .import irq, nmi @@ -235,9 +236,13 @@ Z4: ; This code is in page 2, so we may now start calling subroutines safely, ; since the code we execute is no longer in the stack page. +; Call module constructors - jsr __hinit ; Initialize the heap - jsr initconio ; Initialize conio stuff + jsr initlib + +; Initialize conio stuff + + jsr initconio ; Create the (empty) command line for the program @@ -323,9 +328,9 @@ Start: ldy #4 ; Argument size jsr _main ; call the users code -; Fall thru to exit. +; Call module destructors. This is also the _exit entry. -_exit: jsr doatexit ; call exit functions +_exit: jsr donelib ; Run module destructors ; Clear the start of the zero page, since it will be interpreted as a ; (garbage) BASIC program otherwise. This is also the default entry for diff --git a/libsrc/common/Makefile b/libsrc/common/Makefile index 1e64b0b8a..48db0cdbf 100644 --- a/libsrc/common/Makefile +++ b/libsrc/common/Makefile @@ -5,12 +5,10 @@ .SUFFIXES: .o .s .c %.o: %.c - @echo $< @$(CC) $(CFLAGS) $< @$(AS) -g -o $@ $(AFLAGS) $(*).s %.o: %.s - @echo $< @$(AS) -g -o $@ $(AFLAGS) $< C_OBJS = fclose.o fgets.o fprintf.o calloc.o _fopen.o\ diff --git a/libsrc/common/_heap.s b/libsrc/common/_heap.s index 427ecaea1..f3a5ade48 100644 --- a/libsrc/common/_heap.s +++ b/libsrc/common/_heap.s @@ -5,7 +5,7 @@ ; .export __horg, __hptr, __hend, __hfirst, __hlast - .export __hinit + .constructor initheap, 24 .import __BSS_RUN__, __BSS_SIZE__, __stksize .importzp sp @@ -17,19 +17,17 @@ __hptr: .word __BSS_RUN__+__BSS_SIZE__ ; Dito __hend: .word __BSS_RUN__+__BSS_SIZE__ -__hfirst: +__hfirst: .word 0 __hlast: .word 0 -; -; Initialization. Must be called from startup! -; +; Initialization. Will be called from startup! .code -__hinit: +initheap: sec lda sp sbc __stksize @@ -39,7 +37,3 @@ __hinit: sta __hend+1 rts - - - - diff --git a/libsrc/conio/Makefile b/libsrc/conio/Makefile index ee9d691f0..77152a86f 100644 --- a/libsrc/conio/Makefile +++ b/libsrc/conio/Makefile @@ -5,12 +5,10 @@ .SUFFIXES: .o .s .c %.o: %.c - @echo $< @$(CC) $(CFLAGS) $< @$(AS) -o $@ $(AFLAGS) $(*).s %.o: %.s - @echo $< @$(AS) -g -o $@ $(AFLAGS) $< C_OBJS = diff --git a/libsrc/dbg/Makefile b/libsrc/dbg/Makefile index 1dcf8b116..326d3dfab 100644 --- a/libsrc/dbg/Makefile +++ b/libsrc/dbg/Makefile @@ -5,12 +5,10 @@ .SUFFIXES: .o .s .c %.o: %.c - @echo $< @$(CC) $(CFLAGS) $< @$(AS) -g -o $@ $(AFLAGS) $(*).s %.o: %.s - @echo $< @$(AS) -g -o $@ $(AFLAGS) $< C_OBJS = dbg.o diff --git a/libsrc/geos/devel/Makefile b/libsrc/geos/devel/Makefile index e7c140ad5..ef41ffbcb 100644 --- a/libsrc/geos/devel/Makefile +++ b/libsrc/geos/devel/Makefile @@ -5,7 +5,6 @@ # %.o: %.s - @echo $< @$(AS) -o $@ $(AFLAGS) $< @@ -14,4 +13,4 @@ S_OBJS = crt0.o all: $(S_OBJS) clean: - @rm -f *.~ $(S_OBJS) core \ No newline at end of file + @rm -f *.~ $(S_OBJS) core diff --git a/libsrc/geos/devel/crt0.s b/libsrc/geos/devel/crt0.s index 00cac2d4c..788a0aeb8 100644 --- a/libsrc/geos/devel/crt0.s +++ b/libsrc/geos/devel/crt0.s @@ -7,10 +7,11 @@ ; no __hinit - .export _exit + .export _exit + .import initlib, donelib .import pushax .import _main - .import zerobss, doatexit + .import zerobss ; ------------------------------------------------------------------------ ; Define and export the ZP variables for the C64 runtime @@ -54,9 +55,9 @@ regbank = $a3 ; 6 bytes hopefully not used by Kernal lda #>$7900 sta sp+1 ; Set argument stack ptr -; Initialize the heap +; Call module constructors -;;! jsr __hinit + jsr initlib ; Pass an empty command line @@ -69,9 +70,10 @@ regbank = $a3 ; 6 bytes hopefully not used by Kernal jsr _main ; call the users code jmp $c1c3 ; jump to GEOS MainLoop -; exit must be called from the code! +; Call module destructors. This is also the _exit entry which must be called +; explicitly by the code. -_exit: - jsr doatexit ; call exit functions +_exit: jsr donelib ; Run module destructors - jmp $c22c ; EnterDeskTop + jmp $c22c ; EnterDeskTop + diff --git a/libsrc/geos/disk/Makefile b/libsrc/geos/disk/Makefile index 9020128e1..0ec9ac8ea 100644 --- a/libsrc/geos/disk/Makefile +++ b/libsrc/geos/disk/Makefile @@ -1,10 +1,9 @@ # # Makefile for GEOS lib # for cc65 -# +# %.o: %.s - @echo $< @$(AS) -o $@ $(AFLAGS) $< @@ -17,4 +16,4 @@ S_OBJS = blkalloc.o calcblksfree.o changediskdevice.o chkdkgeos.o enterturbo.o e all: $(S_OBJS) clean: - @rm -f *.~ $(S_OBJS) core \ No newline at end of file + @rm -f *.~ $(S_OBJS) core diff --git a/libsrc/geos/dlgbox/Makefile b/libsrc/geos/dlgbox/Makefile index 3f8cb8e0f..29a83c33e 100644 --- a/libsrc/geos/dlgbox/Makefile +++ b/libsrc/geos/dlgbox/Makefile @@ -5,7 +5,6 @@ # %.o: %.s - @echo $< @$(AS) -o $@ $(AFLAGS) $< @@ -16,4 +15,4 @@ S_OBJS = dodlgbox.o rstrfrmdialogue.o\ all: $(S_OBJS) clean: - @rm -f *.~ $(S_OBJS) core \ No newline at end of file + @rm -f *.~ $(S_OBJS) core diff --git a/libsrc/geos/file/Makefile b/libsrc/geos/file/Makefile index 01299b30b..5b8638fee 100644 --- a/libsrc/geos/file/Makefile +++ b/libsrc/geos/file/Makefile @@ -1,10 +1,9 @@ # # Makefile for GEOS lib # for cc65 -# +# %.o: %.s - @echo $< @$(AS) -o $@ $(AFLAGS) $< @@ -18,4 +17,4 @@ S_OBJS = get1stdirentry.o getnxtdirentry.o\ all: $(S_OBJS) clean: - @rm -f *.~ $(S_OBJS) core \ No newline at end of file + @rm -f *.~ $(S_OBJS) core diff --git a/libsrc/geos/graph/Makefile b/libsrc/geos/graph/Makefile index 1abf1a912..9ea62b994 100644 --- a/libsrc/geos/graph/Makefile +++ b/libsrc/geos/graph/Makefile @@ -5,7 +5,6 @@ # %.o: %.s - @echo $< @$(AS) -o $@ $(AFLAGS) $< @@ -19,4 +18,4 @@ S_OBJS = drawline.o drawpoint.o framerectangle.o hlineregs.o horizontalline.o\ all: $(S_OBJS) clean: - @rm -f *.~ $(S_OBJS) core \ No newline at end of file + @rm -f *.~ $(S_OBJS) core diff --git a/libsrc/geos/memory/Makefile b/libsrc/geos/memory/Makefile index ae00d7167..f9727fde5 100644 --- a/libsrc/geos/memory/Makefile +++ b/libsrc/geos/memory/Makefile @@ -5,7 +5,6 @@ # %.o: %.s - @echo $< @$(AS) -o $@ $(AFLAGS) $< @@ -16,4 +15,4 @@ S_OBJS = crc.o doublepop.o reuregs.o clearram.o fillram.o initram.o movedata.o\ all: $(S_OBJS) clean: - @rm -f *.~ $(S_OBJS) core \ No newline at end of file + @rm -f *.~ $(S_OBJS) core diff --git a/libsrc/geos/menuicon/Makefile b/libsrc/geos/menuicon/Makefile index bf3a9bd2f..2a58d7853 100644 --- a/libsrc/geos/menuicon/Makefile +++ b/libsrc/geos/menuicon/Makefile @@ -5,7 +5,6 @@ # %.o: %.s - @echo $< @$(AS) -o $@ $(AFLAGS) $< @@ -15,4 +14,4 @@ S_OBJS = domenu.o dopreviousmenu.o redomenu.o recovermenu.o recoverallmenus.o\ all: $(S_OBJS) clean: - @rm -f *.~ $(S_OBJS) core \ No newline at end of file + @rm -f *.~ $(S_OBJS) core diff --git a/libsrc/geos/mousesprite/Makefile b/libsrc/geos/mousesprite/Makefile index 30c48c730..0fb3cad23 100644 --- a/libsrc/geos/mousesprite/Makefile +++ b/libsrc/geos/mousesprite/Makefile @@ -5,7 +5,6 @@ # %.o: %.s - @echo $< @$(AS) -o $@ $(AFLAGS) $< @@ -17,4 +16,4 @@ S_OBJS = startmousemode.o clearmousemode.o mouseup.o mouseoff.o\ all: $(S_OBJS) clean: - @rm -f *.~ $(S_OBJS) core \ No newline at end of file + @rm -f *.~ $(S_OBJS) core diff --git a/libsrc/geos/process/Makefile b/libsrc/geos/process/Makefile index 91ad9d2de..47c195a65 100644 --- a/libsrc/geos/process/Makefile +++ b/libsrc/geos/process/Makefile @@ -5,7 +5,6 @@ # %.o: %.s - @echo $< @$(AS) -o $@ $(AFLAGS) $< @@ -14,4 +13,4 @@ S_OBJS = processinitrestartenable.o processblock.o processfreeze.o sleep.o all: $(S_OBJS) clean: - @rm -f *.~ $(S_OBJS) core \ No newline at end of file + @rm -f *.~ $(S_OBJS) core diff --git a/libsrc/geos/system/Makefile b/libsrc/geos/system/Makefile index 8d0b8106d..e761f581f 100644 --- a/libsrc/geos/system/Makefile +++ b/libsrc/geos/system/Makefile @@ -5,7 +5,6 @@ # %.o: %.s - @echo $< @$(AS) -o $@ $(AFLAGS) $< @@ -15,4 +14,4 @@ S_OBJS = callroutine.o enterdesktop.o firstinit.o getrandom.o getserialnumber.o\ all: $(S_OBJS) clean: - @rm -f *.~ $(S_OBJS) core \ No newline at end of file + @rm -f *.~ $(S_OBJS) core diff --git a/libsrc/pet/Makefile b/libsrc/pet/Makefile index 6e5131db8..2f3d280ff 100644 --- a/libsrc/pet/Makefile +++ b/libsrc/pet/Makefile @@ -5,12 +5,10 @@ .SUFFIXES: .o .s .c %.o: %.c - @echo $< @$(CC) $(CFLAGS) $< @$(AS) -o $@ $(AFLAGS) $(*).s %.o: %.s - @echo $< @$(AS) -g -o $@ $(AFLAGS) $< C_OBJS = diff --git a/libsrc/pet/crt0.s b/libsrc/pet/crt0.s index 21bdf0107..24ed2691d 100644 --- a/libsrc/pet/crt0.s +++ b/libsrc/pet/crt0.s @@ -4,8 +4,9 @@ ; This must be the *first* file on the linker command line ; - .export _exit - .import __hinit, initconio, zerobss, push0, doatexit + .export _exit + .import initlib, donelib + .import initconio, zerobss, push0 .import _main .include "pet.inc" @@ -84,9 +85,9 @@ L1: lda sp,x lda MEMSIZE+1 sta sp+1 ; Set argument stack ptr -; Initialize the heap +; Call module constructors - jsr __hinit + jsr initlib ; Initialize conio stuff @@ -100,9 +101,11 @@ L1: lda sp,x ldy #4 ; Argument size jsr _main ; call the users code -; fall thru to exit... +; Call module destructors. This is also the _exit entry. -_exit: jsr doatexit ; call exit functions +_exit: jsr donelib ; Run module destructors + +; Restore system stuff ldx spsave txs ; Restore stack pointer diff --git a/libsrc/plus4/Makefile b/libsrc/plus4/Makefile index ad77f5c67..46bc1dd0a 100644 --- a/libsrc/plus4/Makefile +++ b/libsrc/plus4/Makefile @@ -5,12 +5,10 @@ .SUFFIXES: .o .s .c %.o: %.c - @echo $< @$(CC) $(CFLAGS) $< @$(AS) -o $@ $(AFLAGS) $(*).s %.o: %.s - @echo $< @$(AS) -g -o $@ $(AFLAGS) $< C_OBJS = diff --git a/libsrc/plus4/crt0.s b/libsrc/plus4/crt0.s index b33ff667a..3f25e772a 100644 --- a/libsrc/plus4/crt0.s +++ b/libsrc/plus4/crt0.s @@ -4,8 +4,9 @@ ; This must be the *first* file on the linker command line ; - .export _exit - .import __hinit, push0, doatexit, _main + .export _exit + .import initlib, donelib + .import push0, _main .import initconio, doneconio, zerobss .include "plus4.inc" @@ -87,9 +88,9 @@ L1: lda sp,x MemOk: stx sp sty sp+1 ; set argument stack ptr -; Initialize the heap +; Call module constructors - jsr __hinit + jsr initlib ; Initialize conio stuff @@ -103,9 +104,12 @@ MemOk: stx sp ldy #4 ; Argument size jsr _main ; call the users code -; fall thru to exit... +; Call module destructors. This is also the _exit entry. + +_exit: jsr donelib ; Run module destructors + +; Restore system stuff -_exit: jsr doatexit ; call exit functions ldx spsave txs diff --git a/libsrc/runtime/Makefile b/libsrc/runtime/Makefile index 3fb6dfca7..febeb68f4 100644 --- a/libsrc/runtime/Makefile +++ b/libsrc/runtime/Makefile @@ -5,11 +5,9 @@ .SUFFIXES: .o .s .c .c.s: - @echo $< @$(CC) $(CFLAGS) $< .s.o: - @echo $< @$(AS) -g -o $@ $(AFLAGS) $< OBJS = add.o \ diff --git a/libsrc/runtime/condes.s b/libsrc/runtime/condes.s index e94097535..51130f404 100644 --- a/libsrc/runtime/condes.s +++ b/libsrc/runtime/condes.s @@ -16,7 +16,7 @@ ; lies in the data segment so it's address may be patched at runtime. ; - .export libinit, libdone, condes + .export initlib, donelib, condes .export jmpvec .import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__ @@ -29,7 +29,7 @@ ; -------------------------------------------------------------------------- ; Initialize library modules -.proc libinit +.proc initlib lda #<__CONSTRUCTOR_TABLE__ ldx #>__CONSTRUCTOR_TABLE__ @@ -43,12 +43,12 @@ ; -------------------------------------------------------------------------- ; Cleanup library modules -.proc libdone +.proc donelib - lda #<__DESTRUCTOR_TABLE__ - ldx #>__DESTRUCTOR_TABLE__ - ldy #<(__DESTRUCTOR_COUNT__*2) - bne condes + lda #<__DESTRUCTOR_TABLE__ + ldx #>__DESTRUCTOR_TABLE__ + ldy #<(__DESTRUCTOR_COUNT__*2) + bne condes rts .endproc -- 2.39.5