· 5 years ago · Dec 22, 2020, 02:34 AM
1-- MegaB**t
2-- version 0.0.1.
3--
4-- (this makes)
5-- the bootloader,
6-- reports this version
7-- and will report wrong if
8-- changed
9--
10-- these comments are not to help you understand what this code
11-- means its supposed to make it easier for me to know where i should put stuff
12-- and what i currently have done,
13-- also to make sure i dont make mistakes while typing.
14
15screenWidth, screenHeight = term.getSize() -- get current screen size
16
17screenArray = {} -- initilize screenArray
18biosApis = {
19 "os/b365/apis/test"
20} -- initilize biosApis
21
22blReportVersion = true -- if false at bootup boot loader version
23 -- will not say the version
24 -- and only say unknown.
25blVersion = "0.0.1" -- version string.
26
27local read = {""}
28
29local function getRunningPath()
30 local program = shell.getRunningProgram()
31 local programName = fs.getName(program)
32 return program:sub(1,#program - #programName)
33end
34
35function loadBiosFuncs()
36 for i=1,#biosApis do
37 clear()
38 term.setCursorPos(1, 1)
39 print("loading api from path " ..fs.combine(getRunningPath(), biosApis[i]))
40 os.loadAPI(fs.combine(getRunningPath(), biosApis[i] ..".lua"))
41 local api = require(biosApis[i])
42 --api.load()
43 print("BiosAPI " ..biosApis[i] .. " has been loaded")
44 end
45end
46
47function setupScreenArray()
48 for h=1,screenHeight do
49 screenArray[h] = {}
50 for w=1,screenWidth do
51 screenArray[h][w] = colors.cyan
52 end
53 end
54end
55
56function clear()
57 term.setBackgroundColor(colors.black) -- reset background color.
58 term.setTextColor(colors.white) -- reset text color.
59
60 term.setCursorPos(0, 0) -- move cursor of screen
61 term.clear() -- clears terminal
62
63 paintutils.drawImage(screenArray, 1, 1) -- draw screen array to screen
64
65 term.setCursorPos(0, 0) -- move cursor to a pos that makes it invisable
66 -- so then it doesn't show the blinking line.
67end
68
69function Read(event, key, isHeld)
70 term.setCursorPos(1, 1)
71 write(keys.getName(key))
72 print(isHeld and " is being held." or " was pressed.")
73 if key == nil then else
74 if keys.getName(key) == "space" then
75 read[#read + 1] = " "
76 elseif keys.getName(key) == "backspace" then
77 table.remove(read)
78 elseif keys.getName(key) == "enter" then
79 return read, true
80 else
81 read[#read + 1] = keys.getName(key)
82 end
83
84 end
85 term.setCursorPos(0, 0)
86 return read, false
87end
88
89function eventKey(event,key,isHeld)
90 term.setCursorPos(1, 1)
91 write( keys.getName( key ) )
92 print( isHeld and " is being held." or " was pressed." )
93 term.setCursorPos(0, 0)
94end
95
96loadBiosFuncs()
97
98setupScreenArray()
99clear()
100
101while true do
102 clear()
103
104 local event, key, isHeld = os.pullEvent("key")
105
106 local test, isEnter = Read(event,key,isHeld)
107 term.setCursorPos(1, 3)
108 for i=1,#test do
109 write(test[i])
110 end
111 if isEnter == true then
112 local text = ""
113 for i=1,#test do
114 text = text ..test[i]
115 end
116 if text == "exit" then
117 clear()
118 term.setCursorPos(1,1)
119 error("manual overide : " .."exit" .." command")
120 end
121 end
122 term.setCursorPos(0, 0)
123 eventKey(event,key,isHeld)
124 sleep(0.1)
125end