setup.lua 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. --BIOS Setup Screen
  2. local Handled, Devkits = ... --Handled is passed by BIOS POST
  3. --Engine parts
  4. local coreg = require("Engine.coreg")
  5. --Peripherals
  6. local BIOS = Handled.BIOS
  7. local GPU = Handled.GPU
  8. local CPU = Handled.CPU
  9. local fs = Handled.HDD
  10. local KB = Handled.Keyboard
  11. local TC = Handled.TC
  12. --Constants
  13. local sw,sh = GPU.screenSize()
  14. local tw,th = GPU.termSize()
  15. local fw,fh = GPU.fontSize()
  16. local checkboard = GPU.imagedata("LK12;GPUIMG;2x2;7007")
  17. local TMap = {"left","right","up","down","z","x","c"}
  18. --Setup Variables
  19. local events = {}
  20. local options = {} --Will be overrided later.
  21. local selectedOption = 1
  22. --Functions
  23. local function eventLoop(evlist)
  24. for event, a,b,c,d,e,f in CPU.pullEvent do
  25. if evlist[event] then
  26. if evlist[event](a,b,c,d,e,f) then break end
  27. end
  28. end
  29. end
  30. local function printBG(text,x,y,tc,bc)
  31. local bgw, bgh = #text*(fw+1)+1, fh+2
  32. GPU.rect(x-1,y-1,bgw,bgh,false,bc)
  33. GPU.color(tc)
  34. GPU.print(text,x,y)
  35. end
  36. local function printCenterBG(text,y,tc,bc)
  37. local txtw = #text*(fw+1)-1
  38. printBG(text,(sw-txtw)/2,y,tc,bc)
  39. end
  40. local function drawUI()
  41. GPU.clear(5) --Dark Gray
  42. --Top & Bottom Bar
  43. GPU.rect(0,0,sw,8,false,12)
  44. GPU.rect(0,sh-8,sw,8,false,12)
  45. GPU.patternFill(checkboard)
  46. GPU.rect(1,1,sw-2,6,false,1)
  47. GPU.rect(1,sh-7,sw-2,6,false,1)
  48. GPU.patternFill()
  49. printCenterBG("@=- BIOS SETUP V2.0 -=@",1,1,12)
  50. --Options
  51. for id, option in ipairs(options) do
  52. local txty = 14+(id-1)*(fh+3)
  53. local selected = (id == selectedOption)
  54. --Selection Rect
  55. GPU.rect(1,txty-1,sw-2,fh+2,false, selected and 6 or 5)
  56. GPU.color(selected and 7 or 6)
  57. GPU.print(option[1],2,txty)
  58. end
  59. end
  60. --Touch to Keyboard
  61. function events.touchcontrol(down,tid)
  62. CPU.triggerEvent(down and "keypressed" or "keyreleased",TMap[tid],TMap[tid],false)
  63. end
  64. --Keyboard Navigation
  65. function events.keypressed(key,scancode,isrepeat)
  66. if key == "up" then
  67. if selectedOption == 1 then selectedOption = #options+1 end
  68. selectedOption = selectedOption - 1
  69. if options[selectedOption][1] == "" then
  70. selectedOption = selectedOption - 1
  71. end
  72. drawUI()
  73. elseif key == "down" then
  74. if selectedOption == #options then selectedOption = 0 end
  75. selectedOption = selectedOption + 1
  76. if options[selectedOption][1] == "" then
  77. selectedOption = selectedOption + 1
  78. end
  79. drawUI()
  80. elseif key == "z" or key == "return" then
  81. if isrepeat then return end
  82. return options[selectedOption][2]()
  83. end
  84. end
  85. local function showAppdata()
  86. local ev = {}
  87. ev.touchcontrol = events.touchcontrol
  88. local function draw()
  89. GPU.clear(5) --Dark Gray
  90. --Top & Bottom Bar
  91. GPU.rect(0,0,sw,8,false,12)
  92. GPU.rect(0,sh-8,sw,8,false,12)
  93. GPU.patternFill(checkboard)
  94. GPU.rect(1,1,sw-2,6,false,1)
  95. GPU.rect(1,sh-7,sw-2,6,false,1)
  96. GPU.patternFill()
  97. printCenterBG("@=- APPData Path -=@",1,1,12)
  98. --Appdata path
  99. GPU.color(7)
  100. GPU.print(CPU.getSaveDirectory().."/",0,sh*0.45-fh/2,sw,"center")
  101. printCenterBG("Press the green button to return back",sh*0.66,6,5)
  102. end
  103. function ev.keypressed(key,scancode,isrepeat)
  104. if key == "z" then
  105. return true
  106. end
  107. end
  108. draw()
  109. eventLoop(ev)
  110. drawUI()
  111. end
  112. local function showGPUInfo()
  113. local ev = {}
  114. local name,ver,ven,dev = love.graphics.getRendererInfo()
  115. local encoded = string.format("Renderer Name: %s\n\nVersion: %s\n\nVendor: %s\n\nDevice: %s",name,ver,ven,dev)
  116. ev.touchcontrol = events.touchcontrol
  117. local function draw()
  118. GPU.clear(5) --Dark Gray
  119. --Top & Bottom Bar
  120. GPU.rect(0,0,sw,8,false,12)
  121. GPU.rect(0,sh-8,sw,8,false,12)
  122. GPU.patternFill(checkboard)
  123. GPU.rect(1,1,sw-2,6,false,1)
  124. GPU.rect(1,sh-7,sw-2,6,false,1)
  125. GPU.patternFill()
  126. printCenterBG("@=- GPU Information -=@",1,1,12)
  127. --Appdata path
  128. GPU.color(7)
  129. GPU.print(encoded,0,sh*0.26-fh/2,sw,"center")
  130. if CPU.isMobile() then
  131. printCenterBG("Press the green button to go back",sh*0.75,6,5)
  132. else
  133. printCenterBG("Press Z to go back",sh*0.75,6,5)
  134. end
  135. end
  136. function ev.keypressed(key,scancode,isrepeat)
  137. if key == "z" then
  138. return true
  139. end
  140. end
  141. draw()
  142. eventLoop(ev)
  143. drawUI()
  144. end
  145. --BIOS Options
  146. options = {
  147. {"- Boot from drive D", function()
  148. if not fs.exists("D:/boot.lua") then
  149. GPU._systemMessage("D:/boot.lua doesn't exist !",3,2,9)
  150. return
  151. end
  152. TC.setInput(false)
  153. GPU.clear(0) GPU.color(7)
  154. GPU.printCursor(0,0,0)
  155. CPU.clearEStack() --Remove any events made.
  156. fs.drive("D")
  157. local bootchunk, err = fs.load("/boot.lua")
  158. if not bootchunk then error(err or "") end --Must be replaced with an error screen.
  159. local coglob = coreg:sandbox(bootchunk)
  160. local co = coroutine.create(bootchunk)
  161. local HandledAPIS = BIOS.HandledAPIS()
  162. coroutine.yield("echo",HandledAPIS)
  163. coreg:setCoroutine(co,coglob) --Switch to boot.lua coroutine
  164. return true
  165. end},
  166. {"- Boot PoorOS", function()
  167. TC.setInput(false)
  168. GPU.clear(0) GPU.color(7)
  169. GPU.printCursor(0,0,0)
  170. CPU.clearEStack() --Remove any events made.
  171. fs.drive("C")
  172. local bootchunk, err = love.filesystem.load("/OS/PoorOS/boot.lua")
  173. if not bootchunk then error(err or "") end --Must be replaced with an error screen.
  174. local coglob = coreg:sandbox(bootchunk)
  175. local co = coroutine.create(bootchunk)
  176. local HandledAPIS = BIOS.HandledAPIS()
  177. coroutine.yield("echo",HandledAPIS)
  178. coreg:setCoroutine(co,coglob) --Switch to boot.lua coroutine
  179. return true
  180. end},
  181. {"- Show GPU Information",function()
  182. showGPUInfo()
  183. end},
  184. {"- Open Appdata Folder", function()
  185. if CPU.isMobile() then
  186. showAppdata()
  187. else
  188. CPU.openAppData("/")
  189. end
  190. end},
  191. {"- Toggle DEVMODE", function()
  192. if love.filesystem.getInfo("devmode.txt","file") then
  193. love.filesystem.remove("devmode.txt")
  194. GPU._systemMessage("Disabled DEVMODE",1,1,12)
  195. else
  196. love.filesystem.write("devmode.txt","")
  197. GPU._systemMessage("Enabled DEVMODE",1,1,12)
  198. end
  199. end},
  200. {"",function() end}, --Separetor
  201. {"- Install DiskOS", function()
  202. love.filesystem.load("BIOS/installer.lua")(Handled,"DiskOS",false)
  203. drawUI()
  204. GPU._systemMessage("Installed Successfully",1,1,12)
  205. end},
  206. {"- Install PoorOS", function()
  207. love.filesystem.load("BIOS/installer.lua")(Handled,"PoorOS",false)
  208. drawUI()
  209. GPU._systemMessage("Installed Successfully",1,1,12)
  210. end},
  211. {"",function() end}, --Separetor
  212. {"- Wipe Drive C", function()
  213. GPU._systemMessage("Wiping Drive C...",100)
  214. GPU.flip()
  215. fs.delete("C:/")
  216. GPU._systemMessage("Wiping Complete",1,1,12)
  217. GPU.flip()
  218. end},
  219. {"- Wipe Drive D", function()
  220. GPU._systemMessage("Wiping Drive D...",100)
  221. GPU.flip()
  222. fs.delete("D:/")
  223. GPU._systemMessage("Wiping Complete",1,1,12)
  224. GPU.flip()
  225. end},
  226. {"",function() end}, --Separetor
  227. {"- Reboot", function()
  228. CPU.reboot()
  229. end}
  230. }
  231. if CPU.isMobile() then
  232. options[4][1] = "- Show Appdata Folder"
  233. end
  234. --Enter the UI
  235. drawUI()
  236. TC.setInput(true)
  237. eventLoop(events)