From 6123feffe48fa9805b8c6b8dabf8cd5970ad9a31 Mon Sep 17 00:00:00 2001 From: Sunguk Lee Date: Sun, 18 Sep 2016 15:21:10 +0900 Subject: [PATCH 1/2] Refactor input identifier of map --- src/input/mapping.c | 5 +-- src/input/mapping.h | 11 +++--- src/input/vita.c | 82 ++++++++++++++++++++++++--------------------- src/input/vita.h | 15 +++++---- 4 files changed, 61 insertions(+), 52 deletions(-) diff --git a/src/input/mapping.c b/src/input/mapping.c index 727fc417..cce7ff08 100644 --- a/src/input/mapping.c +++ b/src/input/mapping.c @@ -23,13 +23,14 @@ #include #include -#define write_config(fd, key, value) fprintf(fd, "%s = %hd\n", key, value) +#define write_config(fd, key, value) fprintf(fd, "%s = %x\n", key, value) #define write_config_bool(fd, key, value) fprintf(fd, "%s = %s\n", key, value?"true":"false"); void mapping_load(char* fileName, struct mapping* map) { FILE* fd = fopen(fileName, "r"); if (fd == NULL) { printf("Can't open mapping file: %s\n", fileName); + return; } char *line = NULL; @@ -37,7 +38,7 @@ void mapping_load(char* fileName, struct mapping* map) { while (__getline(&line, &len, fd) != -1) { char key[256], value[256]; if (sscanf(line, "%s = %s", &key, &value) == 2) { - long int_value = strtol(value, NULL, 10); + long int_value = strtol(value, NULL, 16); if (strcmp("abs_x", key) == 0) map->abs_x = int_value; else if (strcmp("abs_y", key) == 0) diff --git a/src/input/mapping.h b/src/input/mapping.h index f62d1b13..605e5ca0 100644 --- a/src/input/mapping.h +++ b/src/input/mapping.h @@ -17,6 +17,7 @@ * along with Moonlight; if not, see . */ +#include #include struct mapping { @@ -31,12 +32,12 @@ struct mapping { short abs_dpad_x, abs_dpad_y; bool reverse_dpad_x, reverse_dpad_y; - short btn_south, btn_east, btn_north, btn_west; - short btn_select, btn_start, btn_mode; - short btn_thumbl, btn_thumbr; - short btn_tl, btn_tr, btn_tl2, btn_tr2; + uint32_t btn_south, btn_east, btn_north, btn_west; + uint32_t btn_select, btn_start, btn_mode; + uint32_t btn_thumbl, btn_thumbr; + uint32_t btn_tl, btn_tr, btn_tl2, btn_tr2; - short btn_dpad_up, btn_dpad_down, btn_dpad_left, btn_dpad_right; + uint32_t btn_dpad_up, btn_dpad_down, btn_dpad_left, btn_dpad_right; }; void mapping_load(char* fileName, struct mapping* map); diff --git a/src/input/vita.c b/src/input/vita.c index 9cd70e12..c53cb4d8 100644 --- a/src/input/vita.c +++ b/src/input/vita.c @@ -184,13 +184,20 @@ static short pad_value(SceCtrlData pad, int sec) { return (short) (value * 256 - (1 << 15) + 128); } -bool check_input(short identifier, SceCtrlData pad, SceTouchData screen) { - if (identifier >= TOUCHSEC_NORTHWEST && identifier <= TOUCHSEC_SOUTHEAST) { - return check_touch_sector(screen, identifier) != -1; - } else { - identifier = identifier + 1; - return pad.buttons & identifier; +bool check_input(uint32_t identifier, SceCtrlData pad, SceTouchData screen) { + uint32_t type = identifier & INPUT_TYPE_MASK; + int value = identifier & INPUT_VALUE_MASK; + + switch (type) { + case INPUT_TYPE_TOUCHSCREEN: + if (value < TOUCHSEC_NORTHWEST || value > TOUCHSEC_SOUTHEAST) { + return false; + } + return check_touch_sector(screen, value) != -1; + case INPUT_TYPE_GAMEPAD: + return pad.buttons & value; } + return false; } static int special_input_config_code(short identifier) { @@ -288,28 +295,27 @@ void vitainput_process(void) { input_data input = {0}; // buttons - INPUT(map.btn_dpad_up, UP_FLAG); - INPUT(map.btn_dpad_up, UP_FLAG); - INPUT(map.btn_dpad_left, LEFT_FLAG); - INPUT(map.btn_dpad_down, DOWN_FLAG); + INPUT(map.btn_dpad_up, UP_FLAG); + INPUT(map.btn_dpad_left, LEFT_FLAG); + INPUT(map.btn_dpad_down, DOWN_FLAG); INPUT(map.btn_dpad_right, RIGHT_FLAG); - INPUT(map.btn_start, PLAY_FLAG); - INPUT(map.btn_select, BACK_FLAG); + INPUT(map.btn_start, PLAY_FLAG); + INPUT(map.btn_select, BACK_FLAG); - INPUT(map.btn_north, Y_FLAG); - INPUT(map.btn_east, B_FLAG); - INPUT(map.btn_south, A_FLAG); - INPUT(map.btn_west, X_FLAG); + INPUT(map.btn_north, Y_FLAG); + INPUT(map.btn_east, B_FLAG); + INPUT(map.btn_south, A_FLAG); + INPUT(map.btn_west, X_FLAG); - INPUT(map.btn_tl2, LS_CLK_FLAG); - INPUT(map.btn_tr2, RS_CLK_FLAG); + INPUT(map.btn_tl2, LS_CLK_FLAG); + INPUT(map.btn_tr2, RS_CLK_FLAG); - INPUT(map.btn_thumbl, LB_FLAG); - INPUT(map.btn_thumbr, RB_FLAG); + INPUT(map.btn_thumbl, LB_FLAG); + INPUT(map.btn_thumbr, RB_FLAG); // AXIS - input.left_trigger = CHECK_INPUT(map.btn_tl) ? 0xff : 0; + input.left_trigger = CHECK_INPUT(map.btn_tl) ? 0xff : 0; input.right_trigger = CHECK_INPUT(map.btn_tr) ? 0xff : 0; input.lx = pad_value(pad, map.abs_x), @@ -442,23 +448,23 @@ void vitainput_config(CONFIGURATION config) { map.abs_rx = 2; map.abs_ry = 3; - map.btn_south = SCE_CTRL_CROSS - 1; - map.btn_east = SCE_CTRL_CIRCLE - 1; - map.btn_north = SCE_CTRL_TRIANGLE - 1; - map.btn_west = SCE_CTRL_SQUARE - 1; - map.btn_select = SCE_CTRL_SELECT - 1; - map.btn_start = SCE_CTRL_START - 1; - map.btn_thumbl = SCE_CTRL_LTRIGGER - 1; - map.btn_thumbr = SCE_CTRL_RTRIGGER - 1; - map.btn_dpad_up = SCE_CTRL_UP - 1; - map.btn_dpad_down = SCE_CTRL_DOWN - 1; - map.btn_dpad_left = SCE_CTRL_LEFT - 1; - map.btn_dpad_right = SCE_CTRL_RIGHT - 1; - - map.btn_tl = TOUCHSEC_NORTHWEST; - map.btn_tr = TOUCHSEC_NORTHEAST; - map.btn_tl2 = TOUCHSEC_SOUTHWEST; - map.btn_tr2 = TOUCHSEC_SOUTHEAST; + map.btn_south = SCE_CTRL_CROSS | INPUT_TYPE_GAMEPAD; + map.btn_east = SCE_CTRL_CIRCLE | INPUT_TYPE_GAMEPAD; + map.btn_north = SCE_CTRL_TRIANGLE | INPUT_TYPE_GAMEPAD; + map.btn_west = SCE_CTRL_SQUARE | INPUT_TYPE_GAMEPAD; + map.btn_select = SCE_CTRL_SELECT | INPUT_TYPE_GAMEPAD; + map.btn_start = SCE_CTRL_START | INPUT_TYPE_GAMEPAD; + map.btn_thumbl = SCE_CTRL_LTRIGGER | INPUT_TYPE_GAMEPAD; + map.btn_thumbr = SCE_CTRL_RTRIGGER | INPUT_TYPE_GAMEPAD; + map.btn_dpad_up = SCE_CTRL_UP | INPUT_TYPE_GAMEPAD; + map.btn_dpad_down = SCE_CTRL_DOWN | INPUT_TYPE_GAMEPAD; + map.btn_dpad_left = SCE_CTRL_LEFT | INPUT_TYPE_GAMEPAD; + map.btn_dpad_right = SCE_CTRL_RIGHT | INPUT_TYPE_GAMEPAD; + + map.btn_tl = TOUCHSEC_NORTHWEST | INPUT_TYPE_TOUCHSCREEN; + map.btn_tr = TOUCHSEC_NORTHEAST | INPUT_TYPE_TOUCHSCREEN; + map.btn_tl2 = TOUCHSEC_SOUTHWEST | INPUT_TYPE_TOUCHSCREEN; + map.btn_tr2 = TOUCHSEC_SOUTHEAST | INPUT_TYPE_TOUCHSCREEN; if (config.mapping) { char config_path[256]; diff --git a/src/input/vita.h b/src/input/vita.h index 7000c3f4..2cc3b052 100644 --- a/src/input/vita.h +++ b/src/input/vita.h @@ -45,14 +45,15 @@ enum { RIGHT_TRIGGER } PadSection; -#define INPUT_TYPE_MASK 0xffff0000 -#define INPUT_VALUE_MASK 0x0000ffff +#define INPUT_TYPE_MASK 0xfff00000 +#define INPUT_VALUE_MASK 0x000fffff -#define INPUT_TYPE_KEYBOARD 0x00000000 -#define INPUT_TYPE_SPECIAL 0x00010000 -#define INPUT_TYPE_MOUSE 0x00020000 -#define INPUT_TYPE_GAMEPAD 0x00030000 -#define INPUT_TYPE_AXIS 0x00040000 +#define INPUT_TYPE_KEYBOARD 0x00000000 +#define INPUT_TYPE_SPECIAL 0x00100000 +#define INPUT_TYPE_MOUSE 0x00200000 +#define INPUT_TYPE_GAMEPAD 0x00300000 +#define INPUT_TYPE_AXIS 0x00400000 +#define INPUT_TYPE_TOUCHSCREEN 0x00500000 enum { INPUT_SPECIAL_KEY_PAUSE From e2c8433f7b18f4e14262482bafbfa8404ee2bcec Mon Sep 17 00:00:00 2001 From: Sunguk Lee Date: Tue, 20 Sep 2016 20:49:49 +0900 Subject: [PATCH 2/2] Update mapping file --- mappings/vita.conf | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/mappings/vita.conf b/mappings/vita.conf index 4fb25e19..a5a50091 100644 --- a/mappings/vita.conf +++ b/mappings/vita.conf @@ -12,35 +12,35 @@ abs_rx = 2 abs_ry = 3 # cross -btn_south = 16383 +btn_south = 304000 # circle -btn_east = 8191 +btn_east = 302000 # triangle -btn_north = 4095 +btn_north = 301000 # square -btn_west = 32767 +btn_west = 308000 # select -btn_select = 0 +btn_select = 300001 # start -btn_start = 7 +btn_start = 300008 # dpad -btn_dpad_up = 15 -btn_dpad_down = 63 -btn_dpad_left = 127 -btn_dpad_right = 31 +btn_dpad_up = 300010 +btn_dpad_down = 300040 +btn_dpad_left = 300080 +btn_dpad_right = 300020 # LB -btn_thumbl = 255 +btn_thumbl = 300100 # RB -btn_thumbr = 511 +btn_thumbr = 300200 # LT -btn_tl = 600 +btn_tl = 500258 # RT -btn_tr = 601 +btn_tr = 500259 # LS -btn_tl2 = 602 +btn_tl2 = 50025a # RS -btn_tr2 = 603 +btn_tr2 = 50025b # not used btn_mode = -1