From 623fd3e103fbac08d23e0360419292ba515c6c04 Mon Sep 17 00:00:00 2001 From: cuz Date: Thu, 26 Oct 2000 06:36:29 +0000 Subject: [PATCH] Splitted the atexit module. Minor cleanup in doatexit. git-svn-id: svn://svn.cc65.org/cc65/trunk@395 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/common/Makefile | 2 ++ libsrc/common/atexit.s | 61 +++++++++++++--------------------------- libsrc/common/doatexit.s | 38 +++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 42 deletions(-) create mode 100644 libsrc/common/doatexit.s diff --git a/libsrc/common/Makefile b/libsrc/common/Makefile index 37bddd075..e90d1a634 100644 --- a/libsrc/common/Makefile +++ b/libsrc/common/Makefile @@ -33,6 +33,7 @@ S_OBJS = _fdesc.o \ atexit.o \ atoi.o \ copydata.o \ + doatexit.o \ errno.o \ fmisc.o \ free.o \ @@ -94,3 +95,4 @@ clean: @rm -f $(C_OBJS:.o=.s) @rm -f $(C_OBJS) @rm -f $(S_OBJS) + diff --git a/libsrc/common/atexit.s b/libsrc/common/atexit.s index 1751b8063..14ba9c26d 100644 --- a/libsrc/common/atexit.s +++ b/libsrc/common/atexit.s @@ -4,34 +4,28 @@ ; int atexit (void (*f) (void)); ; -; The exit functions - - .export _atexit, doatexit - .import __errno, jmpvec + .export _atexit + .import exitfunc_table, exitfunc_index + .importzp exitfunc_max + .import __errno .include "errno.inc" -.bss -ecount: .byte 0 ; Really an index, inc'ed by 2 -efunc: .word 0,0,0,0,0 ; 5 exit functions -maxcount = * - efunc - -.code +.proc _atexit -_atexit: - ldy ecount - cpy #maxcount ; slot available? - beq E0 ; jump if no + ldy exitfunc_index + cpy #exitfunc_max ; Slot available? + beq @Error ; Jump if no ; Enter the function into the table - sta efunc,y + sta exitfunc_table,y iny txa - sta efunc,y + sta exitfunc_table,y iny - sty ecount + sty exitfunc_index ; Done, return zero @@ -41,32 +35,15 @@ _atexit: ; Error, no space left -E0: lda #ENOSPC ; No space left - sta __errno - ldx #$00 - stx __errno+1 - dex - txa - rts - -; Function called from exit - -doatexit: - ldy ecount ; get index - beq L9 ; jump if done - dey - lda efunc,y - sta jmpvec+2 - dey - lda efunc,y - sta jmpvec+1 - sty ecount - ldy #0 ; number of function parms - jsr jmpvec - jmp doatexit ; next one - -L9: rts +@Error: lda #ENOSPC ; No space left + sta __errno + ldx #$00 + stx __errno+1 + dex ; Make return value -1 + txa + rts +.endproc diff --git a/libsrc/common/doatexit.s b/libsrc/common/doatexit.s new file mode 100644 index 000000000..39265cf2c --- /dev/null +++ b/libsrc/common/doatexit.s @@ -0,0 +1,38 @@ +; +; Ullrich von Bassewitz, 26.10.2000 +; +; Handle exit functions +; + + .export doatexit, exitfunc_index, exitfunc_table + .exportzp exitfunc_max + .import jmpvec + +.bss +exitfunc_index: .res 1 ; Index into table, inc'ed by 2 +exitfunc_table: .res 10 ; 5 exit functions +exitfunc_max = <(* - exitfunc_table) + + +.code + +.proc doatexit + + ldy exitfunc_index ; Get index + beq @L9 ; Jump if done + dey + lda exitfunc_table,y + sta jmpvec+2 + dey + lda exitfunc_table,y + sta jmpvec+1 + sty exitfunc_index + jsr jmpvec ; Call the function + jmp doatexit ; Next one + +@L9: rts + +.endproc + + + -- 2.39.5