-
Notifications
You must be signed in to change notification settings - Fork 6
/
IO.ASM
1934 lines (1749 loc) · 34.1 KB
/
IO.ASM
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
; I/O System for 86-DOS version 1.20 and later. Revised 8-02-82.
;
; Assumes a CPU Support card at F0 hex for character I/O,
; with disk drivers for SCP, Tarbell, or Cromemco controllers.
;
; Select whether console input is interrupt-driven or polled.
INTINP: EQU 1
;
; Select whether the auxiliary port is the Support Card parallel port
; or on channel 1 of a Multiport Serial card addressed at 10H.
PARALLELAUX: EQU 1
SERIALAUX: EQU 0
;
; Select whether the printer is connected to the Support card parallel
; output port (standard) or channel 0 of a Multiport Serial card
; addressed at 10H.
PARALLELPRN: EQU 1
SERIALPRN: EQU 0
;
; If the Multiport Serial was chosen for either the auxiliary or the
; printer, select the baud rate here. Refer to Multiport Serial manual
; page 11 to pick the correct value for a given baud rate.
PRNBAUD:EQU 7 ; 1200 baud
AUXBAUD:EQU 0FH ; 19200 baud
;
; Select disk controller here.
SCP: EQU 1
TARBELLSD: EQU 0
TARBELLDD: EQU 0
CROMEMCO4FDC: EQU 0
CROMEMCO16FDC: EQU 0
;
; Select if you want a special conversion version which can read/write
; both the new Microsoft format and the old SCP format.
; For a two drive system, drives A and B are the new Microsoft format,
; and drives C and D are the old SCP format (where C is the same physical
; drive as A, and D is the same drive as B). CONVERT has no effect
; on 5.25-inch drives.
CONVERT:EQU 1
;
; Select disk configuration:
LARGE: EQU 1 ; Large drives.
COMBIN: EQU 0 ; Two 8-inch and one 5.25-inch.
SMALL: EQU 0 ; Three 5.25-inch drives.
CUSTOM: EQU 0 ; User defined.
;
; If 8-inch drives are PerSci, select FASTSEEK here:
; (Fastseek with Tarbell controllers doesn't work yet).
FASTSEEK: EQU 1
;
; For double-density controllers, select double-sided operation of
; 8-inch disks in double-density mode.
LARGEDS: EQU 0
;
; For double-density controllers, select double-sided operation of
; 5.25-inch disks in double-density mode.
SMALLDS: EQU 0
;
; Use table below to select head step speed. Step times for 5" drives
; are double that shown in the table. Times for Fast Seek mode (using
; PerSci drives) is very small - 200-400 microseconds.
;
; Step value 1771 1793
;
; 0 6ms 3ms
; 1 6ms 6ms
; 2 10ms 10ms
; 3 20ms 15ms
;
STPSPD: EQU 0
;
; ****** End of selections ********************************************
;
BIOSSEG:EQU 40H ; I/O system segment.
BIOSLEN:EQU 2048 ; Maximum length of I/O system.
DOSLEN: EQU 8192 ; Maximum length of MS-DOS.
QSIZE: EQU 80 ; Input queue size.
PBUFSIZ:EQU 128 ; Size of print buffer
BASE: EQU 0F0H ; CPU Support card base port number.
SIOBASE:EQU 10H ; Base port number of Multiport Serial card.
STAT: EQU BASE+7 ; Serial I/O status port.
DATA: EQU BASE+6 ; Serial I/O data port.
DAV: EQU 2 ; Data available bit.
TBMT: EQU 1 ; Transmitter buffer empty bit.
SERIAL: EQU SERIALPRN+SERIALAUX
STCDATA:EQU BASE+4 ; Ports for 9513 Timer chip.
STCCOM: EQU BASE+5
IF SERIALAUX
AUXSTAT:EQU SIOBASE+3
AUXDATA:EQU SIOBASE+2
ENDIF
IF PARALLELAUX
AUXSTAT:EQU BASE+13
AUXDATA:EQU BASE+12
ENDIF
IF SERIALPRN
PRNSTAT:EQU SIOBASE+1
PRNDATA:EQU SIOBASE+0
ENDIF
IF PARALLELPRN
PRNSTAT:EQU BASE+13
PRNDATA:EQU BASE+12
ENDIF
ORG 0
PUT 100H
JMP INIT
JMP STATUS
JMP INP
JMP OUTP
JMP PRINT
JMP AUXIN
JMP AUXOUT
JMP READ
JMP WRITE
JMP DSKCHG
JMP SETDATE
JMP SETTIME
JMP GETTIME
JMP FLUSH
JMP MAPDEV
MAPDEV:
RET L
INIT:
XOR BP,BP ; Set up stack just below I/O system.
MOV SS,BP
MOV SP,BIOSSEG*16
IF INTINP-1
MOV AL,0FFH ; Mask all interrupts.
OUTB BASE+3
ENDIF
IF INTINP
DI ; Set up keyboard interrupt vector.
MOV [BP+64H],KBINT
MOV [BP+66H],CS
EI
ENDIF
MOV [BP+4*38H],PRNFCB
MOV [BP+4*38H+2],CS
PUSH CS
POP DS
;
; Initialize time-of-day clock.
;
MOV SI,STCTAB
MOV CX,4 ;Initialize 4 registers
UP
INITSTC:
LODB
OUT STCCOM ;Select register to initialize
LODB
OUT STCDATA
LODB
OUT STCDATA
LOOP INITSTC
IF SERIAL
MOV CX,4
SERINIT:
LODB
OUT SIOBASE+1
OUT SIOBASE+3
LOOP SERINIT
LODB ;Baud rate for channel 0
OUT SIOBASE+8
LODB ;Baud rate for channel 1
OUT SIOBASE+9
ENDIF
;
; Move MS-DOS down to the first segment just above the I/O system.
;
MOV SI,BIOSLEN ; Source points to where MS-DOS currently is.
MOV AX,DOSSEG ; Destination is beginning of DOSSEG.
MOV ES,AX
SUB DI,DI
MOV CX,DOSLEN/2 ; CX is number of words to move.
REP
MOVSW
MOV SI,INITTAB
MOV DX,1 ; Do auto memory scan.
CALL 0,DOSSEG
;
; Change disk read and write vectors (INT 37 and INT 38) to go to
; DIRECTREAD and DIRECTWRITE rather than READ and WRITE.
;
SUB BP,BP
MOV W,[BP+37*4],DIRECTREAD
MOV W,[BP+38*4],DIRECTWRITE
MOV DX,100H
MOV AH,26 ;Set DMA address
INT 33
MOV CX,[6] ;Get size of segment
MOV BX,DS ;Save segment for later
;
; DS must be set to CS so we can point to the FCB.
;
MOV AX,CS
MOV DS,AX
MOV DX,FCB ;File Control Block for COMMAND.COM
MOV AH,15
INT 33 ;Open COMMAND.COM
OR AL,AL
JNZ COMERR ;Error if file not found
XOR AX,AX
MOV [FCB+33],AX ; Set 4-byte Random Record field to
MOV [FCB+35],AX ; beginning of file.
INC AX
MOV [FCB+14],AX ;Set record length field
MOV AH,39 ;Block read (CX already set)
INT 33
JCXZ COMERR ;Error if no records read
TEST AL,1
JZ COMERR ;Error if not end-of-file
;
; Make all segment registers the same.
;
MOV DS,BX
MOV ES,BX
MOV SS,BX
MOV SP,5CH ;Set stack to standard value
XOR AX,AX
PUSH AX ;Put zero on top of stack for return
MOV DX,80H
MOV AH,26
INT 33 ;Set default transfer address (DS:0080)
PUSH BX ;Put segment on stack
MOV AX,100H
PUSH AX ;Put address to execute within segment on stack
RET L ;Jump to COMMAND
COMERR:
MOV DX,BADCOM
MOV AH,9 ;Print string
INT 33
EI
STALL: JP STALL
STCTAB: DB 17H ;Select master mode register
DW 84F3H ;Enable time-of-day
DB 1 ;Counter 1 mode register
DW 0138H
DB 2
DW 0038H
DB 3
DW 0008H ;Set counter 3 to count days
IF SERIAL
DB 0B7H, 77H, 4EH, 37H, PRNBAUD, AUXBAUD
ENDIF
BADCOM: DB 13,10,"Error in loading Command Interpreter",13,10,"$"
FCB: DB 1,"COMMAND COM"
DS 25
;
; ************ Time and Date ************
;
GETTIME:
MOV AL,0A7H ;Save counters 1,2,3
OUT STCCOM
MOV AL,0E0H ;Enable data pointer sequencing
OUT STCCOM
MOV AL,19H ;Select hold 1 / hold cycle
OUT STCCOM
CALL STCTIME ;Get seconds & 1/100's
XCHG AX,DX
CALL STCTIME ;Get hours & minutes
XCHG AX,CX
IN STCDATA
MOV AH,AL
IN STCDATA
XCHG AL,AH ;Count of days
JP POINTSTAT
STCTIME:
CALL STCBYTE
MOV CL,AH
STCBYTE:
IN STCDATA
MOV AH,AL
SHR AH
SHR AH
SHR AH
SHR AH
AND AL,0FH ;Unpack BCD digits
AAD ;Convert to binary
MOV AH,AL
MOV AL,CL
RET
SETTIME:
PUSH CX
PUSH DX
CALL LOAD0 ;Put 0 into load registers to condition timer
MOV AL,43H ;Load counters 1 & 2
OUT STCCOM
POP DX
POP CX
CALL LOAD
MOV AL,43H
OUT STCCOM ;Load counters 1&2
CALL LOAD0
MOV AL,27H ;Arm counters 1,2,3
OUT STCCOM
JP POINTSTAT
LOAD0:
XOR CX,CX
MOV DX,CX
LOAD:
MOV AL,09 ;Counter 1 load register
CALL OUTDX
MOV AL,0AH ;Counter 2 load register
MOV DX,CX
OUTDX:
OUT STCCOM ;Select a load register
MOV AL,DL
CALL OUTBCD
MOV AL,DH
OUTBCD:
AAM ;Convert binary to unpacked BCD
SHL AH
SHL AH
SHL AH
SHL AH
OR AL,AH ;Packed BCD
OUT STCDATA
RET
SETDATE:
XCHG AX,DX ;Put date in DX
MOV AL,0BH ;Select Counter 3 load register
OUT STCCOM
XCHG AX,DX
OUT STCDATA
MOV AL,AH
OUT STCDATA
MOV AL,44H ;Load counter 3
OUT STCCOM
POINTSTAT:
PUSH AX
MOV AL,1FH ;Point to status register
OUT STCCOM ; so power-off glitches won't hurt
POP AX
RET L
;
; ************ CONSOLE INPUT ************
;
IF INTINP-1 ; Non-interrupt driven input.
STATUS:
IN STAT
AND AL,DAV
JZ NOTHING ; Jump if nothing there.
PUSHF ; Save Z flag.
INB DATA
AND AL,7FH
SEG CS
MOV [QUEUE],AL ; Put new character in buffer.
POPF ; Return with Z flag clear.
RET L
NOTHING:
SEG CS
MOV AL,[QUEUE] ; See if there's anything in the buffer.
NOT AL ; Set up the Z flag.
TEST AL,80H
PUSHF
NOT AL
POPF
RET L
INP:
MOV AL,-1
SEG CS
XCHG AL,[QUEUE] ; Remove the character from the buffer.
AND AL,AL
JNS INRET ; Return if we have a character.
INLOOP:
IN STAT ; Wait till a character is available.
AND AL,DAV
JZ INLOOP
IN DATA
AND AL,7FH
INRET:
FLUSH:
RET L
QUEUE: DB -1 ; For storing characters from STATUS to INP.
ENDIF
IF INTINP ; Interrupt-driven input.
;
; Console keyboard interrupt handler.
;
KBINT:
PUSH AX
PUSH SI
MOV AL,20H ;End of Interrupt command
OUT BASE+2 ;Send to slave
IN DATA ;Get the character
AND AL,7FH
CMP AL,"C"-"@"
JZ FLSH
CMP AL,"S"-"@"
JZ FLSH
CMP AL,"F"-"@"
JNZ SAVKY
FLSH:
CALL 13*3,BIOSSEG ; Call I/O system keyboard buffer flush.
SAVKY:
SEG CS
MOV SI,[REAR] ;Pointer to rear of queue
CALL INCQ
SEG CS
CMP SI,[FRONT] ;Any room in queue?
JZ QFULL
SEG CS
MOV [SI],AL ;Put character in queue
SEG CS
MOV [REAR],SI ;Save pointer
LEAVINT:
POP SI
POP AX
IRET
QFULL:
MOV AL,7 ; BELL character.
CALL 3*3,BIOSSEG ; Call I/O system console output function.
JMPS LEAVINT
STATUS:
PUSH SI
;See if printer ready
IN PRNSTAT
AND AL,TBMT
JZ NOPRN
SEG CS
MOV SI,[PFRONT]
SEG CS
CMP SI,[PREAR] ;Anything in print queue?
JNZ SENDPRN
SEG CS
CMP B,[PRNFCB],-1 ;Print spooling in progress?
JZ NOPRN ;If not, nothing to print
;Print spooling in progress. Get next buffer
PUSH DS
PUSH CS
POP DS
PUSH AX
PUSH CX
PUSH DX
PUSH [STKSAV]
PUSH [STKSAV+2]
PUSH [DMAADD]
PUSH [DMAADD+2]
MOV DX,PQUEUE
MOV AH,26 ;Set DMA address
INT 33
MOV DX,PRNFCB
MOV CX,PBUFSIZ
MOV AH,39 ;Read buffer
INT 33
OR AL,AL
JZ NOTEOF
MOV B,[PRNFCB],-1 ;Turn off print spooling at EOF
NOTEOF:
POP [DMAADD+2]
POP [DMAADD]
POP [STKSAV+2]
POP [STKSAV]
MOV SI,CX
POP DX
POP CX
POP AX
POP DS
OR SI,SI
JZ NOPRN
ADD SI,PQUEUE-1
SEG CS
MOV [PREAR],SI
MOV SI,ENDPQ-1
SENDPRN:
CALL INCPQ
SEG CS
MOV [PFRONT],SI
SEG CS
LODSB ;Get character to print
OUT PRNDATA
NOPRN:
DI ; Disable interrupts while checking queue.
SEG CS
MOV SI,[FRONT]
SEG CS
CMP SI,[REAR] ; Anything in queue?
JZ NOCHR ; Jump if nothing in queue.
CALL INCQ
SEG CS
LODSB ;Get character (if there is one)
OR SI,SI ;Reset zero flag
NOCHR:
EI
POP SI
RET L ;Zero clear if we have a character
INP:
CALL STATUS,BIOSSEG ; Get I/O system console input status.
JZ INP
PUSH SI
DI ; Disable interrupts while changing queue pointers.
SEG CS
MOV SI,[FRONT]
CALL INCQ ; Permanently remove char from queue
SEG CS
MOV [FRONT],SI
EI
POP SI
RET L
FLUSH:
DI
SEG CS
MOV [REAR],QUEUE
SEG CS
MOV [FRONT],QUEUE
EI
RET L
INCQ:
INC SI
CMP SI,ENDQ ;Exceeded length of queue?
JB RET
MOV SI,QUEUE
RET
INCPQ:
INC SI
CMP SI,ENDPQ ;Exceeded length of queue?
JB RET
MOV SI,PQUEUE
RET
FRONT: DW QUEUE
REAR: DW QUEUE
QUEUE: DS QSIZE
ENDQ: EQU $
PFRONT: DW PQUEUE
PREAR: DW PQUEUE
PQUEUE: DS PBUFSIZ
ENDPQ: EQU $
PRNFCB: DB -1
DS 36
ENDIF
;
; ************ Console and Printer Output ************
;
OUTP:
PUSH AX
OUTLP:
IN STAT
AND AL,TBMT
JZ OUTLP
POP AX
OUT DATA
RET L
PRINT:
PUSH SI
SEG CS
MOV SI,[PREAR]
CALL INCPQ
PRINLP:
SEG CS
CMP SI,[PFRONT]
JNZ PRNCHR
;Print queue is full
PUSH AX
CALL STATUS,BIOSSEG ;Poll and maybe print something
POP AX
JMPS PRINLP
PRNCHR:
SEG CS
MOV [PREAR],SI
SEG CS
MOV [SI],AL
POP SI
RET L
;
; ************ Auxiliary I/O ************
;
AUXIN:
IN AUXSTAT
AND AL,DAV
JZ AUXIN
IN AUXDATA
RET L
AUXOUT:
PUSH AX
AUXLP:
IN AUXSTAT
AND AL,TBMT
JZ AUXLP
POP AX
OUT AUXDATA
RET L
;
; ************ 1771/1793-type controller disk I/O ************
;
TARBELL:EQU TARBELLSD+TARBELLDD
CROMEMCO:EQU CROMEMCO4FDC+CROMEMCO16FDC
WD1791: EQU SCP+TARBELLDD+CROMEMCO16FDC
WD1771: EQU TARBELLSD+CROMEMCO4FDC
IF WD1791
READCOM:EQU 80H
WRITECOM:EQU 0A0H
ENDIF
IF WD1771
READCOM:EQU 88H
WRITECOM:EQU 0A8H
ENDIF
IF SCP
SMALLBIT:EQU 10H
BACKBIT:EQU 04H
DDENBIT:EQU 08H
DONEBIT:EQU 01H
DISK: EQU 0E0H
ENDIF
IF TARBELL
BACKBIT:EQU 40H
DDENBIT:EQU 08H
DONEBIT:EQU 80H
DISK: EQU 78H
ENDIF
IF CROMEMCO
SMALLBIT:EQU 10H
BACKBIT:EQU 0FDH ; Send this to port 4 to select back.
DDENBIT:EQU 40H
DONEBIT:EQU 01H
DISK: EQU 30H
ENDIF
IF SMALLDS-1
SMALLDDSECT: EQU 8
ENDIF
IF SMALLDS
SMALLDDSECT: EQU 16
ENDIF
IF LARGEDS-1
LARGEDDSECT: EQU 8
ENDIF
IF LARGEDS
LARGEDDSECT: EQU 16
ENDIF
;
; Disk change function.
; On entry:
; AL = disk drive number.
; On exit:
; AH = -1 (FF hex) if disk is changed.
; AH = 0 if don't know.
; AH = 1 if not changed.
;
; CF clear if no disk error.
; AL = disk I/O driver number.
;
; CF set if disk error.
; AL = disk error code (see disk read below).
;
IF WD1771
DSKCHG:
MOV AH,0 ; AH = 0 in case we don't know.
SEG CS
CMP AL,[CURDRV]
JNZ RETL
PUSH AX ; Save drive number.
IF CROMEMCO
INB DISK+4
ENDIF
IF TARBELL
INB DISK
ENDIF
AND AL,20H ; Look at head load bit
POP AX
JZ RETL
MOV AH,1 ; AH = 1, disk not changed.
RETL:
CLC ; No disk error.
RET L
ENDIF ; End of 1771 DSKCHG.
IF WD1791
DSKCHG:
MOV AH,0 ; AH = 0 in case we don't know.
SEG CS
CMP AL,[CURDRV]
JNZ DENSCHK ; Check density if not same drive.
PUSH AX
IF SCP+CROMEMCO
INB DISK+4
ENDIF
IF TARBELL
INB DISK
ENDIF
AND AL,20H ; Look at head load bit
POP AX
JZ DENSCHK ; Check density if head not loaded.
MOV AH,1 ; AH = 1, disk not changed.
MOV BX,PREVDENS
SEG CS
XLAT ; Get previous density
CLC ; No disk error.
RET L
DENSCHK:
CALL CHKNEW ; Unload head if selecting new drive.
CBW
XCHG AX,SI
ADD SI,PREVDENS
MOV CX,4 ; Try each density twice
MOV AH,0 ; Disk may not have been changed.
CHKDENS:
SEG CS
MOV AL,[SI] ; Get previous disk I/O driver number.
MOV BX,DRVTAB
SEG CS
XLAT ; Get drive select byte for previous density
IF CROMEMCO16FDC
CALL MOTOR ; Wait for motor to come up to speed.
ENDIF
OUT DISK+4 ; Select disk
MOV AL,0C4H ; READ ADDRESS command
CALL DCOM
AND AL,98H
IN DISK+3 ; Eat last byte to reset DRQ
JZ HAVDENS ; Jump if no error in reading address.
NOT AH ; AH = -1 (disk changed) if new density works.
SEG CS
XOR B,[SI],1 ; Try other density
LOOP CHKDENS
MOV AX,2 ; Couldn't read disk at all, AH = 0 for don't
STC ; know if disk changed, AL = error code 2 -
RET L ; disk not ready, carry set to indicate error.
HAVDENS:
SEG CS
LODSB ; AL = disk I/O driver number.
CLC ; No disk error.
RET L
PREVDENS:DB 1,3,5,7,9,11,13 ; Table of previous disk I/O driver numbers.
ENDIF ; End of 1793 DSKCHG function.
CHKNEW:
MOV AH,AL ; Save disk drive number in AH.
SEG CS ; AL = previous disk drive number,
XCHG AL,[CURDRV] ; make new drive current.
CMP AL,AH ; Changing drives?
JZ RET
;
; If changing drives, unload head so the head load delay one-shot will
; fire again. Do it by seeking to the same track with the H bit reset.
;
IN DISK+1 ; Get current track number
OUT DISK+3 ; Make it the track to seek to
MOV AL,10H ; Seek and unload head
CALL DCOM
MOV AL,AH ; Restore current drive number
RET
IF CROMEMCO16FDC
MOTOR:
PUSH AX
MOV AH,AL
IN DISK+4 ; See if the motor is on.
TEST AL,08H
MOV AL,AH
OUTB DISK+4 ; Select drive & start motor.
JNZ MOTORSON ; No delay if motors already on.
PUSH CX
MOV CX,43716 ; Loop count for 1 second.
MOTORDELAY: ; (8 MHz, 16-bit memory).
AAM ; 83 clocks.
AAM ; 83 clocks.
LOOP MOTORDELAY ; 17 clocks.
POP CX
MOTORSON:
POP AX
RET
ENDIF
;
; Disk read function.
;
; On entry:
; AL = Disk I/O driver number
; BX = Disk transfer address in DS
; CX = Number of sectors to transfer
; DX = Logical record number of transfer
; On exit:
; CF clear if transfer complete
;
; CF set if hard disk error.
; CX = number of sectors left to transfer.
; AL = disk error code
; 0 = write protect error
; 2 = not ready error
; 4 = "data" (CRC) error
; 6 = seek error
; 8 = sector not found
; 10 = write fault
; 12 = "disk" (none of the above) error
;
READ:
CALL SEEK ;Position head
JC ERROR
PUSH ES ; Make ES same as DS.
MOV BX,DS
MOV ES,BX
RDLP:
CALL READSECT ;Perform sector read
JC POPESERROR
INC DH ;Next sector number
LOOP RDLP ;Read each sector requested
CLC ; No errors.
POP ES ; Restore ES register.
RET L
;
; Disk write function.
; Registers same on entry and exit as read above.
;
WRITE:
CALL SEEK ;Position head
JC ERROR
WRTLP:
CALL WRITESECT ;Perform sector write
JC ERROR
INC DH ;Bump sector counter
LOOP WRTLP ;Write CX sectors
CLC ; No errors.
WRITERET:
RET L
POPESERROR:
POP ES ; Restore ES register.
ERROR:
MOV BL,-1
SEG CS
MOV [DI],BL ; Indicate we don't know where head is.
MOV SI,ERRTAB
GETCOD:
INC BL ; Increment to next error code.
SEG CS
LODB
TEST AH,AL ; See if error code matches disk status.
JZ GETCOD ; Try another if not.
MOV AL,BL ; Now we've got the code.
SHL AL ; Multiply by two.
STC
RET L
ERRTAB:
DB 40H ;Write protect error
DB 80H ;Not ready error
DB 8 ;CRC error
DB 2 ;Seek error
DB 10H ;Sector not found
DB 20H ;Write fault
DB 7 ;"Disk" error
;
; Direct disk read and write from INT 37 and INT 38. Subroutine GETIODRIVER
; calls DSKCHG to convert disk drive number to I/O driver number.
;
; Setting CURDRV to -1 before calling DSKCHG forces DSKCHG to check the disk's
; density before returning the I/O driver number. This is necessary because
; programs such as FORMAT could change the density of a disk and leave the
; head loaded. If the head is loaded DSKCHG assumes the disk hasn't been
; changed and returns the old I/O driver number which could be wrong.
;
; CURDRV is set to -1 before returning so when DSKCHG is called by the
; operating system, it will tell the operating system the disk may have
; been changed (because it may have been).
;
DIRECTREAD:
IF WD1791
CALL GETIODRIVER ; Convert drive number to I/O driver number.
JC DIRECTRET ; Return if DSKCHG returned error.
ENDIF
CALL 7*3,BIOSSEG ; Call READ.
JMPS DIRECTRET
DIRECTWRITE:
IF WD1791
CALL GETIODRIVER ; Convert drive number to I/O driver number.
JC DIRECTRET ; Return if DSKCHG returned error.
ENDIF
CALL 8*3,BIOSSEG ; Call WRITE.
DIRECTRET:
SEG CS
MOV B,[CURDRV],-1 ; Force DSKCHG to do density check.
RET L
IF WD1791
GETIODRIVER:
SEG CS
MOV B,[CURDRV],-1 ; Force DSKCHG to do density check.
PUSH BX
PUSH CX
CALL 9*3,BIOSSEG ; Call DSKCHG.
POP CX
POP BX
RET
ENDIF
;
; Function:
; Seeks to proper track.
; On entry:
; Same as for disk read or write above.
; On exit:
; AH = Drive select byte
; DL = Track number
; DH = Sector number
; SI = Disk transfer address in DS
; DI = pointer to drive's track counter in CS
; CX unchanged (number of sectors)
;
SEEK:
MOV SI,BX ; Save transfer address
CBW
MOV BX,AX ; Prepare to index on drive number
IF WD1791 ; If two disk formats per drive.
SHR AL ; Convert to physical disk drive number.
ENDIF
CALL CHKNEW ; Unload head if changing drives.
SEG CS
MOV AL,[BX+DRVTAB] ; Get drive-select byte.
IF CROMEMCO16FDC
CALL MOTOR ; Wait for the motors to come up to speed.
ENDIF
OUTB DISK+4 ; Select drive.
IF CROMEMCO
OR AL,80H ; Set auto-wait bit.
ENDIF
MOV AH,AL ; Save drive-select byte in AH.
XCHG AX,DX ; AX = logical sector number.
MOV DL,26 ; 26 sectors/track unless changed below
IF SCP
TEST DH,SMALLBIT ; Check if small disk.
JZ BIGONE ; Jump if big disk.
MOV DL,18 ; Assume 18 sectors on small track.
TEST DH,DDENBIT ; Check if double-density.
JZ HAVSECT ; Jump if not.
MOV DL,SMALLDDSECT ; Number of sectors on small DD track.
JP HAVSECT
BIGONE:
TEST DH,DDENBIT ; Check if double-density.
JZ HAVSECT ; Jump if not.
MOV DL,LARGEDDSECT ; Number of sectors on big DD track.
ENDIF
IF TARBELLDD ; Tarbell DD controller.
TEST DH,DDENBIT ; Check for double-density.
JZ HAVSECT
MOV DL,LARGEDDSECT ; Number of sectors on DD track.
ENDIF