changeset 1:3c736a81b886

add disk
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 02 Jul 2018 19:07:39 +0900
parents 9a224bd9b45f
children 31d96e2b364e
files a09.c io.c os9/Makefile os9/makerom.c os9/os9disass.c v09.c
diffstat 6 files changed, 236 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/a09.c	Mon Jul 02 02:12:31 2018 +0900
+++ b/a09.c	Mon Jul 02 19:07:39 2018 +0900
@@ -1137,8 +1137,10 @@
         if(unknown)error|=4;
         loccounter+=operand;
         if(generating&&pass==2) {
-           if(!outmode)for(i=0;i<operand;i++)fputc(0,objfile);
-           else flushhex();  
+           if(!outmode)for(i=0;i<operand;i++) {
+              crc = os9crc(0,crc);   
+              fputc(0,objfile);
+           } else flushhex();  
         }   
         hexaddr=loccounter;
         break;
@@ -1236,7 +1238,7 @@
          if(unknown)error|=4;
          if(generating&&pass==2) {
            for(i=0;i<(unsigned short)operand-loccounter;i++)
-                if(!outmode)fputc(0,objfile);else flushhex();
+                if(!outmode) { fputc(0,objfile); crc=os9crc(0,crc); } else flushhex();
          }             
          loccounter=operand;
          hexaddr=loccounter;
--- a/io.c	Mon Jul 02 02:12:31 2018 +0900
+++ b/io.c	Mon Jul 02 19:07:39 2018 +0900
@@ -34,6 +34,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <string.h>
+#include <time.h>
 
 #ifdef USE_TERMIOS
 #include <termios.h>
@@ -42,6 +43,29 @@
 #define engine extern
 #include "v09.h"
 
+/*
+ *      IO Map
+ *
+ *   0xe000 - 0xe100
+ *
+ *   0xe000   ACIA  control
+ *   0xe001   ACIA  data
+ *
+ *   0xe010   Timer control       0x8f start timer/0x80 stop timer/0x04 update date
+ *   0xe011-  YY/MM/DD/HH/MM/SS
+ *
+ *   0xe020   Disk control        0x81 read/0x55 write   0 ... ok / 0xff .. error
+ *   0xe021   drive no
+ *   0xe022   LSN2
+ *   0xe023   LSN1
+ *   0xe024   LSN0
+ *   0xe025   ADR2
+ *   0xe026   ADR1
+ *
+ */
+
+#define SECSIZE 256
+
 int tflags;
 int timer = 1;
 struct termios termsetting;
@@ -56,10 +80,13 @@
 FILE *logfile;
 FILE *infile;
 FILE *xfile;
+FILE *disk[] = {0,0};
 
 extern void hexadump( unsigned char *b, int l, int loc, int w);
 extern void disasm(int,int);
 
+void do_timer(int,int);
+void do_disk(int,int);
 
 int char_input(void) {
         int c, w, sum;
@@ -151,6 +178,10 @@
                         f = EOF;
                 }
                 return c;
+        } else if ((a&0xf0) == 0x10) { /* timer */
+                return mem[IOPAGE + a];
+        } else if ((a&0xf0) == 0x20) { /* disk */
+                return mem[IOPAGE + a];
         }
         return 0;
 }
@@ -203,6 +234,10 @@
                                 xidx = 0;
                         }
                 }
+        } else if ((a&0xf0) == 0x10) { /* timer */
+             do_timer(a,c);
+        } else if ((a&0xf0) == 0x20) { /* disk */
+             do_disk(a,c);
         }
 }
 
@@ -217,6 +252,54 @@
         exit(0);
 }
 
