home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / cdplay2 / dma.h < prev    next >
C/C++ Source or Header  |  1993-02-24  |  8KB  |  224 lines

  1. /***************************************************************************
  2.    Program Name     : n/a
  3.    System Name      : Atari ST and TT
  4.    Program Author   : Copyright (c) 1991 ICD Inc.
  5.                         All rights reserved
  6.                     : Modified for PURE C (Brian J. Grier)
  7.    Language         : Personal Pascal (Pascal Plus)
  8.    Module Name      : DMA.H (converted from DMA.I by B.Grier)
  9.    Purpose          : This is the header file for DMA.O.  It contains
  10.                         routines for direct hard drive access as well
  11.                         as an interface to tables within the ICD hard
  12.                         disk driver (ICDBOOT.PRG).
  13. ****************************************************************************/
  14.  
  15. /*
  16.  *  This revision posted 6-6-1991.  A number of significant changes have
  17.  *  been made.  The FSCSI and SFSCSI commands are gone.  Full scsi commands
  18.  *  are now indicated by a bit in a FLAGS word.  SCSI ID is no longer
  19.  *  embedded in the command frame.  SCSI ID's can now range from 0 to 15.
  20.  *  0 to 7 will reference devices connected to the DMA port on ST and TT.
  21.  *  8 through 15 reference devices connected to the TT internal SCSI bus.
  22.  */
  23.  
  24.  
  25. /*
  26.  *      Structures kept within the ICDBOOT hard disk driver
  27.  *      ---------------------------------------------------
  28.  */
  29.  
  30. /*
  31.         Define needed constants
  32. */
  33.  
  34. #define   READ_DIR         0
  35. #define   WRITE_DIR        1
  36. #define   FULLSCSI         2
  37. #define   ONE_SECOND  150000l
  38.  
  39. typedef struct {
  40.    int   recsiz ;        /* # bytes/sector */
  41.    int   clsiz ;         /* # sectors/cluster */
  42.    int   clsizb ;        /* # bytes/cluster */
  43.    int   rdlen ;         /* # sectors/dir */
  44.    int   fsiz ;          /* # sectors/FAT */
  45.    int   fatrec ;        /* sector # of 2nd FAT */
  46.    int   datrec ;        /* sector # of first data cluster */
  47.    int   numcl ;         /* # data clusters */
  48.    int   bflags ;        /* bits/FAT entry flag: 1=16 bit? */
  49. } bios_block ;
  50.  
  51.  
  52. typedef struct {
  53.    int         units ;         /* # SCSI IDs online */
  54.    char        id[16] ;
  55.    char        lun[16] ;
  56.    long        start[16] ;
  57.    bios_block  bpb[16] ;
  58.    char        change[16] ;
  59.    long        sizes[16] ;
  60. } drive_parameters ;
  61.  
  62. typedef  drive_parameters  * p_drive_parameters ;
  63.  
  64. /*
  65.  *  typedef  barray * char ;
  66.  *  typedef  bptr   * char ;  { generic byte pointer }
  67.  */
  68.  
  69. typedef union {
  70.    char     Data[16] ;
  71.    char     buf[1] ;
  72. } Com_Rec ;
  73.  
  74. typedef union {
  75.    char     bytes[512] ;
  76.    int      words[256] ;
  77.    long     longs[128] ;
  78.    char     buf[512] ;
  79. } Dat_Rec ;
  80.  
  81.  
  82.  
  83. /*
  84. =========================================================================
  85.                Interface to ICDBOOT.PRG
  86.                ------------------------
  87.  
  88. ICDBOOT: return ptr to drive parameter block
  89.  
  90.     return:
  91.         NIL     = Driver is not present
  92.         !NIL    = ptr to parameter block
  93.  
  94. ICDHEAD: return ptr to beginning of ICDBOOT image. This is used by internal
  95.         ICD utilities and the exact structure is undocumented.
  96.  
  97.     return:
  98.         NIL     = Driver is not present
  99.         !NIL    = ptr to beginning of driver
  100.  
  101. RELOG:  Rescan all partitions and reset all internal tables
  102.  
  103.     return:
  104.         TRUE:   = success
  105.         FALSE:  = driver not present or bad version of ICDBOOT
  106.  
  107. COLDBOOT: reboot system
  108. */
  109.  
  110. /*
  111. ==========================================================================
  112.                Calls to perform SCSI commands
  113.                ------------------------------
  114.  
  115. DMA:    Perform SCSI command (no retries, no REQUEST on error).
  116.  
  117.     in:
  118.       ID        = SCSI ID of device (LUN is embedded in COM_FRAME; see below)
  119.       COM_FRAME = command bytes (packed byte array)
  120.       DATA_FRAME= data buffer (packed byte array)
  121.       FLAGS     = 16 bits as follows:
  122.                      bit[0]=DMA direction.
  123.                      bit[1]=FULL SCSI. 
  124.                      bits[2]-[15] are RESERVED at this time.
  125.  
  126.                   DMA transfer direction bit:
  127.                      0 = read data from drive,
  128.                      1 = write data to drive.
  129.  
  130.                   FULL SCSI bit:
  131.                      0 = ACSI format
  132.                             COM_FRAME is always 6 bytes long.
  133.                             COMMAND BYTE is byte[0]
  134.                             LUN is top 3 bits of byte[1]
  135.                      1 = SCSI format
  136.                             COM_FRAME length is variable; length in byte[0]
  137.                             COMMAND BYTE is byte[1]
  138.                             LUN is top 3 bits of byte[2]
  139.       BLOCKS    = number 512 byte blocks to transfer (round up
  140.                     for non-512 byte multiples)
  141.       TIMEOUT   = timeout value used for command completion (not
  142.                     SCSI selection timeout - selection is fixed at
  143.                     100 ms). 150000 is one second and is NOT dependent
  144.                     on cpu or speed
  145.  
  146.     return:
  147.       0         = success
  148.       2         = indicates an error (do a REQUEST to get actual
  149.                     error sense code)
  150.       -1        = timeout after sending command (drive is not responding)
  151.       -2        = timeout while sending command
  152.       -3        = this ID skipped by ICDBOOT
  153.  
  154. XDMA:   Performs DMA with retries. No retries are performed if the
  155.         drive timed out. Retries are performed only when DMA returns
  156.         a code 2, in which case XDMA does a REQUEST and tries DMA again.
  157.  
  158.     in:
  159.             same as DMA
  160.  
  161.     return:
  162.       0         = success
  163.       -1        = timeout after sending command (drive is not responding)
  164.       -2        = timeout while sending command
  165.       -3        = this ID skipped by ICDBOOT
  166.       127       = REQUEST fails (parity error?)
  167.       1-126     = sense code from drive
  168.       128-252   = more sense codes (not used by most SCSI devices)
  169.  
  170. SXDMA:  Performs XDMA but is used when a non-multiple of 16 bytes needs
  171.         to be returned from the SCSI device. (For example doing a MODESENSE).
  172.         The ST DMA chip has a bug where the FIFO will not flush its data
  173.         when not full in receive mode. This function compensates for this by
  174.         performing the command 4 times without resetting the DMA chip.
  175.         USE ON READ COMMANDS ONLY.
  176.  
  177.     in:
  178.             same as DMA
  179.  
  180.     return:
  181.             same as XDMA
  182.  
  183. REQUEST: Performs a REQUEST SENSE on the SCSI device.
  184.  
  185.     in:
  186.       id        = SCSI ID of device
  187.       lun       = LUN of device
  188.  
  189.     return:
  190.       0         = success
  191.       -1        = timeout after sending command (drive is not responding)
  192.       -2        = timeout while sending command
  193.       -3        = this ID skipped by ICDBOOT
  194.       127       = REQUEST fails (parity error?)
  195.       1-126     = sense code from drive
  196.       128-252   = more sense codes (not used by most SCSI devices)
  197.  
  198. */
  199.  
  200. extern p_drive_parameters ICDBOOT(void) ;
  201.  
  202. extern char              *ICDHEAD(void) ;
  203.  
  204. extern void /*boolean*/   RELOG(void) ;      /* rescan all partitions */
  205.  
  206. extern void               COLDBOOT(void) ;
  207.  
  208. /*
  209. extern int pascal REQUEST(int id, int lun) ;
  210. */
  211.  
  212. extern int _dma(int id, char *com_frame, char *data_frame,
  213.                  int flags, int blocks, long timeout) ;
  214.  
  215. extern int _xdma(int id, char *com_frame, char *data_frame,
  216.                  int flags, int blocks, long timeout) ;
  217.  
  218. extern int _sxdma(int id, char *com_frame, char *data_frame,
  219.                  int flags, int blocks, long timeout) ;
  220.  
  221. extern int       ID,LUN ;             /* global SCSI ID/LUN          */
  222. extern Com_Rec   Command ;            /* global SCSI command buffer  */
  223. extern Dat_Rec   SecBuf ;             /* global sector buffer        */
  224.