DEADSOFTWARE

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