 cycleFlagsTable[338]    |= F_SKIP
 scanlineFlagsTable[261] |= F_SKIP
 
+class Sprite
+
+    constructor: ->
+        @address = 0
+        @height = 0
+        @rowNumber = 0
+        @x = 0
+        @horizontalFlip = false
+        @paletteNumber = 0
+        @inFront = false
+        @zeroSprite = false
+        @patternRow0 = 0
+        @patternRow1 = 0
+
 ###########################################################
 # Picture processing unit
 ###########################################################

        return 0 if @$isSpritePixelInvisible()
        rightX = @cycle - 1
        leftX = rightX - 8
        for sprite in @secondaryOAM when leftX <= sprite.x <= rightX
            columnNumber = rightX - sprite.x
            columnNumber ^= 0x07 if not sprite.horizontalFlip
            colorBit0 = ((sprite.patternRow0 >>> columnNumber) & 1)
            colorBit1 = ((sprite.patternRow1 >>> columnNumber) & 1) << 1
            colorNumber = colorBit1 | colorBit0
            if colorNumber
                @renderedSprite = sprite
                return sprite.paletteNumber | colorNumber
        return 0

    isSpritePixelInvisible: ->
        not @spritesVisible or @spriteClipping and (@cycleFlags & F_CLIP_LEFT)

    evaluateSprites: ->
        @secondaryOAM = []
        @spriteNumber = 0
        @spriteScalineOverflow = 0
        spriteHeight = if @bigSprites then 16 else 8
        bottomY = @scanline
        topY = Math.max 0, bottomY - spriteHeight
        for spriteY, address in @primaryOAM by 4 when topY < spriteY <= bottomY
            @secondaryOAM.push
                address: address
                height: spriteHeight
                rowNumber: bottomY - spriteY
            if @secondaryOAM.length is 8
                @spriteScalineOverflow = 1
                break
        undefined

    fetchSpriteLow: ->
        @sprite = @secondaryOAM[@spriteNumber]
        if @sprite
            address = @sprite.address
            patternNumber = @primaryOAM[address + 1]
            patternTableAddress = @spPatternTableAddress

            @sprite.inFront = (attributes & 0x20) is 0
            @sprite.zeroSprite = address is 0
            @sprite.patternRow0 = @ppuMemory.read @addressBus
        else
            @sprite = null

    fetchSpriteHigh: ->
        if @sprite
            @addressBus += 8
            @sprite.patternRow1 = @ppuMemory.read @addressBus
            @spriteNumber++

