continuing input framework integration

git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@631 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2009-01-03 18:53:35 +00:00
parent 54563d7189
commit fce20e73e7
13 changed files with 252 additions and 457 deletions

View file

@ -15,7 +15,11 @@
#define PBTN_L GP2X_L
#define PBTN_R GP2X_R
int wait_for_input(int interesting);
/* menu nav */
#define PBTN_MOK GP2X_B
#define PBTN_MBACK GP2X_X
#define PBTN_MENU GP2X_SELECT
void gp2x_pd_clone_buffer2(void);
void menu_darken_bg(void *dst, int pixels, int darker);
void menu_flip(void);
@ -24,10 +28,6 @@ void menu_flip(void);
#define SCREEN_HEIGHT 240
#define SCREEN_BUFFER gp2x_screen
#define read_buttons(which) \
wait_for_input(which)
#define read_buttons_async(which) \
(gp2x_joystick_read(0) & (which))
#define menu_draw_begin() \
gp2x_pd_clone_buffer2()
#define clear_screen() \
@ -48,7 +48,6 @@ void menu_flip(void);
#define PBTN_WEST PBTN_REW
#define PBTN_EAST PBTN_FWD
unsigned long wait_for_input(unsigned int interesting);
void menu_draw_begin(int use_bgbuff);
void menu_darken_bg(void *dst, const void *src, int pixels, int darker);
void menu_draw_end(void);
@ -59,9 +58,6 @@ void menu_draw_end(void);
extern void *menu_screen;
extern void *giz_screen;
#define read_buttons(which) \
wait_for_input(which)
#define read_buttons_async(which) 0
#define menu_draw_begin() \
menu_draw_begin(1)
#define clear_screen() \
@ -80,7 +76,6 @@ extern void *giz_screen;
#define PBTN_WEST PBTN_SQUARE
#define PBTN_EAST PBTN_CIRCLE
unsigned long wait_for_input(unsigned int interesting, int is_key_config);
void menu_draw_begin(void);
void menu_darken_bg(void *dst, const void *src, int pixels, int darker);
void menu_draw_end(void);
@ -89,10 +84,6 @@ void menu_draw_end(void);
#define SCREEN_HEIGHT 272
#define SCREEN_BUFFER psp_screen
#define read_buttons(which) \
wait_for_input(which, 0)
#define read_buttons_async(which) \
(psp_pad_read(0) & (which))
#define clear_screen() \
memset(SCREEN_BUFFER, 0, SCREEN_WIDTH*SCREEN_HEIGHT*2)
#define darken_screen() \
@ -102,10 +93,6 @@ void menu_draw_end(void);
#elif defined(PANDORA)
// TODO
#include "../gp2x/gp2x.h"
#define PBTN_UP (1 << 0)
#define PBTN_DOWN (1 << 1)
#define PBTN_LEFT (1 << 2)
@ -118,19 +105,21 @@ void menu_draw_end(void);
#define PBTN_L (1 << 8)
#define PBTN_R (1 << 9)
unsigned long wait_for_input(unsigned long interesting);
/* menu nav */
#define PBTN_MOK PBTN_EAST
#define PBTN_MBACK PBTN_SOUTH
#define PBTN_MENU (1 << 10)
void gp2x_pd_clone_buffer2(void);
void menu_darken_bg(void *dst, int pixels, int darker);
void menu_flip(void);
extern void *gp2x_screen;
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 480
#define SCREEN_BUFFER gp2x_screen
#define read_buttons(which) \
wait_for_input(which)
#define read_buttons_async(which) \
(gp2x_joystick_read(0) & (which))
#define menu_draw_begin() \
gp2x_pd_clone_buffer2()
#define clear_screen() \

View file

