                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Module: Cmnd1  { continuation of the command processor module }
;>
;>      PROCEDURE D_Read
;>      PROCEDURE D_ReadHdr
;>      PROCEDURE D_Write
;>      PROCEDURE Read_CStatus
;>      PROCEDURE Read_SStatus
;>      PROCEDURE Send_ServoCmnd
;>      PROCEDURE Send_Seek
;>      PROCEDURE Send_Restore
;>      PROCEDURE Send_Park
;>      PROCEDURE Set_Ram_Addr
;>      PROCEDURE Wr_SprTbl
;>      PROCEDURE Format
;>      PROCEDURE Read_Abort
;>      PROCEDURE D_RstSrvo
;>      PROCEDURE D_InitSprTbl
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Procedure: D_Read
;>
;>      This procedure is used by the Host to invoke the primitive
;>      read function. The block that is read by this routine is the
;>      last seek address ( cylinder, head, and sector ). It is
;>      best to turn recovery OFF before using this command - as it
;>      is when using ALL diagnostic commands.
;>
;>      Inputs: { none }
;>
;>      Outputs: { none }
;>
;>      Algorithm:
;>
;>      BEGIN
;>       ClrNormStat
;>       Ack_Read( D_Read_Response )
;>       IF NOT( Read_Common )
;>        THEN Data_Ex_Handler( Read_Common.ErrorCode )
;>       Rd_Leave
;>      END
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     Internal
                .LSTON
                .Page
                .FIN

D_Read:
                Call    ClrNormStat
                
                 Ld     Wrk_Io+$A,#D_Read_Response
                Call    Ack_Read
                
                Ld      Data_Type,#User_Type
                And     DiskStat,#$FF-Wr_Op
                Call    Read_Common
                Jr      Nz,D_Read_End
                
                 Ld     !r0,#Error
                Call    Data_Ex_Handler
                
D_Read_End:     Jp      Rd_Leave
                
                .LSTOFF
                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Procedure: D_ReadHdr
;>
;>      This diagnostic command is used to read the header ( and whatever
;>      the contents may be ) of the block pointed to by the last seek 
;>      address. The host should be cautioned that the buffer that the
;>      controller points it to at the completion of the read is longer
;>      than a normal read buffer by the length of the header and the
;>      data gap.
;>
;>      Inputs: { none }
;>
;>      Outputs: { none }
;>
;>      Algorithm:
;>
;>      BEGIN
;>       ClrNormStat
;>       Ack_Read( D_RdHdr_Response )
;>       Sector := Ld_Param1.First
;>       LocateSector
;>       ReadHdr
;>       IF ReadHdr.ServoErr THEN SetStatus( Byte0, ServoEror )
;>       IF ReadHdr.CrcErr THEN SetStatus( Byte0, ReadError )
;>       Move4( RdHdrStatusArray, CStatus0 )
;>       Clr_Bsy( RdHdrStatusArray )
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     Internal
                .LSTON
                .Page
                .FIN

D_ReadHdr:
                Call    ClrNormStat
                
                 Ld     Wrk_Io+$A,#D_RdHdr_Response
                Call    Ack_Read
                
                Call    Ld_Param1
                
                Ld      Sector,!r0 ;load new sector
                 Ld     !r2,#.HIBYTE. LocateSector
                 Ld     !r3,#.LOWBYTE. LocateSector
                Call    Bank_Call
                
                Ld      Data_Type,#User_Type
                And     DiskStat,#$FF-Wr_Op
                
                 Ld     !r2,#.HIBYTE. ReadHdr
                 Ld     !r3,#.LOWBYTE. ReadHdr
                Call    Bank_Call
                
                Push    !r0 ;save status byte
                
                Tm      !r0,#RdHSrvoErr ;IF ReadHdr.ServoErr
                Jr      Z,D_RdH_Crc
                
                 Clr    !r0 ;byte0
                 Ld     !r1,#Stat_Srvo
                Call    SetStatus
                
D_RdH_Crc:      Pop     !r0
                Tm      !r0,#RdCrcErr
                Jr      Z,D_RdH_End
                
                 Clr    !r0 ;byte 0
                 Ld     !r1,#Stat_Rd_Err
                Call    SetStatus
                
