From a4ee126bbe8e543f2f7a27f304e8b30f4ba26522 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Sun, 27 Dec 2020 22:57:11 -0800 Subject: [PATCH] Updated custom_bitstream tool to generate correct checksums for SIMH loader. --- custom_bitstream.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/custom_bitstream.c b/custom_bitstream.c index 144a5ac..680aa21 100644 --- a/custom_bitstream.c +++ b/custom_bitstream.c @@ -13,31 +13,39 @@ #include #include -#define NUMWORDS 20000 +#define NUMWORDS 02000 -void main( int argc, char ** argv ) { - uint16_t * packet = malloc((2*NUMWORDS) + 16); +int +main(int argc, char ** argv) { + uint16_t * block = malloc(2 * (NUMWORDS + 8)); /* - * +16 comes from: - * 3 for start of first packet header - * 1 for first checksum plus padding byte - * 4 for second packet header + checksum on empty packet - * Then double because PDP-11 word is 2 byte. + * +8 comes from: + * 3 for start of first block header + * 1 for first block checksum plus padding byte + * 4 for second block header + checksum on empty block */ - packet[0] = 1; /* Standard header */ - packet[1] = (2*NUMWORDS) + 6; /* Size of packet, including header but excluding checksum */ - packet[2] = 01000; /* Address to load packet */ - packet[NUMWORDS+3] = 0; /* Empty checksum. SIMH complains but still loads the image. */ - packet[NUMWORDS+4] = 1; /* Start of next packet, standard header */ - packet[NUMWORDS+5] = 6; /* Size of packet (just the header since blank body */ - packet[NUMWORDS+6] = 01000; /* Blank body means start execution at this address */ - packet[NUMWORDS+7] = 0; /* Empty checksum. SIMH complains but still loads the image. */ + block[0] = 1; /* Standard header start mark */ + block[1] = (2 * NUMWORDS) + 6; /* Size of block, including header but excluding checksum */ + block[2] = 01000; /* Address to load block */ + block[NUMWORDS+4] = 1; /* Start of end-of-tape block mark */ + block[NUMWORDS+5] = 6; /* Size of block (just the header since blank body */ + block[NUMWORDS+6] = 01000; /* Blank body means start execution at this address */ + block[NUMWORDS+7] = 0; /* Empty checksum */ - uint16_t i; - for(i=0; i < NUMWORDS; i++) packet[i+3] = i; /* Start at 0 so first instruction halts machine */ + for(uint16_t i = 0; i < NUMWORDS; i++) { + block[i + 3] = i; /* Start at 0 so first instruction halts machine */ + } + + uint32_t checksum = 0; + for(int i = 0; i < NUMWORDS+3; i++) { + checksum += block[i] & 0xff; + checksum += (block[i] >> 8) & 0xff; + } + checksum = (~checksum) + 1; + block[NUMWORDS+3] = checksum & 0xff; /* Checksum for first block */ FILE * fp; fp = fopen("testimg.pdp11","w+"); - fwrite(packet,(2*NUMWORDS)+16,1,fp); + fwrite(block,(2*(NUMWORDS+8)),1,fp); fclose(fp); } -- 2.20.1