]> git.sur5r.net Git - cc65/blob - libsrc/common/atexit.s
Replaced missing routine, fixed a bug
[cc65] / libsrc / common / atexit.s
1 ;
2 ; Ullrich von Bassewitz, 06.06.1998
3 ;
4 ; int atexit (void (*f) (void));
5 ;
6
7         .export         _atexit
8         .import         exitfunc_table, exitfunc_index
9         .importzp       exitfunc_max
10         .import         __errno
11
12         .include        "errno.inc"
13
14
15 .proc   _atexit
16
17         ldy     exitfunc_index
18         cpy     #exitfunc_max           ; Slot available?
19         beq     @Error                  ; Jump if no
20
21 ; Enter the function into the table
22
23         sta     exitfunc_table,y
24         iny
25         txa
26         sta     exitfunc_table,y
27         iny
28         sty     exitfunc_index
29
30 ; Done, return zero
31
32         lda     #0
33         tax
34         rts
35
36 ; Error, no space left
37
38 @Error: lda     #ENOSPC         ; No space left
39         sta     __errno
40         ldx     #$00
41         stx     __errno+1
42         dex                     ; Make return value -1
43         txa
44         rts
45
46 .endproc
47
48
49
50