Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --syscall init
- syscall = {}
- local syscalls = {}
- function syscall.register(name, callback)
- syscalls[name] = callback
- end
- function syscall.execute(name, ...)
- local call = syscalls[name]
- if call then
- return call(...)
- else
- error(name)
- end
- end
- --screen init
- local gpu, screen = component.list("gpu")(), component.list("screen")()
- local w, h
- if gpu and screen then
- component.invoke(gpu, "bind", screen)
- w, h = component.invoke(gpu, "getResolution")
- component.invoke(gpu, "setResolution", w, h)
- component.invoke(gpu, "setBackground", 0x000000)
- component.invoke(gpu, "setForeground", 0xFFFFFF)
- component.invoke(gpu, "fill", 1, 1, w, h, " ")
- end
- y = 1
- local log = false
- --syscall term stuff
- syscall.register("stdio_clear",function() local y = 1 component.invoke(gpu, "fill", 1, 1, w, h, " ") end)
- syscall.register("stdout_write",function(msg) --register syscall for output
- msg = tostring(msg)
- if gpu and screen then
- component.invoke(gpu, "set", 1, y, msg)
- if y == h then
- component.invoke(gpu, "copy", 1, 2, w, h - 1, 0, -1)
- component.invoke(gpu, "fill", 1, h, w, 1, " ")
- else
- y = y + 1
- end
- end
- end)
- syscall.register('stdin_read', function(rc)
- local sx, sy = 1, y
- local s = ""
- local gpu = component.proxy(component.list("gpu")())
- local mx, my = gpu.getResolution()
- local function rerender()
- local blanks = ""
- for i = sx+1,mx do
- blanks = blanks.." "
- end
- gpu.set(sx,sy,blanks)
- if rc == nil then
- gpu.set(sx,sy,s.."_")
- else
- local rs = ""
- if s:len() > 0 then
- for i = 1,s:len() do
- rs = rs..rc
- end
- end
- gpu.set(sx,sy,rs.."_")
- end
- end
- rerender()
- repeat
- evtype, _, keya, keyb = computer.pullSignal()
- if evtype == "key_down" then
- if keya > 31 then
- s=s..string.char(keya)
- elseif keya == 8 and keyb == 14 then
- s=s:sub(1,s:len()-1)
- end
- rerender()
- end
- until evtype == "key_down" and keya == 13 and keyb == 28
- if y == my then
- gpu.copy(1, 2, mx, my - 1, 0, -1)
- gpu.fill(1, my, mx, 1, " ")
- else
- y = y + 1
- end
- return s
- end)
- --filesystem code
- local fs={}
- fs.drive_map={}
- fs.activeDrive="A"
- syscall.register("fs_drives",function() return fs.drive_map,fs.activeDrive end)
- syscall.register("fs_mount",function(proxy,index) fs.drive_map[index]=proxy end)
- syscall.execute("fs_mount",component.proxy(computer.getBootAddress()),"A")
- syscall.execute("fs_mount",component.proxy(computer.tmpAddress()),"X")
- syscall.register("fs_proxy",function(index) return fs.drive_map.index end)
- syscall.register("fs_invoke",function(method,...) return fs.drive_map[fs.activeDrive][method](...) end) --wtf?
- syscall.register("fs_get_drive",function() return fs.activeDrive end)
- syscall.register("fs_set_drive",function(index) fs.activeDrive=index end)
- syscall.register("fs_open",function(path,mode) return syscall.execute("fs_invoke","open",path,mode or "r") end)
- syscall.register("fs_write",function(handle, data) return syscall.execute("fs_invoke","write",handle,data) end)
- syscall.register("fs_read",function(handle, length) return syscall.execute("fs_invoke","read",handle,length or math.huge) end)
- syscall.register("fs_close",function(handle) return syscall.execute("fs_invoke","close",handle) end)
- syscall.register("fs_exists", function(path) return syscall.execute("fs_invoke","exists",path) end)
- syscall.register("fs_is_dir", function(path) return syscall.execute("fs_invoke","isDirectory",path) end)
- syscall.register("fs_mkdir", function(path) return syscall.execute("fs_invoke","makeDirectory",path) end)
- syscall.register("fs_list", function(path) return syscall.execute("fs_invoke","list",path or "/") end)
- syscall.register("fs_remove", function(path) return syscall.execute("fs_invoke","remove",path) end)
- syscall.register("fs_move", function(path1, path2) return syscall.execute("fs_invoke","rename", path1, path2) end)
- --component code -- list, type, proxy, doc, methods
- syscall.register("component_list", function(filter) return component.list(filter) end)
- syscall.register("component_type", function(addr) return component.type(addr) end)
- syscall.register("component_proxy", function(addr) return component.proxy(addr) end)
- syscall.register("component_methods", function(addr) return component.methods(addr) end)
- --computer?
- syscall.register("beep",function(freq) computer.beep(freq) end) -- most important part.
- --derp loop
- syscall.execute("fs_mount",component.proxy(computer.getBootAddress()),"A")
- syscall.execute("fs_mount",component.proxy(computer.tmpAddress()),"X")
- local sout=tostring(math.floor(computer.totalMemory()/1024)).."k total, "..tostring(math.floor(computer.freeMemory()/1024)).."k free, "..tostring(math.floor((computer.totalMemory()-computer.freeMemory())/1024)).."k used"
- if syscall.execute("fs_exists","postinit.lua") then
- local f=syscall.execute("fs_open","postinit.lua")
- syscall.execute("stdout_write",tostring(f))
- local c = syscall.execute("fs_read",f)
- syscall.execute("stdout_write",c)
- local functionLoaded = load(c)
- syscall.execute("fs_close",f)
- syscall.execute("stdout_write",tostring(pcall(functionLoaded())))
- else
- repeat
- syscall.execute("stdout_write",sout)
- sout=syscall.execute("stdin_read")
- if sout=="load" then
- for k,v in pairs(syscall.execute("fs_list","/")) do
- syscall.execute("stdout_write",tostring(v))
- end
- local f=syscall.execute("fs_open",syscall.execute("stdin_read"))
- syscall.execute("stdout_write",tostring(f))
- local c = syscall.execute("fs_read",f)
- syscall.execute("stdout_write",c)
- local functionLoaded = load(c)
- syscall.execute("fs_close",f)
- syscall.execute("stdout_write",tostring(pcall(functionLoaded())))
- end
- until sout == "kill"
- end
- computer.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement