src/emu/softlist.c
| r11091 | r11092 | |
| 1845 | 1845 | MENU SUPPORT |
| 1846 | 1846 | ***************************************************************************/ |
| 1847 | 1847 | |
| 1848 | | /* state of the software menu */ |
| 1849 | | typedef struct _software_menu_state software_menu_state; |
| 1850 | | struct _software_menu_state |
| 1851 | | { |
| 1852 | | char *list_name; /* currently selected list */ |
| 1853 | | device_image_interface* image; |
| 1854 | | }; |
| 1855 | | |
| 1856 | 1848 | /* state of a software entry */ |
| 1857 | 1849 | typedef struct _software_entry_state software_entry_state; |
| 1858 | 1850 | struct _software_entry_state |
| 1859 | 1851 | { |
| 1852 | software_entry_state *next; |
| 1853 | |
| 1860 | 1854 | const char *short_name; |
| 1855 | const char *long_name; |
| 1861 | 1856 | const char *interface; |
| 1862 | 1857 | char *list_name; |
| 1863 | 1858 | device_image_interface* image; |
| 1864 | 1859 | }; |
| 1865 | 1860 | |
| 1861 | /* state of the software menu */ |
| 1862 | typedef struct _software_menu_state software_menu_state; |
| 1863 | struct _software_menu_state |
| 1864 | { |
| 1865 | char *list_name; /* currently selected list */ |
| 1866 | device_image_interface* image; |
| 1867 | software_entry_state *entrylist; |
| 1868 | }; |
| 1869 | |
| 1866 | 1870 | /* state of a software part */ |
| 1867 | 1871 | typedef struct _software_part_state software_part_state; |
| 1868 | 1872 | struct _software_part_state |
| r11091 | r11092 | |
| 1942 | 1946 | } |
| 1943 | 1947 | |
| 1944 | 1948 | /* populate a specific list */ |
| 1945 | | static void ui_mess_menu_populate_software_entries(running_machine &machine, ui_menu *menu, char *list_name, device_image_interface* image) |
| 1949 | |
| 1950 | static software_entry_state *append_software_entry(ui_menu *menu, software_menu_state *menustate, |
| 1951 | software_info *swinfo, char *list_name, device_image_interface* image) |
| 1946 | 1952 | { |
| 1947 | | software_list *list = software_list_open(machine.options(), list_name, FALSE, NULL); |
| 1953 | software_entry_state *entry = NULL; |
| 1954 | software_entry_state **entryptr; |
| 1948 | 1955 | const char *interface = image->image_config().image_interface(); |
| 1949 | | if (list) |
| 1956 | |
| 1957 | // check if at least one of the parts has the correct interface and add a menu entry only in this case |
| 1958 | for (software_part *swpart = software_find_part(swinfo, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) |
| 1950 | 1959 | { |
| 1951 | | for (software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) |
| 1960 | if (strcmp(interface, swpart->interface_) == 0) |
| 1952 | 1961 | { |
| 1953 | | software_entry_state *entry = (software_entry_state *) ui_menu_pool_alloc(menu, sizeof(*entry)); |
| 1962 | // allocate a new entry |
| 1963 | entry = (software_entry_state *) ui_menu_pool_alloc(menu, sizeof(*entry)); |
| 1964 | memset(entry, 0, sizeof(*entry)); |
| 1965 | |
| 1954 | 1966 | entry->short_name = ui_menu_pool_strdup(menu, swinfo->shortname); |
| 1967 | entry->long_name = ui_menu_pool_strdup(menu, swinfo->longname); |
| 1955 | 1968 | entry->list_name = list_name; |
| 1956 | 1969 | entry->image = image; |
| 1957 | | |
| 1958 | | // check if at least one of the parts has the correct interface |
| 1959 | | for (software_part *swpart = software_find_part(swinfo, NULL, NULL); swpart != NULL; swpart = software_part_next(swpart)) |
| 1960 | | { |
| 1961 | | if (strcmp(interface, swpart->interface_) == 0) |
| 1962 | | { |
| 1963 | | entry->interface = ui_menu_pool_strdup(menu, swpart->interface_); |
| 1964 | | ui_menu_item_append(menu, swinfo->shortname, swinfo->longname, 0, entry); |
| 1965 | | break; |
| 1966 | | } |
| 1967 | | } |
| 1970 | entry->interface = ui_menu_pool_strdup(menu, swpart->interface_); |
| 1971 | break; |
| 1968 | 1972 | } |
| 1973 | } |
| 1969 | 1974 | |
| 1975 | // find the end of the list |
| 1976 | entryptr = &menustate->entrylist; |
| 1977 | while ((*entryptr != NULL) /*&& (compare_software_entries(entry, *entryptr) >= 0)*/) |
| 1978 | entryptr = &(*entryptr)->next; |
| 1979 | |
| 1980 | // insert the entry |
| 1981 | entry->next = *entryptr; |
| 1982 | *entryptr = entry; |
| 1983 | |
| 1984 | return entry; |
| 1985 | } |
| 1986 | |
| 1987 | |
| 1988 | static void ui_mess_menu_populate_software_entries(running_machine &machine, ui_menu *menu, software_menu_state *menustate) |
| 1989 | { |
| 1990 | software_list *list = software_list_open(machine.options(), menustate->list_name, FALSE, NULL); |
| 1991 | |
| 1992 | // build up the list of entries for the menu |
| 1993 | if (list) |
| 1994 | { |
| 1995 | for (software_info *swinfo = software_list_find(list, "*", NULL); swinfo != NULL; swinfo = software_list_find(list, "*", swinfo)) |
| 1996 | append_software_entry(menu, menustate, swinfo, menustate->list_name, menustate->image); |
| 1997 | |
| 1970 | 1998 | software_list_close(list); |
| 1971 | 1999 | } |
| 2000 | |
| 2001 | // append all of the menu entries |
| 2002 | for (software_entry_state *entry = menustate->entrylist; entry != NULL; entry = entry->next) |
| 2003 | ui_menu_item_append(menu, entry->short_name, entry->long_name, 0, entry); |
| 1972 | 2004 | } |
| 1973 | 2005 | |
| 1974 | 2006 | bool swinfo_has_multiple_parts(software_info *swinfo, const char *interface) |
| r11091 | r11092 | |
| 1992 | 2024 | { |
| 1993 | 2025 | if (sw_state->list_name) |
| 1994 | 2026 | { |
| 1995 | | ui_mess_menu_populate_software_entries(machine, menu, sw_state->list_name, sw_state->image); |
| 2027 | ui_mess_menu_populate_software_entries(machine, menu, sw_state); |
| 1996 | 2028 | } |
| 1997 | 2029 | } |
| 1998 | 2030 | |
| r11091 | r11092 | |
| 2035 | 2067 | bool haveCompatible = FALSE; |
| 2036 | 2068 | const char *interface = image->image_config().image_interface(); |
| 2037 | 2069 | |
| 2070 | // Add original software lists for this system |
| 2038 | 2071 | for (const device_config *dev = machine.config().m_devicelist.first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) |
| 2039 | 2072 | { |
| 2040 | 2073 | software_list_config *swlist = (software_list_config *)downcast<const legacy_device_config_base *>(dev)->inline_config(); |
| r11091 | r11092 | |
| 2065 | 2098 | } |
| 2066 | 2099 | } |
| 2067 | 2100 | |
| 2101 | // Add compatible software lists for this system |
| 2068 | 2102 | for (const device_config *dev = machine.config().m_devicelist.first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) |
| 2069 | 2103 | { |
| 2070 | 2104 | software_list_config *swlist = (software_list_config *)downcast<const legacy_device_config_base *>(dev)->inline_config(); |
| r11091 | r11092 | |
| 2117 | 2151 | software_menu_state *child_menustate = (software_menu_state *)ui_menu_alloc_state(child_menu, sizeof(*child_menustate), NULL); |
| 2118 | 2152 | child_menustate->list_name = (char *)event->itemref; |
| 2119 | 2153 | child_menustate->image = image; |
| 2154 | child_menustate->entrylist = NULL; |
| 2120 | 2155 | ui_menu_stack_push(child_menu); |
| 2121 | 2156 | } |
| 2122 | 2157 | } |