src/emu/softlist.c
| r10040 | r10041 | |
| 826 | 826 | const char *software_get_clone(char *swlist, const char *swname) |
| 827 | 827 | { |
| 828 | 828 | software_list *software_list_ptr = software_list_open(mame_options(), swlist, FALSE, NULL); |
| 829 | | |
| 829 | |
| 830 | 830 | if (software_list_ptr) |
| 831 | 831 | { |
| 832 | 832 | software_info *tmp = software_list_find(software_list_ptr, swname, NULL); |
| 833 | 833 | return tmp->parentname; |
| 834 | 834 | } |
| 835 | | |
| 835 | |
| 836 | 836 | return NULL; |
| 837 | 837 | } |
| 838 | 838 | |
| r10040 | r10041 | |
| 845 | 845 | UINT32 software_get_support(char *swlist, const char *swname) |
| 846 | 846 | { |
| 847 | 847 | software_list *software_list_ptr = software_list_open(mame_options(), swlist, FALSE, NULL); |
| 848 | | |
| 848 | |
| 849 | 849 | if (software_list_ptr) |
| 850 | 850 | { |
| 851 | 851 | software_info *tmp = software_list_find(software_list_ptr, swname, NULL); |
| 852 | 852 | return tmp->supported; |
| 853 | 853 | } |
| 854 | | |
| 854 | |
| 855 | 855 | return 0; |
| 856 | 856 | } |
| 857 | 857 | |
| r10040 | r10041 | |
| 1626 | 1626 | { |
| 1627 | 1627 | const char *short_name; |
| 1628 | 1628 | const char *interface; |
| 1629 | char *list_name; |
| 1630 | device_image_interface* image; |
| 1629 | 1631 | }; |
| 1630 | 1632 | |
| 1633 | /* state of a software part */ |
| 1634 | typedef struct _software_part_state software_part_state; |
| 1635 | struct _software_part_state |
| 1636 | { |
| 1637 | const char *part_name; |
| 1638 | const char *interface; |
| 1639 | }; |
| 1631 | 1640 | |
| 1641 | |
| 1642 | static void ui_mess_menu_populate_software_parts(running_machine *machine, ui_menu *menu, const char *swlist, const char *swinfo, const char *interface) |
| 1643 | { |
| 1644 | //questo dovrebbe generare la lista di parts |
| 1645 | software_list *list = software_list_open(machine->options(), swlist, FALSE, NULL); |
| 1646 | |
| 1647 | if (list) |
| 1648 | { |
| 1649 | software_info *info = software_list_find(list, swinfo, NULL); |
| 1650 | |
| 1651 | if (info) |
| 1652 | { |
| 1653 | for (software_part *swpart = software_find_part(info, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) |
| 1654 | { |
| 1655 | if (strcmp(interface, swpart->interface_) == 0) |
| 1656 | { |
| 1657 | software_part_state *entry = (software_part_state *) ui_menu_pool_alloc(menu, sizeof(*entry)); |
| 1658 | entry->part_name = ui_menu_pool_strdup(menu, swpart->name); |
| 1659 | entry->interface = ui_menu_pool_strdup(menu, swpart->interface_); |
| 1660 | ui_menu_item_append(menu, info->shortname, swpart->name, 0, entry); |
| 1661 | } |
| 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | software_list_close(list); |
| 1666 | } |
| 1667 | } |
| 1668 | |
| 1669 | void ui_mess_menu_software_parts(running_machine *machine, ui_menu *menu, void *parameter, void *state) |
| 1670 | { |
| 1671 | const ui_menu_event *event; |
| 1672 | software_entry_state *sw_state = (software_entry_state *)state; |
| 1673 | const char *swlist = sw_state->list_name; |
| 1674 | const char *swinfo = sw_state->short_name; |
| 1675 | const char *interface = sw_state->interface; |
| 1676 | |
| 1677 | // generate list of available parts |
| 1678 | if (!ui_menu_populated(menu)) |
| 1679 | { |
| 1680 | if (sw_state->list_name) |
| 1681 | { |
| 1682 | ui_mess_menu_populate_software_parts(machine, menu, swlist, swinfo, interface); |
| 1683 | } |
| 1684 | } |
| 1685 | |
| 1686 | /* process the menu */ |
| 1687 | event = ui_menu_process(machine, menu, 0); |
| 1688 | |
| 1689 | if (event != NULL && event->iptkey == IPT_UI_SELECT && event->itemref != NULL) |
| 1690 | { |
| 1691 | software_part_state *entry = (software_part_state *) event->itemref; |
| 1692 | |
| 1693 | // build the name for the part to be loaded |
| 1694 | astring temp_name(sw_state->short_name); |
| 1695 | temp_name.cat(":"); |
| 1696 | temp_name.cat(entry->part_name); |
| 1697 | printf("%s\n", temp_name.cstr()); |
| 1698 | |
| 1699 | sw_state->image->load(temp_name.cstr()); |
| 1700 | } |
| 1701 | } |
| 1702 | |
| 1632 | 1703 | /* populate a specific list */ |
| 1633 | 1704 | static void ui_mess_menu_populate_software_entries(running_machine *machine, ui_menu *menu, char *list_name, device_image_interface* image) |
| 1634 | 1705 | { |
| r10040 | r10041 | |
| 1640 | 1711 | { |
| 1641 | 1712 | software_entry_state *entry = (software_entry_state *) ui_menu_pool_alloc(menu, sizeof(*entry)); |
| 1642 | 1713 | entry->short_name = ui_menu_pool_strdup(menu, swinfo->shortname); |
| 1714 | entry->list_name = list_name; |
| 1715 | entry->image = image; |
| 1643 | 1716 | |
| 1644 | | software_part *part = software_find_part(swinfo, NULL, NULL); |
| 1645 | | entry->interface = ui_menu_pool_strdup(menu, part->interface_); |
| 1646 | | if (strcmp(interface,part->interface_)==0) { |
| 1647 | | ui_menu_item_append(menu, swinfo->shortname, swinfo->longname, 0, entry); |
| 1717 | // check if at least one of the parts has the correct interface |
| 1718 | for (software_part *swpart = software_find_part(swinfo, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) |
| 1719 | { |
| 1720 | if (strcmp(interface, swpart->interface_) == 0) |
| 1721 | { |
| 1722 | entry->interface = ui_menu_pool_strdup(menu, swpart->interface_); |
| 1723 | ui_menu_item_append(menu, swinfo->shortname, swinfo->longname, 0, entry); |
| 1724 | break; |
| 1725 | } |
| 1648 | 1726 | } |
| 1649 | 1727 | } |
| 1650 | 1728 | |
| r10040 | r10041 | |
| 1652 | 1730 | } |
| 1653 | 1731 | } |
| 1654 | 1732 | |
| 1733 | bool swinfo_has_multiple_parts(software_info *swinfo, const char *interface) |
| 1734 | { |
| 1735 | int count = 0; |
| 1736 | |
| 1737 | for (software_part *swpart = software_find_part(swinfo, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) |
| 1738 | { |
| 1739 | if (strcmp(interface, swpart->interface_) == 0) |
| 1740 | count++; |
| 1741 | } |
| 1742 | return (count > 1) ? TRUE : FALSE; |
| 1743 | } |
| 1744 | |
| 1655 | 1745 | void ui_mess_menu_software_list(running_machine *machine, ui_menu *menu, void *parameter, void *state) |
| 1656 | 1746 | { |
| 1657 | 1747 | const ui_menu_event *event; |
| 1658 | 1748 | software_menu_state *sw_state = (software_menu_state *)state; |
| 1659 | 1749 | |
| 1660 | | if (!ui_menu_populated(menu)) { |
| 1661 | | if (sw_state->list_name) { |
| 1662 | | ui_mess_menu_populate_software_entries(machine, menu, sw_state->list_name,sw_state->image); |
| 1750 | if (!ui_menu_populated(menu)) |
| 1751 | { |
| 1752 | if (sw_state->list_name) |
| 1753 | { |
| 1754 | ui_mess_menu_populate_software_entries(machine, menu, sw_state->list_name, sw_state->image); |
| 1663 | 1755 | } |
| 1664 | 1756 | } |
| 1665 | 1757 | |
| r10040 | r10041 | |
| 1670 | 1762 | { |
| 1671 | 1763 | device_image_interface *image = sw_state->image; |
| 1672 | 1764 | software_entry_state *entry = (software_entry_state *) event->itemref; |
| 1673 | | if (image != NULL) |
| 1674 | | image->load(entry->short_name); |
| 1765 | software_list *tmp_list = software_list_open(mame_options(), sw_state->list_name, FALSE, NULL); |
| 1766 | software_info *tmp_info = software_list_find(tmp_list, entry->short_name, NULL); |
| 1767 | |
| 1768 | // if the selected software has multiple parts that can be loaded, open the submenu |
| 1769 | if (swinfo_has_multiple_parts(tmp_info, image->image_config().image_interface())) |
| 1770 | { |
| 1771 | ui_menu *child_menu = ui_menu_alloc(machine, &machine->render().ui_container(), ui_mess_menu_software_parts, entry); |
| 1772 | software_entry_state *child_menustate = (software_entry_state *)ui_menu_alloc_state(child_menu, sizeof(*child_menustate), NULL); |
| 1773 | child_menustate->short_name = entry->short_name; |
| 1774 | child_menustate->interface = image->image_config().image_interface(); |
| 1775 | child_menustate->list_name = sw_state->list_name; |
| 1776 | child_menustate->image = image; |
| 1777 | ui_menu_stack_push(child_menu); |
| 1778 | } |
| 1675 | 1779 | else |
| 1676 | | popmessage("No matching device found for interface '%s'!", entry->interface); |
| 1780 | { |
| 1781 | // otherwise, load the file |
| 1782 | if (image != NULL) |
| 1783 | image->load(entry->short_name); |
| 1784 | else |
| 1785 | popmessage("No matching device found for interface '%s'!", entry->interface); |
| 1786 | } |
| 1677 | 1787 | } |
| 1678 | 1788 | } |
| 1679 | 1789 | |