-
Notifications
You must be signed in to change notification settings - Fork 82
/
mrout.src
1324 lines (1056 loc) · 17.8 KB
/
mrout.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
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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.messg "mrout"
.subttl "mrout"
.page
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
reset_ctl ; reset disk controller
ldy #all
jsr xms ; no access for 500 mS
ldy #all
jsr xms ; *
lda #bit7
sta cachetrk ; *
lda #0
sta dirty
jsr psetdef
jsr setdef
lda #$4e
sta ctltimh
lda #$20
sta ctltiml ; IRQ's
jsr resetim ; reset controller timers
lda #$08 ; setup wd177x commands
sta wdrestore
lda #$18
sta wdseek
lda #$28
sta wdstep
lda #$48
sta wdstepin
lda #$68
sta wdstepout
lda #$88
sta wdreadsector
lda #$aa
sta wdwritesector
lda #$c8
sta wdreadaddress
lda #$e8
sta wdreadtrack
lda #$fa
sta wdwritetrack
lda #$d0
sta wdforceirq
lda #18
sta setval ; 18 mS
ldy #all ; test registers
1$ sty wdtrk
sty wdsec
sty wddat
jsr delay16
cpy wdtrk
bne 3$
cpy wdsec
bne 3$
cpy wddat
bne 3$
dey
bne 1$
jsr wdabort ; abort the wd17xx
lda #0
sta todlsb
jsr delay40 ; wait for 40 uS
lda todlsb
bne 2$ ; default wd1770
inc wdrestore
inc wdseek
inc wdstep
inc wdstepin
inc wdstepout
2$ bne okdone ; bra
3$ lda #$0d ; controller error
.byte skip2
okdone lda #0 ; ok
done jmp errr
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
moton_ctl ; motor on with spinup sequence
jmp okfin ; done
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
motoff_ctl ; motor off with spin down sequence
jmp okdone ; turn off the motor
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
motoni_ctl ; motor on
jsr moton ; turn on the motor
okfin lda #0
fin ldy nextjob
sta jobs,y ; mimick errr w/o spindown
lda #bit7
sta nextjob ; clear job flag
ldy #numjob
jmp erret
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
motoffi_ctl ; motor off
jsr motoff ; turn it off
jmp okfin
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
seek_ctl ; move physical
lda cmdtrk ; we on track yet?
cmp drvtrk
beq 1$ ; br, yep
jmp end_ctl
1$ jmp okdone
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
format_ctl ; format side
jsr cacheip ; setup indirects
jsr fmtrk
bcs 1$
jsr getwdstat ; get status
bne 2$
jsr cacheip ; setup indirects
jsr fmtver_ctl ; won't come back on verify error
lda #1 ; ok
.byte skip2
1$ lda #6 ; format error
2$ jmp errr
.page
fmtrk
lda cmdtrk ; track
sta wdtrk
jsr precmp ; set precomp
lda pstartsec ; starting sector
sta tmp+1
lda pnumsec
sta tmp+2
lda wdwritetrack
jsr wdbusy ; send it a 'write track' command
ldx #32
WDTEST ; chk address
cmd7 lda wdstat
and #3
lsr a
v6 bcc v1
beq cmd7
lda #$4e
sta wddat ; give him the $4E data
dex
bne cmd7
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 wdtrk ; give him the track
sta wddat
WDTEST ; chk address
cmd7e lda wdstat
and #3
lsr a
bcc v2
beq cmd7e
lda tcacheside
sta wddat ; side number is ...
WDTEST ; chk address
cmd7d lda wdstat
and #3
lsr a
bcc v2
beq cmd7d
lda tmp+1 ; sector #
sta wddat
WDTEST ; chk address
cmd7c lda wdstat
and #3
lsr a
v2 bcc v3
beq cmd7c
lda psectorsiz ; sector size
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 ; Counter for 3 F5's.
WDTEST ; chk address
cmd74 lda wdstat
and #3
lsr a
bcc v4
beq cmd74
lda #$f5 ; (Writes A1 data, 0A clock).
sta wddat
dex
bne cmd74
WDTEST ; chk address
cmd7a lda wdstat
and #3
lsr a
bcc v4
beq cmd7a
lda #$fb ; (writes data address mark)
sta wddat
ldy psectorsiz
cpy #3
bne cmd750
iny
WDTEST ; chk address
cmd750 lda wdstat
and #3
lsr a
v4 bcc v5
beq cmd750
lda fillbyte ; fill byte
cmp #$f5 ; track cache fill ?
bne 1$
sty yreg
ldy #0
lda (ip+4),y ; get data
ldy yreg ; restore .y register
1$ sta wddat
inc ip+4 ; inc pointer
bne cmd750
inc ip+5 ; inc high address
dey
bne cmd750
WDTEST ; chk address
cmd7ff lda wdstat
and #3
lsr a
bcc v5
beq cmd7ff
lda #$f7 ; crc
sta wddat
ldx gap3
WDTEST ; chk address
cmd7fe lda wdstat
and #3
lsr a
bcc v5
beq cmd7fe
lda #$4e ; gap 3
sta wddat
dex
bne cmd7fe
dec tmp+2 ; number of sectors
beq finmfm
inc tmp+1
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
bne finmfm ; bra
vfin jsr wdunbusy ; wait for sleepy time
clc ; good carry
.byte $24
v5 sec
rts
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ledacton_ctl ; turn activity led on
lda ledprint
ora #act_led
sta ledprint
jmp okfin
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ledactoff_ctl ; turn activity led off
lda ledprint
and #all-act_led
sta ledprint
jmp okfin
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
errledon_ctl ; blink power led
lda ledprint
ora #pwr_led
sta ledprint
jmp okfin
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
errledoff_ctl ; disable power led blink
lda ledprint
and #all-pwr_led
sta ledprint
jmp okfin
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
side_ctl ; select side
ldy nextjob ; get index
lda sids,y ; side in track position in header queue
and #bit0
sta cacheside ; select side
bne 1$
lda #0 ; side one
.byte skip2
1$ lda #side_sel ; side zero
sta ctmp
lda pa
and #all-side_sel
ora ctmp
sta pa
jmp okfin
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bufmove_ctl ; buffer move
ldy hdrjob ; get index
lda hdrs+1,y ; sector position denotes operation
;
; hdrs: position in track cache
;
; hdrs+1:
;
; bits 7 6 5 4 3 2 1 0
; d m t [ # of 256 blks ]
;
; d: direction (1=to track cache buffer)
; m: mark, set the dirty flag (d must be set)
; t: transfer data (1=transfer)
;
; hdrs2: cachetrk update
;
; sids: cacheside update
;
;
sta tmp+1 ; save command info
bit tmp+1
bpl 1$ ; br, from cache
lda hdrs2,y
sta cachetrk ; this track
ldy nextjob
lda sids,y
sta cacheside ; & this side
jsr bufcache ; transfer to cache
jmp okdone
1$ jsr cachebuf ; transfer from cache
jmp okdone
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
trkwrt_ctl ; track cache dump
jmp okdone ; done by (mfmctl)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*=*+256-<*
wrtold_ctl ; old track cache dump
jsr seek ; seek any header, on error don't come back
lda cachetrk ; this is what is in memory
cmp header
beq 1$
jmp wrongtrk
1$ sta wdtrk
jsr precmp ; set precomp
jsr cacheip ; setup ip
lda pnumsec ; number of sectors on a side
sta tmp+2
lda header+2 ; get sector number
tax ; save in .x
cmp pendsec ; pending sector
php
bne 3$
lda pstartsec ; get starting sector
tax ; save in .x
sec
sbc #1 ; one less
3$ sec
sbc pstartsec ; track cache index=last sector - start sector
clc
adc #1
ldy psectorsiz
4$ dey ; for sectors > 256
beq 5$
asl a ; x2
bcc 4$ ; more ?
5$ jsr chkcache ; check cache address
txa ; retrieve sector
plp
beq 6$ ; if it was the last sector then start at the beginning
clc
adc #1 ; one more
bne 7$ ; bra
6$ lda pstartsec ; get starting sector
7$ sta wdsec
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
8$ lda wdwritesector
jsr wdbusy
ldy psectorsiz ; get sector size
cpy #3
bne 9$
iny
WDTEST
9$ lda wdstat
and #3
lsr a
bcc 10$
beq 9$
sty yreg ; save .y register
ldy #0
lda (ip+4),y ; get data
sta wddat ; put it
ldy yreg ; restore .y register
inc ip+4
bne 9$
inc ip+5
dey
bne 9$
jsr getwdstat
bne 10$ ; error
dec tmp+2 ; done ?
beq 10$
lda wdsec ; put in .a
inc wdsec ; next
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
cmp pendsec ; last sector?
bne 8$
lda cache+1
sta ip+5 ; start at beginning of the track cache buffer
lda pstartsec ; & first sector
sta wdsec
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
jmp 8$
10$ jsr getwdstat ; get status
beq 11$ ; ok?
jmp errr ; nope
11$ jmp wrtver_ctl ; verify job
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diskin_ctl ; disk present?
;~~~~~~~~~~~
pseek_ctl ; move head to logical track
jsr seek ; seek ok...
jmp okdone
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*=*+256-<*
spwrt_ctl ; write physical address
jsr seek ; seek any header, on error abort
lda cmdtrk ; get address
cmp header
beq 1$
jmp wrongtrk
1$ ldx nextjob ; get job number
lda hdrs,x ; get track
sta wdtrk
lda hdrs+1,x
sta wdsec ; and sector
lda #0
sta ip+4 ; zero low
lda #>buff0
sta ip+5 ; point to buffer 0
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
lda wdwritesector
jsr wdbusy
ldy psectorsiz ; get sector size
cpy #3
bne 2$
iny
WDTEST
2$ lda wdstat
and #3
lsr a
bcc 3$
beq 2$
sty yreg ; save .y register
ldy #0
lda (ip+4),y ; get data
sta wddat ; put it
ldy yreg ; restore .y register
inc ip+4
bne 2$
inc ip+5
dey
bne 2$
3$ jsr getwdstat ; get status
jmp errr
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*=*+256-<*
spread_ctl ; read physical address
jsr seek ; seek any header, on error abort
lda cmdtrk ; get address
cmp header
beq 1$
jmp wrongtrk
1$ ldx nextjob ; get job number
lda hdrs,x ; get track
sta wdtrk
lda hdrs+1,x
sta wdsec ; and sector
lda #0
sta ip+4 ; zero low
lda #>buff0
sta ip+5 ; point to buffer 0
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
lda wdreadsector
jsr wdbusy
ldy psectorsiz ; get sector size
cpy #3
bne 2$
iny
WDTEST
2$ lda wdstat
and #3
lsr a
bcc 3$
beq 2$
sty yreg ; save .y register
ldy #0
lda wddat ; get it
sta (ip+4),y ; put data
ldy yreg ; restore .y register
inc ip+4
bne 2$
inc ip+5
dey
bne 2$
3$ jsr getwdstat ; get status
jmp errr
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*=*+256-<*
pread_ctl
pwrt_ctl
wrtsd_ctl ; write to track cache buffer
read_ctl ; read from track cache buffer
jsr seek ; seek any header, on error abort
lda cmdtrk ; get address
cmp header
beq 1$
jmp wrongtrk
1$ sta wdtrk
jsr cacheip ; setup ip
lda tcacheside ; get translated cache side
sta tmp+1 ; in current
lda pnumsec ; number of sectors on a side
sta tmp+2
lda header+2 ; get sector number
tax ; save in .x
cmp pendsec ; pending sector
php
bne 3$
lda pstartsec ; get starting sector
tax ; save in .x
sec
sbc #1 ; one less
3$ sec
sbc pstartsec ; track cache index=last sector - start sector
clc
adc #1
ldy psectorsiz
4$ dey ; for sectors > 256
beq 5$
asl a ; x2
bcc 4$ ; more ?
5$ jsr chkcache ; check cache for valid address
txa ; retrieve sector
plp
beq 6$ ; if it was the last sector then start at the beginning
clc
adc #1 ; one more
bne 7$ ; bra
6$ lda pstartsec ; get starting sector
7$ sta wdsec
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
8$ lda wdreadsector
jsr wdbusy
ldy psectorsiz ; get sector size
cpy #3
bne 9$
iny
WDTEST
9$ lda wdstat
and #3
lsr a
bcc 10$
beq 9$
sty yreg ; save .y register
ldy #0
lda wddat ; get it
sta (ip+4),y ; put data
ldy yreg ; restore .y register
inc ip+4
bne 9$
inc ip+5
dey
bne 9$
jsr getwdstat ; get status
bne 10$ ; error
dec tmp+2 ; done ?
beq 10$
lda wdsec ; put in .a
inc wdsec ; next
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
cmp pendsec ; last sector?
bne 8$
lda cache+1
sta ip+5 ; start at beginning of the track cache buffer
lda pstartsec ; & first sector
sta wdsec
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
jmp 8$
10$ jsr getwdstat ; get status
bne 11$ ; bad
lda tcacheside
sta cacheside ; new current
lda cmdtrk
sta cachetrk ; track in memory
jmp back ; service original
11$ jmp errr ; nope
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wrtver_ctl ; write track cache buffer to disk
bit iobyte
bpl 2$ ; verify on/off ?