comparison io.c @ 1488:f29bd94ffa76 nuklear_ui

Don't crash when keys are pressed before ROM is loaded
author Michael Pavone <pavone@retrodev.com>
date Sun, 26 Nov 2017 20:19:36 -0800
parents 001120e91fed
children 577253765192
comparison
equal deleted inserted replaced
1487:6a35815cc409 1488:f29bd94ffa76
358 } 358 }
359 } 359 }
360 360
361 void handle_keydown(int keycode, uint8_t scancode) 361 void handle_keydown(int keycode, uint8_t scancode)
362 { 362 {
363 if (!current_io) {
364 return;
365 }
363 int bucket = keycode >> 15 & 0xFFFF; 366 int bucket = keycode >> 15 & 0xFFFF;
364 int idx = keycode & 0x7FFF; 367 int idx = keycode & 0x7FFF;
365 keybinding * binding = bindings[bucket] ? bindings[bucket] + idx : NULL; 368 keybinding * binding = bindings[bucket] ? bindings[bucket] + idx : NULL;
366 if (binding && (!current_io->keyboard_captured || (binding->bind_type == BIND_UI && binding->subtype_a == UI_TOGGLE_KEYBOARD_CAPTURE))) { 369 if (binding && (!current_io->keyboard_captured || (binding->bind_type == BIND_UI && binding->subtype_a == UI_TOGGLE_KEYBOARD_CAPTURE))) {
367 handle_binding_down(binding); 370 handle_binding_down(binding);
562 } 565 }
563 } 566 }
564 567
565 void handle_keyup(int keycode, uint8_t scancode) 568 void handle_keyup(int keycode, uint8_t scancode)
566 { 569 {
570 if (!current_io) {
571 return;
572 }
567 int bucket = keycode >> 15 & 0xFFFF; 573 int bucket = keycode >> 15 & 0xFFFF;
568 int idx = keycode & 0x7FFF; 574 int idx = keycode & 0x7FFF;
569 keybinding * binding = bindings[bucket] ? bindings[bucket] + idx : NULL; 575 keybinding * binding = bindings[bucket] ? bindings[bucket] + idx : NULL;
570 if (binding && (!current_io->keyboard_captured || (binding->bind_type == BIND_UI && binding->subtype_a == UI_TOGGLE_KEYBOARD_CAPTURE))) { 576 if (binding && (!current_io->keyboard_captured || (binding->bind_type == BIND_UI && binding->subtype_a == UI_TOGGLE_KEYBOARD_CAPTURE))) {
571 handle_binding_up(binding); 577 handle_binding_up(binding);