Previous 15994 Revisions Next

r7658 Sunday 28th March, 2010 at 11:38:51 UTC by Fabio Priuli
[SNES] Improved HDMA emulation: it now init/updates as specified by Anomie's docs
[src/mame/includes]snes.h
[src/mame/machine]snes.c

src/mame/machine/snes.c
r7657r7658
3636static const UINT16 vram_fgr_shiftab[4] = { 0, 5, 6, 7 };
3737
3838static void snes_dma(const address_space *space, UINT8 channels);
39static void snes_hdma_init(running_machine *machine);
39static void snes_hdma_init(const address_space *space);
4040static void snes_hdma(const address_space *space);
4141
4242struct snes_cart_info snes_cart;
r7657r7658
119119
120120static TIMER_CALLBACK( snes_reset_hdma )
121121{
122   snes_hdma_init(machine);
122   snes_state *state = (snes_state *)machine->driver_data;
123   const address_space *cpu0space = cpu_get_address_space(state->maincpu, ADDRESS_SPACE_PROGRAM);
124   snes_hdma_init(cpu0space);
123125}
124126
125127static TIMER_CALLBACK( snes_scanline_tick )
r7657r7658
190192   // hdma reset happens at scanline 0, H=~6
191193   if (snes_ppu.beam.current_vert == 0)
192194   {
193      snes_hdma_init(machine);
195      const address_space *cpu0space = cpu_get_address_space(state->maincpu, ADDRESS_SPACE_PROGRAM);
196      snes_hdma_init(cpu0space);
194197   }
195198
196199   /* three lines after start of vblank we update the controllers (value from snes9x) */
r7657r7658
440443   }
441444}
442445
446/*************************************************
447
448 SNES OAM accesses:
449
450 OAM accesses during active display are allowed.
451 The actual address varies during rendering, as the
452 PPU reads in data itself for processing.
453 Unfortunately, no one has been able (yet) to
454 determine how this works. The only known game to
455 actually access OAM during active display is
456 Uniracers and it expects accesses to map to
457 offset 0x0218. Hence, following byuu's choice
458 we rerouted OAM accesses during active display
459 to 0x0218 (0x010c in our snes_oam).
460 This is a hack, but it is more accurate than
461 writing to the 'expected' address set by
462 $2102,$2103.
463
464 Notice that, since snes_ram[OAMDATA] is never
465 read/written directly, we use it as an index
466 to choose the high/low byte of the snes_oam word.
467*************************************************/
468
469static READ8_HANDLER( snes_oam_read )
470{
471   offset &= 0x1ff;
472
473   if (offset & 0x100)
474      offset &= 0x10f;
475
476   if (!snes_ppu.screen_disabled)
477   {
478      UINT16 v = video_screen_get_vpos(space->machine->primary_screen);
479
480      if (v < snes_ppu.beam.last_visible_line)
481         offset = 0x010c;
482   }
483
484   return (snes_oam[offset] >> (snes_ram[OAMDATA] << 3)) & 0xff;;
485}
486
487static WRITE8_HANDLER( snes_oam_write )
488{
489   offset &= 0x1ff;
490
491   if (offset & 0x100)
492      offset &= 0x10f;
493
494   if (!snes_ppu.screen_disabled)
495   {
496      UINT16 v = video_screen_get_vpos(space->machine->primary_screen);
497
498      if (v < snes_ppu.beam.last_visible_line)
499         offset = 0x010c;
500   }
501
502   if (!(snes_ram[OAMDATA]))
503      snes_oam[offset] = (snes_oam[offset] & 0xff00) | (data << 0);
504   else
505      snes_oam[offset] = (snes_oam[offset] & 0x00ff) | (data << 8);
506}
507
508/*************************************************
509
510 SNES CGRAM accesses:
511
512 CGRAM writes during hblank are valid. During
513 active display, the actual address the data
514 is written to varies, as the PPU itself changes
515 the address. Like OAM, it is not known the exact
516 algorithm used, but no commercial software seems
517 to attempt this. While byuu, in his emu, maps
518 those accesses to 0x01ff, because it is more
519 accurate to invalidate the 'expected' address
520 than not, MESS has issues if we don't write to
521 the expected address (see e.g. Tokimeki Memorial).
522 This is because writes should work during hblank
523 (so that the game can produce color fading), but
524 ends up not working with the conditions below.
525 Hence, for the moment, we only document the
526 solution adopted by BSNES without enabling it.
527*************************************************/
528
529static READ8_HANDLER( snes_cgram_read )
530{
531   UINT8 res = 0;
532   offset &= 0x1ff;
533
534#if 0
535   if (!snes_ppu.screen_disabled)
536   {
537      UINT16 v = video_screen_get_vpos(space->machine->primary_screen);
538      UINT16 h = video_screen_get_hpos(space->machine->primary_screen);
539
540      if (v < snes_ppu.beam.last_visible_line && h >= 128 && h < 1096)
541         offset = 0x1ff;
542   }
543#endif
544
545   res = ((UINT8 *)snes_cgram)[offset];
546
547   // CGRAM palette data format is 15-bits (0,bbbbb,ggggg,rrrrr).
548   // Highest bit is simply ignored.
549   if (offset & 0x01)
550      res &= 0x7f;
551
552   return res;
553}
554
555static WRITE8_HANDLER( snes_cgram_write )
556{
557   offset &= 0x1ff;
558
559#if 0
560   // FIXME: this currently breaks some games (e.g. Tokimeki Memorial),
561   // even if it's expected to be more accurate than allowing for
562   // writes to the cgram address
563   if (!snes_ppu.screen_disabled)
564   {
565      UINT16 v = video_screen_get_vpos(space->machine->primary_screen);
566      UINT16 h = video_screen_get_hpos(space->machine->primary_screen);
567
568      if (v < snes_ppu.beam.last_visible_line && h >= 128 && h < 1096)
569         offset = 0x1ff;
570   }
571#endif
572
573   // CGRAM palette data format is 15-bits (0,bbbbb,ggggg,rrrrr).
574   // Highest bit is simply ignored.
575   if (offset & 0x01)
576      data &= 0x7f;
577
578   ((UINT8 *)snes_cgram)[offset] = data;
579}
580
443581/*
444582 * DR   - Double read : address is read twice to return a 16bit value.
445583 * low  - This is the low byte of a 16 or 24 bit value
r7657r7658
539677         snes_latch_counters(space->machine);
540678         return snes_open_bus_r(space, 0);      /* Return value is meaningless */
541679      case ROAMDATA:   /* Read data from OAM (DR) */
680         snes_ppu.ppu1_open_bus = snes_oam_read(space, snes_ppu.oam.address);
681         snes_ram[OAMDATA] = (snes_ram[OAMDATA] + 1) % 2;
682         if (!snes_ram[OAMDATA])
542683         {
543            int oam_addr = snes_ppu.oam.address;
544
545            if (oam_addr & 0x100)
546            {
547               oam_addr &= 0x10f;
548            }
549            else
550            {
551               oam_addr &= 0x1ff;
552            }
553
554            snes_ppu.ppu1_open_bus = (snes_oam[oam_addr] >> (snes_ram[OAMDATA] << 3)) & 0xff;
555            snes_ram[OAMDATA] = (snes_ram[OAMDATA] + 1) % 2;
556            if (!snes_ram[OAMDATA])
557            {
558               snes_ppu.oam.address++;
559               snes_ppu.oam.address &= 0x1ff;
560               snes_ppu.oam.first_sprite = snes_ppu.oam.priority_rotation ? (snes_ppu.oam.address >> 1) & 127 : 0;
561            }
562            return snes_ppu.ppu1_open_bus;
684            snes_ppu.oam.address++;
685            snes_ppu.oam.address &= 0x1ff;
686            snes_ppu.oam.first_sprite = snes_ppu.oam.priority_rotation ? (snes_ppu.oam.address >> 1) & 127 : 0;
563687         }
688         return snes_ppu.ppu1_open_bus;
564689      case RVMDATAL:   /* Read data from VRAM (low) */
565690         {
566691            UINT32 addr = snes_get_vram_address(space->machine) << 1;
r7657r7658
596721            return snes_ppu.ppu1_open_bus;
597722         }
598723      case RCGDATA:   /* Read data from CGRAM */
599            if (!(state->cgram_address & 0x01))
600            {
601               snes_ppu.ppu2_open_bus = ((UINT8 *)snes_cgram)[state->cgram_address] & 0xff;
602            }
603            else
604            {
605               snes_ppu.ppu2_open_bus &= 0x80;
606               snes_ppu.ppu2_open_bus |= ((UINT8 *)snes_cgram)[state->cgram_address] & 0x7f;
607            }
724         if (!(state->cgram_address & 0x01))
725            snes_ppu.ppu2_open_bus = snes_cgram_read(space, state->cgram_address);
726         else
727         {
728            snes_ppu.ppu2_open_bus &= 0x80;
729            snes_ppu.ppu2_open_bus |= snes_cgram_read(space, state->cgram_address) & 0x7f;
730         }
608731
609            state->cgram_address = (state->cgram_address + 1) % (SNES_CGRAM_SIZE - 2);
610            return snes_ppu.ppu2_open_bus;
732         state->cgram_address = (state->cgram_address + 1) % (SNES_CGRAM_SIZE - 2);
733         return snes_ppu.ppu2_open_bus;
611734      case OPHCT:      /* Horizontal counter data by ext/soft latch */
735         if (state->read_ophct)
612736         {
613            if (state->read_ophct)
614            {
615               snes_ppu.ppu2_open_bus &= 0xfe;
616               snes_ppu.ppu2_open_bus |= (snes_ppu.beam.latch_horz >> 8) & 0x01;
617            }
618            else
619            {
620               snes_ppu.ppu2_open_bus = snes_ppu.beam.latch_horz & 0xff;
621            }
622            state->read_ophct ^= 1;
623            return snes_ppu.ppu2_open_bus;
737            snes_ppu.ppu2_open_bus &= 0xfe;
738            snes_ppu.ppu2_open_bus |= (snes_ppu.beam.latch_horz >> 8) & 0x01;
624739         }
740         else
741         {
742            snes_ppu.ppu2_open_bus = snes_ppu.beam.latch_horz & 0xff;
743         }
744         state->read_ophct ^= 1;
745         return snes_ppu.ppu2_open_bus;
625746      case OPVCT:      /* Vertical counter data by ext/soft latch */
747         if (state->read_opvct)
626748         {
627            if (state->read_opvct)
628            {
629               snes_ppu.ppu2_open_bus &= 0xfe;
630               snes_ppu.ppu2_open_bus |= (snes_ppu.beam.latch_vert >> 8) & 0x01;
631            }
632            else
633            {
634               snes_ppu.ppu2_open_bus = snes_ppu.beam.latch_vert & 0xff;
635            }
636            state->read_opvct ^= 1;
637            return snes_ppu.ppu2_open_bus;
749            snes_ppu.ppu2_open_bus &= 0xfe;
750            snes_ppu.ppu2_open_bus |= (snes_ppu.beam.latch_vert >> 8) & 0x01;
638751         }
752         else
753         {
754            snes_ppu.ppu2_open_bus = snes_ppu.beam.latch_vert & 0xff;
755         }
756         state->read_opvct ^= 1;
757         return snes_ppu.ppu2_open_bus;
639758      case STAT77:   /* PPU status flag and version number */
640759         value = snes_ppu.stat77_flags & 0xc0; // 0x80 & 0x40 are Time Over / Range Over Sprite flags, set by the video code
641760         // 0x20 - Master/slave mode select. Little is known about this bit. We always seem to read back 0 here.
r7657r7658
669788      case WMADDH:   /* Address to read/write to wram (high) */
670789         return snes_ram[offset];
671790      case OLDJOY1:   /* Data for old NES controllers (JOYSER1) */
672         {
673            if (snes_ram[offset] & 0x1)
674            {
675               return 0 | (snes_open_bus_r(space, 0) & 0xfc); //correct?
676            }
791         if (snes_ram[offset] & 0x1)
792            return 0 | (snes_open_bus_r(space, 0) & 0xfc); //correct?
677793
678            value = state->oldjoy1_read(space->machine);
794         value = state->oldjoy1_read(space->machine);
679795
680            return (value & 0x03) | (snes_open_bus_r(space, 0) & 0xfc); //correct?
681         }
796         return (value & 0x03) | (snes_open_bus_r(space, 0) & 0xfc); //correct?
682797      case OLDJOY2:   /* Data for old NES controllers (JOYSER2) */
683         {
684            if (snes_ram[OLDJOY1] & 0x1)
685            {
686               return 0 | 0x1c | (snes_open_bus_r(space, 0) & 0xe0); //correct?
687            }
798         if (snes_ram[OLDJOY1] & 0x1)
799            return 0 | 0x1c | (snes_open_bus_r(space, 0) & 0xe0); //correct?
688800
689            value = state->oldjoy2_read(space->machine);
801         value = state->oldjoy2_read(space->machine);
690802
691            return value | 0x1c | (snes_open_bus_r(space, 0) & 0xe0); //correct?
692         }
803         return value | 0x1c | (snes_open_bus_r(space, 0) & 0xe0); //correct?
693804      case HTIMEL:
694805      case HTIMEH:
695806      case VTIMEL:
r7657r7658
878989         snes_ram[OAMDATA] = 0;
879990         break;
880991      case OAMDATA:   /* Data for OAM write (DW) */
992         if (snes_ppu.oam.address >= 0x100)
993            snes_oam_write(space, snes_ppu.oam.address, data);
994         else
881995         {
882            int oam_addr = snes_ppu.oam.address;
883
884            if (oam_addr >= 0x100)
885            {
886               oam_addr &= 0x10f;
887               if (!(snes_ram[OAMDATA]))
888               {
889                  snes_oam[oam_addr] &= 0xff00;
890                  snes_oam[oam_addr] |= data;
891               }
892               else
893               {
894                  snes_oam[oam_addr] &= 0x00ff;
895                  snes_oam[oam_addr] |= (data << 8);
896               }
897            }
996            if (!snes_ram[OAMDATA])
997               snes_ppu.oam.write_latch = data;
898998            else
899999            {
900               oam_addr &= 0x1ff;
901               if (!(snes_ram[OAMDATA]))
902               {
903                  snes_ppu.oam.write_latch = data;
904               }
905               else
906               {
907                  snes_oam[oam_addr] = (data << 8) | snes_ppu.oam.write_latch;
908               }
909            }
910            snes_ram[OAMDATA] = (snes_ram[OAMDATA] + 1) % 2;
911            if (snes_ram[OAMDATA] == 0)
912            {
1000               // in this case, we not only write data to the upper byte of the word,
1001               // but also snes_ppu.oam.write_latch to the lower byte (recall that
1002               // snes_ram[OAMDATA] is used to select high/low byte)
1003               snes_oam_write(space, snes_ppu.oam.address, data);
9131004               snes_ram[OAMDATA] = 0;
914               snes_ppu.oam.address++;
915               snes_ppu.oam.address &= 0x1ff;
916               snes_ppu.oam.first_sprite = snes_ppu.oam.priority_rotation ? (snes_ppu.oam.address >> 1) & 127 : 0;
1005               snes_oam_write(space, snes_ppu.oam.address, snes_ppu.oam.write_latch);
1006               snes_ram[OAMDATA] = 1;
9171007            }
918            return;
9191008         }
1009         snes_ram[OAMDATA] = (snes_ram[OAMDATA] + 1) % 2;
1010         if (!snes_ram[OAMDATA])
1011         {
1012            snes_ppu.oam.address++;
1013            snes_ppu.oam.address &= 0x1ff;
1014            snes_ppu.oam.first_sprite = snes_ppu.oam.priority_rotation ? (snes_ppu.oam.address >> 1) & 127 : 0;
1015         }
1016         return;
9201017      case BGMODE:   /* BG mode and character size settings */
9211018         snes_ppu.mode = data & 0x07;
9221019         snes_dynamic_res_change(space->machine);
r7657r7658
10841181         snes_ppu.mode7_last_scroll = data;
10851182         break;
10861183      case CGADD:      /* Initial address for colour RAM writing */
1087         /* CGRAM is 16-bit, but when reading/writing we treat it as
1088                 * 8-bit, so we need to double the address */
1184         /* CGRAM is 16-bit, but when reading/writing we treat it as 8-bit, so we need to double the address */
10891185         state->cgram_address = data << 1;
10901186         break;
10911187      case CGDATA:   /* Data for colour RAM */
1092         ((UINT8 *)snes_cgram)[state->cgram_address] = data;
1188         snes_cgram_write(space, state->cgram_address, data);
10931189         state->cgram_address = (state->cgram_address + 1) % (SNES_CGRAM_SIZE - 2);
10941190         break;
10951191      case W12SEL:   /* Window mask settings for BG1-2 */
r7657r7658
24892585   memory_write_byte(space, dst, memory_read_byte(space, src));
24902586}
24912587
2492#if 0
2493// FIXME: we need to use snes_state->hdma_iaddr[i] where appropriate (we now still
2494// use snes_state->trans_size[i] to avoid regressions in this first wip)
2495// and try to make the addr recovering/updating a bit more abstract
2588/* WIP: These have the advantage to automatically update the address, but then we would need to
2589check again if the transfer is direct/indirect at each step... is it worth? */
24962590INLINE UINT32 snes_get_hdma_addr( running_machine *machine, int dma )
24972591{
24982592   snes_state *state = (snes_state *)machine->driver_data;
r7657r7658
25022596INLINE UINT32 snes_get_hdma_iaddr( running_machine *machine, int dma )
25032597{
25042598   snes_state *state = (snes_state *)machine->driver_data;
2505   return (state->dma_channel[dma].ibank << 16) | (state->dma_channel[dma].hdma_iaddr++);
2599   return (state->dma_channel[dma].ibank << 16) | (state->dma_channel[dma].trans_size++);
25062600}
2507#endif
25082601
2509static void snes_hdma_init( running_machine *machine )
2602static UINT8 snes_hdma_read( const address_space *space, UINT32 abus )
25102603{
2604   if (!dma_abus_valid(abus))
2605      return 0;
2606
2607   return memory_read_byte(space, abus);
2608}
2609
2610static int is_last_active_channel( running_machine *machine, int dma )
2611{
25112612   snes_state *state = (snes_state *)machine->driver_data;
25122613   int i;
25132614
2615   for (i = dma + 1; i < 8; i++)
2616   {
2617      if (BIT(state->hdmaen, i) && state->dma_channel[i].hdma_line_counter)
2618         return 0;   // there is still at least another channel with incomplete HDMA
2619   }
2620
2621   // if we arrive here, all hdma transfers from (dma + 1) to 7 are completed or not active
2622   return 1;
2623}
2624
2625static void snes_hdma_update( const address_space *space, int dma )
2626{
2627   snes_state *state = (snes_state *)space->machine->driver_data;
2628   UINT32 abus = snes_get_hdma_addr(space->machine, dma);
2629
2630   state->dma_channel[dma].hdma_line_counter = snes_hdma_read(space, abus);
2631
2632   if (state->dma_channel[dma].dmap & 0x40)
2633   {
2634      /* One oddity: if $43xA is 0 and this is the last active HDMA channel for this scanline, only load
2635      one byte for Address, and use the $00 for the low byte. So Address ends up incremented one less than
2636      otherwise expected */
2637
2638      abus = snes_get_hdma_addr(space->machine, dma);
2639      state->dma_channel[dma].trans_size = snes_hdma_read(space, abus) << 8;
2640
2641      if (state->dma_channel[dma].hdma_line_counter || !is_last_active_channel(space->machine, dma))
2642      {
2643         // we enter here if we have more transfers to be done or if there are other active channels after this one
2644         abus = snes_get_hdma_addr(space->machine, dma);
2645         state->dma_channel[dma].trans_size >>= 8;
2646         state->dma_channel[dma].trans_size |= snes_hdma_read(space, abus) << 8;
2647      }
2648   }
2649
2650   if (!state->dma_channel[dma].hdma_line_counter)
2651      state->hdmaen &= ~(1 << dma);
2652
2653   state->dma_channel[dma].do_transfer = 1;
2654}
2655
2656static void snes_hdma_init( const address_space *space )
2657{
2658   snes_state *state = (snes_state *)space->machine->driver_data;
2659   int i;
2660
25142661   state->hdmaen = snes_ram[HDMAEN];
25152662   for (i = 0; i < 8; i++)
25162663   {
25172664      if (BIT(state->hdmaen, i))
25182665      {
25192666         state->dma_channel[i].hdma_addr = state->dma_channel[i].src_addr;
2520         state->dma_channel[i].hdma_line_counter = 0;
2667         snes_hdma_update(space, i);
25212668      }
25222669   }
25232670}
r7657r7658
25252672static void snes_hdma( const address_space *space )
25262673{
25272674   snes_state *state = (snes_state *)space->machine->driver_data;
2528   UINT8 i, contmode;
25292675   UINT16 bbus;
25302676   UINT32 abus;
2677   int i;
25312678
2532   /* Assume priority of the 8 DMA channels is 0-7 */
25332679   for (i = 0; i < 8; i++)
25342680   {
25352681      if (BIT(state->hdmaen, i))
25362682      {
2537         /* Check if we need to read a new line from the table */
2538         if (!(state->dma_channel[i].hdma_line_counter & 0x7f))
2683         if (state->dma_channel[i].do_transfer)
25392684         {
2540            abus = (state->dma_channel[i].bank << 16) + state->dma_channel[i].hdma_addr;
2685            /* Get transfer addresses */
2686            if (state->dma_channel[i].dmap & 0x40)   /* Indirect */
2687               abus = (state->dma_channel[i].ibank << 16) + state->dma_channel[i].trans_size;
2688            else                           /* Absolute */
2689               abus = (state->dma_channel[i].bank << 16) + state->dma_channel[i].hdma_addr;
25412690
2542            /* Get the number of lines */
2543            state->dma_channel[i].hdma_line_counter = memory_read_byte(space, abus);
2544            if (!state->dma_channel[i].hdma_line_counter)
2691            bbus = state->dma_channel[i].dest_addr + 0x2100;   
2692
2693            switch (state->dma_channel[i].dmap & 0x07)
25452694            {
2546               /* No more lines so clear HDMA */
2547               state->hdmaen &= ~(1 << i);
2548               continue;
2549            }
2550            abus++;
2551            state->dma_channel[i].hdma_addr = abus;
2552            if (state->dma_channel[i].dmap & 0x40)
2553            {
2554               state->dma_channel[i].trans_size = memory_read_byte(space, abus++);
2555               state->dma_channel[i].trans_size |= (memory_read_byte(space, abus++) << 8);
2556               state->dma_channel[i].hdma_addr = abus;
2557            }
2558         }
2559
2560         contmode = (--state->dma_channel[i].hdma_line_counter) & 0x80;
2561
2562         /* Transfer addresses */
2563         if (state->dma_channel[i].dmap & 0x40)   /* Indirect */
2564            abus = (state->dma_channel[i].ibank << 16) + state->dma_channel[i].trans_size;
2565         else                           /* Absolute */
2566            abus = (state->dma_channel[i].bank << 16) + state->dma_channel[i].hdma_addr;
2567
2568         bbus = state->dma_channel[i].dest_addr + 0x2100;
2569
2570#ifdef SNES_DBG_HDMA
2571         mame_printf_debug( "HDMA-Ch: %d(%s) abus: %X bbus: %X type: %d(%X)\n", i, state->dma_channel[i].dmap & 0x40 ? "Indirect" : "Absolute", abus, bbus, state->dma_channel[i].dmap & 0x07, state->dma_channel[i].hdma_addr);
2572#endif
2573
2574         switch (state->dma_channel[i].dmap & 0x07)
2575         {
2576         case 0:      /* 1 register write once             (1 byte:  p               ) */
2577            snes_dma_transfer(space, i, abus++, bbus);
2578            break;
2579         case 5:      /* 2 registers write twice alternate (4 bytes: p, p+1, p,   p+1) */
2580            snes_dma_transfer(space, i, abus++, bbus);
2581            snes_dma_transfer(space, i, abus++, bbus + 1);
2582            snes_dma_transfer(space, i, abus++, bbus);
2583            snes_dma_transfer(space, i, abus++, bbus + 1);
2584            break;
2585         case 1:      /* 2 registers write once            (2 bytes: p, p+1          ) */
2586            snes_dma_transfer(space, i, abus++, bbus);
2587            snes_dma_transfer(space, i, abus++, bbus + 1);
2588            break;
2589         case 2:      /* 1 register write twice            (2 bytes: p, p            ) */
2590         case 6:
2591            snes_dma_transfer(space, i, abus++, bbus);
2592            snes_dma_transfer(space, i, abus++, bbus);
2593            break;
2594         case 3:      /* 2 registers write twice each      (4 bytes: p, p,   p+1, p+1) */
2595         case 7:
2596            snes_dma_transfer(space, i, abus++, bbus);
2597            snes_dma_transfer(space, i, abus++, bbus);
2598            snes_dma_transfer(space, i, abus++, bbus + 1);
2599            snes_dma_transfer(space, i, abus++, bbus + 1);
2600            break;
2601         case 4:      /* 4 registers write once            (4 bytes: p, p+1, p+2, p+3) */
2602            snes_dma_transfer(space, i, abus++, bbus);
2603            snes_dma_transfer(space, i, abus++, bbus + 1);
2604            snes_dma_transfer(space, i, abus++, bbus + 2);
2605            snes_dma_transfer(space, i, abus++, bbus + 3);
2606            break;
2607         default:
2695            case 0:      /* 1 register write once             (1 byte:  p               ) */
2696               snes_dma_transfer(space, i, abus++, bbus);
2697               break;
2698            case 5:      /* 2 registers write twice alternate (4 bytes: p, p+1, p,   p+1) */
2699               snes_dma_transfer(space, i, abus++, bbus);
2700               snes_dma_transfer(space, i, abus++, bbus + 1);
2701               snes_dma_transfer(space, i, abus++, bbus);
2702               snes_dma_transfer(space, i, abus++, bbus + 1);
2703               break;
2704            case 1:      /* 2 registers write once            (2 bytes: p, p+1          ) */
2705               snes_dma_transfer(space, i, abus++, bbus);
2706               snes_dma_transfer(space, i, abus++, bbus + 1);
2707               break;
2708            case 2:      /* 1 register write twice            (2 bytes: p, p            ) */
2709            case 6:
2710               snes_dma_transfer(space, i, abus++, bbus);
2711               snes_dma_transfer(space, i, abus++, bbus);
2712               break;
2713            case 3:      /* 2 registers write twice each      (4 bytes: p, p,   p+1, p+1) */
2714            case 7:
2715               snes_dma_transfer(space, i, abus++, bbus);
2716               snes_dma_transfer(space, i, abus++, bbus);
2717               snes_dma_transfer(space, i, abus++, bbus + 1);
2718               snes_dma_transfer(space, i, abus++, bbus + 1);
2719               break;
2720            case 4:      /* 4 registers write once            (4 bytes: p, p+1, p+2, p+3) */
2721               snes_dma_transfer(space, i, abus++, bbus);
2722               snes_dma_transfer(space, i, abus++, bbus + 1);
2723               snes_dma_transfer(space, i, abus++, bbus + 2);
2724               snes_dma_transfer(space, i, abus++, bbus + 3);
2725               break;
2726            default:
26082727#ifdef MAME_DEBUG
2609            mame_printf_debug( "  HDMA of unsupported type: %d\n", state->dma_channel[i].dmap & 0x07);
2728               mame_printf_debug( "  HDMA of unsupported type: %d\n", state->dma_channel[i].dmap & 0x07);
26102729#endif
2611            break;
2612         }
2730               break;
2731            }
26132732
2614         /* Update address */
2615         if (contmode)
2616         {
26172733            if (state->dma_channel[i].dmap & 0x40)   /* Indirect */
26182734               state->dma_channel[i].trans_size = abus;
26192735            else                           /* Absolute */
26202736               state->dma_channel[i].hdma_addr = abus;
2737
26212738         }
2739      }
2740   }
26222741
2742   for (i = 0; i < 8; i++)
2743   {
2744      if (BIT(state->hdmaen, i))
2745      {
2746         state->dma_channel[i].do_transfer = (--state->dma_channel[i].hdma_line_counter) & 0x80;
2747
26232748         if (!(state->dma_channel[i].hdma_line_counter & 0x7f))
2624         {
2625            if (!(state->dma_channel[i].dmap & 0x40))   /* Absolute */
2626            {
2627               if (!contmode)
2628                  state->dma_channel[i].hdma_addr = abus;
2629            }
2630         }
2749            snes_hdma_update(space, i);
26312750      }
26322751   }
26332752}
src/mame/includes/snes.h
r7657r7658
2323#define DOTCLK_NTSC   (MCLK_NTSC/4)
2424#define DOTCLK_PAL   (MCLK_PAL/4)
2525
26#define SNES_LAYER_DEBUG 
26#define SNES_LAYER_DEBUG  1
2727
2828/* Debug definitions */
2929#ifdef MAME_DEBUG
r7657r7658
415415      UINT8  hdma_line_counter;
416416      UINT8  unk;
417417
418      int    do_transfer;
419
418420      int    dma_disabled;   // used to stop DMA if HDMA is enabled (currently not implemented, see machine/snes.c)
419421   }dma_channel[8];
420422   UINT8                 hdmaen;   /* channels enabled for HDMA */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team