2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 06.06.1998
|
|
|
|
;
|
|
|
|
; int atexit (void (*f) (void));
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _atexit
|
|
|
|
.destructor doatexit, 17
|
|
|
|
.import callax
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "errno.inc"
|
2000-06-24 09:02:08 +00:00
|
|
|
|
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
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.proc _atexit
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2013-05-09 11:56:54 +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
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
sta exitfunc_table,y
|
|
|
|
iny
|
|
|
|
txa
|
|
|
|
sta exitfunc_table,y
|
|
|
|
iny
|
|
|
|
sty exitfunc_index
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; Done, return zero
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #0
|
|
|
|
tax
|
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; Error, no space left
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
@Error: lda #ENOSPC ; No space left
|
2022-08-28 19:52:53 +00:00
|
|
|
jsr ___seterrno
|
2013-05-09 11:56:54 +00:00
|
|
|
ldx #$FF ; Return -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
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.proc doatexit
|
|
|
|
|
|
|
|
ldy exitfunc_index ; Get index
|
|
|
|
beq @L9 ; Jump if done
|
|
|
|
dey
|
|
|
|
lda exitfunc_table,y
|
|
|
|
tax
|
|
|
|
dey
|
|
|
|
lda exitfunc_table,y
|
|
|
|
sty exitfunc_index
|
|
|
|
jsr callax ; Call the function
|
2003-10-10 17:52:12 +00:00
|
|
|
.if (.cpu .bitand ::CPU_ISET_65SC02)
|
2013-05-09 11:56:54 +00:00
|
|
|
bra doatexit
|
2002-12-25 03:24:09 +00:00
|
|
|
.else
|
2013-05-09 11:56:54 +00:00
|
|
|
jmp doatexit ; Next one
|
2002-12-25 03:24:09 +00:00
|
|
|
.endif
|
2000-11-20 23:05:52 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
@L9: rts
|
2000-11-20 23:05:52 +00:00
|
|
|
|
2003-10-10 17:52:12 +00:00
|
|
|
.endproc
|
2000-11-20 23:05:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.bss
|
2013-05-09 11:56:54 +00:00
|
|
|
exitfunc_index: .res 1 ; Index into table, inc'ed by 2
|
|
|
|
exitfunc_table: .res 10 ; 5 exit functions
|
|
|
|
exitfunc_max = <(* - exitfunc_table)
|
2000-11-20 23:05:52 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|