1 {$INCLUDE ../shared/a_modes.inc}
13 SDL_HAT_CENTERED = $00;
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;
30 AUDIO_U16 = AUDIO_U16LSB;
31 AUDIO_S16 = AUDIO_S16LSB;
34 SDL_TOUCH_MOUSEID = UInt32(-1);
37 PSDL_Window = ^TSDL_Window;
39 w, h, mode: Integer; (* Allegro-specific *)
42 PSDL_Joystick = Pointer;
43 TSDL_JoystickGUID = record
44 data: array[0..15] of UInt8;
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;
71 TSDL_RWops = packed record
81 2: (unknown: TUnknown);
83 //3: (androidio: TAndroidIO);
86 //3: (windowsio: TWindowsIO);
90 PSDL_TouchID = ^TSDL_TouchID;
91 TSDL_TouchID = SInt64;
93 PSDL_FingerID = ^TSDL_FingerID;
94 TSDL_FingerID = SInt64;
99 SDL_FINGERDOWN = $700;
101 SDL_FINGERMOTION = $702;
104 TSDL_TouchFingerEvent = record
107 touchId: TSDL_TouchID;
108 fingerId: TSDL_FingerID;
115 SDL_WINDOWPOS_CENTERED_MASK = $2FFF0000;
116 SDL_WINDOWPOS_CENTERED = SDL_WINDOWPOS_CENTERED_MASK or 0;
119 PSDL_DisplayMode = ^TSDL_DisplayMode;
120 TSDL_DisplayMode = record
124 refresh_rate: SInt32;
128 TSDL_GLContext = Pointer;
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;
158 SDL_TEXTINPUTEVENT_TEXT_SIZE = 32;
163 SDL_WINDOWEVENT = $200;
166 //SDL_TEXTEDITING = $302;
167 SDL_TEXTINPUT = $303;
170 TSDL_WindowEvent = record
171 type_: UInt32; // SDL_WINDOWEVENT
173 windowID: UInt32; // The associated window
174 event: UInt8; // SDL_WindowEventID
178 data1: SInt32; // event dependent data
179 data2: SInt32; // event dependent data
182 PSDL_Keysym = ^TSDL_Keysym;
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
190 TSDL_KeyboardEvent = record
191 type_: UInt32; // SDL_KEYDOWN or SDL_KEYUP
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
198 keysym: TSDL_KeySym; // The key that was pressed or released
201 TSDL_TextInputEvent = record
202 type_: UInt32; // SDL_TEXTINPUT
204 windowID: UInt32; // The window with keyboard focus, if any
205 text: array[0..SDL_TEXTINPUTEVENT_TEXT_SIZE - 1] of Char; // The input text
208 TSDL_QuitEvent = record
209 type_: UInt32; // SDL_QUIT
213 PSDL_Event = ^TSDL_Event;
217 //SDL_COMMONEVENT: (common: TSDL_CommonEvent);
218 SDL_WINDOWEVENT: (window: TSDL_WindowEvent);
220 SDL_KEYDOWN: (key: TSDL_KeyboardEvent);
221 //SDL_TEXTEDITING: (edit: TSDL_TextEditingEvent);
222 SDL_TEXTINPUT: (text: TSDL_TextInputEvent);
223 //SDL_MOUSEMOTION: (motion: TSDL_MouseMotionEvent);
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);
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);
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);
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;
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;
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';
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;
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;
377 e_Log, g_options, SysUtils, Math, Classes, ctypes;
383 deskw, deskh, deskbpp: Integer;
384 keyring: array [0..maxKeyBuffer - 1] of Integer;
385 keybeg, keyend: Integer;
393 s2lc: array [0..KEY_MAX] of char = (
394 #00, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
395 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4',
396 '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', #00,
397 #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, '`', '-', '=', #00,
398 #09, '[', ']', #10, ';', #39, '\', '\', ',', '.', '/', ' ', #00, #00, #00, #00,
399 #00, #00, #00, #00, #00, '/', '*', '-', '+', #00, #00, #00, #00, #00, #00, #00,
400 #00, #00, #00, #00, '@', #00, ':', #00, '=', #00, ';', #00, #00, #00, #00, #00,
401 #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00
403 s2uc: array [0..KEY_MAX] of char = (
404 #00, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
405 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ')', '!', '@', '#', '$',
406 '%', '^', '&', '*', '(', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', #00,
407 #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, '~', '_', '+', #00,
408 #09, '{', '}', #10, ':', '"', '|', '|', '<', '>', '?', ' ', #00, #00, #00, #00,
409 #00, #00, #00, #00, #00, '/', '*', '-', '+', #00, #00, #00, #00, #00, #00, #00,
410 #00, #00, #00, #00, '@', #00, ':', #00, '=', #00, ';', #00, #00, #00, #00, #00,
411 #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00
413 s2sa: array [0..KEY_MAX] of Integer = (
414 SDL_SCANCODE_UNKNOWN,
477 SDL_SCANCODE_BACKSPACE,
479 SDL_SCANCODE_LEFTBRACKET,
480 SDL_SCANCODE_RIGHTBRACKET,
482 SDL_SCANCODE_SEMICOLON,
483 SDL_SCANCODE_APOSTROPHE,
484 SDL_SCANCODE_BACKSLASH,
485 SDL_SCANCODE_NONUSHASH,
487 SDL_SCANCODE_UNKNOWN, (* !!! KEY_STOP *)
495 SDL_SCANCODE_PAGEDOWN,
500 SDL_SCANCODE_KP_DIVIDE,
501 SDL_SCANCODE_KP_MULTIPLY,
502 SDL_SCANCODE_KP_MINUS,
503 SDL_SCANCODE_KP_PLUS,
504 SDL_SCANCODE_KP_PERIOD,
505 SDL_SCANCODE_KP_ENTER,
506 SDL_SCANCODE_PRINTSCREEN,
508 SDL_SCANCODE_UNKNOWN, (* !!! KEY_ABNT_C1 *)
509 SDL_SCANCODE_INTERNATIONAL3, (* ??? KEY_YEN *)
510 SDL_SCANCODE_LANG3, (* ??? KEY_KANA *)
511 SDL_SCANCODE_UNKNOWN, (* !!! KEY_CONVERT *)
512 SDL_SCANCODE_UNKNOWN, (* !!! KEY_NOCONVERT *)
514 SDL_SCANCODE_UNKNOWN, (* !!! KEY_CIRCUMFLEX *)
515 SDL_SCANCODE_KP_COLON,
516 SDL_SCANCODE_UNKNOWN, (* !!! KEY_KANJI *)
517 SDL_SCANCODE_KP_EQUALS,
518 SDL_SCANCODE_UNKNOWN, (* !!! KEY_BACKQUOTE *)
519 SDL_SCANCODE_SEMICOLON,
521 SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN1 *)
522 SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN2 *)
523 SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN3 *)
524 SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN4 *)
525 SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN5 *)
526 SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN6 *)
527 SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN7 *)
528 SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN8 *)
537 SDL_SCANCODE_MODE, (* ??? KEY_MENU *)
538 SDL_SCANCODE_SCROLLLOCK,
539 SDL_SCANCODE_NUMLOCKCLEAR,
540 SDL_SCANCODE_CAPSLOCK,
541 SDL_SCANCODE_UNKNOWN (* KEY_MAX *)
544 procedure LoadCustomPalette (const name: String);
545 var f: TFileStream; i: Integer;
548 f := TFileStream.Create(name, fmOpenRead);
549 e_LogWriteLn('Load custom palette ' + name);
552 custompal[i].r := f.ReadByte();
553 custompal[i].g := f.ReadByte();
554 custompal[i].b := f.ReadByte();
555 custompal[i].filler := $FF;
559 e_LogWriteLn('Fallback to default palette');
560 custompal := default_palette;
564 custompal[i].r := i div 4;
565 custompal[i].g := i div 4;
566 custompal[i].b := i div 4;
567 custompal[i].filler := $FF;
573 procedure UpdatePalette;
575 set_palette(custompal);
576 select_palette(custompal);
577 create_trans_table(@globalTransTable, custompal, 255, 255, 255, nil);
578 create_trans_table(@redTransTable, custompal, 0, 255, 255, nil);
579 create_trans_table(@greenTransTable, custompal, 255, 0, 255, nil);
580 create_trans_table(@blueTransTable, custompal, 255, 255, 0, nil);
581 create_trans_table(@darkTransTable, custompal, 191, 191, 191, nil);
582 create_trans_table(@lightTransTable, custompal, 64, 64, 64, nil);
583 color_map := @globalTransTable;
586 function IsEmptyKeyboard: Boolean;
588 result := keybeg = keyend
591 function IsFullKeyboard: Boolean;
593 result := (keybeg - 1) mod maxKeyBuffer = keyend
596 function NextScancode: Integer;
599 if not IsEmptyKeyboard then
601 result := keyring[keybeg];
602 keybeg := (keybeg + 1) mod maxKeyBuffer
606 procedure KeyboardWatcher (scancode: Integer); cdecl;
608 if (keybeg - 1) mod maxKeyBuffer <> keyend then (* not IsFullKeyboard *)
610 keyring[keyend] := scancode;
611 keyend := (keyend + 1) mod maxKeyBuffer
614 procedure KeyboardWatcherEND; begin end;
618 function SDL_PIXELFLAG(X: Cardinal): Cardinal;
620 Result := (X shr 28) and $0F;
623 function SDL_PIXELTYPE(X: Cardinal): Cardinal;
625 Result := (X shr 24) and $0F;
628 function SDL_PIXELORDER(X: Cardinal): Cardinal;
630 Result := (X shr 20) and $0F;
633 function SDL_PIXELLAYOUT(X: Cardinal): Cardinal;
635 Result := (X shr 16) and $0F;
638 function SDL_BITSPERPIXEL(X: Cardinal): Cardinal;
640 Result := (X shr 8) and $FF;
643 function SDL_IsPixelFormat_FOURCC(format: Variant): Boolean;
645 Result := format and SDL_PIXELFLAG(format) <> 1;
650 (********** FILES **********)
652 function SDL_RWFromFile(const _file: PAnsiChar; const mode: PAnsiChar): PSDL_RWops;
654 result := nil (* stub, used for sdl2stub_mixer *)
657 function SDL_RWFromConstMem(const mem: Pointer; size: SInt32): PSDL_RWops;
659 result := nil (* stub, used for sdl2stub_mixer *)
662 (********** KEYBOARD **********)
664 function SDL_GetScancodeName(scancode: TSDL_ScanCode): PAnsiChar;
667 SDL_SCANCODE_A: result := 'A';
668 SDL_SCANCODE_B: result := 'B';
669 SDL_SCANCODE_C: result := 'C';
670 SDL_SCANCODE_D: result := 'D';
671 SDL_SCANCODE_E: result := 'E';
672 SDL_SCANCODE_F: result := 'F';
673 SDL_SCANCODE_G: result := 'G';
674 SDL_SCANCODE_H: result := 'H';
675 SDL_SCANCODE_I: result := 'I';
676 SDL_SCANCODE_J: result := 'J';
677 SDL_SCANCODE_K: result := 'K';
678 SDL_SCANCODE_L: result := 'L';
679 SDL_SCANCODE_M: result := 'M';
680 SDL_SCANCODE_N: result := 'N';
681 SDL_SCANCODE_O: result := 'O';
682 SDL_SCANCODE_P: result := 'P';
683 SDL_SCANCODE_Q: result := 'Q';
684 SDL_SCANCODE_R: result := 'R';
685 SDL_SCANCODE_S: result := 'S';
686 SDL_SCANCODE_T: result := 'T';
687 SDL_SCANCODE_U: result := 'U';
688 SDL_SCANCODE_V: result := 'V';
689 SDL_SCANCODE_W: result := 'W';
690 SDL_SCANCODE_X: result := 'X';
691 SDL_SCANCODE_Y: result := 'Y';
692 SDL_SCANCODE_Z: result := 'Z';
693 SDL_SCANCODE_0: result := '0';
694 SDL_SCANCODE_1: result := '1';
695 SDL_SCANCODE_2: result := '2';
696 SDL_SCANCODE_3: result := '3';
697 SDL_SCANCODE_4: result := '4';
698 SDL_SCANCODE_5: result := '5';
699 SDL_SCANCODE_6: result := '6';
700 SDL_SCANCODE_7: result := '7';
701 SDL_SCANCODE_8: result := '8';
702 SDL_SCANCODE_9: result := '9';
703 SDL_SCANCODE_RETURN: result := 'Return';
704 SDL_SCANCODE_ESCAPE: result := 'Escape';
705 SDL_SCANCODE_BACKSPACE: result := 'Backspace';
706 SDL_SCANCODE_TAB: result := 'Tab';
707 SDL_SCANCODE_SPACE: result := 'Space';
708 SDL_SCANCODE_MINUS: result := '-';
709 SDL_SCANCODE_EQUALS: result := '=';
710 SDL_SCANCODE_LEFTBRACKET: result := '[';
711 SDL_SCANCODE_RIGHTBRACKET: result := ']';
712 SDL_SCANCODE_BACKSLASH: result := '\';
713 SDL_SCANCODE_SEMICOLON: result := ';';
714 SDL_SCANCODE_APOSTROPHE: result := '''';
715 SDL_SCANCODE_GRAVE: result := '`';
716 SDL_SCANCODE_COMMA: result := ',';
717 SDL_SCANCODE_PERIOD: result := '.';
718 SDL_SCANCODE_SLASH: result := '/';
719 SDL_SCANCODE_CAPSLOCK: result := 'CapsLock';
720 SDL_SCANCODE_F1: result := 'F1';
721 SDL_SCANCODE_F2: result := 'F2';
722 SDL_SCANCODE_F3: result := 'F3';
723 SDL_SCANCODE_F4: result := 'F4';
724 SDL_SCANCODE_F5: result := 'F5';
725 SDL_SCANCODE_F6: result := 'F6';
726 SDL_SCANCODE_F7: result := 'F7';
727 SDL_SCANCODE_F8: result := 'F8';
728 SDL_SCANCODE_F9: result := 'F9';
729 SDL_SCANCODE_F10: result := 'F10';
730 SDL_SCANCODE_F11: result := 'F11';
731 SDL_SCANCODE_F12: result := 'F12';
732 SDL_SCANCODE_PRINTSCREEN: result := 'PrintScreen';
733 SDL_SCANCODE_SCROLLLOCK: result := 'ScrollLock';
734 SDL_SCANCODE_PAUSE: result := 'Pause';
735 SDL_SCANCODE_INSERT: result := 'Insert';
736 SDL_SCANCODE_HOME: result := 'Home';
737 SDL_SCANCODE_PAGEUP: result := 'PageUp';
738 SDL_SCANCODE_DELETE: result := 'Delete';
739 SDL_SCANCODE_END: result := 'End';
740 SDL_SCANCODE_PAGEDOWN: result := 'PageDown';
741 SDL_SCANCODE_RIGHT: result := 'Right';
742 SDL_SCANCODE_LEFT: result := 'Left';
743 SDL_SCANCODE_DOWN: result := 'Down';
744 SDL_SCANCODE_UP: result := 'Up';
745 SDL_SCANCODE_NUMLOCKCLEAR: result := 'Numlock';
746 SDL_SCANCODE_KP_DIVIDE: result := 'Keypad /';
747 SDL_SCANCODE_KP_MULTIPLY: result := 'Keypad *';
748 SDL_SCANCODE_KP_MINUS: result := 'Keypad -';
749 SDL_SCANCODE_KP_PLUS: result := 'Keypad +';
750 SDL_SCANCODE_KP_ENTER: result := 'Keypad Enter';
751 SDL_SCANCODE_KP_1: result := 'Keypad 1';
752 SDL_SCANCODE_KP_2: result := 'Keypad 2';
753 SDL_SCANCODE_KP_3: result := 'Keypad 3';
754 SDL_SCANCODE_KP_4: result := 'Keypad 4';
755 SDL_SCANCODE_KP_5: result := 'Keypad 5';
756 SDL_SCANCODE_KP_6: result := 'Keypad 6';
757 SDL_SCANCODE_KP_7: result := 'Keypad 7';
758 SDL_SCANCODE_KP_8: result := 'Keypad 8';
759 SDL_SCANCODE_KP_9: result := 'Keypad 9';
760 SDL_SCANCODE_KP_0: result := 'Keypad 0';
761 SDL_SCANCODE_KP_PERIOD: result := 'Keypad .';
762 SDL_SCANCODE_APPLICATION: result := 'Application';
763 SDL_SCANCODE_POWER: result := 'Power';
764 SDL_SCANCODE_KP_EQUALS: result := 'Keypad =';
765 (* !!! F1x/F2x and multimedia ... *)
766 SDL_SCANCODE_KP_COMMA: result := 'Keypad ,';
767 SDL_SCANCODE_KP_EQUALSAS400: result := 'Keypad = (AS400)';
768 SDL_SCANCODE_ALTERASE: result := 'AltErase';
769 SDL_SCANCODE_SYSREQ: result := 'SysReq';
770 SDL_SCANCODE_CANCEL: result := 'Cancel';
771 SDL_SCANCODE_CLEAR: result := 'Clear';
772 SDL_SCANCODE_PRIOR: result := 'Prior';
773 SDL_SCANCODE_RETURN2: result := 'Return';
774 SDL_SCANCODE_SEPARATOR: result := 'Separator';
775 SDL_SCANCODE_OUT: result := 'Out';
776 SDL_SCANCODE_OPER: result := 'Oper';
777 SDL_SCANCODE_CLEARAGAIN: result := 'Clear / Again';
778 SDL_SCANCODE_CRSEL: result := 'CrSel';
779 SDL_SCANCODE_EXSEL: result := 'ExSel';
780 (* !!! Additional KP *)
781 SDL_SCANCODE_LCTRL: result := 'Left Ctrl';
782 SDL_SCANCODE_LSHIFT: result := 'Left Shift';
783 SDL_SCANCODE_LALT: result := 'Left Alt';
784 SDL_SCANCODE_LGUI: result := 'Left GUI';
785 SDL_SCANCODE_RCTRL: result := 'Right Ctrl';
786 SDL_SCANCODE_RSHIFT: result := 'Right Shift';
787 SDL_SCANCODE_RALT: result := 'Right Alt';
788 SDL_SCANCODE_RGUI: result := 'Right GUI';
789 SDL_SCANCODE_MODE: result := 'ModeSwitch';
796 function SDL_IsTextInputActive: TSDL_Bool;
804 procedure SDL_StartTextInput;
809 procedure SDL_StopTextInput;
814 (********** JOYSTICK **********)
816 function SDL_NumJoysticks: SInt32;
821 function SDL_JoystickOpen(device_index: SInt32): PSDL_Joystick;
826 function SDL_JoystickName(joystick: PSDL_Joystick): PAnsiChar;
831 function SDL_JoystickNumAxes(joystick: PSDL_Joystick): SInt32;
836 function SDL_JoystickNumButtons(joystick: PSDL_Joystick): SInt32;
841 function SDL_JoystickNumHats(joystick: PSDL_Joystick): SInt32;
846 procedure SDL_JoystickClose(joystick: PSDL_Joystick);
850 procedure SDL_JoystickUpdate;
854 function SDL_JoystickGetButton(joystick: PSDL_Joystick; button: SInt32): UInt8;
859 function SDL_JoystickGetAxis(joystick: PSDL_Joystick; axis: SInt32): SInt16;
864 function SDL_JoystickGetHat(joystick: PSDL_Joystick; hat: SInt32): UInt8;
869 (********** TOUCH **********)
871 function SDL_GetNumTouchDevices: SInt32;
876 (********** TIMERS **********)
878 procedure AllegroTimerCallback; cdecl;
882 procedure AllegroTimerCallbackEND; begin end;
884 function SDL_GetPerformanceCounter: UInt64;
886 result := ticks (* !!! *)
889 function SDL_GetPerformanceFrequency: UInt64;
891 result := 1 (* !!! *)
894 procedure SDL_Delay(ms: UInt32);
899 function SDL_GetTicks: UInt32;
904 (********** DISPLAY MODES **********)
906 function GetPixelFormat (bpp: Integer): UInt32;
909 8: result := SDL_PIXELFORMAT_INDEX8;
910 15: result := SDL_PIXELFORMAT_RGB555;
911 16: result := SDL_PIXELFORMAT_RGB565;
912 24: result := SDL_PIXELFORMAT_RGB888;
913 32: result := SDL_PIXELFORMAT_RGBA8888;
914 else result := SDL_PIXELFORMAT_UNKNOWN
918 function SDL_GetDesktopDisplayMode(displayIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
921 mode.format := GetPixelFormat(deskbpp);
924 mode.refresh_rate := 0;
925 mode.driverdata := nil;
929 function SDL_GetClosestDisplayMode(displayIndex: SInt32; const mode: PSDL_DisplayMode; closest: PSDL_DisplayMode): PSDL_DisplayMode;
930 var m: PGFX_MODE_LIST; i, bpp: Integer;
933 ASSERT(closest <> nil);
936 bpp := SDL_BITSPERPIXEL(mode.format);
937 if bpp = 0 then bpp := deskbpp;
940 if (gfx_driver <> nil) and (@gfx_driver.fetch_mode_list <> nil) then
941 m := gfx_driver.fetch_mode_list;
946 while (i < m.num_modes) and (m.mode[i].bpp <> bpp) do inc(i);
947 if i < m.num_modes then
949 closest.format := mode.format;
950 closest.refresh_rate := 0;
951 closest.driverdata := nil;
952 closest.w := m.mode[i].width;
953 closest.h := m.mode[i].height;
956 while i < m.num_modes do
958 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
960 closest.w := m.mode[i].width;
961 closest.h := m.mode[i].height;
966 destroy_gfx_mode_list(m)
970 function SDL_GetNumDisplayModes(displayIndex: SInt32): SInt32;
971 var m: PGFX_MODE_LIST;
976 if (gfx_driver <> nil) and (@gfx_driver.fetch_mode_list <> nil) then
977 m := gfx_driver.fetch_mode_list;
981 result := m.num_modes;
982 destroy_gfx_mode_list(m);
986 function SDL_GetDisplayMode(displayIndex: SInt32; modeIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
987 var m: PGFX_MODE_LIST;
992 if (gfx_driver <> nil) and (@gfx_driver.fetch_mode_list <> nil) then
993 m := gfx_driver.fetch_mode_list;
997 if (modeIndex >= 0) and (modeIndex < m.num_modes) then
999 mode.format := GetPixelFormat(m.mode[modeIndex].bpp);
1000 mode.w := m.mode[modeIndex].width;
1001 mode.h := m.mode[modeIndex].height;
1002 mode.refresh_rate := 0;
1003 mode.driverdata := nil;
1006 destroy_gfx_mode_list(m)
1010 function SDL_GetDisplayDPI(displayIndex: SInt32; ddpi, hdpi, vdpi: PFloat): SInt32;
1012 result := -1 (* stub *)
1015 (*********** WINDOW MANAGEMENT **********)
1017 function SDL_CreateWindow(const title: PAnsiChar; x: SInt32; y: SInt32; w: SInt32; h: SInt32; flags: UInt32): PSDL_Window;
1018 var window: PSDL_Window; mode: Integer;
1022 {$IF DEFINED(GO32V2)}
1023 mode := GFX_AUTODETECT;
1025 if (flags and (SDL_WINDOW_FULLSCREEN or SDL_WINDOW_FULLSCREEN_DESKTOP)) <> 0 then
1026 mode := GFX_AUTODETECT_FULLSCREEN
1028 mode := GFX_AUTODETECT_WINDOWED;
1031 if sdl2allegro_bpp = 0 then sdl2allegro_bpp := gBPP;
1032 if sdl2allegro_bpp = 0 then sdl2allegro_bpp := deskbpp;
1034 set_color_depth(sdl2allegro_bpp);
1035 if set_gfx_mode(mode, w, h, 0, 0) = 0 then
1038 set_window_title(title);
1039 if sdl2allegro_screen <> nil then
1040 destroy_bitmap(sdl2allegro_screen);
1041 sdl2allegro_screen := create_system_bitmap(w, h);
1042 if sdl2allegro_screen = nil then
1043 sdl2allegro_screen := create_bitmap(w, h);
1044 ASSERT(sdl2allegro_screen <> nil);
1047 window.mode := mode;
1053 function SDL_SetWindowFullscreen(window: PSDL_Window; flags: UInt32): SInt32;
1056 ASSERT(window <> nil);
1059 {$IF DEFINED(GO32V2)}
1060 mode := GFX_AUTODETECT;
1062 if (flags and (SDL_WINDOW_FULLSCREEN or SDL_WINDOW_FULLSCREEN_DESKTOP)) <> 0 then
1063 mode := GFX_AUTODETECT_FULLSCREEN
1065 mode := GFX_AUTODETECT_WINDOWED;
1068 set_color_depth(sdl2allegro_bpp);
1069 if set_gfx_mode(mode, window.w, window.h, 0, 0) = 0 then
1071 if sdl2allegro_screen <> nil then
1072 destroy_bitmap(sdl2allegro_screen);
1073 sdl2allegro_screen := create_system_bitmap(window.w, window.h);
1074 if sdl2allegro_screen = nil then
1075 sdl2allegro_screen := create_bitmap(window.w, window.h);
1076 ASSERT(sdl2allegro_screen <> nil);
1078 window.mode := mode;
1083 procedure SDL_SetWindowSize(window: PSDL_Window; w: SInt32; h: SInt32);
1085 ASSERT(window <> nil);
1086 set_color_depth(sdl2allegro_bpp);
1087 if set_gfx_mode(window.mode, w, h, 0, 0) = 0 then
1089 if sdl2allegro_screen <> nil then
1090 destroy_bitmap(sdl2allegro_screen);
1091 sdl2allegro_screen := create_system_bitmap(w, h);
1092 if sdl2allegro_screen = nil then
1093 sdl2allegro_screen := create_bitmap(w, h);
1094 ASSERT(sdl2allegro_screen <> nil);
1101 ASSERT(FALSE, 'Unable to set window size')
1105 procedure SDL_DestroyWindow(window: PSDL_Window);
1107 if window = nil then exit;
1108 if sdl2allegro_screen <> nil then
1109 destroy_bitmap(sdl2allegro_screen);
1110 sdl2allegro_screen := nil;
1114 procedure SDL_GetWindowSize(window: PSDL_Window; w: PInt; h: PInt);
1116 ASSERT(window <> nil);
1117 if w <> nil then w^ := window.w;
1118 if h <> nil then h^ := window.h;
1121 procedure SDL_RestoreWindow(window: PSDL_Window);
1123 ASSERT(window <> nil);
1127 function SDL_SetWindowGammaRamp(window: PSDL_Window; const red: PUInt16; const green: PUInt16; const blue: PUInt16): SInt32;
1129 ASSERT(window <> nil);
1130 result := 0 (* stub *)
1133 function SDL_GetWindowGammaRamp(window: PSDL_Window; red: PUInt16; green: PUInt16; blue: PUInt16): SInt32;
1135 ASSERT(window <> nil);
1136 result := 0 (* stub *)
1139 (********** OPENGL MANAGEMENT **********)
1141 function SDL_GL_SetAttribute(attr: TSDL_GLattr; value: SInt32): SInt32;
1143 e_LogWritefln('SDL_GL_SetAttribute %s %s', [attr, value]);
1144 allegro_error := 'Attribute ' + IntToStr(attr) + ' := ' + IntToStr(value) + 'not supported';
1148 function SDL_GL_GetAttribute(attr: TSDL_GLattr; value: PInt): SInt32;
1150 e_LogWritefln('SDL_GL_GetAttribute %s', [attr]);
1151 value^ := 0; result := -1
1154 function SDL_GL_CreateContext(window: PSDL_Window): TSDL_GLContext;
1156 result := window (* stub *)
1159 function SDL_GL_MakeCurrent(window: PSDL_Window; context: TSDL_GLContext): SInt32;
1161 ASSERT(window <> nil);
1162 if context <> nil then
1163 ASSERT(window = context);
1164 result := 0 (* stub *)
1167 procedure SDL_GL_DeleteContext(context: TSDL_GLContext);
1172 function SDL_GL_SetSwapInterval(interval: SInt32): SInt32;
1175 if interval = 0 then
1181 procedure SDL_GL_SwapWindow(window: PSDL_Window);
1183 ASSERT(window <> nil);
1184 ASSERT(sdl2allegro_screen <> nil);
1186 blit(sdl2allegro_screen, screen, 0, 0, 0, 0, min(sdl2allegro_screen.w, screen.w), min(sdl2allegro_screen.h, screen.h));
1187 show_video_bitmap(screen);
1193 (********** EVENTS **********)
1195 function SDL_PushEvent(event: PSDL_Event): SInt32;
1199 SDL_QUITEV: quit := True;
1206 function SDL_PollEvent(event: PSDL_Event): SInt32;
1207 var alscan: Integer; pressed, shift, caps: Boolean;
1214 event.type_ := SDL_QUITEV;
1215 event.quit.timestamp := ticks;
1220 if inputText and (inputChar <> #0) then
1222 event.type_ := SDL_TEXTINPUT;
1223 event.text.timestamp := ticks;
1224 event.text.windowID := 0;
1225 event.text.text[0] := inputChar;
1226 event.text.text[1] := #0;
1235 if not IsEmptyKeyboard then
1237 alscan := NextScancode;
1238 pressed := alscan and $80 = 0;
1243 shift := key_shifts and KB_SHIFT_FLAG <> 0;
1244 caps := key_shifts and KB_CAPSLOCK_FLAG <> 0;
1245 if shift xor caps then
1246 inputChar := s2uc[alscan and $7F]
1248 inputChar := s2lc[alscan and $7F];
1249 event.type_ := SDL_KEYDOWN
1252 event.type_ := SDL_KEYUP;
1254 event.key.timestamp := ticks;
1255 event.key.windowID := 0;
1257 (**** df not use it?
1259 event.key.state := SDL_PRESSED
1261 event.key.state := SDL_RELEASED;
1264 event.key._repeat := 0;
1265 event.key.keysym.scancode := s2sa[alscan and $7F];
1266 event.key.keysym.sym := 0; (* df not use it? *)
1267 event.key.keysym._mod := 0; (* df not use it? *)
1273 (********** MOUSE **********)
1275 function SDL_ShowCursor(toggle: SInt32): SInt32;
1277 result := 0 (* stub *)
1280 (********** SDL **********)
1282 procedure AllegroQuitCallback; cdecl;
1286 procedure AllegroQuitCallbackEND; begin end;
1288 function SDL_SetHint(const name: PChar; const value: PChar): boolean;
1290 e_LogWritefln('SDL_SetHint %s %s', [name, value]);
1291 result := false (* stub *)
1294 function SDL_GetError: PAnsiChar;
1296 result := allegro_error
1300 (* HACK: allegro crashes while init without this *)
1302 __crt0_argv: PPchar; cvar; external;
1303 myargv: array [0..1] of Pchar;
1307 __crt0_argv := @myargv[0];
1308 myargv[0] := PChar(ParamStr(0));
1309 e_LogWritefln('argv[0] = %s', [myargv[0]]);
1313 function SDL_Init(flags: UInt32): SInt32;
1319 if allegro_init = 0 then
1321 e_LogWriteln('Allegro Init: ok');
1323 (* without this df dies with fire when swapped *)
1324 lock_data(ticks, sizeof(ticks));
1325 lock_code(@AllegroTimerCallback, PtrUInt(@AllegroTimerCallbackEND) - PtrUInt(@AllegroTimerCallback));
1326 lock_data(keybeg, sizeof(keybeg));
1327 lock_data(keyend, sizeof(keyend));
1328 lock_data(keyring, sizeof(keyring));
1329 lock_code(@KeyboardWatcher, PtrUInt(@KeyboardWatcherEND) - PtrUInt(@KeyboardWatcher));
1330 lock_data(quit, sizeof(quit));
1331 lock_code(@AllegroQuitCallback, PtrUInt(@AllegroQuitCallbackEND) - PtrUInt(@AllegroQuitCallback));
1335 keyboard_lowlevel_callback := KeyboardWatcher;
1336 set_keyboard_rate(0, 0);
1337 install_int_ex(AllegroTimerCallback, MSEC_TO_TIMER(1));
1338 set_close_button_callback(AllegroQuitCallback);
1339 deskbpp := desktop_color_depth;
1340 if deskbpp = 0 then deskbpp := 8;
1341 if get_desktop_resolution(@deskw, @deskh) <> 0 then
1346 LoadCustomPalette('PLAYPAL.LMP');
1353 set_close_button_callback(nil);
1357 unlock_data(ticks, sizeof(ticks));
1358 unlock_code(@AllegroTimerCallback, PtrUInt(@AllegroTimerCallbackEND) - PtrUInt(@AllegroTimerCallback));
1359 unlock_data(keybeg, sizeof(keybeg));
1360 unlock_data(keyend, sizeof(keyend));
1361 unlock_data(keyring, sizeof(keyring));
1362 unlock_code(@KeyboardWatcher, PtrUInt(@KeyboardWatcherEND) - PtrUInt(@KeyboardWatcher));
1363 unlock_data(quit, sizeof(quit));
1364 unlock_code(@AllegroQuitCallback, PtrUInt(@AllegroQuitCallbackEND) - PtrUInt(@AllegroQuitCallback));