DEADSOFTWARE

Added Watt32 support
[d2df-sdl.git] / src / wrappers / sdl2 / sdl2allegro.inc
1 {$INCLUDE ../shared/a_modes.inc}
2 {$SCOPEDENUMS OFF}
4 interface
6 uses Allegro;
8 {$I sdltype.inc}
9 {$I sdlpixels.inc}
10 {$I sdlscancode.inc}
12 const
13 SDL_HAT_CENTERED = $00;
14 SDL_HAT_UP = $01;
15 SDL_HAT_RIGHT = $02;
16 SDL_HAT_DOWN = $04;
17 SDL_HAT_LEFT = $08;
18 SDL_HAT_RIGHTUP = SDL_HAT_RIGHT or SDL_HAT_UP;
19 SDL_HAT_RIGHTDOWN = SDL_HAT_RIGHT or SDL_HAT_DOWN;
20 SDL_HAT_LEFTUP = SDL_HAT_LEFT or SDL_HAT_UP;
21 SDL_HAT_LEFTDOWN = SDL_HAT_LEFT or SDL_HAT_DOWN;
23 const
24 AUDIO_U8 = $0008;
25 AUDIO_S8 = $8008;
26 AUDIO_U16LSB = $0010;
27 AUDIO_S16LSB = $8010;
28 AUDIO_U16MSB = $1010;
29 AUDIO_S16MSB = $9010;
30 AUDIO_U16 = AUDIO_U16LSB;
31 AUDIO_S16 = AUDIO_S16LSB;
33 const
34 SDL_TOUCH_MOUSEID = UInt32(-1);
36 type
37 PSDL_Window = ^TSDL_Window;
38 TSDL_Window = record
39 w, h, mode: Integer; (* Allegro-specific *)
40 end;
42 PSDL_Joystick = Pointer;
43 TSDL_JoystickGUID = record
44 data: array[0..15] of UInt8;
45 end;
46 TSDL_JoystickID = SInt32;
48 PSDL_RWops = ^TSDL_RWops;
50 TSize = function(context: PSDL_RWops): SInt64; cdecl;
51 TSeek = function(context: PSDL_RWops; offset: SInt64; whence: SInt32): SInt64; cdecl;
52 TRead = function(context: PSDL_RWops; ptr: Pointer; size: size_t; maxnum: size_t): size_t; cdecl;
53 TWrite = function(context: PSDL_RWops; const ptr: Pointer; size: size_t; num: size_t): size_t; cdecl;
54 TClose = function(context: PSDL_RWops): SInt32; cdecl;
56 TStdio = record
57 autoclose: TSDL_Bool;
58 fp: file;
59 end;
61 TMem = record
62 base: PUInt8;
63 here: PUInt8;
64 stop: PUInt8;
65 end;
67 TUnknown = record
68 data1: Pointer;
69 end;
71 TSDL_RWops = packed record
72 size: TSize;
73 seek: TSeek;
74 read: TRead;
75 write: TWrite;
76 close: TClose;
77 _type: UInt32;
78 case Integer of
79 0: (stdio: TStdio);
80 1: (mem: TMem);
81 2: (unknown: TUnknown);
82 {$IFDEF ANDROID}
83 //3: (androidio: TAndroidIO);
84 {$ENDIF}
85 {$IFDEF WINDOWS}
86 //3: (windowsio: TWindowsIO);
87 {$ENDIF}
88 end;
90 PSDL_TouchID = ^TSDL_TouchID;
91 TSDL_TouchID = SInt64;
93 PSDL_FingerID = ^TSDL_FingerID;
94 TSDL_FingerID = SInt64;
97 const
98 { Touch events }
99 SDL_FINGERDOWN = $700;
100 SDL_FINGERUP = $701;
101 SDL_FINGERMOTION = $702;
103 type
104 TSDL_TouchFingerEvent = record
105 type_: UInt32;
106 timestamp: UInt32;
107 touchId: TSDL_TouchID;
108 fingerId: TSDL_FingerID;
109 x, y, dx, dy: Float;
110 pressure: Float;
111 end;
114 const
115 SDL_WINDOWPOS_CENTERED_MASK = $2FFF0000;
116 SDL_WINDOWPOS_CENTERED = SDL_WINDOWPOS_CENTERED_MASK or 0;
118 type
119 PSDL_DisplayMode = ^TSDL_DisplayMode;
120 TSDL_DisplayMode = record
121 format: UInt32;
122 w: SInt32;
123 h: SInt32;
124 refresh_rate: SInt32;
125 driverdata: Pointer;
126 end;
128 TSDL_GLContext = Pointer;
130 const
131 SDL_WINDOW_FULLSCREEN = $00000001;
132 SDL_WINDOW_OPENGL = $00000002;
133 SDL_WINDOW_SHOWN = $00000004;
134 SDL_WINDOW_HIDDEN = $00000008;
135 SDL_WINDOW_BORDERLESS = $00000010;
136 SDL_WINDOW_RESIZABLE = $00000020;
137 SDL_WINDOW_MINIMIZED = $00000040;
138 SDL_WINDOW_MAXIMIZED = $00000080;
139 SDL_WINDOW_INPUT_GRABBED = $00000100;
140 SDL_WINDOW_INPUT_FOCUS = $00000200;
141 SDL_WINDOW_MOUSE_FOCUS = $00000400;
142 SDL_WINDOW_FULLSCREEN_DESKTOP = SDL_WINDOW_FULLSCREEN or $00001000;
143 SDL_WINDOW_FOREIGN = $00000800;
144 SDL_WINDOW_ALLOW_HIGHDPI = $00002000;
146 SDL_WINDOWEVENT_EXPOSED = 3;
147 SDL_WINDOWEVENT_MOVED = 4;
148 SDL_WINDOWEVENT_RESIZED = 5;
149 SDL_WINDOWEVENT_MINIMIZED = 7;
150 SDL_WINDOWEVENT_MAXIMIZED = 8;
151 SDL_WINDOWEVENT_RESTORED = 9;
152 SDL_WINDOWEVENT_FOCUS_GAINED = 12;
153 SDL_WINDOWEVENT_FOCUS_LOST = 13;
155 SDL_DISABLE = 0;
156 SDL_ENABLE = 1;
158 SDL_TEXTINPUTEVENT_TEXT_SIZE = 32;
160 SDL_FIRSTEVENT = 0;
161 SDL_COMMONEVENT = 1;
162 SDL_QUITEV = $100;
163 SDL_WINDOWEVENT = $200;
164 SDL_KEYDOWN = $300;
165 SDL_KEYUP = $301;
166 //SDL_TEXTEDITING = $302;
167 SDL_TEXTINPUT = $303;
169 type
170 TSDL_WindowEvent = record
171 type_: UInt32; // SDL_WINDOWEVENT
172 timestamp: UInt32;
173 windowID: UInt32; // The associated window
174 event: UInt8; // SDL_WindowEventID
175 padding1: UInt8;
176 padding2: UInt8;
177 padding3: UInt8;
178 data1: SInt32; // event dependent data
179 data2: SInt32; // event dependent data
180 end;
182 PSDL_Keysym = ^TSDL_Keysym;
183 TSDL_Keysym = record
184 scancode: TSDL_ScanCode; // SDL physical key code - see SDL_Scancode for details
185 sym: TSDL_KeyCode; // SDL virtual key code - see SDL_Keycode for details
186 _mod: UInt16; // current key modifiers
187 unicode: UInt32; // (deprecated) use SDL_TextInputEvent instead
188 end;
190 TSDL_KeyboardEvent = record
191 type_: UInt32; // SDL_KEYDOWN or SDL_KEYUP
192 timestamp: UInt32;
193 windowID: UInt32; // The window with keyboard focus, if any
194 state: UInt8; // SDL_PRESSED or SDL_RELEASED
195 _repeat: UInt8; // Non-zero if this is a key repeat
196 padding2: UInt8;
197 padding3: UInt8;
198 keysym: TSDL_KeySym; // The key that was pressed or released
199 end;
201 TSDL_TextInputEvent = record
202 type_: UInt32; // SDL_TEXTINPUT
203 timestamp: UInt32;
204 windowID: UInt32; // The window with keyboard focus, if any
205 text: array[0..SDL_TEXTINPUTEVENT_TEXT_SIZE - 1] of Char; // The input text
206 end;
208 TSDL_QuitEvent = record
209 type_: UInt32; // SDL_QUIT
210 timestamp: UInt32;
211 end;
213 PSDL_Event = ^TSDL_Event;
214 TSDL_Event = record
215 case Integer of
216 0: (type_: UInt32);
217 //SDL_COMMONEVENT: (common: TSDL_CommonEvent);
218 SDL_WINDOWEVENT: (window: TSDL_WindowEvent);
219 SDL_KEYUP,
220 SDL_KEYDOWN: (key: TSDL_KeyboardEvent);
221 //SDL_TEXTEDITING: (edit: TSDL_TextEditingEvent);
222 SDL_TEXTINPUT: (text: TSDL_TextInputEvent);
223 //SDL_MOUSEMOTION: (motion: TSDL_MouseMotionEvent);
224 //SDL_MOUSEBUTTONUP,
225 //SDL_MOUSEBUTTONDOWN: (button: TSDL_MouseButtonEvent);
226 //SDL_MOUSEWHEEL: (wheel: TSDL_MouseWheelEvent);
227 //SDL_JOYAXISMOTION: (jaxis: TSDL_JoyAxisEvent);
228 //SDL_JOYBALLMOTION: (jball: TSDL_JoyBallEvent);
229 //SDL_JOYHATMOTION: (jhat: TSDL_JoyHatEvent);
230 //SDL_JOYBUTTONDOWN,
231 //SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent);
232 //SDL_JOYDEVICEADDED,
233 //SDL_JOYDEVICEREMOVED: (jdevice: TSDL_JoyDeviceEvent);
234 //SDL_CONTROLLERAXISMOTION: (caxis: TSDL_ControllerAxisEvent);
235 //SDL_CONTROLLERBUTTONUP,
236 //SDL_CONTROLLERBUTTONDOWN: (cbutton: TSDL_ControllerButtonEvent);
237 //SDL_CONTROLLERDEVICEADDED,
238 //SDL_CONTROLLERDEVICEREMOVED,
239 //SDL_CONTROLLERDEVICEREMAPPED: (cdevice: TSDL_ControllerDeviceEvent);
240 //SDL_AUDIODEVICEADDED,
241 //SDL_AUDIODEVICEREMOVED: (adevice: TSDL_AudioDeviceEvent);
242 SDL_QUITEV: (quit: TSDL_QuitEvent);
243 //SDL_USEREVENT: (user: TSDL_UserEvent);
244 //SDL_SYSWMEVENT: (syswm: TSDL_SysWMEvent);
245 SDL_FINGERDOWN,
246 SDL_FINGERUP,
247 SDL_FINGERMOTION: (tfinger: TSDL_TouchFingerEvent);
248 //SDL_MULTIGESTURE: (mgesture: TSDL_MultiGestureEvent);
249 //SDL_DOLLARGESTURE,SDL_DOLLARRECORD: (dgesture: TSDL_DollarGestureEvent);
250 //SDL_DROPFILE: (drop: TSDL_DropEvent);
251 end;
253 const
254 SDL_GL_RED_SIZE = 0;
255 SDL_GL_GREEN_SIZE = 1;
256 SDL_GL_BLUE_SIZE = 2;
257 SDL_GL_ALPHA_SIZE = 3;
258 SDL_GL_BUFFER_SIZE = 4;
259 SDL_GL_DOUBLEBUFFER = 5;
260 SDL_GL_DEPTH_SIZE = 6;
261 SDL_GL_STENCIL_SIZE = 7;
262 SDL_GL_ACCUM_RED_SIZE = 8;
263 SDL_GL_ACCUM_GREEN_SIZE = 9;
264 SDL_GL_ACCUM_BLUE_SIZE = 10;
265 SDL_GL_ACCUM_ALPHA_SIZE = 11;
266 SDL_GL_STEREO = 12;
267 SDL_GL_MULTISAMPLEBUFFERS = 13;
268 SDL_GL_MULTISAMPLESAMPLES = 14;
269 SDL_GL_ACCELERATED_VISUAL = 15;
270 SDL_GL_RETAINED_BACKING = 16;
271 SDL_GL_CONTEXT_MAJOR_VERSION = 17;
272 SDL_GL_CONTEXT_MINOR_VERSION = 18;
273 SDL_GL_CONTEXT_EGL = 19;
274 SDL_GL_CONTEXT_FLAGS = 20;
275 SDL_GL_CONTEXT_PROFILE_MASK = 21;
276 SDL_GL_SHARE_WITH_CURRENT_CONTEXT = 22;
277 SDL_GL_FRAMEBUFFER_SRGB_CAPABLE = 23;
279 type
280 TSDL_GLattr = DWord;
282 const
283 SDL_INIT_TIMER = $00000001;
284 SDL_INIT_AUDIO = $00000010;
285 SDL_INIT_VIDEO = $00000020;
286 SDL_INIT_JOYSTICK = $00000200;
287 SDL_INIT_HAPTIC = $00001000;
288 SDL_INIT_GAMECONTROLLER = $00002000; //turn on game controller also implicitly does JOYSTICK
289 SDL_INIT_NOPARACHUTE = $00100000; //Don't catch fatal signals
290 SDL_INIT_EVERYTHING = SDL_INIT_TIMER or SDL_INIT_AUDIO or
291 SDL_INIT_VIDEO or SDL_INIT_JOYSTICK or
292 SDL_INIT_HAPTIC or SDL_INIT_GAMECONTROLLER;
294 SDL_HINT_ACCELEROMETER_AS_JOYSTICK = 'SDL_ACCELEROMETER_AS_JOYSTICK';
296 var
297 sdl2allegro_screen: PBITMAP;
298 sdl2allegro_bpp: Integer;
299 globalTransTable: COLOR_MAP_T;
300 redTransTable: COLOR_MAP_T;
301 greenTransTable: COLOR_MAP_T;
302 blueTransTable: COLOR_MAP_T;
303 darkTransTable: COLOR_MAP_T;
304 lightTransTable: COLOR_MAP_T;
307 /// FUNCTIONS ///
309 function SDL_SetWindowGammaRamp(window: PSDL_Window; const red: PUInt16; const green: PUInt16; const blue: PUInt16): SInt32;
310 function SDL_GetWindowGammaRamp(window: PSDL_Window; red: PUInt16; green: PUInt16; blue: PUInt16): SInt32;
312 function SDL_NumJoysticks: SInt32;
313 function SDL_JoystickOpen(device_index: SInt32): PSDL_Joystick;
314 function SDL_JoystickName(joystick: PSDL_Joystick): PAnsiChar;
315 function SDL_JoystickNumAxes(joystick: PSDL_Joystick): SInt32;
316 function SDL_JoystickNumButtons(joystick: PSDL_Joystick): SInt32;
317 function SDL_JoystickNumHats(joystick: PSDL_Joystick): SInt32;
318 procedure SDL_JoystickClose(joystick: PSDL_Joystick);
319 procedure SDL_JoystickUpdate;
320 function SDL_JoystickGetButton(joystick: PSDL_Joystick; button: SInt32): UInt8;
321 function SDL_JoystickGetAxis(joystick: PSDL_Joystick; axis: SInt32): SInt16;
322 function SDL_JoystickGetHat(joystick: PSDL_Joystick; hat: SInt32): UInt8;
324 function SDL_GetScancodeName(scancode: TSDL_ScanCode): PAnsiChar;
326 function SDL_GetPerformanceCounter: UInt64;
327 function SDL_GetPerformanceFrequency: UInt64;
329 function SDL_RWFromFile(const _file: PAnsiChar; const mode: PAnsiChar): PSDL_RWops;
330 function SDL_RWFromConstMem(const mem: Pointer; size: SInt32): PSDL_RWops;
332 function SDL_GetDisplayDPI(displayIndex: SInt32; ddpi, hdpi, vdpi: PFloat): SInt32;
333 function SDL_IsTextInputActive: TSDL_Bool;
334 procedure SDL_StartTextInput;
335 procedure SDL_StopTextInput;
336 function SDL_GetNumTouchDevices: SInt32;
338 function SDL_GetDesktopDisplayMode(displayIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
339 function SDL_GetClosestDisplayMode(displayIndex: SInt32; const mode: PSDL_DisplayMode; closest: PSDL_DisplayMode): PSDL_DisplayMode;
341 procedure SDL_DestroyWindow(window: PSDL_Window);
342 procedure SDL_GL_DeleteContext(context: TSDL_GLContext);
343 procedure SDL_RestoreWindow(window: PSDL_Window);
344 procedure SDL_SetWindowSize(window: PSDL_Window; w: SInt32; h: SInt32);
345 function SDL_CreateWindow(const title: PAnsiChar; x: SInt32; y: SInt32; w: SInt32; h: SInt32; flags: UInt32): PSDL_Window;
346 function SDL_SetWindowFullscreen(window: PSDL_Window; flags: UInt32): SInt32;
347 function SDL_GL_MakeCurrent(window: PSDL_Window; context: TSDL_GLContext): SInt32;
348 procedure SDL_GetWindowSize(window: PSDL_Window; w: PInt; h: PInt);
349 function SDL_GetNumDisplayModes(displayIndex: SInt32): SInt32;
350 function SDL_GetDisplayMode(displayIndex: SInt32; modeIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
352 function SDL_ShowCursor(toggle: SInt32): SInt32;
353 procedure SDL_Delay(ms: UInt32);
354 procedure SDL_GL_SwapWindow(window: PSDL_Window);
356 function SDL_GL_CreateContext(window: PSDL_Window): TSDL_GLContext;
357 function SDL_GetTicks: UInt32;
359 function SDL_PushEvent(event: PSDL_Event): SInt32;
360 function SDL_PollEvent(event: PSDL_Event): SInt32;
361 function SDL_GL_SetSwapInterval(interval: SInt32): SInt32;
362 function SDL_GL_SetAttribute(attr: TSDL_GLattr; value: SInt32): SInt32;
363 function SDL_GL_GetAttribute(attr: TSDL_GLattr; value: PInt): SInt32;
365 function SDL_GetError: PAnsiChar;
367 function SDL_Init(flags: UInt32): SInt32;
368 procedure SDL_Quit();
369 function SDL_SetHint( const name: PChar; const value: PChar) : boolean;
371 implementation
373 uses
374 {$IFDEF GO32V2}
375 {$IFNDEF USE_ENETWRAP}
376 Watt32,
377 {$ENDIF}
378 go32,
379 {$ENDIF}
380 e_Log, g_options, SysUtils, Math, Classes, ctypes;
382 const
383 maxKeyBuffer = 64;
385 var
386 deskw, deskh, deskbpp: Integer;
387 keyring: array [0..maxKeyBuffer - 1] of Integer;
388 keybeg, keyend: Integer;
389 inputChar: Char;
390 inputText: Boolean;
391 useVsync: Boolean;
392 ticks: UInt32;
393 quit: Boolean;
394 custompal: PALETTE;
396 s2lc: array [0..KEY_MAX] of char = (
397 #00, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
398 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4',
399 '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', #00,
400 #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, '`', '-', '=', #00,
401 #09, '[', ']', #10, ';', #39, '\', '\', ',', '.', '/', ' ', #00, #00, #00, #00,
402 #00, #00, #00, #00, #00, '/', '*', '-', '+', #00, #00, #00, #00, #00, #00, #00,
403 #00, #00, #00, #00, '@', #00, ':', #00, '=', #00, ';', #00, #00, #00, #00, #00,
404 #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00
405 );
406 s2uc: array [0..KEY_MAX] of char = (
407 #00, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
408 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ')', '!', '@', '#', '$',
409 '%', '^', '&', '*', '(', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', #00,
410 #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, '~', '_', '+', #00,
411 #09, '{', '}', #10, ':', '"', '|', '|', '<', '>', '?', ' ', #00, #00, #00, #00,
412 #00, #00, #00, #00, #00, '/', '*', '-', '+', #00, #00, #00, #00, #00, #00, #00,
413 #00, #00, #00, #00, '@', #00, ':', #00, '=', #00, ';', #00, #00, #00, #00, #00,
414 #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00
415 );
416 s2sa: array [0..KEY_MAX] of Integer = (
417 SDL_SCANCODE_UNKNOWN,
418 SDL_SCANCODE_A,
419 SDL_SCANCODE_B,
420 SDL_SCANCODE_C,
421 SDL_SCANCODE_D,
422 SDL_SCANCODE_E,
423 SDL_SCANCODE_F,
424 SDL_SCANCODE_G,
425 SDL_SCANCODE_H,
426 SDL_SCANCODE_I,
427 SDL_SCANCODE_J,
428 SDL_SCANCODE_K,
429 SDL_SCANCODE_L,
430 SDL_SCANCODE_M,
431 SDL_SCANCODE_N,
432 SDL_SCANCODE_O,
433 SDL_SCANCODE_P,
434 SDL_SCANCODE_Q,
435 SDL_SCANCODE_R,
436 SDL_SCANCODE_S,
437 SDL_SCANCODE_T,
438 SDL_SCANCODE_U,
439 SDL_SCANCODE_V,
440 SDL_SCANCODE_W,
441 SDL_SCANCODE_X,
442 SDL_SCANCODE_Y,
443 SDL_SCANCODE_Z,
444 SDL_SCANCODE_0,
445 SDL_SCANCODE_1,
446 SDL_SCANCODE_2,
447 SDL_SCANCODE_3,
448 SDL_SCANCODE_4,
449 SDL_SCANCODE_5,
450 SDL_SCANCODE_6,
451 SDL_SCANCODE_7,
452 SDL_SCANCODE_8,
453 SDL_SCANCODE_9,
454 SDL_SCANCODE_KP_0,
455 SDL_SCANCODE_KP_1,
456 SDL_SCANCODE_KP_2,
457 SDL_SCANCODE_KP_3,
458 SDL_SCANCODE_KP_4,
459 SDL_SCANCODE_KP_5,
460 SDL_SCANCODE_KP_6,
461 SDL_SCANCODE_KP_7,
462 SDL_SCANCODE_KP_8,
463 SDL_SCANCODE_KP_9,
464 SDL_SCANCODE_F1,
465 SDL_SCANCODE_F2,
466 SDL_SCANCODE_F3,
467 SDL_SCANCODE_F4,
468 SDL_SCANCODE_F5,
469 SDL_SCANCODE_F6,
470 SDL_SCANCODE_F7,
471 SDL_SCANCODE_F8,
472 SDL_SCANCODE_F9,
473 SDL_SCANCODE_F10,
474 SDL_SCANCODE_F11,
475 SDL_SCANCODE_F12,
476 SDL_SCANCODE_ESCAPE,
477 SDL_SCANCODE_GRAVE,
478 SDL_SCANCODE_MINUS,
479 SDL_SCANCODE_EQUALS,
480 SDL_SCANCODE_BACKSPACE,
481 SDL_SCANCODE_TAB,
482 SDL_SCANCODE_LEFTBRACKET,
483 SDL_SCANCODE_RIGHTBRACKET,
484 SDL_SCANCODE_RETURN,
485 SDL_SCANCODE_SEMICOLON,
486 SDL_SCANCODE_APOSTROPHE,
487 SDL_SCANCODE_BACKSLASH,
488 SDL_SCANCODE_NONUSHASH,
489 SDL_SCANCODE_COMMA,
490 SDL_SCANCODE_UNKNOWN, (* !!! KEY_STOP *)
491 SDL_SCANCODE_SLASH,
492 SDL_SCANCODE_SPACE,
493 SDL_SCANCODE_INSERT,
494 SDL_SCANCODE_DELETE,
495 SDL_SCANCODE_HOME,
496 SDL_SCANCODE_END,
497 SDL_SCANCODE_PAGEUP,
498 SDL_SCANCODE_PAGEDOWN,
499 SDL_SCANCODE_LEFT,
500 SDL_SCANCODE_RIGHT,
501 SDL_SCANCODE_UP,
502 SDL_SCANCODE_DOWN,
503 SDL_SCANCODE_KP_DIVIDE,
504 SDL_SCANCODE_KP_MULTIPLY,
505 SDL_SCANCODE_KP_MINUS,
506 SDL_SCANCODE_KP_PLUS,
507 SDL_SCANCODE_KP_PERIOD,
508 SDL_SCANCODE_KP_ENTER,
509 SDL_SCANCODE_PRINTSCREEN,
510 SDL_SCANCODE_PAUSE,
511 SDL_SCANCODE_UNKNOWN, (* !!! KEY_ABNT_C1 *)
512 SDL_SCANCODE_INTERNATIONAL3, (* ??? KEY_YEN *)
513 SDL_SCANCODE_LANG3, (* ??? KEY_KANA *)
514 SDL_SCANCODE_UNKNOWN, (* !!! KEY_CONVERT *)
515 SDL_SCANCODE_UNKNOWN, (* !!! KEY_NOCONVERT *)
516 SDL_SCANCODE_KP_AT,
517 SDL_SCANCODE_UNKNOWN, (* !!! KEY_CIRCUMFLEX *)
518 SDL_SCANCODE_KP_COLON,
519 SDL_SCANCODE_UNKNOWN, (* !!! KEY_KANJI *)
520 SDL_SCANCODE_KP_EQUALS,
521 SDL_SCANCODE_UNKNOWN, (* !!! KEY_BACKQUOTE *)
522 SDL_SCANCODE_SEMICOLON,
523 SDL_SCANCODE_LGUI,
524 SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN1 *)
525 SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN2 *)
526 SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN3 *)
527 SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN4 *)
528 SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN5 *)
529 SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN6 *)
530 SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN7 *)
531 SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN8 *)
532 SDL_SCANCODE_LSHIFT,
533 SDL_SCANCODE_RSHIFT,
534 SDL_SCANCODE_LCTRL,
535 SDL_SCANCODE_RCTRL,
536 SDL_SCANCODE_LALT,
537 SDL_SCANCODE_RALT,
538 SDL_SCANCODE_LGUI,
539 SDL_SCANCODE_RGUI,
540 SDL_SCANCODE_MODE, (* ??? KEY_MENU *)
541 SDL_SCANCODE_SCROLLLOCK,
542 SDL_SCANCODE_NUMLOCKCLEAR,
543 SDL_SCANCODE_CAPSLOCK,
544 SDL_SCANCODE_UNKNOWN (* KEY_MAX *)
545 );
547 procedure LoadCustomPalette (const name: String);
548 var f: TFileStream; i: Integer;
549 begin
550 try
551 f := TFileStream.Create(name, fmOpenRead);
552 e_LogWriteLn('Load custom palette ' + name);
553 for i := 0 to 255 do
554 begin
555 custompal[i].r := f.ReadByte();
556 custompal[i].g := f.ReadByte();
557 custompal[i].b := f.ReadByte();
558 custompal[i].filler := $FF;
559 end;
560 f.Destroy
561 except
562 e_LogWriteLn('Fallback to default palette');
563 custompal := default_palette;
564 (*
565 for i := 0 to 255 do
566 begin
567 custompal[i].r := i div 4;
568 custompal[i].g := i div 4;
569 custompal[i].b := i div 4;
570 custompal[i].filler := $FF;
571 end;
572 *)
573 end
574 end;
576 procedure UpdatePalette;
577 begin
578 set_palette(custompal);
579 select_palette(custompal);
580 create_trans_table(@globalTransTable, custompal, 255, 255, 255, nil);
581 create_trans_table(@redTransTable, custompal, 0, 255, 255, nil);
582 create_trans_table(@greenTransTable, custompal, 255, 0, 255, nil);
583 create_trans_table(@blueTransTable, custompal, 255, 255, 0, nil);
584 create_trans_table(@darkTransTable, custompal, 191, 191, 191, nil);
585 create_trans_table(@lightTransTable, custompal, 64, 64, 64, nil);
586 color_map := @globalTransTable;
587 end;
589 function IsEmptyKeyboard: Boolean;
590 begin
591 result := keybeg = keyend
592 end;
594 function IsFullKeyboard: Boolean;
595 begin
596 result := (keybeg - 1) mod maxKeyBuffer = keyend
597 end;
599 function NextScancode: Integer;
600 begin
601 result := 0;
602 if not IsEmptyKeyboard then
603 begin
604 result := keyring[keybeg];
605 keybeg := (keybeg + 1) mod maxKeyBuffer
606 end
607 end;
609 procedure KeyboardWatcher (scancode: Integer); cdecl;
610 begin
611 if (keybeg - 1) mod maxKeyBuffer <> keyend then (* not IsFullKeyboard *)
612 begin
613 keyring[keyend] := scancode;
614 keyend := (keyend + 1) mod maxKeyBuffer
615 end
616 end;
617 procedure KeyboardWatcherEND; begin end;
619 /// MACRO ///
621 function SDL_PIXELFLAG(X: Cardinal): Cardinal;
622 begin
623 Result := (X shr 28) and $0F;
624 end;
626 function SDL_PIXELTYPE(X: Cardinal): Cardinal;
627 begin
628 Result := (X shr 24) and $0F;
629 end;
631 function SDL_PIXELORDER(X: Cardinal): Cardinal;
632 begin
633 Result := (X shr 20) and $0F;
634 end;
636 function SDL_PIXELLAYOUT(X: Cardinal): Cardinal;
637 begin
638 Result := (X shr 16) and $0F;
639 end;
641 function SDL_BITSPERPIXEL(X: Cardinal): Cardinal;
642 begin
643 Result := (X shr 8) and $FF;
644 end;
646 function SDL_IsPixelFormat_FOURCC(format: Variant): Boolean;
647 begin
648 Result := format and SDL_PIXELFLAG(format) <> 1;
649 end;
651 /// FUNCTIONS ////
653 (********** FILES **********)
655 function SDL_RWFromFile(const _file: PAnsiChar; const mode: PAnsiChar): PSDL_RWops;
656 begin
657 result := nil (* stub, used for sdl2stub_mixer *)
658 end;
660 function SDL_RWFromConstMem(const mem: Pointer; size: SInt32): PSDL_RWops;
661 begin
662 result := nil (* stub, used for sdl2stub_mixer *)
663 end;
665 (********** KEYBOARD **********)
667 function SDL_GetScancodeName(scancode: TSDL_ScanCode): PAnsiChar;
668 begin
669 case scancode of
670 SDL_SCANCODE_A: result := 'A';
671 SDL_SCANCODE_B: result := 'B';
672 SDL_SCANCODE_C: result := 'C';
673 SDL_SCANCODE_D: result := 'D';
674 SDL_SCANCODE_E: result := 'E';
675 SDL_SCANCODE_F: result := 'F';
676 SDL_SCANCODE_G: result := 'G';
677 SDL_SCANCODE_H: result := 'H';
678 SDL_SCANCODE_I: result := 'I';
679 SDL_SCANCODE_J: result := 'J';
680 SDL_SCANCODE_K: result := 'K';
681 SDL_SCANCODE_L: result := 'L';
682 SDL_SCANCODE_M: result := 'M';
683 SDL_SCANCODE_N: result := 'N';
684 SDL_SCANCODE_O: result := 'O';
685 SDL_SCANCODE_P: result := 'P';
686 SDL_SCANCODE_Q: result := 'Q';
687 SDL_SCANCODE_R: result := 'R';
688 SDL_SCANCODE_S: result := 'S';
689 SDL_SCANCODE_T: result := 'T';
690 SDL_SCANCODE_U: result := 'U';
691 SDL_SCANCODE_V: result := 'V';
692 SDL_SCANCODE_W: result := 'W';
693 SDL_SCANCODE_X: result := 'X';
694 SDL_SCANCODE_Y: result := 'Y';
695 SDL_SCANCODE_Z: result := 'Z';
696 SDL_SCANCODE_0: result := '0';
697 SDL_SCANCODE_1: result := '1';
698 SDL_SCANCODE_2: result := '2';
699 SDL_SCANCODE_3: result := '3';
700 SDL_SCANCODE_4: result := '4';
701 SDL_SCANCODE_5: result := '5';
702 SDL_SCANCODE_6: result := '6';
703 SDL_SCANCODE_7: result := '7';
704 SDL_SCANCODE_8: result := '8';
705 SDL_SCANCODE_9: result := '9';
706 SDL_SCANCODE_RETURN: result := 'Return';
707 SDL_SCANCODE_ESCAPE: result := 'Escape';
708 SDL_SCANCODE_BACKSPACE: result := 'Backspace';
709 SDL_SCANCODE_TAB: result := 'Tab';
710 SDL_SCANCODE_SPACE: result := 'Space';
711 SDL_SCANCODE_MINUS: result := '-';
712 SDL_SCANCODE_EQUALS: result := '=';
713 SDL_SCANCODE_LEFTBRACKET: result := '[';
714 SDL_SCANCODE_RIGHTBRACKET: result := ']';
715 SDL_SCANCODE_BACKSLASH: result := '\';
716 SDL_SCANCODE_SEMICOLON: result := ';';
717 SDL_SCANCODE_APOSTROPHE: result := '''';
718 SDL_SCANCODE_GRAVE: result := '`';
719 SDL_SCANCODE_COMMA: result := ',';
720 SDL_SCANCODE_PERIOD: result := '.';
721 SDL_SCANCODE_SLASH: result := '/';
722 SDL_SCANCODE_CAPSLOCK: result := 'CapsLock';
723 SDL_SCANCODE_F1: result := 'F1';
724 SDL_SCANCODE_F2: result := 'F2';
725 SDL_SCANCODE_F3: result := 'F3';
726 SDL_SCANCODE_F4: result := 'F4';
727 SDL_SCANCODE_F5: result := 'F5';
728 SDL_SCANCODE_F6: result := 'F6';
729 SDL_SCANCODE_F7: result := 'F7';
730 SDL_SCANCODE_F8: result := 'F8';
731 SDL_SCANCODE_F9: result := 'F9';
732 SDL_SCANCODE_F10: result := 'F10';
733 SDL_SCANCODE_F11: result := 'F11';
734 SDL_SCANCODE_F12: result := 'F12';
735 SDL_SCANCODE_PRINTSCREEN: result := 'PrintScreen';
736 SDL_SCANCODE_SCROLLLOCK: result := 'ScrollLock';
737 SDL_SCANCODE_PAUSE: result := 'Pause';
738 SDL_SCANCODE_INSERT: result := 'Insert';
739 SDL_SCANCODE_HOME: result := 'Home';
740 SDL_SCANCODE_PAGEUP: result := 'PageUp';
741 SDL_SCANCODE_DELETE: result := 'Delete';
742 SDL_SCANCODE_END: result := 'End';
743 SDL_SCANCODE_PAGEDOWN: result := 'PageDown';
744 SDL_SCANCODE_RIGHT: result := 'Right';
745 SDL_SCANCODE_LEFT: result := 'Left';
746 SDL_SCANCODE_DOWN: result := 'Down';
747 SDL_SCANCODE_UP: result := 'Up';
748 SDL_SCANCODE_NUMLOCKCLEAR: result := 'Numlock';
749 SDL_SCANCODE_KP_DIVIDE: result := 'Keypad /';
750 SDL_SCANCODE_KP_MULTIPLY: result := 'Keypad *';
751 SDL_SCANCODE_KP_MINUS: result := 'Keypad -';
752 SDL_SCANCODE_KP_PLUS: result := 'Keypad +';
753 SDL_SCANCODE_KP_ENTER: result := 'Keypad Enter';
754 SDL_SCANCODE_KP_1: result := 'Keypad 1';
755 SDL_SCANCODE_KP_2: result := 'Keypad 2';
756 SDL_SCANCODE_KP_3: result := 'Keypad 3';
757 SDL_SCANCODE_KP_4: result := 'Keypad 4';
758 SDL_SCANCODE_KP_5: result := 'Keypad 5';
759 SDL_SCANCODE_KP_6: result := 'Keypad 6';
760 SDL_SCANCODE_KP_7: result := 'Keypad 7';
761 SDL_SCANCODE_KP_8: result := 'Keypad 8';
762 SDL_SCANCODE_KP_9: result := 'Keypad 9';
763 SDL_SCANCODE_KP_0: result := 'Keypad 0';
764 SDL_SCANCODE_KP_PERIOD: result := 'Keypad .';
765 SDL_SCANCODE_APPLICATION: result := 'Application';
766 SDL_SCANCODE_POWER: result := 'Power';
767 SDL_SCANCODE_KP_EQUALS: result := 'Keypad =';
768 (* !!! F1x/F2x and multimedia ... *)
769 SDL_SCANCODE_KP_COMMA: result := 'Keypad ,';
770 SDL_SCANCODE_KP_EQUALSAS400: result := 'Keypad = (AS400)';
771 SDL_SCANCODE_ALTERASE: result := 'AltErase';
772 SDL_SCANCODE_SYSREQ: result := 'SysReq';
773 SDL_SCANCODE_CANCEL: result := 'Cancel';
774 SDL_SCANCODE_CLEAR: result := 'Clear';
775 SDL_SCANCODE_PRIOR: result := 'Prior';
776 SDL_SCANCODE_RETURN2: result := 'Return';
777 SDL_SCANCODE_SEPARATOR: result := 'Separator';
778 SDL_SCANCODE_OUT: result := 'Out';
779 SDL_SCANCODE_OPER: result := 'Oper';
780 SDL_SCANCODE_CLEARAGAIN: result := 'Clear / Again';
781 SDL_SCANCODE_CRSEL: result := 'CrSel';
782 SDL_SCANCODE_EXSEL: result := 'ExSel';
783 (* !!! Additional KP *)
784 SDL_SCANCODE_LCTRL: result := 'Left Ctrl';
785 SDL_SCANCODE_LSHIFT: result := 'Left Shift';
786 SDL_SCANCODE_LALT: result := 'Left Alt';
787 SDL_SCANCODE_LGUI: result := 'Left GUI';
788 SDL_SCANCODE_RCTRL: result := 'Right Ctrl';
789 SDL_SCANCODE_RSHIFT: result := 'Right Shift';
790 SDL_SCANCODE_RALT: result := 'Right Alt';
791 SDL_SCANCODE_RGUI: result := 'Right GUI';
792 SDL_SCANCODE_MODE: result := 'ModeSwitch';
793 (* !!! ... *)
794 else
795 result := ''
796 end
797 end;
799 function SDL_IsTextInputActive: TSDL_Bool;
800 begin
801 if inputText then
802 result := SDL_TRUE
803 else
804 result := SDL_FALSE
805 end;
807 procedure SDL_StartTextInput;
808 begin
809 inputText := True
810 end;
812 procedure SDL_StopTextInput;
813 begin
814 inputText := False
815 end;
817 (********** JOYSTICK **********)
819 function SDL_NumJoysticks: SInt32;
820 begin
821 result := 0
822 end;
824 function SDL_JoystickOpen(device_index: SInt32): PSDL_Joystick;
825 begin
826 result := nil
827 end;
829 function SDL_JoystickName(joystick: PSDL_Joystick): PAnsiChar;
830 begin
831 result := ''
832 end;
834 function SDL_JoystickNumAxes(joystick: PSDL_Joystick): SInt32;
835 begin
836 result := 0
837 end;
839 function SDL_JoystickNumButtons(joystick: PSDL_Joystick): SInt32;
840 begin
841 result := 0
842 end;
844 function SDL_JoystickNumHats(joystick: PSDL_Joystick): SInt32;
845 begin
846 result := 0
847 end;
849 procedure SDL_JoystickClose(joystick: PSDL_Joystick);
850 begin
851 end;
853 procedure SDL_JoystickUpdate;
854 begin
855 end;
857 function SDL_JoystickGetButton(joystick: PSDL_Joystick; button: SInt32): UInt8;
858 begin
859 result := 0
860 end;
862 function SDL_JoystickGetAxis(joystick: PSDL_Joystick; axis: SInt32): SInt16;
863 begin
864 result := 0
865 end;
867 function SDL_JoystickGetHat(joystick: PSDL_Joystick; hat: SInt32): UInt8;
868 begin
869 result := 0
870 end;
872 (********** TOUCH **********)
874 function SDL_GetNumTouchDevices: SInt32;
875 begin
876 result := 0
877 end;
879 (********** TIMERS **********)
881 procedure AllegroTimerCallback; cdecl;
882 begin
883 inc(ticks);
884 {$IF DEFINED(GO32V2) AND NOT DEFINED(USE_ENETWRAP)}
885 userTimerTick(1);
886 {$ENDIF}
887 end;
888 procedure AllegroTimerCallbackEND; begin end;
890 function SDL_GetPerformanceCounter: UInt64;
891 begin
892 result := ticks (* !!! *)
893 end;
895 function SDL_GetPerformanceFrequency: UInt64;
896 begin
897 result := 1 (* !!! *)
898 end;
900 procedure SDL_Delay(ms: UInt32);
901 begin
902 rest(ms)
903 end;
905 function SDL_GetTicks: UInt32;
906 begin
907 result := ticks
908 end;
910 (********** DISPLAY MODES **********)
912 function GetPixelFormat (bpp: Integer): UInt32;
913 begin
914 case bpp of
915 8: result := SDL_PIXELFORMAT_INDEX8;
916 15: result := SDL_PIXELFORMAT_RGB555;
917 16: result := SDL_PIXELFORMAT_RGB565;
918 24: result := SDL_PIXELFORMAT_RGB888;
919 32: result := SDL_PIXELFORMAT_RGBA8888;
920 else result := SDL_PIXELFORMAT_UNKNOWN
921 end
922 end;
924 function SDL_GetDesktopDisplayMode(displayIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
925 begin
926 ASSERT(mode <> nil);
927 mode.format := GetPixelFormat(deskbpp);
928 mode.w := deskw;
929 mode.h := deskh;
930 mode.refresh_rate := 0;
931 mode.driverdata := nil;
932 result := 0
933 end;
935 function SDL_GetClosestDisplayMode(displayIndex: SInt32; const mode: PSDL_DisplayMode; closest: PSDL_DisplayMode): PSDL_DisplayMode;
936 var m: PGFX_MODE_LIST; i, bpp: Integer;
937 begin
938 ASSERT(mode <> nil);
939 ASSERT(closest <> nil);
941 result := nil;
942 bpp := SDL_BITSPERPIXEL(mode.format);
943 if bpp = 0 then bpp := deskbpp;
945 m := nil;
946 if (gfx_driver <> nil) and (@gfx_driver.fetch_mode_list <> nil) then
947 m := gfx_driver.fetch_mode_list;
949 if m <> nil then
950 begin
951 i := 0;
952 while (i < m.num_modes) and (m.mode[i].bpp <> bpp) do inc(i);
953 if i < m.num_modes then
954 begin
955 closest.format := mode.format;
956 closest.refresh_rate := 0;
957 closest.driverdata := nil;
958 closest.w := m.mode[i].width;
959 closest.h := m.mode[i].height;
960 result := closest
961 end;
962 while i < m.num_modes do
963 begin
964 if (m.mode[i].bpp = bpp) and (closest.w >= mode.w) and (m.mode[i].width <= closest.w) and (closest.h >= mode.h) and (m.mode[i].height <= closest.h) then
965 begin
966 closest.w := m.mode[i].width;
967 closest.h := m.mode[i].height;
968 result := closest
969 end;
970 inc(i)
971 end;
972 destroy_gfx_mode_list(m)
973 end
974 end;
976 function SDL_GetNumDisplayModes(displayIndex: SInt32): SInt32;
977 var m: PGFX_MODE_LIST;
978 begin
979 result := -1;
981 m := nil;
982 if (gfx_driver <> nil) and (@gfx_driver.fetch_mode_list <> nil) then
983 m := gfx_driver.fetch_mode_list;
985 if m <> nil then
986 begin
987 result := m.num_modes;
988 destroy_gfx_mode_list(m);
989 end
990 end;
992 function SDL_GetDisplayMode(displayIndex: SInt32; modeIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
993 var m: PGFX_MODE_LIST;
994 begin
995 result := -1;
997 m := nil;
998 if (gfx_driver <> nil) and (@gfx_driver.fetch_mode_list <> nil) then
999 m := gfx_driver.fetch_mode_list;
1001 if m <> nil then
1002 begin
1003 if (modeIndex >= 0) and (modeIndex < m.num_modes) then
1004 begin
1005 mode.format := GetPixelFormat(m.mode[modeIndex].bpp);
1006 mode.w := m.mode[modeIndex].width;
1007 mode.h := m.mode[modeIndex].height;
1008 mode.refresh_rate := 0;
1009 mode.driverdata := nil;
1010 result := 0
1011 end;
1012 destroy_gfx_mode_list(m)
1013 end
1014 end;
1016 function SDL_GetDisplayDPI(displayIndex: SInt32; ddpi, hdpi, vdpi: PFloat): SInt32;
1017 begin
1018 result := -1 (* stub *)
1019 end;
1021 (*********** WINDOW MANAGEMENT **********)
1023 function SDL_CreateWindow(const title: PAnsiChar; x: SInt32; y: SInt32; w: SInt32; h: SInt32; flags: UInt32): PSDL_Window;
1024 var window: PSDL_Window; mode: Integer;
1025 begin
1026 result := nil;
1028 {$IF DEFINED(GO32V2)}
1029 mode := GFX_AUTODETECT;
1030 {$ELSE}
1031 if (flags and (SDL_WINDOW_FULLSCREEN or SDL_WINDOW_FULLSCREEN_DESKTOP)) <> 0 then
1032 mode := GFX_AUTODETECT_FULLSCREEN
1033 else
1034 mode := GFX_AUTODETECT_WINDOWED;
1035 {$ENDIF}
1037 if sdl2allegro_bpp = 0 then sdl2allegro_bpp := gBPP;
1038 if sdl2allegro_bpp = 0 then sdl2allegro_bpp := deskbpp;
1040 set_color_depth(sdl2allegro_bpp);
1041 if set_gfx_mode(mode, w, h, 0, 0) = 0 then
1042 begin
1043 new(window);
1044 set_window_title(title);
1045 if sdl2allegro_screen <> nil then
1046 destroy_bitmap(sdl2allegro_screen);
1047 sdl2allegro_screen := create_system_bitmap(w, h);
1048 if sdl2allegro_screen = nil then
1049 sdl2allegro_screen := create_bitmap(w, h);
1050 ASSERT(sdl2allegro_screen <> nil);
1051 window.w := w;
1052 window.h := h;
1053 window.mode := mode;
1054 UpdatePalette;
1055 result := window
1056 end
1057 end;
1059 function SDL_SetWindowFullscreen(window: PSDL_Window; flags: UInt32): SInt32;
1060 var mode: Integer;
1061 begin
1062 ASSERT(window <> nil);
1063 result := -1;
1065 {$IF DEFINED(GO32V2)}
1066 mode := GFX_AUTODETECT;
1067 {$ELSE}
1068 if (flags and (SDL_WINDOW_FULLSCREEN or SDL_WINDOW_FULLSCREEN_DESKTOP)) <> 0 then
1069 mode := GFX_AUTODETECT_FULLSCREEN
1070 else
1071 mode := GFX_AUTODETECT_WINDOWED;
1072 {$ENDIF}
1074 set_color_depth(sdl2allegro_bpp);
1075 if set_gfx_mode(mode, window.w, window.h, 0, 0) = 0 then
1076 begin
1077 if sdl2allegro_screen <> nil then
1078 destroy_bitmap(sdl2allegro_screen);
1079 sdl2allegro_screen := create_system_bitmap(window.w, window.h);
1080 if sdl2allegro_screen = nil then
1081 sdl2allegro_screen := create_bitmap(window.w, window.h);
1082 ASSERT(sdl2allegro_screen <> nil);
1083 UpdatePalette;
1084 window.mode := mode;
1085 result := 0
1086 end
1087 end;
1089 procedure SDL_SetWindowSize(window: PSDL_Window; w: SInt32; h: SInt32);
1090 begin
1091 ASSERT(window <> nil);
1092 set_color_depth(sdl2allegro_bpp);
1093 if set_gfx_mode(window.mode, w, h, 0, 0) = 0 then
1094 begin
1095 if sdl2allegro_screen <> nil then
1096 destroy_bitmap(sdl2allegro_screen);
1097 sdl2allegro_screen := create_system_bitmap(w, h);
1098 if sdl2allegro_screen = nil then
1099 sdl2allegro_screen := create_bitmap(w, h);
1100 ASSERT(sdl2allegro_screen <> nil);
1101 UpdatePalette;
1102 window.w := w;
1103 window.h := h
1104 end
1105 else
1106 begin
1107 ASSERT(FALSE, 'Unable to set window size')
1108 end
1109 end;
1111 procedure SDL_DestroyWindow(window: PSDL_Window);
1112 begin
1113 if window = nil then exit;
1114 if sdl2allegro_screen <> nil then
1115 destroy_bitmap(sdl2allegro_screen);
1116 sdl2allegro_screen := nil;
1117 dispose(window)
1118 end;
1120 procedure SDL_GetWindowSize(window: PSDL_Window; w: PInt; h: PInt);
1121 begin
1122 ASSERT(window <> nil);
1123 if w <> nil then w^ := window.w;
1124 if h <> nil then h^ := window.h;
1125 end;
1127 procedure SDL_RestoreWindow(window: PSDL_Window);
1128 begin
1129 ASSERT(window <> nil);
1130 (* stub *)
1131 end;
1133 function SDL_SetWindowGammaRamp(window: PSDL_Window; const red: PUInt16; const green: PUInt16; const blue: PUInt16): SInt32;
1134 begin
1135 ASSERT(window <> nil);
1136 result := 0 (* stub *)
1137 end;
1139 function SDL_GetWindowGammaRamp(window: PSDL_Window; red: PUInt16; green: PUInt16; blue: PUInt16): SInt32;
1140 begin
1141 ASSERT(window <> nil);
1142 result := 0 (* stub *)
1143 end;
1145 (********** OPENGL MANAGEMENT **********)
1147 function SDL_GL_SetAttribute(attr: TSDL_GLattr; value: SInt32): SInt32;
1148 begin
1149 e_LogWritefln('SDL_GL_SetAttribute %s %s', [attr, value]);
1150 allegro_error := 'Attribute ' + IntToStr(attr) + ' := ' + IntToStr(value) + 'not supported';
1151 result := -1
1152 end;
1154 function SDL_GL_GetAttribute(attr: TSDL_GLattr; value: PInt): SInt32;
1155 begin
1156 e_LogWritefln('SDL_GL_GetAttribute %s', [attr]);
1157 value^ := 0; result := -1
1158 end;
1160 function SDL_GL_CreateContext(window: PSDL_Window): TSDL_GLContext;
1161 begin
1162 result := window (* stub *)
1163 end;
1165 function SDL_GL_MakeCurrent(window: PSDL_Window; context: TSDL_GLContext): SInt32;
1166 begin
1167 ASSERT(window <> nil);
1168 if context <> nil then
1169 ASSERT(window = context);
1170 result := 0 (* stub *)
1171 end;
1173 procedure SDL_GL_DeleteContext(context: TSDL_GLContext);
1174 begin
1175 (* stub *)
1176 end;
1178 function SDL_GL_SetSwapInterval(interval: SInt32): SInt32;
1179 begin
1180 result := 0;
1181 if interval = 0 then
1182 useVsync := False
1183 else
1184 useVsync := True
1185 end;
1187 procedure SDL_GL_SwapWindow(window: PSDL_Window);
1188 begin
1189 ASSERT(window <> nil);
1190 ASSERT(sdl2allegro_screen <> nil);
1191 acquire_screen;
1192 blit(sdl2allegro_screen, screen, 0, 0, 0, 0, min(sdl2allegro_screen.w, screen.w), min(sdl2allegro_screen.h, screen.h));
1193 show_video_bitmap(screen);
1194 release_screen;
1195 if useVsync then
1196 vsync;
1198 {$IF DEFINED(GO32V2) AND NOT DEFINED(USE_ENETWRAP)}
1199 tcp_tick(nil);
1200 {$ENDIF}
1201 end;
1203 (********** EVENTS **********)
1205 function SDL_PushEvent(event: PSDL_Event): SInt32;
1206 begin
1207 result := 1;
1208 case event.type_ of
1209 SDL_QUITEV: quit := True;
1210 else
1211 ASSERT(FALSE);
1212 result := 0
1213 end
1214 end;
1216 function SDL_PollEvent(event: PSDL_Event): SInt32;
1217 var alscan: Integer; pressed, shift, caps: Boolean;
1218 begin
1219 result := 0;
1221 if quit then
1222 begin
1223 quit := False;
1224 event.type_ := SDL_QUITEV;
1225 event.quit.timestamp := ticks;
1226 result := 1;
1227 Exit
1228 end;
1230 if inputText and (inputChar <> #0) then
1231 begin
1232 event.type_ := SDL_TEXTINPUT;
1233 event.text.timestamp := ticks;
1234 event.text.windowID := 0;
1235 event.text.text[0] := inputChar;
1236 event.text.text[1] := #0;
1237 inputChar := #0;
1238 result := 1;
1239 Exit
1240 end
1241 else
1242 inputChar := #0;
1244 poll_keyboard;
1245 if not IsEmptyKeyboard then
1246 begin
1247 alscan := NextScancode;
1248 pressed := alscan and $80 = 0;
1250 inputChar := #0;
1251 if pressed then
1252 begin
1253 shift := key_shifts and KB_SHIFT_FLAG <> 0;
1254 caps := key_shifts and KB_CAPSLOCK_FLAG <> 0;
1255 if shift xor caps then
1256 inputChar := s2uc[alscan and $7F]
1257 else
1258 inputChar := s2lc[alscan and $7F];
1259 event.type_ := SDL_KEYDOWN
1260 end
1261 else
1262 event.type_ := SDL_KEYUP;
1264 event.key.timestamp := ticks;
1265 event.key.windowID := 0;
1267 (**** df not use it?
1268 if pressed then
1269 event.key.state := SDL_PRESSED
1270 else
1271 event.key.state := SDL_RELEASED;
1272 ****)
1274 event.key._repeat := 0;
1275 event.key.keysym.scancode := s2sa[alscan and $7F];
1276 event.key.keysym.sym := 0; (* df not use it? *)
1277 event.key.keysym._mod := 0; (* df not use it? *)
1278 result := 1;
1279 Exit
1280 end;
1282 {$IF DEFINED(GO32V2) AND NOT DEFINED(USE_ENETWRAP)}
1283 tcp_tick(nil);
1284 {$ENDIF}
1285 end;
1287 (********** MOUSE **********)
1289 function SDL_ShowCursor(toggle: SInt32): SInt32;
1290 begin
1291 result := 0 (* stub *)
1292 end;
1294 (********** SDL **********)
1296 procedure AllegroQuitCallback; cdecl;
1297 begin
1298 quit := True
1299 end;
1300 procedure AllegroQuitCallbackEND; begin end;
1302 function SDL_SetHint(const name: PChar; const value: PChar): boolean;
1303 begin
1304 e_LogWritefln('SDL_SetHint %s %s', [name, value]);
1305 result := false (* stub *)
1306 end;
1308 function SDL_GetError: PAnsiChar;
1309 begin
1310 result := allegro_error
1311 end;
1313 {$IFDEF GO32V2}
1314 (* HACK: allegro crashes while init without this *)
1315 var
1316 __crt0_argv: PPchar; cvar; external;
1317 myargv: array [0..1] of Pchar;
1319 procedure FIX_ARGV;
1320 begin
1321 __crt0_argv := @myargv[0];
1322 myargv[0] := PChar(ParamStr(0));
1323 e_LogWritefln('argv[0] = %s', [myargv[0]]);
1324 end;
1325 {$ENDIF}
1327 function SDL_Init(flags: UInt32): SInt32;
1328 begin
1329 result := -1;
1330 {$IFDEF GO32V2}
1331 FIX_ARGV;
1332 {$ENDIF}
1333 if allegro_init = 0 then
1334 begin
1335 e_LogWriteln('Allegro Init: ok');
1336 {$IFDEF GO32V2}
1337 (* without this df dies with fire when swapped *)
1338 lock_data(ticks, sizeof(ticks));
1339 lock_code(@AllegroTimerCallback, PtrUInt(@AllegroTimerCallbackEND) - PtrUInt(@AllegroTimerCallback));
1340 lock_data(keybeg, sizeof(keybeg));
1341 lock_data(keyend, sizeof(keyend));
1342 lock_data(keyring, sizeof(keyring));
1343 lock_code(@KeyboardWatcher, PtrUInt(@KeyboardWatcherEND) - PtrUInt(@KeyboardWatcher));
1344 lock_data(quit, sizeof(quit));
1345 lock_code(@AllegroQuitCallback, PtrUInt(@AllegroQuitCallbackEND) - PtrUInt(@AllegroQuitCallback));
1346 {$ENDIF}
1347 install_timer;
1348 install_keyboard;
1349 keyboard_lowlevel_callback := KeyboardWatcher;
1350 set_keyboard_rate(0, 0);
1351 install_int_ex(AllegroTimerCallback, MSEC_TO_TIMER(1));
1352 set_close_button_callback(AllegroQuitCallback);
1353 deskbpp := desktop_color_depth;
1354 if deskbpp = 0 then deskbpp := 8;
1355 if get_desktop_resolution(@deskw, @deskh) <> 0 then
1356 begin
1357 deskw := 640;
1358 deskh := 480
1359 end;
1360 LoadCustomPalette('PLAYPAL.LMP');
1361 result := 0
1362 end
1363 end;
1365 procedure SDL_Quit;
1366 begin
1367 set_close_button_callback(nil);
1368 remove_keyboard;
1369 remove_timer;
1370 {$IFDEF GO32V2}
1371 unlock_data(ticks, sizeof(ticks));
1372 unlock_code(@AllegroTimerCallback, PtrUInt(@AllegroTimerCallbackEND) - PtrUInt(@AllegroTimerCallback));
1373 unlock_data(keybeg, sizeof(keybeg));
1374 unlock_data(keyend, sizeof(keyend));
1375 unlock_data(keyring, sizeof(keyring));
1376 unlock_code(@KeyboardWatcher, PtrUInt(@KeyboardWatcherEND) - PtrUInt(@KeyboardWatcher));
1377 unlock_data(quit, sizeof(quit));
1378 unlock_code(@AllegroQuitCallback, PtrUInt(@AllegroQuitCallbackEND) - PtrUInt(@AllegroQuitCallback));
1379 {$ENDIF}
1380 allegro_exit
1381 end;