     ###########################################################
 
     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()

    #    X = bit 1 of XXXXX

    renderBackgroundPixel: ->
        @fetchPattern() if @fineXScroll is 0 # When coarse scroll X was incremented.
        return 0 if not @backgroundVisible or @backgroundClipping and @cycle < 9
        columnNumber = @fineXScroll ^ 0x07 # 7 - fineXScroll
        colorSelect1 =  (@patternLayer1Row >>> columnNumber) & 1
        colorSelect2 = ((@patternLayer2Row >>> columnNumber) & 1) << 1
        0x3F00 | @paletteSelect | colorSelect2 | colorSelect1

    fetchPattern: ->
        @fetchPalette() if (@vramAddress & 0x0001) 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 (@vramAddress & 0x0002) is 0 # When coarse scroll was incremented by 4
        areaSelect = (@vramAddress >>> 4) & 0x04 | @vramAddress & 0x02
        @paletteSelect = ((@attribute >>> areaSelect) & 0x03) << 2

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

        value

    copyHorizontalScrollBits: ->
        @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]

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