DEADSOFTWARE

335fcba7289c27280927fb91186b7904f600052e
[d2df-sdl.git] / src / lib / sdl2 / sdlrwops.inc
1 //from "sdl_rwops"
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 *}
12 type
13 PSDL_RWops = ^TSDL_RWops;
15 {**
16 * This is the read/write operation structure -- very basic.
17 *}
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}
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}
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 *}
39 TRead = function(context: PSDL_RWops; ptr: Pointer; size: size_t; maxnum: size_t): size_t; {$IFNDEF GPC} cdecl; {$ENDIF}
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 *}
48 TWrite = function(context: PSDL_RWops; const ptr: Pointer; size: size_t; num: size_t): size_t; {$IFNDEF GPC} cdecl; {$ENDIF}
50 {**
51 * Close and free an allocated SDL_RWops structure.
52 *
53 * 0 if successful or -1 on write error when flushing data.
54 *}
56 TClose = function(context: PSDL_RWops): SInt32; {$IFNDEF GPC} cdecl; {$ENDIF}
58 TStdio = record
59 autoclose: TSDL_Bool;
60 fp: file;
61 end;
63 TMem = record
64 base: PUInt8;
65 here: PUInt8;
66 stop: PUInt8;
67 end;
69 TUnknown = record
70 data1: Pointer;
71 end;
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;
85 TWindowsIOBuffer = record
86 data: Pointer;
87 size: size_t;
88 left: size_t;
89 end;
91 TWindowsIO = record
92 append: TSDL_Bool;
93 h: Pointer;
94 buffer: TWindowsIOBuffer;
95 end;
97 TSDL_RWops = packed record
98 size: TSize;
99 seek: TSeek;
100 read: TRead;
101 write: TWrite;
102 close: TClose;
104 _type: UInt32;
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;
118 {**
119 * RWFrom functions
121 * Functions to create SDL_RWops structures from various data streams.
122 *}
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};
126 {function SDL_RWFromFP(fp: file; autoclose: TSDL_Bool): PSDL_RWops; cdecl; external SDL_LibName;} //don't know if this works
128 function SDL_RWFromFP(fp: Pointer; autoclose: TSDL_Bool): PSDL_RWops; cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_RWFromFP' {$ENDIF} {$ENDIF};
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};
133 {*RWFrom functions*}
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};
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 *}
144 {**
145 * Read/write macros
147 * Macros to easily read and write from an SDL_RWops structure.
148 *}
150 function SDL_RWsize(ctx: PSDL_RWops): SInt64; {$IFNDEF DELPHI} inline; {$ELSE} {$IFDEF DELPHI10UP} inline; {$ENDIF} {$ENDIF}
151 function SDL_RWseek(ctx: PSDL_RWops; offset: SInt64; whence: SInt32): SInt64; {$IFNDEF DELPHI} inline; {$ELSE} {$IFDEF DELPHI10UP} inline; {$ENDIF} {$ENDIF}
152 function SDL_RWtell(ctx: PSDL_RWops): SInt64; {$IFNDEF DELPHI} inline; {$ELSE} {$IFDEF DELPHI10UP} inline; {$ENDIF} {$ENDIF}
153 function SDL_RWread(ctx: PSDL_RWops; ptr: Pointer; size: size_t; n: size_t): size_t; {$IFNDEF DELPHI} inline; {$ELSE} {$IFDEF DELPHI10UP} inline; {$ENDIF} {$ENDIF}
154 function SDL_RWwrite(ctx: PSDL_RWops; ptr: Pointer; size: size_t; n: size_t): size_t; {$IFNDEF DELPHI} inline; {$ELSE} {$IFDEF DELPHI10UP} inline; {$ENDIF} {$ENDIF}
155 function SDL_RWclose(ctx: PSDL_RWops): SInt32; {$IFNDEF DELPHI} inline; {$ELSE} {$IFDEF DELPHI10UP} inline; {$ENDIF} {$ENDIF}
156 { Read/write macros }
159 {**
160 * Read endian functions
162 * Read an item of the specified endianness and return in native format.
163 *}
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};
173 {*Read endian functions*}
175 {**
176 * Write endian functions
178 * Write an item of native format to the specified endianness.
179 *}
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 }