MCPcopy
hub / github.com/fogleman/nes / Step

Method Step

nes/ppu.go:676–744  ·  view source on GitHub ↗

Step executes a single PPU cycle

()

Source from the content-addressed store, hash-verified

674
675// Step executes a single PPU cycle
676func (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 }

Callers

nothing calls this directly

Calls 14

tickMethod · 0.95
renderPixelMethod · 0.95
fetchNameTableByteMethod · 0.95
fetchLowTileByteMethod · 0.95
fetchHighTileByteMethod · 0.95
storeTileDataMethod · 0.95
copyYMethod · 0.95
incrementXMethod · 0.95
incrementYMethod · 0.95
copyXMethod · 0.95
evaluateSpritesMethod · 0.95

Tested by

no test coverage detected