Previous 15994 Revisions Next

r5013 Saturday 13th June, 2009 at 15:20:46 UTC by Wilbert Pol
Made the 8237 dma controller emulation more accurate by implementing it as a state machine.
Deprecated the dma8237_run_transfer function.
[src/emu/machine]8237dma.c 8237dma.h
[src/mess/drivers]mikromik.c
[src/mess/machine]at.c bebox.c pc.c

src/emu/machine/8237dma.c
r5012r5013
2323#include "8237dma.h"
2424
2525
26/* States that the dma8237 device can be in */
27typedef enum {
28   DMA8237_SI,         /* Idle state */
29   DMA8237_S0,         /* HRQ has been triggered, waiting to receive HLDA */
30//   DMA8237_SW,         /* Wait state */
31
32   /* Normal transfer states */
33   DMA8237_S1,         /* Output A8-A15; only used when A8-A15 really needs to be output */
34   DMA8237_S2,         /* Output A0-A7 */
35   DMA8237_S3,         /* Initiate read; skipped in compressed timing. On the S2->S3 transition DACK is set. */
36   DMA8237_S4,         /* Perform read/write */
37
38   /* Memory to memory transfer states */
39   DMA8237_S11,      /* Output A8-A15 */
40//   DMA8237_S12,      /* Output A0-A7 */
41//   DMA8237_S13,      /* Initiate read */
42//   DMA8237_S14,      /* Perform read/write */
43//   DMA8237_S21,      /* Output A8-A15 */
44//   DMA8237_S22,      /* Output A0-A7 */
45//   DMA8237_S23,      /* Initiate read */
46//   DMA8237_S24,      /* Perform read/write */
47} dma8237_state;
48
49
2650typedef struct dma8237   dma8237_t;
2751
2852struct dma8237
2953{
3054   const struct dma8237_interface *intf;
3155   emu_timer *timer;
32   emu_timer *msbflip_timer;
3356
3457   struct
3558   {
59      UINT16 base_address;
60      UINT16 base_count;
3661      UINT16 address;
3762      UINT16 count;
3863      UINT8 mode;
64      int high_address_changed;
3965   } chan[4];
4066
4167   UINT32 msb : 1;
4268   UINT32 eop : 1;
4369   UINT8 temp;
70   UINT8 temporary_data;
4471   UINT8 command;
4572   UINT8 drq;
4673   UINT8 mask;
74   UINT8 hrq;
75   UINT8 hlda;
4776
4877   /* bits  0- 3 :  Terminal count for channels 0-3
4978     * bits  4- 7 :  Transfer in progress for channels 0-3 */
5079   UINT8 status;
80
81   dma8237_state state;      /* State the device is currently in */
82   int service_channel;      /* Channel we will be servicing */
83   int last_service_channel;   /* Previous channel we serviced; used to determine channel priority. */
5184};
5285
5386
5487#define DMA_MODE_CHANNEL(mode)      ((mode) & 0x03)
55#define DMA_MODE_OPERATION(mode)   (((mode) >> 2) & 0x03)
56#define DMA_MODE_DIRECTION(mode)   (((mode) & 0x20) ? -1 : +1)
57#define DMA_MODE_TRANSFERMODE(mode)   (((mode) >> 6) & 0x03)
88#define DMA_MODE_OPERATION(mode)   ((mode) & 0x0c)
89#define DMA_MODE_AUTO_INIT(mode)   ((mode) & 0x10)
90#define DMA_MODE_DIRECTION(mode)   ((mode) & 0x20)
91#define DMA_MODE_TRANSFERMODE(mode)   ((mode) & 0xc0)
5892
93#define DMA8237_VERIFY_TRANSFER      0x00
94#define DMA8237_WRITE_TRANSFER      0x04
95#define DMA8237_READ_TRANSFER      0x08
96#define DMA8237_ILLEGAL_TRANSFER   0x0c
5997
98#define DMA8237_DEMAND_MODE      0x00
99#define DMA8237_SINGLE_MODE      0x40
100#define DMA8237_BLOCK_MODE      0x80
101#define DMA8237_CASCADE_MODE   0xc0
60102
61static TIMER_CALLBACK( dma8237_timerproc );
62static TIMER_CALLBACK( dma8237_msbflip_timerproc );
63static void dma8237_update_status(const device_config *device);
64103
65104/* ----------------------------------------------------------------------- */
66105
r5012r5013
75114/* ----------------------------------------------------------------------- */
76115
77116
78static int dma8237_do_operation(const device_config *device, int channel)
117INLINE void dma8237_do_read( const device_config *device )
79118{
80   dma8237_t   *dma8237 = get_safe_token(device);
81   int done;
82   UINT8 data;
83   UINT8 mode;
119   dma8237_t   *dma8237 = get_safe_token( device );
120   int         channel = dma8237->service_channel;
84121
85   mode = dma8237->chan[channel].mode;
86
87   switch(DMA_MODE_OPERATION(mode)) {
88   case 1:
89      data = dma8237->intf->channel_read_func[channel](device);
90      dma8237->intf->memory_write_func(device, channel, dma8237->chan[channel].address, data);
91
92      dma8237->chan[channel].address += DMA_MODE_DIRECTION(mode);
93      dma8237->chan[channel].count--;
94      done = (dma8237->chan[channel].count == 0xFFFF);
122   switch( DMA_MODE_OPERATION( dma8237->chan[ channel ].mode ) )
123   {
124   case DMA8237_WRITE_TRANSFER:
125      dma8237->temporary_data = dma8237->intf->channel_read_func[ channel ]( device );
95126      break;
127   case DMA8237_READ_TRANSFER:
128      dma8237->temporary_data = dma8237->intf->memory_read_func( device, channel, dma8237->chan[ channel ].address );
129      break;
130   case DMA8237_VERIFY_TRANSFER:
131   case DMA8237_ILLEGAL_TRANSFER:
132      break;
133   }
134}
96135
97   case 2:
98      data = dma8237->intf->memory_read_func(device, channel, dma8237->chan[channel].address);
99      dma8237->intf->channel_write_func[channel](device, data);
100136
101      dma8237->chan[channel].address += DMA_MODE_DIRECTION(mode);
102      dma8237->chan[channel].count--;
103      done = (dma8237->chan[channel].count == 0xFFFF);
104      break;
137INLINE void dma8237_do_write( const device_config *device )
138{
139   dma8237_t   *dma8237 = get_safe_token( device );
140   int         channel = dma8237->service_channel;
105141
106   default:
107      done = TRUE;
142   switch( DMA_MODE_OPERATION( dma8237->chan[ channel ].mode ) )
143   {
144   case DMA8237_WRITE_TRANSFER:
145      dma8237->intf->memory_write_func( device, channel, dma8237->chan[ channel ].address, dma8237->temporary_data );
108146      break;
147   case DMA8237_READ_TRANSFER:
148      dma8237->intf->channel_write_func[channel]( device, dma8237->temporary_data );
149      break;
150   case DMA8237_VERIFY_TRANSFER:
151   case DMA8237_ILLEGAL_TRANSFER:
152      break;
109153   }
110   return done;
111154}
112155
113156
114
115static TIMER_CALLBACK( dma8237_timerproc )
157INLINE void dma8237_advance( const device_config *device )
116158{
117   const device_config *device = (const device_config *)ptr;
118   dma8237_t   *dma8237 = get_safe_token(device);
119   int channel = param % 4;
120   int done;
159   dma8237_t   *dma8237 = get_safe_token( device );
160   int         channel = dma8237->service_channel;
161   int         mode = dma8237->chan[channel].mode;
121162
122   done = dma8237_do_operation(device, channel);
163   switch ( DMA_MODE_OPERATION( mode ) )
164   {
165   case DMA8237_VERIFY_TRANSFER:
166   case DMA8237_WRITE_TRANSFER:
167   case DMA8237_READ_TRANSFER:
168      dma8237->chan[channel].high_address_changed = 0;
123169
124   if (done)
125   {
126      dma8237->status &= ~(0x10 << channel);
127      dma8237->status |=  (0x01 << channel);
128      dma8237->drq    &= ~(0x01 << channel);
129      dma8237_update_status(device);
170      if ( DMA_MODE_DIRECTION( mode ) )
171      {
172         dma8237->chan[channel].address -= 1;
173         if ( ( dma8237->chan[channel].address & 0xFF ) == 0xFF )
174            dma8237->chan[channel].high_address_changed  = 1;
175      }
176      else
177      {
178         dma8237->chan[channel].address += 1;
179         if ( ( dma8237->chan[channel].address & 0xFF ) == 0x00 )
180            dma8237->chan[channel].high_address_changed = 1;
181      }
182
183      dma8237->chan[channel].count--;
184
185      if ( dma8237->chan[channel].count == 0xFFFF )
186      {
187         /* Set TC bit for this channel */
188         dma8237->status |= ( 0x01 << channel );
189
190         if ( DMA_MODE_AUTO_INIT( mode ) )
191         {
192            dma8237->chan[channel].address = dma8237->chan[channel].base_address;
193            dma8237->chan[channel].count = dma8237->chan[channel].base_count;
194            dma8237->chan[channel].high_address_changed = 1;
195         }
196         else
197         {
198            dma8237->mask |= ( 0x01 << channel );
199         }
200      }
201      break;
202   case DMA8237_ILLEGAL_TRANSFER:
203      break;
130204   }
205
131206}
132207
133208
134
135static TIMER_CALLBACK( dma8237_msbflip_timerproc )
209static TIMER_CALLBACK( dma8237_timerproc )
136210{
137211   const device_config *device = (const device_config *)ptr;
138212   dma8237_t   *dma8237 = get_safe_token(device);
139   dma8237->msb ^= 1;
140}
141213
214   /* Check if operation is disabled */
215   if ( dma8237->command & 0x04 )
216      return;
142217
218   switch ( dma8237->state ) {
143219
144static void dma8237_update_status(const device_config *device)
145{
146   dma8237_t   *dma8237 = get_safe_token(device);
147   UINT16 pending_transfer;
148   int channel;
149   UINT32 new_eop;
220   case DMA8237_SI:
221      /* Make sure EOP is high */
222      if ( ! dma8237->eop )
223      {
224         dma8237->eop = 1;
225         if ( dma8237->intf->out_eop_func )
226            dma8237->intf->out_eop_func( device, 0, dma8237->eop ? ASSERT_LINE : CLEAR_LINE );
227      }
150228
151   if ((dma8237->status & 0xF0) == 0)
152   {
153      /* no transfer is active right now; is there a transfer pending right now? */
154      pending_transfer = dma8237->drq & ~dma8237->mask;
155
156      if (pending_transfer)
229      /* Check if a new DMA request has been received. */
157230      {
158         /* we do have a transfer in progress */
159         for (channel = 3; (pending_transfer & (1 << channel)) == 0; channel--)
160            ;
231         /* Bit 6 of the command register determines whether the DREQ signals are active
232           high or active low. */
233         UINT16 pending_request = ( ( dma8237->command & 0x40 ) ? ~dma8237->drq : dma8237->drq ) & ~dma8237->mask;
161234
162         dma8237->status |= 0x10 << channel;
163         dma8237->status &= ~(0x01 << channel);
235         if ( pending_request & 0x0f )
236         {
237            int i, channel, prio_channel = 0;
164238
165         timer_adjust_periodic(dma8237->timer,
166            attotime_zero,
167            channel,
168            double_to_attotime(dma8237->intf->bus_speed));
239            /* Determine the channel that should be serviced */
240            channel = ( dma8237->command & 0x10 ) ? dma8237->last_service_channel : 3;
241            for ( i = 0; i < 4; i++ )
242            {
243               if ( pending_request & ( 1 << channel ) )
244                  prio_channel = channel;
245               channel = ( channel - 1 ) & 0x03;
246            }
247
248            /* Store the channel we will be servicing and go to the next state */
249            dma8237->service_channel = prio_channel;
250            dma8237->last_service_channel = prio_channel;
251            dma8237->hrq = 1;
252            dma8237->intf->hrq_changed( device, dma8237->hrq );
253            dma8237->state = DMA8237_S0;
254
255            timer_enable( dma8237->timer, 1 );
256         }
257         else
258         {
259            timer_enable( dma8237->timer, 0 );
260         }
169261      }
170      else
171      {
172         /* no transfers active right now */
173         timer_reset(dma8237->timer, attotime_never);
174      }
262      break;
175263
176      /* set the halt line */
177      if (dma8237->intf && dma8237->intf->cputag != NULL)
264   case DMA8237_S0:
265      /* S0 is the first of the DMA service. We have requested a hold but are waiting
266        for confirmation. */
267      if ( dma8237->hlda )
178268      {
179         cputag_set_input_line(device->machine, dma8237->intf->cputag, INPUT_LINE_HALT,
180            pending_transfer ? ASSERT_LINE : CLEAR_LINE);
269         if ( dma8237->command & 0x01 )
270         {
271            /* Memory-to-memory transfers */
272            dma8237->state = DMA8237_S11;
273         }
274         else
275         {
276            /* Regular transfers */
277            dma8237->state = DMA8237_S1;
278         }
181279      }
280      break;
182281
183      /* set the eop line, if it has changed */
184      new_eop = (dma8237->status & 0x0F) == 0x0F ? 1 : 0;
185      if (dma8237->eop != new_eop)
282   case DMA8237_S1:   /* Output A8-A15 */
283      dma8237->state = DMA8237_S2;
284      break;
285
286   case DMA8237_S2:   /* Output A7-A0 */
287      /* Check for compressed timing */
288      if ( dma8237->command & 0x08 )
289         dma8237->state = DMA8237_S4;
290      else
291         dma8237->state = DMA8237_S3;
292      break;
293
294   case DMA8237_S3:   /* Initiate read */
295      dma8237_do_read( device );
296      dma8237->state = DMA8237_S4;
297      break;
298
299   case DMA8237_S4:   /* Perform read/write */
300      /* Perform read when in compressed timing mode */
301      if ( dma8237->command & 0x08 )
302         dma8237_do_read( device );
303
304      /* Perform write */
305      dma8237_do_write( device );
306
307      /* Advance */
308      dma8237_advance( device );
309
186310      {
187         dma8237->eop = new_eop;
188         if (dma8237->intf->out_eop_func)
189            dma8237->intf->out_eop_func(device, new_eop ? ASSERT_LINE : CLEAR_LINE);
190      }
191   }
192}
311         int channel = dma8237->service_channel;
193312
313         switch( DMA_MODE_TRANSFERMODE( dma8237->chan[channel].mode ) )
314         {
315         case DMA8237_DEMAND_MODE:
316            /* Check for terminal count or EOP signal or DREQ begin de-asserted */
317            if ( ( dma8237->status & ( 0x01 << channel ) ) || ! dma8237->eop || ! ( dma8237->drq & ( 0x01 << channel ) ) )
318            {
319               dma8237->hrq = 0;
320               dma8237->hlda = 0;
321               dma8237->intf->hrq_changed( device, dma8237->hrq );
322               dma8237->state = DMA8237_SI;
323            }
324            else
325            {
326               dma8237->state = dma8237->chan[channel].high_address_changed ? DMA8237_S1 : DMA8237_S2;
327            }
328            break;
194329
330         case DMA8237_SINGLE_MODE:
331            dma8237->hrq = 0;
332            dma8237->hlda = 0;
333            dma8237->intf->hrq_changed( device, dma8237->hrq );
334            dma8237->state = DMA8237_SI;
335            break;
195336
196/* ----------------------------------------------------------------------- */
337         case DMA8237_BLOCK_MODE:
338            /* Check for terminal count or EOP signal */
339            if ( ( dma8237->status & ( 0x01 << channel ) ) || ! dma8237->eop )
340            {
341               dma8237->hrq = 0;
342               dma8237->hlda = 0;
343               dma8237->intf->hrq_changed( device, dma8237->hrq );
344               dma8237->state = DMA8237_SI;
345            }
346            else
347            {
348               dma8237->state = dma8237->chan[channel].high_address_changed ? DMA8237_S1 : DMA8237_S2;
349            }
350            break;
197351
352         case DMA8237_CASCADE_MODE:
353            if ( ! ( dma8237->drq & ( 0x01 << channel ) ) )
354            {
355               dma8237->hrq = 0;
356               dma8237->hlda = 0;
357               dma8237->intf->hrq_changed( device, dma8237->hrq );
358               dma8237->state = DMA8237_SI;
359            }
360            break;
361         }
198362
199INLINE void prepare_msb_flip(const device_config *device)
200{
201   dma8237_t   *dma8237 = get_safe_token(device);
363         /* Check if EOP output needs to be asserted */
364         if ( dma8237->status & ( 0x01 << channel ) )
365         {
366            dma8237->eop = 0;
367            if ( dma8237->intf->out_eop_func )
368               dma8237->intf->out_eop_func( device, channel, dma8237->eop ? ASSERT_LINE : CLEAR_LINE );
369         }
370      }
371      break;
202372
203   timer_adjust_oneshot(dma8237->msbflip_timer, attotime_zero, 0);
373   case DMA8237_S11:   /* Output A8-A15 */
374      break;
375   }
204376}
205377
206378
207379
380
381/* ----------------------------------------------------------------------- */
382
383
208384READ8_DEVICE_HANDLER( dma8237_r )
209385{
210386   dma8237_t   *dma8237 = get_safe_token(device);
211387   UINT8 data = 0xFF;
212   UINT8 mode;
213388
214389   offset &= 0x0F;
215390
r5012r5013
220395   case 6:
221396      /* DMA address register */
222397      data = dma8237->chan[offset / 2].address >> (dma8237->msb ? 8 : 0);
223      prepare_msb_flip(device);
224
225      /* hack simulating refresh activity for 'ibmxt' BIOS; I do not know
226         * why this is needed; but in any case, the ibmxt driver does not load
227         * if this code is not present */
228      mode = dma8237->chan[0].mode;
229      if ((DMA_MODE_OPERATION(mode) == 2) && (offset == 0))
230      {
231         dma8237->chan[0].address++;
232         dma8237->chan[0].count--;
233      }
398      dma8237->msb ^= 1;
234399      break;
235400
236401   case 1:
r5012r5013
239404   case 7:
240405      /* DMA count register */
241406      data = dma8237->chan[offset / 2].count >> (dma8237->msb ? 8 : 0);
242      prepare_msb_flip(device);
407      dma8237->msb ^= 1;
243408      break;
244409
245410   case 8:
246411      /* DMA status register */
247412      data = (UINT8) dma8237->status;
413
414      /* TC bits are cleared on a status read */
415      dma8237->status &= 0xF0;
248416      break;
249417
250418   case 10:
r5012r5013
265433      data = 0xFF;
266434      break;
267435   }
436
268437   return data;
269438}
270439
r5012r5013
277446
278447   offset &= 0x0F;
279448
449   logerror("dma8237_w: offset = %02x, data = %02x\n", offset, data );
450
280451   switch(offset) {
281452   case 0:
282453   case 2:
283454   case 4:
284455   case 6:
285456      /* DMA address register */
457      channel = offset / 2;
286458      if (dma8237->msb)
287         dma8237->chan[offset / 2].address |= ((UINT16) data) << 8;
459      {
460         dma8237->chan[channel].base_address = ( dma8237->chan[channel].base_address & 0x00FF ) | ( data << 8 );
461         dma8237->chan[channel].address = ( dma8237->chan[channel].address & 0x00FF ) | ( data << 8 );
462      }
288463      else
289         dma8237->chan[offset / 2].address = data;
290      prepare_msb_flip(device);
464      {
465         dma8237->chan[channel].base_address = ( dma8237->chan[channel].base_address & 0xFF00 ) | data;
466         dma8237->chan[channel].address = ( dma8237->chan[channel].address & 0xFF00 ) | data;
467      }
468      dma8237->msb ^= 1;
291469      break;
292470
293471   case 1:
r5012r5013
295473   case 5:
296474   case 7:
297475      /* DMA count register */
476      channel = offset / 2;
298477      if (dma8237->msb)
299         dma8237->chan[offset / 2].count |= ((UINT16) data) << 8;
478      {
479         dma8237->chan[channel].base_count = ( dma8237->chan[channel].base_count & 0x00FF ) | ( data << 8 );
480         dma8237->chan[channel].count = ( dma8237->chan[channel].count & 0x00FF ) | ( data << 8 );
481      }
300482      else
301         dma8237->chan[offset / 2].count = data;
302      prepare_msb_flip(device);
483      {
484         dma8237->chan[channel].base_count = ( dma8237->chan[channel].base_count & 0xFF00 ) | data;
485         dma8237->chan[channel].count = ( dma8237->chan[channel].count & 0xFF00 ) | data;
486      }
487      dma8237->msb ^= 1;
303488      break;
304489
305490   case 8:
306491      /* DMA command register */
307492      dma8237->command = data;
493      timer_enable( dma8237->timer, ( dma8237->command & 0x04 ) ? 0 : 1 );
308494      break;
309495
496   case 9:
497      /* DMA request register */
498      channel = DMA_MODE_CHANNEL(data);
499      if ( data & 0x04 )
500      {
501         dma8237->drq |= 0x01 << channel;
502         timer_enable( dma8237->timer, ( dma8237->command & 0x04 ) ? 0 : 1 );
503      }
504      else
505      {
506         dma8237->status &= ~ ( 0x10 << channel );
507         dma8237->drq &= ~ ( 0x01 << channel );
508      }
509      break;
510
310511   case 10:
311512      /* DMA mask register */
312513      channel = DMA_MODE_CHANNEL(data);
r5012r5013
320521      /* DMA mode register */
321522      channel = DMA_MODE_CHANNEL(data);
322523      dma8237->chan[channel].mode = data;
524      /* Apparently mode writes also clear the TC bit(?) */
525      dma8237->status &= ~ ( 1 << channel );
323526      break;
324527
325528   case 12:
r5012r5013
331534   case 13:
332535      /* DMA master clear */
333536      dma8237->msb = 0;
537      dma8237->mask = 0x0f;
538      dma8237->state = DMA8237_SI;
539      dma8237->status &= 0xF0;
334540      break;
335541
336542   case 14:
337543      /* DMA clear mask register */
338544      dma8237->mask &= ~data;
339      dma8237_update_status(device);
545      dma8237->mask = 0;
340546      break;
341547
342548   case 15:
r5012r5013
348554
349555
350556
351static void dma8237_drq_write_callback(const device_config *device, int param)
557void dma8237_drq_write(const device_config *device, int channel, int state)
352558{
353   dma8237_t   *dma8237 = get_safe_token(device);
354   int channel = (param >> 1) & 0x03;
355   int state = param & 0x01;
559   dma8237_t   *dma8237 = get_safe_token( device );
356560
357   /* normalize state */
358561   if (state)
359      dma8237->drq |= 0x01 << channel;
562      dma8237->drq |= ( 0x01 << channel );
360563   else
361      dma8237->drq &= ~(0x01 << channel);
564      dma8237->drq &= ~( 0x01 << channel );
362565
363   dma8237_update_status(device);
566   timer_enable( dma8237->timer, ( dma8237->command & 0x04 ) ? 0 : 1 );
364567}
365568
366569
570void dma8237_set_hlda(const device_config *device, int state)
571{
572   dma8237_t   *dma8237 = get_safe_token( device );
367573
368void dma8237_drq_write(const device_config *device, int channel, int state)
369{
370   int param = (channel << 1) | (state ? 1 : 0);
371   //timer_call_after_resynch(device->machine, NULL, param, dma8237_drq_write_callback);
372   dma8237_drq_write_callback(device, param);
574   dma8237->hlda = state;
373575}
374576
375577
376
377578/******************* Unfortunate hacks *******************/
378579
379580void dma8237_run_transfer(const device_config *device, int channel)
r5012r5013
382583
383584   dma8237->status |= 0x10 << channel;   /* reset DMA running flag */
384585
385   while(!dma8237_do_operation(device, channel))
386      ;
586   popmessage("dma8237_run_transfer(): please do not use me anymore\n");
387587
388588   dma8237->status &= ~(0x10 << channel);
389589   dma8237->status |=  (0x01 << channel);
r5012r5013
403603
404604   dma8237->status = 0x0F;
405605   dma8237->timer = timer_alloc(device->machine, dma8237_timerproc, (void *)device);
406   dma8237->msbflip_timer = timer_alloc(device->machine, dma8237_msbflip_timerproc, (void *)device);
407606   dma8237->eop = 1;
607   dma8237->state = DMA8237_SI;
608   dma8237->last_service_channel = 3;
408609
409610   dma8237->mask = 0x00;
410611   dma8237->status = 0x0F;
612   dma8237->hrq = 0;
613   dma8237->hlda = 0;
411614   dma8237->chan[0].mode = 0;
412615   dma8237->chan[1].mode = 0;
413616   dma8237->chan[2].mode = 0;
414617   dma8237->chan[3].mode = 0;
415618
416   dma8237_update_status(device);
619   timer_adjust_periodic(dma8237->timer,
620      ATTOTIME_IN_HZ(dma8237->intf->bus_speed),
621      0,
622      ATTOTIME_IN_HZ(dma8237->intf->bus_speed));
417623}
418624
419625
r5012r5013
432638      /* --- the following bits of info are returned as NULL-terminated strings --- */
433639      case DEVINFO_STR_NAME:                  strcpy(info->s, "Intel DMA8237");         break;
434640      case DEVINFO_STR_FAMILY:               strcpy(info->s, "DMA8237");               break;
435      case DEVINFO_STR_VERSION:               strcpy(info->s, "1.00");               break;
641      case DEVINFO_STR_VERSION:               strcpy(info->s, "1.01");               break;
436642      case DEVINFO_STR_SOURCE_FILE:            strcpy(info->s, __FILE__);               break;
437643      case DEVINFO_STR_CREDITS:               strcpy(info->s, "Copyright the MAME and MESS Teams");   break;
438644   }
src/emu/machine/8237dma.h
r5012r5013
99
1010#define DMA8237      DEVICE_GET_INFO_NAME(dma8237)
1111
12typedef void  (*dma8237_hrq_func)(const device_config *device, int state);
1213typedef UINT8 (*dma8237_mem_read_func)(const device_config *device, int channel, offs_t offset);
1314typedef void  (*dma8237_mem_write_func)(const device_config *device, int channel, offs_t offset, UINT8 data);
1415typedef int   (*dma8237_channel_read_func)(const device_config *device);
1516typedef void  (*dma8237_channel_write_func)(const device_config *device, int data);
16typedef void  (*dma8237_out_eop_func)(const device_config *device, int state);
17typedef void  (*dma8237_out_eop_func)(const device_config *device, int channel, int state);
1718
19#define DMA8237_HRQ_CHANGED(name)      void  name(const device_config *device, int state)
1820#define DMA8237_MEM_READ(name)         UINT8 name(const device_config *device, int channel, offs_t offset)
1921#define DMA8237_MEM_WRITE(name)         void  name(const device_config *device, int channel, offs_t offset, UINT8 data)
2022#define DMA8237_CHANNEL_READ(name)      int   name(const device_config *device)
2123#define DMA8237_CHANNEL_WRITE(name)      void  name(const device_config *device, int data)
22#define DMA8237_OUT_EOP(name)         void  name(const device_config *device, int state)
24#define DMA8237_OUT_EOP(name)         void  name(const device_config *device, int channel, int state)
2325
2426struct dma8237_interface
2527{
26   /* CPU to halt when DMA is active */
27   const char *cputag;
28
2928   /* speed of DMA accesses (per byte) */
3029   double bus_speed;
3130
31   /* function that will be called when HRQ may have changed */
32   dma8237_hrq_func         hrq_changed;
33
3234   /* accessors to main memory */
3335   dma8237_mem_read_func      memory_read_func;
3436   dma8237_mem_write_func      memory_write_func;
r5012r5013
5658READ8_DEVICE_HANDLER( dma8237_r );
5759WRITE8_DEVICE_HANDLER( dma8237_w );
5860void dma8237_drq_write(const device_config *device, int channel, int state);
61void dma8237_set_hlda(const device_config *device, int state);
5962
6063/* unfortunate hack for the interim for PC HDC */
6164void dma8237_run_transfer(const device_config *device, int channel);
src/mess/machine/at.c
r5012r5013
3737#define LOG_KBDC   0
3838
3939static struct {
40   const device_config *maincpu;
4041   const device_config   *pic8259_master;
4142   const device_config   *pic8259_slave;
4243   const device_config   *dma8237_1;
r5012r5013
245246}
246247
247248
249static DMA8237_HRQ_CHANGED( pc_dma_hrq_changed )
250{
251   cpu_set_input_line(at_devices.maincpu, INPUT_LINE_HALT, state ? ASSERT_LINE : CLEAR_LINE);
252
253   /* Assert HLDA */
254   dma8237_set_hlda( device, state );
255}
256
248257static DMA8237_MEM_READ( pc_dma_read_byte )
249258{
250259   UINT8 result;
r5012r5013
292301
293302const struct dma8237_interface at_dma8237_1_config =
294303{
295   0,
296   1.0e-6, // 1us
304   XTAL_14_31818MHz/3,
297305
306   pc_dma_hrq_changed,
298307   pc_dma_read_byte,
299308   pc_dma_write_byte,
300309
r5012r5013
307316/* TODO: How is this hooked up in the actual machine? */
308317const struct dma8237_interface at_dma8237_2_config =
309318{
310   0,
311   1.0e-6, // 1us
319   XTAL_14_31818MHz/3,
312320
321   pc_dma_hrq_changed,
313322   pc_dma_read_byte,
314323   pc_dma_write_byte,
315324
r5012r5013
613622      break;
614623
615624   case 4:      /* A2 is wired to 8042 A0 */
625printf("8042 command %02x\n", data );
616626      upi41_master_w( cputag_get_cpu(space->machine, "kbdc8042"), 1, data );
617627      break;
618628    }
r5012r5013
774784
775785MACHINE_RESET( at )
776786{
787   at_devices.maincpu = devtag_get_device(machine, "maincpu");
777788   at_devices.pic8259_master = devtag_get_device(machine, "pic8259_master");
778789   at_devices.pic8259_slave = devtag_get_device(machine, "pic8259_slave");
779790   at_devices.dma8237_1 = devtag_get_device(machine, "dma8237_1");
src/mess/machine/bebox.c
r5012r5013
722722}
723723
724724
725static DMA8237_HRQ_CHANGED( bebox_dma_hrq_changed )
726{
727   cputag_set_input_line(device->machine, "ppc1", INPUT_LINE_HALT, state ? ASSERT_LINE : CLEAR_LINE);
728
729   /* Assert HLDA */
730   dma8237_set_hlda( device, state );
731}
732
733
725734static DMA8237_MEM_READ( bebox_dma_read_byte )
726735{
727736   const address_space *space = cputag_get_address_space(device->machine, "ppc1", ADDRESS_SPACE_PROGRAM);
r5012r5013
757766
758767const struct dma8237_interface bebox_dma8237_1_config =
759768{
760   0,
761   1.0e-6, /* 1us */
769   XTAL_14_31818MHz/3, /* this needs to be verified */
762770
771   bebox_dma_hrq_changed,
763772   bebox_dma_read_byte,
764773   bebox_dma_write_byte,
765774
r5012r5013
771780
772781const struct dma8237_interface bebox_dma8237_2_config =
773782{
774   0,
775   1.0e-6, /* 1us */
783   XTAL_14_31818MHz/3, /* this needs to be verified */
776784
777785   NULL,
778786   NULL,
787   NULL,
779788
780789   { NULL, NULL, NULL, NULL },
781790   { NULL, NULL, NULL, NULL },
src/mess/machine/pc.c
r5012r5013
5959   } while (0)
6060
6161static struct {
62   const device_config *maincpu;
6263   const device_config   *pic8259_master;
6364   const device_config   *pic8259_slave;
6465   const device_config   *dma8237;
6566   const device_config   *pit8253;
67   /* U73 is an LS74 - dual flip flop */
68   /* Q2 is set by OUT1 from the 8253 and goes to DRQ1 on the 8237 */
69   UINT8   u73_q2;
70   UINT8   out1;
6671} pc_devices;
6772
6873/*************************************************************************
r5012r5013
97102}
98103
99104
105static DMA8237_HRQ_CHANGED( pc_dma_hrq_changed )
106{
107   cpu_set_input_line(pc_devices.maincpu, INPUT_LINE_HALT, state ? ASSERT_LINE : CLEAR_LINE);
108
109   /* Assert HLDA */
110   dma8237_set_hlda( device, state );
111}
112
113
100114static DMA8237_MEM_READ( pc_dma_read_byte )
101115{
102116   UINT8 result;
r5012r5013
141155}
142156
143157
158static DMA8237_CHANNEL_WRITE( pc_dma8237_0_dack_w )
159{
160   pc_devices.u73_q2 = 0;
161   dma8237_drq_write( pc_devices.dma8237, 0, pc_devices.u73_q2 );
162}
163
164
144165static DMA8237_OUT_EOP( pc_dma8237_out_eop )
145166{
146   pc_fdc_set_tc_state( device->machine, state );
167   pc_fdc_set_tc_state( device->machine, state == ASSERT_LINE ? 0 : 1 );
147168}
148169
149170
150171const struct dma8237_interface ibm5150_dma8237_config =
151172{
152   0,
153   1.0e-6, // 1us
173   XTAL_14_31818MHz/3,
154174
175   pc_dma_hrq_changed,
155176   pc_dma_read_byte,
156177   pc_dma_write_byte,
157178
158   { 0, 0, pc_dma8237_fdc_dack_r, pc_dma8237_hdc_dack_r },
159   { 0, 0, pc_dma8237_fdc_dack_w, pc_dma8237_hdc_dack_w },
179   { NULL, NULL, pc_dma8237_fdc_dack_r, pc_dma8237_hdc_dack_r },
180   { pc_dma8237_0_dack_w, NULL, pc_dma8237_fdc_dack_w, pc_dma8237_hdc_dack_w },
160181   pc_dma8237_out_eop
161182};
162183
r5012r5013
271292 *
272293 *************************************************************/
273294
274static PIT8253_OUTPUT_CHANGED( ibm5150_timer0_w )
295static PIT8253_OUTPUT_CHANGED( ibm5150_pit8253_out0_changed )
275296{
276297   pic8259_set_irq_line(pc_devices.pic8259_master, 0, state);
277298}
r5012r5013
279300
280301static PIT8253_OUTPUT_CHANGED( ibm5150_pit8253_out1_changed )
281302{
282   /* Trigger DMA channel #0 */
303    /* Trigger DMA channel #0 */
304   if ( pc_devices.out1 == 0 && state == 1 && pc_devices.u73_q2 == 0 )
305   {
306      pc_devices.u73_q2 = 1;
307      dma8237_drq_write( pc_devices.dma8237, 0, pc_devices.u73_q2 );
308   }
309   pc_devices.out1 = state;
283310}
284311
285312
r5012r5013
294321   {
295322      {
296323         XTAL_14_31818MHz/12,            /* heartbeat IRQ */
297         ibm5150_timer0_w
324         ibm5150_pit8253_out0_changed
298325      }, {
299326         XTAL_14_31818MHz/12,            /* dram refresh */
300327         ibm5150_pit8253_out1_changed
r5012r5013
317344   {
318345      {
319346         XTAL_14_31818MHz/12,              /* heartbeat IRQ */
320         ibm5150_timer0_w
347         ibm5150_pit8253_out0_changed
321348      }, {
322349         XTAL_14_31818MHz/12,              /* dram refresh */
323350         NULL
r5012r5013
13221349MACHINE_RESET( pc )
13231350{
13241351   const device_config *speaker = devtag_get_device(machine, "speaker");
1325   cpu_set_irq_callback(machine->cpu[0], pc_irq_callback);
13261352
1353   pc_devices.maincpu = devtag_get_device(machine, "maincpu" );
1354   cpu_set_irq_callback(pc_devices.maincpu, pc_irq_callback);
1355
13271356   pc_devices.pic8259_master = devtag_get_device(machine, "pic8259_master");
13281357   pc_devices.pic8259_slave = devtag_get_device(machine, "pic8259_slave");
13291358   pc_devices.dma8237 = devtag_get_device(machine, "dma8237");
13301359   pc_devices.pit8253 = devtag_get_device(machine, "pit8253");
1360   pc_devices.u73_q2 = 0;
1361   pc_devices.out1 = 0;
13311362   pc_mouse_set_serial_port( devtag_get_device(machine, "ins8250_0") );
13321363   pc_hdc_set_dma8237_device( pc_devices.dma8237 );
13331364   speaker_level_w( speaker, 0 );
src/mess/drivers/mikromik.c
r5012r5013
8686   return 0;
8787}
8888
89static DMA8237_HRQ_CHANGED( dma_hrq_changed )
90{
91   cputag_set_input_line( device->machine, I8085_TAG, INPUT_LINE_HALT, state ? ASSERT_LINE : CLEAR_LINE );
92
93   /* Assert HLDA */
94   dma8237_set_hlda( device, state );
95}
96
8997static DMA8237_MEM_READ( memory_dma_r )
9098{
9199   const address_space *program = cputag_get_address_space(device->machine, I8085_TAG, ADDRESS_SPACE_PROGRAM);
r5012r5013
136144
137145static const struct dma8237_interface mm1_dma8237_intf =
138146{
139   I8085_TAG,
140   1.0e-6, // 1us???
147   XTAL_14_31818MHz/3, /* this needs to be verified */
148   dma_hrq_changed,
141149   memory_dma_r,
142150   memory_dma_w,
143151   { NULL, NULL, NULL, NULL },

Previous 15994 Revisions Next


© 1998-2018 The MESS Team