D_RdH_End:       Ld     !r2,#.HIBYTE. CStatus0
                 Ld     !r3,#.LOWBYTE. CStatus0
                 Ld     !rE,#.HIBYTE. RdH_Stat_Array
                 Ld     !rF,#.LOWBYTE. RdH_Stat_Array
                Call    Move4_B0
                
                Srp    #Wrk_Io
                 Ld     !rA,#Init_Response
                 Clr    !rB
                 Ld     !rC,#.HIBYTE. RdH_Stat_Array
                 Ld     !rD,#.LOWBYTE. RdH_Stat_Array
                Jp      Clr_Bsy
                
                .LSTOFF
                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Procedure: D_Write
;>
;>      This procedure, like D_Read, allows the host to perform
;>      a single write to the last seek address. KEEP IN MIND THAT
;>      THIS ROUTINE WILL ALLOW YOU TO WRITE ANYWHERE ON THE DISK THAT
;>      YOU CARE TO WRITE!!!!
;>
;>      Inputs: { none }
;>
;>      Outputs: { none }
;>
;>      Algorithm:
;>
;>      BEGIN
;>       ClrNormStat
;>       Get_Wr_Data( D_Write_Response )
;>       IF NOT( Write_Common )
;>        THEN Data_Ex_Handler( Wr_Common.ErrorCode )
;>       Rd_Leave
;>      END
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     Internal
                .LSTON
                .Page
                .FIN

D_Write:
                Call    ClrNormStat
                
                Ld      Data_Type,#User_Type
                Or      DiskStat,#Wr_Op
                
                 Ld     Wrk_Io+$A,#D_Write_Response
                Call    Get_Wr_Data
                
                Call    Wr_Common
                Jr      Nz,D_Write_End
                
                 Ld     !r0,#Error
                Call    Data_Ex_Handler
                
D_Write_End:    Jp      Rd_Leave
                
                .LSTOFF
                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Procedure: Read_CStatus
;>
;>      This procedure allows the host to read any of the controllers
;>      status'. These status' all come in 4 byte quantities:
;>      
;>      Status0: Standard_Status { sent to the host at the completion
;>                                 of a command - note that a request
;>                                 for status is NOT a command }
;>      Status1: Last_Logical_Block { 0, HiByte, MidByte, LoByte }
;>      Status2: Last_Seek_Address { HiCylinder, LoCylinder, Head, Sector }
;>      Status3: Current_Cylinder { HiCylinder, LoCylinder, 0, 0 }
;>      Status4: Internal_Stat { Excpt_Stat, DiskStat, BlkStat, 0 }
;>      Status5: Cntrl_Port { 0, SlfTst_Result, 0, Controller_Port }
;>      Status6: Error_Status { RdStat, RdErrCnt, WrStat, WrErrCnt }
;>      Status7: Last_Seek_Address { Lst_HiCyl, Lst_LoCyl, Lst_Head,
;>                                   Lst_Sector }
;>
;>      { all illegal status requests will return standard status }
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     Internal
                .LSTON
                .Page
                .FIN

Read_CStatus:
                 Ld     Wrk_Io+$A,#Rd_Stat_Response
                Call    Ack_Read
                
                Ld      !rE,#.HIBYTE. StatusArray
                Ld      !rF,#.LOWBYTE. StatusArray
                
                Call    Ld_Param1
                
                And     !r0,#$0F ;mask off all but legal status request
                Cp      !r0,#7 ;check for except case
                Jp      Gt,Rd_Leave
                
                Ld      !r2,#.HIBYTE. Stat_Table
                Ld      !r3,#.LOWBYTE. Stat_Table
                Rl      !r0
                Add     !r3,!r0
                Adc     !r2,#0
                Ldc     !rC,@!!r2
                Incw    !!r2
                Ldc     !rD,@!!r2
                Jp      @!rC
                
Stat_Table:     .DW     Rd_Leave
                .DW     Ld_Stat1
                .DW     Ld_Stat2
                .DW     Ld_Stat3
                .DW     Ld_Stat4
                .DW     Ld_Stat5
                .DW     Ld_Stat6
                .DW     Ld_Stat7
                
Ld_Stat1:       Incw    !!rE
                Ld      !r2,#.HIBYTE. LogicalBlock
                Ld      !r3,#.LOWBYTE. LogicalBlock
                Call    Move4_B0
                Jr      Ld_Stat_End
                
Ld_Stat2:       Ld      !r0,#Cylinder
Ld_Stat2_1:     Ld      !r1,#4 ;move 4 bytes
Ld_Stat2_Lp:    Ldei    @!!rE,@!r0
                Djnz    !r1,Ld_Stat2_Lp
                Jr      Ld_Stat_End
                
