'=== User definable area =======================================================
' Hardware Definitions:  Port und Pin for CF-Card/HardDisk
' This hard ware setting is for a hard disk (See HARDDISK_M128.GIF)


' Configuration of Output-Pins must be done by Input-Pin-name till 1.11.7.4
' so output  pins have to be additional declared by their Input-Pin-name


' Constant definitions: No / Low = 0 ; Yes / High = 1

' --- Data Port(s) ------------------------------------------------------------

' Data Port (Low) D0 - D7
ATA_Data_Low Alias PortA
ATA_Data_Low_In Alias PinA

Const ATA_DataBits = 16                  ' 8 for CF-Card or 16 for Hard Disk

#IF ATA_DataBits = 16
' Data Port High D8 - D15 on Hard Disk
ATA_Data_High Alias PortC
ATA_Data_High_In Alias PinC
#ENDIF


' --- Register Address Pins DA0 - DA2 -----------------------------------------

' Address Pins A0
ATA_Pin_DA0 Alias PinB.5
ATA_Port_DA0 Alias PortB.5
Const ATA_DA0_PortOnlyOutput = 0        ' set to 1 on PortC of ATMega103


' Address Pins A1
ATA_Pin_DA1 Alias PinB.6
ATA_Port_DA1 Alias PortB.6
Const ATA_DA1_PortOnlyOutput = 0        ' set to 1 on PortC of ATMega103


' Address Pins A2
ATA_Pin_DA2 Alias PinB.7
ATA_Port_DA2 Alias PortB.7
Const ATA_DA2_PortOnlyOutput = 0        ' set to 1 on PortC of ATMega103


'--- other Drive Control Pins -------------------------------------------------

' CS0 on HD-IDE / CE1 on CF-Card
ATA_Pin_CS0 Alias PinB.0
ATA_Port_CS0 Alias PortB.0
Const ATA_CS0_PortOnlyOutput = 0        ' set to 1 on PortC of ATMega103
Const ATA_CS0_ActiveLevel = 0           ' 0 for direct connect
                                        ' or 1 at address-decoding but depends of real hard ware

' CS1 on HD-IDE / CE2 on CF-Card
Const ATA_CS1_Connected = 1             ' Not used on Cf-Card => 0 and CE2 to High (VCC) level
ATA_Pin_CS1 Alias PinB.1
ATA_Port_CS1 Alias PortB.1
Const ATA_CS1_PortOnlyOutput = 0        ' set to 1 on PortC of ATMega103


' DIOR / OE
ATA_Pin_DIOR Alias PinB.3
ATA_Port_DIOR Alias PortB.3
Const ATA_DIOR_PortOnlyOutput = 0       ' set to 1 on PortC of ATMega103


' DIOW / WE
ATA_Pin_DIOW Alias PinB.4
ATA_Port_DIOW Alias PortB.4
Const ATA_DIOW_PortOnlyOutput = 0       ' set to 1 on PortC of ATMega103


' Reset
Const ATA_Reset_Connected = 1
ATA_Pin_Reset Alias PinB.2
ATA_Port_Reset Alias PortB.2
Const ATA_Reset_PortOnlyOutput = 0      ' set to 1 on PortC of ATMega103
Const ATA_Reset_ActiveLevel = 0         ' set to 1 on CF-Card; set to 0 on hard disk


' Card/Drive Detect CD1
Const ATA_CD1_Connected = 0
#IF ATA_CD1_Connected = 1
ATA_Pin_CD1 Alias PinB.1
ATA_Port_CD1 Alias PortB.1              ' needed for internal Pull up
#ENDIF
Const ATA_CD1_PortInputOnly = 0         ' set to 1 on PortF of ATMega103


Const Waitms_AfterReset = 100

'=== End of User definable area ================================================

' Error-Constants from Driver (use 224 to 255)
Const cpErrDriveNotPresent = 225
Const cpErrDriveTimeOut = 226
const cpErrDriveTimeOutCommand = 227
Const cpErrDriveTimeOutData = 228
Const cpErrDriveTimeOutBusy = 229
Const cpErrDriveError = 230


' Init the Drive
Dim Gbdriveerror As Byte
Dim Gbdriveerrorreg As Byte                                 ' Driver load Error-Register of HD in case of error
Dim Gbdrivestatusreg As Byte                                ' Driver load Status-Register of HD on case of error
Dim Gbdrivesense As Byte
Dim Gbdrivedebug As Byte
gbDriveError = Driveinit()
waitms 1


$Lib "CF_HD.lbx"