src/mess/devices/harddriv.c
| r7126 | r7127 | |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | |
| 387 | | #ifdef UNUSED_FUNCTION |
| 388 | | /*------------------------------------------------- |
| 389 | | ide_hd_validity_check - check this device's validity |
| 390 | | -------------------------------------------------*/ |
| 391 | | |
| 392 | | static int ide_hd_validity_check(const mess_device_class *devclass) |
| 393 | | { |
| 394 | | int error = 0; |
| 395 | | int which_address; |
| 396 | | INT64 count; |
| 397 | | struct ide_interface *intf; |
| 398 | | |
| 399 | | which_address = (int) mess_device_get_info_int(devclass, DEVINFO_INT_IDEDRIVE_ADDRESS); |
| 400 | | intf = (struct ide_interface *) mess_device_get_info_ptr(devclass, DEVINFO_PTR_IDEDRIVE_INTERFACE); |
| 401 | | count = mess_device_get_info_int(devclass, MESS_DEVINFO_INT_COUNT); |
| 402 | | |
| 403 | | if (which_address != 0) |
| 404 | | { |
| 405 | | mame_printf_error("%s: IDE device has non-zero address\n", devclass->gamedrv->name); |
| 406 | | error = 1; |
| 407 | | } |
| 408 | | |
| 409 | | if (!intf) |
| 410 | | { |
| 411 | | mame_printf_error("%s: IDE device does not specify an interface\n", devclass->gamedrv->name); |
| 412 | | error = 1; |
| 413 | | } |
| 414 | | |
| 415 | | return error; |
| 416 | | } |
| 417 | | #endif |
| 418 | | |
| 419 | | |
| 420 | 387 | DEVICE_GET_INFO(mess_ide) |
| 421 | 388 | { |
| 422 | 389 | switch( state ) |
| r7126 | r7127 | |
| 425 | 392 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(mess_ide); break; |
| 426 | 393 | case DEVINFO_FCT_IMAGE_LOAD: info->f = (genf *) DEVICE_IMAGE_LOAD_NAME(mess_ide); break; |
| 427 | 394 | case DEVINFO_FCT_IMAGE_UNLOAD: info->f = (genf *) DEVICE_IMAGE_UNLOAD_NAME(mess_ide); break; |
| 428 | | // case DEVINFO_FCT_IMAGE_VERIFY: info->f = (genf *) ide_hd_validity_check; break; |
| 429 | 395 | |
| 430 | 396 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 431 | 397 | case DEVINFO_STR_NAME: strcpy(info->s, "IDE harddisk"); break; |
src/mess/devices/imagedev.c
| r0 | r7127 | |
| 1 | /***************************************************************************** |
| 2 | * |
| 3 | * Image device |
| 4 | * |
| 5 | ****************************************************************************/ |
| 6 | |
| 7 | #include "emu.h" |
| 8 | #include "imagedev.h" |
| 9 | #include <ctype.h> |
| 10 | #include "hash.h" |
| 11 | #include "unzip.h" |
| 12 | #include "utils.h" |
| 13 | #include "hashfile.h" |
| 14 | #include "ui.h" |
| 15 | #include "device.h" |
| 16 | #include "zippath.h" |
| 17 | #include "softlist.h" |
| 18 | |
| 19 | /*************************************************************************** |
| 20 | TYPE DEFINITIONS |
| 21 | ***************************************************************************/ |
| 22 | |
| 23 | typedef struct _image_t image_t; |
| 24 | struct _image_t |
| 25 | { |
| 26 | core_file *file; |
| 27 | |
| 28 | const image_interface *intf; |
| 29 | }; |
| 30 | |
| 31 | /***************************************************************************** |
| 32 | GLOBAL VARIABLES |
| 33 | *****************************************************************************/ |
| 34 | |
| 35 | |
| 36 | /*************************************************************************** |
| 37 | IMPLEMENTATION |
| 38 | ***************************************************************************/ |
| 39 | |
| 40 | INLINE image_t *get_safe_token(const device_config *device) |
| 41 | { |
| 42 | assert(device != NULL); |
| 43 | assert(device->token != NULL); |
| 44 | assert(device->type == IMAGE); |
| 45 | |
| 46 | return (image_t *)device->token; |
| 47 | } |
| 48 | |
| 49 | /*************************************************************************** |
| 50 | DEVICE INTERFACE |
| 51 | ***************************************************************************/ |
| 52 | |
| 53 | static DEVICE_START( image ) |
| 54 | { |
| 55 | image_t *image = get_safe_token(device); |
| 56 | |
| 57 | image->intf = (const image_interface*)device->static_config; |
| 58 | |
| 59 | } |
| 60 | |
| 61 | static DEVICE_RESET( image ) |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | |
| 66 | DEVICE_GET_INFO( image ) |
| 67 | { |
| 68 | switch (state) |
| 69 | { |
| 70 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 71 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(image_t); break; |
| 72 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 73 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 74 | |
| 75 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 76 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(image); break; |
| 77 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 78 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(image); break; |
| 79 | |
| 80 | |
| 81 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 82 | case DEVINFO_STR_NAME: strcpy(info->s, "Image device"); break; |
| 83 | case DEVINFO_STR_FAMILY: strcpy(info->s, "Image device"); break; |
| 84 | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 85 | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 86 | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MESS Team"); break; |
| 87 | } |
| 88 | } |
src/mess/devices/imagedev.h
| r0 | r7127 | |
| 1 | /*************************************************************************** |
| 2 | |
| 3 | Image device |
| 4 | |
| 5 | ***************************************************************************/ |
| 6 | |
| 7 | #ifndef __IMAGE_DEV_H__ |
| 8 | #define __IMAGE_DEV_H__ |
| 9 | |
| 10 | /*************************************************************************** |
| 11 | TYPE DEFINITIONS |
| 12 | ***************************************************************************/ |
| 13 | |
| 14 | typedef enum |
| 15 | { |
| 16 | IMAGE_CARTSLOT, /* Cartridge Port, as found on most console and on some computers */ |
| 17 | IMAGE_FLOPPY, /* Floppy Disk unit */ |
| 18 | IMAGE_HARDDISK, /* Hard Disk unit */ |
| 19 | IMAGE_CYLINDER, /* Magnetically-Coated Cylinder */ |
| 20 | IMAGE_CASSETTE, /* Cassette Recorder (common on early home computers) */ |
| 21 | IMAGE_PUNCHCARD, /* Card Puncher/Reader */ |
| 22 | IMAGE_PUNCHTAPE, /* Tape Puncher/Reader (reels instead of punchcards) */ |
| 23 | IMAGE_PRINTER, /* Printer device */ |
| 24 | IMAGE_SERIAL, /* Generic Serial Port */ |
| 25 | IMAGE_PARALLEL, /* Generic Parallel Port */ |
| 26 | IMAGE_SNAPSHOT, /* Complete 'snapshot' of the state of the computer */ |
| 27 | IMAGE_QUICKLOAD, /* Allow to load program/data into memory, without matching any actual device */ |
| 28 | IMAGE_MEMCARD, /* Memory card */ |
| 29 | IMAGE_CDROM, /* Optical CD-ROM disc */ |
| 30 | IMAGE_MAGTAPE /* Magentic tape */ |
| 31 | } image_type_t; |
| 32 | |
| 33 | #define IMAGE_READABLE 0x00000001 |
| 34 | #define IMAGE_WRITEABLE 0x00000002 |
| 35 | #define IMAGE_CREATABLE 0x00000004 |
| 36 | #define IMAGE_MUST_BE_LOADED 0x00000008 |
| 37 | #define IMAGE_RESET_ON_LOAD 0x00000010 |
| 38 | |
| 39 | typedef struct _image_interface image_interface; |
| 40 | struct _image_interface |
| 41 | { |
| 42 | image_type_t image_type; |
| 43 | UINT32 image_attributes; |
| 44 | }; |
| 45 | |
| 46 | |
| 47 | /*************************************************************************** |
| 48 | FUNCTION PROTOTYPES |
| 49 | ***************************************************************************/ |
| 50 | |
| 51 | /* device interface */ |
| 52 | DEVICE_GET_INFO( image ); |
| 53 | |
| 54 | /* standard handlers */ |
| 55 | |
| 56 | |
| 57 | /*************************************************************************** |
| 58 | DEVICE CONFIGURATION MACROS |
| 59 | ***************************************************************************/ |
| 60 | |
| 61 | #define IMAGE DEVICE_GET_INFO_NAME(image) |
| 62 | |
| 63 | #define MDRV_IMAGE_ADD(_tag,_intf) \ |
| 64 | MDRV_DEVICE_ADD(_tag, IMAGE, 0) \ |
| 65 | MDRV_DEVICE_CONFIG(_intf) |
| 66 | |
| 67 | |
| 68 | /*************************************************************************** |
| 69 | DEVICE CALLBACKS |
| 70 | ***************************************************************************/ |
| 71 | |
| 72 | #endif /* __IMAGE_DEV_H__ */ |
src/mess/image.c
| r7126 | r7127 | |
| 47 | 47 | device_image_load_func load; |
| 48 | 48 | device_image_create_func create; |
| 49 | 49 | device_image_unload_func unload; |
| 50 | | device_image_verify_func verify; |
| 51 | 50 | |
| 52 | 51 | /* error related info */ |
| 53 | 52 | image_error_t err; |
| r7126 | r7127 | |
| 241 | 240 | slot->load = (device_image_load_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_LOAD); |
| 242 | 241 | slot->create = (device_image_create_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_CREATE); |
| 243 | 242 | slot->unload = (device_image_unload_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_UNLOAD); |
| 244 | | slot->verify = (device_image_verify_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_VERIFY); |
| 245 | 243 | |
| 246 | 244 | /* sodftware list and entry */ |
| 247 | 245 | slot->software_list_ptr = software_list_get_by_name( device_get_info_string(slot->dev, DEVINFO_STR_SOFTWARE_LIST) ); |
| r7126 | r7127 | |
| 402 | 400 | static void get_device_name(const device_config *device, char *buffer, size_t buffer_len) |
| 403 | 401 | { |
| 404 | 402 | const char *name = NULL; |
| 405 | | device_get_name_func get_name; |
| 406 | 403 | |
| 407 | 404 | if (name == NULL) |
| 408 | 405 | { |
| 409 | | /* first try a get_name function */ |
| 410 | | get_name = (device_get_name_func) device_get_info_fct_offline(device, DEVINFO_FCT_GET_NAME); |
| 411 | | if (get_name != NULL) |
| 412 | | name = get_name(device, buffer, buffer_len); |
| 413 | | } |
| 414 | | |
| 415 | | if (name == NULL) |
| 416 | | { |
| 417 | 406 | /* next try DEVINFO_STR_NAME */ |
| 418 | 407 | name = device_get_info_string(device, DEVINFO_STR_NAME); |
| 419 | 408 | } |
| r7126 | r7127 | |
| 815 | 804 | { |
| 816 | 805 | running_machine *machine = image->machine; |
| 817 | 806 | image_error_t err; |
| 818 | | const void *buffer; |
| 819 | 807 | UINT32 open_plan[4]; |
| 820 | 808 | int i; |
| 821 | 809 | image_slot_data *slot = find_image_slot(image); |
| r7126 | r7127 | |
| 889 | 877 | goto done; |
| 890 | 878 | } |
| 891 | 879 | |
| 892 | | /* if applicable, call device verify */ |
| 893 | | if ((slot->verify != NULL) && !image_has_been_created(image)) |
| 894 | | { |
| 895 | | /* access the memory */ |
| 896 | | buffer = image_ptr(image); |
| 897 | | if (!buffer) |
| 898 | | { |
| 899 | | slot->err = IMAGE_ERROR_OUTOFMEMORY; |
| 900 | | goto done; |
| 901 | | } |
| 902 | | |
| 903 | | /* verify the file */ |
| 904 | | err = (image_error_t)(*slot->verify)((const UINT8*)buffer, core_fsize(slot->file)); |
| 905 | | if (err) |
| 906 | | { |
| 907 | | slot->err = IMAGE_ERROR_INVALIDIMAGE; |
| 908 | | goto done; |
| 909 | | } |
| 910 | | } |
| 911 | | |
| 912 | 880 | /* call device load or create */ |
| 913 | 881 | if (image->token != NULL) |
| 914 | 882 | { |
src/mess/image.h
| r7126 | r7127 | |
| 33 | 33 | typedef int (*device_image_load_func)(const device_config *image); |
| 34 | 34 | typedef int (*device_image_create_func)(const device_config *image, int format_type, option_resolution *format_options); |
| 35 | 35 | typedef void (*device_image_unload_func)(const device_config *image); |
| 36 | | typedef int (*device_image_verify_func)(const UINT8 *buf, size_t size); |
| 37 | 36 | typedef void (*device_display_func)(const device_config *image); |
| 38 | 37 | typedef void (*device_image_partialhash_func)(char *, const unsigned char *, unsigned long, unsigned int); |
| 39 | 38 | typedef const char *(*device_get_name_func)(const device_config *device, char *buffer, size_t buffer_length); |
| r7126 | r7127 | |
| 130 | 129 | DEVINFO_FCT_IMAGE_LOAD, /* R/O: device_image_load_func */ |
| 131 | 130 | DEVINFO_FCT_IMAGE_CREATE, /* R/O: device_image_create_func */ |
| 132 | 131 | DEVINFO_FCT_IMAGE_UNLOAD, /* R/O: device_image_unload_func */ |
| 133 | | DEVINFO_FCT_IMAGE_VERIFY, /* R/O: device_image_verify_func */ |
| 134 | 132 | DEVINFO_FCT_DISPLAY, /* R/O: device_display_func */ |
| 135 | 133 | DEVINFO_FCT_IMAGE_PARTIAL_HASH, /* R/O: device_image_partialhash_func */ |
| 136 | | DEVINFO_FCT_GET_NAME, /* R/O: device_get_name_func */ |
| 137 | 134 | DEVINFO_FCT_GET_IMAGE_DEVICES, /* R/O: device_get_image_devices_func */ |
| 138 | 135 | DEVINFO_FCT_IMAGE_LAST = DEVINFO_FCT_FIRST + 0x0fff, |
| 139 | 136 | |
| r7126 | r7127 | |
| 341 | 338 | #define DEVICE_IMAGE_UNLOAD_NAME(name) device_unload_##name |
| 342 | 339 | #define DEVICE_IMAGE_UNLOAD(name) void DEVICE_IMAGE_UNLOAD_NAME(name)(const device_config *image) |
| 343 | 340 | |
| 344 | | #define DEVICE_GET_NAME_NAME(name) device_get_name_##name |
| 345 | | #define DEVICE_GET_NAME(name) const char *DEVICE_GET_NAME_NAME(name)(const device_config *device, char *buffer, size_t buffer_length) |
| 346 | | |
| 347 | 341 | #define DEVICE_GET_IMAGE_DEVICES_NAME(name) device_get_image_devices_##name |
| 348 | 342 | #define DEVICE_GET_IMAGE_DEVICES(name) void DEVICE_GET_IMAGE_DEVICES_NAME(name)(const device_config *device, device_list *devlist) |
| 349 | 343 | |