changeset 61:80f4ec9a3420

fix writeln chdir don't touch the path descriptor contents
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 25 Jul 2018 20:05:06 +0900
parents 84d2d5a54ed0
children 5b3871f8bdaa
files src/io.c src/os9/level2/vrbf.asm src/v09.c src/vdisk.c
diffstat 4 files changed, 52 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/io.c	Tue Jul 24 17:04:46 2018 +0900
+++ b/src/io.c	Wed Jul 25 20:05:06 2018 +0900
@@ -90,7 +90,7 @@
 #define SECSIZE 256
 
 
-int timer = 1;
+int timer = 0;
 int timer_usec = 20000;   //  50Hz
 struct termios termsetting;
 struct termios newterm;
@@ -297,6 +297,7 @@
 void do_timer(int a, int c) {
    struct itimerval timercontrol;
    if (a==0x30+(IOPAGE&0x1ff) && c==0x8f) {
+        if ((timer&2)==0) return;  
         timercontrol.it_interval.tv_sec = 0;
         timercontrol.it_interval.tv_usec = timer_usec;
         timercontrol.it_value.tv_sec = 0;
@@ -405,7 +406,7 @@
         timercontrol.it_interval.tv_usec = timer_usec;
         timercontrol.it_value.tv_sec = 0;
         timercontrol.it_value.tv_usec = timer_usec;
-        if (timer)
+        if (!timer)   // original sbc09 start timer from the beginning
             setitimer(ITIMER_REAL, &timercontrol, NULL);
 }
 
--- a/src/os9/level2/vrbf.asm	Tue Jul 24 17:04:46 2018 +0900
+++ b/src/os9/level2/vrbf.asm	Wed Jul 25 20:05:06 2018 +0900
@@ -72,10 +72,9 @@
 Create   pshs  y,u,cc		Preserve path desc ptr
          orcc  #IntMasks
          bsr   setuppd
-         stb   4,u              put file attribute
          ldb   #$d1
-         stb   ,u               do IO   b,x will be rewrited
-         ldb   ,u
+         stb   ,x               do IO   b,x will be rewrited
+         ldb   ,x
          beq   ok00
          bra   er00
 
--- a/src/v09.c	Tue Jul 24 17:04:46 2018 +0900
+++ b/src/v09.c	Wed Jul 25 20:05:06 2018 +0900
@@ -158,7 +158,7 @@
      tracing=1;attention=1;    
    } else if (strcmp(argv[i],"-rom")==0) {
      i++;
-     timer = 0;         // non standard rom image, don't start timer
+     timer = 3;         // non standard rom image, don't start timer, and timder start call enabled
      timerirq = 1 ;     // os9 cannot handle FIRQ
      romfile = argv[i];
 
@@ -182,7 +182,7 @@
      romstart=strtol(argv[i],(char**)0,0);
    } else if (strcmp(argv[i],"-nt")==0) {  // start debugger at the start
      attention = escape = 1;
-     timer = 0;   // no timer
+     timer = 1;   // desable default  timer interrupt and don't start timer on timer start IO 
    } else if (strcmp(argv[i],"-m")==0) {
      i++;
      memsize=strtol(argv[i],(char**)0,0) & ~0xffff;
--- a/src/vdisk.c	Tue Jul 24 17:04:46 2018 +0900
+++ b/src/vdisk.c	Wed Jul 25 20:05:06 2018 +0900
@@ -16,8 +16,9 @@
 #include <string.h>
 #include <time.h>
 #include <arpa/inet.h>
+#include <fcntl.h>
 
-static int vdiskdebug = 0;  //   bit 1 trace, bit 2 filename
+static int vdiskdebug = 1;  //   bit 1 trace, bit 2 filename
 
 
 Byte pmmu[8];  // process dat mmu
@@ -200,6 +201,8 @@
         for(i=0;i<p-path;i++) name[i] = path[i];
         if (eighth) { name[i] = path[i]&0x7f; p++ ; i++; }
         name[i] = 0;
+        // skip trailing space
+        while(*p==' ') p++;
     }
     char *name1 = addCurdir(name,pd,curdir);
     if (name1!=name && name1!=path) free(name);
@@ -233,13 +236,27 @@
 }
 
 static char * 