+void do_timer(int a, int c) {
+   struct itimerval timercontrol;
+   if (a==0x10 && c==0x8f) {
+        timercontrol.it_interval.tv_sec = 0;
+        timercontrol.it_interval.tv_usec = 20000;
+        timercontrol.it_value.tv_sec = 0;
+        timercontrol.it_value.tv_usec = 20000;
+        setitimer(ITIMER_REAL, &timercontrol, NULL);
+   } else if (a==0x10 && c==0x80) {
+        timercontrol.it_interval.tv_sec = 0;
+        timercontrol.it_interval.tv_usec = 0;
+        setitimer(ITIMER_REAL, &timercontrol, NULL);
+   } else if (a==0x10 && c==0x04) {
+      time_t tm = time(0);
+      struct tm *t = localtime(&tm);
+      mem[IOPAGE+0x11] = t->tm_year;
+      mem[IOPAGE+0x12] = t->tm_mon;
+      mem[IOPAGE+0x13] = t->tm_mday;
+      mem[IOPAGE+0x14] = t->tm_hour;
+      mem[IOPAGE+0x15] = t->tm_min;
+      mem[IOPAGE+0x16] = t->tm_sec;
+   } else {
+      mem[IOPAGE+a]=c;
+   }
+}
+
+void do_disk(int a, int c) {
+   if (a!=0x20) {
+      mem[IOPAGE+a]=c;
+      return;
+   }
+   int drv = mem[IOPAGE+0x21];
+   int lsn = (mem[IOPAGE+0x22]<<16) + (mem[IOPAGE+0x23]<<8) + mem[IOPAGE+0x24];
+   int buf = (mem[IOPAGE+0x25]<<8) + mem[IOPAGE+0x26];
+   if (drv > 1 || disk[drv]==0) goto error;
+   if (c==0x81) {
+      if (lseek(fileno(disk[drv]),lsn*SECSIZE,SEEK_SET)==-1) goto error;
+      if (read(fileno(disk[drv]),&mem[buf],SECSIZE)==-1) goto error;
+   } else if (c==0x55) {
+      if (lseek(fileno(disk[drv]),lsn*SECSIZE,SEEK_SET)==-1) goto error;
+      if (write(fileno(disk[drv]),&mem[buf],SECSIZE)==-1) goto error;
+   }
+   mem[IOPAGE+0x20] = 0;
+   return;
+error :
+   mem[IOPAGE+0x20] = 0xff;
+}
+
 typedef struct bp {
   int address;
   int count;
@@ -244,6 +327,8 @@
      "  c  [count] continue;\n"
      "  x  [adr]   dump\n"
      "  xi [adr]   disassemble\n"
+     "  0  file    disk drive 0 image\n"
+     "  1  file    disk drive 1 image\n"
      "  L  file    start log to file\n"
      "  S  file    set input file\n"
      "  X  exit\n"
@@ -374,7 +459,8 @@
                         fclose(logfile);
                 logfile = 0;
                 if (s[1]) {
-                        logfile = fopen(s + 1, "w");
+                        int i=1; while(s[i]==' ') i++;
+                        logfile = fopen(s + i, "w");
                 }
                 break;
         case 'S':
@@ -382,7 +468,8 @@
                         fclose(infile);
                 infile = 0;
                 if (s[1]) {
-                        infile = fopen(s + 1, "r");
+                        int i=1; while(s[i]==' ') i++;
+                        infile = fopen(s + i, "r");
                 }
                 break;
         case 'h':
@@ -399,12 +486,27 @@
                         xfile = 0;
                 }
                 break;
+        case '0':
+        case '1':
+                {   FILE **drv = &disk[ s[0]-'0'] ;
+                if (*drv)
+                        fclose(*drv);
+                *drv = 0;
+                if (s[1]) {
+                        int i=1; while(s[i]==' ') i++;
+                        *drv = fopen(s + i, "r+b");
+                        if ( *drv == 0 ) { printf("can't open %s\n", &s[i]); }
+                }
+                }
+                break;
         case 'U':
                 if (xfile)
                         fclose(xfile);
                 xfile = 0;
                 if (s[1]) {
-                        xfile = fopen(s + 1, "rb");
+                        int i=1; while(s[i]==' ') i++;
+                        xfile = fopen(s + i, "rb");
+                        if ( xfile == 0 ) { printf("can't open %s\n", &s[i]); }
                 }
                 if (xfile)
                         xmstat = 1;
@@ -420,7 +522,9 @@
                         fclose(xfile);
                 xfile = 0;
                 if (s[1]) {
-                        xfile = fopen(s + 1, "wb");
+                        int i=1; while(s[i]==' ') i++;
+                        xfile = fopen(s + i, "wb");
+                        if ( xfile == 0 ) { printf("can't open %s\n", &s[i]); }
                 }
                 if (xfile)
                         xmstat = 2;
--- a/os9/Makefile	Mon Jul 02 02:12:31 2018 +0900
+++ b/os9/Makefile	Mon Jul 02 19:07:39 2018 +0900
@@ -17,4 +17,7 @@
 
 os9b.rom : makerom modules/init.b modules/pty.b
 	./makerom os9b.rom modules/Basic09 modules/Shell modules/init.b modules/mdir modules/SysGo modules/IOMan modules/SCF modules/pty-dd.b modules/pty.b modules/OS9p2 modules/OS9
+
+os9d.rom : makerom modules/init.b modules/pty.b
+	./makerom os9d.rom  modules/Shell modules/dir.b modules/list.b modules/init.b modules/mdir modules/SysGo modules/IOMan modules/SCF modules/rbf.b modules/pty-dd.b modules/pty.b modules/pdisk.b modules/d0.b modules/d1.b modules/clock.b modules/OS9p2 modules/OS9
    
