 opt lis
 sttl CMI 5" Winchester Boot
 pag
*
* CMI 5" Winchester boot
*

*
* equates and addresses
*
CMITDR equ $00 Test Drive Ready
CMIREC equ $01 Recalibrate (reseek to 0)
CMIRSS equ $03 Request Sense Status
CMIRDS equ $08 Read Sector
CMIIDC equ $0C Initialize Drive Characteristics
CMIRDG equ $E0 Internal RAM Diagnostic
CMIDDG equ $E3 Drive Diagnostic
CMICID equ $E4 Controller Internal Diagnostic
CMIBOOT equ $B000 Load Address for Bootstrap Loader
*
* disk controller definitions
*
CMICMD equ $F100 disk command register
CMIADR equ CMICMD+1 DMA address registers
XBCCOM equ CMICMD+4 Xebec Command Register
CMIREQ equ %00000001 Controller Request Data
*
*  Boot from CMI 5" Winchester
*    Initialize Xebec controller
*    Make sure device is online
*    Initialize drive characteristics
*    Read block #0 (boot sector)
*
cmiboot jsr config configure system
 lda #$80 RESET Xebec Controller
 sta CMICMD
 clr CMICMD
cmibt1 ldx #TDRcmd send Test Drive Ready command
 bsr cmicmd set up and send command
 beq cmibt4 jump if online & no error
 cmpa #$04 not ready error code
 bne cmibt9 give up on any other error
 ldx #BTwait
 jsr pdata
 ldb #30
cmibt2 ldx #0
cmibt3 leax -1,x
 bne cmibt3
 decb
 bne cmibt2
 bra cmibt1 try again
cmibt4 ldx #RDGcmd run RAM diagnostics
 bsr cmicmd run command
 bne cmibt9
 ldx #CIDcmd run Controller Diagnostics
 bsr cmicmd
 bne cmibt9
 lbsr cmiidc initialize Drive Characteristics
 bne cmibt9
 lbsr setadr set up DMA address
 lda #$21 DMA/no IRQ
 ldx #RS0cmd Read Sector 0
 bsr cmicn
 bsr cmist
 bne cmibt9
 lds #sysstk set up UniFLEX stack
 jsr CMIBOOT go execute boot code
cmibt9
 ldx #BTfail
 jsr pdata
cmibtx bra cmibtx
*
*  cmicmd - Issue CMI command and get status
*
cmicmd lda #$01 No DMA/IRQ
 bsr cmicn issue command
 bra cmist get status
*
* cmicn - set up CMI command and send to Xebec
*    A - DMA/IRQ select mask
*    X - Xebec Device Control Block (Command)
*
cmicn
 sta CMICMD set up DMA/IRQ selection
 lda #6 send 6 bytes
cmicn0 bsr cmiwt wait for READY
 ldb ,x+ get next byte
 stb XBCCOM send to controller
 deca done?
 bne cmicn0
 rts
*
* cmist - wait for operation complete & get status
*
cmist
 lda CMICMD wait for command completion
 bpl cmist
cmist0
 bsr cmiwt get command status
 lda XBCCOM
 pshs a
 bsr cmiwt
 ldb XBCCOM
 puls a
 bita #2 error bit set?
 beq cmist9 no - exit
 lda #1 no DMA/IRQ
 ldx #RSScmd Request Sense Status
 bsr cmicn send command
 ldx #CMIerr
 jsr pdata
 lda #4
cmist1 bsr cmiwt wait for READY
 ldb XBCCOM get data
 cmpa #4 first status byte?
 bne cmist2 no
 pshs b yes - save it
cmist2 pshs a
 tfr b,a
 jsr hexbyt
 jsr outsp
 puls a
 deca done?
 bne cmist1
 bsr cmiwt get command status
 lda XBCCOM
 bsr cmiwt
 ldb XBCCOM
 lda ,s+ get major error code
 anda #$7F
 cmpa #$18 allow ECC correctable errors through
cmist9 rts return
*
*  Wait for Xebec to request data
*
cmiwt ldb CMICMD test READY
 bitb #1
 beq cmiwt wait until READY
 rts
*
*  setadr - compute physical address of $B000
*
setadr lda $010B $B000 Map Register
 tfr a,b
 lsra
 lsra
 lsra
 lsra
 comb
 lslb
 lslb
 lslb
 lslb
 std CMIADR
 clr CMIADR+2
 rts
*
*  Set up controller
*
cmiidc
 lda #1 no DMA/IRQ
 ldx #IDCcmd initialize Drive Characteristics
 lbsr cmicn
cmiid0 bsr cmiwt wait for READY
 bitb #$14 wait for REQ=1, I/O=0, C/D=0
 bne cmiid0
 ldx #CMIDCT get address of Drive Characteristic Table
 lda #8
cmiid1 bsr cmiwt wait for READY
 ldb ,x+
 stb XBCCOM
 deca done?
 bne cmiid1
 lbsr cmist wait for end of command and check status
 rts
*
*  CMI Drive characteristics
*
CMIDCT fdb 306 Cylinders -- CMI 5619
 fcb 6 Heads
 fdb 306 Begin reduced write
 fdb 306 Begin write precompensation
 fcb 11 Max ECC error burst
*
*  Various Command Blocks
*
TDRcmd fcb CMITDR Test Drive Ready
 fcb 0,0,0,0,4
RDGcmd fcb CMIRDG RAM Diagnostics
 fcb 0,0,0,0,4
IDCcmd fcb CMIIDC Initialize Drive Characteristics
 fcb 0,0,0,0,4
CIDcmd fcb CMICID Controller Internal Diagnostics
 fcb 0,0,0,0,4
RS0cmd fcb CMIRDS Read Sector 0
 fcb 0,0,0,1,4
RSScmd fcb CMIRSS Request Sense Status
 fcb 0,0,0,0,4
*
*  Error messages
*
BTfail fcc $d,'Bootstrap load failed!',0
BTwait fcc $d,'CMI Drive not ready - waiting',0
CMIerr fcc $d,'CMI Error: ',0
*
 sttl
 pag
