homehds    proc

homecmd    fcb     $C2                 assign disk parameters
           fcb     0,0,0,0,0
           fcb     $B                  seek command
           fcb     0,0,0,0,0
           fcb     4,0,0,0
           fdb     657
           fcb     0,0,16,0
           fcb     $80                 controller address
           fcb     0
           fdb     0                   24 bit address of command
           fcb     0
           fdb     0                   24 bit address of buffer
           fcb     0
           fcb     0
homelen    equ     *-homecmd

hcmd       loc     1                   assign disk parameters
hassn      loc     5
hseek1     loc     1
hseek      loc     5
hdata      loc     4
hcyls      loc     6
hrms       loc     9
drv        loc     1
cyl        loc     2
mspace     loc     2
*
.   Home the heads to cyl 655 (Tulin)
.
tulhome:
           mark    (d,x,u,y)
           aloc
           ldb     #0                  drive number
           ldx     #656                cylinder
           bra    talk
genhome:
           mark    (d,x,u,y)
           aloc
           bsr     gethex              get drive number
           bcs     homeer1
           tfr     a,b
           cmpb    #3                  is it in range?
           bhi     homeer1
           tfr     d,y
.  get cylinder number
           bsr     outsp               space over one
           bsr     getbyte             get high order byte
           bcs     homeer2
           tfr     a,b
           bsr     getbyte             get low order byte
           bcs     homeer2
           exg     b,a
           tfr     d,x
           tfr     y,d
talk       lslb                        shift drive number over for SCSI
           lslb
           lslb
           lslb
           lslb
           stb     drv                 drive number
           stx     cyl                 requested cylinder
           bsr     scsirst             reset and initialize the SCSI
           ldx     #homecmd            move from rom to ram
           ldb     #homelen
           leay    hcmd
homel1     lda     0,x+
           sta     0,y+
           decb
           bne     homel1
.   fill in the holes
           lda     drv                 store drive number in commands
           sta     hassn
           sta     hseek
           ldd     cyl                 define drive to be 1 more than req cyl
           addd    #1
           std     hcyls
           leax    hdata               put addresses in command block
           stx     hrms+5
           leax    hcmd
           stx     hrms+2
.  define the drive
           leax    hrms
           bsr     sendscsi            define the drive
           bcs     homeer3             error from sendscsi
           lda     7,x                 get completion status byte
           anda    #$1f                mask off drive number
           bne     homeer3             error
.  figure the logical block
           lda     cyl
           ldb     #17
           mul
           std     mspace
           lda     cyl+1
           ldb     #17
           mul
           stb     hseek+2
           tfr     a,b
           lda     #0
           addd    mspace
           stb     hseek+1
           anda    #$1f
           ora     hseek
           sta     hseek
.  do the seek
           leax    hseek1
           stx     hrms+2
           leax    hrms
           bsr     sendscsi
           bcs     homeer4             error from sendscsi
           lda     7,x                 get completion status byte
           anda    #$1f                mask off drive number
           bne     homeer4             error
homeexit   exit
homeer1    ldx     #m1
           bsr     pdata
           exit
homeer2    ldx     #m2
           bsr     pdata
           exit
homeer3    ldx     #m3
           bsr     pdata
           exit
homeer4    ldx     #m4
           bsr     pdata
           exit
m1         fcb     cr,"Drive limit 0 - 3",etx
m2         fcb     cr,"Cylinder limit 0000 - FFFF",etx
m3         fcb     cr,"Error while initializing drive",etx
m4         fcb     cr,"Error during seek",etx
           end
