From 3197705f493ca75933a4d5bdeae9bda2e2dd040b Mon Sep 17 00:00:00 2001 From: aap Date: Tue, 31 Jan 2017 00:47:17 +0100 Subject: [PATCH] ld6: added RIM10B loader to RIM format --- tools/ld6.c | 45 +++++++++++++++++++++++++++++---------------- tools/pdp6common.c | 27 +++++++++++++++++++++++++++ tools/pdp6common.h | 3 +++ 3 files changed, 59 insertions(+), 16 deletions(-) diff --git a/tools/ld6.c b/tools/ld6.c index d989b66..9ebb390 100644 --- a/tools/ld6.c +++ b/tools/ld6.c @@ -414,7 +414,8 @@ saverim(const char *filename) fclose(out); } -/* Saves in RIM10 format. Only one block is written. +/* Saves in RIM10 format. Begins with the RIM10B loader, + * after that only one block is written. * IOWD count,origin * word * ... @@ -423,6 +424,23 @@ saverim(const char *filename) * ... * JRST start */ +word rim10b[] = { + 0777762000000, + 0710600000060, + 0541400000004, + 0710740000010, + 0254000000003, + 0710470000007, + 0256010000007, + 0256010000012, + 0364400000000, + 0312740000016, + 0270756000001, + 0331740000016, + 0254200000001, + 0253700000003, + 0254000000002, +}; void saverim10(const char *filename) { @@ -434,6 +452,10 @@ saverim10(const char *filename) out = mustopen(filename, "wb"); checksum = 0; + /* write RIM10B loader */ + for(i = 0; i < 017; i++) + writew(rim10b[i], out); + w = fw(-(locmax+1-locmin), locmin-1); writew(w, out); /* IOWD count,origin */ checksum += w; @@ -441,23 +463,14 @@ saverim10(const char *filename) writew(mem[i], out); checksum += mem[i]; } - writew(-checksum, out); + checksum &= 0777777777777; +// writew(-checksum, out); /* this was apparently wrong? */ + writew(checksum, out); writew(fw(0254000, start), out); /* JRST start */ fclose(out); } -void -writeww(word w, FILE *fp) -{ - unsigned char c; - putc((w >> 29) & 0177, fp); - putc((w >> 22) & 0177, fp); - putc((w >> 15) & 0177, fp); - putc((w >> 8) & 0177, fp); - putc((w>>1) & 0177 | (w & 1) << 7, fp); -} - /* Saves in SAV format. Only one block is saved. * IOWD count,origin * word @@ -472,10 +485,10 @@ savesav(const char *filename) FILE *out; hword i; out = mustopen(filename, "wb"); - writeww(fw(-(locmax+1-locmin), locmin-1), out); /* IOWD count,origin */ + writewbak(fw(-(locmax+1-locmin), locmin-1), out); /* IOWD count,origin */ for(i = locmin; i <= locmax; i++) - writeww(mem[i], out); - writeww(fw(0254000, start), out); /* JRST start */ + writewbak(mem[i], out); + writewbak(fw(0254000, start), out); /* JRST start */ fclose(out); } diff --git a/tools/pdp6common.c b/tools/pdp6common.c index 9c274c2..b7d697a 100644 --- a/tools/pdp6common.c +++ b/tools/pdp6common.c @@ -11,6 +11,7 @@ hword right(word w) { return w & 0777777; } word negw(word w) { return (~w + 1) & 0777777777777; } int isneg(word w) { return !!(w & 0400000000); } +/* write word in rim format */ void writew(word w, FILE *fp) { @@ -37,6 +38,32 @@ readw(FILE *fp) return w; } +/* write word in backup format. This is what pdp10-ka expects. */ +void +writewbak(word w, FILE *fp) +{ + unsigned char c; + putc((w >> 29) & 0177, fp); + putc((w >> 22) & 0177, fp); + putc((w >> 15) & 0177, fp); + putc((w >> 8) & 0177, fp); + putc((w>>1) & 0177 | (w & 1) << 7, fp); +} + +word +readwbak(FILE *fp) +{ + char buf[5]; + if(fread(buf, 1, 5, fp) != 5) + return ~0; + return (word)buf[0] << 29 | + (word)buf[1] << 22 | + (word)buf[2] << 15 | + (word)buf[3] << 8 | + ((word)buf[4]&0177) << 1 | + ((word)buf[4]&0200) >> 7; +} + /* decompose a double into sign, exponent and mantissa */ void decompdbl(double d, int *s, word *e, uint64_t *m) diff --git a/tools/pdp6common.h b/tools/pdp6common.h index d1ef412..ddda1c6 100644 --- a/tools/pdp6common.h +++ b/tools/pdp6common.h @@ -7,8 +7,11 @@ hword left(word w); hword right(word w); word negw(word w); int isneg(word w); + void writew(word w, FILE *fp); word readw(FILE *fp); +void writewbak(word w, FILE *fp); +word readwbak(FILE *fp); void decompdbl(double d, int *s, word *e, uint64_t *m); word dtopdp(double d);