void device_image_interface::update_names(const device_type device_type, const char *inst, const char *brief) { image_interface_iterator iter(device().mconfig().root_device()); int count = 0; int index = -1; for (const device_image_interface *image = iter.first(); image != NULL; image = iter.next()) { if (this == image) index = count; if ((image->image_type() == image_type() && device_type==NULL) || (device_type==image->device().type())) count++; } const char *inst_name = (device_type!=NULL) ? inst : device_typename(image_type()); const char *brief_name = (device_type!=NULL) ? brief : device_brieftypename(image_type()); if (count > 1) { m_instance_name.printf("%s%d", inst_name , index + 1); m_brief_instance_name.printf("%s%d", brief_name, index + 1); } else { m_instance_name = inst_name; m_brief_instance_name = brief_name; } }
static int probe_disks(int devidx, int load_type, int load_unit, int load_slice, int load_partition) { int open_result, unit; struct open_file f; currdev.d_disk.slice = load_slice; currdev.d_disk.partition = load_partition; f.f_devdata = &currdev; open_result = -1; if (load_type == -1) { printf(" Probing all disk devices...\n"); /* Try each disk in succession until one works. */ for (currdev.d_unit = 0; currdev.d_unit < UB_MAX_DEV; currdev.d_unit++) { print_disk_probe_info(); open_result = devsw[devidx]->dv_open(&f, &currdev); if (open_result == 0) { printf(" good.\n"); return (0); } printf("\n"); } return (-1); } if (load_unit == -1) { printf(" Probing all %s devices...\n", device_typename(load_type)); /* Try each disk of given type in succession until one works. */ for (unit = 0; unit < UB_MAX_DEV; unit++) { currdev.d_unit = uboot_diskgetunit(load_type, unit); if (currdev.d_unit == -1) break; print_disk_probe_info(); open_result = devsw[devidx]->dv_open(&f, &currdev); if (open_result == 0) { printf(" good.\n"); return (0); } printf("\n"); } return (-1); } if ((currdev.d_unit = uboot_diskgetunit(load_type, load_unit)) != -1) { print_disk_probe_info(); open_result = devsw[devidx]->dv_open(&f,&currdev); if (open_result == 0) { printf(" good.\n"); return (0); } printf("\n"); } printf(" Requested disk type/unit not found\n"); return (-1); }
void print_game_device(FILE* out, const game_driver* game) { const struct IODevice* dev; const char *name; const char *shortname; int id; begin_resource_tracking(); dev = devices_allocate(game); if (dev) { while(dev->type < IO_COUNT) { /* print out device type */ fprintf(out, "\t\t<device type=\"%s\"", normalize_string(device_typename(dev->type))); /* does this device have a tag? */ if (dev->tag) fprintf(out, " tag=\"%s\"", normalize_string(dev->tag)); /* is this device mandatory? */ if (dev->must_be_loaded) fprintf(out, " mandatory=\"1\""); /* close the XML tag */ fprintf(out, ">\n"); for (id = 0; id < dev->count; id++) { name = device_instancename(&dev->devclass, id); shortname = device_briefinstancename(&dev->devclass, id); fprintf(out, "\t\t\t<instance"); fprintf(out, " name=\"%s\"", normalize_string(name)); fprintf(out, " briefname=\"%s\"", normalize_string(shortname)); fprintf(out, "/>\n"); } if (dev->file_extensions) { const char* ext = dev->file_extensions; while (*ext) { fprintf(out, "\t\t\t<extension"); fprintf(out, " name=\"%s\"", normalize_string(ext)); fprintf(out, "/>\n"); ext += strlen(ext) + 1; } } fprintf(out, "\t\t</device>\n"); dev++; } } end_resource_tracking(); }
void device_image_interface::update_names() { image_interface_iterator iter(device().mconfig().root_device()); int count = 0; int index = -1; for (const device_image_interface *image = iter.first(); image != NULL; image = iter.next()) { if (this == image) index = count; if (image->image_type() == image_type()) count++; } if (count > 1) { m_instance_name.printf("%s%d", device_typename(image_type()), index + 1); m_brief_instance_name.printf("%s%d", device_brieftypename(image_type()), index + 1); } else { m_instance_name = device_typename(image_type()); m_brief_instance_name = device_brieftypename(image_type()); } }
void device_image_interface::update_names() { const device_image_interface *image = NULL; int count = 0; int index = -1; for (bool gotone = device().mconfig().devicelist().first(image); gotone; gotone = image->next(image)) { if (this == image) index = count; if (image->image_type() == image_type()) count++; } if (count > 1) { m_instance_name.printf("%s%d", device_typename(image_type()), index + 1); m_brief_instance_name.printf("%s%d", device_brieftypename(image_type()), index + 1); } else { m_instance_name = device_typename(image_type()); m_brief_instance_name = device_brieftypename(image_type()); } }
void device_image_interface::update_names(const device_type device_type, const char *inst, const char *brief) { int count = 0; int index = -1; for (const device_image_interface &image : image_interface_iterator(device().mconfig().root_device())) { if (this == &image) index = count; if ((image.image_type() == image_type() && device_type == nullptr) || (device_type == image.device().type())) count++; } const char *inst_name = (device_type!=nullptr) ? inst : device_typename(image_type()); const char *brief_name = (device_type!=nullptr) ? brief : device_brieftypename(image_type()); if (count > 1) { m_instance_name = string_format("%s%d", inst_name, index + 1); m_brief_instance_name = string_format("%s%d", brief_name, index + 1); } else { m_instance_name = inst_name; m_brief_instance_name = brief_name; } }
void legacy_image_device_config_base::device_config_complete() { const device_config_image_interface *image = NULL; int count = 0; int index = -1; image_device_format **formatptr; image_device_format *format; formatptr = &m_formatlist; int cnt = 0; m_type = static_cast<iodevice_t>(get_legacy_config_int(DEVINFO_INT_IMAGE_TYPE)); m_readable = get_legacy_config_int(DEVINFO_INT_IMAGE_READABLE)!=0; m_writeable = get_legacy_config_int(DEVINFO_INT_IMAGE_WRITEABLE)!=0; m_creatable = get_legacy_config_int(DEVINFO_INT_IMAGE_CREATABLE)!=0; m_must_be_loaded = get_legacy_config_int(DEVINFO_INT_IMAGE_MUST_BE_LOADED)!=0; m_reset_on_load = get_legacy_config_int(DEVINFO_INT_IMAGE_RESET_ON_LOAD)!=0; m_has_partial_hash = get_legacy_config_int(DEVINFO_FCT_IMAGE_PARTIAL_HASH)!=0; m_interface_name = get_legacy_config_string(DEVINFO_STR_IMAGE_INTERFACE); m_file_extensions = get_legacy_config_string(DEVINFO_STR_IMAGE_FILE_EXTENSIONS); m_create_option_guide = reinterpret_cast<const option_guide *>(get_legacy_config_ptr(DEVINFO_PTR_IMAGE_CREATE_OPTGUIDE)); int format_count = get_legacy_config_int(DEVINFO_INT_IMAGE_CREATE_OPTCOUNT); for (int i = 0; i < format_count; i++) { // only add if creatable if (get_legacy_config_string(DEVINFO_PTR_IMAGE_CREATE_OPTSPEC + i)) { // allocate a new format format = global_alloc_clear(image_device_format); // populate it format->m_index = cnt; format->m_name = get_legacy_config_string(DEVINFO_STR_IMAGE_CREATE_OPTNAME + i); format->m_description = get_legacy_config_string(DEVINFO_STR_IMAGE_CREATE_OPTDESC + i); format->m_extensions = get_legacy_config_string(DEVINFO_STR_IMAGE_CREATE_OPTEXTS + i); format->m_optspec = get_legacy_config_string(DEVINFO_PTR_IMAGE_CREATE_OPTSPEC + i); // and append it to the list *formatptr = format; formatptr = &format->m_next; cnt++; } } for (bool gotone = device_config::m_machine_config.m_devicelist.first(image); gotone; gotone = image->next(image)) { if (this == image) index = count; if (image->image_type_direct() == m_type) count++; } if (count > 1) { m_instance_name.printf("%s%d", device_typename(m_type), index + 1); m_brief_instance_name.printf("%s%d", device_brieftypename(m_type), index + 1); } else { m_instance_name = device_typename(m_type); m_brief_instance_name = device_brieftypename(m_type); } // Override in case of hardcoded values if (strlen(get_legacy_config_string(DEVINFO_STR_IMAGE_INSTANCE_NAME))>0) { m_instance_name = get_legacy_config_string(DEVINFO_STR_IMAGE_INSTANCE_NAME); } if (strlen(get_legacy_config_string(DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME))>0) { m_brief_instance_name = get_legacy_config_string(DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME); } }
static void command_image_loadcreate(void) { mess_image *image; int device_type; int device_slot; const char *device_tag; int i, format_index = 0; const char *filename; const char *format; char buf[128]; const struct IODevice *dev; const char *file_extensions; device_slot = current_command->u.image_args.device_slot; device_type = current_command->u.image_args.device_type; device_tag = current_command->u.image_args.device_tag; /* look up the image slot */ if (device_tag) image = image_from_devtag_and_index(device_tag, device_slot); else image = image_from_devtype_and_index(device_type, device_slot); if (!image) { state = STATE_ABORTED; report_message(MSG_FAILURE, "Image slot '%s %i' does not exist", device_typename(device_type), device_slot); return; } dev = image_device(image); file_extensions = dev->file_extensions; /* is an image format specified? */ format = current_command->u.image_args.format; if (format) { if (current_command->command_type != MESSTEST_COMMAND_IMAGE_CREATE) { state = STATE_ABORTED; report_message(MSG_FAILURE, "Cannot specify format unless creating"); return; } if (!dev->createimage_options) { state = STATE_ABORTED; report_message(MSG_FAILURE, "Cannot specify format for device"); return; } for (i = 0; dev->createimage_options[i].name; i++) { if (!strcmp(format, dev->createimage_options[i].name)) break; } if (!dev->createimage_options[i].name) { state = STATE_ABORTED; report_message(MSG_FAILURE, "Unknown device '%s'", format); return; } format_index = i; file_extensions = dev->createimage_options[i].extensions; } /* figure out the filename */ filename = current_command->u.image_args.filename; if (!filename) { snprintf(buf, sizeof(buf) / sizeof(buf[0]), "%s.%s", current_testcase.name, file_extensions); make_filename_temporary(buf, sizeof(buf) / sizeof(buf[0])); filename = buf; } /* actually create or load the image */ switch(current_command->command_type) { case MESSTEST_COMMAND_IMAGE_CREATE: if (image_create(image, filename, format_index, NULL)) { state = STATE_ABORTED; report_message(MSG_FAILURE, "Failed to create image '%s': %s", filename, image_error(image)); return; } break; case MESSTEST_COMMAND_IMAGE_LOAD: if (image_load(image, filename)) { state = STATE_ABORTED; report_message(MSG_FAILURE, "Failed to load image '%s': %s", filename, image_error(image)); return; } break; default: break; } }
static void command_image_loadcreate(void) { mess_image *image; int device_type; int device_slot; const char *device_tag; int i, format_index = 0; const char *filename; const char *format; char buf[128]; const struct IODevice *dev; const char *file_extensions; char *filepath; int success; const game_driver *gamedrv; device_slot = current_command->u.image_args.device_slot; device_type = current_command->u.image_args.device_type; device_tag = current_command->u.image_args.device_tag; /* look up the image slot */ if (device_tag) image = image_from_devtag_and_index(device_tag, device_slot); else image = image_from_devtype_and_index(device_type, device_slot); if (!image) { state = STATE_ABORTED; report_message(MSG_FAILURE, "Image slot '%s %i' does not exist", device_typename(device_type), device_slot); return; } dev = image_device(image); file_extensions = dev->file_extensions; /* is an image format specified? */ format = current_command->u.image_args.format; if (format) { if (current_command->command_type != MESSTEST_COMMAND_IMAGE_CREATE) { state = STATE_ABORTED; report_message(MSG_FAILURE, "Cannot specify format unless creating"); return; } if (!dev->createimage_options) { state = STATE_ABORTED; report_message(MSG_FAILURE, "Cannot specify format for device"); return; } for (i = 0; dev->createimage_options[i].name; i++) { if (!strcmp(format, dev->createimage_options[i].name)) break; } if (!dev->createimage_options[i].name) { state = STATE_ABORTED; report_message(MSG_FAILURE, "Unknown device '%s'", format); return; } format_index = i; file_extensions = dev->createimage_options[i].extensions; } /* figure out the filename */ filename = current_command->u.image_args.filename; if (!filename) { snprintf(buf, sizeof(buf) / sizeof(buf[0]), "%s.%s", current_testcase.name, file_extensions); osd_get_temp_filename(buf, ARRAY_LENGTH(buf), buf); filename = buf; } success = FALSE; for (gamedrv = Machine->gamedrv; !success && gamedrv; gamedrv = mess_next_compatible_driver(gamedrv)) { /* assemble the full path */ filepath = assemble_software_path(gamedrv, filename); /* actually create or load the image */ switch(current_command->command_type) { case MESSTEST_COMMAND_IMAGE_CREATE: success = (image_create(image, filepath, format_index, NULL) == INIT_PASS); break; case MESSTEST_COMMAND_IMAGE_LOAD: success = (image_load(image, filepath) == INIT_PASS); break; default: fatalerror("Unexpected error"); break; } free(filepath); } if (!success) { state = STATE_ABORTED; report_message(MSG_FAILURE, "Failed to load/create image '%s': %s", filename, image_error(image)); return; } }
static int validate_device(const device_class *devclass) { int error = 0; int is_invalid, i; const char *s; INT64 devcount, optcount; char buf[256]; char *s1; char *s2; iodevice_t devtype; int (*validity_check)(const device_class *devclass); /* critical information */ devtype = (iodevice_t) (int) device_get_info_int(devclass, DEVINFO_INT_TYPE); devcount = device_get_info_int(devclass, DEVINFO_INT_COUNT); /* sanity check device type */ if (devtype >= IO_COUNT) { printf("%s: invalid device type %i\n", devclass->gamedrv->name, (int) devtype); error = 1; } /* sanity check device count */ if ((devcount <= 0) || (devcount > MAX_DEV_INSTANCES)) { printf("%s: device type '%s' has an invalid device count %i\n", devclass->gamedrv->name, device_typename(devtype), (int) devcount); error = 1; } /* File Extensions Checks * * Checks the following * * 1. Tests the integrity of the string list * 2. Checks for duplicate extensions * 3. Makes sure that all extensions are either lower case chars or numbers */ s = device_get_info_string(devclass, DEVINFO_STR_FILE_EXTENSIONS); if (!s) { printf("%s: device type '%s' has null file extensions\n", devclass->gamedrv->name, device_typename(devtype)); error = 1; } else { memset(buf, 0, sizeof(buf)); strcpy(buf, s); /* convert to be null delimited */ s1 = buf; while(*s1) { if (*s1 == ',') *s1 = '\0'; s1++; } s1 = buf; while(*s1) { /* check for invalid chars */ is_invalid = 0; for (s2 = s1; *s2; s2++) { if (!isdigit(*s2) && !islower(*s2)) is_invalid = 1; } if (is_invalid) { printf("%s: device type '%s' has an invalid extension '%s'\n", devclass->gamedrv->name, device_typename(devtype), s1); error = 1; } s2++; /* check for dupes */ is_invalid = 0; while(*s2) { if (!strcmp(s1, s2)) is_invalid = 1; s2 += strlen(s2) + 1; } if (is_invalid) { printf("%s: device type '%s' has duplicate extensions '%s'\n", devclass->gamedrv->name, device_typename(devtype), s1); error = 1; } s1 += strlen(s1) + 1; } } /* enforce certain rules for certain device types */ switch(devtype) { case IO_QUICKLOAD: case IO_SNAPSHOT: if (devcount != 1) { printf("%s: there can only be one instance of devices of type '%s'\n", devclass->gamedrv->name, device_typename(devtype)); error = 1; } /* fallthrough */ case IO_CARTSLOT: if (!device_get_info_int(devclass, DEVINFO_INT_READABLE) || device_get_info_int(devclass, DEVINFO_INT_WRITEABLE) || device_get_info_int(devclass, DEVINFO_INT_CREATABLE)) { printf("%s: devices of type '%s' has invalid open modes\n", devclass->gamedrv->name, device_typename(devtype)); error = 1; } break; default: break; } /* check creation options */ optcount = device_get_info_int(devclass, DEVINFO_INT_CREATE_OPTCOUNT); if ((optcount < 0) || (optcount >= DEVINFO_CREATE_OPTMAX)) { printf("%s: device type '%s' has an invalid creation optcount\n", devclass->gamedrv->name, device_typename(devtype)); error = 1; } else { for (i = 0; i < (int) optcount; i++) { if (!device_get_info_string(devclass, DEVINFO_STR_CREATE_OPTNAME + i)) { printf("%s: device type '%s' create option #%d: name not present\n", devclass->gamedrv->name, device_typename(devtype), i); error = 1; } if (!device_get_info_string(devclass, DEVINFO_STR_CREATE_OPTDESC + i)) { printf("%s: device type '%s' create option #%d: description not present\n", devclass->gamedrv->name, device_typename(devtype), i); error = 1; } if (!device_get_info_string(devclass, DEVINFO_STR_CREATE_OPTEXTS + i)) { printf("%s: device type '%s' create option #%d: extensions not present\n", devclass->gamedrv->name, device_typename(devtype), i); error = 1; } } } /* is there a custom validity check? */ validity_check = (int (*)(const device_class *)) device_get_info_fct(devclass, DEVINFO_PTR_VALIDITY_CHECK); if (validity_check) { if (validity_check(devclass)) error = 1; } return error; }