stab = {} stab.stack = {} stab.pc = 1 stab.cins = 0 mem = {} t400 = require "t400" while true do io.write("*> ") i=io.read() it = {} for s in i:gmatch("%S+") do it[#it+1] = s end if it[1] == "quit" then break elseif it[1] == "peek" then print(mem[tonumber(it[2])]) elseif it[1] == "poke" then mem[tonumber(it[2])] = tonumber(it[3]) elseif it[1] == "push" then stab.stack[#stab.stack+1] = tonumber(it[2]) elseif it[1] == "dumpstack" then for k,v in ipairs(stab.stack) do print(k,v) end elseif it[1] == "ppc" then print(stab.pc) elseif it[1] == "spc" then stab.pc=tonumber(it[2]) elseif it[1] == "step" then local scount = tonumber(it[2]) or 1 for i = 1, scount do stab.cins = mem[stab.pc] stab,rw,addr,val=t400.run(stab) if rw == "halt" then break end if rw == "read" then stab.stack[#stab.stack+1] = mem[addr] elseif rw == "write" then mem[addr] = dat end end elseif it[1] == "load" then local f,e = io.open(it[2]) if f == nil then print("Error: "..e) else local n = tonumber(it[3]) or 0 local c = f:read("*a") f:close() for v in c:gmatch("%S+") do mem[n] = tonumber(v) or 0 n = n + 1 end end end end