Previous 15994 Revisions Next

r7127 Friday 22nd January, 2010 at 14:54:44 UTC by Miodrag Milanović
- Removed some unused code from image implementation
- Implemented skeleton of new image device
[src/mess]image.c image.h mess.mak
[src/mess/devices]harddriv.c imagedev.c* imagedev.h*

src/mess/devices/harddriv.c
r7126r7127
384384}
385385
386386
387#ifdef UNUSED_FUNCTION
388/*-------------------------------------------------
389    ide_hd_validity_check - check this device's validity
390-------------------------------------------------*/
391
392static 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
420387DEVICE_GET_INFO(mess_ide)
421388{
422389   switch( state )
r7126r7127
425392      case DEVINFO_FCT_START:                  info->start = DEVICE_START_NAME(mess_ide); break;
426393      case DEVINFO_FCT_IMAGE_LOAD:            info->f = (genf *) DEVICE_IMAGE_LOAD_NAME(mess_ide); break;
427394      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;
429395
430396      /* --- the following bits of info are returned as NULL-terminated strings --- */
431397      case DEVINFO_STR_NAME:                  strcpy(info->s, "IDE harddisk"); break;
src/mess/devices/imagedev.c
r0r7127
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
23typedef struct _image_t image_t;
24struct _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
40INLINE 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
53static 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
61static DEVICE_RESET( image )
62{
63}
64
65
66DEVICE_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
r0r7127
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
14typedef 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   
39typedef struct _image_interface image_interface;
40struct _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 */
52DEVICE_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
r7126r7127
4747    device_image_load_func load;
4848    device_image_create_func create;
4949    device_image_unload_func unload;
50    device_image_verify_func verify;
5150
5251    /* error related info */
5352    image_error_t err;
r7126r7127
241240        slot->load = (device_image_load_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_LOAD);
242241        slot->create = (device_image_create_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_CREATE);
243242        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);
245243
246244      /* sodftware list and entry */
247245      slot->software_list_ptr = software_list_get_by_name( device_get_info_string(slot->dev, DEVINFO_STR_SOFTWARE_LIST) );
r7126r7127
402400static void get_device_name(const device_config *device, char *buffer, size_t buffer_len)
403401{
404402    const char *name = NULL;
405    device_get_name_func get_name;
406403
407404    if (name == NULL)
408405    {
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    {
417406        /* next try DEVINFO_STR_NAME */
418407        name = device_get_info_string(device, DEVINFO_STR_NAME);
419408    }
r7126r7127
815804{
816805    running_machine *machine = image->machine;
817806    image_error_t err;
818    const void *buffer;
819807    UINT32 open_plan[4];
820808    int i;
821809    image_slot_data *slot = find_image_slot(image);
r7126r7127
889877        goto done;
890878    }
891879
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
912880    /* call device load or create */
913881    if (image->token != NULL)
914882    {
src/mess/image.h
r7126r7127
3333typedef int (*device_image_load_func)(const device_config *image);
3434typedef int (*device_image_create_func)(const device_config *image, int format_type, option_resolution *format_options);
3535typedef void (*device_image_unload_func)(const device_config *image);
36typedef int (*device_image_verify_func)(const UINT8 *buf, size_t size);
3736typedef void (*device_display_func)(const device_config *image);
3837typedef void (*device_image_partialhash_func)(char *, const unsigned char *, unsigned long, unsigned int);
3938typedef const char *(*device_get_name_func)(const device_config *device, char *buffer, size_t buffer_length);
r7126r7127
130129    DEVINFO_FCT_IMAGE_LOAD,                                     /* R/O: device_image_load_func */
131130    DEVINFO_FCT_IMAGE_CREATE,                                   /* R/O: device_image_create_func */
132131    DEVINFO_FCT_IMAGE_UNLOAD,                                   /* R/O: device_image_unload_func */
133    DEVINFO_FCT_IMAGE_VERIFY,                                   /* R/O: device_image_verify_func */
134132    DEVINFO_FCT_DISPLAY,                                        /* R/O: device_display_func */
135133    DEVINFO_FCT_IMAGE_PARTIAL_HASH,                             /* R/O: device_image_partialhash_func */
136    DEVINFO_FCT_GET_NAME,                                       /* R/O: device_get_name_func */
137134    DEVINFO_FCT_GET_IMAGE_DEVICES,                              /* R/O: device_get_image_devices_func */
138135    DEVINFO_FCT_IMAGE_LAST = DEVINFO_FCT_FIRST + 0x0fff,
139136
r7126r7127
341338#define DEVICE_IMAGE_UNLOAD_NAME(name)      device_unload_##name
342339#define DEVICE_IMAGE_UNLOAD(name)           void DEVICE_IMAGE_UNLOAD_NAME(name)(const device_config *image)
343340
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
347341#define DEVICE_GET_IMAGE_DEVICES_NAME(name) device_get_image_devices_##name
348342#define DEVICE_GET_IMAGE_DEVICES(name)      void DEVICE_GET_IMAGE_DEVICES_NAME(name)(const device_config *device, device_list *devlist)
349343
src/mess/mess.mak
r7126r7127
398398#-------------------------------------------------
399399
400400$(MESSOBJ)/shared.a: \
401   $(MESS_DEVICES)/imagedev.o   \
401402   $(MAME_MACHINE)/pckeybrd.o   \
402403   $(MESS_AUDIO)/lmc1992.o      \
403404   $(MESS_AUDIO)/mea8000.o      \

Previous 15994 Revisions Next


© 1998-2018 The MESS Team