mirror of
https://github.com/cc65/cc65.git
synced 2025-08-08 22:25:28 +00:00
Splitted the atexit module. Minor cleanup in doatexit.
git-svn-id: svn://svn.cc65.org/cc65/trunk@395 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -33,6 +33,7 @@ S_OBJS = _fdesc.o \
|
|||||||
atexit.o \
|
atexit.o \
|
||||||
atoi.o \
|
atoi.o \
|
||||||
copydata.o \
|
copydata.o \
|
||||||
|
doatexit.o \
|
||||||
errno.o \
|
errno.o \
|
||||||
fmisc.o \
|
fmisc.o \
|
||||||
free.o \
|
free.o \
|
||||||
@@ -94,3 +95,4 @@ clean:
|
|||||||
@rm -f $(C_OBJS:.o=.s)
|
@rm -f $(C_OBJS:.o=.s)
|
||||||
@rm -f $(C_OBJS)
|
@rm -f $(C_OBJS)
|
||||||
@rm -f $(S_OBJS)
|
@rm -f $(S_OBJS)
|
||||||
|
|
||||||
|
@@ -4,34 +4,28 @@
|
|||||||
; int atexit (void (*f) (void));
|
; int atexit (void (*f) (void));
|
||||||
;
|
;
|
||||||
|
|
||||||
; The exit functions
|
.export _atexit
|
||||||
|
.import exitfunc_table, exitfunc_index
|
||||||
.export _atexit, doatexit
|
.importzp exitfunc_max
|
||||||
.import __errno, jmpvec
|
.import __errno
|
||||||
|
|
||||||
.include "errno.inc"
|
.include "errno.inc"
|
||||||
|
|
||||||
.bss
|
|
||||||
ecount: .byte 0 ; Really an index, inc'ed by 2
|
|
||||||
efunc: .word 0,0,0,0,0 ; 5 exit functions
|
|
||||||
maxcount = * - efunc
|
|
||||||
|
|
||||||
|
.proc _atexit
|
||||||
|
|
||||||
.code
|
ldy exitfunc_index
|
||||||
|
cpy #exitfunc_max ; Slot available?
|
||||||
_atexit:
|
beq @Error ; Jump if no
|
||||||
ldy ecount
|
|
||||||
cpy #maxcount ; slot available?
|
|
||||||
beq E0 ; jump if no
|
|
||||||
|
|
||||||
; Enter the function into the table
|
; Enter the function into the table
|
||||||
|
|
||||||
sta efunc,y
|
sta exitfunc_table,y
|
||||||
iny
|
iny
|
||||||
txa
|
txa
|
||||||
sta efunc,y
|
sta exitfunc_table,y
|
||||||
iny
|
iny
|
||||||
sty ecount
|
sty exitfunc_index
|
||||||
|
|
||||||
; Done, return zero
|
; Done, return zero
|
||||||
|
|
||||||
@@ -41,32 +35,15 @@ _atexit:
|
|||||||
|
|
||||||
; Error, no space left
|
; Error, no space left
|
||||||
|
|
||||||
E0: lda #ENOSPC ; No space left
|
@Error: lda #ENOSPC ; No space left
|
||||||
sta __errno
|
sta __errno
|
||||||
ldx #$00
|
ldx #$00
|
||||||
stx __errno+1
|
stx __errno+1
|
||||||
dex
|
dex ; Make return value -1
|
||||||
txa
|
txa
|
||||||
rts
|
rts
|
||||||
|
|
||||||
; Function called from exit
|
|
||||||
|
|
||||||
doatexit:
|
|
||||||
ldy ecount ; get index
|
|
||||||
beq L9 ; jump if done
|
|
||||||
dey
|
|
||||||
lda efunc,y
|
|
||||||
sta jmpvec+2
|
|
||||||
dey
|
|
||||||
lda efunc,y
|
|
||||||
sta jmpvec+1
|
|
||||||
sty ecount
|
|
||||||
ldy #0 ; number of function parms
|
|
||||||
jsr jmpvec
|
|
||||||
jmp doatexit ; next one
|
|
||||||
|
|
||||||
L9: rts
|
|
||||||
|
|
||||||
|
.endproc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
38
libsrc/common/doatexit.s
Normal file
38
libsrc/common/doatexit.s
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
;
|
||||||
|
; Ullrich von Bassewitz, 26.10.2000
|
||||||
|
;
|
||||||
|
; Handle exit functions
|
||||||
|
;
|
||||||
|
|
||||||
|
.export doatexit, exitfunc_index, exitfunc_table
|
||||||
|
.exportzp exitfunc_max
|
||||||
|
.import jmpvec
|
||||||
|
|
||||||
|
.bss
|
||||||
|
exitfunc_index: .res 1 ; Index into table, inc'ed by 2
|
||||||
|
exitfunc_table: .res 10 ; 5 exit functions
|
||||||
|
exitfunc_max = <(* - exitfunc_table)
|
||||||
|
|
||||||
|
|
||||||
|
.code
|
||||||
|
|
||||||
|
.proc doatexit
|
||||||
|
|
||||||
|
ldy exitfunc_index ; Get index
|
||||||
|
beq @L9 ; Jump if done
|
||||||
|
dey
|
||||||
|
lda exitfunc_table,y
|
||||||
|
sta jmpvec+2
|
||||||
|
dey
|
||||||
|
lda exitfunc_table,y
|
||||||
|
sta jmpvec+1
|
||||||
|
sty exitfunc_index
|
||||||
|
jsr jmpvec ; Call the function
|
||||||
|
jmp doatexit ; Next one
|
||||||
|
|
||||||
|
@L9: rts
|
||||||
|
|
||||||
|
.endproc
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user