Ld_Stat3:       Ld      !r0,#Cur_Cyl
                Jr      Ld_Stat2_1
                
Ld_Stat4:       Ld      !r0,Excpt_Status
                Ld      !r1,DiskStatus
                Ld      !r2,BlkStat
                Ld      !r3,Data_Type
                Jr      Ld_Stat_Reg
                
Ld_Stat5:       Ld      !r0,#0
                Ld      !r1,SlfTst_Result
                Ld      !r2,Port2
                Ld      !rC,#.HIBYTE. Status_Port
                Ld      !rD,#.LOWBYTE. Status_Port
                Lde     !r3,@!!rC
                Jr      Ld_Stat_Reg
                
Ld_Stat6:       Ld      !r0,RdStat
                Ld      !r1,RdErrCnt
                Ld      !r2,WrStat
                Ld      !r3,WrErrCnt
                Jr      Ld_Stat_Reg
                
Ld_Stat7:       Ld      !r0,Lst_HiCyl
                Ld      !r1,Lst_LoCyl
                Ld      !r2,Lst_Head
                Ld      !r3,Lst_Sector
                
Ld_Stat_Reg:    Ld      !r4,Rp
                Ld      !r5,#4 ;move 4 bytes
Stat5_Lp:       Ldei    @!!rE,@!r4
                Djnz    !r5,Stat5_Lp
                
Ld_Stat_End:     Ld     Wrk_Io+$A,#Init_Response
                 Clr    Wrk_Io+$B
                Jp      Rd_Leave1

                .LSTOFF
                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Procedure: Read_SStatus
;>
;>      This procedure is used by the host to examine the servo processor's
;>      status information. The controller makes NO assumptions concerning
;>      knowledge or meaning of the status bits, nor does the controller
;>      interpret the status request sent by the host. In other words,
;>      when the host issues a request for status to the servo, it is
;>      his responsibility to make certain that the request is meaningful.
;>
;>      The returned status is preceded by Standard Status.
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     Internal
                .LSTON
                .Page
                .FIN

Read_SStatus:
                Call    ClrNormStat
                
                 Ld     Wrk_Io+$A,#Rd_SStat_Response
                Call    Ack_Read
                
                Call    Ld_Param1
                
                Call    Set_Dmt
                 Ld     ScrReg3,!r0
                 Ld     ScrReg0,#ReadStatus
                 Ld     ScrReg1,#0
                 Ld     ScrReg2,#0
                 Ld     !r2,#.HIBYTE. ServoStatus
                 Ld     !r3,#.LOWBYTE. ServoStatus
                Call    Bank_Call
                Call    Clr_Dmt
                
                Call    Ld_Stand_Stat
                
                 Ld     !r2,#.HIBYTE. SStatus0
                 Ld     !r3,#.LOWBYTE. SStatus0
                Call    Move4_B0
                
                Jr      Ld_Stat_End
                
                
Ld_Param1:      Ld      ScrReg4,Rp
                Push    Rp
                Srp     #Wrk_Scr
                
                Ld      !rE,#.HIBYTE. ( CStatus4 + 2 )
                Ld      !rF,#.LOWBYTE. ( CStatus4 + 2 )
                Ld      !r5,#4 ;load 4 bytes
Rd_SStat_Lp:    Ldei    @!r4,@!!rE
                Djnz    !r5,Rd_SStat_Lp
                
                Pop     Rp ;get back to original context
                Ret
                
                .LSTOFF
                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Procedure: Send_ServoCmnd
;>
;>      This procedure is used by the host to send the servo a command
;>      of any type EXCEPT a status request ( use Read_SStatus for that ).
;>      The controller will Abort the operation if this servo command
;>      is sent to it.
;>
;>      Also, as in Read_SStatus, the host is responsible for the the
;>      command string that it send to the servo - all the Widget
;>      controller will do is pass along the command string.
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     Internal
                .LSTON
                .Page
                .FIN

Send_ServoCmnd:
                Call    ClrNormStat
                
                 Ld     Wrk_Io+$A,#Sd_S_C_Response
                Call    Ack_Read
                
                Call    Ld_Param1 ;get servo command
                Or      !r0,!r0 ;check for Status Command
                Jr      Nz,S_Scmnd
                
                Call    Abort
                
