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

        @framebuffer

    tick: ->
        

module.exports = PPU

    writeScroll: (value) ->
        @writeAddress value # Uses the same register as VRAM addressing

    updateScrollingDataFromVRAMAddress: ->
        @coarseXScroll =           @vramAddress        & 0x1E # Bits 0-4
        @coarseYScroll =          (@vramAddress >>  5) & 0x1E # Bits 5-9
        @selectedNameTableIndex = (@vramAddress >> 10) & 0x03 # Bits 10,11
        @fineYScroll =            (@vramAddress >> 12) & 0x07 # Bits 12-14

    updateVRAMAddressFromScrollingData: ->
        @vramAddress = @coarseXScroll                | # Bits 0-4
                       @coarseYScroll          <<  5 | # Bits 5-9
                       @selectedNameTableIndex << 10 | # Bits 10,11
                       @fineYScroll            << 12   # Bits 12-14

    ###########################################################
    # VRAM access
    ###########################################################

    writeAddress: (address) ->
        @vramAddress = (@vramAddress << 8 | address) & 0xFFFF
        @updateScrollingDataFromVRAMAddress()
        address

    readData: ->
