Previous 15994 Revisions Next

r5381 Sunday 9th August, 2009 at 06:32:07 UTC by Fabio Priuli
Improved Sprite Overflow emulation of NES PPU (this fixes the first of blargg's Sprite Overflow tests) [Heretical One]
[src/mame/video]ppu2c0x.c

src/mame/video/ppu2c0x.c
r5380r5381
527527   int size;
528528   int spriteCount = 0;
529529   int sprite_line;
530   int drawn;
531530
532531   int first_pixel;
533532
534533   const pen_t *paldata;
535   // const UINT8 *sd;
536534   int pixel;
537535
538536   /* determine if the sprites are 8x8 or 8x16 */
r5380r5381
567565      if ((spriteYPos + size <= scanline) || (spriteYPos > scanline))
568566         continue;
569567
570      /* clear our drawn flag */
571      drawn = 0;
572
573568      tile = sprite_ram[spriteIndex + 1];
574569      color = (sprite_ram[spriteIndex + 2] & 0x03) + 4;
575570      pri = sprite_ram[spriteIndex + 2] & 0x20;
r5380r5381
596591      /* compute the character's line to draw */
597592      sprite_line = scanline - spriteYPos;
598593
599
600594      if (flipy)
601595         sprite_line = (size - 1) - sprite_line;
602596
r5380r5381
615609      plane1 = memory_read_byte(device->space[0], (index1 + sprite_line) & 0x1fff);
616610      plane2 = memory_read_byte(device->space[0], (index1 + sprite_line + 8) & 0x1fff);
617611
612      /* if there are more than 8 sprites on this line, set the flag */
613      if (spriteCount == 8)
614      {
615         ppu_regs[PPU_STATUS] |= PPU_STATUS_8SPRITES;
616//          logerror ("> 8 sprites, scanline: %d\n", scanline);
617
618         /* the real NES only draws up to 8 sprites - the rest should be invisible */
619         break;
620      }
621
622      spriteCount++;
623
624      /* abort drawing if sprites aren't rendered */
625      if (!(ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_SPRITES))
626         continue;
627
618628      if (pri)
619629      {
620630         /* draw the low-priority sprites */
r5380r5381
645655                     /* no, draw */
646656                     if ((spriteXPos + pixel) < VISIBLE_SCREEN_WIDTH)
647657                        *BITMAP_ADDR16(bitmap, scanline, spriteXPos + pixel) = paldata[pixelData];
648                     drawn = 1;
649658                  }
650659                  /* indicate that a sprite was drawn at this location, even if it's not seen */
651660                  if ((spriteXPos + pixel) < VISIBLE_SCREEN_WIDTH)
r5380r5381
669678               pixelData = (plane1 & 1) + ((plane2 & 1) << 1);
670679               plane1 = plane1 >> 1;
671680               plane2 = plane2 >> 1;
672               // sd[7 - pixel]
673681            }
674682            else
675683            {
676684               pixelData = ((plane1 >> 7) & 1) | (((plane2 >> 7) & 1) << 1);
677685               plane1 = plane1 << 1;
678686               plane2 = plane2 << 1;
679               // sd[pixel];
680687            }
681688
682689            /* is this pixel non-transparent? */
r5380r5381
693700                        *BITMAP_ADDR16(bitmap, scanline, spriteXPos + pixel) = paldata[pixelData];
694701                        line_priority[spriteXPos + pixel] |= 0x01;
695702                     }
696                     drawn = 1;
697703                  }
698704               }
699705
r5380r5381
703709            }
704710         }
705711      }
706
707      if (drawn)
708      {
709         /* if there are more than 8 sprites on this line, set the flag */
710         spriteCount++;
711         if (spriteCount == 8)
712         {
713            ppu_regs[PPU_STATUS] |= PPU_STATUS_8SPRITES;
714//              logerror ("> 8 sprites, scanline: %d\n", scanline);
715
716            /* the real NES only draws up to 8 sprites - the rest should be invisible */
717            break;
718         }
719      }
720712   }
721713}
722714
r5380r5381
739731   /* clear the line priority for this scanline */
740732   memset(line_priority, 0, VISIBLE_SCREEN_WIDTH);
741733
742   /* clear the sprite count for this line */
743   ppu_regs[PPU_STATUS] &= ~PPU_STATUS_8SPRITES;
744
745734   /* see if we need to render the background */
746735   if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_BACKGROUND)
747736      draw_background(device, line_priority);
r5380r5381
767756         *BITMAP_ADDR16(bitmap, scanline, i) = back_pen;
768757   }
769758
770   /* if sprites are on, draw them */
771   if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_SPRITES)
772      draw_sprites(device, line_priority);
759   /* if sprites are on, draw them, but we call always to process them */
760   draw_sprites(device, line_priority);
773761
774762    /* done updating, whew */
775763   profiler_mark(PROFILER_END);
r5380r5381
898886   {
899887      // logerror("vblank ending\n");
900888      /* clear the vblank & sprite hit flag */
901      ppu_regs[PPU_STATUS] &= ~(PPU_STATUS_VBLANK | PPU_STATUS_SPRITE0_HIT);
889      ppu_regs[PPU_STATUS] &= ~(PPU_STATUS_VBLANK | PPU_STATUS_SPRITE0_HIT | PPU_STATUS_8SPRITES);
902890   }
903891
904892   /* see if we rolled */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team