Changed to handle new ack object format
authorceriel <none@none>
Thu, 29 Jan 1987 15:54:46 +0000 (15:54 +0000)
committerceriel <none@none>
Thu, 29 Jan 1987 15:54:46 +0000 (15:54 +0000)
mach/i80/dl/Makefile
mach/i80/dl/mccpm.c
mach/i80/dl/nascom.c

index dd1f0da..e922d08 100644 (file)
@@ -1,16 +1,22 @@
+EMHOME=../../..
+OBJLIB=$(EMHOME)/modules/lib/libobject.a
+
 head:  mccpm nascom
 
 mccpm: mccpm.c
-       cc -o mccpm mccpm.c
+       $(CC) -o mccpm mccpm.c $(OBJLIB)
 
 nascom:        nascom.c
-       cc -o nascom nascom.c
+       $(CC) -o nascom nascom.c $(OBJLIB)
 
-install:
+install:       head
        @echo Nothing is installed
 
+cmp:   head
+       @echo Nothing is compared
+
 clean:
-       rm nascom mccpm
+       rm -f *.o
 
 pr:
        @pr `pwd`/Makefile `pwd`/mccpm.c `pwd`/nascom.c
index d9bcb74..44abdc9 100644 (file)
@@ -8,8 +8,8 @@
 
 #define MAXBYTE        24
 #include <stdio.h>
+#include <out.h>
 char hex[] =  "0123456789ABCDEF";
-FILE *fp, *fopen();
 char **s;
 int bytes, bytcnt, checksum;
 unsigned pc;
@@ -27,57 +27,70 @@ char *argv[];
        if (argc == 3)
                if (!(offset = htou(argv[2])))
                        fatal ("adres error %s\n", argv[2]);
