Updated custom_bitstream tool to generate correct checksums for SIMH loader.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Mon, 28 Dec 2020 06:57:11 +0000 (22:57 -0800)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Mon, 28 Dec 2020 06:57:11 +0000 (22:57 -0800)
custom_bitstream.c

index 144a5ac..680aa21 100644 (file)
 #include <stdlib.h>
 #include <stdint.h>
 
 #include <stdlib.h>
 #include <stdint.h>
 
-#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+");
 
     FILE * fp;
     fp = fopen("testimg.pdp11","w+");
-    fwrite(packet,(2*NUMWORDS)+16,1,fp);
+    fwrite(block,(2*(NUMWORDS+8)),1,fp);
     fclose(fp);
 }
     fclose(fp);
 }