-
Notifications
You must be signed in to change notification settings - Fork 0
/
crd2asc.py
executable file
·122 lines (109 loc) · 1.36 KB
/
crd2asc.py
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
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/python
# Convert .crd to SIMH ASCII
import sys
co = """
] 11-0
@ 4-8
* 11-4-8
| 0-2-8
! 11-2-8
} 0-7-8
" 12-7-8
. 12-3-8
) 12-4-8
+ 12
$ 11-3-8
* 11-4-8
- 11
/ 0-1
, 0-3-8
( 0-4-8
= 3-8
A 12-1
B 12-2
C 12-3
D 12-4
E 12-5
F 12-6
G 12-7
H 12-8
I 12-9
J 11-1
K 11-2
L 11-3
M 11-4
N 11-5
O 11-6
P 11-7
Q 11-8
R 11-9
S 0-2
T 0-3
U 0-4
V 0-5
W 0-6
X 0-7
Y 0-8
Z 0-9
0 0
0 12-0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
"""
# bit value of each row of holes
crd = (
(0, 0x80),
(0, 0x40),
(0, 0x20),
(0, 0x10),
(0, 8),
(0, 4),
(0, 2),
(0, 1),
(0x80, 0),
(0x40, 0),
(0x20, 0),
(0x10, 0),
)
# number of each row on card
holes = 12, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
tab = []
for l in co.split("\n"):
x = l.strip()
if x == "": continue
char, h = x.split()
hh = h.split("-")
n1, n2 = 0, 0
for y in hh:
for q, z in enumerate(holes):
if z == int(y):
n1 += crd[q][0]
n2 += crd[q][1]
tab.append((char, n1, n2))
f = open(sys.argv[1], "rb")
n = 0
line = ""
while True:
r = " "
try:
ch = ord(f.read(1))
ch1 = ord(f.read(1))
except:
print(line.rstrip() + "\r")
sys.exit()
n += 1
if n > 80:
n = 1
print(line.rstrip() + "\r")
line = ""
for t in tab:
if ch == t[1] and ch1 == t[2]:
r = t[0]
line += r