2 ; Ullrich von Bassewitz, 06.06.1998
4 ; int atexit (void (*f) (void));
8 .destructor doatexit, 5
14 ; ---------------------------------------------------------------------------
19 cpy #exitfunc_max ; Slot available?
20 beq @Error ; Jump if no
22 ; Enter the function into the table
37 ; Error, no space left
39 @Error: lda #ENOSPC ; No space left
43 dex ; Make return value -1
51 ; ---------------------------------------------------------------------------
57 ldy exitfunc_index ; Get index
58 beq @L9 ; Jump if done
66 jsr jmpvec ; Call the function
67 jmp doatexit ; Next one
75 ; ---------------------------------------------------------------------------
78 exitfunc_index: .res 1 ; Index into table, inc'ed by 2
79 exitfunc_table: .res 10 ; 5 exit functions
80 exitfunc_max = <(* - exitfunc_table)