comparison blastem.c @ 1946:c3c62dbf1ceb

WIP netplay support
author Michael Pavone <pavone@retrodev.com>
date Wed, 29 Apr 2020 01:00:57 -0700
parents b387f1c5a1d0
children 42c12d141f6e
comparison
equal deleted inserted replaced
1945:ba7231d2411c 1946:c3c62dbf1ceb
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"
428 game_system->next_context = menu_system; 429 game_system->next_context = menu_system;
429 setup_saves(&cart, game_system); 430 setup_saves(&cart, game_system);
430 update_title(game_system->info.name); 431 update_title(game_system->info.name);
431 } 432 }
432 433
434 char *parse_addr_port(char *arg)
435 {
436 while (*arg && *arg != ':') {
437 ++arg;
438 }
439 if (!*arg) {
440 return NULL;
441 }
442 char *end;
443 int port = strtol(arg + 1, &end, 10);
444 if (port && !*end) {
445 *arg = 0;
446 return arg + 1;
447 }
448 return NULL;
449 }
450
433 int main(int argc, char ** argv) 451 int main(int argc, char ** argv)
434 { 452 {
435 set_exe_str(argv[0]); 453 set_exe_str(argv[0]);
436 config = load_config(); 454 config = load_config();
437 int width = -1; 455 int width = -1;
439 int debug = 0; 457 int debug = 0;
440 int loaded = 0; 458 int loaded = 0;
441 system_type stype = SYSTEM_UNKNOWN, force_stype = SYSTEM_UNKNOWN; 459 system_type stype = SYSTEM_UNKNOWN, force_stype = SYSTEM_UNKNOWN;
442 char * romfname = NULL; 460 char * romfname = NULL;
443 char * statefile = NULL; 461 char * statefile = NULL;
462 event_reader reader = {0};
444 debugger_type dtype = DEBUGGER_NATIVE; 463 debugger_type dtype = DEBUGGER_NATIVE;
445 uint8_t start_in_debugger = 0; 464 uint8_t start_in_debugger = 0;
446 uint8_t fullscreen = FULLSCREEN_DEFAULT, use_gl = 1; 465 uint8_t fullscreen = FULLSCREEN_DEFAULT, use_gl = 1;
447 uint8_t debug_target = 0; 466 uint8_t debug_target = 0;
467 char *port;
448 for (int i = 1; i < argc; i++) { 468 for (int i = 1; i < argc; i++) {
449 if (argv[i][0] == '-') { 469 if (argv[i][0] == '-') {
450 switch(argv[i][1]) { 470 switch(argv[i][1]) {
451 case 'b': 471 case 'b':
452 i++; 472 i++;
465 break; 485 break;
466 case 'D': 486 case 'D':
467 gdb_remote_init(); 487 gdb_remote_init();
468 dtype = DEBUGGER_GDB; 488 dtype = DEBUGGER_GDB;
469 start_in_debugger = 1; 489 start_in_debugger = 1;
490 break;
491 case 'e':
492 i++;
493 if (i >= argc) {
494 fatal_error("-e must be followed by a file name\n");
495 }
496 port = parse_addr_port(argv[i]);
497 if (port) {
498 event_log_tcp(argv[i], port);
499 } else {
500 event_log_file(argv[i]);
501 }
470 break; 502 break;
471 case 'f': 503 case 'f':
472 fullscreen = !fullscreen; 504 fullscreen = !fullscreen;
473 break; 505 break;
474 case 'g': 506 case 'g':
553 " -d Enter debugger on startup\n" 585 " -d Enter debugger on startup\n"
554 " -n Disable Z80\n" 586 " -n Disable Z80\n"
555 " -v Display version number and exit\n" 587 " -v Display version number and exit\n"
556 " -l Log 68K code addresses (useful for assemblers)\n" 588 " -l Log 68K code addresses (useful for assemblers)\n"
557 " -y Log individual YM-2612 channels to WAVE files\n" 589 " -y Log individual YM-2612 channels to WAVE files\n"
590 " -e FILE Write hardware event log to FILE\n"
558 ); 591 );
559 return 0; 592 return 0;
560 default: 593 default:
561 fatal_error("Unrecognized switch %s\n", argv[i]); 594 fatal_error("Unrecognized switch %s\n", argv[i]);
562 } 595 }
563 } else if (!loaded) { 596 } else if (!loaded) {
564 if (!(cart.size = load_rom(argv[i], &cart.buffer, stype == SYSTEM_UNKNOWN ? &stype : NULL))) { 597 char *port = parse_addr_port(argv[i]);
565 fatal_error("Failed to open %s for reading\n", argv[i]); 598 if (port) {
566 } 599 init_event_reader_tcp(&reader, argv[i], port);
567 cart.dir = path_dirname(argv[i]); 600 } else {
568 cart.name = basename_no_extension(argv[i]); 601 if (!(cart.size = load_rom(argv[i], &cart.buffer, stype == SYSTEM_UNKNOWN ? &stype : NULL))) {
569 cart.extension = path_extension(argv[i]); 602 fatal_error("Failed to open %s for reading\n", argv[i]);
603 }
604 cart.dir = path_dirname(argv[i]);
605 cart.name = basename_no_extension(argv[i]);
606 cart.extension = path_extension(argv[i]);
607 }
570 romfname = argv[i]; 608 romfname = argv[i];
571 loaded = 1; 609 loaded = 1;
572 } else if (width < 0) { 610 } else if (width < 0) {
573 width = atoi(argv[i]); 611 width = atoi(argv[i]);
574 } else if (height < 0) { 612 } else if (height < 0) {
643 } else if (state_format && strcmp(state_format, "native")) { 681 } else if (state_format && strcmp(state_format, "native")) {
644 warning("%s is not a valid value for the ui.state_format setting. Valid values are gst and native\n", state_format); 682 warning("%s is not a valid value for the ui.state_format setting. Valid values are gst and native\n", state_format);
645 } 683 }
646 684
647 if (loaded) { 685 if (loaded) {
648 if (stype == SYSTEM_UNKNOWN) { 686 if (stype == SYSTEM_UNKNOWN || reader.socket) {
649 stype = detect_system_type(&cart); 687 if (reader.socket) {
688 stype = reader_system_type(&reader);
689 } else {
690 stype = detect_system_type(&cart);
691 }
650 } 692 }
651 if (stype == SYSTEM_UNKNOWN) { 693 if (stype == SYSTEM_UNKNOWN) {
652 fatal_error("Failed to detect system type for %s\n", romfname); 694 fatal_error("Failed to detect system type for %s\n", romfname);
653 } 695 }
654 current_system = alloc_config_system(stype, &cart, menu ? 0 : opts, force_region); 696
697 if (reader.socket) {
698 current_system = alloc_config_player(stype, &reader);
699 } else {
700 current_system = alloc_config_system(stype, &cart, menu ? 0 : opts, force_region);
701 }
655 if (!current_system) { 702 if (!current_system) {
656 fatal_error("Failed to configure emulated machine for %s\n", romfname); 703 fatal_error("Failed to configure emulated machine for %s\n", romfname);
657 } 704 }
658 705
659 setup_saves(&cart, current_system); 706 setup_saves(&cart, current_system);