Previous 15994 Revisions Next

r6338 Sunday 8th November, 2009 at 17:07:13 UTC by Curt Coder
Refactored Z80 DMA to use devcb.
[src/emu/machine]z80dma.c z80dma.h
[src/mess/drivers]p8k.c x1.c
[src/mess/machine]conkort.c

src/emu/machine/z80dma.c
r6337r6338
9797typedef struct _z80dma_t z80dma_t;
9898struct _z80dma_t
9999{
100   const z80dma_interface *intf;
100   devcb_resolved_write_line   out_busreq_func;
101   devcb_resolved_write_line   out_int_func;
102   devcb_resolved_write_line   out_bao_func;
103   devcb_resolved_read8      in_mreq_func;
104   devcb_resolved_write8      out_mreq_func;
105   devcb_resolved_read8      in_iorq_func;
106   devcb_resolved_write8      out_iorq_func;
107
101108   emu_timer *timer;
102109
103110   UINT16    regs[REGNUM(6,1)+1];
r6337r6338
147154         if (PORTA_IS_SOURCE(cntx))
148155         {
149156            if (PORTA_MEMORY(cntx))
150               cntx->latch = cntx->intf->memory_read(device, cntx->addressA);
157               cntx->latch = devcb_call_read8(&cntx->in_mreq_func, cntx->addressA);
151158            else
152               cntx->latch = cntx->intf->portA_read(device, cntx->addressA);
159               cntx->latch = devcb_call_read8(&cntx->in_iorq_func, cntx->addressA);
153160
154161            LOG(("A src: %04x \n",cntx->addressA));
155162            cntx->addressA += PORTA_FIXED(cntx) ? 0 : PORTA_INC(cntx) ? PORTA_STEP(cntx) : -PORTA_STEP(cntx);
r6337r6338
157164         else
158165         {
159166            if (PORTB_MEMORY(cntx))
160               cntx->latch = cntx->intf->memory_read(device, cntx->addressB);
167               cntx->latch = devcb_call_read8(&cntx->in_mreq_func, cntx->addressB);
161168            else
162               cntx->latch = cntx->intf->portB_read(device, cntx->addressB);
169               cntx->latch = devcb_call_read8(&cntx->in_iorq_func, cntx->addressB);
163170
164171            LOG(("B src: %04x \n",cntx->addressB));
165172            cntx->addressB += PORTB_FIXED(cntx) ? 0 : PORTB_INC(cntx) ? PORTB_STEP(cntx) : -PORTB_STEP(cntx);
r6337r6338
190197         if (PORTA_IS_SOURCE(cntx))
191198         {
192199            if (PORTB_MEMORY(cntx))
193               cntx->intf->memory_write(device, cntx->addressB, cntx->latch);
200               devcb_call_write8(&cntx->out_mreq_func, cntx->addressB, cntx->latch);
194201            else
195               cntx->intf->portB_write(device, cntx->addressB, cntx->latch);
202               devcb_call_write8(&cntx->out_iorq_func, cntx->addressB, cntx->latch);
196203
197204            LOG(("B dst: %04x \n",cntx->addressB));
198205            cntx->addressB += PORTB_FIXED(cntx) ? 0 : PORTB_INC(cntx) ? PORTB_STEP(cntx) : -PORTB_STEP(cntx);
r6337r6338
200207         else
201208         {
202209            if (PORTA_MEMORY(cntx))
203               cntx->intf->memory_write(device, cntx->addressA, cntx->latch);
210               devcb_call_write8(&cntx->out_mreq_func, cntx->addressA, cntx->latch);
204211            else
205               cntx->intf->portA_write(device, cntx->addressA, cntx->latch);
212               devcb_call_write8(&cntx->out_iorq_func, cntx->addressA, cntx->latch);
206213
207214            LOG(("A dst: %04x \n",cntx->addressA));
208215            cntx->addressA += PORTA_FIXED(cntx) ? 0 : PORTA_INC(cntx) ? PORTA_STEP(cntx) : -PORTA_STEP(cntx);
r6337r6338
296303      timer_reset(z80dma->timer, attotime_never);
297304   }
298305
299   /* set the halt line */
300   if (z80dma->intf && z80dma->intf->cputag != NULL)
301   {
302      //FIXME: Synchronization is done by BUSREQ!
303      cputag_set_input_line(device->machine, z80dma->intf->cputag, INPUT_LINE_HALT,
304         pending_transfer ? ASSERT_LINE : CLEAR_LINE);
305   }
306   /* set the busreq line */
307   devcb_call_write_line(&z80dma->out_busreq_func, pending_transfer ? ASSERT_LINE : CLEAR_LINE);
306308}
307309
308310/* ----------------------------------------------------------------------- */
r6337r6338
423425               LOG(("Disable DMA\n"));
424426               cntx->dma_enabled = 0;
425427               cntx->rdy = 1 ^ ((WR5(cntx) & 0x8)>>3);
426               z80dma_rdy_w(device, 0, cntx->rdy);
428               z80dma_rdy_w(device, cntx->rdy);
427429               break;
428430            case 0x87:   /* Enable dma */
429431               LOG(("Enable DMA\n"));
430432               cntx->dma_enabled = 1;
431433               cntx->rdy = (WR5(cntx) & 0x8)>>3;
432               z80dma_rdy_w(device, 0, cntx->rdy);
434               z80dma_rdy_w(device, cntx->rdy);
433435               break;
434436            case 0xBB:
435437               LOG(("Set Read Mask\n"));
r6337r6338
453455            case 0xB3:   /* Force ready */
454456               LOG(("Force ready\n"));
455457               cntx->rdy = (WR5(cntx) & 0x8)>>3;
456               z80dma_rdy_w(device, 0, cntx->rdy);
458               z80dma_rdy_w(device, cntx->rdy);
457459               break;
458460            case 0xAB:   /* Enable interrupts */
459461               LOG(("Enable IRQ\n"));
r6337r6338
512514}
513515
514516
515WRITE8_DEVICE_HANDLER( z80dma_rdy_w )
517WRITE_LINE_DEVICE_HANDLER( z80dma_rdy_w )
516518{
517519   z80dma_t *z80dma = get_safe_token(device);
518520   int param;
519521
520522   assert( offset == 0);
521523
522   param = (data ? 1 : 0);
523   LOG(("RDY: %d Active High: %d\n", data, READY_ACTIVE_HIGH(z80dma)));
524   param = (state ? 1 : 0);
525   LOG(("RDY: %d Active High: %d\n", state, READY_ACTIVE_HIGH(z80dma)));
524526   timer_call_after_resynch(device->machine, (void *) device, param, z80dma_rdy_write_callback);
525527}
526528
529WRITE_LINE_DEVICE_HANDLER( z80dma_wait_w )
530{
531}
527532
533WRITE_LINE_DEVICE_HANDLER( z80dma_bai_w )
534{
535}
536
537
528538/***************************************************************************
529539    DAISY CHAIN INTERFACE
530540***************************************************************************/
r6337r6338
552562static DEVICE_START( z80dma )
553563{
554564   z80dma_t *z80dma = get_safe_token(device);
565   z80dma_interface *intf = (z80dma_interface *)device->static_config;
555566
556   /* validate arguments */
557   assert(device != NULL);
558   assert(device->tag != NULL);
567   /* resolve callbacks */
568   devcb_resolve_write_line(&z80dma->out_busreq_func, &intf->out_busreq_func, device);
569   devcb_resolve_write_line(&z80dma->out_int_func, &intf->out_int_func, device);
570   devcb_resolve_write_line(&z80dma->out_bao_func, &intf->out_bao_func, device);
571   devcb_resolve_read8(&z80dma->in_mreq_func, &intf->in_mreq_func, device);
572   devcb_resolve_write8(&z80dma->out_mreq_func, &intf->out_mreq_func, device);
573   devcb_resolve_read8(&z80dma->in_iorq_func, &intf->in_iorq_func, device);
574   devcb_resolve_write8(&z80dma->out_iorq_func, &intf->out_iorq_func, device);
559575
560   z80dma->intf = (const z80dma_interface *)device->static_config;
561
576   /* allocate timer */
562577   z80dma->timer = timer_alloc(device->machine, z80dma_timerproc, (void *) device);
563578
579   /* register for state saving */
564580   state_save_register_device_item_array(device, 0, z80dma->regs);
565581   state_save_register_device_item_array(device, 0, z80dma->regs_follow);
566
567582   state_save_register_device_item(device, 0, z80dma->num_follow);
568583   state_save_register_device_item(device, 0, z80dma->cur_follow);
569584   state_save_register_device_item(device, 0, z80dma->status);
570585   state_save_register_device_item(device, 0, z80dma->dma_enabled);
571
572586   state_save_register_device_item(device, 0, z80dma->addressA);
573587   state_save_register_device_item(device, 0, z80dma->addressB);
574588   state_save_register_device_item(device, 0, z80dma->count);
r6337r6338
612626      case DEVINFO_FCT_IRQ_RETI:                  info->f = (genf *)z80dma_irq_reti;      break;
613627
614628      /* --- the following bits of info are returned as NULL-terminated strings --- */
615      case DEVINFO_STR_NAME:                     strcpy(info->s, "Z80DMA");            break;
616      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "DMA controllers");      break;
629      case DEVINFO_STR_NAME:                     strcpy(info->s, "Z8410");            break;
630      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "Z80DMA");            break;
617631      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");               break;
618632      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);            break;
619633      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break;
620634   }
621635}
622
src/emu/machine/z80dma.h
r6337r6338
1/**********************************************************************
1/***************************************************************************
22
3    Z80 DMA interface and emulation
3    Zilog Z80 DMA Direct Memory Access Controller emulation
44
5 **********************************************************************/
5    Copyright Nicola Salmoria and the MAME Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
67
7#ifndef Z80DMA_H
8#define Z80DMA_H
8****************************************************************************
9                            _____   _____
10               A5    1 |*    \_/     | 40  A6
11               A4   2 |             | 39  A7
12               A3    3 |             | 38  IEI
13               A2    4 |             | 37  _INT/_PULSE
14               A1   5 |             | 36  IEO
15               A0   6 |             | 35  D0
16               CLK   7 |             | 34  D1
17               _WR   8 |             | 33  D2
18                   _RD   9 |             | 32  D3
19             _IORQ  10 |    Z8410    | 31  D4
20                   +5V  11 |             | 30  GND
21                 _MREQ  12 |             | 29  D5
22                  _BAO  13 |             | 28  D6
23                  _BAI  14 |             | 27  D7
24               _BUSREQ  15 |             | 26  _M1
25             _CE/_WAIT  16 |             | 25  RDY
26                   A15  17 |             | 24  A8
27                   A14  18 |             | 23  A9
28                   A13  19 |             | 22  A10
29                   A12  20 |_____________| 21  A11
930
31***************************************************************************/
32
33#ifndef __Z80DMA__
34#define __Z80DMA__
35
36#include "devcb.h"
37
38/***************************************************************************
39    MACROS / CONSTANTS
40***************************************************************************/
41
1042#define Z80DMA DEVICE_GET_INFO_NAME(z80dma)
1143
1244#define MDRV_Z80DMA_ADD(_tag, _clock, _config) \
1345   MDRV_DEVICE_ADD(_tag, Z80DMA, _clock) \
1446   MDRV_DEVICE_CONFIG(_config)
1547
48#define Z80DMA_INTERFACE(_name) \
49   const z80dma_interface (_name) =
50
51/***************************************************************************
52    TYPE DEFINITIONS
53***************************************************************************/
54
1655typedef struct _z80dma_interface z80dma_interface;
1756struct _z80dma_interface
1857{
19   /* CPU to halt when DMA is active */
20   const char *cputag;
58   devcb_write_line   out_busreq_func;
59   devcb_write_line   out_int_func;
60   devcb_write_line   out_bao_func;
2161
22   /* accessors to main memory */
23   read8_device_func   memory_read;
24   write8_device_func   memory_write;
62   /* memory accessors */
63   devcb_read8         in_mreq_func;
64   devcb_write8      out_mreq_func;
2565
26   /* port accesors */
27   read8_device_func   portA_read;
28   write8_device_func   portA_write;
29   read8_device_func   portB_read;
30   write8_device_func   portB_write;
31
32   /* interrupt callback - not implemented */
33   void (*irq_cb)(const device_config *device, int state);
66   /* I/O accessors */
67   devcb_read8         in_iorq_func;
68   devcb_write8      out_iorq_func;
3469};
3570
36/* device interface */
37DEVICE_GET_INFO( z80dma );
71/***************************************************************************
72    PROTOTYPES
73***************************************************************************/
3874
75/* register access */
3976READ8_DEVICE_HANDLER( z80dma_r );
40WRITE8_DEVICE_HANDLER( z80dma_w);
77WRITE8_DEVICE_HANDLER( z80dma_w );
4178
42WRITE8_DEVICE_HANDLER( z80dma_rdy_w );
79/* ready */
80WRITE_LINE_DEVICE_HANDLER( z80dma_rdy_w );
4381
44#endif /* Z80_H */
82/* wait */
83WRITE_LINE_DEVICE_HANDLER( z80dma_wait_w );
84
85/* bus acknowledge in */
86WRITE_LINE_DEVICE_HANDLER( z80dma_bai_w );
87
88DEVICE_GET_INFO( z80dma );
89
90#endif
src/mess/machine/conkort.c
r6337r6338
630630
631631*/
632632
633static void dma_irq_callback(const device_config *device, int state)
633static Z80DMA_INTERFACE( dma_intf )
634634{
635   fast_t *conkort = get_safe_token_machine_fast(device->machine);
636
637   cpu_set_input_line(conkort->cpu, INPUT_LINE_IRQ0, state);
638}
639
640static READ8_DEVICE_HANDLER( dma_port_a_r )
641{
642   fast_t *conkort = get_safe_token_machine_fast(device->machine);
643   const address_space *program = cpu_get_address_space(conkort->cpu, ADDRESS_SPACE_PROGRAM);
644
645   UINT8 data = 0xff;
646
647   data = memory_read_byte_8le(program, offset);
648
649   return data;
650}
651
652static WRITE8_DEVICE_HANDLER( dma_port_a_w )
653{
654   fast_t *conkort = get_safe_token_machine_fast(device->machine);
655   const address_space *program = cpu_get_address_space(conkort->cpu, ADDRESS_SPACE_PROGRAM);
656
657   memory_write_byte_8le(program, offset, data);
658}
659
660static READ8_DEVICE_HANDLER( dma_port_b_r )
661{
662   fast_t *conkort = get_safe_token_machine_fast(device->machine);
663   const address_space *io = cpu_get_address_space(conkort->cpu, ADDRESS_SPACE_IO);
664
665   UINT8 data = 0xff;
666
667   data = memory_read_byte_8le(io, offset);
668
669   return data;
670}
671
672static WRITE8_DEVICE_HANDLER( dma_port_b_w )
673{
674   fast_t *conkort = get_safe_token_machine_fast(device->machine);
675   const address_space *io = cpu_get_address_space(conkort->cpu, ADDRESS_SPACE_IO);
676
677   memory_write_byte_8le(io, offset, data);
678}
679
680static const z80dma_interface dma_intf =
681{
682   "conkort:5a",      /* cpu to HALT */
683   dma_port_a_r,      /* memory read */
684   dma_port_a_w,      /* memory write */
685   dma_port_a_r,      /* port A read */
686   dma_port_a_w,      /* port A write */
687   dma_port_b_r,      /* port B read */
688   dma_port_b_w,      /* port B write */
689   dma_irq_callback   /* interrupt callback */
635   DEVCB_CPU_INPUT_LINE("conkort:5a", INPUT_LINE_HALT),
636   DEVCB_CPU_INPUT_LINE("conkort:5a", INPUT_LINE_IRQ0),
637   DEVCB_NULL,
638   DEVCB_MEMORY_HANDLER("conkort:5a", PROGRAM, memory_read_byte),
639   DEVCB_MEMORY_HANDLER("conkort:5a", PROGRAM, memory_write_byte),
640   DEVCB_MEMORY_HANDLER("conkort:5a", IO, memory_read_byte),
641   DEVCB_MEMORY_HANDLER("conkort:5a", IO, memory_write_byte)
690642};
691643
692644static const z80_daisy_chain fast_daisy_chain[] =
r6337r6338
715667static WRITE_LINE_DEVICE_HANDLER( fast_wd1793_drq_w )
716668{
717669   fast_t *conkort = get_safe_token_machine_fast(device->machine);
718   z80dma_rdy_w(conkort->z80dma, 0, state);
670   z80dma_rdy_w(conkort->z80dma, state);
719671}
720672
721673static const wd17xx_interface fast_wd17xx_interface =
src/mess/drivers/x1.c
r6337r6338
15781578   NULL      /* update address callback */
15791579};
15801580
1581static READ8_DEVICE_HANDLER(x1_dma_read_byte)
1581static Z80DMA_INTERFACE( x1_dma )
15821582{
1583   const address_space *space = cputag_get_address_space(device->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
1584   return memory_read_byte(space, offset);
1585}
1586
1587static WRITE8_DEVICE_HANDLER(x1_dma_write_byte)
1588{
1589   const address_space *space = cputag_get_address_space(device->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
1590   memory_write_byte(space, offset, data);
1591}
1592
1593static READ8_DEVICE_HANDLER(x1_dma_read_io)
1594{
1595   const address_space *space = cputag_get_address_space(device->machine, "maincpu", ADDRESS_SPACE_IO);
1596   return memory_read_byte(space, offset);
1597}
1598
1599static WRITE8_DEVICE_HANDLER(x1_dma_write_io)
1600{
1601   const address_space *space = cputag_get_address_space(device->machine, "maincpu", ADDRESS_SPACE_IO);
1602   memory_write_byte(space, offset, data);
1603}
1604
1605
1606static const z80dma_interface x1_dma =
1607{
1608   "maincpu",
1609
1610   x1_dma_read_byte,
1611   x1_dma_write_byte,
1612   x1_dma_read_io, x1_dma_write_io, x1_dma_read_io, x1_dma_write_io,
1613   NULL
1583   DEVCB_CPU_INPUT_LINE("maincpu", INPUT_LINE_HALT),
1584   DEVCB_NULL,
1585   DEVCB_NULL,
1586   DEVCB_MEMORY_HANDLER("maincpu", PROGRAM, memory_read_byte),
1587   DEVCB_MEMORY_HANDLER("maincpu", PROGRAM, memory_write_byte),
1588   DEVCB_MEMORY_HANDLER("maincpu", IO, memory_read_byte),
1589   DEVCB_MEMORY_HANDLER("maincpu", IO, memory_write_byte)
16141590};
16151591
16161592/*************************************
src/mess/drivers/p8k.c
r6337r6338
206206
207207/* Z80 DMA */
208208
209static READ8_DEVICE_HANDLER(p8k_dma_read_byte)
210{
211   const address_space *space = cputag_get_address_space(device->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
212   return memory_read_byte(space, offset);
213}
209// still to implement: dma io read/write which handle FDC. also, the interrupt should deal with FDC as well, with p8k_daisy_interrupt as a fallback
214210
215static WRITE8_DEVICE_HANDLER(p8k_dma_write_byte)
211static Z80DMA_INTERFACE( p8k_dma_intf )
216212{
217   const address_space *space = cputag_get_address_space(device->machine, "maincpu", ADDRESS_SPACE_PROGRAM);
218   memory_write_byte(space, offset, data);
219}
220
221// still to implement: dma io read/write which handle FDC. also, the interrupt should deal with FDC as well, with p8k_daisy_interrupt as a fallback
222static const z80dma_interface p8k_dma_intf =
223{
224   "maincpu",
225   p8k_dma_read_byte,
226   p8k_dma_write_byte,
227   NULL, NULL, NULL, NULL,
228   p8k_daisy_interrupt
213   DEVCB_CPU_INPUT_LINE("maincpu", INPUT_LINE_HALT),
214   DEVCB_CPU_INPUT_LINE("maincpu", INPUT_LINE_IRQ0),
215   DEVCB_NULL,
216   DEVCB_MEMORY_HANDLER("maincpu", PROGRAM, memory_read_byte),
217   DEVCB_MEMORY_HANDLER("maincpu", PROGRAM, memory_write_byte),
218   DEVCB_MEMORY_HANDLER("maincpu", IO, memory_read_byte),
219   DEVCB_MEMORY_HANDLER("maincpu", IO, memory_write_byte)
229220};
230221
231222/* Z80 CTC 0 */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team