sdlrwops.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. //based on "sdl_rwops" (2.0.14)
  2. {**
  3. * \file SDL_rwops.h
  4. *
  5. * This file provides a general interface for SDL to read and write
  6. * data streams. It can easily be extended to files, memory, etc.
  7. *}
  8. const
  9. {* RWops Types *}
  10. SDL_RWOPS_UNKNOWN = 0; {* Unknown stream type *}
  11. SDL_RWOPS_WINFILE = 1; {* Win32 file *}
  12. SDL_RWOPS_STDFILE = 2; {* Stdio file *}
  13. SDL_RWOPS_JNIFILE = 3; {* Android asset *}
  14. SDL_RWOPS_MEMORY = 4; {* Memory stream *}
  15. SDL_RWOPS_MEMORY_RO = 5; {* Read-Only memory stream *}
  16. type
  17. PPSDL_RWops = ^PSDL_RWops;
  18. PSDL_RWops = ^TSDL_RWops;
  19. {**
  20. * This is the read/write operation structure -- very basic.
  21. *}
  22. {**
  23. * Return the size of the file in this rwops, or -1 if unknown
  24. *}
  25. TSize = function(context: PSDL_RWops): cint64; {$IFNDEF GPC} cdecl; {$ENDIF}
  26. {**
  27. * Seek to offset relative to whence, one of stdio's whence values:
  28. * RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
  29. *
  30. * the final offset in the data stream, or -1 on error.
  31. *}
  32. TSeek = function(context: PSDL_RWops; offset: cint64; whence: cint): cint64; {$IFNDEF GPC} cdecl; {$ENDIF}
  33. {**
  34. * Read up to maxnum objects each of size size from the data
  35. * stream to the area pointed at by ptr.
  36. *
  37. * the number of objects read, or 0 at error or end of file.
  38. *}
  39. TRead = function(context: PSDL_RWops; ptr: Pointer; size: csize_t; maxnum: csize_t): csize_t; {$IFNDEF GPC} cdecl; {$ENDIF}
  40. {**
  41. * Write exactly num objects each of size size from the area
  42. * pointed at by ptr to data stream.
  43. *
  44. * the number of objects written, or 0 at error or end of file.
  45. *}
  46. TWrite = function(context: PSDL_RWops; const ptr: Pointer; size: csize_t; num: csize_t): csize_t; {$IFNDEF GPC} cdecl; {$ENDIF}
  47. {**
  48. * Close and free an allocated SDL_RWops structure.
  49. *
  50. * 0 if successful or -1 on write error when flushing data.
  51. *}
  52. TClose = function(context: PSDL_RWops): cint; {$IFNDEF GPC} cdecl; {$ENDIF}
  53. // (2.0.14) Outdated decl., kept commented just in case.
  54. {TAndroidIO = record
  55. fileNameRef: Pointer;
  56. inputStreamRef: Pointer;
  57. readableByteChannelRef: Pointer;
  58. readMethod: Pointer;
  59. assetFileDescriptorRef: Pointer;
  60. position: LongInt;
  61. size: LongInt;
  62. offset: LongInt;
  63. fd: cint32;
  64. end;}
  65. TAndroidIO = record
  66. asset: Pointer;
  67. end;
  68. TWindowsIOBuffer = record
  69. data: Pointer;
  70. size: csize_t;
  71. left: csize_t;
  72. end;
  73. TWindowsIO = record
  74. append: TSDL_Bool;
  75. h: Pointer;
  76. buffer: TWindowsIOBuffer;
  77. end;
  78. TStdio = record
  79. autoclose: TSDL_Bool;
  80. fp: file; // Is this appropriate? C FILE --> Pascal file
  81. end;
  82. TMem = record
  83. base: pcuint8;
  84. here: pcuint8;
  85. stop: pcuint8;
  86. end;
  87. TUnknown = record
  88. data1: Pointer;
  89. data2: Pointer;
  90. end;
  91. TSDL_RWops = packed record
  92. size: TSize;
  93. seek: TSeek;
  94. read: TRead;
  95. write: TWrite;
  96. close: TClose;
  97. _type: cuint32;
  98. case hidden: cint of
  99. {$IFDEF ANDROID}
  100. 0: (androidio: TAndroidIO);
  101. {$ENDIF}
  102. {$IFDEF WINDOWS}
  103. 0: (windowsio: TWindowsIO);
  104. {$ENDIF}
  105. 1: (stdio: TStdio);
  106. 2: (mem: TMem);
  107. 3: (unknown: TUnknown);
  108. end;
  109. {**
  110. * RWFrom functions
  111. *
  112. * Functions to create SDL_RWops structures from various data streams.
  113. *}
  114. function SDL_RWFromFile(const _file: PAnsiChar; const mode: PAnsiChar): PSDL_RWops; cdecl;
  115. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_RWFromFile' {$ENDIF} {$ENDIF};
  116. //function SDL_RWFromFP(fp: file; autoclose: TSDL_Bool): PSDL_RWops; cdecl;
  117. // external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF}; //don't know if this works
  118. function SDL_RWFromFP(fp: Pointer; autoclose: TSDL_Bool): PSDL_RWops; cdecl;
  119. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_RWFromFP' {$ENDIF} {$ENDIF};
  120. function SDL_RWFromMem(mem: Pointer; size: cint): PSDL_RWops; cdecl;
  121. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_RWFromMem' {$ENDIF} {$ENDIF};
  122. function SDL_RWFromConstMem(const mem: Pointer; size: cint): PSDL_RWops; cdecl;
  123. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_RWFromConstMem' {$ENDIF} {$ENDIF};
  124. {*RWFrom functions*}
  125. function SDL_AllocRW: PSDL_RWops; cdecl;
  126. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_AllocRW' {$ENDIF} {$ENDIF};
  127. procedure SDL_FreeRW(area: PSDL_RWops); cdecl;
  128. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_FreeRW' {$ENDIF} {$ENDIF};
  129. const
  130. RW_SEEK_SET = 0; {**< Seek from the beginning of data *}
  131. RW_SEEK_CUR = 1; {**< Seek relative to current read point *}
  132. RW_SEEK_END = 2; {**< Seek relative to the end of data *}
  133. {**
  134. * Return the size of the file in this rwops, or -1 if unknown
  135. *}
  136. function SDL_RWsize(context: PSDL_RWops): cint64; cdecl;
  137. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_RWsize' {$ENDIF} {$ENDIF};
  138. {**
  139. * Seek to \c offset relative to \c whence, one of stdio's whence values:
  140. * RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
  141. *
  142. * \return the final offset in the data stream, or -1 on error.
  143. *}
  144. function SDL_RWseek(context: PSDL_RWops; offset: cint64; whence: cint): cint64; cdecl;
  145. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_RWseek' {$ENDIF} {$ENDIF};
  146. {**
  147. * Return the current offset in the data stream, or -1 on error.
  148. *}
  149. function SDL_RWtell(context: PSDL_RWops): cint64; cdecl;
  150. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_RWtell' {$ENDIF} {$ENDIF};
  151. {**
  152. * Read up to \c maxnum objects each of size \c size from the data
  153. * stream to the area pointed at by \c ptr.
  154. *
  155. * \return the number of objects read, or 0 at error or end of file.
  156. *}
  157. function SDL_RWread(context: PSDL_RWops; ptr: Pointer; size: csize_t; n: csize_t): csize_t; cdecl;
  158. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_RWread' {$ENDIF} {$ENDIF};
  159. {**
  160. * Write exactly \c num objects each of size \c size from the area
  161. * pointed at by \c ptr to data stream.
  162. *
  163. * \return the number of objects written, or 0 at error or end of file.
  164. *}
  165. function SDL_RWwrite(context: PSDL_RWops; ptr: Pointer; size: csize_t; n: csize_t): csize_t; cdecl;
  166. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_RWwrite' {$ENDIF} {$ENDIF};
  167. {**
  168. * Close and free an allocated SDL_RWops structure.
  169. *
  170. * \return 0 if successful or -1 on write error when flushing data.
  171. *}
  172. function SDL_RWclose(context: PSDL_RWops): cint; cdecl;
  173. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_RWclose' {$ENDIF} {$ENDIF};
  174. {**
  175. * Load all the data from an SDL data stream.
  176. *
  177. * The data is allocated with a zero byte at the end (null terminated)
  178. *
  179. * If \c datasize is not NULL, it is filled with the size of the data read.
  180. *
  181. * If \c freesrc is non-zero, the stream will be closed after being read.
  182. *
  183. * The data should be freed with SDL_free().
  184. *
  185. * \return the data, or NULL if there was an error.
  186. *}
  187. function SDL_LoadFile_RW(src: PSDL_RWops; datasize: pcsize_t; freesrc: cint): Pointer; cdecl;
  188. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_LoadFile_RW' {$ENDIF} {$ENDIF};
  189. {**
  190. * Load an entire file.
  191. *
  192. * The data is allocated with a zero byte at the end (null terminated)
  193. *
  194. * If \c datasize is not NULL, it is filled with the size of the data read.
  195. *
  196. * If \c freesrc is non-zero, the stream will be closed after being read.
  197. *
  198. * The data should be freed with SDL_free().
  199. *
  200. * \return the data, or NULL if there was an error.
  201. *}
  202. function SDL_LoadFile(file_: PAnsiChar; datasize: pcsize_t): Pointer; cdecl;
  203. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_LoadFile' {$ENDIF} {$ENDIF};
  204. {**
  205. * Read endian functions
  206. *
  207. * Read an item of the specified endianness and return in native format.
  208. *}
  209. function SDL_ReadU8(src: PSDL_RWops): cuint8; cdecl;
  210. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ReadU8' {$ENDIF} {$ENDIF};
  211. function SDL_ReadLE16(src: PSDL_RWops): cuint16; cdecl;
  212. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ReadLE16' {$ENDIF} {$ENDIF};
  213. function SDL_ReadBE16(src: PSDL_RWops): cuint16; cdecl;
  214. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ReadBE16' {$ENDIF} {$ENDIF};
  215. function SDL_ReadLE32(src: PSDL_RWops): cuint32; cdecl;
  216. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ReadLE32' {$ENDIF} {$ENDIF};
  217. function SDL_ReadBE32(src: PSDL_RWops): cuint32; cdecl;
  218. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ReadBE32' {$ENDIF} {$ENDIF};
  219. function SDL_ReadLE64(src: PSDL_RWops): cuint64; cdecl;
  220. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ReadLE64' {$ENDIF} {$ENDIF};
  221. function SDL_ReadBE64(src: PSDL_RWops): cuint64; cdecl;
  222. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ReadBE64' {$ENDIF} {$ENDIF};
  223. { Read endian functions }
  224. {**
  225. * Write endian functions
  226. *
  227. * Write an item of native format to the specified endianness.
  228. *}
  229. function SDL_WriteU8(dst: PSDL_RWops; value: cuint8): csize_t; cdecl;
  230. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WriteU8' {$ENDIF} {$ENDIF};
  231. function SDL_WriteLE16(dst: PSDL_RWops; value: cuint16): csize_t; cdecl;
  232. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WriteLE16' {$ENDIF} {$ENDIF};
  233. function SDL_WriteBE16(dst: PSDL_RWops; value: cuint16): csize_t; cdecl;
  234. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WriteBE16' {$ENDIF} {$ENDIF};
  235. function SDL_WriteLE32(dst: PSDL_RWops; value: cuint32): csize_t; cdecl;
  236. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WriteLE32' {$ENDIF} {$ENDIF};
  237. function SDL_WriteBE32(dst: PSDL_RWops; value: cuint32): csize_t; cdecl;
  238. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WriteBE32' {$ENDIF} {$ENDIF};
  239. function SDL_WriteLE64(dst: PSDL_RWops; value: cuint64): csize_t; cdecl;
  240. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WriteLE64' {$ENDIF} {$ENDIF};
  241. function SDL_WriteBE64(dst: PSDL_RWops; value: cuint64): csize_t; cdecl;
  242. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WriteBE64' {$ENDIF} {$ENDIF};
  243. { Write endian functions }