--- a/os9/makerom.c	Mon Jul 02 02:12:31 2018 +0900
+++ b/os9/makerom.c	Mon Jul 02 19:07:39 2018 +0900
@@ -8,7 +8,7 @@
 #include <sys/stat.h>
 
 #define IOBASE 0xe000
-#define IOSIZE 0x800
+#define IOSIZE 0x100
 
 typedef struct os9module {
    int size;
@@ -57,6 +57,9 @@
    putchar(*p & 0x7f);
 }
 
+// calcurate position from the botton
+// avoid v09 IO map on 0xe000-0xe800
+// os9p1 have to be last and at 0xf800
 int findLocation(MPTR m, int loc) {
    if (m==0) return loc;
    int top = findLocation(m->next, loc) - m->size;
@@ -106,7 +109,7 @@
  pos = start;
  for(struct os9module *cur = root.next; cur ; cur = cur->next ) {
     if ( cur->size && (cur->name[0]=='O' && cur->name[1]=='S' && cur->name[2]== -71)) {
-       for(; pos < 0xf800 ; pos++) {
+       for(; pos < 0xf800 ; pos++) {   // os9p1 begins at 0xf800
           fputc(0xff,romfile);
        }
     }
--- a/os9/os9disass.c	Mon Jul 02 02:12:31 2018 +0900
+++ b/os9/os9disass.c	Mon Jul 02 19:07:39 2018 +0900
@@ -916,6 +916,103 @@
 				 { "?????",  0,  1,   D_Illegal,   NULL },        /* 0xff */
 };
 
+
+struct os9syscall { int code; char *name; } os9sys[] = {
+    {0x0000,"F$LINK"},
+    {0x0001,"F$LOAD"},
+    {0x0002,"F$UNLINK"},
+    {0x0003,"F$FORK"},
+    {0x0004,"F$WAIT"},
+    {0x0005,"F$CHAIN"},
+    {0x0006,"F$EXIT"},
+    {0x0007,"F$MEM"},
+    {0x0008,"F$SEND"},
+    {0x0009,"F$ICPT"},
+    {0x000a,"F$SLEEP"},
+    {0x000b,"F$SSPD"},
+    {0x000c,"F$ID"},
+    {0x000d,"F$SPRIOR"},
+    {0x000e,"F$SSWI"},
+    {0x000f,"F$PERR"},
+    {0x0010,"F$PRSNAM"},
+    {0x0011,"F$CMPNAM"},
+    {0x0012,"F$SCHBIT"},
+    {0x0013,"F$ALLBIT"},
+    {0x0014,"F$DELBIT"},
+    {0x0015,"F$TIME"},
+    {0x0016,"F$STIME"},
+    {0x0017,"F$CRC"},
+    {0x0018,"F$GPRDSC"},
+    {0x0019,"F$GBLKMP"},
+    {0x001a,"F$GMODDR"},
+    {0x001b,"F$CPYMEM"},
+    {0x001c,"F$SUSER"},
+    {0x001d,"F$UNLOAD"},
+    {0x0027,"F$VIRQ"},
+    {0x0028,"F$SRQMEM"},
+    {0x0029,"F$SRTMEM"},
+    {0x002a,"F$IRQ"},
+    {0x002b,"F$IOQU"},
+    {0x002c,"F$APROC"},
+    {0x002d,"F$NPROC"},
+    {0x002e,"F$VMODUL"},
+    {0x002f,"F$FIND64"},
+    {0x0030,"F$ALL64"},
+    {0x0031,"F$RET64"},
+    {0x0032,"F$SSVC"},
+    {0x0033,"F$IODEL"},
+    {0x0034,"F$SLINK"},
+    {0x0035,"F$BOOT"},
+    {0x0036,"F$BTMEM"},
+    {0x0037,"F$GPROCP"},
+    {0x0038,"F$MOVE"},
+    {0x0039,"F$ALLRAM"},
+    {0x003a,"F$ALLIMG"},
+    {0x003b,"F$DELIMG"},
+    {0x003c,"F$SETIMG"},
+    {0x003d,"F$FREELB"},
+    {0x003e,"F$FREEHB"},
+    {0x003f,"F$ALLTSK"},
+    {0x0040,"F$DELTSK"},
+    {0x0041,"F$SETTSK"},
+    {0x0042,"F$RESTSK"},
+    {0x0043,"F$RELTSK"},
+    {0x0044,"F$DATLOG"},
+    {0x0045,"F$DATTMP"},
+    {0x0046,"F$LDAXY"},
+    {0x0047,"F$LDAXYP"},
+    {0x0048,"F$LDDDXY"},
+    {0x0049,"F$LDABX"},
+    {0x004a,"F$STABX"},
+    {0x004b,"F$ALLPRC"},
+    {0x004c,"F$DELPRC"},
+    {0x004d,"F$ELINK"},
+    {0x004e,"F$FMODUL"},
+    {0x004f,"F$MAPBLK"},
+    {0x0050,"F$CLRBLK"},
+    {0x0051,"F$DELRAM"},
+    {0x0052,"F$GCMDIR"},
+    {0x0053,"F$ALHRAM"},
+    {0x0080    , "I$ATTACH"},
+    {0x0081, "I$DETACH"},
+    {0x0082  , "I$DUP"},
+    {0x0083  , "I$CREATE"},
+    {0x0084, "I$OPEN"},
+    {0x0085    , "I$MAKDIR"},
+    {0x0086    , "I$CHGDIR"},
+    {0x0087  , "I$DELETE"},
+    {0x0088, "I$SEEK"},
+    {0x0089  , "I$READ"},
+    {0x008a, "I$WRITE"},
+    {0x008b    , "I$READLN"},
+    {0x008c    , "I$WRITLN"},
+    {0x008d, "I$GETSTT"},
+    {0x008e    , "I$SSTT"},
+    {0x008f    , "I$CLOSE"},
+    {0x0090  , "I$DELETX"},
+  } ;
+
+
 int iotable[32] = {
 	0x0000,
 	0x0001,
@@ -1092,10 +1189,20 @@
 {
   int offset;
 
-  offset = prog[pc+2];
-
+  offset = prog[pc+1];
+  for(int i =0, j = sizeof(os9sys)/sizeof(struct os9syscall), m = (i+j)/2 ;i<=j; m=(i+j)/2  ) {
+     if (os9sys[m].code > offset) {
+         j=m-1; 
+     } else if (os9sys[m].code < offset) {
+         i=m+1; 
+     } else if (os9sys[m].code == offset) {
+          fprintf(fp,"%0.2X %0.2X       %s%s       %s",
+                code, offset, suffix, op->name, os9sys[m].name);
+          return op->bytes;
+     } 
+  } 
   fprintf(fp,"%0.2X %0.2X       %s%s       $%0.2X",
-	code, offset, suffix, op->name, prog[pc+2]);
+	code, offset, suffix, op->name, prog[pc+1]);
   return op->bytes;
 }
 
@@ -1280,14 +1387,14 @@
 		offset = (prog[pc+2]+pc+3) & 0xFFFF;
 		s = "<";
 		fprintf(fp,"%0.2X %0.2X %0.2X    %s%s       [%s$%0.2X,PCR]",
-				  code, postbyte, prog[pc+2], suffix, op->name, s, offset);
+				  code, postbyte, prog[pc+2], suffix, op->name, s, offset+pc+2+adoffset);
 		extrabytes = 1;
 		break;
 	 case 0x1d :
 		offset = (prog[pc+2] * 256 + prog[pc+3]+pc+4) & 0xFFFF;
 		s = ">";
 		fprintf(fp,"%0.2X %0.2X %0.2X %0.2X %s%s       [%s$%0.4X,PCR]",
-				  code, postbyte, prog[pc+2], prog[pc+3], suffix, op->name, s, offset);
+				  code, postbyte, prog[pc+2], prog[pc+3], suffix, op->name, s, offset+pc+3+adoffset);
 		extrabytes = 2;
 		break;
 	 case 0x1e :
--- a/v09.c	Mon Jul 02 02:12:31 2018 +0900
+++ b/v09.c	Mon Jul 02 19:07:39 2018 +0900
@@ -113,6 +113,7 @@
      tracing=1;attention=1;    
    } else if (strcmp(argv[i],"-rom")==0) {
      i++;
+     timer = 0;  // non standard rom image, don't start timer
      romfile = argv[i];
    } else if (strcmp(argv[i],"-tl")==0) {
      i++;
@@ -126,9 +127,9 @@
    } else if (strcmp(argv[i],"-l")==0) {
      i++;
      romstart=strtol(argv[i],(char**)0,0);
-   } else if (strcmp(argv[i],"-nt")==0) {
+   } else if (strcmp(argv[i],"-nt")==0) {  // start debugger at the start
      attention = escape = 1;
-     timer = 0;
+     timer = 0;   // no timer
    } else usage();
  }   
  #ifdef MSDOS