-os9toUnixAttr(Byte attr) {
-    if ((attr&0x1) && (attr&0x2)) return "r+";
-    if (!(attr&0x1) && (attr&0x2)) return "w";
-    if ((attr&0x1) && !(attr&0x2)) return "r";
+os9toUnixAttr(Byte mode) {
+    if ((mode&0x1) && (mode&0x2)) return "r+";
+    if (!(mode&0x1) && (mode&0x2)) return "w";
+    if ((mode&0x1) && !(mode&0x2)) return "r";
     return "r";
 }
 
+static int 
+os9mode(Byte m) {
+    int mode = 0;
+    if ((m&0x80)) mode|=S_IFDIR ;
+    if ((m&0x01)) mode|=S_IRUSR ;
+    if ((m&0x02)) mode|=S_IWUSR ;
+    if ((m&0x04)) mode|=S_IXUSR ;
+    if ((m&0x08)) mode|=S_IROTH ;
+    if ((m&0x10)) mode|=S_IWOTH ;
+    if ((m&0x20)) mode|=S_IXOTH ;
+    return mode;
+}
+
+
 /*
  *   os9 file descriptor
  *   * File Descriptor Format
@@ -470,16 +487,20 @@
         case 0xd1:
             mode = *areg;
             attr = *breg;
+            pd->fp = 0;
             path = (char *)pmem(xreg);
-            next = pd->name  = checkFileName(path,pd,curdir);
-            pd->dir = 0;
-            pd->fp = fopen(pd->name, os9toUnixAttr(attr));
+            next = checkFileName(path,pd,curdir);
+            *breg = 0xff;
+            int fd = open(pd->name, O_RDWR+O_CREAT,os9mode(attr) );
+            if (fd>0)
+                pd->fp = fdopen(fd, os9toUnixAttr(mode));
             if (next!=0 && pd->fp ) {
+                *breg = 0;
+                *areg = pd->num;
+                *smem(u+1) = *areg ;
                 xreg += ( next - path );
                 pd->use = 1;
             } else  {
-                *breg = 0xff;
-                free(pd->name);
                 pd->use = 0;
             }
             break;
@@ -497,7 +518,6 @@
         *        B = errcode
         */
         case 0xd2:
-            *breg = 0xff;
             mode = *areg;
             attr = *breg;
             pd->fp = 0;
@@ -573,23 +593,24 @@
         *
         *
         * we keep track a cwd and a cxd for a process using 8bit id
+        * don't use path descriptor on y 
         */
-        case 0xd4:
+        case 0xd4: {
+            PathDesc dm = *pd;
             path = (char*)pmem(xreg);
-            next = checkFileName(path,pd,curdir);
+            next = checkFileName(path,&dm,curdir);
             if (next!=0) { 
                 struct stat buf;
-                if (stat(pd->name,&buf)!=0) break;
+                if (stat(dm.name,&buf)!=0) break;
                 if ((buf.st_mode & S_IFMT) != S_IFDIR) break;
                 xreg += ( next - path );
-                *areg = setcd(pd->name);
+                *areg = setcd(dm.name);
                 *smem(u+1) = *areg ;
-                pd->use = 1;
-                pd->dir = 1;
                 *breg = 0;
                 break;
             } 
             *breg = 0xff;
+         }
             break;
 
         /*
@@ -716,7 +737,7 @@
             int len = yreg;
             int i = 0;
             Byte *buf = pmem(xreg);
-            while(len>0 && *buf !='\r') {
+            while(len>0 && buf[i] !='\r') {
                 fputc(buf[i++],pd->fp);
                 len--;
             }
@@ -883,6 +904,12 @@
     ureg  = getword(frame+8);
     pcreg  = getword(frame+10)-3;            // point os9 swi2
     prog = (char*)(pmem(pcreg) - pcreg);
+    if (*pmem(pcreg)==0 && *pmem(pcreg+1)==0) {
+        // may be we are called from system state
+        // of coursel, this may wrong. but in system state, <$50 process has wrong DAT for pc
+        // and we can't know wether we are called from system or user
+        prog = (char*)(smem(pcreg) - pcreg);
+    }
     do_trace(fp);
 }