-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat.py
132 lines (100 loc) · 2.97 KB
/
format.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
122
123
124
125
126
127
128
129
130
131
132
global_label = 1
def next_label(prefix):
global global_label
label = global_label
global_label += 1
lbl = ''
while label != 0:
lbl += 'abcdefghijklmnopqrstuvwxyz'[label % 26]
label = label // 26
return prefix + '_' + lbl
class Loop:
def __init__(self, var, start, end, dbg=''):
"""
This loop construct always clobbers the 'a' register during comparison.
:param var: which register to use for the loop counter
:param start: start value
:param end: end value (exclusive)
:param dbg:
"""
self.var = var
self.start = start
self.end = end
self.dbg = dbg
self.loop_label = None
def __enter__(self):
self.loop_label = next_label('loop')
print('\tmvi {}, {}'.format(self.var, self.start))
if self.dbg:
print('{}_begin: ; {} <= {} < {} - {}'.format(self.loop_label, self.start, self.var, self.end, self.dbg))
else:
print('{}_begin: ; {} <= {} < {}'.format(self.loop_label, self.start, self.var, self.end))
print('\tmvi a, {}'.format(self.end))
print('\tcmp {}'.format(self.var))
print('\tjz {}_end'.format(self.loop_label))
def __exit__(self, exc_type, exc_val, exc_tb):
print('\tinr {}'.format(self.var))
print('\tjmp {}_begin'.format(self.loop_label))
print('{}_end:'.format(self.loop_label))
def out(data):
print('\tin DWAIT')
if type(data) == str:
print('\tmov a, {}'.format(data))
else:
print('\tmvi a, {}'.format(data))
print('\tout DDATA')
print('''
;;
;; Autogenerated by format.py
;;
DWAIT .equ 0fch
DCOM .equ 0f8h
DDATA .equ 0fbh
DSTAT .equ 0f8h
DSECT .equ 0fah
''')
with Loop('d', 0, 0x4d, 'Track Counter'):
print('\tmvi a, 0xf4')
print('\tout DCOM')
with Loop('b', 0, 46):
out(0x00)
out(0xfc)
with Loop('b', 0, 26):
out(0x00)
with Loop('b', 1, 27, 'Segment Counter'):
with Loop('c', 0, 6):
out(0x00)
out(0xfe)
out('d') # track number
out(0)
out('b') # segment number
out(0)
out(0xF7)
with Loop('c', 0, 17):
out(0x00)
out(0xFB)
# Init Sector Data, 0xE5 is IBM standard.
with Loop('c', 0, 128):
out(0xE5)
out(0xF7)
with Loop('c', 0, 27):
out(0x00)
# --- Send 0x00 until floppy controller says to stop ---
end_seq_begin_label = next_label('end_seq') + '_begin'
end_seq_end_label = next_label('end_seq') + '_end'
print('{}:'.format(end_seq_begin_label))
print('\tin DWAIT')
print('\tora a')
print('\tjp {}'.format(end_seq_end_label))
print('\tmvi a, 0')
print('\tout DDATA')
print('\tjmp {}'.format(end_seq_begin_label))
print('{}:'.format(end_seq_end_label))
# ---
# advance to next track
print('''
mvi a, 0b01011100
out DCOM
IN DWAIT
''')
print('\thlt')