From: ceriel Date: Thu, 29 Jan 1987 15:54:46 +0000 (+0000) Subject: Changed to handle new ack object format X-Git-Tag: release-5-5~4877 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=59a08bb7335dc08c24469f0c0789c6bce3c8a46a;p=ack.git Changed to handle new ack object format --- diff --git a/mach/i80/dl/Makefile b/mach/i80/dl/Makefile index dd1f0da85..e922d0897 100644 --- a/mach/i80/dl/Makefile +++ b/mach/i80/dl/Makefile @@ -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 diff --git a/mach/i80/dl/mccpm.c b/mach/i80/dl/mccpm.c index d9bcb7417..44abdc99a 100644 --- a/mach/i80/dl/mccpm.c +++ b/mach/i80/dl/mccpm.c @@ -8,8 +8,8 @@ #define MAXBYTE 24 #include +#include 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) diff --git a/mach/i80/dl/nascom.c b/mach/i80/dl/nascom.c index 81cb90a01..adf044fb8 100644 --- a/mach/i80/dl/nascom.c +++ b/mach/i80/dl/nascom.c @@ -2,11 +2,13 @@ * Download Z80 load module into the NASCOM * * Johan Stevenson, Vrije Universiteit, Amsterdam + * Ceriel Jacobs, Vrije Universiteit, Amsterdam */ #include #include #include #include +#include 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); }