S_Scmnd:        Call    Set_Dmt
                 Ld     ScrReg0,!r0
                 Ld     ScrReg1,!r1
                 Ld     ScrReg2,!r2
                 Ld     ScrReg3,!r3
                 Ld     !r2,#.HIBYTE. ServoCmnd
                 Ld     !r3,#.LOWBYTE. ServoCmnd
                Call    Bank_Call
                Call    Clr_Dmt
                
                Jp      Rd_Leave
                
                .LSTOFF
                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Procedure: Send_Seek
;>
;>      This procedure allows the host to position the heads ANYWHERE
;>      on the disk service that it pleases - the only consideration
;>      is to be aware of the crash stop positions!
;>
;>      The form of the parameters passed into the controller are
;>      HiCylinder, LowCylinder, Head, Sector. Keep in mind that these
;>      values will be used to check for a valid header if and when
;>      a state machine operation ios initiated.
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     Internal
                .LSTON
                .Page
                .FIN

Send_Seek:
                Call    ClrNormStat
                
                 Ld     Wrk_Io+$A,#S_Seek_Response
                Call    Ack_Read
                
                Call    Ld_Param1 ;get parameters from command processor
                
                Ld      Seek_Type,#Access
                
                 Ld     !rC,!r0 ;pass params to Seek
                 Ld     !rD,!r1
                 Ld     !rE,!r2
                 Ld     !rF,!r3
                Call    New_Seek
                 Ld     !r2,#.HIBYTE. Set_SeekNeeded
                 Ld     !r3,#.LOWBYTE. Set_SeekNeeded
                Call    Bank_Call
                
                Jp      Rd_Leave
                
                .LSTOFF
                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Procedure: Send_Restore
;>
;>      This command allows the host to issue either a Format Recal or
;>      a Data Recal to the servo without having to build a primitive
;>      servo command. The value of which type of restore is to be
;>      performed is passed in with the command string.
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     Internal
                .LSTON
                .Page
                .FIN

Send_Restore:
                Call    ClrNormStat
                
                 Ld     Wrk_Io+$A,#S_Rstr_Response
                Call    Ack_Read
                
                Call    Ld_Param1 ;get recal type
                Cp      !r0,#DataRecal
                Jr      Z,S_Restore
                Cp      !r0,#FrmtRecal
                Jr      Z,S_Restore
                
                Call    Abort
                
S_Restore:       Ld     !r2,#.HIBYTE. Restore
                 Ld     !r3,#.LOWBYTE. Restore
                Call    Bank_Call
                
                Jp      Rd_Leave
                
                .LSTOFF
                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Procedure: Set_Recovery
;>
;>      This procedure is used by the host to set the global
;>      variable Recovery either on or off. This variable controls
;>      the behavior of Widget when an exception occurs; in the
;>      case of Recovery = True, the controller tries everything it
;>      can to correct the exception and continue about it's day. 
;>      When Recovery = False, however, the controller will do nothing
;>      about the problem and report the error to the host.
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     Internal
                .LSTON
                .Page
                .FIN

Set_Recovery:
                Call    ClrNormStat
                
                 Ld     Wrk_Io+$A,#Set_Rcvr_Response
                Call    Ack_Read
                
                Call    Ld_Param1 ;get Set/Reset param
                
                Or      Excpt_Status,#Recovery ;assume True
                Or      !r0,!r0 ;test for true or false
                Jr      Nz,Set_Rcvr_Store
                
                And     Excpt_Status,#$FF-Recovery ;clear old bit
                
Set_Rcvr_Store: Jp      Rd_Leave

                .LSTOFF
                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Procedure: Send_Park
;>
;>      This diagnostic command allows the host to issue a Park
;>      command to the drive. This command has the effect of
;>      sending the drive heads off the data surface.
;>
;>      Inputs: { none }
;>
;>      Outputs: { none }
;>
;>      Algorithm:
;>
;>      BEGIN
;>       ClrNormStat
;>       Ack_Read( S_Park_Response )
;>       Park_Heads
;>       Rd_Leave
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     Internal
                .LSTON
                .Page
                .FIN

Send_Park:
                Call    ClrNormStat
                
                 Ld     Wrk_Io+$A,#S_Park_Response
                Call    Ack_Read
                
                 Ld     !r2,#.HIBYTE. Park_Heads
                 Ld     !r3,#.LOWBYTE. Park_Heads
                Call    Bank_Call
                
                Jp      Rd_Leave
                
                .LSTOFF
                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Procedure: Store_Map
