src/emu/softlist.c
| r12255 | r12256 | |
| 120 | 120 | from the global pool. So they should be global_free'ed |
| 121 | 121 | when they are not used anymore. |
| 122 | 122 | -------------------------------------------------*/ |
| 123 | | static void software_name_split(running_machine& machine, const char *swlist_swname, char **swlist_name, char **swname, char **swpart ) |
| 123 | |
| 124 | #define global_strdup(s) strcpy(global_alloc_array(char, strlen(s) + 1), s) |
| 125 | |
| 126 | static void software_name_split(const char *swlist_swname, char **swlist_name, char **swname, char **swpart ) |
| 124 | 127 | { |
| 125 | 128 | const char *split_1st_loc = strchr( swlist_swname, ':' ); |
| 126 | 129 | const char *split_2nd_loc = ( split_1st_loc ) ? strchr( split_1st_loc + 1, ':' ) : NULL; |
| r12255 | r12256 | |
| 134 | 137 | if ( split_2nd_loc ) |
| 135 | 138 | { |
| 136 | 139 | int size = split_1st_loc - swlist_swname; |
| 137 | | *swlist_name = auto_alloc_array_clear(machine,char,size+1); |
| 140 | *swlist_name = global_alloc_array_clear(char,size+1); |
| 138 | 141 | memcpy( *swlist_name, swlist_swname, size ); |
| 139 | 142 | |
| 140 | 143 | size = split_2nd_loc - ( split_1st_loc + 1 ); |
| 141 | | *swname = auto_alloc_array_clear(machine,char,size+1); |
| 144 | *swname = global_alloc_array_clear(char,size+1); |
| 142 | 145 | memcpy( *swname, split_1st_loc + 1, size ); |
| 143 | 146 | |
| 144 | 147 | size = strlen( swlist_swname ) - ( split_2nd_loc + 1 - swlist_swname ); |
| 145 | | *swpart = auto_alloc_array_clear(machine,char,size+1); |
| 148 | *swpart = global_alloc_array_clear(char,size+1); |
| 146 | 149 | memcpy( *swpart, split_2nd_loc + 1, size ); |
| 147 | 150 | } |
| 148 | 151 | else |
| 149 | 152 | { |
| 150 | 153 | int size = split_1st_loc - swlist_swname; |
| 151 | | *swname = auto_alloc_array_clear(machine,char,size+1); |
| 154 | *swname = global_alloc_array_clear(char,size+1); |
| 152 | 155 | memcpy( *swname, swlist_swname, size ); |
| 153 | 156 | |
| 154 | 157 | size = strlen( swlist_swname ) - ( split_1st_loc + 1 - swlist_swname ); |
| 155 | | *swpart = auto_alloc_array_clear(machine,char,size+1); |
| 158 | *swpart = global_alloc_array_clear(char,size+1); |
| 156 | 159 | memcpy( *swpart, split_1st_loc + 1, size ); |
| 157 | 160 | } |
| 158 | 161 | } |
| 159 | 162 | else |
| 160 | 163 | { |
| 161 | | *swname = auto_strdup(machine,swlist_swname); |
| 164 | *swname = global_strdup(swlist_swname); |
| 162 | 165 | } |
| 163 | 166 | } |
| 164 | 167 | |
| r12255 | r12256 | |
| 1372 | 1375 | } |
| 1373 | 1376 | } |
| 1374 | 1377 | } |
| 1375 | | /*------------------------------------------------- |
| 1376 | | load_software_part |
| 1377 | 1378 | |
| 1378 | | Load a software part for a device. The part to |
| 1379 | | load is determined by the "path", software lists |
| 1380 | | configured for a driver, and the interface |
| 1381 | | supported by the device. |
| 1382 | | |
| 1383 | | returns true if the software could be loaded, |
| 1384 | | false otherwise. If the software could be loaded |
| 1385 | | sw_info and sw_part are also set. |
| 1386 | | -------------------------------------------------*/ |
| 1387 | | |
| 1388 | | bool load_software_part(device_image_interface *image, const char *path, software_info **sw_info, software_part **sw_part, char **full_sw_name) |
| 1379 | static void find_software_item(emu_options &options, const device_image_interface *image, const char *path, software_list **software_list_ptr, software_info **software_info_ptr,software_part **software_part_ptr, const char **sw_list_name) |
| 1389 | 1380 | { |
| 1390 | 1381 | char *swlist_name, *swname, *swpart, *swname_bckp; |
| 1391 | | bool result = false; |
| 1392 | | software_list *software_list_ptr = NULL; |
| 1393 | | software_info *software_info_ptr = NULL; |
| 1394 | | software_part *software_part_ptr = NULL; |
| 1382 | *software_list_ptr = NULL; |
| 1383 | *software_info_ptr = NULL; |
| 1384 | *software_part_ptr = NULL; |
| 1395 | 1385 | |
| 1396 | | *sw_info = NULL; |
| 1397 | | *sw_part = NULL; |
| 1398 | | |
| 1399 | 1386 | /* Split full software name into software list name and short software name */ |
| 1400 | | software_name_split( image->device().machine(), path, &swlist_name, &swname, &swpart ); |
| 1387 | software_name_split(path, &swlist_name, &swname, &swpart ); |
| 1401 | 1388 | swname_bckp = swname; |
| 1402 | 1389 | |
| 1403 | 1390 | const char *interface = image->image_interface(); |
| 1404 | 1391 | |
| 1392 | machine_config config(*options.system(), options); |
| 1393 | |
| 1405 | 1394 | if ( swlist_name ) |
| 1406 | 1395 | { |
| 1407 | 1396 | /* Try to open the software list xml file explicitly named by the user */ |
| 1408 | | software_list_ptr = software_list_open( image->device().machine().options(), swlist_name, FALSE, NULL ); |
| 1397 | *software_list_ptr = software_list_open( options, swlist_name, FALSE, NULL ); |
| 1409 | 1398 | |
| 1410 | | if ( software_list_ptr ) |
| 1399 | if ( *software_list_ptr ) |
| 1411 | 1400 | { |
| 1412 | | software_info_ptr = software_list_find( software_list_ptr, swname, NULL ); |
| 1401 | *software_info_ptr = software_list_find( *software_list_ptr, swname, NULL ); |
| 1413 | 1402 | |
| 1414 | | if ( software_info_ptr ) |
| 1403 | if ( *software_info_ptr ) |
| 1415 | 1404 | { |
| 1416 | | software_part_ptr = software_find_part( software_info_ptr, swpart, interface ); |
| 1405 | *software_part_ptr = software_find_part( *software_info_ptr, swpart, interface ); |
| 1417 | 1406 | } |
| 1418 | 1407 | } |
| 1419 | 1408 | } |
| 1420 | 1409 | else |
| 1421 | 1410 | { |
| 1422 | 1411 | /* Loop through all the software lists named in the driver */ |
| 1423 | | for (device_t *swlists = image->device().machine().devicelist().first(SOFTWARE_LIST); swlists != NULL; swlists = swlists->typenext()) |
| 1412 | for (device_t *swlists = config.devicelist().first(SOFTWARE_LIST); swlists != NULL; swlists = swlists->typenext()) |
| 1424 | 1413 | { |
| 1425 | 1414 | if ( swlists ) |
| 1426 | 1415 | { |
| r12255 | r12256 | |
| 1428 | 1417 | software_list_config *swlist = (software_list_config *)downcast<const legacy_device_base *>(swlists)->inline_config(); |
| 1429 | 1418 | UINT32 i = DEVINFO_STR_SWLIST_0; |
| 1430 | 1419 | |
| 1431 | | while ( ! software_part_ptr && i <= DEVINFO_STR_SWLIST_MAX ) |
| 1420 | while ( ! *software_part_ptr && i <= DEVINFO_STR_SWLIST_MAX ) |
| 1432 | 1421 | { |
| 1433 | 1422 | swlist_name = swlist->list_name[i-DEVINFO_STR_SWLIST_0]; |
| 1434 | 1423 | |
| 1435 | 1424 | if ( swlist_name && *swlist_name && (swlist->list_type == SOFTWARE_LIST_ORIGINAL_SYSTEM)) |
| 1436 | 1425 | { |
| 1437 | | if ( software_list_ptr ) |
| 1426 | if ( *software_list_ptr ) |
| 1438 | 1427 | { |
| 1439 | | software_list_close( software_list_ptr ); |
| 1428 | software_list_close( *software_list_ptr ); |
| 1440 | 1429 | } |
| 1441 | 1430 | |
| 1442 | | software_list_ptr = software_list_open( image->device().machine().options(), swlist_name, FALSE, NULL ); |
| 1431 | *software_list_ptr = software_list_open( options, swlist_name, FALSE, NULL ); |
| 1443 | 1432 | |
| 1444 | 1433 | if ( software_list_ptr ) |
| 1445 | 1434 | { |
| 1446 | | software_info_ptr = software_list_find( software_list_ptr, swname, NULL ); |
| 1435 | *software_info_ptr = software_list_find( *software_list_ptr, swname, NULL ); |
| 1447 | 1436 | |
| 1448 | | if ( software_info_ptr ) |
| 1437 | if ( *software_info_ptr ) |
| 1449 | 1438 | { |
| 1450 | | software_part_ptr = software_find_part( software_info_ptr, swpart, interface ); |
| 1439 | *software_part_ptr = software_find_part( *software_info_ptr, swpart, interface ); |
| 1451 | 1440 | } |
| 1452 | 1441 | } |
| 1453 | 1442 | } |
| r12255 | r12256 | |
| 1457 | 1446 | } |
| 1458 | 1447 | |
| 1459 | 1448 | /* If not found try to load the software list using the driver name */ |
| 1460 | | if ( ! software_part_ptr ) |
| 1449 | if ( ! *software_part_ptr ) |
| 1461 | 1450 | { |
| 1462 | | swlist_name = (char *)image->device().machine().system().name; |
| 1451 | swlist_name = (char *)options.system()->name; |
| 1463 | 1452 | |
| 1464 | | if ( software_list_ptr ) |
| 1453 | if ( *software_list_ptr ) |
| 1465 | 1454 | { |
| 1466 | | software_list_close( software_list_ptr ); |
| 1455 | software_list_close( *software_list_ptr ); |
| 1467 | 1456 | } |
| 1468 | 1457 | |
| 1469 | | software_list_ptr = software_list_open( image->device().machine().options(), swlist_name, FALSE, NULL ); |
| 1458 | *software_list_ptr = software_list_open( options, swlist_name, FALSE, NULL ); |
| 1470 | 1459 | |
| 1471 | | if ( software_list_ptr ) |
| 1460 | if ( *software_list_ptr ) |
| 1472 | 1461 | { |
| 1473 | | software_info_ptr = software_list_find( software_list_ptr, swname, NULL ); |
| 1462 | *software_info_ptr = software_list_find( *software_list_ptr, swname, NULL ); |
| 1474 | 1463 | |
| 1475 | | if ( software_info_ptr ) |
| 1464 | if ( *software_info_ptr ) |
| 1476 | 1465 | { |
| 1477 | | software_part_ptr = software_find_part( software_info_ptr, swpart, interface ); |
| 1466 | *software_part_ptr = software_find_part( *software_info_ptr, swpart, interface ); |
| 1478 | 1467 | } |
| 1479 | 1468 | } |
| 1480 | 1469 | } |
| 1481 | 1470 | |
| 1482 | 1471 | /* If not found try to load the software list using the software name as software */ |
| 1483 | 1472 | /* list name and software part name as software name. */ |
| 1484 | | if ( ! software_part_ptr ) |
| 1473 | if ( ! *software_part_ptr ) |
| 1485 | 1474 | { |
| 1486 | 1475 | swlist_name = swname; |
| 1487 | 1476 | swname = swpart; |
| 1488 | 1477 | swpart = NULL; |
| 1489 | 1478 | |
| 1490 | | if ( software_list_ptr ) |
| 1479 | if ( *software_list_ptr ) |
| 1491 | 1480 | { |
| 1492 | | software_list_close( software_list_ptr ); |
| 1481 | software_list_close( *software_list_ptr ); |
| 1493 | 1482 | } |
| 1494 | 1483 | |
| 1495 | | software_list_ptr = software_list_open( image->device().machine().options(), swlist_name, FALSE, NULL ); |
| 1484 | *software_list_ptr = software_list_open( options, swlist_name, FALSE, NULL ); |
| 1496 | 1485 | |
| 1497 | 1486 | if ( software_list_ptr ) |
| 1498 | 1487 | { |
| 1499 | | software_info_ptr = software_list_find( software_list_ptr, swname, NULL ); |
| 1488 | *software_info_ptr = software_list_find( *software_list_ptr, swname, NULL ); |
| 1500 | 1489 | |
| 1501 | | if ( software_info_ptr ) |
| 1490 | if ( *software_info_ptr ) |
| 1502 | 1491 | { |
| 1503 | | software_part_ptr = software_find_part( software_info_ptr, swpart, interface ); |
| 1492 | *software_part_ptr = software_find_part( *software_info_ptr, swpart, interface ); |
| 1504 | 1493 | } |
| 1505 | 1494 | |
| 1506 | | if ( ! software_part_ptr ) |
| 1495 | if ( ! *software_part_ptr ) |
| 1507 | 1496 | { |
| 1508 | | software_list_close( software_list_ptr ); |
| 1509 | | software_list_ptr = NULL; |
| 1497 | software_list_close( *software_list_ptr ); |
| 1498 | *software_list_ptr = NULL; |
| 1510 | 1499 | } |
| 1511 | 1500 | } |
| 1512 | 1501 | } |
| 1513 | 1502 | } |
| 1503 | *sw_list_name = global_strdup(swlist_name); |
| 1504 | |
| 1505 | global_free( swlist_name ); |
| 1506 | global_free( swname ); |
| 1507 | global_free( swpart ); |
| 1508 | } |
| 1514 | 1509 | |
| 1510 | /*------------------------------------------------- |
| 1511 | load_software_part |
| 1512 | |
| 1513 | Load a software part for a device. The part to |
| 1514 | load is determined by the "path", software lists |
| 1515 | configured for a driver, and the interface |
| 1516 | supported by the device. |
| 1517 | |
| 1518 | returns true if the software could be loaded, |
| 1519 | false otherwise. If the software could be loaded |
| 1520 | sw_info and sw_part are also set. |
| 1521 | -------------------------------------------------*/ |
| 1522 | |
| 1523 | bool load_software_part(emu_options &options, device_image_interface *image, const char *path, software_info **sw_info, software_part **sw_part, char **full_sw_name) |
| 1524 | { |
| 1525 | software_list *software_list_ptr = NULL; |
| 1526 | software_info *software_info_ptr = NULL; |
| 1527 | software_part *software_part_ptr = NULL; |
| 1528 | const char *swlist_name = NULL; |
| 1529 | |
| 1530 | bool result = false; |
| 1531 | *sw_info = NULL; |
| 1532 | *sw_part = NULL; |
| 1533 | |
| 1534 | find_software_item(options, image, path, &software_list_ptr, &software_info_ptr, &software_part_ptr, &swlist_name); |
| 1535 | |
| 1515 | 1536 | // if no match has been found, we suggest similar shortnames |
| 1516 | 1537 | if (software_info_ptr == NULL) |
| 1517 | | { |
| 1518 | | software_display_matches(image->device().machine().devicelist(),image->device().machine().options(), image->image_interface(), swname_bckp); |
| 1538 | { |
| 1539 | machine_config config(*options.system(), options); |
| 1540 | software_display_matches(config.devicelist(), options, image->image_interface(), path); |
| 1519 | 1541 | } |
| 1520 | 1542 | |
| 1521 | 1543 | if ( software_part_ptr ) |
| r12255 | r12256 | |
| 1527 | 1549 | catch (emu_fatalerror &fatal) |
| 1528 | 1550 | { |
| 1529 | 1551 | software_list_close( software_list_ptr ); |
| 1552 | global_free(swlist_name); |
| 1530 | 1553 | throw fatal; |
| 1531 | 1554 | } |
| 1532 | 1555 | |
| r12255 | r12256 | |
| 1581 | 1604 | software_info_ptr = NULL; |
| 1582 | 1605 | software_list_ptr = NULL; |
| 1583 | 1606 | } |
| 1584 | | auto_free( image->device().machine(), swlist_name ); |
| 1585 | | auto_free( image->device().machine(), swname ); |
| 1586 | | auto_free( image->device().machine(), swpart ); |
| 1587 | | |
| 1607 | global_free(swlist_name); |
| 1588 | 1608 | return result; |
| 1589 | 1609 | } |
| 1590 | 1610 | |
| r12255 | r12256 | |
| 1610 | 1630 | |
| 1611 | 1631 | } |
| 1612 | 1632 | |
| 1633 | /*------------------------------------------------- |
| 1634 | software_get_default_slot |
| 1635 | -------------------------------------------------*/ |
| 1613 | 1636 | |
| 1637 | const char *software_get_default_slot(emu_options &options, const device_image_interface *image, const char *default_card, const char* default_card_slot) |
| 1638 | { |
| 1639 | const char* retVal = default_card; |
| 1640 | const char* path = options.value(image->instance_name()); |
| 1641 | software_list *software_list_ptr = NULL; |
| 1642 | software_info *software_info_ptr = NULL; |
| 1643 | software_part *software_part_ptr = NULL; |
| 1644 | const char *swlist_name = NULL; |
| 1645 | |
| 1646 | if (strlen(path)>0) { |
| 1647 | retVal = default_card_slot; |
| 1648 | find_software_item(options, image, path, &software_list_ptr, &software_info_ptr, &software_part_ptr, &swlist_name); |
| 1649 | if (software_part_ptr!=NULL) { |
| 1650 | const char *slot = software_part_get_feature(software_part_ptr, "slot"); |
| 1651 | if (slot!=NULL) { |
| 1652 | retVal = core_strdup(slot); |
| 1653 | } |
| 1654 | } |
| 1655 | software_list_close(software_list_ptr); |
| 1656 | global_free(swlist_name); |
| 1657 | } |
| 1658 | return retVal; |
| 1659 | } |
| 1660 | |
| 1614 | 1661 | /*************************************************************************** |
| 1615 | 1662 | DEVICE INTERFACE |
| 1616 | 1663 | ***************************************************************************/ |