Merge pull request #1 from pcercuei/for_upstream

This commit is contained in:
notaz 2013-10-09 16:43:16 -07:00
commit 62e581e179
11 changed files with 145 additions and 125 deletions

View file

@ -20,6 +20,7 @@ typedef unsigned long keybits_t;
#define KEYBITS_WORD_BITS (sizeof(keybits_t) * 8)
struct in_sdl_state {
const in_drv_t *drv;
SDL_Joystick *joy;
int joy_id;
int axis_keydown[2];
@ -162,21 +163,27 @@ static const char * const in_sdl_keys[SDLK_LAST] = {
[SDLK_COMPOSE] = "compose",
};
static void in_sdl_probe(void)
static void in_sdl_probe(const in_drv_t *drv)
{
const struct in_pdata *pdata = drv->pdata;
const char * const * key_names = in_sdl_keys;
struct in_sdl_state *state;
SDL_Joystick *joy;
int i, joycount;
char name[256];
if (pdata->key_names)
key_names = pdata->key_names;
state = calloc(1, sizeof(*state));
if (state == NULL) {
fprintf(stderr, "in_sdl: OOM\n");
return;
}
state->drv = drv;
in_register(IN_SDL_PREFIX "keys", -1, state, SDLK_LAST,
in_sdl_keys, 0);
key_names, 0);
/* joysticks go here too */
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
@ -194,9 +201,10 @@ static void in_sdl_probe(void)
}
state->joy = joy;
state->joy_id = i;
state->drv = drv;
snprintf(name, sizeof(name), IN_SDL_PREFIX "%s", SDL_JoystickName(i));
in_register(name, -1, state, SDLK_LAST, in_sdl_keys, 0);
in_register(name, -1, state, SDLK_LAST, key_names, 0);
}
if (joycount > 0)
@ -215,9 +223,13 @@ static void in_sdl_free(void *drv_data)
}
static const char * const *
in_sdl_get_key_names(int *count)
in_sdl_get_key_names(const in_drv_t *drv, int *count)
{
const struct in_pdata *pdata = drv->pdata;
*count = SDLK_LAST;
if (pdata->key_names)
return pdata->key_names;
return in_sdl_keys;
}
@ -406,52 +418,26 @@ static int in_sdl_update_keycode(void *drv_data, int *is_down)
return ret_kc;
}
struct menu_keymap {
short key;
short pbtn;
};
static const struct menu_keymap key_pbtn_map[] =
{
{ SDLK_UP, PBTN_UP },
{ SDLK_DOWN, PBTN_DOWN },
{ SDLK_LEFT, PBTN_LEFT },
{ SDLK_RIGHT, PBTN_RIGHT },
/* XXX: maybe better set this from it's plat code somehow */
{ SDLK_RETURN, PBTN_MOK },
{ SDLK_ESCAPE, PBTN_MBACK },
{ SDLK_SEMICOLON, PBTN_MA2 },
{ SDLK_QUOTE, PBTN_MA3 },
{ SDLK_BACKSLASH, PBTN_MENU },
{ SDLK_LEFTBRACKET, PBTN_L },
{ SDLK_RIGHTBRACKET, PBTN_R },
};
#define KEY_PBTN_MAP_SIZE (sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0]))
static const struct menu_keymap joybtn_pbtn_map[] =
{
{ SDLK_UP, PBTN_UP },
{ SDLK_DOWN, PBTN_DOWN },
{ SDLK_LEFT, PBTN_LEFT },
{ SDLK_RIGHT, PBTN_RIGHT },
/* joystick */
{ SDLK_WORLD_0, PBTN_MOK },
{ SDLK_WORLD_1, PBTN_MBACK },
{ SDLK_WORLD_2, PBTN_MA2 },
{ SDLK_WORLD_3, PBTN_MA3 },
};
#define JOYBTN_PBTN_MAP_SIZE (sizeof(joybtn_pbtn_map) / sizeof(joybtn_pbtn_map[0]))
static int in_sdl_menu_translate(void *drv_data, int keycode, char *charcode)
{
struct in_sdl_state *state = drv_data;
const struct in_pdata *pdata = state->drv->pdata;
const char * const * key_names = in_sdl_keys;
const struct menu_keymap *map;
int map_len;
int ret = 0;
int i;
map = state->joy ? joybtn_pbtn_map : key_pbtn_map;
map_len = state->joy ? JOYBTN_PBTN_MAP_SIZE : KEY_PBTN_MAP_SIZE;
if (pdata->key_names)
key_names = pdata->key_names;
if (state->joy) {
map = pdata->joy_map;
map_len = pdata->jmap_size;
} else {
map = pdata->key_map;
map_len = pdata->kmap_size;
}
if (keycode < 0)
{
@ -471,10 +457,10 @@ static int in_sdl_menu_translate(void *drv_data, int keycode, char *charcode)
}
if (charcode != NULL && (unsigned int)keycode < SDLK_LAST &&
in_sdl_keys[keycode] != NULL && in_sdl_keys[keycode][1] == 0)
key_names[keycode] != NULL && key_names[keycode][1] == 0)
{
ret |= PBTN_CHAR;
*charcode = in_sdl_keys[keycode][0];
*charcode = key_names[keycode][0];
}
}
@ -491,9 +477,14 @@ static const in_drv_t in_sdl_drv = {
.menu_translate = in_sdl_menu_translate,
};
void in_sdl_init(const struct in_default_bind *defbinds,
void (*handler)(void *event))
int in_sdl_init(const struct in_pdata *pdata, void (*handler)(void *event))
{
in_register_driver(&in_sdl_drv, defbinds);
if (!pdata) {
fprintf(stderr, "in_sdl: Missing input platform data\n");
return -1;
}
in_register_driver(&in_sdl_drv, pdata->defbinds, pdata);
ext_event_handler = handler;
return 0;
}

