From: notaz Date: Fri, 12 Nov 2010 22:08:39 +0000 (+0200) Subject: rename input.c to avoid conflicts, some small refactoring X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0aab059fdffebbbf5af73cc7549adaf58470d0ec;p=sdl_omap.git rename input.c to avoid conflicts, some small refactoring --- diff --git a/src/video/omapdss/Makefile b/src/video/omapdss/Makefile index b70fbb0..523d82f 100644 --- a/src/video/omapdss/Makefile +++ b/src/video/omapdss/Makefile @@ -8,7 +8,7 @@ endif ARCH ?= arm TARGET = libSDL-1.2.so.0 -OBJS += standalone.o input.o config.o \ +OBJS += standalone.o osdl_input.o config.o \ common/input.o linux/fbdev.o linux/in_evdev.o linux/oshide.o linux/plat.o ifeq ($(ARCH),arm) OBJS += arm_utils.o diff --git a/src/video/omapdss/config.c b/src/video/omapdss/config.c index e526c36..865b80a 100644 --- a/src/video/omapdss/config.c +++ b/src/video/omapdss/config.c @@ -6,12 +6,15 @@ */ #include +#include #include #include #include #include "omapsdl.h" +int gcfg_force_vsync; + static char *sskip(char *p) { while (*p && isspace(*p)) @@ -26,10 +29,26 @@ static char *nsskip(char *p) return p; } -static int check_token(const char *p, const char *token) +static int check_token(char **p_, const char *token) { + char *p = *p_; int tlen = strlen(token); - return strncasecmp(p, token, tlen) == 0 && isspace(p[tlen]); + int ret = strncasecmp(p, token, tlen) == 0 && isspace(p[tlen]); + if (ret) + *p_ = sskip(p + tlen + 1); + + return ret; +} + +static int check_token_eq(char **p_, const char *token) +{ + char *p = *p_; + int ret = check_token(&p, token); + ret = ret && *p == '='; + if (ret) + *p_ = sskip(p + 1); + + return ret; } void omapsdl_config(void) @@ -49,9 +68,9 @@ void omapsdl_config(void) if (*p == '#') continue; - if (check_token(p, "bind")) { + if (check_token(&p, "bind")) { char *key, *key_end, *sdlkey, *sdlkey_end; - key = sskip(p + 5); + key = p; key_end = nsskip(key); p = sskip(key_end); if (*p != '=') @@ -66,6 +85,10 @@ void omapsdl_config(void) omapsdl_input_bind(key, sdlkey); continue; } + else if (check_token_eq(&p, "force_vsync")) { + gcfg_force_vsync = strtol(p, NULL, 0); + continue; + } bad: err("config: failed to parse: %s", line); diff --git a/src/video/omapdss/omapsdl.h b/src/video/omapdss/omapsdl.h index f0f1ac4..4e842bc 100644 --- a/src/video/omapdss/omapsdl.h +++ b/src/video/omapdss/omapsdl.h @@ -3,7 +3,7 @@ #define err(fmt, ...) fprintf(stderr, "omapsdl: " fmt "\n", ##__VA_ARGS__) #define not_supported() fprintf(stderr, "omapsdl: %s not supported\n", __FUNCTION__) -#if 1 +#if 0 #define trace(fmt, ...) printf(" %s(" fmt ")\n", __FUNCTION__, ##__VA_ARGS__) #define dbg err #else @@ -13,9 +13,12 @@ void omapsdl_input_init(void); void omapsdl_input_bind(const char *kname, const char *sdlname); -int omapsdl_input_get_event(void *event_, int timeout); +int omapsdl_input_get_event(int *is_down, int timeout); void omapsdl_config(void); /* functions for standalone */ void do_clut(void *dest, void *src, unsigned short *pal, int count); + +/* config */ +extern int gcfg_force_vsync; diff --git a/src/video/omapdss/input.c b/src/video/omapdss/osdl_input.c similarity index 96% rename from src/video/omapdss/input.c rename to src/video/omapdss/osdl_input.c index 6fb8884..86a510d 100644 --- a/src/video/omapdss/input.c +++ b/src/video/omapdss/osdl_input.c @@ -12,8 +12,6 @@ #include "omapsdl.h" #include "common/input.h" -static unsigned char g_keystate[SDLK_LAST]; - static short pmsdl_map[KEY_CNT] = { [KEY_0] = SDLK_0, [KEY_1] = SDLK_1, @@ -376,24 +374,39 @@ void omapsdl_input_init(void) in_probe(); } -int omapsdl_input_get_event(void *event_, int timeout) +int omapsdl_input_get_event(int *is_down, int timeout) { - SDL_Event *event = event_; - int key, is_down; + int key; while (1) { int kc; - is_down = 0; - kc = in_update_keycode(NULL, &is_down, timeout); + *is_down = 0; + kc = in_update_keycode(NULL, is_down, timeout); if (kc < 0 || kc > KEY_MAX) - return 0; + return -1; key = pmsdl_map[kc]; if (key != 0) break; } + return key; +} + +/* SDL */ +#ifdef STANDALONE + +static unsigned char g_keystate[SDLK_LAST]; + +static int do_event(SDL_Event *event, int timeout) +{ + int key, is_down; + + key = omapsdl_input_get_event(&is_down, timeout); + if (key < 0) + return 0; + g_keystate[key] = is_down; if (event == NULL) @@ -409,15 +422,12 @@ int omapsdl_input_get_event(void *event_, int timeout) return 1; } -/* SDL */ -#ifdef STANDALONE - DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event *event) { trace("%p", event); - return omapsdl_input_get_event(event, -1); + return do_event(event, -1); } DECLSPEC int SDLCALL @@ -425,7 +435,7 @@ SDL_PollEvent(SDL_Event *event) { trace("%p", event); - return omapsdl_input_get_event(event, 0); + return do_event(event, 0); } DECLSPEC Uint8 * SDLCALL