Advertisement
Guest User

boot.lua

a guest
Dec 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.86 KB | None | 0 0
  1. -- called from /init.lua
  2. local raw_loadfile = ...
  3.  
  4. _G._OSVERSION = "DevilPuppyOS <3"
  5.  
  6. local component = component
  7. local computer = computer
  8. local unicode = unicode
  9. local process = process
  10. local loading = 1
  11. -- Runlevel information.
  12. local runlevel, shutdown = "S", computer.shutdown
  13. computer.runlevel = function() return runlevel end
  14. computer.shutdown = function(reboot)
  15.   runlevel = reboot and 6 or 0
  16.   if os.sleep then
  17.     computer.pushSignal("shutdown")
  18.     os.sleep(0.1) -- Allow shutdown processing.
  19.   end
  20.   shutdown(reboot)
  21. end
  22.  
  23. local screen = component.list('screen', true)()
  24. for address in component.list('screen', true) do
  25.   if #component.invoke(address, 'getKeyboards') > 0 then
  26.     screen = address
  27.     break
  28.   end
  29. end
  30.  
  31. _G.boot_screen = screen
  32.  
  33. -- Report boot progress if possible.
  34. local gpu = component.list("gpu", true)()
  35. local w, h
  36. if gpu and screen then
  37.   component.invoke(gpu, "bind", screen)
  38.   w, h = component.invoke(gpu, "maxResolution")
  39.   component.invoke(gpu, "setResolution", w, h)
  40.   component.invoke(gpu, "setBackground", 0xbdbdbd)
  41.   component.invoke(gpu, "setForeground", 0x474747)
  42.   component.invoke(gpu, "fill", 1, 1, w, h, " ")
  43. end
  44. local y = 1
  45.  
  46. local function memory()
  47.   free = computer.freeMemory()
  48.     total = computer.totalMemory()
  49.     mad = "RAM: " .. free/1000 .. "kb/" .. total/1000 .. "kb"
  50.     component.invoke(gpu, "set", w-string.len(mad),1,mad)
  51. end
  52.  
  53. local function status(msg)
  54. memory()
  55.   if gpu and screen then
  56.     component.invoke(gpu, "setBackground", 0xbdbdbd)
  57.     component.invoke(gpu, "fill", 1, h/2+2, w, 1, " ")
  58.     component.invoke(gpu, "setBackground", 0x757575)
  59.     component.invoke(gpu, "fill", w/2-25, h/2, loading, 1, " ")
  60.     component.invoke(gpu, "setBackground", 0xbdbdbd)
  61.     component.invoke(gpu, "setForeground", 0x474747)
  62.     component.invoke(gpu, "set", w/2-math.floor(string.len(msg)/2), h/2+2, msg)
  63.     if y == h then
  64.       -- component.invoke(gpu, "copy", 1, 2, w, h - 1, 0, -1)
  65.       -- component.invoke(gpu, "fill", 1, h, w, 1, " ")
  66.     else
  67.       y = y + 1
  68.     end
  69.   end
  70.  memory()
  71. end
  72.  
  73.  
  74.  
  75. loading = 5
  76. status("Запускаем " .. _OSVERSION)
  77.  
  78. -- Custom low-level dofile implementation reading from our ROM.
  79. local loadfile = function(file)
  80.   loading = loading + 1
  81.   status("Загружаю >" .. file .. "...")
  82.   return raw_loadfile(file)
  83. end
  84.  
  85. local function dofile(file)
  86.   local program, reason = loadfile(file)
  87.   if program then
  88.     local result = table.pack(pcall(program))
  89.     if result[1] then
  90.       return table.unpack(result, 2, result.n)
  91.     else
  92.       error(result[2])
  93.     end
  94.   else
  95.     error(reason)
  96.   end
  97. end
  98.  
  99. status("Инициализация пакетных менеджеров...")
  100.  
  101. -- Load file system related libraries we need to load other stuff moree
  102. -- comfortably. This is basically wrapper stuff for the file streams
  103. -- provided by the filesystem components.
  104. local package = dofile("/lib/package.lua")
  105.  
  106. do
  107.   -- Unclutter global namespace now that we have the package module and a filesystem
  108.   _G.component = nil
  109.   _G.computer = nil
  110.   _G.process = nil
  111.   _G.unicode = nil
  112.   _G.process = nil
  113.   -- Inject the package modules into the global namespace, as in Lua.
  114.   _G.package = package
  115.  
  116.   -- Initialize the package module with some of our own APIs.
  117.   package.loaded.component = component
  118.   package.loaded.computer = computer
  119.   package.loaded.unicode = unicode
  120.   package.loaded.process = process
  121.   package.preload["buffer"] = loadfile("/lib/buffer.lua")
  122.   package.preload["filesystem"] = loadfile("/lib/filesystem.lua")
  123.  
  124.   -- Inject the io modules
  125.   _G.io = loadfile("/lib/io.lua")()
  126.  
  127.   --mark modules for delay loaded api
  128.   package.delayed["text"] = true
  129.   package.delayed["sh"] = true
  130.   package.delayed["transforms"] = true
  131.   package.delayed["term"] = true
  132. end
  133.  
  134. status("Запуск файловой системы...")
  135.  
  136. -- Mount the ROM and temporary file systems to allow working on the file
  137. -- system module from this point on.
  138. require("filesystem").mount(computer.getBootAddress(), "/")
  139. package.preload={}
  140.  
  141. status("Запуск скриптов загрузки...")
  142.  
  143. -- Run library startup scripts. These mostly initialize event handlers.
  144. local function rom_invoke(method, ...)
  145.   return component.invoke(computer.getBootAddress(), method, ...)
  146. end
  147.  
  148. local scripts = {}
  149. for _, file in ipairs(rom_invoke("list", "boot")) do
  150.   local path = "boot/" .. file
  151.   if not rom_invoke("isDirectory", path) then
  152.     table.insert(scripts, path)
  153.   end
  154. end
  155. table.sort(scripts)
  156. for i = 1, #scripts do
  157.   dofile(scripts[i])
  158. end
  159.  
  160. status("Инициализация компонентов....")
  161.  
  162. for c, t in component.list() do
  163. loading = loading + 1
  164.   computer.pushSignal("component_added", c, t)
  165. end
  166.  
  167. loading = 45
  168. status("                Инициализация системы...")
  169. loading = 50
  170.  
  171.  
  172. --process.load("/lib/tools/auto.lua")
  173. computer.pushSignal("init") -- so libs know components are initialized.
  174. require("event").pull(1, "init") -- Allow init processing.
  175. _G.runlevel = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement