-
Notifications
You must be signed in to change notification settings - Fork 85
/
lccfmt2a.src
351 lines (262 loc) · 6.99 KB
/
lccfmt2a.src
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
.page
.subttl 'lccfmt2a.src'
gaptbl .byte $21,$22,$23,$24,$25,$26,$27,$28,$29
gp2cmd=*-gaptbl
gp2tbl .byte 2,2,4,6,8,8,11,19,22
; clear at least 6522 bytes written (trk1*1.08%)
spdchk ldy #0 ; 5100/6153 write 82% sync
ldx #28
jsr jclear ; clear whole disk & more
jsr fil_syn ; fill with sync
jsr kill ; go read mode
ldy #mscnt
2$ ldx #mscnt
3$ bit dskcnt ; try to find sync
bpl 5$ ; got sync
dex
bne 3$
dey
bne 2$
4$ lda #2
jmp jfmte10 ; error
5$ ldy #0
ldx #0
6$ bit dskcnt ; wait for sync to go away
bpl 6$ ; got sync
7$ lda dskcnt ; count time till next sync
iny ; lsb not used
bne 8$
inx ; msb
8$ and #$80
bne 7$ ; br, still no sync
lda #0
sta tsttrk
txa ; msb
;*********************************************************
;* --- lookup gap2 in table --- *
;* x : 21 / 22 / 23 / 24 / 25 / 26 / 27 / 28 / 29 *
;* gap2 : 02 / 02 / 04 / 06 / 08 / 08 / 0b / 13 / 16 *
;* speed : fast -------------------------------- slow *
;*********************************************************
ldx #gp2cmd-1
9$ cmp gaptbl,x ; lookup timing gap
beq 10$
dex
bpl 9$
bmi 4$ ; none
10$ lda gp2tbl,x ; look it up
sta dtrck
rts
jformt lda ftnum ; test if formating done
bpl 1$ ; yes
lda #$60 ; status = stepping
sta drvst
lda fmtsid
bne 3$
lda #01
.byte skip2
3$ lda #36
sta drvtrk ; track 1/36
sta ftnum ; track count =1/36
cmp #36 ; set/clr carry flag
jsr set_side
lda #256-92 ; step back 45 tracks
sta steps
lda dskcnt ; phase a
and #$ff-03
sta dskcnt
lda #10
sta cnt ; init error count
jmp jend ; go back to controler
1$ ldy #00
lda (hdrpnt),y
cmp ftnum
beq 2$
lda ftnum
sta (hdrpnt),y
jmp jend
2$ lda dskcnt ; check wps
and #$10
bne toptst ; ok
lda #8
jmp jfmterr ; wp error
fil_syn ldx #20 ; 20*256 bytes of sync
lda #$ff ; write syncs
1$ bit pota1
bmi 1$
sta data2
bit byt_clr
dey
bne 1$
dex
bne 1$
rts
toptst lda tsttrk
bpl 1$
jsr spdchk
1$ lda dtrck
; create header images
clc
lda #>bufs
sta hdrpnt+1
lda #00
sta hdrpnt ; point hdr point to buf0
sta sect
ldy #0
2$ lda hbid ; hbid cs s t id id 0f 0f
sta (hdrpnt),y
iny
lda #00 ; check sum is zero for now
sta (hdrpnt),y
iny
lda sect ; store sector #
sta (hdrpnt),y
iny
lda ftnum ; store track #
sta (hdrpnt),y
iny
lda dskid+1 ; store id low
sta (hdrpnt),y
iny
lda dskid ; store id hi
sta (hdrpnt),y
iny
lda #$0f ; store gap1 bytes
sta (hdrpnt),y
iny
sta (hdrpnt),y
iny
tya ; save this point
pha
ldx #07
lda #00
sta chksum ; zero checksum
3$ dey
lda (hdrpnt),y
eor chksum
sta chksum
dex
bne 3$
sta (hdrpnt),y ; store checksum
pla
tay ; restore pointer
inc sect ; goto next sector
lda sect ; test if done yet
cmp sectr
bcc 2$ ; more to do
lda #3
sta bufpnt+1 ; $03XX
jsr fbtog ; convert to gcr with no bid char
; move buffer up 79 bytes
ldy #$ff-69 ; for i=n-1 to 0:mem{i+69}:=mem{i}:next
4$ lda (hdrpnt),y ; move buf0 up 69 bytes
ldx #69
stx hdrpnt
sta (hdrpnt),y
ldx #00
stx hdrpnt
dey
cpy #$ff
bne 4$
ldy #68 ; #bytes to move
5$ lda ovrbuf+$bb,y
sta (hdrpnt),y
dey
bpl 5$
; create data block of zero
clc
lda #>bufs
adc #02
sta bufpnt+1 ; point to buf2
lda #00
tay ; init offset
6$ sta (bufpnt),y
iny
bne 6$
; convert data block to gcr
; write image
; leave it in ovrbuf and buffer
jsr chkblk ; get block checksum
sta chksum
jsr bingcr
; start the format now
; write out sync header gap1
; data block
lda #0 ; init counter
sta fmhdpt
ldx #6 ; clear 8% of disk
jsr jclear ; clear disk
7$ ldy #numsyn ; write 4 gcr bytes
8$ bit pota1
bmi 8$
lda #$ff ; write sync
sta data2
bit byt_clr ; clear pa latch
dey
bne 8$
ldx #10 ; write out header
ldy fmhdpt
9$ bit pota1
bmi 9$
lda (hdrpnt),y ; get header data
sta data2
bit byt_clr
iny
dex
bne 9$
; * write out gap1
ldy #gap1-2 ; write gcr bytes
10$ bit pota1
bmi 10$
lda #$55
sta data2
bit byt_clr
dey
bne 10$
; * write out data block
lda #$ff ; write data block sync
ldy #numsyn
11$ bit pota1
bmi 11$
sta data2
bit byt_clr
dey
bne 11$
ldy #$bb ; write out ovrbuf
12$ bit pota1
bmi 12$
lda ovrbuf,y
sta data2
bit byt_clr
iny
bne 12$
13$ bit pota1
bmi 13$
lda (bufpnt),y
sta data2
bit byt_clr
iny
bne 13$
lda #$55 ; write gap2(dtrck)
ldy dtrck
14$ bit pota1
bmi 14$
sta data2
bit byt_clr
dey
bne 14$
lda fmhdpt ; advance header pointer
clc
adc #10
sta fmhdpt
; done writing sector
dec sect ; go to next on
beq 15$ ; br, no more to do
jmp 7$
15$ bit pota1 ; wait for last one to write
bmi 15$
bit byt_clr
16$ bit pota1 ;wait for last one to write
bmi 16$
bit byt_clr
jsr kill ; goto read mode