Improve machine availability checking so that it absolutely never uses the legacy method if the machine has a device and the device has a CONFIG_BIOS setting.

This commit is contained in:
OBattler
2025-05-10 05:01:57 +02:00
parent e800f99f5a
commit 76d5fa79af
3 changed files with 52 additions and 33 deletions

View File

@@ -390,37 +390,18 @@ device_get_priv(const device_t *dev)
int int
device_available(const device_t *dev) device_available(const device_t *dev)
{ {
if (dev != NULL) { int ret = machine_device_available(dev);
const device_config_t *config = dev->config;
if ((config != NULL) && (config->type == CONFIG_BIOS)) {
int roms_present = 0;
const device_config_bios_t *bios = (const device_config_bios_t *) config->bios;
/* Go through the ROM's in the device configuration. */
while ((bios != NULL) &&
(bios->name != NULL) &&
(bios->internal_name != NULL) &&
(bios->files_no != 0)) {
int i = 0;
for (uint8_t bf = 0; bf < bios->files_no; bf++)
i += !!rom_present(bios->files[bf]);
if (i == bios->files_no)
roms_present++;
bios++;
}
return (roms_present ? -1 : 0);
}
if (ret == 0) {
/* No CONFIG_BIOS field present, use the classic available(). */ /* No CONFIG_BIOS field present, use the classic available(). */
if (dev->available != NULL) if (dev->available != NULL)
return (dev->available()); ret = (dev->available());
else else
return 1; ret = (dev != NULL);
} } else
ret = (ret == -1);
/* A NULL device is never available. */ return ret;
return 0;
} }
uint8_t uint8_t
@@ -964,6 +945,36 @@ machine_get_config_string(char *str)
return ret; return ret;
} }
int
machine_device_available(const device_t *dev)
{
if (dev != NULL) {
const device_config_t *config = dev->config;
if ((config != NULL) && (config->type == CONFIG_BIOS)) {
int roms_present = 0;
const device_config_bios_t *bios = (const device_config_bios_t *) config->bios;
/* Go through the ROM's in the device configuration. */
while ((bios != NULL) &&
(bios->name != NULL) &&
(bios->internal_name != NULL) &&
(bios->files_no != 0)) {
int i = 0;
for (uint8_t bf = 0; bf < bios->files_no; bf++)
i += !!rom_present(bios->files[bf]);
if (i == bios->files_no)
roms_present++;
bios++;
}
return (roms_present ? -1 : -2);
}
}
/* NULL device or no CONFIG_BIOS field, return 0. */
return 0;
}
const device_t * const device_t *
device_context_get_device(void) device_context_get_device(void)
{ {

View File

@@ -239,6 +239,8 @@ extern const char *device_get_internal_name(const device_t *dev);
extern int machine_get_config_int(char *str); extern int machine_get_config_int(char *str);
extern const char *machine_get_config_string(char *str); extern const char *machine_get_config_string(char *str);
extern int machine_device_available(const device_t *dev);
extern const device_t device_none; extern const device_t device_none;
extern const device_t device_internal; extern const device_t device_internal;

View File

@@ -139,18 +139,24 @@ machine_init(void)
int int
machine_available(int m) machine_available(int m)
{ {
int ret; int ret = 0;
const device_t *dev = machine_get_device(m); const device_t *dev = machine_get_device(m);
bios_only = 1; if (dev != NULL)
ret = machine_device_available(dev);
/*
Only via machine_init_ex() if the device is NULL or
it lacks a CONFIG_BIOS field (or the CONFIG_BIOS field
is not the first in list.
*/
if (ret == 0) {
bios_only = 1;
ret = device_available(dev);
/* Do not check via machine_init_ex() if the device is not NULL and
it has a CONFIG_BIOS field. */
if ((dev == NULL) || (ret != -1))
ret = machine_init_ex(m); ret = machine_init_ex(m);
bios_only = 0; bios_only = 0;
} else if (ret == -2)
ret = 0;
return !!ret; return !!ret;
} }