Previous 15994 Revisions Next

r7760 Wednesday 7th April, 2010 at 17:50:39 UTC by Fabio Priuli
[SNES] proper fix to the DMA issue with S-DD1 games
[src/mame/machine]snes.c snessdd1.c

src/mame/machine/snessdd1.c
r7759r7760
620620            break;
621621      }
622622      snes_ram[addr] = data;
623      snes_io_dma_w(space, addr, data);
623624      return;
624625   }
625626
src/mame/machine/snes.c
r7759r7760
3434static void snes_hdma_init(const address_space *space);
3535static void snes_hdma(const address_space *space);
3636
37READ8_HANDLER(snes_io_dma_r);
38WRITE8_HANDLER(snes_io_dma_w);
39
3740struct snes_cart_info snes_cart;
3841
3942// add-on chip emulators
r7759r7760
301304   return result;
302305}
303306
307/* read & write to DMA addresses are defined separately, to be called by snessdd1 handlers */
308READ8_HANDLER( snes_io_dma_r )
309{
310   snes_state *state = (snes_state *)space->machine->driver_data;
311
312   switch (offset)
313   {
314      case DMAP0:   case DMAP1: case DMAP2: case DMAP3: /*0x43n0*/
315      case DMAP4: case DMAP5: case DMAP6: case DMAP7:
316         return state->dma_channel[(offset >> 4) & 0x07].dmap;
317      case BBAD0: case BBAD1: case BBAD2: case BBAD3: /*0x43n1*/
318      case BBAD4: case BBAD5: case BBAD6: case BBAD7:
319         return state->dma_channel[(offset >> 4) & 0x07].dest_addr;
320      case A1T0L: case A1T1L: case A1T2L: case A1T3L: /*0x43n2*/
321      case A1T4L: case A1T5L: case A1T6L: case A1T7L:
322         return state->dma_channel[(offset >> 4) & 0x07].src_addr & 0xff;
323      case A1T0H: case A1T1H: case A1T2H: case A1T3H: /*0x43n3*/
324      case A1T4H: case A1T5H: case A1T6H: case A1T7H:
325         return (state->dma_channel[(offset >> 4) & 0x07].src_addr >> 8) & 0xff;
326      case A1B0: case A1B1: case A1B2: case A1B3:     /*0x43n4*/
327      case A1B4: case A1B5: case A1B6: case A1B7:
328         return state->dma_channel[(offset >> 4) & 0x07].bank;
329      case DAS0L: case DAS1L: case DAS2L: case DAS3L: /*0x43n5*/
330      case DAS4L: case DAS5L: case DAS6L: case DAS7L:
331         return state->dma_channel[(offset >> 4) & 0x07].trans_size & 0xff;
332      case DAS0H: case DAS1H: case DAS2H: case DAS3H: /*0x43n6*/
333      case DAS4H: case DAS5H: case DAS6H: case DAS7H:
334         return (state->dma_channel[(offset >> 4) & 0x07].trans_size >> 8) & 0xff;
335      case DSAB0: case DSAB1: case DSAB2: case DSAB3: /*0x43n7*/
336      case DSAB4: case DSAB5: case DSAB6: case DSAB7:
337         return state->dma_channel[(offset >> 4) & 0x07].ibank;
338      case A2A0L: case A2A1L: case A2A2L: case A2A3L: /*0x43n8*/
339      case A2A4L: case A2A5L: case A2A6L: case A2A7L:
340         return state->dma_channel[(offset >> 4) & 0x07].hdma_addr & 0xff;
341      case A2A0H: case A2A1H: case A2A2H: case A2A3H: /*0x43n9*/
342      case A2A4H: case A2A5H: case A2A6H: case A2A7H:
343         return (state->dma_channel[(offset >> 4) & 0x07].hdma_addr >> 8) & 0xff;
344      case NTRL0: case NTRL1: case NTRL2: case NTRL3: /*0x43na*/
345      case NTRL4: case NTRL5: case NTRL6: case NTRL7:
346         return state->dma_channel[(offset >> 4) & 0x07].hdma_line_counter;
347      case 0x430b: case 0x431b: case 0x432b: case 0x433b: /* according to bsnes, this does not return open_bus (even if its precise effect is unknown) */
348      case 0x434b: case 0x435b: case 0x436b: case 0x437b:
349         return state->dma_channel[(offset >> 4) & 0x07].unk;
350   }
351
352   /* we should never arrive here */
353   return snes_open_bus_r(space, 0);
354}
355
356WRITE8_HANDLER( snes_io_dma_w )
357{
358   snes_state *state = (snes_state *)space->machine->driver_data;
359
360   switch (offset)
361   {
362         /* Below is all DMA related */
363      case DMAP0:   case DMAP1: case DMAP2: case DMAP3: /*0x43n0*/
364      case DMAP4: case DMAP5: case DMAP6: case DMAP7:
365         state->dma_channel[(offset >> 4) & 0x07].dmap = data;
366         break;
367      case BBAD0: case BBAD1: case BBAD2: case BBAD3: /*0x43n1*/
368      case BBAD4: case BBAD5: case BBAD6: case BBAD7:
369         state->dma_channel[(offset >> 4) & 0x07].dest_addr = data;
370         break;
371      case A1T0L: case A1T1L: case A1T2L: case A1T3L: /*0x43n2*/
372      case A1T4L: case A1T5L: case A1T6L: case A1T7L:
373         state->dma_channel[(offset >> 4) & 0x07].src_addr = (state->dma_channel[(offset >> 4) & 0x07].src_addr & 0xff00) | (data << 0);
374         break;
375      case A1T0H: case A1T1H: case A1T2H: case A1T3H: /*0x43n3*/
376      case A1T4H: case A1T5H: case A1T6H: case A1T7H:
377         state->dma_channel[(offset >> 4) & 0x07].src_addr = (state->dma_channel[(offset >> 4) & 0x07].src_addr & 0x00ff) | (data << 8);
378         break;
379      case A1B0: case A1B1: case A1B2: case A1B3:     /*0x43n4*/
380      case A1B4: case A1B5: case A1B6: case A1B7:
381         state->dma_channel[(offset >> 4) & 0x07].bank = data;
382         break;
383      case DAS0L: case DAS1L: case DAS2L: case DAS3L: /*0x43n5*/
384      case DAS4L: case DAS5L: case DAS6L: case DAS7L:
385         state->dma_channel[(offset >> 4) & 0x07].trans_size = (state->dma_channel[(offset >> 4) & 0x07].trans_size & 0xff00) | (data << 0);
386         break;
387      case DAS0H: case DAS1H: case DAS2H: case DAS3H: /*0x43n6*/
388      case DAS4H: case DAS5H: case DAS6H: case DAS7H:
389         state->dma_channel[(offset >> 4) & 0x07].trans_size = (state->dma_channel[(offset >> 4) & 0x07].trans_size & 0x00ff) | (data << 8);
390         break;
391      case DSAB0: case DSAB1: case DSAB2: case DSAB3: /*0x43n7*/
392      case DSAB4: case DSAB5: case DSAB6: case DSAB7:
393         state->dma_channel[(offset >> 4) & 0x07].ibank = data;
394         break;
395      case A2A0L: case A2A1L: case A2A2L: case A2A3L: /*0x43n8*/
396      case A2A4L: case A2A5L: case A2A6L: case A2A7L:
397         state->dma_channel[(offset >> 4) & 0x07].hdma_addr = (state->dma_channel[(offset >> 4) & 0x07].hdma_addr & 0xff00) | (data << 0);
398         break;
399      case A2A0H: case A2A1H: case A2A2H: case A2A3H: /*0x43n9*/
400      case A2A4H: case A2A5H: case A2A6H: case A2A7H:
401         state->dma_channel[(offset >> 4) & 0x07].hdma_addr = (state->dma_channel[(offset >> 4) & 0x07].hdma_addr & 0x00ff) | (data << 8);
402         break;
403      case NTRL0: case NTRL1: case NTRL2: case NTRL3: /*0x43na*/
404      case NTRL4: case NTRL5: case NTRL6: case NTRL7:
405         state->dma_channel[(offset >> 4) & 0x07].hdma_line_counter = data;
406         break;
407      case 0x430b: case 0x431b: case 0x432b: case 0x433b:
408      case 0x434b: case 0x435b: case 0x436b: case 0x437b:
409         state->dma_channel[(offset >> 4) & 0x07].unk = data;
410         break;
411   }
412
413   snes_ram[offset] = data;
414}
415
304416/*
305417 * DR   - Double read : address is read twice to return a 16bit value.
306418 * low  - This is the low byte of a 16 or 24 bit value
r7759r7760
358470      }
359471   }
360472
473   if (offset >= DMAP0 && offset < 0x4380)
474   {
475      return snes_io_dma_r(space, offset);
476   }
477
361478   /* offset is from 0x000000 */
362479   switch (offset)
363480   {
r7759r7760
416533         return state->joy4l;
417534      case JOY4H:         /* Joypad 4 status register (high) */
418535         return state->joy4h;
419      case DMAP0:   case DMAP1: case DMAP2: case DMAP3: /*0x43n0*/
420      case DMAP4: case DMAP5: case DMAP6: case DMAP7:
421         return state->dma_channel[(offset >> 4) & 0x07].dmap;
422      case BBAD0: case BBAD1: case BBAD2: case BBAD3: /*0x43n1*/
423      case BBAD4: case BBAD5: case BBAD6: case BBAD7:
424         return state->dma_channel[(offset >> 4) & 0x07].dest_addr;
425      case A1T0L: case A1T1L: case A1T2L: case A1T3L: /*0x43n2*/
426      case A1T4L: case A1T5L: case A1T6L: case A1T7L:
427         return state->dma_channel[(offset >> 4) & 0x07].src_addr & 0xff;
428      case A1T0H: case A1T1H: case A1T2H: case A1T3H: /*0x43n3*/
429      case A1T4H: case A1T5H: case A1T6H: case A1T7H:
430         return (state->dma_channel[(offset >> 4) & 0x07].src_addr >> 8) & 0xff;
431      case A1B0: case A1B1: case A1B2: case A1B3:     /*0x43n4*/
432      case A1B4: case A1B5: case A1B6: case A1B7:
433         return state->dma_channel[(offset >> 4) & 0x07].bank;
434      case DAS0L: case DAS1L: case DAS2L: case DAS3L: /*0x43n5*/
435      case DAS4L: case DAS5L: case DAS6L: case DAS7L:
436         return state->dma_channel[(offset >> 4) & 0x07].trans_size & 0xff;
437      case DAS0H: case DAS1H: case DAS2H: case DAS3H: /*0x43n6*/
438      case DAS4H: case DAS5H: case DAS6H: case DAS7H:
439         return (state->dma_channel[(offset >> 4) & 0x07].trans_size >> 8) & 0xff;
440      case DSAB0: case DSAB1: case DSAB2: case DSAB3: /*0x43n7*/
441      case DSAB4: case DSAB5: case DSAB6: case DSAB7:
442         return state->dma_channel[(offset >> 4) & 0x07].ibank;
443      case A2A0L: case A2A1L: case A2A2L: case A2A3L: /*0x43n8*/
444      case A2A4L: case A2A5L: case A2A6L: case A2A7L:
445         return state->dma_channel[(offset >> 4) & 0x07].hdma_addr & 0xff;
446      case A2A0H: case A2A1H: case A2A2H: case A2A3H: /*0x43n9*/
447      case A2A4H: case A2A5H: case A2A6H: case A2A7H:
448         return (state->dma_channel[(offset >> 4) & 0x07].hdma_addr >> 8) & 0xff;
449      case NTRL0: case NTRL1: case NTRL2: case NTRL3: /*0x43na*/
450      case NTRL4: case NTRL5: case NTRL6: case NTRL7:
451         return state->dma_channel[(offset >> 4) & 0x07].hdma_line_counter;
452      case 0x430b: case 0x431b: case 0x432b: case 0x433b: /* according to bsnes, this does not return open_bus (even if its precise effect is unknown) */
453      case 0x434b: case 0x435b: case 0x436b: case 0x437b:
454         return state->dma_channel[(offset >> 4) & 0x07].unk;
455536
456537#ifndef MESS
457538      case 0x4100:      /* NSS Dip-Switches */
r7759r7760
537618      }
538619   }
539620
621   if (offset >= DMAP0 && offset < 0x4380)
622   {
623      snes_io_dma_w(space, offset, data);
624      return;
625   }
626
540627   /* offset is from 0x000000 */
541628   switch (offset)
542629   {
r7759r7760
674761         logerror( "Write to read-only register: %X value: %X", offset, data );
675762#endif /* MAME_DEBUG */
676763         return;
677      /* Below is all DMA related */
678      case DMAP0:   case DMAP1: case DMAP2: case DMAP3: /*0x43n0*/
679      case DMAP4: case DMAP5: case DMAP6: case DMAP7:
680         state->dma_channel[(offset >> 4) & 0x07].dmap = data;
681         break;
682      case BBAD0: case BBAD1: case BBAD2: case BBAD3: /*0x43n1*/
683      case BBAD4: case BBAD5: case BBAD6: case BBAD7:
684         state->dma_channel[(offset >> 4) & 0x07].dest_addr = data;
685         break;
686      case A1T0L: case A1T1L: case A1T2L: case A1T3L: /*0x43n2*/
687      case A1T4L: case A1T5L: case A1T6L: case A1T7L:
688         state->dma_channel[(offset >> 4) & 0x07].src_addr = (state->dma_channel[(offset >> 4) & 0x07].src_addr & 0xff00) | (data << 0);
689         break;
690      case A1T0H: case A1T1H: case A1T2H: case A1T3H: /*0x43n3*/
691      case A1T4H: case A1T5H: case A1T6H: case A1T7H:
692         state->dma_channel[(offset >> 4) & 0x07].src_addr = (state->dma_channel[(offset >> 4) & 0x07].src_addr & 0x00ff) | (data << 8);
693         break;
694      case A1B0: case A1B1: case A1B2: case A1B3:     /*0x43n4*/
695      case A1B4: case A1B5: case A1B6: case A1B7:
696         state->dma_channel[(offset >> 4) & 0x07].bank = data;
697         break;
698      case DAS0L: case DAS1L: case DAS2L: case DAS3L: /*0x43n5*/
699      case DAS4L: case DAS5L: case DAS6L: case DAS7L:
700         state->dma_channel[(offset >> 4) & 0x07].trans_size = (state->dma_channel[(offset >> 4) & 0x07].trans_size & 0xff00) | (data << 0);
701         break;
702      case DAS0H: case DAS1H: case DAS2H: case DAS3H: /*0x43n6*/
703      case DAS4H: case DAS5H: case DAS6H: case DAS7H:
704         state->dma_channel[(offset >> 4) & 0x07].trans_size = (state->dma_channel[(offset >> 4) & 0x07].trans_size & 0x00ff) | (data << 8);
705         break;
706      case DSAB0: case DSAB1: case DSAB2: case DSAB3: /*0x43n7*/
707      case DSAB4: case DSAB5: case DSAB6: case DSAB7:
708         state->dma_channel[(offset >> 4) & 0x07].ibank = data;
709         break;
710      case A2A0L: case A2A1L: case A2A2L: case A2A3L: /*0x43n8*/
711      case A2A4L: case A2A5L: case A2A6L: case A2A7L:
712         state->dma_channel[(offset >> 4) & 0x07].hdma_addr = (state->dma_channel[(offset >> 4) & 0x07].hdma_addr & 0xff00) | (data << 0);
713         break;
714      case A2A0H: case A2A1H: case A2A2H: case A2A3H: /*0x43n9*/
715      case A2A4H: case A2A5H: case A2A6H: case A2A7H:
716         state->dma_channel[(offset >> 4) & 0x07].hdma_addr = (state->dma_channel[(offset >> 4) & 0x07].hdma_addr & 0x00ff) | (data << 8);
717         break;
718      case NTRL0: case NTRL1: case NTRL2: case NTRL3: /*0x43na*/
719      case NTRL4: case NTRL5: case NTRL6: case NTRL7:
720         state->dma_channel[(offset >> 4) & 0x07].hdma_line_counter = data;
721         break;
722      case 0x430b: case 0x431b: case 0x432b: case 0x433b:
723      case 0x434b: case 0x435b: case 0x436b: case 0x437b:
724         state->dma_channel[(offset >> 4) & 0x07].unk = data;
725         break;
726764   }
727765
728766   snes_ram[offset] = data;
r7759r7760
20672105   UINT32 abus, abus_bank;
20682106   UINT16 length;
20692107
2070    /* FIXME: we also need to round to the nearest 8 master cycles */
2108   /* FIXME: we also need to round to the nearest 8 master cycles */
20712109
20722110   /* overhead steals 8 master cycles, correct? */
20732111   cpu_adjust_icount(space->cpu,-8);
r7759r7760
20832121
20842122         //printf( "Making a transfer on channel %d\n", i );
20852123         /* Find transfer addresses */
2086         abus = (snes_ram[SNES_DMA_BASE + (i * 0x10) + 3] << 8) + snes_ram[SNES_DMA_BASE + (i * 0x10) + 2];
2087         abus_bank = (snes_ram[SNES_DMA_BASE + (i * 0x10) + 4] << 16);
2088         bbus = 0x2100 + snes_ram[SNES_DMA_BASE + (i * 0x10) + 1];
2124         abus = state->dma_channel[i].src_addr;
2125         abus_bank = state->dma_channel[i].bank << 16;
2126         bbus = state->dma_channel[i].dest_addr + 0x2100;
20892127
2090         //printf( "Address: %06x\n", abus | abus_bank );
2128         //printf("Address: %06x\n", abus | abus_bank);
20912129         /* Auto increment */
2092         if (snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x8)
2093         {
2130         if (state->dma_channel[i].dmap & 0x8)
20942131            increment = 0;
2095         }
20962132         else
20972133         {
2098            if (snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x10)
2134            if (state->dma_channel[i].dmap & 0x10)
20992135               increment = -1;
21002136            else
21012137               increment = 1;
21022138         }
21032139
21042140         /* Number of bytes to transfer */
2105         length = (snes_ram[SNES_DMA_BASE + (i * 0x10) + 6] << 8) + snes_ram[SNES_DMA_BASE + (i * 0x10) + 5];
2141         length = state->dma_channel[i].trans_size;
21062142
2107         //          printf( "DMA-Ch %d: len: %X, abus: %X, bbus: %X, incr: %d, dir: %s, type: %d\n", i, length, abus, bbus, increment, snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x80 ? "PPU->CPU" : "CPU->PPU", snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x07);
2143         //        printf( "DMA-Ch %d: len: %X, abus: %X, bbus: %X, incr: %d, dir: %s, type: %d\n", i, length, abus | abus_bank, bbus, increment, state->dma_channel[i].dmap & 0x80 ? "PPU->CPU" : "CPU->PPU", state->dma_channel[i].dmap & 0x07);
21082144
21092145#ifdef SNES_DBG_DMA
2110         mame_printf_debug( "DMA-Ch %d: len: %X, abus: %X, bbus: %X, incr: %d, dir: %s, type: %d\n", i, length, abus, bbus, increment, snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x80 ? "PPU->CPU" : "CPU->PPU", snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x07);
2146         mame_printf_debug( "DMA-Ch %d: len: %X, abus: %X, bbus: %X, incr: %d, dir: %s, type: %d\n", i, length, abus | abus_bank, bbus, increment, state->dma_channel[i].dmap & 0x80 ? "PPU->CPU" : "CPU->PPU", state->dma_channel[i].dmap & 0x07);
21112147#endif
21122148
2113         switch (snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x07)
2149         switch (state->dma_channel[i].dmap & 0x07)
21142150         {
21152151            case 0:      /* 1 register write once */
21162152            case 2:      /* 1 register write twice */
r7759r7760
21792215               break;
21802216         }
21812217
2182         /* We're done so write the new abus back to the registers */
2183         snes_w_io(space, SNES_DMA_BASE + (i * 0x10) + 2, abus & 0xff);
2184         snes_w_io(space, SNES_DMA_BASE + (i * 0x10) + 3, (abus >> 8) & 0xff);
2185         snes_w_io(space, SNES_DMA_BASE + (i * 0x10) + 5, 0);
2186         snes_w_io(space, SNES_DMA_BASE + (i * 0x10) + 6, 0);
2218         /* We're done, so write the new abus back to the registers */
2219         state->dma_channel[i].src_addr = abus;
2220         state->dma_channel[i].trans_size = 0;
21872221
2188            /* active channel takes 8 master cycles */
2222         /* active channel takes 8 master cycles */
21892223         cpu_adjust_icount(space->cpu,-8);
21902224      }
21912225   }

Previous 15994 Revisions Next


© 1998-2018 The MESS Team