Last active
April 10, 2018 20:39
-
-
Save eioo/b6df459e46e3a46117e1f368d5b06c70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function read_file (filename) | |
input = io.open(filename, "r") -- Open this file with the read flag. | |
if input ~= nil then | |
io.input(input) -- Set the input that the io library will read from. | |
input_content = io.read() -- Read the contents of the file. | |
io.close(input) -- Close the file. | |
end | |
return input_content | |
end | |
function split(pString, pPattern) | |
local Table = {} -- NOTE: use {n = 0} in Lua-5.0 | |
local fpat = "(.-)" .. pPattern | |
local last_end = 1 | |
local s, e, cap = pString:find(fpat, 1) | |
while s do | |
if s ~= 1 or cap ~= "" then | |
table.insert(Table,cap) | |
end | |
last_end = e+1 | |
s, e, cap = pString:find(fpat, last_end) | |
end | |
if last_end <= #pString then | |
cap = pString:sub(last_end) | |
table.insert(Table, cap) | |
end | |
return Table | |
end | |
prev_inventory = '' | |
while true do | |
inventory = read_file('inventory.hex') | |
if inventory ~= prev_inventory then | |
items = split(inventory, ' ') | |
memory.writebyte(0x7D80, tonumber(items[1], 16)) | |
memory.writebyte(0x7D81, tonumber(items[2], 16)) | |
memory.writebyte(0x7D82, tonumber(items[3], 16)) | |
memory.writebyte(0x7D83, tonumber(items[4], 16)) | |
memory.writebyte(0x7D84, tonumber(items[5], 16)) | |
memory.writebyte(0x7D85, tonumber(items[6], 16)) | |
memory.writebyte(0x7D86, tonumber(items[7], 16)) | |
prev_inventory = inventory | |
end | |
emu.message('Toimii!') -- Print hello world to the screen on every frame | |
emu.frameadvance() -- This essentially tells FCEUX to keep running | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment