#ifndef IDE_H
#define IDE_H

// ATA commands
//
#define IDE_RECALIBRATE      0x10
#define IDE_READ_SECTOR      0x20
#define IDE_WRITE_SECTOR     0x30
#define IDE_VERIFY_SECTOR    0x40
#define IDE_SEEK             0x70
#define IDE_SET_DRV_PARAM    0x91
#define IDE_SET_FEATURES     0xEF
#define IDE_STANDBYIMMEDIATE 0xE0
#define IDE_IDLEIMMEDIATE    0xE1
#define IDE_STANDBY          0xE2
#define IDE_IDLE             0xE3
#define IDE_CHECKPOWERMODE   0xE5
#define IDE_IDENTIFY         0xEC
#define IDE_SET_FEATURES     0xEF

// ATA Status-Bits
//
#define IDE_STS_BSY    0x80
#define IDE_STS_DRDY   0x40
#define IDE_STS_DWF    0x20
#define IDE_STS_DSC    0x10
#define IDE_STS_DRQ    0x08
#define IDE_STS_CORR   0x04
#define IDE_STS_ERR    0x01

// ATA Error-Bits
//
#define IDE_ERR_BBK    0x80
#define IDE_ERR_UNC    0x40
#define IDE_ERR_TMOUT  0x20
#define IDE_ERR_IDNF   0x10
#define IDE_ERR_ABRT   0x04
#define IDE_ERR_TK0NF  0x02
#define IDE_ERR_AMNF   0x01


// IDE_SET_FEATURES subcodes
//
#define  FEAT_EN_ADVANCED_POWER_MANAGE   0x05
#define  FEAT_DIS_ADVANCED_POWER_MANAGE  0x85
#define  FEAT_EN_POWER_UP_IN_STANDBY     0x06
#define  FEAT_DIS_POWER_UP_IN_STANDBY    0x86
#define  FEAT_EN_ACOUSTIC_MANAGE         0x42
#define  FEAT_DIS_ACOUSTIC_MANAGE        0xC2

typedef struct {
  unsigned  id;
  unsigned  sector_size;
  unsigned  cylinders;
  unsigned  heads;
  unsigned  sectors;
  unsigned  long totalSectors;
  unsigned  long totalKBytes;

  char      serial[20+1];
  char      firmware[8+1];
  char      model[40+1];
} DeviceInfo;


extern  void  IDE_Reset();
extern  int   IDE_Identify(DeviceInfo *info);
extern  int   IDE_Read(unsigned cyl, unsigned head, unsigned sect,
                       int  cnt, char *buf);
extern  int   IDE_ReadVerify(unsigned cyl, unsigned head, unsigned sect,
                             int  cnt);
extern  int   IDE_Write(unsigned cyl, unsigned head, unsigned sect,
                        int  cnt, char *buf);

extern  void  IDE_Standby();

extern  int   IDE_SetFeatures( unsigned char feat,
                unsigned c, unsigned char h, unsigned char s,
                unsigned char cnt);

#endif

