Changed to handle new ack object format

This commit is contained in:
ceriel 1987-01-29 15:54:46 +00:00
parent c9fce4aff9
commit 59a08bb733
3 changed files with 110 additions and 76 deletions

View file

@ -1,16 +1,22 @@
EMHOME=../../..
OBJLIB=$(EMHOME)/modules/lib/libobject.a
head: mccpm nascom head: mccpm nascom
mccpm: mccpm.c mccpm: mccpm.c
cc -o mccpm mccpm.c $(CC) -o mccpm mccpm.c $(OBJLIB)
nascom: nascom.c nascom: nascom.c
cc -o nascom nascom.c $(CC) -o nascom nascom.c $(OBJLIB)
install: install: head
@echo Nothing is installed @echo Nothing is installed
cmp: head
@echo Nothing is compared
clean: clean:
rm nascom mccpm rm -f *.o
pr: pr:
@pr `pwd`/Makefile `pwd`/mccpm.c `pwd`/nascom.c @pr `pwd`/Makefile `pwd`/mccpm.c `pwd`/nascom.c

View file

@ -8,8 +8,8 @@
#define MAXBYTE 24 #define MAXBYTE 24
#include <stdio.h> #include <stdio.h>
#include <out.h>
char hex[] = "0123456789ABCDEF"; char hex[] = "0123456789ABCDEF";
FILE *fp, *fopen();
char **s; char **s;
int bytes, bytcnt, checksum; int bytes, bytcnt, checksum;
unsigned pc; unsigned pc;
@ -27,57 +27,70 @@ char *argv[];
if (argc == 3) if (argc == 3)
if (!(offset = htou(argv[2]))) if (!(offset = htou(argv[2])))
fatal ("adres error %s\n", argv[2]); fatal ("adres error %s\n", argv[2]);
if ((fp = fopen (*++argv,"r")) == NULL) if (! rd_open(*++argv)) fatal ("can't open %s\n",*argv);
fatal ("can't open %s\n",*argv);
else { else {
s = argv; s = argv;
convert (); convert ();
fclose (fp);
} }
} }
convert () convert ()
{ {
int c; struct outhead head;
do struct outsect sect[MAXSECT];
{ int i;
pc = getword ();
pc -= offset; rd_ohead(&head);
bytes = getword (); rd_sect(sect, head.oh_nsect);
bytes = getword (); for (i = 0; i < head.oh_nsect; i++) {
while (bytes != 0) rd_outsect(i);
{ pc = sect[i].os_base - offset;
bytcnt = (bytes < MAXBYTE) ? bytes : MAXBYTE; while (sect[i].os_size) {
bytes -= bytcnt; unsigned int sz = 8096, fl;
checksum = 0; extern char *calloc();
Irecord (); 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);
} }
c = getc (fp); while (sz >= MAXBYTE) {
ungetc (c, fp); data(MAXBYTE, (int) pc, buf);
checksum = 0;
sz -= MAXBYTE;
buf += MAXBYTE;
pc += MAXBYTE;
}
if (sz > 0) {
data(sz, (int) pc, buf);
checksum = 0;
}
free(pbuf);
} }
while (c != EOF); }
printf (":00000001FF\n"); printf (":00000001FF\n");
} }
Irecord () data (sz, pc, buf)
{ register char *buf;
{
printf (":"); printf (":");
outbyte (bytcnt); outbyte (sz);
bytcnt += 4; bytcnt += 4;
outbyte (pc >> 8); outbyte (pc >> 8);
outbyte (pc); outbyte (pc);
outbyte (0); outbyte (0);
record (); while (sz != 0)
}
record ()
{
while (bytcnt != 0)
{ {
outbyte (getbyte ()); outbyte (*buf++);
pc ++; sz--;
} }
outbyte (-checksum); outbyte (-checksum);
putchar ('\n'); putchar ('\n');
@ -91,28 +104,18 @@ int b;
checksum = (checksum + b) & 0xFF; checksum = (checksum + b) & 0xFF;
putchar (hex[(b>>4) & 0xF]); putchar (hex[(b>>4) & 0xF]);
putchar (hex[b & 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) fatal (s,a)
{ {
printf (s,a); printf (s,a);
exit (-1); exit (-1);
} }
rd_fatal()
{
fatal("Read error\n");
}
/* convert a string of hex digits to an unsigned 16 bit number */ /* convert a string of hex digits to an unsigned 16 bit number */
unsigned htou(t) unsigned htou(t)

View file

@ -2,11 +2,13 @@
* Download Z80 load module into the NASCOM * Download Z80 load module into the NASCOM
* *
* Johan Stevenson, Vrije Universiteit, Amsterdam * Johan Stevenson, Vrije Universiteit, Amsterdam
* Ceriel Jacobs, Vrije Universiteit, Amsterdam
*/ */
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include <sgtty.h> #include <sgtty.h>
#include <signal.h> #include <signal.h>
#include <out.h>
int check; int check;
int nascom = 1; int nascom = 1;
@ -16,10 +18,15 @@ int disp = 0;
char hex[] = "0123456789ABCDEF"; char hex[] = "0123456789ABCDEF";
char *progname;
struct sgttyb ttynormal; struct sgttyb ttynormal;
struct sgttyb ttyraw; struct sgttyb ttyraw;
int rawmode = 0; int rawmode = 0;
struct outhead ohead;
struct outsect sect[MAXSECT];
stop(code) { stop(code) {
if (rawmode) if (rawmode)
stty(1, &ttynormal); stty(1, &ttynormal);
@ -27,9 +34,12 @@ stop(code) {
} }
main(argc,argv) char **argv; { main(argc,argv) char **argv; {
register unsigned nd,pc; register unsigned nd;
long pc;
register char *s; register char *s;
int i;
progname = argv[0];
while (argc > 1 && argv[1][0] == '-') { while (argc > 1 && argv[1][0] == '-') {
switch (argv[1][1]) { switch (argv[1][1]) {
case 'u': case 'u':
@ -56,7 +66,7 @@ main(argc,argv) char **argv; {
fprintf(stderr,"usage: %s [flags] [object file]\n",argv[0]); fprintf(stderr,"usage: %s [flags] [object file]\n",argv[0]);
stop(-1); stop(-1);
} }
if (freopen(s,"r",stdin) == NULL) { if (! rd_open(s)) {
fprintf(stderr,"%s: can't open %s\n",argv[0],s); fprintf(stderr,"%s: can't open %s\n",argv[0],s);
stop(-1); stop(-1);
} }
@ -77,24 +87,37 @@ main(argc,argv) char **argv; {
stty(1, &ttyraw); stty(1, &ttyraw);
sleep(5); sleep(5);
} }
for (;;) { rd_ohead(&ohead);
pc = get2c(stdin); rd_sect(sect, ohead.oh_nsect);
if (feof(stdin)) for (i = 0; i < ohead.oh_nsect; i++) {
break; rd_outsect(i);
nd = get2c(stdin); pc = sect[i].os_base;
nd = get2c(stdin); while (sect[i].os_size) {
if (nd > 256) { unsigned int sz = 8096, fl;
fprintf(stderr,"bad format on %s\n",s); extern char *calloc();
stop(1); 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);
} }
while (nd > 8) {
data(8,pc);
nd -= 8;
pc += 8;
}
if (nd > 0)
data(nd,pc);
assert(feof(stdin) == 0);
} }
putchar('.'); putchar('.');
putchar(nl); putchar(nl);
@ -103,7 +126,10 @@ main(argc,argv) char **argv; {
stop(0); stop(0);
} }
data(nd,pc) { data(nd,pc,buf)
register char *buf;
int pc;
{
register i; register i;
check = 0; check = 0;
@ -112,7 +138,7 @@ data(nd,pc) {
byte(pc); byte(pc);
for (i = 0; i < nd; i++) { for (i = 0; i < nd; i++) {
putchar(' '); putchar(' ');
byte(getc(stdin)); byte(*buf++);
} }
while (i < 8) { while (i < 8) {
putchar(' '); putchar(' ');
@ -131,9 +157,8 @@ byte(b) {
putchar(hex[b & 017]); putchar(hex[b & 017]);
} }
get2c(f) FILE *f; { rd_fatal()
register c; {
fprintf(stderr, "%s: Read error\n", progname);
c = getc(f); stop(-1);
return((getc(f) << 8) | c);
} }