-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathmfmcntrl.src
More file actions
632 lines (474 loc) · 11.8 KB
/
mfmcntrl.src
File metadata and controls
632 lines (474 loc) · 11.8 KB
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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
.page
.subttl 'mfmcntrl.src'
;bit 7 - test track
;bit 6 - test sector
;bit 5 - test write protect switch
;bit 4 - motor on
;bit 3 - seek to track
;bit 2 - wait for motor up to speed
;bit 1 - logical seek
;bit 0 - error return
cmdinf .byte $00,$15,$00,$00,$00,$15,$00,$bc
.byte $34,$de,$fe,$dc,$15,$15,$00
cmdjmp .word cmdzer ; reset
.word cmdone ; bump
.word cmdtwo ; wp status
.word cmdthr ; setup for step
.word cmdfor ; reserved
.word cmdfve ; read address
.word seke ; seek physical
.word cmdsev ; format track
.word cmdeig ; format disk
.word cmdnin ; read sector
.word cmdten ; write sector
.word cmdele ; verify
.word cmdtwv ; verify format
.word cmdthi ; create sector table
.word diskin ; is the disk home ?
cmdis = *-cmdjmp
.page
prcmd sei
pha ; save cmd
tax
lda cmdinf,x ; get information
sta info
lda dkmode
ora #$80 ; mfm mode
sta dkmode
asl info ; check track
bcc prc00
lda cmdbuf+3
sta cmd_trk ; save track
prc00 asl info ; check sector
bcc prc01
lda cmdbuf+4
sta sectr ; save sector
prc01 asl info ; check wp for write jobs
bcc prc02
lda dskcnt
and #$10
bne prc02
lda switch ; set kill job switch
ora #%00001000
sta switch ; wp error
ldx #8
stx ctl_dat
prc02 asl info ; motor on ?
bcc prc03
jsr stmtr ; start motor
prc03 asl info ; seek ?
bcc prc04 ; seek physical while motor is spinning
jsr seke ; seek job
prc04 asl info ; wait for motor up to speed ?
bcc prc05
jsr wtmtr ; go and wait
; disk up to speed
prc05 jsr sel_sid ; select
asl info ; logical seek required ?
bcc prc06
jsr s_log ; seek by reading
; disk up to speed and on track
prc06 lda #0
pla ; get jobs
asl a
tax
lda cmdjmp,x ; do indirect
sta temp
lda cmdjmp+1,x
sta temp+1
jsr do_the_command
jsr trnoff ; motor off...
ldx mfmcmd
cpx #2
php
asl info
bcs prc07
plp
bcc prc08
jmp exbad
prc07 plp ; restore status
prc08 rts
do_the_command jmp (temp)
.page
;******************************************************
moton php ; no irq's
sei
lda dskcnt
ora #4
sta dskcnt
plp ; retrieve status
rts
;******************************************************
motoff php ; no irq's
sei
lda dskcnt
and #$ff-$04
sta dskcnt
plp ; retrieve status
rts
;******************************************************
led_on php ; no irq's
sei
lda dskcnt ; turn on led
ora #8
sta dskcnt
plp ; retrieve status
rts
;******************************************************
led_off php ; no irq's
sei
lda dskcnt ; turn led off
and #$ff-$08
sta dskcnt
plp ; retrieve status
rts
;******************************************************
stmtr php
sei
lda drvst
bmi 2$ ; accelerating?
and #$30 ; check running & timeout
beq 1$
lda #$20 ; running
sta drvst ; set status
2$ plp
rts
1$ plp
sta cdrive ; set drive #
jmp turnon
nop
nop
nop
nop
nop
nop
;******************************************************
wtmtr php ; wait for motor up to speed
cli
wtmtr1 lda drvst
cmp #$20 ; drv ready ?
bne wtmtr1
plp
rts
;******************************************************
seke php ; wait for not busy
cli ; enable irqs for motor on timing
lda cmd_trk
asl a ; half steps
cmp cur_trk ; correct track ?
beq sekrtn ; br, yep
seklop lda cmd_trk ; where
asl a
cmp cur_trk
beq sekdun
bcs sekup ; hi or lo ?
sekdn jsr stout ; step out
jmp seklop ; next
sekup jsr stin ; step in
jmp seklop ; next also
sekdun
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
ldy #18 ; settle
; *rom ds 08/26/85*, 1570 patch
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
jsr xms ; delay
sekrtn plp
rts
;******************************************************
stin lda cur_trk ; get current valuestep
clc
adc #1
jmp stpfin ; half step out
stout ldy #99 ; wait for trk_00
1$ lda pota1 ; check for trk_00
ror a ; rotate into carry
php ; save carry
lda pota1 ; debounce it
ror a ; carry <=
ror a ; bit 7 <=
plp ; retrieve carry
and #$80 ; set/clear sign bit
bcc 3$ ; on track zero
bpl 2$ ; carry set(off) & sign(on) exit
bmi 4$ ; bra
3$ bmi 2$ ; carry clear(on) & sign(off) exit
4$ dey
bne 1$ ; continue
bcs 2$ ; br, not track 00 ?
lda dskcnt ; phase 0
and #3
bne 2$
lda #0 ; trk zero
sta cur_trk ; current trk = 40*2/0
rts
2$ lda cur_trk ; get current half step
sec
sbc #1
stpfin sta cur_trk ; save
and #3 ; strip unused
sta temp
php ; no irq's
sei
lda dskcnt
and #$fc ; strip step bits
ora temp
sta dskcnt
plp ; retrieve status
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
ldy #$08 ; 8 ms step time, 18 ms settle
; *rom ds 08/26/85 *, 1570 patch
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
xms jsr onems ; delay 1 ms
dey
bne xms
rts
;******************************************************
onems ldx #2
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
lda #$6f
; *rom ds 08/26/85 *, 1570 patch
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
onems1 adc #1
bne onems1
dex
bne onems1
rts
;******************************************************
cvstat WDTEST ; chk address
lda wdstat ; retrieve status
lsr a
lsr a
lsr a
and #3 ; check status
tax
lda mfmer,x
sta mfmcmd
tax
rts
;******************************************************
strtwd pha ; save accum
jsr led_on ; act led on
pla
WDTEST ; chk address
sta wdstat ; send cmd to wd 1770
lda #1 ; wait for busy
WDTEST ; chk address
1$ bit wdstat
beq 1$
jmp jslower ; WD1770 bug ????
;******************************************************
waitdn jsr led_off ; act led off
lda #1 ; wait for unbusy
WDTEST ; chk address
1$ bit wdstat
bne 1$
rts
.page
;******************************************************
sectnx lda minsek
sec
sbc #1
sta ctl_dat ; save min sector - 1
lda cmdbuf+4 ; get original sector
clc
adc cpmit ; next sector
cmp maxsek
beq 2$ ; equal to or
bcc 2$ ; less than
sbc maxsek ; rap around
clc
adc ctl_dat ; add min now
2$ sta cmdbuf+4 ; next sector for controller
rts
.page
;******************************************************
sectcv ldy #0
ldx #0
lda cmdbuf+3 ; start at sector x
and #$3f ; delete mode bit & table bit
sta cmdbuf+3
sta minsek ; new min
pha ; save ss
lda cmdbuf+7 ; save ns
pha
inc cmdbuf+4 ; interleave + 1
sectop lda cmdbuf+3 ; ss
sta cmdbuf+11,y ; table goes to cmdbuf+42
inc cmdbuf+3 ; increment ss
inx
tya ; do addition
clc
adc cmdbuf+4 ; add interleave
tay
cpy #32 ; no more room
bcs bd_int
cpy cmdbuf+7 ; ns
bcc secles ; < than
bne seclmo ; can't be equal until the end
cpx cmdbuf+7 ; ns end ?
beq seclmo
bd_int dec cmdbuf+4 ; restore
pla
sta cmdbuf+7 ; restore ns
pla
sta cmdbuf+3 ; restore ss
sec
rts ; bad exit
seclmo tya
sec
sbc cmdbuf+7 ; ns
tay
secles cpx cmdbuf+7 ; ns
bne sectop
stx cpmsek ; ns
dex
txa
clc
adc minsek ; find max
sta maxsek ; new max
cmp minsek ; better be less than max
bcc bd_int ; bad starting sector
pla
sta cmdbuf+7 ; restore ns
pla
sta cmdbuf+3 ; restore ss
dec cmdbuf+4 ; restore
clc ; ok exit
rts
;******************************************************
verfmt lda mfmcmd
pha ; save current logical track
ldy #0
sty mfmhdr ; init index into sector table
ver_fm ldy mfmhdr ; get current index
lda cmdbuf+11,y
sta wdsec ; setup sector for wd 1770
jsr cmdtwv ; verify
ldx mfmcmd ; get error
cpx #2
bcs ver_00
inc mfmhdr ; next entry in sector table
ldy mfmhdr
cpy cmdbuf+7 ; check with ns
bne ver_fm ; done ?
clc
.byte skip1
ver_00 sec
pla
sta mfmcmd ; restore track address
no_trk rts
;******************************************************
chcsee lda cmdsiz
cmp #7 ; next track parameter given ?
bcc no_trk
lda cmdbuf+6 ; get nt
sta cmd_trk
jmp seke
;******************************************************
s_log lda mfmcmd ; save command
pha
jsr cmdfiv ; where are we?
ldx mfmcmd ; status ok?
cpx #2
bcc 1$ ; see if we are there...
jsr cmdone ; restore to trk_00
jsr cmdfiv ; where are we.. better be track 00
ldx mfmcmd ; status ok?
cpx #2
bcs 2$ ; on error leave on track 00
1$ lda cmd_trk ; we there yet ?
asl a
cmp cur_trk ; are we on ?
beq 2$
jsr seke ; find it...should be there now...hope?
2$ pla
sta mfmcmd ; restore command
rts
;******************************************************
sel_sid php ; no irq's
sei
lda switch
and #%00010000 ; check side
cmp #%00010000 ; set/clr carry
jsr set_side ; set h/w
plp ; retrieve status
rts
;******************************************************
maxmin ldy cpmsek ; get ns
dey ; one less
lda #255 ; as small as min can get
minim cmp cmdbuf+11,y
bcc no_min ; br, no change
lda cmdbuf+11,y
no_min dey
bpl minim
sta minsek ; save min
ldy cpmsek
dey ; one less
lda #0 ; as small as max can get
maxim cmp cmdbuf+11,y
bcs no_max ; br, no change
lda cmdbuf+11,y
no_max dey
bpl maxim
sta maxsek ; save max
rts
;******************************************************
fn_int ldx cpmsek ; location of min
ldy #0 ; start in beginning
fn_000 lda cmdbuf+11,y
cmp minsek
beq fn_001 ; min ?
iny
cpy cpmsek
bne fn_000
fn_001 sty ctl_cmd ; save index
lda minsek ; get min
clc
adc #1 ; add one to it
sta ctl_dat ; save min + 1
ldx #255 ; interleave at zero
fnlook lda cmdbuf+11,y
cmp ctl_dat ; find min + 1 ?
beq fn_002
inx ; cpmit = cpmit + 1
iny
cpy cpmsek ; index here ?
bne fnlook
ldy #0 ; rap around
beq fnlook ; bra
fn_002 rts ; return with hard interleave in .x
;******************************************************
diskin lda temp
pha ; save temp
php ; save status
sei ; no irq's
lda wdtrk ; where are we ?
sta wddat ; here we are..
lda #$18
jsr strtwd ; seek cmd
jsr waitdn ; fin ?
ldx #0
ldy #128 ; wait a little more than a revolution
WDTEST ; chk address
lda wdstat ; get start status
and #2
sta temp ; save current status
WDTEST ; chk address
1$ lda wdstat ; get current status
and #2
cmp temp ; same go on
beq 2$
plp ; retrieve status
jmp 4$ ; finish up ok disk inserted
2$ dex
bne 1$
dey
bne 1$ ; timout ?
plp ; retrieve status
sec ; exit no index sensor toggling
.byte skip1
4$ clc ; ok
pla
sta temp ; restore temp
rts