Previous 15994 Revisions Next

r11204 Saturday 16th April, 2011 at 16:52:14 UTC by Curt Coder
Refactored the AY-5-3600 into a C++ device. (no whatsnew)
[src/emu]devcb.c devcb.h
[src/mess/drivers]bw12.c
[src/mess/includes]bw12.h
[src/mess/machine]kb3600.c kb3600.h

src/emu/devcb.c
r11203r11204
361361      }
362362   }
363363}
364
365
366/*-------------------------------------------------
367    devcb_resolve_read16 - convert a static
368    16-bit read definition to a live definition
369-------------------------------------------------*/
370
371static READ16_DEVICE_HANDLER( trampoline_read_port_to_read16 )
372{
373   return input_port_read_direct((const input_port_config *)device);
374}
375
376static READ16_DEVICE_HANDLER( trampoline_read_line_to_read16 )
377{
378   const devcb_resolved_read16 *resolved = (const devcb_resolved_read16 *)device;
379   return (*resolved->real.readline)((device_t *)resolved->realtarget);
380}
381
382void devcb_resolve_read16(devcb_resolved_read16 *resolved, const devcb_read16 *config, device_t *device)
383{
384   /* reset the resolved structure */
385   memset(resolved, 0, sizeof(*resolved));
386
387   /* input port handlers */
388   if (config->type == DEVCB_TYPE_INPUT)
389   {
390      resolved->target = device->machine().port(config->tag);
391      if (resolved->target == NULL)
392         fatalerror("devcb_resolve_read16: unable to find input port '%s' (requested by %s '%s')", config->tag, device->name(), device->tag());
393      resolved->read = trampoline_read_port_to_read16;
394   }
395
396   /* address space handlers */
397   else if (config->type >= DEVCB_TYPE_MEMORY(AS_PROGRAM) && config->type < DEVCB_TYPE_MEMORY(ADDRESS_SPACES) && config->readspace != NULL)
398   {
399      FPTR spacenum = (FPTR)config->type - (FPTR)DEVCB_TYPE_MEMORY(AS_PROGRAM);
400
401      device_t *targetdev = device->siblingdevice(config->tag);
402      if (targetdev == NULL)
403         fatalerror("devcb_resolve_read16: unable to find device '%s' (requested by %s '%s')", config->tag, device->name(), device->tag());
404      device_memory_interface *memory;
405      if (!targetdev->interface(memory))
406         fatalerror("devcb_resolve_read16: device '%s' (requested by %s '%s') has no memory", config->tag, device->name(), device->tag());
407
408      resolved->target = targetdev->memory().space(spacenum);
409      if (resolved->target == NULL)
410         fatalerror("devcb_resolve_read16: unable to find device '%s' space %d (requested by %s '%s')", config->tag, (int)spacenum, device->name(), device->tag());
411      resolved->read = (read16_device_func)config->readspace;
412   }
413
414   /* device handlers */
415   else if ((config->type == DEVCB_TYPE_DEVICE || config->type == DEVCB_TYPE_SELF || config->type == DEVCB_TYPE_DRIVER) && (config->readline != NULL || config->readdevice != NULL))
416   {
417      if (config->type == DEVCB_TYPE_SELF)
418         resolved->target = device;
419      else if (config->type == DEVCB_TYPE_DRIVER)
420         resolved->target = device->machine().driver_data();
421      else
422         if (strcmp(config->tag, DEVICE_SELF_OWNER) == 0)
423            resolved->target = device->owner();
424         else
425            resolved->target = device->siblingdevice(config->tag);
426
427      if (resolved->target == NULL)
428         fatalerror("devcb_resolve_read16: unable to find device '%s' (requested by %s '%s')", config->tag, device->name(), device->tag());
429
430      /* read16 to read16 is direct */
431      if (config->readdevice != NULL)
432         resolved->read = config->readdevice;
433
434      /* read16 to read_line goes through a trampoline */
435      else
436      {
437         resolved->realtarget = resolved->target;
438         resolved->real.readline = config->readline;
439         resolved->target = resolved;
440         resolved->read = trampoline_read_line_to_read16;
441      }
442   }
443}
444
445
446/*-------------------------------------------------
447    devcb_resolve_write16 - convert a static
448    16-bit write definition to a live definition
449-------------------------------------------------*/
450
451static WRITE16_DEVICE_HANDLER( trampoline_write_port_to_write16 )
452{
453   input_port_write_direct((const input_port_config *)device, data, 0xff);
454}
455
456static WRITE16_DEVICE_HANDLER( trampoline_write_line_to_write16 )
457{
458   const devcb_resolved_write16 *resolved = (const devcb_resolved_write16 *)device;
459   (*resolved->real.writeline)((device_t *)resolved->realtarget, (data & 1) ? ASSERT_LINE : CLEAR_LINE);
460}
461
462void devcb_resolve_write16(devcb_resolved_write16 *resolved, const devcb_write16 *config, device_t *device)
463{
464   /* reset the resolved structure */
465   memset(resolved, 0, sizeof(*resolved));
466
467   if (config->type == DEVCB_TYPE_INPUT)
468   {
469      resolved->target = device->machine().port(config->tag);
470      if (resolved->target == NULL)
471         fatalerror("devcb_resolve_read_line: unable to find input port '%s' (requested by %s '%s')", config->tag, device->name(), device->tag());
472      resolved->write = trampoline_write_port_to_write16;
473   }
474
475   /* address space handlers */
476   else if (config->type >= DEVCB_TYPE_MEMORY(AS_PROGRAM) && config->type < DEVCB_TYPE_MEMORY(ADDRESS_SPACES) && config->writespace != NULL)
477   {
478      FPTR spacenum = (FPTR)config->type - (FPTR)DEVCB_TYPE_MEMORY(AS_PROGRAM);
479
480      device_t *targetdev = device->siblingdevice(config->tag);
481      if (targetdev == NULL)
482         fatalerror("devcb_resolve_write16: unable to find device '%s' (requested by %s '%s')", config->tag, device->name(), device->tag());
483      device_memory_interface *memory;
484      if (!targetdev->interface(memory))
485         fatalerror("devcb_resolve_write16: device '%s' (requested by %s '%s') has no memory", config->tag, device->name(), device->tag());
486
487      resolved->target = targetdev->memory().space(spacenum);
488      if (resolved->target == NULL)
489         fatalerror("devcb_resolve_write16: unable to find device '%s' space %d (requested by %s '%s')", config->tag, (int)spacenum, device->name(), device->tag());
490      resolved->write = (write16_device_func)config->writespace;
491   }
492
493   /* device handlers */
494   else if ((config->type == DEVCB_TYPE_DEVICE || config->type == DEVCB_TYPE_SELF || config->type == DEVCB_TYPE_DRIVER) && (config->writeline != NULL || config->writedevice != NULL))
495   {
496      if (config->type == DEVCB_TYPE_SELF)
497         resolved->target = device;
498      else if (config->type == DEVCB_TYPE_DRIVER)
499         resolved->target = device->machine().driver_data();
500      else
501         if (strcmp(config->tag, DEVICE_SELF_OWNER) == 0)
502            resolved->target = device->owner();
503         else
504            resolved->target = device->siblingdevice(config->tag);
505
506      if (resolved->target == NULL)
507         fatalerror("devcb_resolve_write16: unable to find device '%s' (requested by %s '%s')", config->tag, device->name(), device->tag());
508
509      /* write16 to write16 is direct */
510      if (config->writedevice != NULL)
511         resolved->write = config->writedevice;
512
513      /* write16 to write_line goes through a trampoline */
514      else
515      {
516         resolved->realtarget = resolved->target;
517         resolved->real.writeline = config->writeline;
518         resolved->target = resolved;
519         resolved->write = trampoline_write_line_to_write16;
520      }
521   }
522}
src/emu/devcb.h
r11203r11204
2020        write_line_device_func: (device, data)
2121        read8_device_func:      (device, offset)
2222        write8_device_func:     (device, offset, data)
23        read16_device_func:      (device, offset)
24        write16_device_func:     (device, offset, data)
2325
2426    The adapted callback types supported are:
2527
r11203r11204
3133        write8_device_func:     (device, offset, data)
3234        read8_space_func:       (space, offset)
3335        write8_space_func:      (space, offset, data)
36        read16_device_func:      (device, offset)
37        write16_device_func:     (device, offset, data)
38        read16_space_func:       (space, offset)
39        write16_space_func:      (space, offset, data)
3440
3541***************************************************************************/
3642
r11203r11204
7884   return (target->*_Function)(*memory_nonspecific_space(device->machine()), offset, 0xff);
7985}
8086
87// static template for a read16 stub function that calls through a given READ16_MEMBER
88template<class _Class, UINT16 (_Class::*_Function)(address_space &, offs_t, UINT16)>
89UINT16 devcb_stub(device_t *device, offs_t offset)
90{
91   _Class *target = downcast<_Class *>(device);
92   return (target->*_Function)(*memory_nonspecific_space(device->machine()), offset, 0xffff);
93}
94
8195// static template for a write_line stub function that calls through a given WRITE_LINE_MEMBER
8296template<class _Class, void (_Class::*_Function)(int state)>
8397void devcb_line_stub(device_t *device, int state)
r11203r11204
94108   (target->*_Function)(*memory_nonspecific_space(device->machine()), offset, data, 0xff);
95109}
96110
111// static template for a write16 stub function that calls through a given WRITE16_MEMBER
112template<class _Class, void (_Class::*_Function)(address_space &, offs_t, UINT16, UINT16)>
113void devcb_stub(device_t *device, offs_t offset, UINT16 data)
114{
115   _Class *target = downcast<_Class *>(device);
116   (target->*_Function)(*memory_nonspecific_space(device->machine()), offset, data, 0xffff);
117}
118
97119#define DEVCB_NULL                     { DEVCB_TYPE_NULL }
98120
99121/* standard line or read/write handlers with the calling device passed */
r11203r11204
261283};
262284
263285
286/* static structure used for device configuration when the desired callback type is a read16_device_func */
287typedef struct _devcb_read16 devcb_read16;
288struct _devcb_read16
289{
290   UINT32               type;         /* one of the special DEVCB_TYPE values */
291   const char *         tag;         /* tag of target, where appropriate */
292   read_line_device_func   readline;      /* read line function */
293   read16_device_func      readdevice;      /* read device function */
294   read16_space_func      readspace;      /* read space function */
295};
264296
297typedef struct _devcb_resolved_read16 devcb_resolved_read16;
298struct _devcb_resolved_read16
299{
300   const void *         target;         /* target object */
301   read16_device_func      read;         /* read function */
302   const void *         realtarget;      /* real target object for stubs */
303   union
304   {
305      read16_device_func   readdevice;
306      read16_space_func   readspace;
307      read_line_device_func readline;
308   } real;                           /* real read function for stubs */
309};
310
311
312/* static structure used for device configuration when the desired callback type is a write16_device_func */
313typedef struct _devcb_write16 devcb_write16;
314struct _devcb_write16
315{
316   UINT32               type;         /* one of the special DEVCB_TYPE values */
317   const char *         tag;         /* tag of target, where appropriate */
318   write_line_device_func   writeline;      /* write line function */
319   write16_device_func      writedevice;   /* write device function */
320   write16_space_func      writespace;      /* write space function */
321};
322
323typedef struct _devcb_resolved_write16 devcb_resolved_write16;
324struct _devcb_resolved_write16
325{
326   const void *         target;         /* target object */
327   write16_device_func      write;         /* write function */
328   const void *         realtarget;      /* real target object for stubs */
329   union
330   {
331      write16_device_func   writedevice;
332      write16_space_func   writespace;
333      write_line_device_func writeline;
334   } real;                           /* real write function for stubs */
335};
336
337
265338/***************************************************************************
266339    FUNCTION PROTOTYPES
267340***************************************************************************/
r11203r11204
281354/* convert a static 8-bit write definition to a live definition */
282355void devcb_resolve_write8(devcb_resolved_write8 *resolved, const devcb_write8 *config, device_t *device);
283356
357/* convert a static 16-bit read definition to a live definition */
358void devcb_resolve_read16(devcb_resolved_read16 *resolved, const devcb_read16 *config, device_t *device);
284359
360/* convert a static 16-bit write definition to a live definition */
361void devcb_resolve_write16(devcb_resolved_write16 *resolved, const devcb_write16 *config, device_t *device);
285362
363
364
286365/***************************************************************************
287366    INLINE FUNCTIONS
288367***************************************************************************/
r11203r11204
310389
311390
312391/*-------------------------------------------------
392    devcb_call_read16 - call through a
393    resolved read16 handler
394-------------------------------------------------*/
395
396INLINE int devcb_call_read16(const devcb_resolved_read16 *resolved, offs_t offset)
397{
398   return (resolved->read != NULL) ? (*resolved->read)((device_t *)resolved->target, offset, 0xffff) : 0;
399}
400
401
402/*-------------------------------------------------
313403    devcb_call_write_line - call through a
314404    resolved write_line handler
315405-------------------------------------------------*/
r11203r11204
332422      (*resolved->write)((device_t *)resolved->target, offset, data);
333423}
334424
425
335426/*-------------------------------------------------
427    devcb_call_write16 - call through a
428    resolved write16 handler
429-------------------------------------------------*/
430
431INLINE void devcb_call_write16(const devcb_resolved_write16 *resolved, offs_t offset, UINT16 data)
432{
433   if (resolved->write != NULL)
434      (*resolved->write)((device_t *)resolved->target, offset, data, 0xffff);
435}
436
437
438/*-------------------------------------------------
336439    devcb_line_gnd_r - input tied to GND
337440-------------------------------------------------*/
338441
r11203r11204
341444   return 0;
342445}
343446
447
344448/*-------------------------------------------------
345449    devcb_line_vcc_r - input tied to Vcc
346450-------------------------------------------------*/
src/mess/machine/kb3600.c
r11203r11204
55    Copyright MESS Team.
66    Visit http://mamedev.org for licensing and usage restrictions.
77
8**********************************************************************/
8*********************************************************************/
99
1010/*
1111
1212    TODO:
1313
14   - scan timer clock frequency
1415    - more accurate emulation of real chip
1516
1617*/
1718
18#include "emu.h"
1919#include "kb3600.h"
20#include "machine/devhelpr.h"
2021
21/***************************************************************************
22    TYPE DEFINITIONS
23***************************************************************************/
2422
25typedef struct _ay3600_t ay3600_t;
26struct _ay3600_t
27{
28   devcb_resolved_read_line   in_shift_func;
29   devcb_resolved_read_line   in_control_func;
3023
31   devcb_resolved_write_line   out_data_ready_func;
32   devcb_resolved_write_line   out_ako_func;
24//**************************************************************************
25//  MACROS / CONSTANTS
26//**************************************************************************
3327
34   int b;                  /* output buffer */
35   int ako;               /* any key down */
28#define LOG 0
3629
37   /* timers */
38   emu_timer *scan_timer;      /* keyboard scan timer */
39};
4030
41/***************************************************************************
42    INLINE FUNCTIONS
43***************************************************************************/
4431
45INLINE ay3600_t *get_safe_token(device_t *device)
32//**************************************************************************
33//  GLOBAL VARIABLES
34//**************************************************************************
35
36// devices
37const device_type AY3600 = ay3600_device_config::static_alloc_device_config;
38
39
40
41//**************************************************************************
42//  DEVICE CONFIGURATION
43//**************************************************************************
44
45GENERIC_DEVICE_CONFIG_SETUP(ay3600, "AY-5-3600")
46
47
48//-------------------------------------------------
49//  device_config_complete - perform any
50//  operations now that the configuration is
51//  complete
52//-------------------------------------------------
53
54void ay3600_device_config::device_config_complete()
4655{
47   assert(device != NULL);
48   assert(device->type() == AY3600PRO002);
56   // inherit a copy of the static data
57   const ay3600_interface *intf = reinterpret_cast<const ay3600_interface *>(static_config());
58   if (intf != NULL)
59      *static_cast<ay3600_interface *>(this) = *intf;
4960
50   return (ay3600_t *)downcast<legacy_device_base *>(device)->token();
61   // or initialize to defaults if none provided
62   else
63   {
64      memset(&m_in_shift_func, 0, sizeof(m_in_shift_func));
65      memset(&m_in_control_func, 0, sizeof(m_in_control_func));
66      memset(&m_out_data_ready_func, 0, sizeof(m_out_data_ready_func));
67      memset(&m_out_ako_func, 0, sizeof(m_out_ako_func));
68   }
5169}
5270
53INLINE const ay3600_interface *get_interface(device_t *device)
71
72
73//**************************************************************************
74//  LIVE DEVICE
75//**************************************************************************
76
77//-------------------------------------------------
78//  ay3600_device - constructor
79//-------------------------------------------------
80
81ay3600_device::ay3600_device(running_machine &_machine, const ay3600_device_config &config)
82    : device_t(_machine, config),
83      m_config(config)
5484{
55   assert(device != NULL);
56   assert((device->type() == AY3600PRO002));
57   return (const ay3600_interface *) device->baseconfig().static_config();
5885}
5986
60/***************************************************************************
61    IMPLEMENTATION
62***************************************************************************/
6387
64/*-------------------------------------------------
65    TIMER_CALLBACK( ay3600_scan_tick )
66-------------------------------------------------*/
88//-------------------------------------------------
89//  device_start - device-specific startup
90//-------------------------------------------------
6791
68static TIMER_CALLBACK( ay3600_scan_tick )
92void ay3600_device::device_start()
6993{
70   device_t *device = (device_t *)ptr;
71   ay3600_t *ay3600 = get_safe_token(device);
72   const ay3600_interface *intf = get_interface(device);
94   // resolve callbacks
95   devcb_resolve_read16(&m_in_x_func[0], &m_config.m_in_x0_func, this);
96   devcb_resolve_read16(&m_in_x_func[1], &m_config.m_in_x1_func, this);
97   devcb_resolve_read16(&m_in_x_func[2], &m_config.m_in_x2_func, this);
98   devcb_resolve_read16(&m_in_x_func[3], &m_config.m_in_x3_func, this);
99   devcb_resolve_read16(&m_in_x_func[4], &m_config.m_in_x4_func, this);
100   devcb_resolve_read16(&m_in_x_func[5], &m_config.m_in_x5_func, this);
101   devcb_resolve_read16(&m_in_x_func[6], &m_config.m_in_x6_func, this);
102   devcb_resolve_read16(&m_in_x_func[7], &m_config.m_in_x7_func, this);
103   devcb_resolve_read16(&m_in_x_func[8], &m_config.m_in_x8_func, this);
104   devcb_resolve_read_line(&m_in_shift_func, &m_config.m_in_shift_func, this);
105   devcb_resolve_read_line(&m_in_control_func, &m_config.m_in_control_func, this);
106   devcb_resolve_write_line(&m_out_data_ready_func, &m_config.m_out_data_ready_func, this);
107   devcb_resolve_write_line(&m_out_ako_func, &m_config.m_out_ako_func, this);
73108
74   int x, y;
109   // allocate timers
110   m_scan_timer = timer_alloc();
111   m_scan_timer->adjust(attotime::from_hz(60), 0, attotime::from_hz(60));
112
113   // state saving
114   save_item(NAME(m_b));
115   save_item(NAME(m_ako));
116}
117
118
119//-------------------------------------------------
120//  device_timer - handler timer events
121//-------------------------------------------------
122
123void ay3600_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
124{
75125   int ako = 0;
76126
77   for (x = 0; x < 9; x++)
127   for (int x = 0; x < 9; x++)
78128   {
79      UINT16 data = intf->in_y_func(device, x);
129      UINT16 data = devcb_call_read16(&m_in_x_func[x], 0);
80130
81      for (y = 0; y < 10; y++)
131      for (int y = 0; y < 10; y++)
82132      {
83133         if (BIT(data, y))
84134         {
r11203r11204
92142               b = 0x100 | b;
93143            }
94144
95            b |= (devcb_call_read_line(&ay3600->in_shift_func) << 6);
96            b |= (devcb_call_read_line(&ay3600->in_control_func) << 7);
145            b |= (devcb_call_read_line(&m_in_shift_func) << 6);
146            b |= (devcb_call_read_line(&m_in_control_func) << 7);
97147
98            if (ay3600->b != b)
148            if (m_b != b)
99149            {
100               ay3600->b = b;
150               m_b = b;
101151
102               devcb_call_write_line(&ay3600->out_data_ready_func, 1);
152               devcb_call_write_line(&m_out_data_ready_func, 1);
103153               return;
104154            }
105155         }
r11203r11204
108158
109159   if (!ako)
110160   {
111      ay3600->b = -1;
161      m_b = -1;
112162   }
113163
114   if (ako != ay3600->ako)
164   if (ako != m_ako)
115165   {
116      devcb_call_write_line(&ay3600->out_ako_func, ako);
117      ay3600->ako = ako;
166      devcb_call_write_line(&m_out_ako_func, ako);
167      m_ako = ako;
118168   }
119169}
120170
121/*-------------------------------------------------
122    ay3600_b_r - keyboard data read
123-------------------------------------------------*/
124171
125UINT16 ay3600_b_r(device_t *device)
172//-------------------------------------------------
173//  b_r -
174//-------------------------------------------------
175
176UINT16 ay3600_device::b_r()
126177{
127   ay3600_t *ay3600 = get_safe_token(device);
178   UINT16 data = m_b;
128179
129   UINT16 data = ay3600->b;
180   devcb_call_write_line(&m_out_data_ready_func, 0);
130181
131   devcb_call_write_line(&ay3600->out_data_ready_func, 0);
132
133182   return data;
134183}
135
136/*-------------------------------------------------
137    DEVICE_START( ay3600 )
138-------------------------------------------------*/
139
140static DEVICE_START( ay3600 )
141{
142   ay3600_t *ay3600 = get_safe_token(device);
143   const ay3600_interface *intf = get_interface(device);
144
145   /* resolve callbacks */
146   devcb_resolve_read_line(&ay3600->in_shift_func, &intf->in_shift_func, device);
147   devcb_resolve_read_line(&ay3600->in_control_func, &intf->in_control_func, device);
148   devcb_resolve_write_line(&ay3600->out_data_ready_func, &intf->out_data_ready_func, device);
149   devcb_resolve_write_line(&ay3600->out_ako_func, &intf->out_ako_func, device);
150
151   /* create the timers */
152   ay3600->scan_timer = device->machine().scheduler().timer_alloc(FUNC(ay3600_scan_tick), (void *)device);
153   ay3600->scan_timer->adjust(attotime::zero, 0, attotime::from_hz(60));
154
155   /* register for state saving */
156   device->save_item(NAME(ay3600->b));
157   device->save_item(NAME(ay3600->ako));
158}
159
160/*-------------------------------------------------
161    DEVICE_GET_INFO( ay3600pro002 )
162-------------------------------------------------*/
163
164DEVICE_GET_INFO( ay3600pro002 )
165{
166   switch (state)
167   {
168      /* --- the following bits of info are returned as 64-bit signed integers --- */
169      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(ay3600_t);               break;
170      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
171
172      /* --- the following bits of info are returned as pointers to data or functions --- */
173      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(ay3600);   break;
174      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
175      case DEVINFO_FCT_RESET:                     /* Nothing */                        break;
176
177      /* --- the following bits of info are returned as NULL-terminated strings --- */
178      case DEVINFO_STR_NAME:                     strcpy(info->s, "GI AY-5-3600-PRO-002");   break;
179      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "GI AY-5-3600");         break;
180      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                  break;
181      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);               break;
182      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright MESS Team");      break;
183   }
184}
185
186DEFINE_LEGACY_DEVICE(AY3600PRO002, ay3600pro002);
src/mess/machine/kb3600.h
r11203r11204
5252
5353**********************************************************************/
5454
55#pragma once
56
5557#ifndef __AY3600__
5658#define __AY3600__
5759
58#include "devcb.h"
60#include "emu.h"
5961
60/***************************************************************************
61    MACROS / CONSTANTS
62***************************************************************************/
6362
64DECLARE_LEGACY_DEVICE(AY3600PRO002, ay3600pro002);
6563
66#define MCFG_AY3600PRO002_ADD(_tag, _intf) \
67   MCFG_DEVICE_ADD(_tag, AY3600PRO002, 0) \
68   MCFG_DEVICE_CONFIG(_intf)
64//**************************************************************************
65//  INTERFACE CONFIGURATION MACROS
66//**************************************************************************
6967
68#define MCFG_AY3600_ADD(_tag, _clock, _config) \
69   MCFG_DEVICE_ADD(_tag, AY3600, _clock)   \
70   MCFG_DEVICE_CONFIG(_config)
71
72
7073#define AY3600_INTERFACE(name) \
7174   const ay3600_interface (name) =
7275
73typedef UINT16 (*ay3600_y_r)(device_t *device, int x);
74#define AY3600_Y_READ(name) UINT16 name(device_t *device, int x)
7576
76/***************************************************************************
77    TYPE DEFINITIONS
78***************************************************************************/
7977
80typedef struct _ay3600_interface ay3600_interface;
81struct _ay3600_interface
78//**************************************************************************
79//  TYPE DEFINITIONS
80//**************************************************************************
81
82// ======================> ay3600_interface
83
84struct ay3600_interface
8285{
83   ay3600_y_r         in_y_func;
86   devcb_read16      m_in_x0_func;
87   devcb_read16      m_in_x1_func;
88   devcb_read16      m_in_x2_func;
89   devcb_read16      m_in_x3_func;
90   devcb_read16      m_in_x4_func;
91   devcb_read16      m_in_x5_func;
92   devcb_read16      m_in_x6_func;
93   devcb_read16      m_in_x7_func;
94   devcb_read16      m_in_x8_func;
8495
85   devcb_read_line      in_shift_func;
86   devcb_read_line      in_control_func;
96   devcb_read_line      m_in_shift_func;
97   devcb_read_line      m_in_control_func;
8798
88   /* this gets called for every change of the DATA READY pin */
89   devcb_write_line   out_data_ready_func;
99   devcb_write_line   m_out_data_ready_func;
100   devcb_write_line   m_out_ako_func;
101};
90102
91   /* this gets called for every change of the AKO pin */
92   devcb_write_line   out_ako_func;
103
104// ======================> ay3600_device_config
105
106class ay3600_device_config :   public device_config,
107                               public ay3600_interface
108{
109    friend class ay3600_device;
110
111    // construction/destruction
112    ay3600_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
113
114public:
115    // allocators
116    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
117    virtual device_t *alloc_device(running_machine &machine) const;
118
119protected:
120   // device_config overrides
121   virtual void device_config_complete();
93122};
94123
95/***************************************************************************
96    PROTOTYPES
97***************************************************************************/
98/* data read */
99UINT16 ay3600_b_r(device_t *device);
100124
125// ======================> ay3600_device
126
127class ay3600_device :   public device_t
128{
129    friend class ay3600_device_config;
130
131    // construction/destruction
132    ay3600_device(running_machine &_machine, const ay3600_device_config &_config);
133
134public:
135   UINT16 b_r();
136
137protected:
138    // device-level overrides
139    virtual void device_start();
140   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
141
142private:
143   devcb_resolved_read16      m_in_x_func[9];
144
145   devcb_resolved_read_line   m_in_shift_func;
146   devcb_resolved_read_line   m_in_control_func;
147
148   devcb_resolved_write_line   m_out_data_ready_func;
149   devcb_resolved_write_line   m_out_ako_func;
150
151   int m_b;               // output buffer
152   int m_ako;               // any key down
153
154   // timers
155   emu_timer *m_scan_timer;   // keyboard scan timer
156
157   const ay3600_device_config &m_config;
158};
159
160
161// device type definition
162extern const device_type AY3600;
163
164
165
101166#endif
src/mess/includes/bw12.h
r11203r11204
1111#define PIT8253_TAG         "ic34"
1212#define PIA6821_TAG         "ic16"
1313#define MC1408_TAG         "ic4"
14#define AY3600_TAG         "ic74"
14#define AY3600PRO002_TAG   "ic74"
1515#define CENTRONICS_TAG      "centronics"
1616#define FLOPPY_TIMER_TAG   "motor_off"
1717
r11203r11204
2626        m_maincpu(*this, Z80_TAG),
2727        m_pia(*this, PIA6821_TAG),
2828        m_fdc(*this, UPD765_TAG),
29        m_kbc(*this, AY3600_TAG),
29        m_kbc(*this, AY3600PRO002_TAG),
3030        m_crtc(*this, MC6845_TAG),
3131        m_centronics(*this, CENTRONICS_TAG),
3232        m_ram(*this, RAM_TAG),
r11203r11204
3838   required_device<cpu_device> m_maincpu;
3939   required_device<device_t> m_pia;
4040   required_device<device_t> m_fdc;
41   required_device<device_t> m_kbc;
41   required_device<ay3600_device> m_kbc;
4242   required_device<device_t> m_crtc;
4343   required_device<device_t> m_centronics;
4444   required_device<device_t> m_ram;
r11203r11204
6464   DECLARE_READ_LINE_MEMBER( pia_cb1_r );
6565   DECLARE_WRITE_LINE_MEMBER( pia_cb2_w );
6666   DECLARE_WRITE_LINE_MEMBER( pit_out2_w );
67   DECLARE_READ_LINE_MEMBER( ay3600_shift_r );
68   DECLARE_READ_LINE_MEMBER( ay3600_control_r );
6769   DECLARE_WRITE_LINE_MEMBER( ay3600_data_ready_w );
6870
6971   /* memory state */
src/mess/drivers/bw12.c
r11203r11204
585585
586586/* AY-5-3600-PRO-002 Interface */
587587
588static AY3600_Y_READ( bw2_ay3600_y_r )
588READ_LINE_MEMBER( bw12_state::ay3600_shift_r )
589589{
590   UINT16 data = 0;
591
592   switch (x)
593   {
594   case 0: data = input_port_read(device->machine(), "X0"); break;
595   case 1: data = input_port_read(device->machine(), "X1"); break;
596   case 2: data = input_port_read(device->machine(), "X2"); break;
597   case 3: data = input_port_read(device->machine(), "X3"); break;
598   case 4: data = input_port_read(device->machine(), "X4"); break;
599   case 5: data = input_port_read(device->machine(), "X5"); break;
600   case 6: data = input_port_read(device->machine(), "X6"); break;
601   case 7: data = input_port_read(device->machine(), "X7"); break;
602   case 8: data = input_port_read(device->machine(), "X8"); break;
603   }
604
605   return data;
590   return BIT(input_port_read(m_machine, "MODIFIERS"), 0);
606591}
607592
608static READ_LINE_DEVICE_HANDLER( ay3600_shift_r )
593READ_LINE_MEMBER( bw12_state::ay3600_control_r )
609594{
610   return BIT(input_port_read(device->machine(), "MODIFIERS"), 0);
595   return BIT(input_port_read(m_machine, "MODIFIERS"), 1);
611596}
612597
613static READ_LINE_DEVICE_HANDLER( ay3600_control_r )
614{
615   return BIT(input_port_read(device->machine(), "MODIFIERS"), 1);
616}
617
618598WRITE_LINE_MEMBER( bw12_state::ay3600_data_ready_w )
619599{
620600   m_key_stb = state;
r11203r11204
623603
624604   if (state)
625605   {
626      UINT16 data = ay3600_b_r(m_kbc);
606      UINT16 data = m_kbc->b_r();
627607
628608      m_key_data[0] = BIT(data, 6);
629609      m_key_data[1] = BIT(data, 3);
r11203r11204
642622
643623static AY3600_INTERFACE( bw12_ay3600_intf )
644624{
645   bw2_ay3600_y_r,                     /* Y input */
646   DEVCB_LINE(ay3600_shift_r),         /* shift */
647   DEVCB_LINE(ay3600_control_r),      /* control */
648   DEVCB_DRIVER_LINE_MEMBER(bw12_state, ay3600_data_ready_w),   /* data ready */
649   DEVCB_NULL                        /* any key down */
625   DEVCB_INPUT_PORT("X0"),
626   DEVCB_INPUT_PORT("X1"),
627   DEVCB_INPUT_PORT("X2"),
628   DEVCB_INPUT_PORT("X3"),
629   DEVCB_INPUT_PORT("X4"),
630   DEVCB_INPUT_PORT("X5"),
631   DEVCB_INPUT_PORT("X6"),
632   DEVCB_INPUT_PORT("X7"),
633   DEVCB_INPUT_PORT("X8"),
634   DEVCB_DRIVER_LINE_MEMBER(bw12_state, ay3600_shift_r),
635   DEVCB_DRIVER_LINE_MEMBER(bw12_state, ay3600_control_r),
636   DEVCB_DRIVER_LINE_MEMBER(bw12_state, ay3600_data_ready_w),
637   DEVCB_NULL
650638};
651639
652640/* Machine Initialization */
r11203r11204
812800   MCFG_PIA6821_ADD(PIA6821_TAG, pia_intf)
813801   MCFG_Z80SIO0_ADD(Z80SIO_TAG, XTAL_16MHz/4, sio_intf)
814802   MCFG_PIT8253_ADD(PIT8253_TAG, pit_intf)
815   MCFG_AY3600PRO002_ADD(AY3600_TAG, bw12_ay3600_intf)
803   MCFG_AY3600_ADD(AY3600PRO002_TAG, 0, bw12_ay3600_intf)
816804
817805   /* printer */
818806   MCFG_CENTRONICS_ADD(CENTRONICS_TAG, bw12_centronics_intf)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team