 
     writeWord: (address, value) ->
         @writeByte address, value & 0xFF
-        @writeByte address + 1, value >> 8
+        @writeByte (address + 1) & 0xFFFF, value >> 8
 
     ###########################################################
     # Stack pushing / pulling

        @readWord @readNextProgramWord()

    indirectXMode: =>
        address = @getIndexedAddressByte @readNextProgramByte(), @registerX
        @readWord address

    indirectYMode: =>
        base = @readWord @readNextProgramByte()

    ###########################################################

    relativeMode: =>
        base = (@programCounter + 1) & 0xFFFF # We need to get address of the next instruction
        offset = @getSignedByte @readNextProgramByte()
        @getIndexedAddressWord base, offset

    ###########################################################
    # Indirect addressing modes
