DEADSOFTWARE

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