post.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. --The BIOS Post Screen !
  2. local DevMode = love.filesystem.getInfo("/devmode.txt") and true or false
  3. local events = require("Engine.events")
  4. local coreg = require("Engine.coreg")
  5. local Handled, Devkits = ... --It has been passed by the BIOS :)
  6. local BIOS = Handled.BIOS
  7. local GPU = Handled.GPU
  8. local CPU = Handled.CPU
  9. local fs = Handled.HDD
  10. local RAMKit = Devkits.RAM
  11. local _LIKO_Version, _LIKO_Old = BIOS.getVersion()
  12. local Mobile = CPU.isMobile()
  13. local sw,sh = GPU.screenSize()
  14. local enterSetup = false --Delete/Escape has been pressed, enter setup.
  15. local function wait(timeout, required) --Wait for 'delete' or 'escape' keypress.
  16. if DevMode and not required then return end
  17. local timer = timeout
  18. local setupkey = Mobile and "escape" or "delete"
  19. for event, a,b,c,d,e,f in CPU.pullEvent do
  20. if event == "update" then
  21. timer = timer - a
  22. if timer <= 0 then return end
  23. elseif event == "keypressed" then
  24. if a == setupkey then
  25. enterSetup = true
  26. GPU.rect(0,sh-8,sw,8,false, 7) GPU.color(0)
  27. GPU.print("Entering Setup... ",2,sh-7) GPU.color(7)
  28. GPU.flip()
  29. end
  30. end
  31. end
  32. end
  33. --POST Screen--
  34. GPU.clear() --Fill with black.
  35. GPU.color(7) --Set the color to white.
  36. --Load the bios logos.
  37. local lualogo = GPU.image(love.filesystem.read("/BIOS/lualogo.lk12"))
  38. local likologo = GPU.image(love.filesystem.read("/BIOS/likologo.lk12"))
  39. GPU.flip()
  40. wait(0.5)
  41. lualogo:draw(sw-lualogo:width()-6,5)
  42. likologo:draw(2,7)
  43. GPU.print("LIKO-12 - Fantasy Computer",15,6)
  44. GPU.print("Copyright (C) Rami Sabbagh",15,13)
  45. GPU.printCursor(0,3,0)
  46. GPU.print(string.format("NormBIOS Revision %d%d%d-016",_LVer.magor,_LVer.minor,_LVer.patch))
  47. if DevMode then GPU.color(6) GPU.print("# Devmode Enabled #") GPU.color(7) end
  48. GPU.print("")
  49. if not enterSetup then --If the user already pressed the key.
  50. if Mobile then
  51. GPU.print("Press BACK to enter setup",2,sh-7)
  52. else
  53. GPU.print("Press DEL to enter setup",2,sh-7)
  54. end
  55. end
  56. GPU.flip()
  57. wait(0.3)
  58. if CPU.isMobile() then
  59. GPU.print("Main CPU: Lua 5.1")
  60. else
  61. GPU.print("Main CPU: LuaJIT 5.1")
  62. end
  63. if ram then GPU.print("RAM: "..(ramkit.ramsize/1024).." Kilo-Bytes ("..ramkit.ramsize.." Bytes)") end
  64. GPU.print("GPU: "..sw.."x"..sh.." 4-Bit (16 Color Palette)")
  65. GPU.print("")
  66. GPU.print("Harddisks: ")
  67. GPU.flip()
  68. wait(0.3)
  69. Devkits["HDD"].calcUsage()
  70. for letter,drive in pairs(fs.drives()) do
  71. local size = math.floor((drive.size/1024) * 100)/100
  72. local usage = math.floor((drive.usage/1024) * 100)/100
  73. local percentage = math.floor(((usage*100)/size) * 100)/100
  74. GPU.print("Drive "..letter..": "..usage.."/"..size.." KB ("..percentage.."%)")
  75. end
  76. GPU.flip()
  77. wait(DevMode and 0.5 or 1.5,true)
  78. GPU.clear()
  79. GPU.printCursor(0,0,0)
  80. GPU.flip()
  81. wait(0.2)
  82. fs.drive("C") --Switch to the C drive.
  83. local function InstallOS(update)
  84. love.filesystem.load("BIOS/installer.lua")(Handled,"DiskOS",update)
  85. end
  86. if not fs.exists("/boot.lua") then _LIKO_Old = false; InstallOS()
  87. elseif DevMode or _LVer.tag == "DEV" then InstallOS(true) end
  88. --Update the operating system
  89. if _LIKO_Old then
  90. InstallOS()
  91. love.filesystem.write(".version",tostring(_LIKO_Version)) --Update the .version file
  92. end
  93. if DevMode and love.thread then
  94. local FThread = love.thread.newThread("/BIOS/filethread.lua") --File tracking thread
  95. FThread:start()
  96. events:register("love:reboot",function()
  97. local channel = love.thread.getChannel("BIOSFileThread")
  98. channel:push(true) --Shutdown the thread
  99. end)
  100. events:register("love:quit",function()
  101. local channel = love.thread.getChannel("BIOSFileThread")
  102. channel:push(true) --Shutdown the thread
  103. FThread:wait()
  104. end)
  105. end
  106. CPU.clearEStack() --Remove any events made while booting.
  107. if enterSetup then
  108. coroutine.yield("echo",Handled,Devkits)
  109. local setup = love.filesystem.load("/BIOS/setup.lua")
  110. local setupCo = coroutine.create(setup)
  111. coreg:setCoroutine(setupCo)
  112. else
  113. local bootchunk, err = fs.load("/boot.lua")
  114. if not bootchunk then error(err or "") end --Must be replaced with an error screen.
  115. local coglob = coreg:sandbox(bootchunk)
  116. local co = coroutine.create(bootchunk)
  117. local HandledAPIS = BIOS.HandledAPIS()
  118. coroutine.yield("echo",HandledAPIS)
  119. coreg:setCoroutine(co,coglob) --Switch to boot.lua coroutine
  120. end