DEADSOFTWARE

more implemented functions for allegro port
[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] 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 __crt0_argv: PPchar; cvar; external;
379 myargv: array [0..255] of Pchar;
380 keyring: array [0..maxKeyBuffer - 1] of Integer;
381 keybeg, keyend: Integer;
383 ticks: UInt32; (* !!! VOLATILE !!! *)
385 function IsEmptyKeyboard: Boolean;
386 begin
387 result := keybeg = keyend
388 end;
390 function IsFullKeyboard: Boolean;
391 begin
392 result := (keybeg - 1) mod maxKeyBuffer = keyend
393 end;
395 function NextScancode: Integer;
396 begin
397 result := 0;
398 if not IsEmptyKeyboard then
399 begin
400 result := keyring[keybeg];
401 keybeg := (keybeg + 1) mod maxKeyBuffer
402 end
403 end;
405 procedure KeyboardWatcher (scancode: Integer); cdecl;
406 begin
407 if (keybeg - 1) mod maxKeyBuffer <> keyend then (* not IsFullKeyboard *)
408 begin
409 keyring[keyend] := scancode;
410 keyend := (keyend + 1) mod maxKeyBuffer
411 end
412 end;
413 procedure KeyboardWatcherEND;
414 begin
415 end;
417 /// MACRO ///
419 //from "sdl_pixels.h"
421 function SDL_PIXELFLAG(X: Cardinal): Cardinal;
422 begin
423 Result := (X shr 28) and $0F;
424 end;
426 function SDL_PIXELTYPE(X: Cardinal): Cardinal;
427 begin
428 Result := (X shr 24) and $0F;
429 end;
431 function SDL_PIXELORDER(X: Cardinal): Cardinal;
432 begin
433 Result := (X shr 20) and $0F;
434 end;
436 function SDL_PIXELLAYOUT(X: Cardinal): Cardinal;
437 begin
438 Result := (X shr 16) and $0F;
439 end;
441 function SDL_BITSPERPIXEL(X: Cardinal): Cardinal;
442 begin
443 Result := (X shr 8) and $FF;
444 end;
446 function SDL_IsPixelFormat_FOURCC(format: Variant): Boolean;
447 begin
448 Result := format and SDL_PIXELFLAG(format) <> 1;
449 end;
451 /// FUNCTIONS ////
453 (********** FILES **********)
455 function SDL_RWFromFile(const _file: PAnsiChar; const mode: PAnsiChar): PSDL_RWops;
456 begin
457 result := nil
458 end;
460 function SDL_RWFromConstMem(const mem: Pointer; size: SInt32): PSDL_RWops;
461 begin
462 result := nil
463 end;
465 (********** KEYBOARD **********)
467 function SDL_GetScancodeName(scancode: TSDL_ScanCode): PAnsiChar;
468 begin
469 result := ''
470 end;
472 function SDL_IsTextInputActive: TSDL_Bool;
473 begin
474 result := SDL_FALSE
475 end;
477 procedure SDL_StartTextInput;
478 begin
479 end;
481 procedure SDL_StopTextInput;
482 begin
483 end;
485 (********** JOYSTICK **********)
487 function SDL_NumJoysticks: SInt32;
488 begin
489 result := 0
490 end;
492 function SDL_JoystickOpen(device_index: SInt32): PSDL_Joystick;
493 begin
494 result := nil
495 end;
497 function SDL_JoystickName(joystick: PSDL_Joystick): PAnsiChar;
498 begin
499 result := ''
500 end;
502 function SDL_JoystickNumAxes(joystick: PSDL_Joystick): SInt32;
503 begin
504 result := 0
505 end;
507 function SDL_JoystickNumButtons(joystick: PSDL_Joystick): SInt32;
508 begin
509 result := 0
510 end;
512 function SDL_JoystickNumHats(joystick: PSDL_Joystick): SInt32;
513 begin
514 result := 0
515 end;
517 procedure SDL_JoystickClose(joystick: PSDL_Joystick);
518 begin
519 end;
521 procedure SDL_JoystickUpdate;
522 begin
523 end;
525 function SDL_JoystickGetButton(joystick: PSDL_Joystick; button: SInt32): UInt8;
526 begin
527 result := 0
528 end;
530 function SDL_JoystickGetAxis(joystick: PSDL_Joystick; axis: SInt32): SInt16;
531 begin
532 result := 0
533 end;
535 function SDL_JoystickGetHat(joystick: PSDL_Joystick; hat: SInt32): UInt8;
536 begin
537 result := 0
538 end;
540 (********** TOUCH **********)
542 function SDL_GetNumTouchDevices: SInt32;
543 begin
544 result := 0
545 end;
547 (********** TIMERS **********)
549 procedure AllegroTimerCallback; cdecl;
550 begin
551 inc(ticks)
552 end;
553 procedure AllegroTimerCallbackEND;
554 begin
555 end;
559 function SDL_GetPerformanceCounter: UInt64;
560 begin
561 //e_LogWriteln('SDL_GetPerformanceCounter');
562 result := ticks;
563 end;
565 function SDL_GetPerformanceFrequency: UInt64;
566 begin
567 //e_LogWriteln('SDL_GetPerformanceFrequency');
568 result := 1
569 end;
571 procedure SDL_Delay(ms: UInt32);
572 begin
573 //e_LogWriteln('SDL_Delay');
574 //rest(ms)
575 end;
577 function SDL_GetTicks: UInt32;
578 begin
579 //e_LogWriteln('SDL_GetTicks');
580 result := ticks;
581 end;
583 (********** DISPLAY MODES **********)
585 function SDL_GetDesktopDisplayMode(displayIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
586 begin
587 e_LogWritefln('SDL_GetDesktopDisplayMode %s', [displayIndex]);
588 result := -1;
589 mode.format := SDL_PIXELFORMAT_UNKNOWN; (* FIXIT *)
590 mode.refresh_rate := 0;
591 mode.driverdata := nil;
592 if get_desktop_resolution(@mode.w, @mode.h) = 0 then
593 result := 0
594 end;
596 function SDL_GetClosestDisplayMode(displayIndex: SInt32; const mode: PSDL_DisplayMode; closest: PSDL_DisplayMode): PSDL_DisplayMode;
597 begin
598 e_LogWritefln('SDL_GetClosestDisplayMode %s', [displayIndex]);
599 result := nil;
600 end;
602 function SDL_GetNumDisplayModes(displayIndex: SInt32): SInt32;
603 var m: PGFX_MODE_LIST;
604 begin
605 e_LogWritefln('SDL_GetNumDisplayModes %s', [displayIndex]);
606 result := -1;
607 m := get_gfx_mode_list(GFX_AUTODETECT);
608 if m <> nil then
609 begin
610 result := m.num_modes;
611 destroy_gfx_mode_list(m);
612 end
613 end;
615 function SDL_GetDisplayMode(displayIndex: SInt32; modeIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
616 var m: PGFX_MODE_LIST;
617 begin
618 e_LogWritefln('SDL_GetDisplayMode %s %s', [displayIndex, modeIndex]);
619 result := -1;
620 m := get_gfx_mode_list(GFX_AUTODETECT);
621 if (m <> nil) and (modeIndex >= 0) and (modeIndex < m.num_modes) then
622 begin
623 mode.format := SDL_PIXELFORMAT_UNKNOWN; (* FIX IT *)
624 mode.w := m.mode[modeIndex].width;
625 mode.h := m.mode[modeIndex].height;
626 mode.refresh_rate := 0;
627 mode.driverdata := nil;
628 destroy_gfx_mode_list(m);
629 result := 0
630 end
631 end;
633 function SDL_GetDisplayDPI(displayIndex: SInt32; ddpi, hdpi, vdpi: PFloat): SInt32;
634 begin
635 result := -1
636 end;
638 (*********** WINDOW MANAGEMENT **********)
640 function SDL_CreateWindow(const title: PAnsiChar; x: SInt32; y: SInt32; w: SInt32; h: SInt32; flags: UInt32): PSDL_Window;
641 var window: PSDL_Window; mode: Integer;
642 begin
643 e_LogWritefln('SDL_CreateWindow %s %s %s %s %s %u', [title, x, y, w, h, flags]);
644 result := nil;
646 {$IF DEFINED(AL_TEXT)}
647 mode := GFX_TEXT;
648 w := 0; h := 0;
649 {$ELSEIF DEFINED(GO32V2)}
650 mode := GFX_AUTODETECT;
651 {$ELSE}
652 if (flags and (SDL_WINDOW_FULLSCREEN or SDL_WINDOW_FULLSCREEN_DESKTOP)) <> 0 then
653 mode := GFX_AUTODETECT_FULLSCREEN
654 else
655 mode := GFX_AUTODETECT_WINDOWED;
656 {$ENDIF}
658 set_color_depth(DEFAULT_DEPTH);
659 if set_gfx_mode(mode, w, h, 0, 0) = 0 then
660 begin
661 new(window);
662 {$IF NOT DEFINED(AL_TEXT)}
663 set_window_title(title);
664 if sdl2allegro_screen <> nil then
665 destroy_bitmap(sdl2allegro_screen);
666 //sdl2allegro_screen := create_video_bitmap(w, h);
667 //if sdl2allegro_screen = nil then
668 sdl2allegro_screen := create_system_bitmap(w, h);
669 if sdl2allegro_screen = nil then
670 sdl2allegro_screen := create_bitmap(w, h);
671 ASSERT(sdl2allegro_screen <> nil);
672 {$ENDIF}
673 window.w := w;
674 window.h := h;
675 window.mode := mode;
676 result := window
677 end
678 end;
680 function SDL_SetWindowFullscreen(window: PSDL_Window; flags: UInt32): SInt32;
681 var mode: Integer;
682 begin
683 e_LogWritefln('SDL_SetWindowFullscreen %u', [flags]);
684 result := -1;
685 if window = nil then exit;
687 {$IF DEFINED(AL_TEXT)}
688 mode := GFX_TEXT;
689 window.w := 0; window.h := 0;
690 {$ELSEIF DEFINED(GO32V2)}
691 mode := GFX_AUTODETECT;
692 {$ELSE}
693 if (flags and (SDL_WINDOW_FULLSCREEN or SDL_WINDOW_FULLSCREEN_DESKTOP)) <> 0 then
694 mode := GFX_AUTODETECT_FULLSCREEN
695 else
696 mode := GFX_AUTODETECT_WINDOWED;
697 {$ENDIF}
699 set_color_depth(DEFAULT_DEPTH);
700 if set_gfx_mode(mode, window.w, window.h, 0, 0) = 0 then
701 begin
702 {$IF NOT DEFINED(AL_TEXT)}
703 (*
704 if sdl2allegro_screen <> nil then
705 destroy_bitmap(sdl2allegro_screen);
706 *)
707 //sdl2allegro_screen := create_video_bitmap(window.w, window.h);
708 //if sdl2allegro_screen = nil then
709 sdl2allegro_screen := create_system_bitmap(window.w, window.h);
710 if sdl2allegro_screen = nil then
711 sdl2allegro_screen := create_bitmap(window.w, window.h);
712 ASSERT(sdl2allegro_screen <> nil);
713 set_palette(desktop_palette);
714 {$ENDIF}
715 window.mode := mode;
716 result := 0
717 end
718 end;
720 procedure SDL_SetWindowSize(window: PSDL_Window; w: SInt32; h: SInt32);
721 begin
722 e_LogWritefln('SDL_SetWindowSize %s %s', [w, h]);
723 if window = nil then exit;
724 {$IF DEFINED(AL_TEXT)}
725 window.mode := GFX_TEXT;
726 w := 0; h := 0;
727 {$ENDIF}
728 set_color_depth(DEFAULT_DEPTH);
729 if set_gfx_mode(window.mode, w, h, 0, 0) = 0 then
730 begin
731 {$IF NOT DEFINED(AL_TEXT)}
732 if sdl2allegro_screen <> nil then
733 destroy_bitmap(sdl2allegro_screen);
734 //sdl2allegro_screen := create_video_bitmap(w, h);
735 //if sdl2allegro_screen = nil then
736 sdl2allegro_screen := create_system_bitmap(w, h);
737 if sdl2allegro_screen = nil then
738 sdl2allegro_screen := create_bitmap(w, h);
739 ASSERT(sdl2allegro_screen <> nil);
740 set_palette(desktop_palette);
741 {$ENDIF}
742 window.w := w;
743 window.h := h;
744 end
745 end;
747 procedure SDL_DestroyWindow(window: PSDL_Window);
748 begin
749 e_LogWriteln('SDL_DestroyWindow');
750 if window = nil then exit;
751 if sdl2allegro_screen <> nil then
752 destroy_bitmap(sdl2allegro_screen);
753 sdl2allegro_screen := nil;
754 dispose(window)
755 end;
757 procedure SDL_GetWindowSize(window: PSDL_Window; w: PInt; h: PInt);
758 begin
759 e_LogWriteln('SDL_GetWindowSize');
760 if window = nil then exit;
761 if w <> nil then
762 w^ := window.w;
763 if h <> nil then
764 h^ := window.h;
765 end;
767 procedure SDL_RestoreWindow(window: PSDL_Window);
768 begin
769 e_LogWriteln('SDL_RestoreWindow');
770 if window = nil then exit;
771 (* stub *)
772 end;
774 function SDL_SetWindowGammaRamp(window: PSDL_Window; const red: PUInt16; const green: PUInt16; const blue: PUInt16): SInt32;
775 begin
776 e_LogWriteln('SDL_SetWindowGammaRamp');
777 result := -1;
778 if window = nil then exit;
779 result := 0
780 end;
782 function SDL_GetWindowGammaRamp(window: PSDL_Window; red: PUInt16; green: PUInt16; blue: PUInt16): SInt32;
783 begin
784 e_LogWriteln('SDL_GetWindowGammaRamp');
785 result := -1;
786 if window = nil then exit;
787 result := 0
788 end;
790 (********** OPENGL MANAGEMENT **********)
792 function SDL_GL_MakeCurrent(window: PSDL_Window; context: TSDL_GLContext): SInt32;
793 begin
794 e_LogWriteln('SDL_GL_MakeCurrent');
795 result := 0
796 end;
798 procedure SDL_GL_DeleteContext(context: TSDL_GLContext);
799 begin
800 e_LogWriteln('SDL_GL_DeleteContext');
801 end;
803 procedure SDL_GL_SwapWindow(window: PSDL_Window);
804 var res: cint;
805 begin
806 //e_LogWriteln('SDL_GL_SwapWindow');
807 {$IF NOT DEFINED(AL_TEXT)}
808 ASSERT(sdl2allegro_screen <> nil);
809 blit(sdl2allegro_screen, screen, 0, 0, 0, 0, sdl2allegro_screen.w, sdl2allegro_screen.h);
810 res := show_video_bitmap(screen);
811 //ASSERT(res = 0);
812 {$ENDIF}
813 end;
815 function SDL_GL_CreateContext(window: PSDL_Window): TSDL_GLContext;
816 begin
817 e_LogWriteln('SDL_GL_CreateContext');
818 result := window
819 end;
821 function SDL_GL_SetSwapInterval(interval: SInt32): SInt32;
822 begin
823 e_LogWritefln('SDL_GL_SetSwapInterval %s', [interval]);
824 result := 0
825 end;
827 function SDL_GL_SetAttribute(attr: TSDL_GLattr; value: SInt32): SInt32;
828 begin
829 e_LogWritefln('SDL_GL_SetAttribute %s %s', [attr, value]);
830 result := -1;
831 end;
833 function SDL_GL_GetAttribute(attr: TSDL_GLattr; value: PInt): SInt32;
834 begin
835 e_LogWritefln('SDL_GL_GetAttribute %s', [attr]);
836 value^ := 0; result := -1
837 end;
839 (********** EVENTS **********)
841 function SDL_PushEvent(event: PSDL_Event): SInt32;
842 begin
843 e_LogWriteln('SDL_PushEvent');
844 result := 0
845 end;
847 function allegro_to_sdl_scancode (x: Integer): Integer;
848 begin
849 x := x and $7F;
850 case x of
851 KEY_A..KEY_Z: result := SDL_SCANCODE_A + (x - KEY_A);
852 KEY_0..KEY_0: result := SDL_SCANCODE_0 + (x - KEY_0);
853 KEY_0_PAD: result := SDL_SCANCODE_KP_0;
854 KEY_1_PAD..KEY_9_PAD: result := SDL_SCANCODE_KP_1 + (x - KEY_1_PAD);
855 KEY_F1..KEY_F12: result := SDL_SCANCODE_F1 + (x - KEY_F1);
856 KEY_ESC: result := SDL_SCANCODE_ESCAPE;
857 KEY_TILDE: result := SDL_SCANCODE_GRAVE;
858 KEY_MINUS: result := SDL_SCANCODE_MINUS;
859 KEY_EQUALS: result := SDL_SCANCODE_EQUALS;
860 KEY_BACKSPACE: result := SDL_SCANCODE_BACKSPACE;
861 KEY_TAB: result := SDL_SCANCODE_TAB;
862 KEY_OPENBRACE: result := SDL_SCANCODE_LEFTBRACKET;
863 KEY_CLOSEBRACE: result := SDL_SCANCODE_RIGHTBRACKET;
864 KEY_ENTER: result := SDL_SCANCODE_RETURN;
865 KEY_COLON: result := SDL_SCANCODE_SEMICOLON;
866 KEY_QUOTE: result := SDL_SCANCODE_APOSTROPHE;
867 KEY_BACKSLASH: result := SDL_SCANCODE_BACKSLASH;
868 KEY_BACKSLASH2: result := SDL_SCANCODE_NONUSHASH; (* ??? *)
869 KEY_COMMA: result := SDL_SCANCODE_COMMA;
870 (*KEY_STOP: result :=;*) (* ??? *)
871 KEY_SLASH: result := SDL_SCANCODE_SLASH;
872 KEY_SPACE: result := SDL_SCANCODE_SPACE;
873 KEY_INSERT: result := SDL_SCANCODE_INSERT;
874 KEY_DEL: result := SDL_SCANCODE_DELETE;
875 KEY_HOME: result := SDL_SCANCODE_HOME;
876 KEY_END: result := SDL_SCANCODE_END;
877 KEY_PGUP: result := SDL_SCANCODE_PAGEUP;
878 KEY_PGDN: result := SDL_SCANCODE_PAGEDOWN;
879 KEY_LEFT: result := SDL_SCANCODE_LEFT;
880 KEY_RIGHT: result := SDL_SCANCODE_RIGHT;
881 KEY_UP: result := SDL_SCANCODE_UP;
882 KEY_DOWN: result := SDL_SCANCODE_DOWN;
883 KEY_SLASH_PAD: result := SDL_SCANCODE_KP_DIVIDE;
884 KEY_ASTERISK: result := SDL_SCANCODE_KP_MULTIPLY;
885 KEY_MINUS_PAD: result := SDL_SCANCODE_KP_MINUS;
886 KEY_PLUS_PAD: result := SDL_SCANCODE_KP_PLUS;
887 KEY_DEL_PAD: result := SDL_SCANCODE_KP_PERIOD;
888 KEY_ENTER_PAD: result := SDL_SCANCODE_KP_ENTER;
889 KEY_PRTSCR: result := SDL_SCANCODE_PRINTSCREEN;
890 KEY_PAUSE: result := SDL_SCANCODE_PAUSE;
891 (*KEY_ABNT_C1: result :=;*) (* ??? *)
892 KEY_YEN: result := SDL_SCANCODE_INTERNATIONAL3;
893 KEY_KANA: result := SDL_SCANCODE_LANG3; (* ??? *)
894 (*KEY_CONVERT: result :=;*) (* ??? *)
895 (*KEY_NOCONVERT: result := ;*) (* ??? *)
896 KEY_AT: result := SDL_SCANCODE_KP_AT;
897 (*KEY_CIRCUMFLEX: result :=;*) (* ??? *)
898 KEY_COLON2: result := SDL_SCANCODE_KP_COLON;
899 (*KEY_KANJI: result :=;*) (* ??? *)
900 KEY_EQUALS_PAD: result := SDL_SCANCODE_KP_EQUALS;
901 (*KEY_BACKQUOTE: result :=;*) (* ??? *)
902 KEY_SEMICOLON: result := SDL_SCANCODE_SEMICOLON;
903 KEY_COMMAND: result := SDL_SCANCODE_LGUI;
904 (*KEY_UNKNOWN1: result :=;*)
905 (*KEY_UNKNOWN2: result :=;*)
906 (*KEY_UNKNOWN3: result :=;*)
907 (*KEY_UNKNOWN4: result :=;*)
908 (*KEY_UNKNOWN5: result :=;*)
909 (*KEY_UNKNOWN6: result :=;*)
910 (*KEY_UNKNOWN7: result :=;*)
911 (*KEY_UNKNOWN8: result :=;*)
912 KEY_LSHIFT: result := SDL_SCANCODE_LSHIFT;
913 KEY_RSHIFT: result := SDL_SCANCODE_RSHIFT;
914 KEY_LCONTROL: result := SDL_SCANCODE_LCTRL;
915 KEY_RCONTROL: result := SDL_SCANCODE_RCTRL;
916 KEY_ALT: result := SDL_SCANCODE_LALT;
917 KEY_ALTGR: result := SDL_SCANCODE_RALT;
918 KEY_LWIN: result := SDL_SCANCODE_LGUI;
919 KEY_RWIN: result := SDL_SCANCODE_RGUI;
920 KEY_MENU: result := SDL_SCANCODE_MODE; (* ??? *)
921 KEY_SCRLOCK: result := SDL_SCANCODE_SCROLLLOCK;
922 KEY_NUMLOCK: result := SDL_SCANCODE_NUMLOCKCLEAR;
923 KEY_CAPSLOCK: result := SDL_SCANCODE_CAPSLOCK;
924 else result := SDL_SCANCODE_UNKNOWN
925 end
926 end;
928 function SDL_PollEvent(event: PSDL_Event): SInt32;
929 var alscan: Integer;
930 begin
931 //e_LogWriteln('SDL_PollEvent');
932 poll_keyboard;
933 result := 0;
934 if not IsEmptyKeyboard then
935 begin
936 alscan := NextScancode;
937 if alscan and $80 = 0 then
938 event.type_ := SDL_KEYDOWN
939 else
940 event.type_ := SDL_KEYUP;
941 event.key.timestamp := 0;
942 event.key.windowID := 0;
943 (* df not use it?
944 if alscan and $80 = 0 then
945 event.key.state := SDL_PRESSED
946 else
947 event.key.state := SDL_RELEASED;
948 *)
949 event.key.keysym.scancode := allegro_to_sdl_scancode(alscan);
950 event.key.keysym.sym := 0; (* df not use it? *)
951 event.key.keysym._mod := 0; (* df not use it? *)
952 result := 1
953 end
954 end;
956 (********** MOUSE **********)
958 function SDL_ShowCursor(toggle: SInt32): SInt32;
959 begin
960 e_LogWritefln('SDL_ShowCursor %s', [toggle]);
961 result := 0
962 end;
964 (********** SDL **********)
966 function SDL_SetHint( const name: PChar; const value: PChar) : boolean;
967 begin
968 e_LogWritefln('SDL_SetHint %s %s', [name, value]);
969 result := false
970 end;
972 function SDL_GetError: PAnsiChar;
973 begin
974 e_LogWritefln('SDL_GetError => %s', [allegro_error]);
975 result := allegro_error;
976 end;
978 function SDL_Init(flags: UInt32): SInt32;
979 begin
980 e_LogWritefln('SDL_Init %u', [flags]);
981 result := -1;
982 __crt0_argv := @myargv[0];
983 myargv[0] := PChar(ParamStr(0));
984 e_LogWritefln('argv[0] = %s', [myargv[0]]);
985 if allegro_init = 0 then
986 begin
987 e_LogWriteln('SDL_Init inited! ' + ParamStr(0) + ' tickssize=' + IntToStr(sizeof(keyring)) );
988 {$IFDEF GO32V2}
989 (* without this df dies with fire when swapped *)
990 lock_data(ticks, sizeof(ticks));
991 lock_code(@AllegroTimerCallback, PtrUInt(@AllegroTimerCallbackEND) - PtrUInt(@AllegroTimerCallback));
992 lock_data(keybeg, sizeof(keybeg));
993 lock_data(keyend, sizeof(keyend));
994 lock_data(keyring, sizeof(keyring));
995 lock_code(@KeyboardWatcher, PtrUInt(@KeyboardWatcherEND) - PtrUInt(@KeyboardWatcher));
996 {$ENDIF}
997 install_timer;
998 install_keyboard;
999 keyboard_lowlevel_callback := KeyboardWatcher;
1000 set_keyboard_rate(0, 0);
1001 install_int_ex(AllegroTimerCallback, MSEC_TO_TIMER(1));
1002 result := 0
1003 end
1004 end;
1006 procedure SDL_Quit;
1007 begin
1008 e_LogWriteln('SDL_Quit');
1009 remove_keyboard;
1010 remove_timer;
1011 {$IFDEF GO32V2}
1012 unlock_data(ticks, sizeof(ticks));
1013 unlock_code(@AllegroTimerCallback, PtrUInt(@AllegroTimerCallbackEND) - PtrUInt(@AllegroTimerCallback));
1014 unlock_data(keybeg, sizeof(keybeg));
1015 unlock_data(keyend, sizeof(keyend));
1016 unlock_data(keyring, sizeof(keyring));
1017 unlock_code(@KeyboardWatcher, PtrUInt(@KeyboardWatcherEND) - PtrUInt(@KeyboardWatcher));
1018 {$ENDIF}
1019 allegro_exit
1020 end;