Mercurial > repos > blastem
comparison blastem.c @ 1983:a7b753e260a2 mame_interp
Merge from default
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 09 May 2020 23:39:44 -0700 |
parents | 2c1c88cd1a3f 81df9aa2de9b |
children | 638eb2d25696 |
comparison
equal
deleted
inserted
replaced
1937:cafde1255ad3 | 1983:a7b753e260a2 |
---|---|
28 #include "arena.h" | 28 #include "arena.h" |
29 #include "config.h" | 29 #include "config.h" |
30 #include "bindings.h" | 30 #include "bindings.h" |
31 #include "menu.h" | 31 #include "menu.h" |
32 #include "zip.h" | 32 #include "zip.h" |
33 #include "event_log.h" | |
33 #ifndef DISABLE_NUKLEAR | 34 #ifndef DISABLE_NUKLEAR |
34 #include "nuklear_ui/blastem_nuklear.h" | 35 #include "nuklear_ui/blastem_nuklear.h" |
35 #endif | 36 #endif |
36 | 37 |
37 #define BLASTEM_VERSION "0.6.3-pre" | 38 #define BLASTEM_VERSION "0.6.3-pre" |
155 if (is_smd_format(z->entries[i].name, *dst)) { | 156 if (is_smd_format(z->entries[i].name, *dst)) { |
156 size_t offset; | 157 size_t offset; |
157 for (offset = 0; offset + SMD_BLOCK_SIZE + SMD_HEADER_SIZE <= out_size; offset += SMD_BLOCK_SIZE) | 158 for (offset = 0; offset + SMD_BLOCK_SIZE + SMD_HEADER_SIZE <= out_size; offset += SMD_BLOCK_SIZE) |
158 { | 159 { |
159 uint8_t tmp[SMD_BLOCK_SIZE]; | 160 uint8_t tmp[SMD_BLOCK_SIZE]; |
160 memcpy(tmp, *dst + offset + SMD_HEADER_SIZE, SMD_BLOCK_SIZE); | 161 uint8_t *u8dst = *dst; |
161 process_smd_block(*dst + offset, tmp, SMD_BLOCK_SIZE); | 162 memcpy(tmp, u8dst + offset + SMD_HEADER_SIZE, SMD_BLOCK_SIZE); |
163 process_smd_block((void *)(u8dst + offset), tmp, SMD_BLOCK_SIZE); | |
162 } | 164 } |
163 out_size = offset; | 165 out_size = offset; |
164 } | 166 } |
165 free(ext); | 167 free(ext); |
166 zip_close(z); | 168 zip_close(z); |
323 if (current_system) { | 325 if (current_system) { |
324 if (current_system->next_rom) { | 326 if (current_system->next_rom) { |
325 free(current_system->next_rom); | 327 free(current_system->next_rom); |
326 } | 328 } |
327 current_system->next_rom = strdup(filename); | 329 current_system->next_rom = strdup(filename); |
328 current_system->request_exit(current_system); | 330 system_request_exit(current_system, 1); |
329 if (menu_system && menu_system->type == SYSTEM_GENESIS) { | 331 if (menu_system && menu_system->type == SYSTEM_GENESIS) { |
330 genesis_context *gen = (genesis_context *)menu_system; | 332 genesis_context *gen = (genesis_context *)menu_system; |
331 if (gen->extra) { | 333 if (gen->extra) { |
332 menu_context *menu = gen->extra; | 334 menu_context *menu = gen->extra; |
333 menu->external_game_load = 1; | 335 menu->external_game_load = 1; |
364 int num_parts = parts[0] ? 5 : 3; | 366 int num_parts = parts[0] ? 5 : 3; |
365 if (!parts[4]) { | 367 if (!parts[4]) { |
366 num_parts--; | 368 num_parts--; |
367 } | 369 } |
368 current_system->next_rom = alloc_concat_m(num_parts, start); | 370 current_system->next_rom = alloc_concat_m(num_parts, start); |
369 current_system->request_exit(current_system); | 371 system_request_exit(current_system, 1); |
370 } | 372 } |
371 | 373 |
372 void lockon_media(char *lock_on_path) | 374 void lockon_media(char *lock_on_path) |
373 { | 375 { |
374 reload_media(); | 376 reload_media(); |
432 game_system->next_context = menu_system; | 434 game_system->next_context = menu_system; |
433 setup_saves(&cart, game_system); | 435 setup_saves(&cart, game_system); |
434 update_title(game_system->info.name); | 436 update_title(game_system->info.name); |
435 } | 437 } |
436 | 438 |
439 char *parse_addr_port(char *arg) | |
440 { | |
441 while (*arg && *arg != ':') { | |
442 ++arg; | |
443 } | |
444 if (!*arg) { | |
445 return NULL; | |
446 } | |
447 char *end; | |
448 int port = strtol(arg + 1, &end, 10); | |
449 if (port && !*end) { | |
450 *arg = 0; | |
451 return arg + 1; | |
452 } | |
453 return NULL; | |
454 } | |
455 | |
437 int main(int argc, char ** argv) | 456 int main(int argc, char ** argv) |
438 { | 457 { |
439 set_exe_str(argv[0]); | 458 set_exe_str(argv[0]); |
440 config = load_config(); | 459 config = load_config(); |
441 int width = -1; | 460 int width = -1; |
443 int debug = 0; | 462 int debug = 0; |
444 int loaded = 0; | 463 int loaded = 0; |
445 system_type stype = SYSTEM_UNKNOWN, force_stype = SYSTEM_UNKNOWN; | 464 system_type stype = SYSTEM_UNKNOWN, force_stype = SYSTEM_UNKNOWN; |
446 char * romfname = NULL; | 465 char * romfname = NULL; |
447 char * statefile = NULL; | 466 char * statefile = NULL; |
467 char *reader_addr = NULL, *reader_port = NULL; | |
468 event_reader reader = {0}; | |
448 debugger_type dtype = DEBUGGER_NATIVE; | 469 debugger_type dtype = DEBUGGER_NATIVE; |
449 uint8_t start_in_debugger = 0; | 470 uint8_t start_in_debugger = 0; |
450 uint8_t fullscreen = FULLSCREEN_DEFAULT, use_gl = 1; | 471 uint8_t fullscreen = FULLSCREEN_DEFAULT, use_gl = 1; |
451 uint8_t debug_target = 0; | 472 uint8_t debug_target = 0; |
473 char *port; | |
452 for (int i = 1; i < argc; i++) { | 474 for (int i = 1; i < argc; i++) { |
453 if (argv[i][0] == '-') { | 475 if (argv[i][0] == '-') { |
454 switch(argv[i][1]) { | 476 switch(argv[i][1]) { |
455 case 'b': | 477 case 'b': |
456 i++; | 478 i++; |
472 gdb_remote_init(); | 494 gdb_remote_init(); |
473 dtype = DEBUGGER_GDB; | 495 dtype = DEBUGGER_GDB; |
474 start_in_debugger = 1; | 496 start_in_debugger = 1; |
475 break; | 497 break; |
476 #endif | 498 #endif |
499 case 'e': | |
500 i++; | |
501 if (i >= argc) { | |
502 fatal_error("-e must be followed by a file name\n"); | |
503 } | |
504 port = parse_addr_port(argv[i]); | |
505 if (port) { | |
506 event_log_tcp(argv[i], port); | |
507 } else { | |
508 event_log_file(argv[i]); | |
509 } | |
510 break; | |
477 case 'f': | 511 case 'f': |
478 fullscreen = !fullscreen; | 512 fullscreen = !fullscreen; |
479 break; | 513 break; |
480 case 'g': | 514 case 'g': |
481 use_gl = 0; | 515 use_gl = 0; |
559 " -d Enter debugger on startup\n" | 593 " -d Enter debugger on startup\n" |
560 " -n Disable Z80\n" | 594 " -n Disable Z80\n" |
561 " -v Display version number and exit\n" | 595 " -v Display version number and exit\n" |
562 " -l Log 68K code addresses (useful for assemblers)\n" | 596 " -l Log 68K code addresses (useful for assemblers)\n" |
563 " -y Log individual YM-2612 channels to WAVE files\n" | 597 " -y Log individual YM-2612 channels to WAVE files\n" |
598 " -e FILE Write hardware event log to FILE\n" | |
564 ); | 599 ); |
565 return 0; | 600 return 0; |
566 default: | 601 default: |
567 fatal_error("Unrecognized switch %s\n", argv[i]); | 602 fatal_error("Unrecognized switch %s\n", argv[i]); |
568 } | 603 } |
569 } else if (!loaded) { | 604 } else if (!loaded) { |
605 reader_port = parse_addr_port(argv[i]); | |
606 if (reader_port) { | |
607 reader_addr = argv[i]; | |
608 } else { | |
570 if (!(cart.size = load_rom(argv[i], &cart.buffer, stype == SYSTEM_UNKNOWN ? &stype : NULL))) { | 609 if (!(cart.size = load_rom(argv[i], &cart.buffer, stype == SYSTEM_UNKNOWN ? &stype : NULL))) { |
571 fatal_error("Failed to open %s for reading\n", argv[i]); | 610 fatal_error("Failed to open %s for reading\n", argv[i]); |
572 } | 611 } |
573 cart.dir = path_dirname(argv[i]); | 612 cart.dir = path_dirname(argv[i]); |
574 cart.name = basename_no_extension(argv[i]); | 613 cart.name = basename_no_extension(argv[i]); |
575 cart.extension = path_extension(argv[i]); | 614 cart.extension = path_extension(argv[i]); |
615 } | |
576 romfname = argv[i]; | 616 romfname = argv[i]; |
577 loaded = 1; | 617 loaded = 1; |
578 } else if (width < 0) { | 618 } else if (width < 0) { |
579 width = atoi(argv[i]); | 619 width = atoi(argv[i]); |
580 } else if (height < 0) { | 620 } else if (height < 0) { |
603 char *config_fullscreen = tern_find_path(config, "video\0fullscreen\0", TVAL_PTR).ptrval; | 643 char *config_fullscreen = tern_find_path(config, "video\0fullscreen\0", TVAL_PTR).ptrval; |
604 if (config_fullscreen && !strcmp("on", config_fullscreen)) { | 644 if (config_fullscreen && !strcmp("on", config_fullscreen)) { |
605 fullscreen = !fullscreen; | 645 fullscreen = !fullscreen; |
606 } | 646 } |
607 if (!headless) { | 647 if (!headless) { |
648 if (reader_addr) { | |
649 render_set_external_sync(1); | |
650 } | |
608 render_init(width, height, "BlastEm", fullscreen); | 651 render_init(width, height, "BlastEm", fullscreen); |
609 render_set_drag_drop_handler(on_drag_drop); | 652 render_set_drag_drop_handler(on_drag_drop); |
610 } | 653 } |
611 set_bindings(); | 654 set_bindings(); |
612 | 655 |
648 use_native_states = 0; | 691 use_native_states = 0; |
649 } else if (state_format && strcmp(state_format, "native")) { | 692 } else if (state_format && strcmp(state_format, "native")) { |
650 warning("%s is not a valid value for the ui.state_format setting. Valid values are gst and native\n", state_format); | 693 warning("%s is not a valid value for the ui.state_format setting. Valid values are gst and native\n", state_format); |
651 } | 694 } |
652 | 695 |
653 if (loaded) { | 696 if (loaded && !reader_addr) { |
654 if (stype == SYSTEM_UNKNOWN) { | 697 if (stype == SYSTEM_UNKNOWN) { |
655 stype = detect_system_type(&cart); | 698 stype = detect_system_type(&cart); |
656 } | 699 } |
657 if (stype == SYSTEM_UNKNOWN) { | 700 if (stype == SYSTEM_UNKNOWN) { |
658 fatal_error("Failed to detect system type for %s\n", romfname); | 701 fatal_error("Failed to detect system type for %s\n", romfname); |
659 } | 702 } |
703 | |
660 current_system = alloc_config_system(stype, &cart, menu ? 0 : opts, force_region); | 704 current_system = alloc_config_system(stype, &cart, menu ? 0 : opts, force_region); |
661 if (!current_system) { | 705 if (!current_system) { |
662 fatal_error("Failed to configure emulated machine for %s\n", romfname); | 706 fatal_error("Failed to configure emulated machine for %s\n", romfname); |
663 } | 707 } |
664 | 708 |
676 blastem_nuklear_init(!menu); | 720 blastem_nuklear_init(!menu); |
677 current_system = game_system; | 721 current_system = game_system; |
678 menu = 0; | 722 menu = 0; |
679 } | 723 } |
680 #endif | 724 #endif |
725 | |
726 if (reader_addr) { | |
727 init_event_reader_tcp(&reader, reader_addr, reader_port); | |
728 stype = reader_system_type(&reader); | |
729 if (stype == SYSTEM_UNKNOWN) { | |
730 fatal_error("Failed to detect system type for %s\n", romfname); | |
731 } | |
732 game_system = current_system = alloc_config_player(stype, &reader); | |
733 //free inflate stream as it was inflateCopied to an internal event reader in the player | |
734 inflateEnd(&reader.input_stream); | |
735 setup_saves(&cart, current_system); | |
736 update_title(current_system->info.name); | |
737 } | |
681 | 738 |
682 current_system->debugger_type = dtype; | 739 current_system->debugger_type = dtype; |
683 current_system->enter_debugger = start_in_debugger && menu == debug_target; | 740 current_system->enter_debugger = start_in_debugger && menu == debug_target; |
684 current_system->start_context(current_system, menu ? NULL : statefile); | 741 current_system->start_context(current_system, menu ? NULL : statefile); |
685 render_video_loop(); | 742 render_video_loop(); |
696 menu = 0; | 753 menu = 0; |
697 current_system = game_system; | 754 current_system = game_system; |
698 current_system->debugger_type = dtype; | 755 current_system->debugger_type = dtype; |
699 current_system->enter_debugger = start_in_debugger && menu == debug_target; | 756 current_system->enter_debugger = start_in_debugger && menu == debug_target; |
700 current_system->start_context(current_system, statefile); | 757 current_system->start_context(current_system, statefile); |
758 render_video_loop(); | |
701 } else if (menu && game_system) { | 759 } else if (menu && game_system) { |
702 #ifndef NEW_CORE | 760 #ifndef NEW_CORE |
703 current_system->arena = set_current_arena(game_system->arena); | 761 current_system->arena = set_current_arena(game_system->arena); |
704 #endif | 762 #endif |
705 current_system = game_system; | 763 current_system = game_system; |
717 current_system = menu_system; | 775 current_system = menu_system; |
718 menu = 1; | 776 menu = 1; |
719 } | 777 } |
720 if (!current_system->next_rom) { | 778 if (!current_system->next_rom) { |
721 current_system->resume_context(current_system); | 779 current_system->resume_context(current_system); |
780 render_video_loop(); | |
722 } | 781 } |
723 } else { | 782 } else { |
724 break; | 783 break; |
725 } | 784 } |
726 } | 785 } |