comparison bindings.c @ 1931:374a5ae694e8 mame_interp

Merge from default
author Michael Pavone <pavone@retrodev.com>
date Sat, 18 Apr 2020 11:42:53 -0700
parents 508522f08e4d
children 81df9aa2de9b
comparison
equal deleted inserted replaced
1843:13abdc98379e 1931:374a5ae694e8
34 UI_TOGGLE_FULLSCREEN, 34 UI_TOGGLE_FULLSCREEN,
35 UI_SOFT_RESET, 35 UI_SOFT_RESET,
36 UI_RELOAD, 36 UI_RELOAD,
37 UI_SMS_PAUSE, 37 UI_SMS_PAUSE,
38 UI_SCREENSHOT, 38 UI_SCREENSHOT,
39 UI_VGM_LOG,
39 UI_EXIT, 40 UI_EXIT,
40 UI_PLANE_DEBUG, 41 UI_PLANE_DEBUG,
41 UI_VRAM_DEBUG, 42 UI_VRAM_DEBUG,
42 UI_CRAM_DEBUG, 43 UI_CRAM_DEBUG,
43 UI_COMPOSITE_DEBUG 44 UI_COMPOSITE_DEBUG
255 static uint8_t mouse_captured; 256 static uint8_t mouse_captured;
256 257
257 #ifdef _WIN32 258 #ifdef _WIN32
258 #define localtime_r(a,b) localtime(a) 259 #define localtime_r(a,b) localtime(a)
259 #endif 260 #endif
261
262 char *get_content_config_path(char *config_path, char *config_template, char *default_name)
263 {
264 char *base = tern_find_path(config, config_path, TVAL_PTR).ptrval;
265 if (!base) {
266 base = "$HOME";
267 }
268 const system_media *media = current_media();
269 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir());
270 vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir());
271 vars = tern_insert_ptr(vars, "USERDATA", (char *)get_userdata_dir());
272 vars = tern_insert_ptr(vars, "ROMNAME", media->name);
273 vars = tern_insert_ptr(vars, "ROMDIR", media->dir);
274 base = replace_vars(base, vars, 1);
275 tern_free(vars);
276 ensure_dir_exists(base);
277 time_t now = time(NULL);
278 struct tm local_store;
279 char fname_part[256];
280 char *template = tern_find_path(config, config_template, TVAL_PTR).ptrval;
281 if (template) {
282 vars = tern_insert_ptr(NULL, "ROMNAME", media->name);
283 template = replace_vars(template, vars, 0);
284 } else {
285 template = strdup(default_name);
286 }
287 strftime(fname_part, sizeof(fname_part), template, localtime_r(&now, &local_store));
288 char const *parts[] = {base, PATH_SEP, fname_part};
289 char *path = alloc_concat_m(3, parts);
290 free(base);
291 free(template);
292 return path;
293 }
260 294
261 void handle_binding_up(keybinding * binding) 295 void handle_binding_up(keybinding * binding)
262 { 296 {
263 uint8_t allow_content_binds = content_binds_enabled && current_system; 297 uint8_t allow_content_binds = content_binds_enabled && current_system;
264 switch(binding->bind_type) 298 switch(binding->bind_type)
350 case UI_SMS_PAUSE: 384 case UI_SMS_PAUSE:
351 if (allow_content_binds && current_system->gamepad_down) { 385 if (allow_content_binds && current_system->gamepad_down) {
352 current_system->gamepad_down(current_system, GAMEPAD_MAIN_UNIT, MAIN_UNIT_PAUSE); 386 current_system->gamepad_down(current_system, GAMEPAD_MAIN_UNIT, MAIN_UNIT_PAUSE);
353 } 387 }
354 break; 388 break;
355 case UI_SCREENSHOT: { 389 case UI_SCREENSHOT:
356 if (allow_content_binds) { 390 if (allow_content_binds) {
357 char *screenshot_base = tern_find_path(config, "ui\0screenshot_path\0", TVAL_PTR).ptrval; 391 char *path = get_content_config_path("ui\0screenshot_path\0", "ui\0screenshot_template\0", "blastem_%c.ppm");
358 if (!screenshot_base) { 392 render_save_screenshot(path);
359 screenshot_base = "$HOME"; 393 }
394 break;
395 case UI_VGM_LOG:
396 if (allow_content_binds && current_system->start_vgm_log) {
397 if (current_system->vgm_logging) {
398 current_system->stop_vgm_log(current_system);
399 } else {
400 char *path = get_content_config_path("ui\0vgm_path\0", "ui\0vgm_template\0", "blastem_%c.vgm");
401 current_system->start_vgm_log(current_system, path);
402 free(path);
360 } 403 }
361 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir()); 404 }
362 vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir()); 405 break;
363 screenshot_base = replace_vars(screenshot_base, vars, 1);
364 tern_free(vars);
365 time_t now = time(NULL);
366 struct tm local_store;
367 char fname_part[256];
368 char *template = tern_find_path(config, "ui\0screenshot_template\0", TVAL_PTR).ptrval;
369 if (!template) {
370 template = "blastem_%c.ppm";
371 }
372 strftime(fname_part, sizeof(fname_part), template, localtime_r(&now, &local_store));
373 char const *parts[] = {screenshot_base, PATH_SEP, fname_part};
374 char *path = alloc_concat_m(3, parts);
375 free(screenshot_base);
376 render_save_screenshot(path);
377 }
378 break;
379 }
380 case UI_EXIT: 406 case UI_EXIT:
381 #ifndef DISABLE_NUKLEAR 407 #ifndef DISABLE_NUKLEAR
382 if (is_nuklear_active()) { 408 if (is_nuklear_active()) {
383 show_pause_menu(); 409 show_pause_menu();
384 } else { 410 } else {
623 *subtype_a = UI_RELOAD; 649 *subtype_a = UI_RELOAD;
624 } else if (!strcmp(target + 3, "sms_pause")) { 650 } else if (!strcmp(target + 3, "sms_pause")) {
625 *subtype_a = UI_SMS_PAUSE; 651 *subtype_a = UI_SMS_PAUSE;
626 } else if (!strcmp(target + 3, "screenshot")) { 652 } else if (!strcmp(target + 3, "screenshot")) {
627 *subtype_a = UI_SCREENSHOT; 653 *subtype_a = UI_SCREENSHOT;
654 } else if (!strcmp(target + 3, "vgm_log")) {
655 *subtype_a = UI_VGM_LOG;
628 } else if(!strcmp(target + 3, "exit")) { 656 } else if(!strcmp(target + 3, "exit")) {
629 *subtype_a = UI_EXIT; 657 *subtype_a = UI_EXIT;
630 } else if (!strcmp(target + 3, "plane_debug")) { 658 } else if (!strcmp(target + 3, "plane_debug")) {
631 *subtype_a = UI_PLANE_DEBUG; 659 *subtype_a = UI_PLANE_DEBUG;
632 } else if (!strcmp(target + 3, "vram_debug")) { 660 } else if (!strcmp(target + 3, "vram_debug")) {