PGM DKTEST
        REL
*
* SHOULD BE LOADED AT ABSOLUTE LOCATION #4000
*
BASE    EQU #78     BASE ADDRESS OF CHANNEL
*
* FORMAT DISK ON DRIVE 0
*
START   MOV AX,!#000
        MOV SS,AX
        MOV DS,AX
        MOV ES,AX
        MOV SP,!#41F0
        CALL RESET
        XOR CX,CX
        PUSH CX
        MOV BL,!0      UNIT 0
        CALL RECAL     RECALIBRATE DRIVE
        CALL WAITC
        OR AL,AL
        JE GF2
        INT            ERROR
GNEXT   EQU $
GF2     POP CX
        PUSH CX
        MOV BL,!0      UNIT 0
* TEST READING SECTOR 1 ON TRACK 0
        MOV AL,!4
        MOV CL,!1
        MOV DX,!#5000
        CALL DISKINS
        CALL WAITC
        OR AL,AL
        INT
GF3     POP CX
        INC CH
        PUSH CX
        CMP CH,!77
        JL GNEXT
        INT
*
*
IOPB    DB #T01000000   RAND. FORMAT, EN INTS, WORD LENGTH 8
IODI    DB 0            DISKETTE INSTRUCTION
IONR    DB 1            NO. OF RECORDS
IOTA    DB 0            TRACK ADDRESS
IOSA    DB 0            SECTOR ADDRESS
IOLBA   DB 0            LOWER BUFF. ADD.
IOUBA   DB 0            UPPER BUFF. ADD.
*
* RECALIBRATE
*
RECAL   MOV AL,!RECALIN   BL SHOULD HOLD UNIT NO.
        XOR DX,DX
       MOV CX,!1       TRACK ADDRESS 0, SECTOR ADD. 1
        CALL DISKINS
        RET
*
* GENERAL DISK INSTRUCTION
*   BL   UNIT NO.
*   AL   INSTRUCTION
*   CH   TRACK ADDRESS
*   CL   SECTOR ADDRESS
*   DH   UPPER BUFFER ADDRESS
*   DL   LOWER BUFFER ADDRESS
*
DISKINS MOV IOTA,CH
        MOV IOSA,CL
        OR AL,!#T0000        8 BIT WORDS
        MOV CL,!4
        SHL BL,CL            SHIFT UNIT BITS
        OR AL,BL             OR WITH INST.
        AND AL,!#3F          CLEAR TOP 2 BITS
        MOV IODI,AL
        MOV IOLBA,DL
        MOV IOUBA,DH
        MOV AX,!IOPB
        OUT BASE+1
        MOV AL,AH
        PUSH AX
        POP AX
        OUT BASE+2           START CHANNEL
        RET
*
* FORMAT,
*   BL    UNIT NO.
*   CH    TRACK ADDRESS
*
FORMAT  MOV AL,!FORMIN
       MOV CL,!1             SAY SECTOR ADDRESS 1
        MOV DX,!FCH    FORMAT CHAR. BUFF.
        CALL DISKINS
        RET
*
* WAITC, WAIT FOR CHANNEL END , LOOK AT RESULT
*
WAITC   IN BASE+0
        TEST AL,!INTPEND
        JE WAITC              BUSY WAIT
        PUSH AX
        POP AX
        IN BASE+1             0 IF ERROR
       MOV AH,AL
        PUSH AX
        POP AX
       IN BASE+3             RESULT BYTE
        RET
*
* RESET CHANNEL
*
RESET   OUT BASE+7
        RET
*
*
*
RECALIN EQU 3
FORMIN  EQU 2
INTPEND EQU 4
*
FCH     EQU $
        DW 1
        DW 2
        DW 3
        DW 4
        DW 29
        DW 30
        DW 31
        DW 32
        DW 5
        DW 6
        DW 7
        DW 8
        DW 33
        DW 34
        DW 35
        DW 36
        DW 9
        DW 10
        DW 11
        DW 12
        DW 37
        DW 38
        DW 39
        DW 40
        DW 13
        DW 14
        DW 15
        DW 16
        DW 41
        DW 42
        DW 43
        DW 44
        DW 17
        DW 18
        DW 19
        DW 20
        DW 45
        DW 46
        DW 47
        DW 48
        DW 21
        DW 22
        DW 23
        DW 24
        DW 49
        DW 50
        DW 51
        DW 52
        DW 25
        DW 26
        DW 27
        DW 28
*
        END