home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / midas / rawfile.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-06  |  8KB  |  244 lines

  1. {*      RAWFILE.H
  2.  *
  3.  * Raw file I/O for MIDAS Sound System
  4.  *
  5.  * Copyright 1994 Petteri Kangaslampi and Jarno Paananen
  6.  *
  7.  * This file is part of the MIDAS Sound System, and may only be
  8.  * used, modified and distributed under the terms of the MIDAS
  9.  * Sound System license, LICENSE.TXT. By continuing to use,
  10.  * modify or distribute this file you indicate that you have
  11.  * read the license and understand and accept it fully.
  12. *}
  13.  
  14.  
  15. unit rawFile;
  16.  
  17.  
  18. interface
  19.  
  20.  
  21. {****************************************************************************\
  22. *       struct rfFile
  23. *       -------------
  24. * Description:  File state structure
  25. \****************************************************************************}
  26.  
  27. type
  28.     rfFile = Record
  29.         handle : word;
  30.     end;
  31.  
  32.  
  33.  
  34. {****************************************************************************\
  35. *       typedef rfHandle;
  36. *       -----------------
  37. * Description: Raw file I/O file handle
  38. \****************************************************************************}
  39.  
  40. type
  41.     rfHandle = ^rfFile;
  42.     PrfHandle = ^rfHandle;
  43.  
  44.  
  45.  
  46. {****************************************************************************\
  47. *       enum rfOpenMode
  48. *       ---------------
  49. * Description:  File opening mode. Used by rfOpen()
  50. \****************************************************************************}
  51.  
  52. const
  53.     rfOpenRead = 1;                     { open file for reading }
  54.     rfOpenWrite = 2;                    { open file for writing }
  55.     rfOpenReadWrite = 3;                { open file for both reading and
  56.                                           writing }
  57.  
  58.  
  59.  
  60. {****************************************************************************\
  61. *       enum rfSeekMode
  62. *       ---------------
  63. * Description:  File seeking mode. Used by rfSeek()
  64. \****************************************************************************}
  65.  
  66. const
  67.     rfSeekAbsolute = 1;                 { seek to an absolute position from
  68.                                           the beginning of the file }
  69.     rfSeekRelative = 2;                 { seek to a position relative to
  70.                                           current position }
  71.     rfSeekEnd = 3;                      { seek relative to the end of file }
  72.  
  73.  
  74. type
  75.     Pchar = ^char;
  76.     Plongint = ^longint;
  77.  
  78.  
  79. {****************************************************************************\
  80. *
  81. * Function:     rfOpen(fileName : Pchar; openMode : integer;
  82. *                   fileh : PrfHandle) : integer;
  83. *
  84. * Description:  Opens a file for reading or writing
  85. *
  86. * Input:        fileName : Pchar        pointer to name of file name, ASCIIZ!
  87. *               openMode : integer      file opening mode, see enum rfOpenMode
  88. *               fileh : PrfHandle       pointer to file handle
  89. *
  90. * Returns:      MIDAS error code.
  91. *               File handle is stored in fileh^.
  92. *
  93. \****************************************************************************}
  94.  
  95. function rfOpen(fileName : Pchar; openMode : integer; fileh : PrfHandle)
  96.     : integer;
  97.  
  98.  
  99.  
  100. {****************************************************************************\
  101. *
  102. * Function:     rfClose(fileh : rfHandle) : integer;
  103. *
  104. * Description:  Closes a file opened with rfOpen().
  105. *
  106. * Input:        fileh : rfHandle        handle of an open file
  107. *
  108. * Returns:      MIDAS error code
  109. *
  110. \****************************************************************************}
  111.  
  112. function rfClose(fileh : rfHandle) : integer;
  113.  
  114.  
  115.  
  116.  
  117. {****************************************************************************\
  118. *
  119. * Function:     rfGetSize(fileh : rfHandle; fileSize : Plongint) : integer;
  120. *
  121. * Description:  Get the size of a file
  122. *
  123. * Input:        fileh : rfHandle        handle of an open file
  124. *               fileSize : Plongint     pointer to file size
  125. *
  126. * Returns:      MIDAS error code.
  127. *               File size is stored in fileSize^.
  128. *
  129. \****************************************************************************}
  130.  
  131. function rfGetSize(fileh : rfHandle; fileSize : Plongint) : integer;
  132.  
  133.  
  134.  
  135.  
  136. {****************************************************************************\
  137. *
  138. * Function:     rfRead(fileh : rfHandle; buffer : pointer;
  139. *                   numBytes : longint) : integer;
  140. *
  141. * Description:  Reads binary data from a file
  142. *
  143. * Input:        fileh : rfHandle        file handle
  144. *               buffer : pointer        reading buffer
  145. *               numBytes : longint      number of bytes to read
  146. *
  147. * Returns:      MIDAS error code.
  148. *               Read data is stored in buffer^, which must be large enough
  149. *               for it.
  150. *
  151. \****************************************************************************}
  152.  
  153. function rfRead(fileh : rfHandle; buffer : pointer; numBytes : longint)
  154.     : integer;
  155.  
  156.  
  157.  
  158.  
  159. {****************************************************************************\
  160. *
  161. * Function:     rfWrite(fileh : rfHandle; buffer : pointer;
  162. *               numBytes : longint) : integer;
  163. *
  164. * Description:  Writes binary data to a file
  165. *
  166. * Input:        fileh : rfHandle        file handle
  167. *               buffer : pointer        pointer to data to be written
  168. *               numBytes : longint      number of bytes to write
  169. *
  170. * Returns:      MIDAS error code
  171. *
  172. \****************************************************************************}
  173.  
  174. function rfWrite(fileh : rfHandle; buffer : pointer; numBytes : longint)
  175.     : integer;
  176.  
  177.  
  178.  
  179.  
  180. {****************************************************************************\
  181. *
  182. * Function:     rfSeek(fileh : rfHandle; newPosition : longint;
  183. *               seekMode : integer) : integer;
  184. *
  185. * Description:  Seeks to a new position in file. Subsequent reads and writes
  186. *               go to the new position.
  187. *
  188. * Input:        fileh : rfHandle        file handle
  189. *               newPosition : longint   new file position
  190. *               seekMode : integer      file seek mode, see enum rfSeekMode
  191. *
  192. * Returns:      MIDAS error code
  193. *
  194. \****************************************************************************}
  195.  
  196. function rfSeek(fileh : rfHandle; newPosition : longint; seekMode : integer)
  197.     : integer;
  198.  
  199.  
  200.  
  201.  
  202. {****************************************************************************\
  203. *
  204. * Function:     int rfGetPosition(fileh : rfHandle; position : Plongint)
  205. *                   : integer;
  206. *
  207. * Description:  Reads the current position in a file
  208. *
  209. * Input:        fileh : rfHandle        file handle
  210. *               position : Plongint     pointer to file position
  211. *
  212. * Returns:      MIDAS error code.
  213. *               Current file position is stored in position^.
  214. *
  215. \****************************************************************************}
  216.  
  217. function rfGetPosition(fileh : rfHandle; position : Plongint) : integer;
  218.  
  219.  
  220.  
  221. implementation
  222.  
  223.  
  224. uses    Errors, mMem;
  225.  
  226.  
  227.  
  228. function rfOpen(fileName : Pchar; openMode : integer; fileh : PrfHandle)
  229.     : integer; external;
  230. function rfClose(fileh : rfHandle) : integer; external;
  231. function rfGetSize(fileh : rfHandle; fileSize : Plongint) : integer; external;
  232. function rfRead(fileh : rfHandle; buffer : pointer; numBytes : longint)
  233.     : integer; external;
  234. function rfWrite(fileh : rfHandle; buffer : pointer; numBytes : longint)
  235.     : integer; external;
  236. function rfSeek(fileh : rfHandle; newPosition : longint; seekMode : integer)
  237.     : integer; external;
  238. function rfGetPosition(fileh : rfHandle; position : Plongint) : integer;
  239.     external;
  240. {$L ASMRFILE.OBJ}
  241.  
  242.  
  243. END.
  244.