894d7aea160ad63cd7235a7dab75845c2aaf305e
1 /* Simple program to display a binary card-image file in ASCII.
2 * We assume the deck was written with one card per 16-bit word, left-justified,
3 * and written in PC little-endian order
5 * (C) Copyright 2002, Brian Knittel.
6 * You may freely use this program, but: it offered strictly on an AS-IS, AT YOUR OWN
7 * RISK basis, there is no warranty of fitness for any purpose, and the rest of the
8 * usual yada-yada. Please keep this notice and the copyright in any distributions
11 * This is not a supported product, but I welcome bug reports and fixes.
12 * Mail to sim@ibm1130.org
23 int hollerith_to_ascii (unsigned short h
);
24 void bail (char *msg
);
25 void format_coldstart (unsigned short *buf
);
27 int main (int argc
, char **argv
)
30 char *fname
= NULL
, line
[82], *arg
;
31 BOOL coldstart
= FALSE
;
32 unsigned short buf
[80];
34 static char usestr
[] =
35 "Usage: viewdeck [-c] deckfile\n"
37 "-c: convert cold start card to 16-bit format as a C array initializer\n";
39 for (i
= 1; i
< argc
; i
++) { // process command line arguments
54 else if (fname
== NULL
) // first non-switch arg is file name
57 bail(usestr
); // there can be only one name
60 if (fname
== NULL
) // there must be a name
63 if ((fd
= fopen(fname
, "rb")) == NULL
) {
68 while (fxread(buf
, sizeof(short), 80, fd
) == 80) {
70 format_coldstart(buf
);
75 for (i
= 0; i
< 80; i
++) {
76 line
[i
] = hollerith_to_ascii(buf
[i
]);
80 line
[++lastnb
] = '\n';
81 line
[++lastnb
] = '\0';
86 if (fxread(buf
, sizeof(short), 1, fd
) == 1)
87 bail("Coldstart deck has more than one card");
95 void format_coldstart (unsigned short *buf
)
100 for (i
= 0; i
< 80; i
++) {
101 word
= buf
[i
]; // expand 12-bit card data to 16-bit instruction
102 word
= (word
& 0xF800) | ((word
& 0x0400) ? 0x00C0 : 0x0000) | ((word
& 0x03F0) >> 4);
105 fputs(",\n", stdout
);
111 printf("0x%04x", word
);
119 unsigned short hollerith
;
123 static CPCODE cardcode_029
[] =
126 0x8000, '&', // + in 026 Fortran
166 0x0420, '#', // = in 026 Fortran
167 0x0220, '@', // ' in 026 Fortran
171 0x8820, '\xA2', // cent, in MS-DOS encoding
173 0x8220, '<', // ) in 026 Fortran
182 0x4060, '\xAC', // not, in MS-DOS encoding
184 0x2220, '%', // ( in 026 Fortran
212 0x6010, 'z', // these odd punch codes are used by APL:
213 0x1010, '\001', // no corresponding ASCII using ^A
214 0x0810, '\002', // SYN using ^B
215 0x0410, '\003', // no corresponding ASCII using ^C
216 0x0210, '\004', // PUNCH ON using ^D
217 0x0110, '\005', // READER STOP using ^E
218 0x0090, '\006', // UPPER CASE using ^F
219 0x0050, '\013', // EOT using ^K
220 0x0030, '\016', // no corresponding ASCII using ^N
221 0x1030, '\017', // no corresponding ASCII using ^O
222 0x0830, '\020', // no corresponding ASCII using ^P
225 int hollerith_to_ascii (unsigned short h
)
231 for (i
= 0; i
< sizeof(cardcode_029
) / sizeof(CPCODE
); i
++)
232 if (cardcode_029
[i
].hollerith
== h
)
233 return cardcode_029
[i
].ascii
;
238 void bail (char *msg
)
240 fprintf(stderr
, "%s\n", msg
);