 FRAME_BUFFER_WIDTH  = require("../common/constants").VIDEO_WIDTH
 FRAME_BUFFER_HEIGHT = require("../common/constants").VIDEO_HEIGHT
 
-# Cycle/scanlines flags
+###########################################################
+# PPU cycle/scanlines flags
+###########################################################
+
 F_RENDER    = 1 <<  1 # Rendering cycle
 F_FETCH_NT  = 1 <<  2 # Cycle where nametable byte is fetched
 F_FETCH_AT  = 1 <<  3 # Cycle where attribute byte is fetched

        value

    getStatus: ->
        @spriteScalineOverflow << 5 | # S[5] Set when there is more than 8 sprites on current scanline
        @spriteZeroHit         << 6 | # S[6] Set when a nonzero pixel of sprite 0 overlaps a nonzero background pixel
        @vblankFlag            << 7   # S[7] Set at the start of the VBlank

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

    ###########################################################
    # OAM access ($2003 - address / $2004 - data)

    #    Y = bit 1 of YYYYY
    #    X = bit 1 of XXXXX

    fetchNametable: ->
        @addressBus = 0x2000 | @vramAddress & 0x0FFF
        patternNumer = @ppuMemory.read @addressBus # Nametable byte fetch
