src/mess/softlist.c
| r7695 | r7696 | |
| 8 | 8 | ***************************************************************************/ |
| 9 | 9 | |
| 10 | 10 | #include "emu.h" |
| 11 | #include "pool.h" |
| 12 | #include "expat.h" |
| 13 | #include "emuopts.h" |
| 11 | 14 | #include "softlist.h" |
| 12 | 15 | |
| 13 | 16 | |
| 17 | enum softlist_parse_position |
| 18 | { |
| 19 | POS_ROOT, |
| 20 | POS_MAIN, |
| 21 | POS_SOFT, |
| 22 | POS_PART, |
| 23 | POS_DATA |
| 24 | }; |
| 25 | |
| 26 | |
| 27 | typedef struct _parse_state |
| 28 | { |
| 29 | XML_Parser parser; |
| 30 | int done; |
| 31 | |
| 32 | void (*error_proc)(const char *message); |
| 33 | void *param; |
| 34 | |
| 35 | enum softlist_parse_position pos; |
| 36 | char **text_dest; |
| 37 | } parse_state; |
| 38 | |
| 39 | |
| 40 | struct software_info_list |
| 41 | { |
| 42 | software_info info; |
| 43 | struct software_info_list *next; |
| 44 | }; |
| 45 | |
| 46 | |
| 47 | struct _software_list |
| 48 | { |
| 49 | mame_file *file; |
| 50 | object_pool *pool; |
| 51 | parse_state state; |
| 52 | struct software_info_list *software_info_list; |
| 53 | struct software_info_list *current_software_info; |
| 54 | software_info *softinfo; |
| 55 | const char *look_for; |
| 56 | int part_entries; |
| 57 | int current_part_entry; |
| 58 | int rom_entries; |
| 59 | int current_rom_entry; |
| 60 | void (*error_proc)(const char *message); |
| 61 | }; |
| 62 | |
| 63 | |
| 64 | /*************************************************************************** |
| 65 | EXPAT INTERFACES |
| 66 | ***************************************************************************/ |
| 67 | |
| 14 | 68 | /*------------------------------------------------- |
| 15 | | software_list_get_by_name - return a pointer to |
| 16 | | a software list given its name. |
| 69 | expat_malloc/expat_realloc/expat_free - |
| 70 | wrappers for memory allocation functions so |
| 71 | that they pass through out memory tracking |
| 72 | systems |
| 17 | 73 | -------------------------------------------------*/ |
| 18 | | const software_list* software_list_get_by_name(const char *name) |
| 74 | |
| 75 | static void *expat_malloc(size_t size) |
| 19 | 76 | { |
| 20 | | int listnum; |
| 77 | return global_alloc_array_clear(UINT8,size); |
| 78 | } |
| 21 | 79 | |
| 22 | | /* scan for a match in the list of software lists */ |
| 23 | | for ( listnum = 0; software_lists[listnum] != NULL; listnum++ ) |
| 80 | static void *expat_realloc(void *ptr, size_t size) |
| 81 | { |
| 82 | if (ptr) global_free(ptr); |
| 83 | return global_alloc_array_clear(UINT8,size); |
| 84 | } |
| 85 | |
| 86 | static void expat_free(void *ptr) |
| 87 | { |
| 88 | global_free(ptr); |
| 89 | } |
| 90 | |
| 91 | |
| 92 | /*------------------------------------------------- |
| 93 | parse_error |
| 94 | -------------------------------------------------*/ |
| 95 | |
| 96 | INLINE void ATTR_PRINTF(2,3) parse_error(parse_state *state, const char *fmt, ...) |
| 97 | { |
| 98 | char buf[256]; |
| 99 | va_list va; |
| 100 | |
| 101 | if (state->error_proc) |
| 24 | 102 | { |
| 25 | | if ( mame_stricmp( software_lists[listnum]->name, name ) == 0 ) |
| 103 | va_start(va, fmt); |
| 104 | vsnprintf(buf, ARRAY_LENGTH(buf), fmt, va); |
| 105 | va_end(va); |
| 106 | (*state->error_proc)(buf); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | |
| 111 | /*------------------------------------------------- |
| 112 | unknown_tag |
| 113 | -------------------------------------------------*/ |
| 114 | |
| 115 | INLINE void unknown_tag(parse_state *state, const char *tagname) |
| 116 | { |
| 117 | parse_error(state, "[%lu:%lu]: Unknown tag: %s\n", |
| 118 | XML_GetCurrentLineNumber(state->parser), |
| 119 | XML_GetCurrentColumnNumber(state->parser), |
| 120 | tagname); |
| 121 | } |
| 122 | |
| 123 | |
| 124 | |
| 125 | /*------------------------------------------------- |
| 126 | unknown_attribute |
| 127 | -------------------------------------------------*/ |
| 128 | |
| 129 | INLINE void unknown_attribute(parse_state *state, const char *attrname) |
| 130 | { |
| 131 | parse_error(state, "[%lu:%lu]: Unknown attribute: %s\n", |
| 132 | XML_GetCurrentLineNumber(state->parser), |
| 133 | XML_GetCurrentColumnNumber(state->parser), |
| 134 | attrname); |
| 135 | } |
| 136 | |
| 137 | |
| 138 | |
| 139 | /*------------------------------------------------- |
| 140 | unknown_attribute_value |
| 141 | -------------------------------------------------*/ |
| 142 | |
| 143 | INLINE void unknown_attribute_value(parse_state *state, |
| 144 | const char *attrname, const char *attrvalue) |
| 145 | { |
| 146 | parse_error(state, "[%lu:%lu]: Unknown attribute value: %s\n", |
| 147 | XML_GetCurrentLineNumber(state->parser), |
| 148 | XML_GetCurrentColumnNumber(state->parser), |
| 149 | attrvalue); |
| 150 | } |
| 151 | |
| 152 | |
| 153 | /*------------------------------------------------- |
| 154 | software_name_split |
| 155 | helper; splits a software_list:software:part |
| 156 | string into seperate software_list, software, |
| 157 | and part strings. |
| 158 | |
| 159 | str1:str2:str3 => swlist_name - str1, swname - str2, swpart - str3 |
| 160 | str1:str2 => swlist_name - NULL, swname - str1, swpart - str2 |
| 161 | str1 => swlist_name - NULL, swname - str1, swpart - NULL |
| 162 | |
| 163 | swlist_namem, swnane and swpart will be global_alloc'ed |
| 164 | from the global pool. So they should be global_free'ed |
| 165 | when they are not used anymore. |
| 166 | -------------------------------------------------*/ |
| 167 | static void software_name_split(const char *swlist_swname, char **swlist_name, char **swname, char **swpart ) |
| 168 | { |
| 169 | const char *split_1st_loc = strchr( swlist_swname, ':' ); |
| 170 | const char *split_2nd_loc = ( split_1st_loc ) ? strchr( split_1st_loc + 1, ':' ) : NULL; |
| 171 | |
| 172 | *swlist_name = NULL; |
| 173 | *swname = NULL; |
| 174 | *swpart = NULL; |
| 175 | |
| 176 | if ( split_1st_loc ) |
| 177 | { |
| 178 | if ( split_2nd_loc ) |
| 26 | 179 | { |
| 27 | | return software_lists[listnum]; |
| 180 | int size = split_1st_loc - swlist_swname; |
| 181 | *swlist_name = global_alloc_array_clear(char,size+1); |
| 182 | memcpy( *swlist_name, swlist_swname, size ); |
| 183 | |
| 184 | size = split_2nd_loc - ( split_1st_loc + 1 ); |
| 185 | *swname = global_alloc_array_clear(char,size+1); |
| 186 | memcpy( *swname, split_1st_loc + 1, size ); |
| 187 | |
| 188 | size = strlen( swlist_swname ) - ( split_2nd_loc + 1 - swlist_swname ); |
| 189 | *swpart = global_alloc_array_clear(char,size+1); |
| 190 | memcpy( *swpart, split_2nd_loc + 1, size ); |
| 28 | 191 | } |
| 192 | else |
| 193 | { |
| 194 | int size = split_1st_loc - swlist_swname; |
| 195 | *swname = global_alloc_array_clear(char,size+1); |
| 196 | memcpy( *swname, swlist_swname, size ); |
| 197 | |
| 198 | size = strlen( swlist_swname ) - ( split_1st_loc + 1 - swlist_swname ); |
| 199 | *swpart = global_alloc_array_clear(char,size+1); |
| 200 | memcpy( *swpart, split_1st_loc + 1, size ); |
| 201 | } |
| 29 | 202 | } |
| 203 | else |
| 204 | { |
| 205 | int size = strlen( swlist_swname ); |
| 206 | *swname = global_alloc_array_clear(char,size+1); |
| 207 | memcpy( *swname, swlist_swname, size ); |
| 208 | } |
| 209 | } |
| 30 | 210 | |
| 31 | | return NULL; |
| 211 | |
| 212 | /*------------------------------------------------- |
| 213 | add_rom_entry |
| 214 | -------------------------------------------------*/ |
| 215 | |
| 216 | static void add_rom_entry(software_list *swlist, const char *name, const char *hashdata, UINT32 offset, UINT32 length, UINT32 flags) |
| 217 | { |
| 218 | software_part *part = &swlist->softinfo->partdata[swlist->current_part_entry-1]; |
| 219 | struct rom_entry *entry = &part->romdata[swlist->current_rom_entry]; |
| 220 | |
| 221 | entry->_name = name; |
| 222 | entry->_hashdata = hashdata; |
| 223 | entry->_offset = offset; |
| 224 | entry->_length = length; |
| 225 | entry->_flags = flags; |
| 226 | |
| 227 | swlist->current_rom_entry += 1; |
| 228 | |
| 229 | if ( swlist->current_rom_entry >= swlist->rom_entries ) |
| 230 | { |
| 231 | struct rom_entry *new_entries; |
| 232 | |
| 233 | swlist->rom_entries += 10; |
| 234 | new_entries = (struct rom_entry *)pool_realloc_lib(swlist->pool, part->romdata, swlist->rom_entries * sizeof(struct rom_entry) ); |
| 235 | |
| 236 | if ( new_entries ) |
| 237 | { |
| 238 | part->romdata = new_entries; |
| 239 | } |
| 240 | else |
| 241 | { |
| 242 | /* Allocation error */ |
| 243 | swlist->current_rom_entry -= 1; |
| 244 | } |
| 245 | } |
| 32 | 246 | } |
| 33 | 247 | |
| 34 | 248 | |
| 35 | 249 | /*------------------------------------------------- |
| 36 | | software_get_by_name - return a pointer to |
| 37 | | a software entry list given its name and a |
| 38 | | software list. |
| 250 | add_software_part |
| 39 | 251 | -------------------------------------------------*/ |
| 40 | 252 | |
| 41 | | const software_entry* software_get_by_name(const software_list* list, const char *name) |
| 253 | static void add_software_part(software_list *swlist, const char *name, const char *interface, const char *feature) |
| 42 | 254 | { |
| 43 | | const char *softname; |
| 44 | | int entrynum; |
| 255 | software_part *part = &swlist->softinfo->partdata[swlist->current_part_entry]; |
| 45 | 256 | |
| 46 | | assert( name != NULL ); |
| 257 | part->name = name; |
| 258 | part->interface = interface; |
| 259 | part->feature = feature; |
| 260 | part->romdata = NULL; |
| 47 | 261 | |
| 48 | | softname = strrchr( name, ':' ); |
| 49 | | if ( softname ) |
| 50 | | softname++; /* Skip ':' */ |
| 51 | | else |
| 52 | | softname = name; |
| 262 | swlist->current_part_entry += 1; |
| 53 | 263 | |
| 54 | | /* scan for a match in the software list */ |
| 55 | | for ( entrynum = 0; list->entries[entrynum].name != NULL; entrynum++ ) |
| 264 | if ( swlist->current_part_entry >= swlist->part_entries ) |
| 56 | 265 | { |
| 57 | | if ( mame_stricmp( list->entries[entrynum].name, softname ) == 0 ) |
| 266 | software_part *new_parts; |
| 267 | |
| 268 | swlist->part_entries += 2; |
| 269 | new_parts = (software_part *)pool_realloc_lib(swlist->pool, swlist->softinfo->partdata, swlist->part_entries * sizeof(software_part) ); |
| 270 | |
| 271 | if ( new_parts ) |
| 58 | 272 | { |
| 59 | | return &list->entries[entrynum]; |
| 273 | swlist->softinfo->partdata = new_parts; |
| 60 | 274 | } |
| 275 | else |
| 276 | { |
| 277 | /* Allocation error */ |
| 278 | swlist->current_part_entry -= 1; |
| 279 | } |
| 61 | 280 | } |
| 281 | } |
| 282 | |
| 283 | |
| 284 | /*------------------------------------------------- |
| 285 | start_handler |
| 286 | -------------------------------------------------*/ |
| 287 | |
| 288 | static void start_handler(void *data, const char *tagname, const char **attributes) |
| 289 | { |
| 290 | software_list *swlist = (software_list *) data; |
| 291 | char **text_dest; |
| 292 | |
| 293 | switch(swlist->state.pos) |
| 294 | { |
| 295 | case POS_ROOT: |
| 296 | if (!strcmp(tagname, "softwarelist")) |
| 297 | { |
| 298 | for( ; attributes[0]; attributes += 2 ) |
| 299 | { |
| 300 | if ( ! strcmp(attributes[0], "name" ) ) |
| 301 | { |
| 302 | } |
| 303 | if ( ! strcmp(attributes[0], "description" ) ) |
| 304 | { |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | else |
| 309 | { |
| 310 | unknown_tag(&swlist->state, tagname); |
| 311 | } |
| 312 | break; |
| 313 | |
| 314 | case POS_MAIN: |
| 315 | if ( !strcmp( tagname, "software" ) ) |
| 316 | { |
| 317 | const char *name = NULL; |
| 318 | const char *supported = NULL; |
| 319 | |
| 320 | for ( ; attributes[0]; attributes += 2 ) |
| 321 | { |
| 322 | if ( !strcmp( attributes[0], "name" ) ) |
| 323 | { |
| 324 | name = attributes[1]; |
| 325 | } |
| 326 | if ( !strcmp( attributes[0], "supported" ) ) |
| 327 | { |
| 328 | supported = attributes[1]; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | if ( name && !mame_strwildcmp( swlist->look_for, name ) ) |
| 333 | { |
| 334 | struct software_info_list *elem = (struct software_info_list *)pool_malloc_lib(swlist->pool,sizeof(struct software_info_list)); |
| 335 | |
| 336 | if ( !elem ) |
| 337 | return; |
| 338 | |
| 339 | /* Clear element and add element to list */ |
| 340 | memset(elem,0,sizeof(struct software_info_list)); |
| 341 | |
| 342 | /* Allocate space to hold the shortname and copy the short name */ |
| 343 | elem->info.shortname = (const char*)pool_malloc_lib(swlist->pool, ( strlen( name ) + 1 ) * sizeof(char) ); |
| 344 | |
| 345 | if ( ! elem->info.shortname ) |
| 346 | return; |
| 347 | |
| 348 | strcpy( (char *)elem->info.shortname, name ); |
| 349 | |
| 350 | /* Allocate initial space to hold part information */ |
| 351 | swlist->part_entries = 2; |
| 352 | swlist->current_part_entry = 0; |
| 353 | elem->info.partdata = (software_part *)pool_malloc_lib(swlist->pool, swlist->part_entries * sizeof(software_part) ); |
| 354 | if ( !elem->info.partdata ) |
| 355 | return; |
| 356 | |
| 357 | /* Handle the supported flag */ |
| 358 | elem->info.supported = SOFTWARE_SUPPORTED_YES; |
| 359 | if ( ! strcmp( supported, "partial" ) ) |
| 360 | elem->info.supported = SOFTWARE_SUPPORTED_PARTIAL; |
| 361 | if ( ! strcmp( supported, "no" ) ) |
| 362 | elem->info.supported = SOFTWARE_SUPPORTED_NO; |
| 363 | |
| 364 | /* Add the entry to the end of the list */ |
| 365 | if ( swlist->software_info_list == NULL ) |
| 366 | { |
| 367 | swlist->software_info_list = elem; |
| 368 | swlist->current_software_info = elem; |
| 369 | } |
| 370 | else |
| 371 | { |
| 372 | swlist->current_software_info->next = elem; |
| 373 | swlist->current_software_info = elem; |
| 374 | } |
| 375 | |
| 376 | /* Quick lookup for setting software information */ |
| 377 | swlist->softinfo = &swlist->current_software_info->info; |
| 378 | } |
| 379 | else |
| 380 | { |
| 381 | swlist->softinfo = NULL; |
| 382 | } |
| 383 | } |
| 384 | else |
| 385 | { |
| 386 | unknown_tag(&swlist->state, tagname); |
| 387 | } |
| 388 | break; |
| 389 | |
| 390 | case POS_SOFT: |
| 391 | text_dest = NULL; |
| 392 | |
| 393 | if (!strcmp(tagname, "description")) |
| 394 | text_dest = (char **) &swlist->softinfo->longname; |
| 395 | else if (!strcmp(tagname, "year")) |
| 396 | text_dest = (char **) &swlist->softinfo->year; |
| 397 | else if (!strcmp(tagname, "publisher")) |
| 398 | text_dest = (char **) &swlist->softinfo->publisher; |
| 399 | else if ( !strcmp(tagname, "part" ) ) |
| 400 | { |
| 401 | const char *str_name = NULL; |
| 402 | const char *str_interface = NULL; |
| 403 | const char *str_feature = NULL; |
| 404 | |
| 405 | for ( ; attributes[0]; attributes += 2 ) |
| 406 | { |
| 407 | if ( !strcmp( attributes[0], "name" ) ) |
| 408 | str_name = attributes[1]; |
| 409 | |
| 410 | if ( !strcmp( attributes[0], "interface" ) ) |
| 411 | str_interface = attributes[1]; |
| 412 | |
| 413 | if ( !strcmp( attributes[0], "feature" ) ) |
| 414 | str_feature = attributes[1]; |
| 415 | } |
| 416 | |
| 417 | if ( str_name && str_interface ) |
| 418 | { |
| 419 | if ( swlist->softinfo ) |
| 420 | { |
| 421 | char *name = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_name ) + 1 ) * sizeof(char) ); |
| 422 | char *interface = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_interface ) + 1 ) * sizeof(char) ); |
| 423 | char *feature = NULL; |
| 424 | |
| 425 | if ( !name || !interface ) |
| 426 | return; |
| 427 | |
| 428 | strcpy( name, str_name ); |
| 429 | strcpy( interface, str_interface ); |
| 430 | |
| 431 | if ( str_feature ) |
| 432 | { |
| 433 | feature = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_feature ) + 1 ) * sizeof(char) ); |
| 434 | if ( !feature ) |
| 435 | return; |
| 436 | strcpy( feature, str_feature ); |
| 437 | } |
| 438 | |
| 439 | add_software_part( swlist, name, interface, feature ); |
| 440 | |
| 441 | /* Allocate initial space to hold the rom information */ |
| 442 | swlist->rom_entries = 3; |
| 443 | swlist->current_rom_entry = 0; |
| 444 | swlist->softinfo->partdata[swlist->current_part_entry-1].romdata = (struct rom_entry *)pool_malloc_lib(swlist->pool, swlist->rom_entries * sizeof(struct rom_entry)); |
| 445 | if ( ! swlist->softinfo->partdata[swlist->current_part_entry-1].romdata ) |
| 446 | return; |
| 447 | } |
| 448 | } |
| 449 | else |
| 450 | { |
| 451 | /* Incomplete/incorrect part definition */ |
| 452 | } |
| 453 | } |
| 454 | else |
| 455 | unknown_tag(&swlist->state, tagname); |
| 456 | |
| 457 | if (text_dest && swlist->softinfo) |
| 458 | swlist->state.text_dest = text_dest; |
| 459 | break; |
| 460 | |
| 461 | case POS_PART: |
| 462 | if (!strcmp(tagname, "dataarea")) |
| 463 | { |
| 464 | const char *str_name = NULL; |
| 465 | const char *str_size = NULL; |
| 466 | |
| 467 | for ( ; attributes[0]; attributes += 2 ) |
| 468 | { |
| 469 | if ( !strcmp( attributes[0], "name" ) ) |
| 470 | str_name = attributes[1]; |
| 471 | |
| 472 | if ( !strcmp( attributes[0], "size") ) |
| 473 | str_size = attributes[1]; |
| 474 | } |
| 475 | if ( str_name && str_size ) |
| 476 | { |
| 477 | if ( swlist->softinfo ) |
| 478 | { |
| 479 | UINT32 length = strtol( str_size, NULL, 10 ); |
| 480 | char *s = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_name ) + 1 ) * sizeof(char) ); |
| 481 | |
| 482 | if ( !s ) |
| 483 | return; |
| 484 | |
| 485 | strcpy( s, str_name ); |
| 486 | |
| 487 | /* ROM_REGION( length, "name", flags ) */ |
| 488 | add_rom_entry( swlist, s, NULL, 0, length, ROMENTRYTYPE_REGION ); |
| 489 | } |
| 490 | } |
| 491 | else |
| 492 | { |
| 493 | /* Missing dataarea name or size */ |
| 494 | } |
| 495 | } |
| 496 | else |
| 497 | unknown_tag( &swlist->state, tagname ); |
| 498 | break; |
| 499 | |
| 500 | case POS_DATA: |
| 501 | if (!strcmp(tagname, "rom")) |
| 502 | { |
| 503 | const char *str_name = NULL; |
| 504 | const char *str_size = NULL; |
| 505 | const char *str_crc = NULL; |
| 506 | const char *str_sha1 = NULL; |
| 507 | const char *str_offset = NULL; |
| 508 | const char *str_loadflag = NULL; |
| 509 | |
| 510 | for ( ; attributes[0]; attributes += 2 ) |
| 511 | { |
| 512 | if ( !strcmp( attributes[0], "name" ) ) |
| 513 | str_name = attributes[1]; |
| 514 | if ( !strcmp( attributes[0], "size" ) ) |
| 515 | str_size = attributes[1]; |
| 516 | if ( !strcmp( attributes[0], "crc" ) ) |
| 517 | str_crc = attributes[1]; |
| 518 | if ( !strcmp( attributes[0], "sha1" ) ) |
| 519 | str_sha1 = attributes[1]; |
| 520 | if ( !strcmp( attributes[0], "offset" ) ) |
| 521 | str_offset = attributes[1]; |
| 522 | if ( !strcmp( attributes[0], "loadflag" ) ) |
| 523 | str_loadflag = attributes[1]; |
| 524 | } |
| 525 | if ( str_name && str_size && str_crc && str_sha1 && str_offset ) |
| 526 | { |
| 527 | if ( swlist->softinfo ) |
| 528 | { |
| 529 | UINT32 length = strtol( str_size, NULL, 10 ); |
| 530 | UINT32 offset = strtol( str_offset, NULL, 16 ); |
| 531 | char *s_name = (char *)pool_malloc_lib(swlist->pool, ( strlen( str_name ) + 1 ) * sizeof(char) ); |
| 532 | char *hashdata = (char *)pool_malloc_lib( swlist->pool, sizeof(char) * ( strlen(str_crc) + strlen(str_sha1) + 7 ) ); |
| 533 | |
| 534 | if ( !s_name || !hashdata ) |
| 535 | return; |
| 536 | |
| 537 | strcpy( s_name, str_name ); |
| 538 | sprintf( hashdata, "c:%s#s:%s#", str_crc, str_sha1 ); |
| 539 | |
| 540 | /* ROM_LOAD( name, offset, length, hash ) */ |
| 541 | add_rom_entry( swlist, s_name, hashdata, offset, length, ROMENTRYTYPE_ROM ); |
| 542 | } |
| 543 | } |
| 544 | else |
| 545 | { |
| 546 | /* Missing name, size, crc, sha1, or offset */ |
| 547 | } |
| 548 | } |
| 549 | else |
| 550 | unknown_tag(&swlist->state, tagname); |
| 551 | break; |
| 552 | } |
| 553 | swlist->state.pos = (softlist_parse_position) (swlist->state.pos + 1); |
| 554 | } |
| 555 | |
| 556 | /*------------------------------------------------- |
| 557 | end_handler |
| 558 | -------------------------------------------------*/ |
| 559 | |
| 560 | static void end_handler(void *data, const char *name) |
| 561 | { |
| 562 | software_list *swlist = (software_list *) data; |
| 563 | swlist->state.text_dest = NULL; |
| 564 | |
| 565 | swlist->state.pos = (softlist_parse_position) (swlist->state.pos - 1); |
| 566 | switch(swlist->state.pos) |
| 567 | { |
| 568 | case POS_ROOT: |
| 569 | case POS_SOFT: |
| 570 | break; |
| 571 | |
| 572 | case POS_MAIN: |
| 573 | if ( swlist->softinfo ) |
| 574 | { |
| 575 | add_software_part( swlist, NULL, NULL, NULL ); |
| 576 | } |
| 577 | break; |
| 578 | |
| 579 | case POS_PART: |
| 580 | if ( swlist->softinfo ) |
| 581 | { |
| 582 | /* ROM_END */ |
| 583 | add_rom_entry( swlist, NULL, NULL, 0, 0, ROMENTRYTYPE_END ); |
| 584 | } |
| 585 | break; |
| 586 | |
| 587 | case POS_DATA: |
| 588 | break; |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | |
| 593 | /*------------------------------------------------- |
| 594 | data_handler |
| 595 | -------------------------------------------------*/ |
| 596 | |
| 597 | static void data_handler(void *data, const XML_Char *s, int len) |
| 598 | { |
| 599 | software_list *swlist = (software_list *) data; |
| 600 | int text_len; |
| 601 | char *text; |
| 602 | |
| 603 | if (swlist->state.text_dest) |
| 604 | { |
| 605 | text = *swlist->state.text_dest; |
| 606 | |
| 607 | text_len = text ? strlen(text) : 0; |
| 608 | text = (char*)pool_realloc_lib(swlist->pool, text, text_len + len + 1); |
| 609 | if (!text) |
| 610 | return; |
| 611 | |
| 612 | memcpy(&text[text_len], s, len); |
| 613 | text[text_len + len] = '\0'; |
| 614 | *swlist->state.text_dest = text; |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | |
| 619 | /*------------------------------------------------- |
| 620 | software_list_parse |
| 621 | -------------------------------------------------*/ |
| 622 | |
| 623 | static void software_list_parse(software_list *swlist, |
| 624 | void (*error_proc)(const char *message), |
| 625 | void *param) |
| 626 | { |
| 627 | char buf[1024]; |
| 628 | UINT32 len; |
| 629 | XML_Memory_Handling_Suite memcallbacks; |
| 630 | |
| 631 | mame_fseek(swlist->file, 0, SEEK_SET); |
| 632 | |
| 633 | memset(&swlist->state, 0, sizeof(swlist->state)); |
| 634 | swlist->state.error_proc = error_proc; |
| 635 | swlist->state.param = param; |
| 636 | |
| 637 | /* create the XML parser */ |
| 638 | memcallbacks.malloc_fcn = expat_malloc; |
| 639 | memcallbacks.realloc_fcn = expat_realloc; |
| 640 | memcallbacks.free_fcn = expat_free; |
| 641 | swlist->state.parser = XML_ParserCreate_MM(NULL, &memcallbacks, NULL); |
| 642 | if (!swlist->state.parser) |
| 643 | goto done; |
| 644 | |
| 645 | XML_SetUserData(swlist->state.parser, swlist); |
| 646 | XML_SetElementHandler(swlist->state.parser, start_handler, end_handler); |
| 647 | XML_SetCharacterDataHandler(swlist->state.parser, data_handler); |
| 648 | |
| 649 | while(!swlist->state.done) |
| 650 | { |
| 651 | len = mame_fread(swlist->file, buf, sizeof(buf)); |
| 652 | swlist->state.done = mame_feof(swlist->file); |
| 653 | if (XML_Parse(swlist->state.parser, buf, len, swlist->state.done) == XML_STATUS_ERROR) |
| 654 | { |
| 655 | parse_error(&swlist->state, "[%lu:%lu]: %s\n", |
| 656 | XML_GetCurrentLineNumber(swlist->state.parser), |
| 657 | XML_GetCurrentColumnNumber(swlist->state.parser), |
| 658 | XML_ErrorString(XML_GetErrorCode(swlist->state.parser))); |
| 659 | goto done; |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | done: |
| 664 | if (swlist->state.parser) |
| 665 | XML_ParserFree(swlist->state.parser); |
| 666 | swlist->state.parser = NULL; |
| 667 | swlist->current_software_info = swlist->software_info_list; |
| 668 | } |
| 669 | |
| 670 | |
| 671 | /*------------------------------------------------- |
| 672 | software_list_open |
| 673 | -------------------------------------------------*/ |
| 674 | |
| 675 | software_list *software_list_open(core_options *options, const char *listname, int is_preload, |
| 676 | void (*error_proc)(const char *message)) |
| 677 | { |
| 678 | file_error filerr; |
| 679 | astring *fname; |
| 680 | software_list *swlist = NULL; |
| 681 | object_pool *pool = NULL; |
| 682 | |
| 683 | /* create a pool for this software list file */ |
| 684 | pool = pool_alloc_lib(error_proc); |
| 685 | if (!pool) |
| 686 | goto error; |
| 687 | |
| 688 | /* allocate space for this software list file */ |
| 689 | swlist = (software_list *) pool_malloc_lib(pool, sizeof(*swlist)); |
| 690 | if (!swlist) |
| 691 | goto error; |
| 692 | |
| 693 | /* set up the software_list structure */ |
| 694 | memset(swlist, 0, sizeof(*swlist)); |
| 695 | swlist->pool = pool; |
| 696 | swlist->error_proc = error_proc; |
| 697 | |
| 698 | /* open a file */ |
| 699 | fname = astring_assemble_2(astring_alloc(), listname, ".xml"); |
| 700 | filerr = mame_fopen_options(options, SEARCHPATH_HASH, astring_c(fname), OPEN_FLAG_READ, &swlist->file); |
| 701 | astring_free(fname); |
| 702 | |
| 703 | if (filerr != FILERR_NONE) |
| 704 | goto error; |
| 705 | |
| 706 | // if (is_preload) |
| 707 | // software_list_parse(swlist, swlist->error_proc, NULL); |
| 708 | |
| 709 | return swlist; |
| 710 | |
| 711 | error: |
| 712 | if (swlist != NULL) |
| 713 | software_list_close(swlist); |
| 62 | 714 | return NULL; |
| 63 | 715 | } |
| 64 | 716 | |
| 65 | 717 | |
| 66 | 718 | /*------------------------------------------------- |
| 67 | | software_lists_get_count - returns the amount of |
| 68 | | drivers |
| 719 | software_list_close |
| 69 | 720 | -------------------------------------------------*/ |
| 70 | 721 | |
| 71 | | int software_lists_get_count(void) |
| 722 | void software_list_close(software_list *swlist) |
| 72 | 723 | { |
| 73 | | int count; |
| 724 | if (swlist->file) |
| 725 | mame_fclose(swlist->file); |
| 726 | pool_free_lib(swlist->pool); |
| 727 | } |
| 74 | 728 | |
| 75 | | for (count = 0; software_lists[count] != NULL; count++) ; |
| 76 | | return count; |
| 729 | |
| 730 | /*------------------------------------------------- |
| 731 | software_list_find |
| 732 | -------------------------------------------------*/ |
| 733 | |
| 734 | software_info *software_list_find(software_list *swlist, const char *software) |
| 735 | { |
| 736 | swlist->look_for = software; |
| 737 | software_list_parse( swlist, swlist->error_proc, NULL ); |
| 738 | |
| 739 | return swlist->current_software_info ? &swlist->current_software_info->info : NULL; |
| 77 | 740 | } |
| 741 | |
| 742 | |
| 743 | /*------------------------------------------------- |
| 744 | software_list_first |
| 745 | -------------------------------------------------*/ |
| 746 | |
| 747 | software_info *software_list_first(software_list *swlist) |
| 748 | { |
| 749 | return software_list_find(swlist, "*"); |
| 750 | } |
| 751 | |
| 752 | |
| 753 | /*------------------------------------------------- |
| 754 | software_list_next |
| 755 | -------------------------------------------------*/ |
| 756 | |
| 757 | software_info *software_list_next(software_list *swlist) |
| 758 | { |
| 759 | if ( swlist->current_software_info ) |
| 760 | { |
| 761 | swlist->current_software_info = swlist->current_software_info->next; |
| 762 | } |
| 763 | return swlist->current_software_info ? &swlist->current_software_info->info : NULL; |
| 764 | } |
| 765 | |
| 766 | |
| 767 | /*------------------------------------------------- |
| 768 | software_find_part |
| 769 | -------------------------------------------------*/ |
| 770 | |
| 771 | software_part *software_find_part(software_info *sw, const char *partname, const char *interface) |
| 772 | { |
| 773 | software_part *part = sw ? sw->partdata : NULL; |
| 774 | |
| 775 | /* If neither partname nor interface supplied, then we just return the first entry */ |
| 776 | if ( partname || interface ) |
| 777 | { |
| 778 | while( part && part->name ) |
| 779 | { |
| 780 | if ( partname ) |
| 781 | { |
| 782 | if ( !strcmp(partname, part->name ) ) |
| 783 | { |
| 784 | if ( interface ) |
| 785 | { |
| 786 | if ( !strcmp(interface, part->interface) ) |
| 787 | { |
| 788 | break; |
| 789 | } |
| 790 | } |
| 791 | else |
| 792 | { |
| 793 | break; |
| 794 | } |
| 795 | } |
| 796 | } |
| 797 | else |
| 798 | { |
| 799 | /* No specific partname supplied, find the first match based on interface */ |
| 800 | if ( interface ) |
| 801 | { |
| 802 | if ( !strcmp(interface, part->interface) ) |
| 803 | { |
| 804 | break; |
| 805 | } |
| 806 | } |
| 807 | } |
| 808 | part++; |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | if ( ! part->name ) |
| 813 | part = NULL; |
| 814 | |
| 815 | return part; |
| 816 | } |
| 817 | |
| 818 | |
| 819 | /*------------------------------------------------- |
| 820 | software_part_next |
| 821 | -------------------------------------------------*/ |
| 822 | |
| 823 | software_part *software_part_next(software_part *part) |
| 824 | { |
| 825 | if ( part && part->name ) |
| 826 | { |
| 827 | part++; |
| 828 | } |
| 829 | |
| 830 | if ( ! part->name ) |
| 831 | part = NULL; |
| 832 | |
| 833 | return part; |
| 834 | } |
| 835 | |
| 836 | |
| 837 | /*------------------------------------------------- |
| 838 | load_software_part |
| 839 | |
| 840 | Load a software part for a device. The part to |
| 841 | load is determined by the "path", software lists |
| 842 | configured for a driver, and the interface |
| 843 | supported by the device. |
| 844 | |
| 845 | returns true if the software could be loaded, |
| 846 | false otherwise. If the software could be loaded |
| 847 | sw_info and sw_part are also set. |
| 848 | -------------------------------------------------*/ |
| 849 | |
| 850 | bool load_software_part(running_device *device, const char *path, software_info **sw_info, software_part **sw_part, char **full_sw_name) |
| 851 | { |
| 852 | char *swlist_name, *swname, *swpart; |
| 853 | const char *interface; |
| 854 | bool result = false; |
| 855 | software_list *software_list_ptr = NULL; |
| 856 | software_info *software_info_ptr = NULL; |
| 857 | software_part *software_part_ptr = NULL; |
| 858 | |
| 859 | *sw_info = NULL; |
| 860 | *sw_part = NULL; |
| 861 | |
| 862 | /* Split full software name into software list name and short software name */ |
| 863 | software_name_split( path, &swlist_name, &swname, &swpart ); |
| 864 | |
| 865 | interface = device->get_config_string(DEVINFO_STR_INTERFACE); |
| 866 | |
| 867 | if ( swlist_name ) |
| 868 | { |
| 869 | /* Try to open the software list xml file explicitly named by the user */ |
| 870 | software_list_ptr = software_list_open( mame_options(), swlist_name, FALSE, NULL ); |
| 871 | |
| 872 | if ( software_list_ptr ) |
| 873 | { |
| 874 | software_info_ptr = software_list_find( software_list_ptr, swname ); |
| 875 | |
| 876 | if ( software_info_ptr ) |
| 877 | { |
| 878 | software_part_ptr = software_find_part( software_info_ptr, swpart, interface ); |
| 879 | } |
| 880 | } |
| 881 | } |
| 882 | else |
| 883 | { |
| 884 | /* Loop through all the software lists named in the driver */ |
| 885 | running_device *swlists = devtag_get_device( device->machine, __SOFTWARE_LIST_TAG ); |
| 886 | |
| 887 | if ( swlists ) |
| 888 | { |
| 889 | UINT32 i = DEVINFO_STR_SWLIST_0; |
| 890 | |
| 891 | while ( ! software_part_ptr && i <= DEVINFO_STR_SWLIST_MAX ) |
| 892 | { |
| 893 | swlist_name = (char *)swlists->baseconfig().get_config_string( i ); |
| 894 | |
| 895 | if ( swlist_name && *swlist_name ) |
| 896 | { |
| 897 | if ( software_list_ptr ) |
| 898 | { |
| 899 | software_list_close( software_list_ptr ); |
| 900 | } |
| 901 | |
| 902 | software_list_ptr = software_list_open( mame_options(), swlist_name, FALSE, NULL ); |
| 903 | |
| 904 | if ( software_list_ptr ) |
| 905 | { |
| 906 | software_info_ptr = software_list_find( software_list_ptr, swname ); |
| 907 | |
| 908 | if ( software_info_ptr ) |
| 909 | { |
| 910 | software_part_ptr = software_find_part( software_info_ptr, swpart, interface ); |
| 911 | } |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | i++; |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | /* If not found try to load the software list using the driver name */ |
| 920 | if ( ! software_part_ptr ) |
| 921 | { |
| 922 | swlist_name = (char *)device->machine->gamedrv->name; |
| 923 | |
| 924 | if ( software_list_ptr ) |
| 925 | { |
| 926 | software_list_close( software_list_ptr ); |
| 927 | } |
| 928 | |
| 929 | software_list_ptr = software_list_open( mame_options(), swlist_name, FALSE, NULL ); |
| 930 | |
| 931 | if ( software_list_ptr ) |
| 932 | { |
| 933 | software_info_ptr = software_list_find( software_list_ptr, swname ); |
| 934 | |
| 935 | if ( software_info_ptr ) |
| 936 | { |
| 937 | software_part_ptr = software_find_part( software_info_ptr, swpart, interface ); |
| 938 | } |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | /* If not found try to load the software list using the software name as software */ |
| 943 | /* list name and software part name as software name. */ |
| 944 | if ( ! software_part_ptr ) |
| 945 | { |
| 946 | swlist_name = swname; |
| 947 | swname = swpart; |
| 948 | swpart = NULL; |
| 949 | |
| 950 | if ( software_list_ptr ) |
| 951 | { |
| 952 | software_list_close( software_list_ptr ); |
| 953 | } |
| 954 | |
| 955 | software_list_ptr = software_list_open( mame_options(), swlist_name, FALSE, NULL ); |
| 956 | |
| 957 | if ( software_list_ptr ) |
| 958 | { |
| 959 | software_info_ptr = software_list_find( software_list_ptr, swname ); |
| 960 | |
| 961 | if ( software_info_ptr ) |
| 962 | { |
| 963 | software_part_ptr = software_find_part( software_info_ptr, swpart, interface ); |
| 964 | } |
| 965 | |
| 966 | if ( ! software_part_ptr ) |
| 967 | { |
| 968 | software_list_close( software_list_ptr ); |
| 969 | software_list_ptr = NULL; |
| 970 | } |
| 971 | } |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | if ( software_part_ptr ) |
| 976 | { |
| 977 | /* Load the software part */ |
| 978 | load_software_part_region( device, (char *)swlist_name, (char *)software_info_ptr->shortname, software_part_ptr->romdata ); |
| 979 | |
| 980 | /* Create a copy of the software and part information */ |
| 981 | *sw_info = auto_alloc_clear( device->machine, software_info ); |
| 982 | (*sw_info)->shortname = auto_strdup( device->machine, software_info_ptr->shortname ); |
| 983 | (*sw_info)->longname = auto_strdup( device->machine, software_info_ptr->longname ); |
| 984 | if ( software_info_ptr->year ) |
| 985 | (*sw_info)->year = auto_strdup( device->machine, software_info_ptr->year ); |
| 986 | if ( software_info_ptr->publisher ) |
| 987 | (*sw_info)->publisher = auto_strdup( device->machine, software_info_ptr->publisher ); |
| 988 | |
| 989 | *sw_part = auto_alloc_clear( device->machine, software_part ); |
| 990 | (*sw_part)->name = auto_strdup( device->machine, software_part_ptr->name ); |
| 991 | if ( software_part_ptr->interface ) |
| 992 | (*sw_part)->interface = auto_strdup( device->machine, software_part_ptr->interface ); |
| 993 | if ( software_part_ptr->feature ) |
| 994 | (*sw_part)->feature = auto_strdup( device->machine, software_part_ptr->feature ); |
| 995 | |
| 996 | /* Tell the world which part we actually loaded */ |
| 997 | *full_sw_name = auto_alloc_array( device->machine, char, strlen(swlist_name) + strlen(software_info_ptr->shortname) + strlen(software_part_ptr->name) + 3 ); |
| 998 | sprintf( *full_sw_name, "%s:%s:%s", swlist_name, software_info_ptr->shortname, software_part_ptr->name ); |
| 999 | |
| 1000 | result = true; |
| 1001 | } |
| 1002 | |
| 1003 | /* Close the software list if it's still open */ |
| 1004 | if ( software_list_ptr ) |
| 1005 | { |
| 1006 | software_list_close( software_list_ptr ); |
| 1007 | software_info_ptr = NULL; |
| 1008 | software_list_ptr = NULL; |
| 1009 | } |
| 1010 | global_free( swlist_name ); |
| 1011 | global_free( swname ); |
| 1012 | global_free( swpart ); |
| 1013 | |
| 1014 | return result; |
| 1015 | } |
| 1016 | |
| 1017 | |
| 1018 | /*************************************************************************** |
| 1019 | DEVICE INTERFACE |
| 1020 | ***************************************************************************/ |
| 1021 | |
| 1022 | |
| 1023 | static DEVICE_START( software_list ) |
| 1024 | { |
| 1025 | } |
| 1026 | |
| 1027 | |
| 1028 | DEVICE_GET_INFO( software_list ) |
| 1029 | { |
| 1030 | switch (state) |
| 1031 | { |
| 1032 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1033 | case DEVINFO_INT_TOKEN_BYTES: info->i = 1; break; |
| 1034 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(software_list_config); break; |
| 1035 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 1036 | |
| 1037 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1038 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( software_list ); break; |
| 1039 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 1040 | |
| 1041 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1042 | case DEVINFO_STR_NAME: strcpy(info->s, "Software lists"); break; |
| 1043 | case DEVINFO_STR_FAMILY: strcpy(info->s, "Software lists"); break; |
| 1044 | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 1045 | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 1046 | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MESS Team"); break; |
| 1047 | } |
| 1048 | |
| 1049 | if ( state >= DEVINFO_STR_SWLIST_0 && state <= DEVINFO_STR_SWLIST_MAX ) |
| 1050 | { |
| 1051 | software_list_config *config = (software_list_config *)device->inline_config; |
| 1052 | |
| 1053 | if ( config->list_name[ state - DEVINFO_STR_SWLIST_0 ] ) |
| 1054 | strcpy(info->s, config->list_name[ state - DEVINFO_STR_SWLIST_0 ]); |
| 1055 | } |
| 1056 | } |
| 1057 | |
src/mess/image.c
| r7695 | r7696 | |
| 64 | 64 | unsigned int created : 1; |
| 65 | 65 | unsigned int is_loading : 1; |
| 66 | 66 | |
| 67 | | /* Software list and software entry information */ |
| 68 | | const software_list *software_list_ptr; |
| 69 | | const software_entry *software_entry_ptr; |
| 67 | /* Software information */ |
| 68 | char *full_software_name; |
| 69 | software_info *software_info_ptr; |
| 70 | software_part *software_part_ptr; |
| 70 | 71 | |
| 71 | 72 | /* info read from the hash file */ |
| 72 | 73 | char *longname; |
| r7695 | r7696 | |
| 218 | 219 | slot->unload = (device_image_unload_func) slot->dev->get_config_fct(DEVINFO_FCT_IMAGE_UNLOAD); |
| 219 | 220 | |
| 220 | 221 | /* sodftware list and entry */ |
| 221 | | slot->software_list_ptr = software_list_get_by_name( slot->dev->get_config_string(DEVINFO_STR_SOFTWARE_LIST) ); |
| 222 | | slot->software_entry_ptr = NULL; |
| 222 | slot->full_software_name = NULL; |
| 223 | slot->software_info_ptr = NULL; |
| 224 | slot->software_part_ptr = NULL; |
| 223 | 225 | |
| 224 | 226 | /* creation option guide */ |
| 225 | 227 | slot->create_option_guide = (const option_guide *) slot->dev->get_config_ptr(DEVINFO_PTR_IMAGE_CREATE_OPTGUIDE); |
| r7695 | r7696 | |
| 381 | 383 | static void get_device_instance_name(const machine_config *config, const device_config *device, |
| 382 | 384 | char *buffer, size_t buffer_len, iodevice_t type, UINT32 state, const char *(*get_dev_typename)(iodevice_t)) |
| 383 | 385 | { |
| 384 | | const char *result; |
| 385 | | const device_config *that_device; |
| 386 | | int count, index; |
| 386 | const char *result; |
| 387 | const device_config *that_device; |
| 388 | int count, index; |
| 387 | 389 | |
| 388 | | /* retrieve info about the device instance */ |
| 389 | | result = device->get_config_string(state); |
| 390 | | if ((result != NULL) && (result[0] != '\0')) |
| 391 | | { |
| 392 | | /* we got info directly */ |
| 393 | | snprintf(buffer, buffer_len, "%s", result); |
| 394 | | } |
| 395 | | else |
| 396 | | { |
| 397 | | /* not specified? default to device names based on the device type */ |
| 398 | | result = get_dev_typename(type); |
| 390 | /* retrieve info about the device instance */ |
| 391 | result = device->get_config_string(state); |
| 392 | if ((result != NULL) && (result[0] != '\0')) |
| 393 | { |
| 394 | /* we got info directly */ |
| 395 | snprintf(buffer, buffer_len, "%s", result); |
| 396 | } |
| 397 | else |
| 398 | { |
| 399 | if ( get_dev_typename ) |
| 400 | { |
| 401 | /* not specified? default to device names based on the device type */ |
| 402 | result = get_dev_typename(type); |
| 399 | 403 | |
| 400 | | /* are there multiple devices of the same type */ |
| 401 | | count = 0; |
| 402 | | index = -1; |
| 404 | /* are there multiple devices of the same type */ |
| 405 | count = 0; |
| 406 | index = -1; |
| 403 | 407 | |
| 404 | | for (that_device = config->devicelist.first(); that_device != NULL; that_device = that_device->next) |
| 405 | | { |
| 406 | | if (is_image_device(that_device)) |
| 408 | for (that_device = config->devicelist.first(); that_device != NULL; that_device = that_device->next) |
| 407 | 409 | { |
| 408 | | if (device == that_device) |
| 409 | | index = count; |
| 410 | | if (that_device->get_config_int(DEVINFO_INT_IMAGE_TYPE) == type) |
| 411 | | count++; |
| 412 | | } |
| 413 | | } |
| 410 | if (is_image_device(that_device)) |
| 411 | { |
| 412 | if (device == that_device) |
| 413 | index = count; |
| 414 | if (that_device->get_config_int(DEVINFO_INT_IMAGE_TYPE) == type) |
| 415 | count++; |
| 416 | } |
| 417 | } |
| 414 | 418 | |
| 415 | | /* need to number if there is more than one device */ |
| 416 | | if (count > 1) |
| 417 | | snprintf(buffer, buffer_len, "%s%d", result, index + 1); |
| 418 | | else |
| 419 | | snprintf(buffer, buffer_len, "%s", result); |
| 420 | | } |
| 419 | /* need to number if there is more than one device */ |
| 420 | if (count > 1) |
| 421 | snprintf(buffer, buffer_len, "%s%d", result, index + 1); |
| 422 | else |
| 423 | snprintf(buffer, buffer_len, "%s", result); |
| 424 | } |
| 425 | } |
| 421 | 426 | } |
| 422 | 427 | |
| 423 | 428 | |
| r7695 | r7696 | |
| 458 | 463 | get_device_instance_name(config, device, info.brief_instance_name, ARRAY_LENGTH(info.brief_instance_name), |
| 459 | 464 | info.type, DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME, device_brieftypename); |
| 460 | 465 | |
| 466 | /* retrieve interface name */ |
| 467 | get_device_instance_name(config, device, info.interface_name, ARRAY_LENGTH(info.interface_name), |
| 468 | info.type, DEVINFO_STR_INTERFACE, NULL); |
| 469 | |
| 461 | 470 | return info; |
| 462 | 471 | } |
| 463 | 472 | |
| r7695 | r7696 | |
| 658 | 667 | |
| 659 | 668 | static int is_loaded(image_slot_data *image) |
| 660 | 669 | { |
| 661 | | return (image->file != NULL) || (image->ptr != NULL) || (image->software_entry_ptr != NULL); |
| 670 | return (image->file != NULL) || (image->ptr != NULL) || (image->software_info_ptr != NULL); |
| 662 | 671 | } |
| 663 | 672 | |
| 664 | 673 | |
| r7695 | r7696 | |
| 802 | 811 | mame_schedule_hard_reset(machine); |
| 803 | 812 | |
| 804 | 813 | /* Check if there's a software list defined for this device and use that if we're not creating an image */ |
| 805 | | /* This piece below is commented out until load_region_list or something better is available in src/emu/romload */ |
| 806 | 814 | #if 0 |
| 807 | | if ( !is_create && slot->software_list_ptr ) |
| 815 | if ( is_create || !load_software_part( image, path, &slot->software_info_ptr, &slot->software_part_ptr, &slot->full_software_name ) ) |
| 816 | #endif |
| 808 | 817 | { |
| 809 | | slot->software_entry = software_get_by_name( slot->software_list_ptr, path ); |
| 818 | /* determine open plan */ |
| 819 | determine_open_plan(slot, is_create, open_plan); |
| 810 | 820 | |
| 811 | | if ( slot->software_entry ) |
| 821 | /* attempt to open the file in various ways */ |
| 822 | for (i = 0; !slot->file && open_plan[i]; i++) |
| 812 | 823 | { |
| 813 | | char swname[256]; |
| 814 | | |
| 815 | | sprintf( swname, "%s:%s", slot->software_list_ptr->name, slot->software_entry->name ); |
| 816 | | |
| 817 | | load_software_region(slot->dev, swname, slot->software_entry->rom_info ); |
| 818 | | |
| 819 | | /* call device load or create */ |
| 820 | | if (image->token != NULL) |
| 821 | | { |
| 822 | | err = image_finish_load(image); |
| 823 | | if (err) |
| 824 | | goto done; |
| 825 | | } |
| 826 | | |
| 827 | | goto done; |
| 824 | /* open the file */ |
| 825 | slot->err = load_image_by_path(slot, open_plan[i], path); |
| 826 | if (slot->err && (slot->err != IMAGE_ERROR_FILENOTFOUND)) |
| 827 | goto done; |
| 828 | 828 | } |
| 829 | 829 | } |
| 830 | | #endif |
| 831 | 830 | |
| 832 | | /* determine open plan */ |
| 833 | | determine_open_plan(slot, is_create, open_plan); |
| 831 | /* did we fail to find the file? */ |
| 832 | if (!is_loaded(slot)) |
| 833 | { |
| 834 | slot->err = IMAGE_ERROR_FILENOTFOUND; |
| 835 | goto done; |
| 836 | } |
| 834 | 837 | |
| 835 | | /* attempt to open the file in various ways */ |
| 836 | | for (i = 0; !slot->file && open_plan[i]; i++) |
| 837 | | { |
| 838 | | /* open the file */ |
| 839 | | slot->err = load_image_by_path(slot, open_plan[i], path); |
| 840 | | if (slot->err && (slot->err != IMAGE_ERROR_FILENOTFOUND)) |
| 841 | | goto done; |
| 842 | | } |
| 838 | /* call device load or create */ |
| 839 | if (image->token != NULL) |
| 840 | { |
| 841 | slot->create_format = create_format; |
| 842 | slot->create_args = create_args; |
| 843 | 843 | |
| 844 | | /* did we fail to find the file? */ |
| 845 | | if (!is_loaded(slot)) |
| 846 | | { |
| 847 | | slot->err = IMAGE_ERROR_FILENOTFOUND; |
| 848 | | goto done; |
| 849 | | } |
| 850 | | |
| 851 | | /* call device load or create */ |
| 852 | | if (image->token != NULL) |
| 853 | | { |
| 854 | | slot->create_format = create_format; |
| 855 | | slot->create_args = create_args; |
| 856 | | |
| 857 | 844 | if (slot->not_init_phase) { |
| 858 | 845 | err = (image_error_t)image_finish_load(image); |
| 859 | 846 | if (err) |
| r7695 | r7696 | |
| 1408 | 1395 | image_software_entry |
| 1409 | 1396 | -------------------------------------------------*/ |
| 1410 | 1397 | |
| 1411 | | const software_entry *image_software_entry(running_device *image) |
| 1398 | const software_info *image_software_entry(running_device *image) |
| 1412 | 1399 | { |
| 1413 | 1400 | image_slot_data *slot = find_image_slot(image); |
| 1414 | 1401 | |
| 1415 | | return slot->software_entry_ptr; |
| 1402 | return slot->software_info_ptr; |
| 1416 | 1403 | } |
| 1417 | 1404 | |
| 1418 | 1405 | |
| r7695 | r7696 | |
| 1426 | 1413 | image_slot_data *slot = find_image_slot(image); |
| 1427 | 1414 | char full_tag[256]; |
| 1428 | 1415 | |
| 1429 | | if ( slot->software_list_ptr == NULL || slot->software_entry_ptr == NULL ) |
| 1416 | if ( slot->software_info_ptr == NULL || slot->software_part_ptr == NULL ) |
| 1430 | 1417 | return NULL; |
| 1431 | 1418 | |
| 1432 | | sprintf( full_tag, "%s:%s:%s", slot->software_list_ptr->name, slot->software_entry_ptr->name, tag ); |
| 1419 | sprintf( full_tag, "%s:%s", image->tag(), tag ); |
| 1433 | 1420 | return memory_region( image->machine, full_tag ); |
| 1434 | 1421 | } |
| 1435 | 1422 | |
| r7695 | r7696 | |
| 1442 | 1429 | { |
| 1443 | 1430 | char full_tag[256]; |
| 1444 | 1431 | |
| 1445 | | sprintf( full_tag, "%s:%s:%s", image->tag(), image_software_entry(image)->name, tag ); |
| 1432 | sprintf( full_tag, "%s:%s:%s", image->tag(), image_software_entry(image)->shortname, tag ); |
| 1446 | 1433 | return memory_region_length( image->machine, full_tag ); |
| 1447 | 1434 | } |
| 1448 | 1435 | |