;>
;>      This command allows the Host to logically remap { i.e., change
;>      the interleave factor through a remapping of the sector addresses. }
;>      The way in which the Map is downloaded into the SpareTable is
;>      by doing a write sequence from the Host to the controller.
;>
;>      Inputs: { none }
;>
;>      Outputs: { none }
;>
;>      Algorithm:
;>
;>      BEGIN
;>       Get_Write_Data( St_Map_Response )
;>       FOR i := 0 TO NbrSctrs-1 DO
;>              IF ( WriteBuffer[ i ] >= NbrSctrs ) THEN Abort
;>              Map_Table[ i ] := WriteBuffer[ i ]
;>       UpDate_Spare_Table
;>      END
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     Internal
                .LSTON
                .Page
                .FIN

Store_Map:
                Call    ClrNormStat
                
                 Ld     Wrk_Io+$A,#St_Map_Response
                Call    Get_Wr_Data
                
                Ld      !r2,#.HIBYTE. WBuffer1
                Ld      !r3,#.LOWBYTE. WBuffer1
                Ld      !rE,#.HIBYTE. Map_Table
                Ld      !rF,#.LOWBYTE. Map_Table
                Ld      !r1,#NbrSctrs
                
St_Map_Lp:      Lde     !r0,@!!r2 ;get a value from Write Buffer
                Cp      !r0,#NbrSctrs
                Jr      Lt,St_Map1
                
                 Ld     !rA,!r0
                Call    Abort
                
St_Map1:        Lde     @!!rE,!r0 ;store value into Map_Table
                Incw    !!r2
                Incw    !!rE
                Djnz    !r1,St_Map_Lp
                
                 Ld     !r2,#.HIBYTE. UpDate_SprTbl
                 Ld     !r3,#.LOWBYTE. UpDate_SprTbl
                Call    Bank_Call
                
                Jp      Rd_Leave
                
                .LSTOFF
                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Procedure: Wr_SprTbl
;>
;>      This command allows the host to update the spare table
;>      without the controller's intervention. BE CAREFUL WITH
;>      THIS ONE!
;>
;>      Inputs: { none }
;>
;>      Outputs: { none }
;>
;>      Algorithm:
;>
;>      BEGIN
;>       IF NOT( Chk_PassWord( CommandString+1 ) ) THEN Abort
;>       Ack_Read( Wr_Spr_Response )
;>       Clr_Bsy( SpareArray )
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     Internal
                .LSTON
                .Page
                .FIN

Wr_SprTbl:
                 Ld     Wrk_Io+$A,#Wr_Spr_Response
                Call    Get_Wr_Data
                
                 Call    ClrNormStat
                
                 Ld     ScrReg2,#.HIBYTE. ( CStatus4 + 2 )
                 Ld     ScrReg3,#.LOWBYTE. ( CStatus4 + 2 )
                 Ld     !r2,#.HIBYTE. Chk_PassWord
                 Ld     !r3,#.LOWBYTE. Chk_PassWord
                Call    Bank_Call
                Jr      Nz,Wr_Spr1
                
                Call    Abort
                
Wr_Spr1:         Ld     !r2,#.HIBYTE. WrBuf_To_Spr
                 Ld     !r3,#.LOWBYTE. WrBuf_To_Spr
                Call    Bank_Call
                 Ld     !r2,#.HIBYTE. UpDate_SprTbl
                 Ld     !r3,#.LOWBYTE. UpDate_SprTbl
                Call    Bank_Call
                
                Jp      Rd_Leave
                
                .LSTOFF
                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Procedure: Format
;>
;>      This procedure allows the host to format the track
;>      that the heads are currently positioned over.
;>
;>      BE ULTRA CAREFUL HERE!!!! THIS COMMAND DESTROYS ALL
;>      DATA ON THE TRACK.... DATA RECOVERY WILL BE IMPOSSIBLE
;>      AFTER A TRACK HAS BEEN FORMATTED.
;>
;>      The two parameters that are passed into the controller
;>      by the host allow the host to specify the offset from
;>      Index mark ( in sectors ) that Sector 0 will be located
;>      and the interleave factor.
;>
;>      Inputs: { none }
;>
;>      Outputs: { none }
;>
;>      Algorithm:
;>
;>      BEGIN
;>       ClrNormStat
;>       IF NOT( Chk_PassWord( CStatus4+3 ) ) THEN Abort
;>       Ack_Read( Fmt_Response )
;>       IF NOT( FormatTrack( CStatus4+1, CStatus4+2 ) )
;>        THEN Abort
;>       Rd_Leave
;>      END
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     Internal
                .LSTON
                .Page
                .FIN

