         @vblankStarted         << 7   # S[7]
 
     setStatus: (value) ->
-        @vramWritesIgnored     = (value >>> 4) & 0x01 # S[4]
-        @spriteScalineOverflow = (value >>> 5) & 0x01 # S[5]
-        @spriteZeroHit         = (value >>> 6) & 0x01 # S[6]
-        @vblankStarted         = (value >>> 7)        # S[7]
+        @vramWritesIgnored     = (value >>> 4) & 1 # S[4]
+        @spriteScalineOverflow = (value >>> 5) & 1 # S[5]
+        @spriteZeroHit         = (value >>> 6) & 1 # S[6]
+        @vblankStarted         = (value >>> 7)     # S[7]
 
     ###########################################################
     # Object attribute memory access

    # Byte 3 = x screen coordinate

    renderSpritePixel: ->
        # TODO rewrite and optimize this
        @fetchSprites() if @cycle is 1
        return 0 if not @spritesVisible or (@cycle < 9 and @spriteClipping)
        @spriteZeroRendered = false
        currentX = @cycle - 1
        currentY = @scanline - 1
        heightMask = if @bigSprites then 0x0F else 0x07
        for address in @spriteAddresses
            innerX = currentX - @objectAttributeMemory[address + 3]
            if 0 <= innerX <= 7
                innerY = currentY - @objectAttributeMemory[address]
                patternNumber = @objectAttributeMemory[address + 1]
                attributes = @objectAttributeMemory[address + 2]
                innerX ^= 0x07 if not (attributes & 0x40)
                innerY ^= heightMask if attributes & 0x80
                patternTableIndex = if @bigSprites then patternNumber & 0x01 else @spritesPatternTableIndex
                patternTableAddress = patternTableIndex << 12
                if innerY >= 8
                    patternNumber++
                    innerY -= 8
                patternAddress = patternTableAddress + (patternNumber << 4)
                patternLayer1Row = @read patternAddress + innerY
                patternLayer2Row = @read patternAddress + innerY + 8
                colorSelect1 =  (patternLayer1Row >>> innerX) & 0x01
                colorSelect2 = ((patternLayer2Row >>> innerX) & 0x01) << 1
                colorSelect = colorSelect2 | colorSelect1
                if colorSelect
                    @spriteZeroRendered ||= address is 0
                    @spriteInFront = (attributes & 0x20) is 0
                    paletteSelect = (attributes & 0x03) << 2
                    return 0x10 | paletteSelect | colorSelect
        return 0

    fetchSprites: ->
        @spriteScalineOverflow = 0
        @spriteAddresses = []
        bottomY = @scanline - 1
        topY = Math.max 0, bottomY - (if @bigSprites then 16 else 8)
        for spriteY, address in @objectAttributeMemory by 4
            if topY < spriteY <= bottomY
                @spriteAddresses.push address
                if @spriteAddresses.length >= 8
                    @spriteScalineOverflow = 1
                    return

    ###########################################################
    # Debug rendering

    writeScroll: (value) ->
        @writeToogle = not @writeToogle
        if @writeToogle # 1st write (x scroll)
            @tempXScroll = value & 0x07
            coarseXScroll = value >>> 3
            @tempAddress = (@tempAddress & 0xFFE0) | coarseXScroll
        else            # 2nd write (y scroll)
