summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2016-04-21 22:08:26 -0700
committerMichael Pavone <pavone@retrodev.com>2016-04-21 22:08:26 -0700
commitd5c369a7c040e96e2067ebda45d9e1b9ad018e63 (patch)
tree815e28c01fd1ca72fabc06ea45811a7be3287ab2
parent19fe07ac64063803e053a111c3a6b5f47bb3cffe (diff)
Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
-rw-r--r--blastem.c2
-rw-r--r--blastem.h2
-rw-r--r--io.c25
-rw-r--r--io.h4
4 files changed, 18 insertions, 15 deletions
diff --git a/blastem.c b/blastem.c
index 7676eda..ecf8da0 100644
--- a/blastem.c
+++ b/blastem.c
@@ -878,7 +878,7 @@ genesis_context *alloc_init_genesis(rom_info *rom, int fps, uint32_t ym_opts)
gen->cart = cart;
gen->work_ram = ram;
gen->zram = z80_ram;
- setup_io_devices(config, rom, gen->ports);
+ setup_io_devices(config, rom, gen);
gen->save_type = rom->save_type;
gen->save_type = rom->save_type;
diff --git a/blastem.h b/blastem.h
index ea9e86a..70c5134 100644
--- a/blastem.h
+++ b/blastem.h
@@ -49,6 +49,8 @@ struct genesis_context {
uint8_t bus_busy;
uint8_t should_exit;
uint8_t save_state;
+ uint8_t mouse_mode;
+ uint8_t mouse_captured;
eeprom_state eeprom;
};
diff --git a/io.c b/io.c
index aaa38cf..b7e39b9 100644
--- a/io.c
+++ b/io.c
@@ -108,8 +108,6 @@ static keybinding * bindings[0x10000];
static joystick joysticks[MAX_JOYSTICKS];
static mousebinding mice[MAX_MICE];
const uint8_t dpadbits[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT};
-static mouse_modes mouse_mode;
-static char mouse_captured;
void bind_key(int keycode, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value)
{
@@ -278,8 +276,8 @@ void handle_joydown(int joystick, int button)
void handle_mousedown(int mouse, int button)
{
- if (mouse_mode == MOUSE_CAPTURE && !mouse_captured) {
- mouse_captured = 1;
+ if (genesis->mouse_mode == MOUSE_CAPTURE && !genesis->mouse_captured) {
+ genesis->mouse_captured = 1;
render_relative_mouse(1);
return;
}
@@ -378,8 +376,8 @@ void handle_binding_up(keybinding * binding)
}
break;
case UI_RELEASE_MOUSE:
- if (mouse_captured) {
- mouse_captured = 0;
+ if (genesis->mouse_captured) {
+ genesis->mouse_captured = 0;
render_relative_mouse(0);
}
break;
@@ -443,7 +441,7 @@ void handle_mouse_moved(int mouse, uint16_t x, uint16_t y, int16_t deltax, int16
return;
}
//TODO: relative mode
- switch(mouse_mode)
+ switch(genesis->mouse_mode)
{
case MOUSE_ABSOLUTE: {
float scale_x = 640.0 / ((float)render_width());
@@ -459,7 +457,7 @@ void handle_mouse_moved(int mouse, uint16_t x, uint16_t y, int16_t deltax, int16
break;
}
case MOUSE_CAPTURE: {
- if (mouse_captured) {
+ if (genesis->mouse_captured) {
mice[mouse].motion_port->device.mouse.cur_x += deltax;
mice[mouse].motion_port->device.mouse.cur_y += deltay;
}
@@ -697,8 +695,9 @@ static void cleanup_sockfile()
unlink(sockfile_name);
}
-void setup_io_devices(tern_node * config, rom_info *rom, io_port * ports)
+void setup_io_devices(tern_node * config, rom_info *rom, genesis_context *gen)
{
+ io_port * ports = gen->ports;
tern_node *io_nodes = tern_get_node(tern_find_path(config, "io\0devices\0"));
char * io_1 = rom->port1_override ? rom->port1_override : tern_find_ptr(io_nodes, "1");
char * io_2 = rom->port2_override ? rom->port2_override : tern_find_ptr(io_nodes, "2");
@@ -709,13 +708,13 @@ void setup_io_devices(tern_node * config, rom_info *rom, io_port * ports)
process_device(io_ext, ports+2);
if (render_fullscreen()) {
- mouse_mode = MOUSE_RELATIVE;
+ gen->mouse_mode = MOUSE_RELATIVE;
render_relative_mouse(1);
} else {
if (rom->mouse_mode && !strcmp(rom->mouse_mode, "absolute")) {
- mouse_mode = MOUSE_ABSOLUTE;
+ gen->mouse_mode = MOUSE_ABSOLUTE;
} else {
- mouse_mode = MOUSE_CAPTURE;
+ gen->mouse_mode = MOUSE_CAPTURE;
}
}
@@ -1074,7 +1073,7 @@ void mouse_check_ready(io_port *port, uint32_t current_cycle)
if (port->device.mouse.tr_counter == 3) {
port->device.mouse.latched_x = port->device.mouse.cur_x;
port->device.mouse.latched_y = port->device.mouse.cur_y;
- if (mouse_mode == MOUSE_ABSOLUTE) {
+ if (genesis->mouse_mode == MOUSE_ABSOLUTE) {
//avoid overflow in absolute mode
int deltax = port->device.mouse.latched_x - port->device.mouse.last_read_x;
if (abs(deltax) > 255) {
diff --git a/io.h b/io.h
index c61949f..e020dc7 100644
--- a/io.h
+++ b/io.h
@@ -68,9 +68,11 @@ enum {
IO_READ
};
+typedef struct genesis_context genesis_context;
+
void set_keybindings(io_port *ports);
void map_all_bindings(io_port *ports);
-void setup_io_devices(tern_node * config, rom_info *rom, io_port * ports);
+void setup_io_devices(tern_node * config, rom_info *rom, genesis_context * gen);
void io_adjust_cycles(io_port * pad, uint32_t current_cycle, uint32_t deduction);
void io_data_write(io_port * pad, uint8_t value, uint32_t current_cycle);
uint8_t io_data_read(io_port * pad, uint32_t current_cycle);