Add fallback for unknown CONFIG_BIOS names

This commit is contained in:
RichardG867
2025-10-25 16:56:15 -03:00
parent 3fdf56513f
commit d1f101f9ee
3 changed files with 38 additions and 112 deletions

View File

@@ -396,143 +396,69 @@ device_available(const device_t *dev)
return ret;
}
uint8_t
device_get_bios_type(const device_t *dev, const char *internal_name)
static const device_config_bios_t *
device_get_bios(const device_t *dev, const char *internal_name)
{
if (dev != NULL) {
const device_config_t *config = dev->config;
if (config != NULL) {
while (config->type != CONFIG_END) {
if (config->type == CONFIG_BIOS) {
const device_config_bios_t *bios = (const device_config_bios_t *) config->bios;
while ((bios != NULL) &&
(bios->name != NULL) &&
(bios->internal_name != NULL) &&
(bios->files_no != 0)) {
if (!strcmp(internal_name, bios->internal_name))
return bios->bios_type;
bios++;
}
while (config && (config->type != CONFIG_END)) {
if (config->type == CONFIG_BIOS) {
const device_config_bios_t *bios = (const device_config_bios_t *) config->bios;
/* Go through the ROMs in the device configuration. */
while ((bios != NULL) &&
(bios->name != NULL) &&
(bios->internal_name != NULL) &&
(bios->files_no != 0)) {
if (!strcmp(internal_name, bios->internal_name))
return bios;
bios++;
}
config++;
/* Unknown value, fall back to the default ROMs. */
if (strcmp(internal_name, config->default_string))
return device_get_bios(dev, config->default_string);
}
config++;
}
}
return 0;
return NULL;
}
uint8_t
device_get_bios_type(const device_t *dev, const char *internal_name)
{
const device_config_bios_t *bios = device_get_bios(dev, internal_name);
return bios ? bios->bios_type : 0;
}
uint8_t
device_get_bios_num_files(const device_t *dev, const char *internal_name)
{
if (dev != NULL) {
const device_config_t *config = dev->config;
if (config != NULL) {
while (config->type != CONFIG_END) {
if (config->type == CONFIG_BIOS) {
const device_config_bios_t *bios = (const device_config_bios_t *) config->bios;
while ((bios != NULL) &&
(bios->name != NULL) &&
(bios->internal_name != NULL) &&
(bios->files_no != 0)) {
if (!strcmp(internal_name, bios->internal_name))
return bios->files_no;
bios++;
}
}
config++;
}
}
}
return 0;
const device_config_bios_t *bios = device_get_bios(dev, internal_name);
return bios ? bios->files_no : 0;
}
uint32_t
device_get_bios_local(const device_t *dev, const char *internal_name)
{
if (dev != NULL) {
const device_config_t *config = dev->config;
if (config != NULL) {
while (config->type != CONFIG_END) {
if (config->type == CONFIG_BIOS) {
const device_config_bios_t *bios = (const device_config_bios_t *) config->bios;
while ((bios != NULL) &&
(bios->name != NULL) &&
(bios->internal_name != NULL) &&
(bios->files_no != 0)) {
if (!strcmp(internal_name, bios->internal_name))
return bios->local;
bios++;
}
}
config++;
}
}
}
return 0;
const device_config_bios_t *bios = device_get_bios(dev, internal_name);
return bios ? bios->local : 0;
}
uint32_t
device_get_bios_file_size(const device_t *dev, const char *internal_name)
{
if (dev != NULL) {
const device_config_t *config = dev->config;
if (config != NULL) {
while (config->type != CONFIG_END) {
if (config->type == CONFIG_BIOS) {
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)) {
if (!strcmp(internal_name, bios->internal_name))
return bios->size;
bios++;
}
}
config++;
}
}
}
return 0;
const device_config_bios_t *bios = device_get_bios(dev, internal_name);
return bios ? bios->size : 0;
}
const char *
device_get_bios_file(const device_t *dev, const char *internal_name, int file_no)
device_get_bios_file(const device_t *dev, const char *internal_name, unsigned int file_no)
{
if (dev != NULL) {
const device_config_t *config = dev->config;
if (config != NULL) {
while (config->type != CONFIG_END) {
if (config->type == CONFIG_BIOS) {
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)) {
if (!strcmp(internal_name, bios->internal_name)) {
if (file_no < bios->files_no)
return bios->files[file_no];
else
return NULL;
}
bios++;
}
}
config++;
}
}
}
/* A NULL device is never available. */
return (NULL);
const device_config_bios_t *bios = device_get_bios(dev, internal_name);
return (bios && (file_no < bios->files_no)) ? bios->files[file_no] : NULL;
}
int

View File

@@ -213,7 +213,7 @@ extern uint8_t device_get_bios_type(const device_t *dev, const char *interna
extern uint8_t device_get_bios_num_files(const device_t *dev, const char *internal_name);
extern uint32_t device_get_bios_local(const device_t *dev, const char *internal_name);
extern uint32_t device_get_bios_file_size(const device_t *dev, const char *internal_name);
extern const char *device_get_bios_file(const device_t *dev, const char *internal_name, int file_no);
extern const char *device_get_bios_file(const device_t *dev, const char *internal_name, unsigned int file_no);
extern int device_is_valid(const device_t *, int mch);

View File

@@ -20319,7 +20319,7 @@ machine_get_nvr_name_ex(int m)
if (dev != NULL) {
device_context(dev);
const char *bios = device_get_config_string("bios");
const char *bios = device_get_config_bios("bios");
if ((bios != NULL) && (strcmp(bios, "") != 0))
ret = bios;
device_context_restore();