src/mess/image.c
| r2304 | r2305 | |
| 139 | 139 | |
| 140 | 140 | |
| 141 | 141 | |
| 142 | /*------------------------------------------------- |
| 143 | device_get_info_str_offline - return an integer |
| 144 | state value from an allocated device; can be |
| 145 | called offline |
| 146 | -------------------------------------------------*/ |
| 147 | |
| 148 | INLINE const char *device_get_info_string_offline(const device_config *device, UINT32 state) |
| 149 | { |
| 150 | deviceinfo info; |
| 151 | |
| 152 | assert(device != NULL); |
| 153 | assert(device->type != NULL); |
| 154 | assert(state >= DEVINFO_STR_FIRST && state <= DEVINFO_STR_LAST); |
| 155 | |
| 156 | /* retrieve the value */ |
| 157 | info.s = 0; |
| 158 | (*device->type)(device, state, &info); |
| 159 | return info.s; |
| 160 | } |
| 161 | |
| 162 | |
| 163 | |
| 142 | 164 | /*************************************************************************** |
| 143 | 165 | CORE IMPLEMENTATION |
| 144 | 166 | ***************************************************************************/ |
| r2304 | r2305 | |
| 322 | 344 | ****************************************************************************/ |
| 323 | 345 | |
| 324 | 346 | /*------------------------------------------------- |
| 347 | get_device_name - retrieves the name of a |
| 348 | device |
| 349 | -------------------------------------------------*/ |
| 350 | |
| 351 | static void get_device_name(const device_config *device, char *buffer, size_t buffer_len) |
| 352 | { |
| 353 | const char *name = NULL; |
| 354 | device_get_name_func get_name; |
| 355 | |
| 356 | if (name == NULL) |
| 357 | { |
| 358 | /* first try a get_name function */ |
| 359 | get_name = (device_get_name_func) device_get_info_fct_offline(device, DEVINFO_FCT_GET_NAME); |
| 360 | if (get_name != NULL) |
| 361 | name = get_name(device, buffer, buffer_len); |
| 362 | } |
| 363 | |
| 364 | if (name == NULL) |
| 365 | { |
| 366 | /* next try DEVINFO_STR_NAME */ |
| 367 | name = device_get_info_string_offline(device, DEVINFO_STR_NAME); |
| 368 | } |
| 369 | |
| 370 | /* make sure that the name is put into the buffer */ |
| 371 | if (name != buffer) |
| 372 | snprintf(buffer, buffer_len, "%s", (name != NULL) ? name : ""); |
| 373 | } |
| 374 | |
| 375 | |
| 376 | |
| 377 | /*------------------------------------------------- |
| 325 | 378 | image_device_getinfo - returns info on a device; |
| 326 | 379 | can be called by front end code |
| 327 | 380 | -------------------------------------------------*/ |
| r2304 | r2305 | |
| 344 | 397 | info.creatable = device_get_info_int_offline(device, DEVINFO_INT_IMAGE_CREATABLE) ? 1 : 0; |
| 345 | 398 | info.must_be_loaded = device_get_info_int_offline(device, DEVINFO_INT_IMAGE_MUST_BE_LOADED) ? 1 : 0; |
| 346 | 399 | |
| 400 | /* retrieve name */ |
| 401 | get_device_name(device, info.name, ARRAY_LENGTH(info.name)); |
| 402 | |
| 347 | 403 | iodev = mess_device_from_core_device(device); |
| 348 | 404 | if (iodev != NULL) |
| 349 | 405 | { |
| 350 | | /* retrieve name */ |
| 351 | | s = (*iodev->name)(iodev, iodev->index_in_device, info.name, ARRAY_LENGTH(info.name)); |
| 352 | | if (s != info.name) |
| 353 | | snprintf(info.name, ARRAY_LENGTH(info.name), "%s", s); |
| 354 | | |
| 355 | 406 | /* retrieve file extensions */ |
| 356 | 407 | for(i = 0; iodev->file_extensions[i] != '\0'; i += strlen(&iodev->file_extensions[i]) + 1) |
| 357 | 408 | ; |
| r2304 | r2305 | |
| 1265 | 1316 | |
| 1266 | 1317 | const char *image_typename_id(const device_config *image) |
| 1267 | 1318 | { |
| 1268 | | const struct IODevice *dev; |
| 1269 | | int id; |
| 1270 | | static char buf[64]; |
| 1271 | | |
| 1272 | | dev = mess_device_from_core_device(image); |
| 1273 | | id = image_index_in_device(image); |
| 1274 | | return dev->name(dev, id, buf, sizeof(buf) / sizeof(buf[0])); |
| 1319 | static char buffer[64]; |
| 1320 | get_device_name(image, buffer, ARRAY_LENGTH(buffer)); |
| 1321 | return buffer; |
| 1275 | 1322 | } |
| 1276 | 1323 | |
| 1277 | 1324 | |
src/mess/image.h
| r2304 | r2305 | |
| 27 | 27 | typedef void (*device_image_unload_func)(const device_config *image); |
| 28 | 28 | typedef void (*device_display_func)(const device_config *image); |
| 29 | 29 | typedef void (*device_image_partialhash_func)(char *, const unsigned char *, unsigned long, unsigned int); |
| 30 | typedef const char *(*device_get_name_func)(const device_config *device, char *buffer, size_t buffer_length); |
| 30 | 31 | |
| 31 | 32 | typedef enum |
| 32 | 33 | { |
| r2304 | r2305 | |
| 100 | 101 | DEVINFO_FCT_IMAGE_UNLOAD, /* R/O: device_image_unload_func */ |
| 101 | 102 | DEVINFO_FCT_DISPLAY, /* R/O: device_display_func */ |
| 102 | 103 | DEVINFO_FCT_IMAGE_PARTIAL_HASH, /* R/O: device_image_partialhash_func */ |
| 104 | DEVINFO_FCT_GET_NAME, /* R/O: device_get_name_func */ |
| 103 | 105 | DEVINFO_FCT_IMAGE_LAST = DEVINFO_FCT_FIRST + 0x0fff, |
| 104 | 106 | |
| 105 | 107 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| r2304 | r2305 | |
| 270 | 272 | #define DEVICE_IMAGE_UNLOAD_NAME(name) device_unload_##name |
| 271 | 273 | #define DEVICE_IMAGE_UNLOAD(name) void DEVICE_IMAGE_UNLOAD_NAME(name)(const device_config *image) |
| 272 | 274 | |
| 275 | #define DEVICE_GET_NAME_NAME(name) device_get_name_##name |
| 276 | #define DEVICE_GET_NAME(name) const char *DEVICE_GET_NAME_NAME(name)(const device_config *device, char *buffer, size_t buffer_length) |
| 277 | |
| 273 | 278 | #endif /* __IMAGE_H__ */ |
src/mess/device.c
| r2304 | r2305 | |
| 187 | 187 | |
| 188 | 188 | |
| 189 | 189 | |
| 190 | | static const char *default_device_name(const struct IODevice *dev, int id, |
| 191 | | char *buf, size_t bufsize) |
| 192 | | { |
| 193 | | const char *name; |
| 194 | | |
| 195 | | /* use the cool new device string technique */ |
| 196 | | name = mess_device_get_info_string(&dev->devclass, MESS_DEVINFO_STR_DESCRIPTION+id); |
| 197 | | if (name) |
| 198 | | { |
| 199 | | snprintf(buf, bufsize, "%s", name); |
| 200 | | return buf; |
| 201 | | } |
| 202 | | |
| 203 | | name = device_uiname(dev->type); |
| 204 | | if (dev->multiple) |
| 205 | | { |
| 206 | | /* for the average user counting starts at #1 ;-) */ |
| 207 | | snprintf(buf, bufsize, "%s #%d", name, id + 1); |
| 208 | | name = buf; |
| 209 | | } |
| 210 | | return name; |
| 211 | | } |
| 212 | | |
| 213 | | |
| 214 | | |
| 215 | 190 | /*------------------------------------------------- |
| 216 | 191 | DEVICE_START(mess_device) - device start |
| 217 | 192 | callback |
| r2304 | r2305 | |
| 253 | 228 | |
| 254 | 229 | |
| 255 | 230 | /*------------------------------------------------- |
| 231 | DEVICE_GET_NAME(mess_device) - device get name |
| 232 | callback |
| 233 | -------------------------------------------------*/ |
| 234 | |
| 235 | static DEVICE_GET_NAME(mess_device) |
| 236 | { |
| 237 | const char *name; |
| 238 | const struct IODevice *iodev = mess_device_from_core_device(device); |
| 239 | int id = iodev->index_in_device; |
| 240 | |
| 241 | /* use the cool new device string technique */ |
| 242 | name = mess_device_get_info_string(&iodev->devclass, MESS_DEVINFO_STR_DESCRIPTION + id); |
| 243 | if (name) |
| 244 | { |
| 245 | snprintf(buffer, buffer_length, "%s", name); |
| 246 | return buffer; |
| 247 | } |
| 248 | |
| 249 | name = device_uiname(iodev->type); |
| 250 | if (iodev->multiple) |
| 251 | { |
| 252 | /* for the average user counting starts at #1 ;-) */ |
| 253 | snprintf(buffer, buffer_length, "%s #%d", name, id + 1); |
| 254 | name = buffer; |
| 255 | } |
| 256 | return name; |
| 257 | } |
| 258 | |
| 259 | |
| 260 | |
| 261 | /*------------------------------------------------- |
| 256 | 262 | DEVICE_GET_INFO(mess_device) - device get info |
| 257 | 263 | callback |
| 258 | 264 | -------------------------------------------------*/ |
| r2304 | r2305 | |
| 282 | 288 | case DEVINFO_FCT_IMAGE_UNLOAD: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_UNLOAD); break; |
| 283 | 289 | case DEVINFO_FCT_DISPLAY: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_DISPLAY); break; |
| 284 | 290 | case DEVINFO_FCT_IMAGE_PARTIAL_HASH: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_PARTIAL_HASH); break; |
| 291 | case DEVINFO_FCT_GET_NAME: info->f = (genf *) DEVICE_GET_NAME_NAME(mess_device); break; |
| 285 | 292 | |
| 286 | 293 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 287 | 294 | case DEVINFO_STR_NAME: info->s = "Legacy MESS Device"; break; |
| r2304 | r2305 | |
| 426 | 433 | mess_device->io_device.imgverify = (device_image_verify_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_VERIFY); |
| 427 | 434 | mess_device->io_device.partialhash = (device_image_partialhash_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_PARTIAL_HASH); |
| 428 | 435 | |
| 429 | | mess_device->io_device.name = default_device_name; |
| 430 | | |
| 431 | 436 | mess_device->io_device.createimage_optguide = (const struct OptionGuide *) mess_device_get_info_ptr(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE_OPTGUIDE); |
| 432 | 437 | |
| 433 | 438 | createimage_optcount = (int) mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_CREATE_OPTCOUNT); |