Skip to content

Commit

Permalink
New command line option to start emu with mouse captured (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
mooinglemur authored Nov 5, 2023
1 parent c224340 commit 9a1c29d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <dir>` 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 <dir>` 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.
Expand Down
1 change: 1 addition & 0 deletions src/glue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <app.prg>[,<load_addr>]\n");
printf("\tLoad application from the *host filesystem* into RAM,\n");
printf("\teven if an SD card is attached.\n");
Expand Down Expand Up @@ -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++;
Expand Down
23 changes: 13 additions & 10 deletions src/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9a1c29d

Please sign in to comment.