2 ; Ullrich von Bassewitz, 06.06.1998
4 ; int atexit (void (*f) (void));
8 .destructor doatexit, 5
15 ; ---------------------------------------------------------------------------
20 cpy #exitfunc_max ; Slot available?
21 beq @Error ; Jump if no
23 ; Enter the function into the table
38 ; Error, no space left
40 @Error: lda #ENOSPC ; No space left
44 dex ; Make return value -1
52 ; ---------------------------------------------------------------------------
58 ldy exitfunc_index ; Get index
59 beq @L9 ; Jump if done
66 jsr callax ; Call the function
67 .if (.cpu .bitand ::CPU_ISET_65SC02)
70 jmp doatexit ; Next one
79 ; ---------------------------------------------------------------------------
82 exitfunc_index: .res 1 ; Index into table, inc'ed by 2
83 exitfunc_table: .res 10 ; 5 exit functions
84 exitfunc_max = <(* - exitfunc_table)