         nmiEnabledOld = @nmiEnabled
         @setControl value
         @tempAddress = (@tempAddress & 0xF3FF) | (value & 0x03) << 10 # T[11,10] = C[1,0]
-        @delayedNMI = true if @vblankStarted and not nmiEnabledOld and @nmiEnabled # Generate NMI after next instruction when its enabled (from 0 to 1) during VBLANK
+        @delayedNMI = true if @vblankFlag and not nmiEnabledOld and @nmiEnabled # Generate NMI after next instruction when its enabled (from 0 to 1) during VBLANK
         value
 
     setControl: (value) ->

        @tempXScroll = 0    #  3-bit

    resetVariables: ->
        @scanline = -1         # Total 262 scanlines (0..261)
        @cycle = 0             # Total 341 cycles per scanline (0..340)
        @renderedSprite = null # Currently rendered sprite
        @delayedNMI = false    # Generate NMI after next instruction when its enabled (from 0 to 1) during VBLANK

    setNTSCMode: (ntscMode) ->
        @ntscMode = ntscMode


    readStatus: ->
        value = @getStatus()
        @vblankFlag = 0     # Cleared by reading status
        @writeToogle = 0    # Cleared by reading status
        if @scanline is 241
            @suppressVBlank = true if @cycle is 1                   # Reading just before VBLANK disables NMI generation and VBLANK flag setting
            @cpu.clearInterrupt Interrupt.NMI if @cycle in [ 2, 3 ] # Reading at the start of VBLANK disables only NMI generation
        value

    getStatus: ->
        @vramWritesIgnored     << 4 | # S[4]
        @spriteScalineOverflow << 5 | # S[5]
        @spriteZeroHit         << 6 | # S[6]
        @vblankFlag            << 7   # S[7]

    setStatus: (value) ->
        @vramWritesIgnored     = (value >>> 4) & 1 # S[4]
        @spriteScalineOverflow = (value >>> 5) & 1 # S[5]
        @spriteZeroHit         = (value >>> 6) & 1 # S[6]
        @vblankFlag            = (value >>> 7)     # S[7]

    ###########################################################
    # Object attribute memory access
