--[[ Run this script to actually use the machine. It runs the simulation with proper timing and sends keyboard inputs to the machine. The keyboard inputs are on pin D (13). When you read from it using an IN instruction, it returns 0 if no keys are being pressed, else the keycode of the currently pressed key. Only 1 key can be considered "pressed" at a time. Right now, only the arrow keys are supported. Left = -1 Up = -2 Right = -3 Down = -4 ]] local g = golly() local speed = g.getstring("Enter speed, as an exponent. The default, 22, is usually good.", "22", "Enter speed.") speed = tonumber(speed) if not speed then error("Invalid speed.") end speed = math.floor(speed) if speed < 0 then error("Speed exponent cannot be negative.") end local lwss = g.parse("o2bo$4bo$o3bo$b4o!") function writeToEXTPER(word) --g.warn("yeah") local x, y = -241511, -202689 x = x + 32 * 3 -- clear any previous data, just in case function was called multiple -- times in same frame g.select{x, y + 128, 997, 4} g.clear(0) for i=0, 31 do g.putcells(lwss, x + i * 32, y) if word & (1 << (31 - i)) == 0 then g.putcells(lwss, x + i * 32, y + 128) end end g.select{} end -- advance by 26*64 to align display g.run(26*64) --s = "" while true do g.update() g.run(2^speed) g.sleep(50) --s = s .. "|||" repeat local e = g.getevent() --s = s .. "\n" .. e if e == "key left none" then writeToEXTPER(-1) elseif e == "key up none" then writeToEXTPER(-2) elseif e == "key right none" then writeToEXTPER(-3) elseif e == "key down none" then writeToEXTPER(-4) --g.warn(s) elseif e == "kup left" then writeToEXTPER(0) elseif e == "kup up" then writeToEXTPER(0) elseif e == "kup right" then writeToEXTPER(0) elseif e == "kup down" then writeToEXTPER(0) else g.doevent(e) end until e == "" end