Format:
                 Ld     Wrk_Io+$A,#Fmt_Response
                Call    Ack_Read
                 
                Call    Chk_FmtParms
                 
                 Ld     !r4,!r0
                 Ld     !r5,!r1
                 Ld     !r2,#.HIBYTE. FormatTrack
                 Ld     !r3,#.LOWBYTE. FormatTrack
                Call    Bank_Call
                
                Jp      Rd_Leave
                
                
Chk_FmtParms:   Call    ClrNormStat
                
                 Ld     ScrReg2,#.HIBYTE. ( CStatus4+4 )
                 Ld     ScrReg3,#.LOWBYTE. ( CStatus4+4 )
                 Ld     !r2,#.HIBYTE. Chk_PassWord
                 Ld     !r3,#.LOWBYTE. Chk_PassWord
                Call    Bank_Call
                Jr      Nz,Format1
                
                Call    Abort

Format1:        Call    Ld_Param1

                Tm      !r0,#$F0 ;check for illegal offset
                Jr      Z,Fmt_Chk_Inter
                
Format_Abort:    Ld     !r9,!r0
                 Ld     !rA,!r1
                Call    Abort
                
Fmt_Chk_Inter:  Cp      !r1,#Max_InterLeave
                Jr      Ugt,Format_Abort
                Ret
                
                .LSTOFF
                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Procedure: Read_Abort
;>
;>      This command is used by the host to read the contents of
;>      the controller's register set at the time of the last abort.
;>      If there has been no abort, the results of this command
;>      will be undefined.
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     Internal
                .LSTON
                .Page
                .FIN

Read_Abort:
                Call    ClrNormStat
                
                 Ld     Wrk_Io+$A,#Rd_Abrt_Response
                Call    Ack_Read
                
                 Ld     !r0,#.HIBYTE. Abort_Stat
                 Ld     !r1,#.LOWBYTE. Abort_Stat
                 Ld     !r2,#.HIBYTE. RBuffer1
                 Ld     !r3,#.LOWBYTE. RBuffer1
                 Ld     !r4,#128 ;move 128 bytes
                 
Rd_Abt_Lp:      Lde     !r5,@!!r0
                Lde     @!!r2,!r5
                Incw    !!r0
                Incw    !!r2
                Djnz    !r4,Rd_Abt_Lp
                
                Jp      Rd_Leave
                
                .LSTOFF
                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Procedure: D_RstSrvo
;>
;>      This procedure allows the host to reset the servo processor.
;>
;>      Inputs: { none }
;>
;>      Outputs: { none }
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     Internal
                .LSTON
                .Page
                .FIN

D_RstSrvo:
                Call    ClrNormStat
                 
                 Ld     Wrk_Io+$A,#RstSrvo_Response
                Call    Ack_Read
                
                 Ld     !r2,#.HIBYTE. ResetServo
                 Ld     !r3,#.LOWBYTE. ResetServo
                Call    Bank_Call
                
                Jp      Rd_Leave
                
                .LSTOFF
                .DO     External
                .LSTON
                .Page
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>
;>      Procedure: D_Init_SprTbl
;>
;>      This procedure allows the host to initialize the spare table
;>      on the disk.
;>
;>      Inputs: { none }
;>
;>      Outputs: { none }
;>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .LSTOFF
                .FIN
                .DO     Internal
                .LSTON
                .Page
                .FIN

D_Init_SprTbl:
                Call    ClrNormStat
                
                 Ld     Wrk_Io+$A,#I_Spr_Response
                Call    Ack_Read
                
                 Ld     ScrReg2,#.HIBYTE. ( CStatus4+4 )
                 Ld     ScrReg3,#.LOWBYTE. ( CStatus4+4 )
                 Ld     !r2,#.HIBYTE. Chk_PassWord
                 Ld     !r3,#.LOWBYTE. Chk_PassWord
                Call    Bank_Call
                Jr      Nz,D_I_SprTbl
                
                Call    Abort
                
D_I_SprTbl:     Call    Ld_Param1
                
                 Ld     !r4,!r0 ;pass offset value
                 Ld     !r5,!r1 ;pass interleave value
                 Ld     !r2,#.HIBYTE. Init_SprTbl
                 Ld     !r3,#.LOWBYTE. Init_SprTbl
                Call    Bank_Call
                
                Jp      Rd_Leave
                
                .LSTOFF
                
