From 12fdea5b21b1292214852c148dd2585e5381e1d3 Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Tue, 19 May 2015 00:56:40 +0200 Subject: [PATCH] Adapt the generating and dumping of object files to what is observed in RSX-11M+ files. Use conditional compilation so the RT-11 version can be restored. --- dumpobj.c | 19 ++++++++++++++++++- object.c | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/dumpobj.c b/dumpobj.c index 8399d6e..8b61551 100644 --- a/dumpobj.c +++ b/dumpobj.c @@ -64,6 +64,7 @@ char *readrec( chksum = 0; +#if RT11 while (c = fgetc(fp), c != EOF && c == 0) ; if (c == EOF) @@ -83,6 +84,7 @@ char *readrec( } chksum -= c; // even though for 0 the checksum isn't changed... +#endif /* RT11 */ c = fgetc(fp); if (c == EOF) { @@ -103,7 +105,9 @@ char *readrec( chksum -= c; +#if RT11 *len -= 4; // Subtract header and length bytes from length +#endif if (*len < 0) { fprintf(stderr, "Improperly formatted OBJ file (5)\n"); return NULL; @@ -125,15 +129,28 @@ char *readrec( for (i = 0; i < *len; i++) chksum -= (buf[i] & 0xff); +#if RT11 c = fgetc(fp); c &= 0xff; chksum &= 0xff; if (c != chksum) { free(buf); - fprintf(stderr, "Bad record checksum, " "calculated=%d, recorded=%d\n", chksum, c); + fprintf(stderr, "Bad record checksum, " "calculated=$%04x, recorded=$%04x\n", chksum, c); return NULL; } +#else + if (*len & 1) { + /* skip 1 byte of padding */ + c = fgetc(fp); + if (c == EOF) { + free(buf); + fprintf(stderr, "EOF where padding byte should be"); + return NULL; + } + + } +#endif /* RT11 */ return buf; } diff --git a/object.c b/object.c index b64dc26..4a29bb2 100644 --- a/object.c +++ b/object.c @@ -55,6 +55,10 @@ DAMAGE. Each is preceeded by any number of 0 bytes, begins with a 1,0 pair, followed by 2 byte length, followed by data, followed by 1 byte negative checksum. + + The RSX version is similar but subtly different: + There are no "any number of 0 bytes", nor the "1,0 pair" following it. + There is no checksum byte, but odd lengths are padded with a 0-byte. */ static int writerec( @@ -65,18 +69,24 @@ static int writerec( int chksum; /* Checksum is negative sum of all bytes including header and length */ int i; +#if RT11 unsigned hdrlen = len + 4; +#else + unsigned hdrlen = len; +#endif if (fp == NULL) return 1; /* Silently ignore this attempt to write. */ chksum = 0; +#if RT11 if (fputc(FBR_LEAD1, fp) == EOF) /* All recs begin with 1,0 */ return 0; chksum -= FBR_LEAD1; if (fputc(FBR_LEAD2, fp) == EOF) return 0; chksum -= FBR_LEAD2; +#endif /* RT11 */ i = hdrlen & 0xff; /* length, lsb */ chksum -= i; @@ -99,7 +109,13 @@ static int writerec( chksum &= 0xff; +#if RT11 fputc(chksum, fp); /* Followed by the checksum byte */ +#else /* RT11 */ + if (hdrlen & 1) { + fputc(0, fp); /* Padding to even boundary */ + } +#endif /* RT11 */ return 1; /* Worked okay. */ }