X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fwrappers%2Fsdl2%2Fsdl2allegro.inc;h=8cbe419a16d73813a96203b35997f09ea2cf4b9d;hb=23c3f9ee3fc3837cd1d0380496a2e1b0f87833d8;hp=ebedf9c02a85980f99b5b8e619959d3a6c257575;hpb=f2421615862d0a6c093c6fc3117849010d26557b;p=d2df-sdl.git diff --git a/src/wrappers/sdl2/sdl2allegro.inc b/src/wrappers/sdl2/sdl2allegro.inc index ebedf9c..8cbe419 100644 --- a/src/wrappers/sdl2/sdl2allegro.inc +++ b/src/wrappers/sdl2/sdl2allegro.inc @@ -9,9 +9,6 @@ interface {$I sdlpixels.inc} {$I sdlscancode.inc} - const - DEFAULT_DEPTH = 8; - const SDL_HAT_CENTERED = $00; SDL_HAT_UP = $01; @@ -205,7 +202,7 @@ interface type_: UInt32; // SDL_TEXTINPUT timestamp: UInt32; windowID: UInt32; // The window with keyboard focus, if any - text: array[0..SDL_TEXTINPUTEVENT_TEXT_SIZE] of Char; // The input text + text: array[0..SDL_TEXTINPUTEVENT_TEXT_SIZE - 1] of Char; // The input text end; TSDL_QuitEvent = record @@ -298,6 +295,7 @@ interface var sdl2allegro_screen: PBITMAP; + sdl2allegro_bpp: Integer; /// FUNCTIONS /// @@ -369,17 +367,172 @@ implementation {$IFDEF GO32V2} go32, {$ENDIF} - e_Log, SysUtils, ctypes; + e_Log, g_options, SysUtils, Math, ctypes; const maxKeyBuffer = 64; var + deskw, deskh, deskbpp: Integer; keyring: array [0..maxKeyBuffer - 1] of Integer; keybeg, keyend: Integer; + inputChar: Char; + inputText: Boolean; + useVsync: Boolean; ticks: UInt32; quit: Boolean; + s2lc: array [0..KEY_MAX] of char = ( + #00, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', + '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', #00, + #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, '`', '-', '=', #00, + #09, '[', ']', #10, ';', #39, '\', '\', ',', '.', '/', ' ', #00, #00, #00, #00, + #00, #00, #00, #00, #00, '/', '*', '-', '+', #00, #00, #00, #00, #00, #00, #00, + #00, #00, #00, #00, '@', #00, ':', #00, '=', #00, ';', #00, #00, #00, #00, #00, + #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00 + ); + s2uc: array [0..KEY_MAX] of char = ( + #00, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ')', '!', '@', '#', '$', + '%', '^', '&', '*', '(', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', #00, + #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, '~', '_', '+', #00, + #09, '{', '}', #10, ':', '"', '|', '|', '<', '>', '?', ' ', #00, #00, #00, #00, + #00, #00, #00, #00, #00, '/', '*', '-', '+', #00, #00, #00, #00, #00, #00, #00, + #00, #00, #00, #00, '@', #00, ':', #00, '=', #00, ';', #00, #00, #00, #00, #00, + #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00, #00 + ); + s2sa: array [0..KEY_MAX] of Integer = ( + SDL_SCANCODE_UNKNOWN, + SDL_SCANCODE_A, + SDL_SCANCODE_B, + SDL_SCANCODE_C, + SDL_SCANCODE_D, + SDL_SCANCODE_E, + SDL_SCANCODE_F, + SDL_SCANCODE_G, + SDL_SCANCODE_H, + SDL_SCANCODE_I, + SDL_SCANCODE_J, + SDL_SCANCODE_K, + SDL_SCANCODE_L, + SDL_SCANCODE_M, + SDL_SCANCODE_N, + SDL_SCANCODE_O, + SDL_SCANCODE_P, + SDL_SCANCODE_Q, + SDL_SCANCODE_R, + SDL_SCANCODE_S, + SDL_SCANCODE_T, + SDL_SCANCODE_U, + SDL_SCANCODE_V, + SDL_SCANCODE_W, + SDL_SCANCODE_X, + SDL_SCANCODE_Y, + SDL_SCANCODE_Z, + SDL_SCANCODE_0, + SDL_SCANCODE_1, + SDL_SCANCODE_2, + SDL_SCANCODE_3, + SDL_SCANCODE_4, + SDL_SCANCODE_5, + SDL_SCANCODE_6, + SDL_SCANCODE_7, + SDL_SCANCODE_8, + SDL_SCANCODE_9, + SDL_SCANCODE_KP_0, + SDL_SCANCODE_KP_1, + SDL_SCANCODE_KP_2, + SDL_SCANCODE_KP_3, + SDL_SCANCODE_KP_4, + SDL_SCANCODE_KP_5, + SDL_SCANCODE_KP_6, + SDL_SCANCODE_KP_7, + SDL_SCANCODE_KP_8, + SDL_SCANCODE_KP_9, + SDL_SCANCODE_F1, + SDL_SCANCODE_F2, + SDL_SCANCODE_F3, + SDL_SCANCODE_F4, + SDL_SCANCODE_F5, + SDL_SCANCODE_F6, + SDL_SCANCODE_F7, + SDL_SCANCODE_F8, + SDL_SCANCODE_F9, + SDL_SCANCODE_F10, + SDL_SCANCODE_F11, + SDL_SCANCODE_F12, + SDL_SCANCODE_ESCAPE, + SDL_SCANCODE_GRAVE, + SDL_SCANCODE_MINUS, + SDL_SCANCODE_EQUALS, + SDL_SCANCODE_BACKSPACE, + SDL_SCANCODE_TAB, + SDL_SCANCODE_LEFTBRACKET, + SDL_SCANCODE_RIGHTBRACKET, + SDL_SCANCODE_RETURN, + SDL_SCANCODE_SEMICOLON, + SDL_SCANCODE_APOSTROPHE, + SDL_SCANCODE_BACKSLASH, + SDL_SCANCODE_NONUSHASH, + SDL_SCANCODE_COMMA, + SDL_SCANCODE_UNKNOWN, (* !!! KEY_STOP *) + SDL_SCANCODE_SLASH, + SDL_SCANCODE_SPACE, + SDL_SCANCODE_INSERT, + SDL_SCANCODE_DELETE, + SDL_SCANCODE_HOME, + SDL_SCANCODE_END, + SDL_SCANCODE_PAGEUP, + SDL_SCANCODE_PAGEDOWN, + SDL_SCANCODE_LEFT, + SDL_SCANCODE_RIGHT, + SDL_SCANCODE_UP, + SDL_SCANCODE_DOWN, + SDL_SCANCODE_KP_DIVIDE, + SDL_SCANCODE_KP_MULTIPLY, + SDL_SCANCODE_KP_MINUS, + SDL_SCANCODE_KP_PLUS, + SDL_SCANCODE_KP_PERIOD, + SDL_SCANCODE_KP_ENTER, + SDL_SCANCODE_PRINTSCREEN, + SDL_SCANCODE_PAUSE, + SDL_SCANCODE_UNKNOWN, (* !!! KEY_ABNT_C1 *) + SDL_SCANCODE_INTERNATIONAL3, (* ??? KEY_YEN *) + SDL_SCANCODE_LANG3, (* ??? KEY_KANA *) + SDL_SCANCODE_UNKNOWN, (* !!! KEY_CONVERT *) + SDL_SCANCODE_UNKNOWN, (* !!! KEY_NOCONVERT *) + SDL_SCANCODE_KP_AT, + SDL_SCANCODE_UNKNOWN, (* !!! KEY_CIRCUMFLEX *) + SDL_SCANCODE_KP_COLON, + SDL_SCANCODE_UNKNOWN, (* !!! KEY_KANJI *) + SDL_SCANCODE_KP_EQUALS, + SDL_SCANCODE_UNKNOWN, (* !!! KEY_BACKQUOTE *) + SDL_SCANCODE_SEMICOLON, + SDL_SCANCODE_LGUI, + SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN1 *) + SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN2 *) + SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN3 *) + SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN4 *) + SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN5 *) + SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN6 *) + SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN7 *) + SDL_SCANCODE_UNKNOWN, (* !!! KEY_UNKNOWN8 *) + SDL_SCANCODE_LSHIFT, + SDL_SCANCODE_RSHIFT, + SDL_SCANCODE_LCTRL, + SDL_SCANCODE_RCTRL, + SDL_SCANCODE_LALT, + SDL_SCANCODE_RALT, + SDL_SCANCODE_LGUI, + SDL_SCANCODE_RGUI, + SDL_SCANCODE_MODE, (* ??? KEY_MENU *) + SDL_SCANCODE_SCROLLLOCK, + SDL_SCANCODE_NUMLOCKCLEAR, + SDL_SCANCODE_CAPSLOCK, + SDL_SCANCODE_UNKNOWN (* KEY_MAX *) + ); + function IsEmptyKeyboard: Boolean; begin result := keybeg = keyend @@ -448,32 +601,164 @@ implementation function SDL_RWFromFile(const _file: PAnsiChar; const mode: PAnsiChar): PSDL_RWops; begin - result := nil + result := nil (* stub, used for sdl2stub_mixer *) end; function SDL_RWFromConstMem(const mem: Pointer; size: SInt32): PSDL_RWops; begin - result := nil + result := nil (* stub, used for sdl2stub_mixer *) end; (********** KEYBOARD **********) function SDL_GetScancodeName(scancode: TSDL_ScanCode): PAnsiChar; begin - result := '' + case scancode of + SDL_SCANCODE_A: result := 'A'; + SDL_SCANCODE_B: result := 'B'; + SDL_SCANCODE_C: result := 'C'; + SDL_SCANCODE_D: result := 'D'; + SDL_SCANCODE_E: result := 'E'; + SDL_SCANCODE_F: result := 'F'; + SDL_SCANCODE_G: result := 'G'; + SDL_SCANCODE_H: result := 'H'; + SDL_SCANCODE_I: result := 'I'; + SDL_SCANCODE_J: result := 'J'; + SDL_SCANCODE_K: result := 'K'; + SDL_SCANCODE_L: result := 'L'; + SDL_SCANCODE_M: result := 'M'; + SDL_SCANCODE_N: result := 'N'; + SDL_SCANCODE_O: result := 'O'; + SDL_SCANCODE_P: result := 'P'; + SDL_SCANCODE_Q: result := 'Q'; + SDL_SCANCODE_R: result := 'R'; + SDL_SCANCODE_S: result := 'S'; + SDL_SCANCODE_T: result := 'T'; + SDL_SCANCODE_U: result := 'U'; + SDL_SCANCODE_V: result := 'V'; + SDL_SCANCODE_W: result := 'W'; + SDL_SCANCODE_X: result := 'X'; + SDL_SCANCODE_Y: result := 'Y'; + SDL_SCANCODE_Z: result := 'Z'; + SDL_SCANCODE_0: result := '0'; + SDL_SCANCODE_1: result := '1'; + SDL_SCANCODE_2: result := '2'; + SDL_SCANCODE_3: result := '3'; + SDL_SCANCODE_4: result := '4'; + SDL_SCANCODE_5: result := '5'; + SDL_SCANCODE_6: result := '6'; + SDL_SCANCODE_7: result := '7'; + SDL_SCANCODE_8: result := '8'; + SDL_SCANCODE_9: result := '9'; + SDL_SCANCODE_RETURN: result := 'Return'; + SDL_SCANCODE_ESCAPE: result := 'Escape'; + SDL_SCANCODE_BACKSPACE: result := 'Backspace'; + SDL_SCANCODE_TAB: result := 'Tab'; + SDL_SCANCODE_SPACE: result := 'Space'; + SDL_SCANCODE_MINUS: result := '-'; + SDL_SCANCODE_EQUALS: result := '='; + SDL_SCANCODE_LEFTBRACKET: result := '['; + SDL_SCANCODE_RIGHTBRACKET: result := ']'; + SDL_SCANCODE_BACKSLASH: result := '\'; + SDL_SCANCODE_SEMICOLON: result := ';'; + SDL_SCANCODE_APOSTROPHE: result := ''''; + SDL_SCANCODE_GRAVE: result := '`'; + SDL_SCANCODE_COMMA: result := ','; + SDL_SCANCODE_PERIOD: result := '.'; + SDL_SCANCODE_SLASH: result := '/'; + SDL_SCANCODE_CAPSLOCK: result := 'CapsLock'; + SDL_SCANCODE_F1: result := 'F1'; + SDL_SCANCODE_F2: result := 'F2'; + SDL_SCANCODE_F3: result := 'F3'; + SDL_SCANCODE_F4: result := 'F4'; + SDL_SCANCODE_F5: result := 'F5'; + SDL_SCANCODE_F6: result := 'F6'; + SDL_SCANCODE_F7: result := 'F7'; + SDL_SCANCODE_F8: result := 'F8'; + SDL_SCANCODE_F9: result := 'F9'; + SDL_SCANCODE_F10: result := 'F10'; + SDL_SCANCODE_F11: result := 'F11'; + SDL_SCANCODE_F12: result := 'F12'; + SDL_SCANCODE_PRINTSCREEN: result := 'PrintScreen'; + SDL_SCANCODE_SCROLLLOCK: result := 'ScrollLock'; + SDL_SCANCODE_PAUSE: result := 'Pause'; + SDL_SCANCODE_INSERT: result := 'Insert'; + SDL_SCANCODE_HOME: result := 'Home'; + SDL_SCANCODE_PAGEUP: result := 'PageUp'; + SDL_SCANCODE_DELETE: result := 'Delete'; + SDL_SCANCODE_END: result := 'End'; + SDL_SCANCODE_PAGEDOWN: result := 'PageDown'; + SDL_SCANCODE_RIGHT: result := 'Right'; + SDL_SCANCODE_LEFT: result := 'Left'; + SDL_SCANCODE_DOWN: result := 'Down'; + SDL_SCANCODE_UP: result := 'Up'; + SDL_SCANCODE_NUMLOCKCLEAR: result := 'Numlock'; + SDL_SCANCODE_KP_DIVIDE: result := 'Keypad /'; + SDL_SCANCODE_KP_MULTIPLY: result := 'Keypad *'; + SDL_SCANCODE_KP_MINUS: result := 'Keypad -'; + SDL_SCANCODE_KP_PLUS: result := 'Keypad +'; + SDL_SCANCODE_KP_ENTER: result := 'Keypad Enter'; + SDL_SCANCODE_KP_1: result := 'Keypad 1'; + SDL_SCANCODE_KP_2: result := 'Keypad 2'; + SDL_SCANCODE_KP_3: result := 'Keypad 3'; + SDL_SCANCODE_KP_4: result := 'Keypad 4'; + SDL_SCANCODE_KP_5: result := 'Keypad 5'; + SDL_SCANCODE_KP_6: result := 'Keypad 6'; + SDL_SCANCODE_KP_7: result := 'Keypad 7'; + SDL_SCANCODE_KP_8: result := 'Keypad 8'; + SDL_SCANCODE_KP_9: result := 'Keypad 9'; + SDL_SCANCODE_KP_0: result := 'Keypad 0'; + SDL_SCANCODE_KP_PERIOD: result := 'Keypad .'; + SDL_SCANCODE_APPLICATION: result := 'Application'; + SDL_SCANCODE_POWER: result := 'Power'; + SDL_SCANCODE_KP_EQUALS: result := 'Keypad ='; + (* !!! F1x/F2x and multimedia ... *) + SDL_SCANCODE_KP_COMMA: result := 'Keypad ,'; + SDL_SCANCODE_KP_EQUALSAS400: result := 'Keypad = (AS400)'; + SDL_SCANCODE_ALTERASE: result := 'AltErase'; + SDL_SCANCODE_SYSREQ: result := 'SysReq'; + SDL_SCANCODE_CANCEL: result := 'Cancel'; + SDL_SCANCODE_CLEAR: result := 'Clear'; + SDL_SCANCODE_PRIOR: result := 'Prior'; + SDL_SCANCODE_RETURN2: result := 'Return'; + SDL_SCANCODE_SEPARATOR: result := 'Separator'; + SDL_SCANCODE_OUT: result := 'Out'; + SDL_SCANCODE_OPER: result := 'Oper'; + SDL_SCANCODE_CLEARAGAIN: result := 'Clear / Again'; + SDL_SCANCODE_CRSEL: result := 'CrSel'; + SDL_SCANCODE_EXSEL: result := 'ExSel'; + (* !!! Additional KP *) + SDL_SCANCODE_LCTRL: result := 'Left Ctrl'; + SDL_SCANCODE_LSHIFT: result := 'Left Shift'; + SDL_SCANCODE_LALT: result := 'Left Alt'; + SDL_SCANCODE_LGUI: result := 'Left GUI'; + SDL_SCANCODE_RCTRL: result := 'Right Ctrl'; + SDL_SCANCODE_RSHIFT: result := 'Right Shift'; + SDL_SCANCODE_RALT: result := 'Right Alt'; + SDL_SCANCODE_RGUI: result := 'Right GUI'; + SDL_SCANCODE_MODE: result := 'ModeSwitch'; + (* !!! ... *) + else + result := '' + end end; function SDL_IsTextInputActive: TSDL_Bool; begin - result := SDL_FALSE + if inputText then + result := SDL_TRUE + else + result := SDL_FALSE end; procedure SDL_StartTextInput; begin + inputText := True end; procedure SDL_StopTextInput; begin + inputText := False end; (********** JOYSTICK **********) @@ -548,14 +833,12 @@ implementation function SDL_GetPerformanceCounter: UInt64; begin - (* TODO *) - result := ticks; + result := ticks (* !!! *) end; function SDL_GetPerformanceFrequency: UInt64; begin - (* TODO *) - result := 1 + result := 1 (* !!! *) end; procedure SDL_Delay(ms: UInt32); @@ -565,34 +848,84 @@ implementation function SDL_GetTicks: UInt32; begin - result := ticks; + result := ticks end; (********** DISPLAY MODES **********) + function GetPixelFormat (bpp: Integer): UInt32; + begin + case bpp of + 8: result := SDL_PIXELFORMAT_INDEX8; + 15: result := SDL_PIXELFORMAT_RGB555; + 16: result := SDL_PIXELFORMAT_RGB565; + 24: result := SDL_PIXELFORMAT_RGB888; + 32: result := SDL_PIXELFORMAT_RGBA8888; + else result := SDL_PIXELFORMAT_UNKNOWN + end + end; + function SDL_GetDesktopDisplayMode(displayIndex: SInt32; mode: PSDL_DisplayMode): SInt32; begin - e_LogWritefln('SDL_GetDesktopDisplayMode %s', [displayIndex]); - result := -1; - mode.format := SDL_PIXELFORMAT_UNKNOWN; (* FIXIT *) + ASSERT(mode <> nil); + mode.format := GetPixelFormat(deskbpp); + mode.w := deskw; + mode.h := deskh; mode.refresh_rate := 0; mode.driverdata := nil; - if get_desktop_resolution(@mode.w, @mode.h) = 0 then - result := 0 + result := 0 end; function SDL_GetClosestDisplayMode(displayIndex: SInt32; const mode: PSDL_DisplayMode; closest: PSDL_DisplayMode): PSDL_DisplayMode; + var m: PGFX_MODE_LIST; i, bpp: Integer; begin - e_LogWritefln('SDL_GetClosestDisplayMode %s', [displayIndex]); + ASSERT(mode <> nil); + ASSERT(closest <> nil); + result := nil; + bpp := SDL_BITSPERPIXEL(mode.format); + if bpp = 0 then bpp := deskbpp; + + m := nil; + if (gfx_driver <> nil) and (@gfx_driver.fetch_mode_list <> nil) then + m := gfx_driver.fetch_mode_list; + + if m <> nil then + begin + i := 0; + while (i < m.num_modes) and (m.mode[i].bpp <> bpp) do inc(i); + if i < m.num_modes then + begin + closest.format := mode.format; + closest.refresh_rate := 0; + closest.driverdata := nil; + closest.w := m.mode[i].width; + closest.h := m.mode[i].height; + result := closest + end; + while i < m.num_modes do + begin + 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 + begin + closest.w := m.mode[i].width; + closest.h := m.mode[i].height; + result := closest + end; + inc(i) + end; + destroy_gfx_mode_list(m) + end end; function SDL_GetNumDisplayModes(displayIndex: SInt32): SInt32; var m: PGFX_MODE_LIST; begin - e_LogWritefln('SDL_GetNumDisplayModes %s', [displayIndex]); result := -1; - m := get_gfx_mode_list(GFX_AUTODETECT); + + m := nil; + if (gfx_driver <> nil) and (@gfx_driver.fetch_mode_list <> nil) then + m := gfx_driver.fetch_mode_list; + if m <> nil then begin result := m.num_modes; @@ -603,24 +936,30 @@ implementation function SDL_GetDisplayMode(displayIndex: SInt32; modeIndex: SInt32; mode: PSDL_DisplayMode): SInt32; var m: PGFX_MODE_LIST; begin - e_LogWritefln('SDL_GetDisplayMode %s %s', [displayIndex, modeIndex]); result := -1; - m := get_gfx_mode_list(GFX_AUTODETECT); - if (m <> nil) and (modeIndex >= 0) and (modeIndex < m.num_modes) then + + m := nil; + if (gfx_driver <> nil) and (@gfx_driver.fetch_mode_list <> nil) then + m := gfx_driver.fetch_mode_list; + + if m <> nil then begin - mode.format := SDL_PIXELFORMAT_UNKNOWN; (* FIX IT *) - mode.w := m.mode[modeIndex].width; - mode.h := m.mode[modeIndex].height; - mode.refresh_rate := 0; - mode.driverdata := nil; - destroy_gfx_mode_list(m); - result := 0 + if (modeIndex >= 0) and (modeIndex < m.num_modes) then + begin + mode.format := GetPixelFormat(m.mode[modeIndex].bpp); + mode.w := m.mode[modeIndex].width; + mode.h := m.mode[modeIndex].height; + mode.refresh_rate := 0; + mode.driverdata := nil; + result := 0 + end; + destroy_gfx_mode_list(m) end end; function SDL_GetDisplayDPI(displayIndex: SInt32; ddpi, hdpi, vdpi: PFloat): SInt32; begin - result := -1 + result := -1 (* stub *) end; (*********** WINDOW MANAGEMENT **********) @@ -628,7 +967,6 @@ implementation function SDL_CreateWindow(const title: PAnsiChar; x: SInt32; y: SInt32; w: SInt32; h: SInt32; flags: UInt32): PSDL_Window; var window: PSDL_Window; mode: Integer; begin - e_LogWritefln('SDL_CreateWindow %s %s %s %s %s %u', [title, x, y, w, h, flags]); result := nil; {$IF DEFINED(GO32V2)} @@ -640,7 +978,10 @@ implementation mode := GFX_AUTODETECT_WINDOWED; {$ENDIF} - set_color_depth(DEFAULT_DEPTH); + if sdl2allegro_bpp = 0 then sdl2allegro_bpp := gBPP; + if sdl2allegro_bpp = 0 then sdl2allegro_bpp := deskbpp; + + set_color_depth(sdl2allegro_bpp); if set_gfx_mode(mode, w, h, 0, 0) = 0 then begin new(window); @@ -661,9 +1002,8 @@ implementation function SDL_SetWindowFullscreen(window: PSDL_Window; flags: UInt32): SInt32; var mode: Integer; begin - e_LogWritefln('SDL_SetWindowFullscreen %u', [flags]); + ASSERT(window <> nil); result := -1; - if window = nil then exit; {$IF DEFINED(GO32V2)} mode := GFX_AUTODETECT; @@ -674,7 +1014,7 @@ implementation mode := GFX_AUTODETECT_WINDOWED; {$ENDIF} - set_color_depth(DEFAULT_DEPTH); + set_color_depth(sdl2allegro_bpp); if set_gfx_mode(mode, window.w, window.h, 0, 0) = 0 then begin if sdl2allegro_screen <> nil then @@ -691,9 +1031,8 @@ implementation procedure SDL_SetWindowSize(window: PSDL_Window; w: SInt32; h: SInt32); begin - e_LogWritefln('SDL_SetWindowSize %s %s', [w, h]); - if window = nil then exit; - set_color_depth(DEFAULT_DEPTH); + ASSERT(window <> nil); + set_color_depth(sdl2allegro_bpp); if set_gfx_mode(window.mode, w, h, 0, 0) = 0 then begin if sdl2allegro_screen <> nil then @@ -704,13 +1043,16 @@ implementation ASSERT(sdl2allegro_screen <> nil); set_palette(desktop_palette); window.w := w; - window.h := h; + window.h := h + end + else + begin + ASSERT(FALSE, 'Unable to set window size') end end; procedure SDL_DestroyWindow(window: PSDL_Window); begin - e_LogWriteln('SDL_DestroyWindow'); if window = nil then exit; if sdl2allegro_screen <> nil then destroy_bitmap(sdl2allegro_screen); @@ -720,85 +1062,81 @@ implementation procedure SDL_GetWindowSize(window: PSDL_Window; w: PInt; h: PInt); begin - e_LogWriteln('SDL_GetWindowSize'); - if window = nil then exit; - if w <> nil then - w^ := window.w; - if h <> nil then - h^ := window.h; + ASSERT(window <> nil); + if w <> nil then w^ := window.w; + if h <> nil then h^ := window.h; end; procedure SDL_RestoreWindow(window: PSDL_Window); begin - e_LogWriteln('SDL_RestoreWindow'); - if window = nil then exit; + ASSERT(window <> nil); (* stub *) end; function SDL_SetWindowGammaRamp(window: PSDL_Window; const red: PUInt16; const green: PUInt16; const blue: PUInt16): SInt32; begin - e_LogWriteln('SDL_SetWindowGammaRamp'); - result := -1; - if window = nil then exit; - result := 0 + ASSERT(window <> nil); + result := 0 (* stub *) end; function SDL_GetWindowGammaRamp(window: PSDL_Window; red: PUInt16; green: PUInt16; blue: PUInt16): SInt32; begin - e_LogWriteln('SDL_GetWindowGammaRamp'); - result := -1; - if window = nil then exit; - result := 0 + ASSERT(window <> nil); + result := 0 (* stub *) end; (********** OPENGL MANAGEMENT **********) - function SDL_GL_MakeCurrent(window: PSDL_Window; context: TSDL_GLContext): SInt32; + function SDL_GL_SetAttribute(attr: TSDL_GLattr; value: SInt32): SInt32; begin - e_LogWriteln('SDL_GL_MakeCurrent'); - result := 0 + e_LogWritefln('SDL_GL_SetAttribute %s %s', [attr, value]); + allegro_error := 'Attribute ' + IntToStr(attr) + ' := ' + IntToStr(value) + 'not supported'; + result := -1 end; - procedure SDL_GL_DeleteContext(context: TSDL_GLContext); + function SDL_GL_GetAttribute(attr: TSDL_GLattr; value: PInt): SInt32; begin - e_LogWriteln('SDL_GL_DeleteContext'); + e_LogWritefln('SDL_GL_GetAttribute %s', [attr]); + value^ := 0; result := -1 end; - procedure SDL_GL_SwapWindow(window: PSDL_Window); - var res: cint; + function SDL_GL_CreateContext(window: PSDL_Window): TSDL_GLContext; begin - //e_LogWriteln('SDL_GL_SwapWindow'); - ASSERT(sdl2allegro_screen <> nil); - acquire_screen; - blit(sdl2allegro_screen, screen, 0, 0, 0, 0, sdl2allegro_screen.w, sdl2allegro_screen.h); - res := show_video_bitmap(screen); - release_screen; -// ASSERT(res = 0); + result := window (* stub *) end; - function SDL_GL_CreateContext(window: PSDL_Window): TSDL_GLContext; + function SDL_GL_MakeCurrent(window: PSDL_Window; context: TSDL_GLContext): SInt32; begin - e_LogWriteln('SDL_GL_CreateContext'); - result := window + ASSERT(window <> nil); + if context <> nil then + ASSERT(window = context); + result := 0 (* stub *) end; - function SDL_GL_SetSwapInterval(interval: SInt32): SInt32; + procedure SDL_GL_DeleteContext(context: TSDL_GLContext); begin - e_LogWritefln('SDL_GL_SetSwapInterval %s', [interval]); - result := 0 + (* stub *) end; - function SDL_GL_SetAttribute(attr: TSDL_GLattr; value: SInt32): SInt32; + function SDL_GL_SetSwapInterval(interval: SInt32): SInt32; begin - e_LogWritefln('SDL_GL_SetAttribute %s %s', [attr, value]); - allegro_error := 'Attribute ' + IntToStr(attr) + ' := ' + IntToStr(value) + 'not supported'; - result := -1 + result := 0; + if interval = 0 then + useVsync := False + else + useVsync := True end; - function SDL_GL_GetAttribute(attr: TSDL_GLattr; value: PInt): SInt32; + procedure SDL_GL_SwapWindow(window: PSDL_Window); begin - e_LogWritefln('SDL_GL_GetAttribute %s', [attr]); - value^ := 0; result := -1 + ASSERT(window <> nil); + ASSERT(sdl2allegro_screen <> nil); + acquire_screen; + blit(sdl2allegro_screen, screen, 0, 0, 0, 0, min(sdl2allegro_screen.w, screen.w), min(sdl2allegro_screen.h, screen.h)); + show_video_bitmap(screen); + release_screen; + if useVsync then + vsync; end; (********** EVENTS **********) @@ -808,93 +1146,14 @@ implementation result := 1; case event.type_ of SDL_QUITEV: quit := True; - else ASSERT(FALSE); result := 0 - end - end; - - function allegro_to_sdl_scancode (x: Integer): Integer; - begin - x := x and $7F; - case x of - KEY_A..KEY_Z: result := SDL_SCANCODE_A + (x - KEY_A); - KEY_0..KEY_0: result := SDL_SCANCODE_0 + (x - KEY_0); - KEY_0_PAD: result := SDL_SCANCODE_KP_0; - KEY_1_PAD..KEY_9_PAD: result := SDL_SCANCODE_KP_1 + (x - KEY_1_PAD); - KEY_F1..KEY_F12: result := SDL_SCANCODE_F1 + (x - KEY_F1); - KEY_ESC: result := SDL_SCANCODE_ESCAPE; - KEY_TILDE: result := SDL_SCANCODE_GRAVE; - KEY_MINUS: result := SDL_SCANCODE_MINUS; - KEY_EQUALS: result := SDL_SCANCODE_EQUALS; - KEY_BACKSPACE: result := SDL_SCANCODE_BACKSPACE; - KEY_TAB: result := SDL_SCANCODE_TAB; - KEY_OPENBRACE: result := SDL_SCANCODE_LEFTBRACKET; - KEY_CLOSEBRACE: result := SDL_SCANCODE_RIGHTBRACKET; - KEY_ENTER: result := SDL_SCANCODE_RETURN; - KEY_COLON: result := SDL_SCANCODE_SEMICOLON; - KEY_QUOTE: result := SDL_SCANCODE_APOSTROPHE; - KEY_BACKSLASH: result := SDL_SCANCODE_BACKSLASH; - KEY_BACKSLASH2: result := SDL_SCANCODE_NONUSHASH; (* ??? *) - KEY_COMMA: result := SDL_SCANCODE_COMMA; - (*KEY_STOP: result :=;*) (* ??? *) - KEY_SLASH: result := SDL_SCANCODE_SLASH; - KEY_SPACE: result := SDL_SCANCODE_SPACE; - KEY_INSERT: result := SDL_SCANCODE_INSERT; - KEY_DEL: result := SDL_SCANCODE_DELETE; - KEY_HOME: result := SDL_SCANCODE_HOME; - KEY_END: result := SDL_SCANCODE_END; - KEY_PGUP: result := SDL_SCANCODE_PAGEUP; - KEY_PGDN: result := SDL_SCANCODE_PAGEDOWN; - KEY_LEFT: result := SDL_SCANCODE_LEFT; - KEY_RIGHT: result := SDL_SCANCODE_RIGHT; - KEY_UP: result := SDL_SCANCODE_UP; - KEY_DOWN: result := SDL_SCANCODE_DOWN; - KEY_SLASH_PAD: result := SDL_SCANCODE_KP_DIVIDE; - KEY_ASTERISK: result := SDL_SCANCODE_KP_MULTIPLY; - KEY_MINUS_PAD: result := SDL_SCANCODE_KP_MINUS; - KEY_PLUS_PAD: result := SDL_SCANCODE_KP_PLUS; - KEY_DEL_PAD: result := SDL_SCANCODE_KP_PERIOD; - KEY_ENTER_PAD: result := SDL_SCANCODE_KP_ENTER; - KEY_PRTSCR: result := SDL_SCANCODE_PRINTSCREEN; - KEY_PAUSE: result := SDL_SCANCODE_PAUSE; - (*KEY_ABNT_C1: result :=;*) (* ??? *) - KEY_YEN: result := SDL_SCANCODE_INTERNATIONAL3; - KEY_KANA: result := SDL_SCANCODE_LANG3; (* ??? *) - (*KEY_CONVERT: result :=;*) (* ??? *) - (*KEY_NOCONVERT: result := ;*) (* ??? *) - KEY_AT: result := SDL_SCANCODE_KP_AT; - (*KEY_CIRCUMFLEX: result :=;*) (* ??? *) - KEY_COLON2: result := SDL_SCANCODE_KP_COLON; - (*KEY_KANJI: result :=;*) (* ??? *) - KEY_EQUALS_PAD: result := SDL_SCANCODE_KP_EQUALS; - (*KEY_BACKQUOTE: result :=;*) (* ??? *) - KEY_SEMICOLON: result := SDL_SCANCODE_SEMICOLON; - KEY_COMMAND: result := SDL_SCANCODE_LGUI; - (*KEY_UNKNOWN1: result :=;*) - (*KEY_UNKNOWN2: result :=;*) - (*KEY_UNKNOWN3: result :=;*) - (*KEY_UNKNOWN4: result :=;*) - (*KEY_UNKNOWN5: result :=;*) - (*KEY_UNKNOWN6: result :=;*) - (*KEY_UNKNOWN7: result :=;*) - (*KEY_UNKNOWN8: result :=;*) - KEY_LSHIFT: result := SDL_SCANCODE_LSHIFT; - KEY_RSHIFT: result := SDL_SCANCODE_RSHIFT; - KEY_LCONTROL: result := SDL_SCANCODE_LCTRL; - KEY_RCONTROL: result := SDL_SCANCODE_RCTRL; - KEY_ALT: result := SDL_SCANCODE_LALT; - KEY_ALTGR: result := SDL_SCANCODE_RALT; - KEY_LWIN: result := SDL_SCANCODE_LGUI; - KEY_RWIN: result := SDL_SCANCODE_RGUI; - KEY_MENU: result := SDL_SCANCODE_MODE; (* ??? *) - KEY_SCRLOCK: result := SDL_SCANCODE_SCROLLLOCK; - KEY_NUMLOCK: result := SDL_SCANCODE_NUMLOCKCLEAR; - KEY_CAPSLOCK: result := SDL_SCANCODE_CAPSLOCK; - else result := SDL_SCANCODE_UNKNOWN + else + ASSERT(FALSE); + result := 0 end end; function SDL_PollEvent(event: PSDL_Event): SInt32; - var alscan: Integer; + var alscan: Integer; pressed, shift, caps: Boolean; begin result := 0; @@ -907,23 +1166,52 @@ implementation Exit end; + if inputText and (inputChar <> #0) then + begin + event.type_ := SDL_TEXTINPUT; + event.text.timestamp := ticks; + event.text.windowID := 0; + event.text.text[0] := inputChar; + event.text.text[1] := #0; + inputChar := #0; + result := 1; + Exit + end + else + inputChar := #0; + poll_keyboard; if not IsEmptyKeyboard then begin alscan := NextScancode; - if alscan and $80 = 0 then + pressed := alscan and $80 = 0; + + inputChar := #0; + if pressed then + begin + shift := key_shifts and KB_SHIFT_FLAG <> 0; + caps := key_shifts and KB_CAPSLOCK_FLAG <> 0; + if shift xor caps then + inputChar := s2uc[alscan and $7F] + else + inputChar := s2lc[alscan and $7F]; event.type_ := SDL_KEYDOWN + end else event.type_ := SDL_KEYUP; + event.key.timestamp := ticks; event.key.windowID := 0; + (**** df not use it? - if alscan and $80 = 0 then + if pressed then event.key.state := SDL_PRESSED else event.key.state := SDL_RELEASED; ****) - event.key.keysym.scancode := allegro_to_sdl_scancode(alscan); + + event.key._repeat := 0; + event.key.keysym.scancode := s2sa[alscan and $7F]; event.key.keysym.sym := 0; (* df not use it? *) event.key.keysym._mod := 0; (* df not use it? *) result := 1; @@ -935,9 +1223,7 @@ implementation function SDL_ShowCursor(toggle: SInt32): SInt32; begin - e_LogWritefln('SDL_ShowCursor %s', [toggle]); - (* TODO *) - result := 0 + result := 0 (* stub *) end; (********** SDL **********) @@ -948,23 +1234,22 @@ implementation end; procedure AllegroQuitCallbackEND; begin end; - function SDL_SetHint( const name: PChar; const value: PChar) : boolean; + function SDL_SetHint(const name: PChar; const value: PChar): boolean; begin e_LogWritefln('SDL_SetHint %s %s', [name, value]); - (* TODO *) - result := false + result := false (* stub *) end; function SDL_GetError: PAnsiChar; begin - result := allegro_error; + result := allegro_error end; {$IFDEF GO32V2} (* HACK: allegro crashes while init without this *) var __crt0_argv: PPchar; cvar; external; - myargv: array [0..255] of Pchar; + myargv: array [0..1] of Pchar; procedure FIX_ARGV; begin @@ -1000,6 +1285,13 @@ implementation set_keyboard_rate(0, 0); install_int_ex(AllegroTimerCallback, MSEC_TO_TIMER(1)); set_close_button_callback(AllegroQuitCallback); + deskbpp := desktop_color_depth; + if deskbpp = 0 then deskbpp := 8; + if get_desktop_resolution(@deskw, @deskh) <> 0 then + begin + deskw := 640; + deskh := 480 + end; result := 0 end end;