Mercurial > repos > blastem
comparison blastem.c @ 2404:6f8400ce7a0f
Fix reload of zipped and gzipped ROMS
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 02 Jan 2024 18:14:28 -0800 |
parents | 34b4ff091891 |
children | 65c2e4d990cc |
comparison
equal
deleted
inserted
replaced
2403:8171409b62ef | 2404:6f8400ce7a0f |
---|---|
182 } | 182 } |
183 zip_close(z); | 183 zip_close(z); |
184 return 0; | 184 return 0; |
185 } | 185 } |
186 | 186 |
187 uint32_t load_media(const char * filename, system_media *dst, system_type *stype) | 187 uint32_t load_media(char * filename, system_media *dst, system_type *stype) |
188 { | 188 { |
189 uint8_t header[10]; | 189 uint8_t header[10]; |
190 dst->orig_path = filename; | |
190 char *ext = path_extension(filename); | 191 char *ext = path_extension(filename); |
191 if (ext && !strcasecmp(ext, "zip")) { | 192 if (ext && !strcasecmp(ext, "zip")) { |
192 free(ext); | 193 free(ext); |
193 return load_media_zip(filename, dst); | 194 return load_media_zip(filename, dst); |
194 } | 195 } |
386 if (current_system && current_system->config_updated) { | 387 if (current_system && current_system->config_updated) { |
387 current_system->config_updated(current_system); | 388 current_system->config_updated(current_system); |
388 } | 389 } |
389 } | 390 } |
390 | 391 |
391 static void on_drag_drop(const char *filename) | 392 static void on_drag_drop(char *filename) |
392 { | 393 { |
393 if (current_system) { | 394 if (current_system) { |
394 if (current_system->next_rom) { | 395 if (current_system->next_rom) { |
395 free(current_system->next_rom); | 396 free(current_system->next_rom); |
396 } | 397 } |
419 return &cart; | 420 return &cart; |
420 } | 421 } |
421 | 422 |
422 void reload_media(void) | 423 void reload_media(void) |
423 { | 424 { |
424 if (!current_system) { | 425 if (!current_system || !cart.orig_path) { |
425 return; | 426 return; |
426 } | 427 } |
427 if (current_system->next_rom) { | 428 if (current_system->next_rom) { |
428 free(current_system->next_rom); | 429 free(current_system->next_rom); |
429 } | 430 } |
430 char const *parts[] = { | 431 current_system->next_rom = cart.orig_path; |
431 cart.dir, PATH_SEP, cart.name, ".", cart.extension | 432 cart.orig_path = NULL; |
432 }; | |
433 char const **start = parts[0] ? parts : parts + 2; | |
434 int num_parts = parts[0] ? 5 : 3; | |
435 if (!parts[4]) { | |
436 num_parts -= 2; | |
437 } | |
438 current_system->next_rom = alloc_concat_m(num_parts, start); | |
439 if (cart.chain) { | 433 if (cart.chain) { |
440 parts[0] = cart.chain->dir; | 434 load_media(cart.chain->orig_path, cart.chain, NULL); |
441 parts[2] = cart.chain->name; | |
442 parts[4] = cart.chain->extension; | |
443 start = parts[0] ? parts : parts + 2; | |
444 num_parts = parts[0] ? 5 : 3; | |
445 char *lock_on_path = alloc_concat_m(num_parts, start); | |
446 load_media(lock_on_path, cart.chain, NULL); | |
447 free(lock_on_path); | |
448 } | 435 } |
449 system_request_exit(current_system, 1); | 436 system_request_exit(current_system, 1); |
450 } | 437 } |
451 | 438 |
452 void lockon_media(char *lock_on_path) | 439 void lockon_media(char *lock_on_path) |
453 { | 440 { |
454 free(lock_on.dir); | 441 free(lock_on.dir); |
455 free(lock_on.name); | 442 free(lock_on.name); |
456 free(lock_on.extension); | 443 free(lock_on.extension); |
444 free(lock_on.orig_path); | |
457 if (lock_on_path) { | 445 if (lock_on_path) { |
458 reload_media(); | 446 reload_media(); |
459 cart.chain = &lock_on; | 447 cart.chain = &lock_on; |
460 load_media(lock_on_path, &lock_on, NULL); | 448 load_media(lock_on_path, &lock_on, NULL); |
461 } else { | 449 } else { |
462 lock_on.dir = NULL; | 450 lock_on.dir = NULL; |
463 lock_on.name = NULL; | 451 lock_on.name = NULL; |
464 lock_on.extension = NULL; | 452 lock_on.extension = NULL; |
453 lock_on.orig_path = NULL; | |
465 cart.chain = NULL; | 454 cart.chain = NULL; |
466 } | 455 } |
467 } | 456 } |
468 | 457 |
469 static uint32_t opts = 0; | 458 static uint32_t opts = 0; |
470 static uint8_t force_region = 0; | 459 static uint8_t force_region = 0; |
471 void init_system_with_media(const char *path, system_type force_stype) | 460 void init_system_with_media(char *path, system_type force_stype) |
472 { | 461 { |
473 if (game_system) { | 462 if (game_system) { |
474 if (game_system->persist_save) { | 463 if (game_system->persist_save) { |
475 game_system->persist_save(game_system); | 464 game_system->persist_save(game_system); |
476 } | 465 } |
485 current_system->arena = start_new_arena(); | 474 current_system->arena = start_new_arena(); |
486 } | 475 } |
487 free(cart.dir); | 476 free(cart.dir); |
488 free(cart.name); | 477 free(cart.name); |
489 free(cart.extension); | 478 free(cart.extension); |
479 free(cart.orig_path); | |
490 system_type stype = SYSTEM_UNKNOWN; | 480 system_type stype = SYSTEM_UNKNOWN; |
491 if (!(cart.size = load_media(path, &cart, &stype))) { | 481 if (!(cart.size = load_media(path, &cart, &stype))) { |
492 fatal_error("Failed to open %s for reading\n", path); | 482 fatal_error("Failed to open %s for reading\n", path); |
493 } | 483 } |
494 | 484 |
679 } else if (!loaded) { | 669 } else if (!loaded) { |
680 reader_port = parse_addr_port(argv[i]); | 670 reader_port = parse_addr_port(argv[i]); |
681 if (reader_port) { | 671 if (reader_port) { |
682 reader_addr = argv[i]; | 672 reader_addr = argv[i]; |
683 } else { | 673 } else { |
684 if (!load_media(argv[i], &cart, stype == SYSTEM_UNKNOWN ? &stype : NULL)) { | 674 romfname = strdup(argv[i]); |
685 fatal_error("Failed to open %s for reading\n", argv[i]); | 675 if (!load_media(romfname, &cart, stype == SYSTEM_UNKNOWN ? &stype : NULL)) { |
686 } | 676 fatal_error("Failed to open %s for reading\n", argv[i]); |
687 } | 677 } |
688 romfname = argv[i]; | 678 } |
689 loaded = 1; | 679 loaded = 1; |
690 } else if (width < 0) { | 680 } else if (width < 0) { |
691 width = atoi(argv[i]); | 681 width = atoi(argv[i]); |
692 } else if (height < 0) { | 682 } else if (height < 0) { |
693 height = atoi(argv[i]); | 683 height = atoi(argv[i]); |
734 //load menu | 724 //load menu |
735 romfname = tern_find_path(config, "ui\0rom\0", TVAL_PTR).ptrval; | 725 romfname = tern_find_path(config, "ui\0rom\0", TVAL_PTR).ptrval; |
736 if (!romfname) { | 726 if (!romfname) { |
737 romfname = "menu.bin"; | 727 romfname = "menu.bin"; |
738 } | 728 } |
729 romfname = strdup(romfname); | |
739 if (is_absolute_path(romfname)) { | 730 if (is_absolute_path(romfname)) { |
740 if (!(cart.size = load_media(romfname, &cart, &stype))) { | 731 if (!(cart.size = load_media(romfname, &cart, &stype))) { |
741 fatal_error("Failed to open UI ROM %s for reading", romfname); | 732 fatal_error("Failed to open UI ROM %s for reading", romfname); |
742 } | 733 } |
743 } else { | 734 } else { |
751 cart.size = rom_size; | 742 cart.size = rom_size; |
752 } | 743 } |
753 cart.dir = path_dirname(romfname); | 744 cart.dir = path_dirname(romfname); |
754 cart.name = basename_no_extension(romfname); | 745 cart.name = basename_no_extension(romfname); |
755 cart.extension = path_extension(romfname); | 746 cart.extension = path_extension(romfname); |
747 cart.orig_path = romfname; | |
756 } | 748 } |
757 //force system detection, value on command line is only for games not the menu | 749 //force system detection, value on command line is only for games not the menu |
758 stype = detect_system_type(&cart); | 750 stype = detect_system_type(&cart); |
759 loaded = 1; | 751 loaded = 1; |
760 } | 752 } |
819 } | 811 } |
820 if (current_system->next_rom) { | 812 if (current_system->next_rom) { |
821 char *next_rom = current_system->next_rom; | 813 char *next_rom = current_system->next_rom; |
822 current_system->next_rom = NULL; | 814 current_system->next_rom = NULL; |
823 init_system_with_media(next_rom, force_stype); | 815 init_system_with_media(next_rom, force_stype); |
824 free(next_rom); | |
825 menu = 0; | 816 menu = 0; |
826 current_system = game_system; | 817 current_system = game_system; |
827 current_system->debugger_type = dtype; | 818 current_system->debugger_type = dtype; |
828 current_system->enter_debugger = start_in_debugger && menu == debug_target; | 819 current_system->enter_debugger = start_in_debugger && menu == debug_target; |
829 current_system->start_context(current_system, statefile); | 820 current_system->start_context(current_system, statefile); |