Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --gOS by negamartin
- function runFree() --Will run directly from the BIOS, no fussy shell sandbox
- os.shutdown=sd;sd=nil;
- print=np;np=nil;
- local ok,err=pcall(function()
- --Visual stuff
- local realWidth;
- local realHeight;
- realWidth,realHeight=term.getSize();
- local xOffset=0;
- local yOffset=1;
- local fakeWidth=realWidth;
- local fakeHeight=realHeight-2;
- local isBlinking=false;
- local nativeSCP=term.setCursorPos;
- local nativeGCP=term.getCursorPos;
- local nativeClear=term.clear;
- local nativeCL=term.clearLine;
- local nativeBlink=term.setCursorBlink;
- term.setCursorPos=function(x,y)
- if math.floor(x)>fakeWidth or math.floor(y)>fakeHeight or math.floor(x)<1 or math.floor(y)<1 then
- error("Cursor out of bounds",2);
- end
- nativeSCP(x+xOffset,y+yOffset);
- end
- term.getCursorPos=function()
- local x;
- local y;
- x,y=nativeGCP();
- return x-xOffset,y-yOffset;
- end
- term.getSize=function()return fakeWidth,fakeHeight; end
- term.clear=function()
- local x;
- local y;
- x,y=nativeGCP();
- for i=1+yOffset,yOffset+fakeHeight do
- nativeSCP(1+xOffset,i);
- term.write(string.rep(" ",fakeWidth));
- end
- nativeSCP(x,y);
- end
- term.clearLine=function()
- local x;
- local y;
- x,y=nativeGCP();
- nativeSCP(1+xOffset,y);
- term.write(string.rep(" ",fakeWidth));
- nativeSCP(x,y);
- end
- term.setCursorBlink=function(blink)
- if type(blink)~="boolean" then error("Expected boolean",2); end
- isBlinking=blink;
- nativeBlink(blink);
- end
- --Important stuff
- function loadCoroutine(filename)
- local func,err=loadfile(filename);
- if func then
- return true,coroutine.create(func);
- else
- return false,err;
- end
- end
- local modem=peripheral.wrap("back");
- local running;
- function redrawOnScreen()
- local x;
- local y;
- x,y=nativeGCP();
- nativeSCP(1,1);
- term.setBackgroundColor(colors.black);
- nativeCL();
- term.setTextColor(colors.white);
- nativeSCP(realWidth-2,1);
- if modem then
- term.write("(o)");
- else
- term.write("(x)");
- end
- nativeSCP((realWidth/2)-(#"(HOME)"/2),realHeight);
- nativeCL();
- term.write("(HOME)");
- nativeSCP(x,y);
- end
- local runningX=1+xOffset;
- local runningY=1+yOffset;
- local runningBlink=false;
- function resumeRunning(ev)
- nativeSCP(runningX,runningY);
- nativeBlink(runningBlink);
- local ok;
- local err;
- ok,err=coroutine.resume(running,unpack(ev));
- if not ok then
- error(err);
- end
- runningBlink=isBlinking;
- runningX,runningY=nativeGCP();
- end
- local ok;
- local ev={};
- ok,running=loadCoroutine("launcher.lua");
- if not ok then
- error(running);
- end
- print("Launcher loaded");
- redrawOnScreen();
- while true do
- if ev[1]=="mouse_click" then
- if ev[3]>xOffset and ev[3]<=xOffset+fakeWidth and ev[4]>yOffset and ev[4]<=yOffset+fakeHeight then
- resumeRunning(ev);
- end
- redrawOnScreen();
- else
- resumeRunning(ev);
- end
- ev={os.pullEvent()};
- end
- end);
- if not ok then
- print(err);
- sleep(3);
- end
- end
- if not pocket then
- print("gOS is intended for pocket use");
- error();
- end
- if not term.isColor() then
- print("gOS only works on colored pocket computers");
- print("If you ARE making one, better waste some gold, right?");
- error();
- end
- --Check End
- local sd=os.shutdown;
- local np=print;
- term.clear();
- term.setCursorPos(1,1);
- print("Starting gOS...");
- local timer=os.startTimer(1);
- local start=true;
- while true do
- local ev={os.pullEvent()};
- if ev[1]=="timer" and ev[2]==timer then
- start=true;
- break;
- elseif ev[1]=="key" and ev[2]==keys.f12 then
- start=false;
- break;
- end
- end
- if start then
- print=function()end;
- getfenv(rednet.run).isOpen=error;
- os.shutdown=runFree;
- os.startTimer(0.2);
- os.queueEvent("modem_message");
- else
- print("Start Canceled");
- end
Advertisement
Add Comment
Please, Sign In to add comment