Advertisement
PolskiWisnia

Bootloader

Feb 28th, 2020 (edited)
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.34 KB | None | 0 0
  1. local function s(...) return sleep(...) end
  2. local function w(...) return write(...) end
  3. local function p(...) return print(...) end
  4. local function tw(...) return term.write(...) end
  5. local function scp(...) return term.setCursorPos(...) end
  6. local function sbc(...) return term.setBackgroundColor(...) end
  7. local function stc(...) return term.setTextColor(...) end
  8. local function tc(...) return term.clear(...) end
  9. local function tcl(...) return term.clearLine(...) end
  10. local function r(...) return shell.run(...) end
  11. local function sp(...) return textutils.slowPrint(...) end
  12. local function sw(...) return textutils.slowWrite(...) end
  13. local function fse(...) return fs.exists(...) end
  14. local function pul(...) return paintutils.loadImage(...) end
  15. local function pud(...) return paintutils.drawImage(...) end
  16. local function pfb(...) return paintutils.drawFilledBox(...) end
  17. local function su(...) return os.shutdown(...) end
  18. local function re(...) return os.reboot(...) end
  19. local function pdp(...) return paintutils.drawPixel(...) end
  20. local w, h = term.getSize()
  21.  
  22.  
  23. function advbios()
  24. while true do
  25. sbc(colors.lightGray)
  26. tc()
  27. sbc(colors.lightGray)
  28. pfb(1,1,w,1, colors.gray)
  29. pfb(1,h,w,h, colors.gray)
  30. ac = w/2
  31. stc(colors.white)
  32. scp(ac-10,1)
  33. p("Microcraft BIOS")
  34. pfb(1,2,w,2,colors.black)
  35. scp(1,2)
  36. sbc(colors.black)
  37. stc(colors.white)
  38. p("Main")
  39. scp(7,2)
  40. p("Boot")
  41. sbc(colors.white)
  42. stc(colors.black)
  43. scp(13,2)
  44. p("Advanced")
  45. scp(1,4)
  46. sbc(colors.lightGray)
  47. stc(colors.white)
  48. miejsce = fs.getFreeSpace("/")
  49. miejscekb = miejsce/1024
  50. p("Microcraft Bootloader")
  51. local startupBoot = settings.get("shell.allow_startup", "not set")
  52. local hidden = settings.get("list.show_hidden", "not set")
  53. local multishell = settings.get("bios.use_multishell", "not set")
  54. p("Set defaults")
  55. p("1. Show hidden files: ", hidden)
  56. p("2. Use multishell: ", multishell)
  57. scp(1,h)
  58. sbc(colors.gray)
  59. stc(colors.white)
  60. write("Press HERE to reboot.")
  61. local event, button, x, y = os.pullEvent("mouse_click")
  62. if x>0 and x<7 and y == 2 then bios() end
  63. if x>6 and x<12 and y == 2 then bootbios() end
  64. if x>0 and x<w and y == h then re() end
  65.  
  66. if x>0 and x<30 and y == 5 then
  67.  settings.set("shell.allow_startup", true)
  68.  settings.set("list.show_hidden", false)
  69.  settings.set("bios.use_multishell", true)
  70.  settings.save(".settings")
  71. end
  72.  
  73. if x>0 and x<30 and y == 6 and hidden == "not set" or x>0 and x<30 and y == 6 and hidden == false then  
  74. settings.set("list.show_hidden", true)
  75. settings.save(".settings")
  76. end
  77. if x>0 and x<30 and y == 6 and hidden == "not set" or x>0 and x<30 and y == 6 and hidden == true then  
  78. settings.set("list.show_hidden", false)
  79. settings.save(".settings")
  80. end
  81.  
  82. if x>0 and x<30 and y == 7 and multishell == "not set" or x>0 and x<30 and y == 7 and multishell == false then  
  83. settings.set("bios.use_multishell", true)
  84. settings.save(".settings")
  85. end
  86. if x>0 and x<30 and y == 7 and multishell == "not set" or x>0 and x<30 and y == 7 and multishell == true then  
  87. settings.set("bios.use_multishell", false)
  88. settings.save(".settings")
  89. end
  90.  
  91. end
  92. end
  93.  
  94. function bios()
  95. while true do
  96. sbc(colors.lightGray)
  97. tc()
  98. sbc(colors.lightGray)
  99. pfb(1,1,w,1, colors.gray)
  100. pfb(1,h,w,h, colors.gray)
  101. ac = w/2
  102. stc(colors.white)
  103. scp(ac-10,1)
  104. p("Microcraft BIOS")
  105. pfb(1,2,w,2,colors.black)
  106. scp(1,2)
  107. sbc(colors.white)
  108. stc(colors.black)
  109. p("Main")
  110. sbc(colors.black)
  111. stc(colors.white)
  112. scp(7,2)
  113. p("Boot")
  114. scp(13,2)
  115. p("Advanced")
  116. scp(1,4)
  117. sbc(colors.lightGray)
  118. stc(colors.white)
  119. miejsce = fs.getFreeSpace("/")
  120. miejscekb = math.ceil(miejsce/1024)
  121. p("Microcraft Bootloader")
  122. p("BIOS version: 0.2A")
  123. p("HDD Free space: ", miejscekb, "KB")
  124. p("CraftOS version: ", os.version())
  125. local nextui = fse("/os/.next")
  126. local minecore = fse("/os/.menu")
  127. local hydra = fse("/hydra/.next")
  128. p("")
  129. p("")
  130. p("Installed operating systems:")
  131. p("NextUI: ", nextui)
  132. p("MineCore: ", minecore)
  133. p("HydraUI: ", hydra)
  134. scp(1,h)
  135. sbc(colors.gray)
  136. stc(colors.white)
  137. write("Press HERE to reboot.")
  138. local event, button, x, y = os.pullEvent("mouse_click")
  139. if x>6 and x<12 and y == 2 then bootbios() end
  140. if x>12 and x<24 and y == 2 then advbios() end
  141. if x>0 and x<w and y == h then re() end
  142. end
  143. end
  144.  
  145.  
  146.  
  147.  
  148. function bootbios()
  149. while true do
  150. sbc(colors.lightGray)
  151. tc()
  152. sbc(colors.lightGray)
  153. pfb(1,1,w,1, colors.gray)
  154. pfb(1,h,w,h, colors.gray)
  155. ac = w/2
  156. stc(colors.white)
  157. scp(ac-10,1)
  158. p("Microcraft BIOS")
  159. pfb(1,2,w,2,colors.black)
  160. sbc(colors.white)
  161. stc(colors.black)
  162. scp(7,2)
  163. p("Boot")
  164. scp(1,2)
  165. sbc(colors.black)
  166. stc(colors.white)
  167. p("Main")
  168. scp(13,2)
  169. p("Advanced")
  170. scp(1,4)
  171. sbc(colors.lightGray)
  172. stc(colors.white)
  173. p("Microcraft Bootloader")
  174. local startupBoot = settings.get("shell.allow_startup", "not set")
  175. local bootFromDisk = settings.get("shell.allow_disk_startup", "not set")
  176. p("Set defaults")
  177. p("1. Floppy Disk startup: ", bootFromDisk)
  178. p("2. Startup from HDD: ", startupBoot)
  179. scp(1,h)
  180. sbc(colors.gray)
  181. stc(colors.white)
  182. write("Press HERE to reboot.")
  183. local event, click, x, y = os.pullEvent("mouse_click")
  184. if x>0 and x<7 and y == 2 then bios() end
  185. if x>12 and x<24 and y == 2 then advbios() end
  186.  
  187. if x>0 and x<30 and y == 5 then
  188.  settings.set("shell.allow_disk_startup", false)
  189.  settings.set("shell.allow_startup", true)
  190.  settings.save(".settings")
  191. end
  192.  
  193. if x>0 and x<25 and y == 6 and bootFromDisk == "not set" or x>0 and x<30 and y == 6 and bootFromDisk == false then  
  194. settings.set("shell.allow_disk_startup", true)
  195. settings.save(".settings")
  196. end
  197. if x>0 and x<25 and y == 6 and bootFromDisk == "not set" or x>0 and x<30 and y == 6 and bootFromDisk == true then  
  198. settings.set("shell.allow_disk_startup", false)
  199. settings.save(".settings")
  200. end
  201.  
  202.  
  203. if x>0 and x<30 and y == 7 and startupBoot == "not set" or x>0 and x<30 and y == 7 and startupBoot == false then    
  204. settings.set("shell.allow_startup", true)
  205. settings.save(".settings")
  206. end
  207. if x>0 and x<30 and y == 7 and startupBoot == "not set" or x>0 and x<30 and y == 7 and startupBoot == true then    
  208. settings.set("shell.allow_startup", false)
  209. settings.save(".settings")
  210. end
  211.  
  212. if x>0 and x<w and y == h then re() end
  213. end
  214. end
  215.  
  216.  
  217.  
  218. function boot()
  219. tc()
  220. pfb(1, 1, w, h, colors.gray)
  221. stc(colors.white)
  222. if fse("/disk/startup") then dysk = 1 end
  223. scp(1,1)
  224. p("Microcraft")
  225. scp(1,4)
  226. p("2021 (c) Microcraft")
  227. p("Bootloader version: Beta 3A")
  228. s(1)
  229. sp("Searching for bootable media...")
  230. s(1)
  231. while true do
  232. tc()
  233. scp(1,1)
  234. p("Choose operating system to boot")
  235. if fse("/os/.next") then
  236. pfb(3, 4, 13, 6, colors.orange)
  237. scp(3,5)
  238. stc(colors.white)
  239. p("NextUI")
  240. end
  241. if fse("/os/.menu") then
  242. pfb(27, 4, 37, 6, colors.cyan)
  243. scp(27,5)
  244. stc(colors.white)
  245. p("MineCore")
  246. end
  247. pfb(15, 4, 25, 6, colors.green)
  248. scp(15,5)
  249. stc(colors.white)
  250. p("BIOS")
  251. if fse("/hydra/.next") then
  252. pfb(39, 4, 49, 6, colors.red)
  253. scp(39,5)
  254. stc(colors.white)
  255. p("HydraUI")
  256. end
  257.  
  258. scp(1,h)
  259. write("CraftOS")
  260.  
  261. if fse("/disk/startup") then dysk = 1 end
  262. if dysk == 1 then
  263. pfb(3, 8, 13, 10, colors.purple)
  264. scp(3,9)
  265. stc(colors.white)
  266. p("Boot disk")
  267. end
  268. sbc(colors.black)
  269. local event, click, x, y = os.pullEvent("mouse_click")
  270. if x>0 and x<w and y == h then scp(1,1) sbc(colors.black) tc() sbc(colors.black) break end
  271. if x>2 and x<14 and y>3 and y<7 and fse("/os/.next") then r("/os/.next") break end
  272. if x>14 and x<26 and y>3 and y<7 then bios() end
  273. if x>2 and x<14 and y>7 and x<11 and fse("/disk/startup") then r("/disk/startup") break end
  274. end
  275. end
  276.  
  277.  
  278.  
  279. boot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement