Previous 15994 Revisions Next

r3353 Tuesday 30th September, 2008 at 21:36:29 UTC by Wilbert Pol
Merged z80 daisy chain updates from mamedev.
Changed z80dart implementation into a device.
[src/emu/cpu/z180]z180.c
[src/emu/cpu/z80]z80.c z80daisy.c z80daisy.h
[src/emu/machine]z80ctc.c z80ctc.h z80pio.c z80pio.h z80sio.c z80sio.h
[src/mess/drivers]abc80.c abc80x.c einstein.c kc.c mbee.c mpf1.c mtx.c newbrain.c osborne1.c sord.c super80.c
[src/mess/includes]kc.h mbee.h mtx.h osborne1.h
[src/mess/machine]kc.c mbee.c mtx.c osborne1.c
[src/mess/video]abc80x.c

src/emu/cpu/z180/z180.c
r3352r3353
115115   UINT8   nmi_pending;      /* nmi pending */
116116   UINT8   irq_state[3];      /* irq line states (INT0,INT1,INT2) */
117117   UINT8   after_EI;         /* are we in the EI shadow? */
118   const struct z80_irq_daisy_chain *daisy;
118   z80_daisy_state *daisy;
119119   int    (*irq_callback)(int irqline);
120120}   Z180_Regs;
121121
r3352r3353
18981898
18991899static void z180_init(int index, int clock, const void *config, int (*irqcallback)(int))
19001900{
1901   Z180.daisy = config;
1901   Z180.daisy = NULL;
1902   if (config)
1903      Z180.daisy = z80daisy_init(Machine, config);
19021904   Z180.irq_callback = irqcallback;
19031905
19041906   state_save_register_item("z180", index, Z180.AF.w.l);
r3352r3353
19331935 ****************************************************************************/
19341936static void z180_reset(void)
19351937{
1936   const struct z80_irq_daisy_chain *save_daisy;
1938   z80_daisy_state *save_daisy;
19371939   int (*save_irqcallback)(int);
19381940   int i, p;
19391941#if BIG_FLAGS_ARRAY
src/emu/cpu/z80/z80daisy.h
r3352r3353
66
77***************************************************************************/
88
9#pragma once
910
10#ifndef Z80DAISY_H
11#define Z80DAISY_H
11#ifndef __Z80DAISY_H__
12#define __Z80DAISY_H__
1213
14#include "devintrf.h"
1315
14/* daisy-chain link */
15struct z80_irq_daisy_chain
16{
17   void (*reset)(int);          /* reset callback */
18   int (*irq_state)(int);         /* get interrupt state */
19   int (*irq_ack)(int);         /* interrupt acknowledge callback */
20   void (*irq_reti)(int);         /* reti callback */
21   int param;                  /* callback parameter (-1 ends list) */
22};
2316
17/***************************************************************************
18    CONSTANTS
19***************************************************************************/
2420
2521/* these constants are returned from the irq_state function */
2622#define Z80_DAISY_INT    0x01      /* interrupt request mask */
2723#define Z80_DAISY_IEO    0x02      /* interrupt disable mask (IEO) */
2824
2925
30/* prototypes */
31void z80daisy_reset(const struct z80_irq_daisy_chain *daisy);
32int z80daisy_update_irq_state(const struct z80_irq_daisy_chain *chain);
33int z80daisy_call_ack_device(const struct z80_irq_daisy_chain *chain);
34void z80daisy_call_reti_device(const struct z80_irq_daisy_chain *chain);
26enum
27{
28   DEVINFO_FCT_IRQ_STATE = DEVINFO_FCT_DEVICE_SPECIFIC,   /* R/O: z80_daisy_irq_state */
29   DEVINFO_FCT_IRQ_ACK,                           /* R/O: z80_daisy_irq_ack */
30   DEVINFO_FCT_IRQ_RETI                           /* R/O: z80_daisy_irq_reti */
31};
3532
33
34
35/***************************************************************************
36    TYPE DEFINITIONS
37***************************************************************************/
38
39/* per-device callback functions */
40typedef int (*z80_daisy_irq_state)(const device_config *device);
41typedef int (*z80_daisy_irq_ack)(const device_config *device);
42typedef int (*z80_daisy_irq_reti)(const device_config *device);
43
44
45/* opaque internal daisy chain state */
46typedef struct _z80_daisy_state z80_daisy_state;
47
48
49/* daisy chain structure */
50typedef struct _z80_daisy_chain z80_daisy_chain;
51struct _z80_daisy_chain
52{
53   device_type      devtype;               /* type of device */
54   const char *   devname;               /* name of the device */
55};
56
57
58
59/***************************************************************************
60    FUNCTION PROTOTYPES
61***************************************************************************/
62
63z80_daisy_state *z80daisy_init(running_machine *machine, const z80_daisy_chain *daisy);
64
65void z80daisy_reset(z80_daisy_state *daisy);
66int z80daisy_update_irq_state(z80_daisy_state *chain);
67int z80daisy_call_ack_device(z80_daisy_state *chain);
68void z80daisy_call_reti_device(z80_daisy_state *chain);
69
3670#endif
src/emu/cpu/z80/z80.c
r3352r3353
127127   UINT8   nmi_pending;      /* nmi pending */
128128   UINT8   irq_state;         /* irq line state */
129129   UINT8   after_ei;         /* are we in the EI shadow? */
130   const struct z80_irq_daisy_chain *daisy;
131130   int      (*irq_callback)(int irqline);
131   z80_daisy_state *daisy;
132132}   Z80_Regs;
133133
134134#define CF   0x01
r3352r3353
34983498
34993499   /* Reset registers to their initial values */
35003500   memset(&Z80, 0, sizeof(Z80));
3501   Z80.daisy = config;
3501   if (config != NULL)
3502      Z80.daisy = z80daisy_init(Machine, config);
35023503   Z80.irq_callback = irqcallback;
35033504   IX = IY = 0xffff; /* IX and IY are FFFF after a reset! */
35043505   F = ZF;         /* Zero flag is set */
src/emu/cpu/z80/z80daisy.c
r3352r3353
1010#include "z80daisy.h"
1111
1212
13void z80daisy_reset(const struct z80_irq_daisy_chain *daisy)
13struct _z80_daisy_state
1414{
15   z80_daisy_state *      next;         /* next device */
16   const device_config *   device;         /* associated device */
17   z80_daisy_irq_state      irq_state;      /* IRQ state callback */
18   z80_daisy_irq_ack      irq_ack;      /* IRQ ack callback */
19   z80_daisy_irq_reti      irq_reti;      /* IRQ reti callback */
20};
21
22
23z80_daisy_state *z80daisy_init(running_machine *machine, const z80_daisy_chain *daisy)
24{
25   z80_daisy_state *head = NULL;
26   z80_daisy_state **tailptr = &head;
27
28   /* create a linked list of devices */   
29   for ( ; daisy->devtype != NULL; daisy++)
30   {
31      *tailptr = auto_malloc(sizeof(**tailptr));
32      (*tailptr)->next = NULL;
33      (*tailptr)->device = devtag_get_device(machine, daisy->devtype, daisy->devname);
34      (*tailptr)->irq_state = (z80_daisy_irq_state)device_get_info_fct((*tailptr)->device, DEVINFO_FCT_IRQ_STATE);
35      (*tailptr)->irq_ack = (z80_daisy_irq_ack)device_get_info_fct((*tailptr)->device, DEVINFO_FCT_IRQ_ACK);
36      (*tailptr)->irq_reti = (z80_daisy_irq_reti)device_get_info_fct((*tailptr)->device, DEVINFO_FCT_IRQ_RETI);
37      tailptr = &(*tailptr)->next;
38   }
39   
40   return head;
41}
42
43
44void z80daisy_reset(z80_daisy_state *daisy)
45{
1546   /* loop over all devices and call their reset function */
16   for ( ; daisy->param != -1; daisy++)
17      if (daisy->reset)
18         (*daisy->reset)(daisy->param);
47   for ( ; daisy != NULL; daisy = daisy->next)
48      device_reset(daisy->device);
1949}
2050
2151
22int z80daisy_update_irq_state(const struct z80_irq_daisy_chain *daisy)
52int z80daisy_update_irq_state(z80_daisy_state *daisy)
2353{
2454   /* loop over all devices; dev[0] is highest priority */
25   for ( ; daisy->param != -1; daisy++)
55   for ( ; daisy != NULL; daisy = daisy->next)
2656   {
27      int state = (*daisy->irq_state)(daisy->param);
57      int state = (*daisy->irq_state)(daisy->device);
2858
2959      /* if this device is asserting the INT line, that's the one we want */
3060      if (state & Z80_DAISY_INT)
r3352r3353
3969}
4070
4171
42int z80daisy_call_ack_device(const struct z80_irq_daisy_chain *daisy)
72int z80daisy_call_ack_device(z80_daisy_state *daisy)
4373{
4474   /* loop over all devices; dev[0] is the highest priority */
45   for ( ; daisy->param != -1; daisy++)
75   for ( ; daisy != NULL; daisy = daisy->next)
4676   {
47      int state = (*daisy->irq_state)(daisy->param);
77      int state = (*daisy->irq_state)(daisy->device);
4878
4979      /* if this device is asserting the INT line, that's the one we want */
5080      if (state & Z80_DAISY_INT)
51         return (*daisy->irq_ack)(daisy->param);
81         return (*daisy->irq_ack)(daisy->device);
5282   }
5383
5484   logerror("z80daisy_call_ack_device: failed to find an device to ack!\n");
r3352r3353
5686}
5787
5888
59void z80daisy_call_reti_device(const struct z80_irq_daisy_chain *daisy)
89void z80daisy_call_reti_device(z80_daisy_state *daisy)
6090{
6191   /* loop over all devices; dev[0] is the highest priority */
62   for ( ; daisy->param != -1; daisy++)
92   for ( ; daisy != NULL; daisy = daisy->next)
6393   {
64      int state = (*daisy->irq_state)(daisy->param);
94      int state = (*daisy->irq_state)(daisy->device);
6595
6696      /* if this device is asserting the IEO line, that's the one we want */
6797      if (state & Z80_DAISY_IEO)
6898      {
69         (*daisy->irq_reti)(daisy->param);
99         (*daisy->irq_reti)(daisy->device);
70100         return;
71101      }
72102   }
src/emu/machine/z80pio.c
r3352r3353
5353    TYPE DEFINITIONS
5454***************************************************************************/
5555
56typedef struct _z80pio z80pio_t;
5657struct _z80pio
5758{
5859   UINT8 vector[2];                      /* interrupt vector               */
59   void (*intr)(running_machine *, int which);            /* interrupt callbacks            */
60   void (*intr)(const device_config *, int which);            /* interrupt callbacks            */
6061   void (*rdyr[2])(int data);          /* RDY active callback            */
6162   read8_device_func  port_read[2];     /* port read callbacks            */
6263   write8_device_func port_write[2];    /* port write callbacks           */
r3352r3353
7071   UINT8 strobe[2];                  /* strobe inputs */
7172   UINT8 int_state[2];                   /* interrupt status (daisy chain) */
7273};
73typedef struct _z80pio z80pio_t;
7474
7575
76
7677/***************************************************************************
78    FUNCTION PROTOTYPES
79***************************************************************************/
80
81static int z80pio_irq_state(const device_config *device);
82static int z80pio_irq_ack(const device_config *device);
83static void z80pio_irq_reti(const device_config *device);
84
85
86
87/***************************************************************************
7788    INLINE FUNCTIONS
7889***************************************************************************/
7990
r3352r3353
108119
109120   /* if we have a callback, update it with the current state */
110121   if (z80pio->intr)
111      z80pio->intr(device->machine, (z80pio_irq_state(device) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE);
122      z80pio->intr(device, (z80pio_irq_state(device) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE);
112123}
113124
114125
r3352r3353
442453    DAISY CHAIN INTERFACE
443454***************************************************************************/
444455
445int z80pio_irq_state(const device_config *device)
456static int z80pio_irq_state(const device_config *device)
446457{
447458   z80pio_t *z80pio = get_safe_token( device );
448459   int state = 0;
r3352r3353
463474}
464475
465476
466int z80pio_irq_ack(const device_config *device)
477static int z80pio_irq_ack(const device_config *device)
467478{
468479   z80pio_t *z80pio = get_safe_token( device );
469480   int ch;
r3352r3353
485496}
486497
487498
488void z80pio_irq_reti(const device_config *device)
499static void z80pio_irq_reti(const device_config *device)
489500{
490501   z80pio_t *z80pio = get_safe_token( device );
491502   int ch;
r3352r3353
555566}
556567
557568
558void z80pio_reset( const device_config *device )
569static DEVICE_RESET( z80pio )
559570{
560571   z80pio_t   *z80pio = get_safe_token( device );
561572   int i;
r3352r3353
575586}
576587
577588
578static DEVICE_RESET( z80pio )
579{
580   z80pio_reset( device );
581}
582
583
584589static DEVICE_SET_INFO( z80pio )
585590{
586591   switch (state)
r3352r3353
604609      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(z80pio);break;
605610      case DEVINFO_FCT_STOP:                     /* Nothing */                     break;
606611      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(z80pio);break;
612      case DEVINFO_FCT_IRQ_STATE:                  info->f = (genf *)z80pio_irq_state;      break;
613      case DEVINFO_FCT_IRQ_ACK:                  info->f = (genf *)z80pio_irq_ack;      break;
614      case DEVINFO_FCT_IRQ_RETI:                  info->f = (genf *)z80pio_irq_reti;      break;
607615
608616      /* --- the following bits of info are returned as NULL-terminated strings --- */
609      case DEVINFO_STR_NAME:                     info->s = "Zilog Z80PIO";            break;
610      case DEVINFO_STR_FAMILY:                  info->s = "Z80PIO";                  break;
617      case DEVINFO_STR_NAME:                     info->s = "Zilog Z80 PIO";            break;
618      case DEVINFO_STR_FAMILY:                  info->s = "Z80";                  break;
611619      case DEVINFO_STR_VERSION:                  info->s = "1.0";                  break;
612620      case DEVINFO_STR_SOURCE_FILE:               info->s = __FILE__;                  break;
613621      case DEVINFO_STR_CREDITS:                  info->s = "Copyright Nicola Salmoria and the MAME Team"; break;
src/emu/machine/z80pio.h
r3352r3353
77
88***************************************************************************/
99
10#ifndef __Z80PIO_H_
11#define __Z80PIO_H_
10#ifndef __Z80PIO_H__
11#define __Z80PIO_H__
1212
1313
1414/***************************************************************************
1515    TYPE DEFINITIONS
1616***************************************************************************/
1717
18typedef struct _z80pio_interface z80pio_interface;
1819struct _z80pio_interface
1920{
20   void (*intr)(running_machine *machine, int which);    /* callback when change interrupt status */
21   void (*intr)(const device_config *device, int which);    /* callback when change interrupt status */
2122   read8_device_func portAread;    /* port A read callback */
2223   read8_device_func portBread;    /* port B read callback */
2324   write8_device_func portAwrite;  /* port A write callback */
r3352r3353
2526   void (*rdyA)(int data);     /* portA ready active callback (do not support yet)*/
2627   void (*rdyB)(int data);     /* portB ready active callback (do not support yet)*/
2728};
28typedef struct _z80pio_interface z80pio_interface;
2929
3030
31
3132/***************************************************************************
3233    DEVICE CONFIGURATION MACROS
3334***************************************************************************/
r3352r3353
4243
4344
4445/***************************************************************************
45    INITIALIZATION
46***************************************************************************/
47
48void z80pio_reset( const device_config *device );
49
50
51/***************************************************************************
5246    CONTROL REGISTER READ/WRITE
5347***************************************************************************/
5448
r3352r3353
8175
8276
8377/***************************************************************************
84    DAISY CHAIN INTERFACE
85***************************************************************************/
86
87int z80pio_irq_state(const device_config *device);
88int z80pio_irq_ack(const device_config *device);
89void z80pio_irq_reti(const device_config *device);
90
91
92/***************************************************************************
9378    READ/WRITE HANDLERS
9479***************************************************************************/
9580READ8_DEVICE_HANDLER(z80pio_r);
src/emu/machine/z80sio.c
r3352r3353
167167   int         inbuf;            /* input buffer */
168168   int         outbuf;            /* output buffer */
169169   UINT8      int_on_next_rx;      /* interrupt on next rx? */
170   emu_timer *receive_timer;      /* timer to clock data in */
170   emu_timer *   receive_timer;      /* timer to clock data in */
171171   UINT8      receive_buffer[16];   /* buffer for incoming data */
172172   UINT8      receive_inptr;      /* index of data coming in */
173173   UINT8      receive_outptr;      /* index of data going out */
r3352r3353
179179{
180180   sio_channel   chan[2];         /* 2 channels */
181181   UINT8      int_state[8];      /* interrupt states */
182   UINT32      clock;            /* clock value */
182183
183   void (*irq_cb)(running_machine *machine, int state);
184   write8_machine_func dtr_changed_cb;
185   write8_machine_func rts_changed_cb;
186   write8_machine_func break_changed_cb;
187   write8_machine_func transmit_cb;
188   int (*receive_poll_cb)(int which);
184   void (*irq_cb)(const device_config *device, int state);
185   write8_device_func dtr_changed_cb;
186   write8_device_func rts_changed_cb;
187   write8_device_func break_changed_cb;
188   write8_device_func transmit_cb;
189   int (*receive_poll_cb)(const device_config *device, int channel);
189190};
190191
191192
r3352r3353
198199
199200
200201
201/***************************************************************************
202    GLOBAL VARIABLES
203***************************************************************************/
204
205static z80sio sios[MAX_SIO];
206
207
208202/*
209203
210204    Interrupt priorities:
r3352r3353
258252
259253
260254/***************************************************************************
255    FUNCTION PROTOTYPES
256***************************************************************************/
257
258static int z80sio_irq_state(const device_config *device);
259static int z80sio_irq_ack(const device_config *device);
260static void z80sio_irq_reti(const device_config *device);
261
262
263
264/***************************************************************************
261265    INLINE FUNCTIONS
262266***************************************************************************/
263267
264INLINE void interrupt_check(running_machine *machine, z80sio *sio)
268INLINE z80sio *get_safe_token(const device_config *device)
265269{
270   assert(device != NULL);
271   assert(device->token != NULL);
272   assert(device->type == Z80SIO);
273   return (z80sio *)device->token;
274}
275
276
277INLINE void interrupt_check(const device_config *device)
278{
266279   /* if we have a callback, update it with the current state */
280   z80sio *sio = get_safe_token(device);
267281   if (sio->irq_cb != NULL)
268      (*sio->irq_cb)(machine, (z80sio_irq_state(sio - sios) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE);
282      (*sio->irq_cb)(device, (z80sio_irq_state(device) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE);
269283}
270284
271285
r3352r3353
282296***************************************************************************/
283297
284298/*-------------------------------------------------
285    z80sio_init - initialize a single SIO chip
286-------------------------------------------------*/
287
288void z80sio_init(int which, z80sio_interface *intf)
289{
290   z80sio *sio = sios + which;
291
292   assert(which < MAX_SIO);
293
294   memset(sio, 0, sizeof(*sio));
295
296   sio->chan[0].receive_timer = timer_alloc(serial_callback, NULL);
297   sio->chan[1].receive_timer = timer_alloc(serial_callback, NULL);
298
299   sio->irq_cb = intf->irq_cb;
300   sio->dtr_changed_cb = intf->dtr_changed_cb;
301   sio->rts_changed_cb = intf->rts_changed_cb;
302   sio->break_changed_cb = intf->break_changed_cb;
303   sio->transmit_cb = intf->transmit_cb;
304   sio->receive_poll_cb = intf->receive_poll_cb;
305
306   z80sio_reset(which);
307}
308
309
310/*-------------------------------------------------
311299    reset_channel - reset a single SIO channel
312300-------------------------------------------------*/
313301
314static void reset_channel(running_machine *machine, z80sio *sio, int ch)
302static void reset_channel(const device_config *device, int ch)
315303{
304   z80sio *sio = get_safe_token(device);
316305   attotime tpc = compute_time_per_character(sio, ch);
317306   sio_channel *chan = &sio->chan[ch];
318307
r3352r3353
327316   sio->int_state[2 + 4*ch] = 0;
328317   sio->int_state[3 + 4*ch] = 0;
329318
330   interrupt_check(machine, sio);
319   interrupt_check(device);
331320
332321   /* start the receive timer running */
333   timer_adjust_periodic(chan->receive_timer, tpc, ((sio - sios) << 1) | ch, tpc);
322   timer_adjust_periodic(chan->receive_timer, tpc, ch, tpc);
334323}
335324
336325
337/*-------------------------------------------------
338    z80sio_reset - reset a single SIO chip
339-------------------------------------------------*/
340326
341void z80sio_reset(int which)
342{
343   z80sio *sio = sios + which;
344   int ch;
345
346   assert(which < MAX_SIO);
347
348   /* loop over channels */
349   for (ch = 0; ch < 2; ch++)
350      reset_channel(Machine, sio, ch);
351}
352
353
354
355327/***************************************************************************
356328    CONTROL REGISTER READ/WRITE
357329***************************************************************************/
r3352r3353
360332    z80sio_c_w - write to a control register
361333-------------------------------------------------*/
362334
363void z80sio_c_w(running_machine *machine, int which, int ch, UINT8 data)
335WRITE8_DEVICE_HANDLER( z80sio_c_w )
364336{
365   z80sio *sio = sios + which;
337   z80sio *sio = get_safe_token(device);
338   int ch = offset & 1;
366339   sio_channel *chan = &sio->chan[ch];
367340   int reg = chan->regs[0] & 7;
368341   UINT8 old = chan->regs[reg];
r3352r3353
386359         {
387360            case SIO_WR0_COMMAND_CH_RESET:
388361               VPRINTF(("%04X:SIO reset channel %c\n", activecpu_get_pc(), 'A' + ch));
389               reset_channel(machine, sio, ch);
362               reset_channel(device, ch);
390363               break;
391364
392365            case SIO_WR0_COMMAND_RES_STATUS_INT:
393366               sio->int_state[INT_CHA_STATUS - 4*ch] &= ~Z80_DAISY_INT;
394               interrupt_check(machine, sio);
367               interrupt_check(device);
395368               break;
396369
397370            case SIO_WR0_COMMAND_ENA_RX_INT:
398371               chan->int_on_next_rx = TRUE;
399               interrupt_check(machine, sio);
372               interrupt_check(device);
400373               break;
401374
402375            case SIO_WR0_COMMAND_RES_TX_INT:
403376               sio->int_state[INT_CHA_TRANSMIT - 4*ch] &= ~Z80_DAISY_INT;
404               interrupt_check(machine, sio);
377               interrupt_check(device);
405378               break;
406379
407380            case SIO_WR0_COMMAND_RES_ERROR:
408381               sio->int_state[INT_CHA_ERROR - 4*ch] &= ~Z80_DAISY_INT;
409               interrupt_check(machine, sio);
382               interrupt_check(device);
410383               break;
411384         }
412385         break;
413386
414387      /* SIO write register 1 */
415388      case 1:
416         interrupt_check(machine, sio);
389         interrupt_check(device);
417390         break;
418391
419392      /* SIO write register 5 */
420393      case 5:
421394         if (((old ^ data) & SIO_WR5_DTR) && sio->dtr_changed_cb)
422            (*sio->dtr_changed_cb)(machine, ch, (data & SIO_WR5_DTR) != 0);
395            (*sio->dtr_changed_cb)(device, ch, (data & SIO_WR5_DTR) != 0);
423396         if (((old ^ data) & SIO_WR5_SEND_BREAK) && sio->break_changed_cb)
424            (*sio->break_changed_cb)(machine, ch, (data & SIO_WR5_SEND_BREAK) != 0);
397            (*sio->break_changed_cb)(device, ch, (data & SIO_WR5_SEND_BREAK) != 0);
425398         if (((old ^ data) & SIO_WR5_RTS) && sio->rts_changed_cb)
426            (*sio->rts_changed_cb)(machine, ch, (data & SIO_WR5_RTS) != 0);
399            (*sio->rts_changed_cb)(device, ch, (data & SIO_WR5_RTS) != 0);
427400         break;
428401   }
429402}
r3352r3353
433406    z80sio_c_r - read from a control register
434407-------------------------------------------------*/
435408
436UINT8 z80sio_c_r(int which, int ch)
409READ8_DEVICE_HANDLER( z80sio_c_r )
437410{
438   z80sio *sio = sios + which;
411   z80sio *sio = get_safe_token(device);
412   int ch = offset & 1;
439413   sio_channel *chan = &sio->chan[ch];
440414   int reg = chan->regs[0] & 7;
441415   UINT8 result = chan->status[reg];
r3352r3353
446420      /* SIO read register 0 */
447421      case 0:
448422         result &= ~SIO_RR0_INT_PENDING;
449         if (z80sio_irq_state(which) & Z80_DAISY_INT)
423         if (z80sio_irq_state(device) & Z80_DAISY_INT)
450424            result |= SIO_RR0_INT_PENDING;
451425         break;
452426   }
r3352r3353
467441    z80sio_d_w - write to a data register
468442-------------------------------------------------*/
469443
470void z80sio_d_w(running_machine *machine, int which, int ch, UINT8 data)
444WRITE8_DEVICE_HANDLER( z80sio_d_w )
471445{
472   z80sio *sio = sios + which;
446   z80sio *sio = get_safe_token(device);
447   int ch = offset & 1;
473448   sio_channel *chan = &sio->chan[ch];
474449
475450   VPRINTF(("%04X:sio_data_w(%c) = %02X\n", activecpu_get_pc(), 'A' + ch, data));
r3352r3353
483458
484459   /* reset the transmit interrupt */
485460   sio->int_state[INT_CHA_TRANSMIT - 4*ch] &= ~Z80_DAISY_INT;
486   interrupt_check(machine, sio);
461   interrupt_check(device);
487462
488463   /* stash the character */
489464   chan->outbuf = data;
r3352r3353
494469    z80sio_d_r - read from a data register
495470-------------------------------------------------*/
496471
497UINT8 z80sio_d_r(running_machine *machine, int which, int ch)
472READ8_DEVICE_HANDLER( z80sio_d_r )
498473{
499   z80sio *sio = sios + which;
474   z80sio *sio = get_safe_token(device);
475   int ch = offset & 1;
500476   sio_channel *chan = &sio->chan[ch];
501477
502478   /* update the status register */
r3352r3353
504480
505481   /* reset the receive interrupt */
506482   sio->int_state[INT_CHA_RECEIVE - 4*ch] &= ~Z80_DAISY_INT;
507   interrupt_check(machine, sio);
483   interrupt_check(device);
508484
509485   VPRINTF(("%04X:sio_data_r(%c) = %02X\n", activecpu_get_pc(), 'A' + ch, chan->inbuf));
510486
r3352r3353
522498    line
523499-------------------------------------------------*/
524500
525int z80sio_get_dtr(int which, int ch)
501READ8_DEVICE_HANDLER( z80sio_get_dtr )
526502{
527   z80sio *sio = sios + which;
528   sio_channel *chan = &sio->chan[ch];
503   z80sio *sio = get_safe_token(device);
504   sio_channel *chan = &sio->chan[offset & 1];
529505   return ((chan->regs[5] & SIO_WR5_DTR) != 0);
530506}
531507
r3352r3353
535511    line
536512-------------------------------------------------*/
537513
538int z80sio_get_rts(int which, int ch)
514READ8_DEVICE_HANDLER( z80sio_get_rts )
539515{
540   z80sio *sio = sios + which;
541   sio_channel *chan = &sio->chan[ch];
516   z80sio *sio = get_safe_token(device);
517   sio_channel *chan = &sio->chan[offset & 1];
542518   return ((chan->regs[5] & SIO_WR5_RTS) != 0);
543519}
544520
r3352r3353
550526
551527static TIMER_CALLBACK( change_input_line )
552528{
553   z80sio *sio = sios + ((param >> 1) & 0x3f);
529   const device_config *device = ptr;
530   z80sio *sio = get_safe_token(device);
554531   sio_channel *chan = &sio->chan[param & 1];
555532   UINT8 line = (param >> 8) & 0xff;
556533   int state = (param >> 7) & 1;
r3352r3353
571548   if (((old ^ chan->status[0]) & line) && (chan->regs[1] & SIO_WR1_STATUSINT_ENABLE))
572549   {
573550      sio->int_state[INT_CHA_STATUS - 4*ch] |= Z80_DAISY_INT;
574      interrupt_check(machine, sio);
551      interrupt_check(device);
575552   }
576553}
577554
r3352r3353
581558    line
582559-------------------------------------------------*/
583560
584void z80sio_set_cts(int which, int ch, int state)
561WRITE8_DEVICE_HANDLER( z80sio_set_cts )
585562{
586563   /* operate deferred */
587   timer_call_after_resynch(NULL, (SIO_RR0_CTS << 8) + (state != 0) * 0x80 + which * 2 + ch, change_input_line);
564   void *ptr = (void *)device;
565   timer_call_after_resynch(ptr, (SIO_RR0_CTS << 8) + (data != 0) * 0x80 + (offset & 1), change_input_line);
588566}
589567
590568
r3352r3353
593571    line
594572-------------------------------------------------*/
595573
596void z80sio_set_dcd(int which, int ch, int state)
574WRITE8_DEVICE_HANDLER( z80sio_set_dcd )
597575{
598576   /* operate deferred */
599   timer_call_after_resynch(NULL, (SIO_RR0_DCD << 8) + (state != 0) * 0x80 + which * 2 + ch, change_input_line);
577   void *ptr = (void *)device;
578   timer_call_after_resynch(ptr, (SIO_RR0_DCD << 8) + (data != 0) * 0x80 + (offset & 1), change_input_line);
600579}
601580
602581
r3352r3353
605584    input lines
606585-------------------------------------------------*/
607586
608void z80sio_receive_data(int which, int ch, UINT8 data)
587WRITE8_DEVICE_HANDLER( z80sio_receive_data )
609588{
610   z80sio *sio = sios + which;
611   sio_channel *chan = &sio->chan[ch];
589   z80sio *sio = get_safe_token(device);
590   sio_channel *chan = &sio->chan[offset & 1];
612591   int newinptr;
613592
614593   /* put it on the queue */
r3352r3353
630609
631610static TIMER_CALLBACK( serial_callback )
632611{
633   z80sio *sio = sios + (param >> 1);
634   sio_channel *chan = &sio->chan[param & 1];
635   int ch = param & 1;
612   const device_config *device = ptr;
613   z80sio *sio = get_safe_token(device);
614   sio_channel *chan = &sio->chan[param];
615   int ch = param;
636616   int data = -1;
637617
638618   /* first perform any outstanding transmits */
r3352r3353
642622
643623      /* actually transmit the character */
644624      if (sio->transmit_cb != NULL)
645         (*sio->transmit_cb)(machine, ch, chan->outbuf);
625         (*sio->transmit_cb)(device, ch, chan->outbuf);
646626
647627      /* update the status register */
648628      chan->status[0] |= SIO_RR0_TX_BUFFER_EMPTY;
r3352r3353
651631      if (chan->regs[1] & SIO_WR1_TXINT_ENABLE)
652632      {
653633         sio->int_state[INT_CHA_TRANSMIT - 4*ch] |= Z80_DAISY_INT;
654         interrupt_check(machine, sio);
634         interrupt_check(device);
655635      }
656636
657637      /* reset the output buffer */
r3352r3353
660640
661641   /* ask the polling callback if there is data to receive */
662642   if (sio->receive_poll_cb != NULL)
663      data = (*sio->receive_poll_cb)(ch);
643      data = (*sio->receive_poll_cb)(device, ch);
664644
665645   /* if we have buffered data, pull it */
666646   if (chan->receive_inptr != chan->receive_outptr)
r3352r3353
695675         case SIO_WR1_RXINT_ALL_NOPARITY:
696676         case SIO_WR1_RXINT_ALL_PARITY:
697677            sio->int_state[INT_CHA_RECEIVE - 4*ch] |= Z80_DAISY_INT;
698            interrupt_check(machine, sio);
678            interrupt_check(device);
699679            break;
700680      }
701681      chan->int_on_next_rx = FALSE;
r3352r3353
721701};
722702
723703
724int z80sio_irq_state(int which)
704static int z80sio_irq_state(const device_config *device)
725705{
726   z80sio *sio = sios + which;
706   z80sio *sio = get_safe_token(device);
727707   int state = 0;
728708   int i;
729709
r3352r3353
749729}
750730
751731
752int z80sio_irq_ack(int which)
732static int z80sio_irq_ack(const device_config *device)
753733{
754   z80sio *sio = sios + which;
734   z80sio *sio = get_safe_token(device);
755735   int i;
756736
757737   /* loop over all interrupt sources */
r3352r3353
766746
767747         /* clear interrupt, switch to the IEO state, and update the IRQs */
768748         sio->int_state[inum] = Z80_DAISY_IEO;
769         interrupt_check(Machine, sio);
749         interrupt_check(device);
770750         return sio->chan[1].regs[2] + inum * 2;
771751      }
772752   }
r3352r3353
776756}
777757
778758
779void z80sio_irq_reti(int which)
759static void z80sio_irq_reti(const device_config *device)
780760{
781   z80sio *sio = sios + which;
761   z80sio *sio = get_safe_token(device);
782762   int i;
783763
784764   /* loop over all interrupt sources */
r3352r3353
793773
794774         /* clear the IEO state and update the IRQs */
795775         sio->int_state[inum] &= ~Z80_DAISY_IEO;
796         interrupt_check(Machine, sio);
776         interrupt_check(device);
797777         return;
798778      }
799779   }
800780
801781   logerror("z80sio_irq_reti: failed to find an interrupt to clear IEO on!\n");
802782}
783
784
785static DEVICE_START( z80sio )
786{
787   const z80sio_interface *intf = device->static_config;
788   z80sio *sio = get_safe_token(device);
789   void *ptr = (void *)device;
790   int cpunum = -1;
791
792   if (intf->cpu != NULL)
793      cpunum = mame_find_cpu_index(device->machine, intf->cpu);
794   if (cpunum != -1)
795      sio->clock = device->machine->config->cpu[cpunum].clock;
796   else
797      sio->clock = intf->baseclock;
798
799   sio->chan[0].receive_timer = timer_alloc(serial_callback, ptr);
800   sio->chan[1].receive_timer = timer_alloc(serial_callback, ptr);
801
802   sio->irq_cb = intf->irq_cb;
803   sio->dtr_changed_cb = intf->dtr_changed_cb;
804   sio->rts_changed_cb = intf->rts_changed_cb;
805   sio->break_changed_cb = intf->break_changed_cb;
806   sio->transmit_cb = intf->transmit_cb;
807   sio->receive_poll_cb = intf->receive_poll_cb;
808
809   return DEVICE_START_OK;
810}
811
812
813static DEVICE_RESET( z80sio )
814{
815   int ch;
816
817   /* loop over channels */
818   for (ch = 0; ch < 2; ch++)
819      reset_channel(device, ch);
820}
821
822
823static DEVICE_SET_INFO( z80sio )
824{
825   switch (state)
826   {
827      /* no parameters to set */
828   }
829}
830
831
832DEVICE_GET_INFO( z80sio )
833{
834   switch (state)
835   {
836      /* --- the following bits of info are returned as 64-bit signed integers --- */
837      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(z80sio);            break;
838      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                     break;
839      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;      break;
840
841      /* --- the following bits of info are returned as pointers to data or functions --- */
842      case DEVINFO_FCT_SET_INFO:                  info->set_info = DEVICE_SET_INFO_NAME(z80sio); break;
843      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(z80sio);break;
844      case DEVINFO_FCT_STOP:                     /* Nothing */                     break;
845      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(z80sio);break;
846      case DEVINFO_FCT_IRQ_STATE:                  info->f = (genf *)z80sio_irq_state;      break;
847      case DEVINFO_FCT_IRQ_ACK:                  info->f = (genf *)z80sio_irq_ack;      break;
848      case DEVINFO_FCT_IRQ_RETI:                  info->f = (genf *)z80sio_irq_reti;      break;
849
850      /* --- the following bits of info are returned as NULL-terminated strings --- */
851      case DEVINFO_STR_NAME:                     info->s = "Zilog Z80 SIO";            break;
852      case DEVINFO_STR_FAMILY:                  info->s = "Z80";                  break;
853      case DEVINFO_STR_VERSION:                  info->s = "1.0";                  break;
854      case DEVINFO_STR_SOURCE_FILE:               info->s = __FILE__;                  break;
855      case DEVINFO_STR_CREDITS:                  info->s = "Copyright Nicola Salmoria and the MAME Team"; break;
856   }
857}
858
src/emu/machine/z80sio.h
r3352r3353
77
88***************************************************************************/
99
10/***************************************************************************
11    CONSTANTS
12***************************************************************************/
10#ifndef __Z80SIO_H__
11#define __Z80SIO_H__
1312
14#define MAX_SIO         2
1513
16
17
1814/***************************************************************************
1915    TYPE DEFINITIONS
2016***************************************************************************/
r3352r3353
2218typedef struct _z80sio_interface z80sio_interface;
2319struct _z80sio_interface
2420{
21   const char *cpu;                  /* CPU whose clock we use for our base */
2522   int baseclock;
26   void (*irq_cb)(running_machine *machine, int state);
27   write8_machine_func dtr_changed_cb;
28   write8_machine_func rts_changed_cb;
29   write8_machine_func break_changed_cb;
30   write8_machine_func transmit_cb;
31   int (*receive_poll_cb)(int which);
23   void (*irq_cb)(const device_config *device, int state);
24   write8_device_func dtr_changed_cb;
25   write8_device_func rts_changed_cb;
26   write8_device_func break_changed_cb;
27   write8_device_func transmit_cb;
28   int (*receive_poll_cb)(const device_config *device, int channel);
3229};
3330
3431
3532
3633/***************************************************************************
37    INITIALIZATION/CONFIGURATION
34    DEVICE CONFIGURATION MACROS
3835***************************************************************************/
3936
40void z80sio_init(int which, z80sio_interface *intf);
41void z80sio_reset(int which);
37#define MDRV_Z80SIO_ADD(_tag, _intrf) \
38   MDRV_DEVICE_ADD(_tag, Z80SIO) \
39   MDRV_DEVICE_CONFIG(_intrf)
4240
41#define MDRV_Z80SIO_REMOVE(_tag) \
42   MDRV_DEVICE_REMOVE(_tag, Z80SIO)
4343
4444
45
4546/***************************************************************************
4647    CONTROL REGISTER READ/WRITE
4748***************************************************************************/
4849
49void z80sio_c_w(running_machine *machine, int which, int ch, UINT8 data);
50UINT8 z80sio_c_r(int which, int ch);
50WRITE8_DEVICE_HANDLER( z80sio_c_w );
51READ8_DEVICE_HANDLER( z80sio_c_r );
5152
5253
5354
r3352r3353
5556    DATA REGISTER READ/WRITE
5657***************************************************************************/
5758
58void z80sio_d_w(running_machine *machine, int which, int ch, UINT8 data);
59UINT8 z80sio_d_r(running_machine *machine, int which, int ch);
59WRITE8_DEVICE_HANDLER( z80sio_d_w );
60READ8_DEVICE_HANDLER( z80sio_d_r );
6061
6162
6263
r3352r3353
6465    CONTROL LINE READ/WRITE
6566***************************************************************************/
6667
67int z80sio_get_dtr(int which, int ch);
68int z80sio_get_rts(int which, int ch);
69void z80sio_set_cts(int which, int ch, int state);
70void z80sio_set_dcd(int which, int ch, int state);
71void z80sio_receive_data(int which, int ch, UINT8 data);
68READ8_DEVICE_HANDLER( z80sio_get_dtr );
69READ8_DEVICE_HANDLER( z80sio_get_rts );
70WRITE8_DEVICE_HANDLER( z80sio_set_cts );
71WRITE8_DEVICE_HANDLER( z80sio_set_dcd );
72WRITE8_DEVICE_HANDLER( z80sio_receive_data );
7273
7374
75/* ----- device interface ----- */
7476
75/***************************************************************************
76    DAISY CHAIN INTERFACE
77***************************************************************************/
77#define Z80SIO DEVICE_GET_INFO_NAME(z80sio)
78DEVICE_GET_INFO( z80sio );
7879
79int z80sio_irq_state(int which);
80int z80sio_irq_ack(int which);
81void z80sio_irq_reti(int which);
80#endif
src/emu/machine/z80ctc.c
r3352r3353
1010***************************************************************************/
1111
1212#include "driver.h"
13#include "deprecat.h"
1413#include "z80ctc.h"
1514#include "cpu/z80/z80.h"
1615#include "cpu/z80/z80daisy.h"
r3352r3353
7372    TYPE DEFINITIONS
7473***************************************************************************/
7574
75typedef struct _ctc_channel ctc_channel;
76struct _ctc_channel
77{
78   write8_device_func    zc;               /* zero crossing callbacks */
79   UINT8            notimer;         /* no timer masks */
80   UINT16             mode;            /* current mode */
81   UINT16             tconst;            /* time constant */
82   UINT16             down;            /* down counter (clock mode only) */
83   UINT8             extclk;            /* current signal from the external clock */
84   emu_timer *         timer;            /* array of active timers */
85   UINT8            int_state;         /* interrupt status (for daisy chain) */
86};
87
88
7689typedef struct _z80ctc z80ctc;
7790struct _z80ctc
7891{
79   UINT8 vector;            /* interrupt vector */
80   UINT32 clock;            /* system clock */
81   attotime period16;         /* 16/system clock */
82   attotime period256;      /* 256/system clock */
83   void (*intr)(running_machine *machine, int which);   /* interrupt callback */
84   write8_machine_func zc[4];      /* zero crossing callbacks */
85   UINT8 notimer;            /* no timer masks */
86   UINT16 mode[4];            /* current mode */
87   UINT16 tconst[4];         /* time constant */
88   UINT16 down[4];            /* down counter (clock mode only) */
89   UINT8 extclk[4];         /* current signal from the external clock */
90   emu_timer *timer[4];            /* array of active timers */
91   UINT8 int_state[4];         /* interrupt status (for daisy chain) */
92   UINT8            vector;            /* interrupt vector */
93   UINT32            clock;            /* system clock */
94   attotime         period16;         /* 16/system clock */
95   attotime         period256;         /* 256/system clock */
96   void (*intr)(const device_config *device, int which);   /* interrupt callback */
97   ctc_channel         channel[4];         /* data for each channel */
9298};
9399
94100
95101
96102/***************************************************************************
97    GLOBAL VARIABLES
103    FUNCTION PROTOTYPES
98104***************************************************************************/
99105
100static z80ctc ctcs[MAX_CTC];
106static int z80ctc_irq_state(const device_config *device);
107static int z80ctc_irq_ack(const device_config *device);
108static void z80ctc_irq_reti(const device_config *device);
101109
102110
103111
104112/***************************************************************************
113    INLINE FUNCTIONS
114***************************************************************************/
115
116INLINE z80ctc *get_safe_token(const device_config *device)
117{
118   assert(device != NULL);
119   assert(device->token != NULL);
120   assert(device->type == Z80CTC);
121   return (z80ctc *)device->token;
122}
123
124
125
126/***************************************************************************
105127    INTERNAL STATE MANAGEMENT
106128***************************************************************************/
107129
108static void interrupt_check(running_machine *machine, int which)
130static void interrupt_check(const device_config *device)
109131{
110   z80ctc *ctc = ctcs + which;
132   z80ctc *ctc = get_safe_token(device);
111133
112134   /* if we have a callback, update it with the current state */
113   if (ctc->intr)
114      (*ctc->intr)(machine, (z80ctc_irq_state(which) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE);
135   if (ctc->intr != NULL)
136      (*ctc->intr)(device, (z80ctc_irq_state(device) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE);
115137}
116138
117139
118140static TIMER_CALLBACK( timercallback )
119141{
120   int which = param >> 2;
121   int ch = param & 3;
122   z80ctc *ctc = ctcs + which;
142   const device_config *device = ptr;
143   z80ctc *ctc = get_safe_token(device);
144   ctc_channel *channel = &ctc->channel[param];
123145
124146   /* down counter has reached zero - see if we should interrupt */
125   if ((ctc->mode[ch] & INTERRUPT) == INTERRUPT_ON)
147   if ((channel->mode & INTERRUPT) == INTERRUPT_ON)
126148   {
127      ctc->int_state[ch] |= Z80_DAISY_INT;
128      VPRINTF(("CTC timer ch%d\n", ch));
129      interrupt_check(machine, which);
149      channel->int_state |= Z80_DAISY_INT;
150      VPRINTF(("CTC timer ch%d\n", param));
151      interrupt_check(device);
130152   }
131153
132154   /* generate the clock pulse */
133   if (ctc->zc[ch])
155   if (channel->zc != NULL)
134156   {
135      (*ctc->zc[ch])(machine,0,1);
136      (*ctc->zc[ch])(machine,0,0);
157      (*channel->zc)(device, 0, 1);
158      (*channel->zc)(device, 0, 0);
137159   }
138160
139161   /* reset the down counter */
140   ctc->down[ch] = ctc->tconst[ch];
162   channel->down = channel->tconst;
141163}
142164
143165
r3352r3353
146168    INITIALIZATION/CONFIGURATION
147169***************************************************************************/
148170
149void z80ctc_init(int which, z80ctc_interface *intf)
171attotime z80ctc_getperiod(const device_config *device, int ch)
150172{
151   z80ctc *ctc = &ctcs[which];
152
153   assert(which < MAX_CTC);
154
155   memset(ctc, 0, sizeof(*ctc));
156
157   ctc->clock = intf->baseclock;
158   ctc->period16 = attotime_mul(ATTOTIME_IN_HZ(intf->baseclock), 16);
159   ctc->period256 = attotime_mul(ATTOTIME_IN_HZ(intf->baseclock), 256);
160   ctc->notimer = intf->notimer;
161   ctc->intr = intf->intr;
162   ctc->timer[0] = timer_alloc(timercallback, NULL);
163   ctc->timer[1] = timer_alloc(timercallback, NULL);
164   ctc->timer[2] = timer_alloc(timercallback, NULL);
165   ctc->timer[3] = timer_alloc(timercallback, NULL);
166   ctc->zc[0] = intf->zc0;
167   ctc->zc[1] = intf->zc1;
168   ctc->zc[2] = intf->zc2;
169   ctc->zc[3] = 0;
170   z80ctc_reset(which);
171
172    state_save_register_item("z80ctc", which, ctc->vector);
173    state_save_register_item_array("z80ctc", which, ctc->mode);
174    state_save_register_item_array("z80ctc", which, ctc->tconst);
175    state_save_register_item_array("z80ctc", which, ctc->down);
176    state_save_register_item_array("z80ctc", which, ctc->extclk);
177    state_save_register_item_array("z80ctc", which, ctc->int_state);
178}
179
180
181void z80ctc_reset(int which)
182{
183   z80ctc *ctc = ctcs + which;
184   int i;
185
186   /* set up defaults */
187   for (i = 0; i < 4; i++)
188   {
189      ctc->mode[i] = RESET_ACTIVE;
190      ctc->tconst[i] = 0x100;
191      timer_adjust_oneshot(ctc->timer[i], attotime_never, 0);
192      ctc->int_state[i] = 0;
193   }
194   interrupt_check(Machine, which);
195   VPRINTF(("CTC Reset\n"));
196}
197
198
199attotime z80ctc_getperiod(int which, int ch)
200{
201   z80ctc *ctc = ctcs + which;
173   z80ctc *ctc = get_safe_token(device);
174   ctc_channel *channel = &ctc->channel[ch];
202175   attotime period;
203176
204177   /* if reset active, no period */
205   if ((ctc->mode[ch] & RESET) == RESET_ACTIVE)
178   if ((channel->mode & RESET) == RESET_ACTIVE)
206179      return attotime_zero;
207180
208181   /* if counter mode, no real period */
209   if ((ctc->mode[ch] & MODE) == MODE_COUNTER)
182   if ((channel->mode & MODE) == MODE_COUNTER)
210183   {
211184      logerror("CTC %d is CounterMode : Can't calculate period\n", ch );
212185      return attotime_zero;
213186   }
214187
215188   /* compute the period */
216   period = ((ctc->mode[ch] & PRESCALER) == PRESCALER_16) ? ctc->period16 : ctc->period256;
217   return attotime_mul(period, ctc->tconst[ch]);
189   period = ((channel->mode & PRESCALER) == PRESCALER_16) ? ctc->period16 : ctc->period256;
190   return attotime_mul(period, channel->tconst);
218191}
219192
220193
r3352r3353
223196    WRITE HANDLERS
224197***************************************************************************/
225198
226void z80ctc_w(int which, int ch, UINT8 data)
199WRITE8_DEVICE_HANDLER( z80ctc_w )
227200{
228   z80ctc *ctc = ctcs + which;
201   z80ctc *ctc = get_safe_token(device);
202   int ch = offset & 3;
203   ctc_channel *channel = &ctc->channel[ch];
229204   int mode;
230205
231206   /* get the current mode */
232   mode = ctc->mode[ch];
207   mode = channel->mode;
233208
234209   /* if we're waiting for a time constant, this is it */
235210   if ((mode & CONSTANT) == CONSTANT_LOAD)
r3352r3353
237212      VPRINTF(("CTC ch.%d constant = %02x\n", ch, data));
238213
239214      /* set the time constant (0 -> 0x100) */
240      ctc->tconst[ch] = data ? data : 0x100;
215      channel->tconst = data ? data : 0x100;
241216
242217      /* clear the internal mode -- we're no longer waiting */
243      ctc->mode[ch] &= ~CONSTANT;
218      channel->mode &= ~CONSTANT;
244219
245220      /* also clear the reset, since the constant gets it going again */
246      ctc->mode[ch] &= ~RESET;
221      channel->mode &= ~RESET;
247222
248223      /* if we're in timer mode.... */
249224      if ((mode & MODE) == MODE_TIMER)
r3352r3353
251226         /* if we're triggering on the time constant, reset the down counter now */
252227         if ((mode & TRIGGER) == TRIGGER_AUTO)
253228         {
254            if (!(ctc->notimer & (1<<ch)))
229            if (!channel->notimer)
255230            {
256231               attotime period = ((mode & PRESCALER) == PRESCALER_16) ? ctc->period16 : ctc->period256;
257               period = attotime_mul(period, ctc->tconst[ch]);
232               period = attotime_mul(period, channel->tconst);
258233
259               timer_adjust_periodic(ctc->timer[ch], period, (which << 2) + ch, period);
234               timer_adjust_periodic(channel->timer, period, ch, period);
260235            }
261236            else
262               timer_adjust_oneshot(ctc->timer[ch], attotime_never, 0);
237               timer_adjust_oneshot(channel->timer, attotime_never, 0);
263238         }
264239
265240         /* else set the bit indicating that we're waiting for the appropriate trigger */
266241         else
267            ctc->mode[ch] |= WAITING_FOR_TRIG;
242            channel->mode |= WAITING_FOR_TRIG;
268243      }
269244
270245      /* also set the down counter in case we're clocking externally */
271      ctc->down[ch] = ctc->tconst[ch];
246      channel->down = channel->tconst;
272247
273248      /* all done here */
274249      return;
r3352r3353
292267   if ((data & CONTROL) == CONTROL_WORD)
293268   {
294269      /* set the new mode */
295      ctc->mode[ch] = data;
270      channel->mode = data;
296271      VPRINTF(("CTC ch.%d mode = %02x\n", ch, data));
297272
298273      /* if we're being reset, clear out any pending timers for this channel */
299274      if ((data & RESET) == RESET_ACTIVE)
300275      {
301         timer_adjust_oneshot(ctc->timer[ch], attotime_never, 0);
276         timer_adjust_oneshot(channel->timer, attotime_never, 0);
302277         /* note that we don't clear the interrupt state here! */
303278      }
304279
r3352r3353
307282   }
308283}
309284
310WRITE8_HANDLER( z80ctc_0_w ) { z80ctc_w(0, offset, data); }
311WRITE8_HANDLER( z80ctc_1_w ) { z80ctc_w(1, offset, data); }
312285
313286
314
315287/***************************************************************************
316288    READ HANDLERS
317289***************************************************************************/
318290
319UINT8 z80ctc_r(int which, int ch)
291READ8_DEVICE_HANDLER( z80ctc_r )
320292{
321   z80ctc *ctc = ctcs + which;
293   z80ctc *ctc = get_safe_token(device);
294   int ch = offset & 3;
295   ctc_channel *channel = &ctc->channel[ch];
322296
323297   /* if we're in counter mode, just return the count */
324   if ((ctc->mode[ch] & MODE) == MODE_COUNTER || (ctc->mode[ch] & WAITING_FOR_TRIG))
325      return ctc->down[ch];
298   if ((channel->mode & MODE) == MODE_COUNTER || (channel->mode & WAITING_FOR_TRIG))
299      return channel->down;
326300
327301   /* else compute the down counter value */
328302   else
329303   {
330      attotime period = ((ctc->mode[ch] & PRESCALER) == PRESCALER_16) ? ctc->period16 : ctc->period256;
304      attotime period = ((channel->mode & PRESCALER) == PRESCALER_16) ? ctc->period16 : ctc->period256;
331305
332306      VPRINTF(("CTC clock %f\n",ATTOSECONDS_TO_HZ(period.attoseconds)));
333307
334      if (ctc->timer[ch])
335         return ((int)(attotime_to_double(timer_timeleft(ctc->timer[ch])) * attotime_to_double(period)) + 1) & 0xff;
308      if (channel->timer != NULL)
309         return ((int)(attotime_to_double(timer_timeleft(channel->timer)) * attotime_to_double(period)) + 1) & 0xff;
336310      else
337311         return 0;
338312   }
339313}
340314
341READ8_HANDLER( z80ctc_0_r ) { return z80ctc_r(0, offset); }
342READ8_HANDLER( z80ctc_1_r ) { return z80ctc_r(1, offset); }
343315
344316
345
346317/***************************************************************************
347318    EXTERNAL TRIGGERS
348319***************************************************************************/
349320
350void z80ctc_trg_w(running_machine *machine, int which, int ch, UINT8 data)
321void z80ctc_trg_w(const device_config *device, int ch, UINT8 data)
351322{
352   z80ctc *ctc = ctcs + which;
323   z80ctc *ctc = get_safe_token(device);
324   ctc_channel *channel = &ctc->channel[ch];
353325
354326   /* normalize data */
355327   data = data ? 1 : 0;
356328
357329   /* see if the trigger value has changed */
358   if (data != ctc->extclk[ch])
330   if (data != channel->extclk)
359331   {
360      ctc->extclk[ch] = data;
332      channel->extclk = data;
361333
362334      /* see if this is the active edge of the trigger */
363      if (((ctc->mode[ch] & EDGE) == EDGE_RISING && data) || ((ctc->mode[ch] & EDGE) == EDGE_FALLING && !data))
335      if (((channel->mode & EDGE) == EDGE_RISING && data) || ((channel->mode & EDGE) == EDGE_FALLING && !data))
364336      {
365337         /* if we're waiting for a trigger, start the timer */
366         if ((ctc->mode[ch] & WAITING_FOR_TRIG) && (ctc->mode[ch] & MODE) == MODE_TIMER)
338         if ((channel->mode & WAITING_FOR_TRIG) && (channel->mode & MODE) == MODE_TIMER)
367339         {
368            if (!(ctc->notimer & (1<<ch)))
340            if (!channel->notimer)
369341            {
370               attotime period = ((ctc->mode[ch] & PRESCALER) == PRESCALER_16) ? ctc->period16 : ctc->period256;
371               period = attotime_mul(period, ctc->tconst[ch]);
342               attotime period = ((channel->mode & PRESCALER) == PRESCALER_16) ? ctc->period16 : ctc->period256;
343               period = attotime_mul(period, channel->tconst);
372344
373345               VPRINTF(("CTC period %s\n", attotime_string(period, 9)));
374               timer_adjust_periodic(ctc->timer[ch], period, (which << 2) + ch, period);
346               timer_adjust_periodic(channel->timer, period, ch, period);
375347            }
376348            else
377349            {
378350               VPRINTF(("CTC disabled\n"));
379351
380               timer_adjust_oneshot(ctc->timer[ch], attotime_never, 0);
352               timer_adjust_oneshot(channel->timer, attotime_never, 0);
381353            }
382354         }
383355
384356         /* we're no longer waiting */
385         ctc->mode[ch] &= ~WAITING_FOR_TRIG;
357         channel->mode &= ~WAITING_FOR_TRIG;
386358
387359         /* if we're clocking externally, decrement the count */
388         if ((ctc->mode[ch] & MODE) == MODE_COUNTER)
360         if ((channel->mode & MODE) == MODE_COUNTER)
389361         {
390            ctc->down[ch]--;
362            channel->down--;
391363
392364            /* if we hit zero, do the same thing as for a timer interrupt */
393            if (!ctc->down[ch])
394               timercallback(machine, NULL, (which << 2) + ch);
365            if (!channel->down)
366            {
367               void *ptr = (void *)device;
368               timercallback(device->machine, ptr, ch);
369            }
395370         }
396371      }
397372   }
398373}
374WRITE8_DEVICE_HANDLER( z80ctc_trg0_w ) { z80ctc_trg_w(device, 0, data); }
375WRITE8_DEVICE_HANDLER( z80ctc_trg1_w ) { z80ctc_trg_w(device, 1, data); }
376WRITE8_DEVICE_HANDLER( z80ctc_trg2_w ) { z80ctc_trg_w(device, 2, data); }
377WRITE8_DEVICE_HANDLER( z80ctc_trg3_w ) { z80ctc_trg_w(device, 3, data); }
399378
400WRITE8_HANDLER( z80ctc_0_trg0_w ) { z80ctc_trg_w(machine, 0, 0, data); }
401WRITE8_HANDLER( z80ctc_0_trg1_w ) { z80ctc_trg_w(machine, 0, 1, data); }
402WRITE8_HANDLER( z80ctc_0_trg2_w ) { z80ctc_trg_w(machine, 0, 2, data); }
403WRITE8_HANDLER( z80ctc_0_trg3_w ) { z80ctc_trg_w(machine, 0, 3, data); }
404WRITE8_HANDLER( z80ctc_1_trg0_w ) { z80ctc_trg_w(machine, 1, 0, data); }
405WRITE8_HANDLER( z80ctc_1_trg1_w ) { z80ctc_trg_w(machine, 1, 1, data); }
406WRITE8_HANDLER( z80ctc_1_trg2_w ) { z80ctc_trg_w(machine, 1, 2, data); }
407WRITE8_HANDLER( z80ctc_1_trg3_w ) { z80ctc_trg_w(machine, 1, 3, data); }
408379
409380
410
411381/***************************************************************************
412382    DAISY CHAIN INTERFACE
413383***************************************************************************/
414384
415int z80ctc_irq_state(int which)
385static int z80ctc_irq_state(const device_config *device)
416386{
417   z80ctc *ctc = ctcs + which;
387   z80ctc *ctc = get_safe_token(device);
418388   int state = 0;
419389   int ch;
420390
421   VPRINTF(("CTC IRQ state = %d%d%d%d\n", ctc->int_state[0], ctc->int_state[1], ctc->int_state[2], ctc->int_state[3]));
391   VPRINTF(("CTC IRQ state = %d%d%d%d\n", ctc->channel[0].int_state, ctc->channel[1].int_state, ctc->channel[2].int_state, ctc->channel[3].int_state));
422392
423393   /* loop over all channels */
424394   for (ch = 0; ch < 4; ch++)
425395   {
396      ctc_channel *channel = &ctc->channel[ch];
397
426398      /* if we're servicing a request, don't indicate more interrupts */
427      if (ctc->int_state[ch] & Z80_DAISY_IEO)
399      if (channel->int_state & Z80_DAISY_IEO)
428400      {
429401         state |= Z80_DAISY_IEO;
430402         break;
431403      }
432      state |= ctc->int_state[ch];
404      state |= channel->int_state;
433405   }
434406
435407   return state;
436408}
437409
438410
439int z80ctc_irq_ack(int which)
411static int z80ctc_irq_ack(const device_config *device)
440412{
441   z80ctc *ctc = ctcs + which;
413   z80ctc *ctc = get_safe_token(device);
442414   int ch;
443415
444416   /* loop over all channels */
445417   for (ch = 0; ch < 4; ch++)
418   {
419      ctc_channel *channel = &ctc->channel[ch];
446420
447421      /* find the first channel with an interrupt requested */
448      if (ctc->int_state[ch] & Z80_DAISY_INT)
422      if (channel->int_state & Z80_DAISY_INT)
449423      {
450424         VPRINTF(("CTC IRQAck ch%d\n", ch));
451425
452426         /* clear interrupt, switch to the IEO state, and update the IRQs */
453         ctc->int_state[ch] = Z80_DAISY_IEO;
454         interrupt_check(Machine, which);
427         channel->int_state = Z80_DAISY_IEO;
428         interrupt_check(device);
455429         return ctc->vector + ch * 2;
456430      }
431   }
457432
458433   logerror("z80ctc_irq_ack: failed to find an interrupt to ack!\n");
459434   return ctc->vector;
460435}
461436
462437
463void z80ctc_irq_reti(int which)
438static void z80ctc_irq_reti(const device_config *device)
464439{
465   z80ctc *ctc = ctcs + which;
440   z80ctc *ctc = get_safe_token(device);
466441   int ch;
467442
468443   /* loop over all channels */
469444   for (ch = 0; ch < 4; ch++)
445   {
446      ctc_channel *channel = &ctc->channel[ch];
470447
471448      /* find the first channel with an IEO pending */
472      if (ctc->int_state[ch] & Z80_DAISY_IEO)
449      if (channel->int_state & Z80_DAISY_IEO)
473450      {
474451         VPRINTF(("CTC IRQReti ch%d\n", ch));
475452
476453         /* clear the IEO state and update the IRQs */
477         ctc->int_state[ch] &= ~Z80_DAISY_IEO;
478         interrupt_check(Machine, which);
454         channel->int_state &= ~Z80_DAISY_IEO;
455         interrupt_check(device);
479456         return;
480457      }
458   }
481459
482460   logerror("z80ctc_irq_reti: failed to find an interrupt to clear IEO on!\n");
483461}
462
463static DEVICE_START( z80ctc )
464{
465   const z80ctc_interface *intf = device->static_config;
466   z80ctc *ctc = get_safe_token(device);
467   char unique_tag[30];
468   int cpunum = -1;
469   int ch;
470
471   if (intf->cpu != NULL)
472      cpunum = mame_find_cpu_index(device->machine, intf->cpu);
473   if (cpunum != -1)
474      ctc->clock = device->machine->config->cpu[cpunum].clock;
475   else
476      ctc->clock = intf->baseclock;
477   ctc->period16 = attotime_mul(ATTOTIME_IN_HZ(ctc->clock), 16);
478   ctc->period256 = attotime_mul(ATTOTIME_IN_HZ(ctc->clock), 256);
479   for (ch = 0; ch < 4; ch++)
480   {
481      ctc_channel *channel = &ctc->channel[ch];
482      void *ptr = (void *)device;
483      channel->notimer = (intf->notimer >> ch) & 1;
484      channel->timer = timer_alloc(timercallback, ptr);
485   }
486   ctc->intr = intf->intr;
487   ctc->channel[0].zc = intf->zc0;
488   ctc->channel[1].zc = intf->zc1;
489   ctc->channel[2].zc = intf->zc2;
490   ctc->channel[3].zc = NULL;
491
492   /* register for save states */
493   state_save_combine_module_and_tag(unique_tag, "z80ctc", device->tag);
494
495    state_save_register_item(unique_tag, 0, ctc->vector);
496    for (ch = 0; ch < 4; ch++)
497    {
498      ctc_channel *channel = &ctc->channel[ch];
499       state_save_register_item(unique_tag, ch, channel->mode);
500       state_save_register_item(unique_tag, ch, channel->tconst);
501       state_save_register_item(unique_tag, ch, channel->down);
502       state_save_register_item(unique_tag, ch, channel->extclk);
503       state_save_register_item(unique_tag, ch, channel->int_state);
504   }
505
506   return DEVICE_START_OK;
507}
508
509
510static DEVICE_RESET( z80ctc )
511{
512   z80ctc *ctc = get_safe_token(device);
513   int ch;
514
515   /* set up defaults */
516   for (ch = 0; ch < 4; ch++)
517   {
518      ctc_channel *channel = &ctc->channel[ch];
519      channel->mode = RESET_ACTIVE;
520      channel->tconst = 0x100;
521      timer_adjust_oneshot(channel->timer, attotime_never, 0);
522      channel->int_state = 0;
523   }
524   interrupt_check(device);
525   VPRINTF(("CTC Reset\n"));
526}
527
528
529static DEVICE_SET_INFO( z80ctc )
530{
531   switch (state)
532   {
533      /* no parameters to set */
534   }
535}
536
537
538DEVICE_GET_INFO( z80ctc )
539{
540   switch (state)
541   {
542      /* --- the following bits of info are returned as 64-bit signed integers --- */
543      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(z80ctc);            break;
544      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                     break;
545      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;      break;
546
547      /* --- the following bits of info are returned as pointers to data or functions --- */
548      case DEVINFO_FCT_SET_INFO:                  info->set_info = DEVICE_SET_INFO_NAME(z80ctc); break;
549      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(z80ctc);break;
550      case DEVINFO_FCT_STOP:                     /* Nothing */                     break;
551      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(z80ctc);break;
552      case DEVINFO_FCT_IRQ_STATE:                  info->f = (genf *)z80ctc_irq_state;      break;
553      case DEVINFO_FCT_IRQ_ACK:                  info->f = (genf *)z80ctc_irq_ack;      break;
554      case DEVINFO_FCT_IRQ_RETI:                  info->f = (genf *)z80ctc_irq_reti;      break;
555
556      /* --- the following bits of info are returned as NULL-terminated strings --- */
557      case DEVINFO_STR_NAME:                     info->s = "Zilog Z80 CTC";            break;
558      case DEVINFO_STR_FAMILY:                  info->s = "Z80";                  break;
559      case DEVINFO_STR_VERSION:                  info->s = "1.0";                  break;
560      case DEVINFO_STR_SOURCE_FILE:               info->s = __FILE__;                  break;
561      case DEVINFO_STR_CREDITS:                  info->s = "Copyright Nicola Salmoria and the MAME Team"; break;
562   }
563}
564
src/emu/machine/z80ctc.h
r3352r3353
77
88***************************************************************************/
99
10#ifndef __Z80CTC_H__
11#define __Z80CTC_H__
12
13
1014/***************************************************************************
1115    CONSTANTS
1216***************************************************************************/
1317
14#define MAX_CTC 2
15
1618#define NOTIMER_0 (1<<0)
1719#define NOTIMER_1 (1<<1)
1820#define NOTIMER_2 (1<<2)
r3352r3353
2426    TYPE DEFINITIONS
2527***************************************************************************/
2628
27typedef struct
29typedef struct _z80ctc_interface z80ctc_interface;
30struct _z80ctc_interface
2831{
29   int baseclock;                           /* timer clock */
30   int notimer;                         /* timer disablers */
31   void (*intr)(running_machine *machine, int which);             /* callback when change interrupt status */
32   write8_machine_func zc0;   /* ZC/TO0 callback */
33   write8_machine_func zc1;   /* ZC/TO1 callback */
34   write8_machine_func zc2;   /* ZC/TO2 callback */
35} z80ctc_interface;
32   const char *cpu;                  /* CPU whose clock we use for our base */
33   int baseclock;                     /* timer clock */
34   int notimer;                     /* timer disablers */
35   void (*intr)(const device_config *device, int which); /* callback when change interrupt status */
36   write8_device_func zc0;               /* ZC/TO0 callback */
37   write8_device_func zc1;               /* ZC/TO1 callback */
38   write8_device_func zc2;               /* ZC/TO2 callback */
39};
3640
3741
3842
3943/***************************************************************************
40    INITIALIZATION/CONFIGURATION
44    DEVICE CONFIGURATION MACROS
4145***************************************************************************/
4246
43void z80ctc_init(int which, z80ctc_interface *intf);
44void z80ctc_reset(int which);
45attotime z80ctc_getperiod (int which, int ch);
47#define MDRV_Z80CTC_ADD(_tag, _intrf) \
48   MDRV_DEVICE_ADD(_tag, Z80CTC) \
49   MDRV_DEVICE_CONFIG(_intrf)
4650
51#define MDRV_Z80CTC_REMOVE(_tag) \
52   MDRV_DEVICE_REMOVE(_tag, Z80CTC)
4753
4854
55
4956/***************************************************************************
50    WRITE HANDLERS
57    INITIALIZATION/CONFIGURATION
5158***************************************************************************/
5259
53void z80ctc_w(int which, int ch, UINT8 data);
54WRITE8_HANDLER( z80ctc_0_w );
55WRITE8_HANDLER( z80ctc_1_w );
60void z80ctc_reset(const device_config *device);
61attotime z80ctc_getperiod(const device_config *device, int ch);
5662
5763
5864
5965/***************************************************************************
60    READ HANDLERS
66    READ/WRITE HANDLERS
6167***************************************************************************/
6268
63UINT8 z80ctc_r(int which, int ch);
64READ8_HANDLER( z80ctc_0_r );
65READ8_HANDLER( z80ctc_1_r );
69WRITE8_DEVICE_HANDLER( z80ctc_w );
70READ8_DEVICE_HANDLER( z80ctc_r );
6671
6772
6873
r3352r3353
7075    EXTERNAL TRIGGERS
7176***************************************************************************/
7277
73void z80ctc_trg_w(running_machine *machine, int which, int trg, UINT8 data);
74WRITE8_HANDLER( z80ctc_0_trg0_w );
75WRITE8_HANDLER( z80ctc_0_trg1_w );
76WRITE8_HANDLER( z80ctc_0_trg2_w );
77WRITE8_HANDLER( z80ctc_0_trg3_w );
78WRITE8_HANDLER( z80ctc_1_trg0_w );
79WRITE8_HANDLER( z80ctc_1_trg1_w );
80WRITE8_HANDLER( z80ctc_1_trg2_w );
81WRITE8_HANDLER( z80ctc_1_trg3_w );
78void z80ctc_trg_w(const device_config *device, int trg, UINT8 data);
79WRITE8_DEVICE_HANDLER( z80ctc_trg0_w );
80WRITE8_DEVICE_HANDLER( z80ctc_trg1_w );
81WRITE8_DEVICE_HANDLER( z80ctc_trg2_w );
82WRITE8_DEVICE_HANDLER( z80ctc_trg3_w );
8283
8384
8485
85/***************************************************************************
86    DAISY CHAIN INTERFACE
87***************************************************************************/
86/* ----- device interface ----- */
8887
89int z80ctc_irq_state(int which);
90int z80ctc_irq_ack(int which);
91void z80ctc_irq_reti(int which);
88#define Z80CTC DEVICE_GET_INFO_NAME(z80ctc)
89DEVICE_GET_INFO( z80ctc );
90
91#endif
src/mess/video/abc80x.c
r3352r3353
455455
456456static MC6845_ON_VSYNC_CHANGED(abc800_vsync_changed)
457457{
458   z80dart_set_ri(0, vsync);
458   z80dart_set_ri(device_list_find_by_tag(device->machine->config->devicelist, Z80DART, "z80dart"), vsync);
459459}
460460
461461static MC6845_UPDATE_ROW( abc800c_update_row )
r3352r3353
555555
556556static MC6845_ON_VSYNC_CHANGED(abc802_vsync_changed)
557557{
558   z80dart_set_ri(0, vsync);
558   z80dart_set_ri(device_list_find_by_tag(device->machine->config->devicelist, Z80DART, "z80dart"), vsync);
559559}
560560
561561static MC6845_UPDATE_ROW( abc806_update_row )
r3352r3353
637637      abc806_v50_addr = 0;
638638   }
639639
640   z80dart_set_ri(0, vsync);
640   z80dart_set_ri(device_list_find_by_tag(device->machine->config->devicelist, Z80DART, "z80dart"), vsync);
641641}
642642
643643/* MC6845 Interfaces */
src/mess/includes/kc.h
r3352r3353
88#define KC_H_
99
1010#include "cpu/z80/z80daisy.h"
11#include "machine/z80ctc.h"
1112#include "machine/z80pio.h"
1213#include "devices/snapquik.h"
1314
r3352r3353
6768READ8_HANDLER(kc85_pio_control_r);
6869WRITE8_HANDLER(kc85_pio_control_w);
6970
70READ8_HANDLER(kc85_ctc_r);
71WRITE8_HANDLER(kc85_ctc_w);
71READ8_DEVICE_HANDLER(kc85_ctc_r);
72WRITE8_DEVICE_HANDLER(kc85_ctc_w);
7273
7374extern const z80pio_interface kc85_pio_intf;
74extern const struct z80_irq_daisy_chain kc85_daisy_chain[];
75extern const z80ctc_interface kc85_ctc_intf;
76extern const z80_daisy_chain kc85_daisy_chain[];
7577
7678
7779/*** MODULE SYSTEM ***/
r3352r3353
101103/* these are internal to the disc interface */
102104
103105/* disc hardware internal i/o */
104READ8_HANDLER(kc85_disk_hw_ctc_r);
106READ8_DEVICE_HANDLER(kc85_disk_hw_ctc_r);
105107/* disc hardware internal i/o */
106WRITE8_HANDLER(kc85_disk_hw_ctc_w);
108WRITE8_DEVICE_HANDLER(kc85_disk_hw_ctc_w);
107109/* 4-bit input latch: DMA Data Request, FDC Int, FDD Ready.. */
108110READ8_HANDLER(kc85_disc_hw_input_gate_r);
109111/* output port to set NEC765 terminal count input */
src/mess/includes/mbee.h
r3352r3353
1515MACHINE_START( mbee );
1616
1717extern UINT8 *mbee_workram;
18extern const struct z80_irq_daisy_chain mbee_daisy_chain[];
18extern const z80_daisy_chain mbee_daisy_chain[];
1919
2020INTERRUPT_GEN( mbee_interrupt );
2121
src/mess/includes/mtx.h
r3352r3353
88#define MTX_H_
99
1010#include "devices/snapquik.h"
11#include "machine/z80ctc.h"
12#include "machine/z80dart.h"
1113
1214
1315#define MTX_SYSTEM_CLOCK   XTAL_4MHz
r3352r3353
4345READ8_HANDLER( mtx_key_hi_r );
4446
4547/* Z80 CTC */
46READ8_HANDLER( mtx_ctc_r );
47WRITE8_HANDLER( mtx_ctc_w );
48extern const z80ctc_interface mtx_ctc_intf;
49READ8_DEVICE_HANDLER( mtx_ctc_r );
50WRITE8_DEVICE_HANDLER( mtx_ctc_w );
4851
4952/* Z80 Dart */
50READ8_HANDLER( mtx_dart_data_r );
51READ8_HANDLER( mtx_dart_control_r );
52WRITE8_HANDLER( mtx_dart_data_w );
53WRITE8_HANDLER( mtx_dart_control_w );
53extern const z80dart_interface mtx_dart_intf;
54READ8_DEVICE_HANDLER( mtx_dart_data_r );
55READ8_DEVICE_HANDLER( mtx_dart_control_r );
56WRITE8_DEVICE_HANDLER( mtx_dart_data_w );
57WRITE8_DEVICE_HANDLER( mtx_dart_control_w );
5458
5559
5660#endif /*MTX_H_*/
src/mess/includes/osborne1.h
r3352r3353
1010
1111/*----------- defined in machine/osborne1.c -----------*/
1212
13extern const struct z80_irq_daisy_chain osborne1_daisy_chain[];
14
1513WRITE8_HANDLER( osborne1_0000_w );
1614WRITE8_HANDLER( osborne1_1000_w );
1715READ8_HANDLER( osborne1_2000_r );
r3352r3353
2725MACHINE_START( osborne1 );
2826MACHINE_RESET( osborne1 );
2927
28/* Osborne1 specific daisy chain interface */
29#define OSBORNE1_DAISY   DEVICE_GET_INFO_NAME( osborne1_daisy )
30DEVICE_GET_INFO( osborne1_daisy );
3031
3132#endif /* OSBORNE1_H_ */
src/mess/machine/mbee.c
r3352r3353
3535UINT8 *mbee_workram;
3636
3737
38static void mbee_z80pio_reset(int which)
38const z80_daisy_chain mbee_daisy_chain[] =
3939{
40   z80pio_reset( mbee_z80pio );
41}
42
43static int mbee_z80pio_irq_state(int which)
44{
45   return z80pio_irq_state( mbee_z80pio );
46}
47
48static int mbee_z80pio_irq_ack(int which)
49{
50   return z80pio_irq_ack( mbee_z80pio );
51}
52
53static void mbee_z80pio_irq_reti(int which)
54{
55   z80pio_irq_reti( mbee_z80pio );
56}
57
58const struct z80_irq_daisy_chain mbee_daisy_chain[] =
59{
60   { mbee_z80pio_reset, mbee_z80pio_irq_state, mbee_z80pio_irq_ack, mbee_z80pio_irq_reti, 0 }, /* PIO number 0 */
61   { 0, 0, 0, 0, -1}      /* end mark */
40   { Z80PIO, "z80pio" },
41   { NULL }
6242};
6343
6444
src/mess/machine/osborne1.c
r3352r3353
2727
2828#define RAMMODE      (0x01)
2929
30static struct osborne1 {
30
31static struct osborne1
32{
3133   UINT8   bank2_enabled;
3234   UINT8   bank3_enabled;
3335   UINT8   *bank4_ptr;
r3352r3353
4951   UINT8   beep;
5052} osborne1;
5153
52/* Prototypes */
53static void osborne1_z80_reset(int);
54static int osborne1_z80_irq_state(int);
55static int osborne1_z80_irq_ack(int);
56static void osborne1_z80_irq_reti(int);
5754
58const struct z80_irq_daisy_chain osborne1_daisy_chain[] = {
59   { osborne1_z80_reset, osborne1_z80_irq_state, osborne1_z80_irq_ack, osborne1_z80_irq_reti, 0 },
60   { NULL, NULL, NULL, NULL, -1 }
61};
62
63
64WRITE8_HANDLER( osborne1_0000_w ) {
55WRITE8_HANDLER( osborne1_0000_w )
56{
6557   /* Check whether regular RAM is enabled */
66   if ( ! osborne1.bank2_enabled || ( osborne1.in_irq_handler && osborne1.bankswitch == RAMMODE ) ) {
58   if ( ! osborne1.bank2_enabled || ( osborne1.in_irq_handler && osborne1.bankswitch == RAMMODE ) )
59   {
6760      mess_ram[ offset ] = data;
6861   }
6962}
7063
71WRITE8_HANDLER( osborne1_1000_w ) {
64
65WRITE8_HANDLER( osborne1_1000_w )
66{
7267   /* Check whether regular RAM is enabled */
73   if ( ! osborne1.bank2_enabled || ( osborne1.in_irq_handler && osborne1.bankswitch == RAMMODE ) ) {
68   if ( ! osborne1.bank2_enabled || ( osborne1.in_irq_handler && osborne1.bankswitch == RAMMODE ) )
69   {
7470      mess_ram[ 0x1000 + offset ] = data;
7571   }
7672}
7773
78READ8_HANDLER( osborne1_2000_r ) {
74
75READ8_HANDLER( osborne1_2000_r )
76{
7977   UINT8   data = 0xFF;
8078
8179   /* Check whether regular RAM is enabled */
82   if ( ! osborne1.bank2_enabled ) {
80   if ( ! osborne1.bank2_enabled )
81   {
8382      data = mess_ram[ 0x2000 + offset ];
84   } else {
85      switch( offset & 0x0F00 ) {
83   }
84   else
85   {
86      switch( offset & 0x0F00 )
87      {
8688      case 0x100:   /* Floppy */
8789         data = wd17xx_r( machine, offset );
8890         break;
r3352r3353
117119   return data;
118120}
119121
120WRITE8_HANDLER( osborne1_2000_w ) {
122
123WRITE8_HANDLER( osborne1_2000_w )
124{
121125   /* Check whether regular RAM is enabled */
122   if ( ! osborne1.bank2_enabled ) {
126   if ( ! osborne1.bank2_enabled )
127   {
123128      mess_ram[ 0x2000 + offset ] = data;
124   } else {
125      if ( osborne1.in_irq_handler && osborne1.bankswitch == RAMMODE ) {
129   }
130   else
131   {
132      if ( osborne1.in_irq_handler && osborne1.bankswitch == RAMMODE )
133      {
126134         mess_ram[ 0x2000 + offset ] = data;
127135      }
128136      /* Handle writes to the I/O area */
129      switch( offset & 0x0F00 ) {
137      switch( offset & 0x0F00 )
138      {
130139      case 0x100:   /* Floppy */
131140         wd17xx_w( machine, offset, data );
132141         break;
r3352r3353
142151   }
143152}
144153
145WRITE8_HANDLER( osborne1_3000_w ) {
154
155WRITE8_HANDLER( osborne1_3000_w )
156{
146157   /* Check whether regular RAM is enabled */
147   if ( ! osborne1.bank2_enabled || ( osborne1.in_irq_handler && osborne1.bankswitch == RAMMODE ) ) {
158   if ( ! osborne1.bank2_enabled || ( osborne1.in_irq_handler && osborne1.bankswitch == RAMMODE ) )
159   {
148160      mess_ram[ 0x3000 + offset ] = data;
149161   }
150162}
151163
152WRITE8_HANDLER( osborne1_videoram_w ) {
164
165WRITE8_HANDLER( osborne1_videoram_w )
166{
153167   /* Check whether the video attribute section is enabled */
154   if ( osborne1.bank3_enabled ) {
168   if ( osborne1.bank3_enabled )
169   {
155170      data |= 0x7F;
156171   }
157172   osborne1.bank4_ptr[offset] = data;
158173}
159174
160WRITE8_HANDLER( osborne1_bankswitch_w ) {
161   switch( offset ) {
175
176WRITE8_HANDLER( osborne1_bankswitch_w )
177{
178   switch( offset )
179   {
162180   case 0x00:
163181      osborne1.bank2_enabled = 1;
164182      osborne1.bank3_enabled = 0;
r3352r3353
176194      osborne1.bank3_enabled = 0;
177195      break;
178196   }
179   if ( osborne1.bank2_enabled ) {
197   if ( osborne1.bank2_enabled )
198   {
180199      memory_set_bankptr( 1, memory_region(machine, "main") );
181200      memory_set_bankptr( 2, osborne1.empty_4K );
182201      memory_set_bankptr( 3, osborne1.empty_4K );
183   } else {
202   }
203   else
204   {
184205      memory_set_bankptr( 1, mess_ram );
185206      memory_set_bankptr( 2, mess_ram + 0x1000 );
186207      memory_set_bankptr( 3, mess_ram + 0x3000 );
r3352r3353
191212   osborne1.in_irq_handler = 0;
192213}
193214
194static OPBASE_HANDLER( osborne1_opbase ) {
195   if ( ( address & 0xF000 ) == 0x2000 ) {
196      if ( ! osborne1.bank2_enabled ) {
215
216static OPBASE_HANDLER( osborne1_opbase )
217{
218   if ( ( address & 0xF000 ) == 0x2000 )
219   {
220      if ( ! osborne1.bank2_enabled )
221      {
197222         opbase->mask = 0x0fff;
198223         opbase->ram = mess_ram + 0x2000;
199224         opbase->rom = mess_ram + 0x2000;
r3352r3353
205230   return address;
206231}
207232
208static void osborne1_z80_reset(int param) {
209   osborne1.pia_1_irq_state = 0;
210   osborne1.in_irq_handler = 0;
211}
212233
213static int osborne1_z80_irq_state(int param) {
214   return ( osborne1.pia_1_irq_state ? Z80_DAISY_INT : 0 );
215}
216
217static int osborne1_z80_irq_ack(int param) {
218   /* Enable ROM and I/O when IRQ is acknowledged */
219   UINT8   old_bankswitch = osborne1.bankswitch;
220   osborne1_bankswitch_w( Machine, 0, 0 );
221   osborne1.bankswitch = old_bankswitch;
222   osborne1.in_irq_handler = 1;
223   return 0xF8;
224}
225
226static void osborne1_z80_irq_reti(int param) {
227}
228
229static void osborne1_update_irq_state(running_machine *machine) {
234static void osborne1_update_irq_state(running_machine *machine)
235{
230236   //logerror("Changing irq state; pia_0_irq_state = %s, pia_1_irq_state = %s\n", osborne1.pia_0_irq_state ? "SET" : "CLEARED", osborne1.pia_1_irq_state ? "SET" : "CLEARED" );
231237
232   if ( osborne1.pia_1_irq_state ) {
238   if ( osborne1.pia_1_irq_state )
239   {
233240      cpunum_set_input_line(machine, 0, 0, ASSERT_LINE );
234   } else {
241   }
242   else
243   {
235244      cpunum_set_input_line(machine, 0, 0, CLEAR_LINE );
236245   }
237246}
238247
239static void ieee_pia_irq_a_func(running_machine *machine, int state) {
248
249static void ieee_pia_irq_a_func(running_machine *machine, int state)
250{
240251   osborne1.pia_0_irq_state = state;
241252   osborne1_update_irq_state(machine);
242253}
243254
244static const pia6821_interface osborne1_ieee_pia_config = {
255
256static const pia6821_interface osborne1_ieee_pia_config =
257{
245258   NULL,   /* in_a_func */
246259   NULL,   /* in_b_func */
247260   NULL,   /* in_ca1_func */
r3352r3353
256269   NULL   /* irq_b_func */
257270};
258271
259static WRITE8_HANDLER( video_pia_out_cb2_dummy ) {
272
273static WRITE8_HANDLER( video_pia_out_cb2_dummy )
274{
260275}
261276
262static WRITE8_HANDLER( video_pia_port_a_w ) {
277
278static WRITE8_HANDLER( video_pia_port_a_w )
279{
263280   osborne1.new_start_x = data >> 1;
264281   wd17xx_set_density( ( data & 0x01 ) ? DEN_FM_LO : DEN_FM_HI );
265282
266283   //logerror("Video pia port a write: %02X, density set to %s\n", data, data & 1 ? "DEN_FM_LO" : "DEN_FM_HI" );
267284}
268285
269static WRITE8_HANDLER( video_pia_port_b_w ) {
286
287static WRITE8_HANDLER( video_pia_port_b_w )
288{
270289   osborne1.new_start_y = data & 0x1F;
271290   osborne1.beep = ( data & 0x20 ) ? 1 : 0;
272   if ( data & 0x40 ) {
291   if ( data & 0x40 )
292   {
273293      wd17xx_set_drive( 0 );
274   } else if ( data & 0x80 ) {
294   }
295   else if ( data & 0x80 )
296   {
275297      wd17xx_set_drive( 1 );
276298   }
277299   //logerror("Video pia port b write: %02X\n", data );
278300}
279301
280static void video_pia_irq_a_func(running_machine *machine, int state) {
302
303static void video_pia_irq_a_func(running_machine *machine, int state)
304{
281305   osborne1.pia_1_irq_state = state;
282306   osborne1_update_irq_state(machine);
283307}
284308
285static const pia6821_interface osborne1_video_pia_config = {
309
310static const pia6821_interface osborne1_video_pia_config =
311{
286312   NULL,   /* in_a_func */
287313   NULL,   /* in_b_func */
288314   NULL,   /* in_ca1_func */
r3352r3353
297323   NULL   /* irq_b_func */
298324};
299325
300//static const struct aica6850_interface osborne1_6850_config = {
326
327//static const struct aica6850_interface osborne1_6850_config =
328//{
301329//   10,   /* tx_clock */
302330//   10,   /* rx_clock */
303331//   NULL,   /* rx_pin */
r3352r3353
308336//   NULL   /* int_callback */
309337//};
310338
311static TIMER_CALLBACK(osborne1_video_callback) {
339
340static TIMER_CALLBACK(osborne1_video_callback)
341{
312342   int y = video_screen_get_vpos(machine->primary_screen);
313343
314344   /* Check for start of frame */
315   if ( y == 0 ) {
345   if ( y == 0 )
346   {
316347      /* Clear CA1 on video PIA */
317348      osborne1.start_y = ( osborne1.new_start_y - 1 ) & 0x1F;
318349      osborne1.charline = 0;
319350      pia_1_ca1_w( machine, 0, 0 );
320351   }
321   if ( y == 240 ) {
352   if ( y == 240 )
353   {
322354      /* Set CA1 on video PIA */
323355      pia_1_ca1_w( machine, 0, 0xFF );
324356   }
325   if ( y < 240 ) {
357   if ( y < 240 )
358   {
326359      /* Draw a line of the display */
327360      UINT16 address = osborne1.start_y * 128 + osborne1.new_start_x + 11;
328361      UINT16 *p = BITMAP_ADDR16( tmpbitmap, y, 0 );
329362      int x;
330363
331      for ( x = 0; x < 52; x++ ) {
364      for ( x = 0; x < 52; x++ )
365      {
332366         UINT8   character = mess_ram[ 0xF000 + ( ( address + x ) & 0xFFF ) ];
333367         UINT8   cursor = character & 0x80;
334368         UINT8   dim = mess_ram[ 0x10000 + ( ( address + x ) & 0xFFF ) ] & 0x80;
335369         UINT8   bits = osborne1.charrom[ osborne1.charline * 128 + ( character & 0x7F ) ];
336370         int      bit;
337371
338         if ( cursor && osborne1.charline == 9 ) {
372         if ( cursor && osborne1.charline == 9 )
373         {
339374            bits = 0xFF;
340375         }
341         for ( bit = 0; bit < 8; bit++ ) {
376         for ( bit = 0; bit < 8; bit++ )
377         {
342378            p[x * 8 + bit] = ( bits & 0x80 ) ? ( dim ? 1 : 2 ) : 0;
343379            bits = bits << 1;
344380         }
345381      }
346382
347383      osborne1.charline += 1;
348      if ( osborne1.charline == 10 ) {
384      if ( osborne1.charline == 10 )
385      {
349386         osborne1.start_y += 1;
350387         osborne1.charline = 0;
351388      }
352389   }
353390
354   if ( ( y % 10 ) == 2 || ( y % 10 ) == 6 ) {
391   if ( ( y % 10 ) == 2 || ( y % 10 ) == 6 )
392   {
355393      beep_set_state( 0, osborne1.beep );
356   } else {
394   }
395   else
396   {
357397      beep_set_state( 0, 0 );
358398   }
359399
r3352r3353
369409 * - DEC 1820 double density: 40 tracks, 9 sectors per track, 512-byte sectors (180 KByte)
370410 *
371411 */
372DEVICE_IMAGE_LOAD( osborne1_floppy ) {
412DEVICE_IMAGE_LOAD( osborne1_floppy )
413{
373414   int size, sectors, sectorsize;
374415
375   if ( ! image_has_been_created( image ) ) {
416   if ( ! image_has_been_created( image ) )
417   {
376418      size = image_length( image );
377419
378      switch( size ) {
420      switch( size )
421      {
379422      case 40 * 10 * 256:
380423         sectors = 10;
381424         sectorsize = 256;
r3352r3353
404447      default:
405448         return INIT_FAIL;
406449      }
407   } else {
450   }
451   else
452   {
408453      return INIT_FAIL;
409454   }
410455
411   if ( device_load_basicdsk_floppy( image ) != INIT_PASS ) {
456   if ( device_load_basicdsk_floppy( image ) != INIT_PASS )
457   {
412458      return INIT_FAIL;
413459   }
414460
r3352r3353
417463   return INIT_PASS;
418464}
419465
420static TIMER_CALLBACK( setup_beep ) {
466
467static TIMER_CALLBACK( setup_beep )
468{
421469   beep_set_state( 0, 0 );
422470   beep_set_frequency( 0, 300 /* 60 * 240 / 2 */ );
423471}
424472
473
425474MACHINE_START( osborne1 )
426475{
427476   /* Configure the floppy disk interface */
428477   wd17xx_init( machine, WD_TYPE_MB8877, NULL, NULL );
429478}   
430479
431MACHINE_RESET( osborne1 ) {
480
481MACHINE_RESET( osborne1 )
482{
432483   /* Initialize memory configuration */
433484   osborne1_bankswitch_w( machine, 0x00, 0 );
434485
435486   osborne1.pia_0_irq_state = FALSE;
436487   osborne1.pia_1_irq_state = FALSE;
437488
489   osborne1.pia_1_irq_state = 0;
490   osborne1.in_irq_handler = 0;
491
438492   osborne1.charrom = memory_region( machine, "gfx1" );
439493
440494   memset( mess_ram + 0x10000, 0xFF, 0x1000 );
r3352r3353
448502   memory_set_opbase_handler( 0, osborne1_opbase );
449503}
450504
451DRIVER_INIT( osborne1 ) {
505
506DRIVER_INIT( osborne1 )
507{
452508   memset( &osborne1, 0, sizeof( osborne1 ) );
453509
454510   osborne1.empty_4K = auto_malloc( 0x1000 );
r3352r3353
462518//   acia6850_config( 0, &osborne1_6850_config );
463519}
464520
521
522/****************************************************************
523   Osborne1 specific daisy chain code
524****************************************************************/
525
526
527static int osborne1_daisy_irq_state(const device_config *device)
528{
529    return ( osborne1.pia_1_irq_state ? Z80_DAISY_INT : 0 );
530}
531
532
533static int osborne1_daisy_irq_ack(const device_config *device)
534{
535    /* Enable ROM and I/O when IRQ is acknowledged */
536    UINT8   old_bankswitch = osborne1.bankswitch;
537    osborne1_bankswitch_w( Machine, 0, 0 );
538    osborne1.bankswitch = old_bankswitch;
539    osborne1.in_irq_handler = 1;
540    return 0xF8;
541}
542
543static void osborne1_daisy_irq_reti(const device_config *device)
544{
545}
546
547
548static DEVICE_START( osborne1_daisy )
549{
550   return DEVICE_START_OK;
551}
552
553
554static DEVICE_RESET( osborne1_daisy )
555{
556}
557
558
559static DEVICE_SET_INFO( osborne1_daisy )
560{
561}
562
563
564DEVICE_GET_INFO( osborne1_daisy )
565{
566   switch (state)
567   {
568      /* --- the following bits of info are returned as 64-bit signed integers --- */
569      case DEVINFO_INT_TOKEN_BYTES:               info->i = 4;                                 break;
570      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                                 break;
571      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;                  break;
572
573      /* --- the following bits of info are returned as pointers to data or functions --- */
574      case DEVINFO_FCT_SET_INFO:                  info->set_info = DEVICE_SET_INFO_NAME(osborne1_daisy);   break;
575      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(osborne1_daisy);      break;
576      case DEVINFO_FCT_STOP:                     /* Nothing */                                 break;
577      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(osborne1_daisy);      break;
578      case DEVINFO_FCT_IRQ_STATE:                  info->f = (genf *)osborne1_daisy_irq_state;            break;
579      case DEVINFO_FCT_IRQ_ACK:                  info->f = (genf *)osborne1_daisy_irq_ack;            break;
580      case DEVINFO_FCT_IRQ_RETI:                  info->f = (genf *)osborne1_daisy_irq_reti;            break;
581
582      /* --- the following bits of info are returned as NULL-terminated strings --- */
583      case DEVINFO_STR_NAME:                     info->s = "Osborne1 daisy";                        break;
584      case DEVINFO_STR_FAMILY:                  info->s = "Z80";                              break;
585      case DEVINFO_STR_VERSION:                  info->s = "1.0";                              break;
586      case DEVINFO_STR_SOURCE_FILE:               info->s = __FILE__;                              break;
587      case DEVINFO_STR_CREDITS:                  info->s = "Copyright the MESS Team";               break;
588   }
589}
590
src/mess/machine/mtx.c
r3352r3353
5050
5151static void mtx_tms9929a_interrupt(running_machine *machine, int data)
5252{
53   z80ctc_0_trg0_w(machine, 0, data ? 0 : 1);
53   z80ctc_trg0_w( device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), 0, data ? 0 : 1);
5454}
5555
5656static const TMS9928a_interface tms9928a_interface =
r3352r3353
208208 *
209209 *************************************/
210210
211static void mtx_ctc_interrupt(running_machine *machine, int state)
211static void mtx_ctc_interrupt(const device_config *device, int state)
212212{
213213//  logerror("mtx_ctc_interrupt: %02x\n", state);
214   cpunum_set_input_line(machine, 0, 0, state);
214   cpunum_set_input_line(device->machine, 0, 0, state);
215215}
216216
217READ8_HANDLER( mtx_ctc_r )
217READ8_DEVICE_HANDLER( mtx_ctc_r )
218218{
219   return z80ctc_0_r(machine, offset);
219   return z80ctc_r(device, offset);
220220}
221221
222WRITE8_HANDLER( mtx_ctc_w )
222WRITE8_DEVICE_HANDLER( mtx_ctc_w )
223223{
224224//  logerror("mtx_ctc_w: %02x\n", data);
225225   if (offset < 3)
226      z80ctc_0_w(machine, offset,data);
226      z80ctc_w(device, offset,data);
227227}
228228
229static z80ctc_interface mtx_ctc_intf =
229const z80ctc_interface mtx_ctc_intf =
230230{
231   "main",
231232   MTX_SYSTEM_CLOCK,
232233   0,
233234   mtx_ctc_interrupt,
r3352r3353
244245 *
245246 *************************************/
246247
247READ8_HANDLER( mtx_dart_data_r )
248READ8_DEVICE_HANDLER( mtx_dart_data_r )
248249{
249   return z80dart_d_r(0, offset);
250   return z80dart_d_r(device, offset);
250251}
251252
252READ8_HANDLER( mtx_dart_control_r )
253READ8_DEVICE_HANDLER( mtx_dart_control_r )
253254{
254   return z80dart_c_r(0, offset);
255   return z80dart_c_r(device, offset);
255256}
256257
257WRITE8_HANDLER( mtx_dart_data_w )
258WRITE8_DEVICE_HANDLER( mtx_dart_data_w )
258259{
259   z80dart_d_w(0, offset, data);
260   z80dart_d_w(device, offset, data);
260261}
261262
262WRITE8_HANDLER( mtx_dart_control_w )
263WRITE8_DEVICE_HANDLER( mtx_dart_control_w )
263264{
264   z80dart_c_w(machine, 0, offset, data);
265   z80dart_c_w(device, offset, data);
265266}
266267
267static const z80dart_interface mtx_dart_intf =
268const z80dart_interface mtx_dart_intf =
268269{
270      "main",
269271      MTX_SYSTEM_CLOCK,
270272      NULL,
271273      NULL,
r3352r3353
348350
349351   /* setup tms9928a */
350352   TMS9928A_configure(&tms9928a_interface);
351
352   /* setup ctc */
353   z80ctc_init(0, &mtx_ctc_intf);
354353}
355354
356355DRIVER_INIT( rs128 )
357356{
358357   DRIVER_INIT_CALL(mtx512);
359358
360   z80dart_init(0, &mtx_dart_intf);
361
362359   /* install handlers for dart interface */
363   memory_install_readwrite8_handler(machine, 0, ADDRESS_SPACE_IO, 0x0c, 0x0d, 0, 0, mtx_dart_data_r, mtx_dart_data_w);
364   memory_install_readwrite8_handler(machine, 0, ADDRESS_SPACE_IO, 0x0e, 0x0f, 0, 0, mtx_dart_control_r, mtx_dart_control_w);
360   memory_install_readwrite8_device_handler(device_list_find_by_tag(machine->config->devicelist, Z80DART, "z80dart"), 0, ADDRESS_SPACE_IO, 0x0c, 0x0d, 0, 0, mtx_dart_data_r, mtx_dart_data_w);
361   memory_install_readwrite8_device_handler(device_list_find_by_tag(machine->config->devicelist, Z80DART, "z80dart"), 0, ADDRESS_SPACE_IO, 0x0e, 0x0f, 0, 0, mtx_dart_control_r, mtx_dart_control_w);
365362}
366363
367364MACHINE_RESET( rs128 )
368365{
369   z80dart_reset(0);
370366}
src/mess/machine/kc.c
r3352r3353
154154}
155155#endif
156156
157READ8_HANDLER(kc85_disk_hw_ctc_r)
157READ8_DEVICE_HANDLER(kc85_disk_hw_ctc_r)
158158{
159   return z80ctc_1_r(machine, offset);
159   return z80ctc_r(device, offset);
160160}
161161
162WRITE8_HANDLER(kc85_disk_hw_ctc_w)
162WRITE8_DEVICE_HANDLER(kc85_disk_hw_ctc_w)
163163{
164   z80ctc_1_w(machine, offset, data);
164   z80ctc_w(device, offset, data);
165165}
166166
167167WRITE8_HANDLER(kc85_disc_interface_ram_w)
r3352r3353
242242
243243   nec765_init(machine, &kc_fdc_interface,NEC765A,NEC765_RDY_PIN_CONNECTED);
244244
245   /* reset ctc */
246   z80ctc_reset(1);
247
248245   /* hold cpu at reset */
249246   cpunum_set_input_line(machine, 1, INPUT_LINE_RESET, ASSERT_LINE);
250247}
r3352r3353
17101707}
17111708
17121709
1713 READ8_HANDLER ( kc85_ctc_r )
1710 READ8_DEVICE_HANDLER ( kc85_ctc_r )
17141711{
17151712   unsigned char data;
17161713
1717   data = z80ctc_0_r(machine, offset);
1714   data = z80ctc_r(device, offset);
17181715   //LOG_KBD(("ctc data r:%02x\n",data));
17191716   return data;
17201717}
17211718
1722WRITE8_HANDLER ( kc85_ctc_w )
1719WRITE8_DEVICE_HANDLER ( kc85_ctc_w )
17231720{
17241721   //logerror("ctc data w:%02x\n",data);
17251722
1726   z80ctc_0_w(machine, offset,data);
1723   z80ctc_w(device, offset,data);
17271724}
17281725
17291726
1730static void kc85_pio_interrupt(running_machine *machine, int state)
1727static void kc85_pio_interrupt(const device_config *device, int state)
17311728{
1732   cpunum_set_input_line(machine, 0, 0, state);
1729   cpunum_set_input_line(device->machine, 0, 0, state);
17331730}
17341731
1735static void kc85_ctc_interrupt(running_machine *machine, int state)
1732static void kc85_ctc_interrupt(const device_config *device, int state)
17361733{
1737   cpunum_set_input_line(machine, 0, 1, state);
1734   cpunum_set_input_line(device->machine, 0, 1, state);
17381735}
17391736
17401737/* callback for ardy output from PIO */
r3352r3353
17721769   kc85_pio_brdy_callback   /* portB ready active callback */
17731770};
17741771
1775static void kc85_z80pio_reset(int which)
1776{
1777   z80pio_reset(kc85_z80pio);
1778}
17791772
17801773/* pio is last in chain and therefore has highest priority */
17811774
1782const struct z80_irq_daisy_chain kc85_daisy_chain[] =
1775const z80_daisy_chain kc85_daisy_chain[] =
17831776{
1784   {kc85_z80pio_reset, z80ctc_irq_state, z80ctc_irq_ack, z80ctc_irq_reti, 0},
1785   {z80ctc_reset, z80ctc_irq_state, z80ctc_irq_ack, z80ctc_irq_reti, 0},
1786   {0,0,0,0,-1}
1777   { Z80PIO, "z80pio" },
1778   { Z80CTC, "z80ctc" },
1779   { NULL }
17871780};
17881781
17891782/* used in cassette write -> K0 */
1790static WRITE8_HANDLER(kc85_zc0_callback)
1783static WRITE8_DEVICE_HANDLER(kc85_zc0_callback)
17911784{
17921785
17931786
17941787}
17951788
17961789/* used in cassette write -> K1 */
1797static WRITE8_HANDLER(kc85_zc1_callback)
1790static WRITE8_DEVICE_HANDLER(kc85_zc1_callback)
17981791{
17991792
18001793}
r3352r3353
18021795
18031796static TIMER_CALLBACK(kc85_15khz_timer_callback)
18041797{
1798   const device_config *device = ptr;
1799
18051800   /* toggle state of square wave */
18061801   kc85_15khz_state^=1;
18071802
18081803   /* set clock input for channel 2 and 3 to ctc */
1809   z80ctc_0_trg0_w(machine, 0,kc85_15khz_state);
1810   z80ctc_0_trg1_w(machine, 0,kc85_15khz_state);
1804   z80ctc_trg0_w(device, 0,kc85_15khz_state);
1805   z80ctc_trg1_w(device, 0,kc85_15khz_state);
18111806
18121807   kc85_15khz_count++;
18131808
r3352r3353
18191814      kc85_50hz_state^=1;
18201815
18211816      /* set clock input for channel 2 and 3 to ctc */
1822      z80ctc_0_trg2_w(machine, 0, kc85_50hz_state);
1823      z80ctc_0_trg3_w(machine, 0, kc85_50hz_state);
1817      z80ctc_trg2_w(device, 0, kc85_50hz_state);
1818      z80ctc_trg3_w(device, 0, kc85_50hz_state);
18241819   }
18251820}
18261821
18271822/* video blink */
1828static WRITE8_HANDLER(kc85_zc2_callback)
1823static WRITE8_DEVICE_HANDLER(kc85_zc2_callback)
18291824{
18301825   /* is blink enabled? */
18311826   if (kc85_pio_data[1] & (1<<7))
18321827   {
18331828      /* yes */
18341829      /* toggle state of blink to video hardware */
1835      kc85_video_set_blink_state(machine, data);
1830      kc85_video_set_blink_state(device->machine, data);
18361831   }
18371832}
18381833
1839static z80ctc_interface   kc85_ctc_intf =
1834const z80ctc_interface   kc85_ctc_intf =
18401835{
1836   "main",
18411837   1379310.344828,
18421838   0,
18431839    kc85_ctc_interrupt,
r3352r3353
18481844
18491845static void   kc85_common_init(running_machine *machine)
18501846{
1851   z80ctc_init(0, &kc85_ctc_intf);
1852
1853   z80ctc_reset(0);
1854
18551847   kc_cassette_init();
18561848   kc_keyboard_init(machine);
18571849
r3352r3353
18621854   kc85_50hz_state = 0;
18631855   kc85_15khz_state = 0;
18641856   kc85_15khz_count = 0;
1865   timer_pulse(ATTOTIME_IN_HZ(15625), NULL, 0, kc85_15khz_timer_callback);
1857   timer_pulse(ATTOTIME_IN_HZ(15625), (void *)device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), 0, kc85_15khz_timer_callback);
18661858   timer_set(attotime_zero, NULL, 0, kc85_reset_timer_callback);
18671859   kc85_module_system_init();
18681860}
src/mess/drivers/sord.c
r3352r3353
293293/*********************************************************************************************/
294294
295295
296static void sord_m5_ctc_interrupt(running_machine *machine, int state)
296static void sord_m5_ctc_interrupt(const device_config *device, int state)
297297{
298298   //logerror("interrupting ctc %02x\r\n ",state);
299   cpunum_set_input_line(machine, 0, 0, state);
299   cpunum_set_input_line(device->machine, 0, 0, state);
300300}
301301
302static z80ctc_interface   sord_m5_ctc_intf =
302static const z80ctc_interface   sord_m5_ctc_intf =
303303{
304   "main",
304305   3800000,
305306   0,
306307   sord_m5_ctc_interrupt,
r3352r3353
326327
327328
328329
329static READ8_HANDLER(sord_ctc_r)
330static READ8_DEVICE_HANDLER(sord_ctc_r)
330331{
331332   unsigned char data;
332333
333   data = z80ctc_0_r(machine, offset & 0x03);
334   data = z80ctc_r(device, offset & 0x03);
334335
335336   logerror("sord ctc r: %04x %02x\n",(offset & 0x03), data);
336337
337338   return data;
338339}
339340
340static WRITE8_HANDLER(sord_ctc_w)
341static WRITE8_DEVICE_HANDLER(sord_ctc_w)
341342{
342343   logerror("sord ctc w: %04x %02x\n",(offset & 0x03), data);
343344
344   z80ctc_0_w(machine, offset & 0x03, data);
345   z80ctc_w(device, offset & 0x03, data);
345346}
346347
347348static  READ8_HANDLER(sord_sys_r)
r3352r3353
412413
413414static ADDRESS_MAP_START( sord_m5_io , ADDRESS_SPACE_IO, 8)
414415   ADDRESS_MAP_GLOBAL_MASK(0xff)
415   AM_RANGE(0x00, 0x0f)               AM_READWRITE(sord_ctc_r,         sord_ctc_w)
416   AM_RANGE(0x00, 0x0f)               AM_DEVREADWRITE(Z80CTC, "z80ctc", sord_ctc_r,         sord_ctc_w)
416417   AM_RANGE(0x10, 0x10) AM_MIRROR(0x0e)   AM_READWRITE(TMS9928A_vram_r,      TMS9928A_vram_w)
417418   AM_RANGE(0x11, 0x11) AM_MIRROR(0x0e)   AM_READWRITE(TMS9928A_register_r,   TMS9928A_register_w)
418419   AM_RANGE(0x20, 0x2f)               AM_WRITE(                     sn76496_0_w)
r3352r3353
423424
424425static ADDRESS_MAP_START( srdm5fd5_io , ADDRESS_SPACE_IO, 8)
425426   ADDRESS_MAP_GLOBAL_MASK(0xff)
426   AM_RANGE(0x00, 0x0f)               AM_READWRITE(sord_ctc_r,         sord_ctc_w)
427   AM_RANGE(0x00, 0x0f)               AM_DEVREADWRITE(Z80CTC, "z80ctc", sord_ctc_r,         sord_ctc_w)
427428   AM_RANGE(0x10, 0x10) AM_MIRROR(0x0e)   AM_READWRITE(TMS9928A_vram_r,      TMS9928A_vram_w)
428429   AM_RANGE(0x11, 0x11) AM_MIRROR(0x0e)   AM_READWRITE(TMS9928A_register_r,   TMS9928A_register_w)
429430   AM_RANGE(0x20, 0x2f)               AM_WRITE(                     sn76496_0_w)
r3352r3353
447448{
448449   if (state)
449450   {
450      z80ctc_0_trg3_w(machine, 0, 1);
451      z80ctc_0_trg3_w(machine, 0, 0);
451      z80ctc_trg3_w(device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), 0, 1);
452      z80ctc_trg3_w(device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), 0, 0);
452453   }
453454}
454455
r3352r3353
467468
468469static MACHINE_RESET( sord_m5 )
469470{
470   z80ctc_init(0, &sord_m5_ctc_intf);
471
472471//  cassette_timer = timer_pulse(TIME_IN_HZ(11025), NULL, 0, cassette_timer_callback);
473472   TMS9928A_reset ();
474   z80ctc_reset(0);
475473
476474   /* should be done in a special callback to work properly! */
477475   memory_set_bankptr(1, memory_region(machine, "user1"));
r3352r3353
604602INPUT_PORTS_END
605603
606604
607static const struct z80_irq_daisy_chain sord_m5_daisy_chain[] =
605static const z80_daisy_chain sord_m5_daisy_chain[] =
608606{
609   {z80ctc_reset, z80ctc_irq_state, z80ctc_irq_ack, z80ctc_irq_reti, 0},
610   {0,0,0,0,-1}
607   { Z80CTC, "z80ctc" },
608   { NULL }
611609};
612610
613611
r3352r3353
640638   MDRV_DEVICE_ADD( "ppi8255", PPI8255 )
641639   MDRV_DEVICE_CONFIG( sord_ppi8255_interface )
642640
641   MDRV_Z80CTC_ADD( "z80ctc", sord_m5_ctc_intf )
642
643643   /* video hardware */
644644   MDRV_IMPORT_FROM(tms9928a)
645645   MDRV_SCREEN_MODIFY("main")
src/mess/drivers/mbee.c
r3352r3353
280280}
281281
282282
283static void pio_interrupt(running_machine *machine, int state)
283static void pio_interrupt(const device_config *device, int state)
284284{
285   cpunum_set_input_line(machine, 0, 0, state ? ASSERT_LINE : CLEAR_LINE);
285   cpunum_set_input_line(device->machine, 0, 0, state ? ASSERT_LINE : CLEAR_LINE);
286286}
287287
288288static const z80pio_interface mbee_z80pio_intf =
src/mess/drivers/abc80.c
r3352r3353
377377
378378/* Machine Initialization */
379379
380static void abc80_z80pio_reset(int which)
380static const z80_daisy_chain abc80_daisy_chain[] =
381381{
382   z80pio_reset( abc80_z80pio );
383}
384
385static int abc80_z80pio_irq_state(int which)
386{
387   return z80pio_irq_state( abc80_z80pio );
388}
389
390static int abc80_z80pio_irq_ack(int which)
391{
392   return z80pio_irq_ack( abc80_z80pio );
393}
394
395static void abc80_z80pio_irq_reti(int which)
396{
397   z80pio_irq_reti( abc80_z80pio );
398}
399
400static const struct z80_irq_daisy_chain abc80_daisy_chain[] =
401{
402   { abc80_z80pio_reset, abc80_z80pio_irq_state, abc80_z80pio_irq_ack, abc80_z80pio_irq_reti, 0 },
403   { 0, 0, 0, 0, -1 }
382   { Z80PIO, "z80pio" },
383   { NULL }
404384};
405385
406386static TIMER_CALLBACK( abc80_keyboard_tick )
src/mess/drivers/mpf1.c
r3352r3353
367367
368368/* Z80 PIO Interface */
369369
370static void mpf1_pio_interrupt( running_machine *machine, int state )
370static void mpf1_pio_interrupt( const device_config *device, int state )
371371{
372372   logerror("pio irq state: %02x\n",state);
373373}
src/mess/drivers/super80.c
r3352r3353
342342
343343/**************************** PIO ******************************************************************************/
344344
345static void pio_interrupt(running_machine *machine, int state)
345static void pio_interrupt(const device_config *device, int state)
346346{
347   cpunum_set_input_line( machine, 0, 0, state ? ASSERT_LINE : CLEAR_LINE );
347   cpunum_set_input_line( device->machine, 0, 0, state ? ASSERT_LINE : CLEAR_LINE );
348348}
349349
350
350351static const z80pio_interface pio_intf =
351352{
352353   pio_interrupt,      /* callback when change interrupt status */
r3352r3353
359360};
360361
361362
362static void super80_z80pio_reset(int which)
363static const z80_daisy_chain super80_daisy_chain[] =
363364{
364   z80pio_reset( super80_z80pio );
365}
366
367static int super80_z80pio_irq_state(int which)
368{
369   return z80pio_irq_state( super80_z80pio );
370}
371
372static int super80_z80pio_irq_ack(int which)
373{
374   return z80pio_irq_ack( super80_z80pio );
375}
376
377static void super80_z80pio_irq_reti(int which)
378{
379   z80pio_irq_reti( super80_z80pio );
380}
381
382static const struct z80_irq_daisy_chain super80_daisy_chain[] =
383{
384   { super80_z80pio_reset, super80_z80pio_irq_state, super80_z80pio_irq_ack, super80_z80pio_irq_reti, 0 },
385   { 0, 0, 0, 0, -1}      /* end mark */
365   { Z80PIO, "z80pio" },
366   { NULL }
386367};
387368
388369/**************************** CASSETTE ROUTINES *****************************************************************/
src/mess/drivers/abc80x.c
r3352r3353
174174
175175// Z80 SIO/2
176176
177static READ8_HANDLER( sio2_r )
177static READ8_DEVICE_HANDLER( sio2_r )
178178{
179179   switch (offset)
180180   {
181181   case 0:
182      return z80sio_d_r(machine, 0, 0);
182      return z80sio_d_r(device, 0);
183183   case 1:
184      return z80sio_c_r(0, 0);
184      return z80sio_c_r(device, 0);
185185   case 2:
186      return z80sio_d_r(machine, 0, 1);
186      return z80sio_d_r(device, 1);
187187   case 3:
188      return z80sio_c_r(0, 1);
188      return z80sio_c_r(device, 1);
189189   }
190190
191191   return 0;
192192}
193193
194static WRITE8_HANDLER( sio2_w )
194static WRITE8_DEVICE_HANDLER( sio2_w )
195195{
196196   switch (offset)
197197   {
198198   case 0:
199      z80sio_d_w(machine, 0, 0, data);
199      z80sio_d_w(device, 0, data);
200200      break;
201201   case 1:
202      z80sio_c_w(machine, 0, 0, data);
202      z80sio_c_w(device, 0, data);
203203      break;
204204   case 2:
205      z80sio_d_w(machine, 0, 1, data);
205      z80sio_d_w(device, 1, data);
206206      break;
207207   case 3:
208      z80sio_c_w(machine, 0, 1, data);
208      z80sio_c_w(device, 1, data);
209209      break;
210210   }
211211}
212212
213213// Z80 DART
214214
215static READ8_HANDLER( dart_r )
215static READ8_DEVICE_HANDLER( dart_r )
216216{
217217   switch (offset)
218218   {
219219   case 0:
220      return z80dart_d_r(0, 0);
220      return z80dart_d_r(device, 0);
221221   case 1:
222      return z80dart_c_r(0, 0);
222      return z80dart_c_r(device, 0);
223223   case 2:
224      return z80dart_d_r(0, 1);
224      return z80dart_d_r(device, 1);
225225   case 3:
226      return z80dart_c_r(0, 0); // this gets ABC806 booting, should be z80dart_c_r(0, 1)
226      return z80dart_c_r(device, 0); // this gets ABC806 booting, should be z80dart_c_r(0, 1)
227227   }
228228
229229   return 0xff;
230230}
231231
232static WRITE8_HANDLER( dart_w )
232static WRITE8_DEVICE_HANDLER( dart_w )
233233{
234234   switch (offset)
235235   {
236236   case 0:
237      z80dart_d_w(0, 0, data);
237      z80dart_d_w(device, 0, data);
238238      break;
239239   case 1:
240      z80dart_c_w(machine, 0, 0, data);
240      z80dart_c_w(device, 0, data);
241241      break;
242242   case 2:
243      z80dart_d_w(0, 1, data);
243      z80dart_d_w(device, 1, data);
244244      break;
245245   case 3:
246      z80dart_c_w(machine, 0, 1, data);
246      z80dart_c_w(device, 1, data);
247247      break;
248248   }
249249}
r3352r3353
294294   abc77_keydown = BIT(data, 6);
295295   abc77_hys = BIT(data, 7);
296296
297   z80dart_set_dcd(0, 0, abc77_keydown);
297   z80dart_set_dcd(device_list_find_by_tag(machine->config->devicelist, Z80DART, "z80dart"), 0, abc77_keydown);
298298   //z80dart_set_cts(0, 0, abc77_keydown); on ABC802 only
299299
300300   // write abc77_txd to Z80DART TxD
r3352r3353
333333   AM_RANGE(0x02, 0x05) AM_MIRROR(0x18) AM_WRITE(abcbus_command_w)
334334   AM_RANGE(0x06, 0x06) AM_MIRROR(0x18) AM_WRITE(abc800m_hrs_w)
335335   AM_RANGE(0x07, 0x07) AM_MIRROR(0x18) AM_READWRITE(abcbus_reset_r, abc800m_hrc_w)
336   AM_RANGE(0x20, 0x23) AM_MIRROR(0x0c) AM_READWRITE(dart_r, dart_w)
336   AM_RANGE(0x20, 0x23) AM_MIRROR(0x0c) AM_DEVREADWRITE(Z80DART, "z80dart", dart_r, dart_w)
337337   AM_RANGE(0x30, 0x32) AM_WRITE(abc800_ram_ctrl_w)
338338   AM_RANGE(0x31, 0x31) AM_MIRROR(0x06) AM_DEVREAD(MC6845, MC6845_TAG, mc6845_register_r)
339339   AM_RANGE(0x38, 0x38) AM_MIRROR(0x06) AM_DEVWRITE(MC6845, MC6845_TAG, mc6845_address_w)
340340   AM_RANGE(0x39, 0x39) AM_MIRROR(0x06) AM_DEVWRITE(MC6845, MC6845_TAG, mc6845_register_w)
341   AM_RANGE(0x40, 0x43) AM_MIRROR(0x1c) AM_READWRITE(sio2_r, sio2_w)
342   AM_RANGE(0x50, 0x53) AM_MIRROR(0x1c) AM_READWRITE(z80ctc_0_r, z80ctc_0_w)
341   AM_RANGE(0x40, 0x43) AM_MIRROR(0x1c) AM_DEVREADWRITE(Z80SIO, "z80sio", sio2_r, sio2_w)
342   AM_RANGE(0x50, 0x53) AM_MIRROR(0x1c) AM_DEVREADWRITE(Z80CTC, "z80ctc", z80ctc_r, z80ctc_w)
343343   AM_RANGE(0x80, 0x80) AM_MIRROR(0x7f) AM_READWRITE(abcbus_strobe_r, abcbus_strobe_w)
344344ADDRESS_MAP_END
345345
r3352r3353
361361   AM_RANGE(0x02, 0x05) AM_MIRROR(0x18) AM_WRITE(abcbus_command_w)
362362   AM_RANGE(0x06, 0x06) AM_MIRROR(0x18) AM_WRITE(abc800c_hrs_w)
363363   AM_RANGE(0x07, 0x07) AM_MIRROR(0x18) AM_READWRITE(abcbus_reset_r, abc800c_hrc_w)
364   AM_RANGE(0x20, 0x23) AM_MIRROR(0x0c) AM_READWRITE(dart_r, dart_w)
364   AM_RANGE(0x20, 0x23) AM_MIRROR(0x0c) AM_DEVREADWRITE(Z80DART, "z80dart", dart_r, dart_w)
365365   AM_RANGE(0x30, 0x32) AM_WRITE(abc800_ram_ctrl_w)
366366   AM_RANGE(0x31, 0x31) AM_MIRROR(0x06) AM_DEVREAD(MC6845, MC6845_TAG, mc6845_register_r)
367367   AM_RANGE(0x38, 0x38) AM_MIRROR(0x06) AM_DEVWRITE(MC6845, MC6845_TAG, mc6845_address_w)
368368   AM_RANGE(0x39, 0x39) AM_MIRROR(0x06) AM_DEVWRITE(MC6845, MC6845_TAG, mc6845_register_w)
369   AM_RANGE(0x40, 0x43) AM_MIRROR(0x1c) AM_READWRITE(sio2_r, sio2_w)
370   AM_RANGE(0x50, 0x53) AM_MIRROR(0x1c) AM_READWRITE(z80ctc_0_r, z80ctc_0_w)
369   AM_RANGE(0x40, 0x43) AM_MIRROR(0x1c) AM_DEVREADWRITE(Z80SIO, "z80sio", sio2_r, sio2_w)
370   AM_RANGE(0x50, 0x53) AM_MIRROR(0x1c) AM_DEVREADWRITE(Z80CTC, "z80ctc", z80ctc_r, z80ctc_w)
371371   AM_RANGE(0x80, 0x80) AM_MIRROR(0x7f) AM_READWRITE(abcbus_strobe_r, abcbus_strobe_w)
372372ADDRESS_MAP_END
373373
r3352r3353
387387   AM_RANGE(0x01, 0x01) AM_READWRITE(abcbus_status_r, abcbus_channel_w)
388388   AM_RANGE(0x02, 0x05) AM_WRITE(abcbus_command_w)
389389   AM_RANGE(0x07, 0x07) AM_READ(abcbus_reset_r)
390   AM_RANGE(0x20, 0x23) AM_READWRITE(dart_r, dart_w)
390   AM_RANGE(0x20, 0x23) AM_DEVREADWRITE(Z80DART, "z80dart", dart_r, dart_w)
391391   AM_RANGE(0x31, 0x31) AM_DEVREAD(MC6845, MC6845_TAG, mc6845_register_r)
392   AM_RANGE(0x32, 0x35) AM_READWRITE(sio2_r, sio2_w)
392   AM_RANGE(0x32, 0x35) AM_DEVREADWRITE(Z80SIO, "z80sio", sio2_r, sio2_w)
393393   AM_RANGE(0x38, 0x38) AM_DEVWRITE(MC6845, MC6845_TAG, mc6845_address_w)
394394   AM_RANGE(0x39, 0x39) AM_DEVWRITE(MC6845, MC6845_TAG, mc6845_register_w)
395   AM_RANGE(0x60, 0x63) AM_READWRITE(z80ctc_0_r, z80ctc_0_w)
395   AM_RANGE(0x60, 0x63) AM_DEVREADWRITE(Z80CTC, "z80ctc", z80ctc_r, z80ctc_w)
396396   AM_RANGE(0x80, 0xff) AM_READWRITE(abcbus_strobe_r, abcbus_strobe_w)
397397ADDRESS_MAP_END
398398
r3352r3353
429429   AM_RANGE(0x02, 0x05) AM_MIRROR(0xff18) AM_WRITE(abcbus_command_w)
430430   AM_RANGE(0x06, 0x06) AM_MIRROR(0xff18) AM_WRITE(abc806_hrs_w)
431431   AM_RANGE(0x07, 0x07) AM_MIRROR(0xff18) AM_READWRITE(abcbus_reset_r, abc806_hrc_w)
432   AM_RANGE(0x20, 0x23) AM_MIRROR(0xff0c) AM_READWRITE(dart_r, dart_w)
432   AM_RANGE(0x20, 0x23) AM_MIRROR(0xff0c) AM_DEVREADWRITE(Z80DART, "z80dart", dart_r, dart_w)
433433   AM_RANGE(0x31, 0x31) AM_MIRROR(0xff06) AM_DEVREAD(MC6845, MC6845_TAG, mc6845_register_r)
434434   AM_RANGE(0x34, 0x34) AM_MIRROR(0xff00) AM_MASK(0xff00) AM_READWRITE(abc806_bankswitch_r, abc806_bankswitch_w)
435435   AM_RANGE(0x35, 0x35) AM_MIRROR(0xff00) AM_READWRITE(abc806_colorram_r, abc806_colorram_w)
r3352r3353
437437   AM_RANGE(0x37, 0x37) AM_MIRROR(0xff00) AM_READWRITE(abc806_fgctlprom_r, abc806_sync_w)
438438   AM_RANGE(0x38, 0x38) AM_MIRROR(0xff06) AM_DEVWRITE(MC6845, MC6845_TAG, mc6845_address_w)
439439   AM_RANGE(0x39, 0x39) AM_MIRROR(0xff06) AM_DEVWRITE(MC6845, MC6845_TAG, mc6845_register_w)
440   AM_RANGE(0x40, 0x41) AM_MIRROR(0xff1c) AM_READWRITE(sio2_r, sio2_w)
441   AM_RANGE(0x60, 0x63) AM_MIRROR(0xff1c) AM_READWRITE(z80ctc_0_r, z80ctc_0_w)
440   AM_RANGE(0x40, 0x41) AM_MIRROR(0xff1c) AM_DEVREADWRITE(Z80SIO, "z80sio", sio2_r, sio2_w)
441   AM_RANGE(0x60, 0x63) AM_MIRROR(0xff1c) AM_DEVREADWRITE(Z80CTC, "z80ctc", z80ctc_r, z80ctc_w)
442442   AM_RANGE(0x80, 0x80) AM_MIRROR(0xff7f) AM_READWRITE(abcbus_strobe_r, abcbus_strobe_w)
443443ADDRESS_MAP_END
444444
r3352r3353
597597
598598/* Machine Initialization */
599599
600static WRITE8_HANDLER( abc800_ctc_z2_w )
600static WRITE8_DEVICE_HANDLER( abc800_ctc_z2_w )
601601{
602602   // write to DART channel A RxC/TxC
603603}
604604
605static z80ctc_interface abc800_ctc_intf =
605static const z80ctc_interface abc800_ctc_intf =
606606{
607   "main",               /* cpu */
607608   ABC800_X01/2/2,         /* clock */
608609   0,                    /* timer disables */
609610   0,                    /* interrupt handler */
r3352r3353
612613   abc800_ctc_z2_w          /* ZC/TO2 callback */
613614};
614615
615static WRITE8_HANDLER( sio_serial_transmit )
616static WRITE8_DEVICE_HANDLER( sio_serial_transmit )
616617{
617618}
618619
619static int sio_serial_receive(int ch)
620static int sio_serial_receive( const device_config *device, int channel )
620621{
621622   return -1;
622623}
623624
624625static z80sio_interface abc800_sio_intf =
625626{
627   "main",               /* cpu */
626628   ABC800_X01/2/2,         /* clock */
627629   0,                  /* interrupt handler */
628630   0,                  /* DTR changed handler */
r3352r3353
632634   sio_serial_receive      /* receive handler */
633635};
634636
635static WRITE8_HANDLER( dart_serial_transmit )
637static WRITE8_DEVICE_HANDLER( dart_serial_transmit )
636638{
637639}
638640
639static int dart_serial_receive(int ch)
641static int dart_serial_receive(const device_config *device, int ch)
640642{
641643   return -1;
642644}
643645
644646static const z80dart_interface abc800_dart_intf =
645647{
648   "main",               /* cpu */
646649   ABC800_X01/2/2,         /* clock */
647650   0,                  /* interrupt handler */
648651   0,                  /* DTR changed handler */
r3352r3353
652655   dart_serial_receive      /* receive handler */
653656};
654657
655static WRITE8_HANDLER( abc802_dart_dtr_w )
658static WRITE8_DEVICE_HANDLER( abc802_dart_dtr_w )
656659{
657660   if (offset == 1)
658661   {
r3352r3353
660663   }
661664}
662665
663static WRITE8_HANDLER( abc802_dart_rts_w )
666static WRITE8_DEVICE_HANDLER( abc802_dart_rts_w )
664667{
665668   if (offset == 1)
666669   {
r3352r3353
670673
671674static const z80dart_interface abc802_dart_intf =
672675{
676   "main",               /* cpu */
673677   ABC800_X01/2/2,         /* clock */
674678   0,                  /* interrupt handler */
675679   abc802_dart_dtr_w,      /* DTR changed handler */
r3352r3353
679683   dart_serial_receive      /* receive handler */
680684};
681685
682static const struct z80_irq_daisy_chain abc800_daisy_chain[] =
686static const z80_daisy_chain abc800_daisy_chain[] =
683687{
684   { z80ctc_reset, z80ctc_irq_state, z80ctc_irq_ack, z80ctc_irq_reti, 0 },
685   { z80sio_reset, z80sio_irq_state, z80sio_irq_ack, z80sio_irq_reti, 0 },
686   { z80dart_reset, z80dart_irq_state, z80dart_irq_ack, z80dart_irq_reti, 0 },
687   { 0, 0, 0, 0, -1 }
688   { Z80CTC, "z80ctc" },
689   { Z80SIO, "z80sio" },
690   { Z80DART, "z80dart" },
691   { NULL }
688692};
689693
690694static TIMER_CALLBACK(abc800_ctc_tick)
691695{
692   z80ctc_trg_w(machine, 0, 0, 1);
693   z80ctc_trg_w(machine, 0, 0, 0);
694   z80ctc_trg_w(machine, 0, 1, 1);
695   z80ctc_trg_w(machine, 0, 1, 0);
696   z80ctc_trg_w(machine, 0, 2, 1);
697   z80ctc_trg_w(machine, 0, 2, 0);
696   const device_config *device = ptr;
697
698   z80ctc_trg_w(device, 0, 1);
699   z80ctc_trg_w(device, 0, 0);
700   z80ctc_trg_w(device, 1, 1);
701   z80ctc_trg_w(device, 1, 0);
702   z80ctc_trg_w(device, 2, 1);
703   z80ctc_trg_w(device, 2, 0);
698704}
699705
700706static MACHINE_START( abc800 )
r3352r3353
702708   state_save_register_global(abc77_keylatch);
703709   state_save_register_global(abc77_clock);
704710
705   abc800_ctc_timer = timer_alloc(abc800_ctc_tick, NULL);
711   abc800_ctc_timer = timer_alloc(abc800_ctc_tick, (void *)device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc") );
706712   timer_adjust_periodic(abc800_ctc_timer, attotime_zero, 0, ATTOTIME_IN_HZ(ABC800_X01/2/2/2));
707
708   z80ctc_init(0, &abc800_ctc_intf);
709   z80sio_init(0, &abc800_sio_intf);
710   z80dart_init(0, &abc800_dart_intf);
711713}
712714
713715static MACHINE_START( abc802 )
714716{
715717   MACHINE_START_CALL(abc800);
716718
717   z80dart_init(0, &abc802_dart_intf);
718
719719   memory_configure_bank(1, 0, 1, memory_region(machine, "main"), 0);
720720   memory_configure_bank(1, 1, 1, mess_ram, 0);
721721}
r3352r3353
798798
799799   MDRV_MACHINE_START(abc800)
800800
801   MDRV_Z80CTC_ADD( "z80ctc", abc800_ctc_intf )
802   MDRV_Z80SIO_ADD( "z80sio", abc800_sio_intf )
803   MDRV_Z80DART_ADD( "z80dart", abc800_dart_intf )
804
801805   MDRV_IMPORT_FROM(abc800m_video)
802806
803807   MDRV_DEVICE_ADD("printer", PRINTER)
r3352r3353
819823
820824   MDRV_MACHINE_START(abc800)
821825
826   MDRV_Z80CTC_ADD( "z80ctc", abc800_ctc_intf )
827   MDRV_Z80SIO_ADD( "z80sio", abc800_sio_intf )
828   MDRV_Z80DART_ADD( "z80dart", abc800_dart_intf )
829
822830   MDRV_IMPORT_FROM(abc800c_video)
823831
824832   MDRV_DEVICE_ADD("printer", PRINTER)
r3352r3353
841849   MDRV_MACHINE_START(abc802)
842850   MDRV_MACHINE_RESET(abc802)
843851
852   MDRV_Z80CTC_ADD( "z80ctc", abc800_ctc_intf )
853   MDRV_Z80SIO_ADD( "z80sio", abc800_sio_intf )
854   MDRV_Z80DART_ADD( "z80dart", abc802_dart_intf )
855
844856   MDRV_IMPORT_FROM(abc802_video)
845857
846858   MDRV_DEVICE_ADD("printer", PRINTER)
r3352r3353
863875   MDRV_MACHINE_START(abc806)
864876   MDRV_MACHINE_RESET(abc806)
865877
878   MDRV_Z80CTC_ADD( "z80ctc", abc800_ctc_intf )
879   MDRV_Z80SIO_ADD( "z80sio", abc800_sio_intf )
880   MDRV_Z80DART_ADD( "z80dart", abc800_dart_intf )
881
866882   MDRV_IMPORT_FROM(abc806_video)
867883
868884   MDRV_DEVICE_ADD("printer", PRINTER)
src/mess/drivers/newbrain.c
r3352r3353
903903   AM_RANGE(0x17, 0x17) AM_MIRROR(0xff00) AM_READWRITE(ei_usbs_r, ei_usbs_w)
904904   AM_RANGE(0x18, 0x18) AM_MIRROR(0xff00) AM_READWRITE(acia6850_0_stat_r, acia6850_0_ctrl_w)
905905   AM_RANGE(0x19, 0x19) AM_MIRROR(0xff00) AM_READWRITE(acia6850_0_data_r, acia6850_0_data_w)
906   AM_RANGE(0x1c, 0x1f) AM_MIRROR(0xff00) AM_READWRITE(z80ctc_0_r, z80ctc_0_w)
906   AM_RANGE(0x1c, 0x1f) AM_MIRROR(0xff00) AM_DEVREADWRITE(Z80CTC, "z80ctc", z80ctc_r, z80ctc_w)
907907   AM_RANGE(0xff, 0xff) AM_MIRROR(0xff00) AM_MASK(0xff00) AM_WRITE(ei_paging_w)
908908ADDRESS_MAP_END
909909
r3352r3353
922922   AM_RANGE(0x16, 0x16) AM_MIRROR(0xffc0) AM_READ(ust2_r)
923923   AM_RANGE(0x18, 0x18) AM_MIRROR(0xffc0) AM_READWRITE(acia6850_0_stat_r, acia6850_0_ctrl_w)
924924   AM_RANGE(0x19, 0x19) AM_MIRROR(0xffc0) AM_READWRITE(acia6850_0_data_r, acia6850_0_data_w)
925   AM_RANGE(0x1c, 0x1c) AM_MIRROR(0xffc0) AM_READWRITE(z80ctc_0_r, z80ctc_0_w)
925   AM_RANGE(0x1c, 0x1c) AM_MIRROR(0xffc0) AM_DEVREADWRITE(Z80CTC, "z80ctc", z80ctc_r, z80ctc_w)
926926ADDRESS_MAP_END
927927
928928static ADDRESS_MAP_START( newbrain_a_io_map, ADDRESS_SPACE_IO, 8 )
r3352r3353
951951   AM_RANGE(0x15, 0x15) AM_MIRROR(0xffc2) AM_READ(user_r)
952952   AM_RANGE(0x18, 0x18) AM_MIRROR(0xffc0) AM_READWRITE(acia6850_0_stat_r, acia6850_0_ctrl_w)
953953   AM_RANGE(0x19, 0x19) AM_MIRROR(0xffc0) AM_READWRITE(acia6850_0_data_r, acia6850_0_data_w)
954   AM_RANGE(0x1c, 0x1c) AM_MIRROR(0xffc0) AM_READWRITE(z80ctc_0_r, z80ctc_0_w)
954   AM_RANGE(0x1c, 0x1c) AM_MIRROR(0xffc0) AM_DEVREADWRITE(Z80CTC, "z80ctc", z80ctc_r, z80ctc_w)
955955ADDRESS_MAP_END
956956
957957static ADDRESS_MAP_START( newbrain_cop_map, ADDRESS_SPACE_PROGRAM, 8 )
r3352r3353
11181118
11191119static z80ctc_interface newbrain_ctc_intf =
11201120{
1121   "main",               /* cpu */
11211122   1,                  /* clock */
11221123   0,                    /* timer disables */
11231124   NULL,                 /* interrupt handler */
r3352r3353
11731174
11741175   nec765_init(machine, &newbrain_nec765_interface, NEC765A, NEC765_RDY_PIN_NOT_CONNECTED);
11751176   acia6850_config(0, &newbrain_acia_intf);
1176   z80ctc_init(0, &newbrain_ctc_intf);
11771177
11781178   /* allocate reset timer */
11791179   
r3352r3353
12601260   MDRV_MACHINE_START(newbrain)
12611261   MDRV_MACHINE_RESET(newbrain)
12621262
1263   MDRV_Z80CTC_ADD( "z80ctc", newbrain_ctc_intf )
1264
12631265   // A/D converter
12641266
12651267   MDRV_DEVICE_ADD(ADC0809_TAG, ADC0809)
src/mess/drivers/mtx.c
r3352r3353
6767   AM_RANGE(0x04, 0x04) AM_READWRITE(mtx_prt_r, mtx_prt_w)
6868   AM_RANGE(0x05, 0x05) AM_READWRITE(mtx_key_lo_r, mtx_sense_w)
6969   AM_RANGE(0x06, 0x06) AM_READWRITE(mtx_key_hi_r, sn76496_0_w)
70   AM_RANGE(0x08, 0x0b) AM_READWRITE(mtx_ctc_r, mtx_ctc_w)
70   AM_RANGE(0x08, 0x0b) AM_DEVREADWRITE(Z80CTC, "z80ctc", mtx_ctc_r, mtx_ctc_w)
7171ADDRESS_MAP_END
7272
7373
r3352r3353
217217 *
218218 *************************************/
219219
220static const struct z80_irq_daisy_chain mtx_daisy_chain[] =
220static const z80_daisy_chain mtx_daisy_chain[] =
221221{
222   {z80ctc_reset, z80ctc_irq_state, z80ctc_irq_ack, z80ctc_irq_reti, 0},
223   {0, 0, 0, 0, -1}
222   { Z80CTC, "z80ctc" },
223   { NULL }
224224};
225225
226226
r3352r3353
250250   MDRV_SOUND_ADD("sn76489a", SN76489A, MTX_SYSTEM_CLOCK)
251251   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
252252
253   MDRV_Z80CTC_ADD( "z80ctc", mtx_ctc_intf )
254
253255   /* printer */
254256   MDRV_DEVICE_ADD("printer", PRINTER)
255257
r3352r3353
261263static MACHINE_DRIVER_START( rs128 )
262264   MDRV_IMPORT_FROM(mtx512)
263265   MDRV_MACHINE_RESET(rs128)
266
267   MDRV_Z80DART_ADD( "z80dart", mtx_dart_intf )
264268MACHINE_DRIVER_END
265269
266270
src/mess/drivers/einstein.c
r3352r3353
327327
328328static TIMER_CALLBACK(einstein_ctc_trigger_callback)
329329{
330   const device_config *device = ptr;
331
330332   einstein_ctc_trigger^=1;
331333
332334   /* channel 0 and 1 have a 2Mhz input clock for triggering */
333   z80ctc_0_trg0_w(machine, 0, einstein_ctc_trigger);
334   z80ctc_0_trg1_w(machine, 0, einstein_ctc_trigger);
335   z80ctc_trg0_w(device, 0, einstein_ctc_trigger);
336   z80ctc_trg1_w(device, 0, einstein_ctc_trigger);
335337}
336338
337339/* refresh keyboard data. It is refreshed when the keyboard line is written */
r3352r3353
403405
404406
405407/* interrupt state callback for ctc */
406static void einstein_ctc_interrupt(running_machine *machine, int state)
408static void einstein_ctc_interrupt(const device_config *device, int state)
407409{
408410   logerror("ctc irq state: %02x\n",state);
409   cpunum_set_input_line(machine, 0, 1, state);
411   cpunum_set_input_line(device->machine, 0, 1, state);
410412}
411413
412static void einstein_pio_interrupt(running_machine *machine, int state)
414static void einstein_pio_interrupt(const device_config *device, int state)
413415{
414416   logerror("pio irq state: %02x\n",state);
415   cpunum_set_input_line(machine, 0, 3, state);
417   cpunum_set_input_line(device->machine, 0, 3, state);
416418}
417419
418static WRITE8_HANDLER(einstein_serial_transmit_clock)
420static WRITE8_DEVICE_HANDLER(einstein_serial_transmit_clock)
419421{
420422   msm8251_transmit_clock();
421423}
422424
423static WRITE8_HANDLER(einstein_serial_receive_clock)
425static WRITE8_DEVICE_HANDLER(einstein_serial_receive_clock)
424426{
425427   msm8251_receive_clock();
426428}
427429
428430static z80ctc_interface   einstein_ctc_intf =
429431{
432   "main",
430433   EINSTEIN_SYSTEM_CLOCK,
431434   0,
432435   einstein_ctc_interrupt,
433436   einstein_serial_transmit_clock,
434437   einstein_serial_receive_clock,
435    z80ctc_0_trg3_w
438    z80ctc_trg3_w
436439};
437440
438441static void einstein_pio_ardy(int data)
r3352r3353
461464   NULL
462465};
463466
464/* not required for this interrupt source */
465static void einstein_keyboard_int_reset(int which)
467
468/****************************************************************
469   Einstein specific keyboard daisy chain code
470****************************************************************/
471
472static int einstein_daisy_irq_state(const device_config *device)
466473{
467   einstein_int_mask &= ~EINSTEIN_KEY_INT;
474   return 0xFF;
475}
468476
469   einstein_update_interrupts(Machine);
477
478static void einstein_daisy_irq_reti(const device_config *device)
479{
470480}
471481
472482
473/* not required for this interrupt source */
474static void einstein_adc_int_reset(int which)
483static DEVICE_START( einstein_daisy )
475484{
476   einstein_int_mask &= ~EINSTEIN_ADC_INT;
485   return DEVICE_START_OK;
486}
477487
478   einstein_update_interrupts(Machine);
488
489static DEVICE_RESET( einstein_daisy )
490{
479491}
480492
493
494static DEVICE_SET_INFO( einstein_daisy )
495{
496}
497
498
499static DEVICE_GET_INFO( einstein_daisy )
500{
501   switch (state)
502   {
503      /* --- the following bits of info are returned as 64-bit signed integers --- */
504      case DEVINFO_INT_TOKEN_BYTES:               info->i = 4;                                 break;
505      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                                 break;
506      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;                  break;
507
508      /* --- the following bits of info are returned as pointers to data or functions --- */
509      case DEVINFO_FCT_SET_INFO:                  info->set_info = DEVICE_SET_INFO_NAME(einstein_daisy);   break;
510      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(einstein_daisy);      break;
511      case DEVINFO_FCT_STOP:                     /* Nothing */                                 break;
512      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(einstein_daisy);      break;
513      case DEVINFO_FCT_IRQ_STATE:                  info->f = (genf *)einstein_daisy_irq_state;            break;
514      case DEVINFO_FCT_IRQ_RETI:                  info->f = (genf *)einstein_daisy_irq_reti;            break;
515
516      /* --- the following bits of info are returned as NULL-terminated strings --- */
517      case DEVINFO_STR_NAME:                     info->s = "Einstein daisy";                        break;
518      case DEVINFO_STR_FAMILY:                  info->s = "Z80";                              break;
519      case DEVINFO_STR_VERSION:                  info->s = "1.0";                              break;
520      case DEVINFO_STR_SOURCE_FILE:               info->s = __FILE__;                              break;
521      case DEVINFO_STR_CREDITS:                  info->s = "Copyright the MESS Team";               break;
522   }
523}
524
525
481526#ifdef UNUSED_FUNCTION
482527/* not required for this interrupt source */
483528static void einstein_fire_int_reset(int which)
r3352r3353
486531
487532   einstein_update_interrupts(Machine);
488533}
489#endif
490534
491static int einstein_keyboard_interrupt(int which)
492{
493   logerror("keyboard int routine in daisy chain\n");
494535
495   /* return vector */
496   return 0x0ff;
497}
498
499static int einstein_adc_interrupt(int which)
500{
501   logerror("adc int routine in daisy chain\n");
502   /* return vector */
503   return 0x0ff;
504}
505
506#ifdef UNUSED_FUNCTION
507536static int einstein_fire_interrupt(int which)
508537{
509538   logerror("fire int routine in daisy chain\n");
510539   /* return vector */
511540   return 0x0ff;
512541}
513#endif
514542
515/* reti has no effect on this interrupt */
516static void einstein_keyboard_reti(int which)
517{
518}
519543
520544/* reti has no effect on this interrupt */
521static void einstein_adc_reti(int which)
522{
523}
524
525#ifdef UNUSED_FUNCTION
526/* reti has no effect on this interrupt */
527545static void einstein_fire_reti(int which)
528546{
529547}
530548#endif
531549
532static void einstein_z80pio_reset(int which)
550static const z80_daisy_chain einstein_daisy_chain[] =
533551{
534   z80pio_reset( einstein_z80pio );
535}
536
537static int einstein_z80pio_irq_state(int which)
538{
539   return z80pio_irq_state( einstein_z80pio );
540}
541
542static int einstein_z80pio_irq_ack(int which)
543{
544   return z80pio_irq_ack( einstein_z80pio );
545}
546
547static void einstein_z80pio_irq_reti(int which)
548{
549   z80pio_irq_reti( einstein_z80pio );
550}
551
552static const struct z80_irq_daisy_chain einstein_daisy_chain[] =
553{
554   {einstein_keyboard_int_reset, einstein_keyboard_interrupt, 0, einstein_keyboard_reti, 0},
555    {z80ctc_reset, z80ctc_irq_state, z80ctc_irq_ack, z80ctc_irq_reti, 0},
556   {einstein_adc_int_reset,einstein_adc_interrupt, 0, einstein_adc_reti, 0},
557   {einstein_z80pio_reset, einstein_z80pio_irq_state, einstein_z80pio_irq_ack, einstein_z80pio_irq_reti, 0},
552   { DEVICE_GET_INFO_NAME( einstein_daisy ), "keyboard_daisy" },
553//   {einstein_keyboard_int_reset, einstein_keyboard_interrupt, 0, einstein_keyboard_reti, 0},
554   { Z80CTC, "z80ctc" },
555   { DEVICE_GET_INFO_NAME( einstein_daisy ), "adc_daisy" },
556//   {einstein_adc_int_reset,einstein_adc_interrupt, 0, einstein_adc_reti, 0},
557   { Z80PIO, "z80pio" },
558558//  {einstein_fire_int_reset,einstein_fire_interrupt, einstein_fire_reti, 0},
559   {0,0,0,0,-1}
559   { NULL }
560560};
561561
562562static  READ8_HANDLER(einstein_vdp_r)
r3352r3353
675675   return z80pio_r( einstein_z80pio, offset );
676676}
677677
678static  READ8_HANDLER(einstein_ctc_r)
678static  READ8_DEVICE_HANDLER(einstein_ctc_r)
679679{
680680   logerror("ctc r: %04x\n",offset);
681681
682   return z80ctc_0_r(machine, offset & 0x03);
682   return z80ctc_r(device, offset & 0x03);
683683}
684684
685static WRITE8_HANDLER(einstein_ctc_w)
685static WRITE8_DEVICE_HANDLER(einstein_ctc_w)
686686{
687687   logerror("ctc w: %04x %02x\n",offset,data);
688688
689   z80ctc_0_w(machine, offset & 0x03,data);
689   z80ctc_w(device, offset & 0x03,data);
690690}
691691
692692static WRITE8_HANDLER(einstein_serial_w)
r3352r3353
10191019      case 0x2d:
10201020      case 0x2e:
10211021      case 0x2f:
1022         return einstein_ctc_r(machine, offset);
1022         return einstein_ctc_r( device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), offset);
10231023      case 0x30:
10241024      case 0x31:
10251025      case 0x32:
r3352r3353
11231123      case 0x2d:
11241124      case 0x2e:
11251125      case 0x2f:
1126         einstein_ctc_w(machine, offset,data);
1126         einstein_ctc_w( device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), offset,data);
11271127         return;
11281128      case 0x30:
11291129      case 0x31:
r3352r3353
12121212      case 0x2d:
12131213      case 0x2e:
12141214      case 0x2f:
1215         return einstein_ctc_r(machine, offset);
1215         return einstein_ctc_r( device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), offset);
12161216      case 0x30:
12171217      case 0x31:
12181218      case 0x32:
r3352r3353
12991299      case 0x2d:
13001300      case 0x2e:
13011301      case 0x2f:
1302         einstein_ctc_w(machine, offset,data);
1302         einstein_ctc_w( device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), offset,data);
13031303         return;
13041304      case 0x30:
13051305      case 0x31:
r3352r3353
14381438   memory_set_bankptr(3, mess_ram);
14391439   memory_set_bankptr(4, mess_ram+0x02000);
14401440
1441   z80ctc_init(0, &einstein_ctc_intf);
14421441   msm8251_init(&einstein_msm8251_intf);
14431442
1444   z80ctc_reset(0);
1445
14461443   TMS9928A_reset ();
14471444
14481445   einstein_rom_enabled = 1;
r3352r3353
14651462
14661463   /* the input to channel 0 and 1 of the ctc is a 2mhz clock */
14671464   einstein_ctc_trigger = 0;
1468   timer_pulse(ATTOTIME_IN_HZ(2000000), NULL, 0, einstein_ctc_trigger_callback);
1465   timer_pulse(ATTOTIME_IN_HZ(2000000), (void *)device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), 0, einstein_ctc_trigger_callback);
14691466
14701467   centronics_config(0, einstein_cent_config);
14711468   /* assumption: select is tied low */
r3352r3353
17311728   MDRV_MACHINE_RESET( einstein )
17321729
17331730   MDRV_Z80PIO_ADD( "z80pio", einstein_pio_intf )
1731   MDRV_Z80CTC_ADD( "z80ctc", einstein_ctc_intf )
1732   MDRV_DEVICE_ADD( "keyboard_daisy", DEVICE_GET_INFO_NAME( einstein_daisy ) )
1733   MDRV_DEVICE_ADD( "adc_daisy", DEVICE_GET_INFO_NAME( einstein_daisy ) )
17341734
17351735    /* video hardware */
17361736   MDRV_IMPORT_FROM(tms9928a)
src/mess/drivers/osborne1.c
r3352r3353
4040#include "cpu/z80/z80daisy.h"
4141#include "includes/osborne1.h"
4242
43
4344#define MAIN_CLOCK   15974400
4445
46
4547static ADDRESS_MAP_START( osborne1_mem, ADDRESS_SPACE_PROGRAM, 8 )
4648   AM_RANGE( 0x0000, 0x0FFF ) AM_READWRITE( SMH_BANK1, osborne1_0000_w )
4749   AM_RANGE( 0x1000, 0x1FFF ) AM_READWRITE( SMH_BANK2, osborne1_1000_w )
r3352r3353
5153   AM_RANGE( 0xF000, 0xFFFF ) AM_READWRITE( SMH_BANK4, osborne1_videoram_w )
5254ADDRESS_MAP_END
5355
56
5457static ADDRESS_MAP_START( osborne1_io, ADDRESS_SPACE_IO, 8 )
5558   ADDRESS_MAP_UNMAP_HIGH
5659   ADDRESS_MAP_GLOBAL_MASK(0xff)
5760   AM_RANGE( 0x00, 0x03 ) AM_WRITE( osborne1_bankswitch_w )
5861ADDRESS_MAP_END
5962
63
6064static INPUT_PORTS_START( osborne1 )
6165   PORT_START("ROW0")
6266   PORT_BIT(0x80, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH2)   PORT_CHAR('[') PORT_CHAR(']')
r3352r3353
141145   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_UNUSED)
142146INPUT_PORTS_END
143147
144static PALETTE_INIT( osborne1 ) {
148
149static PALETTE_INIT( osborne1 )
150{
145151   palette_set_color_rgb( machine, 0, 0, 0, 0 );   /* Black */
146152   palette_set_color_rgb( machine, 1, 0, 255, 0 );   /* Full */
147153   palette_set_color_rgb( machine, 2, 0, 128, 0 );   /* Dimmed */
148154}
149155
156
157static const z80_daisy_chain osborne1_daisy_chain[] =
158{
159/*   { osborne1_z80_reset, osborne1_z80_irq_state, osborne1_z80_irq_ack, osborne1_z80_irq_reti, 0 }, */
160   { OSBORNE1_DAISY, "osborne1_daisy" },
161   { NULL }
162};
163
164
150165static MACHINE_DRIVER_START( osborne1 )
151166   MDRV_CPU_ADD( "main", Z80, MAIN_CLOCK/4 )
152167   MDRV_CPU_PROGRAM_MAP( osborne1_mem, 0 )
r3352r3353
156171   MDRV_MACHINE_START( osborne1 )
157172   MDRV_MACHINE_RESET( osborne1 )
158173
174   MDRV_DEVICE_ADD( "osborne1_daisy", OSBORNE1_DAISY )
175
159176   MDRV_SCREEN_ADD("main", RASTER)
160177   MDRV_SCREEN_FORMAT( BITMAP_FORMAT_INDEXED16 )
161178   MDRV_SCREEN_RAW_PARAMS( MAIN_CLOCK/2, 512, 0, 416, 260, 0, 240 )
r3352r3353
169186   MDRV_SOUND_ROUTE( ALL_OUTPUTS, "mono", 1.00 )
170187MACHINE_DRIVER_END
171188
189
172190ROM_START( osborne1 )
173191   ROM_REGION(0x1000, "main", 0)
174192   ROM_SYSTEM_BIOS( 0, "ver144", "BIOS version 1.44" )
r3352r3353
189207   ROM_LOAD( "osbchr.bin", 0x0000, 0x800, BAD_DUMP CRC(6c1eab0d) SHA1(b04459d377a70abc9155a5486003cb795342c801) )
190208ROM_END
191209
192static void osborne1_floppy_getinfo( const mess_device_class *devclass, UINT32 state, union devinfo *info ) {
193   switch( state ) {
210
211static void osborne1_floppy_getinfo( const mess_device_class *devclass, UINT32 state, union devinfo *info )
212{
213   switch( state )
214   {
194215   case MESS_DEVINFO_INT_COUNT:            info->i = 2; break;
195216   case MESS_DEVINFO_PTR_LOAD:            info->load = DEVICE_IMAGE_LOAD_NAME(osborne1_floppy); break;
196217   case MESS_DEVINFO_STR_FILE_EXTENSIONS:   strcpy( info->s = device_temp_str(), "img" ); break;
r3352r3353
198219   }
199220}
200221
222
201223static SYSTEM_CONFIG_START( osborne1 )
202224   CONFIG_DEVICE( osborne1_floppy_getinfo )
203225   CONFIG_RAM_DEFAULT( 68 * 1024 )      /* 64KB Main RAM and 4Kbit video attribute RAM */
204226SYSTEM_CONFIG_END
205227
228
206229/*    YEAR  NAME        PARENT  COMPAT  MACHINE     INPUT       INIT        CONFIG      COMPANY     FULLNAME        FLAGS */
207230COMP( 1981, osborne1,   0,      0,      osborne1,   osborne1,   osborne1,   osborne1,   "Osborne",  "Osborne-1",    0 )
src/mess/drivers/kc.c
r3352r3353
5858      case 0x08d:
5959      case 0x08e:
6060      case 0x08f:
61         return kc85_ctc_r(machine, port-0x08c);
61         return kc85_ctc_r(device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), port-0x08c);
6262
6363   }
6464
r3352r3353
102102      case 0x08d:
103103      case 0x08e:
104104      case 0x08f:
105         kc85_ctc_w(machine, port-0x08c, data);
105         kc85_ctc_w(device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), port-0x08c, data);
106106         return;
107107   }
108108
r3352r3353
154154      case 0x08d:
155155      case 0x08e:
156156      case 0x08f:
157         return kc85_ctc_r(machine, port-0x08c);
157         return kc85_ctc_r(device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), port-0x08c);
158158   }
159159
160160   logerror("unhandled port r: %04x\n",offset);
r3352r3353
187187      case 0x08d:
188188      case 0x08e:
189189      case 0x08f:
190         kc85_ctc_w(machine, port-0x08c, data);
190         kc85_ctc_w(device_list_find_by_tag(machine->config->devicelist, Z80CTC, "z80ctc"), port-0x08c, data);
191191         return;
192192   }
193193
r3352r3353
317317   AM_RANGE(0x0f4, 0x0f5) AM_READ(kc85_disc_hw_input_gate_r)
318318   /*{0x0f6, 0x0f7, SMH_NOP},*/      /* for controller */
319319   AM_RANGE(0x0f8, 0x0f9) AM_WRITE( kc85_disc_hw_terminal_count_w) /* terminal count */
320   AM_RANGE(0x0fc, 0x0ff) AM_READWRITE(kc85_disk_hw_ctc_r, kc85_disk_hw_ctc_w)
320   AM_RANGE(0x0fc, 0x0ff) AM_DEVREADWRITE(Z80CTC, "z80ctc_1", kc85_disk_hw_ctc_r, kc85_disk_hw_ctc_w)
321321ADDRESS_MAP_END
322322
323323static MACHINE_DRIVER_START( cpu_kc_disc )
324324   MDRV_CPU_ADD("disc", Z80, 4000000)
325325   MDRV_CPU_PROGRAM_MAP(kc85_disc_hw_mem, 0)
326326   MDRV_CPU_IO_MAP(kc85_disc_hw_io, 0)
327
328//   MDRV_Z80CTC_ADD( "z80ctc_1", kc85_disc_ctc_intf )
327329MACHINE_DRIVER_END
328330
329331
r3352r3353
339341   MDRV_MACHINE_RESET( kc85_3 )
340342
341343   MDRV_Z80PIO_ADD( "z80pio", kc85_pio_intf )
344   MDRV_Z80CTC_ADD( "z80ctc", kc85_ctc_intf )
342345
343346   /* video hardware */
344347   MDRV_SCREEN_ADD("main", RASTER)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team