]> git.sur5r.net Git - cc65/commitdiff
Rewrote fopen in assembler
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 23 Nov 2002 18:46:40 +0000 (18:46 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 23 Nov 2002 18:46:40 +0000 (18:46 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@1608 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/common/.cvsignore
libsrc/common/Makefile
libsrc/common/fopen.c [deleted file]
libsrc/common/fopen.s [new file with mode: 0644]

index 46556ea50ec8139fbc30240d37351c3eae2bc012..3f648ea4fa677e0553b3730d4959d25b01514a2b 100644 (file)
@@ -11,7 +11,6 @@ fdopen.s
 fgetc.s
 fgetpos.s
 fgets.s
-fopen.s
 fputc.s
 fputs.s
 fread.s
index 94129707b9b1b89b4bacff2cb7c6dd326855ad9a..ba1d3b6979244e005b17b4af354bc14600e1ea9b 100644 (file)
@@ -23,7 +23,6 @@ C_OBJS =      _afailed.o      \
                fgetc.o         \
                fgetpos.o       \
                fgets.o         \
-               fopen.o         \
                fputc.o         \
                fputs.o         \
                fread.o         \
@@ -72,6 +71,7 @@ S_OBJS =      _fdesc.o        \
                 divt.o          \
                errno.o         \
                fmisc.o         \
+               fopen.o         \
                fprintf.o       \
                free.o          \
                getcpu.o        \
diff --git a/libsrc/common/fopen.c b/libsrc/common/fopen.c
deleted file mode 100644 (file)
index f5c3652..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * fopen.c
- *
- * Ullrich von Bassewitz, 17.06.1998
- */
-
-
-
-#include <stdio.h>
-#include <fcntl.h>
-#include <errno.h>
-#include "_file.h"
-
-
-
-FILE* fopen (const char* name, const char* mode)
-{
-    FILE* f;
-
-    /* Find a free file slot */
-    if (!(f = _fdesc ())) {
-               /* No slots */
-               _errno = EMFILE;                /* Too many files */
-               return 0;
-    }
-
-    /* Open the file and return the descriptor */
-    return _fopen (name, mode, f);
-}
-
-
-
diff --git a/libsrc/common/fopen.s b/libsrc/common/fopen.s
new file mode 100644 (file)
index 0000000..791dfcf
--- /dev/null
@@ -0,0 +1,51 @@
+;
+; Ullrich von Bassewitz, 22.11.2002
+;
+; FILE* __fastcall__ fopen (const char* name, const char* mode)
+; /* Open a file */
+;
+
+        .export         _fopen
+
+        .import         __fopen, __fdesc
+        .import         pushax, return0
+
+        .include        "errno.inc"
+
+
+; ------------------------------------------------------------------------
+; Code
+
+.proc   _fopen
+
+; Bring the mode parameter on the stack
+
+        jsr     pushax
+
+; Allocate a new file stream
+
+        jsr     __fdesc
+
+; Check if we have a stream
+
+        cmp     #$00
+        bne     @L1
+        cpx     #$00
+        bne     @L1
+
+; Failed to allocate a file stream
+
+        lda     #EMFILE
+        sta     __errno
+        lda     #0
+        sta     __errno+1
+        tax
+        rts                     ; Return zero
+
+; Open the file and return the file descriptor. All arguments are already
+; in place: name and mode on the stack, and f in a/x
+
+@L1:    jmp     __fopen
+
+.endproc
+