Humble Bee Buttons
Go Back One
Humble Bee Buttons
Presented by: Only On Saturday Night

 
 opt g
 nam DD
 ttl IDE Description

 ifp1
 use /DD/DEFS/OS9Defs
 endc

rev     set 1
tylg    set Devic+Obj6309
atrv    set ReEnt+rev

 mod eom,name,tylg,atrv,mgrnam,drvnam

 fcb UPDAT. mode byte
 fcb $07    page address
 fdb $FF70  port address, status
 fcb initsize-*-1

 fcb DT.RBF
 fcb 0       drive#              PD.DRV
 fcb 0       step-rate           PD.STP
 fcb $80     hard-disk           PD.TYP
 fcb 3       density             PD.DNS
 fdb 255     cylinders           PD.CYL
 fcb 8       heads               PD.SID
 fcb 0       verify, 0=yes       PD.VFY
 fdb 32      track               PD.SCT
 fdb 32      sectors             PD.T0S
 fcb 0       interleave          PD.ILV
 fcb 1       sectors/cluster     PD.SAS

initsize equ *

name   fcs /DD/
       fcb rev
mgrnam fcs /RBF/
drvnam fcs /IdeDiskP8/

 emod
eom    equ *
 end


 
 nam 'IdeDiskP8'
 ttl 8 bit IDE Hard Disk Driver OS9 L2V2
* July 19, 1999 Version 1 Revision 1.
* This code supports 1 physical drive,
* with 8 partitions inside this
* physical drive by manipulating
* the LBA bits in the IDE registers.
* see: LSN routine.

NDrvs    equ 1 only one drive
Parts    equ 8 how many partitions current
Rev      equ 1

* upside down addresses:
*
Port     equ $FF70
Status   equ Port+0 * results
CmdIde   equ Port+0 * Commands
Lba2427  equ Port+1 * DevHead
DevHead  equ Port+1 * Lba2427
Lba1623  equ Port+2 * CylHigh
Lba815   equ Port+3 * CylLow
Lba07    equ Port+4 * SecNum
SecCnt   equ Port+5 * always=1
ErrReg   equ Port+6 * Errors
RData    equ Port+7 * data 0..7
WData    equ Port+7 * data 0..7
Rd815    equ Port+8 * data 8..15
Wr815    equ Port+8 * data 8..15

* IDE Commands:
*
NopCmd     equ $00
Tk00Cmd    equ $10
ReadCmd    equ $20
WriteCmd   equ $30
FmtCmd     equ $50
SeekCmd    equ $70
InitCmd    equ $91
Diagnos    equ $90

* Status Bits:
* normal mode=$50
* Drdy+Dsc, ready & over track
*
BusyBit equ %10000000 BUSY=1
DrdyBit equ %01000000 drive ready=1
DfBit   equ %00100000 drive failed=1
DscBit  equ %00010000 seek finished=1
DrqBit  equ %00001000 data requested=1
CorrBit equ %00000100 corrected CRC=1
IdxBit  equ %00000010
ErrBit  equ %00000001 error_reg has it
Device0 equ %11101111 and mask
Device1 equ %00010000 or  mask
LbaMode equ %01000000 or  mask

* >>>---=== 6309 CODE ===---<<< *

 ifp1
 use    /DD/DEFS/defsfile
 endc

tylg    set Drivr+Obj6309
atrv    set ReEnt+Rev
 mod    pgmend,modnam,tylg,atrv,start,size
 fcb    UPDAT. mode byte

        org DrvBeg   one per partition
IDE0    rmb DrvMem   /DD partition 0
IDE1    rmb DrvMem   /I1 partition 1
IDE2    rmb DrvMem   /I2 partition 2
IDE3    rmb DrvMem   /I3 partition 3
IDE4    rmb DrvMem   /I4 partition 4
IDE5    rmb DrvMem   /I5 partition 5
IDE6    rmb DrvMem   /I6 partition 6
IDE7    rmb DrvMem   /I7 partition 7

ZerFlg  rmb 1   =0 if LSN=0
Stack   rmb 20
Size    equ .

* ..............

Start
 lbra Init      Initialize
 bra  ReadSec   Read
 nop
 lbra WriteSec  Write
 lbra RetNoErr  GetStatus
 lbra RetNoErr  SetStatus
 lbra RetNoErr  Terminate

* ..............

ReadSec
 tfr  x,w       B:W
 bsr  ChkBusy   sleep if so

