src/emulator/PPU.js
// Step executes a single PPU cycle
Step executes a single PPU cycle
Step executes a single PPU cycle
step() {
        this.tick()
        let renderingEnabled = this.flagShowBackground != 0 || this.flagShowSprites != 0
        let preLine = this.scanLine == 261
        let visibleLine = this.scanLine < 240
        let renderLine = preLine || visibleLine
        let preFetchCycle = this.cycle >= 321 && this.cycle <= 336
        let visibleCycle = this.cycle >= 1 && this.cycle <= 256
        let fetchCycle = preFetchCycle || visibleCycle
        if (renderingEnabled) {
            if (visibleLine && visibleCycle) {
                this.renderPixel()
            }
            if (renderLine && fetchCycle) {
                this.tileData <<= 4
                switch (this.cycle % 8) {
                    case 1:
                        this.fetchNameTableByte()
                    case 3:
                        this.fetchAttributeTableByte()
                    case 5:
                        this.fetchLowTileByte()
                    case 7:
                        this.fetchHighTileByte()
                    case 0:
                        this.storeTileData()
                }
            }
            if (preLine && this.cycle >= 280 && this.cycle <= 304) {
                this.copyY()
            }
            if (renderLine) {
                if (fetchCycle && this.cycle % 8 == 0) {
                    this.incrementX()
                }
                if (this.cycle == 256) {
                    this.incrementY()
                }
                if (this.cycle == 257) {
                    this.copyX()
                }
            }
        }
        if (renderingEnabled) {
            if (this.cycle == 257) {
                if (visibleLine) {
                    this.evaluateSprites()
                } else {
                    this.spriteCount = 0
                }
            }
        }
        if (this.scanLine == 241 && this.cycle == 1) {
            this.setVerticalBlank()
        }
        if (preLine && this.Cycle == 1) {
            this.clearVerticalBlank()
            this.flagSpriteZeroHit = 0
            this.flagSpriteOverflow = 0
        }
    }
step ( ) { this . tick ( ) let renderingEnabled = this . flagShowBackground != 0 || this . flagShowSprites != 0 let preLine = this . scanLine == 261 let visibleLine = this . scanLine < 240 let renderLine = preLine || visibleLine let preFetchCycle = this . cycle >= 321 && this . cycle <= 336 let visibleCycle = this . cycle >= 1 && this . cycle <= 256 let fetchCycle = preFetchCycle || visibleCycle if ( renderingEnabled ) { if ( visibleLine && visibleCycle ) { this . renderPixel ( ) } if ( renderLine && fetchCycle ) { this . tileData <<= 4 switch ( this . cycle % 8 ) { case 1 : this . fetchNameTableByte ( ) case 3 : this . fetchAttributeTableByte ( ) case 5 : this . fetchLowTileByte ( ) case 7 : this . fetchHighTileByte ( ) case 0 : this . storeTileData ( ) } } if ( preLine && this . cycle >= 280 && this . cycle <= 304 ) { this . copyY ( ) } if ( renderLine ) { if ( fetchCycle && this . cycle % 8 == 0 ) { this . incrementX ( ) } if ( this . cycle == 256 ) { this . incrementY ( ) } if ( this . cycle == 257 ) { this . copyX ( ) } } } if ( renderingEnabled ) { if ( this . cycle == 257 ) { if ( visibleLine ) { this . evaluateSprites ( ) } else { this . spriteCount = 0 } } } if ( this . scanLine == 241 && this . cycle == 1 ) { this . setVerticalBlank ( ) } if ( preLine && this . Cycle == 1 ) { this . clearVerticalBlank ( ) this . flagSpriteZeroHit = 0 this . flagSpriteOverflow = 0 } }
Step executes a single PPU cycle
Step executes a single PPU cycle
// background logic // sprite logic // vblank logic