-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto_simh.c
111 lines (98 loc) · 3.94 KB
/
to_simh.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* Read a "tape" in the format written by Van Snyder's autocoder, and
write it in the format Supnik's simh 1401 simulator
(simh.trailing-edge.com) expects.
In Snyder's format, records are ASCII. Each record begins with a
three-digit total-record length, which includes word marks, followed
by a three-digit data-only length, which would be the length if a
word mark were represented by a bit in each character, followed by the
data. Word marks are represented by =, and apply to the next
character, as on 1401 tapes. The mapping from ASCII to BCD is given
by the array ascii_to_bcd.
simh wants records on "tapes" to be represented by a 32-bit little-
endian count before and after the record. The characters are
represented in the low-order six bits of each byte, in BCD, with no
parity. A word mark is represented by a word mark character before
the data character, just like on 1401 tapes. The number of
characters in each record has to be even, even if the count is odd.
simh ignores the extra character.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ( argc, argv )
int argc;
char **argv;
{
char line[168];
unsigned int i, n1, n2;
unsigned char k;
FILE *fi, *fo;
/* ASCII to BCD conversion -- From simh's i1401_dat.h */
const char ascii_to_bcd_old[128] = { /* Traditional SimH */
000, 000, 000, 000, 000, 000, 000, 000, /* 000 - 037 */
000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000,
000, 052, 077, 013, 053, 034, 060, 032, /* 040 - 077 */
017, 074, 054, 037, 033, 040, 073, 021,
012, 001, 002, 003, 004, 005, 006, 007,
010, 011, 015, 056, 076, 035, 016, 072,
014, 061, 062, 063, 064, 065, 066, 067, /* 100 - 137 */
070, 071, 041, 042, 043, 044, 045, 046,
047, 050, 051, 022, 023, 024, 025, 026,
027, 030, 031, 075, 036, 055, 020, 057,
000, 061, 062, 063, 064, 065, 066, 067, /* 140 - 177 */
070, 071, 041, 042, 043, 044, 045, 046,
047, 050, 051, 022, 023, 024, 025, 026,
027, 030, 031, 000, 000, 000, 000, 000 };
const char ascii_to_bcd[128] = { /* Pierce A and H */
000, 000, 000, 000, 000, 000, 000, 000, /* 000 - 037 */
000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000,
000, 000, 000, 000, 000, 000, 000, 000,
000, 052, 037, 013, 053, 034, 060, 014, /* 040 - 077 */
034, 074, 054, 060, 033, 040, 073, 021,
012, 001, 002, 003, 004, 005, 006, 007,
010, 011, 015, 056, 076, 013, 016, 072,
014, 061, 062, 063, 064, 065, 066, 067, /* 100 - 137 */
070, 071, 041, 042, 043, 044, 045, 046,
047, 050, 051, 022, 023, 024, 025, 026,
027, 030, 031, 075, 036, 055, 020, 057,
000, 061, 062, 063, 064, 065, 066, 067, /* 140 - 177 */
070, 071, 041, 042, 043, 044, 045, 046,
047, 050, 051, 022, 023, 024, 025, 026,
027, 030, 031, 017, 032, 077, 035, 000
};
if ( argc != 3 ) /* arg 0 is command name */
{ printf ( "The number of command-line arguments must be exactly 2.\n" );
printf ( "The first is the input file, the second is the output file.\n" );
exit ( 1 );
}
if ( ( fi = fopen ( argv[1], "r" ) ) == NULL )
{ perror ( argv[1] );
exit ( 2 );
}
if ( ( fo = fopen ( argv[2], "wb" ) ) == NULL )
{ perror ( argv[2] );
exit ( 3 );
}
while ( fgets ( line, 168, fi ) != NULL )
{ n1 = strlen(line);
n2 = n1;
for ( i=0; i<4; i++ ) /* Output the count, little-endian */
{ k = n2 % 256; n2 = n2 / 256;
fputc ( k, fo );
}
for ( i=0; i<n1; i++ ) fputc ( ascii_to_bcd[line[i]], fo );
if ( n1 % 2 ) fputc ( (char)0, fo ); /* simh want's even-length records */
n2 = n1;
for ( i=0; i<4; i++ ) /* Output the count, little-endian */
{ k = n2 % 256; n2 = n2 / 256;
fputc ( k, fo );
}
}
k = 0;
for ( i=0; i<4; i++ ) fputc ( k, fo ); /* Output simh's EOF */
fclose ( fi );
fclose ( fo );
}