Mercurial > repos > blastem
comparison bindings.c @ 1680:326d1a601fb9
Fixed crash bug that could occur in a narrow window of time when loading a ROM
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 17 Jan 2019 10:00:24 -0800 |
parents | deaf31803b11 |
children | eda8df5bc74c |
comparison
equal
deleted
inserted
replaced
1679:deaf31803b11 | 1680:326d1a601fb9 |
---|---|
257 #define localtime_r(a,b) localtime(a) | 257 #define localtime_r(a,b) localtime(a) |
258 #endif | 258 #endif |
259 | 259 |
260 void handle_binding_up(keybinding * binding) | 260 void handle_binding_up(keybinding * binding) |
261 { | 261 { |
262 uint8_t allow_content_binds = content_binds_enabled && current_system; | |
262 switch(binding->bind_type) | 263 switch(binding->bind_type) |
263 { | 264 { |
264 case BIND_GAMEPAD: | 265 case BIND_GAMEPAD: |
265 if (content_binds_enabled && current_system->gamepad_up) { | 266 if (allow_content_binds && current_system->gamepad_up) { |
266 current_system->gamepad_up(current_system, binding->subtype_a, binding->subtype_b); | 267 current_system->gamepad_up(current_system, binding->subtype_a, binding->subtype_b); |
267 } | 268 } |
268 break; | 269 break; |
269 case BIND_MOUSE: | 270 case BIND_MOUSE: |
270 if (content_binds_enabled && current_system->mouse_up) { | 271 if (allow_content_binds && current_system->mouse_up) { |
271 current_system->mouse_up(current_system, binding->subtype_a, binding->subtype_b); | 272 current_system->mouse_up(current_system, binding->subtype_a, binding->subtype_b); |
272 } | 273 } |
273 break; | 274 break; |
274 case BIND_UI: | 275 case BIND_UI: |
275 switch (binding->subtype_a) | 276 switch (binding->subtype_a) |
276 { | 277 { |
277 case UI_DEBUG_MODE_INC: | 278 case UI_DEBUG_MODE_INC: |
278 if (content_binds_enabled) { | 279 if (allow_content_binds) { |
279 current_system->inc_debug_mode(current_system); | 280 current_system->inc_debug_mode(current_system); |
280 } | 281 } |
281 break; | 282 break; |
282 case UI_ENTER_DEBUGGER: | 283 case UI_ENTER_DEBUGGER: |
283 if (content_binds_enabled) { | 284 if (allow_content_binds) { |
284 current_system->enter_debugger = 1; | 285 current_system->enter_debugger = 1; |
285 } | 286 } |
286 break; | 287 break; |
287 case UI_SAVE_STATE: | 288 case UI_SAVE_STATE: |
288 if (content_binds_enabled) { | 289 if (allow_content_binds) { |
289 current_system->save_state = QUICK_SAVE_SLOT+1; | 290 current_system->save_state = QUICK_SAVE_SLOT+1; |
290 } | 291 } |
291 break; | 292 break; |
292 case UI_NEXT_SPEED: | 293 case UI_NEXT_SPEED: |
293 if (content_binds_enabled) { | 294 if (allow_content_binds) { |
294 current_speed++; | 295 current_speed++; |
295 if (current_speed >= num_speeds) { | 296 if (current_speed >= num_speeds) { |
296 current_speed = 0; | 297 current_speed = 0; |
297 } | 298 } |
298 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); | 299 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); |
299 current_system->set_speed_percent(current_system, speeds[current_speed]); | 300 current_system->set_speed_percent(current_system, speeds[current_speed]); |
300 } | 301 } |
301 break; | 302 break; |
302 case UI_PREV_SPEED: | 303 case UI_PREV_SPEED: |
303 if (content_binds_enabled) { | 304 if (allow_content_binds) { |
304 current_speed--; | 305 current_speed--; |
305 if (current_speed < 0) { | 306 if (current_speed < 0) { |
306 current_speed = num_speeds - 1; | 307 current_speed = num_speeds - 1; |
307 } | 308 } |
308 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); | 309 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); |
309 current_system->set_speed_percent(current_system, speeds[current_speed]); | 310 current_system->set_speed_percent(current_system, speeds[current_speed]); |
310 } | 311 } |
311 break; | 312 break; |
312 case UI_SET_SPEED: | 313 case UI_SET_SPEED: |
313 if (content_binds_enabled) { | 314 if (allow_content_binds) { |
314 if (binding->subtype_b < num_speeds) { | 315 if (binding->subtype_b < num_speeds) { |
315 current_speed = binding->subtype_b; | 316 current_speed = binding->subtype_b; |
316 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); | 317 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); |
317 current_system->set_speed_percent(current_system, speeds[current_speed]); | 318 current_system->set_speed_percent(current_system, speeds[current_speed]); |
318 } else { | 319 } else { |
326 mouse_captured = 0; | 327 mouse_captured = 0; |
327 render_relative_mouse(0); | 328 render_relative_mouse(0); |
328 } | 329 } |
329 break; | 330 break; |
330 case UI_TOGGLE_KEYBOARD_CAPTURE: | 331 case UI_TOGGLE_KEYBOARD_CAPTURE: |
331 if (content_binds_enabled && current_system->has_keyboard) { | 332 if (allow_content_binds && current_system->has_keyboard) { |
332 keyboard_captured = !keyboard_captured; | 333 keyboard_captured = !keyboard_captured; |
333 } | 334 } |
334 break; | 335 break; |
335 case UI_TOGGLE_FULLSCREEN: | 336 case UI_TOGGLE_FULLSCREEN: |
336 render_toggle_fullscreen(); | 337 render_toggle_fullscreen(); |
337 break; | 338 break; |
338 case UI_SOFT_RESET: | 339 case UI_SOFT_RESET: |
339 if (content_binds_enabled) { | 340 if (allow_content_binds) { |
340 current_system->soft_reset(current_system); | 341 current_system->soft_reset(current_system); |
341 } | 342 } |
342 break; | 343 break; |
343 case UI_RELOAD: | 344 case UI_RELOAD: |
344 if (content_binds_enabled) { | 345 if (allow_content_binds) { |
345 reload_media(); | 346 reload_media(); |
346 } | 347 } |
347 break; | 348 break; |
348 case UI_SMS_PAUSE: | 349 case UI_SMS_PAUSE: |
349 if (content_binds_enabled && current_system->gamepad_down) { | 350 if (allow_content_binds && current_system->gamepad_down) { |
350 current_system->gamepad_down(current_system, GAMEPAD_MAIN_UNIT, MAIN_UNIT_PAUSE); | 351 current_system->gamepad_down(current_system, GAMEPAD_MAIN_UNIT, MAIN_UNIT_PAUSE); |
351 } | 352 } |
352 break; | 353 break; |
353 case UI_SCREENSHOT: { | 354 case UI_SCREENSHOT: { |
354 if (content_binds_enabled) { | 355 if (allow_content_binds) { |
355 char *screenshot_base = tern_find_path(config, "ui\0screenshot_path\0", TVAL_PTR).ptrval; | 356 char *screenshot_base = tern_find_path(config, "ui\0screenshot_path\0", TVAL_PTR).ptrval; |
356 if (!screenshot_base) { | 357 if (!screenshot_base) { |
357 screenshot_base = "$HOME"; | 358 screenshot_base = "$HOME"; |
358 } | 359 } |
359 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir()); | 360 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir()); |
396 break; | 397 break; |
397 case UI_PLANE_DEBUG: | 398 case UI_PLANE_DEBUG: |
398 case UI_VRAM_DEBUG: | 399 case UI_VRAM_DEBUG: |
399 case UI_CRAM_DEBUG: | 400 case UI_CRAM_DEBUG: |
400 case UI_COMPOSITE_DEBUG: | 401 case UI_COMPOSITE_DEBUG: |
401 if (content_binds_enabled) { | 402 if (allow_content_binds) { |
402 vdp_context *vdp = NULL; | 403 vdp_context *vdp = NULL; |
403 if (current_system->type == SYSTEM_GENESIS) { | 404 if (current_system->type == SYSTEM_GENESIS) { |
404 genesis_context *gen = (genesis_context *)current_system; | 405 genesis_context *gen = (genesis_context *)current_system; |
405 vdp = gen->vdp; | 406 vdp = gen->vdp; |
406 } else if (current_system->type == SYSTEM_SMS) { | 407 } else if (current_system->type == SYSTEM_SMS) { |