DEADSOFTWARE

cb5ea6f7ad1f6f9b247e630f8008479c534f5d89
[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] 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;
299 /// FUNCTIONS ///
301 function SDL_SetWindowGammaRamp(window: PSDL_Window; const red: PUInt16; const green: PUInt16; const blue: PUInt16): SInt32;
302 function SDL_GetWindowGammaRamp(window: PSDL_Window; red: PUInt16; green: PUInt16; blue: PUInt16): SInt32;
304 function SDL_NumJoysticks: SInt32;
305 function SDL_JoystickOpen(device_index: SInt32): PSDL_Joystick;
306 function SDL_JoystickName(joystick: PSDL_Joystick): PAnsiChar;
307 function SDL_JoystickNumAxes(joystick: PSDL_Joystick): SInt32;
308 function SDL_JoystickNumButtons(joystick: PSDL_Joystick): SInt32;
309 function SDL_JoystickNumHats(joystick: PSDL_Joystick): SInt32;
310 procedure SDL_JoystickClose(joystick: PSDL_Joystick);
311 procedure SDL_JoystickUpdate;
312 function SDL_JoystickGetButton(joystick: PSDL_Joystick; button: SInt32): UInt8;
313 function SDL_JoystickGetAxis(joystick: PSDL_Joystick; axis: SInt32): SInt16;
314 function SDL_JoystickGetHat(joystick: PSDL_Joystick; hat: SInt32): UInt8;
316 function SDL_GetScancodeName(scancode: TSDL_ScanCode): PAnsiChar;
318 function SDL_GetPerformanceCounter: UInt64;
319 function SDL_GetPerformanceFrequency: UInt64;
321 function SDL_RWFromFile(const _file: PAnsiChar; const mode: PAnsiChar): PSDL_RWops;
322 function SDL_RWFromConstMem(const mem: Pointer; size: SInt32): PSDL_RWops;
324 function SDL_GetDisplayDPI(displayIndex: SInt32; ddpi, hdpi, vdpi: PFloat): SInt32;
325 function SDL_IsTextInputActive: TSDL_Bool;
326 procedure SDL_StartTextInput;
327 procedure SDL_StopTextInput;
328 function SDL_GetNumTouchDevices: SInt32;
330 function SDL_GetDesktopDisplayMode(displayIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
331 function SDL_GetClosestDisplayMode(displayIndex: SInt32; const mode: PSDL_DisplayMode; closest: PSDL_DisplayMode): PSDL_DisplayMode;
333 procedure SDL_DestroyWindow(window: PSDL_Window);
334 procedure SDL_GL_DeleteContext(context: TSDL_GLContext);
335 procedure SDL_RestoreWindow(window: PSDL_Window);
336 procedure SDL_SetWindowSize(window: PSDL_Window; w: SInt32; h: SInt32);
337 function SDL_CreateWindow(const title: PAnsiChar; x: SInt32; y: SInt32; w: SInt32; h: SInt32; flags: UInt32): PSDL_Window;
338 function SDL_SetWindowFullscreen(window: PSDL_Window; flags: UInt32): SInt32;
339 function SDL_GL_MakeCurrent(window: PSDL_Window; context: TSDL_GLContext): SInt32;
340 procedure SDL_GetWindowSize(window: PSDL_Window; w: PInt; h: PInt);
341 function SDL_GetNumDisplayModes(displayIndex: SInt32): SInt32;
342 function SDL_GetDisplayMode(displayIndex: SInt32; modeIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
344 function SDL_ShowCursor(toggle: SInt32): SInt32;
345 procedure SDL_Delay(ms: UInt32);
346 procedure SDL_GL_SwapWindow(window: PSDL_Window);
348 function SDL_GL_CreateContext(window: PSDL_Window): TSDL_GLContext;
349 function SDL_GetTicks: UInt32;
351 function SDL_PushEvent(event: PSDL_Event): SInt32;
352 function SDL_PollEvent(event: PSDL_Event): SInt32;
353 function SDL_GL_SetSwapInterval(interval: SInt32): SInt32;
354 function SDL_GL_SetAttribute(attr: TSDL_GLattr; value: SInt32): SInt32;
355 function SDL_GL_GetAttribute(attr: TSDL_GLattr; value: PInt): SInt32;
357 function SDL_GetError: PAnsiChar;
359 function SDL_Init(flags: UInt32): SInt32;
360 procedure SDL_Quit();
361 function SDL_SetHint( const name: PChar; const value: PChar) : boolean;
363 implementation
365 uses e_Log, SysUtils;
367 const
368 maxKeyBuffer = 64;
370 var
371 __crt0_argv: PPchar; cvar; external;
372 myargv: array [0..255] of Pchar;
373 keyring: array [0..maxKeyBuffer - 1] of Integer;
374 keybeg, keyend: Integer;
376 function IsEmptyKeyboard: Boolean;
377 begin
378 result := keybeg = keyend
379 end;
381 function IsFullKeyboard: Boolean;
382 begin
383 result := (keybeg - 1) mod maxKeyBuffer = keyend
384 end;
386 function NextScancode: Integer;
387 begin
388 result := 0;
389 if not IsEmptyKeyboard then
390 begin
391 result := keyring[keybeg];
392 keybeg := (keybeg + 1) mod maxKeyBuffer
393 end
394 end;
396 procedure KeyboardWatcher (scancode: Integer); cdecl;
397 begin
398 if not IsFullKeyboard then
399 begin
400 keyring[keyend] := scancode;
401 keyend := (keyend + 1) mod maxKeyBuffer
402 end
403 end;
405 /// MACRO ///
407 //from "sdl_pixels.h"
409 function SDL_PIXELFLAG(X: Cardinal): Cardinal;
410 begin
411 Result := (X shr 28) and $0F;
412 end;
414 function SDL_PIXELTYPE(X: Cardinal): Cardinal;
415 begin
416 Result := (X shr 24) and $0F;
417 end;
419 function SDL_PIXELORDER(X: Cardinal): Cardinal;
420 begin
421 Result := (X shr 20) and $0F;
422 end;
424 function SDL_PIXELLAYOUT(X: Cardinal): Cardinal;
425 begin
426 Result := (X shr 16) and $0F;
427 end;
429 function SDL_BITSPERPIXEL(X: Cardinal): Cardinal;
430 begin
431 Result := (X shr 8) and $FF;
432 end;
434 function SDL_IsPixelFormat_FOURCC(format: Variant): Boolean;
435 begin
436 Result := format and SDL_PIXELFLAG(format) <> 1;
437 end;
439 /// FUNCTIONS ////
441 (********** FILES **********)
443 function SDL_RWFromFile(const _file: PAnsiChar; const mode: PAnsiChar): PSDL_RWops;
444 begin
445 result := nil
446 end;
448 function SDL_RWFromConstMem(const mem: Pointer; size: SInt32): PSDL_RWops;
449 begin
450 result := nil
451 end;
453 (********** KEYBOARD **********)
455 function SDL_GetScancodeName(scancode: TSDL_ScanCode): PAnsiChar;
456 begin
457 result := ''
458 end;
460 function SDL_IsTextInputActive: TSDL_Bool;
461 begin
462 result := SDL_FALSE
463 end;
465 procedure SDL_StartTextInput;
466 begin
467 end;
469 procedure SDL_StopTextInput;
470 begin
471 end;
473 (********** JOYSTICK **********)
475 function SDL_NumJoysticks: SInt32;
476 begin
477 result := 0
478 end;
480 function SDL_JoystickOpen(device_index: SInt32): PSDL_Joystick;
481 begin
482 result := nil
483 end;
485 function SDL_JoystickName(joystick: PSDL_Joystick): PAnsiChar;
486 begin
487 result := ''
488 end;
490 function SDL_JoystickNumAxes(joystick: PSDL_Joystick): SInt32;
491 begin
492 result := 0
493 end;
495 function SDL_JoystickNumButtons(joystick: PSDL_Joystick): SInt32;
496 begin
497 result := 0
498 end;
500 function SDL_JoystickNumHats(joystick: PSDL_Joystick): SInt32;
501 begin
502 result := 0
503 end;
505 procedure SDL_JoystickClose(joystick: PSDL_Joystick);
506 begin
507 end;
509 procedure SDL_JoystickUpdate;
510 begin
511 end;
513 function SDL_JoystickGetButton(joystick: PSDL_Joystick; button: SInt32): UInt8;
514 begin
515 result := 0
516 end;
518 function SDL_JoystickGetAxis(joystick: PSDL_Joystick; axis: SInt32): SInt16;
519 begin
520 result := 0
521 end;
523 function SDL_JoystickGetHat(joystick: PSDL_Joystick; hat: SInt32): UInt8;
524 begin
525 result := 0
526 end;
528 (********** TOUCH **********)
530 function SDL_GetNumTouchDevices: SInt32;
531 begin
532 result := 0
533 end;
535 (********** TIMERS **********)
537 function SDL_GetPerformanceCounter: UInt64;
538 begin
539 e_LogWriteln('SDL_GetPerformanceCounter');
540 result := 1
541 end;
543 function SDL_GetPerformanceFrequency: UInt64;
544 begin
545 e_LogWriteln('SDL_GetPerformanceFrequency');
546 result := 1
547 end;
549 procedure SDL_Delay(ms: UInt32);
550 begin
551 e_LogWriteln('SDL_Delay');
552 //allegro_rest(ms)
553 end;
555 function SDL_GetTicks: UInt32;
556 begin
557 e_LogWriteln('SDL_GetTicks');
558 result := 1
559 end;
561 (********** DISPLAY MODES **********)
563 function SDL_GetDesktopDisplayMode(displayIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
564 begin
565 e_LogWritefln('SDL_GetDesktopDisplayMode %s', [displayIndex]);
566 result := -1;
567 mode.format := SDL_PIXELFORMAT_UNKNOWN; (* FIXIT *)
568 mode.refresh_rate := 0;
569 mode.driverdata := nil;
570 if get_desktop_resolution(@mode.w, @mode.h) = 0 then
571 result := 0
572 end;
574 function SDL_GetClosestDisplayMode(displayIndex: SInt32; const mode: PSDL_DisplayMode; closest: PSDL_DisplayMode): PSDL_DisplayMode;
575 begin
576 e_LogWritefln('SDL_GetClosestDisplayMode %s', [displayIndex]);
577 result := nil;
578 end;
580 function SDL_GetNumDisplayModes(displayIndex: SInt32): SInt32;
581 var m: PGFX_MODE_LIST;
582 begin
583 e_LogWritefln('SDL_GetNumDisplayModes %s', [displayIndex]);
584 result := -1;
585 m := get_gfx_mode_list(GFX_AUTODETECT);
586 if m <> nil then
587 begin
588 result := m.num_modes;
589 destroy_gfx_mode_list(m);
590 end
591 end;
593 function SDL_GetDisplayMode(displayIndex: SInt32; modeIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
594 var m: PGFX_MODE_LIST;
595 begin
596 e_LogWritefln('SDL_GetDisplayMode %s %s', [displayIndex, modeIndex]);
597 result := -1;
598 m := get_gfx_mode_list(GFX_AUTODETECT);
599 if (m <> nil) and (modeIndex >= 0) and (modeIndex < m.num_modes) then
600 begin
601 mode.format := SDL_PIXELFORMAT_UNKNOWN; (* FIX IT *)
602 mode.w := m.mode[modeIndex].width;
603 mode.h := m.mode[modeIndex].height;
604 mode.refresh_rate := 0;
605 mode.driverdata := nil;
606 destroy_gfx_mode_list(m);
607 result := 0
608 end
609 end;
611 function SDL_GetDisplayDPI(displayIndex: SInt32; ddpi, hdpi, vdpi: PFloat): SInt32;
612 begin
613 result := -1
614 end;
616 (*********** WINDOW MANAGEMENT **********)
618 function SDL_CreateWindow(const title: PAnsiChar; x: SInt32; y: SInt32; w: SInt32; h: SInt32; flags: UInt32): PSDL_Window;
619 var window: PSDL_Window; mode: Integer;
620 begin
621 e_LogWritefln('SDL_CreateWindow %s %s %s %s %s %u', [title, x, y, w, h, flags]);
622 result := nil;
624 if (flags and (SDL_WINDOW_FULLSCREEN or SDL_WINDOW_FULLSCREEN_DESKTOP)) <> 0 then
625 mode := GFX_AUTODETECT_FULLSCREEN
626 else
627 mode := GFX_AUTODETECT_WINDOWED;
628 mode := GFX_SAFE;
630 if set_gfx_mode(mode, w, h, 0, 0) = 0 then
631 begin
632 new(window);
633 set_window_title(title);
634 if sdl2allegro_screen <> nil then
635 destroy_bitmap(sdl2allegro_screen);
636 sdl2allegro_screen := create_video_bitmap(w, h);
637 if sdl2allegro_screen = nil then
638 sdl2allegro_screen := create_system_bitmap(w, h);
639 if sdl2allegro_screen = nil then
640 sdl2allegro_screen := create_bitmap(w, h);
641 assert(sdl2allegro_screen <> nil);
642 window.w := w;
643 window.h := h;
644 window.mode := mode;
645 result := window
646 end
647 end;
649 function SDL_SetWindowFullscreen(window: PSDL_Window; flags: UInt32): SInt32;
650 var mode: Integer;
651 begin
652 e_LogWritefln('SDL_SetWindowFullscreen %u', [flags]);
653 result := -1;
654 if window = nil then exit;
656 if (flags and (SDL_WINDOW_FULLSCREEN or SDL_WINDOW_FULLSCREEN_DESKTOP)) <> 0 then
657 mode := GFX_AUTODETECT_FULLSCREEN
658 else
659 mode := GFX_AUTODETECT_WINDOWED;
660 mode := GFX_SAFE;
662 if set_gfx_mode(mode, window.w, window.h, 0, 0) = 0 then
663 begin
664 (*
665 if sdl2allegro_screen <> nil then
666 destroy_bitmap(sdl2allegro_screen);
667 *)
668 sdl2allegro_screen := create_video_bitmap(window.w, window.h);
669 if sdl2allegro_screen = nil then
670 sdl2allegro_screen := create_system_bitmap(window.w, window.h);
671 if sdl2allegro_screen = nil then
672 sdl2allegro_screen := create_bitmap(window.w, window.h);
673 assert(sdl2allegro_screen <> nil);
674 window.mode := mode;
675 result := 0
676 end
677 end;
679 procedure SDL_SetWindowSize(window: PSDL_Window; w: SInt32; h: SInt32);
680 begin
681 e_LogWritefln('SDL_SetWindowSize %s %s', [w, h]);
682 if window = nil then exit;
683 if set_gfx_mode(window.mode, w, h, 0, 0) = 0 then
684 begin
685 if sdl2allegro_screen <> nil then
686 destroy_bitmap(sdl2allegro_screen);
687 if sdl2allegro_screen = nil then
688 sdl2allegro_screen := create_system_bitmap(w, h);
689 if sdl2allegro_screen = nil then
690 sdl2allegro_screen := create_bitmap(w, h);
691 sdl2allegro_screen := create_video_bitmap(w, h);
692 assert(sdl2allegro_screen <> nil);
693 window.w := w;
694 window.h := h;
695 end
696 end;
698 procedure SDL_DestroyWindow(window: PSDL_Window);
699 begin
700 e_LogWriteln('SDL_DestroyWindow');
701 if window = nil then exit;
702 if sdl2allegro_screen <> nil then
703 destroy_bitmap(sdl2allegro_screen);
704 sdl2allegro_screen := nil;
705 dispose(window)
706 end;
708 procedure SDL_GetWindowSize(window: PSDL_Window; w: PInt; h: PInt);
709 begin
710 e_LogWriteln('SDL_GetWindowSize');
711 if window = nil then exit;
712 if w <> nil then
713 w^ := window.w;
714 if h <> nil then
715 h^ := window.h;
716 end;
718 procedure SDL_RestoreWindow(window: PSDL_Window);
719 begin
720 e_LogWriteln('SDL_RestoreWindow');
721 if window = nil then exit;
722 (* stub *)
723 end;
725 function SDL_SetWindowGammaRamp(window: PSDL_Window; const red: PUInt16; const green: PUInt16; const blue: PUInt16): SInt32;
726 begin
727 e_LogWriteln('SDL_SetWindowGammaRamp');
728 result := -1;
729 if window = nil then exit;
730 result := 0
731 end;
733 function SDL_GetWindowGammaRamp(window: PSDL_Window; red: PUInt16; green: PUInt16; blue: PUInt16): SInt32;
734 begin
735 e_LogWriteln('SDL_GetWindowGammaRamp');
736 result := -1;
737 if window = nil then exit;
738 result := 0
739 end;
741 (********** OPENGL MANAGEMENT **********)
743 function SDL_GL_MakeCurrent(window: PSDL_Window; context: TSDL_GLContext): SInt32;
744 begin
745 e_LogWriteln('SDL_GL_MakeCurrent');
746 result := 0
747 end;
749 procedure SDL_GL_DeleteContext(context: TSDL_GLContext);
750 begin
751 e_LogWriteln('SDL_GL_DeleteContext');
752 end;
754 procedure SDL_GL_SwapWindow(window: PSDL_Window);
755 begin
756 e_LogWriteln('SDL_GL_SwapWindow');
757 assert(sdl2allegro_screen <> nil);
758 show_video_bitmap(sdl2allegro_screen);
759 end;
761 function SDL_GL_CreateContext(window: PSDL_Window): TSDL_GLContext;
762 begin
763 e_LogWriteln('SDL_GL_CreateContext');
764 result := window
765 end;
767 function SDL_GL_SetSwapInterval(interval: SInt32): SInt32;
768 begin
769 e_LogWritefln('SDL_GL_SetSwapInterval %s', [interval]);
770 result := 0
771 end;
773 function SDL_GL_SetAttribute(attr: TSDL_GLattr; value: SInt32): SInt32;
774 begin
775 e_LogWritefln('SDL_GL_SetAttribute %s %s', [attr, value]);
776 result := -1;
777 end;
779 function SDL_GL_GetAttribute(attr: TSDL_GLattr; value: PInt): SInt32;
780 begin
781 e_LogWritefln('SDL_GL_GetAttribute %s', [attr]);
782 value^ := 0; result := -1
783 end;
785 (********** EVENTS **********)
787 function SDL_PushEvent(event: PSDL_Event): SInt32;
788 begin
789 e_LogWriteln('SDL_PushEvent');
790 result := 0
791 end;
793 function allegro_to_sdl_scancode (x: Integer): Integer;
794 begin
795 x := x and $7F;
796 case x of
797 KEY_A..KEY_Z: result := SDL_SCANCODE_A + (x - KEY_A);
798 KEY_0..KEY_0: result := SDL_SCANCODE_0 + (x - KEY_0);
799 KEY_0_PAD: result := SDL_SCANCODE_KP_0;
800 KEY_1_PAD..KEY_9_PAD: result := SDL_SCANCODE_KP_1 + (x - KEY_1_PAD);
801 KEY_F1..KEY_F12: result := SDL_SCANCODE_F1 + (x - KEY_F1);
802 KEY_ESC: result := SDL_SCANCODE_ESCAPE;
803 KEY_TILDE: result := SDL_SCANCODE_GRAVE;
804 KEY_MINUS: result := SDL_SCANCODE_MINUS;
805 KEY_EQUALS: result := SDL_SCANCODE_EQUALS;
806 KEY_BACKSPACE: result := SDL_SCANCODE_BACKSPACE;
807 KEY_TAB: result := SDL_SCANCODE_TAB;
808 KEY_OPENBRACE: result := SDL_SCANCODE_LEFTBRACKET;
809 KEY_CLOSEBRACE: result := SDL_SCANCODE_RIGHTBRACKET;
810 KEY_ENTER: result := SDL_SCANCODE_RETURN;
811 KEY_COLON: result := SDL_SCANCODE_SEMICOLON;
812 KEY_QUOTE: result := SDL_SCANCODE_APOSTROPHE;
813 KEY_BACKSLASH: result := SDL_SCANCODE_BACKSLASH;
814 KEY_BACKSLASH2: result := SDL_SCANCODE_NONUSHASH; (* ??? *)
815 KEY_COMMA: result := SDL_SCANCODE_COMMA;
816 (*KEY_STOP: result :=;*) (* ??? *)
817 KEY_SLASH: result := SDL_SCANCODE_SLASH;
818 KEY_SPACE: result := SDL_SCANCODE_SPACE;
819 KEY_INSERT: result := SDL_SCANCODE_INSERT;
820 KEY_DEL: result := SDL_SCANCODE_DELETE;
821 KEY_HOME: result := SDL_SCANCODE_HOME;
822 KEY_END: result := SDL_SCANCODE_END;
823 KEY_PGUP: result := SDL_SCANCODE_PAGEUP;
824 KEY_PGDN: result := SDL_SCANCODE_PAGEDOWN;
825 KEY_LEFT: result := SDL_SCANCODE_LEFT;
826 KEY_RIGHT: result := SDL_SCANCODE_RIGHT;
827 KEY_UP: result := SDL_SCANCODE_UP;
828 KEY_DOWN: result := SDL_SCANCODE_DOWN;
829 KEY_SLASH_PAD: result := SDL_SCANCODE_KP_DIVIDE;
830 KEY_ASTERISK: result := SDL_SCANCODE_KP_MULTIPLY;
831 KEY_MINUS_PAD: result := SDL_SCANCODE_KP_MINUS;
832 KEY_PLUS_PAD: result := SDL_SCANCODE_KP_PLUS;
833 KEY_DEL_PAD: result := SDL_SCANCODE_KP_PERIOD;
834 KEY_ENTER_PAD: result := SDL_SCANCODE_KP_ENTER;
835 KEY_PRTSCR: result := SDL_SCANCODE_PRINTSCREEN;
836 KEY_PAUSE: result := SDL_SCANCODE_PAUSE;
837 (*KEY_ABNT_C1: result :=;*) (* ??? *)
838 KEY_YEN: result := SDL_SCANCODE_INTERNATIONAL3;
839 KEY_KANA: result := SDL_SCANCODE_LANG3; (* ??? *)
840 (*KEY_CONVERT: result :=;*) (* ??? *)
841 (*KEY_NOCONVERT: result := ;*) (* ??? *)
842 KEY_AT: result := SDL_SCANCODE_KP_AT;
843 (*KEY_CIRCUMFLEX: result :=;*) (* ??? *)
844 KEY_COLON2: result := SDL_SCANCODE_KP_COLON;
845 (*KEY_KANJI: result :=;*) (* ??? *)
846 KEY_EQUALS_PAD: result := SDL_SCANCODE_KP_EQUALS;
847 (*KEY_BACKQUOTE: result :=;*) (* ??? *)
848 KEY_SEMICOLON: result := SDL_SCANCODE_SEMICOLON;
849 KEY_COMMAND: result := SDL_SCANCODE_LGUI;
850 (*KEY_UNKNOWN1: result :=;*)
851 (*KEY_UNKNOWN2: result :=;*)
852 (*KEY_UNKNOWN3: result :=;*)
853 (*KEY_UNKNOWN4: result :=;*)
854 (*KEY_UNKNOWN5: result :=;*)
855 (*KEY_UNKNOWN6: result :=;*)
856 (*KEY_UNKNOWN7: result :=;*)
857 (*KEY_UNKNOWN8: result :=;*)
858 KEY_LSHIFT: result := SDL_SCANCODE_LSHIFT;
859 KEY_RSHIFT: result := SDL_SCANCODE_RSHIFT;
860 KEY_LCONTROL: result := SDL_SCANCODE_LCTRL;
861 KEY_RCONTROL: result := SDL_SCANCODE_RCTRL;
862 KEY_ALT: result := SDL_SCANCODE_LALT;
863 KEY_ALTGR: result := SDL_SCANCODE_RALT;
864 KEY_LWIN: result := SDL_SCANCODE_LGUI;
865 KEY_RWIN: result := SDL_SCANCODE_RGUI;
866 KEY_MENU: result := SDL_SCANCODE_MODE; (* ??? *)
867 KEY_SCRLOCK: result := SDL_SCANCODE_SCROLLLOCK;
868 KEY_NUMLOCK: result := SDL_SCANCODE_NUMLOCKCLEAR;
869 KEY_CAPSLOCK: result := SDL_SCANCODE_CAPSLOCK;
870 else result := SDL_SCANCODE_UNKNOWN
871 end
872 end;
874 function SDL_PollEvent(event: PSDL_Event): SInt32;
875 var alscan: Integer;
876 begin
877 e_LogWriteln('SDL_PollEvent');
878 poll_keyboard;
879 result := 0;
880 if not IsEmptyKeyboard then
881 begin
882 alscan := NextScancode;
883 if alscan and $80 = 0 then
884 event.type_ := SDL_KEYDOWN
885 else
886 event.type_ := SDL_KEYDOWN;
887 event.key.timestamp := 0;
888 event.key.windowID := 0;
889 (* df not use it?
890 if alscan and $80 = 0 then
891 event.key.state := SDL_PRESSED
892 else
893 event.key.state := SDL_RELEASED;
894 *)
895 event.key.keysym.scancode := allegro_to_sdl_scancode(alscan);
896 event.key.keysym.sym := 0; (* df not use it? *)
897 event.key.keysym._mod := 0; (* df not use it? *)
898 result := 1
899 end
900 end;
902 (********** MOUSE **********)
904 function SDL_ShowCursor(toggle: SInt32): SInt32;
905 begin
906 e_LogWritefln('SDL_ShowCursor %s', [toggle]);
907 result := 0
908 end;
910 (********** SDL **********)
912 function SDL_SetHint( const name: PChar; const value: PChar) : boolean;
913 begin
914 e_LogWritefln('SDL_SetHint %s %s', [name, value]);
915 result := false
916 end;
918 function SDL_GetError: PAnsiChar;
919 begin
920 e_LogWritefln('SDL_GetError => %s', [allegro_error]);
921 result := allegro_error;
922 end;
924 function TestGet: AnsiString;
925 begin
926 result := '+++ Test concat qwertyiop!'
927 end;
929 procedure Test;
930 begin
931 // WTF? when 'Test concat qwertyio! ' it not messed!
932 //e_LogWriteln('Test concat qwertyiop! ' + ParamStr(0));
933 e_LogWriteln('Test concat qwertyiop! ' + TestGet);
934 end;
936 function SDL_Init(flags: UInt32): SInt32;
937 begin
938 Test;
939 e_LogWritefln('SDL_Init %u', [flags]);
940 result := -1;
941 __crt0_argv := @myargv[0];
942 myargv[0] := PChar(ParamStr(0));
943 e_LogWritefln('argv[0] = %s', [myargv[0]]);
944 if allegro_init = 0 then
945 begin
946 e_LogWriteln('SDL_Init inited! ' + ParamStr(0) + ' ');
947 install_timer;
948 install_keyboard;
949 keyboard_lowlevel_callback := KeyboardWatcher;
950 set_keyboard_rate(0, 0);
951 result := 0
952 end
953 end;
955 procedure SDL_Quit;
956 begin
957 e_LogWriteln('SDL_Quit');
958 remove_keyboard;
959 remove_timer;
960 allegro_exit
961 end;