@ -209,16 +209,6 @@ static void custom_write(FILE *f, const menu_entry *me, int no_def)
}
#if PLAT_HAVE_JOY
static const char *joyKeyNames[32] =
{
"UP", "DOWN", "LEFT", "RIGHT", "b1", "b2", "b3", "b4",
"b5", "b6", "b7", "b8", "b9", "b10", "b11", "b12",
"b13", "b14", "b15", "b16", "b17", "b19", "b19", "b20",
"b21", "b22", "b23", "b24", "b25", "b26", "b27", "b28"
};
#endif
static void keys_write(FILE *fn, const char *bind_str, int dev_id, const int *binds, int no_defaults)
{
char act[48];
@ -401,7 +391,7 @@ write:
for (t = 0; t < IN_MAX_DEVS; t++)
{
const int *binds = in_get_dev_binds(t);
const char *name = in_get_dev_name(t);
const char *name = in_get_dev_name(t, 0);
if (binds == NULL || name == NULL)
continue;
@ -412,7 +402,7 @@ write:
for (t = 0; t < IN_MAX_DEVS; t++)
{
const int *binds = in_get_dev_binds(t);
const char *name = in_get_dev_name(t);
const char *name = in_get_dev_name(t, 0);
char strbind[16];
int count;
@ -426,17 +416,6 @@ write:
keys_write(fn, strbind, t, binds, no_defaults);
}
#if 0
/* old stuff */
keys_write(fn, "bind", currentConfig.KeyBinds, defaultConfig.KeyBinds, keyNames, PLAT_MAX_KEYS, no_defaults);
#if PLAT_HAVE_JOY
keys_write(fn, "bind_joy0", currentConfig.JoyBinds[0], defaultConfig.JoyBinds[0], joyKeyNames, 32, 1);
keys_write(fn, "bind_joy1", currentConfig.JoyBinds[1], defaultConfig.JoyBinds[1], joyKeyNames, 32, 1);
keys_write(fn, "bind_joy2", currentConfig.JoyBinds[2], defaultConfig.JoyBinds[2], joyKeyNames, 32, 1);
keys_write(fn, "bind_joy3", currentConfig.JoyBinds[3], defaultConfig.JoyBinds[3], joyKeyNames, 32, 1);
#endif
#endif
#ifndef PSP
if (section == NULL)
fprintf(fn, "Sound Volume = %i" NL, currentConfig.volume);
@ -771,42 +750,6 @@ static void keys_parse(const char *key, const char *val, int dev_id)
}
in_config_bind_key(dev_id, key, binds);
/*
for (t = 0; t < 32; t++)
{
if (names[t] && strcmp(names[t], var) == 0) break;
}
if (t == 32)
{
int len = strlen(var);
if (len == 1) t = var[0];
else if (len >= 4 && var[0] == '\\' && var[1] == 'x') {
char *p;
t = (int)strtoul(var + 2, &p, 16);
if (*p != 0) t = max_keys; // parse failed
}
else
t = max_keys; // invalid
}
if (t < 0 || t >= max_keys) {
lprintf("unhandled bind \"%s\"\n", var);
return;
}
// unbind old, but only when key is first encountered
if (t < 32 && binds == currentConfig.KeyBinds && !(keys_encountered & (1<<t))) {
binds[t] = 0;
keys_encountered |= 1<<t;
}
*/
}
#define try_joy_parse(num) { \
if (strncasecmp(var, "bind_joy"#num " ", 10) == 0) { \
keys_parse(var + 10, val, currentConfig.JoyBinds[num], joyKeyNames, 32); \
return; \
} \
}
static int get_numvar_num(const char *var)
@ -846,7 +789,7 @@ static void parse(const char *var, const char *val)
if (num >= 0 && num < IN_MAX_DEVS)
input_dev_map[num] = in_config_parse_dev(val);
else
printf("failed to parse: %s\n", var);
lprintf("config: failed to parse: %s\n", var);
return;
}
@ -855,13 +798,13 @@ static void parse(const char *var, const char *val)
const char *p = var + 4;
int num = get_numvar_num(p);
if (num < 0 || num >= IN_MAX_DEVS) {
printf("failed to parse: %s\n", var);
lprintf("config: failed to parse: %s\n", var);
return;
}
num = input_dev_map[num];
if (num < 0 || num >= IN_MAX_DEVS) {
printf("invalid device id: %s\n", var);
lprintf("config: invalid device id: %s\n", var);
return;
}
@ -871,13 +814,6 @@ static void parse(const char *var, const char *val)
return;
}
#if 0//PLAT_HAVE_JOY
try_joy_parse(0)
try_joy_parse(1)
try_joy_parse(2)
try_joy_parse(3)
#endif
for (t = 0; t < sizeof(cfg_opts) / sizeof(cfg_opts[0]) && ret == 0; t++)
{
me = cfg_opts[t];

View file

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "input.h"
#include "../linux/in_evdev.h"
@ -195,7 +196,7 @@ void in_set_blocking(int is_blocking)
menu_key_state = 0;
/* flush events */
in_update_keycode(NULL, NULL, 1);
in_update_keycode(NULL, NULL, 0);
}
/*
@ -204,7 +205,7 @@ void in_set_blocking(int is_blocking)
*/
int in_update_keycode(int *dev_id_out, int *is_down_out, int timeout_ms)
{
int result = 0, dev_id, is_down, result_menu;
int result = 0, dev_id = 0, is_down, result_menu;
#ifdef IN_EVDEV
void **data;
int i, id = 0, count = 0;
@ -229,7 +230,7 @@ int in_update_keycode(int *dev_id_out, int *is_down_out, int timeout_ms)
#endif
/* keep track of menu key state, to allow mixing
* in_update_keycode() and in_update_menu() calls */
* in_update_keycode() and in_menu_wait_any() calls */
result_menu = DRV(in_devices[dev_id].drv_id).menu_translate(result);
if (result_menu != 0) {
if (is_down)
@ -245,10 +246,8 @@ int in_update_keycode(int *dev_id_out, int *is_down_out, int timeout_ms)
return result;
}
/*
* same as above, only return bitfield of BTN_*
*/
int in_update_menu(int timeout_ms)
/* same as above, only return bitfield of PBTN_* */
int in_menu_wait_any(int timeout_ms)
{
int keys_old = menu_key_state;
@ -259,7 +258,7 @@ int in_update_menu(int timeout_ms)
code = in_update_keycode(&dev_id, &is_down, timeout_ms);
code = DRV(in_devices[dev_id].drv_id).menu_translate(code);
if (timeout_ms != 0)
if (timeout_ms >= 0)
break;
if (code == 0)
continue;
@ -270,6 +269,45 @@ int in_update_menu(int timeout_ms)
return menu_key_state;
}
/* wait for menu input, do autorepeat */
int in_menu_wait(int interesting)
{
static int inp_prev = 0;
static int repeats = 0, wait = 20;
int ret = 0, release = 0, i;
if (repeats == 2) wait = 3;
else if (repeats == 4) wait = 2;
else if (repeats == 6) wait = 1;
for (i = 0; i < wait; i++) {
ret = in_menu_wait_any(30);
if (ret != inp_prev) break;
if (i == 0) repeats++;
}
while (!(ret & interesting)) {
ret = in_menu_wait_any(-1);
release = 1;
}
if (release || ret != inp_prev) {
repeats = 0;
wait = 20;
}
if (wait > 6 && (ret & (PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT)))
wait = 6;
inp_prev = ret;
// we don't need diagonals in menus
if ((ret & PBTN_UP) && (ret & PBTN_LEFT)) ret &= ~PBTN_LEFT;
if ((ret & PBTN_UP) && (ret & PBTN_RIGHT)) ret &= ~PBTN_RIGHT;
if ((ret & PBTN_DOWN) && (ret & PBTN_LEFT)) ret &= ~PBTN_LEFT;
if ((ret & PBTN_DOWN) && (ret & PBTN_RIGHT)) ret &= ~PBTN_RIGHT;
return ret;
}
const int *in_get_dev_binds(int dev_id)
{
if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
@ -297,11 +335,13 @@ int in_get_dev_bind_count(int dev_id)
return in_bind_count(in_devices[dev_id].drv_id);
}
const char *in_get_dev_name(int dev_id)
const char *in_get_dev_name(int dev_id, int must_be_active)
{
if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
return NULL;
if (must_be_active && !in_devices[dev_id].probed)
return NULL;
return in_devices[dev_id].name;
}
@ -580,7 +620,7 @@ int main(void)
}
#else
while (1) {
ret = in_update_menu();
ret = in_menu_wait_any();
printf("%08x\n", ret);
}
#endif

