-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathmfmsubr1.src
503 lines (382 loc) · 6.86 KB
/
mfmsubr1.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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
.page
.subttl 'mfmsubr1.src'
; format track
cmdsev lda #$f8 ; write track
jsr strtwd ; send command
bit switch ; system 34 / iso standard switch
bvc no_ind ; write index ?
ldx #80
WDTEST ; chk address
2$ lda wdstat
and #3
lsr a
bcc v6
beq 2$
lda #$4e
sta wddat ; give him the data
dex
bne 2$
ldx #12
WDTEST ; chk address
3$ lda wdstat
and #3
lsr a
bcc v6
beq 3$
lda #0
sta wddat
dex
bne 3$
ldx #3
WDTEST ; chk address
4$ lda wdstat
and #3
lsr a
bcc v6
beq 4$
lda #$f6
sta wddat
dex
bne 4$
WDTEST ; chk address
5$ lda wdstat
and #3
lsr a
bcc v6
beq 5$
lda #$fc
sta wddat
ldx #50
WDTEST ; chk address
6$ lda wdstat
and #3
lsr a
bcc v6
beq 6$
lda #$4e
sta wddat ; give him the data
dex
bne 6$
beq inner ; bra... done...
no_ind ldx #60
WDTEST ; chk address
cmd7 lda wdstat
and #3
lsr a
v6 bcc v1
beq cmd7
lda #$4e
sta wddat ; give him the data
dex
bne cmd7
inner ldy #1 ; ss
main7 ldx #12
WDTEST ; chk address
cmd70 lda wdstat
and #3
lsr a
bcc v1
beq cmd70
lda #0
sta wddat
dex
bne cmd70
ldx #3
WDTEST ; chk address
cmd71 lda wdstat
and #3
lsr a
v1 bcc v2
beq cmd71
lda #$f5
sta wddat
dex
bne cmd71
WDTEST ; chk address
cmd7n lda wdstat
and #3
lsr a
bcc v2
beq cmd7n
lda #$fe ; id address mark
sta wddat
WDTEST ; chk address
cmd7f lda wdstat
and #3
lsr a
bcc v2
beq cmd7f
lda mfmcmd ; give him the track
sta wddat
WDTEST ; chk address
cmd7e lda wdstat
and #3
lsr a
bcc v2
beq cmd7e
lda switch
and #%00010000 ; what side are we on ?
bne 1$
lda #0
.byte skip2
1$ lda #1
sta wddat ; side number is ...
WDTEST ; chk address
cmd7d lda wdstat
and #3
lsr a
bcc v2
beq cmd7d
lda cmdbuf+10,y ; sector number actually cmdbuf+11
sta wddat
WDTEST ; chk address
cmd7c lda wdstat
and #3
lsr a
v2 bcc v3
beq cmd7c
lda cmdbuf+5 ; sz
sta wddat
WDTEST ; chk address
cmd7b lda wdstat
and #3
lsr a
bcc v3
beq cmd7b
lda #$f7 ; crc 2 bytes written
sta wddat
ldx #22
WDTEST ; chk address
cmd72 lda wdstat
and #3
lsr a
bcc v3
beq cmd72
lda #$4e
sta wddat
dex
bne cmd72
ldx #12
WDTEST ; chk address
cmd73 lda wdstat
and #3
lsr a
v3 bcc v4
beq cmd73
lda #0
sta wddat
dex
bne cmd73
ldx #3
WDTEST ; chk address
cmd74 lda wdstat
and #3
lsr a
bcc v4
beq cmd74
lda #$f5 ; a1
sta wddat
dex
bne cmd74
WDTEST ; chk address
cmd7a lda wdstat
and #3
lsr a
bcc v4
beq cmd7a
lda #$fb ; dam
sta wddat
sty temp ; save current sector
ldy mfmsiz_hi ; high
WDTEST ; chk address
cmd750 lda wdstat
and #3
lsr a
v4 bcc v5
beq cmd750
lda cmdbuf+10 ; fl
sta wddat
cpx mfmsiz_lo
beq cmd75x
inx ; increment
jmp cmd750
cmd75x inx
dey
bne cmd750
WDTEST ; chk address
cmd7ff lda wdstat
and #3
lsr a
bcc v5
beq cmd7ff
lda #$f7 ; crc
sta wddat
ldy cmdbuf+5 ; ss
lda gapmfm,y
ldy temp ; sector restore
tax
WDTEST ; chk address
cmd7fe lda wdstat
and #3
lsr a
bcc v5
beq cmd7fe
lda #$4e ; gap 3
sta wddat
dex
bne cmd7fe
cpy cmdbuf+7 ; ns
beq finmfm
iny ; inc sector
jmp main7
WDTEST ; chk address
finmfm lda wdstat
and #3
lsr a
bcc vfin
beq finmfm
clc
lda #$4e ; wait for wd to time out
sta wddat
jmp finmfm
vfin jsr waitdn ; wait for sleepy time
clc ; good carry
.byte skip1
v5 sec
rts
; min gap size @2% fast
gapmfm .byte 7, 12, 23, 44
numsek .byte 26, 16, 9, 5
.page
; format disk
; 0 1 2 3 4 5 6 7 8 9 10 + cmdbuf
; ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
; "U" + $00 + N + MD + CP + SZ + LT + NS + ST + S + FL
cmdeig lda switch ; check abort command switch
and #%00001000
beq 1$
ldx ctl_dat ; get error
stx mfmcmd ; save for prcmd
sec ; wp error usually
rts
1$ jsr clrchn ; close all channels
lda cmdsiz ; setup default parms
sec
sbc #4 ; less mandatory + 1
tay
beq cp00 ; mode only, gave cp
dey
beq sz00 ; md, cp only, gave sz
lda #0
sta mfmcmd ; clear status
lda cmdbuf+5
jsr consek ; setup sector size
dey
beq lt00 ; md, cp, sz only, gave lt
dey
beq ns00 ; md, cp, sz, lt only, gave ns
dey
beq st00 ; md, cp, sz, lt, ns only, gave st
dey
beq s00 ; md, cp, sz, lt, ns, st only, gave s
dey
beq fl00 ; md, cp, sz, lt, ns, st, ss only, gave fl
jmp start8
.page
cp00 lda #0 ; default interleave
sta cmdbuf+4
sz00 lda #0
sta mfmcmd ; clear status
lda #1 ; 256 byte sectors
sta cmdbuf+5
jsr consek ; setup block size
lt00 lda #39 ; last track is #39, 40 tracks total
sta cmdbuf+6
ns00 lda numsek,x ; x=sector size index for # of sectors per track
sta cmdbuf+7
st00 lda #0 ; default track #0 start
sta cmdbuf+8
sta wdtrk
s00 lda #0 ; default steps from track 00
sta cmdbuf+9
fl00 lda #$e5 ; default block fill
sta cmdbuf+10
.page
start8 jsr go_fmt ; format side zero
lda mfmcmd ; error ?
cpx #2
bcs 1$
lda switch ; check for double sided opt
and #%00100000
beq 1$
lda switch ; set single side
ora #%00010000
sta switch
jsr sel_sid ; select h/w
jsr go_fmt ; format side one
1$ jmp cmdone ; restore
.page
go_fmt jsr diskin ; is there a diskette in the unit
bcs c_801 ; br, nope...
lda #1
sta ifr1 ; clear irq from write protect
jsr cmdone ; restore to track one/zero ?
lda cmdbuf+8 ; store logical
sta mfmcmd ; in mfmcmd
sta wdtrk
bit cmdbuf+3 ; check table bit
bvs 1$ ; br, table has been given to us
jsr sectcv ; generate sector table
bcs c_801
1$ lda cmdbuf+9 ; offset track 00 by s steps
and #$7f ; clear mode bit
beq c_800
clc
adc cmd_trk ; add to it
sta cmd_trk ; physical
jsr seke ; & seek to it
c_800 sei
lda ifr1 ; check for disk change
lsr a
bcs c_801
jsr cmdsev ; format track
bcs c_801
lda ifr1 ; check for disk change
lsr a
bcs c_801
jsr verfmt ; verify format
bcs c_801
lda ifr1 ; check for disk change
lsr a
bcs c_801
lda mfmcmd ; last track ?
cmp cmdbuf+6 ; lt
beq c_802
inc cmd_trk
inc wdtrk
inc mfmcmd ; track to write
jsr seke ; goto next track
jmp c_800
c_802 bit switch
bpl c_803 ; kill next
sec
lda cmdbuf+6 ; lt
sbc cmdbuf+8 ; st
cmp #39 ; no more than 40 tracks
bcs c_803
inc cmd_trk ; clear next track
jsr seke
ldx #28
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
jsr ptch0d ; *** rom ds 01-13-87 ***,no SO
nop
nop
nop ; fill
; jsr jclear ; with gcr 0
; jsr kill ; read mode again
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
c_803 ldx #0
.byte skip2
c_801 ldx #6
stx mfmcmd ; ok exit
jmp upinst