author | unc0rr |
Sun, 28 Sep 2008 08:26:18 +0000 | |
changeset 1287 | 4a0cbcbe3521 |
parent 1225 | f882a92ef872 |
child 1556 | 3369f016b79d |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
19 |
unit SDLh; |
|
20 |
interface |
|
753 | 21 |
|
4 | 22 |
{$IFDEF LINUX} |
23 |
{$DEFINE UNIX} |
|
24 |
{$ENDIF} |
|
25 |
{$IFDEF FREEBSD} |
|
26 |
{$DEFINE UNIX} |
|
27 |
{$ENDIF} |
|
28 |
||
29 |
{$IFDEF UNIX} |
|
30 |
{$linklib c} |
|
105 | 31 |
{$linklib pthread} |
4 | 32 |
{$ENDIF} |
33 |
||
432 | 34 |
{$PACKRECORDS C} |
4 | 35 |
|
36 |
(* SDL *) |
|
37 |
const {$IFDEF WIN32} |
|
38 |
SDLLibName = 'SDL.dll'; |
|
39 |
{$ENDIF} |
|
40 |
{$IFDEF UNIX} |
|
41 |
SDLLibName = 'libSDL.so'; |
|
42 |
{$ENDIF} |
|
43 |
SDL_SWSURFACE = $00000000; |
|
44 |
SDL_HWSURFACE = $00000001; |
|
45 |
SDL_ASYNCBLIT = $00000004; |
|
46 |
SDL_ANYFORMAT = $10000000; |
|
47 |
SDL_HWPALETTE = $20000000; |
|
358 | 48 |
SDL_DOUBLEBUF = $40000000; |
4 | 49 |
SDL_FULLSCREEN = $80000000; |
50 |
SDL_NOFRAME = $00000020; |
|
51 |
SDL_HWACCEL = $00000100; |
|
52 |
SDL_SRCCOLORKEY = $00001000; |
|
53 |
SDL_RLEACCEL = $00004000; |
|
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
883
diff
changeset
|
54 |
|
4 | 55 |
SDL_NOEVENT = 0; |
308 | 56 |
SDL_ACTIVEEVENT = 1; |
4 | 57 |
SDL_KEYDOWN = 2; |
58 |
SDL_KEYUP = 3; |
|
59 |
SDL_QUITEV = 12; |
|
1120 | 60 |
SDL_VIDEORESIZE = 16; |
4 | 61 |
|
308 | 62 |
SDL_APPINPUTFOCUS = 2; |
63 |
||
4 | 64 |
SDL_INIT_VIDEO = $00000020; |
11 | 65 |
SDL_INIT_AUDIO = $00000010; |
753 | 66 |
|
67 |
SDL_GL_DOUBLEBUFFER = 5; |
|
68 |
SDL_OPENGL = 2; |
|
1120 | 69 |
SDL_RESIZABLE = $00000010; |
754 | 70 |
|
71 |
RMask = $FF; |
|
72 |
GMask = $FF00; |
|
73 |
BMask = $FF0000; |
|
74 |
AMask = $FF000000; |
|
75 |
||
4 | 76 |
type PSDL_Rect = ^TSDL_Rect; |
77 |
TSDL_Rect = record |
|
78 |
x, y: SmallInt; |
|
79 |
w, h: Word; |
|
80 |
end; |
|
81 |
||
82 |
TPoint = record |
|
105 | 83 |
X: LongInt; |
84 |
Y: LongInt; |
|
4 | 85 |
end; |
86 |
||
87 |
PSDL_PixelFormat = ^TSDL_PixelFormat; |
|
88 |
TSDL_PixelFormat = record |
|
89 |
palette: Pointer; |
|
90 |
BitsPerPixel : Byte; |
|
91 |
BytesPerPixel: Byte; |
|
92 |
Rloss : Byte; |
|
93 |
Gloss : Byte; |
|
94 |
Bloss : Byte; |
|
95 |
Aloss : Byte; |
|
96 |
Rshift: Byte; |
|
97 |
Gshift: Byte; |
|
98 |
Bshift: Byte; |
|
99 |
Ashift: Byte; |
|
100 |
RMask : Longword; |
|
101 |
GMask : Longword; |
|
102 |
BMask : Longword; |
|
103 |
AMask : Longword; |
|
104 |
colorkey: Longword; |
|
105 |
alpha : Byte; |
|
106 |
end; |
|
107 |
||
108 |
||
109 |
PSDL_Surface = ^TSDL_Surface; |
|
110 |
TSDL_Surface = record |
|
111 |
flags : Longword; |
|
112 |
format: PSDL_PixelFormat; |
|
432 | 113 |
w, h : LongInt; |
4 | 114 |
pitch : Word; |
115 |
pixels: Pointer; |
|
432 | 116 |
offset: LongInt; |
4 | 117 |
end; |
118 |
||
119 |
PSDL_Color = ^TSDL_Color; |
|
120 |
TSDL_Color = record |
|
206
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
121 |
case byte of |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
122 |
0: (r: Byte; |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
123 |
g: Byte; |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
124 |
b: Byte; |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
125 |
unused: Byte; |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
126 |
); |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
127 |
1: (value: Longword); |
4 | 128 |
end; |
129 |
||
130 |
PSDL_RWops = ^TSDL_RWops; |
|
105 | 131 |
TSeek = function( context: PSDL_RWops; offset: LongInt; whence: LongInt ): LongInt; cdecl; |
132 |
TRead = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; maxnum : LongInt ): LongInt; cdecl; |
|
133 |
TWrite = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; num: LongInt ): LongInt; cdecl; |
|
134 |
TClose = function( context: PSDL_RWops ): LongInt; cdecl; |
|
4 | 135 |
|
136 |
TStdio = record |
|
105 | 137 |
autoclose: LongInt; |
4 | 138 |
fp: pointer; |
139 |
end; |
|
140 |
||
141 |
TMem = record |
|
142 |
base: PByte; |
|
143 |
here: PByte; |
|
144 |
stop: PByte; |
|
145 |
end; |
|
146 |
||
147 |
TUnknown = record |
|
148 |
data1: Pointer; |
|
149 |
end; |
|
150 |
||
151 |
TSDL_RWops = record |
|
152 |
seek: TSeek; |
|
153 |
read: TRead; |
|
154 |
write: TWrite; |
|
155 |
close: TClose; |
|
156 |
type_: Longword; |
|
157 |
case Byte of |
|
158 |
0: (stdio: TStdio); |
|
159 |
1: (mem: TMem); |
|
160 |
2: (unknown: TUnknown); |
|
161 |
end; |
|
162 |
||
163 |
TSDL_KeySym = record |
|
164 |
scancode: Byte; |
|
106 | 165 |
sym: Longword; |
4 | 166 |
modifier: Longword; |
167 |
unicode: Word; |
|
168 |
end; |
|
169 |
||
308 | 170 |
TSDL_ActiveEvent = record |
171 |
type_: byte; |
|
1120 | 172 |
gain: byte; |
173 |
state: byte; |
|
174 |
end; |
|
308 | 175 |
|
4 | 176 |
TSDL_KeyboardEvent = record |
177 |
type_: Byte; |
|
178 |
which: Byte; |
|
179 |
state: Byte; |
|
180 |
keysym: TSDL_KeySym; |
|
181 |
end; |
|
182 |
||
183 |
TSDL_QuitEvent = record |
|
184 |
type_: Byte; |
|
185 |
end; |
|
1120 | 186 |
TSDL_ResizeEvent = record |
187 |
type_: Byte; |
|
188 |
w, h: LongInt; |
|
189 |
end; |
|
190 |
||
4 | 191 |
PSDL_Event = ^TSDL_Event; |
192 |
TSDL_Event = record |
|
193 |
case Byte of |
|
194 |
SDL_NOEVENT: (type_: byte); |
|
308 | 195 |
SDL_ACTIVEEVENT: (active: TSDL_ActiveEvent); |
4 | 196 |
SDL_KEYDOWN, SDL_KEYUP: (key: TSDL_KeyboardEvent); |
197 |
SDL_QUITEV: (quit: TSDL_QuitEvent); |
|
1120 | 198 |
SDL_VIDEORESIZE: (resize: TSDL_ResizeEvent); |
4 | 199 |
end; |
200 |
||
201 |
PByteArray = ^TByteArray; |
|
316 | 202 |
TByteArray = array[0..65535] of Byte; |
203 |
PLongWordArray = ^TLongWordArray; |
|
204 |
TLongWordArray = array[0..16383] of LongWord; |
|
4 | 205 |
|
433 | 206 |
PSDL_Thread = Pointer; |
207 |
PSDL_mutex = Pointer; |
|
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
883
diff
changeset
|
208 |
|
432 | 209 |
function SDL_Init(flags: Longword): LongInt; cdecl; external SDLLibName; |
4 | 210 |
procedure SDL_Quit; cdecl; external SDLLibName; |
432 | 211 |
function SDL_VideoDriverName(var namebuf; maxlen: LongInt): PChar; cdecl; external SDLLibName; |
212 |
procedure SDL_EnableUNICODE(enable: LongInt); cdecl; external SDLLibName; |
|
4 | 213 |
|
214 |
procedure SDL_Delay(msec: Longword); cdecl; external SDLLibName; |
|
215 |
function SDL_GetTicks: Longword; cdecl; external SDLLibName; |
|
216 |
||
217 |
function SDL_MustLock(Surface: PSDL_Surface): Boolean; |
|
432 | 218 |
function SDL_LockSurface(Surface: PSDL_Surface): LongInt; cdecl; external SDLLibName; |
4 | 219 |
procedure SDL_UnlockSurface(Surface: PSDL_Surface); cdecl; external SDLLibName; |
220 |
||
221 |
function SDL_GetError: PChar; cdecl; external SDLLibName; |
|
222 |
||
432 | 223 |
function SDL_SetVideoMode(width, height, bpp: LongInt; flags: Longword): PSDL_Surface; cdecl; external SDLLibName; |
224 |
function SDL_CreateRGBSurface(flags: Longword; Width, Height, Depth: LongInt; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName; |
|
225 |
function SDL_CreateRGBSurfaceFrom(pixels: Pointer; width, height, depth, pitch: LongInt; RMask, GMask, BMask, AMask: Longword): PSDL_Surface; cdecl; external SDLLibName; |
|
4 | 226 |
procedure SDL_FreeSurface(Surface: PSDL_Surface); cdecl; external SDLLibName; |
105 | 227 |
function SDL_SetColorKey(surface: PSDL_Surface; flag, key: Longword): LongInt; cdecl; external SDLLibName; |
4 | 228 |
|
105 | 229 |
function SDL_UpperBlit(src: PSDL_Surface; srcrect: PSDL_Rect; dst: PSDL_Surface; dstrect: PSDL_Rect): LongInt; cdecl; external SDLLibName; |
230 |
function SDL_FillRect(dst: PSDL_Surface; dstrect: PSDL_Rect; color: Longword): LongInt; cdecl; external SDLLibName; |
|
231 |
procedure SDL_UpdateRect(Screen: PSDL_Surface; x, y: LongInt; w, h: Longword); cdecl; external SDLLibName; |
|
432 | 232 |
function SDL_Flip(Screen: PSDL_Surface): LongInt; cdecl; external SDLLibName; |
4 | 233 |
|
234 |
procedure SDL_GetRGB(pixel: Longword; fmt: PSDL_PixelFormat; r, g, b: PByte); cdecl; external SDLLibName; |
|
107 | 235 |
function SDL_MapRGB(format: PSDL_PixelFormat; r, g, b: Byte): Longword; cdecl; external SDLLibName; |
4 | 236 |
|
237 |
function SDL_DisplayFormat(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName; |
|
35 | 238 |
function SDL_DisplayFormatAlpha(Surface: PSDL_Surface): PSDL_Surface; cdecl; external SDLLibName; |
4 | 239 |
|
240 |
function SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName; |
|
432 | 241 |
function SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: LongInt): LongInt; cdecl; external SDLLibName; |
4 | 242 |
|
105 | 243 |
function SDL_GetKeyState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName; |
107 | 244 |
function SDL_GetMouseState(x, y: PInteger): Byte; cdecl; external SDLLibName; |
4 | 245 |
function SDL_GetKeyName(key: Longword): PChar; cdecl; external SDLLibName; |
246 |
procedure SDL_WarpMouse(x, y: Word); cdecl; external SDLLibName; |
|
247 |
||
432 | 248 |
function SDL_PollEvent(event: PSDL_Event): LongInt; cdecl; external SDLLibName; |
4 | 249 |
|
432 | 250 |
function SDL_ShowCursor(toggle: LongInt): LongInt; cdecl; external SDLLibName; |
4 | 251 |
|
252 |
procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName; |
|
253 |
||
433 | 254 |
function SDL_CreateMutex: PSDL_mutex; cdecl; external SDLLibName; |
255 |
procedure SDL_DestroyMutex(mutex: PSDL_mutex); cdecl; external SDLLibName; |
|
256 |
function SDL_LockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName name 'SDL_mutexP'; |
|
257 |
function SDL_UnlockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName name 'SDL_mutexV'; |
|
258 |
||
753 | 259 |
function SDL_GL_SetAttribute(attr: byte; value: LongInt): LongInt; cdecl; external SDLLibName; |
260 |
procedure SDL_GL_SwapBuffers(); cdecl; external SDLLibName; |
|
261 |
||
4 | 262 |
(* TTF *) |
263 |
||
264 |
const {$IFDEF WIN32} |
|
265 |
SDL_TTFLibName = 'SDL_ttf.dll'; |
|
266 |
{$ENDIF} |
|
267 |
{$IFDEF UNIX} |
|
268 |
SDL_TTFLibName = 'libSDL_ttf.so'; |
|
269 |
{$ENDIF} |
|
202 | 270 |
TTF_STYLE_NORMAL = 0; |
271 |
TTF_STYLE_BOLD = 1; |
|
272 |
TTF_STYLE_ITALIC = 2; |
|
4 | 273 |
|
274 |
type PTTF_Font = ^TTTF_font; |
|
275 |
TTTF_Font = record |
|
276 |
end; |
|
277 |
||
432 | 278 |
function TTF_Init: LongInt; cdecl; external SDL_TTFLibName; |
4 | 279 |
procedure TTF_Quit; cdecl; external SDL_TTFLibName; |
280 |
||
281 |
||
432 | 282 |
function TTF_SizeUTF8(font: PTTF_Font; const text: PChar; var w, h: LongInt): LongInt; cdecl; external SDL_TTFLibName; |
206
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
283 |
(* TSDL_Color -> Longword conversion is workaround over freepascal bug. |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
284 |
See http://www.freepascal.org/mantis/view.php?id=7613 for details *) |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
285 |
function TTF_RenderUTF8_Solid(font: PTTF_Font; const text: PChar; fg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName; |
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
286 |
function TTF_RenderUTF8_Blended(font: PTTF_Font; const text: PChar; fg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName; |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
883
diff
changeset
|
287 |
function TTF_RenderUTF8_Shaded(font: PTTF_Font; const text: PChar; fg, bg: Longword): PSDL_Surface; cdecl; external SDL_TTFLibName; |
206
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
202
diff
changeset
|
288 |
|
432 | 289 |
function TTF_OpenFont(const filename: PChar; size: LongInt): PTTF_Font; cdecl; external SDL_TTFLibName; |
290 |
procedure TTF_SetFontStyle(font: PTTF_Font; style: LongInt); cdecl; external SDL_TTFLibName; |
|
4 | 291 |
|
292 |
(* SDL_mixer *) |
|
293 |
||
294 |
const {$IFDEF WIN32} |
|
295 |
SDL_MixerLibName = 'SDL_mixer.dll'; |
|
296 |
{$ENDIF} |
|
297 |
{$IFDEF UNIX} |
|
298 |
SDL_MixerLibName = 'libSDL_mixer.so'; |
|
299 |
{$ENDIF} |
|
300 |
||
174 | 301 |
const MIX_MAX_VOLUME = 128; |
302 |
||
4 | 303 |
type PMixChunk = ^TMixChunk; |
304 |
TMixChunk = record |
|
305 |
allocated: Longword; |
|
306 |
abuf : PByte; |
|
307 |
alen : Longword; |
|
308 |
volume : PByte; |
|
106 | 309 |
end; |
4 | 310 |
TMusic = (MUS_CMD, MUS_WAV, MUS_MOD, MUS_MID, MUS_OGG, MUS_MP3); |
311 |
TMix_Fading = (MIX_NO_FADING, MIX_FADING_OUT, MIX_FADING_IN); |
|
312 |
||
313 |
TMidiSong = record |
|
105 | 314 |
samples : LongInt; |
4 | 315 |
events : pointer; |
316 |
end; |
|
317 |
||
318 |
TMusicUnion = record |
|
319 |
case Byte of |
|
320 |
0: ( midi : TMidiSong ); |
|
321 |
1: ( ogg : pointer); |
|
322 |
end; |
|
323 |
||
324 |
PMixMusic = ^TMixMusic; |
|
325 |
TMixMusic = record |
|
326 |
end; |
|
327 |
||
105 | 328 |
function Mix_OpenAudio(frequency: LongInt; format: Word; channels: LongInt; chunksize: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 329 |
procedure Mix_CloseAudio; cdecl; external SDL_MixerLibName; |
330 |
||
174 | 331 |
function Mix_Volume(channel: LongInt; volume: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
332 |
function Mix_SetDistance(channel: LongInt; distance: Byte): LongInt; cdecl; external SDL_MixerLibName; |
|
105 | 333 |
function Mix_VolumeMusic(volume: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 334 |
|
174 | 335 |
function Mix_AllocateChannels(numchans: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 336 |
procedure Mix_FreeChunk(chunk: PMixChunk); cdecl; external SDL_MixerLibName; |
337 |
procedure Mix_FreeMusic(music: PMixMusic); cdecl; external SDL_MixerLibName; |
|
338 |
||
105 | 339 |
function Mix_LoadWAV_RW(src: PSDL_RWops; freesrc: LongInt): PMixChunk; cdecl; external SDL_MixerLibName; |
4 | 340 |
function Mix_LoadMUS(const filename: PChar): PMixMusic; cdecl; external SDL_MixerLibName; |
341 |
||
105 | 342 |
function Mix_Playing(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
343 |
function Mix_PlayingMusic: LongInt; cdecl; external SDL_MixerLibName; |
|
1225
f882a92ef872
Play music in menu also, with fading effects when run game
unc0rr
parents:
1120
diff
changeset
|
344 |
function Mix_FadeInMusic(music: PMixMusic; loops: LongInt; ms: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
4 | 345 |
|
105 | 346 |
function Mix_PlayChannelTimed(channel: LongInt; chunk: PMixChunk; loops: LongInt; ticks: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
347 |
function Mix_PlayMusic(music: PMixMusic; loops: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
|
348 |
function Mix_HaltChannel(channel: LongInt): LongInt; cdecl; external SDL_MixerLibName; |
|
4 | 349 |
|
350 |
(* SDL_image *) |
|
351 |
||
352 |
const {$IFDEF WIN32} |
|
353 |
SDL_ImageLibName = 'SDL_image.dll'; |
|
354 |
{$ENDIF} |
|
355 |
{$IFDEF UNIX} |
|
356 |
SDL_ImageLibName = 'libSDL_image.so'; |
|
357 |
{$ENDIF} |
|
358 |
||
359 |
function IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName; |
|
360 |
||
361 |
(* SDL_net *) |
|
362 |
||
363 |
const {$IFDEF WIN32} |
|
364 |
SDL_NetLibName = 'SDL_net.dll'; |
|
365 |
{$ENDIF} |
|
366 |
{$IFDEF UNIX} |
|
367 |
SDL_NetLibName = 'libSDL_net.so'; |
|
368 |
{$ENDIF} |
|
369 |
||
370 |
type TIPAddress = record |
|
371 |
host: Longword; |
|
372 |
port: Word; |
|
373 |
end; |
|
374 |
||
375 |
PTCPSocket = ^TTCPSocket; |
|
376 |
TTCPSocket = record |
|
106 | 377 |
ready: LongInt; |
105 | 378 |
channel: LongInt; |
106 | 379 |
remoteAddress: TIPaddress; |
4 | 380 |
localAddress: TIPaddress; |
105 | 381 |
sflag: LongInt; |
4 | 382 |
end; |
383 |
PSDLNet_SocketSet = ^TSDLNet_SocketSet; |
|
384 |
TSDLNet_SocketSet = record |
|
385 |
numsockets, |
|
105 | 386 |
maxsockets: LongInt; |
4 | 387 |
sockets: PTCPSocket; |
388 |
end; |
|
389 |
||
105 | 390 |
function SDLNet_Init: LongInt; cdecl; external SDL_NetLibName; |
4 | 391 |
procedure SDLNet_Quit; cdecl; external SDL_NetLibName; |
392 |
||
105 | 393 |
function SDLNet_AllocSocketSet(maxsockets: LongInt): PSDLNet_SocketSet; cdecl; external SDL_NetLibName; |
394 |
function SDLNet_ResolveHost(var address: TIPaddress; host: PCHar; port: Word): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 395 |
function SDLNet_TCP_Accept(server: PTCPsocket): PTCPSocket; cdecl; external SDL_NetLibName; |
396 |
function SDLNet_TCP_Open(var ip: TIPaddress): PTCPSocket; cdecl; external SDL_NetLibName; |
|
105 | 397 |
function SDLNet_TCP_Send(sock: PTCPsocket; data: Pointer; len: LongInt): LongInt; cdecl; external SDL_NetLibName; |
398 |
function SDLNet_TCP_Recv(sock: PTCPsocket; data: Pointer; len: LongInt): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 399 |
procedure SDLNet_TCP_Close(sock: PTCPsocket); cdecl; external SDL_NetLibName; |
400 |
procedure SDLNet_FreeSocketSet(_set: PSDLNet_SocketSet); cdecl; external SDL_NetLibName; |
|
105 | 401 |
function SDLNet_AddSocket(_set: PSDLNet_SocketSet; sock: PTCPSocket): LongInt; cdecl; external SDL_NetLibName; |
402 |
function SDLNet_CheckSockets(_set: PSDLNet_SocketSet; timeout: LongInt): LongInt; cdecl; external SDL_NetLibName; |
|
4 | 403 |
|
459
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
404 |
procedure SDLNet_Write16(value: Word; buf: pointer); |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
405 |
procedure SDLNet_Write32(value: LongWord; buf: pointer); |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
406 |
function SDLNet_Read16(buf: pointer): Word; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
407 |
function SDLNet_Read32(buf: pointer): LongWord; |
4 | 408 |
|
409 |
implementation |
|
410 |
||
411 |
function SDL_MustLock(Surface: PSDL_Surface): Boolean; |
|
412 |
begin |
|
432 | 413 |
SDL_MustLock:= ( surface^.offset <> 0 ) |
4 | 414 |
or(( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0) |
415 |
end; |
|
416 |
||
459
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
417 |
procedure SDLNet_Write16(value: Word; buf: pointer); |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
418 |
begin |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
419 |
PByteArray(buf)^[1]:= value; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
420 |
PByteArray(buf)^[0]:= value shr 8 |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
421 |
end; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
422 |
|
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
423 |
procedure SDLNet_Write32(value: LongWord; buf: pointer); |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
424 |
begin |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
425 |
PByteArray(buf)^[3]:= value; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
426 |
PByteArray(buf)^[2]:= value shr 8; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
427 |
PByteArray(buf)^[1]:= value shr 16; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
428 |
PByteArray(buf)^[0]:= value shr 24 |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
429 |
end; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
430 |
|
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
431 |
function SDLNet_Read16(buf: pointer): Word; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
432 |
begin |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
433 |
SDLNet_Read16:= PByteArray(buf)^[1] or |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
434 |
(PByteArray(buf)^[0] shl 8) |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
435 |
end; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
436 |
|
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
437 |
function SDLNet_Read32(buf: pointer): LongWord; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
438 |
begin |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
439 |
SDLNet_Read32:= PByteArray(buf)^[3] or |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
440 |
(PByteArray(buf)^[2] shl 8) or |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
441 |
(PByteArray(buf)^[1] shl 16) or |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
442 |
(PByteArray(buf)^[0] shl 24) |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
443 |
end; |
95163c6efa69
Do not use SDL_Net's to/from network byte order conversion functions
unc0rr
parents:
433
diff
changeset
|
444 |
|
4 | 445 |
end. |