CoCoZilla Page NoCan3 Page NoCan2 Page Bottom Connector Page MPI Clone Page IDEZilla Page Pocket IDE Page 512K Schematic, BIG 828 x 1114. MFM HardDrive Page 4MHZ Page PLCC 6309 Page
Make a NitrOS-9 Boot Disk. NoCan3 Information Page Address Selection Page Pocket IDE Photos 4MHz PCB Page
Frequently Asked Questions NoCan3 Circuit Board Page NoCan2 PCB Page IDE PCB Page
I2C Page NoCan3 Jumpers Page NoCan2 Jumpers Page IDE CHS Driver Page
Update Your 26-3024 MPI for CoCo-3 Use Auto-Refresh No Excuses List IDE LBA Driver Page
HiDensity Modifications HiDensity Mod Text FIle
NoCan3 with I2C Bus Bart GIF Page Get the 26-3024 UpGrade GAL MPI 26-3124 UpGrade Page Back to the Thumbnail Page

 
Presented by: Only On Saturday Night

 
 opt g
 nam DD
 ttl IDE Description
* March 29, 1999, for "CHSDisk8"
*
 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 $FF    mode byte
 fcb $07    page address
 fdb $FF30  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 1      density             PD.DNS
 fdb 762    cylinders           PD.CYL
 fcb 7      sides, heads        PD.SID
 fcb 0      verify, 0=yes       PD.VFY
 fdb 32     sectors/track       PD.SCT
 fdb 32     track-0 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 /CHSDisk8/
*
 emod
eom equ *
 end

 
  nam 'CHSDisk8'
 ttl '8 bit IDE Hard Disk Driver OS9 L2V2'
* May 17, 1999  CHS-8 256-byte sectors.
* Copyright: Paul Taylor Barton.
* Company: Only On Saturday Night.
*
* Supports two drives.
* CHS mode.
* Example: for a IDE CP30104H, 121MB.
* 762 cylinders, 8 heads, 39 sectors.
* ( (762 * 8) * 39) * 256bytes/sector
* = 60,862,464 MB.

Rev equ 2
Port equ $FF30

* IDE addresses:
* (these are upside down from normal)
*
Status  equ Port+0 Results of read/write
CmdIde  equ Port+0 Commands
DevHead equ Port+1 0,0,0,DEV,(h3),h2,h1,h0  0..15
CylHigh equ Port+2 0..65535
CylLow  equ Port+3 ../
SecNum  equ Port+4 1..256
SecCnt  equ Port+5 always=1
ErrReg  equ Port+6 Has the errors
RData   equ Port+7 data 0..7
WData   equ Port+7 data 0..7

Rd815   equ Port+8 data 8..15, latch
Wr815   equ Port+8 data 8..15, latch
AltReg1 equ Port+9  $3F6 alternate
AltReg2 equ Port+10 $3F7 alternate
CslReg  equ Port+11 Special Cabling

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

* Status Bits:
*
BusyBit equ %10000000 BUSY=1
DrdyBit equ %01000000 drive ready=1
DfBit   equ %00100000 drive failed bit
DscBit  equ %00010000 seek finished=1
DrqBit  equ %00001000 data requested=1
CorrBit equ %00000100 corrected data bit
IdxBit  equ %00000010 index marker
ErrBit  equ %00000001 error_reg has data
RdyTrk  equ %01010000 ready & over track
RdyDrq  equ %01011000 ready & seek & data

* bits in ErrReg:
Tk00NF  equ %00000010 in ErrReg-ister

ChsMode equ %10111111 and mask

NDrvs    equ 2 two drives
Device0  equ %11101111 and mask
Device1  equ %00010000 or  mask
Master   equ %00000000
Slave    equ %00010000

* ========< 6309 CODE >==========
*
 ifp1
 use /DD/DEFS/defsfile
 endc

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

 org DrvBeg
IDE0    rmb DrvMem
IDE1    rmb DrvMem
ZerFlg  rmb 1 =0 if LSN=0

* Local copies that get sent to the drive:
*
DevHd   rmb 1 0,0,0,d,(h3),h2,h1,h0
CylHi   rmb 1
CylLo   rmb 2
SecNm   rmb 1 0,0,s5,s4,s3,s2,s1,s0
Stack   rmb 20
Size    equ .

Start
 lbra Init      Init Drive
 bra  ReadSec
 nop
 lbra WriteSec
 lbra RetNoErr  GetSta
 lbra RetNoErr  SetSta
 lbra RetNoErr  Terminate

* ........................
*
ReadSec
 bsr  LSN       convert drive & update ZerFlg
 bsr  ChkBusy   sleep 1 tick if so

RdyHuh1
 ldb  Status    is IDE ready for commands?
 andb #DrdyBit  look at Drdy Bit
 beq  RdyHuh1   loop until Drdy =1

 ldx  PD.BUF,y  destination
 ldb  #256/8    lower 8-bits only
 ldw  #RData
 lda  #ReadCmd  actual command to go out
 sta  CmdIde    finish process

Blk2
 lda  Status    is IDE ready to send?
 anda #DrqBit   DRQ, data request
 beq  Blk2      loop until DRQ =1

BlkLp
 lda ,w         a<-RData, 0..7
 sta ,x+        into RAM
 lda ,w         a<-RData, 0..7
 sta ,x+        into RAM
 lda ,w         a<-RData, 0..7
 sta ,x+        into RAM
 lda ,w         a<-RData, 0..7
 sta ,x+        into RAM

 lda ,w         a<-RData, 0..7
 sta ,x+        into RAM
 lda ,w         a<-RData, 0..7
 sta ,x+        into RAM
 lda ,w         a<-RData, 0..7
 sta ,x+        into RAM
 lda ,w         a<-RData, 0..7
 sta ,x+        into RAM
 decb           512/2= 256 each 8-bit xfers
 bne  BlkLp     go get the rest

 lda  Status    check for error-bit
 anda #ErrBit   move good sector?
 bne  ReadErr   not good sector

 ldb  ZerFlg,u  is it LSN0?
 bne  ReadXit   LSN <>0
 bra  Lsn0      yes, move LSN0

