Previous 15994 Revisions Next

r8911 Thursday 26th August, 2010 at 20:01:36 UTC by Miodrag Milanović
- Sync with MAME
- Also contains MAMEUI part fix to enable compile with latest MAME
[src/emu]deprecat.h devcpu.c devcpu.h devintrf.c devintrf.h devlegcy.c devlegcy.h diexec.c diexec.h dimemory.c dimemory.h disound.c disound.h driver.h emu.h image.c info.c mconfig.c mconfig.h memory.c memory.h sound.c sound.h timer.c timer.h video.c video.h
[src/emu/machine]6532riot.c 6821pia.h 6840ptm.c 6840ptm.h 6850acia.c 6850acia.h 74123.c 7474.c 7474.h 8237dma.c 8237dma.h 8255ppi.c 8255ppi.h devhelpr.h* eeprom.c eeprom.h i2cmem.c i2cmem.h ldcore.h timekpr.c timekpr.h
[src/emu/sound]okim6295.c okim6295.h
[src/mess/devices]coco_232.c coco_fdc.c
[src/osd/winui]treeview.c

src/osd/winui/treeview.c
r8910r8911
925925   LPTREEFOLDER device_folders[512];
926926   LPTREEFOLDER folder;
927927   machine_config *config = NULL;
928   const machine_config_token *last_tokens = NULL;
929   const device_config_execute_interface *device = NULL;
928   machine_config_constructor last_tokens = NULL;
929   const device_config_execute_interface *device;
930930   int nFolder = numFolders;
931931
932932   for (i = 0; drivers[i] != NULL; i++)
r8910r8911
997997   LPTREEFOLDER device_folders[512];
998998   LPTREEFOLDER folder;
999999   machine_config *config = NULL;
1000   const machine_config_token *last_tokens = NULL;
1001   const device_config_sound_interface *device = NULL;
1000   machine_config_constructor last_tokens = NULL;
1001   const device_config_sound_interface *device;
10021002   int nFolder = numFolders;
10031003
10041004   for (i = 0; drivers[i] != NULL; i++)
src/emu/video.c
r8910r8911
17211721
17221722
17231723//-------------------------------------------------
1724//  device_config_complete - perform any
1725//  operations now that the configuration is
1726//  complete
1724//  static_set_format - configuration helper
1725//  to set the bitmap format
17271726//-------------------------------------------------
17281727
1729void screen_device_config::device_config_complete()
1728void screen_device_config::static_set_format(device_config *device, bitmap_format format)
17301729{
1731   // move inline data into its final home
1732   m_type = static_cast<screen_type_enum>(m_inline_data[INLINE_TYPE]);
1733   m_width = static_cast<INT16>(m_inline_data[INLINE_WIDTH]);
1734   m_height = static_cast<INT16>(m_inline_data[INLINE_HEIGHT]);
1735   m_visarea.min_x = static_cast<INT16>(m_inline_data[INLINE_VIS_MINX]);
1736   m_visarea.min_y = static_cast<INT16>(m_inline_data[INLINE_VIS_MINY]);
1737   m_visarea.max_x = static_cast<INT16>(m_inline_data[INLINE_VIS_MAXX]);
1738   m_visarea.max_y = static_cast<INT16>(m_inline_data[INLINE_VIS_MAXY]);
1739   m_oldstyle_vblank_supplied = (m_inline_data[INLINE_OLDVBLANK] != 0);
1740   m_refresh = m_inline_data[INLINE_REFRESH];
1741   m_vblank = m_inline_data[INLINE_VBLANK];
1742   m_format = static_cast<bitmap_format>(m_inline_data[INLINE_FORMAT]);
1743   m_xoffset = static_cast<double>(static_cast<INT32>(m_inline_data[INLINE_XOFFSET])) / (double)(1 << 24);
1744   m_yoffset = static_cast<double>(static_cast<INT32>(m_inline_data[INLINE_YOFFSET])) / (double)(1 << 24);
1745   m_xscale = (m_inline_data[INLINE_XSCALE] == 0) ? 1.0 : (static_cast<double>(static_cast<INT32>(m_inline_data[INLINE_XSCALE])) / (double)(1 << 24));
1746   m_yscale = (m_inline_data[INLINE_YSCALE] == 0) ? 1.0 : (static_cast<double>(static_cast<INT32>(m_inline_data[INLINE_YSCALE])) / (double)(1 << 24));
1730   screen_device_config *screen = downcast<screen_device_config *>(device);
1731   screen->m_format = format;
17471732}
17481733
17491734
17501735//-------------------------------------------------
1736//  static_set_type - configuration helper
1737//  to set the screen type
1738//-------------------------------------------------
1739
1740void screen_device_config::static_set_type(device_config *device, screen_type_enum type)
1741{
1742   screen_device_config *screen = downcast<screen_device_config *>(device);
1743   screen->m_type = type;
1744}
1745
1746
1747//-------------------------------------------------
1748//  static_set_raw - configuration helper
1749//  to set the raw screen parameters
1750//-------------------------------------------------
1751
1752void screen_device_config::static_set_raw(device_config *device, UINT32 pixclock, UINT16 htotal, UINT16 hbend, UINT16 hbstart, UINT16 vtotal, UINT16 vbend, UINT16 vbstart)
1753{
1754   screen_device_config *screen = downcast<screen_device_config *>(device);
1755   screen->m_refresh = HZ_TO_ATTOSECONDS(pixclock) * htotal * vtotal;
1756   screen->m_vblank = screen->m_refresh / vtotal * (vtotal - (vbstart - vbend));
1757   screen->m_width = htotal;
1758   screen->m_height = vtotal;
1759   screen->m_visarea.min_x = hbend;
1760   screen->m_visarea.max_x = hbstart - 1;
1761   screen->m_visarea.min_y = vbend;
1762   screen->m_visarea.max_y = vbstart - 1;
1763}
1764
1765
1766//-------------------------------------------------
1767//  static_set_refresh - configuration helper
1768//  to set the refresh rate
1769//-------------------------------------------------
1770
1771void screen_device_config::static_set_refresh(device_config *device, attoseconds_t rate)
1772{
1773   screen_device_config *screen = downcast<screen_device_config *>(device);
1774   screen->m_refresh = rate;
1775}
1776
1777
1778//-------------------------------------------------
1779//  static_set_vblank_time - configuration helper
1780//  to set the VBLANK duration
1781//-------------------------------------------------
1782
1783void screen_device_config::static_set_vblank_time(device_config *device, attoseconds_t time)
1784{
1785   screen_device_config *screen = downcast<screen_device_config *>(device);
1786   screen->m_vblank = time;
1787   screen->m_oldstyle_vblank_supplied = true;
1788}
1789
1790
1791//-------------------------------------------------
1792//  static_set_size - configuration helper to set
1793//  the width/height of the screen
1794//-------------------------------------------------
1795
1796void screen_device_config::static_set_size(device_config *device, UINT16 width, UINT16 height)
1797{
1798   screen_device_config *screen = downcast<screen_device_config *>(device);
1799   screen->m_width = width;
1800   screen->m_height = height;
1801}
1802
1803
1804//-------------------------------------------------
1805//  static_set_visarea - configuration helper to
1806//  set the visible area of the screen
1807//-------------------------------------------------
1808
1809void screen_device_config::static_set_visarea(device_config *device, INT16 minx, INT16 maxx, INT16 miny, INT16 maxy)
1810{
1811   screen_device_config *screen = downcast<screen_device_config *>(device);
1812   screen->m_visarea.min_x = minx;
1813   screen->m_visarea.max_x = maxx;
1814   screen->m_visarea.min_y = miny;
1815   screen->m_visarea.max_y = maxy;
1816}
1817
1818
1819//-------------------------------------------------
1820//  static_set_default_position - configuration
1821//  helper to set the default position and scale
1822//  factors for the screen
1823//-------------------------------------------------
1824
1825void screen_device_config::static_set_default_position(device_config *device, double xscale, double xoffs, double yscale, double yoffs)
1826{
1827   screen_device_config *screen = downcast<screen_device_config *>(device);
1828   screen->m_xscale = xscale;
1829   screen->m_xoffset = xoffs;
1830   screen->m_yscale = yscale;
1831   screen->m_yoffset = yoffs;
1832}
1833
1834
1835//-------------------------------------------------
17511836//  device_validity_check - verify device
17521837//  configuration
17531838//-------------------------------------------------
src/emu/video.h
r8910r8911
108108   float xscale() const { return m_xscale; }
109109   float yscale() const { return m_yscale; }
110110
111   // indexes to inline data
112   enum
113   {
114      INLINE_TYPE,
115      INLINE_FORMAT,
116      INLINE_REFRESH,
117      INLINE_VBLANK,
118      INLINE_WIDTH,
119      INLINE_HEIGHT,
120      INLINE_VIS_MINX,
121      INLINE_VIS_MAXX,
122      INLINE_VIS_MINY,
123      INLINE_VIS_MAXY,
124      INLINE_XOFFSET,
125      INLINE_XSCALE,
126      INLINE_YOFFSET,
127      INLINE_YSCALE,
128      INLINE_OLDVBLANK
129   };
111   // inline configuration helpers
112   static void static_set_format(device_config *device, bitmap_format format);
113   static void static_set_type(device_config *device, screen_type_enum type);
114   static void static_set_raw(device_config *device, UINT32 pixclock, UINT16 htotal, UINT16 hbend, UINT16 hbstart, UINT16 vtotal, UINT16 vbend, UINT16 vbstart);
115   static void static_set_refresh(device_config *device, attoseconds_t rate);
116   static void static_set_vblank_time(device_config *device, attoseconds_t time);
117   static void static_set_size(device_config *device, UINT16 width, UINT16 height);
118   static void static_set_visarea(device_config *device, INT16 minx, INT16 maxx, INT16 miny, INT16 maxy);
119   static void static_set_default_position(device_config *device, double xscale, double xoffs, double yscale, double yoffs);
130120
131121private:
132122   // device_config overrides
133   virtual void device_config_complete();
134123   virtual bool device_validity_check(const game_driver &driver) const;
135124
136   // configuration data
125   // inline configuration data
137126   screen_type_enum   m_type;                  // type of screen
138127   int               m_width, m_height;         // default total width/height (HTOTAL, VTOTAL)
139128   rectangle         m_visarea;               // default visible area (HBLANK end/start, VBLANK end/start)
r8910r8911
279268
280269#define MDRV_SCREEN_ADD(_tag, _type) \
281270   MDRV_DEVICE_ADD(_tag, SCREEN, 0) \
282   MDRV_SCREEN_TYPE(_type)
271   MDRV_SCREEN_TYPE(_type) \
283272
284273#define MDRV_SCREEN_MODIFY(_tag) \
285274   MDRV_DEVICE_MODIFY(_tag)
286275
287276#define MDRV_SCREEN_FORMAT(_format) \
288   MDRV_DEVICE_INLINE_DATA16(screen_device_config::INLINE_FORMAT, _format)
277   screen_device_config::static_set_format(device, _format); \
289278
290279#define MDRV_SCREEN_TYPE(_type) \
291   MDRV_DEVICE_INLINE_DATA16(screen_device_config::INLINE_TYPE, SCREEN_TYPE_##_type)
280   screen_device_config::static_set_type(device, SCREEN_TYPE_##_type); \
292281
293282#define MDRV_SCREEN_RAW_PARAMS(_pixclock, _htotal, _hbend, _hbstart, _vtotal, _vbend, _vbstart) \
294   MDRV_DEVICE_INLINE_DATA64(screen_device_config::INLINE_REFRESH, HZ_TO_ATTOSECONDS(_pixclock) * (_htotal) * (_vtotal)) \
295   MDRV_DEVICE_INLINE_DATA64(screen_device_config::INLINE_VBLANK, ((HZ_TO_ATTOSECONDS(_pixclock) * (_htotal) * (_vtotal)) / (_vtotal)) * ((_vtotal) - ((_vbstart) - (_vbend)))) \
296   MDRV_DEVICE_INLINE_DATA16(screen_device_config::INLINE_WIDTH, _htotal)   \
297   MDRV_DEVICE_INLINE_DATA16(screen_device_config::INLINE_HEIGHT, _vtotal)   \
298   MDRV_DEVICE_INLINE_DATA16(screen_device_config::INLINE_VIS_MINX, _hbend) \
299   MDRV_DEVICE_INLINE_DATA16(screen_device_config::INLINE_VIS_MAXX, (_hbstart) - 1) \
300   MDRV_DEVICE_INLINE_DATA16(screen_device_config::INLINE_VIS_MINY, _vbend) \
301   MDRV_DEVICE_INLINE_DATA16(screen_device_config::INLINE_VIS_MAXY, (_vbstart) - 1)
283   screen_device_config::static_set_raw(device, _pixclock, _htotal, _hbend, _hbstart, _vtotal, _vbend, _vbstart);
302284
303285#define MDRV_SCREEN_REFRESH_RATE(_rate) \
304   MDRV_DEVICE_INLINE_DATA64(screen_device_config::INLINE_REFRESH, HZ_TO_ATTOSECONDS(_rate))
286   screen_device_config::static_set_refresh(device, HZ_TO_ATTOSECONDS(_rate)); \
305287
306288#define MDRV_SCREEN_VBLANK_TIME(_time) \
307   MDRV_DEVICE_INLINE_DATA64(screen_device_config::INLINE_VBLANK, _time) \
308   MDRV_DEVICE_INLINE_DATA16(screen_device_config::INLINE_OLDVBLANK, true)
289   screen_device_config::static_set_vblank_time(device, _time); \
309290
310291#define MDRV_SCREEN_SIZE(_width, _height) \
311   MDRV_DEVICE_INLINE_DATA16(screen_device_config::INLINE_WIDTH, _width) \
312   MDRV_DEVICE_INLINE_DATA16(screen_device_config::INLINE_HEIGHT, _height)
292   screen_device_config::static_set_size(device, _width, _height); \
313293
314294#define MDRV_SCREEN_VISIBLE_AREA(_minx, _maxx, _miny, _maxy) \
315   MDRV_DEVICE_INLINE_DATA16(screen_device_config::INLINE_VIS_MINX, _minx) \
316   MDRV_DEVICE_INLINE_DATA16(screen_device_config::INLINE_VIS_MAXX, _maxx) \
317   MDRV_DEVICE_INLINE_DATA16(screen_device_config::INLINE_VIS_MINY, _miny) \
318   MDRV_DEVICE_INLINE_DATA16(screen_device_config::INLINE_VIS_MAXY, _maxy)
295   screen_device_config::static_set_visarea(device, _minx, _maxx, _miny, _maxy); \
319296
320297#define MDRV_SCREEN_DEFAULT_POSITION(_xscale, _xoffs, _yscale, _yoffs)   \
321   MDRV_DEVICE_INLINE_DATA32(screen_device_config::INLINE_XOFFSET, (INT32)((_xoffs) * (double)(1 << 24))) \
322   MDRV_DEVICE_INLINE_DATA32(screen_device_config::INLINE_XSCALE, (INT32)((_xscale) * (double)(1 << 24))) \
323   MDRV_DEVICE_INLINE_DATA32(screen_device_config::INLINE_YOFFSET, (INT32)((_yoffs) * (double)(1 << 24))) \
324   MDRV_DEVICE_INLINE_DATA32(screen_device_config::INLINE_YSCALE, (INT32)((_yscale) * (double)(1 << 24)))
298   screen_device_config::static_set_default_position(device, _xscale, _xoffs, _yscale, _yoffs); \
325299
326300
327301
src/emu/devintrf.c
r8910r8911
273273
274274
275275//-------------------------------------------------
276//  interface_process_token - default token
277//  processing for a given interface
278//-------------------------------------------------
279
280bool device_config_interface::interface_process_token(UINT32 entrytype, const machine_config_token *&tokens)
281{
282   return false;
283}
284
285
286//-------------------------------------------------
287276//  interface_validity_check - default validation
288277//  for a device after the configuration has been
289278//  constructed
r8910r8911
317306     m_tag(tag),
318307     m_config_complete(false)
319308{
320   memset(m_inline_data, 0, sizeof(m_inline_data));
321
322309   // derive the clock from our owner if requested
323310   if ((m_clock & 0xff000000) == 0xff000000)
324311   {
r8910r8911
354341
355342
356343//-------------------------------------------------
357//  process_token - process tokens
358//-------------------------------------------------
359
360void device_config::process_token(UINT32 entrytype, const machine_config_token *&tokens)
361{
362   int size, offset, bits, index;
363   UINT32 data32;
364   UINT64 data64;
365   bool processed = false;
366
367   // first process stuff we know about
368   switch (entrytype)
369   {
370      // specify device clock
371      case MCONFIG_TOKEN_DEVICE_CLOCK:
372         TOKEN_UNGET_UINT32(tokens);
373         TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, m_clock, 32);
374         processed = true;
375         break;
376
377      // specify pointer to static device configuration
378      case MCONFIG_TOKEN_DEVICE_CONFIG:
379         m_static_config = TOKEN_GET_PTR(tokens, voidptr);
380         processed = true;
381         break;
382
383      // provide inline device data packed into a 16-bit space
384      case MCONFIG_TOKEN_DEVICE_INLINE_DATA16:
385         TOKEN_UNGET_UINT32(tokens);
386         TOKEN_GET_UINT32_UNPACK3(tokens, entrytype, 8, index, 8, data32, 16);
387         assert(index >= 0 && index < ARRAY_LENGTH(m_inline_data));
388         m_inline_data[index] = data32;
389         processed = true;
390         break;
391
392      // provide inline device data packed into a 32-bit space
393      case MCONFIG_TOKEN_DEVICE_INLINE_DATA32:
394         TOKEN_UNGET_UINT32(tokens);
395         TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, index, 8);
396         assert(index >= 0 && index < ARRAY_LENGTH(m_inline_data));
397         m_inline_data[index] = TOKEN_GET_UINT32(tokens);
398         processed = true;
399         break;
400
401      // provide inline device data packed into a 64-bit space
402      case MCONFIG_TOKEN_DEVICE_INLINE_DATA64:
403         TOKEN_UNGET_UINT32(tokens);
404         TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, index, 8);
405         assert(index >= 0 && index < ARRAY_LENGTH(m_inline_data));
406         TOKEN_EXTRACT_UINT64(tokens, m_inline_data[index]);
407         processed = true;
408         break;
409
410      // provide inline device data packed into a 32-bit word
411      case MCONFIG_TOKEN_DEVICE_CONFIG_DATA32:
412         TOKEN_UNGET_UINT32(tokens);
413         TOKEN_GET_UINT32_UNPACK3(tokens, entrytype, 8, size, 4, offset, 12);
414         data32 = TOKEN_GET_UINT32(tokens);
415         switch (size)
416         {
417            case 1: *(UINT8 *) ((UINT8 *)downcast<legacy_device_config_base *>(this)->inline_config() + offset) = data32; break;
418            case 2: *(UINT16 *)((UINT8 *)downcast<legacy_device_config_base *>(this)->inline_config() + offset) = data32; break;
419            case 4: *(UINT32 *)((UINT8 *)downcast<legacy_device_config_base *>(this)->inline_config() + offset) = data32; break;
420         }
421         processed = true;
422         break;
423
424      // provide inline device data packed into a 64-bit word
425      case MCONFIG_TOKEN_DEVICE_CONFIG_DATA64:
426         TOKEN_UNGET_UINT32(tokens);
427         TOKEN_GET_UINT32_UNPACK3(tokens, entrytype, 8, size, 4, offset, 12);
428         TOKEN_EXTRACT_UINT64(tokens, data64);
429         switch (size)
430         {
431            case 1: *(UINT8 *) ((UINT8 *)downcast<legacy_device_config_base *>(this)->inline_config() + offset) = data64; break;
432            case 2: *(UINT16 *)((UINT8 *)downcast<legacy_device_config_base *>(this)->inline_config() + offset) = data64; break;
433            case 4: *(UINT32 *)((UINT8 *)downcast<legacy_device_config_base *>(this)->inline_config() + offset) = data64; break;
434            case 8: *(UINT64 *)((UINT8 *)downcast<legacy_device_config_base *>(this)->inline_config() + offset) = data64; break;
435         }
436         processed = true;
437         break;
438
439      // provide inline floating-point device data packed into a fixed-point 32-bit word
440      case MCONFIG_TOKEN_DEVICE_CONFIG_DATAFP32:
441         TOKEN_UNGET_UINT32(tokens);
442         TOKEN_GET_UINT32_UNPACK4(tokens, entrytype, 8, size, 4, bits, 6, offset, 12);
443         data32 = TOKEN_GET_UINT32(tokens);
444         switch (size)
445         {
446            case 4: *(float *)((UINT8 *)downcast<legacy_device_config_base *>(this)->inline_config() + offset) = (float)(INT32)data32 / (float)(1 << bits); break;
447            case 8: *(double *)((UINT8 *)downcast<legacy_device_config_base *>(this)->inline_config() + offset) = (double)(INT32)data32 / (double)(1 << bits); break;
448         }
449         processed = true;
450         break;
451   }
452
453   // anything else might be handled by one of our interfaces
454   for (device_config_interface *intf = m_interface_list; intf != NULL; intf = intf->interface_next())
455      if (intf->interface_process_token(entrytype, tokens))
456      {
457         assert(!processed);
458         processed = true;
459      }
460
461   // or it might be processed by the device itself
462   if (device_process_token(entrytype, tokens))
463   {
464      assert(!processed);
465      processed = true;
466   }
467
468   // regardless, *somebody* must handle it
469   if (!processed)
470      throw emu_fatalerror("Unhandled token %d for device '%s'", entrytype, tag());
471}
472
473
474//-------------------------------------------------
475344//  validity_check - validate a device after the
476345//  configuration has been constructed
477346//-------------------------------------------------
r8910r8911
506375
507376
508377//-------------------------------------------------
509//  device_process_token - process basic device
510//  tokens
511//-------------------------------------------------
512
513bool device_config::device_process_token(UINT32 entrytype, const machine_config_token *&tokens)
514{
515   // handle nothing by default
516   return false;
517}
518
519
520//-------------------------------------------------
521378//  device_validity_check - validate a device after
522379//  the configuration has been constructed
523380//-------------------------------------------------
r8910r8911
541398
542399
543400//-------------------------------------------------
544//  machine_config_tokens - return a pointer to
545//  a set of machine configuration tokens
546//  describing sub-devices for this device
401//  machine_config - return a pointer to a machine
402//  config constructor describing sub-devices for
403//  this device
547404//-------------------------------------------------
548405
549const machine_config_token *device_config::machine_config_tokens() const
406machine_config_constructor device_config::machine_config_additions() const
550407{
551408   return NULL;
552409}
src/emu/devintrf.h
r8910r8911
6666
6767// configure devices
6868#define MDRV_DEVICE_CONFIG(_config) \
69   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DEVICE_CONFIG, 8), \
70   TOKEN_PTR(voidptr, &(_config)),
69   device_config::static_set_static_config(device, &(_config)); \
7170
7271#define MDRV_DEVICE_CONFIG_CLEAR() \
73   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DEVICE_CONFIG, 8), \
74   TOKEN_PTR(voidptr, NULL),
72   device_config::static_set_static_config(device, NULL); \
7573
7674#define MDRV_DEVICE_CLOCK(_clock) \
77   TOKEN_UINT64_PACK2(MCONFIG_TOKEN_DEVICE_CLOCK, 8, _clock, 32),
75   device_config::static_set_clock(device, _clock); \
7876
79#define MDRV_DEVICE_INLINE_DATA16(_index, _data) \
80   TOKEN_UINT32_PACK3(MCONFIG_TOKEN_DEVICE_INLINE_DATA16, 8, _index, 8, (UINT16)(_data), 16), \
8177
82#define MDRV_DEVICE_INLINE_DATA32(_index, _data) \
83   TOKEN_UINT32_PACK2(MCONFIG_TOKEN_DEVICE_INLINE_DATA32, 8, _index, 8), \
84   TOKEN_UINT32((UINT32)(_data)),
8578
86#define MDRV_DEVICE_INLINE_DATA64(_index, _data) \
87   TOKEN_UINT32_PACK2(MCONFIG_TOKEN_DEVICE_INLINE_DATA64, 8, _index, 8), \
88   TOKEN_UINT64((UINT64)(_data)),
89
90#ifdef PTR64
91#define MDRV_DEVICE_INLINE_DATAPTR(_index, _data) MDRV_DEVICE_INLINE_DATA64(_index, (FPTR)(_data))
92#else
93#define MDRV_DEVICE_INLINE_DATAPTR(_index, _data) MDRV_DEVICE_INLINE_DATA32(_index, (FPTR)(_data))
94#endif
95
96
97
9879//**************************************************************************
9980//  TYPE DEFINITIONS
10081//**************************************************************************
r8910r8911
11091class device_memory_interface;
11192class device_state_interface;
11293struct rom_entry;
113union machine_config_token;
11494class machine_config;
11595
11696
r8910r8911
265245   const void *static_config() const { return m_static_config; }
266246
267247   // methods that wrap both interface-level and device-level behavior
268   void process_token(UINT32 entrytype, const machine_config_token *&tokens);
269248   void config_complete();
270249   bool validity_check(const game_driver &driver) const;
250   
251   // configuration helpers
252   static void static_set_clock(device_config *device, UINT32 clock) { device->m_clock = clock; }
253   static void static_set_static_config(device_config *device, const void *config) { device->m_static_config = config; }
271254
272255   //------------------- begin derived class overrides
273256
r8910r8911
276259
277260   // optional operation overrides
278261protected:
279   virtual bool device_process_token(UINT32 entrytype, const machine_config_token *&tokens);
280262   virtual void device_config_complete();
281263   virtual bool device_validity_check(const game_driver &driver) const;
282264
283265public:
284266   // optional information overrides
285267   virtual const rom_entry *rom_region() const;
286   virtual const machine_config_token *machine_config_tokens() const;
268   virtual machine_config_constructor machine_config_additions() const;
287269
288270   //------------------- end derived class overrides
289271
r8910r8911
298280
299281   const machine_config &   m_machine_config;      // reference to the machine's configuration
300282   const void *         m_static_config;      // static device configuration
301   UINT64               m_inline_data[16];      // array of inline configuration values
302283
303284   astring               m_name;               // name of the device
304285
r8910r8911
333314
334315   // optional operation overrides
335316   virtual void interface_config_complete();
336   virtual bool interface_process_token(UINT32 entrytype, const machine_config_token *&tokens);
337317   virtual bool interface_validity_check(const game_driver &driver) const;
338318
339319protected:
r8910r8911
416396
417397   // machine and ROM configuration getters ... pass through to underlying config
418398   const rom_entry *rom_region() const { return m_baseconfig.rom_region(); }
419   const machine_config_token *machine_config_tokens() const { return m_baseconfig.machine_config_tokens(); }
399   machine_config_constructor machine_config_additions() const { return m_baseconfig.machine_config_additions(); }
420400
421401public:
422402   running_machine *      machine;
src/emu/emu.h
r8910r8911
6969#include "memory.h"
7070#include "addrmap.h"
7171
72// define machine_config_constructor here due to circular dependency
73// between devices and the machine config
74class machine_config;
75class device_config;
76typedef void (*machine_config_constructor)(machine_config &config, device_config *owner);
77
7278// devices and callbacks
7379#include "devintrf.h"
7480#include "devcb.h"
src/emu/sound/okim6295.c
r8910r8911
118118
119119
120120//-------------------------------------------------
121//  device_config_complete - perform any
122//  operations now that the configuration is
123//  complete
121//  static_set_pin7 - configuration helper to set
122//  the pin 7 state
124123//-------------------------------------------------
125124
126void okim6295_device_config::device_config_complete()
125void okim6295_device_config::static_set_pin7(device_config *device, int pin7)
127126{
128   // copy the pin7 state from inline data
129   m_pin7 = m_inline_data[INLINE_PIN7];
127   okim6295_device_config *okim6295 = downcast<okim6295_device_config *>(device);
128   okim6295->m_pin7 = pin7;
130129}
131130
132131
src/emu/sound/okim6295.h
r8910r8911
4040   MDRV_OKIM6295_PIN7(_pin7)
4141
4242#define MDRV_OKIM6295_PIN7(_pin7) \
43   MDRV_DEVICE_INLINE_DATA16(okim6295_device_config::INLINE_PIN7, _pin7)
43   okim6295_device_config::static_set_pin7(device, _pin7); \
4444
4545
4646
r8910r8911
8989   static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
9090   virtual device_t *alloc_device(running_machine &machine) const;
9191
92   // inline configuration indexes
93   enum
94   {
95      INLINE_PIN7
96   };
92   // inline configuration helpers
93   static void static_set_pin7(device_config *device, int pin7);
9794
9895protected:
9996   // device_config overrides
100   virtual void device_config_complete();
10197   virtual const address_space_config *memory_space_config(int spacenum = 0) const;
10298
10399   // internal state
104100   const address_space_config  m_space_config;
101
102   // inline data
105103   UINT8                  m_pin7;
106104};
107105
src/emu/devlegcy.c
r8910r8911
128128
129129
130130//-------------------------------------------------
131//  static_set_inline32 - configuration helper to
132//  set a 32-bit value in the inline configuration
133//-------------------------------------------------
134
135void legacy_device_config_base::static_set_inline32(device_config *device, UINT32 offset, UINT32 size, UINT32 value)
136{
137   legacy_device_config_base *legacy = downcast<legacy_device_config_base *>(device);
138   void *dest = reinterpret_cast<UINT8 *>(legacy->m_inline_config) + offset;
139   if (size == 1)
140      *reinterpret_cast<UINT8 *>(dest) = value;
141   else if (size == 2)
142      *reinterpret_cast<UINT16 *>(dest) = value;
143   else if (size == 4)
144      *reinterpret_cast<UINT32 *>(dest) = value;
145   else
146      throw emu_fatalerror("Unexpected size %d in legacy_device_config_base::static_set_inline32", size);
147}
148
149
150//-------------------------------------------------
151//  static_set_inline64 - configuration helper to
152//  set a 64-bit value in the inline configuration
153//-------------------------------------------------
154
155void legacy_device_config_base::static_set_inline64(device_config *device, UINT32 offset, UINT32 size, UINT64 value)
156{
157   legacy_device_config_base *legacy = downcast<legacy_device_config_base *>(device);
158   void *dest = reinterpret_cast<UINT8 *>(legacy->m_inline_config) + offset;
159   if (size == 1)
160      *reinterpret_cast<UINT8 *>(dest) = value;
161   else if (size == 2)
162      *reinterpret_cast<UINT16 *>(dest) = value;
163   else if (size == 4)
164      *reinterpret_cast<UINT32 *>(dest) = value;
165   else if (size == 8)
166      *reinterpret_cast<UINT64 *>(dest) = value;
167   else
168      throw emu_fatalerror("Unexpected size %d in legacy_device_config_base::static_set_inline64", size);
169}
170
171
172//-------------------------------------------------
173//  static_set_inline_float - configuration helper
174//  to set a floating-point value in the inline
175//  configuration
176//-------------------------------------------------
177
178void legacy_device_config_base::static_set_inline_float(device_config *device, UINT32 offset, UINT32 size, float value)
179{
180   legacy_device_config_base *legacy = downcast<legacy_device_config_base *>(device);
181   void *dest = reinterpret_cast<UINT8 *>(legacy->m_inline_config) + offset;
182   if (size == 4)
183      *reinterpret_cast<float *>(dest) = value;
184   else
185      throw emu_fatalerror("Unexpected size %d in legacy_device_config_base::static_set_inline_float", size);
186}
187
188
189//-------------------------------------------------
131190//  device_validity_check - perform validity
132191//  checks on a device configuration
133192//-------------------------------------------------
src/emu/devlegcy.h
r8910r8911
275275//  DEVICE_CONFIGURATION_MACROS
276276//**************************************************************************
277277
278#define structsizeof(_struct, _field) sizeof(((_struct *)NULL)->_field)
279
278280// inline device configurations that require 32 bits of storage in the token
279281#define MDRV_DEVICE_CONFIG_DATA32_EXPLICIT(_size, _offset, _val) \
280   TOKEN_UINT32_PACK3(MCONFIG_TOKEN_DEVICE_CONFIG_DATA32, 8, _size, 4, _offset, 12), \
281   TOKEN_UINT32((UINT32)(_val)),
282   legacy_device_config_base::static_set_inline32(device, _offset, _size, (UINT32)(_val));
282283
283284#define MDRV_DEVICE_CONFIG_DATA32(_struct, _field, _val) \
284285   MDRV_DEVICE_CONFIG_DATA32_EXPLICIT(structsizeof(_struct, _field), offsetof(_struct, _field), _val)
r8910r8911
301302
302303// inline device configurations that require 32 bits of fixed-point storage in the token
303304#define MDRV_DEVICE_CONFIG_DATAFP32_EXPLICIT(_size, _offset, _val, _fixbits) \
304   TOKEN_UINT32_PACK4(MCONFIG_TOKEN_DEVICE_CONFIG_DATAFP32, 8, _size, 4, _fixbits, 6, _offset, 12), \
305   TOKEN_UINT32((INT32)((float)(_val) * (float)(1 << (_fixbits)))),
305   legacy_device_config_base::static_set_inline_float(device, _offset, _size, (float)(_val));
306306
307307#define MDRV_DEVICE_CONFIG_DATAFP32(_struct, _field, _val, _fixbits) \
308308   MDRV_DEVICE_CONFIG_DATAFP32_EXPLICIT(structsizeof(_struct, _field), offsetof(_struct, _field), _val, _fixbits)
r8910r8911
325325
326326// inline device configurations that require 64 bits of storage in the token
327327#define MDRV_DEVICE_CONFIG_DATA64_EXPLICIT(_size, _offset, _val) \
328   TOKEN_UINT32_PACK3(MCONFIG_TOKEN_DEVICE_CONFIG_DATA64, 8, _size, 4, _offset, 12), \
329   TOKEN_UINT64((UINT64)(_val)),
328   legacy_device_config_base::static_set_inline64(device, _offset, _size, (UINT64)(_val));
330329
331330#define MDRV_DEVICE_CONFIG_DATA64(_struct, _field, _val) \
332331   MDRV_DEVICE_CONFIG_DATA64_EXPLICIT(structsizeof(_struct, _field), offsetof(_struct, _field), _val)
r8910r8911
373372//**************************************************************************
374373
375374union deviceinfo;
375class machine_config;
376class device_config;
376377
377378char *get_temp_string_buffer(void);
378379resource_pool &machine_get_pool(running_machine &machine);
r8910r8911
402403   device_execute_func    execute;               // DEVINFO_FCT_EXECUTE
403404   device_nvram_func      nvram;                  // DEVINFO_FCT_NVRAM
404405   const rom_entry *      romregion;               // DEVINFO_PTR_ROM_REGION
405   const machine_config_token *machine_config;         // DEVINFO_PTR_MACHINE_CONFIG
406   machine_config_constructor machine_config;         // DEVINFO_PTR_MACHINE_CONFIG
406407   address_map_constructor   internal_map8;            // DEVINFO_PTR_INTERNAL_MEMORY_MAP
407408   address_map_constructor   internal_map16;            // DEVINFO_PTR_INTERNAL_MEMORY_MAP
408409   address_map_constructor   internal_map32;            // DEVINFO_PTR_INTERNAL_MEMORY_MAP
r8910r8911
433434   // basic information getters
434435public:
435436   virtual const rom_entry *rom_region() const { return reinterpret_cast<const rom_entry *>(get_legacy_config_ptr(DEVINFO_PTR_ROM_REGION)); }
436   virtual const machine_config_token *machine_config_tokens() const { return reinterpret_cast<const machine_config_token *>(get_legacy_config_ptr(DEVINFO_PTR_MACHINE_CONFIG)); }
437   virtual machine_config_constructor machine_config_additions() const { return reinterpret_cast<machine_config_constructor>(get_legacy_config_ptr(DEVINFO_PTR_MACHINE_CONFIG)); }
437438
438439   // access to legacy inline configuartion
439440   void *inline_config() const { return m_inline_config; }
440441
442   // inline configuration helpers
443   static void static_set_inline32(device_config *device, UINT32 offset, UINT32 size, UINT32 value);
444   static void static_set_inline64(device_config *device, UINT32 offset, UINT32 size, UINT64 value);
445   static void static_set_inline_float(device_config *device, UINT32 offset, UINT32 size, float value);
446
441447protected:
442448   // overrides
443449   virtual bool device_validity_check(const game_driver &driver) const;
src/emu/disound.c
r8910r8911
6868
6969
7070//-------------------------------------------------
71//  interface_process_token - token processing for
72//  the sound interface
71//  static_add_route - configuration helper to add
72//  a new route to the device
7373//-------------------------------------------------
7474
75bool device_config_sound_interface::interface_process_token(UINT32 entrytype, const machine_config_token *&tokens)
75void device_config_sound_interface::static_add_route(device_config *device, UINT32 output, const char *target, double gain, UINT32 input)
7676{
77   switch (entrytype)
78   {
79      // custom config 1 is a new route
80      case MCONFIG_TOKEN_DISOUND_ROUTE:
81      {
82         // put back the token that was originally fetched so we can grab a packed 64-bit token
83         TOKEN_UNGET_UINT32(tokens);
77   device_config_sound_interface *sound = dynamic_cast<device_config_sound_interface *>(device);
78   if (sound == NULL)
79      throw emu_fatalerror("MDRV_SOUND_ROUTE called on device '%s' with no sound interface", device->tag());
8480
85         // extract data
86         int output, input;
87         UINT32 gain;
88         TOKEN_GET_UINT64_UNPACK4(tokens, entrytype, 8, output, 12, input, 12, gain, 32);
89         float fgain = (float)gain * (1.0f / (float)(1 << 24));
90         const char *target = TOKEN_GET_STRING(tokens);
81   sound_route **routeptr;
82   for (routeptr = &sound->m_route_list; *routeptr != NULL; routeptr = &(*routeptr)->m_next) ;
83   *routeptr = global_alloc(sound_route(output, input, gain, target));
84}
9185
92         // allocate a new route
93         sound_route **routeptr;
94         for (routeptr = &m_route_list; *routeptr != NULL; routeptr = &(*routeptr)->m_next) ;
95         *routeptr = global_alloc(sound_route(output, input, fgain, target));
96         return true;
97      }
9886
99      // custom config 2 resets the sound routes
100      case MCONFIG_TOKEN_DISOUND_RESET:
101         reset_routes();
102         return true;
103   }
87//-------------------------------------------------
88//  static_reset_routes - configuration helper to
89//  reset all existing routes to the device
90//-------------------------------------------------
10491
105   return false;
92void device_config_sound_interface::static_reset_routes(device_config *device)
93{
94   device_config_sound_interface *sound = dynamic_cast<device_config_sound_interface *>(device);
95   if (sound == NULL)
96      throw emu_fatalerror("MDRV_SOUND_ROUTES_RESET called on device '%s' with no sound interface", device->tag());
97
98   sound->reset_routes();
10699}
107100
108101
src/emu/disound.h
r8910r8911
7676   MDRV_DEVICE_CONFIG(_config)
7777
7878#define MDRV_SOUND_ROUTE_EX(_output, _target, _gain, _input) \
79   TOKEN_UINT64_PACK4(MCONFIG_TOKEN_DISOUND_ROUTE, 8, _output, 12, _input, 12, ((float)(_gain) * (float)(1 << 24)), 32), \
80   TOKEN_PTR(stringptr, _target),
79   device_config_sound_interface::static_add_route(device, _output, _target, _gain, _input); \
8180
8281#define MDRV_SOUND_ROUTE(_output, _target, _gain) \
8382   MDRV_SOUND_ROUTE_EX(_output, _target, _gain, 0)
8483
8584#define MDRV_SOUND_ROUTES_RESET() \
86   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DISOUND_RESET, 8),
85   device_config_sound_interface::static_reset_routes(device); \
8786
8887
8988
r8910r8911
118117
119118   sound_route *      m_route_list;         // list of sound routes
120119
120   // static inline helpers
121   static void static_add_route(device_config *device, UINT32 output, const char *target, double gain, UINT32 input = 0);
122   static void static_reset_routes(device_config *device);
123
121124protected:
122125   // optional operation overrides
123   virtual bool interface_process_token(UINT32 entrytype, const machine_config_token *&tokens);
124126   virtual bool interface_validity_check(const game_driver &driver) const;
125127
126128   void reset_routes();
src/emu/image.c
r8910r8911
517517   device_config *devconfig = type(*config, owner->subtag(tempstring,tag), &owner->baseconfig(), clock);
518518   running_device *device = device_list->append(devconfig->tag(), devconfig->alloc_device(*owner->machine));
519519
520   const machine_config_token *tokens = device->machine_config_tokens();
521   if (tokens != NULL)
520   machine_config_constructor machconfig = device->machine_config_additions();
521   if (machconfig != NULL)
522522    {
523      config->detokenize(tokens,devconfig);
523       (*machconfig)(*config, devconfig);
524524        for (const device_config *config_dev = config->m_devicelist.first(); config_dev != NULL; config_dev = config_dev->next())
525525        {
526526         if (config_dev->owner()==devconfig) {
src/emu/devcpu.c
r8910r8911
225225     m_state_export(reinterpret_cast<cpu_state_io_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_EXPORT_STATE))),
226226     m_string_export(reinterpret_cast<cpu_string_io_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_EXPORT_STRING))),
227227     m_exit(reinterpret_cast<cpu_exit_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_EXIT))),
228     m_using_legacy_state(false)
228     m_using_legacy_state(false),
229     m_inited(false)
229230{
230231   memset(&m_partial_frame_period, 0, sizeof(m_partial_frame_period));
231232
r8910r8911
245246legacy_cpu_device::~legacy_cpu_device()
246247{
247248   // call the CPU's exit function if present
248   if (m_exit != NULL)
249   if (m_inited && m_exit != NULL)
249250      (*m_exit)(this);
250251}
251252
r8910r8911
259260   // standard init
260261   cpu_init_func init = reinterpret_cast<cpu_init_func>(m_cpu_config.get_legacy_config_fct(CPUINFO_FCT_INIT));
261262   (*init)(this, static_standard_irq_callback);
263   m_inited = true;
262264
263265   // fetch information about the CPU states
264266   if (m_state_list == NULL)
src/emu/devcpu.h
r8910r8911
420420public:
421421   // basic information getters
422422   virtual const rom_entry *rom_region() const { return reinterpret_cast<const rom_entry *>(get_legacy_config_ptr(DEVINFO_PTR_ROM_REGION)); }
423   virtual const machine_config_token *machine_config_tokens() const { return reinterpret_cast<const machine_config_token *>(get_legacy_config_ptr(DEVINFO_PTR_MACHINE_CONFIG)); }
423   virtual machine_config_constructor machine_config_additions() const { return reinterpret_cast<machine_config_constructor>(get_legacy_config_ptr(DEVINFO_PTR_MACHINE_CONFIG)); }
424424
425425protected:
426426   // device_config_execute_interface overrides
r8910r8911
536536
537537   UINT64               m_state_io;               // temporary buffer for state I/O
538538   bool               m_using_legacy_state;      // true if we are using the old-style state access
539   bool               m_inited;
539540};
540541
541542
src/emu/info.c
r8910r8911
10411041   if (game->description != NULL)
10421042      fprintf(out, "\t\t<description>%s</description>\n", xml_normalize_string(game->description));
10431043
1044   /* print the year only if is a number */
1044   /* print the year only if is a number or another allowed character (? or +) */
10451045   if (game->year != NULL && strspn(game->year, "0123456789?+") == strlen(game->year))
10461046      fprintf(out, "\t\t<year>%s</year>\n", xml_normalize_string(game->year));
10471047
src/emu/deprecat.h
r8910r8911
3131 *************************************/
3232
3333#define MDRV_CPU_VBLANK_INT_HACK(_func, _rate) \
34   TOKEN_UINT32_PACK2(MCONFIG_TOKEN_DIEXEC_VBLANK_INT, 8, _rate, 24), \
35   TOKEN_PTR(cpu_interrupt, _func), \
36   TOKEN_PTR(stringptr, NULL), \
34   device_config_execute_interface::static_set_vblank_int(device, _func, NULL, _rate); \
3735
3836
3937
src/emu/memory.c
r8910r8911
353353   // compare a range against our range
354354   bool matches_exactly(offs_t bytestart, offs_t byteend) const { return (m_bytestart == bytestart && m_byteend == byteend); }
355355   bool fully_covers(offs_t bytestart, offs_t byteend) const { return (m_bytestart <= bytestart && m_byteend >= byteend); }
356   bool partially_covers(offs_t bytestart, offs_t byteend) const { return (m_bytestart <= byteend && m_byteend >= bytestart); }
356   bool is_covered_by(offs_t bytestart, offs_t byteend) const { return (m_bytestart >= bytestart && m_byteend <= byteend); }
357   bool straddles(offs_t bytestart, offs_t byteend) const { return (m_bytestart < byteend && m_byteend > bytestart); }
357358
358359   // track and verify address space references to this bank
359360   bool references_space(address_space &space, read_or_write readorwrite) const;
r8910r8911
789790      m_live_lookup = m_table;
790791      _UintType result;
791792      if (sizeof(_UintType) == 1) result = m_space.read_byte(offset);
792      if (sizeof(_UintType) == 2) result = m_space.read_word(offset, mask);
793      if (sizeof(_UintType) == 4) result = m_space.read_dword(offset, mask);
794      if (sizeof(_UintType) == 8) result = m_space.read_qword(offset, mask);
793      if (sizeof(_UintType) == 2) result = m_space.read_word(offset << 1, mask);
794      if (sizeof(_UintType) == 4) result = m_space.read_dword(offset << 2, mask);
795      if (sizeof(_UintType) == 8) result = m_space.read_qword(offset << 3, mask);
795796      m_live_lookup = oldtable;
796797      return result;
797798   }
r8910r8911
841842      UINT8 *oldtable = m_live_lookup;
842843      m_live_lookup = m_table;
843844      if (sizeof(_UintType) == 1) m_space.write_byte(offset, data);
844      if (sizeof(_UintType) == 2) m_space.write_word(offset, data, mask);
845      if (sizeof(_UintType) == 4) m_space.write_dword(offset, data, mask);
846      if (sizeof(_UintType) == 8) m_space.write_qword(offset, data, mask);
845      if (sizeof(_UintType) == 2) m_space.write_word(offset << 1, data, mask);
846      if (sizeof(_UintType) == 4) m_space.write_dword(offset << 2, data, mask);
847      if (sizeof(_UintType) == 8) m_space.write_qword(offset << 3, data, mask);
847848      m_live_lookup = oldtable;
848849   }
849850
r8910r8911
22372238      // consider this bank if it is used for reading and matches the address space
22382239      if (bank->references_space(*this, ROW_READ))
22392240      {
2240         // verify that the region fully covers the decrypted range
2241         if (bank->fully_covers(bytestart, byteend))
2241         // verify that the provided range fully covers this bank
2242         if (bank->is_covered_by(bytestart, byteend))
22422243         {
22432244            // set the decrypted pointer for the corresponding memory bank
22442245            bank->set_base_decrypted(reinterpret_cast<UINT8 *>(base) + bank->bytestart() - bytestart);
r8910r8911
22462247         }
22472248
22482249         // fatal error if the decrypted region straddles the bank
2249         else if (bank->partially_covers(bytestart, byteend))
2250         else if (bank->straddles(bytestart, byteend))
22502251            throw emu_fatalerror("memory_set_decrypted_region found straddled region %08X-%08X for device '%s'", bytestart, byteend, m_device.tag());
22512252      }
22522253   }
src/emu/memory.h
r8910r8911
308308   inline offs_t addr2byte(offs_t address) const { return (m_addrbus_shift < 0) ? (address << -m_addrbus_shift) : (address >> m_addrbus_shift); }
309309   inline offs_t addr2byte_end(offs_t address) const { return (m_addrbus_shift < 0) ? ((address << -m_addrbus_shift) | ((1 << -m_addrbus_shift) - 1)) : (address >> m_addrbus_shift); }
310310   inline offs_t byte2addr(offs_t address) const { return (m_addrbus_shift > 0) ? (address << m_addrbus_shift) : (address >> -m_addrbus_shift); }
311   inline offs_t byte2addr_end(offs_t address) const { return (m_addrbus_shift > 0) ? ((address << m_addrbus_shift) | ((1 << -m_addrbus_shift) - 1)) : (address >> -m_addrbus_shift); }
311   inline offs_t byte2addr_end(offs_t address) const { return (m_addrbus_shift > 0) ? ((address << m_addrbus_shift) | ((1 << m_addrbus_shift) - 1)) : (address >> -m_addrbus_shift); }
312312
313313   // state
314314   const char *      m_name;
src/emu/machine/timekpr.c
r8910r8911
1/*
2 * STmicroelectronics TIMEKEEPER SRAM
3 *
4 * Supports:
5 *           M48T02
6 *           M48T35
7 *           M48T58
8 *           MK48T08
9 *
10 */
1/***************************************************************************
112
3    timekpr.h
4
5    Various ST Microelectronics timekeeper SRAM implementations:
6       - M48T02
7       - M48T35
8       - M48T58
9       - MK48T08
10
11***************************************************************************/
12
1213#include "emu.h"
1314#include "machine/timekpr.h"
1415
15typedef struct
16{
17   UINT8 control;
18   UINT8 seconds;
19   UINT8 minutes;
20   UINT8 hours;
21   UINT8 day;
22   UINT8 date;
23   UINT8 month;
24   UINT8 year;
25   UINT8 century;
26   UINT8 *data;
27   UINT8 *default_data;
28   running_device *device;
29   int size;
30   int offset_control;
31   int offset_seconds;
32   int offset_minutes;
33   int offset_hours;
34   int offset_day;
35   int offset_date;
36   int offset_month;
37   int offset_year;
38   int offset_century;
39   int offset_flags;
40} timekeeper_state;
4116
17/***************************************************************************
18    MACROS
19***************************************************************************/
20
4221#define MASK_SECONDS ( 0x7f )
4322#define MASK_MINUTES ( 0x7f )
4423#define MASK_HOURS ( 0x3f )
r8910r8911
6443
6544#define FLAGS_BL ( 0x10 ) /* MK48T08: not emulated */
6645
46#define TIMEKPR_DEV_DERIVED_CTOR(devtype) \
47   devtype##_device::devtype##_device(running_machine &_machine, const devtype##_device_config &config) \
48      : timekeeper_device(_machine, config) \
49   { }
50
51#define TIMEKPR_DEVCFG_DERIVED_CTOR(devtype, name) \
52   devtype##_device_config::devtype##_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) \
53    : timekeeper_device_config(mconfig, name, tag, owner, clock) \
54   { }
55
56#define TIMEKPR_DEVCFG_DERIVED_STATIC_ALLOC(devtype) \
57   device_config *devtype##_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) \
58   { return global_alloc(devtype##_device_config(mconfig, tag, owner, clock)); }
59
60#define TIMEKPR_DEVCFG_DERIVED_DEV_ALLOC(devtype) \
61   device_t *devtype##_device_config::alloc_device(running_machine &machine) const \
62   { return auto_alloc(&machine, devtype##_device(machine, *this)); }
63
64#define TIMEKPR_DERIVE(devtype, name) \
65   TIMEKPR_DEV_DERIVED_CTOR(devtype) \
66   TIMEKPR_DEVCFG_DERIVED_CTOR(devtype, name) \
67   TIMEKPR_DEVCFG_DERIVED_STATIC_ALLOC(devtype) \
68   TIMEKPR_DEVCFG_DERIVED_DEV_ALLOC(devtype)
69
70//**************************************************************************
71//  STATIC DATA
72//**************************************************************************
73
74//**************************************************************************
75//  DEVICE CONFIGURATION
76//**************************************************************************
77
78//-------------------------------------------------
79//  timekeeper_device_config - constructor
80//-------------------------------------------------
81
82timekeeper_device_config::timekeeper_device_config(const machine_config &mconfig, const char *type, const char *tag, const device_config *owner, UINT32 clock)
83    : device_config(mconfig, static_alloc_device_config, type, tag, owner, clock),
84     device_config_nvram_interface(mconfig, *this)
85{
86
87}
88
89
90//-------------------------------------------------
91//  static_alloc_device_config - allocate a new
92//  configuration object
93//-------------------------------------------------
94
95device_config *timekeeper_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
96{
97    return global_alloc(timekeeper_device_config(mconfig, "TIMEKEEPER", tag, owner, clock));
98}
99
100
101//-------------------------------------------------
102//  alloc_device - allocate a new device object
103//-------------------------------------------------
104
105device_t *timekeeper_device_config::alloc_device(running_machine &machine) const
106{
107    return auto_alloc(&machine, timekeeper_device(machine, *this));
108}
109
110/***************************************************************************
111    INLINE FUNCTIONS
112***************************************************************************/
113
67114INLINE UINT8 make_bcd(UINT8 data)
68115{
69116   return ( ( ( data / 10 ) % 10 ) << 4 ) + ( data % 10 );
r8910r8911
105152   }
106153}
107154
108static void counters_to_ram( timekeeper_state *c )
109{
110   counter_to_ram( c->data, c->offset_control, c->control );
111   counter_to_ram( c->data, c->offset_seconds, c->seconds );
112   counter_to_ram( c->data, c->offset_minutes, c->minutes );
113   counter_to_ram( c->data, c->offset_hours, c->hours );
114   counter_to_ram( c->data, c->offset_day, c->day );
115   counter_to_ram( c->data, c->offset_date, c->date );
116   counter_to_ram( c->data, c->offset_month, c->month );
117   counter_to_ram( c->data, c->offset_year, c->year );
118   counter_to_ram( c->data, c->offset_century, c->century );
119}
120
121155static int counter_from_ram( UINT8 *data, int offset )
122156{
123157   if( offset >= 0 )
r8910r8911
127161   return 0;
128162}
129163
130static void counters_from_ram( timekeeper_state *c )
164//**************************************************************************
165//  LIVE DEVICE
166//**************************************************************************
167
168const device_type M48T02 = m48t02_device_config::static_alloc_device_config;
169const device_type M48T35 = m48t35_device_config::static_alloc_device_config;
170const device_type M48T58 = m48t58_device_config::static_alloc_device_config;
171const device_type MK48T08 = mk48t08_device_config::static_alloc_device_config;
172
173TIMEKPR_DERIVE(m48t02, "M48T02")
174TIMEKPR_DERIVE(m48t35, "M48T35")
175TIMEKPR_DERIVE(m48t58, "M48T58")
176TIMEKPR_DERIVE(mk48t08, "MK48T08")
177
178//-------------------------------------------------
179//  timekeeper_device - constructor
180//-------------------------------------------------
181
182timekeeper_device::timekeeper_device(running_machine &_machine, const timekeeper_device_config &config)
183    : device_t(_machine, config),
184     device_nvram_interface(_machine, config, *this),
185      m_config(config)
131186{
132   c->control = counter_from_ram( c->data, c->offset_control );
133   c->seconds = counter_from_ram( c->data, c->offset_seconds );
134   c->minutes = counter_from_ram( c->data, c->offset_minutes );
135   c->hours = counter_from_ram( c->data, c->offset_hours );
136   c->day = counter_from_ram( c->data, c->offset_day );
137   c->date = counter_from_ram( c->data, c->offset_date );
138   c->month = counter_from_ram( c->data, c->offset_month );
139   c->year = counter_from_ram( c->data, c->offset_year );
140   c->century = counter_from_ram( c->data, c->offset_century );
187
141188}
142189
143static TIMER_CALLBACK( timekeeper_tick )
190//-------------------------------------------------
191//  device_start - device-specific startup
192//-------------------------------------------------
193
194void timekeeper_device::device_start()
144195{
145   timekeeper_state *c = (timekeeper_state *) ptr;
196   emu_timer *timer;
197   attotime duration;
198   system_time systime;
146199
147   int carry;
200   /* validate some basic stuff */
201   assert(this != NULL);
148202
149   if( ( c->seconds & SECONDS_ST ) != 0 ||
150      ( c->control & CONTROL_W ) != 0 )
203   m_machine.base_datetime(systime);
204
205   m_control = 0;
206   m_seconds = make_bcd( systime.local_time.second );
207   m_minutes = make_bcd( systime.local_time.minute );
208   m_hours = make_bcd( systime.local_time.hour );
209   m_day = make_bcd( systime.local_time.weekday + 1 );
210   m_date = make_bcd( systime.local_time.mday );
211   m_month = make_bcd( systime.local_time.month + 1 );
212   m_year = make_bcd( systime.local_time.year % 100 );
213   m_century = make_bcd( systime.local_time.year / 100 );
214   m_data = auto_alloc_array( &m_machine, UINT8, m_size );
215
216   m_default_data = *region();
217   if (m_default_data)
151218   {
219      assert( region()->bytes() == m_size );
220   }
221
222   state_save_register_device_item( this, 0, m_control );
223   state_save_register_device_item( this, 0, m_seconds );
224   state_save_register_device_item( this, 0, m_minutes );
225   state_save_register_device_item( this, 0, m_hours );
226   state_save_register_device_item( this, 0, m_day );
227   state_save_register_device_item( this, 0, m_date );
228   state_save_register_device_item( this, 0, m_month );
229   state_save_register_device_item( this, 0, m_year );
230   state_save_register_device_item( this, 0, m_century );
231   state_save_register_device_item_pointer( this, 0, m_data, m_size );
232
233   timer = timer_alloc( &m_machine, timekeeper_tick_callback, (void *)this );
234   duration = ATTOTIME_IN_SEC(1);
235   timer_adjust_periodic( timer, duration, 0, duration );
236}
237
238void m48t02_device::device_start()
239{
240   m_offset_control = 0x7f8;
241   m_offset_seconds = 0x7f9;
242   m_offset_minutes = 0x7fa;
243   m_offset_hours = 0x7fb;
244   m_offset_day = 0x7fc;
245   m_offset_date = 0x7fd;
246   m_offset_month = 0x7fe;
247   m_offset_year = 0x7ff;
248   m_offset_century = -1;
249   m_offset_flags = -1;
250   m_size = 0x800;
251
252   timekeeper_device::device_start();
253}
254
255void m48t35_device::device_start()
256{
257   m_offset_control = 0x7ff8;
258   m_offset_seconds = 0x7ff9;
259   m_offset_minutes = 0x7ffa;
260   m_offset_hours = 0x7ffb;
261   m_offset_day = 0x7ffc;
262   m_offset_date = 0x7ffd;
263   m_offset_month = 0x7ffe;
264   m_offset_year = 0x7fff;
265   m_offset_century = -1;
266   m_offset_flags = -1;
267   m_size = 0x8000;
268
269   timekeeper_device::device_start();
270}
271
272void m48t58_device::device_start()
273{
274   m_offset_control = 0x1ff8;
275   m_offset_seconds = 0x1ff9;
276   m_offset_minutes = 0x1ffa;
277   m_offset_hours = 0x1ffb;
278   m_offset_day = 0x1ffc;
279   m_offset_date = 0x1ffd;
280   m_offset_month = 0x1ffe;
281   m_offset_year = 0x1fff;
282   m_offset_century = -1;
283   m_offset_flags = -1;
284   m_size = 0x2000;
285
286   timekeeper_device::device_start();
287}
288
289void mk48t08_device::device_start()
290{
291   m_offset_control = 0x1ff8;
292   m_offset_seconds = 0x1ff9;
293   m_offset_minutes = 0x1ffa;
294   m_offset_hours = 0x1ffb;
295   m_offset_day = 0x1ffc;
296   m_offset_date = 0x1ffd;
297   m_offset_month = 0x1ffe;
298   m_offset_year = 0x1fff;
299   m_offset_century = 0x1ff1;
300   m_offset_flags = 0x1ff0;
301   m_size = 0x2000;
302
303   timekeeper_device::device_start();
304}
305
306//-------------------------------------------------
307//  device_reset - device-specific reset
308//-------------------------------------------------
309
310void timekeeper_device::device_reset()
311{
312
313}
314
315
316void timekeeper_device::counters_to_ram()
317{
318   counter_to_ram( m_data, m_offset_control, m_control );
319   counter_to_ram( m_data, m_offset_seconds, m_seconds );
320   counter_to_ram( m_data, m_offset_minutes, m_minutes );
321   counter_to_ram( m_data, m_offset_hours, m_hours );
322   counter_to_ram( m_data, m_offset_day, m_day );
323   counter_to_ram( m_data, m_offset_date, m_date );
324   counter_to_ram( m_data, m_offset_month, m_month );
325   counter_to_ram( m_data, m_offset_year, m_year );
326   counter_to_ram( m_data, m_offset_century, m_century );
327}
328
329void timekeeper_device::counters_from_ram()
330{
331   m_control = counter_from_ram( m_data, m_offset_control );
332   m_seconds = counter_from_ram( m_data, m_offset_seconds );
333   m_minutes = counter_from_ram( m_data, m_offset_minutes );
334   m_hours = counter_from_ram( m_data, m_offset_hours );
335   m_day = counter_from_ram( m_data, m_offset_day );
336   m_date = counter_from_ram( m_data, m_offset_date );
337   m_month = counter_from_ram( m_data, m_offset_month );
338   m_year = counter_from_ram( m_data, m_offset_year );
339   m_century = counter_from_ram( m_data, m_offset_century );
340}
341
342TIMER_CALLBACK( timekeeper_device::timekeeper_tick_callback )
343{
344    reinterpret_cast<timekeeper_device *>(ptr)->timekeeper_tick();
345}
346
347void timekeeper_device::timekeeper_tick()
348{
349   if( ( m_seconds & SECONDS_ST ) != 0 ||
350      ( m_control & CONTROL_W ) != 0 )
351   {
152352      return;
153353   }
154354
155   carry = inc_bcd( &c->seconds, MASK_SECONDS, 0x00, 0x59 );
355   int carry = inc_bcd( &m_seconds, MASK_SECONDS, 0x00, 0x59 );
156356   if( carry )
157357   {
158      carry = inc_bcd( &c->minutes, MASK_MINUTES, 0x00, 0x59 );
358      carry = inc_bcd( &m_minutes, MASK_MINUTES, 0x00, 0x59 );
159359   }
160360   if( carry )
161361   {
162      carry = inc_bcd( &c->hours, MASK_HOURS, 0x00, 0x23 );
362      carry = inc_bcd( &m_hours, MASK_HOURS, 0x00, 0x23 );
163363   }
164364
165365   if( carry )
166366   {
167      UINT8 month;
168      UINT8 year;
169367      UINT8 maxdays;
170368      static const UINT8 daysinmonth[] = { 0x31, 0x28, 0x31, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x31, 0x30, 0x31 };
171369
172      inc_bcd( &c->day, MASK_DAY, 0x01, 0x07 );
370      inc_bcd( &m_day, MASK_DAY, 0x01, 0x07 );
173371
174      month = from_bcd( c->month );
175      year = from_bcd( c->year );
372      UINT8 month = from_bcd( m_month );
373      UINT8 year = from_bcd( m_year );
176374
177375      if( month == 2 && ( year % 4 ) == 0 )
178376      {
r8910r8911
187385         maxdays = 0x31;
188386      }
189387
190      carry = inc_bcd( &c->date, MASK_DATE, 0x01, maxdays );
388      carry = inc_bcd( &m_date, MASK_DATE, 0x01, maxdays );
191389   }
192390   if( carry )
193391   {
194      carry = inc_bcd( &c->month, MASK_MONTH, 0x01, 0x12 );
392      carry = inc_bcd( &m_month, MASK_MONTH, 0x01, 0x12 );
195393   }
196394   if( carry )
197395   {
198      carry = inc_bcd( &c->year, MASK_YEAR, 0x00, 0x99 );
396      carry = inc_bcd( &m_year, MASK_YEAR, 0x00, 0x99 );
199397   }
200398   if( carry )
201399   {
202      carry = inc_bcd( &c->century, MASK_CENTURY, 0x00, 0x99 );
400      carry = inc_bcd( &m_century, MASK_CENTURY, 0x00, 0x99 );
203401
204      if( c->device->type() == M48T35 ||
205         c->device->type() == M48T58 )
402      if( type() == M48T35 ||
403         type() == M48T58 )
206404      {
207         if( ( c->day & DAY_CEB ) != 0 )
405         if( ( m_day & DAY_CEB ) != 0 )
208406         {
209            c->day ^= DAY_CB;
407            m_day ^= DAY_CB;
210408         }
211409      }
212410   }
213411
214   if( ( c->control & CONTROL_R ) == 0 )
412   if( ( m_control & CONTROL_R ) == 0 )
215413   {
216      counters_to_ram( c );
414      counters_to_ram();
217415   }
218416}
219417
220/*-------------------------------------------------
221    get_safe_token - makes sure that the passed
222    in device is the right type
223-------------------------------------------------*/
224
225INLINE timekeeper_state *get_safe_token(running_device *device)
418void timekeeper_device::write(UINT16 offset, UINT8 data)
226419{
227   assert(device != NULL);
228   assert((device->type() == M48T02) ||
229         (device->type() == M48T35) ||
230         (device->type() == M48T58) ||
231         (device->type() == MK48T08));
232
233   return (timekeeper_state *)downcast<legacy_device_base *>(device)->token();
234}
235
236/* memory handlers */
237
238WRITE8_DEVICE_HANDLER( timekeeper_w )
239{
240   timekeeper_state *c = get_safe_token(device);
241
242   if( offset == c->offset_control )
420   if( offset == m_offset_control )
243421   {
244      if( ( c->control & CONTROL_W ) != 0 &&
422      if( ( m_control & CONTROL_W ) != 0 &&
245423         ( data & CONTROL_W ) == 0 )
246424      {
247         counters_from_ram( c );
425         counters_from_ram();
248426      }
249      c->control = data;
427      m_control = data;
250428   }
251   else if( offset == c->offset_day )
429   else if( offset == m_offset_day )
252430   {
253      if( c->device->type() == M48T35 ||
254         c->device->type() == M48T58 )
431      if( type() == M48T35 ||
432         type() == M48T58 )
255433      {
256         c->day = ( c->day & ~DAY_CEB ) | ( data & DAY_CEB );
434         m_day = ( m_day & ~DAY_CEB ) | ( data & DAY_CEB );
257435      }
258436   }
259   else if( offset == c->offset_date && c->device->type() == M48T58 )
437   else if( offset == m_offset_date && type() == M48T58 )
260438   {
261439      data &= ~DATE_BL;
262440   }
263   else if( offset == c->offset_flags && c->device->type() == MK48T08 )
441   else if( offset == m_offset_flags && type() == MK48T08 )
264442   {
265443      data &= ~FLAGS_BL;
266444   }
267445
268//  logerror( "%s: timekeeper_write( %s, %04x, %02x )\n", cpuexec_describe_context(machine), c->device->tag, offset, data );
269   c->data[ offset ] = data;
446   m_data[ offset ] = data;
270447}
271448
272READ8_DEVICE_HANDLER( timekeeper_r )
449UINT8 timekeeper_device::read(UINT16 offset)
273450{
274   timekeeper_state *c = get_safe_token(device);
275   UINT8 data = c->data[ offset ];
276//  logerror( "%s: timekeeper_read( %s, %04x ) %02x\n", cpuexec_describe_context(machine), c->device->tag, offset, data );
277   return data;
451   return m_data[ offset ];
278452}
279453
280/*-------------------------------------------------
281    device start callback
282-------------------------------------------------*/
454//-------------------------------------------------
455//  nvram_default - called to initialize NVRAM to
456//  its default state
457//-------------------------------------------------
283458
284static DEVICE_START(timekeeper)
459void timekeeper_device::nvram_default()
285460{
286   timekeeper_state *c = get_safe_token(device);
287   emu_timer *timer;
288   attotime duration;
289   system_time systime;
290
291   /* validate some basic stuff */
292   assert(device != NULL);
293//  assert(device->baseconfig().static_config() != NULL);
294   assert(downcast<const legacy_device_config_base &>(device->baseconfig()).inline_config() == NULL);
295   assert(device->machine != NULL);
296   assert(device->machine->config != NULL);
297
298   device->machine->base_datetime(systime);
299
300   c->device = device;
301   c->control = 0;
302   c->seconds = make_bcd( systime.local_time.second );
303   c->minutes = make_bcd( systime.local_time.minute );
304   c->hours = make_bcd( systime.local_time.hour );
305   c->day = make_bcd( systime.local_time.weekday + 1 );
306   c->date = make_bcd( systime.local_time.mday );
307   c->month = make_bcd( systime.local_time.month + 1 );
308   c->year = make_bcd( systime.local_time.year % 100 );
309   c->century = make_bcd( systime.local_time.year / 100 );
310   c->data = auto_alloc_array( device->machine, UINT8, c->size );
311
312   c->default_data = *device->region();
313   if (c->default_data)
314      assert( device->region()->bytes() == c->size );
315
316   state_save_register_device_item( device, 0, c->control );
317   state_save_register_device_item( device, 0, c->seconds );
318   state_save_register_device_item( device, 0, c->minutes );
319   state_save_register_device_item( device, 0, c->hours );
320   state_save_register_device_item( device, 0, c->day );
321   state_save_register_device_item( device, 0, c->date );
322   state_save_register_device_item( device, 0, c->month );
323   state_save_register_device_item( device, 0, c->year );
324   state_save_register_device_item( device, 0, c->century );
325   state_save_register_device_item_pointer( device, 0, c->data, c->size );
326
327   timer = timer_alloc( device->machine, timekeeper_tick, c );
328   duration = ATTOTIME_IN_SEC(1);
329   timer_adjust_periodic( timer, duration, 0, duration );
330}
331
332static DEVICE_START(m48t02)
333{
334   timekeeper_state *c = get_safe_token(device);
335
336   c->offset_control = 0x7f8;
337   c->offset_seconds = 0x7f9;
338   c->offset_minutes = 0x7fa;
339   c->offset_hours = 0x7fb;
340   c->offset_day = 0x7fc;
341   c->offset_date = 0x7fd;
342   c->offset_month = 0x7fe;
343   c->offset_year = 0x7ff;
344   c->offset_century = -1;
345   c->offset_flags = -1;
346   c->size = 0x800;
347
348   DEVICE_START_CALL( timekeeper );
349}
350
351static DEVICE_START(m48t35)
352{
353   timekeeper_state *c = get_safe_token(device);
354
355   c->offset_control = 0x7ff8;
356   c->offset_seconds = 0x7ff9;
357   c->offset_minutes = 0x7ffa;
358   c->offset_hours = 0x7ffb;
359   c->offset_day = 0x7ffc;
360   c->offset_date = 0x7ffd;
361   c->offset_month = 0x7ffe;
362   c->offset_year = 0x7fff;
363   c->offset_century = -1;
364   c->offset_flags = -1;
365   c->size = 0x8000;
366
367   DEVICE_START_CALL( timekeeper );
368}
369
370static DEVICE_START(m48t58)
371{
372   timekeeper_state *c = get_safe_token(device);
373
374   c->offset_control = 0x1ff8;
375   c->offset_seconds = 0x1ff9;
376   c->offset_minutes = 0x1ffa;
377   c->offset_hours = 0x1ffb;
378   c->offset_day = 0x1ffc;
379   c->offset_date = 0x1ffd;
380   c->offset_month = 0x1ffe;
381   c->offset_year = 0x1fff;
382   c->offset_century = -1;
383   c->offset_flags = -1;
384   c->size = 0x2000;
385
386   DEVICE_START_CALL( timekeeper );
387}
388
389static DEVICE_START(mk48t08)
390{
391   timekeeper_state *c = get_safe_token(device);
392
393   c->offset_control = 0x1ff8;
394   c->offset_seconds = 0x1ff9;
395   c->offset_minutes = 0x1ffa;
396   c->offset_hours = 0x1ffb;
397   c->offset_day = 0x1ffc;
398   c->offset_date = 0x1ffd;
399   c->offset_month = 0x1ffe;
400   c->offset_year = 0x1fff;
401   c->offset_century = 0x1ff1;
402   c->offset_flags = 0x1ff0;
403   c->size = 0x2000;
404
405   DEVICE_START_CALL( timekeeper );
406}
407
408/*-------------------------------------------------
409    device reset callback
410-------------------------------------------------*/
411
412static DEVICE_RESET(timekeeper)
413{
414}
415
416static DEVICE_NVRAM(timekeeper)
417{
418   timekeeper_state *c = get_safe_token(device);
419
420   if( read_or_write )
461   if( m_default_data != NULL )
421462   {
422      mame_fwrite( file, c->data, c->size );
463      memcpy( m_data, m_default_data, m_size );
423464   }
424465   else
425466   {
426      if( file )
427      {
428         mame_fread( file, c->data, c->size );
429      }
430      else
431      {
432         if( c->default_data != NULL )
433         {
434            memcpy( c->data, c->default_data, c->size );
435         }
436         else
437         {
438            memset( c->data, 0xff, c->size );
439         }
440      }
441
442      counters_to_ram( c );
467      memset( m_data, 0xff, m_size );
443468   }
444469}
445470
446/*-------------------------------------------------
447    device get info callback
448-------------------------------------------------*/
449471
450static DEVICE_GET_INFO(timekeeper)
451{
452   switch (state)
453   {
454      /* --- the following bits of info are returned as 64-bit signed integers --- */
455      case DEVINFO_INT_TOKEN_BYTES:         info->i = sizeof(timekeeper_state); break;
456      case DEVINFO_INT_INLINE_CONFIG_BYTES:   info->i = 0; break; // sizeof(timekeeper_config)
472//-------------------------------------------------
473//  nvram_read - called to read NVRAM from the
474//  .nv file
475//-------------------------------------------------
457476
458      /* --- the following bits of info are returned as pointers to data or functions --- */
459      case DEVINFO_FCT_START:               info->start = DEVICE_START_NAME(timekeeper); break;
460      case DEVINFO_FCT_STOP:               /* nothing */ break;
461      case DEVINFO_FCT_RESET:               info->reset = DEVICE_RESET_NAME(timekeeper); break;
462      case DEVINFO_FCT_NVRAM:               info->nvram = DEVICE_NVRAM_NAME(timekeeper); break;
463
464      /* --- the following bits of info are returned as NULL-terminated strings --- */
465      case DEVINFO_STR_NAME:               strcpy(info->s, "Timekeeper"); break;
466      case DEVINFO_STR_FAMILY:            strcpy(info->s, "EEPROM"); break;
467      case DEVINFO_STR_VERSION:            strcpy(info->s, "1.0"); break;
468      case DEVINFO_STR_SOURCE_FILE:         strcpy(info->s, __FILE__); break;
469      case DEVINFO_STR_CREDITS:            strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break;
470   }
471}
472
473DEVICE_GET_INFO( m48t02 )
477void timekeeper_device::nvram_read(mame_file &file)
474478{
475   switch (state)
476   {
477      /* --- the following bits of info are returned as NULL-terminated strings --- */
478      case DEVINFO_STR_NAME:                     strcpy(info->s, "M48T02");               break;
479   mame_fread( &file, m_data, m_size );
479480
480      /* --- the following bits of info are returned as pointers to data or functions --- */
481      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(m48t02);   break;
482
483      default:                              DEVICE_GET_INFO_CALL(timekeeper);         break;
484   }
481   counters_to_ram();
485482}
486483
487DEVICE_GET_INFO( m48t35 )
488{
489   switch (state)
490   {
491      /* --- the following bits of info are returned as NULL-terminated strings --- */
492      case DEVINFO_STR_NAME:                     strcpy(info->s, "M48T35");               break;
493484
494      /* --- the following bits of info are returned as pointers to data or functions --- */
495      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(m48t35);   break;
485//-------------------------------------------------
486//  nvram_write - called to write NVRAM to the
487//  .nv file
488//-------------------------------------------------
496489
497      default:                              DEVICE_GET_INFO_CALL(timekeeper);         break;
498   }
499}
500
501DEVICE_GET_INFO( m48t58 )
490void timekeeper_device::nvram_write(mame_file &file)
502491{
503   switch (state)
504   {
505      /* --- the following bits of info are returned as NULL-terminated strings --- */
506      case DEVINFO_STR_NAME:                     strcpy(info->s, "M48T58");               break;
507
508      /* --- the following bits of info are returned as pointers to data or functions --- */
509      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(m48t58);   break;
510
511      default:                              DEVICE_GET_INFO_CALL(timekeeper);         break;
512   }
492   mame_fwrite( &file, m_data, m_size );
513493}
514494
515DEVICE_GET_INFO( mk48t08 )
516{
517   switch (state)
518   {
519      /* --- the following bits of info are returned as NULL-terminated strings --- */
520      case DEVINFO_STR_NAME:                     strcpy(info->s, "MK48T08");               break;
521495
522      /* --- the following bits of info are returned as pointers to data or functions --- */
523      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(mk48t08);   break;
524496
525      default:                              DEVICE_GET_INFO_CALL(timekeeper);         break;
526   }
527}
497/***************************************************************************
498    TRAMPOLINES
499***************************************************************************/
528500
501WRITE8_DEVICE_HANDLER( timekeeper_w ) { downcast<timekeeper_device *>(device)->write(offset, data); }
502READ8_DEVICE_HANDLER( timekeeper_r ) { return downcast<timekeeper_device*>(device)->read(offset); }
529503
530DEFINE_LEGACY_NVRAM_DEVICE(M48T02, m48t02);
531DEFINE_LEGACY_NVRAM_DEVICE(M48T35, m48t35);
532DEFINE_LEGACY_NVRAM_DEVICE(M48T58, m48t58);
533DEFINE_LEGACY_NVRAM_DEVICE(MK48T08, mk48t08);
src/emu/machine/devhelpr.h
r0r8911
1/**********************************************************************
2
3    Generic modern device trampolines and other helpers, to minimize
4    the amount of redundant copy/pasting between modernized devices.
5
6**********************************************************************/
7
8#ifndef __DEVHELPR_H__
9#define __DEVHELPR_H__
10
11#define READ8_DEVICE_HANDLER_TRAMPOLINE(devname, funcname) \
12   READ8_DEVICE_HANDLER( funcname ) \
13   { return downcast<devname##_device*>(device)->funcname(offset); } \
14   UINT8 devname##_device::funcname(UINT32 offset)
15
16#define WRITE8_DEVICE_HANDLER_TRAMPOLINE(devname, funcname) \
17   WRITE8_DEVICE_HANDLER( funcname ) \
18   { downcast<devname##_device*>(device)->funcname(offset, data); } \
19   void devname##_device::funcname(UINT32 offset, UINT8 data)
20
21#define READ_LINE_DEVICE_HANDLER_TRAMPOLINE(devname, funcname) \
22   READ_LINE_DEVICE_HANDLER( funcname ) \
23   { return downcast<devname##_device *>(device)->funcname(); } \
24   void devname##_device::funcname()
25
26#define WRITE_LINE_DEVICE_HANDLER_TRAMPOLINE(devname, funcname) \
27   WRITE_LINE_DEVICE_HANDLER( funcname ) \
28   { return downcast<devname##_device *>(device)->funcname(state); } \
29   void devname##_device::funcname(UINT8 state)
30
31#define GENERIC_DEVICE_CONFIG_SETUP(devname, devtag) \
32   devname##_device_config::devname##_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) \
33       : device_config(mconfig, static_alloc_device_config, devtag, tag, owner, clock) \
34   { } \
35   \
36   device_config *devname##_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) \
37   { return global_alloc(devname##_device_config(mconfig, tag, owner, clock)); } \
38   \
39   device_t *devname##_device_config::alloc_device(running_machine &machine) const \
40   { return auto_alloc(&machine, devname##_device(machine, *this)); }
41
42
43#endif // __DEVHELPR_H__
No newline at end of file
src/emu/machine/74123.c
r8910r8911
2323//-------------------------------------------------
2424
2525ttl74123_device_config::ttl74123_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
26    : device_config(mconfig, static_alloc_device_config, "TTL74123", tag, owner, clock)
26   : device_config(mconfig, static_alloc_device_config, "TTL74123", tag, owner, clock)
2727{
2828}
2929
r8910r8911
3535
3636device_config *ttl74123_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
3737{
38    return global_alloc(ttl74123_device_config(mconfig, tag, owner, clock));
38   return global_alloc(ttl74123_device_config(mconfig, tag, owner, clock));
3939}
4040
4141
r8910r8911
4545
4646device_t *ttl74123_device_config::alloc_device(running_machine &machine) const
4747{
48    return auto_alloc(&machine, ttl74123_device(machine, *this));
48   return auto_alloc(&machine, ttl74123_device(machine, *this));
4949}
5050
5151
r8910r8911
5757
5858void ttl74123_device_config::device_config_complete()
5959{
60   // inherit a copy of the static data
61   const ttl74123_interface *intf = reinterpret_cast<const ttl74123_interface *>(static_config());
62   if (intf != NULL)
63      *static_cast<ttl74123_interface *>(this) = *intf;
6064
65   // or initialize to defaults if none provided
66   else
67   {
68      m_connection_type = TTL74123_NOT_GROUNDED_NO_DIODE;
69      m_res = 1.0;
70      m_cap = 1.0;
71      m_a = 0;
72      m_b = 0;
73      m_clear = 0;
74       memset(&m_output_changed_cb, 0, sizeof(m_output_changed_cb));
75   }
6176}
6277
6378
r8910r8911
7186//-------------------------------------------------
7287
7388ttl74123_device::ttl74123_device(running_machine &_machine, const ttl74123_device_config &config)
74    : device_t(_machine, config),
75      m_config(config)
89   : device_t(_machine, config),
90     m_config(config)
7691{
7792
7893}
r8910r8911
8499
85100void ttl74123_device::device_start()
86101{
87    m_timer = timer_alloc(&m_machine, clear_callback, (void *)this);
102   m_timer = timer_alloc(&m_machine, clear_callback, (void *)this);
88103
89104   /* start with the defaults */
90    m_a = m_config.m_a;
91    m_b = m_config.m_b;
92    m_clear = m_config.m_clear;
105   m_a = m_config.m_a;
106   m_b = m_config.m_b;
107   m_clear = m_config.m_clear;
93108
94109   /* register for state saving */
95    state_save_register_device_item(this, 0, m_a);
96    state_save_register_device_item(this, 0, m_b);
97    state_save_register_device_item(this, 0, m_clear);
110   state_save_register_device_item(this, 0, m_a);
111   state_save_register_device_item(this, 0, m_b);
112   state_save_register_device_item(this, 0, m_clear);
98113}
99114
100115
r8910r8911
109124
110125
111126
112/*-------------------------------------------------
113    compute_duration
114-------------------------------------------------*/
127//-------------------------------------------------
128//  compute_duration - compute timer duration
129//-------------------------------------------------
115130
116131attotime ttl74123_device::compute_duration()
117132{
118    double duration;
133   double duration;
119134
120    switch (m_config.m_connection_type)
121    {
122    case TTL74123_NOT_GROUNDED_NO_DIODE:
123        duration = 0.28 * m_config.m_res * m_config.m_cap * (1.0 + (700.0 / m_config.m_res));
124        break;
135   switch (m_config.m_connection_type)
136   {
137   case TTL74123_NOT_GROUNDED_NO_DIODE:
138      duration = 0.28 * m_config.m_res * m_config.m_cap * (1.0 + (700.0 / m_config.m_res));
139      break;
125140
126    case TTL74123_NOT_GROUNDED_DIODE:
127        duration = 0.25 * m_config.m_res * m_config.m_cap * (1.0 + (700.0 / m_config.m_res));
128        break;
141   case TTL74123_NOT_GROUNDED_DIODE:
142      duration = 0.25 * m_config.m_res * m_config.m_cap * (1.0 + (700.0 / m_config.m_res));
143      break;
129144
130    case TTL74123_GROUNDED:
131    default:
132        if (m_config.m_cap < CAP_U(0.1))
133        {
134            /* this is really a curve - a very flat one in the 0.1uF-.01uF range */
135            duration = 0.32 * m_config.m_res * m_config.m_cap;
136        }
137        else
138        {
139            duration = 0.33 * m_config.m_res * m_config.m_cap;
140        }
141        break;
142    }
145   case TTL74123_GROUNDED:
146   default:
147      if (m_config.m_cap < CAP_U(0.1))
148      {
149         /* this is really a curve - a very flat one in the 0.1uF-.01uF range */
150         duration = 0.32 * m_config.m_res * m_config.m_cap;
151      }
152      else
153      {
154         duration = 0.33 * m_config.m_res * m_config.m_cap;
155      }
156      break;
157   }
143158
144    return double_to_attotime(duration);
159   return double_to_attotime(duration);
145160}
146161
147162
148/*-------------------------------------------------
149    timer_running
150-------------------------------------------------*/
163//-------------------------------------------------
164//  timer_running - is the timer running?
165//-------------------------------------------------
151166
152167int ttl74123_device::timer_running()
153168{
154    return (attotime_compare(timer_timeleft(m_timer), attotime_zero) > 0) &&
155           (attotime_compare(timer_timeleft(m_timer), attotime_never) != 0);
169   return (attotime_compare(timer_timeleft(m_timer), attotime_zero) > 0) &&
170         (attotime_compare(timer_timeleft(m_timer), attotime_never) != 0);
156171}
157172
158173
159174/*-------------------------------------------------
160    TIMER_CALLBACK( output_callback )
175   TIMER_CALLBACK( output_callback )
161176-------------------------------------------------*/
162177
163178TIMER_CALLBACK( ttl74123_device::output_callback )
164179{
165    ttl74123_device *dev = reinterpret_cast<ttl74123_device*>(ptr);
166    dev->output(param);
180   ttl74123_device *dev = reinterpret_cast<ttl74123_device*>(ptr);
181   dev->output(param);
167182}
168183
169184void ttl74123_device::output(INT32 param)
170185{
171    m_config.m_output_changed_cb(this, 0, param);
186   m_config.m_output_changed_cb(this, 0, param);
172187}
173188
174189
190//-------------------------------------------------
191//  set_output - set the output line state
192//-------------------------------------------------
193
175194void ttl74123_device::set_output()
176195{
177    int output = timer_running();
196   int output = timer_running();
178197
179    timer_set( &m_machine, attotime_zero, (void *)this, output, output_callback );
198   timer_set( &m_machine, attotime_zero, (void *)this, output, output_callback );
180199
181    if (LOG) logerror("74123 %s:  Output: %d\n", tag(), output);
200   if (LOG) logerror("74123 %s:  Output: %d\n", tag(), output);
182201}
183202
184203
204/*-------------------------------------------------
205    TIMER_CALLBACK( clear_callback )
206-------------------------------------------------*/
207
185208TIMER_CALLBACK( ttl74123_device::clear_callback )
186209{
187    ttl74123_device *dev = reinterpret_cast<ttl74123_device*>(ptr);
188    dev->clear();
210   ttl74123_device *dev = reinterpret_cast<ttl74123_device*>(ptr);
211   dev->clear();
189212}
190213
191214void ttl74123_device::clear()
192215{
193    int output = timer_running();
216   int output = timer_running();
194217
195    m_config.m_output_changed_cb(this, 0, output);
218   m_config.m_output_changed_cb(this, 0, output);
196219}
197220
198221
222//-------------------------------------------------
223//  start_pulse - begin timing
224//-------------------------------------------------
225
199226void ttl74123_device::start_pulse()
200227{
201    attotime duration = compute_duration();
228   attotime duration = compute_duration();
202229
203    if(timer_running())
204    {
205        /* retriggering, but not if we are called to quickly */
206        attotime delay_time = attotime_make(0, ATTOSECONDS_PER_SECOND * m_config.m_cap * 220);
230   if(timer_running())
231   {
232      /* retriggering, but not if we are called to quickly */
233      attotime delay_time = attotime_make(0, ATTOSECONDS_PER_SECOND * m_config.m_cap * 220);
207234
208        if(attotime_compare(timer_timeelapsed(m_timer), delay_time) >= 0)
209        {
210            timer_adjust_oneshot(m_timer, duration, 0);
235      if(attotime_compare(timer_timeelapsed(m_timer), delay_time) >= 0)
236      {
237         timer_adjust_oneshot(m_timer, duration, 0);
211238
212            if (LOG) logerror("74123 %s:  Retriggering pulse.  Duration: %f\n", tag(), attotime_to_double(duration));
213        }
214        else
215        {
216            if (LOG) logerror("74123 %s:  Retriggering failed.\n", tag());
217        }
218    }
219    else
220    {
221        /* starting */
222        timer_adjust_oneshot(m_timer, duration, 0);
239         if (LOG) logerror("74123 %s:  Retriggering pulse.  Duration: %f\n", tag(), attotime_to_double(duration));
240      }
241      else
242      {
243         if (LOG) logerror("74123 %s:  Retriggering failed.\n", tag());
244      }
245   }
246   else
247   {
248      /* starting */
249      timer_adjust_oneshot(m_timer, duration, 0);
223250
224        set_output();
251      set_output();
225252
226        if (LOG) logerror("74123 %s:  Starting pulse.  Duration: %f\n", tag(), attotime_to_double(duration));
227    }
253      if (LOG) logerror("74123 %s:  Starting pulse.  Duration: %f\n", tag(), attotime_to_double(duration));
254   }
228255}
229256
230257
258//-------------------------------------------------
259//  a_w - write register a data
260//-------------------------------------------------
261
231262WRITE8_DEVICE_HANDLER( ttl74123_a_w )
232263{
233    ttl74123_device *dev = reinterpret_cast<ttl74123_device *>(device);
234    dev->a_w(data);
264   ttl74123_device *dev = downcast<ttl74123_device *>(device);
265   dev->a_w(data);
235266}
236267
237268void ttl74123_device::a_w(UINT8 data)
238269{
239    /* start/regtrigger pulse if B=HI and falling edge on A (while clear is HI) */
240    if (!data && m_a && m_b && m_clear)
241    {
242        start_pulse();
243    }
270   /* start/regtrigger pulse if B=HI and falling edge on A (while clear is HI) */
271   if (!data && m_a && m_b && m_clear)
272   {
273      start_pulse();
274   }
244275
245    m_a = data;
276   m_a = data;
246277}
247278
248279
280//-------------------------------------------------
281//  b_w - write register b data
282//-------------------------------------------------
283
249284WRITE8_DEVICE_HANDLER( ttl74123_b_w )
250285{
251    ttl74123_device *dev = reinterpret_cast<ttl74123_device *>(device);
252    dev->b_w(data);
286   ttl74123_device *dev = downcast<ttl74123_device *>(device);
287   dev->b_w(data);
253288}
254289
255290void ttl74123_device::b_w(UINT8 data)
256291{
257    /* start/regtrigger pulse if A=LO and rising edge on B (while clear is HI) */
258    if (data && !m_b && !m_a && m_clear)
259    {
260        start_pulse();
261    }
292   /* start/regtrigger pulse if A=LO and rising edge on B (while clear is HI) */
293   if (data && !m_b && !m_a && m_clear)
294   {
295      start_pulse();
296   }
262297
263    m_b = data;
298   m_b = data;
264299}
265300
266301
302//-------------------------------------------------
303//  clear_w - write register clear data
304//-------------------------------------------------
305
267306WRITE8_DEVICE_HANDLER( ttl74123_clear_w )
268307{
269    ttl74123_device *dev = reinterpret_cast<ttl74123_device *>(device);
270    dev->clear_w(data);
308   ttl74123_device *dev = downcast<ttl74123_device *>(device);
309   dev->clear_w(data);
271310}
272311
273312void ttl74123_device::clear_w(UINT8 data)
274313{
275    /* start/regtrigger pulse if B=HI and A=LO and rising edge on clear */
276    if (data && !m_a && m_b && !m_clear)
277    {
278        start_pulse();
279    }
280    else if (!data)     /* clear the output  */
281    {
282        timer_adjust_oneshot(m_timer, attotime_zero, 0);
314   /* start/regtrigger pulse if B=HI and A=LO and rising edge on clear */
315   if (data && !m_a && m_b && !m_clear)
316   {
317      start_pulse();
318   }
319   else if (!data)    /* clear the output  */
320   {
321      timer_adjust_oneshot(m_timer, attotime_zero, 0);
283322
284        if (LOG) logerror("74123 #%s:  Cleared\n", tag() );
285    }
286    m_clear = data;
323      if (LOG) logerror("74123 #%s:  Cleared\n", tag() );
324   }
325   m_clear = data;
287326}
288327
328
329//-------------------------------------------------
330//  reset_w - reset device
331//-------------------------------------------------
332
289333WRITE8_DEVICE_HANDLER( ttl74123_reset_w )
290334{
291    ttl74123_device *dev = reinterpret_cast<ttl74123_device *>(device);
292    dev->reset_w();
335   ttl74123_device *dev = downcast<ttl74123_device *>(device);
336   dev->reset_w();
293337}
294338
295339void ttl74123_device::reset_w()
296340{
297    set_output();
341   set_output();
298342}
299343
300344const device_type TTL74123 = ttl74123_device_config::static_alloc_device_config;
src/emu/machine/timekpr.h
r8910r8911
1/*
2 * STmicroelectronics TIMEKEEPER SRAM
3 *
4 * Supports:
5 *           M48T02
6 *           M48T35
7 *           M48T58
8 *           MK48T08
9 *
10 */
1/***************************************************************************
112
12#if !defined( TIMEKPR_H )
13#define TIMEKPR_H ( 1 )
3    timekpr.h
144
15#include "devlegcy.h"
5    Various ST Microelectronics timekeeper SRAM implementations:
6       - M48T02
7       - M48T35
8       - M48T58
9       - MK48T08
1610
17typedef struct _timekeeper_config timekeeper_config;
18struct _timekeeper_config
19{
20   const char *data;
21};
11***************************************************************************/
2212
23DECLARE_LEGACY_NVRAM_DEVICE(M48T02, m48t02);
13#pragma once
2414
15#ifndef __TIMEKPR_H__
16#define __TIMEKPR_H__
17
18#include "emu.h"
19
20
21
22//**************************************************************************
23//  INTERFACE CONFIGURATION MACROS
24//**************************************************************************
25
2526#define MDRV_M48T02_ADD(_tag) \
2627   MDRV_DEVICE_ADD(_tag, M48T02, 0)
2728
28
29DECLARE_LEGACY_NVRAM_DEVICE(M48T35, m48t35);
30
3129#define MDRV_M48T35_ADD(_tag) \
3230   MDRV_DEVICE_ADD(_tag, M48T35, 0)
3331
34
35DECLARE_LEGACY_NVRAM_DEVICE(M48T58, m48t58);
36
3732#define MDRV_M48T58_ADD(_tag) \
3833   MDRV_DEVICE_ADD(_tag, M48T58, 0)
3934
40
41DECLARE_LEGACY_NVRAM_DEVICE(MK48T08, mk48t08);
42
4335#define MDRV_MK48T08_ADD(_tag) \
4436   MDRV_DEVICE_ADD(_tag, MK48T08, 0)
4537
4638
47/* memory handlers */
4839
40//**************************************************************************
41//  TYPE DEFINITIONS
42//**************************************************************************
43
44
45// ======================> timekeeper_config
46
47struct timekeeper_config
48{
49   const UINT8 *m_data;
50};
51
52// ======================> timekeeper_device_config
53
54class timekeeper_device_config :   public device_config,
55                           public device_config_nvram_interface,
56                           public timekeeper_config
57{
58   friend class timekeeper_device;
59   friend class m48t02_device_config;
60   friend class m48t35_device_config;
61   friend class m48t58_device_config;
62   friend class mk48t08_device_config;
63
64protected:
65   // construction/destruction
66   timekeeper_device_config(const machine_config &mconfig, const char *type, const char *tag, const device_config *owner, UINT32 clock);
67
68public:
69   // allocators
70   static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
71   virtual device_t *alloc_device(running_machine &machine) const;
72};
73
74
75// ======================> timekeeper_device
76
77class timekeeper_device :   public device_t,
78                     public device_nvram_interface
79{
80   friend class timekeeper_device_config;
81   friend class m48t02_device;
82   friend class m48t35_device;
83   friend class m48t58_device;
84   friend class mk48t08_device;
85
86   // construction/destruction
87   timekeeper_device(running_machine &_machine, const timekeeper_device_config &config);
88
89public:
90   void timekeeper_tick();
91
92   void write(UINT16 offset, UINT8 data);
93   UINT8 read(UINT16 offset);
94
95protected:
96   // device-level overrides
97   virtual void device_start();
98   virtual void device_reset();
99
100   // device_nvram_interface overrides
101   virtual void nvram_default();
102   virtual void nvram_read(mame_file &file);
103   virtual void nvram_write(mame_file &file);
104
105   // internal state
106   const timekeeper_device_config &m_config;
107
108   static TIMER_CALLBACK( timekeeper_tick_callback );
109
110private:
111   void counters_to_ram();
112   void counters_from_ram();
113
114   UINT8 m_control;
115   UINT8 m_seconds;
116   UINT8 m_minutes;
117   UINT8 m_hours;
118   UINT8 m_day;
119   UINT8 m_date;
120   UINT8 m_month;
121   UINT8 m_year;
122   UINT8 m_century;
123
124   UINT8 *m_data;
125   UINT8 *m_default_data;
126
127   int m_size;
128   int m_offset_control;
129   int m_offset_seconds;
130   int m_offset_minutes;
131   int m_offset_hours;
132   int m_offset_day;
133   int m_offset_date;
134   int m_offset_month;
135   int m_offset_year;
136   int m_offset_century;
137   int m_offset_flags;
138};
139
140
141// ======================> m48t02_device_config
142
143class m48t02_device_config : public timekeeper_device_config
144{
145   friend class mt48t02_device;
146
147   m48t02_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
148
149public:
150   // allocators
151   static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
152   virtual device_t *alloc_device(running_machine &machine) const;
153};
154
155
156// ======================> m48t02_device
157
158class m48t02_device : public timekeeper_device
159{
160   friend class timekeeper_device;
161   friend class m48t02_device_config;
162
163   // construction/destruction
164   m48t02_device(running_machine &_machine, const m48t02_device_config &config);
165
166protected:
167   // device-level overrides
168   virtual void device_start();
169};
170
171
172// ======================> m48t35_device_config
173
174class m48t35_device_config : public timekeeper_device_config
175{
176   friend class m48t35_device;
177   friend class timekeeper_device_config;
178
179   m48t35_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
180
181public:
182   // allocators
183   static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
184   virtual device_t *alloc_device(running_machine &machine) const;
185};
186
187
188// ======================> m48t35_device
189
190class m48t35_device : public timekeeper_device
191{
192   friend class m48t35_device_config;
193
194   // construction/destruction
195   m48t35_device(running_machine &_machine, const m48t35_device_config &config);
196
197protected:
198   // device-level overrides
199   virtual void device_start();
200};
201
202
203// ======================> m48t58_device_config
204
205class m48t58_device_config : public timekeeper_device_config
206{
207   friend class m48t58_device;
208   friend class timekeeper_device_config;
209
210   m48t58_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
211
212public:
213   // allocators
214   static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
215   virtual device_t *alloc_device(running_machine &machine) const;
216};
217
218
219// ======================> m48t58_device
220
221class m48t58_device : public timekeeper_device
222{
223   friend class m48t58_device_config;
224
225   // construction/destruction
226   m48t58_device(running_machine &_machine, const m48t58_device_config &config);
227
228protected:
229   // device-level overrides
230   virtual void device_start();
231};
232
233
234// ======================> mk48t08_device_config
235
236class mk48t08_device_config : public timekeeper_device_config
237{
238   friend class mk48t08_device;
239   friend class timekeeper_device_config;
240
241   mk48t08_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
242
243public:
244   // allocators
245   static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
246   virtual device_t *alloc_device(running_machine &machine) const;
247};
248
249
250// ======================> mk48t08_device
251
252class mk48t08_device : public timekeeper_device
253{
254   friend class mk48t08_device_config;
255
256   // construction/destruction
257   mk48t08_device(running_machine &_machine, const mk48t08_device_config &config);
258
259protected:
260   // device-level overrides
261   virtual void device_start();
262};
263
264
265// device type definition
266extern const device_type M48T02;
267extern const device_type M48T35;
268extern const device_type M48T58;
269extern const device_type MK48T08;
270
271
272
273//**************************************************************************
274//  READ/WRITE HANDLERS
275//**************************************************************************
276
49277WRITE8_DEVICE_HANDLER( timekeeper_w );
50278READ8_DEVICE_HANDLER( timekeeper_r );
51279
52#endif
280#endif // __TIMEKPR_H__
src/emu/machine/6532riot.c
r8910r8911
4040//-------------------------------------------------
4141
4242riot6532_device_config::riot6532_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
43    : device_config(mconfig, static_alloc_device_config, "RIOT6532", tag, owner, clock)
43   : device_config(mconfig, static_alloc_device_config, "RIOT6532", tag, owner, clock)
4444{
4545}
4646
r8910r8911
5252
5353device_config *riot6532_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
5454{
55    return global_alloc(riot6532_device_config(mconfig, tag, owner, clock));
55   return global_alloc(riot6532_device_config(mconfig, tag, owner, clock));
5656}
5757
5858
r8910r8911
6262
6363device_t *riot6532_device_config::alloc_device(running_machine &machine) const
6464{
65    return auto_alloc(&machine, riot6532_device(machine, *this));
65   return auto_alloc(&machine, riot6532_device(machine, *this));
6666}
6767
6868
r8910r8911
7474
7575void riot6532_device_config::device_config_complete()
7676{
77    // inherit a copy of the static data
78    const riot6532_interface *intf = reinterpret_cast<const riot6532_interface *>(static_config());
79    if (intf != NULL)
80    {
81        *static_cast<riot6532_interface *>(this) = *intf;
82    }
77   // inherit a copy of the static data
78   const riot6532_interface *intf = reinterpret_cast<const riot6532_interface *>(static_config());
79   if (intf != NULL)
80   {
81      *static_cast<riot6532_interface *>(this) = *intf;
82   }
8383
84    // or initialize to defaults if none provided
85    else
86    {
87        memset(&m_in_a_func, 0, sizeof(m_in_a_func));
88        memset(&m_in_b_func, 0, sizeof(m_in_b_func));
89        memset(&m_out_a_func, 0, sizeof(m_out_a_func));
90        memset(&m_out_b_func, 0, sizeof(m_out_b_func));
91        memset(&m_irq_func, 0, sizeof(m_irq_func));
92    }
84   // or initialize to defaults if none provided
85   else
86   {
87      memset(&m_in_a_func, 0, sizeof(m_in_a_func));
88      memset(&m_in_b_func, 0, sizeof(m_in_b_func));
89      memset(&m_out_a_func, 0, sizeof(m_out_a_func));
90      memset(&m_out_b_func, 0, sizeof(m_out_b_func));
91      memset(&m_irq_func, 0, sizeof(m_irq_func));
92   }
9393}
9494
9595
r8910r8911
108108   int state = (m_irqstate & m_irqenable);
109109
110110   if (m_irq_func.write != NULL)
111    {
111   {
112112      devcb_call_write_line(&m_irq_func, (state != 0) ? ASSERT_LINE : CLEAR_LINE);
113    }
113   }
114114   else
115    {
115   {
116116      logerror("%s:6532RIOT chip #%d: no irq callback function\n", cpuexec_describe_context(&m_machine), m_index);
117    }
117   }
118118}
119119
120120
r8910r8911
156156{
157157   /* if idle, return 0 */
158158   if (m_timerstate == TIMER_IDLE)
159    {
159   {
160160      return 0;
161    }
161   }
162162
163163   /* if counting, return the number of ticks remaining */
164164   else if (m_timerstate == TIMER_COUNTING)
165    {
165   {
166166      return attotime_to_ticks(timer_timeleft(m_timer), clock()) >> m_timershift;
167    }
167   }
168168
169169   /* if finishing, return the number of ticks without the shift */
170170   else
171    {
171   {
172172      return attotime_to_ticks(timer_timeleft(m_timer), clock());
173    }
173   }
174174}
175175
176176
r8910r8911
182182
183183TIMER_CALLBACK( riot6532_device::timer_end_callback )
184184{
185    riot6532_device *via = reinterpret_cast<riot6532_device *>(ptr);
186    via->timer_end();
185   riot6532_device *via = reinterpret_cast<riot6532_device *>(ptr);
186   via->timer_end();
187187}
188188
189189void riot6532_device::timer_end()
r8910r8911
220220
221221WRITE8_DEVICE_HANDLER( riot6532_w )
222222{
223    riot6532_device *via = reinterpret_cast<riot6532_device *>(device);
224    via->reg_w(offset, data);
223   riot6532_device *via = downcast<riot6532_device *>(device);
224   via->reg_w(offset, data);
225225}
226226
227227void riot6532_device::reg_w(UINT8 offset, UINT8 data)
r8910r8911
244244
245245      /* writes here clear the timer flag */
246246      if (m_timerstate != TIMER_FINISHING || get_timer() != 0xff)
247        {
247      {
248248         m_irqstate &= ~TIMER_FLAG;
249        }
249      }
250250      update_irqstate();
251251
252252      /* update the timer */
r8910r8911
260260   {
261261      /* A1 contains the A7 IRQ enable */
262262      if (offset & 2)
263        {
263      {
264264         m_irqenable |= PA7_FLAG;
265        }
265      }
266266      else
267        {
267      {
268268         m_irqenable &= ~PA7_FLAG;
269        }
269      }
270270
271271      /* A0 specifies the edge detect direction: 0=negative, 1=positive */
272272      m_pa7dir = (offset & 1) << 7;
r8910r8911
280280
281281      /* if A0 == 1, we are writing to the port's DDR */
282282      if (offset & 1)
283        {
283      {
284284         port->m_ddr = data;
285        }
285      }
286286
287287      /* if A0 == 0, we are writing to the port's output */
288288      else
289289      {
290290         port->m_out = data;
291291         if (port->m_out_func.write != NULL)
292            {
292         {
293293            devcb_call_write8(&port->m_out_func, 0, data);
294            }
294         }
295295         else
296            {
296         {
297297            logerror("%s:6532RIOT chip %s: Port %c is being written to but has no handler. %02X\n", cpuexec_describe_context(&m_machine), tag(), 'A' + (offset & 1), data);
298            }
298         }
299299      }
300300
301301      /* writes to port A need to update the PA7 state */
302302      if (port == &m_port[0])
303        {
303      {
304304         update_pa7_state();
305        }
305      }
306306   }
307307}
308308
r8910r8911
313313
314314READ8_DEVICE_HANDLER( riot6532_r )
315315{
316    riot6532_device *via = reinterpret_cast<riot6532_device *>(device);
317    return via->reg_r(offset);
316   riot6532_device *via = downcast<riot6532_device *>(device);
317   return via->reg_r(offset);
318318}
319319
320320UINT8 riot6532_device::reg_r(UINT8 offset)
r8910r8911
338338
339339      /* A3 contains the timer IRQ enable */
340340      if (offset & 8)
341        {
341      {
342342         m_irqenable |= TIMER_FLAG;
343        }
343      }
344344      else
345        {
345      {
346346         m_irqenable &= ~TIMER_FLAG;
347        }
347      }
348348
349349      /* implicitly clears the timer flag */
350350      if (m_timerstate != TIMER_FINISHING || val != 0xff)
351        {
351      {
352352         m_irqstate &= ~TIMER_FLAG;
353        }
353      }
354354      update_irqstate();
355355   }
356356
r8910r8911
362362
363363      /* if A0 == 1, we are reading the port's DDR */
364364      if (offset & 1)
365        {
365      {
366366         val = port->m_ddr;
367        }
367      }
368368
369369      /* if A0 == 0, we are reading the port as an input */
370370      else
r8910r8911
376376
377377            /* changes to port A need to update the PA7 state */
378378            if (port == &m_port[0])
379                {
379            {
380380               update_pa7_state();
381                }
381            }
382382         }
383383         else
384            {
384         {
385385            logerror("%s:6532RIOT chip %s: Port %c is being read but has no handler\n", cpuexec_describe_context(&m_machine), tag(), 'A' + (offset & 1));
386            }
386         }
387387
388388         /* apply the DDR to the result */
389389         val = apply_ddr(port);
r8910r8911
399399
400400void riot6532_porta_in_set(running_device *device, UINT8 data, UINT8 mask)
401401{
402    riot6532_device *via = reinterpret_cast<riot6532_device *>(device);
403    via->porta_in_set(data, mask);
402   riot6532_device *via = downcast<riot6532_device *>(device);
403   via->porta_in_set(data, mask);
404404}
405405
406406void riot6532_device::porta_in_set(UINT8 data, UINT8 mask)
r8910r8911
416416
417417void riot6532_portb_in_set(running_device *device, UINT8 data, UINT8 mask)
418418{
419    riot6532_device *via = reinterpret_cast<riot6532_device *>(device);
420    via->portb_in_set(data, mask);
419   riot6532_device *via = downcast<riot6532_device *>(device);
420   via->portb_in_set(data, mask);
421421}
422422
423423void riot6532_device::portb_in_set(UINT8 data, UINT8 mask)
r8910r8911
432432
433433UINT8 riot6532_porta_in_get(running_device *device)
434434{
435    riot6532_device *via = reinterpret_cast<riot6532_device *>(device);
436    return via->porta_in_get();
435   riot6532_device *via = downcast<riot6532_device *>(device);
436   return via->porta_in_get();
437437}
438438
439439UINT8 riot6532_device::porta_in_get()
r8910r8911
448448
449449UINT8 riot6532_portb_in_get(running_device *device)
450450{
451    riot6532_device *via = reinterpret_cast<riot6532_device *>(device);
452    return via->portb_in_get();
451   riot6532_device *via = downcast<riot6532_device *>(device);
452   return via->portb_in_get();
453453}
454454
455455UINT8 riot6532_device::portb_in_get()
r8910r8911
464464
465465UINT8 riot6532_porta_out_get(running_device *device)
466466{
467    riot6532_device *via = reinterpret_cast<riot6532_device *>(device);
468    return via->porta_out_get();
467   riot6532_device *via = downcast<riot6532_device *>(device);
468   return via->porta_out_get();
469469}
470470
471471UINT8 riot6532_device::porta_out_get()
r8910r8911
480480
481481UINT8 riot6532_portb_out_get(running_device *device)
482482{
483    riot6532_device *via = reinterpret_cast<riot6532_device *>(device);
484    return via->portb_out_get();
483   riot6532_device *via = downcast<riot6532_device *>(device);
484   return via->portb_out_get();
485485}
486486
487487UINT8 riot6532_device::portb_out_get()
r8910r8911
499499//-------------------------------------------------
500500
501501riot6532_device::riot6532_device(running_machine &_machine, const riot6532_device_config &config)
502    : device_t(_machine, config),
503      m_config(config)
502   : device_t(_machine, config),
503     m_config(config)
504504{
505505}
506506
r8910r8911
517517   m_index = m_machine.m_devicelist.index(RIOT6532, tag());
518518
519519   /* configure the ports */
520    devcb_resolve_read8(&m_port[0].m_in_func, &m_config.m_in_a_func, this);
521    devcb_resolve_write8(&m_port[0].m_out_func, &m_config.m_out_a_func, this);
522    devcb_resolve_read8(&m_port[1].m_in_func, &m_config.m_in_b_func, this);
523    devcb_resolve_write8(&m_port[1].m_out_func, &m_config.m_out_b_func, this);
520   devcb_resolve_read8(&m_port[0].m_in_func, &m_config.m_in_a_func, this);
521   devcb_resolve_write8(&m_port[0].m_out_func, &m_config.m_out_a_func, this);
522   devcb_resolve_read8(&m_port[1].m_in_func, &m_config.m_in_b_func, this);
523   devcb_resolve_write8(&m_port[1].m_out_func, &m_config.m_out_b_func, this);
524524
525525   /* resolve irq func */
526    devcb_resolve_write_line(&m_irq_func, &m_config.m_irq_func, this);
526   devcb_resolve_write_line(&m_irq_func, &m_config.m_irq_func, this);
527527
528528   /* allocate timers */
529    m_timer = timer_alloc(&m_machine, timer_end_callback, (void *)this);
529   m_timer = timer_alloc(&m_machine, timer_end_callback, (void *)this);
530530
531531   /* register for save states */
532    state_save_register_device_item(this, 0, m_port[0].m_in);
533    state_save_register_device_item(this, 0, m_port[0].m_out);
534    state_save_register_device_item(this, 0, m_port[0].m_ddr);
535    state_save_register_device_item(this, 0, m_port[1].m_in);
536    state_save_register_device_item(this, 0, m_port[1].m_out);
537    state_save_register_device_item(this, 0, m_port[1].m_ddr);
532   state_save_register_device_item(this, 0, m_port[0].m_in);
533   state_save_register_device_item(this, 0, m_port[0].m_out);
534   state_save_register_device_item(this, 0, m_port[0].m_ddr);
535   state_save_register_device_item(this, 0, m_port[1].m_in);
536   state_save_register_device_item(this, 0, m_port[1].m_out);
537   state_save_register_device_item(this, 0, m_port[1].m_ddr);
538538
539    state_save_register_device_item(this, 0, m_irqstate);
540    state_save_register_device_item(this, 0, m_irqenable);
539   state_save_register_device_item(this, 0, m_irqstate);
540   state_save_register_device_item(this, 0, m_irqenable);
541541
542    state_save_register_device_item(this, 0, m_pa7dir);
543    state_save_register_device_item(this, 0, m_pa7prev);
542   state_save_register_device_item(this, 0, m_pa7dir);
543   state_save_register_device_item(this, 0, m_pa7prev);
544544
545    state_save_register_device_item(this, 0, m_timershift);
546    state_save_register_device_item(this, 0, m_timerstate);
545   state_save_register_device_item(this, 0, m_timershift);
546   state_save_register_device_item(this, 0, m_timerstate);
547547}
548548
549549
src/emu/machine/6821pia.h
r8910r8911
33    Motorola 6821 PIA interface and emulation
44
55    Notes:
6        * pia6821_get_port_b_z_mask() gives the caller the bitmask
7          that show which bits are high-impendance when
8          reading port B, thus neither 0 or 1.
9          pia6821_get_output_cb2_z() returns the same
10          information for the CB2 pin
11        * pia6821_set_port_a_z_mask allows the input callback to
12          indicate which port A bits are disconnected.
13          For these bit, the read operation will return the
14          output buffer's contents
15        * the 'alt' interface functions are used when the A0 and A1
16          address bits are swapped
17        * all 'int' data or return values are Boolean
6        * get_port_b_z_mask() gives the caller the bitmask that shows
7          which bits are high-impendance when reading port B, and thus
8          neither 0 or 1. get_output_cb2_z() returns the same info
9          for the CB2 pin.
10        * set_port_a_z_mask allows the input callback to indicate
11          which port A bits are disconnected. For these bits, the
12          read operation will return the output buffer's contents.
13        * The 'alt' interface functions are used when the A0 and A1
14          address bits are swapped.
15        * All 'int' data or return values are bool, and should be
16          converted to bool at some point.
1817
1918**********************************************************************/
2019
src/emu/machine/7474.c
r8910r8911
7575}
7676
7777
78//-------------------------------------------------
79//  static_set_target_tag - configuration helper
80//  to set the target tag
81//-------------------------------------------------
7882
83void ttl7474_device_config::static_set_target_tag(device_config *device, const char *tag)
84{
85   ttl7474_device_config *ttl7474 = downcast<ttl7474_device_config *>(device);
86   ttl7474->m_output_cb.tag = tag;
87   ttl7474->m_comp_output_cb.tag = tag;
88}
89
90
7991//-------------------------------------------------
80//  device_config_complete - perform any
81//  operations now that the configuration is
82//  complete
92//  static_set_output_cb - configuration helper
93//  to set the output callback
8394//-------------------------------------------------
8495
85void ttl7474_device_config::device_config_complete()
96void ttl7474_device_config::static_set_output_cb(device_config *device, write_line_device_func callback)
8697{
87   m_target_tag = reinterpret_cast<const char *>(m_inline_data[INLINE_TARGET_TAG]);
88   m_base_output_cb = reinterpret_cast<void (*)(device_t *device, INT32)>(m_inline_data[INLINE_OUTPUT_CB]);
89   m_base_comp_output_cb = reinterpret_cast<void (*)(device_t *device, INT32)>(m_inline_data[INLINE_COMP_OUTPUT_CB]);
98   ttl7474_device_config *ttl7474 = downcast<ttl7474_device_config *>(device);
99   if (callback != NULL)
100   {
101      ttl7474->m_output_cb.type = DEVCB_TYPE_DEVICE;
102      ttl7474->m_output_cb.writeline = callback;
103   }
104   else
105      ttl7474->m_output_cb.type = DEVCB_TYPE_NULL;
106}
90107
91   m_output_cb.type = DEVCB_TYPE_DEVICE;
92   m_output_cb.tag = m_target_tag;
93   m_output_cb.writeline = m_base_output_cb;
94108
95   m_comp_output_cb.type = DEVCB_TYPE_DEVICE;
96   m_comp_output_cb.tag = m_target_tag;
97   m_comp_output_cb.writeline = m_base_comp_output_cb;
109//-------------------------------------------------
110//  static_set_comp_output_cb - configuration
111//  helper to set the comp. output callback
112//-------------------------------------------------
113
114void ttl7474_device_config::static_set_comp_output_cb(device_config *device, write_line_device_func callback)
115{
116   ttl7474_device_config *ttl7474 = downcast<ttl7474_device_config *>(device);
117   if (callback != NULL)
118   {
119      ttl7474->m_comp_output_cb.type = DEVCB_TYPE_DEVICE;
120      ttl7474->m_comp_output_cb.writeline = callback;
121   }
122   else
123      ttl7474->m_comp_output_cb.type = DEVCB_TYPE_NULL;
98124}
99125
100126
r8910r8911
130156    state_save_register_device_item(this, 0, m_last_output);
131157    state_save_register_device_item(this, 0, m_last_output_comp);
132158
133    devcb_resolve_write_line(&m_output_cb, &m_config.m_output_cb, this);
134    devcb_resolve_write_line(&m_comp_output_cb, &m_config.m_comp_output_cb, this);
159   devcb_resolve_write_line(&m_output_cb, &m_config.m_output_cb, this);
160   devcb_resolve_write_line(&m_comp_output_cb, &m_config.m_comp_output_cb, this);
135161}
136162
137163//-------------------------------------------------
src/emu/machine/7474.h
r8910r8911
6363    MDRV_7474_COMP_OUTPUT_CB(_comp_output_cb)
6464
6565#define MDRV_7474_TARGET_TAG(_target_tag) \
66    MDRV_DEVICE_INLINE_DATAPTR(ttl7474_device_config::INLINE_TARGET_TAG, _target_tag)
66   ttl7474_device_config::static_set_target_tag(device, _target_tag); \
6767
6868#define MDRV_7474_OUTPUT_CB(_cb) \
69    MDRV_DEVICE_INLINE_DATAPTR(ttl7474_device_config::INLINE_OUTPUT_CB, _cb)
69   ttl7474_device_config::static_set_output_cb(device, _cb); \
7070
7171#define MDRV_7474_COMP_OUTPUT_CB(_cb) \
72    MDRV_DEVICE_INLINE_DATAPTR(ttl7474_device_config::INLINE_COMP_OUTPUT_CB, _cb)
72   ttl7474_device_config::static_set_comp_output_cb(device, _cb); \
7373
7474
7575
r8910r8911
9191    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
9292    virtual device_t *alloc_device(running_machine &machine) const;
9393
94    // inline configuration indexes go here
95    enum
96    {
97      INLINE_TARGET_TAG,
98        INLINE_OUTPUT_CB,
99        INLINE_COMP_OUTPUT_CB
100    };
94   // inline configuration helpers
95   static void static_set_target_tag(device_config *device, const char *tag);
96   static void static_set_output_cb(device_config *device, write_line_device_func callback);
97   static void static_set_comp_output_cb(device_config *device, write_line_device_func callback);
10198
10299protected:
103    // device_config overrides
104    virtual void device_config_complete();
105
106100    // internal state goes here
107   const char *m_target_tag;
108   void (*m_base_output_cb)(device_t *device, INT32);
109   void (*m_base_comp_output_cb)(device_t *device, INT32);
110
111101    devcb_write_line m_output_cb;
112102    devcb_write_line m_comp_output_cb;
113103};
src/emu/machine/6840ptm.c
r8910r8911
3535
3636#include "emu.h"
3737#include "6840ptm.h"
38#include "devhelpr.h"
3839
3940
4041#define PTMVERBOSE 0
4142#define PLOG(x) do { if (PTMVERBOSE) logerror x; } while (0)
4243
4344/***************************************************************************
44    PARAMETERS / PROTOTYPES
45    LOCAL VARIABLES
4546***************************************************************************/
4647
47enum
48const char *const ptm6840_device::opmode[] =
4849{
49   PTM_6840_CTRL1   = 0,
50   PTM_6840_CTRL2   = 1,
51   PTM_6840_STATUS  = 1,
52   PTM_6840_MSBBUF1 = 2,
53   PTM_6840_LSB1    = 3,
54   PTM_6840_MSBBUF2 = 4,
55   PTM_6840_LSB2    = 5,
56   PTM_6840_MSBBUF3 = 6,
57   PTM_6840_LSB3    = 7,
58};
59
60static const char *const opmode[] =
61{
6250   "000 continuous mode",
6351   "001 freq comparison mode",
6452   "010 continuous mode",
r8910r8911
6957   "111 pulse width comparison mode"
7058};
7159
72static void ptm6840_timeout(running_device *device, int idx);
73
7460/***************************************************************************
75    TYPE DEFINITIONS
61    IMPLEMENTATION
7662***************************************************************************/
7763
78typedef struct _ptm6840_state ptm6840_state;
79struct _ptm6840_state
64GENERIC_DEVICE_CONFIG_SETUP(ptm6840, "PTM6840")
65
66const device_type PTM6840 = ptm6840_device_config::static_alloc_device_config;
67
68//-------------------------------------------------
69//  device_config_complete - perform any
70//  operations now that the configuration is
71//  complete
72//-------------------------------------------------
73
74void ptm6840_device_config::device_config_complete()
8075{
81   double internal_clock;
82   double external_clock[3];
83   devcb_resolved_write8 out_func[3];   // function to call when output[idx] changes
84   devcb_resolved_write_line irq_func;   // function called if IRQ line changes
76   // inherit a copy of the static data
77   const ptm6840_interface *intf = reinterpret_cast<const ptm6840_interface *>(static_config());
78   if (intf != NULL)
79   {
80      *static_cast<ptm6840_interface *>(this) = *intf;
81   }
8582
86   UINT8 control_reg[3];
87   UINT8 output[3]; /* Output states */
88   UINT8 gate[3];   /* Input gate states */
89   UINT8 clock[3];  /* Clock states */
90   UINT8 enabled[3];
91   UINT8 mode[3];
92   UINT8 fired[3];
93   UINT8 t3_divisor;
94   UINT8 t3_scaler;
95   UINT8 IRQ;
96   UINT8 status_reg;
97   UINT8 status_read_since_int;
98   UINT8 lsb_buffer;
99   UINT8 msb_buffer;
83   // or initialize to defaults if none provided
84   else
85   {
86      m_internal_clock = 0.0;
87      m_external_clock[0] = 0.0;
88      m_external_clock[1] = 0.0;
89      m_external_clock[2] = 0.0;
90      memset(&m_irq_func, 0, sizeof(m_irq_func));
91       memset(&m_out_func[0], 0, sizeof(m_out_func[0]));
92       memset(&m_out_func[1], 0, sizeof(m_out_func[1]));
93       memset(&m_out_func[2], 0, sizeof(m_out_func[2]));
94   }
95}
10096
101   /* Each PTM has 3 timers */
102   emu_timer *timer[3];
10397
104   UINT16 latch[3];
105   UINT16 counter[3];
106};
98//-------------------------------------------------
99//  ptm6840_device - constructor
100//-------------------------------------------------
107101
102ptm6840_device::ptm6840_device(running_machine &_machine, const ptm6840_device_config &config)
103    : device_t(_machine, config),
104      m_config(config)
105{
108106
109/***************************************************************************
110    INLINE FUNCTIONS
111***************************************************************************/
107}
112108
113INLINE ptm6840_state *get_safe_token(running_device *device)
109
110//-------------------------------------------------
111//  device_start - device-specific startup
112//-------------------------------------------------
113
114void ptm6840_device::device_start()
114115{
115   assert(device != NULL);
116   assert((device->type() == PTM6840));
117   return (ptm6840_state *)downcast<legacy_device_base *>(device)->token();
116   m_internal_clock = m_config.m_internal_clock;
117
118   /* resolve callbacks */
119   for (int i = 0; i < 3; i++)
120   {
121      devcb_resolve_write8(&m_out_func[i], &m_config.m_out_func[i], this);
122   }
123
124   for (int i = 0; i < 3; i++)
125   {
126      if ( m_config.m_external_clock[i] )
127      {
128         m_external_clock[i] = m_config.m_external_clock[i];
129      }
130      else
131      {
132         m_external_clock[i] = 1;
133      }
134   }
135
136
137   m_timer[0] = timer_alloc(&m_machine, ptm6840_timer1_cb, (void *)this);
138   m_timer[1] = timer_alloc(&m_machine, ptm6840_timer2_cb, (void *)this);
139   m_timer[2] = timer_alloc(&m_machine, ptm6840_timer3_cb, (void *)this);
140
141   for (int i = 0; i < 3; i++)
142   {
143      timer_enable(m_timer[i], FALSE);
144   }
145
146   devcb_resolve_write_line(&m_irq_func, &m_config.m_irq_func, this);
147
148   /* register for state saving */
149   state_save_register_device_item(this, 0, m_lsb_buffer);
150   state_save_register_device_item(this, 0, m_msb_buffer);
151   state_save_register_device_item(this, 0, m_status_read_since_int);
152   state_save_register_device_item(this, 0, m_status_reg);
153   state_save_register_device_item(this, 0, m_t3_divisor);
154   state_save_register_device_item(this, 0, m_t3_scaler);
155   state_save_register_device_item(this, 0, m_internal_clock);
156   state_save_register_device_item(this, 0, m_IRQ);
157
158   state_save_register_device_item_array(this, 0, m_control_reg);
159   state_save_register_device_item_array(this, 0, m_output);
160   state_save_register_device_item_array(this, 0, m_gate);
161   state_save_register_device_item_array(this, 0, m_clk);
162   state_save_register_device_item_array(this, 0, m_mode);
163   state_save_register_device_item_array(this, 0, m_fired);
164   state_save_register_device_item_array(this, 0, m_enabled);
165   state_save_register_device_item_array(this, 0, m_external_clock);
166   state_save_register_device_item_array(this, 0, m_counter);
167   state_save_register_device_item_array(this, 0, m_latch);
118168}
119169
120INLINE const ptm6840_interface *get_interface(running_device *device)
170
171//-------------------------------------------------
172//  device_reset - device-specific reset
173//-------------------------------------------------
174
175void ptm6840_device::device_reset()
121176{
122   assert(device != NULL);
123   assert((device->type() == PTM6840));
124   return (const ptm6840_interface *) device->baseconfig().static_config();
177   m_control_reg[2]       = 0;
178   m_control_reg[1]       = 0;
179   m_control_reg[0]       = 1;
180   m_status_reg          = 0;
181   m_t3_divisor          = 1;
182   m_status_read_since_int = 0;
183   m_IRQ                   = 0;
184
185   for (int i = 0; i < 3; i++)
186   {
187      m_counter[i] = 0xffff;
188      m_latch[i]   = 0xffff;
189      m_output[i]  = 0;
190      m_fired[i]   = 0;
191   }
125192}
126193
127194
128/***************************************************************************
129    IMPLEMENTATION
130***************************************************************************/
131195
132196/*-------------------------------------------------
133197    ptm6840_get_status - Get enabled status
r8910r8911
135199
136200int ptm6840_get_status( running_device *device, int clock )
137201{
138   ptm6840_state *ptm6840 = get_safe_token(device);
139   return ptm6840->enabled[clock - 1];
202   return downcast<ptm6840_device*>(device)->ptm6840_get_status(clock);
140203}
141204
205int ptm6840_device::ptm6840_get_status( int clock )
206{
207   return m_enabled[clock - 1];
208}
209
210
211
142212/*-------------------------------------------------
143213    ptm6840_get_irq - Get IRQ state
144214-------------------------------------------------*/
145215
146216int ptm6840_get_irq( running_device *device )
147217{
148   ptm6840_state *ptm6840 = get_safe_token(device);
149   return ptm6840->IRQ;
218   return downcast<ptm6840_device*>(device)->ptm6840_get_irq();
150219}
151220
221int ptm6840_device::ptm6840_get_irq()
222{
223   return m_IRQ;
224}
225
226
227
152228/*-------------------------------------------------
153229    subtract_from_counter - Subtract from Counter
154230-------------------------------------------------*/
155231
156static void subtract_from_counter( running_device *device, int counter, int count )
232void ptm6840_device::subtract_from_counter(int counter, int count)
157233{
158   ptm6840_state *ptm6840 = get_safe_token(device);
159234   double clock;
160   attotime duration;
161235
162236   /* Determine the clock frequency for this timer */
163   if (ptm6840->control_reg[counter] & 0x02)
164      clock = ptm6840->internal_clock;
237   if (m_control_reg[counter] & 0x02)
238   {
239      clock = m_internal_clock;
240   }
165241   else
166      clock = ptm6840->external_clock[counter];
242   {
243      clock = m_external_clock[counter];
244   }
167245
168246   /* Dual-byte mode */
169   if (ptm6840->control_reg[counter] & 0x04)
247   if (m_control_reg[counter] & 0x04)
170248   {
171      int lsb = ptm6840->counter[counter] & 0xff;
172      int msb = ptm6840->counter[counter] >> 8;
249      int lsb = m_counter[counter] & 0xff;
250      int msb = m_counter[counter] >> 8;
173251
174252      /* Count the clocks */
175253      lsb -= count;
r8910r8911
178256      while (lsb < 0)
179257      {
180258         /* Borrow from the MSB */
181         lsb += (ptm6840->latch[counter] & 0xff) + 1;
259         lsb += (m_latch[counter] & 0xff) + 1;
182260         msb--;
183261
184262         /* If MSB goes less than zero, we've expired */
185263         if (msb < 0)
186264         {
187            ptm6840_timeout(device, counter);
188            msb = (ptm6840->latch[counter] >> 8) + 1;
265            ptm6840_timeout(counter);
266            msb = (m_latch[counter] >> 8) + 1;
189267         }
190268      }
191269
192270      /* Store the result */
193      ptm6840->counter[counter] = (msb << 8) | lsb;
271      m_counter[counter] = (msb << 8) | lsb;
194272   }
195273
196274   /* Word mode */
197275   else
198276   {
199      int word = ptm6840->counter[counter];
277      int word = m_counter[counter];
200278
201279      /* Count the clocks */
202280      word -= count;
r8910r8911
205283      while (word < 0)
206284      {
207285         /* Borrow from the MSB */
208         word += ptm6840->latch[counter] + 1;
286         word += m_latch[counter] + 1;
209287
210288         /* We've expired */
211         ptm6840_timeout(device, counter);
289         ptm6840_timeout(counter);
212290      }
213291
214292      /* Store the result */
215      ptm6840->counter[counter] = word;
293      m_counter[counter] = word;
216294   }
217295
218   if (ptm6840->enabled[counter])
296   if (m_enabled[counter])
219297   {
220      duration = attotime_mul(ATTOTIME_IN_HZ(clock), ptm6840->counter[counter]);
298      attotime duration = attotime_mul(ATTOTIME_IN_HZ(clock), m_counter[counter]);
221299
222300      if (counter == 2)
223         duration = attotime_mul(duration, ptm6840->t3_divisor);
301      {
302         duration = attotime_mul(duration, m_t3_divisor);
303      }
224304
225      timer_adjust_oneshot(ptm6840->timer[counter], duration, 0);
305      timer_adjust_oneshot(m_timer[counter], duration, 0);
226306   }
227307}
228308
309
310
229311/*-------------------------------------------------
230312    ptm_tick
231313-------------------------------------------------*/
232314
233static void ptm_tick( running_device *device, int counter, int count )
315void ptm6840_device::ptm_tick(int counter, int count)
234316{
235   ptm6840_state *ptm6840 = get_safe_token(device);
236
237317   if (counter == 2)
238318   {
239      ptm6840->t3_scaler += count;
319      m_t3_scaler += count;
240320
241      if ( ptm6840->t3_scaler > ptm6840->t3_divisor - 1)
321      if ( m_t3_scaler > m_t3_divisor - 1)
242322      {
243         subtract_from_counter(device, counter, 1);
244         ptm6840->t3_scaler = 0;
323         subtract_from_counter(counter, 1);
324         m_t3_scaler = 0;
245325      }
246326   }
247327   else
248328   {
249      subtract_from_counter(device, counter, count);
329      subtract_from_counter(counter, count);
250330   }
251331}
252332
333
334
253335/*-------------------------------------------------
254336    update_interrupts - Update Internal Interrupts
255337-------------------------------------------------*/
256338
257INLINE void update_interrupts( running_device *device )
339void update_interrupts( running_device *device )
258340{
259   ptm6840_state *ptm6840 = get_safe_token(device);
260   int new_state;
341   downcast<ptm6840_device*>(device)->update_interrupts();
342}
261343
262   new_state = ((ptm6840->status_reg & 0x01) && (ptm6840->control_reg[0] & 0x40)) ||
263            ((ptm6840->status_reg & 0x02) && (ptm6840->control_reg[1] & 0x40)) ||
264            ((ptm6840->status_reg & 0x04) && (ptm6840->control_reg[2] & 0x40));
344void ptm6840_device::update_interrupts()
345{
346   int new_state = ((m_status_reg & 0x01) && (m_control_reg[0] & 0x40)) ||
347               ((m_status_reg & 0x02) && (m_control_reg[1] & 0x40)) ||
348               ((m_status_reg & 0x04) && (m_control_reg[2] & 0x40));
265349
266   if (new_state != ptm6840->IRQ)
350   if (new_state != m_IRQ)
267351   {
268      ptm6840->IRQ = new_state;
352      m_IRQ = new_state;
269353
270      if (ptm6840->IRQ)
271         ptm6840->status_reg |= 0x80;
354      if (m_IRQ)
355      {
356         m_status_reg |= 0x80;
357      }
272358      else
273         ptm6840->status_reg &= ~0x80;
359      {
360         m_status_reg &= ~0x80;
361      }
274362
275      devcb_call_write_line(&ptm6840->irq_func, ptm6840->IRQ);
363      devcb_call_write_line(&m_irq_func, m_IRQ);
276364   }
277365}
278366
367
368
279369/*-------------------------------------------------
280370    compute_counter - Compute Counter
281371-------------------------------------------------*/
282372
283static UINT16 compute_counter( running_device *device, int counter )
373UINT16 ptm6840_device::compute_counter( int counter )
284374{
285   ptm6840_state *ptm6840 = get_safe_token(device);
286375   double clock;
287   int remaining = 0;
288376
289377   /* If there's no timer, return the count */
290   if (!ptm6840->enabled[counter])
378   if (!m_enabled[counter])
291379   {
292      PLOG(("MC6840 #%s: read counter(%d): %d\n", device->tag(), counter, ptm6840->counter[counter]));
293      return ptm6840->counter[counter];
380      PLOG(("MC6840 #%s: read counter(%d): %d\n", tag(), counter, m_counter[counter]));
381      return m_counter[counter];
294382   }
295383
296384   /* determine the clock frequency for this timer */
297   if (ptm6840->control_reg[counter] & 0x02)
385   if (m_control_reg[counter] & 0x02)
298386   {
299      clock = ptm6840->internal_clock;
300      PLOG(("MC6840 #%s: %d internal clock freq %f \n", device->tag(), counter, clock));
387      clock = m_internal_clock;
388      PLOG(("MC6840 #%s: %d internal clock freq %f \n", tag(), counter, clock));
301389   }
302390   else
303391   {
304      clock = ptm6840->external_clock[counter];
305      PLOG(("MC6840 #%s: %d external clock freq %f \n", device->tag(), counter, clock));
392      clock = m_external_clock[counter];
393      PLOG(("MC6840 #%s: %d external clock freq %f \n", tag(), counter, clock));
306394   }
307395   /* See how many are left */
308   remaining = attotime_to_double(attotime_mul(timer_timeleft(ptm6840->timer[counter]), clock));
396   int remaining = attotime_to_double(attotime_mul(timer_timeleft(m_timer[counter]), clock));
309397
310398   /* Adjust the count for dual byte mode */
311   if (ptm6840->control_reg[counter] & 0x04)
399   if (m_control_reg[counter] & 0x04)
312400   {
313      int divisor = (ptm6840->counter[counter] & 0xff) + 1;
401      int divisor = (m_counter[counter] & 0xff) + 1;
314402      int msb = remaining / divisor;
315403      int lsb = remaining % divisor;
316404      remaining = (msb << 8) | lsb;
317405   }
318   PLOG(("MC6840 #%s: read counter(%d): %d\n", device->tag(), counter, remaining));
406   PLOG(("MC6840 #%s: read counter(%d): %d\n", tag(), counter, remaining));
319407   return remaining;
320408}
321409
410
411
322412/*-------------------------------------------------
323413    reload_count - Reload Counter
324414-------------------------------------------------*/
325415
326static void reload_count( running_device *device, int idx )
416void ptm6840_device::reload_count(int idx)
327417{
328   ptm6840_state *ptm6840 = get_safe_token(device);
329418   double clock;
330   int count;
331   attotime duration;
332419
333420   /* Copy the latched value in */
334   ptm6840->counter[idx] = ptm6840->latch[idx];
421   m_counter[idx] = m_latch[idx];
335422
336423   /* Determine the clock frequency for this timer */
337   if (ptm6840->control_reg[idx] & 0x02)
424   if (m_control_reg[idx] & 0x02)
338425   {
339      clock = ptm6840->internal_clock;
340      PLOG(("MC6840 #%s: %d internal clock freq %f \n", device->tag(), idx, clock));
426      clock = m_internal_clock;
427      PLOG(("MC6840 #%s: %d internal clock freq %f \n", tag(), idx, clock));
341428   }
342429   else
343430   {
344      clock = ptm6840->external_clock[idx];
345      PLOG(("MC6840 #%s: %d external clock freq %f \n", device->tag(), idx, clock));
431      clock = m_external_clock[idx];
432      PLOG(("MC6840 #%s: %d external clock freq %f \n", tag(), idx, clock));
346433   }
347434
348435   /* Determine the number of clock periods before we expire */
349   count = ptm6840->counter[idx];
350   if (ptm6840->control_reg[idx] & 0x04)
436   int count = m_counter[idx];
437   if (m_control_reg[idx] & 0x04)
438   {
351439      count = ((count >> 8) + 1) * ((count & 0xff) + 1);
440   }
352441   else
442   {
353443      count = count + 1;
444   }
354445
355   ptm6840->fired[idx] = 0;
446   m_fired[idx] = 0;
356447
357   if ((ptm6840->mode[idx] == 4) || (ptm6840->mode[idx] == 6))
448   if ((m_mode[idx] == 4) || (m_mode[idx] == 6))
358449   {
359      ptm6840->output[idx] = 1;
360      if (ptm6840->out_func[idx].write != NULL)
361         devcb_call_write8(&ptm6840->out_func[idx], 0, ptm6840->output[idx]);
450      m_output[idx] = 1;
451      if (m_out_func[idx].write != NULL)
452      {
453         devcb_call_write8(&m_out_func[idx], 0, m_output[idx]);
454      }
362455   }
363456
364457   /* Set the timer */
365   PLOG(("MC6840 #%s: reload_count(%d): clock = %f  count = %d\n", device->tag(), idx, clock, count));
458   PLOG(("MC6840 #%s: reload_count(%d): clock = %f  count = %d\n", tag(), idx, clock, count));
366459
367   duration = attotime_mul(ATTOTIME_IN_HZ(clock), count);
460   attotime duration = attotime_mul(ATTOTIME_IN_HZ(clock), count);
368461   if (idx == 2)
369      duration = attotime_mul(duration, ptm6840->t3_divisor);
462   {
463      duration = attotime_mul(duration, m_t3_divisor);
464   }
370465
371   PLOG(("MC6840 #%s: reload_count(%d): output = %lf\n", device->tag(), idx, attotime_to_double(duration)));
466   PLOG(("MC6840 #%s: reload_count(%d): output = %lf\n", tag(), idx, attotime_to_double(duration)));
372467
373468#if 0
374   if (!(ptm6840->control_reg[idx] & 0x02))
469   if (!(m_control_reg[idx] & 0x02))
375470   {
376      if (!ptm6840->external_clock[idx])
471      if (!m_external_clock[idx])
377472      {
378         ptm6840->enabled[idx] = 0;
379         timer_enable(ptm6840->timer[idx],FALSE);
473         m_enabled[idx] = 0;
474         timer_enable(m_timer[idx],FALSE);
380475      }
381476   }
382477   else
383478#endif
384479   {
385      ptm6840->enabled[idx] = 1;
386      timer_adjust_oneshot(ptm6840->timer[idx], duration, 0);
387      timer_enable(ptm6840->timer[idx], TRUE);
480      m_enabled[idx] = 1;
481      timer_adjust_oneshot(m_timer[idx], duration, 0);
482      timer_enable(m_timer[idx], TRUE);
388483   }
389484}
390485
391486
487
392488/*-------------------------------------------------
393489    ptm6840_read - Read Timer
394490-------------------------------------------------*/
395491
396READ8_DEVICE_HANDLER( ptm6840_read )
492READ8_DEVICE_HANDLER_TRAMPOLINE(ptm6840, ptm6840_read)
397493{
398   ptm6840_state *ptm6840 = get_safe_token(device);
399494   int val;
400495
401496   switch ( offset )
r8910r8911
408503
409504      case PTM_6840_STATUS:
410505      {
411         PLOG(("%s: MC6840 #%s: Status read = %04X\n", cpuexec_describe_context(device->machine), device->tag(), ptm6840->status_reg));
412         ptm6840->status_read_since_int |= ptm6840->status_reg & 0x07;
413         val = ptm6840->status_reg;
506         PLOG(("%s: MC6840 #%s: Status read = %04X\n", cpuexec_describe_context(&m_machine), tag(), m_status_reg));
507         m_status_read_since_int |= m_status_reg & 0x07;
508         val = m_status_reg;
414509         break;
415510      }
416511
r8910r8911
419514      case PTM_6840_MSBBUF3:
420515      {
421516         int idx = (offset - 2) / 2;
422         int result = compute_counter(device, idx);
517         int result = compute_counter(idx);
423518
424519         /* Clear the interrupt if the status has been read */
425         if (ptm6840->status_read_since_int & (1 << idx))
520         if (m_status_read_since_int & (1 << idx))
426521         {
427            ptm6840->status_reg &= ~(1 << idx);
428            update_interrupts(device);
522            m_status_reg &= ~(1 << idx);
523            update_interrupts();
429524         }
430525
431         ptm6840->lsb_buffer = result & 0xff;
526         m_lsb_buffer = result & 0xff;
432527
433         PLOG(("%s: MC6840 #%s: Counter %d read = %04X\n", cpuexec_describe_context(device->machine), device->tag(), idx, result >> 8));
528         PLOG(("%s: MC6840 #%s: Counter %d read = %04X\n", cpuexec_describe_context(&m_machine), tag(), idx, result >> 8));
434529         val = result >> 8;
435530         break;
436531      }
r8910r8911
439534      case PTM_6840_LSB2:
440535      case PTM_6840_LSB3:
441536      {
442         val = ptm6840->lsb_buffer;
537         val = m_lsb_buffer;
443538         break;
444539      }
445540
r8910r8911
453548   return val;
454549}
455550
551
456552/*-------------------------------------------------
457553    ptm6840_write - Write Timer
458554-------------------------------------------------*/
459555
460WRITE8_DEVICE_HANDLER( ptm6840_write )
556WRITE8_DEVICE_HANDLER_TRAMPOLINE(ptm6840, ptm6840_write)
461557{
462   ptm6840_state *ptm6840 = get_safe_token(device);
463   int idx;
464   int i;
465   UINT8 diffs;
466
467558   switch ( offset )
468559   {
469560      case PTM_6840_CTRL1:
470561      case PTM_6840_CTRL2:
471562      {
472         idx = (offset == 1) ? 1 : (ptm6840->control_reg[1] & 0x01) ? 0 : 2;
473         diffs = data ^ ptm6840->control_reg[idx];
474         ptm6840->t3_divisor = (ptm6840->control_reg[2] & 0x01) ? 8 : 1;
475         ptm6840->mode[idx] = (data >> 3) & 0x07;
476         ptm6840->control_reg[idx] = data;
563         int idx = (offset == 1) ? 1 : (m_control_reg[1] & 0x01) ? 0 : 2;
564         UINT8 diffs = data ^ m_control_reg[idx];
565         m_t3_divisor = (m_control_reg[2] & 0x01) ? 8 : 1;
566         m_mode[idx] = (data >> 3) & 0x07;
567         m_control_reg[idx] = data;
477568
478         PLOG(("MC6840 #%s : Control register %d selected\n", device->tag(), idx));
479         PLOG(("operation mode   = %s\n", opmode[ ptm6840->mode[idx] ]));
480         PLOG(("value            = %04X\n", ptm6840->control_reg[idx]));
481         PLOG(("t3divisor        = %d\n", ptm6840->t3_divisor));
569         PLOG(("MC6840 #%s : Control register %d selected\n", tag(), idx));
570         PLOG(("operation mode   = %s\n", opmode[ m_mode[idx] ]));
571         PLOG(("value            = %04X\n", m_control_reg[idx]));
572         PLOG(("t3divisor        = %d\n", m_t3_divisor));
482573
483         if (!(ptm6840->control_reg[idx] & 0x80 ))
574         if (!(m_control_reg[idx] & 0x80 ))
484575         {
485576            /* Output cleared */
486            if (ptm6840->out_func[idx].write != NULL)
487               devcb_call_write8(&ptm6840->out_func[idx], 0, 0);
577            devcb_call_write8(&m_out_func[idx], 0, 0);
488578         }
489579         /* Reset? */
490580         if (idx == 0 && (diffs & 0x01))
r8910r8911
492582            /* Holding reset down */
493583            if (data & 0x01)
494584            {
495               PLOG(("MC6840 #%s : Timer reset\n", device->tag()));
496               for (i = 0; i < 3; i++)
585               PLOG(("MC6840 #%s : Timer reset\n", tag()));
586               for (int i = 0; i < 3; i++)
497587               {
498                  timer_enable(ptm6840->timer[i], FALSE);
499                  ptm6840->enabled[i] = 0;
588                  timer_enable(m_timer[i], FALSE);
589                  m_enabled[i] = 0;
500590               }
501591            }
502592            /* Releasing reset */
503593            else
504594            {
505               for (i = 0; i < 3; i++)
506                  reload_count(device, i);
595               for (int i = 0; i < 3; i++)
596               {
597                  reload_count(i);
598               }
507599            }
508600
509            ptm6840->status_reg = 0;
510            update_interrupts(device);
601            m_status_reg = 0;
602            update_interrupts();
511603
512604            /* Changing the clock source? (e.g. Zwackery) */
513605            if (diffs & 0x02)
514               reload_count(device, idx);
606            {
607               reload_count(idx);
608            }
515609         }
516610         break;
517611      }
r8910r8911
520614      case PTM_6840_MSBBUF2:
521615      case PTM_6840_MSBBUF3:
522616      {
523         PLOG(("MC6840 #%s msbbuf%d = %02X\n", device->tag(), offset / 2, data));
524         ptm6840->msb_buffer = data;
617         PLOG(("MC6840 #%s msbbuf%d = %02X\n", tag(), offset / 2, data));
618         m_msb_buffer = data;
525619         break;
526620      }
527621
r8910r8911
529623      case PTM_6840_LSB2:
530624      case PTM_6840_LSB3:
531625      {
532         idx = (offset - 3) / 2;
533         ptm6840->latch[idx] = (ptm6840->msb_buffer << 8) | (data & 0xff);
626         int idx = (offset - 3) / 2;
627         m_latch[idx] = (m_msb_buffer << 8) | (data & 0xff);
534628
535629         /* Clear the interrupt */
536         ptm6840->status_reg &= ~(1 << idx);
537         update_interrupts(device);
630         m_status_reg &= ~(1 << idx);
631         update_interrupts();
538632
539633         /* Reload the count if in an appropriate mode */
540         if (!(ptm6840->control_reg[idx] & 0x10))
541            reload_count(device,idx);
634         if (!(m_control_reg[idx] & 0x10))
635         {
636            reload_count(idx);
637         }
542638
543         PLOG(("%s:MC6840 #%s: Counter %d latch = %04X\n", cpuexec_describe_context(device->machine), device->tag(), idx, ptm6840->latch[idx]));
639         PLOG(("%s:MC6840 #%s: Counter %d latch = %04X\n", cpuexec_describe_context(&m_machine), tag(), idx, m_latch[idx]));
544640         break;
545641      }
546642   }
547643}
548644
645
549646/*-------------------------------------------------
550647    ptm6840_timeout - Called if timer is mature
551648-------------------------------------------------*/
552649
553static void ptm6840_timeout( running_device *device, int idx )
650void ptm6840_device::ptm6840_timeout(int idx)
554651{
555   ptm6840_state *ptm6840 = get_safe_token(device);
652   PLOG(("**ptm6840 %s t%d timeout**\n", tag(), idx + 1));
556653
557   PLOG(("**ptm6840 %s t%d timeout**\n", device->tag(), idx + 1));
558
559654   /* Set the interrupt flag */
560   ptm6840->status_reg |= (1 << idx);
561   ptm6840->status_read_since_int &= ~(1 << idx);
562   update_interrupts(device);
655   m_status_reg |= (1 << idx);
656   m_status_read_since_int &= ~(1 << idx);
657   update_interrupts();
563658
564   if ( ptm6840->control_reg[idx] & 0x80 )
659   if ( m_control_reg[idx] & 0x80 )
565660   {
566      if ((ptm6840->mode[idx] == 0)||(ptm6840->mode[idx] == 2))
661      if ((m_mode[idx] == 0)||(m_mode[idx] == 2))
567662      {
568         ptm6840->output[idx] = ptm6840->output[idx] ? 0 : 1;
569         PLOG(("**ptm6840 %s t%d output %d **\n", device->tag(), idx + 1, ptm6840->output[idx]));
663         m_output[idx] = m_output[idx] ? 0 : 1;
664         PLOG(("**ptm6840 %s t%d output %d **\n", tag(), idx + 1, m_output[idx]));
570665
571         if (ptm6840->out_func[idx].write != NULL)
572            devcb_call_write8(&ptm6840->out_func[idx], 0, ptm6840->output[idx]);
666         devcb_call_write8(&m_out_func[idx], 0, m_output[idx]);
573667      }
574      if ((ptm6840->mode[idx] == 4)||(ptm6840->mode[idx] == 6))
668      if ((m_mode[idx] == 4)||(m_mode[idx] == 6))
575669      {
576         if (!ptm6840->fired[idx])
670         if (!m_fired[idx])
577671         {
578            ptm6840->output[idx] = 1;
579            PLOG(("**ptm6840 %s t%d output %d **\n", device->tag(), idx + 1, ptm6840->output[idx]));
672            m_output[idx] = 1;
673            PLOG(("**ptm6840 %s t%d output %d **\n", tag(), idx + 1, m_output[idx]));
580674
581            if (ptm6840->out_func[idx].write != NULL)
582               devcb_call_write8(&ptm6840->out_func[idx], 0, ptm6840->output[idx]);
675            devcb_call_write8(&m_out_func[idx], 0, m_output[idx]);
583676
584677            /* No changes in output until reinit */
585            ptm6840->fired[idx] = 1;
678            m_fired[idx] = 1;
586679         }
587680      }
588681   }
589   ptm6840->enabled[idx]= 0;
590   reload_count(device, idx);
682   m_enabled[idx]= 0;
683   reload_count(idx);
591684}
592685
686
593687/*-------------------------------------------------
594688    TIMER_CALLBACKs for Timer 1, 2 & 3
595689-------------------------------------------------*/
596690
597static TIMER_CALLBACK( ptm6840_timer1_cb )
691TIMER_CALLBACK( ptm6840_device::ptm6840_timer1_cb )
598692{
599   running_device *device = (running_device *)ptr;
600   ptm6840_timeout(device, 0);
693   reinterpret_cast<ptm6840_device *>(ptr)->ptm6840_timeout(0);
601694}
602695
603static TIMER_CALLBACK( ptm6840_timer2_cb )
696TIMER_CALLBACK( ptm6840_device::ptm6840_timer2_cb )
604697{
605   running_device *device = (running_device *)ptr;
606   ptm6840_timeout(device, 1);
698   reinterpret_cast<ptm6840_device *>(ptr)->ptm6840_timeout(1);
607699}
608700
609static TIMER_CALLBACK( ptm6840_timer3_cb )
701TIMER_CALLBACK( ptm6840_device::ptm6840_timer3_cb )
610702{
611   running_device *device = (running_device *)ptr;
612   ptm6840_timeout(device, 2);
703   reinterpret_cast<ptm6840_device *>(ptr)->ptm6840_timeout(2);
613704}
614705
615706
r8910r8911
617708    ptm6840_set_gate - set gate status (0 or 1)
618709-------------------------------------------------*/
619710
620INLINE void ptm6840_set_gate( running_device *device, int state, int idx )
711void ptm6840_device::ptm6840_set_gate(int state, int idx)
621712{
622   ptm6840_state *ptm6840 = get_safe_token(device);
623
624   if ( (ptm6840->mode[idx] == 0) || (ptm6840->mode[idx] == 2) || (ptm6840->mode[0] == 4) || (ptm6840->mode[idx] == 6) )
713   if ( (m_mode[idx] == 0) || (m_mode[idx] == 2) || (m_mode[0] == 4) || (m_mode[idx] == 6) )
625714   {
626      if (state == 0 && ptm6840->gate[idx])
627         reload_count(device,idx);
715      if (state == 0 && m_gate[idx])
716      {
717         reload_count(idx);
718      }
628719   }
629   ptm6840->gate[idx] = state;
720   m_gate[idx] = state;
630721}
631722
723
632724/*-------------------------------------------------
633725    WRITE8_DEVICE_HANDLERs for Gate 1, 2 & 3
634726-------------------------------------------------*/
635727
636728WRITE8_DEVICE_HANDLER( ptm6840_set_g1 )
637729{
638   ptm6840_set_gate(device, data, 0);
730   downcast<ptm6840_device*>(device)->ptm6840_set_gate(data, 0);
639731}
640732
641733WRITE8_DEVICE_HANDLER( ptm6840_set_g2 )
642734{
643   ptm6840_set_gate(device, data, 1);
735   downcast<ptm6840_device*>(device)->ptm6840_set_gate(data, 1);
644736}
645737
646738WRITE8_DEVICE_HANDLER( ptm6840_set_g3 )
647739{
648   ptm6840_set_gate(device, data, 2);
740   downcast<ptm6840_device*>(device)->ptm6840_set_gate(data, 2);
649741}
650742
743
651744/*-------------------------------------------------
652745    ptm6840_set_clock - set clock status (0 or 1)
653746-------------------------------------------------*/
654747
655INLINE void ptm6840_set_clock( running_device *device, int state, int idx )
748void ptm6840_device::ptm6840_set_clock(int state, int idx)
656749{
657   ptm6840_state *ptm6840 = get_safe_token(device);
750   m_clk[idx] = state;
658751
659   ptm6840->clock[idx] = state;
660
661   if (!(ptm6840->control_reg[idx] & 0x02))
752   if (!(m_control_reg[idx] & 0x02))
662753   {
663754      if (state)
664         ptm_tick(device, idx, 1);
755      {
756         ptm_tick(idx, 1);
757      }
665758   }
666759}
667760
761
668762/*-------------------------------------------------
669763    WRITE8_DEVICE_HANDLERs for Clock 1, 2 & 3
670764-------------------------------------------------*/
671765
672766WRITE8_DEVICE_HANDLER( ptm6840_set_c1 )
673767{
674   ptm6840_set_clock(device, data, 0);
768   downcast<ptm6840_device*>(device)->ptm6840_set_clock(data, 0);
675769}
676770
677771WRITE8_DEVICE_HANDLER( ptm6840_set_c2 )
678772{
679   ptm6840_set_clock(device, data, 1);
773   downcast<ptm6840_device*>(device)->ptm6840_set_clock(data, 1);
680774}
681775
682776WRITE8_DEVICE_HANDLER( ptm6840_set_c3 )
683777{
684   ptm6840_set_clock(device, data, 2);
778   downcast<ptm6840_device*>(device)->ptm6840_set_clock(data, 2);
685779}
686780
687781
r8910r8911
689783    ptm6840_get_count - get count value
690784-------------------------------------------------*/
691785
692UINT16 ptm6840_get_count( running_device *device, int counter )
786UINT16 ptm6840_get_count(running_device *device, int counter)
693787{
694   return compute_counter(device, counter);
788   return downcast<ptm6840_device*>(device)->ptm6840_get_count(counter);
695789}
696790
791UINT16 ptm6840_device::ptm6840_get_count(int counter)
792{
793   return compute_counter(counter);
794}
795
796
697797/*------------------------------------------------------------
698798    ptm6840_set_ext_clock - set external clock frequency
699799------------------------------------------------------------*/
700800
701void ptm6840_set_ext_clock( running_device *device, int counter, double clock )
801void ptm6840_set_ext_clock(running_device *device, int counter, double clock)
702802{
703   ptm6840_state *ptm6840 = get_safe_token(device);
803   downcast<ptm6840_device*>(device)->ptm6840_set_ext_clock(counter, clock);
804}
704805
705   ptm6840->external_clock[counter] = clock;
806void ptm6840_device::ptm6840_set_ext_clock(int counter, double clock)
807{
808   m_external_clock[counter] = clock;
706809
707   if (!(ptm6840->control_reg[counter] & 0x02))
810   if (!(m_control_reg[counter] & 0x02))
708811   {
709      if (!ptm6840->external_clock[counter])
812      if (!m_external_clock[counter])
710813      {
711         ptm6840->enabled[counter] = 0;
712         timer_enable(ptm6840->timer[counter], FALSE);
814         m_enabled[counter] = 0;
815         timer_enable(m_timer[counter], FALSE);
713816      }
714817   }
715818   else
r8910r8911
718821      attotime duration;
719822
720823      /* Determine the number of clock periods before we expire */
721      count = ptm6840->counter[counter];
824      count = m_counter[counter];
722825
723      if (ptm6840->control_reg[counter] & 0x04)
826      if (m_control_reg[counter] & 0x04)
827      {
724828         count = ((count >> 8) + 1) * ((count & 0xff) + 1);
829      }
725830      else
831      {
726832         count = count + 1;
833      }
727834
728835      duration = attotime_mul(ATTOTIME_IN_HZ(clock), count);
729836
730837      if (counter == 2)
731         duration = attotime_mul(duration, ptm6840->t3_divisor);
838      {
839         duration = attotime_mul(duration, m_t3_divisor);
840      }
732841
733      ptm6840->enabled[counter] = 1;
734      timer_adjust_oneshot(ptm6840->timer[counter], duration, 0);
735      timer_enable(ptm6840->timer[counter], TRUE);
842      m_enabled[counter] = 1;
843      timer_adjust_oneshot(m_timer[counter], duration, 0);
844      timer_enable(m_timer[counter], TRUE);
736845   }
737846}
738847
848
739849/*------------------------------------------------------------
740850    ptm6840_get_ext_clock - get external clock frequency
741851------------------------------------------------------------*/
742852
743853int ptm6840_get_ext_clock( running_device *device, int counter )
744854{
745   ptm6840_state *ptm6840 = get_safe_token(device);
746   return ptm6840->external_clock[counter];
855   return downcast<ptm6840_device*>(device)->ptm6840_get_ext_clock(counter);
747856}
748857
749
750/*-------------------------------------------------
751    DEVICE_START( ptm6840 )
752-------------------------------------------------*/
753
754static DEVICE_START( ptm6840 )
858int ptm6840_device::ptm6840_get_ext_clock(int counter)
755859{
756   ptm6840_state *ptm6840 = get_safe_token(device);
757   const ptm6840_interface *intf = get_interface(device);
758   int i;
759
760   ptm6840->internal_clock = intf->internal_clock;
761
762   /* resolve callbacks */
763   for (i = 0; i < 3; i++)
764   {
765      devcb_resolve_write8(&ptm6840->out_func[i], &intf->out_func[i], device);
766   }
767
768   for (i = 0; i < 3; i++)
769   {
770      if ( intf->external_clock[i] )
771         ptm6840->external_clock[i] = intf->external_clock[i];
772      else
773         ptm6840->external_clock[i] = 1;
774   }
775
776
777   ptm6840->timer[0] = timer_alloc(device->machine, ptm6840_timer1_cb, (void *)device);
778   ptm6840->timer[1] = timer_alloc(device->machine, ptm6840_timer2_cb, (void *)device);
779   ptm6840->timer[2] = timer_alloc(device->machine, ptm6840_timer3_cb, (void *)device);
780
781   for (i = 0; i < 3; i++)
782   {
783      timer_enable(ptm6840->timer[i], FALSE);
784   }
785
786   devcb_resolve_write_line(&ptm6840->irq_func, &intf->irq_func, device);
787
788   /* register for state saving */
789   state_save_register_device_item(device, 0, ptm6840->lsb_buffer);
790   state_save_register_device_item(device, 0, ptm6840->msb_buffer);
791   state_save_register_device_item(device, 0, ptm6840->status_read_since_int);
792   state_save_register_device_item(device, 0, ptm6840->status_reg);
793   state_save_register_device_item(device, 0, ptm6840->t3_divisor);
794   state_save_register_device_item(device, 0, ptm6840->t3_scaler);
795   state_save_register_device_item(device, 0, ptm6840->internal_clock);
796   state_save_register_device_item(device, 0, ptm6840->IRQ);
797
798   state_save_register_device_item_array(device, 0, ptm6840->control_reg);
799   state_save_register_device_item_array(device, 0, ptm6840->output);
800   state_save_register_device_item_array(device, 0, ptm6840->gate);
801   state_save_register_device_item_array(device, 0, ptm6840->clock);
802   state_save_register_device_item_array(device, 0, ptm6840->mode);
803   state_save_register_device_item_array(device, 0, ptm6840->fired);
804   state_save_register_device_item_array(device, 0, ptm6840->enabled);
805   state_save_register_device_item_array(device, 0, ptm6840->external_clock);
806   state_save_register_device_item_array(device, 0, ptm6840->counter);
807   state_save_register_device_item_array(device, 0, ptm6840->latch);
860   return m_external_clock[counter];
808861}
809
810/*-------------------------------------------------
811    DEVICE_RESET( ptm6840 )
812-------------------------------------------------*/
813
814static DEVICE_RESET( ptm6840 )
815{
816   ptm6840_state *ptm6840 = get_safe_token(device);
817   int i;
818
819   ptm6840->control_reg[2]       = 0;
820   ptm6840->control_reg[1]       = 0;
821   ptm6840->control_reg[0]       = 1;
822   ptm6840->status_reg          = 0;
823   ptm6840->t3_divisor          = 1;
824   ptm6840->status_read_since_int = 0;
825   ptm6840->IRQ                   = 0;
826
827   for (i = 0; i < 3; i++)
828   {
829      ptm6840->counter[i] = 0xffff;
830      ptm6840->latch[i]   = 0xffff;
831      ptm6840->output[i]  = 0;
832      ptm6840->fired[i]   = 0;
833   }
834}
835
836/*-------------------------------------------------
837    device definition
838-------------------------------------------------*/
839
840static const char DEVTEMPLATE_SOURCE[] = __FILE__;
841
842#define DEVTEMPLATE_ID(p,s)      p##ptm6840##s
843#define DEVTEMPLATE_FEATURES   DT_HAS_START | DT_HAS_RESET
844#define DEVTEMPLATE_NAME      "6840 PTM"
845#include "devtempl.h"
846
847DEFINE_LEGACY_DEVICE(PTM6840, ptm6840);
src/emu/machine/6840ptm.h
r8910r8911
66
77***************************************************************************/
88
9#pragma once
10
911#ifndef __6840PTM_H__
1012#define __6840PTM_H__
1113
12#include "devlegcy.h"
14#include "emu.h"
1315
1416
17
1518/***************************************************************************
16    MACROS / CONSTANTS
19    DEVICE CONFIGURATION MACROS
1720***************************************************************************/
1821
19DECLARE_LEGACY_DEVICE(PTM6840, ptm6840);
20
2122#define MDRV_PTM6840_ADD(_tag, _config) \
2223   MDRV_DEVICE_ADD(_tag, PTM6840, 0) \
2324   MDRV_DEVICE_CONFIG(_config)
r8910r8911
2728    TYPE DEFINITIONS
2829***************************************************************************/
2930
31// ======================> ptm6840_interface
3032
31typedef struct _ptm6840_interface ptm6840_interface;
32struct _ptm6840_interface
33struct ptm6840_interface
3334{
34   double internal_clock;
35   double external_clock[3];
35   double m_internal_clock;
36   double m_external_clock[3];
3637
37   devcb_write8 out_func[3];   // function to call when output[idx] changes
38   devcb_write_line irq_func;   // function called if IRQ line changes
38   devcb_write8 m_out_func[3];      // function to call when output[idx] changes
39   devcb_write_line m_irq_func;   // function called if IRQ line changes
3940};
4041
4142
43
44// ======================> ptm6840_device_config
45
46class ptm6840_device_config : public device_config,
47                               public ptm6840_interface
48{
49    friend class ptm6840_device;
50
51    // construction/destruction
52    ptm6840_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
53
54public:
55    // allocators
56    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
57    virtual device_t *alloc_device(running_machine &machine) const;
58
59protected:
60    // device_config overrides
61    virtual void device_config_complete();
62};
63
64
65
66// ======================> ptm6840_device
67
68class ptm6840_device :  public device_t
69{
70    friend class ptm6840_device_config;
71
72    // construction/destruction
73    ptm6840_device(running_machine &_machine, const ptm6840_device_config &_config);
74
75public:
76
77   int ptm6840_get_status(int clock);      // get whether timer is enabled
78   int ptm6840_get_irq();               // get IRQ state
79   UINT16 ptm6840_get_count(int counter);   // get counter value
80   void ptm6840_set_ext_clock(int counter, double clock);   // set clock frequency
81   int ptm6840_get_ext_clock(int counter);   // get clock frequency
82
83   void ptm6840_set_g1(UINT32 offset, UINT8 data);   // set gate1 state
84   void ptm6840_set_g2(UINT32 offset, UINT8 data);   // set gate2 state
85   void ptm6840_set_g3(UINT32 offset, UINT8 data);   // set gate3 state
86   void ptm6840_set_c1(UINT32 offset, UINT8 data);   // set clock1 state
87   void ptm6840_set_c2(UINT32 offset, UINT8 data);   // set clock2 state
88   void ptm6840_set_c3(UINT32 offset, UINT8 data);   // set clock3 state
89
90   void ptm6840_write(UINT32 offset, UINT8 data);
91   UINT8 ptm6840_read(UINT32 offset);
92
93   void ptm6840_set_gate(int state, int idx);
94   void ptm6840_set_clock(int state, int idx);
95
96   void update_interrupts();
97
98protected:
99    // device-level overrides
100    virtual void device_start();
101    virtual void device_reset();
102    virtual void device_post_load() { }
103    virtual void device_clock_changed() { }
104
105   static TIMER_CALLBACK( ptm6840_timer1_cb );
106   static TIMER_CALLBACK( ptm6840_timer2_cb );
107   static TIMER_CALLBACK( ptm6840_timer3_cb );
108
109private:
110
111   void subtract_from_counter(int counter, int count);
112   void ptm_tick(int counter, int count);
113
114   void ptm6840_timeout(int idx);
115
116   UINT16 compute_counter(int counter);
117   void reload_count(int idx);
118
119   enum
120   {
121      PTM_6840_CTRL1   = 0,
122      PTM_6840_CTRL2   = 1,
123      PTM_6840_STATUS  = 1,
124      PTM_6840_MSBBUF1 = 2,
125      PTM_6840_LSB1    = 3,
126      PTM_6840_MSBBUF2 = 4,
127      PTM_6840_LSB2    = 5,
128      PTM_6840_MSBBUF3 = 6,
129      PTM_6840_LSB3    = 7,
130   };
131
132   double m_internal_clock;
133   double m_external_clock[3];
134
135   devcb_resolved_write8 m_out_func[3];   // function to call when output[idx] changes
136   devcb_resolved_write_line m_irq_func;   // function called if IRQ line changes
137
138   UINT8 m_control_reg[3];
139   UINT8 m_output[3]; /* Output states */
140   UINT8 m_gate[3];   /* Input gate states */
141   UINT8 m_clk[3];  /* Clock states */
142   UINT8 m_enabled[3];
143   UINT8 m_mode[3];
144   UINT8 m_fired[3];
145   UINT8 m_t3_divisor;
146   UINT8 m_t3_scaler;
147   UINT8 m_IRQ;
148   UINT8 m_status_reg;
149   UINT8 m_status_read_since_int;
150   UINT8 m_lsb_buffer;
151   UINT8 m_msb_buffer;
152
153   /* Each PTM has 3 timers */
154   emu_timer *m_timer[3];
155
156   UINT16 m_latch[3];
157   UINT16 m_counter[3];
158
159    const ptm6840_device_config &m_config;
160
161   static const char *const opmode[];
162};
163
164
165// device type definition
166extern const device_type PTM6840;
167
168
169
42170/***************************************************************************
43171    PROTOTYPES
44172***************************************************************************/
src/emu/machine/8255ppi.c
r8910r8911
9292
9393#include "emu.h"
9494#include "8255ppi.h"
95#include "devhelpr.h"
9596
96typedef struct _ppi8255 ppi8255_t;
97//**************************************************************************
98//  DEVICE CONFIGURATION
99//**************************************************************************
97100
98struct _ppi8255
101GENERIC_DEVICE_CONFIG_SETUP(ppi8255, "PPI8255")
102
103//-------------------------------------------------
104//  device_config_complete - perform any
105//  operations now that the configuration is
106//  complete
107//-------------------------------------------------
108
109void ppi8255_device_config::device_config_complete()
99110{
100   const ppi8255_interface   *intf;
111   // inherit a copy of the static data
112   const ppi8255_interface *intf = reinterpret_cast<const ppi8255_interface *>(static_config());
113   if (intf != NULL)
114   {
115      *static_cast<ppi8255_interface *>(this) = *intf;
116   }
101117
102   devcb_resolved_read8 port_read[3];
103   devcb_resolved_write8 port_write[3];
118   // or initialize to defaults if none provided
119   else
120   {
121       memset(&m_port_a_read, 0, sizeof(m_port_a_read));
122       memset(&m_port_b_read, 0, sizeof(m_port_b_read));
123       memset(&m_port_c_read, 0, sizeof(m_port_c_read));
124       memset(&m_port_a_write, 0, sizeof(m_port_a_write));
125       memset(&m_port_b_write, 0, sizeof(m_port_b_write));
126       memset(&m_port_c_write, 0, sizeof(m_port_c_write));
127   }
128}
104129
105   /* mode flags */
106   UINT8 group_a_mode;
107   UINT8 group_b_mode;
108   UINT8 port_a_dir;
109   UINT8 port_b_dir;
110   UINT8 port_ch_dir;
111   UINT8 port_cl_dir;
112130
113   /* handshake signals (1=asserted; 0=non-asserted) */
114   UINT8 obf_a;
115   UINT8 obf_b;
116   UINT8 ibf_a;
117   UINT8 ibf_b;
118   UINT8 inte_a;
119   UINT8 inte_b;
120   UINT8 inte_1;
121   UINT8 inte_2;
122131
123   UINT8 in_mask[3];   /* input mask */
124   UINT8 out_mask[3];   /* output mask */
125   UINT8 read[3];      /* data read from ports */
126   UINT8 latch[3];      /* data written to ports */
127   UINT8 output[3];   /* actual output data */
128   UINT8 control;      /* mode control word */
129};
132//**************************************************************************
133//  LIVE DEVICE
134//**************************************************************************
130135
136const device_type PPI8255 = ppi8255_device_config::static_alloc_device_config;
131137
132static void set_mode(running_device *device, int data, int call_handlers);
133static void ppi8255_write_port(running_device *device, int port);
138//-------------------------------------------------
139//  ppi8255_device - constructor
140//-------------------------------------------------
134141
142ppi8255_device::ppi8255_device(running_machine &_machine, const ppi8255_device_config &config)
143    : device_t(_machine, config),
144      m_config(config)
145{
135146
136INLINE ppi8255_t *get_safe_token(running_device *device) {
137   assert( device != NULL );
138   assert( device->type() == PPI8255 );
139   return ( ppi8255_t * ) downcast<legacy_device_base *>(device)->token();
140147}
141148
149//-------------------------------------------------
150//  device_start - device-specific startup
151//-------------------------------------------------
142152
143INLINE void ppi8255_get_handshake_signals(ppi8255_t *ppi8255, int is_read, UINT8 *result)
153void ppi8255_device::device_start()
144154{
155   devcb_resolve_read8(&m_port_read[0], &m_config.m_port_a_read, this);
156   devcb_resolve_read8(&m_port_read[1], &m_config.m_port_b_read, this);
157   devcb_resolve_read8(&m_port_read[2], &m_config.m_port_c_read, this);
158
159   devcb_resolve_write8(&m_port_write[0], &m_config.m_port_a_write, this);
160   devcb_resolve_write8(&m_port_write[1], &m_config.m_port_b_write, this);
161   devcb_resolve_write8(&m_port_write[2], &m_config.m_port_c_write, this);
162
163   /* register for state saving */
164   state_save_register_device_item(this, 0, m_group_a_mode);
165   state_save_register_device_item(this, 0, m_group_b_mode);
166   state_save_register_device_item(this, 0, m_port_a_dir);
167   state_save_register_device_item(this, 0, m_port_b_dir);
168   state_save_register_device_item(this, 0, m_port_ch_dir);
169   state_save_register_device_item(this, 0, m_port_cl_dir);
170   state_save_register_device_item(this, 0, m_obf_a);
171   state_save_register_device_item(this, 0, m_obf_b);
172   state_save_register_device_item(this, 0, m_ibf_a);
173   state_save_register_device_item(this, 0, m_ibf_b);
174   state_save_register_device_item(this, 0, m_inte_a);
175   state_save_register_device_item(this, 0, m_inte_b);
176   state_save_register_device_item(this, 0, m_inte_1);
177   state_save_register_device_item(this, 0, m_inte_2);
178   state_save_register_device_item_array(this, 0, m_in_mask);
179   state_save_register_device_item_array(this, 0, m_out_mask);
180   state_save_register_device_item_array(this, 0, m_read);
181   state_save_register_device_item_array(this, 0, m_latch);
182}
183
184
185//-------------------------------------------------
186//  device_reset - device-specific reset
187//-------------------------------------------------
188
189void ppi8255_device::device_reset()
190{
191   m_group_a_mode = 0;
192   m_group_b_mode = 0;
193   m_port_a_dir = 0;
194   m_port_b_dir = 0;
195   m_port_ch_dir = 0;
196   m_port_cl_dir = 0;
197   m_obf_a = m_ibf_a = 0;
198   m_obf_b = m_ibf_b = 0;
199   m_inte_a = m_inte_b = m_inte_1 = m_inte_2 = 0;
200
201   for (int i = 0; i < 3; i++)
202   {
203      m_in_mask[i] = m_out_mask[i] = m_read[i] = m_latch[i] = m_output[i] = 0;
204   }
205
206   set_mode(0x9b, 0);   /* Mode 0, all ports set to input */
207}
208
209
210void ppi8255_device::ppi8255_get_handshake_signals(int is_read, UINT8 *result)
211{
145212   UINT8 handshake = 0x00;
146213   UINT8 mask = 0x00;
147214
148215   /* group A */
149   if (ppi8255->group_a_mode == 1)
216   if (m_group_a_mode == 1)
150217   {
151      if (ppi8255->port_a_dir)
218      if (m_port_a_dir)
152219      {
153         handshake |= ppi8255->ibf_a ? 0x20 : 0x00;
154         handshake |= (ppi8255->ibf_a && ppi8255->inte_a) ? 0x08 : 0x00;
220         handshake |= m_ibf_a ? 0x20 : 0x00;
221         handshake |= (m_ibf_a && m_inte_a) ? 0x08 : 0x00;
155222         mask |= 0x28;
156223      }
157224      else
158225      {
159         handshake |= ppi8255->obf_a ? 0x00 : 0x80;
160         handshake |= (ppi8255->obf_a && ppi8255->inte_a) ? 0x08 : 0x00;
226         handshake |= m_obf_a ? 0x00 : 0x80;
227         handshake |= (m_obf_a && m_inte_a) ? 0x08 : 0x00;
161228         mask |= 0x88;
162229      }
163230   }
164   else if (ppi8255->group_a_mode == 2)
231   else if (m_group_a_mode == 2)
165232   {
166      handshake |= ppi8255->obf_a ? 0x00 : 0x80;
167      handshake |= ppi8255->ibf_a ? 0x20 : 0x00;
168      handshake |= ((ppi8255->obf_a && ppi8255->inte_1) || (ppi8255->ibf_a && ppi8255->inte_2)) ? 0x08 : 0x00;
233      handshake |= m_obf_a ? 0x00 : 0x80;
234      handshake |= m_ibf_a ? 0x20 : 0x00;
235      handshake |= ((m_obf_a && m_inte_1) || (m_ibf_a && m_inte_2)) ? 0x08 : 0x00;
169236      mask |= 0xA8;
170237   }
171238
172239   /* group B */
173   if (ppi8255->group_b_mode == 1)
240   if (m_group_b_mode == 1)
174241   {
175      if (ppi8255->port_b_dir)
242      if (m_port_b_dir)
176243      {
177         handshake |= ppi8255->ibf_b ? 0x02 : 0x00;
178         handshake |= (ppi8255->ibf_b && ppi8255->inte_b) ? 0x01 : 0x00;
244         handshake |= m_ibf_b ? 0x02 : 0x00;
245         handshake |= (m_ibf_b && m_inte_b) ? 0x01 : 0x00;
179246         mask |= 0x03;
180247      }
181248      else
182249      {
183         handshake |= ppi8255->obf_b ? 0x00 : 0x02;
184         handshake |= (ppi8255->obf_b && ppi8255->inte_b) ? 0x01 : 0x00;
250         handshake |= m_obf_b ? 0x00 : 0x02;
251         handshake |= (m_obf_b && m_inte_b) ? 0x01 : 0x00;
185252         mask |= 0x03;
186253      }
187254   }
r8910r8911
192259
193260
194261
195static void ppi8255_input(running_device *device, int port, UINT8 data)
262void ppi8255_device::ppi8255_input(int port, UINT8 data)
196263{
197   ppi8255_t   *ppi8255 = get_safe_token(device);
198264   int changed = 0;
199265
200   ppi8255->read[port] = data;
266   m_read[port] = data;
201267
202268   /* port C is special */
203269   if (port == 2)
204270   {
205      if (((ppi8255->group_a_mode == 1) && (ppi8255->port_a_dir == 0)) || (ppi8255->group_a_mode == 2))
271      if (((m_group_a_mode == 1) && (m_port_a_dir == 0)) || (m_group_a_mode == 2))
206272      {
207273         /* is !ACKA asserted? */
208         if (ppi8255->obf_a && !(data & 0x40))
274         if (m_obf_a && !(data & 0x40))
209275         {
210            ppi8255->obf_a = 0;
276            m_obf_a = 0;
211277            changed = 1;
212278         }
213279      }
214280
215      if (((ppi8255->group_a_mode == 1) && (ppi8255->port_a_dir == 1)) || (ppi8255->group_a_mode == 2))
281      if (((m_group_a_mode == 1) && (m_port_a_dir == 1)) || (m_group_a_mode == 2))
216282      {
217283         /* is !STBA asserted? */
218         if (!ppi8255->ibf_a && !(data & 0x10))
284         if (!m_ibf_a && !(data & 0x10))
219285         {
220            ppi8255->ibf_a = 1;
286            m_ibf_a = 1;
221287            changed = 1;
222288         }
223289      }
224290
225      if ((ppi8255->group_b_mode == 1) && (ppi8255->port_b_dir == 0))
291      if ((m_group_b_mode == 1) && (m_port_b_dir == 0))
226292      {
227293         /* is !ACKB asserted? */
228         if (ppi8255->obf_b && !(data & 0x04))
294         if (m_obf_b && !(data & 0x04))
229295         {
230            ppi8255->obf_b = 0;
296            m_obf_b = 0;
231297            changed = 1;
232298         }
233299      }
234300
235      if ((ppi8255->group_b_mode == 1) && (ppi8255->port_b_dir == 1))
301      if ((m_group_b_mode == 1) && (m_port_b_dir == 1))
236302      {
237303         /* is !STBB asserted? */
238         if (!ppi8255->ibf_b && !(data & 0x04))
304         if (!m_ibf_b && !(data & 0x04))
239305         {
240            ppi8255->ibf_b = 1;
306            m_ibf_b = 1;
241307            changed = 1;
242308         }
243309      }
244310
245311      if (changed)
246         ppi8255_write_port(device, 2);
312      {
313         ppi8255_write_port(2);
314      }
247315   }
248316}
249317
250318
251319
252static UINT8 ppi8255_read_port(running_device *device, int port)
320UINT8 ppi8255_device::ppi8255_read_port(int port)
253321{
254   ppi8255_t   *ppi8255 = get_safe_token(device);
255322   UINT8 result = 0x00;
256323
257   if (ppi8255->in_mask[port])
324   if (m_in_mask[port])
258325   {
259      if (ppi8255->port_read[port].read != NULL)
260         ppi8255_input(device, port, devcb_call_read8(&ppi8255->port_read[port], 0));
261
262      result |= ppi8255->read[port] & ppi8255->in_mask[port];
326      ppi8255_input(port, devcb_call_read8(&m_port_read[port], 0));
327      result |= m_read[port] & m_in_mask[port];
263328   }
264   result |= ppi8255->latch[port] & ppi8255->out_mask[port];
329   result |= m_latch[port] & m_out_mask[port];
265330
266331   switch (port)
267332   {
268333   case 0:
269334      /* clear input buffer full flag */
270      ppi8255->ibf_a = 0;
335      m_ibf_a = 0;
271336      break;
272337
273338   case 1:
274339      /* clear input buffer full flag */
275      ppi8255->ibf_b = 0;
340      m_ibf_b = 0;
276341      break;
277342
278343   case 2:
279344      /* read special port 2 signals */
280      ppi8255_get_handshake_signals(ppi8255, 1, &result);
345      ppi8255_get_handshake_signals(1, &result);
281346      break;
282347   }
283348
r8910r8911
286351
287352
288353
289READ8_DEVICE_HANDLER( ppi8255_r )
354READ8_DEVICE_HANDLER_TRAMPOLINE(ppi8255, ppi8255_r)
290355{
291   ppi8255_t   *ppi8255 = get_safe_token(device);
292356   UINT8 result = 0;
293357
294358   offset %= 4;
r8910r8911
298362      case 0: /* Port A read */
299363      case 1: /* Port B read */
300364      case 2: /* Port C read */
301         result = ppi8255_read_port(device, offset);
365         result = ppi8255_read_port(offset);
302366         break;
303367
304368      case 3: /* Control word */
305         result = ppi8255->control;
369         result = m_control;
306370         break;
307371   }
308372
r8910r8911
311375
312376
313377
314static void ppi8255_write_port(running_device *device, int port)
378void ppi8255_device::ppi8255_write_port(int port)
315379{
316   ppi8255_t   *ppi8255 = get_safe_token(device);
317   UINT8 write_data;
380   UINT8 write_data = m_latch[port] & m_out_mask[port];
381   write_data |= 0xFF & ~m_out_mask[port];
318382
319   write_data = ppi8255->latch[port] & ppi8255->out_mask[port];
320   write_data |= 0xFF & ~ppi8255->out_mask[port];
321
322383   /* write out special port 2 signals */
323384   if (port == 2)
324      ppi8255_get_handshake_signals(ppi8255, 0, &write_data);
385   {
386      ppi8255_get_handshake_signals(0, &write_data);
387   }
325388
326   ppi8255->output[port] = write_data;
327   if (ppi8255->port_write[port].write != NULL)
328      devcb_call_write8(&ppi8255->port_write[port], 0, write_data);
389   m_output[port] = write_data;
390   devcb_call_write8(&m_port_write[port], 0, write_data);
329391}
330392
331393
332394
333WRITE8_DEVICE_HANDLER( ppi8255_w )
395WRITE8_DEVICE_HANDLER_TRAMPOLINE(ppi8255, ppi8255_w)
334396{
335   ppi8255_t   *ppi8255 = get_safe_token(device);
336
337397   offset %= 4;
338398
339399   switch( offset )
r8910r8911
341401      case 0: /* Port A write */
342402      case 1: /* Port B write */
343403      case 2: /* Port C write */
344         ppi8255->latch[offset] = data;
345         ppi8255_write_port(device, offset);
404         m_latch[offset] = data;
405         ppi8255_write_port(offset);
346406
347407         switch(offset)
348408         {
349409            case 0:
350               if (!ppi8255->port_a_dir && (ppi8255->group_a_mode != 0))
410               if (!m_port_a_dir && (m_group_a_mode != 0))
351411               {
352                  ppi8255->obf_a = 1;
353                  ppi8255_write_port(device, 2);
412                  m_obf_a = 1;
413                  ppi8255_write_port(2);
354414               }
355415               break;
356416
357417            case 1:
358               if (!ppi8255->port_b_dir && (ppi8255->group_b_mode != 0))
418               if (!m_port_b_dir && (m_group_b_mode != 0))
359419               {
360                  ppi8255->obf_b = 1;
361                  ppi8255_write_port(device, 2);
420                  m_obf_b = 1;
421                  ppi8255_write_port(2);
362422               }
363423               break;
364424         }
r8910r8911
367427      case 3: /* Control word */
368428         if (data & 0x80)
369429         {
370            set_mode(device, data & 0x7f, 1);
430            set_mode(data & 0x7f, 1);
371431         }
372432         else
373433         {
374434            /* bit set/reset */
375            int bit;
435            int bit = (data >> 1) & 0x07;
376436
377            bit = (data >> 1) & 0x07;
378
379437            if (data & 1)
380               ppi8255->latch[2] |= (1<<bit);   /* set bit */
438            {
439               m_latch[2] |= (1 << bit);   /* set bit */
440            }
381441            else
382               ppi8255->latch[2] &= ~(1<<bit);   /* reset bit */
442            {
443               m_latch[2] &= ~(1 << bit);   /* reset bit */
444            }
383445
384            if (ppi8255->group_b_mode == 1)
446            if (m_group_b_mode == 1)
385447            {
386               if (bit == 2) ppi8255->inte_b = data & 1;
448               if (bit == 2)
449               {
450                  m_inte_b = data & 1;
451               }
387452            }
388453
389            if (ppi8255->group_a_mode == 1)
454            if (m_group_a_mode == 1)
390455            {
391               if (bit == 4 && ppi8255->port_a_dir) ppi8255->inte_a = data & 1;
392               if (bit == 6 && !ppi8255->port_a_dir) ppi8255->inte_a = data & 1;
456               if (bit == 4 && m_port_a_dir)
457               {
458                  m_inte_a = data & 1;
459               }
460               if (bit == 6 && !m_port_a_dir)
461               {
462                  m_inte_a = data & 1;
463               }
393464            }
394465
395            if (ppi8255->group_a_mode == 2)
466            if (m_group_a_mode == 2)
396467            {
397               if (bit == 4) ppi8255->inte_2 = data & 1;
398               if (bit == 6) ppi8255->inte_1 = data & 1;
468               if (bit == 4)
469               {
470                  m_inte_2 = data & 1;
471               }
472               if (bit == 6)
473               {
474                  m_inte_1 = data & 1;
475               }
399476            }
400477
401            ppi8255_write_port(device, 2);
478            ppi8255_write_port(2);
402479         }
403480         break;
404481   }
405482}
406483
407484
408void ppi8255_set_port_a_read(running_device *device, const devcb_read8 *config)
485void ppi8255_device::set_mode(int data, int call_handlers)
409486{
410   ppi8255_t   *ppi8255 = get_safe_token(device);
411   devcb_resolve_read8(&ppi8255->port_read[0], config, device);
412}
413
414void ppi8255_set_port_b_read(running_device *device, const devcb_read8 *config)
415{
416   ppi8255_t   *ppi8255 = get_safe_token(device);
417   devcb_resolve_read8(&ppi8255->port_read[1], config, device);
418}
419
420void ppi8255_set_port_c_read(running_device *device, const devcb_read8 *config)
421{
422   ppi8255_t   *ppi8255 = get_safe_token(device);
423   devcb_resolve_read8(&ppi8255->port_read[2], config, device);
424}
425
426
427void ppi8255_set_port_a_write(running_device *device, const devcb_write8 *config)
428{
429   ppi8255_t   *ppi8255 = get_safe_token(device);
430   devcb_resolve_write8(&ppi8255->port_write[0], config, device);
431}
432
433void ppi8255_set_port_b_write(running_device *device, const devcb_write8 *config)
434{
435   ppi8255_t   *ppi8255 = get_safe_token(device);
436   devcb_resolve_write8(&ppi8255->port_write[1], config, device);
437}
438
439void ppi8255_set_port_c_write(running_device *device, const devcb_write8 *config)
440{
441   ppi8255_t   *ppi8255 = get_safe_token(device);
442   devcb_resolve_write8(&ppi8255->port_write[2], config, device);
443}
444
445
446static void set_mode(running_device *device, int data, int call_handlers)
447{
448   ppi8255_t   *ppi8255 = get_safe_token(device);
449   int i;
450
451487   /* parse out mode */
452   ppi8255->group_a_mode = (data >> 5) & 3;
453   ppi8255->group_b_mode = (data >> 2) & 1;
454   ppi8255->port_a_dir = (data >> 4) & 1;
455   ppi8255->port_b_dir = (data >> 1) & 1;
456   ppi8255->port_ch_dir = (data >> 3) & 1;
457   ppi8255->port_cl_dir = (data >> 0) & 1;
488   m_group_a_mode = (data >> 5) & 3;
489   m_group_b_mode = (data >> 2) & 1;
490   m_port_a_dir = (data >> 4) & 1;
491   m_port_b_dir = (data >> 1) & 1;
492   m_port_ch_dir = (data >> 3) & 1;
493   m_port_cl_dir = (data >> 0) & 1;
458494
459495   /* normalize group_a_mode */
460   if (ppi8255->group_a_mode == 3)
461      ppi8255->group_a_mode = 2;
496   if (m_group_a_mode == 3)
497   {
498      m_group_a_mode = 2;
499   }
462500
463501   /* Port A direction */
464   if (ppi8255->group_a_mode == 2)
465      ppi8255->in_mask[0] = 0xFF, ppi8255->out_mask[0] = 0xFF;   /* bidirectional */
502   if (m_group_a_mode == 2)
503   {
504      m_in_mask[0] = 0xFF;
505      m_out_mask[0] = 0xFF;   /* bidirectional */
506   }
466507   else
467      if (ppi8255->port_a_dir)
468         ppi8255->in_mask[0] = 0xFF, ppi8255->out_mask[0] = 0x00;   /* input */
508   {
509      if (m_port_a_dir)
510      {
511         m_in_mask[0] = 0xFF;
512         m_out_mask[0] = 0x00;   /* input */
513      }
469514      else
470         ppi8255->in_mask[0] = 0x00, ppi8255->out_mask[0] = 0xFF;   /* output */
515      {
516         m_in_mask[0] = 0x00;
517         m_out_mask[0] = 0xFF;   /* output */
518      }
519   }
471520
472521   /* Port B direction */
473   if (ppi8255->port_b_dir)
474      ppi8255->in_mask[1] = 0xFF, ppi8255->out_mask[1] = 0x00;   /* input */
522   if (m_port_b_dir)
523   {
524      m_in_mask[1] = 0xFF;
525      m_out_mask[1] = 0x00;   /* input */
526   }
475527   else
476      ppi8255->in_mask[1] = 0x00, ppi8255->out_mask[1] = 0xFF;   /* output */
528   {
529      m_in_mask[1] = 0x00;
530      m_out_mask[1] = 0xFF;   /* output */
531   }
477532
478533   /* Port C upper direction */
479   if (ppi8255->port_ch_dir)
480      ppi8255->in_mask[2] = 0xF0, ppi8255->out_mask[2] = 0x00;   /* input */
534   if (m_port_ch_dir)
535   {
536      m_in_mask[2] = 0xF0;
537      m_out_mask[2] = 0x00;   /* input */
538   }
481539   else
482      ppi8255->in_mask[2] = 0x00, ppi8255->out_mask[2] = 0xF0;   /* output */
540   {
541      m_in_mask[2] = 0x00;
542      m_out_mask[2] = 0xF0;   /* output */
543   }
483544
484545   /* Port C lower direction */
485   if (ppi8255->port_cl_dir)
486      ppi8255->in_mask[2] |= 0x0F;   /* input */
546   if (m_port_cl_dir)
547   {
548      m_in_mask[2] |= 0x0F;   /* input */
549   }
487550   else
488      ppi8255->out_mask[2] |= 0x0F;   /* output */
551   {
552      m_out_mask[2] |= 0x0F;   /* output */
553   }
489554
490555   /* now depending on the group modes, certain Port C lines may be replaced
491556     * with varying control signals */
492   switch(ppi8255->group_a_mode)
557   switch(m_group_a_mode)
493558   {
494559      case 0:   /* Group A mode 0 */
495560         /* no changes */
r8910r8911
497562
498563      case 1:   /* Group A mode 1 */
499564         /* bits 5-3 are reserved by Group A mode 1 */
500         ppi8255->in_mask[2] &= ~0x38;
501         ppi8255->out_mask[2] &= ~0x38;
565         m_in_mask[2] &= ~0x38;
566         m_out_mask[2] &= ~0x38;
502567         break;
503568
504569      case 2: /* Group A mode 2 */
505570         /* bits 7-3 are reserved by Group A mode 2 */
506         ppi8255->in_mask[2] &= ~0xF8;
507         ppi8255->out_mask[2] &= ~0xF8;
571         m_in_mask[2] &= ~0xF8;
572         m_out_mask[2] &= ~0xF8;
508573         break;
509574   }
510575
511   switch(ppi8255->group_b_mode)
576   switch(m_group_b_mode)
512577   {
513578      case 0:   /* Group B mode 0 */
514579         /* no changes */
r8910r8911
516581
517582      case 1:   /* Group B mode 1 */
518583         /* bits 2-0 are reserved by Group B mode 1 */
519         ppi8255->in_mask[2] &= ~0x07;
520         ppi8255->out_mask[2] &= ~0x07;
584         m_in_mask[2] &= ~0x07;
585         m_out_mask[2] &= ~0x07;
521586         break;
522587   }
523588
524589   /* KT: 25-Dec-99 - 8255 resets latches when mode set */
525   ppi8255->latch[0] = ppi8255->latch[1] = ppi8255->latch[2] = 0;
590   m_latch[0] = m_latch[1] = m_latch[2] = 0;
526591
527592   if (call_handlers)
528593   {
529      for (i = 0; i < 3; i++)
530         ppi8255_write_port(device, i);
594      for (int i = 0; i < 3; i++)
595      {
596         ppi8255_write_port(i);
597      }
531598   }
532599
533600   /* reset flip-flops */
534   ppi8255->obf_a = ppi8255->ibf_a = 0;
535   ppi8255->obf_b = ppi8255->ibf_b = 0;
536   ppi8255->inte_a = ppi8255->inte_b = ppi8255->inte_1 = ppi8255->inte_2 = 0;
601   m_obf_a = m_ibf_a = 0;
602   m_obf_b = m_ibf_b = 0;
603   m_inte_a = m_inte_b = m_inte_1 = m_inte_2 = 0;
537604
538605   /* store control word */
539   ppi8255->control = data;
606   m_control = data;
540607}
541608
609void ppi8255_set_port_a_read(running_device *device, const devcb_read8 *config)
610{
611   downcast<ppi8255_device*>(device)->ppi8255_set_port_read(0, config);
612}
542613
543void ppi8255_set_port_a( running_device *device, UINT8 data ) { ppi8255_input(device, 0, data); }
544void ppi8255_set_port_b( running_device *device, UINT8 data ) { ppi8255_input(device, 1, data); }
545void ppi8255_set_port_c( running_device *device, UINT8 data ) { ppi8255_input(device, 2, data); }
614void ppi8255_set_port_b_read(running_device *device, const devcb_read8 *config)
615{
616   downcast<ppi8255_device*>(device)->ppi8255_set_port_read(1, config);
617}
546618
547UINT8 ppi8255_get_port_a( running_device *device ) {
548   ppi8255_t   *ppi8255 = get_safe_token(device);
549
550   return ppi8255->output[0];
619void ppi8255_set_port_c_read(running_device *device, const devcb_read8 *config)
620{
621   downcast<ppi8255_device*>(device)->ppi8255_set_port_read(2, config);
551622}
552623
553UINT8 ppi8255_get_port_b( running_device *device ) {
554   ppi8255_t   *ppi8255 = get_safe_token(device);
555624
556   return ppi8255->output[1];
625void ppi8255_set_port_a_write(running_device *device, const devcb_write8 *config)
626{
627   downcast<ppi8255_device*>(device)->ppi8255_set_port_write(0, config);
557628}
558629
559UINT8 ppi8255_get_port_c( running_device *device ) {
560   ppi8255_t   *ppi8255 = get_safe_token(device);
630void ppi8255_set_port_b_write(running_device *device, const devcb_write8 *config)
631{
632   downcast<ppi8255_device*>(device)->ppi8255_set_port_write(1, config);
633}
561634
562   return ppi8255->output[2];
635void ppi8255_set_port_c_write(running_device *device, const devcb_write8 *config)
636{
637   downcast<ppi8255_device*>(device)->ppi8255_set_port_write(2, config);
563638}
564639
565640
566static DEVICE_START( ppi8255 ) {
567   ppi8255_t   *ppi8255 = get_safe_token(device);
641void ppi8255_set_port_a( running_device *device, UINT8 data )
642{
643   downcast<ppi8255_device*>(device)->ppi8255_set_port(0, data);
644}
568645
569   ppi8255->intf = (const ppi8255_interface *)device->baseconfig().static_config();
646void ppi8255_set_port_b( running_device *device, UINT8 data )
647{
648   downcast<ppi8255_device*>(device)->ppi8255_set_port(1, data);
649}
570650
571   devcb_resolve_read8(&ppi8255->port_read[0], &ppi8255->intf->port_a_read, device);
572   devcb_resolve_read8(&ppi8255->port_read[1], &ppi8255->intf->port_b_read, device);
573   devcb_resolve_read8(&ppi8255->port_read[2], &ppi8255->intf->port_c_read, device);
651void ppi8255_set_port_c( running_device *device, UINT8 data )
652{
653   downcast<ppi8255_device*>(device)->ppi8255_set_port(2, data);
654}
574655
575   devcb_resolve_write8(&ppi8255->port_write[0], &ppi8255->intf->port_a_write, device);
576   devcb_resolve_write8(&ppi8255->port_write[1], &ppi8255->intf->port_b_write, device);
577   devcb_resolve_write8(&ppi8255->port_write[2], &ppi8255->intf->port_c_write, device);
578656
579   /* register for state saving */
580   state_save_register_device_item(device, 0, ppi8255->group_a_mode);
581   state_save_register_device_item(device, 0, ppi8255->group_b_mode);
582   state_save_register_device_item(device, 0, ppi8255->port_a_dir);
583   state_save_register_device_item(device, 0, ppi8255->port_b_dir);
584   state_save_register_device_item(device, 0, ppi8255->port_ch_dir);
585   state_save_register_device_item(device, 0, ppi8255->port_cl_dir);
586   state_save_register_device_item(device, 0, ppi8255->obf_a);
587   state_save_register_device_item(device, 0, ppi8255->obf_b);
588   state_save_register_device_item(device, 0, ppi8255->ibf_a);
589   state_save_register_device_item(device, 0, ppi8255->ibf_b);
590   state_save_register_device_item(device, 0, ppi8255->inte_a);
591   state_save_register_device_item(device, 0, ppi8255->inte_b);
592   state_save_register_device_item(device, 0, ppi8255->inte_1);
593   state_save_register_device_item(device, 0, ppi8255->inte_2);
594   state_save_register_device_item_array(device, 0, ppi8255->in_mask);
595   state_save_register_device_item_array(device, 0, ppi8255->out_mask);
596   state_save_register_device_item_array(device, 0, ppi8255->read);
597   state_save_register_device_item_array(device, 0, ppi8255->latch);
657UINT8 ppi8255_get_port_a( running_device *device )
658{
659   return downcast<ppi8255_device*>(device)->ppi8255_get_port(0);
598660}
599661
600
601static DEVICE_RESET( ppi8255 ) {
602   ppi8255_t   *ppi8255 = get_safe_token(device);
603   int         i;
604
605   ppi8255->group_a_mode = 0;
606   ppi8255->group_b_mode = 0;
607   ppi8255->port_a_dir = 0;
608   ppi8255->port_b_dir = 0;
609   ppi8255->port_ch_dir = 0;
610   ppi8255->port_cl_dir = 0;
611   ppi8255->obf_a = ppi8255->ibf_a = 0;
612   ppi8255->obf_b = ppi8255->ibf_b = 0;
613   ppi8255->inte_a = ppi8255->inte_b = ppi8255->inte_1 = ppi8255->inte_2 = 0;
614
615   for ( i = 0; i < 3; i++ ) {
616      ppi8255->in_mask[i] = ppi8255->out_mask[i] = ppi8255->read[i] = ppi8255->latch[i] = ppi8255->output[i] = 0;
617   }
618
619   set_mode(device, 0x9b, 0);   /* Mode 0, all ports set to input */
662UINT8 ppi8255_get_port_b( running_device *device )
663{
664   return downcast<ppi8255_device*>(device)->ppi8255_get_port(1);
620665}
621666
622
623DEVICE_GET_INFO(ppi8255) {
624   switch ( state ) {
625      /* --- the following bits of info are returned as 64-bit signed integers --- */
626      case DEVINFO_INT_TOKEN_BYTES:            info->i = sizeof(ppi8255_t);            break;
627      case DEVINFO_INT_INLINE_CONFIG_BYTES:      info->i = 0;                        break;
628
629      /* --- the following bits of info are returned as pointers to data or functions --- */
630      case DEVINFO_FCT_START:                  info->start = DEVICE_START_NAME(ppi8255);   break;
631      case DEVINFO_FCT_STOP:                  /* nothing */                        break;
632      case DEVINFO_FCT_RESET:                  info->reset = DEVICE_RESET_NAME(ppi8255);   break;
633
634      /* --- the following bits of info are returned as NULL-terminated strings --- */
635      case DEVINFO_STR_NAME:                  strcpy(info->s, "Intel PPI8255");         break;
636      case DEVINFO_STR_FAMILY:               strcpy(info->s, "PPI8255");               break;
637      case DEVINFO_STR_VERSION:               strcpy(info->s, "1.00");               break;
638      case DEVINFO_STR_SOURCE_FILE:            strcpy(info->s, __FILE__);               break;
639      case DEVINFO_STR_CREDITS:               strcpy(info->s, "Copyright the MAME and MESS Teams"); break;
640   }
667UINT8 ppi8255_get_port_c( running_device *device )
668{
669   return downcast<ppi8255_device*>(device)->ppi8255_get_port(2);
641670}
642
643
644DEFINE_LEGACY_DEVICE(PPI8255, ppi8255);
src/emu/machine/8255ppi.h
r8910r8911
66
77*********************************************************************/
88
9#pragma once
10
911#ifndef __8255PPI_H_
1012#define __8255PPI_H_
1113
12#include "devlegcy.h"
14#include "emu.h"
1315
1416
15DECLARE_LEGACY_DEVICE(PPI8255, ppi8255);
1617
17
1818/***************************************************************************
19    TYPE DEFINITIONS
20***************************************************************************/
21
22typedef struct _ppi8255_interface ppi8255_interface;
23struct _ppi8255_interface
24{
25   devcb_read8 port_a_read;
26   devcb_read8 port_b_read;
27   devcb_read8 port_c_read;
28   devcb_write8 port_a_write;
29   devcb_write8 port_b_write;
30   devcb_write8 port_c_write;
31};
32
33
34/***************************************************************************
3519    DEVICE CONFIGURATION MACROS
3620***************************************************************************/
3721
r8910r8911
4428   MDRV_DEVICE_CONFIG(_intrf)
4529
4630
31/***************************************************************************
32    TYPE DEFINITIONS
33***************************************************************************/
4734
35
36// ======================> ppi8255_interface
37
38struct ppi8255_interface
39{
40   devcb_read8 m_port_a_read;
41   devcb_read8 m_port_b_read;
42   devcb_read8 m_port_c_read;
43   devcb_write8 m_port_a_write;
44   devcb_write8 m_port_b_write;
45   devcb_write8 m_port_c_write;
46};
47
48
49
50// ======================> ppi8255_device_config
51
52class ppi8255_device_config : public device_config,
53                              public ppi8255_interface
54{
55    friend class ppi8255_device;
56
57    // construction/destruction
58    ppi8255_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
59
60public:
61    // allocators
62    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
63    virtual device_t *alloc_device(running_machine &machine) const;
64
65protected:
66    // device_config overrides
67    virtual void device_config_complete();
68};
69
70
71
72// ======================> ppi8255_device
73
74class ppi8255_device :  public device_t
75{
76    friend class ppi8255_device_config;
77
78    // construction/destruction
79    ppi8255_device(running_machine &_machine, const ppi8255_device_config &_config);
80
81public:
82
83   UINT8 ppi8255_r(UINT32 offset);
84   void ppi8255_w(UINT32 offset, UINT8 data);
85
86   void ppi8255_set_port_read(int which, const devcb_read8 *config) { devcb_resolve_read8(&m_port_read[which], config, this); }
87   void ppi8255_set_port_write(int which, const devcb_write8 *config) { devcb_resolve_write8(&m_port_write[which], config, this); }
88
89   void ppi8255_set_port(int which, UINT8 data) { ppi8255_input(which, data); }
90   UINT8 ppi8255_get_port(int which) { return m_output[which]; }
91
92   void ppi8255_set_port_a(UINT8 data);
93   void ppi8255_set_port_b(UINT8 data);
94   void ppi8255_set_port_c(UINT8 data);
95
96   UINT8 ppi8255_get_port_a();
97   UINT8 ppi8255_get_port_b();
98   UINT8 ppi8255_get_port_c();
99
100protected:
101    // device-level overrides
102    virtual void device_start();
103    virtual void device_reset();
104    virtual void device_post_load() { }
105    virtual void device_clock_changed() { }
106
107   static TIMER_CALLBACK( callback );
108
109private:
110
111   void ppi8255_get_handshake_signals(int is_read, UINT8 *result);
112   void ppi8255_input(int port, UINT8 data);
113
114   UINT8 ppi8255_read_port(int port);
115   void ppi8255_write_port(int port);
116
117   void set_mode(int data, int call_handlers);
118
119   devcb_resolved_read8 m_port_read[3];
120   devcb_resolved_write8 m_port_write[3];
121
122   /* mode flags */
123   UINT8 m_group_a_mode;
124   UINT8 m_group_b_mode;
125   UINT8 m_port_a_dir;
126   UINT8 m_port_b_dir;
127   UINT8 m_port_ch_dir;
128   UINT8 m_port_cl_dir;
129
130   /* handshake signals (1=asserted; 0=non-asserted) */
131   UINT8 m_obf_a;
132   UINT8 m_obf_b;
133   UINT8 m_ibf_a;
134   UINT8 m_ibf_b;
135   UINT8 m_inte_a;
136   UINT8 m_inte_b;
137   UINT8 m_inte_1;
138   UINT8 m_inte_2;
139
140   UINT8 m_in_mask[3];      /* input mask */
141   UINT8 m_out_mask[3];   /* output mask */
142   UINT8 m_read[3];      /* data read from ports */
143   UINT8 m_latch[3];      /* data written to ports */
144   UINT8 m_output[3];      /* actual output data */
145   UINT8 m_control;      /* mode control word */
146
147    const ppi8255_device_config &m_config;
148};
149
150
151// device type definition
152extern const device_type PPI8255;
153
154
155
156/***************************************************************************
157    PROTOTYPES
158***************************************************************************/
159
48160READ8_DEVICE_HANDLER( ppi8255_r );
49161WRITE8_DEVICE_HANDLER( ppi8255_w );
50162
51
52163void ppi8255_set_port_a_read( running_device *device, const devcb_read8 *config );
53164void ppi8255_set_port_b_read( running_device *device, const devcb_read8 *config );
54165void ppi8255_set_port_c_read( running_device *device, const devcb_read8 *config );
src/emu/machine/i2cmem.c
r8910r8911
110110
111111
112112//-------------------------------------------------
113//  static_set_interface - set the device
114//  configuration
115//-------------------------------------------------
116
117void i2cmem_device_config::static_set_interface(device_config *device, const i2cmem_interface &interface)
118{
119   i2cmem_device_config *i2cmem = downcast<i2cmem_device_config *>(device);
120   *static_cast<i2cmem_interface *>(i2cmem) = interface;
121}
122
123
124//-------------------------------------------------
113125//  device_config_complete - perform any
114126//  operations now that the configuration is
115127//  complete
r8910r8911
117129
118130void i2cmem_device_config::device_config_complete()
119131{
120   // extract inline configuration from raw data
121   const i2cmem_interface *intf = reinterpret_cast<const i2cmem_interface *>( m_inline_data[ INLINE_INTERFACE ] );
122
123   // inherit a copy of the static data
124   if( intf != NULL )
125   {
126      *static_cast<i2cmem_interface *>(this) = *intf;
127   }
128
129132   m_space_config = address_space_config( "i2cmem", ENDIANNESS_BIG, 8,  m_address_bits, 0, *ADDRESS_MAP_NAME( i2cmem_map8 ) );
130133}
131134
r8910r8911
138141bool i2cmem_device_config::device_validity_check( const game_driver &driver ) const
139142{
140143   bool error = false;
141
142   if( m_inline_data[ INLINE_INTERFACE ] == 0 )
143   {
144      mame_printf_error( "%s: %s i2cmem device '%s' did not specify an interface\n", driver.source_file, driver.name, tag() );
145      error = true;
146   }
147
148144   return error;
149145}
150146
src/emu/machine/i2cmem.h
r8910r8911
2626
2727#define MDRV_I2CMEM_ADD( _tag, _interface ) \
2828   MDRV_DEVICE_ADD( _tag, I2CMEM, 0 ) \
29   MDRV_DEVICE_INLINE_DATAPTR( i2cmem_device_config::INLINE_INTERFACE, &_interface )
29   i2cmem_device_config::static_set_interface(device, _interface);
3030
3131
3232//**************************************************************************
r8910r8911
6161   static device_config *static_alloc_device_config( const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock );
6262   virtual device_t *alloc_device( running_machine &machine ) const;
6363
64   // inline configuration indexes
65   enum
66   {
67      INLINE_INTERFACE
68   };
64   // inline configuration
65   static void static_set_interface(device_config *device, const i2cmem_interface &interface);
6966
7067protected:
7168   // device_config overrides
src/emu/machine/6850acia.c
r8910r8911
88
99#include "emu.h"
1010#include "6850acia.h"
11#include "devhelpr.h"
1112
1213
1314/***************************************************************************
r8910r8911
2021#define CR7      0x80
2122
2223#define TXD(_data) \
23   devcb_call_write_line(&acia_p->out_tx_func, _data)
24   devcb_call_write_line(&m_out_tx_func, _data)
2425
2526#define RTS(_data) \
26   devcb_call_write_line(&acia_p->out_rts_func, _data)
27   devcb_call_write_line(&m_out_rts_func, _data)
2728
28static void acia6850_check_interrupts(running_device *device);
29
3029/***************************************************************************
31    TYPE DEFINITIONS
32***************************************************************************/
33
34enum serial_state
35{
36   START,
37   DATA,
38   PARITY,
39   STOP,
40   STOP2,
41};
42
43enum _parity_type
44{
45   NONE,
46   ODD,
47   EVEN
48};
49typedef enum _parity_type parity_type;
50
51typedef struct _acia6850_t acia6850_t;
52struct _acia6850_t
53{
54   devcb_resolved_read_line   in_rx_func;
55   devcb_resolved_write_line   out_tx_func;
56   devcb_resolved_read_line   in_cts_func;
57   devcb_resolved_write_line   out_rts_func;
58   devcb_resolved_read_line   in_dcd_func;
59   devcb_resolved_write_line   out_irq_func;
60
61   UINT8      ctrl;
62   UINT8      status;
63
64   UINT8      tdr;
65   UINT8      rdr;
66   UINT8      rx_shift;
67   UINT8      tx_shift;
68
69   UINT8      rx_counter;
70   UINT8      tx_counter;
71
72   int         rx_clock;
73   int         tx_clock;
74
75   int         divide;
76
77   /* Counters */
78   int         tx_bits;
79   int         rx_bits;
80   int         tx_parity;
81   int         rx_parity;
82
83   /* TX/RX state */
84   int         bits;
85   parity_type   parity;
86   int         stopbits;
87   int         tx_int;
88
89   /* Signals */
90   int         overrun;
91   int         reset;
92   int         rts;
93   int         brk;
94   int         first_reset;
95   int         status_read;
96   enum      serial_state rx_state;
97   enum      serial_state tx_state;
98   int         irq;
99
100   emu_timer   *rx_timer;
101   emu_timer   *tx_timer;
102};
103
104
105/***************************************************************************
10630    LOCAL VARIABLES
10731***************************************************************************/
10832
109static const int ACIA6850_DIVIDE[3] = { 1, 16, 64 };
33const int acia6850_device::ACIA6850_DIVIDE[3] = { 1, 16, 64 };
11034
111static const int ACIA6850_WORD[8][3] =
35const int acia6850_device::ACIA6850_WORD[8][3] =
11236{
11337   { 7, EVEN, 2 },
11438   { 7, ODD,  2 },
r8910r8911
12145};
12246
12347
48
12449/***************************************************************************
125    PROTOTYPES
50    LIVE DEVICE
12651***************************************************************************/
12752
128static TIMER_CALLBACK( receive_event );
129static TIMER_CALLBACK( transmit_event );
53const device_type ACIA6850 = acia6850_device_config::static_alloc_device_config;
13054
55GENERIC_DEVICE_CONFIG_SETUP(acia6850, "ACIA6850")
13156
132/***************************************************************************
133    INLINE FUNCTIONS
134***************************************************************************/
57//-------------------------------------------------
58//  device_config_complete - perform any
59//  operations now that the configuration is
60//  complete
61//-------------------------------------------------
13562
136INLINE acia6850_t *get_token(running_device *device)
63void acia6850_device_config::device_config_complete()
13764{
138   assert(device != NULL);
139   assert(device->type() == ACIA6850);
140   return (acia6850_t *) downcast<legacy_device_base *>(device)->token();
65   // inherit a copy of the static data
66   const acia6850_interface *intf = reinterpret_cast<const acia6850_interface *>(static_config());
67   if (intf != NULL)
68   {
69      *static_cast<acia6850_interface *>(this) = *intf;
70   }
71
72   // or initialize to defaults if none provided
73   else
74   {
75      m_tx_clock = 0;
76      m_rx_clock = 0;
77       memset(&m_in_rx_func, 0, sizeof(m_in_rx_func));
78       memset(&m_out_tx_func, 0, sizeof(m_out_tx_func));
79       memset(&m_in_cts_func, 0, sizeof(m_in_cts_func));
80       memset(&m_out_rts_func, 0, sizeof(m_out_rts_func));
81       memset(&m_in_dcd_func, 0, sizeof(m_in_dcd_func));
82       memset(&m_out_irq_func, 0, sizeof(m_out_irq_func));
83   }
14184}
14285
14386
144INLINE acia6850_interface *get_interface(running_device *device)
87//-------------------------------------------------
88//  acia6850_device - constructor
89//-------------------------------------------------
90
91acia6850_device::acia6850_device(running_machine &_machine, const acia6850_device_config &config)
92    : device_t(_machine, config),
93      m_config(config)
14594{
146   assert(device != NULL);
147   assert(device->type() == ACIA6850);
148   return (acia6850_interface *) device->baseconfig().static_config();
95
14996}
15097
15198
152/***************************************************************************
153    IMPLEMENTATION
154***************************************************************************/
99//-------------------------------------------------
100//  device_start - device-specific startup
101//-------------------------------------------------
155102
156/*-------------------------------------------------
157    DEVICE_RESET( acia6850 )
158-------------------------------------------------*/
159
160static DEVICE_RESET( acia6850 )
103void acia6850_device::device_start()
161104{
162   acia6850_t *acia_p = get_token(device);
105   /* resolve callbacks */
106   devcb_resolve_read_line(&m_in_rx_func, &m_config.m_in_rx_func, this);
107   devcb_resolve_write_line(&m_out_tx_func, &m_config.m_out_tx_func, this);
108   devcb_resolve_read_line(&m_in_cts_func, &m_config.m_in_cts_func, this);
109   devcb_resolve_write_line(&m_out_rts_func, &m_config.m_out_rts_func, this);
110   devcb_resolve_read_line(&m_in_dcd_func, &m_config.m_in_dcd_func, this);
111   devcb_resolve_write_line(&m_out_irq_func, &m_config.m_out_irq_func, this);
163112
164   int cts = devcb_call_read_line(&acia_p->in_cts_func);
165   int dcd = devcb_call_read_line(&acia_p->in_dcd_func);
113   m_rx_clock = m_config.m_rx_clock;
114   m_tx_clock = m_config.m_tx_clock;
115   m_tx_counter = 0;
116   m_rx_counter = 0;
117   m_rx_timer = timer_alloc(&m_machine, receive_event_callback, (void *)this);
118   m_tx_timer = timer_alloc(&m_machine, transmit_event_callback, (void *)this);
119   m_first_reset = 1;
120   m_status_read = 0;
121   m_brk = 0;
166122
167   acia_p->status = (cts << 3) | (dcd << 2) | ACIA6850_STATUS_TDRE;
168   acia_p->tdr = 0;
169   acia_p->rdr = 0;
170   acia_p->tx_shift = 0;
171   acia_p->rx_shift = 0;
172   acia_p->tx_counter = 0;
173   acia_p->rx_counter = 0;
123   timer_reset(m_rx_timer, attotime_never);
124   timer_reset(m_tx_timer, attotime_never);
174125
126   state_save_register_device_item(this, 0, m_ctrl);
127   state_save_register_device_item(this, 0, m_status);
128   state_save_register_device_item(this, 0, m_rx_clock);
129   state_save_register_device_item(this, 0, m_tx_clock);
130   state_save_register_device_item(this, 0, m_rx_counter);
131   state_save_register_device_item(this, 0, m_tx_counter);
132   state_save_register_device_item(this, 0, m_rx_shift);
133   state_save_register_device_item(this, 0, m_tx_shift);
134   state_save_register_device_item(this, 0, m_rdr);
135   state_save_register_device_item(this, 0, m_tdr);
136   state_save_register_device_item(this, 0, m_rx_bits);
137   state_save_register_device_item(this, 0, m_tx_bits);
138   state_save_register_device_item(this, 0, m_rx_parity);
139   state_save_register_device_item(this, 0, m_tx_parity);
140   state_save_register_device_item(this, 0, m_tx_int);
141
142   state_save_register_device_item(this, 0, m_divide);
143   state_save_register_device_item(this, 0, m_overrun);
144   state_save_register_device_item(this, 0, m_reset);
145   state_save_register_device_item(this, 0, m_first_reset);
146   state_save_register_device_item(this, 0, m_rts);
147   state_save_register_device_item(this, 0, m_brk);
148   state_save_register_device_item(this, 0, m_status_read);
149}
150
151
152//-------------------------------------------------
153//  device_reset - device-specific reset
154//-------------------------------------------------
155
156void acia6850_device::device_reset()
157{
158   int cts = devcb_call_read_line(&m_in_cts_func);
159   int dcd = devcb_call_read_line(&m_in_dcd_func);
160
161   m_status = (cts << 3) | (dcd << 2) | ACIA6850_STATUS_TDRE;
162   m_tdr = 0;
163   m_rdr = 0;
164   m_tx_shift = 0;
165   m_rx_shift = 0;
166   m_tx_counter = 0;
167   m_rx_counter = 0;
168
175169   TXD(1);
176   acia_p->overrun = 0;
177   acia_p->status_read = 0;
178   acia_p->brk = 0;
170   m_overrun = 0;
171   m_status_read = 0;
172   m_brk = 0;
179173
180   acia_p->rx_state = START;
181   acia_p->tx_state = START;
182   acia_p->irq = 0;
174   m_rx_state = START;
175   m_tx_state = START;
176   m_irq = 0;
183177
184   devcb_call_write_line(&acia_p->out_irq_func, 1);
178   devcb_call_write_line(&m_out_irq_func, 1);
185179
186   if (acia_p->first_reset)
180   if (m_first_reset)
187181   {
188      acia_p->first_reset = 0;
182      m_first_reset = 0;
189183
190184      RTS(1);
191185   }
192186   else
193187   {
194      RTS(acia_p->rts);
188      RTS(m_rts);
195189   }
196190}
197191
198192
199193
200194/*-------------------------------------------------
201    DEVICE_START( acia6850 )
202-------------------------------------------------*/
203
204static DEVICE_START( acia6850 )
205{
206   acia6850_t *acia_p = get_token(device);
207   acia6850_interface *intf = get_interface(device);
208
209   /* resolve callbacks */
210   devcb_resolve_read_line(&acia_p->in_rx_func, &intf->in_rx_func, device);
211   devcb_resolve_write_line(&acia_p->out_tx_func, &intf->out_tx_func, device);
212   devcb_resolve_read_line(&acia_p->in_cts_func, &intf->in_cts_func, device);
213   devcb_resolve_write_line(&acia_p->out_rts_func, &intf->out_rts_func, device);
214   devcb_resolve_read_line(&acia_p->in_dcd_func, &intf->in_dcd_func, device);
215   devcb_resolve_write_line(&acia_p->out_irq_func, &intf->out_irq_func, device);
216
217   acia_p->rx_clock = intf->rx_clock;
218   acia_p->tx_clock = intf->tx_clock;
219   acia_p->tx_counter = 0;
220   acia_p->rx_counter = 0;
221   acia_p->rx_timer = timer_alloc(device->machine, receive_event, (void *) device);
222   acia_p->tx_timer = timer_alloc(device->machine, transmit_event, (void *) device);
223   acia_p->first_reset = 1;
224   acia_p->status_read = 0;
225   acia_p->brk = 0;
226
227   timer_reset(acia_p->rx_timer, attotime_never);
228   timer_reset(acia_p->tx_timer, attotime_never);
229
230   state_save_register_device_item(device, 0, acia_p->ctrl);
231   state_save_register_device_item(device, 0, acia_p->status);
232   state_save_register_device_item(device, 0, acia_p->rx_clock);
233   state_save_register_device_item(device, 0, acia_p->tx_clock);
234   state_save_register_device_item(device, 0, acia_p->rx_counter);
235   state_save_register_device_item(device, 0, acia_p->tx_counter);
236   state_save_register_device_item(device, 0, acia_p->rx_shift);
237   state_save_register_device_item(device, 0, acia_p->tx_shift);
238   state_save_register_device_item(device, 0, acia_p->rdr);
239   state_save_register_device_item(device, 0, acia_p->tdr);
240   state_save_register_device_item(device, 0, acia_p->rx_bits);
241   state_save_register_device_item(device, 0, acia_p->tx_bits);
242   state_save_register_device_item(device, 0, acia_p->rx_parity);
243   state_save_register_device_item(device, 0, acia_p->tx_parity);
244   state_save_register_device_item(device, 0, acia_p->tx_int);
245
246   state_save_register_device_item(device, 0, acia_p->divide);
247   state_save_register_device_item(device, 0, acia_p->overrun);
248   state_save_register_device_item(device, 0, acia_p->reset);
249   state_save_register_device_item(device, 0, acia_p->first_reset);
250   state_save_register_device_item(device, 0, acia_p->rts);
251   state_save_register_device_item(device, 0, acia_p->brk);
252   state_save_register_device_item(device, 0, acia_p->status_read);
253}
254
255
256/*-------------------------------------------------
257195    acia6850_stat_r - Read Status Register
258196-------------------------------------------------*/
259197
260READ8_DEVICE_HANDLER( acia6850_stat_r )
198READ8_DEVICE_HANDLER_TRAMPOLINE(acia6850, acia6850_stat_r)
261199{
262200   UINT8 status;
263201
264   acia6850_t *acia_p = get_token(device);
202   m_status_read = 1;
203   status = m_status;
265204
266   acia_p->status_read = 1;
267   status = acia_p->status;
268
269205   if (status & ACIA6850_STATUS_CTS)
206   {
270207      status &= ~ACIA6850_STATUS_TDRE;
208   }
271209
272210   return status;
273211}
r8910r8911
277215    acia6850_ctrl_w - Write Control Register
278216-------------------------------------------------*/
279217
280WRITE8_DEVICE_HANDLER( acia6850_ctrl_w )
218WRITE8_DEVICE_HANDLER_TRAMPOLINE(acia6850, acia6850_ctrl_w )
281219{
282   acia6850_t *acia_p = get_token(device);
283
284220   int wordsel;
285221   int divide;
286222
r8910r8911
290226
291227   if (divide == 3)
292228   {
293      acia_p->reset = 1;
294      device->reset();
229      m_reset = 1;
230      device_reset();
295231   }
296232   else
297233   {
298      acia_p->reset = 0;
299      acia_p->divide = ACIA6850_DIVIDE[divide];
234      m_reset = 0;
235      m_divide = ACIA6850_DIVIDE[divide];
300236   }
301237
302238   // Word Select Bits
303239
304240   wordsel = (data & CR4_2) >> 2;
305241
306   acia_p->bits = ACIA6850_WORD[wordsel][0];
307   acia_p->parity = (parity_type)ACIA6850_WORD[wordsel][1];
308   acia_p->stopbits = ACIA6850_WORD[wordsel][2];
242   m_bits = ACIA6850_WORD[wordsel][0];
243   m_parity = (parity_type)ACIA6850_WORD[wordsel][1];
244   m_stopbits = ACIA6850_WORD[wordsel][2];
309245
310246   // Transmitter Control Bits
311247
312248   switch ((data & CR6_5) >> 5)
313249   {
314250   case 0:
315      acia_p->rts = 0;
316      RTS(acia_p->rts);
251      m_rts = 0;
252      RTS(m_rts);
317253
318      acia_p->tx_int = 0;
319      acia_p->brk = 0;
254      m_tx_int = 0;
255      m_brk = 0;
320256      break;
321257
322258   case 1:
323      acia_p->rts = 0;
324      RTS(acia_p->rts);
259      m_rts = 0;
260      RTS(m_rts);
325261
326      acia_p->tx_int = 1;
327      acia_p->brk = 0;
262      m_tx_int = 1;
263      m_brk = 0;
328264      break;
329265
330266   case 2:
331      acia_p->rts = 1;
332      RTS(acia_p->rts);
267      m_rts = 1;
268      RTS(m_rts);
333269
334      acia_p->tx_int = 0;
335      acia_p->brk = 0;
270      m_tx_int = 0;
271      m_brk = 0;
336272      break;
337273
338274   case 3:
339      acia_p->rts = 0;
340      RTS(acia_p->rts);
275      m_rts = 0;
276      RTS(m_rts);
341277
342      acia_p->tx_int = 0;
343      acia_p->brk = 1;
278      m_tx_int = 0;
279      m_brk = 1;
344280      break;
345281   }
346282
347   acia6850_check_interrupts(device);
283   check_interrupts();
348284
349285   // After writing the word type, set the rx/tx clocks (provided the divide values have changed)
350286
351   if ((acia_p->ctrl ^ data) & CR1_0)
287   if ((m_ctrl ^ data) & CR1_0)
352288   {
353      if (!acia_p->reset)
289      if (!m_reset)
354290      {
355         if (acia_p->rx_clock)
291         if (m_rx_clock)
356292         {
357            attotime rx_period = attotime_mul(ATTOTIME_IN_HZ(acia_p->rx_clock), acia_p->divide);
358            timer_adjust_periodic(acia_p->rx_timer, rx_period, 0, rx_period);
293            attotime rx_period = attotime_mul(ATTOTIME_IN_HZ(m_rx_clock), m_divide);
294            timer_adjust_periodic(m_rx_timer, rx_period, 0, rx_period);
359295         }
360296
361         if (acia_p->tx_clock)
297         if (m_tx_clock)
362298         {
363            attotime tx_period = attotime_mul(ATTOTIME_IN_HZ(acia_p->tx_clock), acia_p->divide);
364            timer_adjust_periodic(acia_p->tx_timer, tx_period, 0, tx_period);
299            attotime tx_period = attotime_mul(ATTOTIME_IN_HZ(m_tx_clock), m_divide);
300            timer_adjust_periodic(m_tx_timer, tx_period, 0, tx_period);
365301         }
366302      }
367303   }
368   acia_p->ctrl = data;
304   m_ctrl = data;
369305}
370306
371307
372308/*-------------------------------------------------
373    acia6850_check_interrupts
309    check_interrupts
374310-------------------------------------------------*/
375311
376static void acia6850_check_interrupts(running_device *device)
312void acia6850_device::check_interrupts()
377313{
378   acia6850_t *acia_p = get_token(device);
314   int irq = (m_tx_int && (m_status & ACIA6850_STATUS_TDRE) && (~m_status & ACIA6850_STATUS_CTS)) ||
315      ((m_ctrl & 0x80) && ((m_status & (ACIA6850_STATUS_RDRF|ACIA6850_STATUS_DCD)) || m_overrun));
379316
380   int irq = (acia_p->tx_int && (acia_p->status & ACIA6850_STATUS_TDRE) && (~acia_p->status & ACIA6850_STATUS_CTS)) ||
381      ((acia_p->ctrl & 0x80) && ((acia_p->status & (ACIA6850_STATUS_RDRF|ACIA6850_STATUS_DCD)) || acia_p->overrun));
382
383   if (irq != acia_p->irq)
317   if (irq != m_irq)
384318   {
385      acia_p->irq = irq;
319      m_irq = irq;
386320
387321      if (irq)
388322      {
389         acia_p->status |= ACIA6850_STATUS_IRQ;
390         devcb_call_write_line(&acia_p->out_irq_func, 0);
323         m_status |= ACIA6850_STATUS_IRQ;
324         devcb_call_write_line(&m_out_irq_func, 0);
391325      }
392326      else
393327      {
394         acia_p->status &= ~ACIA6850_STATUS_IRQ;
395         devcb_call_write_line(&acia_p->out_irq_func, 1);
328         m_status &= ~ACIA6850_STATUS_IRQ;
329         devcb_call_write_line(&m_out_irq_func, 1);
396330      }
397331   }
398332}
r8910r8911
402336    acia6850_data_w - Write transmit register
403337-------------------------------------------------*/
404338
405WRITE8_DEVICE_HANDLER( acia6850_data_w )
339WRITE8_DEVICE_HANDLER_TRAMPOLINE(acia6850, acia6850_data_w)
406340{
407   acia6850_t *acia_p = get_token(device);
408
409   if (!acia_p->reset)
341   if (!m_reset)
410342   {
411      acia_p->tdr = data;
412      acia_p->status &= ~ACIA6850_STATUS_TDRE;
413      acia6850_check_interrupts(device);
343      m_tdr = data;
344      m_status &= ~ACIA6850_STATUS_TDRE;
345      check_interrupts();
414346   }
415347   else
416348   {
417      logerror("%s:ACIA %p: Data write while in reset!\n", cpuexec_describe_context(device->machine), device);
349      logerror("%s:ACIA %p: Data write while in reset!\n", cpuexec_describe_context(&m_machine), this);
418350   }
419351}
420352
r8910r8911
423355    acia6850_data_r - Read character
424356-------------------------------------------------*/
425357
426READ8_DEVICE_HANDLER( acia6850_data_r )
358READ8_DEVICE_HANDLER_TRAMPOLINE(acia6850, acia6850_data_r)
427359{
428   acia6850_t *acia_p = get_token(device);
360   m_status &= ~(ACIA6850_STATUS_RDRF | ACIA6850_STATUS_IRQ | ACIA6850_STATUS_PE);
429361
430   acia_p->status &= ~(ACIA6850_STATUS_RDRF | ACIA6850_STATUS_IRQ | ACIA6850_STATUS_PE);
431
432   if (acia_p->status_read)
362   if (m_status_read)
433363   {
434      int dcd = devcb_call_read_line(&acia_p->in_dcd_func);
364      int dcd = devcb_call_read_line(&m_in_dcd_func);
435365
436      acia_p->status_read = 0;
437      acia_p->status &= ~(ACIA6850_STATUS_OVRN | ACIA6850_STATUS_DCD);
366      m_status_read = 0;
367      m_status &= ~(ACIA6850_STATUS_OVRN | ACIA6850_STATUS_DCD);
438368
439369      if (dcd)
440370      {
441         acia_p->status |= ACIA6850_STATUS_DCD;
371         m_status |= ACIA6850_STATUS_DCD;
442372      }
443373   }
444374
445   if (acia_p->overrun == 1)
375   if (m_overrun == 1)
446376   {
447      acia_p->status |= ACIA6850_STATUS_OVRN;
448      acia_p->overrun = 0;
377      m_status |= ACIA6850_STATUS_OVRN;
378      m_overrun = 0;
449379   }
450380
451   acia6850_check_interrupts(device);
381   check_interrupts();
452382
453   return acia_p->rdr;
383   return m_rdr;
454384}
455385
456386
r8910r8911
458388    tx_tick - Transmit a bit
459389-------------------------------------------------*/
460390
461static void tx_tick(running_device *device)
391void acia6850_device::tx_tick()
462392{
463   acia6850_t *acia_p = get_token(device);
464
465   switch (acia_p->tx_state)
393   switch (m_tx_state)
466394   {
467395      case START:
468396      {
469         if (acia_p->brk)
397         if (m_brk)
470398         {
471399            // transmit break
472400
r8910r8911
474402         }
475403         else
476404         {
477            int _cts = devcb_call_read_line(&acia_p->in_cts_func);
405            int _cts = devcb_call_read_line(&m_in_cts_func);
478406
479407            if (_cts)
480               acia_p->status |= ACIA6850_STATUS_CTS;
408            {
409               m_status |= ACIA6850_STATUS_CTS;
410            }
481411            else
482               acia_p->status &= ~ACIA6850_STATUS_CTS;
412            {
413               m_status &= ~ACIA6850_STATUS_CTS;
414            }
483415
484            acia6850_check_interrupts(device);
416            check_interrupts();
485417
486            if (acia_p->status & ACIA6850_STATUS_TDRE)
418            if (m_status & ACIA6850_STATUS_TDRE)
487419            {
488420               // transmitter idle
489421               TXD(1);
r8910r8911
492424            {
493425               // transmit character
494426
495               //logerror("ACIA6850 #%u: TX DATA %x\n", which, acia_p->tdr);
427               //logerror("ACIA6850 #%u: TX DATA %x\n", which, m_tdr);
496428               //logerror("ACIA6850 #%u: TX START BIT\n", which);
497429
498430               TXD(0);
499431
500               acia_p->tx_bits = acia_p->bits;
501               acia_p->tx_shift = acia_p->tdr;
502               acia_p->tx_parity = 0;
503               acia_p->tx_state = DATA;
432               m_tx_bits = m_bits;
433               m_tx_shift = m_tdr;
434               m_tx_parity = 0;
435               m_tx_state = DATA;
504436            }
505437         }
506438         break;
507439      }
508440      case DATA:
509441      {
510         int val = acia_p->tx_shift & 1;
442         int val = m_tx_shift & 1;
511443         //logerror("ACIA6850 #%u: TX DATA BIT %x\n", which, val);
512444
513445         TXD(val);
514         acia_p->tx_parity ^= val;
515         acia_p->tx_shift >>= 1;
446         m_tx_parity ^= val;
447         m_tx_shift >>= 1;
516448
517         if (--(acia_p->tx_bits) == 0)
518            acia_p->tx_state = (acia_p->parity == NONE) ? STOP : PARITY;
449         if (--(m_tx_bits) == 0)
450         {
451            m_tx_state = (m_parity == NONE) ? STOP : PARITY;
452         }
519453
520454         break;
521455      }
522456      case PARITY:
523457      {
524         if (acia_p->parity == EVEN)
525            TXD((acia_p->tx_parity & 1) ? 1 : 0);
458         if (m_parity == EVEN)
459         {
460            TXD((m_tx_parity & 1) ? 1 : 0);
461         }
526462         else
527            TXD((acia_p->tx_parity & 1) ? 0 : 1);
463         {
464            TXD((m_tx_parity & 1) ? 0 : 1);
465         }
528466
529         //logerror("ACIA6850 #%u: TX PARITY BIT %x\n", which, *acia_p->tx_pin);
530         acia_p->tx_state = STOP;
467         //logerror("ACIA6850 #%u: TX PARITY BIT %x\n", which, *m_tx_pin);
468         m_tx_state = STOP;
531469         break;
532470      }
533471      case STOP:
r8910r8911
535473         //logerror("ACIA6850 #%u: TX STOP BIT\n", which);
536474         TXD(1);
537475
538         if (acia_p->stopbits == 1)
476         if (m_stopbits == 1)
539477         {
540            acia_p->tx_state = START;
541            acia_p->status |= ACIA6850_STATUS_TDRE;
478            m_tx_state = START;
479            m_status |= ACIA6850_STATUS_TDRE;
542480         }
543481         else
544482         {
545            acia_p->tx_state = STOP2;
483            m_tx_state = STOP2;
546484         }
547485         break;
548486      }
r8910r8911
550488      {
551489         //logerror("ACIA6850 #%u: TX STOP BIT\n", which);
552490         TXD(1);
553         acia_p->tx_state = START;
554         acia_p->status |= ACIA6850_STATUS_TDRE;
491         m_tx_state = START;
492         m_status |= ACIA6850_STATUS_TDRE;
555493         break;
556494      }
557495   }
r8910r8911
559497
560498
561499/*-------------------------------------------------
562    TIMER_CALLBACK( transmit_event )
500    transmit_event
563501-------------------------------------------------*/
564502
565static TIMER_CALLBACK( transmit_event )
503TIMER_CALLBACK( acia6850_device::transmit_event_callback ) { reinterpret_cast<acia6850_device *>(ptr)->transmit_event(); }
504
505void acia6850_device::transmit_event()
566506{
567   running_device *device = (running_device *)ptr;
568   acia6850_t *acia_p = get_token(device);
569   tx_tick(device);
570   acia_p->tx_counter = 0;
507   tx_tick();
508   m_tx_counter = 0;
571509}
572510
573511
574512/*-------------------------------------------------
575    acia6850_tx_clock_in - As above, but using the tx pin
513    tx_clock_in - As above, but using the tx pin
576514-------------------------------------------------*/
577515
578void acia6850_tx_clock_in(running_device *device)
516void acia6850_tx_clock_in(running_device *device) { downcast<acia6850_device*>(device)->tx_clock_in(); }
517
518void acia6850_device::tx_clock_in()
579519{
580   acia6850_t *acia_p = get_token(device);
520   int _cts = devcb_call_read_line(&m_in_cts_func);
581521
582   int _cts = devcb_call_read_line(&acia_p->in_cts_func);
583
584522   if (_cts)
585      acia_p->status |= ACIA6850_STATUS_CTS;
523   {
524      m_status |= ACIA6850_STATUS_CTS;
525   }
586526   else
587      acia_p->status &= ~ACIA6850_STATUS_CTS;
527   {
528      m_status &= ~ACIA6850_STATUS_CTS;
529   }
588530
589   acia_p->tx_counter ++;
531   m_tx_counter ++;
590532
591   if ( acia_p->tx_counter > acia_p->divide-1)
533   if ( m_tx_counter > m_divide - 1)
592534   {
593      tx_tick(device);
594      acia_p->tx_counter = 0;
535      tx_tick();
536      m_tx_counter = 0;
595537   }
596538
597539}
r8910r8911
601543    rx_tick - Receive a bit
602544-------------------------------------------------*/
603545
604static void rx_tick(running_device *device)
546void acia6850_device::rx_tick()
605547{
606   acia6850_t *acia_p = get_token(device);
548   int dcd = devcb_call_read_line(&m_in_dcd_func);
607549
608   int dcd = devcb_call_read_line(&acia_p->in_dcd_func);
609
610550   if (dcd)
611551   {
612      acia_p->status |= ACIA6850_STATUS_DCD;
613      acia6850_check_interrupts(device);
552      m_status |= ACIA6850_STATUS_DCD;
553      check_interrupts();
614554   }
615   else if ((acia_p->status & (ACIA6850_STATUS_DCD|ACIA6850_STATUS_IRQ)) == ACIA6850_STATUS_DCD)
555   else if ((m_status & (ACIA6850_STATUS_DCD | ACIA6850_STATUS_IRQ)) == ACIA6850_STATUS_DCD)
616556   {
617      acia_p->status &= ~ACIA6850_STATUS_DCD;
557      m_status &= ~ACIA6850_STATUS_DCD;
618558   }
619559
620   if (acia_p->status & ACIA6850_STATUS_DCD)
560   if (m_status & ACIA6850_STATUS_DCD)
621561   {
622      acia_p->rx_state = START;
562      m_rx_state = START;
623563   }
624564   else
625565   {
626      int rxd = devcb_call_read_line(&acia_p->in_rx_func);
566      int rxd = devcb_call_read_line(&m_in_rx_func);
627567
628      switch (acia_p->rx_state)
568      switch (m_rx_state)
629569      {
630570         case START:
631571         {
632572            if (rxd == 0)
633573            {
634574               //logerror("ACIA6850 #%u: RX START BIT\n", which);
635               acia_p->rx_shift = 0;
636               acia_p->rx_parity = 0;
637               acia_p->rx_bits = acia_p->bits;
638               acia_p->rx_state = DATA;
575               m_rx_shift = 0;
576               m_rx_parity = 0;
577               m_rx_bits = m_bits;
578               m_rx_state = DATA;
639579            }
640580            break;
641581         }
642582         case DATA:
643583         {
644584            //logerror("ACIA6850 #%u: RX DATA BIT %x\n", which, rxd);
645            acia_p->rx_shift |= rxd ? 0x80 : 0;
646            acia_p->rx_parity ^= rxd;
585            m_rx_shift |= rxd ? 0x80 : 0;
586            m_rx_parity ^= rxd;
647587
648            if (--acia_p->rx_bits == 0)
588            if (--m_rx_bits == 0)
649589            {
650               if (acia_p->status & ACIA6850_STATUS_RDRF)
590               if (m_status & ACIA6850_STATUS_RDRF)
651591               {
652                  acia_p->overrun = 1;
653                  acia6850_check_interrupts(device);
592                  m_overrun = 1;
593                  check_interrupts();
654594               }
655595
656               acia_p->rx_state = acia_p->parity == NONE ? STOP : PARITY;
596               m_rx_state = m_parity == NONE ? STOP : PARITY;
657597            }
658598            else
659599            {
660               acia_p->rx_shift >>= 1;
600               m_rx_shift >>= 1;
661601            }
662602            break;
663603         }
664604         case PARITY:
665605         {
666606            //logerror("ACIA6850 #%u: RX PARITY BIT %x\n", which, rxd);
667            acia_p->rx_parity ^= rxd;
607            m_rx_parity ^= rxd;
668608
669            if (acia_p->parity == EVEN)
609            if (m_parity == EVEN)
670610            {
671               if (acia_p->rx_parity)
611               if (m_rx_parity)
672612               {
673                  acia_p->status |= ACIA6850_STATUS_PE;
613                  m_status |= ACIA6850_STATUS_PE;
674614               }
675615            }
676616            else
677617            {
678               if (!acia_p->rx_parity)
618               if (!m_rx_parity)
679619               {
680                  acia_p->status |= ACIA6850_STATUS_PE;
620                  m_status |= ACIA6850_STATUS_PE;
681621               }
682622            }
683623
684            acia_p->rx_state = STOP;
624            m_rx_state = STOP;
685625            break;
686626         }
687627         case STOP:
r8910r8911
689629            if (rxd == 1)
690630            {
691631               //logerror("ACIA6850 #%u: RX STOP BIT\n", which);
692               if (acia_p->stopbits == 1)
632               if (m_stopbits == 1)
693633               {
694                  acia_p->status &= ~ACIA6850_STATUS_FE;
634                  m_status &= ~ACIA6850_STATUS_FE;
695635
696                  if (!(acia_p->status & ACIA6850_STATUS_RDRF))
636                  if (!(m_status & ACIA6850_STATUS_RDRF))
697637                  {
698                     //logerror("ACIA6850 #%u: RX DATA %x\n", which, acia_p->rx_shift);
699                     acia_p->rdr = acia_p->rx_shift;
700                     acia_p->status |= ACIA6850_STATUS_RDRF;
701                     acia6850_check_interrupts(device);
638                     //logerror("ACIA6850 #%u: RX DATA %x\n", which, m_rx_shift);
639                     m_rdr = m_rx_shift;
640                     m_status |= ACIA6850_STATUS_RDRF;
641                     check_interrupts();
702642                  }
703643
704                  acia_p->rx_state = START;
644                  m_rx_state = START;
705645               }
706646               else
707647               {
708                  acia_p->rx_state = STOP2;
648                  m_rx_state = STOP2;
709649               }
710650            }
711651            else
712652            {
713               acia_p->status |= ACIA6850_STATUS_FE;
714               acia_p->rx_state = START;
653               m_status |= ACIA6850_STATUS_FE;
654               m_rx_state = START;
715655            }
716656            break;
717657         }
r8910r8911
720660            if (rxd == 1)
721661            {
722662               //logerror("ACIA6850 #%u: RX STOP BIT\n", which);
723               acia_p->status &= ~ACIA6850_STATUS_FE;
663               m_status &= ~ACIA6850_STATUS_FE;
724664
725               if (!(acia_p->status & ACIA6850_STATUS_RDRF))
665               if (!(m_status & ACIA6850_STATUS_RDRF))
726666               {
727                  //logerror("ACIA6850 #%u: RX DATA %x\n", which, acia_p->rx_shift);
728                  acia_p->rdr = acia_p->rx_shift;
729                  acia_p->status |= ACIA6850_STATUS_RDRF;
730                  acia6850_check_interrupts(device);
667                  //logerror("ACIA6850 #%u: RX DATA %x\n", which, m_rx_shift);
668                  m_rdr = m_rx_shift;
669                  m_status |= ACIA6850_STATUS_RDRF;
670                  check_interrupts();
731671               }
732672
733               acia_p->rx_state = START;
673               m_rx_state = START;
734674            }
735675            else
736676            {
737               acia_p->status |= ACIA6850_STATUS_FE;
738               acia_p->rx_state = START;
677               m_status |= ACIA6850_STATUS_FE;
678               m_rx_state = START;
739679            }
740680            break;
741681         }
r8910r8911
745685
746686
747687/*-------------------------------------------------
748    TIMER_CALLBACK( receive_event ) - Called on
749    receive timer event
688    TIMER_CALLBACK( receive_event_callback ) -
689    Called on receive timer event
750690-------------------------------------------------*/
751691
752static TIMER_CALLBACK( receive_event )
692TIMER_CALLBACK( acia6850_device::receive_event_callback ) { reinterpret_cast<acia6850_device *>(ptr)->receive_event(); }
693
694void acia6850_device::receive_event()
753695{
754   running_device *device = (running_device *)ptr;
755   acia6850_t *acia_p = get_token(device);
756   rx_tick(device);
757   acia_p->rx_counter = 0;
696   rx_tick();
697   m_rx_counter = 0;
758698}
759699
760700
761701/*-------------------------------------------------
762    acia6850_rx_clock_in - As above, but using the rx pin
702    rx_clock_in - As above, but using the rx pin
763703-------------------------------------------------*/
764704
765void acia6850_rx_clock_in(running_device *device)
705void acia6850_rx_clock_in(running_device *device) { downcast<acia6850_device*>(device)->rx_clock_in(); }
706
707void acia6850_device::rx_clock_in()
766708{
767   acia6850_t *acia_p = get_token(device);
709   int dcd = devcb_call_read_line(&m_in_dcd_func);
768710
769   int dcd = devcb_call_read_line(&acia_p->in_dcd_func);
770
771711   if (dcd)
772712   {
773      acia_p->status |= ACIA6850_STATUS_DCD;
774      acia6850_check_interrupts(device);
713      m_status |= ACIA6850_STATUS_DCD;
714      check_interrupts();
775715   }
776   else if ((acia_p->status & (ACIA6850_STATUS_DCD|ACIA6850_STATUS_IRQ)) == ACIA6850_STATUS_DCD)
716   else if ((m_status & (ACIA6850_STATUS_DCD|ACIA6850_STATUS_IRQ)) == ACIA6850_STATUS_DCD)
777717   {
778      acia_p->status &= ~ACIA6850_STATUS_DCD;
718      m_status &= ~ACIA6850_STATUS_DCD;
779719   }
780720
781   acia_p->rx_counter ++;
721   m_rx_counter ++;
782722
783   if ( acia_p->rx_counter > acia_p->divide-1)
723   if ( m_rx_counter > m_divide - 1)
784724   {
785      rx_tick(device);
786      acia_p->rx_counter = 0;
725      rx_tick();
726      m_rx_counter = 0;
787727   }
788728}
789729
r8910r8911
795735
796736void acia6850_set_rx_clock(running_device *device, int clock)
797737{
798   acia6850_t *acia_p = get_token(device);
799   acia_p->rx_clock = clock;
738   downcast<acia6850_device*>(device)->set_rx_clock(clock);
800739}
801740
802741
r8910r8911
807746
808747void acia6850_set_tx_clock(running_device *device, int clock)
809748{
810   acia6850_t *acia_p = get_token(device);
811   acia_p->tx_clock = clock;
749   downcast<acia6850_device*>(device)->set_tx_clock(clock);
812750}
813
814
815/*-------------------------------------------------
816    DEVICE_GET_INFO( acia6850 )
817-------------------------------------------------*/
818
819DEVICE_GET_INFO( acia6850 )
820{
821   switch (state)
822   {
823      /* --- the following bits of info are returned as 64-bit signed integers --- */
824      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(acia6850_t);               break;
825      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                           break;
826
827      /* --- the following bits of info are returned as pointers to data or functions --- */
828      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(acia6850);      break;
829      case DEVINFO_FCT_STOP:                     /* Nothing */                           break;
830      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(acia6850);      break;
831
832      /* --- the following bits of info are returned as NULL-terminated strings --- */
833      case DEVINFO_STR_NAME:                     strcpy(info->s, "6850 ACIA");               break;
834      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "6850 ACIA");               break;
835      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                     break;
836      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);                  break;
837      case DEVINFO_STR_CREDITS:                  /* Nothing */                           break;
838   }
839}
840
841DEFINE_LEGACY_DEVICE(ACIA6850, acia6850);
src/emu/machine/6850acia.h
r8910r8911
66
77*********************************************************************/
88
9#pragma once
10
911#ifndef __ACIA6850_H__
1012#define __ACIA6850_H__
1113
12#include "devlegcy.h"
14#include "emu.h"
1315
1416
17
1518/***************************************************************************
16    MACROS
19    EXTERNAL MACROS
1720***************************************************************************/
1821
19DECLARE_LEGACY_DEVICE(ACIA6850, acia6850);
20
2122#define ACIA6850_STATUS_RDRF   0x01
2223#define ACIA6850_STATUS_TDRE   0x02
2324#define ACIA6850_STATUS_DCD      0x04
r8910r8911
2728#define ACIA6850_STATUS_PE      0x40
2829#define ACIA6850_STATUS_IRQ      0x80
2930
31
32
33/***************************************************************************
34    DEVICE CONFIGURATION MACROS
35***************************************************************************/
36
3037#define MDRV_ACIA6850_ADD(_tag, _config) \
3138   MDRV_DEVICE_ADD(_tag, ACIA6850, 0) \
3239   MDRV_DEVICE_CONFIG(_config)
r8910r8911
3946    TYPE DEFINITIONS
4047***************************************************************************/
4148
42typedef struct _acia6850_interface acia6850_interface;
43struct _acia6850_interface
49
50// ======================> acia6850_interface
51
52struct acia6850_interface
4453{
45   int   tx_clock;
46   int   rx_clock;
54   int   m_tx_clock;
55   int   m_rx_clock;
4756
48   devcb_read_line      in_rx_func;
49   devcb_write_line   out_tx_func;
57   devcb_read_line      m_in_rx_func;
58   devcb_write_line   m_out_tx_func;
5059
51   devcb_read_line      in_cts_func;
52   devcb_write_line   out_rts_func;
53   devcb_read_line      in_dcd_func;
60   devcb_read_line      m_in_cts_func;
61   devcb_write_line   m_out_rts_func;
62   devcb_read_line      m_in_dcd_func;
5463
55   devcb_write_line   out_irq_func;
64   devcb_write_line   m_out_irq_func;
5665};
5766
5867
68
69// ======================> acia6850_device_config
70
71class acia6850_device_config : public device_config,
72                               public acia6850_interface
73{
74    friend class acia6850_device;
75
76    // construction/destruction
77    acia6850_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
78
79public:
80    // allocators
81    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
82    virtual device_t *alloc_device(running_machine &machine) const;
83
84protected:
85    // device_config overrides
86    virtual void device_config_complete();
87};
88
89
90
91// ======================> acia6850_device
92
93class acia6850_device :  public device_t
94{
95    friend class acia6850_device_config;
96
97    // construction/destruction
98    acia6850_device(running_machine &_machine, const acia6850_device_config &_config);
99
100public:
101
102   void acia6850_tx_clock_in();
103   void acia6850_rx_clock_in();
104
105   void acia6850_set_rx_clock(int clock);
106   void acia6850_set_tx_clock(int clock);
107
108   void acia6850_ctrl_w(UINT32 offset, UINT8 data);
109   UINT8 acia6850_stat_r(UINT32 offset);
110   void acia6850_data_w(UINT32 offset, UINT8 data);
111   UINT8 acia6850_data_r(UINT32 offset);
112
113   void tx_clock_in();
114   void rx_clock_in();
115
116   void set_rx_clock(int clock) { m_rx_clock = clock; }
117   void set_tx_clock(int clock) { m_tx_clock = clock; }
118
119protected:
120    // device-level overrides
121    virtual void device_start();
122    virtual void device_reset();
123    virtual void device_post_load() { }
124    virtual void device_clock_changed() { }
125
126   static TIMER_CALLBACK( transmit_event_callback );
127   static TIMER_CALLBACK( receive_event_callback );
128
129private:
130
131   void check_interrupts();
132
133   void tx_tick();
134   void transmit_event();
135
136   void rx_tick();
137   void receive_event();
138
139   enum serial_state
140   {
141      START,
142      DATA,
143      PARITY,
144      STOP,
145      STOP2,
146   };
147
148   enum parity_type
149   {
150      NONE,
151      ODD,
152      EVEN
153   };
154
155   devcb_resolved_read_line   m_in_rx_func;
156   devcb_resolved_write_line   m_out_tx_func;
157   devcb_resolved_read_line   m_in_cts_func;
158   devcb_resolved_write_line   m_out_rts_func;
159   devcb_resolved_read_line   m_in_dcd_func;
160   devcb_resolved_write_line   m_out_irq_func;
161
162   UINT8      m_ctrl;
163   UINT8      m_status;
164
165   UINT8      m_tdr;
166   UINT8      m_rdr;
167   UINT8      m_rx_shift;
168   UINT8      m_tx_shift;
169
170   UINT8      m_rx_counter;
171   UINT8      m_tx_counter;
172
173   int         m_rx_clock;
174   int         m_tx_clock;
175
176   int         m_divide;
177
178   /* Counters */
179   int         m_tx_bits;
180   int         m_rx_bits;
181   int         m_tx_parity;
182   int         m_rx_parity;
183
184   /* TX/RX state */
185   int         m_bits;
186   parity_type   m_parity;
187   int         m_stopbits;
188   int         m_tx_int;
189
190   /* Signals */
191   int         m_overrun;
192   int         m_reset;
193   int         m_rts;
194   int         m_brk;
195   int         m_first_reset;
196   int         m_status_read;
197   serial_state m_rx_state;
198   serial_state m_tx_state;
199   int         m_irq;
200
201   emu_timer   *m_rx_timer;
202   emu_timer   *m_tx_timer;
203
204    const acia6850_device_config &m_config;
205
206   static const int ACIA6850_DIVIDE[3];
207   static const int ACIA6850_WORD[8][3];
208};
209
210
211// device type definition
212extern const device_type ACIA6850;
213
214
215
59216/***************************************************************************
60    FUNCTION PROTOTYPES
217    PROTOTYPES
61218***************************************************************************/
62219
63220void acia6850_tx_clock_in(running_device *device) ATTR_NONNULL(1);
src/emu/machine/ldcore.h
r8910r8911
148148   size_t               statesize;            /* size of the state */
149149   const char *         name;               /* name of the player */
150150   const rom_entry *      romregion;            /* pointer to ROM region information */
151   const machine_config_token *machine_config;      /* pointer to machine configuration */
151   machine_config_constructor machine_config;      /* pointer to machine configuration */
152152   laserdisc_init_func      init;               /* initialization callback */
153153   laserdisc_vsync_func   vsync;               /* vsync begin callback */
154154   laserdisc_update_func   update;               /* update callback (line 16) */
src/emu/machine/8237dma.c
r8910r8911
2121#include "emu.h"
2222#include "memconv.h"
2323#include "8237dma.h"
24#include "devhelpr.h"
2425
26/***************************************************************************
27    MACROS
28***************************************************************************/
2529
26/* States that the i8237 device can be in */
27typedef enum {
28   DMA8237_SI,         /* Idle state */
29   DMA8237_S0,         /* HRQ has been triggered, waiting to receive HLDA */
30//  DMA8237_SW,         /* Wait state */
31
32   /* Normal transfer states */
33   DMA8237_S1,         /* Output A8-A15; only used when A8-A15 really needs to be output */
34   DMA8237_S2,         /* Output A0-A7 */
35   DMA8237_S3,         /* Initiate read; skipped in compressed timing. On the S2->S3 transition DACK is set. */
36   DMA8237_S4,         /* Perform read/write */
37
38   /* Memory to memory transfer states */
39   DMA8237_S11,      /* Output A8-A15 */
40//  DMA8237_S12,        /* Output A0-A7 */
41//  DMA8237_S13,        /* Initiate read */
42//  DMA8237_S14,        /* Perform read/write */
43//  DMA8237_S21,        /* Output A8-A15 */
44//  DMA8237_S22,        /* Output A0-A7 */
45//  DMA8237_S23,        /* Initiate read */
46//  DMA8237_S24,        /* Perform read/write */
47} dma8237_state;
48
49
50typedef struct _i8237_t i8237_t;
51struct _i8237_t
52{
53   devcb_resolved_write_line   out_hrq_func;
54   devcb_resolved_write_line   out_eop_func;
55   devcb_resolved_read8      in_memr_func;
56   devcb_resolved_write8      out_memw_func;
57
58   emu_timer *timer;
59
60   struct
61   {
62      devcb_resolved_read8      in_ior_func;
63      devcb_resolved_write8      out_iow_func;
64      devcb_resolved_write_line   out_dack_func;
65      UINT16 base_address;
66      UINT16 base_count;
67      UINT16 address;
68      UINT16 count;
69      UINT8 mode;
70      int high_address_changed;
71   } chan[4];
72
73   UINT32 msb : 1;
74   UINT32 eop : 1;
75   UINT8 temp;
76   UINT8 temporary_data;
77   UINT8 command;
78   UINT8 drq;
79   UINT8 mask;
80   UINT8 hrq;
81   UINT8 hlda;
82
83   /* bits  0- 3 :  Terminal count for channels 0-3
84     * bits  4- 7 :  Transfer in progress for channels 0-3 */
85   UINT8 status;
86
87   dma8237_state state;      /* State the device is currently in */
88   int service_channel;      /* Channel we will be servicing */
89   int last_service_channel;   /* Previous channel we serviced; used to determine channel priority. */
90};
91
92
9330#define DMA_MODE_CHANNEL(mode)      ((mode) & 0x03)
9431#define DMA_MODE_OPERATION(mode)   ((mode) & 0x0c)
9532#define DMA_MODE_AUTO_INIT(mode)   ((mode) & 0x10)
r8910r8911
10744#define DMA8237_CASCADE_MODE   0xc0
10845
10946
110/* ----------------------------------------------------------------------- */
47//**************************************************************************
48//  DEVICE CONFIGURATION
49//**************************************************************************
11150
112INLINE i8237_t *get_safe_token(running_device *device) {
113   assert( device != NULL );
114   assert( device->type() == I8237 );
115   return ( i8237_t *) downcast<legacy_device_base *>(device)->token();
51GENERIC_DEVICE_CONFIG_SETUP(i8237, "I8237")
52
53//-------------------------------------------------
54//  device_config_complete - perform any
55//  operations now that the configuration is
56//  complete
57//-------------------------------------------------
58
59void i8237_device_config::device_config_complete()
60{
61   // inherit a copy of the static data
62   const i8237_interface *intf = reinterpret_cast<const i8237_interface *>(static_config());
63   if (intf != NULL)
64   {
65      *static_cast<i8237_interface *>(this) = *intf;
66   }
67
68   // or initialize to defaults if none provided
69   else
70   {
71       memset(&m_out_hrq_func, 0, sizeof(m_out_hrq_func));
72       memset(&m_out_eop_func, 0, sizeof(m_out_eop_func));
73       memset(&m_in_memr_func, 0, sizeof(m_in_memr_func));
74       memset(&m_out_memw_func, 0, sizeof(m_out_memw_func));
75       memset(&m_in_ior_func[0], 0, sizeof(m_in_ior_func[0]));
76       memset(&m_in_ior_func[1], 0, sizeof(m_in_ior_func[1]));
77       memset(&m_in_ior_func[2], 0, sizeof(m_in_ior_func[2]));
78       memset(&m_in_ior_func[3], 0, sizeof(m_in_ior_func[3]));
79       memset(&m_out_iow_func[0], 0, sizeof(m_out_iow_func[0]));
80       memset(&m_out_iow_func[1], 0, sizeof(m_out_iow_func[1]));
81       memset(&m_out_iow_func[2], 0, sizeof(m_out_iow_func[2]));
82       memset(&m_out_iow_func[3], 0, sizeof(m_out_iow_func[3]));
83       memset(&m_out_dack_func[0], 0, sizeof(m_out_dack_func[0]));
84       memset(&m_out_dack_func[1], 0, sizeof(m_out_dack_func[1]));
85       memset(&m_out_dack_func[2], 0, sizeof(m_out_dack_func[2]));
86       memset(&m_out_dack_func[3], 0, sizeof(m_out_dack_func[3]));
87   }
11688}
11789
11890
119/* ----------------------------------------------------------------------- */
12091
92//**************************************************************************
93//  LIVE DEVICE
94//**************************************************************************
12195
122INLINE void dma8237_do_read( running_device *device )
96const device_type I8237 = i8237_device_config::static_alloc_device_config;
97
98//-------------------------------------------------
99//  i8237_device - constructor
100//-------------------------------------------------
101
102i8237_device::i8237_device(running_machine &_machine, const i8237_device_config &config)
103    : device_t(_machine, config),
104      m_config(config)
123105{
124   i8237_t   *i8237 = get_safe_token( device );
125   int         channel = i8237->service_channel;
126106
127   switch( DMA_MODE_OPERATION( i8237->chan[ channel ].mode ) )
107}
108
109//-------------------------------------------------
110//  device_start - device-specific startup
111//-------------------------------------------------
112
113void i8237_device::device_start()
114{
115   /* resolve callbacks */
116   devcb_resolve_write_line(&m_out_hrq_func, &m_config.m_out_hrq_func, this);
117   devcb_resolve_write_line(&m_out_eop_func, &m_config.m_out_eop_func, this);
118   devcb_resolve_read8(&m_in_memr_func, &m_config.m_in_memr_func, this);
119   devcb_resolve_write8(&m_out_memw_func, &m_config.m_out_memw_func, this);
120
121   for (int i = 0; i < 4; i++)
128122   {
123      devcb_resolve_read8(&m_chan[i].m_in_ior_func, &m_config.m_in_ior_func[i], this);
124      devcb_resolve_write8(&m_chan[i].m_out_iow_func, &m_config.m_out_iow_func[i], this);
125      devcb_resolve_write_line(&m_chan[i].m_out_dack_func, &m_config.m_out_dack_func[i], this);
126   }
127
128   m_timer = timer_alloc(&m_machine, i8237_timerproc_callback, (void *)this);
129}
130
131
132//-------------------------------------------------
133//  device_reset - device-specific reset
134//-------------------------------------------------
135
136void i8237_device::device_reset()
137{
138   m_status = 0x0F;
139   m_eop = 1;
140   m_state = DMA8237_SI;
141   m_last_service_channel = 3;
142
143   m_mask = 0x00;
144   m_status = 0x0F;
145   m_hrq = 0;
146   m_hlda = 0;
147   m_chan[0].m_mode = 0;
148   m_chan[1].m_mode = 0;
149   m_chan[2].m_mode = 0;
150   m_chan[3].m_mode = 0;
151
152   timer_adjust_periodic(m_timer, ATTOTIME_IN_HZ(clock()), 0, ATTOTIME_IN_HZ(clock()));
153}
154
155
156void i8237_device::i8237_do_read()
157{
158   int channel = m_service_channel;
159
160   switch( DMA_MODE_OPERATION( m_chan[ channel ].m_mode ) )
161   {
129162   case DMA8237_WRITE_TRANSFER:
130      i8237->temporary_data = devcb_call_read8(&i8237->chan[channel].in_ior_func, 0);
163      m_temporary_data = devcb_call_read8(&m_chan[channel].m_in_ior_func, 0);
131164      break;
132165   case DMA8237_READ_TRANSFER:
133      i8237->temporary_data = devcb_call_read8(&i8237->in_memr_func, i8237->chan[ channel ].address);
166      m_temporary_data = devcb_call_read8(&m_in_memr_func, m_chan[ channel ].m_address);
134167      break;
135168   case DMA8237_VERIFY_TRANSFER:
136169   case DMA8237_ILLEGAL_TRANSFER:
r8910r8911
139172}
140173
141174
142INLINE void dma8237_do_write( running_device *device )
175void i8237_device::i8237_do_write()
143176{
144   i8237_t   *i8237 = get_safe_token( device );
145   int         channel = i8237->service_channel;
177   int channel = m_service_channel;
146178
147   switch( DMA_MODE_OPERATION( i8237->chan[ channel ].mode ) )
179   switch( DMA_MODE_OPERATION( m_chan[ channel ].m_mode ) )
148180   {
149181   case DMA8237_WRITE_TRANSFER:
150      devcb_call_write8(&i8237->out_memw_func, i8237->chan[ channel ].address, i8237->temporary_data);
182      devcb_call_write8(&m_out_memw_func, m_chan[ channel ].m_address, m_temporary_data);
151183      break;
152184   case DMA8237_READ_TRANSFER:
153      devcb_call_write8(&i8237->chan[channel].out_iow_func, 0, i8237->temporary_data);
185      devcb_call_write8(&m_chan[channel].m_out_iow_func, 0, m_temporary_data);
154186      break;
155187   case DMA8237_VERIFY_TRANSFER:
156188   case DMA8237_ILLEGAL_TRANSFER:
r8910r8911
159191}
160192
161193
162INLINE void dma8237_advance( running_device *device )
194void i8237_device::i8237_advance()
163195{
164   i8237_t   *i8237 = get_safe_token( device );
165   int         channel = i8237->service_channel;
166   int         mode = i8237->chan[channel].mode;
196   int channel = m_service_channel;
197   int mode = m_chan[channel].m_mode;
167198
168199   switch ( DMA_MODE_OPERATION( mode ) )
169200   {
170201   case DMA8237_VERIFY_TRANSFER:
171202   case DMA8237_WRITE_TRANSFER:
172203   case DMA8237_READ_TRANSFER:
173      i8237->chan[channel].high_address_changed = 0;
204      m_chan[channel].m_high_address_changed = 0;
174205
175206      if ( DMA_MODE_DIRECTION( mode ) )
176207      {
177         i8237->chan[channel].address -= 1;
178         if ( ( i8237->chan[channel].address & 0xFF ) == 0xFF )
179            i8237->chan[channel].high_address_changed  = 1;
208         m_chan[channel].m_address -= 1;
209         if ( ( m_chan[channel].m_address & 0xFF ) == 0xFF )
210         {
211            m_chan[channel].m_high_address_changed  = 1;
212         }
180213      }
181214      else
182215      {
183         i8237->chan[channel].address += 1;
184         if ( ( i8237->chan[channel].address & 0xFF ) == 0x00 )
185            i8237->chan[channel].high_address_changed = 1;
216         m_chan[channel].m_address += 1;
217         if ( ( m_chan[channel].m_address & 0xFF ) == 0x00 )
218         {
219            m_chan[channel].m_high_address_changed = 1;
220         }
186221      }
187222
188      i8237->chan[channel].count--;
223      m_chan[channel].m_count--;
189224
190      if ( i8237->chan[channel].count == 0xFFFF )
225      if ( m_chan[channel].m_count == 0xFFFF )
191226      {
192227         /* Set TC bit for this channel */
193         i8237->status |= ( 0x01 << channel );
228         m_status |= ( 0x01 << channel );
194229
195230         if ( DMA_MODE_AUTO_INIT( mode ) )
196231         {
197            i8237->chan[channel].address = i8237->chan[channel].base_address;
198            i8237->chan[channel].count = i8237->chan[channel].base_count;
199            i8237->chan[channel].high_address_changed = 1;
232            m_chan[channel].m_address = m_chan[channel].m_base_address;
233            m_chan[channel].m_count = m_chan[channel].m_base_count;
234            m_chan[channel].m_high_address_changed = 1;
200235         }
201236         else
202237         {
203            i8237->mask |= ( 0x01 << channel );
238            m_mask |= ( 0x01 << channel );
204239         }
205240      }
206241      break;
207242   case DMA8237_ILLEGAL_TRANSFER:
208243      break;
209244   }
210
211245}
212246
213static void set_dack(i8237_t *i8237, int channel)
214{
215   int i;
216247
217   for (i = 0; i < 4; i++)
248void i8237_device::set_dack(int channel)
249{
250   for (int i = 0; i < 4; i++)
218251   {
219      int state = (i == channel) ^ !BIT(i8237->command, 7);
252      int state = (i == channel) ^ !BIT(m_command, 7);
220253
221      devcb_call_write_line(&i8237->chan[i].out_dack_func, state);
254      devcb_call_write_line(&m_chan[i].m_out_dack_func, state);
222255   }
223256}
224257
225static TIMER_CALLBACK( dma8237_timerproc )
258
259TIMER_CALLBACK( i8237_device::i8237_timerproc_callback )
226260{
227   running_device *device = (running_device *)ptr;
228   i8237_t   *i8237 = get_safe_token(device);
261   reinterpret_cast<i8237_device*>(ptr)->i8237_timerproc();
262}
229263
264
265void i8237_device::i8237_timerproc()
266{
230267   /* Check if operation is disabled */
231   if ( i8237->command & 0x04 )
268   if ( m_command & 0x04 )
269   {
232270      return;
271   }
233272
234   switch ( i8237->state ) {
273   switch ( m_state )
274   {
235275
236276   case DMA8237_SI:
277   {
237278      /* Make sure EOP is high */
238      if ( ! i8237->eop )
279      if ( !m_eop )
239280      {
240         i8237->eop = 1;
241         devcb_call_write_line(&i8237->out_eop_func, i8237->eop ? ASSERT_LINE : CLEAR_LINE);
281         m_eop = 1;
282         devcb_call_write_line(&m_out_eop_func, m_eop ? ASSERT_LINE : CLEAR_LINE);
242283      }
243284
244285      /* Check if a new DMA request has been received. */
286      /* Bit 6 of the command register determines whether the DREQ signals are active
287        high or active low. */
288      UINT16 pending_request = ( ( m_command & 0x40 ) ? ~m_drq : m_drq ) & ~m_mask;
289
290      if ( pending_request & 0x0f )
245291      {
246         /* Bit 6 of the command register determines whether the DREQ signals are active
247              high or active low. */
248         UINT16 pending_request = ( ( i8237->command & 0x40 ) ? ~i8237->drq : i8237->drq ) & ~i8237->mask;
292         int prio_channel = 0;
249293
250         if ( pending_request & 0x0f )
294         /* Determine the channel that should be serviced */
295         int channel = ( m_command & 0x10 ) ? m_last_service_channel : 3;
296         for ( int i = 0; i < 4; i++ )
251297         {
252            int i, channel, prio_channel = 0;
253
254            /* Determine the channel that should be serviced */
255            channel = ( i8237->command & 0x10 ) ? i8237->last_service_channel : 3;
256            for ( i = 0; i < 4; i++ )
298            if ( pending_request & ( 1 << channel ) )
257299            {
258               if ( pending_request & ( 1 << channel ) )
259                  prio_channel = channel;
260               channel = ( channel - 1 ) & 0x03;
300               prio_channel = channel;
261301            }
302            channel = ( channel - 1 ) & 0x03;
303         }
262304
263            /* Store the channel we will be servicing and go to the next state */
264            i8237->service_channel = prio_channel;
265            i8237->last_service_channel = prio_channel;
266            i8237->hrq = 1;
267            devcb_call_write_line(&i8237->out_hrq_func, i8237->hrq);
268            i8237->state = DMA8237_S0;
305         /* Store the channel we will be servicing and go to the next state */
306         m_service_channel = prio_channel;
307         m_last_service_channel = prio_channel;
308         m_hrq = 1;
309         devcb_call_write_line(&m_out_hrq_func, m_hrq);
310         m_state = DMA8237_S0;
269311
270            timer_enable( i8237->timer, 1 );
271         }
272         else
273         {
274            timer_enable( i8237->timer, 0 );
275         }
312         timer_enable( m_timer, 1 );
276313      }
314      else
315      {
316         timer_enable( m_timer, 0 );
317      }
277318      break;
319   }
278320
279321   case DMA8237_S0:
280322      /* S0 is the first of the DMA service. We have requested a hold but are waiting
281323          for confirmation. */
282      if ( i8237->hlda )
324      if ( m_hlda )
283325      {
284         if ( i8237->command & 0x01 )
326         if ( m_command & 0x01 )
285327         {
286328            /* Memory-to-memory transfers */
287            i8237->state = DMA8237_S11;
329            m_state = DMA8237_S11;
288330         }
289331         else
290332         {
291333            /* Regular transfers */
292            i8237->state = DMA8237_S1;
334            m_state = DMA8237_S1;
293335         }
294336      }
295337      break;
296338
297339   case DMA8237_S1:   /* Output A8-A15 */
298      i8237->state = DMA8237_S2;
340      m_state = DMA8237_S2;
299341      break;
300342
301343   case DMA8237_S2:   /* Output A7-A0 */
302344      /* set DACK */
303      set_dack(i8237, i8237->service_channel);
345      set_dack(m_service_channel);
304346
305347      /* Check for compressed timing */
306      if ( i8237->command & 0x08 )
307         i8237->state = DMA8237_S4;
348      if ( m_command & 0x08 )
349      {
350         m_state = DMA8237_S4;
351      }
308352      else
309         i8237->state = DMA8237_S3;
353      {
354         m_state = DMA8237_S3;
355      }
310356      break;
311357
312358   case DMA8237_S3:   /* Initiate read */
313      dma8237_do_read( device );
314      i8237->state = DMA8237_S4;
359      i8237_do_read();
360      m_state = DMA8237_S4;
315361      break;
316362
317363   case DMA8237_S4:   /* Perform read/write */
318364      /* Perform read when in compressed timing mode */
319      if ( i8237->command & 0x08 )
320         dma8237_do_read( device );
365      if ( m_command & 0x08 )
366      {
367         i8237_do_read();
368      }
321369
322370      /* Perform write */
323      dma8237_do_write( device );
371      i8237_do_write();
324372
373
325374      /* Advance */
326      dma8237_advance( device );
375      i8237_advance();
327376
328377      {
329         int channel = i8237->service_channel;
378         int channel = m_service_channel;
330379
331         switch( DMA_MODE_TRANSFERMODE( i8237->chan[channel].mode ) )
380         switch( DMA_MODE_TRANSFERMODE( m_chan[channel].m_mode ) )
332381         {
333382         case DMA8237_DEMAND_MODE:
334383            /* Check for terminal count or EOP signal or DREQ begin de-asserted */
335            if ( ( i8237->status & ( 0x01 << channel ) ) || ! i8237->eop || ! ( i8237->drq & ( 0x01 << channel ) ) )
384            if ( ( m_status & ( 0x01 << channel ) ) || !m_eop || !( m_drq & ( 0x01 << channel ) ) )
336385            {
337               i8237->hrq = 0;
338               i8237->hlda = 0;
339               devcb_call_write_line(&i8237->out_hrq_func, i8237->hrq);
340               i8237->state = DMA8237_SI;
386               m_hrq = 0;
387               m_hlda = 0;
388               devcb_call_write_line(&m_out_hrq_func, m_hrq);
389               m_state = DMA8237_SI;
341390            }
342391            else
343392            {
344               i8237->state = i8237->chan[channel].high_address_changed ? DMA8237_S1 : DMA8237_S2;
393               m_state = m_chan[channel].m_high_address_changed ? DMA8237_S1 : DMA8237_S2;
345394            }
346395            break;
347396
348397         case DMA8237_SINGLE_MODE:
349            i8237->hrq = 0;
350            i8237->hlda = 0;
351            devcb_call_write_line(&i8237->out_hrq_func, i8237->hrq);
352            i8237->state = DMA8237_SI;
398            m_hrq = 0;
399            m_hlda = 0;
400            devcb_call_write_line(&m_out_hrq_func, m_hrq);
401            m_state = DMA8237_SI;
353402            break;
354403
355404         case DMA8237_BLOCK_MODE:
356405            /* Check for terminal count or EOP signal */
357            if ( ( i8237->status & ( 0x01 << channel ) ) || ! i8237->eop )
406            if ( ( m_status & ( 0x01 << channel ) ) || !m_eop )
358407            {
359               i8237->hrq = 0;
360               i8237->hlda = 0;
361               devcb_call_write_line(&i8237->out_hrq_func, i8237->hrq);
362               i8237->state = DMA8237_SI;
408               m_hrq = 0;
409               m_hlda = 0;
410               devcb_call_write_line(&m_out_hrq_func, m_hrq);
411               m_state = DMA8237_SI;
363412            }
364413            else
365414            {
366               i8237->state = i8237->chan[channel].high_address_changed ? DMA8237_S1 : DMA8237_S2;
415               m_state = m_chan[channel].m_high_address_changed ? DMA8237_S1 : DMA8237_S2;
367416            }
368417            break;
369418
370419         case DMA8237_CASCADE_MODE:
371            if ( ! ( i8237->drq & ( 0x01 << channel ) ) )
420            if ( ! ( m_drq & ( 0x01 << channel ) ) )
372421            {
373               i8237->hrq = 0;
374               i8237->hlda = 0;
375               devcb_call_write_line(&i8237->out_hrq_func, i8237->hrq);
376               i8237->state = DMA8237_SI;
422               m_hrq = 0;
423               m_hlda = 0;
424               devcb_call_write_line(&m_out_hrq_func, m_hrq);
425               m_state = DMA8237_SI;
377426            }
378427            break;
379428         }
380429
381430         /* Check if EOP output needs to be asserted */
382         if ( i8237->status & ( 0x01 << channel ) )
431         if ( m_status & ( 0x01 << channel ) )
383432         {
384            i8237->eop = 0;
385            devcb_call_write_line(&i8237->out_eop_func, i8237->eop ? ASSERT_LINE : CLEAR_LINE);
433            m_eop = 0;
434            devcb_call_write_line(&m_out_eop_func, m_eop ? ASSERT_LINE : CLEAR_LINE);
386435         }
387436      }
388437
389438      /* clear DACK */
390      set_dack(i8237, -1);
439      set_dack(-1);
391440      break;
392441
393442   case DMA8237_S11:   /* Output A8-A15 */
r8910r8911
396445}
397446
398447
399
400
401/* ----------------------------------------------------------------------- */
402
403
404READ8_DEVICE_HANDLER( i8237_r )
448READ8_DEVICE_HANDLER_TRAMPOLINE(i8237, i8237_r)
405449{
406   i8237_t   *i8237 = get_safe_token(device);
407450   UINT8 data = 0xFF;
408451
409452   offset &= 0x0F;
r8910r8911
414457   case 4:
415458   case 6:
416459      /* DMA address register */
417      data = i8237->chan[offset / 2].address >> (i8237->msb ? 8 : 0);
418      i8237->msb ^= 1;
460      data = m_chan[offset / 2].m_address >> (m_msb ? 8 : 0);
461      m_msb ^= 1;
419462      break;
420463
421464   case 1:
r8910r8911
423466   case 5:
424467   case 7:
425468      /* DMA count register */
426      data = i8237->chan[offset / 2].count >> (i8237->msb ? 8 : 0);
427      i8237->msb ^= 1;
469      data = m_chan[offset / 2].m_count >> (m_msb ? 8 : 0);
470      m_msb ^= 1;
428471      break;
429472
430473   case 8:
431474      /* DMA status register */
432      data = (UINT8) i8237->status;
475      data = (UINT8) m_status;
433476
434477      /* TC bits are cleared on a status read */
435      i8237->status &= 0xF0;
478      m_status &= 0xF0;
436479      break;
437480
438481   case 10:
439482      /* DMA mask register */
440      data = i8237->mask;
483      data = m_mask;
441484      break;
442485
443486   case 13:
444487      /* DMA master clear */
445      data = i8237->temp;
488      data = m_temp;
446489      break;
447490
448491   case 9:      /* DMA write request register */
r8910r8911
458501}
459502
460503
461
462WRITE8_DEVICE_HANDLER( i8237_w )
504WRITE8_DEVICE_HANDLER_TRAMPOLINE(i8237, i8237_w)
463505{
464   i8237_t   *i8237 = get_safe_token(device);
465   int channel;
466
467506   offset &= 0x0F;
468507
469508   logerror("i8237_w: offset = %02x, data = %02x\n", offset, data );
r8910r8911
473512   case 2:
474513   case 4:
475514   case 6:
515   {
476516      /* DMA address register */
477      channel = offset / 2;
478      if (i8237->msb)
517      int channel = offset / 2;
518      if (m_msb)
479519      {
480         i8237->chan[channel].base_address = ( i8237->chan[channel].base_address & 0x00FF ) | ( data << 8 );
481         i8237->chan[channel].address = ( i8237->chan[channel].address & 0x00FF ) | ( data << 8 );
520         m_chan[channel].m_base_address = ( m_chan[channel].m_base_address & 0x00FF ) | ( data << 8 );
521         m_chan[channel].m_address = ( m_chan[channel].m_address & 0x00FF ) | ( data << 8 );
482522      }
483523      else
484524      {
485         i8237->chan[channel].base_address = ( i8237->chan[channel].base_address & 0xFF00 ) | data;
486         i8237->chan[channel].address = ( i8237->chan[channel].address & 0xFF00 ) | data;
525         m_chan[channel].m_base_address = ( m_chan[channel].m_base_address & 0xFF00 ) | data;
526         m_chan[channel].m_address = ( m_chan[channel].m_address & 0xFF00 ) | data;
487527      }
488      i8237->msb ^= 1;
528      m_msb ^= 1;
489529      break;
530   }
490531
491532   case 1:
492533   case 3:
493534   case 5:
494535   case 7:
536   {
495537      /* DMA count register */
496      channel = offset / 2;
497      if (i8237->msb)
538      int channel = offset / 2;
539      if (m_msb)
498540      {
499         i8237->chan[channel].base_count = ( i8237->chan[channel].base_count & 0x00FF ) | ( data << 8 );
500         i8237->chan[channel].count = ( i8237->chan[channel].count & 0x00FF ) | ( data << 8 );
541         m_chan[channel].m_base_count = ( m_chan[channel].m_base_count & 0x00FF ) | ( data << 8 );
542         m_chan[channel].m_count = ( m_chan[channel].m_count & 0x00FF ) | ( data << 8 );
501543      }
502544      else
503545      {
504         i8237->chan[channel].base_count = ( i8237->chan[channel].base_count & 0xFF00 ) | data;
505         i8237->chan[channel].count = ( i8237->chan[channel].count & 0xFF00 ) | data;
546         m_chan[channel].m_base_count = ( m_chan[channel].m_base_count & 0xFF00 ) | data;
547         m_chan[channel].m_count = ( m_chan[channel].m_count & 0xFF00 ) | data;
506548      }
507      i8237->msb ^= 1;
549      m_msb ^= 1;
508550      break;
551   }
509552
510553   case 8:
511554      /* DMA command register */
512      i8237->command = data;
513      timer_enable( i8237->timer, ( i8237->command & 0x04 ) ? 0 : 1 );
555      m_command = data;
556      timer_enable( m_timer, ( m_command & 0x04 ) ? 0 : 1 );
514557      break;
515558
516559   case 9:
560   {
517561      /* DMA request register */
518      channel = DMA_MODE_CHANNEL(data);
562      int channel = DMA_MODE_CHANNEL(data);
519563      if ( data & 0x04 )
520564      {
521         i8237->drq |= 0x01 << channel;
522         timer_enable( i8237->timer, ( i8237->command & 0x04 ) ? 0 : 1 );
565         m_drq |= 0x01 << channel;
566         timer_enable( m_timer, ( m_command & 0x04 ) ? 0 : 1 );
523567      }
524568      else
525569      {
526         i8237->status &= ~ ( 0x10 << channel );
527         i8237->drq &= ~ ( 0x01 << channel );
570         m_status &= ~ ( 0x10 << channel );
571         m_drq &= ~ ( 0x01 << channel );
528572      }
529573      break;
574   }
530575
531576   case 10:
577   {
532578      /* DMA mask register */
533      channel = DMA_MODE_CHANNEL(data);
579      int channel = DMA_MODE_CHANNEL(data);
534580      if (data & 0x04)
535         i8237->mask |= 0x11 << channel;
581      {
582         m_mask |= 0x11 << channel;
583      }
536584      else
537         i8237->mask &= ~(0x11 << channel);
585      {
586         m_mask &= ~(0x11 << channel);
587      }
538588      break;
589   }
539590
540591   case 11:
592   {
541593      /* DMA mode register */
542      channel = DMA_MODE_CHANNEL(data);
543      i8237->chan[channel].mode = data;
594      int channel = DMA_MODE_CHANNEL(data);
595      m_chan[channel].m_mode = data;
544596      /* Apparently mode writes also clear the TC bit(?) */
545      i8237->status &= ~ ( 1 << channel );
597      m_status &= ~ ( 1 << channel );
546598      break;
599   }
547600
548601   case 12:
549602      /* DMA clear byte pointer flip-flop */
550      i8237->temp = data;
551      i8237->msb = 0;
603      m_temp = data;
604      m_msb = 0;
552605      break;
553606
554607   case 13:
555608      /* DMA master clear */
556      i8237->msb = 0;
557      i8237->mask = 0x0f;
558      i8237->state = DMA8237_SI;
559      i8237->status &= 0xF0;
609      m_msb = 0;
610      m_mask = 0x0f;
611      m_state = DMA8237_SI;
612      m_status &= 0xF0;
560613      break;
561614
562615   case 14:
563616      /* DMA clear mask register */
564      i8237->mask &= ~data;
565      i8237->mask = 0;
617      m_mask &= ~data;
618      m_mask = 0;
566619      break;
567620
568621   case 15:
569622      /* DMA write mask register */
570      i8237->mask = data & 0x0f;
623      m_mask = data & 0x0f;
571624      break;
572625   }
573626}
574627
575628
576
577static void dma8237_drq_write(running_device *device, int channel, int state)
629void i8237_device::i8237_drq_write(int channel, int state)
578630{
579   i8237_t   *i8237 = get_safe_token( device );
580
581631   if (state)
582      i8237->drq |= ( 0x01 << channel );
632   {
633      m_drq |= ( 0x01 << channel );
634   }
583635   else
584      i8237->drq &= ~( 0x01 << channel );
585
586   timer_enable( i8237->timer, ( i8237->command & 0x04 ) ? 0 : 1 );
587}
588
589WRITE_LINE_DEVICE_HANDLER( i8237_hlda_w )
590{
591   i8237_t   *i8237 = get_safe_token( device );
592
593   i8237->hlda = state;
594}
595
596WRITE_LINE_DEVICE_HANDLER( i8237_ready_w )
597{
598}
599
600WRITE_LINE_DEVICE_HANDLER( i8237_dreq0_w ) { dma8237_drq_write(device, 0, state); }
601WRITE_LINE_DEVICE_HANDLER( i8237_dreq1_w ) { dma8237_drq_write(device, 1, state); }
602WRITE_LINE_DEVICE_HANDLER( i8237_dreq2_w ) { dma8237_drq_write(device, 2, state); }
603WRITE_LINE_DEVICE_HANDLER( i8237_dreq3_w ) { dma8237_drq_write(device, 3, state); }
604
605WRITE_LINE_DEVICE_HANDLER( i8237_eop_w )
606{
607}
608
609
610static DEVICE_START( i8237 ) {
611   i8237_t   *i8237 = get_safe_token(device);
612   i8237_interface *intf = (i8237_interface *)device->baseconfig().static_config();
613   int i;
614
615   /* resolve callbacks */
616   devcb_resolve_write_line(&i8237->out_hrq_func, &intf->out_hrq_func, device);
617   devcb_resolve_write_line(&i8237->out_eop_func, &intf->out_eop_func, device);
618   devcb_resolve_read8(&i8237->in_memr_func, &intf->in_memr_func, device);
619   devcb_resolve_write8(&i8237->out_memw_func, &intf->out_memw_func, device);
620
621   for (i = 0; i < 4; i++)
622636   {
623      devcb_resolve_read8(&i8237->chan[i].in_ior_func, &intf->in_ior_func[i], device);
624      devcb_resolve_write8(&i8237->chan[i].out_iow_func, &intf->out_iow_func[i], device);
625      devcb_resolve_write_line(&i8237->chan[i].out_dack_func, &intf->out_dack_func[i], device);
637      m_drq &= ~( 0x01 << channel );
626638   }
627639
628   i8237->timer = timer_alloc(device->machine, dma8237_timerproc, (void *)device);
640   timer_enable( m_timer, ( m_command & 0x04 ) ? 0 : 1 );
629641}
630642
631643
632static DEVICE_RESET( i8237 ) {
633   i8237_t   *i8237 = get_safe_token(device);
634644
635   i8237->status = 0x0F;
636   i8237->eop = 1;
637   i8237->state = DMA8237_SI;
638   i8237->last_service_channel = 3;
645/***************************************************************************
646    TRAMPOLINES
647***************************************************************************/
639648
640   i8237->mask = 0x00;
641   i8237->status = 0x0F;
642   i8237->hrq = 0;
643   i8237->hlda = 0;
644   i8237->chan[0].mode = 0;
645   i8237->chan[1].mode = 0;
646   i8237->chan[2].mode = 0;
647   i8237->chan[3].mode = 0;
648
649   timer_adjust_periodic(i8237->timer,
650      ATTOTIME_IN_HZ(device->clock()),
651      0,
652      ATTOTIME_IN_HZ(device->clock()));
653}
654
655
656DEVICE_GET_INFO( i8237 ) {
657   switch ( state ) {
658      /* --- the following bits of info are returned as 64-bit signed integers --- */
659      case DEVINFO_INT_TOKEN_BYTES:            info->i = sizeof(i8237_t);            break;
660      case DEVINFO_INT_INLINE_CONFIG_BYTES:      info->i = 0;                        break;
661
662      /* --- the following bits of info are returned as pointers to data or functions --- */
663      case DEVINFO_FCT_START:                  info->start = DEVICE_START_NAME(i8237);   break;
664      case DEVINFO_FCT_STOP:                  /* nothing */                        break;
665      case DEVINFO_FCT_RESET:                  info->reset = DEVICE_RESET_NAME(i8237);   break;
666
667      /* --- the following bits of info are returned as NULL-terminated strings --- */
668      case DEVINFO_STR_NAME:                  strcpy(info->s, "Intel 8237");         break;
669      case DEVINFO_STR_FAMILY:               strcpy(info->s, "Intel 8080");               break;
670      case DEVINFO_STR_VERSION:               strcpy(info->s, "1.01");               break;
671      case DEVINFO_STR_SOURCE_FILE:            strcpy(info->s, __FILE__);               break;
672      case DEVINFO_STR_CREDITS:               strcpy(info->s, "Copyright the MAME and MESS Teams");   break;
673   }
674}
675
676
677DEFINE_LEGACY_DEVICE(I8237, i8237);
649WRITE_LINE_DEVICE_HANDLER( i8237_hlda_w ) { downcast<i8237_device*>(device)->i8237_hlda_w(state); }
650WRITE_LINE_DEVICE_HANDLER( i8237_ready_w ) { }
651WRITE_LINE_DEVICE_HANDLER( i8237_dreq0_w ) { downcast<i8237_device*>(device)->i8237_drq_write(0, state); }
652WRITE_LINE_DEVICE_HANDLER( i8237_dreq1_w ) { downcast<i8237_device*>(device)->i8237_drq_write(1, state); }
653WRITE_LINE_DEVICE_HANDLER( i8237_dreq2_w ) { downcast<i8237_device*>(device)->i8237_drq_write(2, state); }
654WRITE_LINE_DEVICE_HANDLER( i8237_dreq3_w ) { downcast<i8237_device*>(device)->i8237_drq_write(3, state); }
655WRITE_LINE_DEVICE_HANDLER( i8237_eop_w ) { }
src/emu/machine/eeprom.c
r8910r8911
107107
108108
109109//-------------------------------------------------
110//  device_config_complete - perform any
111//  operations now that the configuration is
112//  complete
110//  static_set_interface - configuration helper
111//  to set the interface
113112//-------------------------------------------------
114113
115void eeprom_device_config::device_config_complete()
114void eeprom_device_config::static_set_interface(device_config *device, const eeprom_interface &interface)
116115{
117   // extract inline configuration from raw data
118   const eeprom_interface *intf = reinterpret_cast<const eeprom_interface *>(m_inline_data[INLINE_INTERFACE]);
119   m_default_data = reinterpret_cast<const UINT8 *>(m_inline_data[INLINE_DATAPTR]);
120   m_default_data_size = m_inline_data[INLINE_DATASIZE];
121   m_default_value = m_inline_data[INLINE_DEFVALUE];
116   eeprom_device_config *eeprom = downcast<eeprom_device_config *>(device);
117   *static_cast<eeprom_interface *>(eeprom) = interface;
122118
123   // inherit a copy of the static data
124   if (intf != NULL)
125      *static_cast<eeprom_interface *>(this) = *intf;
126
127   // now describe our address space
128   if (m_data_bits == 8)
129      m_space_config = address_space_config("eeprom", ENDIANNESS_BIG, 8,  m_address_bits, 0, *ADDRESS_MAP_NAME(eeprom_map8));
119   // describe our address space
120   if (eeprom->m_data_bits == 8)
121      eeprom->m_space_config = address_space_config("eeprom", ENDIANNESS_BIG, 8,  eeprom->m_address_bits, 0, *ADDRESS_MAP_NAME(eeprom_map8));
130122   else
131      m_space_config = address_space_config("eeprom", ENDIANNESS_BIG, 16, m_address_bits * 2, 0, *ADDRESS_MAP_NAME(eeprom_map16));
123      eeprom->m_space_config = address_space_config("eeprom", ENDIANNESS_BIG, 16, eeprom->m_address_bits * 2, 0, *ADDRESS_MAP_NAME(eeprom_map16));
132124}
133125
134126
135127//-------------------------------------------------
128//  static_set_default_data - configuration helpers
129//  to set the default data
130//-------------------------------------------------
131
132void eeprom_device_config::static_set_default_data(device_config *device, const UINT8 *data, UINT32 size)
133{
134   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");
136//   assert(eeprom->m_data_bits == 8);
137   eeprom->m_default_data = data;
138   eeprom->m_default_data_size = size;
139}
140
141void eeprom_device_config::static_set_default_data(device_config *device, const UINT16 *data, UINT32 size)
142{
143   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");
145//   assert(eeprom->m_data_bits == 16);
146   eeprom->m_default_data = reinterpret_cast<const UINT8 *>(data);
147   eeprom->m_default_data_size = size;
148}
149
150
151//-------------------------------------------------
152//  static_set_default_value - configuration helper
153//  to set the default value
154//-------------------------------------------------
155
156void eeprom_device_config::static_set_default_value(device_config *device, UINT16 value)
157{
158   downcast<eeprom_device_config *>(device)->m_default_value = 0x10000 | value;
159}
160
161
162//-------------------------------------------------
136163//  device_validity_check - perform validity checks
137164//  on this device
138165//-------------------------------------------------
r8910r8911
141168{
142169   bool error = false;
143170
144   if (m_inline_data[INLINE_INTERFACE] == 0)
171   if (m_data_bits != 8 && m_data_bits != 16)
145172   {
146      mame_printf_error("%s: %s eeprom device '%s' did not specify an interface\n", driver.source_file, driver.name, tag());
147      error = true;
148   }
149   else if (m_data_bits != 8 && m_data_bits != 16)
150   {
151173      mame_printf_error("%s: %s eeprom device '%s' specified invalid data width %d\n", driver.source_file, driver.name, tag(), m_data_bits);
152174      error = true;
153175   }
src/emu/machine/8237dma.h
r8910r8911
3030
3131***************************************************************************/
3232
33#pragma once
34
3335#ifndef __I8237__
3436#define __I8237__
3537
36#include "devlegcy.h"
38#include "emu.h"
3739
3840
41
3942/***************************************************************************
40    MACROS / CONSTANTS
43    DEVICE CONFIGURATION MACROS
4144***************************************************************************/
4245
43DECLARE_LEGACY_DEVICE(I8237, i8237);
44
4546#define MDRV_I8237_ADD(_tag, _clock, _config) \
4647   MDRV_DEVICE_ADD(_tag, I8237, _clock) \
4748   MDRV_DEVICE_CONFIG(_config)
r8910r8911
4950#define I8237_INTERFACE(_name) \
5051   const i8237_interface (_name) =
5152
53
5254/***************************************************************************
5355    TYPE DEFINITIONS
5456***************************************************************************/
5557
56typedef struct _i8237_interface i8237_interface;
57struct _i8237_interface
58
59// ======================> i8237_interface
60
61struct i8237_interface
5862{
59   devcb_write_line   out_hrq_func;
60   devcb_write_line   out_eop_func;
63   devcb_write_line   m_out_hrq_func;
64   devcb_write_line   m_out_eop_func;
6165
6266   /* accessors to main memory */
63   devcb_read8         in_memr_func;
64   devcb_write8      out_memw_func;
67   devcb_read8         m_in_memr_func;
68   devcb_write8      m_out_memw_func;
6569
6670   /* channel accessors */
67   devcb_read8         in_ior_func[4];
68   devcb_write8      out_iow_func[4];
69   devcb_write_line   out_dack_func[4];
71   devcb_read8         m_in_ior_func[4];
72   devcb_write8      m_out_iow_func[4];
73   devcb_write_line   m_out_dack_func[4];
7074};
7175
76
77
78// ======================> i8237_device_config
79
80class i8237_device_config : public device_config,
81                            public i8237_interface
82{
83    friend class i8237_device;
84
85    // construction/destruction
86    i8237_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
87
88public:
89    // allocators
90    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
91    virtual device_t *alloc_device(running_machine &machine) const;
92
93protected:
94    // device_config overrides
95    virtual void device_config_complete();
96};
97
98
99
100// ======================> i8237_device
101
102class i8237_device :  public device_t
103{
104    friend class i8237_device_config;
105
106    // construction/destruction
107    i8237_device(running_machine &_machine, const i8237_device_config &_config);
108
109public:
110
111   /* register access */
112   UINT8 i8237_r(UINT32 offset);
113   void i8237_w(UINT32 offset, UINT8 data);
114
115   /* hold acknowledge */
116   void i8237_hlda_w(UINT8 state) { m_hlda = state; }
117
118   /* data request */
119   void i8237_drq_write(int channel, int state);
120
121   void i8237_timerproc();
122
123protected:
124    // device-level overrides
125    virtual void device_start();
126    virtual void device_reset();
127    virtual void device_post_load() { }
128    virtual void device_clock_changed() { }
129
130   static TIMER_CALLBACK( i8237_timerproc_callback );
131   static TIMER_CALLBACK( receive_event_callback );
132
133private:
134
135   void i8237_do_read();
136   void i8237_do_write();
137   void i8237_advance();
138   void set_dack(int channel);
139
140   /* States that the i8237 device can be in */
141   enum dma8237_state
142   {
143      DMA8237_SI,         /* Idle state */
144      DMA8237_S0,         /* HRQ has been triggered, waiting to receive HLDA */
145   //  DMA8237_SW,         /* Wait state */
146
147      /* Normal transfer states */
148      DMA8237_S1,         /* Output A8-A15; only used when A8-A15 really needs to be output */
149      DMA8237_S2,         /* Output A0-A7 */
150      DMA8237_S3,         /* Initiate read; skipped in compressed timing. On the S2->S3 transition DACK is set. */
151      DMA8237_S4,         /* Perform read/write */
152
153      /* Memory to memory transfer states */
154      DMA8237_S11,      /* Output A8-A15 */
155   //  DMA8237_S12,        /* Output A0-A7 */
156   //  DMA8237_S13,        /* Initiate read */
157   //  DMA8237_S14,        /* Perform read/write */
158   //  DMA8237_S21,        /* Output A8-A15 */
159   //  DMA8237_S22,        /* Output A0-A7 */
160   //  DMA8237_S23,        /* Initiate read */
161   //  DMA8237_S24,        /* Perform read/write */
162   };
163
164   devcb_resolved_write_line   m_out_hrq_func;
165   devcb_resolved_write_line   m_out_eop_func;
166   devcb_resolved_read8      m_in_memr_func;
167   devcb_resolved_write8      m_out_memw_func;
168
169   emu_timer *m_timer;
170
171   struct
172   {
173      devcb_resolved_read8      m_in_ior_func;
174      devcb_resolved_write8      m_out_iow_func;
175      devcb_resolved_write_line   m_out_dack_func;
176      UINT16 m_base_address;
177      UINT16 m_base_count;
178      UINT16 m_address;
179      UINT16 m_count;
180      UINT8 m_mode;
181      int m_high_address_changed;
182   } m_chan[4];
183
184   UINT32 m_msb : 1;
185   UINT32 m_eop : 1;
186   UINT8 m_temp;
187   UINT8 m_temporary_data;
188   UINT8 m_command;
189   UINT8 m_drq;
190   UINT8 m_mask;
191   UINT8 m_hrq;
192   UINT8 m_hlda;
193
194   /* bits  0- 3 :  Terminal count for channels 0-3
195     * bits  4- 7 :  Transfer in progress for channels 0-3 */
196   UINT8 m_status;
197
198   dma8237_state m_state;      /* State the device is currently in */
199   int m_service_channel;      /* Channel we will be servicing */
200   int m_last_service_channel;   /* Previous channel we serviced; used to determine channel priority. */
201
202    const i8237_device_config &m_config;
203};
204
205
206// device type definition
207extern const device_type I8237;
208
209
210
72211/***************************************************************************
73212    PROTOTYPES
74213***************************************************************************/
src/emu/machine/eeprom.h
r8910r8911
1919
2020#define MDRV_EEPROM_ADD(_tag, _interface) \
2121   MDRV_DEVICE_ADD(_tag, EEPROM, 0) \
22   MDRV_DEVICE_INLINE_DATAPTR(eeprom_device_config::INLINE_INTERFACE, &_interface)
22   eeprom_device_config::static_set_interface(device, _interface); \
2323
2424#define MDRV_EEPROM_93C46_ADD(_tag) \
2525   MDRV_EEPROM_ADD(_tag, eeprom_interface_93C46)
r8910r8911
2828   MDRV_EEPROM_ADD(_tag, eeprom_interface_93C66B)
2929
3030#define MDRV_EEPROM_DATA(_data, _size) \
31   MDRV_DEVICE_INLINE_DATAPTR(eeprom_device_config::INLINE_DATAPTR, &_data) \
32   MDRV_DEVICE_INLINE_DATA16(eeprom_device_config::INLINE_DATASIZE, _size)
31   eeprom_device_config::static_set_default_data(device, _data, _size); \
3332
3433#define MDRV_EEPROM_DEFAULT_VALUE(_value) \
35   MDRV_DEVICE_INLINE_DATA32(eeprom_device_config::INLINE_DEFVALUE, 0x10000 | ((_value) & 0xffff))
34   eeprom_device_config::static_set_default_value(device, _value); \
3635
3736
3837
r8910r8911
7675   static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
7776   virtual device_t *alloc_device(running_machine &machine) const;
7877
79   // inline configuration indexes
80   enum
81   {
82      INLINE_INTERFACE,
83      INLINE_DATAPTR,
84      INLINE_DATASIZE,
85      INLINE_DEFVALUE
86   };
78   // inline configuration helpers
79   static void static_set_interface(device_config *deviec, const eeprom_interface &interface);
80   static void static_set_default_data(device_config *device, const UINT8 *data, UINT32 size);
81   static void static_set_default_data(device_config *device, const UINT16 *data, UINT32 size);
82   static void static_set_default_value(device_config *device, UINT16 value);
8783
8884protected:
8985   // device_config overrides
90   virtual void device_config_complete();
9186   virtual bool device_validity_check(const game_driver &driver) const;
9287
9388   // device_config_memory_interface overrides
9489   virtual const address_space_config *memory_space_config(int spacenum = 0) const;
9590
9691   // device-specific configuration
92   address_space_config      m_space_config;
93
94   // internal state
9795   const UINT8 *            m_default_data;
9896   int                   m_default_data_size;
9997   UINT32                  m_default_value;
100   address_space_config      m_space_config;
10198};
10299
103100
src/emu/diexec.c
r8910r8911
7878     m_vblank_interrupts_per_frame(0),
7979     m_vblank_interrupt_screen(NULL),
8080     m_timed_interrupt(NULL),
81     m_timed_interrupt_period(0)
81     m_timed_interrupt_period(attotime_zero)
8282{
8383}
8484
r8910r8911
9393
9494
9595//-------------------------------------------------
96//  static_set_disable - configuration helper to
97//  set the disabled state of a device
98//-------------------------------------------------
99
100void device_config_execute_interface::static_set_disable(device_config *device)
101{
102   device_config_execute_interface *exec = dynamic_cast<device_config_execute_interface *>(device);
103   if (exec == NULL)
104      throw emu_fatalerror("MDRV_DEVICE_DISABLE called on device '%s' with no execute interface", device->tag());
105   exec->m_disabled = true;
106}
107
108
109//-------------------------------------------------
110//  static_set_vblank_int - configuration helper
111//  to set up VBLANK interrupts on the device
112//-------------------------------------------------
113
114void device_config_execute_interface::static_set_vblank_int(device_config *device, device_interrupt_func function, const char *tag, int rate)
115{
116   device_config_execute_interface *exec = dynamic_cast<device_config_execute_interface *>(device);
117   if (exec == NULL)
118      throw emu_fatalerror("MDRV_DEVICE_VBLANK_INT called on device '%s' with no execute interface", device->tag());
119   exec->m_vblank_interrupt = function;
120   exec->m_vblank_interrupts_per_frame = rate;
121   exec->m_vblank_interrupt_screen = tag;
122}
123
124
125//-------------------------------------------------
126//  static_set_periodic_int - configuration helper
127//  to set up periodic interrupts on the device
128//-------------------------------------------------
129
130void device_config_execute_interface::static_set_periodic_int(device_config *device, device_interrupt_func function, attotime rate)
131{
132   device_config_execute_interface *exec = dynamic_cast<device_config_execute_interface *>(device);
133   if (exec == NULL)
134      throw emu_fatalerror("MDRV_DEVICE_PERIODIC_INT called on device '%s' with no execute interface", device->tag());
135   exec->m_timed_interrupt = function;
136   exec->m_timed_interrupt_period = rate;
137}
138
139
140//-------------------------------------------------
96141//  execute_clocks_to_cycles - convert the number
97142//  of clocks to cycles, rounding down if necessary
98143//-------------------------------------------------
r8910r8911
161206
162207
163208//-------------------------------------------------
164//  interface_process_token - token processing for
165//  the sound interface
166//-------------------------------------------------
167
168bool device_config_execute_interface::interface_process_token(UINT32 entrytype, const machine_config_token *&tokens)
169{
170   switch (entrytype)
171   {
172      // disable a device
173      case MCONFIG_TOKEN_DIEXEC_DISABLE:
174         m_disabled = true;
175         return true;
176
177      // VBLANK interrupt
178      case MCONFIG_TOKEN_DIEXEC_VBLANK_INT:
179         TOKEN_UNGET_UINT32(tokens);
180         TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, m_vblank_interrupts_per_frame, 24);
181         m_vblank_interrupt = TOKEN_GET_PTR(tokens, cpu_interrupt);
182         m_vblank_interrupt_screen = TOKEN_GET_STRING(tokens);
183         return true;
184
185      // timed interrupt
186      case MCONFIG_TOKEN_DIEXEC_PERIODIC_INT:
187         m_timed_interrupt = TOKEN_GET_PTR(tokens, cpu_interrupt);
188         TOKEN_EXTRACT_UINT64(tokens, m_timed_interrupt_period);
189         return true;
190   }
191
192   return false;
193}
194
195
196//-------------------------------------------------
197209//  interface_validity_check - validation for a
198210//  device after the configuration has been
199211//  constructed
r8910r8911
234246      error = true;
235247   }
236248
237   if (m_timed_interrupt != NULL && m_timed_interrupt_period == 0)
249   if (m_timed_interrupt != NULL && attotime_compare(m_timed_interrupt_period, attotime_zero) == 0)
238250   {
239251      mame_printf_error("%s: %s device '%s' has a timer interrupt handler with 0 period!\n", driver.source_file, driver.name, devconfig->tag());
240252      error = true;
241253   }
242   else if (m_timed_interrupt == NULL && m_timed_interrupt_period != 0)
254   else if (m_timed_interrupt == NULL && attotime_compare(m_timed_interrupt_period, attotime_zero) != 0)
243255   {
244256      mame_printf_error("%s: %s device '%s' has a no timer interrupt handler but has a non-0 period given!\n", driver.source_file, driver.name, devconfig->tag());
245257      error = true;
r8910r8911
548560   // allocate timers if we need them
549561   if (m_execute_config.m_vblank_interrupts_per_frame > 1)
550562      m_partial_frame_timer = timer_alloc(&m_machine, static_trigger_partial_frame_interrupt, (void *)this);
551   if (m_execute_config.m_timed_interrupt_period != 0)
563   if (attotime_compare(m_execute_config.m_timed_interrupt_period, attotime_zero) != 0)
552564      m_timedint_timer = timer_alloc(&m_machine, static_trigger_periodic_interrupt, (void *)this);
553565
554566   // register for save states
r8910r8911
624636   }
625637
626638   // reconfigure periodic interrupts
627   if (m_execute_config.m_timed_interrupt_period != 0)
639   if (attotime_compare(m_execute_config.m_timed_interrupt_period, attotime_zero) != 0)
628640   {
629      attotime timedint_period = UINT64_ATTOTIME_TO_ATTOTIME(m_execute_config.m_timed_interrupt_period);
641      attotime timedint_period = m_execute_config.m_timed_interrupt_period;
630642      assert(m_timedint_timer != NULL);
631643      timer_adjust_periodic(m_timedint_timer, timedint_period, 0, timedint_period);
632644   }
src/emu/diexec.h
r8910r8911
109109//**************************************************************************
110110
111111#define MDRV_DEVICE_DISABLE() \
112   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DIEXEC_DISABLE, 8), \
112   device_config_execute_interface::static_set_disable(device); \
113113
114114#define MDRV_DEVICE_VBLANK_INT(_tag, _func) \
115   TOKEN_UINT32_PACK2(MCONFIG_TOKEN_DIEXEC_VBLANK_INT, 8, 0, 24), \
116   TOKEN_PTR(device_interrupt, _func), \
117   TOKEN_PTR(stringptr, _tag), \
115   device_config_execute_interface::static_set_vblank_int(device, _func, _tag); \
118116
119117#define MDRV_DEVICE_PERIODIC_INT(_func, _rate)   \
120   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DIEXEC_PERIODIC_INT, 8), \
121   TOKEN_PTR(device_interrupt, _func), \
122   TOKEN_UINT64(UINT64_ATTOTIME_IN_HZ(_rate)), \
118   device_config_execute_interface::static_set_periodic_int(device, _func, ATTOTIME_IN_HZ(_rate)); \
123119
124120
125121
r8910r8911
164160   UINT32 input_lines() const { return execute_input_lines(); }
165161   UINT32 default_irq_vector() const { return execute_default_irq_vector(); }
166162
163   // static inline helpers
164   static void static_set_disable(device_config *device);
165   static void static_set_vblank_int(device_config *device, device_interrupt_func function, const char *tag, int rate = 0);
166   static void static_set_periodic_int(device_config *device, device_interrupt_func function, attotime rate);
167
167168protected:
168169   // clock and cycle information getters
169170   virtual UINT64 execute_clocks_to_cycles(UINT64 clocks) const;
r8910r8911
176177   virtual UINT32 execute_default_irq_vector() const;
177178
178179   // optional operation overrides
179   virtual bool interface_process_token(UINT32 entrytype, const machine_config_token *&tokens);
180180   virtual bool interface_validity_check(const game_driver &driver) const;
181181
182182   bool               m_disabled;
r8910r8911
184184   int                m_vblank_interrupts_per_frame;   // usually 1
185185   const char *         m_vblank_interrupt_screen;      // the screen that causes the VBLANK interrupt
186186   device_interrupt_func   m_timed_interrupt;            // for interrupts not tied to VBLANK
187   UINT64               m_timed_interrupt_period;      // period for periodic interrupts
187   attotime            m_timed_interrupt_period;      // period for periodic interrupts
188188};
189189
190190
src/emu/sound.c
r8910r8911
496496
497497
498498//-------------------------------------------------
499//  device_config_complete - perform any
500//  operations now that the configuration is
501//  complete
499//  static_set_position - configuration helper to
500//  set the speaker position
502501//-------------------------------------------------
503502
504void speaker_device_config::device_config_complete()
503void speaker_device_config::static_set_position(device_config *device, double x, double y, double z)
505504{
506   // move inline data into its final home
507   m_x = static_cast<double>(static_cast<INT32>(m_inline_data[INLINE_X])) / (double)(1 << 24);
508   m_y = static_cast<double>(static_cast<INT32>(m_inline_data[INLINE_Y])) / (double)(1 << 24);
509   m_z = static_cast<double>(static_cast<INT32>(m_inline_data[INLINE_Z])) / (double)(1 << 24);
505   speaker_device_config *speaker = downcast<speaker_device_config *>(device);
506   speaker->m_x = x;
507   speaker->m_y = y;
508   speaker->m_z = z;
510509}
511510
512511
src/emu/sound.h
r8910r8911
4949   static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
5050   virtual device_t *alloc_device(running_machine &machine) const;
5151
52   // indexes to inline data
53   enum
54   {
55      INLINE_X,
56      INLINE_Y,
57      INLINE_Z
58   };
52   // inline configuration helpers
53   static void static_set_position(device_config *device, double x, double y, double z);
5954
6055protected:
61   // device_config overrides
62   virtual void device_config_complete();
63
64   // internal state
56   // inline configuration state
6557   double      m_x;
6658   double      m_y;
6759   double      m_z;
r8910r8911
133125/* add/remove speakers */
134126#define MDRV_SPEAKER_ADD(_tag, _x, _y, _z) \
135127   MDRV_DEVICE_ADD(_tag, SPEAKER, 0) \
136   MDRV_DEVICE_INLINE_DATA32(speaker_device_config::INLINE_X, (INT32)((_x) * (double)(1 << 24))) \
137   MDRV_DEVICE_INLINE_DATA32(speaker_device_config::INLINE_Y, (INT32)((_y) * (double)(1 << 24))) \
138   MDRV_DEVICE_INLINE_DATA32(speaker_device_config::INLINE_Z, (INT32)((_z) * (double)(1 << 24)))
128   speaker_device_config::static_set_position(device, _x, _y, _z); \
139129
140130#define MDRV_SPEAKER_STANDARD_MONO(_tag) \
141131   MDRV_SPEAKER_ADD(_tag, 0.0, 0.0, 1.0)
src/emu/driver.h
r8910r8911
6767   const char *      description;            /* full name of the game */
6868   const char *      year;                  /* year the game was released */
6969   const char *      manufacturer;            /* manufacturer of the game */
70   const machine_config_token *machine_config;      /* machine driver tokens */
70   machine_config_constructor machine_config;      /* machine driver tokens */
7171   const input_port_token *ipt;               /* pointer to array of input port tokens */
7272   void            (*driver_init)(running_machine *machine); /* DRIVER_INIT callback */
7373   const rom_entry *   rom;                  /* pointer to list of ROMs for the game */
src/emu/timer.c
r8910r8911
943943     m_type(TIMER_TYPE_GENERIC),
944944     m_callback(NULL),
945945     m_ptr(NULL),
946     m_start_delay(0),
947     m_period(0),
946     m_start_delay(attotime_zero),
947     m_period(attotime_zero),
948948     m_param(0),
949949     m_screen(NULL),
950950     m_first_vpos(0),
r8910r8911
975975
976976
977977//-------------------------------------------------
978//  device_config_complete - perform any
979//  operations now that the configuration is
980//  complete
978//  static_configure_generic - configuration
979//  helper to set up a generic timer
981980//-------------------------------------------------
982981
983void timer_device_config::device_config_complete()
982void timer_device_config::static_configure_generic(device_config *device, timer_device_fired_func callback)
984983{
985   // move inline data into its final home
986   m_type = static_cast<timer_type>(m_inline_data[INLINE_TYPE]);
987   m_callback = reinterpret_cast<timer_device_fired_func>(m_inline_data[INLINE_CALLBACK]);
988   m_ptr = reinterpret_cast<void *>(m_inline_data[INLINE_PTR]);
989   m_start_delay = static_cast<UINT64>(m_inline_data[INLINE_DELAY]);
990   m_period = static_cast<UINT64>(m_inline_data[INLINE_PERIOD]);
991   m_param = static_cast<UINT32>(m_inline_data[INLINE_PARAM]);
992   m_screen = reinterpret_cast<const char *>(m_inline_data[INLINE_SCREEN]);
993   m_first_vpos = static_cast<INT16>(m_inline_data[INLINE_FIRST_VPOS]);
994   m_increment = static_cast<INT16>(m_inline_data[INLINE_INCREMENT]);
984   timer_device_config *timer = downcast<timer_device_config *>(device);
985   timer->m_type = TIMER_TYPE_GENERIC;
986   timer->m_callback = callback;
995987}
996988
997989
998990//-------------------------------------------------
991//  static_configure_periodic - configuration
992//  helper to set up a periodic timer
993//-------------------------------------------------
994
995void timer_device_config::static_configure_periodic(device_config *device, timer_device_fired_func callback, attotime period)
996{
997   timer_device_config *timer = downcast<timer_device_config *>(device);
998   timer->m_type = TIMER_TYPE_PERIODIC;
999   timer->m_callback = callback;
1000   timer->m_period = period;
1001}
1002
1003
1004//-------------------------------------------------
1005//  static_configure_scanline - configuration
1006//  helper to set up a scanline timer
1007//-------------------------------------------------
1008
1009void timer_device_config::static_configure_scanline(device_config *device, timer_device_fired_func callback, const char *screen, int first_vpos, int increment)
1010{
1011   timer_device_config *timer = downcast<timer_device_config *>(device);
1012   timer->m_type = TIMER_TYPE_SCANLINE;
1013   timer->m_callback = callback;
1014   timer->m_screen = screen;
1015   timer->m_first_vpos = first_vpos;
1016   timer->m_increment = increment;
1017}
1018
1019
1020//-------------------------------------------------
1021//  static_set_callback - configuration helper
1022//  to set the callback
1023//-------------------------------------------------
1024
1025void timer_device_config::static_set_callback(device_config *device, timer_device_fired_func callback)
1026{
1027   timer_device_config *timer = downcast<timer_device_config *>(device);
1028   timer->m_callback = callback;
1029}
1030
1031
1032//-------------------------------------------------
1033//  static_set_start_delay - configuration helper
1034//  to set the starting delay
1035//-------------------------------------------------
1036
1037void timer_device_config::static_set_start_delay(device_config *device, attotime delay)
1038{
1039   timer_device_config *timer = downcast<timer_device_config *>(device);
1040   timer->m_start_delay = delay;
1041}
1042
1043
1044//-------------------------------------------------
1045//  static_set_param - configuration helper to set
1046//  the integer parameter
1047//-------------------------------------------------
1048
1049void timer_device_config::static_set_param(device_config *device, int param)
1050{
1051   timer_device_config *timer = downcast<timer_device_config *>(device);
1052   timer->m_param = param;
1053}
1054
1055
1056//-------------------------------------------------
1057//  static_set_ptr - configuration helper to set
1058//  the pointer parameter
1059//-------------------------------------------------
1060
1061void timer_device_config::static_set_ptr(device_config *device, void *ptr)
1062{
1063   timer_device_config *timer = downcast<timer_device_config *>(device);
1064   timer->m_ptr = ptr;
1065}
1066
1067
1068//-------------------------------------------------
9991069//  device_validity_check - validate the device
10001070//  configuration
10011071//-------------------------------------------------
r8910r8911
10081078   switch (m_type)
10091079   {
10101080      case TIMER_TYPE_GENERIC:
1011         if (m_screen != NULL || m_first_vpos != 0 || m_start_delay != 0)
1081         if (m_screen != NULL || m_first_vpos != 0 || attotime_compare(m_start_delay, attotime_zero) != 0)
10121082            mame_printf_warning("%s: %s generic timer '%s' specified parameters for a scanline timer\n", driver.source_file, driver.name, tag());
1013         if (m_period != 0 || m_start_delay != 0)
1083         if (attotime_compare(m_period, attotime_zero) != 0 || attotime_compare(m_start_delay, attotime_zero) != 0)
10141084            mame_printf_warning("%s: %s generic timer '%s' specified parameters for a periodic timer\n", driver.source_file, driver.name, tag());
10151085         break;
10161086
10171087      case TIMER_TYPE_PERIODIC:
10181088         if (m_screen != NULL || m_first_vpos != 0)
10191089            mame_printf_warning("%s: %s periodic timer '%s' specified parameters for a scanline timer\n", driver.source_file, driver.name, tag());
1020         if (m_period <= 0)
1090         if (attotime_compare(m_period, attotime_zero) <= 0)
10211091         {
10221092            mame_printf_error("%s: %s periodic timer '%s' specified invalid period\n", driver.source_file, driver.name, tag());
10231093            error = true;
r8910r8911
10251095         break;
10261096
10271097      case TIMER_TYPE_SCANLINE:
1028         if (m_period != 0 || m_start_delay != 0)
1098         if (attotime_compare(m_period, attotime_zero) != 0 || attotime_compare(m_start_delay, attotime_zero) != 0)
10291099            mame_printf_warning("%s: %s scanline timer '%s' specified parameters for a periodic timer\n", driver.source_file, driver.name, tag());
10301100         if (m_param != 0)
10311101            mame_printf_warning("%s: %s scanline timer '%s' specified parameter which is ignored\n", driver.source_file, driver.name, tag());
r8910r8911
11041174      {
11051175         // convert the period into attotime
11061176         attotime period = attotime_never;
1107         if (m_config.m_period > 0)
1177         if (attotime_compare(m_config.m_period, attotime_zero) > 0)
11081178         {
1109            period = UINT64_ATTOTIME_TO_ATTOTIME(m_config.m_period);
1179            period = m_config.m_period;
11101180
11111181            // convert the start_delay into attotime
11121182            attotime start_delay = attotime_zero;
1113            if (m_config.m_start_delay > 0)
1114               start_delay = UINT64_ATTOTIME_TO_ATTOTIME(m_config.m_start_delay);
1183            if (attotime_compare(m_config.m_start_delay, attotime_zero) > 0)
1184               start_delay = m_config.m_start_delay;
11151185
11161186            // allocate and start the backing timer
11171187            timer_adjust_periodic(m_timer, start_delay, m_config.m_param, period);
src/emu/mconfig.c
r8910r8911
4949//  machine_config - constructor
5050//-------------------------------------------------
5151
52machine_config::machine_config(const machine_config_token *tokens)
52machine_config::machine_config(machine_config_constructor constructor)
5353   : m_driver_data_alloc(NULL),
5454     m_minimum_quantum(attotime_zero),
5555     m_perfect_cpu_quantum(NULL),
r8910r8911
7272     m_sound_reset(NULL),
7373     m_parse_level(0)
7474{
75   // parse tokens into the config
76   detokenize(tokens);
75   // construct the config
76   (*constructor)(*this, NULL);
77
78   // process any device-specific machine configurations
79   for (device_config *devconfig = m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next())
80      if (!devconfig->m_config_complete)
81      {
82         machine_config_constructor additions = devconfig->machine_config_additions();
83         if (additions != NULL)
84            (*additions)(*this, devconfig);
85      }
86
87   // then notify all devices that their configuration is complete
88   for (device_config *devconfig = m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next())
89      if (!devconfig->m_config_complete)
90      {
91         devconfig->config_complete();
92         devconfig->m_config_complete = true;
93      }
7794}
7895
7996
r8910r8911
87104
88105
89106//-------------------------------------------------
90//  detokenize - detokenize a machine config
107//  device_add - configuration helper to add a
108//  new device
91109//-------------------------------------------------
92110
93void machine_config::detokenize(const machine_config_token *tokens, const device_config *owner)
111device_config *machine_config::device_add(device_config *owner, const char *tag, device_type type, UINT32 clock)
94112{
95   device_config *device = NULL;
96113   astring tempstring;
114   const char *fulltag = owner->subtag(tempstring, tag);
115   return m_devicelist.append(fulltag, (*type)(*this, fulltag, owner, clock));
116}
97117
98   // increase the parse level
99   m_parse_level++;
100118
101   // loop over tokens until we hit the end
102   UINT32 entrytype = MCONFIG_TOKEN_INVALID;
103   while (entrytype != MCONFIG_TOKEN_END)
104   {
105      device_type devtype;
106      const char *tag;
107      UINT64 data64;
108      UINT32 clock;
119//-------------------------------------------------
120//  device_replace - configuration helper to
121//  replace one device with a new device
122//-------------------------------------------------
109123
110      // unpack the token from the first entry
111      TOKEN_GET_UINT32_UNPACK1(tokens, entrytype, 8);
112      switch (entrytype)
113      {
114         // end
115         case MCONFIG_TOKEN_END:
116            break;
124device_config *machine_config::device_replace(device_config *owner, const char *tag, device_type type, UINT32 clock)
125{
126   astring tempstring;
127   const char *fulltag = owner->subtag(tempstring, tag);
128   return m_devicelist.replace(fulltag, (*type)(*this, fulltag, owner, clock));
129}
117130
118         // including
119         case MCONFIG_TOKEN_INCLUDE:
120            detokenize(TOKEN_GET_PTR(tokens, tokenptr), owner);
121            break;
122131
123         // device management
124         case MCONFIG_TOKEN_DEVICE_ADD:
125            TOKEN_UNGET_UINT32(tokens);
126            TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, clock, 32);
127            devtype = TOKEN_GET_PTR(tokens, devtype);
128            tag = owner->subtag(tempstring, TOKEN_GET_STRING(tokens));
129            device = m_devicelist.append(tag, (*devtype)(*this, tag, owner, clock));
130            break;
132//-------------------------------------------------
133//  device_remove - configuration helper to
134//  remove a device
135//-------------------------------------------------
131136
132         case MCONFIG_TOKEN_DEVICE_REPLACE:
133            TOKEN_UNGET_UINT32(tokens);
134            TOKEN_GET_UINT64_UNPACK2(tokens, entrytype, 8, clock, 32);
135            devtype = TOKEN_GET_PTR(tokens, devtype);
136            tag = owner->subtag(tempstring, TOKEN_GET_STRING(tokens));
137            device = m_devicelist.replace(tag, (*devtype)(*this, tag, owner, clock));
138            break;
137device_config *machine_config::device_remove(device_config *owner, const char *tag)
138{
139   astring tempstring;
140   const char *fulltag = owner->subtag(tempstring, tag);
141   m_devicelist.remove(fulltag);
142   return NULL;
143}
139144
140         case MCONFIG_TOKEN_DEVICE_REMOVE:
141            tag = TOKEN_GET_STRING(tokens);
142            m_devicelist.remove(owner->subtag(tempstring, tag));
143            device = NULL;
144            break;
145145
146         case MCONFIG_TOKEN_DEVICE_MODIFY:
147            tag = TOKEN_GET_STRING(tokens);
148            device = m_devicelist.find(owner->subtag(tempstring, tag).cstr());
149            if (device == NULL)
150               fatalerror("Unable to find device: tag=%s\n", tempstring.cstr());
151            break;
146//-------------------------------------------------
147//  device_find - configuration helper to
148//  locate a device
149//-------------------------------------------------
152150
153         case MCONFIG_TOKEN_DEVICE_CLOCK:
154         case MCONFIG_TOKEN_DEVICE_CONFIG:
155         case MCONFIG_TOKEN_DEVICE_INLINE_DATA16:
156         case MCONFIG_TOKEN_DEVICE_INLINE_DATA32:
157         case MCONFIG_TOKEN_DEVICE_INLINE_DATA64:
158
159         case MCONFIG_TOKEN_DIEXEC_DISABLE:
160         case MCONFIG_TOKEN_DIEXEC_VBLANK_INT:
161         case MCONFIG_TOKEN_DIEXEC_PERIODIC_INT:
162
163         case MCONFIG_TOKEN_DIMEMORY_MAP:
164
165         case MCONFIG_TOKEN_DISOUND_ROUTE:
166         case MCONFIG_TOKEN_DISOUND_RESET:
167
168         case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_1:
169         case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_2:
170         case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_3:
171         case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_4:
172         case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_5:
173         case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_6:
174         case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_7:
175         case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_8:
176         case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_9:
177         case MCONFIG_TOKEN_DEVICE_CONFIG_DATA32:
178         case MCONFIG_TOKEN_DEVICE_CONFIG_DATA64:
179         case MCONFIG_TOKEN_DEVICE_CONFIG_DATAFP32:
180         case MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_FREE:
181            assert(device != NULL);
182            device->process_token(entrytype, tokens);
183            break;
184
185
186         // core parameters
187         case MCONFIG_TOKEN_DRIVER_DATA:
188            m_driver_data_alloc = TOKEN_GET_PTR(tokens, driver_data_alloc);
189            break;
190
191         case MCONFIG_TOKEN_QUANTUM_TIME:
192            TOKEN_EXTRACT_UINT64(tokens, data64);
193            m_minimum_quantum = UINT64_ATTOTIME_TO_ATTOTIME(data64);
194            break;
195
196         case MCONFIG_TOKEN_QUANTUM_PERFECT_CPU:
197            m_perfect_cpu_quantum = TOKEN_GET_STRING(tokens);
198            break;
199
200         case MCONFIG_TOKEN_WATCHDOG_VBLANK:
201            TOKEN_UNGET_UINT32(tokens);
202            TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, m_watchdog_vblank_count, 24);
203            break;
204
205         case MCONFIG_TOKEN_WATCHDOG_TIME:
206            TOKEN_EXTRACT_UINT64(tokens, data64);
207            m_watchdog_time = UINT64_ATTOTIME_TO_ATTOTIME(data64);
208            break;
209
210         // core functions
211         case MCONFIG_TOKEN_MACHINE_START:
212            m_machine_start = TOKEN_GET_PTR(tokens, machine_start);
213            break;
214
215         case MCONFIG_TOKEN_MACHINE_RESET:
216            m_machine_reset = TOKEN_GET_PTR(tokens, machine_reset);
217            break;
218
219         case MCONFIG_TOKEN_NVRAM_HANDLER:
220            m_nvram_handler = TOKEN_GET_PTR(tokens, nvram_handler);
221            break;
222
223         case MCONFIG_TOKEN_MEMCARD_HANDLER:
224            m_memcard_handler = TOKEN_GET_PTR(tokens, memcard_handler);
225            break;
226
227         // core video parameters
228         case MCONFIG_TOKEN_VIDEO_ATTRIBUTES:
229            TOKEN_UNGET_UINT32(tokens);
230            TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, m_video_attributes, 24);
231            break;
232
233         case MCONFIG_TOKEN_GFXDECODE:
234            m_gfxdecodeinfo = TOKEN_GET_PTR(tokens, gfxdecode);
235            break;
236
237         case MCONFIG_TOKEN_PALETTE_LENGTH:
238            TOKEN_UNGET_UINT32(tokens);
239            TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, m_total_colors, 24);
240            break;
241
242         case MCONFIG_TOKEN_DEFAULT_LAYOUT:
243            m_default_layout = TOKEN_GET_STRING(tokens);
244            break;
245
246         // core video functions
247         case MCONFIG_TOKEN_PALETTE_INIT:
248            m_init_palette = TOKEN_GET_PTR(tokens, palette_init);
249            break;
250
251         case MCONFIG_TOKEN_VIDEO_START:
252            m_video_start = TOKEN_GET_PTR(tokens, video_start);
253            break;
254
255         case MCONFIG_TOKEN_VIDEO_RESET:
256            m_video_reset = TOKEN_GET_PTR(tokens, video_reset);
257            break;
258
259         case MCONFIG_TOKEN_VIDEO_EOF:
260            m_video_eof = TOKEN_GET_PTR(tokens, video_eof);
261            break;
262
263         case MCONFIG_TOKEN_VIDEO_UPDATE:
264            m_video_update = TOKEN_GET_PTR(tokens, video_update);
265            break;
266
267         // core sound functions
268         case MCONFIG_TOKEN_SOUND_START:
269            m_sound_start = TOKEN_GET_PTR(tokens, sound_start);
270            break;
271
272         case MCONFIG_TOKEN_SOUND_RESET:
273            m_sound_reset = TOKEN_GET_PTR(tokens, sound_reset);
274            break;
275
276         default:
277            fatalerror("Invalid token %d in machine config\n", entrytype);
278            break;
279      }
280   }
281
282   // if we started at parse level 0 (and are thus at level 1), do post-processing
283   if (m_parse_level == 1)
284   {
285      // process any device-specific machine configurations
286      for (const device_config *devconfig = m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next())
287         if (!devconfig->m_config_complete)
288         {
289            tokens = devconfig->machine_config_tokens();
290            if (tokens != NULL)
291               detokenize(tokens, devconfig);
292         }
293
294      // then notify all devices that their configuration is complete
295      for (device_config *devconfig = m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next())
296         if (!devconfig->m_config_complete)
297         {
298            devconfig->config_complete();
299            devconfig->m_config_complete = true;
300         }
301   }
302
303   // bump down the parse level
304   m_parse_level--;
151device_config *machine_config::device_find(device_config *owner, const char *tag)
152{
153   astring tempstring;
154   const char *fulltag = owner->subtag(tempstring, tag);
155   device_config *device = m_devicelist.find(fulltag);
156   if (device == NULL)
157      throw emu_fatalerror("Unable to find device: tag=%s\n", fulltag);
158   return device;
305159}
src/emu/timer.h
r8910r8911
8080
8181#define MDRV_TIMER_ADD(_tag, _callback) \
8282   MDRV_DEVICE_ADD(_tag, TIMER, 0) \
83   MDRV_DEVICE_INLINE_DATA16(timer_device_config::INLINE_TYPE, timer_device_config::TIMER_TYPE_GENERIC) \
84   MDRV_DEVICE_INLINE_DATAPTR(timer_device_config::INLINE_CALLBACK, _callback)
83   timer_device_config::static_configure_generic(device, _callback); \
8584
8685#define MDRV_TIMER_ADD_PERIODIC(_tag, _callback, _period) \
8786   MDRV_DEVICE_ADD(_tag, TIMER, 0) \
88   MDRV_DEVICE_INLINE_DATA16(timer_device_config::INLINE_TYPE, timer_device_config::TIMER_TYPE_PERIODIC) \
89   MDRV_DEVICE_INLINE_DATAPTR(timer_device_config::INLINE_CALLBACK, _callback) \
90   MDRV_DEVICE_INLINE_DATA64(timer_device_config::INLINE_PERIOD, UINT64_ATTOTIME_IN_##_period)
87   timer_device_config::static_configure_periodic(device, _callback, ATTOTIME_IN_##_period); \
9188
9289#define MDRV_TIMER_ADD_SCANLINE(_tag, _callback, _screen, _first_vpos, _increment) \
9390   MDRV_DEVICE_ADD(_tag, TIMER, 0) \
94   MDRV_DEVICE_INLINE_DATA16(timer_device_config::INLINE_TYPE, timer_device_config::TIMER_TYPE_SCANLINE) \
95   MDRV_DEVICE_INLINE_DATAPTR(timer_device_config::INLINE_CALLBACK, _callback) \
96   MDRV_DEVICE_INLINE_DATAPTR(timer_device_config::INLINE_SCREEN, _screen) \
97   MDRV_DEVICE_INLINE_DATA16(timer_device_config::INLINE_FIRST_VPOS, _first_vpos) \
98   MDRV_DEVICE_INLINE_DATA16(timer_device_config::INLINE_INCREMENT, _increment)
91   timer_device_config::static_configure_scanline(device, _callback, _screen, _first_vpos, _increment); \
9992
10093#define MDRV_TIMER_MODIFY(_tag) \
10194   MDRV_DEVICE_MODIFY(_tag)
10295
10396#define MDRV_TIMER_CALLBACK(_callback) \
104   MDRV_DEVICE_INLINE_DATA32(timer_device_config::INLINE_CALLBACK, _callback)
97   timer_device_config::static_set_callback(device, _callback); \
10598
10699#define MDRV_TIMER_START_DELAY(_start_delay) \
107   MDRV_DEVICE_INLINE_DATA64(timer_device_config::INLINE_DELAY, UINT64_ATTOTIME_IN_##_start_delay)
100   timer_device_config::static_set_start_delay(device, ATTOTIME_IN_##_start_delay); \
108101
109102#define MDRV_TIMER_PARAM(_param) \
110   MDRV_DEVICE_INLINE_DATA32(timer_device_config::INLINE_PARAM, _param)
103   timer_device_config::static_set_param(device, _param); \
111104
112105#define MDRV_TIMER_PTR(_ptr) \
113   MDRV_DEVICE_INLINE_DATAPTR(timer_device_config::INLINE_PTR, _ptr)
106   timer_device_config::static_set_ptr(device, (void *)(_ptr)); \
114107
115108
116109
r8910r8911
233226   static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
234227   virtual device_t *alloc_device(running_machine &machine) const;
235228
236   // indexes to inline data
237   enum
238   {
239      INLINE_TYPE,
240      INLINE_CALLBACK,
241      INLINE_PERIOD,
242      INLINE_SCREEN,
243      INLINE_FIRST_VPOS,
244      INLINE_INCREMENT,
245      INLINE_DELAY,
246      INLINE_PARAM,
247      INLINE_PTR
248   };
229   // inline configuration helpers
230   static void static_configure_generic(device_config *device, timer_device_fired_func callback);
231   static void static_configure_periodic(device_config *device, timer_device_fired_func callback, attotime period);
232   static void static_configure_scanline(device_config *device, timer_device_fired_func callback, const char *screen, int first_vpos, int increment);
233   static void static_set_callback(device_config *device, timer_device_fired_func callback);
234   static void static_set_start_delay(device_config *device, attotime delay);
235   static void static_set_param(device_config *device, int param);
236   static void static_set_ptr(device_config *device, void *ptr);
249237
238private:
239   // device_config overrides
240   virtual bool device_validity_check(const game_driver &driver) const;
241
250242   // timer types
251243   enum timer_type
252244   {
r8910r8911
255247      TIMER_TYPE_GENERIC
256248   };
257249
258private:
259   // device_config overrides
260   virtual void device_config_complete();
261   virtual bool device_validity_check(const game_driver &driver) const;
262
263250   // configuration data
264251   timer_type            m_type;            // type of timer
265252   timer_device_fired_func   m_callback;         // the timer's callback function
266253   void *               m_ptr;            // the pointer parameter passed to the timer callback
267254
268255   // periodic timers only
269   UINT64               m_start_delay;      // delay before the timer fires for the first time
270   UINT64               m_period;         // period of repeated timer firings
256   attotime            m_start_delay;      // delay before the timer fires for the first time
257   attotime            m_period;         // period of repeated timer firings
271258   INT32               m_param;         // the integer parameter passed to the timer callback
272259
273260   // scanline timers only
src/emu/dimemory.c
r8910r8911
144144
145145
146146//-------------------------------------------------
147//  interface_process_token - token processing for
148//  the memory interface
147//  static_set_vblank_int - configuration helper
148//  to set up VBLANK interrupts on the device
149149//-------------------------------------------------
150150
151bool device_config_memory_interface::interface_process_token(UINT32 entrytype, const machine_config_token *&tokens)
151void device_config_memory_interface::static_set_addrmap(device_config *device, int spacenum, address_map_constructor map)
152152{
153   UINT32 data32;
154
155   switch (entrytype)
156   {
157      // specify device address map
158      case MCONFIG_TOKEN_DIMEMORY_MAP:
159         TOKEN_UNGET_UINT32(tokens);
160         TOKEN_GET_UINT32_UNPACK2(tokens, entrytype, 8, data32, 8);
161         assert(data32 < ARRAY_LENGTH(m_address_map));
162         m_address_map[data32] = TOKEN_GET_PTR(tokens, addrmap);
163         return true;
164   }
165
166   return false;
153   device_config_memory_interface *memory = dynamic_cast<device_config_memory_interface *>(device);
154   if (memory == NULL)
155      throw emu_fatalerror("MDRV_DEVICE_ADDRESS_MAP called on device '%s' with no memory interface", device->tag());
156   if (spacenum >= ARRAY_LENGTH(memory->m_address_map))
157      throw emu_fatalerror("MDRV_DEVICE_ADDRESS_MAP called with out-of-range space number %d", device->tag(), spacenum);
158   memory->m_address_map[spacenum] = map;
167159}
168160
169161
src/emu/mconfig.h
r8910r8911
4747#define __MCONFIG_H__
4848
4949
50//**************************************************************************
51//  CONSTANTS
52//**************************************************************************
53
54// by convention, tags should all lowercase and between 2-15 characters
55#define MIN_TAG_LENGTH         2
56#define MAX_TAG_LENGTH         15
57
58
59
60// ----- flags for video_attributes -----
61
62// should VIDEO_UPDATE by called at the start of VBLANK or at the end?
63#define   VIDEO_UPDATE_BEFORE_VBLANK      0x0000
64#define   VIDEO_UPDATE_AFTER_VBLANK      0x0004
65
66// indicates VIDEO_UPDATE will add container bits its
67#define VIDEO_SELF_RENDER            0x0008
68
69// automatically extend the palette creating a darker copy for shadows
70#define VIDEO_HAS_SHADOWS            0x0010
71
72// automatically extend the palette creating a brighter copy for highlights
73#define VIDEO_HAS_HIGHLIGHTS         0x0020
74
75// Mish 181099:  See comments in video/generic.c for details
76#define VIDEO_BUFFERS_SPRITERAM         0x0040
77
78// force VIDEO_UPDATE to be called even for skipped frames
79#define VIDEO_ALWAYS_UPDATE            0x0080
80
81// calls VIDEO_UPDATE for every visible scanline, even for skipped frames
82#define VIDEO_UPDATE_SCANLINE         0x0100
83
84
85
5086#define NVRAM_HANDLER_NAME(name)   nvram_handler_##name
5187#define NVRAM_HANDLER(name)         void NVRAM_HANDLER_NAME(name)(running_machine *machine, mame_file *file, int read_or_write)
5288#define NVRAM_HANDLER_CALL(name)   NVRAM_HANDLER_NAME(name)(machine, file, read_or_write)
r8910r8911
106142#define video_update_0            NULL
107143
108144
145
146//**************************************************************************
147//  TYPE DEFINITIONS
148//**************************************************************************
149
150// forward references
151struct gfx_decode_entry;
109152class driver_data_t;
110153
154
155
156// various callback functions
111157typedef void   (*nvram_handler_func)(running_machine *machine, mame_file *file, int read_or_write);
112158typedef void   (*memcard_handler_func)(running_machine *machine, mame_file *file, int action);
113159typedef void   (*machine_start_func)(running_machine *machine);
r8910r8911
118164typedef void   (*video_reset_func)(running_machine *machine);
119165typedef void   (*palette_init_func)(running_machine *machine, const UINT8 *color_prom);
120166typedef void   (*video_eof_func)(running_machine *machine);
121typedef UINT32 (*video_update_func)(device_t *screen, bitmap_t *bitmap, const rectangle *cliprect);
167typedef UINT32 (*video_update_func)(screen_device *screen, bitmap_t *bitmap, const rectangle *cliprect);
122168typedef driver_data_t *(*driver_data_alloc_func)(running_machine &machine);
123169
124170
125171
126/***************************************************************************
127    CONSTANTS
128***************************************************************************/
172// ======================> address_map_entry
129173
130// by convention, tags should all lowercase and between 2-15 characters
131#define MIN_TAG_LENGTH         2
132#define MAX_TAG_LENGTH         15
133
134
135// token types
136enum
137{
138   MCONFIG_TOKEN_INVALID,
139   MCONFIG_TOKEN_END,
140   MCONFIG_TOKEN_INCLUDE,
141
142   MCONFIG_TOKEN_DRIVER_DATA,
143   MCONFIG_TOKEN_QUANTUM_TIME,
144   MCONFIG_TOKEN_QUANTUM_PERFECT_CPU,
145   MCONFIG_TOKEN_WATCHDOG_VBLANK,
146   MCONFIG_TOKEN_WATCHDOG_TIME,
147
148   MCONFIG_TOKEN_MACHINE_START,
149   MCONFIG_TOKEN_MACHINE_RESET,
150   MCONFIG_TOKEN_NVRAM_HANDLER,
151   MCONFIG_TOKEN_MEMCARD_HANDLER,
152
153   MCONFIG_TOKEN_VIDEO_ATTRIBUTES,
154   MCONFIG_TOKEN_GFXDECODE,
155   MCONFIG_TOKEN_PALETTE_LENGTH,
156   MCONFIG_TOKEN_DEFAULT_LAYOUT,
157
158   MCONFIG_TOKEN_PALETTE_INIT,
159   MCONFIG_TOKEN_VIDEO_START,
160   MCONFIG_TOKEN_VIDEO_RESET,
161   MCONFIG_TOKEN_VIDEO_EOF,
162   MCONFIG_TOKEN_VIDEO_UPDATE,
163
164   MCONFIG_TOKEN_SOUND_START,
165   MCONFIG_TOKEN_SOUND_RESET,
166
167   MCONFIG_TOKEN_DEVICE_ADD,
168   MCONFIG_TOKEN_DEVICE_REPLACE,
169   MCONFIG_TOKEN_DEVICE_REMOVE,
170   MCONFIG_TOKEN_DEVICE_MODIFY,
171
172   // device-specific tokens
173   MCONFIG_TOKEN_DEVICE_CLOCK,
174   MCONFIG_TOKEN_DEVICE_CONFIG,
175   MCONFIG_TOKEN_DEVICE_INLINE_DATA16,
176   MCONFIG_TOKEN_DEVICE_INLINE_DATA32,
177   MCONFIG_TOKEN_DEVICE_INLINE_DATA64,
178
179   // execute interface-specific tokens
180   MCONFIG_TOKEN_DIEXEC_DISABLE,
181   MCONFIG_TOKEN_DIEXEC_VBLANK_INT,
182   MCONFIG_TOKEN_DIEXEC_PERIODIC_INT,
183
184   // memory interface-specific tokens
185   MCONFIG_TOKEN_DIMEMORY_MAP,
186
187   // sound interface-specific tokens
188   MCONFIG_TOKEN_DISOUND_ROUTE,
189   MCONFIG_TOKEN_DISOUND_RESET,
190
191   // legacy custom tokens
192   MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_1,
193   MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_2,
194   MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_3,
195   MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_4,
196   MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_5,
197   MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_6,
198   MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_7,
199   MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_8,
200   MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_9,
201
202   MCONFIG_TOKEN_DEVICE_CONFIG_DATA32,
203   MCONFIG_TOKEN_DEVICE_CONFIG_DATA64,
204   MCONFIG_TOKEN_DEVICE_CONFIG_DATAFP32,
205   MCONFIG_TOKEN_DEVICE_CONFIG_CUSTOM_FREE,
206};
207
208
209// ----- flags for video_attributes -----
210
211// should VIDEO_UPDATE by called at the start of VBLANK or at the end?
212#define   VIDEO_UPDATE_BEFORE_VBLANK      0x0000
213#define   VIDEO_UPDATE_AFTER_VBLANK      0x0004
214
215// indicates VIDEO_UPDATE will add container bits its
216#define VIDEO_SELF_RENDER            0x0008
217
218// automatically extend the palette creating a darker copy for shadows
219#define VIDEO_HAS_SHADOWS            0x0010
220
221// automatically extend the palette creating a brighter copy for highlights
222#define VIDEO_HAS_HIGHLIGHTS         0x0020
223
224// Mish 181099:  See comments in video/generic.c for details
225#define VIDEO_BUFFERS_SPRITERAM         0x0040
226
227// force VIDEO_UPDATE to be called even for skipped frames
228#define VIDEO_ALWAYS_UPDATE            0x0080
229
230// calls VIDEO_UPDATE for every visible scanline, even for skipped frames
231#define VIDEO_UPDATE_SCANLINE         0x0100
232
233
234
235/***************************************************************************
236    TYPE DEFINITIONS
237***************************************************************************/
238
239// forward references
240struct gfx_decode_entry;
241
242
174// machine configuration definition
243175class machine_config
244176{
245177   DISABLE_COPYING(machine_config);
r8910r8911
247179   friend class running_machine;
248180
249181public:
250   machine_config(const machine_config_token *tokens);
182   machine_config(machine_config_constructor constructor);
251183   ~machine_config();
252184
253   void detokenize(const machine_config_token *tokens, const device_config *owner = NULL);
254
255185   driver_data_alloc_func   m_driver_data_alloc;      // allocator for driver data
256186
257187   attotime            m_minimum_quantum;         // minimum scheduling quantum
r8910r8911
281211
282212   device_config_list      m_devicelist;            // list of device configs
283213
214   // helpers during configuration; not for general use
215   device_config *device_add(device_config *owner, const char *tag, device_type type, UINT32 clock);
216   device_config *device_replace(device_config *owner, const char *tag, device_type type, UINT32 clock);
217   device_config *device_remove(device_config *owner, const char *tag);
218   device_config *device_find(device_config *owner, const char *tag);
219
284220private:
285221   int                  m_parse_level;            // nested parsing level
286222};
287223
288224
289225
290/***************************************************************************
291    MACROS FOR BUILDING MACHINE DRIVERS
292***************************************************************************/
226//**************************************************************************
227//  MACHINE CONFIG MACROS
228//**************************************************************************
293229
294// this type is used to encode machine configuration definitions
295union machine_config_token
296{
297   TOKEN_COMMON_FIELDS
298   const machine_config_token *tokenptr;
299   const gfx_decode_entry *gfxdecode;
300   address_map_constructor addrmap;
301   device_type devtype;
302   nvram_handler_func nvram_handler;
303   memcard_handler_func memcard_handler;
304   machine_start_func machine_start;
305   machine_reset_func machine_reset;
306   sound_start_func sound_start;
307   sound_reset_func sound_reset;
308   video_start_func video_start;
309   video_reset_func video_reset;
310   palette_init_func palette_init;
311   video_eof_func video_eof;
312   video_update_func video_update;
313   device_interrupt_func cpu_interrupt;
314   driver_data_alloc_func driver_data_alloc;
315};
316
317
318// helper macro for returning the size of a field within a struct; similar to offsetof()
319#define structsizeof(_struct, _field) sizeof(((_struct *)NULL)->_field)
320
321#define DEVCONFIG_OFFSETOF(_class, _member)   \
322   ((FPTR)&static_cast<_class *>(reinterpret_cast<device_config *>(1000000))->_member - 1000000)
323
324#define DEVCONFIG_SIZEOF(_class, _member)   \
325   sizeof(reinterpret_cast<_class *>(NULL)->_member)
326
327
328230// start/end tags for the machine driver
329#define MACHINE_DRIVER_NAME(_name) \
330   machine_config_##_name
231#define MACHINE_DRIVER_NAME(_name) construct_machine_config_##_name
331232
332233#define MACHINE_DRIVER_START(_name) \
333   const machine_config_token MACHINE_DRIVER_NAME(_name)[] = {
234void MACHINE_DRIVER_NAME(_name)(machine_config &config, device_config *owner) \
235{ \
236   device_config *device = NULL; \
237   const char *tag; \
238   astring tempstring; \
239   (void)device; \
240   (void)tag; \
334241
335242#define MACHINE_DRIVER_END \
336   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_END, 8) };
243}
337244
338245// use this to declare external references to a machine driver
339246#define MACHINE_DRIVER_EXTERN(_name) \
340   extern const machine_config_token MACHINE_DRIVER_NAME(_name)[]
247   extern void MACHINE_DRIVER_NAME(_name)(machine_config &config, device_config *owner)
341248
342249
343250// importing data from other machine drivers
344251#define MDRV_IMPORT_FROM(_name) \
345   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_INCLUDE, 8), \
346   TOKEN_PTR(tokenptr, MACHINE_DRIVER_NAME(_name)),
252   MACHINE_DRIVER_NAME(_name)(config, owner);
347253
348254
349255// core parameters
350256#define MDRV_DRIVER_DATA(_class) \
351   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DRIVER_DATA, 8), \
352   TOKEN_PTR(m_driver_data_alloc, _class::alloc),
257   config.m_driver_data_alloc = &_class::alloc; \
353258
354259#define MDRV_QUANTUM_TIME(_time) \
355   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_QUANTUM_TIME, 8), \
356   TOKEN_UINT64(UINT64_ATTOTIME_IN_##_time),
260   config.m_minimum_quantum = ATTOTIME_IN_##_time; \
357261
358262#define MDRV_QUANTUM_PERFECT_CPU(_cputag) \
359   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_QUANTUM_PERFECT_CPU, 8), \
360   TOKEN_STRING(_cputag),
263   config.m_perfect_cpu_quantum = _cputag; \
361264
362265#define MDRV_WATCHDOG_VBLANK_INIT(_count) \
363   TOKEN_UINT32_PACK2(MCONFIG_TOKEN_WATCHDOG_VBLANK, 8, _count, 24),
266   config.m_watchdog_vblank_count = _count; \
364267
365268#define MDRV_WATCHDOG_TIME_INIT(_time) \
366   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_WATCHDOG_TIME, 8), \
367   TOKEN_UINT64(UINT64_ATTOTIME_IN_##_time),
269   config.m_watchdog_time = ATTOTIME_IN_##_time; \
368270
369271
370272// core functions
371273#define MDRV_MACHINE_START(_func) \
372   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_MACHINE_START, 8), \
373   TOKEN_PTR(machine_start, MACHINE_START_NAME(_func)),
274   config.m_machine_start = MACHINE_START_NAME(_func); \
374275
375276#define MDRV_MACHINE_RESET(_func) \
376   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_MACHINE_RESET, 8), \
377   TOKEN_PTR(machine_reset, MACHINE_RESET_NAME(_func)),
277   config.m_machine_reset = MACHINE_RESET_NAME(_func); \
378278
379279#define MDRV_NVRAM_HANDLER(_func) \
380   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_NVRAM_HANDLER, 8), \
381   TOKEN_PTR(nvram_handler, NVRAM_HANDLER_NAME(_func)),
280   config.m_nvram_handler = NVRAM_HANDLER_NAME(_func); \
382281
383282#define MDRV_MEMCARD_HANDLER(_func) \
384   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_MEMCARD_HANDLER, 8), \
385   TOKEN_PTR(memcard_handler, MEMCARD_HANDLER_NAME(_func)),
283   config.m_memcard_handler = MEMCARD_HANDLER_NAME(_func); \
386284
387285
388286// core video parameters
389287#define MDRV_VIDEO_ATTRIBUTES(_flags) \
390   TOKEN_UINT32_PACK2(MCONFIG_TOKEN_VIDEO_ATTRIBUTES, 8, _flags, 24),
288   config.m_video_attributes = _flags; \
391289
392290#define MDRV_GFXDECODE(_gfx) \
393   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_GFXDECODE, 8), \
394   TOKEN_PTR(gfxdecode, GFXDECODE_NAME(_gfx)),
291   config.m_gfxdecodeinfo = GFXDECODE_NAME(_gfx); \
395292
396293#define MDRV_PALETTE_LENGTH(_length) \
397   TOKEN_UINT32_PACK2(MCONFIG_TOKEN_PALETTE_LENGTH, 8, _length, 24),
294   config.m_total_colors = _length; \
398295
399296#define MDRV_DEFAULT_LAYOUT(_layout) \
400   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DEFAULT_LAYOUT, 8), \
401   TOKEN_STRING(&(_layout)[0]),
297   config.m_default_layout = &(_layout)[0]; \
402298
403299
404300// core video functions
405301#define MDRV_PALETTE_INIT(_func) \
406   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_PALETTE_INIT, 8), \
407   TOKEN_PTR(palette_init, PALETTE_INIT_NAME(_func)),
302   config.m_init_palette = PALETTE_INIT_NAME(_func); \
408303
409304#define MDRV_VIDEO_START(_func) \
410   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_VIDEO_START, 8), \
411   TOKEN_PTR(video_start, VIDEO_START_NAME(_func)),
305   config.m_video_start = VIDEO_START_NAME(_func); \
412306
413307#define MDRV_VIDEO_RESET(_func) \
414   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_VIDEO_RESET, 8), \
415   TOKEN_PTR(video_reset, VIDEO_RESET_NAME(_func)),
308   config.m_video_reset = VIDEO_RESET_NAME(_func); \
416309
417310#define MDRV_VIDEO_EOF(_func) \
418   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_VIDEO_EOF, 8), \
419   TOKEN_PTR(video_eof, VIDEO_EOF_NAME(_func)),
311   config.m_video_eof = VIDEO_EOF_NAME(_func); \
420312
421313#define MDRV_VIDEO_UPDATE(_func) \
422   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_VIDEO_UPDATE, 8), \
423   TOKEN_PTR(video_update, VIDEO_UPDATE_NAME(_func)),
314   config.m_video_update = VIDEO_UPDATE_NAME(_func); \
424315
425316
426317// core sound functions
427318#define MDRV_SOUND_START(_func) \
428   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_SOUND_START, 8), \
429   TOKEN_PTR(sound_start, SOUND_START_NAME(_func)),
319   config.m_sound_start = SOUND_START_NAME(_func); \
430320
431321#define MDRV_SOUND_RESET(_func) \
432   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_SOUND_RESET, 8), \
433   TOKEN_PTR(sound_reset, SOUND_RESET_NAME(_func)),
322   config.m_sound_reset = SOUND_RESET_NAME(_func); \
434323
435324
436325// add/remove devices
437326#define MDRV_DEVICE_ADD(_tag, _type, _clock) \
438   TOKEN_UINT64_PACK2(MCONFIG_TOKEN_DEVICE_ADD, 8, _clock, 32), \
439   TOKEN_PTR(devtype, _type), \
440   TOKEN_STRING(_tag),
327   device = config.device_add(owner, _tag, _type, _clock); \
441328
442329#define MDRV_DEVICE_REPLACE(_tag, _type, _clock) \
443   TOKEN_UINT64_PACK2(MCONFIG_TOKEN_DEVICE_REPLACE, 8, _clock, 32), \
444   TOKEN_PTR(devtype, _type), \
445   TOKEN_STRING(_tag),
330   device = config.device_replace(owner, _tag, _type, _clock); \
446331
447332#define MDRV_DEVICE_REMOVE(_tag) \
448   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DEVICE_REMOVE, 8), \
449   TOKEN_STRING(_tag),
333   device = config.device_remove(owner, _tag); \
450334
451335#define MDRV_DEVICE_MODIFY(_tag)   \
452   TOKEN_UINT32_PACK1(MCONFIG_TOKEN_DEVICE_MODIFY, 8), \
453   TOKEN_STRING(_tag),
336   device = config.device_find(owner, _tag); \
454337
455338
456339#endif   /* __MCONFIG_H__ */
src/emu/dimemory.h
r8910r8911
8282//**************************************************************************
8383
8484#define MDRV_DEVICE_ADDRESS_MAP(_space, _map) \
85   TOKEN_UINT32_PACK2(MCONFIG_TOKEN_DIMEMORY_MAP, 8, _space, 8), \
86   TOKEN_PTR(addrmap, (address_map_constructor)ADDRESS_MAP_NAME(_map)),
85   device_config_memory_interface::static_set_addrmap(device, _space, ADDRESS_MAP_NAME(_map));
8786
8887#define MDRV_DEVICE_PROGRAM_MAP(_map) \
8988   MDRV_DEVICE_ADDRESS_MAP(AS_PROGRAM, _map)
r8910r8911
116115   address_map_constructor address_map(int spacenum = 0) const { return (spacenum < ARRAY_LENGTH(m_address_map)) ? m_address_map[spacenum] : NULL; }
117116   const address_space_config *space_config(int spacenum = 0) const { return memory_space_config(spacenum); }
118117
118   // static inline helpers
119   static void static_set_addrmap(device_config *device, int spacenum, address_map_constructor map);
120
119121protected:
120122   // required overrides
121123   virtual const address_space_config *memory_space_config(int spacenum) const = 0;
122124
123125   // optional operation overrides
124   virtual bool interface_process_token(UINT32 entrytype, const machine_config_token *&tokens);
125126   virtual bool interface_validity_check(const game_driver &driver) const;
126127
127128   address_map_constructor   m_address_map[ADDRESS_SPACES]; // address maps for each address space
src/mess/devices/coco_fdc.c
r8910r8911
102102   write8_device_func ff40_w;
103103   unsigned initial_drq : 1;
104104   device_type wdtype;
105   const machine_config_token *wdmachine;
105   machine_config_constructor wdmachine;
106106};
107107
108108
r8910r8911
477477    DEVICE_GET_INFO(coco_cartridge_pcb_fdc_coco) -
478478    get info function for the CoCo FDC
479479-------------------------------------------------*/
480static MACHINE_DRIVER_START(coco_fdc)
481   MDRV_WD1773_ADD(WD_TAG, coco_wd17xx_interface)
482   MDRV_MSM6242_ADD(DISTO_TAG)
483   MDRV_DS1315_ADD(CLOUD9_TAG)
484MACHINE_DRIVER_END
480485
481486DEVICE_GET_INFO(coco_cartridge_pcb_fdc_coco)
482487{
483   static MACHINE_DRIVER_START(coco_fdc)
484      MDRV_WD1773_ADD(WD_TAG, coco_wd17xx_interface)
485      MDRV_MSM6242_ADD(DISTO_TAG)
486      MDRV_DS1315_ADD(CLOUD9_TAG)
487   MACHINE_DRIVER_END
488
489488   static const fdc_hardware_type hwtype =
490489   {
491490      "CoCo FDC",
r8910r8911
629628    DEVICE_GET_INFO(coco_cartridge_pcb_fdc_dragon) -
630629    get info function for the CoCo FDC
631630-------------------------------------------------*/
632
631static MACHINE_DRIVER_START(dragon_fdc)
632   MDRV_WD179X_ADD(WD_TAG, coco_wd17xx_interface)
633MACHINE_DRIVER_END
634   
633635DEVICE_GET_INFO(coco_cartridge_pcb_fdc_dragon)
634636{
635   static MACHINE_DRIVER_START(dragon_fdc)
636      MDRV_WD179X_ADD(WD_TAG, coco_wd17xx_interface)
637   MACHINE_DRIVER_END
638
639637   static const fdc_hardware_type hwtype =
640638   {
641639      "Dragon FDC",
src/mess/devices/coco_232.c
r8910r8911
9494/*-------------------------------------------------
9595    DEVICE_GET_INFO(coco_cartridge_pcb_rs232)
9696-------------------------------------------------*/
97static MACHINE_DRIVER_START(coco_rs232)
98   MDRV_ACIA6551_ADD(UART_TAG)
99MACHINE_DRIVER_END
97100
98101DEVICE_GET_INFO(coco_cartridge_pcb_rs232)
99102{
100   static MACHINE_DRIVER_START(coco_rs232)
101      MDRV_ACIA6551_ADD(UART_TAG)
102   MACHINE_DRIVER_END
103
104103   switch(state)
105104   {
106105      /* --- the following bits of info are returned as 64-bit signed integers --- */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team