comparison io.c @ 971:e28f365605da

Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
author Michael Pavone <pavone@retrodev.com>
date Thu, 21 Apr 2016 22:08:26 -0700
parents 750995b587a0
children 580a806aef6a
comparison
equal deleted inserted replaced
970:e2d7067ea2d8 971:e28f365605da
106 106
107 static keybinding * bindings[0x10000]; 107 static keybinding * bindings[0x10000];
108 static joystick joysticks[MAX_JOYSTICKS]; 108 static joystick joysticks[MAX_JOYSTICKS];
109 static mousebinding mice[MAX_MICE]; 109 static mousebinding mice[MAX_MICE];
110 const uint8_t dpadbits[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT}; 110 const uint8_t dpadbits[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT};
111 static mouse_modes mouse_mode;
112 static char mouse_captured;
113 111
114 void bind_key(int keycode, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value) 112 void bind_key(int keycode, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value)
115 { 113 {
116 int bucket = keycode >> 15 & 0xFFFF; 114 int bucket = keycode >> 15 & 0xFFFF;
117 if (!bindings[bucket]) { 115 if (!bindings[bucket]) {
276 handle_binding_down(binding); 274 handle_binding_down(binding);
277 } 275 }
278 276
279 void handle_mousedown(int mouse, int button) 277 void handle_mousedown(int mouse, int button)
280 { 278 {
281 if (mouse_mode == MOUSE_CAPTURE && !mouse_captured) { 279 if (genesis->mouse_mode == MOUSE_CAPTURE && !genesis->mouse_captured) {
282 mouse_captured = 1; 280 genesis->mouse_captured = 1;
283 render_relative_mouse(1); 281 render_relative_mouse(1);
284 return; 282 return;
285 } 283 }
286 if (mouse >= MAX_MICE || button > MAX_MOUSE_BUTTONS || button <= 0) { 284 if (mouse >= MAX_MICE || button > MAX_MOUSE_BUTTONS || button <= 0) {
287 return; 285 return;
376 printf("Setting speed to %d\n", speeds[current_speed]); 374 printf("Setting speed to %d\n", speeds[current_speed]);
377 set_speed_percent(genesis, binding->value); 375 set_speed_percent(genesis, binding->value);
378 } 376 }
379 break; 377 break;
380 case UI_RELEASE_MOUSE: 378 case UI_RELEASE_MOUSE:
381 if (mouse_captured) { 379 if (genesis->mouse_captured) {
382 mouse_captured = 0; 380 genesis->mouse_captured = 0;
383 render_relative_mouse(0); 381 render_relative_mouse(0);
384 } 382 }
385 break; 383 break;
386 case UI_EXIT: 384 case UI_EXIT:
387 genesis->m68k->should_return = 1; 385 genesis->m68k->should_return = 1;
441 { 439 {
442 if (mouse >= MAX_MICE || !mice[mouse].motion_port) { 440 if (mouse >= MAX_MICE || !mice[mouse].motion_port) {
443 return; 441 return;
444 } 442 }
445 //TODO: relative mode 443 //TODO: relative mode
446 switch(mouse_mode) 444 switch(genesis->mouse_mode)
447 { 445 {
448 case MOUSE_ABSOLUTE: { 446 case MOUSE_ABSOLUTE: {
449 float scale_x = 640.0 / ((float)render_width()); 447 float scale_x = 640.0 / ((float)render_width());
450 float scale_y = 480.0 / ((float)render_height()); 448 float scale_y = 480.0 / ((float)render_height());
451 float scale = scale_x > scale_y ? scale_y : scale_x; 449 float scale = scale_x > scale_y ? scale_y : scale_x;
457 mice[mouse].motion_port->device.mouse.cur_x += deltax; 455 mice[mouse].motion_port->device.mouse.cur_x += deltax;
458 mice[mouse].motion_port->device.mouse.cur_y += deltay; 456 mice[mouse].motion_port->device.mouse.cur_y += deltay;
459 break; 457 break;
460 } 458 }
461 case MOUSE_CAPTURE: { 459 case MOUSE_CAPTURE: {
462 if (mouse_captured) { 460 if (genesis->mouse_captured) {
463 mice[mouse].motion_port->device.mouse.cur_x += deltax; 461 mice[mouse].motion_port->device.mouse.cur_x += deltax;
464 mice[mouse].motion_port->device.mouse.cur_y += deltay; 462 mice[mouse].motion_port->device.mouse.cur_y += deltay;
465 } 463 }
466 } 464 }
467 } 465 }
695 static void cleanup_sockfile() 693 static void cleanup_sockfile()
696 { 694 {
697 unlink(sockfile_name); 695 unlink(sockfile_name);
698 } 696 }
699 697
700 void setup_io_devices(tern_node * config, rom_info *rom, io_port * ports) 698 void setup_io_devices(tern_node * config, rom_info *rom, genesis_context *gen)
701 { 699 {
700 io_port * ports = gen->ports;
702 tern_node *io_nodes = tern_get_node(tern_find_path(config, "io\0devices\0")); 701 tern_node *io_nodes = tern_get_node(tern_find_path(config, "io\0devices\0"));
703 char * io_1 = rom->port1_override ? rom->port1_override : tern_find_ptr(io_nodes, "1"); 702 char * io_1 = rom->port1_override ? rom->port1_override : tern_find_ptr(io_nodes, "1");
704 char * io_2 = rom->port2_override ? rom->port2_override : tern_find_ptr(io_nodes, "2"); 703 char * io_2 = rom->port2_override ? rom->port2_override : tern_find_ptr(io_nodes, "2");
705 char * io_ext = rom->ext_override ? rom->ext_override : tern_find_ptr(io_nodes, "ext"); 704 char * io_ext = rom->ext_override ? rom->ext_override : tern_find_ptr(io_nodes, "ext");
706 705
707 process_device(io_1, ports); 706 process_device(io_1, ports);
708 process_device(io_2, ports+1); 707 process_device(io_2, ports+1);
709 process_device(io_ext, ports+2); 708 process_device(io_ext, ports+2);
710 709
711 if (render_fullscreen()) { 710 if (render_fullscreen()) {
712 mouse_mode = MOUSE_RELATIVE; 711 gen->mouse_mode = MOUSE_RELATIVE;
713 render_relative_mouse(1); 712 render_relative_mouse(1);
714 } else { 713 } else {
715 if (rom->mouse_mode && !strcmp(rom->mouse_mode, "absolute")) { 714 if (rom->mouse_mode && !strcmp(rom->mouse_mode, "absolute")) {
716 mouse_mode = MOUSE_ABSOLUTE; 715 gen->mouse_mode = MOUSE_ABSOLUTE;
717 } else { 716 } else {
718 mouse_mode = MOUSE_CAPTURE; 717 gen->mouse_mode = MOUSE_CAPTURE;
719 } 718 }
720 } 719 }
721 720
722 for (int i = 0; i < 3; i++) 721 for (int i = 0; i < 3; i++)
723 { 722 {
1072 port->device.mouse.tr_counter++; 1071 port->device.mouse.tr_counter++;
1073 port->device.mouse.ready_cycle = CYCLE_NEVER; 1072 port->device.mouse.ready_cycle = CYCLE_NEVER;
1074 if (port->device.mouse.tr_counter == 3) { 1073 if (port->device.mouse.tr_counter == 3) {
1075 port->device.mouse.latched_x = port->device.mouse.cur_x; 1074 port->device.mouse.latched_x = port->device.mouse.cur_x;
1076 port->device.mouse.latched_y = port->device.mouse.cur_y; 1075 port->device.mouse.latched_y = port->device.mouse.cur_y;
1077 if (mouse_mode == MOUSE_ABSOLUTE) { 1076 if (genesis->mouse_mode == MOUSE_ABSOLUTE) {
1078 //avoid overflow in absolute mode 1077 //avoid overflow in absolute mode
1079 int deltax = port->device.mouse.latched_x - port->device.mouse.last_read_x; 1078 int deltax = port->device.mouse.latched_x - port->device.mouse.last_read_x;
1080 if (abs(deltax) > 255) { 1079 if (abs(deltax) > 255) {
1081 port->device.mouse.latched_x = port->device.mouse.last_read_x + (deltax > 0 ? 255 : -255); 1080 port->device.mouse.latched_x = port->device.mouse.last_read_x + (deltax > 0 ? 255 : -255);
1082 } 1081 }