]> git.sur5r.net Git - cc65/commitdiff
Implemented rewinddir/seekdir.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 3 Jun 2012 15:11:32 +0000 (15:11 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 3 Jun 2012 15:11:32 +0000 (15:11 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@5676 b7a2c559-68d2-44c3-8de9-860c34a00d81

include/dirent.h
libsrc/cbm/Makefile
libsrc/cbm/dir.inc
libsrc/cbm/rewinddir.s [new file with mode: 0644]
libsrc/cbm/seekdir.c [new file with mode: 0644]

index 11c6edc32ff7a6e944fd3d97b3ce9929f933351d..cb3ddc139bda241506c38d43a3827daefb373279 100644 (file)
@@ -126,6 +126,10 @@ struct dirent* __fastcall__ readdir (DIR* dir);
 
 int __fastcall__ closedir (DIR* dir);
 
+long __fastcall__ telldir (DIR* dir);
+
+void __fastcall__ seekdir (DIR* dir, long offs);
+
 void __fastcall__ rewinddir (DIR* dir);
 
 
index c25d068305fe3592b8cc78770e23760cb6118b2b..c91428a428ab1155f6d1d223c615481f87fa35e0 100644 (file)
@@ -33,7 +33,8 @@ C_OBJS =              cbm_dir.o       \
                 cbm_load.o     \
                cbm_save.o      \
                 opendir.o       \
-                readdir.o
+                readdir.o       \
+                seekdir.o
 
 S_OBJS =       c_acptr.o       \
                c_basin.o       \
@@ -82,6 +83,7 @@ S_OBJS =      c_acptr.o       \
                 oserrlist.o     \
                oserror.o       \
                 read.o          \
+                rewinddir.o     \
                 rwcommon.o      \
                 scratch.o       \
                 sysremove.o     \
index ffab6c20c3dd9754c7fb54ddd586985c8820b8a1..5e2dfc6d64eb6f749f1a290ca12a6b074150e86a 100644 (file)
@@ -10,7 +10,7 @@
 
 .struct DIR
     fd          .word
-    off         .word     
+    off         .word
     name        .byte   16+1
 .endstruct
 
         .global _opendir
         .global _closedir
         .global _readdir
-;        .global _telldir
-;        .global _rewinddir
+        .global _seekdir
+        .global _telldir
+        .global _rewinddir
         .global __dirread
         .global __dirread1
-        .global __dirskip
 
 
diff --git a/libsrc/cbm/rewinddir.s b/libsrc/cbm/rewinddir.s
new file mode 100644 (file)
index 0000000..d84d08a
--- /dev/null
@@ -0,0 +1,25 @@
+;
+; Ullrich von Bassewitz, 2012-06-03
+;
+; Based on C code by Groepaz
+;
+; void __fastcall__ rewinddir (DIR *dir);
+;
+
+
+        .include        "dir.inc"
+        .include        "zeropage.inc"
+
+        .import         pushax
+
+.proc   _rewinddir
+
+        jsr     pushax          ; Push dir
+        ldx     #0
+        stx     sreg+1
+        stx     sreg
+        lda     #32             ; Pass 32 as offset ...
+        jmp     _seekdir        ; ... to seekdir
+
+.endproc
+
diff --git a/libsrc/cbm/seekdir.c b/libsrc/cbm/seekdir.c
new file mode 100644 (file)
index 0000000..0a4fe07
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Ullrich von Bassewitz, 2012-06-03. Based on code by Groepaz.
+ */
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include "dir.h"
+
+
+
+void __fastcall__ seekdir (register DIR* dir, long offs)
+{
+    unsigned      o;
+    unsigned char count;
+    unsigned char buf[128];
+
+    /* Make sure we have a reasonable value for offs */
+    if (offs > 0x1000) {
+        errno = EINVAL;
+        return;
+    }
+
+    /* Close the directory file descriptor */
+    close (dir->fd);
+
+    /* Reopen it using the old name */
+    dir->fd = open (dir->name, O_RDONLY);
+    if (dir->fd < 0) {
+        /* Oops! */
+        return;
+    }
+
+    /* Skip until we've reached the target offset in the directory */
+    o = dir->off = offs;
+    while (o) {
+
+        /* Determine size of next chunk to read */
+        if (o > sizeof (buf)) {  
+            count = sizeof (buf);
+            o -= sizeof (buf);
+        } else {
+            count = offs;
+            o = 0;
+        }
+
+        /* Skip */
+        if (!_dirread (dir, buf, count)) {
+            return;
+        }
+    }
+}
+
+
+