Advertisement
ArtemHasker

DaveBIOS.efi

Apr 6th, 2025
277
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.97 KB | Source Code | 0 0
  1. local check = true
  2. local check_dalay = 1.5
  3. local invoke = component.invoke
  4. local component_list = component.list
  5. local cursor_x = 1
  6. local cursor_y = 1
  7. local eeprom = component_list("eeprom")()
  8. local screen = component_list("screen")()
  9. local gpu = component_list("gpu")()
  10. local bootF = {"/init.lua", "/OS.lua"}
  11. local function pinvoke(address, method, ...)
  12.     local ok, result = pcall(invoke, address, method, ...)
  13.     if ok then
  14.         return result
  15.     else
  16.         return nil, result
  17.     end
  18. end
  19. local function print(message, ...)
  20.     if gpu and screen then
  21.         local old_foreground = invoke(gpu, "getForeground")
  22.         message = string.format(message, ...)
  23.         for i = 1, #message, 1 do
  24.             local char = string.sub(message, i, i)
  25.             if char == "]" then
  26.                 invoke(gpu, "setForeground", old_foreground)
  27.             end
  28.             if char == '\n' then
  29.                 cursor_x = 1
  30.                 cursor_y = cursor_y + 1
  31.             else
  32.                 invoke(gpu, "set", cursor_x, cursor_y, char)
  33.                 cursor_x = cursor_x + 1
  34.             end
  35.             if char == "[" then
  36.                 invoke(gpu, "setForeground", 0x55FF55)
  37.             end
  38.         end
  39.     end
  40. end
  41. computer.getBootAddress = function()
  42.     return pinvoke(eeprom, "getData")
  43. end
  44. computer.setBootAddress = function(address)
  45.     return pinvoke(eeprom, "setData", address)
  46. end
  47. local function boot_drive(address)
  48.     for _, name in pairs(bootF) do
  49.         local handle = pinvoke(address, "open", name)
  50.         if handle then
  51.             local buffer = ""
  52.             repeat
  53.                 local data, reason = invoke(address, "read", handle, math.maxinteger or math.huge)
  54.                 if not data and reason then
  55.                     return false
  56.                 end
  57.                 buffer = buffer .. (data or "")
  58.             until not data
  59.             invoke(address, "close", handle)
  60.             local program, _ = load(buffer, "=init")
  61.             if program then
  62.                 computer.setBootAddress(address)
  63.                 print("Booting OS...")
  64.                 computer.pullSignal(5)
  65.                 local ok, _ = pcall(program)
  66.                 if not ok then
  67.                     return false
  68.                 end
  69.             else
  70.                 return false
  71.             end
  72.             return true
  73.         end
  74.     end
  75.     return false
  76. end
  77. local function boot()
  78.     local found = false
  79.     if computer.getBootAddress() then
  80.         found = boot_drive(computer.getBootAddress())
  81.     end
  82.     for address in component_list("filesystem") do
  83.         found = boot_drive(address)
  84.     end
  85.     if not found then
  86.         cursor_x = 1
  87.         cursor_y = 9
  88.         invoke(gpu, "setForeground", 0xAAAAAA)
  89.         print("Disk Boot Fail\n\nPress Any Key...")
  90.         while true do
  91.             local signal = {computer.pullSignal()}
  92.  
  93.             if signal[1] == "key_down" then
  94.                 computer.shutdown(true)
  95.             end
  96.         end
  97.     end
  98. end
  99. if gpu and screen then
  100.     invoke(gpu, "bind", screen)
  101.     local res_x, res_y = invoke(gpu, "maxResolution", screen)
  102.     invoke(gpu, "setResolution", math.min(80,res_x), math.min(25, res_y))
  103.     invoke(gpu, "setBackground", 0x000000)
  104.     invoke(gpu, "setForeground", 0xAAAAAA)
  105.     invoke(gpu, "fill", 1, 1, res_x, res_y, ' ')
  106.     print("DaveBIOS Lua Edition v4.5\n")
  107.     print("(C) DaveCorporation\n\n")
  108.     invoke(gpu, "setForeground", 0x00AAAA)
  109.     print("RAM   [ 0000 KB OK ]\n")
  110.     local devices_info = computer.getDeviceInfo()
  111.     local gpu_info = devices_info[gpu]
  112.     local cpu_info
  113.     for _, info in pairs(devices_info) do
  114.         if info.class == "processor" then
  115.             cpu_info = info
  116.             break
  117.         end
  118.     end
  119.     print("CPU   [ %s ]\n", cpu_info.product)
  120.     print("Video [ %s ]\n", gpu_info.product)
  121.     print("FDD   [ 1 ]\n")
  122.     if check then
  123.         local memory_size = computer.totalMemory() / 1024
  124.         cursor_y = 4
  125.  
  126.         for i = 0, memory_size, 512 do
  127.             computer.pullSignal(check_dalay)
  128.             cursor_x = 7
  129.  
  130.             print("[ %04d KB OK ]", i)
  131.         end
  132.     end
  133.     cursor_x = 1
  134.     cursor_y = 9
  135.     invoke(gpu, "setForeground", 0xAAAAAA)
  136.     boot()
  137. end
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement