comparison io.c @ 766:1b2f8280ba81

WIP changes to support reading cart memory map from ROM DB
author Michael Pavone <pavone@retrodev.com>
date Sun, 05 Jul 2015 14:21:34 -0700
parents daa31ee7d8cd
children 0565b2c1a034
comparison
equal deleted inserted replaced
765:dc54387ee1cd 766:1b2f8280ba81
534 unlink(sockfile_name); 534 unlink(sockfile_name);
535 } 535 }
536 536
537 void setup_io_devices(tern_node * config, io_port * ports) 537 void setup_io_devices(tern_node * config, io_port * ports)
538 { 538 {
539 tern_node *io_nodes = tern_find_prefix(config, "iodevices"); 539 tern_node *io_nodes = tern_get_node(tern_find_path(config, "io\0devices\0"));
540 char * io_1 = tern_find_ptr(io_nodes, "1"); 540 char * io_1 = tern_find_ptr(io_nodes, "1");
541 char * io_2 = tern_find_ptr(io_nodes, "2"); 541 char * io_2 = tern_find_ptr(io_nodes, "2");
542 char * io_ext = tern_find_ptr(io_nodes, "ext"); 542 char * io_ext = tern_find_ptr(io_nodes, "ext");
543 543
544 process_device(io_1, ports); 544 process_device(io_1, ports);
548 for (int i = 0; i < 3; i++) 548 for (int i = 0; i < 3; i++)
549 { 549 {
550 #ifndef _WIN32 550 #ifndef _WIN32
551 if (ports[i].device_type == IO_SEGA_PARALLEL) 551 if (ports[i].device_type == IO_SEGA_PARALLEL)
552 { 552 {
553 char *pipe_name = tern_find_ptr(config, "ioparallel_pipe"); 553 char *pipe_name = tern_find_path(config, "io\0parallel_pipe\0").ptrval;
554 if (!pipe_name) 554 if (!pipe_name)
555 { 555 {
556 fprintf(stderr, "IO port %s is configured to use the sega parallel board, but no paralell_pipe is set!\n", io_name(i)); 556 fprintf(stderr, "IO port %s is configured to use the sega parallel board, but no paralell_pipe is set!\n", io_name(i));
557 ports[i].device_type = IO_NONE; 557 ports[i].device_type = IO_NONE;
558 } else { 558 } else {
574 } 574 }
575 } 575 }
576 } 576 }
577 } 577 }
578 } else if (ports[i].device_type == IO_GENERIC) { 578 } else if (ports[i].device_type == IO_GENERIC) {
579 char *sock_name = tern_find_ptr(config, "iosocket"); 579 char *sock_name = tern_find_path(config, "io\0socket\0").ptrval;
580 if (!sock_name) 580 if (!sock_name)
581 { 581 {
582 fprintf(stderr, "IO port %s is configured to use generic IO, but no socket is set!\n", io_name(i)); 582 fprintf(stderr, "IO port %s is configured to use generic IO, but no socket is set!\n", io_name(i));
583 ports[i].device_type = IO_NONE; 583 ports[i].device_type = IO_NONE;
584 } else { 584 } else {
663 padbuttons = tern_insert_int(padbuttons, ".y", BUTTON_Y); 663 padbuttons = tern_insert_int(padbuttons, ".y", BUTTON_Y);
664 padbuttons = tern_insert_int(padbuttons, ".z", BUTTON_Z); 664 padbuttons = tern_insert_int(padbuttons, ".z", BUTTON_Z);
665 padbuttons = tern_insert_int(padbuttons, ".start", BUTTON_START); 665 padbuttons = tern_insert_int(padbuttons, ".start", BUTTON_START);
666 padbuttons = tern_insert_int(padbuttons, ".mode", BUTTON_MODE); 666 padbuttons = tern_insert_int(padbuttons, ".mode", BUTTON_MODE);
667 667
668 tern_node * keys = tern_find_prefix(config, "bindingskeys"); 668 tern_node * keys = tern_get_node(tern_find_path(config, "bindings\0keys\0"));
669 process_keys(keys, special, padbuttons, NULL); 669 process_keys(keys, special, padbuttons, NULL);
670 char prefix[] = "bindingspads00"; 670 char numstr[] = "00";
671 for (int i = 0; i < 100 && i < render_num_joysticks(); i++) 671 tern_node * pads = tern_get_node(tern_find_path(config, "bindings\0pads\0"));
672 { 672 if (pads) {
673 if (i < 10) { 673 for (int i = 0; i < 100 && i < render_num_joysticks(); i++)
674 prefix[strlen("bindingspads")] = i + '0'; 674 {
675 prefix[strlen("bindingspads")+1] = 0; 675
676 } else { 676 if (i < 10) {
677 prefix[strlen("bindingspads")] = i/10 + '0'; 677 numstr[0] = i + '0';
678 prefix[strlen("bindingspads")+1] = i%10 + '0'; 678 numstr[1] = 0;
679 } 679 } else {
680 tern_node * pad = tern_find_prefix(config, prefix); 680 numstr[0] = i/10 + '0';
681 if (pad) { 681 numstr[1] = i%10 + '0';
682 char dprefix[] = "dpads0"; 682 }
683 for (int dpad = 0; dpad < 10 && dpad < render_joystick_num_hats(i); dpad++) 683 tern_node * pad = tern_find_ptr(pads, numstr);
684 { 684 if (pad) {
685 dprefix[strlen("dpads")] = dpad + '0'; 685 tern_node * dpad_node = tern_find_ptr(pad, "dpads");
686 tern_node * pad_dpad = tern_find_prefix(pad, dprefix); 686 if (dpad_node) {
687 char * dirs[] = {"up", "down", "left", "right"}; 687 for (int dpad = 0; dpad < 10 && dpad < render_joystick_num_hats(i); dpad++)
688 int dirnums[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT}; 688 {
689 for (int dir = 0; dir < sizeof(dirs)/sizeof(dirs[0]); dir++) { 689 numstr[0] = dpad + '0';
690 char * target = tern_find_ptr(pad_dpad, dirs[dir]); 690 numstr[1] = 0;
691 if (target) { 691 tern_node * pad_dpad = tern_find_ptr(dpad_node, numstr);
692 int ui_func, padnum, button; 692 char * dirs[] = {"up", "down", "left", "right"};
693 int bindtype = parse_binding_target(target, padbuttons, &ui_func, &padnum, &button); 693 int dirnums[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT};
694 if (bindtype == 1) { 694 for (int dir = 0; dir < sizeof(dirs)/sizeof(dirs[0]); dir++) {
695 bind_dpad_gamepad(i, dpad, dirnums[dir], padnum, button); 695 char * target = tern_find_ptr(pad_dpad, dirs[dir]);
696 } else if (bindtype == 2) { 696 if (target) {
697 bind_dpad_ui(i, dpad, dirnums[dir], ui_func, button); 697 int ui_func, padnum, button;
698 int bindtype = parse_binding_target(target, padbuttons, &ui_func, &padnum, &button);
699 if (bindtype == 1) {
700 bind_dpad_gamepad(i, dpad, dirnums[dir], padnum, button);
701 } else if (bindtype == 2) {
702 bind_dpad_ui(i, dpad, dirnums[dir], ui_func, button);
703 }
704 }
698 } 705 }
699 } 706 }
700 } 707 }
701 } 708 tern_node *button_node = tern_find_ptr(pad, "buttons");
702 char bprefix[] = "buttons00"; 709 if (button_node) {
703 for (int but = 0; but < 100 && but < render_joystick_num_buttons(i); but++) 710 for (int but = 0; but < 100 && but < render_joystick_num_buttons(i); but++)
704 { 711 {
705 if (but < 10) { 712 if (but < 10) {
706 bprefix[strlen("buttons")] = but + '0'; 713 numstr[0] = but + '0';
707 bprefix[strlen("buttons")+1] = 0; 714 numstr[1] = 0;
708 } else { 715 } else {
709 bprefix[strlen("buttons")] = but/10 + '0'; 716 numstr[0] = but/10 + '0';
710 bprefix[strlen("buttons")+1] = but%10 + '0'; 717 numstr[1] = but%10 + '0';
711 } 718 }
712 char * target = tern_find_ptr(pad, bprefix); 719 char * target = tern_find_ptr(button_node, numstr);
713 if (target) { 720 if (target) {
714 int ui_func, padnum, button; 721 int ui_func, padnum, button;
715 int bindtype = parse_binding_target(target, padbuttons, &ui_func, &padnum, &button); 722 int bindtype = parse_binding_target(target, padbuttons, &ui_func, &padnum, &button);
716 if (bindtype == 1) { 723 if (bindtype == 1) {
717 bind_button_gamepad(i, but, padnum, button); 724 bind_button_gamepad(i, but, padnum, button);
718 } else if (bindtype == 2) { 725 } else if (bindtype == 2) {
719 bind_button_ui(i, but, ui_func, button); 726 bind_button_ui(i, but, ui_func, button);
727 }
728 }
720 } 729 }
721 } 730 }
722 } 731 }
723 } 732 }
724 } 733 }
725 tern_node * speed_nodes = tern_find_prefix(config, "clocksspeeds"); 734 tern_node * speed_nodes = tern_get_node(tern_find_path(config, "clocks\0speeds\0"));
726 speeds = malloc(sizeof(uint32_t)); 735 speeds = malloc(sizeof(uint32_t));
727 speeds[0] = 100; 736 speeds[0] = 100;
728 process_speeds(speed_nodes, NULL); 737 process_speeds(speed_nodes, NULL);
729 for (int i = 0; i < num_speeds; i++) 738 for (int i = 0; i < num_speeds; i++)
730 { 739 {