From 9a1c29d9125e85b549e0adf1d0762963a9b56888 Mon Sep 17 00:00:00 2001 From: mooinglemur Date: Sat, 4 Nov 2023 20:30:22 -0700 Subject: [PATCH] New command line option to start emu with mouse captured (#190) --- README.md | 1 + src/glue.h | 1 + src/main.c | 7 +++++++ src/video.c | 23 +++++++++++++---------- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index fa255eb..e5ea755 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ When starting `x16emu` without arguments, it will pick up the system ROM (`rom.b * `-nvram` lets you specify a 64 byte file for the system's non-volatile RAM. If it does not exist, it will be created once the NVRAM is modified. * `-keymap` tells the KERNAL to switch to a specific keyboard layout. Use it without an argument to view the supported layouts. * `-noemucmdkeys` Disable emulator command keys. +* `-capture` starts the emulator with the mouse/keyboard captured * `-sdcard` lets you specify an SD card image (partition table + FAT32). Without this option, drive 8 will interface to the current directory on the host. * `-fsroot ` specifies a file system root for the HostFS interface. This lets you save and load files without an SD card image. (As of R42, this is the preferred method.) Default is the current working directory. * `-startin ` specify the host filesystem directory path that the emulated filesystem starts in. Default is the current working directory if it lies within the hierarchy of fsroot, otherwise it defaults to fsroot itself. diff --git a/src/glue.h b/src/glue.h index d257c88..ab2a648 100644 --- a/src/glue.h +++ b/src/glue.h @@ -71,6 +71,7 @@ extern uint8_t *fsroot_path; extern uint8_t *startin_path; extern uint8_t keymap; extern bool warp_mode; +extern bool grab_mouse; extern bool testbench; extern bool has_via2; extern uint32_t host_sample_rate; diff --git a/src/main.c b/src/main.c index 6943e0c..dc1b1c9 100644 --- a/src/main.c +++ b/src/main.c @@ -103,6 +103,7 @@ bool dump_ram = true; bool dump_bank = true; bool dump_vram = false; bool warp_mode = false; +bool grab_mouse = false; echo_mode_t echo_mode; bool save_on_exit = true; bool disable_emu_cmd_keys = false; @@ -381,6 +382,8 @@ usage() printf("\totherwise it defaults to fsroot itself.\n"); printf("-noemucmdkeys\n"); printf("\tDisable emulator command keys.\n"); + printf("-capture\n"); + printf("\tStart emulator with mouse/keyboard captured.\n"); printf("-prg [,]\n"); printf("\tLoad application from the *host filesystem* into RAM,\n"); printf("\teven if an SD card is attached.\n"); @@ -896,6 +899,10 @@ main(int argc, char **argv) argc--; argv++; disable_emu_cmd_keys = true; + } else if (!strcmp(argv[0], "-capture")) { + argc--; + argv++; + grab_mouse = true; } else if (!strcmp(argv[0], "-via2")) { argc--; argv++; diff --git a/src/video.c b/src/video.c index bdab7fe..ddb32a8 100644 --- a/src/video.c +++ b/src/video.c @@ -201,6 +201,16 @@ static void video_space_read_range(uint8_t* dest, uint32_t address, uint32_t siz static void refresh_palette(); +void +mousegrab_toggle() { + mouse_grabbed = !mouse_grabbed; + SDL_SetWindowGrab(window, mouse_grabbed); + SDL_SetRelativeMouseMode(mouse_grabbed); + SDL_ShowCursor((mouse_grabbed || kernal_mouse_enabled) ? SDL_DISABLE : SDL_ENABLE); + sprintf(window_title, WINDOW_TITLE "%s", mouse_grabbed ? MOUSE_GRAB_MSG : ""); + video_update_title(window_title); +} + void video_reset() { @@ -358,6 +368,9 @@ video_init(int window_scale, float screen_x_scale, char *quality, bool fullscree DEBUGInitUI(renderer); } + if (grab_mouse && !mouse_grabbed) + mousegrab_toggle(); + return true; } @@ -531,16 +544,6 @@ struct video_sprite_properties uint16_t palette_offset; }; -void -mousegrab_toggle() { - mouse_grabbed = !mouse_grabbed; - SDL_SetWindowGrab(window, mouse_grabbed); - SDL_SetRelativeMouseMode(mouse_grabbed); - SDL_ShowCursor((mouse_grabbed || kernal_mouse_enabled) ? SDL_DISABLE : SDL_ENABLE); - sprintf(window_title, WINDOW_TITLE "%s", mouse_grabbed ? MOUSE_GRAB_MSG : ""); - video_update_title(window_title); -} - #ifndef __EMSCRIPTEN__ static void screenshot(void)