Previous 15994 Revisions Next

r7754 Wednesday 7th April, 2010 at 15:34:14 UTC by Fabio Priuli
[SNES] temporarily reverted some dma code to allow S-DD1 games to boot
[src/mame/machine]snes.c

src/mame/machine/snes.c
r7753r7754
203203   timer_adjust_oneshot(state->scanline_timer, attotime_never, 0);
204204   timer_adjust_oneshot(state->hblank_timer, video_screen_get_time_until_pos(machine->primary_screen, snes_ppu.beam.current_vert, state->hblank_offset * state->htmult), 0);
205205
206//   printf("%02x %d\n",snes_ram[HVBJOY],snes_ppu.beam.current_vert);
206//  printf("%02x %d\n",snes_ram[HVBJOY],snes_ppu.beam.current_vert);
207207}
208208
209209/* This is called at the start of hblank *before* the scanline indicated in current_vert! */
r7753r7754
418418         return state->joy4h;
419419      case DMAP0:   case DMAP1: case DMAP2: case DMAP3: /*0x43n0*/
420420      case DMAP4: case DMAP5: case DMAP6: case DMAP7:
421         return state->dma_channel[(offset & 0x70) >> 4].dmap;
421         return state->dma_channel[(offset >> 4) & 0x07].dmap;
422422      case BBAD0: case BBAD1: case BBAD2: case BBAD3: /*0x43n1*/
423423      case BBAD4: case BBAD5: case BBAD6: case BBAD7:
424         return state->dma_channel[(offset & 0x70) >> 4].dest_addr;
424         return state->dma_channel[(offset >> 4) & 0x07].dest_addr;
425425      case A1T0L: case A1T1L: case A1T2L: case A1T3L: /*0x43n2*/
426426      case A1T4L: case A1T5L: case A1T6L: case A1T7L:
427         return state->dma_channel[(offset & 0x70) >> 4].src_addr & 0xff;
427         return state->dma_channel[(offset >> 4) & 0x07].src_addr & 0xff;
428428      case A1T0H: case A1T1H: case A1T2H: case A1T3H: /*0x43n3*/
429429      case A1T4H: case A1T5H: case A1T6H: case A1T7H:
430         return (state->dma_channel[(offset & 0x70) >> 4].src_addr >> 8) & 0xff;
430         return (state->dma_channel[(offset >> 4) & 0x07].src_addr >> 8) & 0xff;
431431      case A1B0: case A1B1: case A1B2: case A1B3:     /*0x43n4*/
432432      case A1B4: case A1B5: case A1B6: case A1B7:
433         return state->dma_channel[(offset & 0x70) >> 4].bank;
433         return state->dma_channel[(offset >> 4) & 0x07].bank;
434434      case DAS0L: case DAS1L: case DAS2L: case DAS3L: /*0x43n5*/
435435      case DAS4L: case DAS5L: case DAS6L: case DAS7L:
436         return state->dma_channel[(offset & 0x70) >> 4].trans_size & 0xff;
436         return state->dma_channel[(offset >> 4) & 0x07].trans_size & 0xff;
437437      case DAS0H: case DAS1H: case DAS2H: case DAS3H: /*0x43n6*/
438438      case DAS4H: case DAS5H: case DAS6H: case DAS7H:
439         return (state->dma_channel[(offset & 0x70) >> 4].trans_size >> 8) & 0xff;
439         return (state->dma_channel[(offset >> 4) & 0x07].trans_size >> 8) & 0xff;
440440      case DSAB0: case DSAB1: case DSAB2: case DSAB3: /*0x43n7*/
441441      case DSAB4: case DSAB5: case DSAB6: case DSAB7:
442         return state->dma_channel[(offset & 0x70) >> 4].ibank;
442         return state->dma_channel[(offset >> 4) & 0x07].ibank;
443443      case A2A0L: case A2A1L: case A2A2L: case A2A3L: /*0x43n8*/
444444      case A2A4L: case A2A5L: case A2A6L: case A2A7L:
445         return state->dma_channel[(offset & 0x70) >> 4].hdma_addr & 0xff;
445         return state->dma_channel[(offset >> 4) & 0x07].hdma_addr & 0xff;
446446      case A2A0H: case A2A1H: case A2A2H: case A2A3H: /*0x43n9*/
447447      case A2A4H: case A2A5H: case A2A6H: case A2A7H:
448         return (state->dma_channel[(offset & 0x70) >> 4].hdma_addr >> 8) & 0xff;
448         return (state->dma_channel[(offset >> 4) & 0x07].hdma_addr >> 8) & 0xff;
449449      case NTRL0: case NTRL1: case NTRL2: case NTRL3: /*0x43na*/
450450      case NTRL4: case NTRL5: case NTRL6: case NTRL7:
451         return state->dma_channel[(offset & 0x70) >> 4].hdma_line_counter;
451         return state->dma_channel[(offset >> 4) & 0x07].hdma_line_counter;
452452      case 0x430b: case 0x431b: case 0x432b: case 0x433b: /* according to bsnes, this does not return open_bus (even if its precise effect is unknown) */
453453      case 0x434b: case 0x435b: case 0x436b: case 0x437b:
454         return state->dma_channel[(offset & 0x70) >> 4].unk;
454         return state->dma_channel[(offset >> 4) & 0x07].unk;
455455
456456#ifndef MESS
457457      case 0x4100:      /* NSS Dip-Switches */
r7753r7754
677677      /* Below is all DMA related */
678678      case DMAP0:   case DMAP1: case DMAP2: case DMAP3: /*0x43n0*/
679679      case DMAP4: case DMAP5: case DMAP6: case DMAP7:
680         state->dma_channel[(offset & 0x70) >> 4].dmap = data;
680         state->dma_channel[(offset >> 4) & 0x07].dmap = data;
681681         break;
682682      case BBAD0: case BBAD1: case BBAD2: case BBAD3: /*0x43n1*/
683683      case BBAD4: case BBAD5: case BBAD6: case BBAD7:
684         state->dma_channel[(offset & 0x70) >> 4].dest_addr = data;
684         state->dma_channel[(offset >> 4) & 0x07].dest_addr = data;
685685         break;
686686      case A1T0L: case A1T1L: case A1T2L: case A1T3L: /*0x43n2*/
687687      case A1T4L: case A1T5L: case A1T6L: case A1T7L:
688         state->dma_channel[(offset & 0x70) >> 4].src_addr = (state->dma_channel[(offset & 0x70) >> 4].src_addr & 0xff00) | (data << 0);
688         state->dma_channel[(offset >> 4) & 0x07].src_addr = (state->dma_channel[(offset >> 4) & 0x07].src_addr & 0xff00) | (data << 0);
689689         break;
690690      case A1T0H: case A1T1H: case A1T2H: case A1T3H: /*0x43n3*/
691691      case A1T4H: case A1T5H: case A1T6H: case A1T7H:
692         state->dma_channel[(offset & 0x70) >> 4].src_addr = (state->dma_channel[(offset & 0x70) >> 4].src_addr & 0x00ff) | (data << 8);
692         state->dma_channel[(offset >> 4) & 0x07].src_addr = (state->dma_channel[(offset >> 4) & 0x07].src_addr & 0x00ff) | (data << 8);
693693         break;
694694      case A1B0: case A1B1: case A1B2: case A1B3:     /*0x43n4*/
695695      case A1B4: case A1B5: case A1B6: case A1B7:
696         state->dma_channel[(offset & 0x70) >> 4].bank = data;
696         state->dma_channel[(offset >> 4) & 0x07].bank = data;
697697         break;
698698      case DAS0L: case DAS1L: case DAS2L: case DAS3L: /*0x43n5*/
699699      case DAS4L: case DAS5L: case DAS6L: case DAS7L:
700         state->dma_channel[(offset & 0x70) >> 4].trans_size = (state->dma_channel[(offset & 0x70) >> 4].trans_size & 0xff00) | (data << 0);
700         state->dma_channel[(offset >> 4) & 0x07].trans_size = (state->dma_channel[(offset >> 4) & 0x07].trans_size & 0xff00) | (data << 0);
701701         break;
702702      case DAS0H: case DAS1H: case DAS2H: case DAS3H: /*0x43n6*/
703703      case DAS4H: case DAS5H: case DAS6H: case DAS7H:
704         state->dma_channel[(offset & 0x70) >> 4].trans_size = (state->dma_channel[(offset & 0x70) >> 4].trans_size & 0x00ff) | (data << 8);
704         state->dma_channel[(offset >> 4) & 0x07].trans_size = (state->dma_channel[(offset >> 4) & 0x07].trans_size & 0x00ff) | (data << 8);
705705         break;
706706      case DSAB0: case DSAB1: case DSAB2: case DSAB3: /*0x43n7*/
707707      case DSAB4: case DSAB5: case DSAB6: case DSAB7:
708         state->dma_channel[(offset & 0x70) >> 4].ibank = data;
708         state->dma_channel[(offset >> 4) & 0x07].ibank = data;
709709         break;
710710      case A2A0L: case A2A1L: case A2A2L: case A2A3L: /*0x43n8*/
711711      case A2A4L: case A2A5L: case A2A6L: case A2A7L:
712         state->dma_channel[(offset & 0x70) >> 4].hdma_addr = (state->dma_channel[(offset & 0x70) >> 4].hdma_addr & 0xff00) | (data << 0);
712         state->dma_channel[(offset >> 4) & 0x07].hdma_addr = (state->dma_channel[(offset >> 4) & 0x07].hdma_addr & 0xff00) | (data << 0);
713713         break;
714714      case A2A0H: case A2A1H: case A2A2H: case A2A3H: /*0x43n9*/
715715      case A2A4H: case A2A5H: case A2A6H: case A2A7H:
716         state->dma_channel[(offset & 0x70) >> 4].hdma_addr = (state->dma_channel[(offset & 0x70) >> 4].hdma_addr & 0x00ff) | (data << 8);
716         state->dma_channel[(offset >> 4) & 0x07].hdma_addr = (state->dma_channel[(offset >> 4) & 0x07].hdma_addr & 0x00ff) | (data << 8);
717717         break;
718718      case NTRL0: case NTRL1: case NTRL2: case NTRL3: /*0x43na*/
719719      case NTRL4: case NTRL5: case NTRL6: case NTRL7:
720         state->dma_channel[(offset & 0x70) >> 4].hdma_line_counter = data;
720         state->dma_channel[(offset >> 4) & 0x07].hdma_line_counter = data;
721721         break;
722722      case 0x430b: case 0x431b: case 0x432b: case 0x433b:
723723      case 0x434b: case 0x435b: case 0x436b: case 0x437b:
724         state->dma_channel[(offset & 0x70) >> 4].unk = data;
724         state->dma_channel[(offset >> 4) & 0x07].unk = data;
725725         break;
726726   }
727727
r7753r7754
19331933   if (state->dma_channel[dma].dmap & 0x40)
19341934   {
19351935      /* One oddity: if $43xA is 0 and this is the last active HDMA channel for this scanline, only load
1936      one byte for Address, and use the $00 for the low byte. So Address ends up incremented one less than
1937      otherwise expected */
1936        one byte for Address, and use the $00 for the low byte. So Address ends up incremented one less than
1937        otherwise expected */
19381938
19391939      abus = snes_get_hdma_addr(space->machine, dma);
19401940      state->dma_channel[dma].trans_size = snes_abus_read(space, abus) << 8;
r7753r7754
20582058   int i;
20592059   INT8 increment;
20602060   UINT16 bbus;
2061   UINT32 abus, abus_bank, length;
2061   UINT32 abus, abus_bank;
2062   UINT16 length;
20622063
2063   /* FIXME: we also need to round to the nearest 8 master cycles */
2064    /* FIXME: we also need to round to the nearest 8 master cycles */
20642065
20652066   /* overhead steals 8 master cycles, correct? */
20662067   cpu_adjust_icount(space->cpu,-8);
r7753r7754
20712072      if (BIT(channels, i))
20722073      {
20732074         /* FIXME: the following should be used to stop DMA if the same channel is used by HDMA (being set to 1 in snes_hdma)
2074            However, this cannot be implemented as is atm, because currently DMA transfers always happen as soon as they are enabled... */
2075            However, this cannot be implemented as is atm, because currently DMA transfers always happen as soon as they are enabled... */
20752076         state->dma_channel[i].dma_disabled = 0;
20762077
20772078         //printf( "Making a transfer on channel %d\n", i );
20782079         /* Find transfer addresses */
2079         abus = state->dma_channel[i].src_addr;
2080         abus_bank = state->dma_channel[i].bank << 16;
2081         bbus = state->dma_channel[i].dest_addr + 0x2100;
2080         abus = (snes_ram[SNES_DMA_BASE + (i * 0x10) + 3] << 8) + snes_ram[SNES_DMA_BASE + (i * 0x10) + 2];
2081         abus_bank = (snes_ram[SNES_DMA_BASE + (i * 0x10) + 4] << 16);
2082         bbus = 0x2100 + snes_ram[SNES_DMA_BASE + (i * 0x10) + 1];
20822083
2083         //printf("Address: %06x\n", abus | abus_bank);
2084         //printf( "Address: %06x\n", abus | abus_bank );
20842085         /* Auto increment */
2085         if (state->dma_channel[i].dmap & 0x8)
2086         if (snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x8)
2087         {
20862088            increment = 0;
2089         }
20872090         else
20882091         {
2089            if (state->dma_channel[i].dmap & 0x10)
2092            if (snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x10)
20902093               increment = -1;
20912094            else
20922095               increment = 1;
20932096         }
20942097
20952098         /* Number of bytes to transfer */
2096         length = state->dma_channel[i].trans_size;
2097         if (!length)
2098            length = 0x10000;   /* 0x0000 really means 0x10000 */
2099         length = (snes_ram[SNES_DMA_BASE + (i * 0x10) + 6] << 8) + snes_ram[SNES_DMA_BASE + (i * 0x10) + 5];
20992100
2100//          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);
2101         //          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);
21012102
21022103#ifdef SNES_DBG_DMA
2103         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);
2104         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);
21042105#endif
21052106
2106         switch (state->dma_channel[i].dmap & 0x07)
2107         switch (snes_ram[SNES_DMA_BASE + (i * 0x10)] & 0x07)
21072108         {
2108         case 0:      /* 1 register write once */
2109         case 2:      /* 1 register write twice */
2110         case 6:      /* 1 register write twice */
2111            while (length-- && !state->dma_channel[i].dma_disabled)
2112            {
2113               snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus);
2114               abus += increment;
2115            }
2116            break;
2117         case 1:      /* 2 registers write once */
2118         case 5:      /* 2 registers write twice alternate */
2119            while (length-- && !state->dma_channel[i].dma_disabled)
2120            {
2121               snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus);
2122               abus += increment;
2123               if (!(length--) || state->dma_channel[i].dma_disabled)
2124                  break;
2125               snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus + 1);
2126               abus += increment;
2127            }
2128            break;
2129         case 3:      /* 2 registers write twice each */
2130         case 7:      /* 2 registers write twice each */
2131            while (length-- && !state->dma_channel[i].dma_disabled)
2132            {
2133               snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus);
2134               abus += increment;
2135               if (!(length--) || state->dma_channel[i].dma_disabled)
2136                  break;
2137               snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus);
2138               abus += increment;
2139               if (!(length--) || state->dma_channel[i].dma_disabled)
2140                  break;
2141               snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus + 1);
2142               abus += increment;
2143               if (!(length--) || state->dma_channel[i].dma_disabled)
2144                  break;
2145               snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus + 1);
2146               abus += increment;
2147            }
2148            break;
2149         case 4:      /* 4 registers write once */
2150            while (length-- && !state->dma_channel[i].dma_disabled)
2151            {
2152               snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus);
2153               abus += increment;
2154               if (!(length--) || state->dma_channel[i].dma_disabled)
2155                  break;
2156               snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus + 1);
2157               abus += increment;
2158               if (!(length--) || state->dma_channel[i].dma_disabled)
2159                  break;
2160               snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus + 2);
2161               abus += increment;
2162               if (!(length--) || state->dma_channel[i].dma_disabled)
2163                  break;
2164               snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus + 3);
2165               abus += increment;
2166            }
2167            break;
2168         default:
2109            case 0:      /* 1 register write once */
2110            case 2:      /* 1 register write twice */
2111            case 6:      /* 1 register write twice */
2112               do
2113               {
2114                  snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus);
2115                  abus += increment;
2116               } while (--length && !state->dma_channel[i].dma_disabled);
2117               break;
2118            case 1:      /* 2 registers write once */
2119            case 5:      /* 2 registers write twice alternate */
2120               do
2121               {
2122                  snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus);
2123                  abus += increment;
2124                  if (!(--length) || state->dma_channel[i].dma_disabled)
2125                     break;
2126                  snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus + 1);
2127                  abus += increment;
2128               } while (--length && !state->dma_channel[i].dma_disabled);
2129               break;
2130            case 3:      /* 2 registers write twice each */
2131            case 7:      /* 2 registers write twice each */
2132               do
2133               {
2134                  snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus);
2135                  abus += increment;
2136                  if (!(--length) || state->dma_channel[i].dma_disabled)
2137                     break;
2138                  snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus);
2139                  abus += increment;
2140                  if (!(--length) || state->dma_channel[i].dma_disabled)
2141                     break;
2142                  snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus + 1);
2143                  abus += increment;
2144                  if (!(--length) || state->dma_channel[i].dma_disabled)
2145                     break;
2146                  snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus + 1);
2147                  abus += increment;
2148               } while (--length && !state->dma_channel[i].dma_disabled);
2149               break;
2150            case 4:      /* 4 registers write once */
2151               do
2152               {
2153                  snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus);
2154                  abus += increment;
2155                  if (!(--length) || state->dma_channel[i].dma_disabled)
2156                     break;
2157                  snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus + 1);
2158                  abus += increment;
2159                  if (!(--length) || state->dma_channel[i].dma_disabled)
2160                     break;
2161                  snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus + 2);
2162                  abus += increment;
2163                  if (!(--length) || state->dma_channel[i].dma_disabled)
2164                     break;
2165                  snes_dma_transfer(space, i, (abus & 0xffff) | abus_bank, bbus + 3);
2166                  abus += increment;
2167               } while (--length && !state->dma_channel[i].dma_disabled);
2168               break;
2169            default:
21692170#ifdef MAME_DEBUG
2170            mame_printf_debug("  DMA of unsupported type: %d\n", state->dma_channel[i].dmap & 0x07);
2171               mame_printf_debug("  DMA of unsupported type: %d\n", state->dma_channel[i].dmap & 0x07);
21712172#endif
2172            break;
2173               break;
21732174         }
21742175
2175         /* We're done, so write the new abus back to the registers */
2176         state->dma_channel[i].src_addr = abus;
2177         state->dma_channel[i].trans_size = 0;
2178         /* active channel takes 8 master cycles */
2176         /* We're done so write the new abus back to the registers */
2177         snes_w_io(space, SNES_DMA_BASE + (i * 0x10) + 2, abus & 0xff);
2178         snes_w_io(space, SNES_DMA_BASE + (i * 0x10) + 3, (abus >> 8) & 0xff);
2179         snes_w_io(space, SNES_DMA_BASE + (i * 0x10) + 5, 0);
2180         snes_w_io(space, SNES_DMA_BASE + (i * 0x10) + 6, 0);
2181
2182            /* active channel takes 8 master cycles */
21792183         cpu_adjust_icount(space->cpu,-8);
21802184      }
21812185   }
r7753r7754
21972201READ8_HANDLER( superfx_r_bank3 )
21982202{
21992203   /* IMPORTANT: SFX RAM sits in 0x600000-0x7fffff, and it's mirrored in 0xe00000-0xffffff. However, SNES
2200   has only access to 0x600000-0x7dffff (because there is WRAM after that), hence we directly use the mirror
2201   as the place where to write & read SFX RAM. SNES handlers have been setup accordingly. */
2204    has only access to 0x600000-0x7dffff (because there is WRAM after that), hence we directly use the mirror
2205    as the place where to write & read SFX RAM. SNES handlers have been setup accordingly. */
22022206   //printf("superfx_r_bank3: %08x = %02x\n", offset, snes_ram[0xe00000 + offset]);
22032207   return snes_ram[0xe00000 + offset];
22042208}
r7753r7754
22182222WRITE8_HANDLER( superfx_w_bank3 )
22192223{
22202224   /* IMPORTANT: SFX RAM sits in 0x600000-0x7fffff, and it's mirrored in 0xe00000-0xffffff. However, SNES
2221   has only access to 0x600000-0x7dffff (because there is WRAM after that), hence we directly use the mirror
2222   as the place where to write & read SFX RAM. SNES handlers have been setup accordingly. */
2225    has only access to 0x600000-0x7dffff (because there is WRAM after that), hence we directly use the mirror
2226    as the place where to write & read SFX RAM. SNES handlers have been setup accordingly. */
22232227   //printf("superfx_w_bank3: %08x = %02x\n", offset, data);
22242228   snes_ram[0xe00000 + offset] = data;
22252229}

Previous 15994 Revisions Next


© 1998-2018 The MESS Team