Step executes a single PPU cycle
()
| 674 | |
| 675 | // Step executes a single PPU cycle |
| 676 | func (ppu *PPU) Step() { |
| 677 | ppu.tick() |
| 678 | |
| 679 | renderingEnabled := ppu.flagShowBackground != 0 || ppu.flagShowSprites != 0 |
| 680 | preLine := ppu.ScanLine == 261 |
| 681 | visibleLine := ppu.ScanLine < 240 |
| 682 | // postLine := ppu.ScanLine == 240 |
| 683 | renderLine := preLine || visibleLine |
| 684 | preFetchCycle := ppu.Cycle >= 321 && ppu.Cycle <= 336 |
| 685 | visibleCycle := ppu.Cycle >= 1 && ppu.Cycle <= 256 |
| 686 | fetchCycle := preFetchCycle || visibleCycle |
| 687 | |
| 688 | // background logic |
| 689 | if renderingEnabled { |
| 690 | if visibleLine && visibleCycle { |
| 691 | ppu.renderPixel() |
| 692 | } |
| 693 | if renderLine && fetchCycle { |
| 694 | ppu.tileData <<= 4 |
| 695 | switch ppu.Cycle % 8 { |
| 696 | case 1: |
| 697 | ppu.fetchNameTableByte() |
| 698 | case 3: |
| 699 | ppu.fetchAttributeTableByte() |
| 700 | case 5: |
| 701 | ppu.fetchLowTileByte() |
| 702 | case 7: |
| 703 | ppu.fetchHighTileByte() |
| 704 | case 0: |
| 705 | ppu.storeTileData() |
| 706 | } |
| 707 | } |
| 708 | if preLine && ppu.Cycle >= 280 && ppu.Cycle <= 304 { |
| 709 | ppu.copyY() |
| 710 | } |
| 711 | if renderLine { |
| 712 | if fetchCycle && ppu.Cycle%8 == 0 { |
| 713 | ppu.incrementX() |
| 714 | } |
| 715 | if ppu.Cycle == 256 { |
| 716 | ppu.incrementY() |
| 717 | } |
| 718 | if ppu.Cycle == 257 { |
| 719 | ppu.copyX() |
| 720 | } |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | // sprite logic |
| 725 | if renderingEnabled { |
| 726 | if ppu.Cycle == 257 { |
| 727 | if visibleLine { |
| 728 | ppu.evaluateSprites() |
| 729 | } else { |
| 730 | ppu.spriteCount = 0 |
| 731 | } |
| 732 | } |
| 733 | } |
nothing calls this directly
no test coverage detected