From f6a7f37ecf354e7d8170ab563dc1435b5d20784c Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Thu, 11 Feb 2016 17:34:00 +1000 Subject: [PATCH] Added Timer & dodgy unicode support (for basic latin) --- configure | 6 ++ configure.in | 6 ++ include/SDL_config.h.in | 1 + src/timer/quinn/SDL_systimer.c | 118 ++++++++++++++++++++++++++++++ src/video/quinn/SDL_quinnevents.c | 62 +++++++++++++++- src/video/quinn/SDL_quinnvideo.c | 2 +- 6 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 src/timer/quinn/SDL_systimer.c diff --git a/configure b/configure index 5024ff1..d1e2436 100755 --- a/configure +++ b/configure @@ -21706,6 +21706,12 @@ case "$host" in SOURCES="$SOURCES $srcdir/src/video/quinn/*.c" SDL_LIBS="$SDL_LIBS -lquinn -lpng -lz -lm -lfreetype" + if test x$enable_timers = xyes; then + $as_echo "#define SDL_TIMER_QUINN 1" >>confdefs.h + + SOURCES="$SOURCES $srcdir/src/timer/quinn/*.c" + have_timers=yes + fi ;; *-*-cygwin* | *-*-mingw32*) ARCH=win32 diff --git a/configure.in b/configure.in index b2a5ef4..ab4e639 100644 --- a/configure.in +++ b/configure.in @@ -2509,6 +2509,12 @@ case "$host" in AC_DEFINE(SDL_VIDEO_DRIVER_QUINN) SOURCES="$SOURCES $srcdir/src/video/quinn/*.c" EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lquinn" + if test x$enable_timers = xyes; then + AC_DEFINE(SDL_TIMER_QUINN) + SOURCES="$SOURCES $srcdir/src/timer/quinn/*.c" + have_timers=yes + fi + ;; *-*-cygwin* | *-*-mingw32*) ARCH=win32 diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index 13ef0a0..9fc5d12 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -251,6 +251,7 @@ #undef SDL_TIMER_UNIX #undef SDL_TIMER_WIN32 #undef SDL_TIMER_WINCE +#undef SDL_TIMER_QUINN /* Enable various video drivers */ #undef SDL_VIDEO_DRIVER_AALIB diff --git a/src/timer/quinn/SDL_systimer.c b/src/timer/quinn/SDL_systimer.c new file mode 100644 index 0000000..6a7a96f --- /dev/null +++ b/src/timer/quinn/SDL_systimer.c @@ -0,0 +1,118 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#ifdef SDL_TIMER_QUINN + +#include +#include +#include + +#include "SDL_timer.h" +#include "../SDL_timer_c.h" + +static Uint32 start; +static Uint32 timerStart; + +void SDL_StartTicks(void) +{ + /* Set first ticks value */ + __asm__ volatile ("int $0x30" : "=a" (start) : "0" (46)); +} + +Uint32 SDL_GetTicks (void) +{ + Uint32 ticks; + Uint32 now; + __asm__ volatile ("int $0x30" : "=a" (now) : "0" (46)); + ticks= now - start; + return(ticks); +} + +void SDL_Delay (Uint32 ms) +{ + Uint32 then, now, elapsed; + + /* Set the timeout interval */ + then = SDL_GetTicks(); + do { + /* Calculate the time interval left (in case of interrupt) */ + now = SDL_GetTicks(); + elapsed = (now-then); + then = now; + if ( elapsed >= (ms / 10) ) { + break; + } + ms -= elapsed; + + quinn_yield(); + } while (1); +} + + + +/* This is only called if the event thread is not running */ +int SDL_SYS_TimerInit(void) +{ + return 0; +} + +void SDL_SYS_TimerQuit(void) +{ + SDL_SetTimer(0, NULL); +} + +int SDL_SYS_StartTimer(void) +{ + timerStart = SDL_GetTicks(); + return(0); +} + +void SDL_SYS_StopTimer(void) +{ + return; +} + + +void QUINN_CheckTimer() +{ + if (SDL_timer_running && SDL_GetTicks() - timerStart >= SDL_alarm_interval) + { + Uint32 ms; + + ms = SDL_alarm_callback(SDL_alarm_interval); + if ( ms != SDL_alarm_interval ) + { + if ( ms ) + { + SDL_alarm_interval = ROUND_RESOLUTION(ms); + } else + { + SDL_alarm_interval = 0; + SDL_timer_running = 0; + } + } + if (SDL_alarm_interval) timerStart = SDL_GetTicks(); + } +} + +#endif diff --git a/src/video/quinn/SDL_quinnevents.c b/src/video/quinn/SDL_quinnevents.c index 49b2a21..656e7c1 100644 --- a/src/video/quinn/SDL_quinnevents.c +++ b/src/video/quinn/SDL_quinnevents.c @@ -30,6 +30,55 @@ #include "quinn.h" +static const int sdl_unicode_shift[] = { + 0, 0, 0x21, 0x40, + 0x23, 0x24, 0x25, 0x5e, + 0x26, 0x2a, 0x28, 0x29, + 0x5f, 0x2b, 0x08, 0x09, + 0x51, 0x57, 0x45, 0x52, + 0x54, 0x59, 0x55, 0x49, + 0x4F, 0x50, 0x7b, 0x7d, + 0x0d, 0, 0x41, 0x53, + 0x44, 0x46, 0x47, 0x48, + 0x4a, 0x4b, 0x4c, 0x3A, + 0x22, 0x7e, 0, 0x7c, + 0x5a, 0x58, 0x43, 0x56, + 0x42, 0x4e, 0x4d, 0x3c, + 0x3e, 0x3f, 0, 0, + 0, 0x20, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, 0 +}; + +static const int sdl_unicode[] = { + 0, 0, 0x31, 0x32, + 0x33, 0x34, 0x35, 0x36, + 0x37, 0x38, 0x39, 0x30, + 0x2d, 0x3d, 0x08, 0x09, + 0x71, 0x77, 0x65, 0x72, + 0x74, 0x79, 0x75, 0x69, + 0x6F, 0x70, 0x5b, 0x5d, + 0x0d, 0, 0x61, 0x73, + 0x64, 0x66, 0x67, 0x68, + 0x6a, 0x6b, 0x6c, 0x3B, + 0x27, 0x60, 0, 0x5c, + 0x7a, 0x78, 0x63, 0x76, + 0x62, 0x6e, 0x6d, 0x2c, + 0x2e, 0x2f, 0, 0, + 0, 0x20, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, 0 +}; static const int sdl_keyset[] = { 0, SDLK_ESCAPE, SDLK_1, SDLK_2, @@ -92,6 +141,10 @@ void QUINN_recv_event(struct window_update_req *req) { void QUINN_PumpEvents(_THIS) { int i; + if (this->hidden->doexit == 1) { + SDL_PrivateQuit(); + } + if (current_req_current) { if (current_req.lclick != _lmstate) { if (current_req.lclick) { @@ -128,7 +181,11 @@ void QUINN_PumpEvents(_THIS) { for (i=0;i<88;i++) { if (_k_last_state[i] != current_req.key_codes[i]) { keysym.scancode = i; - keysym.unicode = 0; + if (current_req.key_codes[42] == 1 || current_req.key_codes[54] == 1) { + keysym.unicode = sdl_unicode_shift[i]; + } else { + keysym.unicode = sdl_unicode[i]; + } keysym.mod = make_mod(current_req.key_codes); if (current_req.key_codes[i] == 1) { // key down @@ -139,12 +196,13 @@ void QUINN_PumpEvents(_THIS) { keysym.sym = sdl_keyset[i]; SDL_PrivateKeyboard(SDL_RELEASED, &keysym); } + _k_last_state[i] = current_req.key_codes[i]; } - _k_last_state[i] = current_req.key_codes[i]; } current_req_current = 0; } + quinn_process_input(); } void QUINN_InitOSKeymap(_THIS) diff --git a/src/video/quinn/SDL_quinnvideo.c b/src/video/quinn/SDL_quinnvideo.c index 70a25db..dafd855 100644 --- a/src/video/quinn/SDL_quinnvideo.c +++ b/src/video/quinn/SDL_quinnvideo.c @@ -245,7 +245,7 @@ static void QUINN_UnlockHWSurface(_THIS, SDL_Surface *surface) static void QUINN_UpdateRects(_THIS, int numrects, SDL_Rect *rects) { - quinn_process(); + quinn_update_window(); quinn_yield(); }