src/mame/video/ppu2c0x.c
| r5380 | r5381 | |
| 527 | 527 | int size; |
| 528 | 528 | int spriteCount = 0; |
| 529 | 529 | int sprite_line; |
| 530 | | int drawn; |
| 531 | 530 | |
| 532 | 531 | int first_pixel; |
| 533 | 532 | |
| 534 | 533 | const pen_t *paldata; |
| 535 | | // const UINT8 *sd; |
| 536 | 534 | int pixel; |
| 537 | 535 | |
| 538 | 536 | /* determine if the sprites are 8x8 or 8x16 */ |
| r5380 | r5381 | |
| 567 | 565 | if ((spriteYPos + size <= scanline) || (spriteYPos > scanline)) |
| 568 | 566 | continue; |
| 569 | 567 | |
| 570 | | /* clear our drawn flag */ |
| 571 | | drawn = 0; |
| 572 | | |
| 573 | 568 | tile = sprite_ram[spriteIndex + 1]; |
| 574 | 569 | color = (sprite_ram[spriteIndex + 2] & 0x03) + 4; |
| 575 | 570 | pri = sprite_ram[spriteIndex + 2] & 0x20; |
| r5380 | r5381 | |
| 596 | 591 | /* compute the character's line to draw */ |
| 597 | 592 | sprite_line = scanline - spriteYPos; |
| 598 | 593 | |
| 599 | | |
| 600 | 594 | if (flipy) |
| 601 | 595 | sprite_line = (size - 1) - sprite_line; |
| 602 | 596 | |
| r5380 | r5381 | |
| 615 | 609 | plane1 = memory_read_byte(device->space[0], (index1 + sprite_line) & 0x1fff); |
| 616 | 610 | plane2 = memory_read_byte(device->space[0], (index1 + sprite_line + 8) & 0x1fff); |
| 617 | 611 | |
| 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 | |
| 618 | 628 | if (pri) |
| 619 | 629 | { |
| 620 | 630 | /* draw the low-priority sprites */ |
| r5380 | r5381 | |
| 645 | 655 | /* no, draw */ |
| 646 | 656 | if ((spriteXPos + pixel) < VISIBLE_SCREEN_WIDTH) |
| 647 | 657 | *BITMAP_ADDR16(bitmap, scanline, spriteXPos + pixel) = paldata[pixelData]; |
| 648 | | drawn = 1; |
| 649 | 658 | } |
| 650 | 659 | /* indicate that a sprite was drawn at this location, even if it's not seen */ |
| 651 | 660 | if ((spriteXPos + pixel) < VISIBLE_SCREEN_WIDTH) |
| r5380 | r5381 | |
| 669 | 678 | pixelData = (plane1 & 1) + ((plane2 & 1) << 1); |
| 670 | 679 | plane1 = plane1 >> 1; |
| 671 | 680 | plane2 = plane2 >> 1; |
| 672 | | // sd[7 - pixel] |
| 673 | 681 | } |
| 674 | 682 | else |
| 675 | 683 | { |
| 676 | 684 | pixelData = ((plane1 >> 7) & 1) | (((plane2 >> 7) & 1) << 1); |
| 677 | 685 | plane1 = plane1 << 1; |
| 678 | 686 | plane2 = plane2 << 1; |
| 679 | | // sd[pixel]; |
| 680 | 687 | } |
| 681 | 688 | |
| 682 | 689 | /* is this pixel non-transparent? */ |
| r5380 | r5381 | |
| 693 | 700 | *BITMAP_ADDR16(bitmap, scanline, spriteXPos + pixel) = paldata[pixelData]; |
| 694 | 701 | line_priority[spriteXPos + pixel] |= 0x01; |
| 695 | 702 | } |
| 696 | | drawn = 1; |
| 697 | 703 | } |
| 698 | 704 | } |
| 699 | 705 | |
| r5380 | r5381 | |
| 703 | 709 | } |
| 704 | 710 | } |
| 705 | 711 | } |
| 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 | | } |
| 720 | 712 | } |
| 721 | 713 | } |
| 722 | 714 | |
| r5380 | r5381 | |
| 739 | 731 | /* clear the line priority for this scanline */ |
| 740 | 732 | memset(line_priority, 0, VISIBLE_SCREEN_WIDTH); |
| 741 | 733 | |
| 742 | | /* clear the sprite count for this line */ |
| 743 | | ppu_regs[PPU_STATUS] &= ~PPU_STATUS_8SPRITES; |
| 744 | | |
| 745 | 734 | /* see if we need to render the background */ |
| 746 | 735 | if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_BACKGROUND) |
| 747 | 736 | draw_background(device, line_priority); |
| r5380 | r5381 | |
| 767 | 756 | *BITMAP_ADDR16(bitmap, scanline, i) = back_pen; |
| 768 | 757 | } |
| 769 | 758 | |
| 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); |
| 773 | 761 | |
| 774 | 762 | /* done updating, whew */ |
| 775 | 763 | profiler_mark(PROFILER_END); |
| r5380 | r5381 | |
| 898 | 886 | { |
| 899 | 887 | // logerror("vblank ending\n"); |
| 900 | 888 | /* 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); |
| 902 | 890 | } |
| 903 | 891 | |
| 904 | 892 | /* see if we rolled */ |