// simple mag tape diagnostic // Author: David Holdsworth -- David.Holdsworth@bcs.org #include #include #include #include #ifndef O_BINARY #define O_BINARY 0 #endif #define LINEEND 0x5E #define BLOCKEND 0x7E #define NUMEND 0x7D char charval[256]; // declared before chapter0() char hexval[256]; // TEMP !!! or maybe not // Basic Quartet // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // ___________________________________________________ // 0 | Sp | // 1 | - | // 2 | & | // Control 3 | 0 | // Quartet 4 | 1 2 3 4 5 6 7 8 9 10 11 + : . p | // 5 | A B C D E F G H I = * ' ? ? ? | // 6 | J K L M N O P Q R ? % > < ? \ | // 7 | / S T U V W X Y Z ( ) , ; ? ? | // |_________________________________________________| void mkchars() // create the above conversion tables charval and hexval // same as in Translator // hexval may never get used { int i; memset(charval, 0, 255); memset(hexval, 0, 255); for ( i = 0; i<16; i++ ) { hexval[i] = i; hexval[i+'0'] = i; } for ( i = 0; i<6; i++ ) hexval[i+'A'] = i + 10; hexval['t'] = 10; // ten char charval['t'] = 0x4A; // ten char hexval['e'] = 11; // eleven char charval['e'] = 0x4B; // eleven char hexval['p'] = 15; // pound char charval['p'] = 0x4F; // pound char charval[' '] = 0; charval['-'] = 16; charval['&'] = 32; charval['0'] = 48; for ( i = 1; i<10; i++ ) { charval[i+'0'] = i + 0x40; charval[i+'A'-1] = i + 0x50; charval[i+'Q'] = i + 0x70; // must precede next line charval[i+'I'] = i + 0x60; } charval['/'] = 0x71; hexval['+'] = 12; charval['+'] = 0x4C; hexval[':'] = 13; charval[':'] = 0x4D; hexval['.'] = 14; charval['.'] = 0x4E; hexval['p'] = 15; charval['p'&255] = 0x4F; // pound char charval['='] = 0x5A; charval['*'] = 0x5B; charval['\''] = 0x5C; charval['?'] = 0x5D; charval['%'] = 0x6B; charval['>'] = 0x6C; charval['<'] = 0x6D; charval['\\'] = 0x6F; charval['h'] = 0x6E; // h = half charval['('] = 0x7A; charval[')'] = 0x7B; charval[','] = 0x7C; charval[';'] = 0x7D; charval['\n'] = LINEEND; } char alpha[256]; // convert Leo octet to ASCII char void mkalpha() // make the inverse tables converting Leo III code to ASCII { int i; memset(alpha, '!', 256); // excalmation mark is not in the Leo char set for ( i = 0; i<128; i++ ) if ( charval[i] > 0 ) { alpha[charval[i]] = i; alpha[charval[i]&0x3F] = i; // create the alpha sextets } alpha[0x4F] = 'p'; alpha[LINEEND] = 'c'; // avoid unwanted newlines alpha[BLOCKEND] = '#'; alpha[0xF] = 'p'; alpha[LINEEND&077] = 'c'; alpha[BLOCKEND&077] = '#'; alpha[0] = ' '; } char *tostr(int ms, int ls) // convert a long word of alpha to a string { static unsigned char res[8]; int i, w; ms &= 0xFFFFF; // ignore sign for ( i = 0; i<5; i++ ) { res[i] = alpha[ms>>12]; ms = ((ms<<8) | (ls>>12)) & 0xFFFFF; ls = (ls<<8) & 0xFFFFF; } res[5] = 0; return res; } int verbosity = 1; // diagnostic parameters int buff[10000]; main(int argc, char **argv) { int dv; int n, i, j, k, nl, w; int bc = 0; char *s; int icols = 0; // no of columns when printing instructions FILE *diag = stdout; if ( argc < 2 ) { fprintf(stderr, "Usage %s leo_MT [output_file]\n", *argv); exit(1); } i = 0; // index along params while ( ++i < argc && *(s = argv[i]) == '-' ) if ( *++s == 'i' ) icols = atoi(s+1); dv = open(argv[i], O_RDONLY + O_BINARY); if ( dv < 0 ) { perror(argv[i]); exit(1); } if ( argc >= i+2) diag = fopen(argv[++i], "w"); if ( diag == NULL ) { perror(argv[i]); exit(1); } fprintf(diag, "File: %s\n", argv[i-1]); mkchars(); mkalpha(); while ( (n = read(dv, buff, sizeof(int))) > 0 ) { n = buff[0] & 0x7FF; // 11-bit count fprintf(diag, "\nBlock %d, size = %d (prev = %d)", ++bc, n, buff[0]>>11); i = read(dv, buff, n * sizeof(int)); if ( icols == 0 ) // do not print instruction format { for ( i = 0; i>8)&0xF00) | ((w>>4)&0xF0) | (w&0xF); w |= (buff[i+1]<<8) & 0x3F0F000; if ( (w&0x3000000) != 0x1000000 ) // not -ve w &= 0xFFFFFF; w = ((w>>4)&0x1F0000) | (w&0xFFFF); buff[i/2] = w; } n = n/2; } nl = (n+icols-1) / icols; for ( i = 0; i>16, (w>>15)&1, (w>>13)&3, w&0x1FFF); s = " "; } } fprintf(diag, "\n"); } } close(dv); exit(0); for ( i = 0; i<54; i++ ) { fprintf(diag, " %06X", buff[i]); if ( i%5 == 0 ) fprintf(diag, "\n%2d", i); fprintf(diag, " %06X", buff[i]); } fprintf(diag, "\n"); }