Previous 15994 Revisions Next

r9051 Monday 6th September, 2010 at 06:32:58 UTC by Miodrag Milanović
Sync with MAME.
Known issues:
- i386 drivers have problem since of changes in debugcmd.c
- hp48 having issue with nvram
[src/emu]addrmap.h debugger.c delegate.h devcb.h devintrf.c devintrf.h emu.h emu.mak machine.c machine.h memory.c memory.h
[src/emu/debug]debugcmd.c debugcmt.c debugcmt.h debugcpu.c debugcpu.h debugvw.c dvdisasm.c dvdisasm.h
[src/emu/machine]eeprom.c generic.c generic.h ldv1000.c nvram.c* nvram.h*
[src/emu/sound]okim6295.c okim6295.h
[src/mess/drivers]amiga.c at.c cpschngr.c dectalk.c fmtowns.c gamecom.c hp48.c ti85.c vectrex.c x68k.c
[src/mess/includes]fmtowns.h
[src/mess/machine]hp48.c

src/emu/debug/debugcmt.h
r9050r9051
1/***************************************************************************
2
3    debugcmt.h
4
5    Debugger code-comment management functions.
6
7    Copyright Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10***************************************************************************/
11
12#pragma once
13
14#ifndef __DEBUGCMT_H__
15#define __DEBUGCMT_H__
16
17#define DEBUG_COMMENT_MAX_LINE_LENGTH (128)   /* 128 characters per comment - 50 are displayed at once */
18#define DEBUG_COMMENT_MAX_NUM (0x10000)      /* 64k comments should be good for awhile */
19
20/* init and exit */
21int debug_comment_init(running_machine *machine);
22
23/* load and save */
24int debug_comment_save(running_machine *machine);
25int debug_comment_load(running_machine *machine);
26
27/* comment interface functions */
28int debug_comment_add(device_t *device, offs_t addr, const char *comment, rgb_t color, UINT32 c_crc);
29int debug_comment_remove(device_t *device, offs_t addr, UINT32 c_crc);
30
31const char *debug_comment_get_text(device_t *device, offs_t addr, UINT32 c_crc);
32int debug_comment_get_count(device_t *device);
33UINT32 debug_comment_get_change_count(device_t *device);
34UINT32 debug_comment_all_change_count(running_machine *machine);
35
36/* local functionality */
37UINT32 debug_comment_get_opcode_crc32(device_t *device, offs_t address);   /* pull a crc for the opcode at a given address */
38void debug_comment_dump(device_t *device, offs_t addr);      /* dump all (or a single) comment to the command line */
39
40#endif
src/emu/debug/debugcmt.c
r9050r9051
1/***************************************************************************
2
3    debugcmt.c
4
5    Debugger code-comment management functions.
6
7    Copyright Nicola Salmoria and the MAME Team.
8    Visit http://mamedev.org for licensing and usage restrictions.
9
10****************************************************************************
11
12    Debugger comment file format:
13
14    (from comment struct - assuming (MAX_COMMENT_LINE_LENGTH == 128))
15    0           - valid byte
16    1:4         - address
17    5:133       - comment
18    134:138     - color
19    139:142     - instruction crc
20
21***************************************************************************/
22
23#include "emu.h"
24#include "emuopts.h"
25#include "xmlfile.h"
26#include "debugcmt.h"
27#include "debugcpu.h"
28#include "debugvw.h"
29#include "info.h"
30#include <zlib.h>
31
32
33
34/***************************************************************************
35    DEBUGGING
36***************************************************************************/
37
38#define VERBOSE 0
39#define LOG(x) do { if (VERBOSE) logerror x; } while (0)
40
41
42
43/***************************************************************************
44    CONSTANTS
45***************************************************************************/
46
47#define COMMENT_VERSION   (1)
48
49
50
51/***************************************************************************
52    TYPE DEFINITIONS
53***************************************************************************/
54
55typedef struct _debug_comment debug_comment;
56struct _debug_comment
57{
58   UINT8         is_valid;
59   UINT32         address;
60   char         text[DEBUG_COMMENT_MAX_LINE_LENGTH];
61   rgb_t         color;
62   UINT32         crc;
63};
64
65
66class debug_cpu_comment_group
67{
68public:
69   int          comment_count;
70   UINT32         change_count;
71   debug_comment *   comment_info[DEBUG_COMMENT_MAX_NUM];
72};
73
74
75
76/***************************************************************************
77    FUNCTION PROTOTYPES
78***************************************************************************/
79
80static int debug_comment_load_xml(running_machine *machine, mame_file *file);
81static void debug_comment_exit(running_machine &machine);
82
83
84
85/***************************************************************************
86    INITIALIZATION
87***************************************************************************/
88
89/*-------------------------------------------------------------------------
90    debug_comment_init - initializes the comment memory and
91                         loads any existing comment file
92-------------------------------------------------------------------------*/
93
94int debug_comment_init(running_machine *machine)
95{
96   /* allocate memory for the comments */
97   device_disasm_interface *disasm;
98   for (device_t *device = machine->m_devicelist.first(); device != NULL; device = device->next())
99      if (device->interface(disasm))
100         device->debug()->m_comments = auto_alloc_clear(machine, debug_cpu_comment_group);
101
102   /* automatically load em up */
103   debug_comment_load(machine);
104   machine->add_notifier(MACHINE_NOTIFY_EXIT, debug_comment_exit);
105   return 1;
106}
107
108
109/*-------------------------------------------------------------------------
110    debug_comment_add - adds a comment to the list at the given address.
111                        use debug_comment_get_opcode_crc32(addr) to get
112                        the proper crc32
113-------------------------------------------------------------------------*/
114
115int debug_comment_add(device_t *device, offs_t addr, const char *comment, rgb_t color, UINT32 c_crc)
116{
117   debug_cpu_comment_group *comments = device->debug()->m_comments;
118   int insert_point = comments->comment_count;
119   int match = 0;
120   int i = 0;
121
122   /* Create a new item to insert into the list */
123   debug_comment *insert_me = auto_alloc(device->machine, debug_comment);
124   insert_me->color = color;
125   insert_me->is_valid = 1;
126   insert_me->address = addr;
127   insert_me->crc = c_crc;
128   strcpy(insert_me->text, comment);
129
130   /* Find the insert point */
131   for (i = 0; i < comments->comment_count; i++)
132   {
133      if (insert_me->address < comments->comment_info[i]->address)
134      {
135         insert_point = i;
136         break;
137      }
138      else if (insert_me->address == comments->comment_info[i]->address &&
139             insert_me->crc == comments->comment_info[i]->crc)
140      {
141         insert_point = i;
142         match = 1;
143         break;
144      }
145   }
146
147   /* Got an exact match?  Just replace */
148   if (match == 1)
149   {
150      auto_free(device->machine, comments->comment_info[insert_point]);
151      comments->comment_info[insert_point] = insert_me;
152      comments->change_count++;
153
154      /* force an update of disassembly views */
155      device->machine->m_debug_view->update_all(DVT_DISASSEMBLY);
156      return 1;
157   }
158
159   /* Otherwise insert */
160   /* First, shift the list down */
161   for (i = comments->comment_count; i >= insert_point; i--)
162      comments->comment_info[i] = comments->comment_info[i-1];
163
164   /* do the insertion */
165   comments->comment_info[insert_point] = insert_me;
166   comments->comment_count++;
167   comments->change_count++;
168
169   /* force an update of disassembly views */
170   device->machine->m_debug_view->update_all(DVT_DISASSEMBLY);
171
172   return 1;
173}
174
175
176/*-------------------------------------------------------------------------
177    debug_comment_remove - removes a comment at a given address
178                        use debug_comment_get_opcode_crc32(addr) to get
179                        the proper crc32
180-------------------------------------------------------------------------*/
181
182int debug_comment_remove(device_t *device, offs_t addr, UINT32 c_crc)
183{
184   debug_cpu_comment_group *comments = device->debug()->m_comments;
185   int remove_index = -1;
186   int i;
187
188   for (i = 0; i < comments->comment_count; i++)
189      if (comments->comment_info[i]->address == addr)   /* got an address match */
190         if (comments->comment_info[i]->crc == c_crc)
191            remove_index = i;
192
193   /* The comment doesn't exist? */
194   if (remove_index == -1)
195      return 0;
196
197   /* Okay, it's there, now remove it */
198   auto_free(device->machine, comments->comment_info[remove_index]);
199
200   for (i = remove_index; i < comments->comment_count-1; i++)
201      comments->comment_info[i] = comments->comment_info[i+1];
202
203   comments->comment_count--;
204   comments->change_count++;
205
206   /* force an update of disassembly views */
207   device->machine->m_debug_view->update_all(DVT_DISASSEMBLY);
208
209   return 1;
210}
211
212
213/*-------------------------------------------------------------------------
214    debug_comment_get_text - returns the comment for a given addresses
215                        use debug_comment_get_opcode_crc32(addr) to get
216                        the proper crc32
217-------------------------------------------------------------------------*/
218
219const char *debug_comment_get_text(device_t *device, offs_t addr, UINT32 c_crc)
220{
221   debug_cpu_comment_group *comments = device->debug()->m_comments;
222   int i;
223
224   /* inefficient - should use bsearch - but will be a little tricky with multiple comments per addr */
225   for (i = 0; i < comments->comment_count; i++)
226      if (comments->comment_info[i]->address == addr)   /* got an address match */
227      {
228         /* now check the bank information to be sure */
229         if (comments->comment_info[i]->crc == c_crc)
230            return comments->comment_info[i]->text;
231      }
232
233   return 0x00;
234}
235
236
237/*-------------------------------------------------------------------------
238    debug_comment_get_count - returns the number of comments
239    for a given cpu number
240-------------------------------------------------------------------------*/
241
242int debug_comment_get_count(device_t *device)
243{
244   debug_cpu_comment_group *comments = device->debug()->m_comments;
245   return comments->comment_count;
246}
247
248
249/*-------------------------------------------------------------------------
250    debug_comment_get_change_count - returns the change counter
251    for a given cpu number
252-------------------------------------------------------------------------*/
253
254UINT32 debug_comment_get_change_count(device_t *device)
255{
256   debug_cpu_comment_group *comments = device->debug()->m_comments;
257   return comments->change_count;
258}
259
260/*-------------------------------------------------------------------------
261    debug_comment_all_change_count - returns the change counter
262    for all cpu's
263-------------------------------------------------------------------------*/
264
265UINT32 debug_comment_all_change_count(running_machine *machine)
266{
267   UINT32 retVal = 0;
268
269   for (device_t *device = machine->m_devicelist.first(); device != NULL; device = device->next())
270      if (device->debug()->m_comments != NULL)
271         retVal += device->debug()->m_comments->change_count;
272
273   return retVal;
274}
275
276/*-------------------------------------------------------------------------
277    debug_comment_get_opcode_crc32 - magic function that takes all the
278                        current state of the debugger and returns a crc32
279                        for the opcode at the requested address.
280-------------------------------------------------------------------------*/
281
282UINT32 debug_comment_get_opcode_crc32(device_t *device, offs_t address)
283{
284   address_space *space = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM);
285   int i;
286   UINT32 crc;
287   UINT8 opbuf[64], argbuf[64];
288   char buff[256];
289   offs_t numbytes;
290   cpu_device *cpudevice = downcast<cpu_device *>(device);
291   int maxbytes = cpudevice->max_opcode_bytes();
292   UINT32 addrmask = space->logaddrmask();
293
294   memset(opbuf, 0x00, sizeof(opbuf));
295   memset(argbuf, 0x00, sizeof(argbuf));
296
297   // fetch the bytes up to the maximum
298   for (i = 0; i < maxbytes; i++)
299   {
300      opbuf[i] = debug_read_opcode(space, address + i, 1, FALSE);
301      argbuf[i] = debug_read_opcode(space, address + i, 1, TRUE);
302   }
303
304   numbytes = device->debug()->disassemble(buff, address & addrmask, opbuf, argbuf) & DASMFLAG_LENGTHMASK;
305   numbytes = space->address_to_byte(numbytes);
306
307   crc = crc32(0, argbuf, numbytes);
308
309   return crc;
310}
311
312
313/*-------------------------------------------------------------------------
314    debug_comment_dump - debugging function to dump junk to the command line
315-------------------------------------------------------------------------*/
316
317void debug_comment_dump(device_t *device, offs_t addr)
318{
319   debug_cpu_comment_group *comments = device->debug()->m_comments;
320   int i;
321   int ff = 0;
322
323   if (addr == -1)
324   {
325      for (i = 0; i < comments->comment_count; i++)
326         if (comments->comment_info[i]->is_valid)
327            logerror("%d : %s (%d %d)\n", i, comments->comment_info[i]->text,
328                                     comments->comment_info[i]->address,
329                                     comments->comment_info[i]->crc);
330   }
331   else
332   {
333      UINT32 c_crc = debug_comment_get_opcode_crc32(device, addr);
334
335      for (i = 0; i < comments->comment_count; i++)
336         if (comments->comment_info[i]->address == addr)   /* got an address match */
337         {
338            /* now check the bank information to be sure */
339            if (comments->comment_info[i]->crc == c_crc)
340            {
341               logerror("%d : %s (%d %d)\n", addr,
342                                      comments->comment_info[addr]->text,
343                                      comments->comment_info[addr]->address,
344                                      comments->comment_info[addr]->crc);
345               ff = 1;
346            }
347         }
348
349      if (!ff) logerror("No comment exists for address : 0x%x\n", addr);
350   }
351}
352
353
354/*-------------------------------------------------------------------------
355    debug_comment_save - comment file saving
356-------------------------------------------------------------------------*/
357
358int debug_comment_save(running_machine *machine)
359{
360   int j;
361   char crc_buf[20];
362   xml_data_node *root = xml_file_create();
363   xml_data_node *commentnode, *systemnode;
364   int total_comments = 0;
365
366   /* if we don't have a root, bail */
367   if (root == NULL)
368      return 0;
369
370   /* create a comment node */
371   commentnode = xml_add_child(root, "mamecommentfile", NULL);
372   if (commentnode == NULL)
373      goto error;
374   xml_set_attribute_int(commentnode, "version", COMMENT_VERSION);
375
376   /* create a system node */
377   systemnode = xml_add_child(commentnode, "system", NULL);
378   if (systemnode == NULL)
379      goto error;
380   xml_set_attribute(systemnode, "name", machine->gamedrv->name);
381
382   /* for each cpu */
383   for (device_t *device = machine->m_devicelist.first(); device != NULL; device = device->next())
384   {
385      debug_cpu_comment_group *comments = device->debug()->m_comments;
386      if (comments != NULL)
387      {
388         xml_data_node *curnode = xml_add_child(systemnode, "cpu", NULL);
389         if (curnode == NULL)
390            goto error;
391         xml_set_attribute(curnode, "tag", device->tag());
392
393         for (j = 0; j < comments->comment_count; j++)
394         {
395            xml_data_node *datanode = xml_add_child(curnode, "comment", xml_normalize_string(comments->comment_info[j]->text));
396            if (datanode == NULL)
397               goto error;
398            xml_set_attribute_int(datanode, "address", comments->comment_info[j]->address);
399            xml_set_attribute_int(datanode, "color", comments->comment_info[j]->color);
400            sprintf(crc_buf, "%08X", comments->comment_info[j]->crc);
401            xml_set_attribute(datanode, "crc", crc_buf);
402            total_comments++;
403         }
404      }
405   }
406
407   /* flush the file */
408   if (total_comments > 0)
409   {
410      file_error filerr;
411      mame_file *fp;
412
413      astring fname(machine->basename(), ".cmt");
414      filerr = mame_fopen(SEARCHPATH_COMMENT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &fp);
415
416      if (filerr == FILERR_NONE)
417      {
418         xml_file_write(root, mame_core_file(fp));
419         mame_fclose(fp);
420      }
421   }
422
423   /* free and get out of here */
424   xml_file_free(root);
425   return 1;
426
427error:
428   xml_file_free(root);
429   return 0;
430}
431
432
433/*-------------------------------------------------------------------------
434    debug_comment_load(_xml) - comment file loading
435-------------------------------------------------------------------------*/
436
437int debug_comment_load(running_machine *machine)
438{
439   file_error filerr;
440   mame_file *fp;
441
442   astring fname(machine->basename(), ".cmt");
443   filerr = mame_fopen(SEARCHPATH_COMMENT, fname, OPEN_FLAG_READ, &fp);
444
445   if (filerr != FILERR_NONE) return 0;
446   debug_comment_load_xml(machine, fp);
447   mame_fclose(fp);
448
449   return 1;
450}
451
452static int debug_comment_load_xml(running_machine *machine, mame_file *fp)
453{
454   int j;
455   xml_data_node *root, *commentnode, *systemnode, *cpunode, *datanode;
456   const char *name;
457   int version;
458
459   /* read the file */
460   root = xml_file_read(mame_core_file(fp), NULL);
461   if (root == NULL)
462      goto error;
463
464   /* find the config node */
465   commentnode = xml_get_sibling(root->child, "mamecommentfile");
466   if (commentnode == NULL)
467      goto error;
468
469   /* validate the config data version */
470   version = xml_get_attribute_int(commentnode, "version", 0);
471   if (version != COMMENT_VERSION)
472      goto error;
473
474   /* check to make sure the file is applicable */
475   systemnode = xml_get_sibling(commentnode->child, "system");
476   name = xml_get_attribute_string(systemnode, "name", "");
477   if (strcmp(name, machine->gamedrv->name) != 0)
478      goto error;
479
480   for (cpunode = xml_get_sibling(systemnode->child, "cpu"); cpunode; cpunode = xml_get_sibling(cpunode->next, "cpu"))
481   {
482      device_t *cpu = machine->device(xml_get_attribute_string(cpunode, "tag", ""));
483      if (cpu != NULL)
484      {
485         debug_cpu_comment_group *comments = cpu->debug()->m_comments;
486         j = 0;
487
488         for (datanode = xml_get_sibling(cpunode->child, "comment"); datanode; datanode = xml_get_sibling(datanode->next, "comment"))
489         {
490            /* Malloc the comment */
491            comments->comment_info[j] = auto_alloc(machine, debug_comment);
492
493            comments->comment_info[j]->address = xml_get_attribute_int(datanode, "address", 0);
494            comments->comment_info[j]->color = xml_get_attribute_int(datanode, "color", 0);
495            sscanf(xml_get_attribute_string(datanode, "crc", 0), "%08X", &comments->comment_info[j]->crc);
496            strcpy(comments->comment_info[j]->text, datanode->value);
497            comments->comment_info[j]->is_valid = 1;
498
499            j++;
500         }
501
502         comments->comment_count = j;
503      }
504   }
505
506   /* free the parser */
507   xml_file_free(root);
508
509   return 1;
510
511error:
512   if (root)
513      xml_file_free(root);
514   return 0;
515}
516
517
518/*-------------------------------------------------------------------------
519    debug_comment_exit - saves the comments and frees memory
520-------------------------------------------------------------------------*/
521
522static void debug_comment_exit(running_machine &machine)
523{
524   debug_comment_save(&machine);
525}
src/emu/debug/debugcpu.c
r9050r9051
3838***************************************************************************/
3939
4040#include "emu.h"
41#include "emuopts.h"
4142#include "osdepend.h"
4243#include "debugcpu.h"
4344#include "debugcmd.h"
44#include "debugcmt.h"
4545#include "debugcon.h"
4646#include "express.h"
4747#include "debugvw.h"
4848#include "debugger.h"
4949#include "debugint/debugint.h"
5050#include "uiinput.h"
51#include "xmlfile.h"
5152#include <ctype.h>
53#include <zlib.h>
5254
5355
5456
r9050r9051
9698   UINT64         tempvar[NUM_TEMP_VARIABLES];
9799
98100   osd_ticks_t    last_periodic_update_time;
101
102   bool         comments_loaded;
99103};
100104
101105
r9050r9051
184188      symtable_add_register(global->symtable, symname, &global->tempvar[regnum], get_tempvar, set_tempvar);
185189   }
186190
187   /* loop over devices and build up their info */
188   for (device_t *device = machine->m_devicelist.first(); device != NULL; device = device->next())
189      device->set_debug(*auto_alloc(machine, device_debug(*device, global->symtable)));
190
191191   /* first CPU is visible by default */
192192   global->visiblecpu = machine->firstcpu;
193193
r9050r9051
313313
314314
315315
316//**************************************************************************
317//  MEMORY AND DISASSEMBLY HELPERS
318//**************************************************************************
319
320//-------------------------------------------------
321//  debug_comment_save - save all comments for
322//  the given machine
323//-------------------------------------------------
324
325bool debug_comment_save(running_machine *machine)
326{
327   // if we don't have a root, bail
328   xml_data_node *root = xml_file_create();
329   if (root == NULL)
330      return false;
331
332   // wrap in a try/catch to handle errors
333   try
334   {
335      // create a comment node
336      xml_data_node *commentnode = xml_add_child(root, "mamecommentfile", NULL);
337      if (commentnode == NULL)
338         throw emu_exception();
339      xml_set_attribute_int(commentnode, "version", COMMENT_VERSION);
340
341      // create a system node
342      xml_data_node *systemnode = xml_add_child(commentnode, "system", NULL);
343      if (systemnode == NULL)
344         throw emu_exception();
345      xml_set_attribute(systemnode, "name", machine->gamedrv->name);
346
347      // for each device
348      bool found_comments = false;
349      for (device_t *device = machine->m_devicelist.first(); device != NULL; device = device->next())
350         if (device->debug()->comment_count() > 0)
351         {
352            // create a node for this device
353            xml_data_node *curnode = xml_add_child(systemnode, "cpu", NULL);
354            if (curnode == NULL)
355               throw emu_exception();
356            xml_set_attribute(curnode, "tag", device->tag());
357           
358            // export the comments
359            if (!device->debug()->comment_export(*curnode))
360               throw emu_exception();
361            found_comments = true;
362         }
363
364      // flush the file
365      if (found_comments)
366      {
367         astring fname(machine->basename(), ".cmt");
368         mame_file *fp;
369         file_error filerr = mame_fopen(SEARCHPATH_COMMENT, fname, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS, &fp);
370
371         if (filerr == FILERR_NONE)
372         {
373            xml_file_write(root, mame_core_file(fp));
374            mame_fclose(fp);
375         }
376      }
377   }
378   catch (emu_exception &)
379   {
380      xml_file_free(root);
381      return false;
382   }
383
384   // free and get out of here
385   xml_file_free(root);
386   return true;
387}
388
389
390//-------------------------------------------------
391//  debug_comment_load - load all comments for
392//  the given machine
393//-------------------------------------------------
394
395bool debug_comment_load(running_machine *machine)
396{
397   // open the file
398   astring fname(machine->basename(), ".cmt");
399   mame_file *fp;
400   file_error filerr = mame_fopen(SEARCHPATH_COMMENT, fname, OPEN_FLAG_READ, &fp);
401
402   // if an error, just return false
403   if (filerr != FILERR_NONE)
404      return false;
405
406   // wrap in a try/catch to handle errors
407   xml_data_node *root = xml_file_read(mame_core_file(fp), NULL);
408   try
409   {
410      // read the file
411      if (root == NULL)
412         throw emu_exception();
413
414      // find the config node
415      xml_data_node *commentnode = xml_get_sibling(root->child, "mamecommentfile");
416      if (commentnode == NULL)
417         throw emu_exception();
418
419      // validate the config data version
420      int version = xml_get_attribute_int(commentnode, "version", 0);
421      if (version != COMMENT_VERSION)
422         throw emu_exception();
423
424      // check to make sure the file is applicable
425      xml_data_node *systemnode = xml_get_sibling(commentnode->child, "system");
426      const char *name = xml_get_attribute_string(systemnode, "name", "");
427      if (strcmp(name, machine->gamedrv->name) != 0)
428         throw emu_exception();
429
430      // iterate over devices
431      for (xml_data_node *cpunode = xml_get_sibling(systemnode->child, "cpu"); cpunode; cpunode = xml_get_sibling(cpunode->next, "cpu"))
432      {
433         device_t *device = machine->device(xml_get_attribute_string(cpunode, "tag", ""));
434         if (device != NULL)
435            if (!device->debug()->comment_import(*cpunode))
436               throw emu_exception();
437      }
438   }
439   catch (emu_exception &)
440   {
441      // clean up in case of error
442      if (root != NULL)
443         xml_file_free(root);
444      mame_fclose(fp);
445      return false;
446   }
447
448   // free the parser
449   xml_file_free(root);
450   mame_fclose(fp);
451   return true;
452}
453
454
455
316456/***************************************************************************
317457    MEMORY AND DISASSEMBLY HELPERS
318458***************************************************************************/
r9050r9051
15621702//  device_debug - constructor
15631703//-------------------------------------------------
15641704
1565device_debug::device_debug(device_t &device, symbol_table *globalsyms)
1705device_debug::device_debug(device_t &device)
15661706   : m_device(device),
15671707     m_exec(NULL),
15681708     m_memory(NULL),
15691709     m_state(NULL),
15701710     m_disasm(NULL),
15711711     m_flags(0),
1572     m_symtable(symtable_alloc(globalsyms, (void *)&device)),
1712     m_symtable(symtable_alloc(debug_cpu_get_global_symtable(device.machine), (void *)&device)),
15731713     m_instrhook(NULL),
15741714     m_dasm_override(NULL),
15751715     m_opwidth(0),
r9050r9051
15851725     m_trace(NULL),
15861726     m_hotspots(NULL),
15871727     m_hotspot_count(0),
1588     m_hotspot_threshhold(0),
1589     m_comments(NULL)
1728     m_hotspot_threshhold(0)
15901729{
15911730   memset(m_pc_history, 0, sizeof(m_pc_history));
15921731   memset(m_wplist, 0, sizeof(m_wplist));
r9050r9051
18431982   if (global->execution_state == EXECUTION_STATE_STOPPED)
18441983   {
18451984      int firststop = true;
1985     
1986      // load comments if we haven't yet
1987      if (!global->comments_loaded)
1988      {
1989         debug_comment_load(m_device.machine);
1990         global->comments_loaded = true;
1991      }
18461992
18471993      // reset any transient state
18481994      reset_transient_flags(*m_device.machine);
r9050r9051
19492095//  PC on a given device
19502096//-------------------------------------------------
19512097
1952offs_t device_debug::disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram)
2098offs_t device_debug::disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram) const
19532099{
19542100   offs_t result = 0;
19552101
r9050r9051
24152561
24162562
24172563//-------------------------------------------------
2564//  comment_add - adds a comment to the list at
2565//  the given address
2566//-------------------------------------------------
2567
2568void device_debug::comment_add(offs_t addr, const char *comment, rgb_t color)
2569{
2570   // create a new item for the list
2571   UINT32 crc = compute_opcode_crc32(addr);
2572   dasm_comment *newcomment = auto_alloc(m_device.machine, dasm_comment(comment, addr, color, crc));
2573   
2574   // figure out where to insert it
2575   dasm_comment *prev = NULL;
2576   dasm_comment *curr;
2577   for (curr = m_comment_list.first(); curr != NULL; prev = curr, curr = curr->next())
2578      if (curr->m_address >= addr)
2579         break;
2580
2581   // we could be the new head
2582   if (prev == NULL)
2583      m_comment_list.prepend(*newcomment);
2584   
2585   // or else we just insert ourselves here
2586   else
2587   {
2588      newcomment->m_next = prev->m_next;
2589      prev->m_next = newcomment;
2590   }
2591   
2592   // scan forward from here to delete any exact matches
2593   for ( ; curr != NULL && curr->m_address == addr; curr = curr->next())
2594      if (curr->m_crc == crc)
2595      {
2596         m_comment_list.remove(*curr);
2597         break;
2598      }
2599
2600   // force an update
2601   m_comment_change++;
2602}
2603
2604
2605//-------------------------------------------------
2606//  comment_remove - removes a comment at the
2607//  given address with a matching CRC
2608//-------------------------------------------------
2609
2610bool device_debug::comment_remove(offs_t addr)
2611{
2612   // scan the list for a match
2613   UINT32 crc = compute_opcode_crc32(addr);
2614   for (dasm_comment *curr = m_comment_list.first(); curr != NULL; curr = curr->next())
2615   {
2616      // if we're past the address, we failed
2617      if (curr->m_address > addr)
2618         break;
2619     
2620      // find an exact match
2621      if (curr->m_address == addr && curr->m_crc == crc)
2622      {
2623         // remove it and force an update
2624         m_comment_list.remove(*curr);
2625         m_comment_change++;
2626         return true;
2627      }
2628   }
2629   
2630   // failure is an option
2631   return false;
2632}
2633
2634
2635//-------------------------------------------------
2636//  comment_text - return the text of a comment
2637//-------------------------------------------------
2638
2639const char *device_debug::comment_text(offs_t addr) const
2640{
2641   // scan the list for a match
2642   UINT32 crc = compute_opcode_crc32(addr);
2643   for (dasm_comment *curr = m_comment_list.first(); curr != NULL; curr = curr->next())
2644   {
2645      // if we're past the address, we failed
2646      if (curr->m_address > addr)
2647         break;
2648     
2649      // find an exact match
2650      if (curr->m_address == addr && curr->m_crc == crc)
2651         return curr->m_text;
2652   }
2653   
2654   // failure is an option
2655   return NULL;
2656}
2657
2658
2659//-------------------------------------------------
2660//  comment_export - export the comments to the
2661//  given XML data node
2662//-------------------------------------------------
2663
2664bool device_debug::comment_export(xml_data_node &curnode)
2665{
2666   // iterate through the comments
2667   astring crc_buf;
2668   for (dasm_comment *curr = m_comment_list.first(); curr != NULL; curr = curr->next())
2669   {
2670      xml_data_node *datanode = xml_add_child(&curnode, "comment", xml_normalize_string(curr->m_text));
2671      if (datanode == NULL)
2672         return false;
2673      xml_set_attribute_int(datanode, "address", curr->m_address);
2674      xml_set_attribute_int(datanode, "color", curr->m_color);
2675      crc_buf.printf("%08X", curr->m_crc);
2676      xml_set_attribute(datanode, "crc", crc_buf);
2677   }
2678   return true;
2679}
2680
2681
2682//-------------------------------------------------
2683//  comment_import - import the comments from the
2684//  given XML data node
2685//-------------------------------------------------
2686
2687bool device_debug::comment_import(xml_data_node &cpunode)
2688{
2689   // iterate through nodes
2690   for (xml_data_node *datanode = xml_get_sibling(cpunode.child, "comment"); datanode; datanode = xml_get_sibling(datanode->next, "comment"))
2691   {
2692      // extract attributes
2693      offs_t address = xml_get_attribute_int(datanode, "address", 0);
2694      rgb_t color = xml_get_attribute_int(datanode, "color", 0);
2695      UINT32 crc;
2696      sscanf(xml_get_attribute_string(datanode, "crc", 0), "%08X", &crc);
2697     
2698      // add the new comment; we assume they were saved ordered
2699      m_comment_list.append(*auto_alloc(m_device.machine, dasm_comment(datanode->value, address, color, crc)));
2700   }
2701   return true;
2702}
2703
2704
2705//-------------------------------------------------
2706//  comment_dump - logs comments to the error.log
2707//  at a given address
2708//-------------------------------------------------
2709
2710void device_debug::comment_dump(offs_t addr)
2711{
2712   // determine the CRC at the given address (if valid)
2713   UINT32 crc = (addr == ~0) ? 0 : compute_opcode_crc32(addr);
2714
2715   // dump everything that matches
2716   bool found = false;
2717   for (dasm_comment *curr = m_comment_list.first(); curr != NULL; curr = curr->next())
2718      if (addr == ~0 || (curr->m_address == addr && curr->m_crc == crc))
2719      {
2720         found = true;
2721         logerror("%08X %08X - %s\n", curr->m_address, curr->m_crc, curr->m_text.cstr());
2722      }
2723
2724   // if nothing found, indicate as much
2725   if (!found)
2726      logerror("No comment exists for address : 0x%x\n", addr);
2727}
2728
2729
2730//-------------------------------------------------
2731//  compute_opcode_crc32 - determine the CRC of
2732//  the opcode bytes at the given address
2733//-------------------------------------------------
2734
2735UINT32 device_debug::compute_opcode_crc32(offs_t address) const
2736{
2737   // no memory interface, just fail
2738   if (m_memory == NULL)
2739      return 0;
2740
2741   // no program interface, just fail
2742   address_space *space = m_memory->space(AS_PROGRAM);
2743   if (space == NULL)
2744      return 0;
2745     
2746   // zero out the buffers
2747   UINT8 opbuf[64], argbuf[64];
2748   memset(opbuf, 0x00, sizeof(opbuf));
2749   memset(argbuf, 0x00, sizeof(argbuf));
2750
2751   // fetch the bytes up to the maximum
2752   int maxbytes = m_disasm->max_opcode_bytes();
2753   for (int index = 0; index < maxbytes; index++)
2754   {
2755      opbuf[index] = debug_read_opcode(space, address + index, 1, false);
2756      argbuf[index] = debug_read_opcode(space, address + index, 1, true);
2757   }
2758
2759   // disassemble and then convert to bytes
2760   char buff[256];
2761   int numbytes = disassemble(buff, address & space->logaddrmask(), opbuf, argbuf) & DASMFLAG_LENGTHMASK;
2762   numbytes = space->address_to_byte(numbytes);
2763
2764   // return a CRC of the resulting bytes
2765   return crc32(0, argbuf, numbytes);
2766}
2767
2768
2769//-------------------------------------------------
24182770//  trace - trace execution of a given device
24192771//-------------------------------------------------
24202772
r9050r9051
30673419   fflush(&m_file);
30683420}
30693421
3422
3423//-------------------------------------------------
3424//  dasm_comment - constructor
3425//-------------------------------------------------
3426
3427device_debug::dasm_comment::dasm_comment(const char *text, offs_t address, rgb_t color, UINT32 crc)
3428   : m_next(NULL),
3429     m_address(address),
3430     m_color(color),
3431     m_crc(crc),
3432     m_text(text)
3433{
3434}
src/emu/debug/debugcpu.h
r9050r9051
5353const UINT8 WATCHPOINT_WRITE         = 2;
5454const UINT8 WATCHPOINT_READWRITE      = WATCHPOINT_READ | WATCHPOINT_WRITE;
5555
56const int COMMENT_VERSION             = 1;
5657
5758
59
5860//**************************************************************************
5961//  TYPE DEFINITIONS
6062//**************************************************************************
r9050r9051
6264typedef int (*debug_instruction_hook_func)(device_t &device, offs_t curpc);
6365
6466
65class debug_cpu_comment_group;
67typedef struct _xml_data_node xml_data_node;
6668
6769
6870class device_debug
r9050r9051
126128      bool hit(int type, offs_t address, int size);
127129
128130      watchpoint *      m_next;                  // next in the list
129      address_space &m_space;               // address space
131      address_space &      m_space;               // address space
130132      int               m_index;               // user reported index
131133      bool            m_enabled;               // enabled?
132134      UINT8            m_type;                  // type (read/write)
r9050r9051
138140
139141public:
140142   // construction/destruction
141   device_debug(device_t &device, symbol_table *globalsyms);
143   device_debug(device_t &device);
142144   ~device_debug();
143145
144146   // getters
r9050r9051
164166   void set_dasm_override(dasm_override_func dasm_override) { m_dasm_override = dasm_override; }
165167
166168   // disassembly
167   offs_t disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram);
169   offs_t disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram) const;
168170
169171   // debugger focus
170172   void ignore(bool ignore = true);
r9050r9051
203205   // hotspots
204206   bool hotspot_tracking_enabled() const { return (m_hotspots != NULL); }
205207   void hotspot_track(int numspots, int threshhold);
208   
209   // comments
210   void comment_add(offs_t address, const char *comment, rgb_t color);
211   bool comment_remove(offs_t addr);
212   const char *comment_text(offs_t addr) const;
213   UINT32 comment_count() const { return m_comment_list.count(); }
214   UINT32 comment_change_count() const { return m_comment_change; }
215   bool comment_export(xml_data_node &node);
216   bool comment_import(xml_data_node &node);
217   void comment_dump(offs_t addr = ~0);
218   UINT32 compute_opcode_crc32(offs_t address) const;
206219
207220   // history
208221   offs_t history_pc(int index) const;
r9050r9051
304317   {
305318      offs_t            m_access;               // access address
306319      offs_t            m_pc;                  // PC of the access
307      address_space *m_space;               // space where the access occurred
320      address_space *      m_space;               // space where the access occurred
308321      UINT32            m_count;               // number of hits
309322   };
310323   hotspot_entry *         m_hotspots;               // hotspot list
311324   int                  m_hotspot_count;         // number of hotspots
312325   int                  m_hotspot_threshhold;      // threshhold for the number of hits to print
313326
327   // comments
328   class dasm_comment
329   {
330   public:
331      dasm_comment(const char *text, offs_t address, rgb_t color, UINT32 crc);
332     
333      dasm_comment *next() const { return m_next; }
334   
335      dasm_comment *      m_next;                  // next comment in the list
336      offs_t            m_address;               // address in question
337      rgb_t            m_color;               // color to use
338      UINT32            m_crc;                  // CRC of code
339      astring            m_text;                  // text
340   };
341   simple_list<dasm_comment> m_comment_list;         // list of comments
342   UINT32               m_comment_change;         // change counter for comments
343
314344   // internal flag values
315345   static const UINT32 DEBUG_FLAG_OBSERVING      = 0x00000001;      // observing this CPU
316346   static const UINT32 DEBUG_FLAG_HISTORY         = 0x00000002;      // tracking this CPU's history
r9050r9051
332362   static const UINT32 DEBUG_FLAG_TRACING_ANY      = DEBUG_FLAG_TRACING | DEBUG_FLAG_TRACING_OVER;
333363   static const UINT32 DEBUG_FLAG_TRANSIENT      = DEBUG_FLAG_STEPPING_ANY | DEBUG_FLAG_STOP_PC | DEBUG_FLAG_STOP_CONTEXT |
334364         DEBUG_FLAG_STOP_INTERRUPT | DEBUG_FLAG_STOP_EXCEPTION | DEBUG_FLAG_STOP_VBLANK | DEBUG_FLAG_STOP_TIME;
335
336public: // until comments get folded in
337   debug_cpu_comment_group *m_comments;            // disassembly comments
338365};
339366
340367
r9050r9051
391418
392419
393420
421/* ----- debugger comment helpers ----- */
422
423// save all comments for a given machine
424bool debug_comment_save(running_machine *machine);
425
426// load all comments for a given machine
427bool debug_comment_load(running_machine *machine);
428
429
430
394431/* ----- debugger memory accessors ----- */
395432
396433/* return the physical address corresponding to the given logical address */
src/emu/debug/debugvw.c
r9050r9051
4444#include "dvdisasm.h"
4545#include "dvmemory.h"
4646#include "debugcmd.h"
47#include "debugcmt.h"
4847#include "debugcpu.h"
4948#include "debugcon.h"
5049#include "express.h"
src/emu/debug/debugcmd.c
r9050r9051
1212#include "emu.h"
1313#include "emuopts.h"
1414#include "debugcmd.h"
15#include "debugcmt.h"
1615#include "debugcon.h"
1716#include "debugcpu.h"
1817#include "express.h"
r9050r9051
11171116   }
11181117
11191118   /* Now try adding the comment */
1120   debug_comment_add(cpu, address, param[1], 0x00ff0000, debug_comment_get_opcode_crc32(cpu, address));
1119   cpu->debug()->comment_add(address, param[1], 0x00ff0000);
11211120   cpu->machine->m_debug_view->update_all(DVT_DISASSEMBLY);
11221121}
11231122
r9050r9051
11411140
11421141   /* If it's a number, it must be an address */
11431142   /* The bankoff and cbn will be pulled from what's currently active */
1144   debug_comment_remove(cpu, address, debug_comment_get_opcode_crc32(cpu, address));
1143   cpu->debug()->comment_remove(address);
11451144   cpu->machine->m_debug_view->update_all(DVT_DISASSEMBLY);
11461145}
11471146
r9050r9051
22162215   for (i = 0; i < length; )
22172216   {
22182217      int pcbyte = space->address_to_byte(offset + i) & space->bytemask();
2219      char output[200+DEBUG_COMMENT_MAX_LINE_LENGTH], disasm[200];
2218      char output[512], disasm[200];
22202219      const char *comment;
22212220      offs_t tempaddr;
22222221      int outdex = 0;
r9050r9051
22582257      sprintf(&output[outdex], "%s", disasm);
22592258
22602259      /* attempt to add the comment */
2261      comment = debug_comment_get_text(space->cpu, tempaddr, debug_comment_get_opcode_crc32(space->cpu, tempaddr));
2260      comment = space->cpu->debug()->comment_text(tempaddr);
22622261      if (comment != NULL)
22632262      {
22642263         /* somewhat arbitrary guess as to how long most disassembly lines will be [column 60] */
src/emu/debug/dvdisasm.c
r9050r9051
4040#include "emu.h"
4141#include "debugvw.h"
4242#include "dvdisasm.h"
43#include "debugcmt.h"
4443#include "debugcpu.h"
4544
4645
r9050r9051
9897   for (const debug_view_source *source = m_source_list.head(); source != NULL; source = source->next())
9998   {
10099      const debug_view_disasm_source &dasmsource = downcast<const debug_view_disasm_source &>(*source);
101      total_comments += debug_comment_get_count(&dasmsource.m_device);
100      total_comments += dasmsource.m_device.debug()->comment_count();
102101   }
103102
104103   // initialize
r9050r9051
438437      {
439438         // get and add the comment, if present
440439         offs_t comment_address = source.m_space->byte_to_address(m_byteaddress[instr]);
441         const char *text = debug_comment_get_text(&source.m_device, comment_address, debug_comment_get_opcode_crc32(&source.m_device, comment_address));
440         const char *text = source.m_device.debug()->comment_text(comment_address);
442441         if (text != NULL)
443442            sprintf(&destbuf[m_divider2], "// %.*s", m_allocated.x - m_divider2 - 1, text);
444443      }
r9050r9051
451450   // update opcode base information
452451   m_last_direct_decrypted = source.m_space->direct().decrypted();
453452   m_last_direct_raw = source.m_space->direct().raw();
454   m_last_change_count = debug_comment_all_change_count(&m_machine);
453   m_last_change_count = source.m_device.debug()->comment_change_count();
455454
456455   // now longer need to recompute
457456   m_recompute = false;
r9050r9051
502501      m_recompute = true;
503502
504503   // if the comments have changed, redo it
505   if (m_last_change_count != debug_comment_all_change_count(&m_machine))
504   if (m_last_change_count != source.m_device.debug()->comment_change_count())
506505      m_recompute = true;
507506
508507   // if we need to recompute, do it
r9050r9051
511510   if (m_recompute)
512511   {
513512      // recompute the view
514      if (m_byteaddress != NULL && m_last_change_count != debug_comment_all_change_count(&m_machine))
513      if (m_byteaddress != NULL && m_last_change_count != source.m_device.debug()->comment_change_count())
515514      {
516515         // smoosh us against the left column, but not the top row
517516         m_topleft.x = 0;
src/emu/debug/dvdisasm.h
r9050r9051
7979   // internal state
8080   device_t &         m_device;            // underlying device
8181   device_disasm_interface *m_disasmintf;      // disassembly interface
82   address_space *m_space;            // address space to display
82   address_space *      m_space;            // address space to display
8383};
8484
8585
src/emu/devcb.h
r9050r9051
6161    MACROS
6262***************************************************************************/
6363
64// static template for a read8 stub function that calls through a given READ8_MEMBER
65template<class _Class, UINT8 (_Class::*_Function)(address_space &, offs_t, UINT8)>
66UINT8 devcb_stub(device_t *device, offs_t offset)
67{
68   _Class *target = downcast<_Class *>(device);
69   return (target->*_Function)(*device->machine->m_nonspecific_space, offset, 0xff);
70}
71
72// static template for a write8 stub function that calls through a given WRITE8_MEMBER
73template<class _Class, void (_Class::*_Function)(address_space &, offs_t, UINT8, UINT8)>
74void devcb_stub(device_t *device, offs_t offset, UINT8 data)
75{
76   _Class *target = downcast<_Class *>(device);
77   (target->*_Function)(*device->machine->m_nonspecific_space, offset, data, 0xff);
78}
79
6480#define DEVCB_NULL                     { DEVCB_TYPE_NULL }
6581
6682/* standard line or read/write handlers with the calling device passed */
r9050r9051
7288/* line or read/write handlers for another device */
7389#define DEVCB_DEVICE_LINE(tag,func)         { DEVCB_TYPE_DEVICE, tag, (func), NULL, NULL }
7490#define DEVCB_DEVICE_HANDLER(tag,func)      { DEVCB_TYPE_DEVICE, tag, NULL, (func), NULL }
91#define DEVCB_DEVICE_MEMBER(tag,cls,memb)   { DEVCB_TYPE_DEVICE, tag, NULL, &devcb_stub<cls, &cls::memb>, NULL }
7592
7693/* read/write handlers for a given CPU's address space */
7794#define DEVCB_MEMORY_HANDLER(cpu,space,func) { DEVCB_TYPE_MEMORY(ADDRESS_SPACE_##space), (cpu), NULL, NULL, (func) }
r9050r9051
102119#define MDRV_DEVICE_CONFIG_READ_HANDLER(_struct, _entry, _tag, _func) MDRV_DEVICE_CONFIG_DEVCB_GENERIC(read, _struct, _entry, _tag, DEVCB_TYPE_DEVICE, NULL, _func, NULL)
103120#define MDRV_DEVICE_CONFIG_WRITE_HANDLER(_struct, _entry, _tag, _func) MDRV_DEVICE_CONFIG_DEVCB_GENERIC(write, _struct, _entry, _tag, DEVCB_TYPE_DEVICE, NULL, _func, NULL)
104121
122
123
105124/***************************************************************************
106125    TYPE DEFINITIONS
107126***************************************************************************/
r9050r9051
110129class device_config;
111130
112131
113/* read/write types for I/O lines (similar to read/write handlers but no offset) */
114typedef int (*read_line_device_func)(device_t *device);
115typedef void (*write_line_device_func)(device_t *device, int state);
116
117
118132/* static structure used for device configuration when the desired callback type is a read_line_device_func */
119133typedef struct _devcb_read_line devcb_read_line;
120134struct _devcb_read_line
src/emu/devintrf.c
r9050r9051
3838***************************************************************************/
3939
4040#include "emu.h"
41#include "debug/debugcpu.h"
4142
4243
4344
r9050r9051
199200
200201void device_list::static_exit(running_machine &machine)
201202{
203   // first let the debugger save comments
204   if ((machine.debug_flags & DEBUG_FLAG_ENABLED) != 0)
205      debug_comment_save(&machine);
206   
207   // then nuke the devices
202208   machine.m_devicelist.reset();
203209}
204210
r9050r9051
726732
727733   // force an update of the clock
728734   notify_clock_changed();
735   
736   // if we're debugging, create a device_debug object
737   if ((m_machine.debug_flags & DEBUG_FLAG_ENABLED) != 0)
738      m_debug = auto_alloc(&m_machine, device_debug(*this));
729739
730740   // register our save states
731741   state_save_register_device_item(this, 0, m_clock);
src/emu/devintrf.h
r9050r9051
102102typedef device_config *(*device_type)(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
103103
104104
105// read/write types for I/O lines (similar to read/write handlers but no offset)
106typedef int (*read_line_device_func)(device_t *device);
107typedef void (*write_line_device_func)(device_t *device, int state);
105108
109
110
106111// ======================> tagged_device_list
107112
108113// tagged_device_list is a tagged_list with additional searching based on type
r9050r9051
387392
388393   // debugging
389394   device_debug *debug() const { return m_debug; }
390   void set_debug(device_debug &debug) { m_debug = &debug; }
391395
392396   // basic information getters ... pass through to underlying config
393397   device_type type() const { return m_baseconfig.type(); }
src/emu/emu.h
r9050r9051
7777
7878// devices and callbacks
7979#include "devintrf.h"
80#include "devcb.h"
8180#include "distate.h"
8281#include "dimemory.h"
8382#include "diexec.h"
r9050r9051
129128#include "sound.h"
130129
131130// generic helpers
131#include "devcb.h"
132132#include "drivers/xtal.h"
133133#include "audio/generic.h"
134134#include "machine/generic.h"
src/emu/machine.c
r9050r9051
10491049
10501050
10511051//-------------------------------------------------
1052//  find_devices - default implementation which
1053//  does nothing
1054//-------------------------------------------------
1055
1056void driver_device::find_devices()
1057{
1058}
1059
1060
1061//-------------------------------------------------
10621052//  driver_start - default implementation which
10631053//  does nothing
10641054//-------------------------------------------------
r9050r9051
11861176   if (next() != NULL)
11871177      throw device_missing_dependencies();
11881178   
1189   // first find devices
1190   find_devices();
1179   // find all the registered devices
1180   for (auto_finder_base *autodev = m_auto_finder_list; autodev != NULL; autodev = autodev->m_next)
1181      autodev->findit(*this);
11911182
11921183   // call the game-specific init
11931184   if (m_config.m_game->driver_init != NULL)
r9050r9051
12201211}
12211212
12221213
1214//-------------------------------------------------
1215//  auto_finder_base - constructor
1216//-------------------------------------------------
12231217
1218void driver_device::register_auto_finder(auto_finder_base &autodev)
1219{
1220   // add to this list
1221   autodev.m_next = m_auto_finder_list;
1222   m_auto_finder_list = &autodev;
1223}
1224
1225
1226//-------------------------------------------------
1227//  auto_finder_base - constructor
1228//-------------------------------------------------
1229
1230driver_device::auto_finder_base::auto_finder_base(driver_device &base, const char *tag)
1231   : m_next(NULL),
1232     m_tag(tag)
1233{
1234   // register ourselves with our device class
1235   base.register_auto_finder(*this);
1236}
1237
1238
1239//-------------------------------------------------
1240//  ~auto_finder_base - destructor
1241//-------------------------------------------------
1242
1243driver_device::auto_finder_base::~auto_finder_base()
1244{
1245}
1246
1247
1248
12241249//**************************************************************************
12251250//  SYSTEM TIME
12261251//**************************************************************************
src/emu/sound/okim6295.c
r9050r9051
287287
288288
289289//-------------------------------------------------
290//  status_read - read the status register
290//  read_status - read the status register
291291//-------------------------------------------------
292292
293READ8_DEVICE_HANDLER( okim6295_r )
293UINT8 okim6295_device::read_status()
294294{
295   return downcast<okim6295_device *>(device)->read(*device->machine->m_nonspecific_space, offset);
296}
297
298READ8_MEMBER( okim6295_device::read )
299{
300295   UINT8 result = 0xf0;   // naname expects bits 4-7 to be 1
301296
302297   // set the bit to 1 if something is playing on a given channel
r9050r9051
308303   return result;
309304}
310305
311
306   
312307//-------------------------------------------------
313//  data_write - write to the command/data register
308//  read - memory interface for read
314309//-------------------------------------------------
315310
316WRITE8_DEVICE_HANDLER( okim6295_w )
311READ8_MEMBER( okim6295_device::read )
317312{
318   downcast<okim6295_device *>(device)->write(*device->machine->m_nonspecific_space, offset, data);
313   return read_status();
319314}
320315
321WRITE8_MEMBER( okim6295_device::write )
316
317//-------------------------------------------------
318//  write_command - write to the command register
319//-------------------------------------------------
320
321void okim6295_device::write_command(UINT8 command)
322322{
323323   // if a command is pending, process the second half
324324   if (m_command != -1)
325325   {
326326      // the manual explicitly says that it's not possible to start multiple voices at the same time
327      int voicemask = data >> 4;
327      int voicemask = command >> 4;
328328      if (voicemask != 0 && voicemask != 1 && voicemask != 2 && voicemask != 4 && voicemask != 8)
329329         popmessage("OKI6295 start %x contact MAMEDEV", voicemask);
330330
r9050r9051
362362
363363                  // also reset the ADPCM parameters
364364                  voice.m_adpcm.reset();
365                  voice.m_volume = s_volume_table[data & 0x0f];
365                  voice.m_volume = s_volume_table[command & 0x0f];
366366               }
367367               else
368368                  logerror("OKIM6295:'%s' requested to play sample %02x on non-stopped voice\n",tag(),m_command);
r9050r9051
381381   }
382382
383383   // if this is the start of a command, remember the sample number for next time
384   else if (data & 0x80)
385      m_command = data & 0x7f;
384   else if (command & 0x80)
385      m_command = command & 0x7f;
386386
387387   // otherwise, see if this is a silence command
388388   else
r9050r9051
391391      stream_update(m_stream);
392392
393393      // determine which voice(s) (voice is set by a 1 bit in bits 3-6 of the command
394      int voicemask = data >> 3;
394      int voicemask = command >> 3;
395395      for (int voicenum = 0; voicenum < OKIM6295_VOICES; voicenum++, voicemask >>= 1)
396396         if (voicemask & 1)
397397            m_voice[voicenum].m_playing = false;
r9050r9051
399399}
400400
401401
402//-------------------------------------------------
403//  write - memory interface for write
404//-------------------------------------------------
402405
406WRITE8_MEMBER( okim6295_device::write )
407{
408   write_command(data);
409}
410
411
412
403413//**************************************************************************
404414//  OKIM VOICE
405415//**************************************************************************
src/emu/sound/okim6295.h
r9050r9051
120120   void set_bank_base(offs_t base);
121121   void set_pin7(int pin7);
122122
123   UINT8 read_status();
124   void write_command(UINT8 command);
125   
123126   DECLARE_READ8_MEMBER( read );
124127   DECLARE_WRITE8_MEMBER( write );
125128
r9050r9051
170173extern const device_type OKIM6295;
171174
172175
173
174//**************************************************************************
175//  READ/WRITE HANDLERS
176//**************************************************************************
177
178READ8_DEVICE_HANDLER( okim6295_r );
179WRITE8_DEVICE_HANDLER( okim6295_w );
180
181
182176#endif /* __OKIM6295_H__ */
src/emu/machine.h
r9050r9051
278278// holds generic pointers that are commonly used
279279struct generic_pointers
280280{
281   generic_ptr            nvram;            // generic NVRAM
282   UINT32               nvram_size;
283281   generic_ptr            videoram;         // videoram
284282   UINT32               videoram_size;
285283   generic_ptr            spriteram;         // spriteram
r9050r9051
617615
618616protected:
619617   // helpers called at startup
620   virtual void find_devices();
621618   virtual void driver_start();
622619   virtual void machine_start();
623620   virtual void sound_start();
r9050r9051
633630   virtual void device_start();
634631   virtual void device_reset();
635632   
636   // device locators
637   template<class T>
638   bool optional_device(T *&device, const char *tag)
633   // helper class to request auto-object discovery in the constructor of a derived class
634   class auto_finder_base
639635   {
640      device = downcast<T *>(m_machine.device<T>(tag));
641      return (device != NULL);
642   }
636   public:
637      // construction/destruction
638      auto_finder_base(driver_device &base, const char *tag);
639      virtual ~auto_finder_base();
643640
644   template<class T>
645   void required_device(T *&device, const char *tag)
641      // getters
642      virtual void findit(driver_device &base) = 0;
643   
644      // internal state
645      auto_finder_base *m_next;
646      const char *m_tag;
647   };
648
649   // templated version bound to a specific type
650   template<typename _TargetType, bool _Required>
651   class auto_finder_type : public auto_finder_base
646652   {
647      if (!optional_device(device, tag))
648         throw emu_fatalerror("Unable to find device '%s'", tag);
649   }
653   public:
654      // construction/destruction
655      auto_finder_type(driver_device &base, const char *tag)
656         : auto_finder_base(base, tag),
657           m_target(NULL) { }
650658
659      // operators to make use transparent
660      operator _TargetType() { return m_target; }
661      operator _TargetType() const { return m_target; }
662      _TargetType operator->() { return m_target; }
663
664      // setter for setting the object
665      void set_target(_TargetType target)
666      {
667         m_target = target;
668         if (target == 0 && _Required)
669            throw emu_fatalerror("Unable to find required object '%s'", this->m_tag);
670      }
671
672      // internal state
673      _TargetType m_target;
674   };
675   
676   // optional device finder
677   template<class _DeviceClass>
678   class optional_device : public auto_finder_type<_DeviceClass *, false>
679   {
680   public:
681      optional_device(driver_device &base, const char *tag) : auto_finder_type<_DeviceClass *, false>(base, tag) { }
682      virtual void findit(driver_device &base) { set_target(base.m_machine.device<_DeviceClass>(this->m_tag)); }
683   };
684   
685   // required devices are similar but throw an error if they are not found
686   template<class _DeviceClass>
687   class required_device : public auto_finder_type<_DeviceClass *, true>
688   {
689   public:
690      required_device(driver_device &base, const char *tag) : auto_finder_type<_DeviceClass *, true>(base, tag) { }
691      virtual void findit(driver_device &base) { set_target(base.m_machine.device<_DeviceClass>(this->m_tag)); }
692   };
693   
694   // optional shared pointer finder
695   template<typename _PointerType>
696   class optional_shared_ptr : public auto_finder_type<_PointerType *, false>
697   {
698   public:
699      optional_shared_ptr(driver_device &base, const char *tag) : auto_finder_type<_PointerType *, false>(base, tag) { }
700      virtual void findit(driver_device &base) { set_target(reinterpret_cast<_PointerType *>(memory_get_shared(base.m_machine, this->m_tag))); }
701   };
702   
703   // required shared pointer finder
704   template<typename _PointerType>
705   class required_shared_ptr : public auto_finder_type<_PointerType *, true>
706   {
707   public:
708      required_shared_ptr(driver_device &base, const char *tag) : auto_finder_type<_PointerType *, true>(base, tag) { }
709      virtual void findit(driver_device &base) { set_target(reinterpret_cast<_PointerType *>(memory_get_shared(base.m_machine, this->m_tag))); }
710   };
711   
712   // optional shared pointer size finder
713   class optional_shared_size : public auto_finder_type<size_t, false>
714   {
715   public:
716      optional_shared_size(driver_device &base, const char *tag) : auto_finder_type<size_t, false>(base, tag) { }
717      virtual void findit(driver_device &base) { size_t size; memory_get_shared(base.m_machine, this->m_tag, size); set_target(size); }
718   };
719   
720   // required shared pointer size finder
721   class required_shared_size : public auto_finder_type<size_t, true>
722   {
723   public:
724      required_shared_size(driver_device &base, const char *tag) : auto_finder_type<size_t, true>(base, tag) { }
725      virtual void findit(driver_device &base) { size_t size; memory_get_shared(base.m_machine, this->m_tag, size); set_target(size); }
726   };
727   
728   // internal helpers
729   void register_auto_finder(auto_finder_base &autodev);
730
651731   // internal state
652732   const driver_device_config_base &m_config;
733   auto_finder_base *m_auto_finder_list;
653734};
654735
655736
src/emu/memory.c
r9050r9051
224224// banking constants
225225const int BANK_ENTRY_UNSPECIFIED = -1;
226226
227// shares are initially mapped to this invalid pointer
228static void *UNMAPPED_SHARE_PTR = ((void *)-1);
229
230227// other address map constants
231228const int MEMORY_BLOCK_CHUNK = 65536;               // minimum chunk size of allocated memory blocks
232229
r9050r9051
392389};
393390
394391
392// ======================> memory_share
393
394// a memory share contains information about shared memory region
395class memory_share
396{
397public:
398   // construction/destruction
399   memory_share(size_t size, void *ptr = NULL)
400      : m_ptr(ptr),
401        m_size(size) { }
402   
403   // getters
404   void *ptr() const { return m_ptr; }
405   size_t size() const { return m_size; }
406   
407   // setters
408   void set_ptr(void *ptr) { m_ptr = ptr; }
409   
410private:
411   // internal state
412   void *               m_ptr;               // pointer to the memory backing the region
413   size_t               m_size;               // size of the shared region
414};
415
416
395417// ======================> handler_entry
396418
397419// a handler entry contains information about a memory handler
r9050r9051
14991521   tagmap_t<memory_bank *>   bankmap;                  // map for fast bank lookups
15001522   UINT8               banknext;                  // next bank to allocate
15011523
1502   tagmap_t<void *>      sharemap;                  // map for share lookups
1524   tagmap_t<memory_share *> sharemap;                  // map for share lookups
15031525};
15041526
15051527
r9050r9051
16761698
16771699
16781700//-------------------------------------------------
1701//  memory_get_shared - get a pointer to a shared
1702//  memory region by tag
1703//-------------------------------------------------
1704
1705void *memory_get_shared(running_machine &machine, const char *tag)
1706{
1707   size_t size;
1708   return memory_get_shared(machine, tag, size);
1709}
1710
1711void *memory_get_shared(running_machine &machine, const char *tag, size_t &length)
1712{
1713   memory_share *share = machine.memory_data->sharemap.find(tag);
1714   if (share == NULL)
1715      return NULL;
1716   length = share->size();
1717   return share->ptr();
1718}
1719
1720
1721//-------------------------------------------------
16791722//  memory_dump - dump the internal memory tables
16801723//  to the given file
16811724//-------------------------------------------------
r9050r9051
19081951   // make a pass over the address map, adjusting for the device and getting memory pointers
19091952   for (address_map_entry *entry = m_map->m_entrylist.first(); entry != NULL; entry = entry->next())
19101953   {
1911      // if we have a share entry, add it to our map
1912      if (entry->m_share != NULL)
1913         m_machine.memory_data->sharemap.add(entry->m_share, UNMAPPED_SHARE_PTR, false);
1914
19151954      // computed adjusted addresses first
19161955      entry->m_bytestart = entry->m_addrstart;
19171956      entry->m_byteend = entry->m_addrend;
r9050r9051
19191958      entry->m_bytemask = entry->m_addrmask;
19201959      adjust_addresses(entry->m_bytestart, entry->m_byteend, entry->m_bytemask, entry->m_bytemirror);
19211960
1961      // if we have a share entry, add it to our map
1962      if (entry->m_share != NULL && m_machine.memory_data->sharemap.find(entry->m_share) == NULL)
1963      {
1964         memory_share *share = auto_alloc(&m_machine, memory_share(entry->m_byteend + 1 - entry->m_bytestart));
1965         m_machine.memory_data->sharemap.add(entry->m_share, share, false);
1966      }
1967
19221968      // if this is a ROM handler without a specified region, attach it to the implicit region
19231969      if (m_spacenum == ADDRESS_SPACE_0 && entry->m_read.m_type == AMH_ROM && entry->m_region == NULL)
19241970      {
r9050r9051
22742320      // if we haven't assigned this block yet, see if we have a mapped shared pointer for it
22752321      if (entry->m_memory == NULL && entry->m_share != NULL)
22762322      {
2277         void *shareptr = memdata->sharemap.find(entry->m_share);
2278         if (shareptr != UNMAPPED_SHARE_PTR)
2323         memory_share *share = memdata->sharemap.find(entry->m_share);
2324         if (share != NULL && share->ptr() != NULL)
22792325         {
2280            entry->m_memory = shareptr;
2326            entry->m_memory = share->ptr();
22812327            VPRINTF(("memory range %08X-%08X -> shared_ptr '%s' [%p]\n", entry->m_addrstart, entry->m_addrend, entry->m_share, entry->m_memory));
22822328         }
22832329      }
r9050r9051
22922338      // if we're the first match on a shared pointer, assign it now
22932339      if (entry->m_memory != NULL && entry->m_share != NULL)
22942340      {
2295         void *shareptr = memdata->sharemap.find(entry->m_share);
2296         if (shareptr == UNMAPPED_SHARE_PTR)
2297            memdata->sharemap.add(entry->m_share, entry->m_memory, TRUE);
2341         memory_share *share = memdata->sharemap.find(entry->m_share);
2342         if (share != NULL && share->ptr() == NULL)
2343            share->set_ptr(entry->m_memory);
22982344      }
22992345
23002346      // keep track of the first unassigned entry
r9050r9051
29563002   // if we are asked to provide a base pointer, then yes, we do need backing
29573003   if (entry->m_baseptr != NULL || entry->m_baseptroffs_plus1 != 0 || entry->m_genbaseptroffs_plus1 != 0)
29583004      return true;
3005   
3006   // if we are sharing, and we don't have a pointer yet, create one
3007   if (entry->m_share != NULL)
3008   {
3009      memory_share *share = m_machine.memory_data->sharemap.find(entry->m_share);
3010      if (share != NULL && share->ptr() == NULL)
3011         return true;
3012   }
29593013
29603014   // if we're writing to any sort of bank or RAM, then yes, we do need backing
29613015   if (entry->m_write.m_type == AMH_BANK || entry->m_write.m_type == AMH_RAM)
src/emu/emu.mak
r9050r9051
9999   $(EMUOBJ)/video.o \
100100   $(EMUOBJ)/watchdog.o \
101101   $(EMUOBJ)/debug/debugcmd.o \
102   $(EMUOBJ)/debug/debugcmt.o \
103102   $(EMUOBJ)/debug/debugcon.o \
104103   $(EMUOBJ)/debug/debugcpu.o \
105104   $(EMUOBJ)/debug/debughlp.o \
r9050r9051
175174   $(EMUMACHINE)/mc146818.o \
176175   $(EMUMACHINE)/microtch.o \
177176   $(EMUMACHINE)/msm6242.o \
177   $(EMUMACHINE)/nvram.o \
178178   $(EMUMACHINE)/pc16552d.o \
179179   $(EMUMACHINE)/pci.o \
180180   $(EMUMACHINE)/pic8259.o \
src/emu/memory.h
r9050r9051
740740// set the absolute address of a bank base
741741void memory_set_bankptr(running_machine *machine, const char *tag, void *base) ATTR_NONNULL(1, 3);
742742
743// get a pointer to a shared memory region by tag
744void *memory_get_shared(running_machine &machine, const char *tag);
745void *memory_get_shared(running_machine &machine, const char *tag, size_t &length);
746
743747// dump the internal memory tables to the given file
744748void memory_dump(running_machine *machine, FILE *file);
745749
src/emu/machine/generic.c
r9050r9051
104104   state_save_register_item_array(machine, "coin", NULL, 0, state->coinlockedout);
105105   state_save_register_item_array(machine, "coin", NULL, 0, state->lastcoin);
106106
107   /* reset NVRAM size and pointers */
108   machine->generic.nvram.v = NULL;
109   machine->generic.nvram_size = 0;
110
111107   /* reset memory card info */
112108   state->memcard_inserted = -1;
113109
r9050r9051
401397}
402398
403399
404/*-------------------------------------------------
405    NVRAM_HANDLER( generic_0fill ) - generic NVRAM
406    with a 0 fill
407-------------------------------------------------*/
408400
409NVRAM_HANDLER( generic_0fill )
410{
411   const region_info *region = machine->region("nvram");
412   if (read_or_write)
413      mame_fwrite(file, machine->generic.nvram.v, machine->generic.nvram_size);
414   else if (file != NULL)
415      mame_fread(file, machine->generic.nvram.v, machine->generic.nvram_size);
416   else if (region != NULL && region->bytes() == machine->generic.nvram_size)
417      memcpy(machine->generic.nvram.v, region->base(), machine->generic.nvram_size);
418   else
419      memset(machine->generic.nvram.v, 0, machine->generic.nvram_size);
420}
421
422
423/*-------------------------------------------------
424    NVRAM_HANDLER( generic_1fill ) - generic NVRAM
425    with a 1 fill
426-------------------------------------------------*/
427
428NVRAM_HANDLER( generic_1fill )
429{
430   const region_info *region = machine->region("nvram");
431   if (read_or_write)
432      mame_fwrite(file, machine->generic.nvram.v, machine->generic.nvram_size);
433   else if (file != NULL)
434      mame_fread(file, machine->generic.nvram.v, machine->generic.nvram_size);
435   else if (region != NULL && region->bytes() == machine->generic.nvram_size)
436      memcpy(machine->generic.nvram.v, region->base(), machine->generic.nvram_size);
437   else
438      memset(machine->generic.nvram.v, 0xff, machine->generic.nvram_size);
439}
440
441
442/*-------------------------------------------------
443    NVRAM_HANDLER( generic_randfill ) - generic NVRAM
444    with a random fill
445-------------------------------------------------*/
446
447NVRAM_HANDLER( generic_randfill )
448{
449   const region_info *region = machine->region("nvram");
450   if (read_or_write)
451      mame_fwrite(file, machine->generic.nvram.v, machine->generic.nvram_size);
452   else if (file != NULL)
453      mame_fread(file, machine->generic.nvram.v, machine->generic.nvram_size);
454   else if (region != NULL && region->bytes() == machine->generic.nvram_size)
455      memcpy(machine->generic.nvram.v, region->base(), machine->generic.nvram_size);
456   else
457   {
458      UINT8 *nvram = (UINT8 *)machine->generic.nvram.v;
459      int i;
460      for (i = 0; i < machine->generic.nvram_size; i++)
461         nvram[i] = mame_rand(machine);
462   }
463}
464
465
466
467401/***************************************************************************
468402    MEMORY CARD MANAGEMENT
469403***************************************************************************/
src/emu/machine/generic.h
r9050r9051
8282/* save NVRAM to a file */
8383void nvram_save(running_machine *machine);
8484
85/* generic NVRAM handler that defaults to a 0 fill */
86NVRAM_HANDLER( generic_0fill );
8785
88/* generic NVRAM handler that defaults to a 1 fill */
89NVRAM_HANDLER( generic_1fill );
9086
91/* generic NVRAM handler that defaults to a random fill */
92NVRAM_HANDLER( generic_randfill );
93
94
95
9687/* ----- memory card management ----- */
9788
9889/* create a new memory card with the given index */
src/emu/machine/nvram.c
r0r9051
1/***************************************************************************
2
3    nvram.c
4
5    Generic non-volatile RAM.
6
7****************************************************************************
8
9    Copyright Aaron Giles
10    All rights reserved.
11
12    Redistribution and use in source and binary forms, with or without
13    modification, are permitted provided that the following conditions are
14    met:
15
16        * Redistributions of source code must retain the above copyright
17          notice, this list of conditions and the following disclaimer.
18        * Redistributions in binary form must reproduce the above copyright
19          notice, this list of conditions and the following disclaimer in
20          the documentation and/or other materials provided with the
21          distribution.
22        * Neither the name 'MAME' nor the names of its contributors may be
23          used to endorse or promote products derived from this software
24          without specific prior written permission.
25
26    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36    POSSIBILITY OF SUCH DAMAGE.
37
38***************************************************************************/
39
40#include "emu.h"
41#include "machine/nvram.h"
42
43
44
45//**************************************************************************
46//  DEVICE CONFIGURATION
47//**************************************************************************
48
49//-------------------------------------------------
50//  nvram_device_config - constructor
51//-------------------------------------------------
52
53nvram_device_config::nvram_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
54   : device_config(mconfig, static_alloc_device_config, "NVRAM", tag, owner, clock),
55     device_config_nvram_interface(mconfig, *this),
56     m_default_value(DEFAULT_ALL_1)
57{
58}
59
60
61//-------------------------------------------------
62//  static_alloc_device_config - allocate a new
63//  configuration object
64//-------------------------------------------------
65
66device_config *nvram_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
67{
68   return global_alloc(nvram_device_config(mconfig, tag, owner, clock));
69}
70
71
72//-------------------------------------------------
73//  alloc_device - allocate a new device object
74//-------------------------------------------------
75
76device_t *nvram_device_config::alloc_device(running_machine &machine) const
77{
78   return auto_alloc(&machine, nvram_device(machine, *this));
79}
80
81
82//-------------------------------------------------
83//  static_set_interface - configuration helper
84//  to set the interface
85//-------------------------------------------------
86
87void nvram_device_config::static_set_default_value(device_config *device, default_value value)
88{
89   nvram_device_config *nvram = downcast<nvram_device_config *>(device);
90   nvram->m_default_value = value;
91}
92
93
94//-------------------------------------------------
95//  static_set_custom_handler - configuration
96//  helper to set a custom callback
97//-------------------------------------------------
98
99void nvram_device_config::static_set_custom_handler(device_config *device, nvram_init_proto_delegate handler)
100{
101   nvram_device_config *nvram = downcast<nvram_device_config *>(device);
102   nvram->m_custom_handler = handler;
103}
104
105
106
107//**************************************************************************
108//  LIVE DEVICE
109//**************************************************************************
110
111//-------------------------------------------------
112//  nvram_device - constructor
113//-------------------------------------------------
114
115nvram_device::nvram_device(running_machine &_machine, const nvram_device_config &config)
116   : device_t(_machine, config),
117     device_nvram_interface(_machine, config, *this),
118     m_config(config),
119     m_base(NULL),
120     m_length(0)
121{
122}
123
124
125//-------------------------------------------------
126//  device_start - device-specific startup
127//-------------------------------------------------
128
129void nvram_device::device_start()
130{
131   // bind our handler
132   if (!m_config.m_custom_handler.isnull())
133      m_custom_handler = nvram_init_delegate(m_config.m_custom_handler, *m_owner);
134
135   // find our shared pointer with the target RAM
136   m_base = memory_get_shared(m_machine, tag(), m_length);
137   if (m_base == NULL)
138      throw emu_fatalerror("NVRAM device '%s' has no corresponding AM_SHARE region", tag());
139
140   // if we are region-backed for the default, find it now and make sure it's the right size
141   if (m_region != NULL && m_region->bytes() != m_length)
142      throw emu_fatalerror("NVRAM device '%s' has a default region, but it should be 0x%X bytes", tag(), m_length);
143}
144
145
146//-------------------------------------------------
147//  nvram_default - called to initialize NVRAM to
148//  its default state
149//-------------------------------------------------
150
151void nvram_device::nvram_default()
152{
153   // region always wins
154   if (m_region != NULL)
155   {
156      memcpy(m_base, *m_region, m_length);
157      return;
158   }
159
160   // default values for other cases
161   switch (m_config.m_default_value)
162   {
163      // all-0's
164      case nvram_device_config::DEFAULT_ALL_0:
165         memset(m_base, 0, m_length);
166         break;
167
168      // all 1's
169      default:
170      case nvram_device_config::DEFAULT_ALL_1:
171         memset(m_base, 0xff, m_length);
172         break;
173
174      // random values
175      case nvram_device_config::DEFAULT_RANDOM:
176      {
177         UINT8 *nvram = reinterpret_cast<UINT8 *>(m_base);
178         for (int index = 0; index < m_length; index++)
179            nvram[index] = mame_rand(&m_machine);
180         break;
181      }
182     
183      // custom handler
184      case nvram_device_config::DEFAULT_CUSTOM:
185         m_custom_handler(*this, m_base, m_length);
186         break;
187   }
188}
189
190
191//-------------------------------------------------
192//  nvram_read - called to read NVRAM from the
193//  .nv file
194//-------------------------------------------------
195
196void nvram_device::nvram_read(mame_file &file)
197{
198   mame_fread(&file, m_base, m_length);
199}
200
201
202//-------------------------------------------------
203//  nvram_write - called to write NVRAM to the
204//  .nv file
205//-------------------------------------------------
206
207void nvram_device::nvram_write(mame_file &file)
208{
209   mame_fwrite(&file, m_base, m_length);
210}
211
212
213const device_type NVRAM = nvram_device_config::static_alloc_device_config;
src/emu/machine/nvram.h
r0r9051
1/***************************************************************************
2
3    nvram.h
4
5    Generic non-volatile RAM.
6
7****************************************************************************
8
9    Copyright Aaron Giles
10    All rights reserved.
11
12    Redistribution and use in source and binary forms, with or without
13    modification, are permitted provided that the following conditions are
14    met:
15
16        * Redistributions of source code must retain the above copyright
17          notice, this list of conditions and the following disclaimer.
18        * Redistributions in binary form must reproduce the above copyright
19          notice, this list of conditions and the following disclaimer in
20          the documentation and/or other materials provided with the
21          distribution.
22        * Neither the name 'MAME' nor the names of its contributors may be
23          used to endorse or promote products derived from this software
24          without specific prior written permission.
25
26    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36    POSSIBILITY OF SUCH DAMAGE.
37
38***************************************************************************/
39
40#pragma once
41
42#ifndef __NVRAM_H__
43#define __NVRAM_H__
44
45
46
47//**************************************************************************
48//  INTERFACE CONFIGURATION MACROS
49//**************************************************************************
50
51#define MDRV_NVRAM_ADD_0FILL(_tag) \
52   MDRV_DEVICE_ADD(_tag, NVRAM, 0) \
53   nvram_device_config::static_set_default_value(device, nvram_device_config::DEFAULT_ALL_0); \
54
55#define MDRV_NVRAM_ADD_1FILL(_tag) \
56   MDRV_DEVICE_ADD(_tag, NVRAM, 0) \
57   nvram_device_config::static_set_default_value(device, nvram_device_config::DEFAULT_ALL_1); \
58
59#define MDRV_NVRAM_ADD_RANDOM_FILL(_tag) \
60   MDRV_DEVICE_ADD(_tag, NVRAM, 0) \
61   nvram_device_config::static_set_default_value(device, nvram_device_config::DEFAULT_RANDOM); \
62
63#define MDRV_NVRAM_ADD_CUSTOM(_tag, _class, _method) \
64   MDRV_DEVICE_ADD(_tag, NVRAM, 0) \
65   nvram_device_config::static_set_custom_handler(device, nvram_init_proto_delegate::_create_member<_class, &_class::_method>(#_class "::" #_method)); \
66
67
68#define MDRV_NVRAM_REPLACE_0FILL(_tag) \
69   MDRV_DEVICE_REPLACE(_tag, NVRAM, 0) \
70   nvram_device_config::static_set_default_value(device, nvram_device_config::DEFAULT_ALL_0); \
71
72#define MDRV_NVRAM_REPLACE_1FILL(_tag) \
73   MDRV_DEVICE_REPLACE(_tag, NVRAM, 0) \
74   nvram_device_config::static_set_default_value(device, nvram_device_config::DEFAULT_ALL_1); \
75
76#define MDRV_NVRAM_REPLACE_RANDOM_FILL(_tag) \
77   MDRV_DEVICE_REPLACE(_tag, NVRAM, 0) \
78   nvram_device_config::static_set_default_value(device, nvram_device_config::DEFAULT_RANDOM); \
79
80#define MDRV_NVRAM_REPLACE_CUSTOM(_tag, _class, _method) \
81   MDRV_DEVICE_REPLACE(_tag, NVRAM, 0) \
82   nvram_device_config::static_set_custom_handler(device, nvram_init_proto_delegate::_create_member<_class, &_class::_method>(#_class "::" #_method)); \
83
84
85
86//**************************************************************************
87//  TYPE DEFINITIONS
88//**************************************************************************
89
90class nvram_device;
91
92
93// custom initialization for default state
94typedef proto_delegate_3param<void, nvram_device &, void *, size_t> nvram_init_proto_delegate;
95typedef delegate_3param<void, nvram_device &, void *, size_t> nvram_init_delegate;
96
97
98// ======================> nvram_device_config
99
100class nvram_device_config :   public device_config,
101                     public device_config_nvram_interface
102{
103   friend class nvram_device;
104
105   // construction/destruction
106   nvram_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
107
108public:
109   // values
110   enum default_value
111   {
112      DEFAULT_ALL_0,
113      DEFAULT_ALL_1,
114      DEFAULT_RANDOM,
115      DEFAULT_CUSTOM
116   };
117
118   // allocators
119   static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
120   virtual device_t *alloc_device(running_machine &machine) const;
121
122   // inline configuration helpers
123   static void static_set_default_value(device_config *device, default_value value);
124   static void static_set_custom_handler(device_config *device, nvram_init_proto_delegate callback);
125
126protected:
127   // internal state
128   default_value            m_default_value;
129   nvram_init_proto_delegate   m_custom_handler;
130};
131
132
133// ======================> nvram_device
134
135class nvram_device :   public device_t,
136                  public device_nvram_interface
137{
138   friend class nvram_device_config;
139
140   // construction/destruction
141   nvram_device(running_machine &_machine, const nvram_device_config &config);
142
143public:
144   // controls
145   void set_base(void *base, size_t length) { m_base = base; m_length = length; }
146
147protected:
148   // device-level overrides
149   virtual void device_start();
150
151   // device_nvram_interface overrides
152   virtual void nvram_default();
153   virtual void nvram_read(mame_file &file);
154   virtual void nvram_write(mame_file &file);
155
156   // internal state
157   const nvram_device_config &   m_config;
158   void *                  m_base;
159   size_t                  m_length;
160   nvram_init_delegate         m_custom_handler;
161};
162
163
164// device type definition
165extern const device_type NVRAM;
166
167
168#endif
src/emu/machine/eeprom.c
r9050r9051
132132void eeprom_device_config::static_set_default_data(device_config *device, const UINT8 *data, UINT32 size)
133133{
134134   eeprom_device_config *eeprom = downcast<eeprom_device_config *>(device);
135if (eeprom->m_data_bits != 8) mame_printf_warning("16-bit EEPROM set with 8-bit data\n");
135if (eeprom->m_data_bits != 8) mame_printf_debug("16-bit EEPROM set with 8-bit data\n");
136136//  assert(eeprom->m_data_bits == 8);
137137   eeprom->m_default_data = data;
138138   eeprom->m_default_data_size = size;
r9050r9051
141141void eeprom_device_config::static_set_default_data(device_config *device, const UINT16 *data, UINT32 size)
142142{
143143   eeprom_device_config *eeprom = downcast<eeprom_device_config *>(device);
144if (eeprom->m_data_bits != 16) mame_printf_warning("8-bit EEPROM set with 16-bit data\n");
144if (eeprom->m_data_bits != 16) mame_printf_debug("8-bit EEPROM set with 16-bit data\n");
145145//  assert(eeprom->m_data_bits == 16);
146146   eeprom->m_default_data = reinterpret_cast<const UINT8 *>(data);
147147   eeprom->m_default_data_size = size;
src/emu/machine/ldv1000.c
r9050r9051
423423static WRITE_LINE_DEVICE_HANDLER( ctc_interrupt )
424424{
425425   laserdisc_state *ld = ldcore_get_safe_token(device->owner());
426   cpu_set_input_line(ld->player->cpu, 0, state ? ASSERT_LINE : CLEAR_LINE);
426   if (ld->player->cpu != NULL)
427      cpu_set_input_line(ld->player->cpu, 0, state ? ASSERT_LINE : CLEAR_LINE);
427428}
428429
429430
src/emu/addrmap.h
r9050r9051
586586   curentry->set_handler(devconfig, _tag, _rhandler, #_rhandler, _whandler, #_whandler, _unitmask); \
587587
588588
589// device reads
590#define AM_DEVREAD_MODERN(_tag, _class, _handler) \
591   curentry->set_handler(devconfig, _tag, read_proto_delegate::_create_member<_class, &_class::_handler>(#_class "::" #_handler)); \
592
593#define AM_DEVREAD8_MODERN(_tag, _class, _handler, _unitmask) \
594   curentry->set_handler(devconfig, _tag, read8_proto_delegate::_create_member<_class, &_class::_handler>(#_class "::" #_handler), _unitmask); \
595
596#define AM_DEVREAD16_MODERN(_tag, _class, _handler, _unitmask) \
597   curentry->set_handler(devconfig, _tag, read16_proto_delegate::_create_member<_class, &_class::_handler>(#_class "::" #_handler), _unitmask); \
598
599#define AM_DEVREAD32_MODERN(_tag, _class, _handler, _unitmask) \
600   curentry->set_handler(devconfig, _tag, read32_proto_delegate::_create_member<_class, &_class::_handler>(#_class "::" #_handler), _unitmask); \
601
602
603// device writes
604#define AM_DEVWRITE_MODERN(_tag, _class, _handler) \
605   curentry->set_handler(devconfig, _tag, write_proto_delegate::_create_member<_class, &_class::_handler>(#_class "::" #_handler)); \
606
607#define AM_DEVWRITE8_MODERN(_tag, _class, _handler, _unitmask) \
608   curentry->set_handler(devconfig, _tag, write8_proto_delegate::_create_member<_class, &_class::_handler>(#_class "::" #_handler), _unitmask); \
609
610#define AM_DEVWRITE16_MODERN(_tag, _class, _handler, _unitmask) \
611   curentry->set_handler(devconfig, _tag, write16_proto_delegate::_create_member<_class, &_class::_handler>(#_class "::" #_handler), _unitmask); \
612
613#define AM_DEVWRITE32_MODERN(_tag, _class, _handler, _unitmask) \
614   curentry->set_handler(devconfig, _tag, write32_proto_delegate::_create_member<_class, &_class::_handler>(#_class "::" #_handler), _unitmask); \
615
616
617// device reads/writes
618#define AM_DEVREADWRITE_MODERN(_tag, _class, _rhandler, _whandler) \
619   curentry->set_handler(devconfig, _tag, read_proto_delegate::_create_member<_class, &_class::_rhandler>(#_class "::" #_rhandler), write_proto_delegate::_create_member<_class, &_class::_whandler>(#_class "::" #_whandler)); \
620
621#define AM_DEVREADWRITE8_MODERN(_tag, _class, _rhandler, _whandler, _unitmask) \
622   curentry->set_handler(devconfig, _tag, read8_proto_delegate::_create_member<_class, &_class::_rhandler>(#_class "::" #_rhandler), write8_proto_delegate::_create_member<_class, &_class::_whandler>(#_class "::" #_whandler), _unitmask); \
623
624#define AM_DEVREADWRITE16_MODERN(_tag, _class, _rhandler, _whandler, _unitmask) \
625   curentry->set_handler(devconfig, _tag, read16_proto_delegate::_create_member<_class, &_class::_rhandler>(#_class "::" #_rhandler), write16_proto_delegate::_create_member<_class, &_class::_whandler>(#_class "::" #_whandler), _unitmask); \
626
627#define AM_DEVREADWRITE32_MODERN(_tag, _class, _rhandler, _whandler, _unitmask) \
628   curentry->set_handler(devconfig, _tag, read32_proto_delegate::_create_member<_class, &_class::_rhandler>(#_class "::" #_rhandler), write32_proto_delegate::_create_member<_class, &_class::_whandler>(#_class "::" #_whandler), _unitmask); \
629
630
589631// special-case accesses
590632#define AM_ROM \
591633   curentry->set_read_type(AMH_ROM); \
src/emu/debugger.c
r9050r9051
1313#include "debugger.h"
1414#include "debug/debugcpu.h"
1515#include "debug/debugcmd.h"
16#include "debug/debugcmt.h"
1716#include "debug/debugcon.h"
1817#include "debug/express.h"
1918#include "debug/debugvw.h"
r9050r9051
7271      debug_cpu_init(machine);
7372      debug_command_init(machine);
7473      debug_console_init(machine);
75      debug_comment_init(machine);
7674
7775      /* always initialize the internal render debugger */
7876      debugint_init(machine);
src/emu/delegate.h
r9050r9051
776776   // bind the actual object
777777   void bind(bindable_object &object)
778778   {
779      m_object = (*m_caster)(object);
779      m_object = (*this->m_caster)(object);
780780      if (m_rawfunction.u.funcptr != NULL)
781781         m_function = reinterpret_cast<static_func>(delegate_convert_raw(m_object, m_rawfunction));
782782   }
r9050r9051
878878   // bind the actual object
879879   void bind(bindable_object &object)
880880   {
881      m_object = (*m_caster)(object);
881      m_object = (*this->m_caster)(object);
882882      if (m_rawfunction.u.funcptr != NULL)
883883         m_function = reinterpret_cast<static_func>(delegate_convert_raw(m_object, m_rawfunction));
884884   }
r9050r9051
980980   // bind the actual object
981981   void bind(bindable_object &object)
982982   {
983      m_object = (*m_caster)(object);
983      m_object = (*this->m_caster)(object);
984984      if (m_rawfunction.u.funcptr != NULL)
985985         m_function = reinterpret_cast<static_func>(delegate_convert_raw(m_object, m_rawfunction));
986986   }
r9050r9051
10821082   // bind the actual object
10831083   void bind(bindable_object &object)
10841084   {
1085      m_object = (*m_caster)(object);
1085      m_object = (*this->m_caster)(object);
10861086      if (m_rawfunction.u.funcptr != NULL)
10871087         m_function = reinterpret_cast<static_func>(delegate_convert_raw(m_object, m_rawfunction));
10881088   }
r9050r9051
11841184   // bind the actual object
11851185   void bind(bindable_object &object)
11861186   {
1187      m_object = (*m_caster)(object);
1187      m_object = (*this->m_caster)(object);
11881188      if (m_rawfunction.u.funcptr != NULL)
11891189         m_function = reinterpret_cast<static_func>(delegate_convert_raw(m_object, m_rawfunction));
11901190   }
src/mess/machine/hp48.c
r9050r9051
1414
1515#include "devices/xmodem.h"
1616#include "devices/kermit.h"
17#include "machine/nvram.h"
1718
1819#include "includes/hp48.h"
1920
r9050r9051
11641165
11651166   /* internal RAM */
11661167   ram_size = HP48_GX_MODEL ? (128 * 1024) : (32 * 1024);
1167   machine->generic.nvram_size = 2 * ram_size;
1168   machine->generic.nvram.u8 = auto_alloc_array(machine, UINT8, machine->generic.nvram_size);
1169   ram = machine->generic.nvram.u8;
1168     
1169   ram = auto_alloc_array(machine, UINT8, 2 * ram_size);
1170   machine->device<nvram_device>("nvram")->set_base(ram, 2 * ram_size);   
1171   
11701172
11711173   /* ROM load */
11721174   rom_size = HP48_S_SERIES ? (256 * 1024) : (512 * 1024);
r9050r9051
11741176   hp48_decode_nibble( rom, memory_region( machine, "maincpu" ), rom_size );
11751177
11761178   /* init state */
1177   memset( machine->generic.nvram.u8, 0, machine->generic.nvram_size );
1179   memset( ram, 0, 2 * ram_size );
11781180   memset( hp48_io, 0, sizeof( hp48_io ) );
11791181   hp48_out = 0;
11801182   hp48_kdn = 0;
r9050r9051
12331235      state_save_register_item(machine, "globals", NULL, i, hp48_modules[i].mask );
12341236   }
12351237   state_save_register_global_array(machine,  hp48_io );
1236   state_save_register_global_pointer(machine,  machine->generic.nvram.u8, machine->generic.nvram_size );
1238   //state_save_register_global_pointer(machine,  machine->generic.nvram.u8, machine->generic.nvram_size );
12371239
12381240   state_save_register_postload( machine, hp48_update_annunciators, NULL );
12391241   state_save_register_postload( machine, hp48_apply_modules, NULL );
src/mess/includes/fmtowns.h
r9050r9051
7676{
7777   public:
7878   towns_state(running_machine &machine, const driver_device_config_base &config)
79      : driver_device(machine, config) { }
80
79      : driver_device(machine, config),
80        m_nvram(*this, "nvram") { }
81       
8182   UINT8 ftimer;
8283   UINT8 nmi_mask;
8384   UINT8 compat_mode;
r9050r9051
8586   UINT32 towns_ankcg_enable;
8687   UINT32 towns_mainmem_enable;
8788   UINT32 towns_ram_enable;
88   UINT8* towns_cmos;
8989   UINT32* towns_vram;
9090   UINT8* towns_gfxvram;
9191   UINT8* towns_txtvram;
r9050r9051
117117   UINT8 towns_mouse_y;
118118   struct towns_cdrom_controller towns_cd;
119119   struct towns_video_controller video;
120   required_shared_ptr<UINT8>   m_nvram;
120121
121122   /* devices */
122123   running_device* maincpu;
src/mess/drivers/dectalk.c
r9050r9051
720720    MDRV_QUANTUM_PERFECT_CPU("dsp")
721721#endif
722722
723    //MDRV_NVRAM_HANDLER(generic_0fill)
723    //MDRV_NVRAM_ADD_0FILL("nvram")
724724
725725    /* video hardware */
726726    //MDRV_DEFAULT_LAYOUT(layout_dectalk) // hack to avoid screenless system crash
src/mess/drivers/hp48.c
r9050r9051
1414#include "devices/kermit.h"
1515#include "cpu/saturn/saturn.h"
1616#include "sound/dac.h"
17#include "machine/nvram.h"
1718
1819#include "includes/hp48.h"
1920
r9050r9051
950951   MDRV_CPU_CONFIG( hp48_config )
951952
952953   /* memory */
953   MDRV_NVRAM_HANDLER( generic_0fill )
954   MDRV_NVRAM_ADD_0FILL("nvram")
954955
955956   /* video */
956957   MDRV_SCREEN_ADD( "screen", RASTER )
src/mess/drivers/gamecom.c
r9050r9051
3535   AM_RANGE( 0x6000, 0x7FFF )  AM_ROMBANK("bank3")                                       /* External ROM/Flash. Controlled by MMU3 */
3636   AM_RANGE( 0x8000, 0x9FFF )  AM_ROMBANK("bank4")                                       /* External ROM/Flash. Controlled by MMU4 */
3737   AM_RANGE( 0xA000, 0xDFFF )  AM_RAM AM_BASE(&gamecom_vram)         /* VRAM */
38   AM_RANGE( 0xE000, 0xFFFF )  AM_RAM AM_BASE_SIZE_GENERIC(nvram)                  /* Extended I/O, Extended RAM */
38   AM_RANGE( 0xE000, 0xFFFF )  AM_RAM AM_SHARE("nvram")                  /* Extended I/O, Extended RAM */
3939ADDRESS_MAP_END
4040
4141static const SM8500_CONFIG gamecom_cpu_config = {
r9050r9051
107107   MDRV_SCREEN_VBLANK_TIME(500)
108108   MDRV_QUANTUM_TIME(HZ(60))
109109
110   MDRV_NVRAM_HANDLER(generic_0fill)
110   //MDRV_NVRAM_ADD_0FILL("nvram")
111111
112112   MDRV_MACHINE_RESET( gamecom )
113113
src/mess/drivers/at.c
r9050r9051
106106   AM_RANGE(0x000c8000, 0x000cffff) AM_ROM
107107   AM_RANGE(0x000d0000, 0x000effff) AM_ROM
108108   AM_RANGE(0x000f0000, 0x000fffff) AM_ROM
109   AM_RANGE(0x00800000, 0x00800bff) AM_RAM AM_BASE_SIZE_GENERIC(nvram)
109   AM_RANGE(0x00800000, 0x00800bff) AM_RAM AM_SHARE("nvram")
110110   AM_RANGE(0x00ff0000, 0x00ffffff) AM_ROM AM_REGION("maincpu", 0x0f0000)
111111ADDRESS_MAP_END
112112
r9050r9051
114114   AM_RANGE(0x00000000, 0x0009ffff) AM_RAMBANK("bank10")
115115   AM_RANGE(0x000a0000, 0x000bffff) AM_NOP
116116//  AM_RANGE(0x000b8000, 0x000bffff) AM_READWRITE(SMH_RAM, pc_video_videoram32_w) AM_BASE((UINT32 **) &videoram) AM_SIZE(&videoram_size)
117   AM_RANGE(0x00800000, 0x00800bff) AM_RAM AM_BASE_SIZE_GENERIC(nvram)
117   AM_RANGE(0x00800000, 0x00800bff) AM_RAM AM_SHARE("nvram")
118118   AM_RANGE(0xfffe0000, 0xffffffff) AM_ROM AM_REGION("user1", 0x20000)
119119ADDRESS_MAP_END
120120
r9050r9051
826826   MDRV_KB_KEYTRONIC_ADD("keyboard", at_keytronic_intf)
827827
828828   MDRV_NVRAM_HANDLER( mc146818 )
829//  MDRV_NVRAM_HANDLER(generic_0fill)
829//  MDRV_NVRAM_ADD_0FILL("nvram")
830830
831831   /* printers */
832832   MDRV_PC_LPT_ADD("lpt_0", at_lpt_config)
src/mess/drivers/amiga.c
r9050r9051
3131#include "machine/amigacrt.h"
3232#include "machine/msm6242.h"
3333#include "machine/ctronics.h"
34#include "machine/nvram.h"
3435#include "sound/cdda.h"
3536
3637/* Devices */
r9050r9051
150151   AM_RANGE(0x000000, 0x0fffff) AM_RAMBANK("bank1") AM_BASE(&amiga_chip_ram) AM_SIZE(&amiga_chip_ram_size)
151152   AM_RANGE(0xbfd000, 0xbfefff) AM_READWRITE(amiga_cia_r, amiga_cia_w)
152153   AM_RANGE(0xdc0000, 0xdc003f) AM_READWRITE(amiga_clock_r, amiga_clock_w)
153   AM_RANGE(0xdc8000, 0xdc87ff) AM_RAM AM_BASE_GENERIC(nvram)
154   AM_RANGE(0xdc8000, 0xdc87ff) AM_RAM AM_SHARE("nvram")
154155   AM_RANGE(0xdf0000, 0xdfffff) AM_READWRITE(amiga_custom_r, amiga_custom_w) AM_BASE(&amiga_custom_regs)   /* Custom Chips */
155156   AM_RANGE(0xe80000, 0xe8ffff) AM_READWRITE(amiga_autoconfig_r, amiga_autoconfig_w)
156157   AM_RANGE(0xf00000, 0xffffff) AM_ROM AM_REGION("user1", 0)   /* CDTV & System ROM */
r9050r9051
435436   MDRV_MACHINE_START( cdtv )
436437   MDRV_MACHINE_RESET( cdtv )
437438
438   MDRV_NVRAM_HANDLER(generic_0fill)
439   MDRV_NVRAM_ADD_0FILL("nvram")
439440
440441   MDRV_SOUND_ADD( "cdda", CDDA, 0 )
441442   MDRV_SOUND_ROUTE( 0, "lspeaker", 1.0 )
src/mess/drivers/fmtowns.c
r9050r9051
125125#include "machine/upd71071.h"
126126#include "devices/messram.h"
127127#include "includes/fmtowns.h"
128#include "machine/nvram.h"
128129
129130// CD controller IRQ types
130131#define TOWNS_CD_IRQ_MPU 1
r9050r9051
957958static READ8_HANDLER( towns_cmos8_r )
958959{
959960   towns_state* state = space->machine->driver_data<towns_state>();
960   return state->towns_cmos[offset];
961   return state->m_nvram[offset];
961962}
962963
963964static WRITE8_HANDLER( towns_cmos8_w )
964965{
965966   towns_state* state = space->machine->driver_data<towns_state>();
966   state->towns_cmos[offset] = data;
967   state->m_nvram[offset] = data;
967968}
968969
969970static READ8_HANDLER( towns_cmos_low_r )
r9050r9051
972973   if(state->towns_mainmem_enable != 0)
973974      return messram_get_ptr(state->messram)[offset + 0xd8000];
974975
975   return state->towns_cmos[offset];
976   return state->m_nvram[offset];
976977}
977978
978979static WRITE8_HANDLER( towns_cmos_low_w )
r9050r9051
981982   if(state->towns_mainmem_enable != 0)
982983      messram_get_ptr(state->messram)[offset+0xd8000] = data;
983984   else
984      state->towns_cmos[offset] = data;
985      state->m_nvram[offset] = data;
985986}
986987
987988static READ8_HANDLER( towns_cmos_r )
988989{
989990   towns_state* state = space->machine->driver_data<towns_state>();
990   return state->towns_cmos[offset];
991   return state->m_nvram[offset];
991992}
992993
993994static WRITE8_HANDLER( towns_cmos_w )
994995{
995996   towns_state* state = space->machine->driver_data<towns_state>();
996   state->towns_cmos[offset] = data;
997   state->m_nvram[offset] = data;
997998}
998999
9991000void towns_update_video_banks(address_space* space)
r9050r9051
18371838  AM_RANGE(0x000cc000, 0x000cff7f) AM_RAM
18381839  AM_RANGE(0x000cff80, 0x000cffff) AM_READWRITE8(towns_video_cff80_mem_r,towns_video_cff80_mem_w,0xffffffff)
18391840  AM_RANGE(0x000d0000, 0x000d7fff) AM_RAM
1840  AM_RANGE(0x000d8000, 0x000d9fff) AM_READWRITE8(towns_cmos_low_r,towns_cmos_low_w,0xffffffff) AM_BASE_SIZE_GENERIC(nvram) // CMOS? RAM
1841  AM_RANGE(0x000d8000, 0x000d9fff) AM_READWRITE8(towns_cmos_low_r,towns_cmos_low_w,0xffffffff) AM_SHARE("nvram") // CMOS? RAM
18411842  AM_RANGE(0x000da000, 0x000effff) AM_RAM //READWRITE(SMH_BANK(11),SMH_BANK(11))
18421843  AM_RANGE(0x000f0000, 0x000f7fff) AM_RAM //READWRITE(SMH_BANK(12),SMH_BANK(12))
18431844  AM_RANGE(0x000f8000, 0x000fffff) AM_READ_BANK("bank11") AM_WRITE_BANK("bank12")
r9050r9051
18611862  AM_RANGE(0x000cc000, 0x000cff7f) AM_RAM
18621863  AM_RANGE(0x000cff80, 0x000cffff) AM_READWRITE8(towns_video_cff80_r,towns_video_cff80_w,0xffffffff)
18631864  AM_RANGE(0x000d0000, 0x000d7fff) AM_RAM
1864  AM_RANGE(0x000d8000, 0x000d9fff) AM_READWRITE8(towns_cmos_low_r,towns_cmos_low_w,0xffffffff) AM_BASE_SIZE_GENERIC(nvram) // CMOS? RAM
1865  AM_RANGE(0x000d8000, 0x000d9fff) AM_READWRITE8(towns_cmos_low_r,towns_cmos_low_w,0xffffffff) AM_SHARE("nvram") // CMOS? RAM
18651866  AM_RANGE(0x000da000, 0x000effff) AM_RAM //READWRITE(SMH_BANK(11),SMH_BANK(11))
18661867  AM_RANGE(0x000f0000, 0x000f7fff) AM_RAM //READWRITE(SMH_BANK(12),SMH_BANK(12))
18671868  AM_RANGE(0x000f8000, 0x000fffff) AM_READ_BANK("bank11") AM_WRITE_BANK("bank12")
r9050r9051
21482149   state->pic_master = machine->device("pic8259_master");
21492150   state->pic_slave = machine->device("pic8259_slave");
21502151   state->towns_vram = auto_alloc_array(machine,UINT32,0x20000);
2151   state->towns_cmos = machine->generic.nvram.u8;
21522152   state->towns_gfxvram = auto_alloc_array(machine,UINT8,0x80000);
21532153   state->towns_txtvram = auto_alloc_array(machine,UINT8,0x20000);
21542154   //towns_sprram = auto_alloc_array(machine,UINT8,0x20000);
r9050r9051
23542354   MDRV_UPD71071_ADD("dma_1",towns_dma_config)
23552355   MDRV_UPD71071_ADD("dma_2",towns_dma_config)
23562356
2357   MDRV_NVRAM_HANDLER( generic_0fill )
2357   MDRV_NVRAM_ADD_0FILL("nvram")
23582358
23592359    MDRV_VIDEO_START(towns)
23602360    MDRV_VIDEO_UPDATE(towns)
src/mess/drivers/ti85.c
r9050r9051
191191#include "includes/ti85.h"
192192#include "devices/snapquik.h"
193193#include "formats/ti85_ser.h"
194#include "machine/nvram.h"
194195
195196/* port i/o functions */
196197
r9050r9051
270271static ADDRESS_MAP_START( ti81_mem , ADDRESS_SPACE_PROGRAM, 8)
271272   AM_RANGE(0x0000, 0x3fff) AM_ROMBANK("bank1")
272273   AM_RANGE(0x4000, 0x7fff) AM_ROMBANK("bank2")
273   AM_RANGE(0x8000, 0xffff) AM_RAM AM_BASE_SIZE_GENERIC(nvram)
274   AM_RANGE(0x8000, 0xffff) AM_RAM AM_SHARE("nvram")
274275ADDRESS_MAP_END
275276
276277static ADDRESS_MAP_START( ti86_mem , ADDRESS_SPACE_PROGRAM, 8)
r9050r9051
485486      PORT_DIPSETTING( 0x00, "Low Battery" )
486487INPUT_PORTS_END
487488
489class ti_state : public driver_device
490{
491public:
492   ti_state(running_machine &machine, const driver_device_config_base &config)
493      : driver_device(machine, config),
494        m_nvram(*this, "nvram") { }
495
496   required_shared_ptr<UINT8>   m_nvram;
497};
498
488499/* machine definition */
489static MACHINE_CONFIG_START( ti81, driver_device )
500static MACHINE_CONFIG_START( ti81, ti_state )
490501   /* basic machine hardware */
491502   MDRV_CPU_ADD("maincpu", Z80, 2000000)        /* 2 MHz */
492503   MDRV_CPU_PROGRAM_MAP(ti81_mem)
r9050r9051
508519   MDRV_VIDEO_START( ti85 )
509520   MDRV_VIDEO_UPDATE( ti85 )
510521
511   MDRV_NVRAM_HANDLER(generic_0fill)
522   MDRV_NVRAM_ADD_0FILL("nvram")
512523MACHINE_CONFIG_END
513524
514525
src/mess/drivers/cpschngr.c
r9050r9051
207207   AM_RANGE(0x8000, 0xbfff) AM_ROMBANK("bank1")
208208   AM_RANGE(0xd000, 0xd7ff) AM_RAM
209209   AM_RANGE(0xf000, 0xf001) AM_DEVREADWRITE("2151", ym2151_r, ym2151_w)
210   AM_RANGE(0xf002, 0xf002) AM_DEVREADWRITE("oki", okim6295_r, okim6295_w)
210   AM_RANGE(0xf002, 0xf002) AM_DEVREADWRITE_MODERN("oki", okim6295_device, read, write)
211211   AM_RANGE(0xf004, 0xf004) AM_WRITE(cps1_snd_bankswitch_w)
212212   AM_RANGE(0xf006, 0xf006) AM_DEVWRITE("oki", cps1_oki_pin7_w) /* controls pin 7 of OKI chip */
213213   AM_RANGE(0xf008, 0xf008) AM_READ(soundlatch_r)   /* Sound command */
src/mess/drivers/vectrex.c
r9050r9051
1616#include "devices/cartslot.h"
1717#include "sound/ay8910.h"
1818#include "sound/dac.h"
19#include "machine/nvram.h"
1920
2021UINT8 *gce_vectorram;
2122size_t gce_vectorram_size;
r9050r9051
178179
179180static ADDRESS_MAP_START(raaspec_map , ADDRESS_SPACE_PROGRAM, 8)
180181   AM_RANGE(0x0000, 0x7fff) AM_ROM
181   AM_RANGE(0x8000, 0x87ff) AM_RAM AM_BASE_SIZE_GENERIC(nvram)
182   AM_RANGE(0x8000, 0x87ff) AM_RAM AM_SHARE("nvram")
182183   AM_RANGE(0xa000, 0xa000) AM_WRITE(raaspec_led_w)
183184   AM_RANGE(0xc800, 0xcbff) AM_RAM AM_MIRROR(0x0400) AM_BASE(&gce_vectorram) AM_SIZE(&gce_vectorram_size)
184185   AM_RANGE(0xd000, 0xd7ff) AM_READWRITE (vectrex_via_r, vectrex_via_w)
r9050r9051
207208static MACHINE_CONFIG_DERIVED( raaspec, vectrex )
208209   MDRV_CPU_MODIFY("maincpu")
209210   MDRV_CPU_PROGRAM_MAP(raaspec_map)
210   MDRV_NVRAM_HANDLER(generic_0fill)
211   MDRV_NVRAM_ADD_0FILL("nvram")
211212
212213   MDRV_VIDEO_START(raaspec)
213214
src/mess/drivers/x68k.c
r9050r9051
135135#include "machine/x68k_hdc.h"
136136#include "includes/x68k.h"
137137#include "devices/messram.h"
138#include "machine/nvram.h"
138139#include "x68000.lh"
139140
141
142class x68000_state : public driver_device
143{
144public:
145   x68000_state(running_machine &machine, const driver_device_config_base &config)
146      : driver_device(machine, config),
147        m_nvram(*this, "nvram") { }
148
149   required_shared_ptr<UINT16>   m_nvram;
150};
151
152
140153struct x68k_system x68k_sys;
141154
142155static UINT16* sram;   // SRAM
r9050r9051
15061519
15071520static WRITE16_HANDLER( x68k_sram_w )
15081521{
1522   x68000_state *state = space->machine->driver_data<x68000_state>();
1523
15091524   if(x68k_sys.sysport.sram_writeprotect == 0x31)
15101525   {
1511      COMBINE_DATA(space->machine->generic.nvram.u16+offset);
1526      COMBINE_DATA(state->m_nvram + offset);
15121527   }
15131528}
15141529
15151530static READ16_HANDLER( x68k_sram_r )
15161531{
1532   x68000_state *state = space->machine->driver_data<x68000_state>();
15171533   // HACKS!
15181534//  if(offset == 0x5a/2)  // 0x5a should be 0 if no SASI HDs are present.
15191535//      return 0x0000;
r9050r9051
15271543    if(offset == 0x70/2)
15281544        return 0x0700;
15291545#endif
1530   return space->machine->generic.nvram.u16[offset];
1546   return state->m_nvram[offset];
15311547}
15321548
15331549static READ32_HANDLER( x68k_sram32_r )
15341550{
1551   x68000_state *state = space->machine->driver_data<x68000_state>();
15351552   if(offset == 0x08/4)
15361553      return (messram_get_size(space->machine->device("messram")) & 0xffff0000);  // RAM size
15371554#if 0
r9050r9051
15421559    if(offset == 0x70/2)
15431560        return 0x0700;
15441561#endif
1545   return space->machine->generic.nvram.u32[offset];
1562   return state->m_nvram[offset];
15461563}
15471564
15481565static WRITE32_HANDLER( x68k_sram32_w )
15491566{
1567   x68000_state *state = space->machine->driver_data<x68000_state>();
15501568   if(x68k_sys.sysport.sram_writeprotect == 0x31)
15511569   {
1552      COMBINE_DATA(space->machine->generic.nvram.u32+offset);
1570      COMBINE_DATA(state->m_nvram + offset);
15531571   }
15541572}
15551573
r9050r9051
19371955   AM_RANGE(0xeb8000, 0xebffff) AM_READWRITE(x68k_spriteram_r, x68k_spriteram_w)
19381956   AM_RANGE(0xec0000, 0xecffff) AM_NOP  // User I/O
19391957//  AM_RANGE(0xed0000, 0xed3fff) AM_READWRITE(sram_r, sram_w) AM_BASE(&generic_nvram16) AM_SIZE(&generic_nvram_size)
1940   AM_RANGE(0xed0000, 0xed3fff) AM_RAMBANK("bank4") AM_BASE_SIZE_GENERIC(nvram)
1958   AM_RANGE(0xed0000, 0xed3fff) AM_RAMBANK("bank4") AM_SHARE("nvram")
19411959   AM_RANGE(0xed4000, 0xefffff) AM_NOP
19421960   AM_RANGE(0xf00000, 0xfbffff) AM_ROM
19431961//  AM_RANGE(0xfc0000, 0xfdffff) AM_READWRITE(x68k_rom0_r, x68k_rom0_w)
r9050r9051
19721990   AM_RANGE(0xeb8000, 0xebffff) AM_READWRITE16(x68k_spriteram_r, x68k_spriteram_w,0xffffffff)
19731991   AM_RANGE(0xec0000, 0xecffff) AM_NOP  // User I/O
19741992//  AM_RANGE(0xed0000, 0xed3fff) AM_READWRITE(sram_r, sram_w) AM_BASE(&generic_nvram16) AM_SIZE(&generic_nvram_size)
1975   AM_RANGE(0xed0000, 0xed3fff) AM_RAMBANK("bank4") AM_BASE_SIZE_GENERIC(nvram)
1993   AM_RANGE(0xed0000, 0xed3fff) AM_RAMBANK("bank4") AM_SHARE("nvram")
19761994   AM_RANGE(0xed4000, 0xefffff) AM_NOP
19771995   AM_RANGE(0xf00000, 0xfbffff) AM_ROM
19781996//  AM_RANGE(0xfc0000, 0xfdffff) AM_READWRITE16(x68k_rom0_r, x68k_rom0_w,0xffffffff)
r9050r9051
24822500static MACHINE_START( x68000 )
24832501{
24842502   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
2503   x68000_state *state = machine->driver_data<x68000_state>();
24852504   /*  Install RAM handlers  */
24862505   x68k_spriteram = (UINT16*)memory_region(machine, "user1");
24872506   memory_install_read16_handler(space,0x000000,0xbffffb,0xffffffff,0,(read16_space_func)x68k_emptyram_r);
r9050r9051
24962515   memory_set_bankptr(machine, "bank3",x68k_tvram);  // so that code in VRAM is executable - needed for Terra Cresta
24972516   memory_install_read16_handler(space,0xed0000,0xed3fff,0xffffffff,0,x68k_sram_r);
24982517   memory_install_write16_handler(space,0xed0000,0xed3fff,0xffffffff,0,x68k_sram_w);
2499   memory_set_bankptr(machine, "bank4",space->machine->generic.nvram.u16);  // so that code in SRAM is executable, there is an option for booting from SRAM
2518   memory_set_bankptr(machine, "bank4",state->m_nvram);  // so that code in SRAM is executable, there is an option for booting from SRAM
25002519
25012520   // start keyboard timer
25022521   timer_adjust_periodic(kb_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(5));  // every 5ms
r9050r9051
25122531static MACHINE_START( x68030 )
25132532{
25142533   address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
2534   x68000_state *state = machine->driver_data<x68000_state>();
25152535   /*  Install RAM handlers  */
25162536   x68k_spriteram = (UINT16*)memory_region(machine, "user1");
25172537   memory_install_read32_handler(space,0x000000,0xbffffb,0xffffffff,0,(read32_space_func)x68k_rom0_r);
r9050r9051
25292549   memory_set_bankptr(machine, "bank3",x68k_tvram);  // so that code in VRAM is executable - needed for Terra Cresta
25302550   memory_install_read32_handler(space,0xed0000,0xed3fff,0xffffffff,0,x68k_sram32_r);
25312551   memory_install_write32_handler(space,0xed0000,0xed3fff,0xffffffff,0,x68k_sram32_w);
2532   memory_set_bankptr(machine, "bank4",machine->generic.nvram.u32);  // so that code in SRAM is executable, there is an option for booting from SRAM
2552   memory_set_bankptr(machine, "bank4",state->m_nvram);  // so that code in SRAM is executable, there is an option for booting from SRAM
25332553
25342554   // start keyboard timer
25352555   timer_adjust_periodic(kb_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(5));  // every 5ms
r9050r9051
25962616   x68k_sys.sysport.cputype = 0xdc; // 68030, 25MHz
25972617}
25982618
2599static MACHINE_CONFIG_START( x68000, driver_device )
2619static MACHINE_CONFIG_START( x68000, x68000_state )
26002620   /* basic machine hardware */
26012621   MDRV_CPU_ADD("maincpu", M68000, 10000000)  /* 10 MHz */
26022622   MDRV_CPU_PROGRAM_MAP(x68k_map)
r9050r9051
26462666    MDRV_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 0.50)
26472667    MDRV_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.50)
26482668
2649   MDRV_NVRAM_HANDLER( generic_0fill )
2669   MDRV_NVRAM_ADD_0FILL("nvram")
26502670
26512671   MDRV_UPD72065_ADD("upd72065", fdc_interface)
26522672   MDRV_FLOPPY_4_DRIVES_ADD(x68k_floppy_config)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team