
 sttl DMAF2 Boot Loader
 pag
*
* Disk boot code
*

*
*   disk bootstrap program
*

btsec    equ     1                   sector number of ipl record
seclen     equ     512                 disk sector length
btadr    equ     usrseg<<12         logical bootstrap address
realad    equ     !(ramap<<4)&$F000   physical address of bootstrap
*
*   DMAF2 1791 disk controller definitions
*
cmmnd    equ     $F004               disk controller command register
status     equ     $F004               disk controller status register
track      equ     $F005               disk controller track register
sector     equ     $F006               disk controller sector register
data       equ     $F007               disk controller data register
*
*   DMAF2 1791 disk controller command definitions
*
frcint   equ     %11011000           force interrupt command
restore    equ     %00001001           restore command
read       equ     %10001100           single sector read command
*
*   DMAF2 1791 disk controller status bits
*
drdy       equ     %10000000           1 => drive not ready
skerr    equ     %00010000           1 => seek error
nrf        equ     %00010000           1 => no record found error
crc        equ     %00000100           1 => crc error
lsd        equ     %00000010           1 => lost data error
dbusy      equ     %00000001           1 => controller busy
*
*   DMAF2 drive select latch definitions
*
drive      equ     $F000               drive select latch (inverted)

dnsty    equ     %00100000           1 => double density selected
select     equ     %00000001           1 => drive zero selected
*
*   DMAF2 6844 DMA controller definitions
*
address    equ     $F002               DMA address register (zero)
channel    equ     $F001               DMA channel control register
*
*   reset the stack and set up direct addressing
*    (B) has drive select code
*
loadip           seti     irq,firq            disable irq and firq
 lda #8 set retries
           pshs    d,dp                 save the direct page register
           lda     #address>>8         load the msp of the address
           tfr     a,dp               set direct addressing
           setdp   $f0             and tell the assembler
*
*   quiesce the dma (in case it is active)
*
trybt      lda     #0                 clear all relevant DMA registers
           sta     channel             clear channel control register
*
*   disable irq from the 1791 controller
*
 lda 1,s get drive select
retrit     sta     drive               stuff into drive select latch
           lda     #frcint           load a force interrupt command
           bsr     diskcmd             send the command to te disk
*
*   read 1791 status latch and see if drive comes up ready
*
           ldy     #14000              allow up to 3 seconds for drive ready
dmchk      bsr     delay               delay 174 uSeconds
           lda     status              check 1791 drive ready status bit
           bpl     dorest              if ready, go do the restore
           leay    -1,y                decrement delay count
           bne     dmchk               loop if not so
           bra     loadxit
*
*   restore the drive and wait for it to complete
*
dorest     lda     #restore            load a restore command
           bsr     diskcmd             and attempt to restore the drive
waitrst    lda     status              pick up 1791 status register
           bita    #dbusy              check for the busy bit
           bne     waitrst             loop until busy goes away
           bita    #skerr            test for seek error
           bne     loadxit
*
*   set up the dma count and address registers
*
           ldd     #realad           load real boot address
           std     address             stuff into DMA address register
*
*   set up the dma mode and control registers
*
           lda     #$10                 set up steal mode
           sta     channel             store into channel control register
*
*   now fire up 1791 controller to do a single sector read
*
           ldd     #btsec            load boot sector number
           std     track               set track number to zero
           lda     #read               load single sector read
           bsr     diskcmd             and fire up the controller
*
*   wait for the command to complete
*
wboot      ldx     #50000              allow up to 500 mS delay
wfboot lda drive get status
 asla
 bmi checkit
           leax    -1,x                decrement the wait counter
           bne     wfboot              loop waiting for boot to complete
           lda     status              pick up status byte
 bita #dbusy still busy?
 bne wboot
 bita #nrf record not found?
 beq loadxit
*
* retry it
*
rtry ldb 1,s get density selection
 eorb #dnsty
 stb 1,s switch densities
 dec 0,s dec retry count
 bne trybt
*
*   load has failed - first shut down the DMA
*
loadxit    sta 0,s                   push the offending status
 clr channel
*
*   then shut down the 1791 and exit
*
           lda     #frcint           force an interrupt
           sta     cmmnd             write into the command register
  clra
           sta     drive               to turn off the lights
 coma
 puls d,dp,pc
*
*   boot has completed - check for any sicknesses along the way
*
checkit    lda     status              pick up disk controller status
           bita    #crc+lsd+drdy   test for error conditions
           bne     loadxit             exit if error on boot sector
 clr channel
 bita #nrf wrong density?
 bne rtry
chki2 lda 1,s reset drive reg
 sta drive
      ldx     #btadr            load bootstrap address
           clra                        set equal to show boot complete
 puls d,dp,pc
*
*   send a command to the 1791 and wait for it to respond
*
diskcmd    sta     cmmnd             store the disk command
delay      lda     #32                 set up a delay counter
del        deca                        decrement the delay count
           bne     del                 hang in there for the count
           rts

           setdp   0

