 sttl WIN 5" Winchester Boot
 pag
*
* WIN 5" Winchester boot
*

*
* equates and addresses
*
WINTDR equ $00 Test Drive Ready
WINREC equ $01 Recalibrate (reseek to 0)
WINRSS equ $03 Request Sense Status
WINRDS equ $08 Read Sector
WINIDC equ $0C Initialize Drive Characteristics
WINRDG equ $E0 Internal RAM Diagnostic
WINDDG equ $E3 Drive Diagnostic
WINCID equ $E4 Controller Internal Diagnostic
WINBOOT equ $B000 Load Address for Bootstrap Loader
*
* disk controller definitions
*
WINCMD equ $F100 disk command register
WINADR equ WINCMD+1 DMA address registers
XBCCOM equ WINCMD+4 Xebec Command Register
WINREQ equ %00000001 Controller Request Data
*
*  Boot from WIN 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 WINCMD
 clr WINCMD
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
 if 0
 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
 endif
 lbsr setadr set up DMA address
 stb WINADR
 stx WINADR+1
 lda #$21 DMA/no IRQ
 ldx #RS0cmd Read Sector 0
 bsr cmicn
 bsr cmist
 bne cmibt9
 lds #sysstk set up UniFLEX stack
 jsr WINBOOT go execute boot code
cmibt9
 ldx #BTfail
 jsr pdata
cmibtx bra cmibtx
*
*  cmicmd - Issue WIN command and get status
*
cmicmd lda #$01 No DMA/IRQ
 bsr cmicn issue command
 bra cmist get status
*
* cmicn - set up WIN command and send to Xebec
*    A - DMA/IRQ select mask
*    X - Xebec Device Control Block (Command)
*
cmicn
 sta WINCMD 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 WINCMD 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 #WINerr
 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 WINCMD test READY
 bitb #1
 beq cmiwt wait until READY
 rts
*
*  setadr - compute physical address of $B000
*    X - Lower 16 bits of physical address
*    B - Upper 4 bits
*
setadr lda $010B $B000 Map Register
 tfr a,b
 lsrb
 lsrb
 lsrb
 lsrb
 pshs b
 lsla
 lsla
 lsla
 lsla
 clrb
 tfr d,x
 puls b,pc
 if 0
*
*  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 #WINDCT 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
*
*  WIN Drive characteristics
*
WINDCT fdb 306 Cylinders -- WIN 5619
 fcb 6 Heads
 fdb 306 Begin reduced write
 fdb 306 Begin write precompensation
 fcb 11 Max ECC error burst
 endif
*
*  Various Command Blocks
*
TDRcmd fcb WINTDR Test Drive Ready
 fcb 0,0,0,0,0
 if 0
RDGcmd fcb WINRDG RAM Diagnostics
 fcb 0,0,0,0,0
IDCcmd fcb WINIDC Initialize Drive Characteristics
 fcb 0,0,0,0,0
CIDcmd fcb WINCID Controller Internal Diagnostics
 fcb 0,0,0,0,0
 endif
RS0cmd fcb WINRDS Read Sector 0
 fcb 0,0,0,1,4
RSScmd fcb WINRSS Request Sense Status
 fcb 0,0,0,0,4
*
*  Error messages
*
BTfail fcc $d,'Boot load failed!',0
BTwait fcc $d,'WIN not ready',0
WINerr fcc $d,'WIN Error: ',0
*
