Mercurial > repos > blastem
changeset 2181:0c723b8b637c
Add bindup and binddown debugger commands
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 13 Aug 2022 20:04:02 -0700 |
parents | b87658ba3b94 |
children | 2d7f8195be3b |
files | bindings.c bindings.h debug.c |
diffstat | 3 files changed, 63 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/bindings.c Sat Aug 13 19:39:42 2022 -0700 +++ b/bindings.c Sat Aug 13 20:04:02 2022 -0700 @@ -586,7 +586,7 @@ } } -int parse_binding_target(int device_num, char * target, tern_node * padbuttons, tern_node *mousebuttons, uint8_t * subtype_a, uint8_t * subtype_b) +int parse_binding_target(int device_num, const char * target, tern_node * padbuttons, tern_node *mousebuttons, uint8_t * subtype_a, uint8_t * subtype_b) { const int gpadslen = strlen("gamepads."); const int mouselen = strlen("mouse."); @@ -953,6 +953,29 @@ return mousebuttons; } +uint8_t bind_up(const char *target) +{ + keybinding bind; + bind.bind_type = parse_binding_target(0, target, get_pad_buttons(), get_mouse_buttons(), &bind.subtype_a, &bind.subtype_b); + if (!bind.bind_type) { + return 0; + } + handle_binding_up(&bind); + return 1; +} + +uint8_t bind_down(const char *target) +{ + keybinding bind; + bind.bind_type = parse_binding_target(0, target, get_pad_buttons(), get_mouse_buttons(), &bind.subtype_a, &bind.subtype_b); + if (!bind.bind_type) { + return 0; + } + handle_binding_down(&bind); + return 1; +} + + tern_node *get_binding_node_for_pad(int padnum) { if (padnum > MAX_JOYSTICKS) {
--- a/bindings.h Sat Aug 13 19:39:42 2022 -0700 +++ b/bindings.h Sat Aug 13 20:04:02 2022 -0700 @@ -22,6 +22,8 @@ void handle_mouse_moved(int mouse, uint16_t x, uint16_t y, int16_t deltax, int16_t deltay); void handle_mousedown(int mouse, int button); void handle_mouseup(int mouse, int button); +uint8_t bind_up(const char *target); +uint8_t bind_down(const char *target); void bindings_release_capture(void); void bindings_reacquire_capture(void);
--- a/debug.c Sat Aug 13 19:39:42 2022 -0700 +++ b/debug.c Sat Aug 13 20:04:02 2022 -0700 @@ -3,6 +3,7 @@ #include "68kinst.h" #include "segacd.h" #include "blastem.h" +#include "bindings.h" #include <ctype.h> #include <stdlib.h> #include <string.h> @@ -1310,6 +1311,22 @@ return 0; } +static uint8_t cmd_bindup(debug_root *root, char *format, char *param) +{ + if (!bind_up(param)) { + fprintf(stderr, "%s is not a valid binding name\n", param); + } + return 1; +} + +static uint8_t cmd_binddown(debug_root *root, char *format, char *param) +{ + if (!bind_down(param)) { + fprintf(stderr, "%s is not a valid binding name\n", param); + } + return 1; +} + static uint8_t cmd_delete_m68k(debug_root *root, char *format, int num_args, command_arg *args) { bp_def **this_bp = find_breakpoint_idx(&root->breakpoints, args[0].value); @@ -1699,6 +1716,26 @@ .impl = cmd_frames, .min_args = 1, .max_args = 1 + }, + { + .names = (const char *[]){ + "bindup", NULL + }, + .usage = "bindup NAME", + .desc = "Simulate a keyup for binding NAME", + .raw_impl = cmd_bindup, + .min_args = 1, + .max_args = 1 + }, + { + .names = (const char *[]){ + "binddown", NULL + }, + .usage = "bindown NAME", + .desc = "Simulate a keydown for binding NAME", + .raw_impl = cmd_binddown, + .min_args = 1, + .max_args = 1 } }; #define NUM_COMMON (sizeof(common_commands)/sizeof(*common_commands))