src/emu/clifront.c
| r7700 | r7701 | |
| 57 | 57 | static int info_romident(core_options *options, const char *gamename); |
| 58 | 58 | |
| 59 | 59 | /* utilities */ |
| 60 | | static void romident(const char *filename, romident_status *status); |
| 61 | | static void identify_file(const char *name, romident_status *status); |
| 62 | | static void identify_data(const char *name, const UINT8 *data, int length, romident_status *status); |
| 63 | | static void match_roms(const char *hash, int length, int *found); |
| 60 | static void romident(core_options *options, const char *filename, romident_status *status); |
| 61 | static void identify_file(core_options *options, const char *name, romident_status *status); |
| 62 | static void identify_data(core_options *options, const char *name, const UINT8 *data, int length, romident_status *status); |
| 63 | static void match_roms(core_options *options, const char *hash, int length, int *found); |
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | |
| r7700 | r7701 | |
| 97 | 97 | { "listdevices;ld", "0", OPTION_COMMAND, "list available devices" }, |
| 98 | 98 | #ifdef MESS |
| 99 | 99 | { "listmedia;lm", "0", OPTION_COMMAND, "list available media for the system" }, |
| 100 | { "listsoftware", "0", OPTION_COMMAND, "list known software for the system" }, |
| 100 | 101 | #endif |
| 101 | 102 | |
| 102 | 103 | { NULL } |
| r7700 | r7701 | |
| 274 | 275 | { CLIOPTION_VERIFYSAMPLES, info_verifysamples }, |
| 275 | 276 | #ifdef MESS |
| 276 | 277 | { CLIOPTION_LISTMEDIA, info_listmedia }, |
| 278 | { CLIOPTION_LISTSOFTWARE, info_listsoftware }, |
| 277 | 279 | #endif |
| 278 | 280 | { CLIOPTION_ROMIDENT, info_romident } |
| 279 | 281 | }; |
| r7700 | r7701 | |
| 876 | 878 | return MAMERR_FATALERROR; |
| 877 | 879 | |
| 878 | 880 | /* do the identification */ |
| 879 | | romident(gamename, &status); |
| 881 | romident(options, gamename, &status); |
| 880 | 882 | |
| 881 | 883 | /* clear out any cached files */ |
| 882 | 884 | zip_file_cache_clear(); |
| r7700 | r7701 | |
| 902 | 904 | romident - identify files |
| 903 | 905 | -------------------------------------------------*/ |
| 904 | 906 | |
| 905 | | static void romident(const char *filename, romident_status *status) |
| 907 | static void romident(core_options *options, const char *filename, romident_status *status) |
| 906 | 908 | { |
| 907 | 909 | osd_directory *directory; |
| 908 | 910 | |
| r7700 | r7701 | |
| 920 | 922 | if (entry->type == ENTTYPE_FILE) |
| 921 | 923 | { |
| 922 | 924 | astring curfile(filename, PATH_SEPARATOR, entry->name); |
| 923 | | identify_file(curfile, status); |
| 925 | identify_file(options, curfile, status); |
| 924 | 926 | } |
| 925 | 927 | osd_closedir(directory); |
| 926 | 928 | } |
| r7700 | r7701 | |
| 945 | 947 | /* decompress data into RAM and identify it */ |
| 946 | 948 | ziperr = zip_file_decompress(zip, data, entry->uncompressed_length); |
| 947 | 949 | if (ziperr == ZIPERR_NONE) |
| 948 | | identify_data(entry->filename, data, entry->uncompressed_length, status); |
| 950 | identify_data(options, entry->filename, data, entry->uncompressed_length, status); |
| 949 | 951 | global_free(data); |
| 950 | 952 | } |
| 951 | 953 | } |
| r7700 | r7701 | |
| 957 | 959 | |
| 958 | 960 | /* otherwise, identify as a raw file */ |
| 959 | 961 | else |
| 960 | | identify_file(filename, status); |
| 962 | identify_file(options, filename, status); |
| 961 | 963 | } |
| 962 | 964 | |
| 963 | 965 | |
| r7700 | r7701 | |
| 967 | 969 | files |
| 968 | 970 | -------------------------------------------------*/ |
| 969 | 971 | |
| 970 | | static void identify_file(const char *name, romident_status *status) |
| 972 | static void identify_file(core_options *options, const char *name, romident_status *status) |
| 971 | 973 | { |
| 972 | 974 | file_error filerr; |
| 973 | 975 | osd_file *file; |
| r7700 | r7701 | |
| 985 | 987 | /* read file data into RAM and identify it */ |
| 986 | 988 | filerr = osd_read(file, data, 0, length, &bytes); |
| 987 | 989 | if (filerr == FILERR_NONE) |
| 988 | | identify_data(name, data, bytes, status); |
| 990 | identify_data(options, name, data, bytes, status); |
| 989 | 991 | global_free(data); |
| 990 | 992 | } |
| 991 | 993 | osd_close(file); |
| r7700 | r7701 | |
| 999 | 1001 | fusemap into raw data first |
| 1000 | 1002 | -------------------------------------------------*/ |
| 1001 | 1003 | |
| 1002 | | static void identify_data(const char *name, const UINT8 *data, int length, romident_status *status) |
| 1004 | static void identify_data(core_options *options, const char *name, const UINT8 *data, int length, romident_status *status) |
| 1003 | 1005 | { |
| 1004 | 1006 | char hash[HASH_BUF_SIZE]; |
| 1005 | 1007 | UINT8 *tempjed = NULL; |
| r7700 | r7701 | |
| 1031 | 1033 | mame_printf_info("%-20s", basename.cstr()); |
| 1032 | 1034 | |
| 1033 | 1035 | /* see if we can find a match in the ROMs */ |
| 1034 | | match_roms(hash, length, &found); |
| 1036 | match_roms(options, hash, length, &found); |
| 1035 | 1037 | |
| 1036 | 1038 | /* if we didn't find it, try to guess what it might be */ |
| 1037 | 1039 | if (found == 0) |
| r7700 | r7701 | |
| 1062 | 1064 | match_roms - scan for a matching ROM by hash |
| 1063 | 1065 | -------------------------------------------------*/ |
| 1064 | 1066 | |
| 1065 | | static void match_roms(const char *hash, int length, int *found) |
| 1067 | static void match_roms(core_options *options, const char *hash, int length, int *found) |
| 1066 | 1068 | { |
| 1067 | 1069 | int drvindex; |
| 1068 | 1070 | |
| r7700 | r7701 | |
| 1090 | 1092 | |
| 1091 | 1093 | machine_config_free(config); |
| 1092 | 1094 | } |
| 1095 | |
| 1096 | #ifdef MESS |
| 1097 | mess_match_roms( options, hash, length, found ); |
| 1098 | #endif |
| 1093 | 1099 | } |
src/mess/climess.c
| r7700 | r7701 | |
| 10 | 10 | #include "climess.h" |
| 11 | 11 | #include "output.h" |
| 12 | 12 | #include "hash.h" |
| 13 | #include "xmlfile.h" |
| 13 | 14 | |
| 14 | 15 | |
| 15 | 16 | /*------------------------------------------------- |
| r7700 | r7701 | |
| 109 | 110 | |
| 110 | 111 | |
| 111 | 112 | /*------------------------------------------------- |
| 113 | info_listsoftware - output the list of |
| 114 | software supported by a given game or set of |
| 115 | games |
| 116 | TODO: Avoid outputting lists more than once. |
| 117 | TODO: Add DTD. |
| 118 | -------------------------------------------------*/ |
| 119 | |
| 120 | int info_listsoftware(core_options *options, const char *gamename) |
| 121 | { |
| 122 | FILE *out = stdout; |
| 123 | |
| 124 | fprintf( out, |
| 125 | "<?xml version=\"1.0\"?>\n" |
| 126 | "<softwarelists>\n" |
| 127 | ); |
| 128 | |
| 129 | for ( int drvindex = 0; drivers[drvindex] != NULL; drvindex++ ) |
| 130 | { |
| 131 | if ( mame_strwildcmp( gamename, drivers[drvindex]->name ) == 0 ) |
| 132 | { |
| 133 | /* allocate the machine config */ |
| 134 | machine_config *config = machine_config_alloc( drivers[drvindex]->machine_config ); |
| 135 | |
| 136 | for (const device_config *dev = config->devicelist.first(); dev != NULL; dev = dev->next) |
| 137 | { |
| 138 | if ( ! strcmp( dev->tag(), __SOFTWARE_LIST_TAG ) ) |
| 139 | { |
| 140 | software_list_config *swlist = (software_list_config *)dev->inline_config; |
| 141 | |
| 142 | for ( int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++ ) |
| 143 | { |
| 144 | if ( swlist->list_name[i] ) |
| 145 | { |
| 146 | fprintf(out, "\t<softwarelist name=\"%s\">\n", swlist->list_name[i] ); |
| 147 | |
| 148 | software_list *list = software_list_open( options, swlist->list_name[i], FALSE, NULL ); |
| 149 | |
| 150 | for ( software_info *swinfo = software_list_first( list ); swinfo != NULL; swinfo = software_list_next( list ) ) |
| 151 | { |
| 152 | fprintf( out, "\t\t<software name=\"%s\"", swinfo->shortname ); |
| 153 | if ( swinfo->supported == SOFTWARE_SUPPORTED_PARTIAL ) |
| 154 | fprintf( out, " supported=\"partial\"" ); |
| 155 | if ( swinfo->supported == SOFTWARE_SUPPORTED_NO ) |
| 156 | fprintf( out, " supported=\"no\"" ); |
| 157 | fprintf( out, ">\n" ); |
| 158 | fprintf( out, "\t\t\t<description>%s</description>\n", xml_normalize_string(swinfo->longname) ); |
| 159 | fprintf( out, "\t\t\t<year>%s</year>\n", xml_normalize_string( swinfo->year ) ); |
| 160 | fprintf( out, "\t\t\t<publisher>%s</publisher>\n", xml_normalize_string( swinfo->publisher ) ); |
| 161 | |
| 162 | for ( software_part *part = software_find_part( swinfo, NULL, NULL ); part != NULL; part = software_part_next( part ) ) |
| 163 | { |
| 164 | fprintf( out, "\t\t\t<part name=\"%s\"", part->name ); |
| 165 | if ( part->interface ) |
| 166 | fprintf( out, " interface=\"%s\"", part->interface ); |
| 167 | if ( part->feature ) |
| 168 | fprintf( out, " features=\"%s\"", part->feature ); |
| 169 | fprintf( out, ">\n"); |
| 170 | |
| 171 | /* TODO: display rom region information */ |
| 172 | for ( const rom_entry *region = part->romdata; region; region = rom_next_region( region ) ) |
| 173 | { |
| 174 | fprintf( out, "\t\t\t\t<dataarea name=\"%s\" size=\"%x\">\n", ROMREGION_GETTAG(region), ROMREGION_GETLENGTH(region) ); |
| 175 | |
| 176 | for ( const rom_entry *rom = rom_first_file( region ); rom; rom = rom_next_file( rom ) ) |
| 177 | { |
| 178 | if ( ROMENTRY_ISFILE(rom) ) |
| 179 | { |
| 180 | fprintf( out, "\t\t\t\t\t<rom name=\"%s\" size=\"%d\"", ROM_GETNAME(rom), ROM_GETLENGTH(rom) ); |
| 181 | |
| 182 | /* dump checksum information only if there is a known dump */ |
| 183 | if (!hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_NO_DUMP)) |
| 184 | { |
| 185 | char checksum[HASH_BUF_SIZE]; |
| 186 | int hashtype; |
| 187 | |
| 188 | /* iterate over hash function types and print out their values */ |
| 189 | for (hashtype = 0; hashtype < HASH_NUM_FUNCTIONS; hashtype++) |
| 190 | if (hash_data_extract_printable_checksum(ROM_GETHASHDATA(rom), 1 << hashtype, checksum)) |
| 191 | fprintf(out, " %s=\"%s\"", hash_function_name(1 << hashtype), checksum); |
| 192 | } |
| 193 | |
| 194 | fprintf( out, " offset=\"%x\" />\n", ROM_GETOFFSET(rom) ); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | fprintf( out, "\t\t\t\t</datearea>\n" ); |
| 199 | } |
| 200 | |
| 201 | fprintf( out, "\t\t\t</part>\n" ); |
| 202 | } |
| 203 | |
| 204 | fprintf( out, "\t\t</software>\n" ); |
| 205 | } |
| 206 | |
| 207 | software_list_close( list ); |
| 208 | |
| 209 | fprintf(out, "\t</softwarelist>\n" ); |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | machine_config_free( config ); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | fprintf( out, "</softwarelists>\n" ); |
| 220 | |
| 221 | return MAMERR_NONE; |
| 222 | } |
| 223 | |
| 224 | |
| 225 | /*------------------------------------------------- |
| 112 | 226 | match_roms - scan for a matching software ROM by hash |
| 113 | 227 | -------------------------------------------------*/ |
| 114 | | void mess_match_roms(const char *hash, int length, int *found) |
| 228 | void mess_match_roms(core_options *options, const char *hash, int length, int *found) |
| 115 | 229 | { |
| 116 | | int listnum; |
| 230 | int drvindex; |
| 117 | 231 | |
| 118 | | for ( listnum = 0; software_lists[listnum] != NULL; listnum++ ) |
| 232 | /* iterate over drivers */ |
| 233 | for (drvindex = 0; drivers[drvindex] != NULL; drvindex++) |
| 119 | 234 | { |
| 120 | | const software_list *swlist = software_lists[listnum]; |
| 121 | | int j; |
| 235 | machine_config *config = machine_config_alloc(drivers[drvindex]->machine_config); |
| 122 | 236 | |
| 123 | | for ( j = 0; swlist->entries[j].name != NULL; j++ ) |
| 237 | for (const device_config *dev = config->devicelist.first(); dev != NULL; dev = dev->next) |
| 124 | 238 | { |
| 125 | | const software_entry *sw = &swlist->entries[j]; |
| 126 | | const rom_entry *region, *rom; |
| 239 | if ( ! strcmp( dev->tag(), __SOFTWARE_LIST_TAG ) ) |
| 240 | { |
| 241 | software_list_config *swlist = (software_list_config *)dev->inline_config; |
| 127 | 242 | |
| 128 | | for (region = &sw->rom_info[0]; region; region = rom_next_region(region)) |
| 129 | | { |
| 130 | | for (rom = rom_first_file(region); rom; rom = rom_next_file(rom)) |
| 243 | for ( int i = 0; i < DEVINFO_STR_SWLIST_MAX - DEVINFO_STR_SWLIST_0; i++ ) |
| 131 | 244 | { |
| 132 | | if (hash_data_is_equal(hash, ROM_GETHASHDATA(rom), 0)) |
| 245 | if ( swlist->list_name[i] ) |
| 133 | 246 | { |
| 134 | | int baddump = hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_BAD_DUMP); |
| 247 | software_list *list = software_list_open( options, swlist->list_name[i], FALSE, NULL ); |
| 135 | 248 | |
| 136 | | /* output information about the match */ |
| 137 | | if (*found != 0) |
| 138 | | mame_printf_info(" "); |
| 139 | | mame_printf_info("= %s%-20s %-10s %s [%s]\n", baddump ? "(BAD) " : "", ROM_GETNAME(rom), sw->name, sw->fullname, swlist->name); |
| 140 | | (*found)++; |
| 249 | for ( software_info *swinfo = software_list_first( list ); swinfo != NULL; swinfo = software_list_next( list ) ) |
| 250 | { |
| 251 | for ( software_part *part = software_find_part( swinfo, NULL, NULL ); part != NULL; part = software_part_next( part ) ) |
| 252 | { |
| 253 | for ( const rom_entry *region = part->romdata; region; region = rom_next_region(region) ) |
| 254 | { |
| 255 | for ( const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom) ) |
| 256 | { |
| 257 | if ( hash_data_is_equal(hash, ROM_GETHASHDATA(rom), 0) ) |
| 258 | { |
| 259 | int baddump = hash_data_has_info(ROM_GETHASHDATA(rom), HASH_INFO_BAD_DUMP); |
| 260 | |
| 261 | /* output information about the match */ |
| 262 | if (*found != 0) |
| 263 | mame_printf_info(" "); |
| 264 | mame_printf_info("= %s%-20s %s:%s %s\n", baddump ? "(BAD) " : "", ROM_GETNAME(rom), swlist->list_name[i], swinfo->shortname, swinfo->longname); |
| 265 | (*found)++; |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | software_list_close( list ); |
| 141 | 273 | } |
| 142 | 274 | } |
| 143 | 275 | } |
| 144 | 276 | } |
| 277 | |
| 278 | machine_config_free(config); |
| 145 | 279 | } |
| 146 | 280 | } |
| 147 | 281 | |
| 148 | | |