          NAM HDPARK
          OPT PAG
          PAG
* HD-PARK PROGRAM FOR SK*DOS 68K
* SUPPORTS THE PERIPHERAL TECH PT-68K COMPUTER WINCHESTER
* COPYRIGHT (C) 1986 BY PETER A. STARK
* FOR STAR-K SOFTWARE SYSTEMS CORP.

* SK*DOS EQUATES

          LIB     SKEQUATE
WINTAB    EQU $200                 OFFSET FOR DOS'S WINTAB

WDREAD    EQU $E0020 READ DATA REGISTER
WDWRIT    EQU WDREAD WRITE DATA REGISTER
WDERRO    EQU $E0024 ERROR REGISTER
WDWPRE    EQU WDERRO WRITE PRECOMP REGISTER
WDSCNT    EQU $E0028 SECTOR COUNT REGISTER
WDSNUM    EQU $E002C SECTOR NUMBER
WDCYLO    EQU $E0030 CYLINDER NUMBER - LOW ORDER BYTE
WDCYHI    EQU $E0034 CYLINDER NUMBER - HIGH ORDER BYTE
WDSDHR    EQU $E0038 SIZE,DRIVE,HEAD REGISTER
WDSTAT    EQU $E003C STATUS REG - READ ONLY
WDCOMA    EQU WDSTAT COMMAND REG - WRITE ONLY


START     BRA.S START1

          DC.W  $0101              VERSION

START1    DC VPOINT
          MOVE.L LPOINT(A6),A5     POINT TO NEXT CHAR
          MOVE.B (A5),D7           GET NEXT CHAR
          CMP.B #$33F,D7           ??
          BEQ.L HELP               HELP IF QUESTION MARK
          MOVE.L DOSORG(A6),A0
          LEA WINTAB(A0),A0        POINT TO SK*DOS WINTAB
          MOVE.L A0,A1             DITTO
          MOVE.B #$88,D0           SDH CODE FOR DRIVE A
          MOVE.B #$20,D1           H0 CODE
          MOVE.B #$41,D2           A
          BSR.S PARKIT             GO PARK DRIVE A
          LEA 64(A0),A1            POINT TO WINTAB DRIVE B ENTRY
          MOVE.B #$90,D0           SDH CODE FOR DRIVE B
          MOVE.B #$24,D1           H1 CODE
          MOVE.B #$42,D2           B
          BSR.S PARKIT             GO PARK DRIVE B
          CLR.B WDSDHR             DESELECT DRIVES
          DC WARMST                THEN RETURN TO SK*DOS

* PARKIT SUBROUTINE - DETERMINE WHETHER DIVE EXISTS, AND
* GO PARK IT IF IT DOES.

PARKIT    CMP.B 0(A1),D1           CHECK ENTRY
          BNE.S PARRTS             RETURN IF NO SUCH DRIVE

          MOVE.B 1(A1),D7          STEP RATE FOR DRIVE
          ADD.B #$70,D7            SEEK COMMAND
          MOVE.W 12(A1),D6         PARK CYLINDER
          MOVE.B D6,WDCYLO         GIVE CYLINDER TO WD
          LSR.W #8,D6
          MOVE.B D6,WDCYHI         DITTO
          MOVE.B D0,WDSDHR         SELECT DRIVE
          MOVE.B D7,WDCOMA         GIVE SEEK COMMAND
          LEA PDRMSG(PC),A4
          DC PSTRNG                PRINT "PARKING DRIVE "
          MOVE.B D2,D4
          DC PUTCH                 PRINT A OR B
          BSR.S CHBUSY             WAIT UNTIL FINISHED
PARRTS    RTS                      AND RETURN


* CHBUSY - WAIT IF BUSY, BUT ABORT IF IT TAKES TOO LONG

CHBUSY    MOVE.L #$100000,D6        TIMEOUT COUNTER
CHBUS1    SUB.L #1,D6              DROP TIMEOUT COUNT
          BEQ.S CHBUS2             SOMETHING WRONG?
          TST.B WDSTAT             CHECK WD1002 STATUS
          BMI.S CHBUS1             WAIT UNTIL NOT BUSY
          RTS

CHBUS2    CLR.B WDSDHR             DESELECT DRIVE
          LEA RESMSG(PC),A4
          DC PSTRNG                PRINT "HARDWARE PROBLEM - SLOW
          DC WARMST                AND QUIT

* PRINT HELP MESSAGE

HELP      LEA HLPMSG(PC),A4
          DC PSTRNG
          DC WARMST

* TEST STRINGS

HLPMSG    DC.B 'PARK is used to park the heads on all hard drives currently'
          DC.B $0D,$0A
          DC.B 'on line. This is an absolute necessity if the system is to'
          DC.B $0D,$0A
          DC.B 'be moved, and is probably a good idea at other times as well,'
          DC.B $0D,$0A
          DC.B 'as it moves the heads to a part of the disk which does not'
          DC.B $0D,$0A
          DC.B 'normally hold any data and which would therefore not be'
          DC.B $0D,$0A
          DC.B 'damaged by the head landing on it when power is shut off.'
          DC.B $0D,$0A
          DC.B 'The syntax is simply'
          DC.B $0D,$0A
          DC.B '   PARK'
          DC.B $0D,$0A
          DC.B 'with no other arguments.',4
PDRMSG    FCC 'Parking drive ',4
RESMSG    FCC 'Hardware problem - BUSY too long - parking aborted.',4

          END START