View file

@ -1,4 +1 @@
struct in_default_bind;
void in_sdl_init(const struct in_default_bind *defbinds,
void (*handler)(void *event));
int in_sdl_init(const struct in_pdata *pdata, void (*handler)(void *event));

14
input.c
View file

@ -63,7 +63,7 @@ static int *in_alloc_binds(int drv_id, int key_count)
if (defbinds[i].bit == 0 && defbinds[i].btype == 0
&& defbinds[i].bit == 0)
break;
binds[IN_BIND_OFFS(defbinds[i].code, defbinds[i].btype)] =
binds[IN_BIND_OFFS(defbinds[i].code, defbinds[i].btype)] |=
1 << defbinds[i].bit;
}
@ -247,7 +247,7 @@ void in_probe(void)
for (i = 0; i < in_driver_count; i++) {
in_probe_dev_id = i;
in_drivers[i].probe();
in_drivers[i].probe(&DRV(i));
}
/* get rid of devs without binds and probes */
@ -808,7 +808,8 @@ int in_config_parse_dev(const char *name)
if (in_devices[i].name == NULL)
return -1;
in_devices[i].key_names = DRV(drv_id).get_key_names(&in_devices[i].key_count);
in_devices[i].key_names = DRV(drv_id).get_key_names(&DRV(drv_id),
&in_devices[i].key_count);
in_devices[i].drv_id = drv_id;
if (i + 1 > in_dev_count)
@ -932,7 +933,8 @@ static const char *in_def_get_key_name(int keycode) { return NULL; }
if (d.f == NULL) d.f = in_def_##f
/* to be called by drivers */
int in_register_driver(const in_drv_t *drv, const struct in_default_bind *defbinds)
int in_register_driver(const in_drv_t *drv,
const struct in_default_bind *defbinds, const void *pdata)
{
int count_new = in_driver_count + 1;
in_drv_t *new_drivers;
@ -954,7 +956,9 @@ int in_register_driver(const in_drv_t *drv, const struct in_default_bind *defbin
CHECK_ADD_STUB(new_drivers[in_driver_count], menu_translate);
CHECK_ADD_STUB(new_drivers[in_driver_count], get_key_code);
CHECK_ADD_STUB(new_drivers[in_driver_count], get_key_name);
if (defbinds != NULL)
if (pdata)
new_drivers[in_driver_count].pdata = pdata;
if (defbinds)
new_drivers[in_driver_count].defbinds = defbinds;
in_drivers = new_drivers;
in_driver_count = count_new;

28
input.h
View file

@ -76,12 +76,14 @@ enum {
#define IN_BIND_OFFS(key, btype) \
((key) * IN_BINDTYPE_COUNT + (btype))
typedef struct {
typedef struct InputDriver in_drv_t;
struct InputDriver {
const char *prefix;
void (*probe)(void);
void (*probe)(const in_drv_t *drv);
void (*free)(void *drv_data);
const char * const *
(*get_key_names)(int *count);
(*get_key_names)(const in_drv_t *drv, int *count);
int (*clean_binds)(void *drv_data, int *binds, int *def_finds);
int (*get_config)(void *drv_data, int what, int *val);
int (*set_config)(void *drv_data, int what, int val);
@ -94,7 +96,8 @@ typedef struct {
const char * (*get_key_name)(int keycode);
const struct in_default_bind *defbinds;
} in_drv_t;
const void *pdata;
};
struct in_default_bind {
unsigned short code;
@ -102,8 +105,23 @@ struct in_default_bind {
unsigned char bit;
};
struct menu_keymap {
short key;
short pbtn;
};
struct in_pdata {
const struct in_default_bind *defbinds;
const struct menu_keymap *key_map;
size_t kmap_size;
const struct menu_keymap *joy_map;
size_t jmap_size;
const char * const *key_names;
};
/* to be called by drivers */
int in_register_driver(const in_drv_t *drv, const struct in_default_bind *defbinds);
int in_register_driver(const in_drv_t *drv,
const struct in_default_bind *defbinds, const void *pdata);
void in_register(const char *nname, int drv_fd_hnd, void *drv_data,
int key_count, const char * const *key_names, int combos);
void in_combos_find(const int *binds, int last_key, int *combo_keys, int *combo_acts);

View file

@ -41,6 +41,8 @@ typedef struct {
int abs_mult[MAX_ABS_DEVS]; /* 16.16 multiplier to IN_ABS_RANGE */
int abs_adj[MAX_ABS_DEVS]; /* adjust for centering */
unsigned int abs_to_digital:1;
const in_drv_t *drv;
} in_evdev_t;
#ifndef KEY_CNT
@ -147,7 +149,7 @@ static const char * const in_evdev_keys[KEY_CNT] = {
};
static void in_evdev_probe(void)
static void in_evdev_probe(const in_drv_t *drv)
{
long keybits[KEY_CNT / sizeof(long) / 8];
long absbits[(ABS_MAX+1) / sizeof(long) / 8];
@ -206,6 +208,8 @@ static void in_evdev_probe(void)
if (dev == NULL)
goto skip;
dev->drv = drv;
ret = ioctl(fd, EVIOCGKEY(sizeof(keybits)), keybits);
if (ret == -1) {
printf("Warning: EVIOCGKEY not supported, will have to track state\n");
@ -286,9 +290,13 @@ static void in_evdev_free(void *drv_data)
}
static const char * const *
in_evdev_get_key_names(int *count)
in_evdev_get_key_names(const in_drv_t *drv, int *count)
{
const struct in_pdata *pdata = drv->pdata;
*count = KEY_CNT;
if (pdata->key_names)
return pdata->key_names;
return in_evdev_keys;
}
@ -522,47 +530,10 @@ out:
return ret_kc;
}
static const struct {
short key;
short pbtn;
} key_pbtn_map[] =
{
{ KEY_UP, PBTN_UP },
{ KEY_DOWN, PBTN_DOWN },
{ KEY_LEFT, PBTN_LEFT },
{ KEY_RIGHT, PBTN_RIGHT },
/* XXX: maybe better set this from it's plat code somehow */
/* Pandora */
{ KEY_END, PBTN_MOK },
{ KEY_PAGEDOWN, PBTN_MBACK },
{ KEY_HOME, PBTN_MA2 },
{ KEY_PAGEUP, PBTN_MA3 },
{ KEY_LEFTCTRL, PBTN_MENU },
{ KEY_RIGHTSHIFT, PBTN_L },
{ KEY_RIGHTCTRL, PBTN_R },
/* Caanoo */
{ BTN_THUMB2, PBTN_MOK },
{ BTN_THUMB, PBTN_MBACK },
{ BTN_TRIGGER, PBTN_MA2 },
{ BTN_TOP, PBTN_MA3 },
{ BTN_BASE, PBTN_MENU },
{ BTN_TOP2, PBTN_L },
{ BTN_PINKIE, PBTN_R },
/* "normal" keyboards */
{ KEY_ENTER, PBTN_MOK },
{ KEY_ESC, PBTN_MBACK },
{ KEY_SEMICOLON, PBTN_MA2 },
{ KEY_APOSTROPHE, PBTN_MA3 },
{ KEY_BACKSLASH, PBTN_MENU },
{ KEY_LEFTBRACE, PBTN_L },
{ KEY_RIGHTBRACE, PBTN_R },
};
#define KEY_PBTN_MAP_SIZE (sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0]))
static int in_evdev_menu_translate(void *drv_data, int keycode, char *charcode)
{
in_evdev_t *dev = drv_data;
const struct in_pdata *pdata = dev->drv->pdata;
int ret = 0;
int i;
@ -570,9 +541,9 @@ static int in_evdev_menu_translate(void *drv_data, int keycode, char *charcode)
{
/* menu -> kc */
keycode = -keycode;
for (i = 0; i < KEY_PBTN_MAP_SIZE; i++)
if (key_pbtn_map[i].pbtn == keycode) {
int k = key_pbtn_map[i].key;
for (i = 0; i < pdata->kmap_size; i++)
if (pdata->key_map[i].pbtn == keycode) {
int k = pdata->key_map[i].key;
/* should really check EVIOCGBIT, but this is enough for now */
if (dev->kc_first <= k && k <= dev->kc_last)
return k;
@ -580,9 +551,9 @@ static int in_evdev_menu_translate(void *drv_data, int keycode, char *charcode)
}
else
{
for (i = 0; i < KEY_PBTN_MAP_SIZE; i++) {
if (key_pbtn_map[i].key == keycode) {
ret = key_pbtn_map[i].pbtn;
for (i = 0; i < pdata->kmap_size; i++) {
if (pdata->key_map[i].key == keycode) {
ret = pdata->key_map[i].pbtn;
break;
}
}
@ -649,8 +620,14 @@ static const in_drv_t in_evdev_drv = {
.menu_translate = in_evdev_menu_translate,
};
void in_evdev_init(const struct in_default_bind *defbinds)
int in_evdev_init(const struct in_pdata *pdata)
{
in_register_driver(&in_evdev_drv, defbinds);
if (!pdata) {
fprintf(stderr, "in_sdl: Missing input platform data\n");
return -1;
}
in_register_driver(&in_evdev_drv, pdata->defbinds, pdata);
return 0;
}

View file

@ -1,5 +1,3 @@
struct in_default_bind;
extern int in_evdev_allow_abs_only;
void in_evdev_init(const struct in_default_bind *defbinds);
int in_evdev_init(const struct in_pdata *pdata);

View file

@ -19,6 +19,7 @@
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
#include <sys/stat.h>
#include "../plat.h"
@ -40,24 +41,54 @@ int plat_is_dir(const char *path)
return 0;
}
int plat_get_root_dir(char *dst, int len)
static int plat_get_data_dir(char *dst, int len)
{
int j, ret;
ret = readlink("/proc/self/exe", dst, len - 1);
#ifdef PICO_DATA_DIR
memcpy(dst, PICO_DATA_DIR, sizeof PICO_DATA_DIR);
return sizeof(PICO_DATA_DIR) - 1;
#else
int j, ret = readlink("/proc/self/exe", dst, len - 1);
if (ret < 0) {
perror("readlink");
ret = 0;
}
dst[ret] = 0;
for (j = strlen(dst); j > 0; j--)
for (j = ret - 1; j > 0; j--)
if (dst[j] == '/') {
dst[++j] = 0;
break;
}
return j;
#endif
}
int plat_get_skin_dir(char *dst, int len)
{
int ret = plat_get_data_dir(dst, len);
if (ret < 0)
return ret;
memcpy(dst + ret, "skin/", sizeof "skin/");
return ret + sizeof("skin/") - 1;
}
#ifndef PICO_HOME_DIR
#define PICO_HOME_DIR "/.picodrive/"
#endif
int plat_get_root_dir(char *dst, int len)
{
#if defined(__GP2X__) || defined(PANDORA)
return plat_get_data_dir(dst, len);
#else
char *home = getenv("HOME");
size_t nb = strlen(home);
memcpy(dst, home, nb);
memcpy(dst + nb, PICO_HOME_DIR, sizeof PICO_HOME_DIR);
mkdir(dst, 0755);
return nb + sizeof(PICO_HOME_DIR) - 1;
#endif
}
#ifdef __GP2X__

9
menu.c
View file

@ -239,7 +239,7 @@ static char tolower_simple(char c)
void menu_init_base(void)
{
int i, c, l;
int i, c, l, pos;
unsigned char *fd, *fds;
char buff[256];
FILE *f;
@ -294,17 +294,18 @@ void menu_init_base(void)
}
// load custom font and selector (stored as 1st symbol in font table)
emu_make_path(buff, "skin/font.png", sizeof(buff));
pos = plat_get_skin_dir(buff, sizeof(buff));
strcpy(buff + pos, "font.png");
readpng(menu_font_data, buff, READPNG_FONT,
MENU_X2 ? 256 : 128, MENU_X2 ? 320 : 160);
// default selector symbol is '>'
memcpy(menu_font_data, menu_font_data + ((int)'>') * me_mfont_w * me_mfont_h / 2,
me_mfont_w * me_mfont_h / 2);
emu_make_path(buff, "skin/selector.png", sizeof(buff));
strcpy(buff + pos, "selector.png");
readpng(menu_font_data, buff, READPNG_SELECTOR, me_mfont_w, me_mfont_h);
// load custom colors
emu_make_path(buff, "skin/skin.txt", sizeof(buff));
strcpy(buff + pos, "skin.txt");
f = fopen(buff, "r");
if (f != NULL)
{

3
plat.h
View file

@ -104,6 +104,9 @@ void plat_video_wait_vsync(void);
/* return the dir/ where configs, saves, bios, etc. are found */
int plat_get_root_dir(char *dst, int len);
/* return the dir/ where skin files are found */
int plat_get_skin_dir(char *dst, int len);
int plat_is_dir(const char *path);
int plat_wait_event(int *fds_hnds, int count, int timeout_ms);
void plat_sleep_ms(int ms);

View file

@ -120,7 +120,7 @@ int plat_sdl_change_video_mode(int w, int h, int force)
if (plat_target.vout_method == 0) {
SDL_PumpEvents();
plat_sdl_screen = SDL_SetVideoMode(w, h, 16, SDL_SWSURFACE);
plat_sdl_screen = SDL_SetVideoMode(w, h, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
if (plat_sdl_screen == NULL) {
fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError());
return -1;
@ -227,7 +227,7 @@ int plat_sdl_init(void)
// overlay/gl require native bpp in some cases..
plat_sdl_screen = SDL_SetVideoMode(g_menuscreen_w, g_menuscreen_h,
0, SDL_SWSURFACE);
0, plat_sdl_screen->flags);
if (plat_sdl_screen == NULL) {
fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError());
goto fail;

View file

@ -75,7 +75,7 @@ int sndout_sdl_start(int rate, int stereo)
desired.callback = callback;
desired.userdata = NULL;
samples = rate * 4 * 16 / 1000;
samples = rate >> 6;
for (shift = 8; (1 << shift) < samples; shift++)
;
desired.samples = 1 << shift;