         else
             backgroundColor
 
+    setFramePixel: (color) ->
+        colorPosition = color << 2 # Each RGBA color is 4B.
+        @frameBuffer[@framePosition++] = RGBA_COLORS[colorPosition++]
+        @frameBuffer[@framePosition++] = RGBA_COLORS[colorPosition++]
+        @frameBuffer[@framePosition++] = RGBA_COLORS[colorPosition]
+        @framePosition++ # Skip alpha because it was already set to 0xFF.
+
     updateScrolling: ->
-        @incrementFineYScroll() if @cycle is 256
-        @incrementFineXScroll() if 1 <= @cycle <= 256
-        @copyHorizontalScrollBits() if @cycle is 257
-        @copyVerticalScrollBits() if @scanline is -1 and 280 <= @cycle <= 304
+        if 1 <= @cycle <= 256
+            @incrementFineXScroll()
+            @incrementFineYScroll() if @cycle is 256
+        else if @cycle is 257
+            @copyHorizontalScrollBits()
+        else if @scanline is -1 and 280 <= @cycle <= 304
+            @copyVerticalScrollBits() 
 
     incrementCycle: ->
         @cycle++

        @frameBuffer = buffer
        @frameAvailable = false

    startFrame: ->
        @framePosition = 0
        @fetchPattern()
        @fetchAttribute()
        @fetchPalette()

    updateFramePixel: ->
        colorAddress = 0x3F00 | @renderFramePixel()
        @setFramePixel @read colorAddress

    setFramePixel: (color) ->
        colorPosition = color << 2 # Each RGBA color is 4B.
        @frameBuffer[@framePosition++] = RGBA_COLORS[colorPosition++]
        @frameBuffer[@framePosition++] = RGBA_COLORS[colorPosition++]
        @frameBuffer[@framePosition++] = RGBA_COLORS[colorPosition]
        @framePosition++ # Skip alpha because it was already set to 0xFF.

    renderFramePixel: ->
        backgroundColor = @renderBackgroundPixel()


    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
