actual version
[sdl-headers.git] / sdlrwops.inc
1 //from "sdl_rwops"
2
3 const
4   {* RWops Types *}
5   SDL_RWOPS_UNKNOWN       = 0;  {* Unknown stream type *}
6   SDL_RWOPS_WINFILE       = 1;  {* Win32 file *}
7   SDL_RWOPS_STDFILE       = 2;  {* Stdio file *}
8   SDL_RWOPS_JNIFILE       = 3;  {* Android asset *}
9   SDL_RWOPS_MEMORY    = 4;      {* Memory stream *}
10   SDL_RWOPS_MEMORY_RO = 5;      {* Read-Only memory stream *}
11
12 type
13   PSDL_RWops = ^TSDL_RWops;
14
15   {**
16    * This is the read/write operation structure -- very basic.
17    *}
18
19   {**
20    *  Return the size of the file in this rwops, or -1 if unknown
21    *}
22   TSize = function(context: PSDL_RWops): SInt64; {$IFNDEF GPC} cdecl; {$ENDIF}
23
24   {**
25    *  Seek to offset relative to whence, one of stdio's whence values:
26    *  RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
27    *
28    *  the final offset in the data stream, or -1 on error.
29    *}
30   TSeek = function(context: PSDL_RWops; offset: SInt64; whence: SInt32): SInt64; {$IFNDEF GPC} cdecl; {$ENDIF}
31                    
32   {**
33    *  Read up to maxnum objects each of size size from the data
34    *  stream to the area pointed at by ptr.
35    *
36    *  the number of objects read, or 0 at error or end of file.
37    *}
38
39    TRead = function(context: PSDL_RWops; ptr: Pointer; size: size_t; maxnum: size_t): size_t; {$IFNDEF GPC} cdecl; {$ENDIF}
40
41   {**
42    *  Write exactly num objects each of size size from the area
43    *  pointed at by ptr to data stream.
44    *  
45    *  the number of objects written, or 0 at error or end of file.
46    *}
47         
48    TWrite = function(context: PSDL_RWops; const ptr: Pointer; size: size_t; num: size_t): size_t; {$IFNDEF GPC} cdecl; {$ENDIF}
49         
50   {**
51    *  Close and free an allocated SDL_RWops structure.
52    *  
53    *  0 if successful or -1 on write error when flushing data.
54    *}
55
56   TClose =  function(context: PSDL_RWops): SInt32; {$IFNDEF GPC} cdecl; {$ENDIF}
57
58   TStdio = record
59     autoclose: TSDL_Bool;
60         fp: file;
61   end;
62   
63   TMem = record
64     base: PUInt8;
65         here: PUInt8;
66         stop: PUInt8;
67   end;
68   
69   TUnknown = record
70     data1: Pointer;
71   end;
72
73   TAndroidIO = record
74     fileNameRef: Pointer;
75     inputStreamRef: Pointer;
76     readableByteChannelRef: Pointer;
77     readMethod: Pointer;
78     assetFileDescriptorRef: Pointer;
79     position: LongInt;
80     size: LongInt;
81     offset: LongInt;
82     fd: SInt32;
83   end;
84
85   TWindowsIOBuffer = record
86     data: Pointer;
87         size: size_t;
88         left: size_t;
89   end;
90
91   TWindowsIO = record
92     append: TSDL_Bool;
93     h: Pointer;
94     buffer: TWindowsIOBuffer;
95   end;
96
97   TSDL_RWops = packed record
98     size: TSize;
99     seek: TSeek;
100     read: TRead;
101     write: TWrite;
102     close: TClose;
103
104     _type: UInt32;
105
106         case Integer of
107           0: (stdio: TStdio);
108           1: (mem: TMem);
109           2: (unknown: TUnknown);
110           {$IFDEF ANDROID}
111           3: (androidio: TAndroidIO);
112           {$ENDIF}
113           {$IFDEF WINDOWS}
114           3: (windowsio: TWindowsIO);
115           {$ENDIF}
116   end;
117
118   {**
119    *  RWFrom functions
120    *
121    *  Functions to create SDL_RWops structures from various data streams.
122    *}
123
124 function SDL_RWFromFile(const _file: PAnsiChar; const mode: PAnsiChar): PSDL_RWops; cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_RWFromFile' {$ENDIF} {$ENDIF};
125
126   {function SDL_RWFromFP(fp: file; autoclose: TSDL_Bool): PSDL_RWops; cdecl; external SDL_LibName;} //don't know if this works
127
128 function SDL_RWFromFP(fp: Pointer; autoclose: TSDL_Bool): PSDL_RWops; cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_RWFromFP' {$ENDIF} {$ENDIF};
129
130 function SDL_RWFromMem(mem: Pointer; size: SInt32): PSDL_RWops; cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_RWFromMem' {$ENDIF} {$ENDIF};
131 function SDL_RWFromConstMem(const mem: Pointer; size: SInt32): PSDL_RWops; cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_RWFromConstMem' {$ENDIF} {$ENDIF};
132
133 {*RWFrom functions*}
134
135
136 function SDL_AllocRW: PSDL_RWops; cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_AllocRW' {$ENDIF} {$ENDIF};
137 procedure SDL_FreeRW(area: PSDL_RWops); cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_FreeRW' {$ENDIF} {$ENDIF};
138
139 const
140   RW_SEEK_SET = 0;       {**< Seek from the beginning of data *}
141   RW_SEEK_CUR = 1;       {**< Seek relative to current read point *}
142   RW_SEEK_END = 2;       {**< Seek relative to the end of data *}
143
144   {**
145    *  Read/write macros
146    *
147    *  Macros to easily read and write from an SDL_RWops structure.
148    *}
149
150   function SDL_RWsize(ctx: PSDL_RWops): SInt64;
151   function SDL_RWseek(ctx: PSDL_RWops; offset: SInt64; whence: SInt32): SInt64;
152   function SDL_RWtell(ctx: PSDL_RWops): SInt64;
153   function SDL_RWread(ctx: PSDL_RWops; ptr: Pointer; size: size_t; n: size_t): size_t;
154   function SDL_RWwrite(ctx: PSDL_RWops; ptr: Pointer; size: size_t; n: size_t): size_t;
155   function SDL_RWclose(ctx: PSDL_RWops): SInt32;
156   { Read/write macros }
157
158
159   {**
160    *  Read endian functions
161    *
162    *  Read an item of the specified endianness and return in native format.
163    *}
164
165 function SDL_ReadU8(src: PSDL_RWops): UInt8 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ReadU8' {$ENDIF} {$ENDIF};
166 function SDL_ReadLE16(src: PSDL_RWops): UInt16 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ReadLE16' {$ENDIF} {$ENDIF};
167 function SDL_ReadBE16(src: PSDL_RWops): UInt16 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ReadBE16' {$ENDIF} {$ENDIF};
168 function SDL_ReadLE32(src: PSDL_RWops): UInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ReadLE32' {$ENDIF} {$ENDIF};
169 function SDL_ReadBE32(src: PSDL_RWops): UInt32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ReadBE32' {$ENDIF} {$ENDIF};
170 function SDL_ReadLE64(src: PSDL_RWops): UInt64 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ReadLE64' {$ENDIF} {$ENDIF};
171 function SDL_ReadBE64(src: PSDL_RWops): UInt64 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ReadBE64' {$ENDIF} {$ENDIF};
172
173   {*Read endian functions*}
174
175   {**
176    *  Write endian functions
177    *
178    *  Write an item of native format to the specified endianness.
179    *}
180
181 function SDL_WriteU8(dst: PSDL_RWops; value: UInt8): size_t cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WriteU8' {$ENDIF} {$ENDIF};
182 function SDL_WriteLE16(dst: PSDL_RWops; value: UInt16): size_t cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WriteLE16' {$ENDIF} {$ENDIF};
183 function SDL_WriteBE16(dst: PSDL_RWops; value: UInt16): size_t cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WriteBE16' {$ENDIF} {$ENDIF};
184 function SDL_WriteLE32(dst: PSDL_RWops; value: UInt32): size_t cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WriteLE32' {$ENDIF} {$ENDIF};
185 function SDL_WriteBE32(dst: PSDL_RWops; value: UInt32): size_t cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WriteBE32' {$ENDIF} {$ENDIF};
186 function SDL_WriteLE64(dst: PSDL_RWops; value: UInt64): size_t cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WriteLE64' {$ENDIF} {$ENDIF};
187 function SDL_WriteBE64(dst: PSDL_RWops; value: UInt64): size_t cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_WriteBE64' {$ENDIF} {$ENDIF};
188   { Write endian functions }