Previous 15994 Revisions Next

r2210 Wednesday 2nd April, 2008 at 10:49:18 UTC by Nathan Woods
Now using the normal device start/stop functions. Also made
image_alloctag()/image_lookuptag() specific to legacy devices.
[src/emu]mame.c
[src/mess]device.c device.h image.c image.h mess.c mess.h

src/emu/mame.c
r2209r2210
15651565   cpuint_init(machine);
15661566
15671567#ifdef MESS
1568   /* initialize the devices */
1569   devices_init(machine);
1568   /* first MESS initialization */
1569   mess_predevice_init(machine);
15701570#endif
15711571
15721572   /* call the game driver's init function */
r2209r2210
15791579   /* start up the devices */
15801580   device_list_start(machine);
15811581
1582#ifdef MESS
1583   /* second MESS initialization */
1584   mess_postdevice_init(machine);
1585#endif
1586
15821587   /* start the video and audio hardware */
15831588   video_init(machine);
15841589   tilemap_init(machine);
src/mess/mess.c
r2209r2210
102102
103103
104104/*-------------------------------------------------
105    devices_init - initialize devices for a specific
105    mess_predevice_init - initialize devices for a specific
106106   running_machine
107107-------------------------------------------------*/
108108
109void devices_init(running_machine *machine)
109void mess_predevice_init(running_machine *machine)
110110{
111   const struct IODevice *dev;
112   int result = INIT_FAIL;
113   const char *image_name;
114   const device_config *image;
115
116111   /* initialize natural keyboard support */
117112   inputx_init(machine);
118113
r2209r2210
121116
122117   /* initialize RAM code */
123118   ram_init(machine->gamedrv);
119}
124120
121
122
123/*-------------------------------------------------
124    mess_postdevice_init - initialize devices for a specific
125   running_machine
126-------------------------------------------------*/
127
128void mess_postdevice_init(running_machine *machine)
129{
130   const struct IODevice *dev;
131   int result = INIT_FAIL;
132   const char *image_name;
133   const device_config *image;
134
125135   /* init all devices */
126136   image_init(machine);
127137
src/mess/mess.h
r2209r2210
7171int mess_validitychecks(void);
7272
7373/* these are called from mame.c */
74void devices_init(running_machine *machine);
74void mess_predevice_init(running_machine *machine);
75void mess_postdevice_init(running_machine *machine);
7576
7677void mess_config_init(running_machine *machine);
7778
src/mess/image.c
r2209r2210
1919#include "unzip.h"
2020#include "devices/flopdrv.h"
2121#include "utils.h"
22#include "tagpool.h"
2322#include "hashfile.h"
2423#include "mamecore.h"
2524#include "messopts.h"
r2209r2210
3433struct _image_slot_data
3534{
3635   /* variables that persist across image mounts */
37   tag_pool tagpool;
3836   object_pool *mempool;
3937   const device_config *dev;
4038
r2209r2210
162160   {
163161      slot = &machine->images_data->slots[indx];
164162
165      /* interim changes until we use the normal device->start */
166      ((device_config *) dev)->machine = machine;
167      ((device_config *) dev)->token = (void *) ~0;
168
169163      /* create a memory pool */
170      machine->images_data->slots[indx].mempool = pool_alloc(memory_error);
164      slot->mempool = pool_alloc(memory_error);
171165
172166      /* setup the device */
173      tagpool_init(&slot->tagpool);
174167      machine->images_data->slots[indx].dev = dev;
175168
176169      /* callbacks */
r2209r2210
178171      slot->create = (device_image_create_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_CREATE);
179172      slot->unload = (device_image_unload_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_UNLOAD);
180173
181      /* invoke start, if present */
182      if (dev->start != NULL)
183      {
184         dev->start(slot->dev);
185      }
186174      indx++;
187
188      /* interim changes until we use the normal device->start */
189      ((device_config *) dev)->token = NULL;
190175   }
191176
192177   add_exit_callback(machine, image_exit);
r2209r2210
206191
207192   if (machine->images_data != NULL)
208193   {
209      /* interim hack until we use normal device startup/shutdown */
210      for (i = 0; i < machine->images_data->slot_count; i++)
211      {
212         ((device_config *) machine->images_data->slots[i].dev)->machine = machine;
213      }
214
215194      /* unload all devices */
216195      image_unload_all(FALSE);
217196      image_unload_all(TRUE);
r2209r2210
221200         /* identify the image slot */
222201         slot = &machine->images_data->slots[i];
223202
224         /* free the tagpool */
225         tagpool_exit(&slot->tagpool);
226
227203         /* free the working directory */
228204         if (slot->working_directory != NULL)
229205         {
r2209r2210
236212         slot->mempool = NULL;
237213      }
238214
239      /* interim hack until we use normal device startup/shutdown */
240      for (i = 0; i < machine->images_data->slot_count; i++)
241      {
242         ((device_config *) machine->images_data->slots[i].dev)->machine = NULL;
243      }
244
245215      machine->images_data = NULL;
246216   }
247217}
r2209r2210
964934
965935
966936/****************************************************************************
967  Tag management functions.
968
969  When devices have private data structures that need to be associated with a
970  device, it is recommended that image_alloctag() be called in the device
971  init function.  If the allocation succeeds, then a pointer will be returned
972  to a block of memory of the specified size that will last for the lifetime
973  of the emulation.  This pointer can be retrieved with image_lookuptag().
974
975  Note that since image_lookuptag() is used to index preallocated blocks of
976  memory, image_lookuptag() cannot fail legally.  In fact, an assert will be
977  raised if this happens
978****************************************************************************/
979
980void *image_alloctag(const device_config *image, const char *tag, size_t size)
981{
982   image_slot_data *slot = find_image_slot(image);
983   void *ptr = tagpool_alloc(&slot->tagpool, tag, size);
984   if (ptr == NULL)
985   {
986      memory_error("Out of memory");
987   }
988   return ptr;
989}
990
991
992
993void *image_lookuptag(const device_config *image, const char *tag)
994{
995   image_slot_data *slot = find_image_slot(image);
996   return tagpool_lookup(&slot->tagpool, tag);
997}
998
999
1000
1001/****************************************************************************
1002937  Hash info loading
1003938
1004939  If the hash is not checked and the relevant info not loaded, force that info
src/mess/image.h
r2209r2210
102102
103103
104104/****************************************************************************
105  Tag management functions.
106
107  When devices have private data structures that need to be associated with a
108  device, it is recommended that image_alloctag() be called in the device
109  init function.  If the allocation succeeds, then a pointer will be returned
110  to a block of memory of the specified size that will last for the lifetime
111  of the emulation.  This pointer can be retrieved with image_lookuptag().
112
113  Note that since image_lookuptag() is used to index preallocated blocks of
114  memory, image_lookuptag() cannot fail legally.  In fact, an assert will be
115  raised if this happens
116****************************************************************************/
117
118void *image_alloctag(const device_config *img, const char *tag, size_t size);
119void *image_lookuptag(const device_config *img, const char *tag);
120
121
122
123/****************************************************************************
124105  Accessor functions
125106
126107  These provide information about the device; and about the mounted image
src/mess/device.c
r2209r2210
1212#include "mslegacy.h"
1313#include "driver.h"
1414#include "pool.h"
15#include "tagpool.h"
1516
1617
1718
r2209r2210
3839
3940
4041
42typedef struct _mess_device_token mess_device_token;
43struct _mess_device_token
44{
45   tag_pool tagpool;
46};
47
48
49
4150struct Devices
4251{
4352   iodevice_t type;
r2209r2210
198207static DEVICE_START(mess_device)
199208{
200209   mess_device_config *mess_device = (mess_device_config *) device->inline_config;
210   mess_device_token *token = (mess_device_token *) device->token;
201211
212   /* initialize the tag pool */
213   tagpool_init(&token->tagpool);
214
202215   /* if present, invoke the start handler */
203216   if (mess_device->io_device.start != NULL)
204217      (*mess_device->io_device.start)(device);
r2209r2210
207220
208221
209222/*-------------------------------------------------
223    DEVICE_STOP(mess_device) - device stop
224    callback
225-------------------------------------------------*/
226
227static DEVICE_STOP(mess_device)
228{
229   mess_device_config *mess_device = (mess_device_config *) device->inline_config;
230   mess_device_token *token = (mess_device_token *) device->token;
231
232   /* if present, invoke the stop handler */
233   if (mess_device->io_device.stop != NULL)
234      (*mess_device->io_device.stop)(device);
235
236   /* tear down the tag pool */
237   tagpool_exit(&token->tagpool);
238}
239
240
241
242/*-------------------------------------------------
210243    DEVICE_GET_INFO(mess_device) - device get info
211244    callback
212245-------------------------------------------------*/
r2209r2210
219252   {
220253      /* --- the following bits of info are returned as 64-bit signed integers --- */
221254      case DEVINFO_INT_INLINE_CONFIG_BYTES:   info->i = sizeof(mess_device_config);         break;
222      case DEVINFO_INT_TOKEN_BYTES:         info->i = 1;                           break;
255      case DEVINFO_INT_TOKEN_BYTES:         info->i = sizeof(mess_device_token);         break;
223256      case DEVINFO_INT_CLASS:               info->i = DEVICE_CLASS_OTHER;               break;
224257
225258      /* --- the following bits of info are returned as pointers to data or functions --- */
226259      case DEVINFO_FCT_SET_INFO:            /* Nothing */                           break;
227260      case DEVINFO_FCT_START:               info->start = DEVICE_START_NAME(mess_device);   break;
228      case DEVINFO_FCT_STOP:               /* Nothing */                           break;
261      case DEVINFO_FCT_STOP:               info->stop = DEVICE_STOP_NAME(mess_device);      break;
229262      case DEVINFO_FCT_RESET:               /* Nothing */                           break;
230263      case DEVINFO_FCT_IMAGE_LOAD:         info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_LOAD); break;
231264      case DEVINFO_FCT_IMAGE_CREATE:         info->f   = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE); break;
r2209r2210
557590
558591/*************************************
559592 *
593 *   Tag management
594 *
595 *************************************/
596
597static mess_device_token *get_token(const device_config *device)
598{
599   assert(device->type == MESS_DEVICE);
600   return (mess_device_token *) device->token;
601}
602
603
604
605void *image_alloctag(const device_config *device, const char *tag, size_t size)
606{
607   void *ptr = tagpool_alloc(&get_token(device)->tagpool, tag, size);
608   if (ptr == NULL)
609   {
610      fatalerror("Out of memory");
611   }
612   return ptr;
613}
614
615
616
617void *image_lookuptag(const device_config *device, const char *tag)
618{
619   return tagpool_lookup(&get_token(device)->tagpool, tag);
620}
621
622
623
624/*************************************
625 *
560626 *   Diagnostics
561627 *
562628 *************************************/
src/mess/device.h
r2209r2210
291291const struct IODevice *device_find_from_machine(const running_machine *machine, iodevice_t type);
292292int device_count(running_machine *machine, iodevice_t type);
293293
294/* deprecated tag management functions; only works on legacy devices */
295void *image_alloctag(const device_config *device, const char *tag, size_t size);
296void *image_lookuptag(const device_config *device, const char *tag);
297
294298/* diagnostics */
295299int device_valididtychecks(void);
296300

Previous 15994 Revisions Next


© 1998-2018 The MESS Team