ReadXit
 clrb
 rts

ReadErr
 comb           bad 256-sector
 ldb  #E$Read   Read Error
 rts

* ...............................
* re-locate LSN0 into the buffer,
* the contents of LSN0.
*
Lsn0
 pshs y
 ldb  #DD.SIZ    length
 ldx  PD.BUF,y   source
 leay Ide0,u     /DD
 lda  PD.DRV,y   master drive? (2-cycles quicker)
 beq  LsnMove    /DD

 leay Ide1,u     slave drive

LsnMove
 lda  ,x+        move LNS0 of Ide#
 sta  ,y+        to DrvMem buffer
 decb

 bne LsnMove

 clrb            erase flags
 puls y,pc

* ........................
*
Nap
 ldx  #1
 OS9  F$Sleep

ChkBusy
 ldb  Status
 andb #BusyBit  10000000
 bne  Nap       if =1 then loop
 rts            exit when BUSY =0

* ....................................
* B        Xhi      Xlo
* CCCCCCCC CCCCCCCC HHHSSSSS
* HiByte   MidByte  LowByte
*
LSN
 stb  CylHigh    23-16
 clra            no bits, please
 orr  x,d        now find if LSN =0
 orr  a,b
 stb  ZerFlg,u   update flag =0 or <>0

* Now make into CHS:
*
 tfr  x,d        RESULTS:
 sta  CylLow     15-08

 andb #$1F       000SSSSS
 incb            1..32, no sector zero!
 stb  SecNum     00SSSSSS, 04-00

 lda  #1        only one at a time
 sta  SecCnt    only one at a time

 tfr  x,d
 lsrb            0HHHSSSS
 lsrb            00HHHSSS
 lsrb            000HHHSS
 lsrb            0000HHHS
 lsrb            00000HHH, default = Master

 lda  PD.DRV,y  Master or Slave? (2-cycles quicker)
 beq  PikUnit   Master

 orb  #Slave    Slave

PikUnit
 stb  DevHead   000d/0hhh 07-05
 rts

* ........................
*
WriteSec
 bsr  LSN       convert drive & update ZerFlg
 bsr  ChkBusy   sleep if so

RdyHuh3
 ldb  Status    is IDE ready for commands?
 andb #DrdyBit  look at Drdy Bit
 beq  RdyHuh3   loop until Drdy =1

 ldx  PD.BUF,y  source
 ldb  #256/8    byte counter
 ldw  #WData    data register
 lda  #WriteCmd sector
 sta  CmdIde    IDE register

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

BlokLp
 lda  ,x+       fetch data for IDE
 sta  ,w        0..7
 lda  ,x+       fetch data for IDE
 sta  ,w        0..7
 lda  ,x+       fetch data for IDE
 sta  ,w        0..7
 lda  ,x+       fetch data for IDE
 sta  ,w        0..7

 lda  ,x+       fetch data for IDE
 sta  ,w        0..7
 lda  ,x+       fetch data for IDE
 sta  ,w        0..7
 lda  ,x+       fetch data for IDE
 sta  ,w        0..7
 lda  ,x+       fetch data for IDE
 sta  ,w        0..7
 decb           256 8-bit xfers
 bne BlokLp     IDE auto-inc's

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

WriteErr
 comb           bad 256-sector
 ldb  #E$Write  Write Error
 rts

RetNoErr
 clrb
 rts

* ......................................
* Init the drive by providing sectors/track
* to the sector/count register,
* and heads-1 to the device/head register.
*
Init
 lbsr ChkBusy    could be spinning up...
 lda  #Diagnos   hits both drives
 sta  CmdIde     ../
 lbsr ChkBusy    wait 'til both done

RdyHuh9
 lda  Status     is IDE ready for commands?
 anda #DrdyBit   look at Drdy Bit
 beq  RdyHuh9    loop until Drdy =1

* Give the drive it's
* CHS translation parameters:
*
* No matter what the descriptor says,
* it's 8 heads & 32 sectors/track,
* for the drive's CHS translation method.
*
 ldd  #$0720     heads-1, sectors/track
 sta  DevHead    master+heads IDE, drive=0
 stb  SecCnt     sector/count IDE
 lda  #InitCmd   Init drive cmd
 sta  CmdIde     Init the Drive
 lbsr ChkBusy    wait until init'd

 ldd  #$1720     heads-1, sectors/track
 sta  DevHead    slave+heads IDE, drive=0
 stb  SecCnt     sector/count IDE
 lda  #InitCmd   Init drive cmd
 sta  CmdIde     Init the Drive

 ldb  #NDrvs     drive count, max=2
 stb  V.NDRV,u   tell OS9 how many, 1..2

 lda  #$FF       LSN <>0
 leax IDE0,u     drive 0 only
 sta  DD.TOT+1,x
 sta  V.TRAK,x   say <>0

 leax IDE1,u     drive 0 only
 sta  DD.TOT+1,x
 sta  V.TRAK,x   say <>0

 clr  V.BUSY,u   say not busy
 clr  V.WAKE,u   say not sleeping
 clrb
 rts

modnam fcs /CHSDisk8/
       fcb Rev
 emod
pgmend equ *
 end

1