         @oamAddress = address
 
     readOAMData: ->
-        @objectAttributeMemory[@oamAddress] # Read does not increment the address.
+        value = @objectAttributeMemory[@oamAddress]   # Read does not increment the address.
+        value &= 0xE3 if (@oamAddress & 0x03) is 0x02 # Clear bits 2-4 when reading byte 2 of a sprite (these bits are not stored in OAM).
+        value
 
     writeOAMData: (value) ->
         @objectAttributeMemory[@oamAddress] = value if not @isRenderingInProgress()

    isRenderingEnabled: ->
        @spritesVisible or @backgroundVisible

    startFrame: ->
        @framePosition = 0
        @fetchCurrentPattern()
        @fetchCurrentAttribute()
        @fetchCurrentPalette()

    renderFramePixel: ->
        backgroundColor = @renderBackgroundPixel() if @backgroundVisible
        spriteColor = @renderSpritePixel() if @spritesVisible
        @setFramePixel backgroundColor or 0 # TODO rendering priority

    # Colors are saved at addresses with structure 0111.1111.000S.PPCC.
    #    S = 0 for background, 1 for sprites
    #   PP = palette number

        @resetVariables()

    resetOAM: ->
        @objectAttributeMemory = (0 for [0..0x100])  # 256B

    resetRegisters: ->
        @setControl 0        #  8-bit
        @setMask 0           #  8-bit
        @setStatus 0         #  8-bit
        @oamAddress = 0      # 15-bit
        @tempAddress = 0     # 15-bit also known as 'Loopy_T'
        @vramAddress = 0     # 15-bit also known as 'Loopy_V'
        @vramReadBuffer = 0  #  8-bit
        @writeToogle = 0     #  1-bit        
        @fineXScroll = 0     #  3-bit
        @tempFineXScroll = 0 #  3-bit

    resetVariables: ->
        @scanline = -1 # Total 262+1 scanlines (-1..261)
        @cycle = 0     # Total 341 cycles per scanline (0..340)
        @spriteAddresses = []
        @spriteZeroRendered = false
        @spriteInFront = false

    ###########################################################
    # Control register
