2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 06.06.1998
|
|
|
|
;
|
|
|
|
; int atexit (void (*f) (void));
|
|
|
|
;
|
|
|
|
|
2000-10-26 06:36:29 +00:00
|
|
|
.export _atexit
|
|
|
|
.import exitfunc_table, exitfunc_index
|
|
|
|
.importzp exitfunc_max
|
|
|
|
.import __errno
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-24 09:02:08 +00:00
|
|
|
.include "errno.inc"
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-10-26 06:36:29 +00:00
|
|
|
.proc _atexit
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-10-26 06:36:29 +00:00
|
|
|
ldy exitfunc_index
|
|
|
|
cpy #exitfunc_max ; Slot available?
|
|
|
|
beq @Error ; Jump if no
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; Enter the function into the table
|
|
|
|
|
2000-10-26 06:36:29 +00:00
|
|
|
sta exitfunc_table,y
|
2000-05-28 13:40:48 +00:00
|
|
|
iny
|
|
|
|
txa
|
2000-10-26 06:36:29 +00:00
|
|
|
sta exitfunc_table,y
|
2000-05-28 13:40:48 +00:00
|
|
|
iny
|
2000-10-26 06:36:29 +00:00
|
|
|
sty exitfunc_index
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; Done, return zero
|
|
|
|
|
|
|
|
lda #0
|
|
|
|
tax
|
|
|
|
rts
|
|
|
|
|
|
|
|
; Error, no space left
|
|
|
|
|
2000-10-26 06:36:29 +00:00
|
|
|
@Error: lda #ENOSPC ; No space left
|
|
|
|
sta __errno
|
|
|
|
ldx #$00
|
|
|
|
stx __errno+1
|
|
|
|
dex ; Make return value -1
|
|
|
|
txa
|
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-10-26 06:36:29 +00:00
|
|
|
.endproc
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|