View file

@ -28,7 +28,8 @@ void in_probe(void);
int in_update(void);
void in_set_blocking(int is_blocking);
int in_update_keycode(int *dev_id, int *is_down, int timeout_ms);
int in_update_menu(int timeout_ms);
int in_menu_wait_any(int timeout_ms);
int in_menu_wait(int interesting);
int in_get_dev_bind_count(int dev_id);
void in_config_start(void);
int in_config_parse_dev(const char *dev_name);
@ -39,5 +40,5 @@ void in_debug_dump(void);
const int *in_get_dev_binds(int dev_id);
const int *in_get_dev_def_binds(int dev_id);
const char *in_get_dev_name(int dev_id);
const char *in_get_dev_name(int dev_id, int must_be_active);
const char *in_get_key_name(int dev_id, int keycode);

View file

@ -13,6 +13,7 @@
#include "readpng.h"
#include "lprintf.h"
#include "common.h"
#include "input.h"
#include "emu.h"
@ -350,7 +351,7 @@ static void mplayer_loop(void)
while (1)
{
PDebugZ80Frame();
if (read_buttons_async(PBTN_NORTH)) break;
if (in_menu_wait_any(0) & PBTN_NORTH) break;
emu_waitSound();
}
@ -429,8 +430,8 @@ void debug_menu_loop(void)
}
menu_draw_end();
inp = read_buttons(PBTN_EAST|PBTN_SOUTH|PBTN_WEST|PBTN_NORTH|PBTN_L|PBTN_R|PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT);
if (inp & PBTN_SOUTH) return;
inp = in_menu_wait(PBTN_EAST|PBTN_MBACK|PBTN_WEST|PBTN_NORTH|PBTN_L|PBTN_R|PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT);
if (inp & PBTN_MBACK) return;
if (inp & PBTN_L) { mode--; if (mode < 0) mode = 3; }
if (inp & PBTN_R) { mode++; if (mode > 3) mode = 0; }
switch (mode)
@ -438,13 +439,13 @@ void debug_menu_loop(void)
case 0:
if (inp & PBTN_EAST) SekStepM68k();
if (inp & PBTN_NORTH) {
while (inp & PBTN_NORTH) inp = read_buttons_async(PBTN_NORTH);
while (inp & PBTN_NORTH) inp = in_menu_wait_any(-1);
mplayer_loop();
}
if ((inp & (PBTN_WEST|PBTN_LEFT)) == (PBTN_WEST|PBTN_LEFT)) {
mkdir("dumps", 0777);
PDebugDumpMem();
while (inp & PBTN_WEST) inp = read_buttons_async(PBTN_WEST);
while (inp & PBTN_WEST) inp = in_menu_wait_any(-1);
dumped = 1;
}
break;
@ -458,7 +459,7 @@ void debug_menu_loop(void)
PicoSkipFrame = 1;
PicoFrame();
PicoSkipFrame = 0;
while (inp & PBTN_EAST) inp = read_buttons_async(PBTN_EAST);
while (inp & PBTN_EAST) inp = in_menu_wait_any(-1);
}
break;
case 3: