Previous 15994 Revisions Next

r15386 Saturday 2nd June, 2012 at 20:49:08 UTC by Sandro Ronco
Converted TMS5501 into a C++ device. (nw)
[src/mess/drivers]dai.c
[src/mess/includes]dai.h
[src/mess/machine]dai.c tms5501.c tms5501.h

src/mess/machine/dai.c
r15385r15386
2424
2525WRITE8_MEMBER(dai_state::dai_stack_interrupt_circuit_w)
2626{
27   tms5501_sensor (m_tms5501, 1);
28   tms5501_sensor (m_tms5501, 0);
27   m_tms5501->set_sensor(1);
28   m_tms5501->set_sensor(0);
2929}
3030
3131static void dai_update_memory(running_machine &machine, int dai_rom_bank)
r15385r15386
4040}
4141
4242
43static UINT8 dai_keyboard_read (device_t *device)
43READ8_MEMBER(dai_state::dai_keyboard_r)
4444{
45   dai_state *state = device->machine().driver_data<dai_state>();
4645   UINT8 data = 0x00;
47   int i;
4846   static const char *const keynames[] = { "IN0", "IN1", "IN2", "IN3", "IN4", "IN5", "IN6", "IN7" };
4947
50   for (i = 0; i < 8; i++)
48   for (int i = 0; i < 8; i++)
5149   {
52      if (state->m_keyboard_scan_mask & (1 << i))
53         data |= device->machine().root_device().ioport(keynames[i])->read();
50      if (m_keyboard_scan_mask & (1 << i))
51         data |= ioport(keynames[i])->read();
5452   }
53
5554   return data;
5655}
5756
58static void dai_keyboard_write (device_t *device, UINT8 data)
57WRITE8_MEMBER(dai_state::dai_keyboard_w)
5958{
60   dai_state *state = device->machine().driver_data<dai_state>();
61   state->m_keyboard_scan_mask = data;
59   m_keyboard_scan_mask = data;
6260}
6361
64static void dai_interrupt_callback(device_t *device, int intreq, UINT8 vector)
62static TMS5501_IRQ_CALLBACK(dai_interrupt_callback)
6563{
6664   if (intreq)
67      cputag_set_input_line_and_vector(device->machine(), "maincpu", 0, HOLD_LINE, vector);
65      cputag_set_input_line_and_vector(device.machine(), "maincpu", 0, HOLD_LINE, vector);
6866   else
69      cputag_set_input_line(device->machine(), "maincpu", 0, CLEAR_LINE);
67      cputag_set_input_line(device.machine(), "maincpu", 0, CLEAR_LINE);
7068}
7169
72const tms5501_interface dai_tms5501_interface =
70TMS5501_INTERFACE( dai_tms5501_interface )
7371{
74   dai_keyboard_read,
75   dai_keyboard_write,
76   dai_interrupt_callback,
77   2000000.
72   DEVCB_DRIVER_MEMBER(dai_state, dai_keyboard_r),
73   DEVCB_DRIVER_MEMBER(dai_state, dai_keyboard_w),
74   dai_interrupt_callback
7875};
7976
8077I8255A_INTERFACE( dai_ppi82555_intf )
r15385r15386
111108static TIMER_CALLBACK( dai_timer )
112109{
113110   dai_state *state = machine.driver_data<dai_state>();
114   tms5501_set_pio_bit_7 (state->m_tms5501, (machine.root_device().ioport("IN8")->read() & 0x04) ? 1:0);
111   state->m_tms5501->set_pio_bit_7((state->ioport("IN8")->read() & 0x04) ? 1:0);
115112}
116113
117114MACHINE_START( dai )
src/mess/machine/tms5501.c
r15385r15386
2929
3030#define DEBUG_TMS5501   0
3131
32#define LOG_TMS5501(device, message, data) do { if (DEBUG_TMS5501) logerror ("\nTMS5501 %s: %s %02x", device->tag(), message, data); } while (0)
32#define LOG_TMS5501(message, data) do { if (DEBUG_TMS5501) logerror ("\nTMS5501 %s: %s %02x", tag(), message, data); } while (0)
3333
3434/* status register */
3535#define TMS5501_FRAME_ERROR      0x01
r15385r15386
6363
6464#define TMS5501_PIO_INT_7      0x80
6565
66// device type definition
67const device_type TMS5501 = &device_creator<tms5501_device>;
6668
67/***************************************************************************
68    TYPE DEFINITIONS
69***************************************************************************/
7069
71typedef struct _tms5501_t tms5501_t;
72struct _tms5501_t
73{
74   /* internal registers */
75   UINT8 status;         /* status register */
76   UINT8 command;         /* command register, bits 1-5 are latched */
70static const UINT8 timer_name[] = { TMS5501_TIMER_0_INT, TMS5501_TIMER_1_INT, TMS5501_TIMER_2_INT, TMS5501_TIMER_3_INT, TMS5501_TIMER_4_INT };
7771
78   UINT8 sio_rate;         /* SIO configuration register */
79   UINT8 sio_input_buffer;      /* SIO input buffer */
80   UINT8 sio_output_buffer;   /* SIO output buffer */
81
82   UINT8 pio_input_buffer;      /* PIO input buffer */
83   UINT8 pio_output_buffer;   /* PIO output buffer */
84
85   UINT8 interrupt_mask;      /* interrupt mask register */
86   UINT8 pending_interrupts;   /* pending interrupts register */
87   UINT8 interrupt_address;   /* interrupt vector register */
88
89   UINT8 sensor;         /* sensor input */
90
91   /* internal timers */
92   UINT8 timer_counter[5];
93   emu_timer * timer[5];
94};
95
96
97
9872/***************************************************************************
99    INLINE FUNCTIONS
73    IMPLEMENTATION
10074***************************************************************************/
10175
102INLINE tms5501_t *get_token(device_t *device)
76//-------------------------------------------------
77//  tms5501_device - constructor
78//-------------------------------------------------
79
80tms5501_device::tms5501_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
81   : device_t(mconfig, TMS5501, "TMS5501", tag, owner, clock)
10382{
104   assert(device != NULL);
105   assert(device->type() == TMS5501);
106   return (tms5501_t *) downcast<legacy_device_base *>(device)->token();
10783}
10884
10985
110INLINE const tms5501_interface *get_interface(device_t *device)
86//-------------------------------------------------
87//  device_config_complete - perform any
88//  operations now that the configuration is
89//  complete
90//-------------------------------------------------
91
92void tms5501_device::device_config_complete()
11193{
112   assert(device != NULL);
113   assert(device->type() == TMS5501);
114   return (const tms5501_interface *) device->static_config();
94   // inherit a copy of the static data
95   const tms5501_interface *intf = reinterpret_cast<const tms5501_interface *>(static_config());
96   if (intf != NULL)
97   {
98      *static_cast<tms5501_interface *>(this) = *intf;
99   }
100   // or initialize to defaults if none provided
101   else
102   {
103      m_interrupt_cb = NULL;
104      memset(&m_pio_read_cb, 0, sizeof(m_pio_read_cb));
105      memset(&m_pio_write_cb, 0, sizeof(m_pio_write_cb));
106   }
115107}
116108
117static const UINT8 timer_name[] = { TMS5501_TIMER_0_INT, TMS5501_TIMER_1_INT, TMS5501_TIMER_2_INT, TMS5501_TIMER_3_INT, TMS5501_TIMER_4_INT };
118
119/***************************************************************************
120    IMPLEMENTATION
121***************************************************************************/
122
123109/*-------------------------------------------------
124110    find_first_bit
125111-------------------------------------------------*/
126112
127static int find_first_bit(int value)
113int tms5501_device::find_first_bit(int value)
128114{
129115   int bit = 0;
130116
r15385r15386
140126}
141127
142128
143
144129/*-------------------------------------------------
145    tms5501_field_interrupts
130    tms5501_device::field_interrupts()
146131-------------------------------------------------*/
147132
148static void tms5501_field_interrupts(device_t *device)
133void tms5501_device::field_interrupts()
149134{
150135   static const UINT8 int_vectors[] = { 0xc7, 0xcf, 0xd7, 0xdf, 0xe7, 0xef, 0xf7, 0xff };
136   UINT8 current_ints = m_pending_interrupts;
151137
152   tms5501_t *tms = get_token(device);
153   const tms5501_interface *intf = get_interface(device);
154   UINT8 current_ints = tms->pending_interrupts;
155
156138   /* disabling masked interrupts */
157   current_ints &= tms->interrupt_mask;
139   current_ints &= m_interrupt_mask;
158140
159   LOG_TMS5501(device, "Pending interrupts", tms->pending_interrupts);
160   LOG_TMS5501(device, "Interrupt mask", tms->interrupt_mask);
161   LOG_TMS5501(device, "Current interrupts", current_ints);
141   LOG_TMS5501("Pending interrupts", m_pending_interrupts);
142   LOG_TMS5501("Interrupt mask", m_interrupt_mask);
143   LOG_TMS5501("Current interrupts", current_ints);
162144
163145   if (current_ints)
164146   {
165147      /* selecting interrupt with highest priority */
166148      int level = find_first_bit(current_ints);
167      LOG_TMS5501(device, "Interrupt level", level);
149      LOG_TMS5501("Interrupt level", level);
168150
169151      /* resetting proper bit in pending interrupts register */
170      tms->pending_interrupts &= ~(1<<level);
152      m_pending_interrupts &= ~(1<<level);
171153
172154      /* selecting  interrupt vector */
173      tms->interrupt_address = int_vectors[level];
174      LOG_TMS5501(device, "Interrupt vector", int_vectors[level]);
155      m_interrupt_address = int_vectors[level];
156      LOG_TMS5501("Interrupt vector", int_vectors[level]);
175157
176      if ((tms->command & TMS5501_INT_ACK_ENABLE))
158      if ((m_command & TMS5501_INT_ACK_ENABLE))
177159      {
178         if (intf->interrupt_callback)
179            (*intf->interrupt_callback)(device, 1, int_vectors[level]);
160         if (m_interrupt_cb)
161            (m_interrupt_cb)(*this, 1, int_vectors[level]);
180162      }
181163      else
182         tms->status |= TMS5501_INTERRUPT_PENDING;
164         m_status |= TMS5501_INTERRUPT_PENDING;
183165   }
184166   else
185167   {
186      if ((tms->command & TMS5501_INT_ACK_ENABLE))
168      if ((m_command & TMS5501_INT_ACK_ENABLE))
187169      {
188         if (intf->interrupt_callback)
189            (*intf->interrupt_callback)(device, 0, 0);
170         if (m_interrupt_cb)
171            (m_interrupt_cb)(*this, 0, 0);
190172      }
191173      else
192         tms->status &= ~TMS5501_INTERRUPT_PENDING;
174         m_status &= ~TMS5501_INTERRUPT_PENDING;
193175   }
194176}
195177
196178
197179/*-------------------------------------------------
198    tms5501_timer_decrementer
180    tms5501_device::timer_decrementer
199181-------------------------------------------------*/
200182
201static void tms5501_timer_decrementer(device_t *device, UINT8 mask)
183void tms5501_device::timer_decrementer(UINT8 mask)
202184{
203   tms5501_t *tms = get_token(device);
185   if ((mask != TMS5501_TIMER_4_INT) || ((mask == TMS5501_TIMER_4_INT) && (!(m_command & TMS5501_INT_7_SELECT))))
186      m_pending_interrupts |= mask;
204187
205   if ((mask != TMS5501_TIMER_4_INT) || ((mask == TMS5501_TIMER_4_INT) && (!(tms->command & TMS5501_INT_7_SELECT))))
206      tms->pending_interrupts |= mask;
207
208   tms5501_field_interrupts(device);
188   field_interrupts();
209189}
210190
211191
212192/*-------------------------------------------------
213    TIMER_CALLBACK(tms5501_timer_decrementer_callback)
193    tms5501_device::timer_reload
214194-------------------------------------------------*/
215195
216static TIMER_CALLBACK(tms5501_timer_decrementer_callback)
196void tms5501_device::timer_reload(int timer)
217197{
218   device_t *device = (device_t *) ptr;
219   UINT8 mask = param;
220
221   tms5501_timer_decrementer(device, mask);
222}
223
224
225/*-------------------------------------------------
226    tms5501_timer_reload
227-------------------------------------------------*/
228
229static void tms5501_timer_reload(device_t *device, int timer)
230{
231   tms5501_t *tms = get_token(device);
232   const tms5501_interface *intf = get_interface(device);
233
234   if (tms->timer_counter[timer])
198   if (m_timer_counter[timer])
235199   {   /* reset clock interval */
236      tms->timer[timer]->adjust(attotime::from_double((double) tms->timer_counter[timer] / (intf->clock_rate / 128.)), timer_name[timer], attotime::from_double((double) tms->timer_counter[timer] / (intf->clock_rate / 128.)));
200      m_timer[timer]->adjust(attotime::from_double((double) m_timer_counter[timer] / (clock() / 128.)), timer_name[timer], attotime::from_double((double) m_timer_counter[timer] / (clock() / 128.)));
237201   }
238202   else
239203   {   /* clock interval == 0 -> no timer */
240204      switch (timer)
241205      {
242         case 0: tms5501_timer_decrementer(device, TMS5501_TIMER_0_INT); break;
243         case 1: tms5501_timer_decrementer(device, TMS5501_TIMER_1_INT); break;
244         case 2: tms5501_timer_decrementer(device, TMS5501_TIMER_2_INT); break;
245         case 3: tms5501_timer_decrementer(device, TMS5501_TIMER_3_INT); break;
246         case 4: tms5501_timer_decrementer(device, TMS5501_TIMER_4_INT); break;
206         case 0: timer_decrementer(TMS5501_TIMER_0_INT); break;
207         case 1: timer_decrementer(TMS5501_TIMER_1_INT); break;
208         case 2: timer_decrementer(TMS5501_TIMER_2_INT); break;
209         case 3: timer_decrementer(TMS5501_TIMER_3_INT); break;
210         case 4: timer_decrementer(TMS5501_TIMER_4_INT); break;
247211      }
248      tms->timer[timer]->enable(0);
212      m_timer[timer]->enable(0);
249213   }
250214}
251215
r15385r15386
254218    DEVICE_RESET( tms5501 )
255219-------------------------------------------------*/
256220
257static DEVICE_RESET( tms5501 )
221void tms5501_device::device_reset()
258222{
259   tms5501_t *tms = get_token(device);
260   int i;
223   m_status &= ~(TMS5501_RCV_BUFFER_LOADED|TMS5501_FULL_BIT_DETECT|TMS5501_START_BIT_DETECT|TMS5501_OVERRUN_ERROR);
224   m_status |= TMS5501_XMIT_BUFFER_EMPTY|TMS5501_SERIAL_RCVD;
261225
262   tms->status &= ~(TMS5501_RCV_BUFFER_LOADED|TMS5501_FULL_BIT_DETECT|TMS5501_START_BIT_DETECT|TMS5501_OVERRUN_ERROR);
263   tms->status |= TMS5501_XMIT_BUFFER_EMPTY|TMS5501_SERIAL_RCVD;
226   m_pending_interrupts = TMS5501_SERIAL_XMIT_EMPTY_INT;
264227
265   tms->pending_interrupts = TMS5501_SERIAL_XMIT_EMPTY_INT;
266
267   for (i=0; i<5; i++)
228   for (int i=0; i<5; i++)
268229   {
269      tms->timer_counter[i] = 0;
270      tms->timer[i]->enable(0);
230      m_timer_counter[i] = 0;
231      m_timer[i]->enable(0);
271232   }
272233
273   LOG_TMS5501(device, "Reset", 0);
234   LOG_TMS5501("Reset", 0);
274235}
275236
276237
r15385r15386
278239    DEVICE_START( tms5501 )
279240-------------------------------------------------*/
280241
281static DEVICE_START( tms5501 )
242void tms5501_device::device_start()
282243{
283   int i;
284   tms5501_t *tms = get_token(device);
244   // resolve callbacks
245   m_pio_read_func.resolve(m_pio_read_cb, *this);
246   m_pio_write_func.resolve(m_pio_write_cb, *this);
285247
286   for (i = 0; i < 5; i++)
248   // allocate timers
249   for (int i = 0; i < 5; i++)
287250   {
288      tms->timer[i] = device->machine().scheduler().timer_alloc(FUNC(tms5501_timer_decrementer_callback), (void *) device);
289      tms->timer[i]->set_param(i);
251      m_timer[i] = timer_alloc(TIMER_DECREMENTER);
252      m_timer[i]->set_param(i);
290253   }
291254
292   tms->interrupt_mask = 0;
293   tms->interrupt_address = 0;
255   m_interrupt_mask = 0;
256   m_interrupt_address = 0;
294257
295   tms->sensor = 0;
296   tms->sio_rate = 0;
297   tms->sio_input_buffer = 0;
298   tms->sio_output_buffer = 0;
299   tms->pio_input_buffer = 0;
300   tms->pio_output_buffer = 0;
258   m_sensor = 0;
259   m_sio_rate = 0;
260   m_sio_input_buffer = 0;
261   m_sio_output_buffer = 0;
262   m_pio_input_buffer = 0;
263   m_pio_output_buffer = 0;
301264
302   tms->command = 0;
303   LOG_TMS5501(device, "Init", 0);
265   m_command = 0;
266   LOG_TMS5501("Init", 0);
304267}
305268
306269
270//-------------------------------------------------
271//  device_timer - handler timer events
272//-------------------------------------------------
273
274void tms5501_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
275{
276   switch (id)
277   {
278   case TIMER_DECREMENTER:
279      timer_decrementer((UINT8)param);
280      break;
281   }
282}
283
284
307285/*-------------------------------------------------
308    tms5501_set_pio_bit_7
286    tms5501_device::set_pio_bit_7
309287-------------------------------------------------*/
310288
311void tms5501_set_pio_bit_7 (device_t *device, UINT8 data)
289DECLARE_WRITE_LINE_MEMBER( tms5501_device::set_pio_bit_7 )
312290{
313   tms5501_t *tms = get_token(device);
314
315   if (tms->command & TMS5501_INT_7_SELECT)
291   if (m_command & TMS5501_INT_7_SELECT)
316292   {
317      if (!(tms->pio_input_buffer & TMS5501_PIO_INT_7) && data)
318         tms->pending_interrupts |= TMS5501_INT_7_INT;
293      if (!(m_pio_input_buffer & TMS5501_PIO_INT_7) && state)
294         m_pending_interrupts |= TMS5501_INT_7_INT;
319295      else
320         tms->pending_interrupts &= ~TMS5501_INT_7_INT;
296         m_pending_interrupts &= ~TMS5501_INT_7_INT;
321297   }
322298
323   tms->pio_input_buffer &= ~TMS5501_PIO_INT_7;
324   if (data)
325      tms->pio_input_buffer |= TMS5501_PIO_INT_7;
299   m_pio_input_buffer &= ~TMS5501_PIO_INT_7;
300   if (state)
301      m_pio_input_buffer |= TMS5501_PIO_INT_7;
326302
327   if (tms->pending_interrupts & TMS5501_INT_7_INT)
328      tms5501_field_interrupts(device);
303   if (m_pending_interrupts & TMS5501_INT_7_INT)
304      field_interrupts();
329305}
330306
331307
332308/*-------------------------------------------------
333    tms5501_sensor
309    tms5501_device::set_sensor
334310-------------------------------------------------*/
335311
336void tms5501_sensor (device_t *device, UINT8 data)
312WRITE_LINE_MEMBER(tms5501_device::set_sensor)
337313{
338   tms5501_t *tms = get_token(device);
339
340   if (!(tms->sensor) && data)
341      tms->pending_interrupts |= TMS5501_SENSOR_INT;
314   if (!(m_sensor) && state)
315      m_pending_interrupts |= TMS5501_SENSOR_INT;
342316   else
343      tms->pending_interrupts &= ~TMS5501_SENSOR_INT;
317      m_pending_interrupts &= ~TMS5501_SENSOR_INT;
344318
345   tms->sensor = data;
319   m_sensor = state;
346320
347   if (tms->pending_interrupts &= TMS5501_SENSOR_INT)
348      tms5501_field_interrupts(device);
321   if (m_pending_interrupts &= TMS5501_SENSOR_INT)
322      field_interrupts();
349323}
350324
351325
r15385r15386
353327    READ8_DEVICE_HANDLER( tms5501_r )
354328-------------------------------------------------*/
355329
356READ8_DEVICE_HANDLER( tms5501_r )
330READ8_MEMBER( tms5501_device::read )
357331{
358   tms5501_t *tms = get_token(device);
359   const tms5501_interface *intf = get_interface(device);
360
361332   UINT8 data = 0x00;
362333   offset &= 0x0f;
363334
364335   switch (offset)
365336   {
366337      case 0x00:   /* Serial input buffer */
367         data = tms->sio_input_buffer;
368         tms->status &= ~TMS5501_RCV_BUFFER_LOADED;
369         LOG_TMS5501(device, "Reading from serial input buffer", data);
338         data = m_sio_input_buffer;
339         m_status &= ~TMS5501_RCV_BUFFER_LOADED;
340         LOG_TMS5501("Reading from serial input buffer", data);
370341         break;
371342      case 0x01:   /* PIO input port */
372         if (intf->pio_read_callback)
373            data = (*intf->pio_read_callback)(device);
374         LOG_TMS5501(device, "Reading from PIO", data);
343         if (!m_pio_read_func.isnull())
344            data = m_pio_read_func(0);
345         LOG_TMS5501("Reading from PIO", data);
375346         break;
376347      case 0x02:   /* Interrupt address register */
377         data = tms->interrupt_address;
378         tms->status &= ~TMS5501_INTERRUPT_PENDING;
348         data = m_interrupt_address;
349         m_status &= ~TMS5501_INTERRUPT_PENDING;
379350         break;
380351      case 0x03:   /* Status register */
381         data = tms->status;
352         data = m_status;
382353         break;
383354      case 0x04:   /* Command register */
384         data = tms->command;
385         LOG_TMS5501(device, "Command register read", data);
355         data = m_command;
356         LOG_TMS5501("Command register read", data);
386357         break;
387358      case 0x05:   /* Serial rate register */
388         data = tms->sio_rate;
389         LOG_TMS5501(device, "Serial rate read", data);
359         data = m_sio_rate;
360         LOG_TMS5501("Serial rate read", data);
390361         break;
391362      case 0x06:   /* Serial output buffer */
392363      case 0x07:   /* PIO output */
393364         break;
394365      case 0x08:   /* Interrupt mask register */
395         data = tms->interrupt_mask;
396         LOG_TMS5501(device, "Interrupt mask read", data);
366         data = m_interrupt_mask;
367         LOG_TMS5501("Interrupt mask read", data);
397368         break;
398369      case 0x09:   /* Timer 0 address */
399370      case 0x0a:   /* Timer 1 address */
r15385r15386
410381    WRITE8_DEVICE_HANDLER( tms5501_w )
411382-------------------------------------------------*/
412383
413WRITE8_DEVICE_HANDLER( tms5501_w )
384WRITE8_MEMBER( tms5501_device::write )
414385{
415   tms5501_t *tms = get_token(device);
416   const tms5501_interface *intf = get_interface(device);
417386   offset &= 0x0f;
418387
419388   switch (offset)
r15385r15386
422391      case 0x01:   /* Keyboard input port, Page blanking signal */
423392      case 0x02:   /* Interrupt address register */
424393      case 0x03:   /* Status register */
425         LOG_TMS5501(device, "Writing to read only port", offset&0x000f);
426         LOG_TMS5501(device, "Data", data);
394         LOG_TMS5501("Writing to read only port", offset&0x000f);
395         LOG_TMS5501("Data", data);
427396         break;
428397      case 0x04:
429398         /* Command register
r15385r15386
435404                bits 6-7: not used, normally '0'
436405               bits 1-5 are latched */
437406
438         tms->command = data & TMS5501_COMMAND_LATCHED_BITS;
439         LOG_TMS5501(device, "Command register write", data);
407         m_command = data & TMS5501_COMMAND_LATCHED_BITS;
408         LOG_TMS5501("Command register write", data);
440409
441410         if (data & TMS5501_RESET)
442            device->reset();
411            reset();
443412         break;
444413      case 0x05:
445414         /* Serial rate register
r15385r15386
452421                bit 6: 9600 baud
453422                bit 7: '0' - two stop bits, '1' - one stop bit */
454423
455         tms->sio_rate = data;
456         LOG_TMS5501(device, "Serial rate write", data);
424         m_sio_rate = data;
425         LOG_TMS5501("Serial rate write", data);
457426         break;
458427      case 0x06:   /* Serial output buffer */
459         tms->sio_output_buffer = data;
460         LOG_TMS5501(device, "Serial output data", data);
428         m_sio_output_buffer = data;
429         LOG_TMS5501("Serial output data", data);
461430         break;
462431      case 0x07:   /* PIO output */
463         tms->pio_output_buffer = data;
464         if (intf->pio_write_callback)
465            (*intf->pio_write_callback)(device, tms->pio_output_buffer);
466         LOG_TMS5501(device, "Writing to PIO", data);
432         m_pio_output_buffer = data;
433         if (!m_pio_write_func.isnull())
434            m_pio_write_func(0, m_pio_output_buffer);
435         LOG_TMS5501("Writing to PIO", data);
467436         break;
468437      case 0x08:
469438         /* Interrupt mask register
r15385r15386
476445                bit 6: Timer 4 has expired (KBIM)
477446                bit 7: Timer 5 has expired or IN7 (CLKIM) */
478447
479         tms->interrupt_mask = data;
480         LOG_TMS5501(device, "Interrupt mask write", data);
448         m_interrupt_mask = data;
449         LOG_TMS5501("Interrupt mask write", data);
481450         break;
482451      case 0x09:   /* Timer 0 counter */
483452      case 0x0a:   /* Timer 1 counter */
r15385r15386
485454      case 0x0c:   /* Timer 3 counter */
486455      case 0x0d:   /* Timer 4 counter */
487456         offset -= 9;
488         tms->timer_counter[offset] = data;
489         tms5501_timer_reload(device, offset);
490         LOG_TMS5501(device, "Write timer", offset);
491         LOG_TMS5501(device, "Timer counter set", data);
457         m_timer_counter[offset] = data;
458         timer_reload(offset);
459         LOG_TMS5501("Write timer", offset);
460         LOG_TMS5501("Timer counter set", data);
492461         break;
493462   }
494463}
495
496
497/*-------------------------------------------------
498    DEVICE_GET_INFO( tms5501 )
499-------------------------------------------------*/
500
501DEVICE_GET_INFO( tms5501 )
502{
503   switch (state)
504   {
505      /* --- the following bits of info are returned as 64-bit signed integers --- */
506      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(tms5501_t);            break;
507      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
508
509      /* --- the following bits of info are returned as pointers to data or functions --- */
510      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(tms5501);   break;
511      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
512      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(tms5501);   break;
513
514      /* --- the following bits of info are returned as NULL-terminated strings --- */
515      case DEVINFO_STR_NAME:                     strcpy(info->s, "TMS5501");               break;
516      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "TMS5501");               break;
517      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                  break;
518      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);               break;
519      case DEVINFO_STR_CREDITS:                  /* Nothing */                        break;
520   }
521}
522
523DEFINE_LEGACY_DEVICE(TMS5501, tms5501);
src/mess/machine/tms5501.h
r15385r15386
1111
1212
1313/***************************************************************************
14    MACROS
14    DEVICE CONFIGURATION MACROS
1515***************************************************************************/
1616
17DECLARE_LEGACY_DEVICE(TMS5501, tms5501);
17#define MCFG_TMS5501_ADD(_tag, _clock, _intrf) \
18   MCFG_DEVICE_ADD(_tag, TMS5501, _clock) \
19   MCFG_DEVICE_CONFIG(_intrf)
1820
21#define TMS5501_INTERFACE(name) \
22   const tms5501_interface (name) =
1923
2024
2125/***************************************************************************
2226    TYPE DEFINITIONS
2327***************************************************************************/
2428
25/* TMS5501 timer and interrupt controller */
26typedef struct _tms5501_interface tms5501_interface;
27struct _tms5501_interface
29typedef void (*tms5501_interrupt_cb)(device_t &device, int intreq, UINT8 vector);
30#define TMS5501_IRQ_CALLBACK(name) void name(device_t &device, int intreq, UINT8 vector)
31
32
33// ======================> tms5501_interface
34
35struct tms5501_interface
2836{
29   UINT8 (*pio_read_callback)(device_t *device);
30   void (*pio_write_callback)(device_t *device, UINT8);
31   void (*interrupt_callback)(device_t *device, int intreq, UINT8 vector);
32   double clock_rate;
37   devcb_read8            m_pio_read_cb;       // PIO read
38   devcb_write8         m_pio_write_cb;       // PIO write
39   tms5501_interrupt_cb   m_interrupt_cb;       // interrupt callback
3340};
3441
42// ======================> tms5501_device
3543
44class tms5501_device :   public device_t,
45                  public tms5501_interface
46{
47public:
48    // construction/destruction
49   tms5501_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
3650
37/***************************************************************************
38    DEVICE CONFIGURATION MACROS
39***************************************************************************/
51   DECLARE_READ8_MEMBER( read );
52   DECLARE_WRITE8_MEMBER( write );
53   DECLARE_WRITE_LINE_MEMBER( set_pio_bit_7 );
54   DECLARE_WRITE_LINE_MEMBER( set_sensor );
4055
41#define MCFG_TMS5501_ADD(_tag, _intrf) \
42   MCFG_DEVICE_ADD(_tag, TMS5501, 0) \
43   MCFG_DEVICE_CONFIG(_intrf)
56protected:
57   // device-level overrides
58   virtual void device_config_complete();
59   virtual void device_start();
60   virtual void device_reset();
61   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
4462
63public:
64   int  find_first_bit(int value);
65   void field_interrupts();
66   void timer_decrementer(UINT8 mask);
67   void timer_reload(int timer);
4568
69   static const device_timer_id TIMER_DECREMENTER = 0;
4670
47/***************************************************************************
48    FUNCTION PROTOTYPES
49***************************************************************************/
71   // internal registers
72   UINT8   m_status;               // status register
73   UINT8   m_command;               // command register, bits 1-5 are latched
5074
51READ8_DEVICE_HANDLER( tms5501_r );
52WRITE8_DEVICE_HANDLER( tms5501_w );
75   UINT8   m_sio_rate;               // SIO configuration register
76   UINT8   m_sio_input_buffer;         // SIO input buffer
77   UINT8   m_sio_output_buffer;      // SIO output buffer
5378
54void tms5501_set_pio_bit_7 (device_t *device, UINT8 data);
55void tms5501_sensor (device_t *device, UINT8 data);
79   UINT8   m_pio_input_buffer;         // PIO input buffer
80   UINT8   m_pio_output_buffer;      // PIO output buffer
5681
82   UINT8   m_interrupt_mask;         // interrupt mask register
83   UINT8   m_pending_interrupts;      // pending interrupts register
84   UINT8   m_interrupt_address;      // interrupt vector register
85
86   int    m_sensor;               // sensor input
87
88   // internal timers
89   UINT8      m_timer_counter[5];
90   emu_timer * m_timer[5];
91
92   // PIO callbacks
93   devcb_resolved_read8   m_pio_read_func;
94   devcb_resolved_write8   m_pio_write_func;
95};
96
97
98// device type definition
99extern const device_type TMS5501;
100
57101#endif /* __TMS5501_H__ */
src/mess/includes/dai.h
r15385r15386
5959      { }
6060
6161   required_device<device_t> m_pit;
62   required_device<device_t> m_tms5501;
62   required_device<tms5501_device> m_tms5501;
6363   required_device<dai_sound_device> m_sound;
6464
6565   UINT8 m_paddle_select;
r15385r15386
7474   DECLARE_WRITE8_MEMBER(dai_amd9511_w);
7575   DECLARE_READ8_MEMBER(dai_pit_r);
7676   DECLARE_WRITE8_MEMBER(dai_pit_w);
77   DECLARE_READ8_MEMBER(dai_keyboard_r);
78   DECLARE_WRITE8_MEMBER(dai_keyboard_w);
7779};
7880
7981
src/mess/drivers/dai.c
r15385r15386
7676   AM_RANGE( 0xfc00, 0xfcff) AM_READWRITE(dai_pit_r, dai_pit_w) // AM_DEVREADWRITE_LEGACY("pit8253", pit8253_r, pit8253_w )
7777   AM_RANGE( 0xfd00, 0xfdff) AM_READWRITE(dai_io_discrete_devices_r, dai_io_discrete_devices_w )
7878   AM_RANGE( 0xfe00, 0xfeff) AM_DEVREADWRITE("ppi8255", i8255_device, read, write)
79   AM_RANGE( 0xff00, 0xffff) AM_DEVREADWRITE_LEGACY("tms5501", tms5501_r, tms5501_w )
79   AM_RANGE( 0xff00, 0xffff) AM_DEVREADWRITE("tms5501", tms5501_device, read, write )
8080ADDRESS_MAP_END
8181
8282
r15385r15386
236236   MCFG_CASSETTE_ADD( CASSETTE_TAG, dai_cassette_interface )
237237
238238   /* tms5501 */
239   MCFG_TMS5501_ADD( "tms5501", dai_tms5501_interface )
239   MCFG_TMS5501_ADD( "tms5501", 2000000, dai_tms5501_interface )
240240
241241   /* internal ram */
242242   MCFG_RAM_ADD(RAM_TAG)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team