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
|
2002-12-03 20:01:43 +00:00
|
|
|
.destructor doatexit, 5
|
2000-10-26 06:36:29 +00:00
|
|
|
.import __errno
|
2002-12-26 16:00:35 +00:00
|
|
|
.import callax
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2000-06-24 09:02:08 +00:00
|
|
|
.include "errno.inc"
|
|
|
|
|
2003-10-10 17:52:12 +00:00
|
|
|
.macpack cpu
|
|
|
|
|
2000-11-20 23:05:52 +00:00
|
|
|
; ---------------------------------------------------------------------------
|
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?
|
2003-10-10 17:52:12 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
2000-11-20 23:05:52 +00:00
|
|
|
; ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.code
|
|
|
|
|
|
|
|
.proc doatexit
|
|
|
|
|
|
|
|
ldy exitfunc_index ; Get index
|
|
|
|
beq @L9 ; Jump if done
|
|
|
|
dey
|
|
|
|
lda exitfunc_table,y
|
2002-12-26 16:00:35 +00:00
|
|
|
tax
|
2000-11-20 23:05:52 +00:00
|
|
|
dey
|
|
|
|
lda exitfunc_table,y
|
|
|
|
sty exitfunc_index
|
2002-12-26 16:00:35 +00:00
|
|
|
jsr callax ; Call the function
|
2003-10-10 17:52:12 +00:00
|
|
|
.if (.cpu .bitand ::CPU_ISET_65SC02)
|
2002-12-25 03:24:09 +00:00
|
|
|
bra doatexit
|
|
|
|
.else
|
2000-11-20 23:05:52 +00:00
|
|
|
jmp doatexit ; Next one
|
2002-12-25 03:24:09 +00:00
|
|
|
.endif
|
2000-11-20 23:05:52 +00:00
|
|
|
|
|
|
|
@L9: rts
|
|
|
|
|
2003-10-10 17:52:12 +00:00
|
|
|
.endproc
|
2000-11-20 23:05:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.bss
|
|
|
|
exitfunc_index: .res 1 ; Index into table, inc'ed by 2
|
|
|
|
exitfunc_table: .res 10 ; 5 exit functions
|
|
|
|
exitfunc_max = <(* - exitfunc_table)
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|