]> git.sur5r.net Git - cc65/commitdiff
added closeallfiles: close all files at program exit
authorcpg <cpg@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 5 Jan 2003 23:36:16 +0000 (23:36 +0000)
committercpg <cpg@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 5 Jan 2003 23:36:16 +0000 (23:36 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1892 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/atari/open.s

index e45f7813fc83a89ac0b0228f3ac03c5d7430b28f..7d97a7dffcd60e604cb1108dd5aaf3e016e2b2d2 100644 (file)
@@ -1,5 +1,5 @@
 ;
-; Christian Groessler, May-2002
+; Christian Groessler, Jan-2003
 ;
 ; int open(const char *name,int flags,...);
 ;
@@ -7,7 +7,12 @@
        .include "atari.inc"
        .include "fcntl.inc"
        .include "errno.inc"
+       .include "fd.inc"
+
        .export _open
+        .destructor     closeallfiles, 17
+
+       .import _close
        .import clriocb
        .import fddecusage,newfd
        .import findfreeiocb
@@ -47,7 +52,6 @@ iocbok:       stx     tmp4
        jsr     clriocb         ; init with zero
        ldy     #1
        jsr     ldaxysp         ; get mode
-       ;brk
        ldx     tmp4
        pha
        and     #O_APPEND
@@ -149,3 +153,20 @@ ok:        lda     tmp2            ; get fd
        rts
 
 .endproc
+
+
+; closeallfiles: Close all files opened by the program.
+
+.proc   closeallfiles
+
+       lda     #MAX_FD_INDEX-1
+loop:  ldx     #0
+       pha
+       jsr     _close
+       pla
+       clc
+       sbc     #0
+       bpl     loop
+       rts
+
+.endproc