Blk1
 lda  Status    is drive ready for command
 anda #DrdyBit  DRDY =1 is good
 beq  Blk1      =0 is not ready

 bsr  LSN       B:W, convert & update ZerFlg
 ldx  PD.BUF,y  destination
 ldw  #RData    data register
 lda  #ReadCmd  actual command to go out
 sta  CmdIde    write command
 clrb           byte counter

Blk3
 lda  Status    is IDE ready to receive?
 anda #DrqBit   DRQ, data request
 beq  Blk3      loop while DRQ =0

Blk4
 lda  ,w        fetch IDE data
 sta  ,x+       move into RAM
 decb           update byte counter
 bne  Blk4      do more

 lda  Status    did it move a
 anda #ErrBit   good sector?
 bne  ReadErr   no

 ldb  ZerFlg,u  yes, is it LSN0?
 beq  Lsn0      yup, move LSN0

ReadXit
 clrb
 rts

ReadErr
 comb           set carry
 ldb  #E$Read   Read Error
 rts

*************************************
* Transfer B:W LBA to IDE drive     *
* Limited to 8 logical drives.      *
* The drive number is the partition *
* number.                           *
* Max Partition Address:            *
* B:W = $00FF00                     *
* Max Address: $07FFFF              *
* 00000111-11111111-11111111        *
* 00000ppp-aaaaaaaa-aaaaaaaa        *
*************************************

LSN
 clra           LSN(B:W)
 orr  w,d       looking for LSN=0
 orr  b,a       .../
 sta  ZerFlg,u  ../

 lda  PD.DRV,y  0..255 may crash...
 anda #$07       (limit partition count)
 sta  Lba1623   ...if drive is too small

 stw  Lba815    <-E ; F-> Lba07

 ldd  #$4001    lbamode/master & sectors to move
 stb  SecCnt    how many sectors to read/write
 sta  Lba2427   always drive =0 !
 rts

* ..............
* re-locate into a buffer,
* a portion of lsn zero.

Lsn0
 leax IDE0,u    i'm /DD
 lda  PD.DRV,y
 beq  LsnNxt
 ldb  #DrvMem

LsnLp
 abx            find the buffer
 deca
 bne  LsnLp

LsnNxt
 ldb  #DD.SIZ   length
 pshs y
 ldy  PD.BUF,y  source

LsnMove
 lda  ,y+       move sct0 of IDE0
 sta  ,x+       to buffer
 decb
 bne  LsnMove

 clrb
 puls y,pc

* ..............

Nap
 ldx  #1
 OS9  F$Sleep

ChkBusy
 lda  Status    IDE status
 anda #BusyBit  loop while =1
 bne  Nap       exit when =0
 rts

* ..............

WriteSec
 tfr  x,w       B:W
 bsr  ChkBusy   sleep if so

Blok1
 lda  Status    is drive ready for command
 anda #DrdyBit  DRDY =1 is good
 beq  Blok1     =0 is not ready

 bsr  LSN       B:W, convert & set ZerFlg
 ldx  PD.BUF,y  source
 ldw  #WData
 lda  #WriteCmd actual command
 sta  CmdIde    IDE address
 clrb           byte counter

Blok3
 lda  Status    is drive ready to receive data?
 anda #DrqBit   DRQ =1 is good
 beq  Blok3     =0 is not ready

BlokWrt
 lda  ,x+       fetch data for IDE
 sta  ,w        ship it out
 decb           update counter
 bne  BlokWrt   IDE auto-inc's

 lda  Status    error?
 anda #ErrBit   keep error-bit
 beq  RetNoErr  good 256-sector

WriteErr
 comb           set carry
 ldb  #E$Write  Write Error
 rts

RetNoErr
 clrb
 rts

* ..............

Init
 bsr  ChkBusy   could be spinning up
 lda  #Diagnos
 sta  CmdIde

 ldb  #NDrvs    drive count, max=2
 stb  V.NDRV,u  logical drive count

 ldb  #Parts    partition count, max=8
 lda  #$FF
 leax IDE0,u

InitLp
 sta  DD.TOT+1,x
 sta  V.TRAK,x
 leax DrvMem,x
 decb
 bne InitLp

 clr  V.BUSY,u
 clr  V.WAKE,u
 clrb
 rts

* .............

modnam fcs /IdeDiskP8/
 fcb   Rev

 emod
pgmend equ *
 end

1