]> git.sur5r.net Git - cc65/commitdiff
Merge pull request #129 from greg-king5/cbmdir
authorOliver Schmidt <ol.sc@web.de>
Thu, 17 Jul 2014 14:50:49 +0000 (16:50 +0200)
committerOliver Schmidt <ol.sc@web.de>
Thu, 17 Jul 2014 14:50:49 +0000 (16:50 +0200)
Update 2 CBM directory functions.

libsrc/cbm/seekdir.c
libsrc/cbm/syschdir.s

index 3ae206b4ef34f4875a46dbc5fd7ea7b78f785e8e..8ccfadb96f47938164923a714cfd346e3e509799 100644 (file)
@@ -1,5 +1,6 @@
 /*
-** Ullrich von Bassewitz, 2012-06-03. Based on code by Groepaz.
+** 2012-06-03, Ullrich von Bassewitz. Based on code by Groepaz.
+** 2014-07-16, Greg King
 */
 
 #include <fcntl.h>
@@ -15,8 +16,10 @@ void __fastcall__ seekdir (register DIR* dir, long offs)
     unsigned char count;
     unsigned char buf[128];
 
-    /* Make sure we have a reasonable value for offs */
-    if (offs > 0x1000) {
+    /* Make sure that we have a reasonable value for offs.  We reject
+    ** negative numbers by converting them to (very high) unsigned values.
+    */
+    if ((unsigned long)offs > 0x1000uL) {
         errno = EINVAL;
         return;
     }
@@ -32,15 +35,15 @@ void __fastcall__ seekdir (register DIR* dir, long offs)
     }
 
     /* Skip until we've reached the target offset in the directory */
-    o = dir->off = offs;
+    o = dir->off = (unsigned)offs;
     while (o) {
 
         /* Determine size of next chunk to read */
-        if (o > sizeof (buf)) {  
+        if (o > sizeof (buf)) {
             count = sizeof (buf);
             o -= sizeof (buf);
         } else {
-            count = offs;
+            count = (unsigned char)o;
             o = 0;
         }
 
index 9361d56f0754ad9f731b80a242dfa6ff05632327..a4a83cd21537a5de41b54c5d8e339da570426c05 100644 (file)
@@ -1,5 +1,6 @@
 ;
-; Oliver Schmidt, 2012-10-16
+; 2012-10-16, Oliver Schmidt
+; 2014-07-16, Greg King
 ;
 ; unsigned char __fastcall__ _syschdir (const char* name);
 ;
 
 ; Multiply first digit by 10
 
-        ldx     #8
-@L0:    asl
-        asl     tmp1
-        bcc     @L1
-        clc
-        adc     #10
-@L1:    dex
-        bne     @L0
+        txa
+        asl     a               ; * 2
+        asl     a               ; * 4, carry cleared
+        adc     tmp1            ; * 5
+        asl     a               ; * 10, carry cleared
 
 ; Add second digit to product
 
-        clc
         adc     tmp2
         tax
 
@@ -80,7 +77,8 @@ done:   rts
 .endproc
 
 ;--------------------------------------------------------------------------
-; getdigit
+; getdigit -- Converts PetSCII to binary.
+; Sets carry if the character is outside of '0'-'9'.
 
 .proc   getdigit