-       if ((fp = fopen (*++argv,"r")) == NULL)
-               fatal ("can't open %s\n",*argv);
+       if (! rd_open(*++argv)) fatal ("can't open %s\n",*argv);
        else    {
                s = argv;
                convert ();
-               fclose (fp);
                }
        }
 
 convert ()
        {
-       int c;
-       do
-               {
-               pc = getword ();
-               pc -= offset;
-               bytes = getword ();
-               bytes = getword ();
-               while (bytes != 0) 
-                       {
-                       bytcnt = (bytes < MAXBYTE) ? bytes : MAXBYTE;
-                       bytes -= bytcnt;
-                       checksum = 0;
-                       Irecord ();
+       struct outhead head;
+       struct outsect sect[MAXSECT];
+       int i;
+
+       rd_ohead(&head);
+       rd_sect(sect, head.oh_nsect);
+       for (i = 0; i < head.oh_nsect; i++) {
+               rd_outsect(i);
+               pc = sect[i].os_base - offset;
+               while (sect[i].os_size) {
+                       unsigned int sz = 8096, fl;
+                       extern char *calloc();
+                       register char *buf;
+                       char *pbuf;
+
+                       if (sz > sect[i].os_size) sz = sect[i].os_size;
+                       sect[i].os_size -= sz;
+                       pbuf = buf = calloc(sz, 1);
+                       if (fl = sect[i].os_flen) {
+                               if (fl > sz) fl = sz;
+                               sect[i].os_flen -= fl;
+
+                               rd_emit(buf, (long) fl);
+                       }
+                       while (sz >= MAXBYTE) {
+                               data(MAXBYTE, (int) pc, buf);
+                               checksum = 0;
+                               sz -= MAXBYTE;
+                               buf += MAXBYTE;
+                               pc += MAXBYTE;
                        }
-               c = getc (fp);
-               ungetc (c, fp);
+                       if (sz > 0) {
+                               data(sz, (int) pc, buf);
+                               checksum = 0;
+                       }
+                       free(pbuf);
                }
-       while (c != EOF);
+       }
        printf (":00000001FF\n");
        }
 
 
-Irecord ()
-       {
+data (sz, pc, buf)
+       register char *buf;
+{
        printf (":");
-       outbyte (bytcnt);
+       outbyte (sz);
        bytcnt += 4;
        outbyte (pc >> 8);
        outbyte (pc);
        outbyte (0);
-       record ();
-       }
-
-
-record ()
-       {
-       while (bytcnt != 0) 
+       while (sz != 0) 
                {
-               outbyte (getbyte ());
-               pc ++;
+               outbyte (*buf++);
+               sz--;
                }
        outbyte (-checksum);
        putchar ('\n');
@@ -91,28 +104,18 @@ int b;
        checksum = (checksum + b) & 0xFF;
        putchar (hex[(b>>4) & 0xF]);
        putchar  (hex[b & 0xF]);
-       -- bytcnt;
-       }
-
-getword ()
-       {
-       int c;
-       c = getbyte ();
-       return ((getbyte () << 8) | c );
        }
 
-getbyte ()
-       {
-       int c;
-       if ((c = getc (fp)) == EOF) fatal ("end of %s\n",*s);
-       return (c);
-       }
 fatal (s,a)
        {
        printf (s,a);
        exit (-1);
        }
 
+rd_fatal()
+{
+       fatal("Read error\n");
+}
 /* convert a string of hex digits to an unsigned 16 bit number */
 
 unsigned htou(t)
index 81cb90a..adf044f 100644 (file)
@@ -2,11 +2,13 @@
  * Download Z80 load module into the NASCOM
  *
  * Johan Stevenson, Vrije Universiteit, Amsterdam
+ * Ceriel Jacobs, Vrije Universiteit, Amsterdam
  */
 #include       <stdio.h>
 #include       <assert.h>
 #include       <sgtty.h>
 #include       <signal.h>
+#include       <out.h>
 
 int    check;
 int    nascom = 1;
@@ -16,10 +18,15 @@ int disp = 0;
 
 char   hex[] = "0123456789ABCDEF";
 
+char *progname;
+
 struct sgttyb  ttynormal;
 struct sgttyb  ttyraw;
 int            rawmode = 0;
 
+struct outhead ohead;
+struct outsect sect[MAXSECT];
+
 stop(code) {
        if (rawmode)
                stty(1, &ttynormal);
@@ -27,9 +34,12 @@ stop(code) {
 }
 
 main(argc,argv) char **argv; {
-       register unsigned nd,pc;
+       register unsigned nd;
+       long pc;
        register char *s;
+       int i;
 
+       progname = argv[0];
        while (argc > 1 && argv[1][0] == '-') {
                switch (argv[1][1]) {
                case 'u':
@@ -56,7 +66,7 @@ main(argc,argv) char **argv; {
                fprintf(stderr,"usage: %s [flags] [object file]\n",argv[0]);
                stop(-1);
        }
-       if (freopen(s,"r",stdin) == NULL) {
+       if (! rd_open(s)) {
                fprintf(stderr,"%s: can't open %s\n",argv[0],s);
                stop(-1);
        }
@@ -77,24 +87,37 @@ main(argc,argv) char **argv; {
                stty(1, &ttyraw);
                sleep(5);
        }
-       for (;;) {
-               pc = get2c(stdin);
-               if (feof(stdin))
-                       break;
-               nd = get2c(stdin);
-               nd = get2c(stdin);
-               if (nd > 256) {
-                       fprintf(stderr,"bad format on %s\n",s);
-                       stop(1);
-               }
-               while (nd > 8) {
-                       data(8,pc);
-                       nd -= 8;
-                       pc += 8;
+       rd_ohead(&ohead);
+       rd_sect(sect, ohead.oh_nsect);
+       for (i = 0; i < ohead.oh_nsect; i++) {
+               rd_outsect(i);
+               pc = sect[i].os_base;
+               while (sect[i].os_size) {
+                       unsigned int sz = 8096, fl;
+                       extern char *calloc();
+                       register char *buf;
+                       char *pbuf;
+
+                       if (sz > sect[i].os_size) sz = sect[i].os_size;
+                       sect[i].os_size -= sz;
+                       pbuf = buf = calloc(sz, 1);
+                       if (fl = sect[i].os_flen) {
+                               if (fl > sz) fl = sz;
+                               sect[i].os_flen -= fl;
+
+                               rd_emit(buf, (long) fl);
+                       }
+                       while (sz >= 8) {
+                               data(8, (int) pc, buf);
+                               sz -= 8;
+                               buf += 8;
+                               pc += 8;
+                       }
+                       if (sz > 0) {
+                               data(sz, (int) pc, buf);
+                       }
+                       free(pbuf);
                }
-               if (nd > 0)
-                       data(nd,pc);
-               assert(feof(stdin) == 0);
        }
        putchar('.');
        putchar(nl);
@@ -103,7 +126,10 @@ main(argc,argv) char **argv; {
        stop(0);
 }
 
-data(nd,pc) {
+data(nd,pc,buf)
+       register char *buf;
+       int pc;
+{
        register i;
 
        check = 0;
@@ -112,7 +138,7 @@ data(nd,pc) {
        byte(pc);
        for (i = 0; i < nd; i++) {
                putchar(' ');
-               byte(getc(stdin));
+               byte(*buf++);
        }
        while (i < 8) {
                putchar(' ');
@@ -131,9 +157,8 @@ byte(b) {
        putchar(hex[b & 017]);
 }
 
-get2c(f) FILE *f; {
-       register c;
-
-       c = getc(f);
-       return((getc(f) << 8) | c);
+rd_fatal()
+{
+       fprintf(stderr, "%s: Read error\n", progname);
+       stop(-1);
 }