     ###########################################################
 
     tick: ->
+        @$fetchPattern() if @cycle > 0 and (@cycle & 0x7) is 0
         @$updateFramePixel() if @$isRenderingCycle()
+        @$shiftPatternBuffers 1 if @cycle >= 1 and @cycle <= 336
+        @$shiftPaletteBuffers 1 if @cycle >= 1 and @cycle <= 336 #and (@cycle & 0x7) is 0
         @$updateScrolling() if @$isRenderingActive()
         @$updateVBlank()
         @$incrementCycle()

        value

    copyHorizontalScrollBits: ->
        @fineXScroll = @tempXScroll
        @vramAddress = (@vramAddress & 0x7BE0) | (@tempAddress & 0x041F) # V[10,4-0] = T[10,4-0]

    copyVerticalScrollBits: ->
        @vramAddress = (@vramAddress & 0x041F) | (@tempAddress & 0x7BE0) # V[14-11,9-5] = T[14-11,9-5]

    incrementFineXScroll: ->
        if @fineXScroll is 7
            @fineXScroll = 0
            @$incrementCoarseXScroll()
        else
            @fineXScroll++

    incrementCoarseXScroll: ->
        if (@vramAddress & 0x001F) is 0x001F # if coarseScrollX is 31

    #    X = bit 1 of XXXXX

    renderBackgroundPixel: ->
        return 0 if not @backgroundVisible or @backgroundClipping and @cycle < 9
        colorSelect1 = ((@patternLayer1Row << @fineXScroll) >> 15) & 0x1
        colorSelect2 = ((@patternLayer2Row << @fineXScroll) >> 14) & 0x2
        p1 = ((@paletteBuffer1 << @fineXScroll) >> 5) & 0x4
        p2 = ((@paletteBuffer2 << @fineXScroll) >> 4) & 0x8
        0x3F00 | p2 | p1 | colorSelect2 | colorSelect1

    shiftPatternBuffers: (amount) ->
        @patternLayer1Row <<= amount
        @patternLayer2Row <<= amount

    shiftPaletteBuffers: ->
        @paletteBuffer1 <<= 1
        @paletteBuffer2 <<= 1
        @paletteBuffer1 |= @paletteLatch1
        @paletteBuffer2 |= @paletteLatch2

    patternLayer1Row: 0
    patternLayer2Row: 0
    paletteBuffer1: 0
    paletteBuffer2: 0

    paletteLatch1: 0
    paletteLatch2: 0

    fetchPattern: ->
        @fetchPalette() #if (@cycle & 0xF) is 0 # When coarse scroll was incremented by 2
        patternNumer = @$read 0x2000 | @vramAddress & 0x0FFF
        patternAddress = @bgPatternTableAddress + (patternNumer << 4)
        fineYScroll = (@vramAddress >>> 12) & 0x07
        @patternLayer1Row |= @$read patternAddress + fineYScroll
        @patternLayer2Row |= @$read patternAddress + fineYScroll + 8

    fetchPalette: ->
        @fetchAttribute() #if (@cycle & 0x1F) is 0 # When coarse scroll was incremented by 4
        area = (@vramAddress >>> 4) & 0x04 | @vramAddress & 0x02
        palette = (@attribute >>> area) & 0x03
        @paletteLatch1 = palette & 1
        @paletteLatch2 = (palette >>> 1) & 1

    fetchAttribute: ->
        attributeTableAddress = 0x23C0 | @vramAddress & 0x0C00
