Advertisement
DOGGYWOOF

Opencomputers defualt bios code

Apr 18th, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. local init
  2. do
  3. local component_invoke = component.invoke
  4. local function boot_invoke(address, method, ...)
  5. local result = table.pack(pcall(component_invoke, address, method, ...))
  6. if not result[1] then
  7. return nil, result[2]
  8. else
  9. return table.unpack(result, 2, result.n)
  10. end
  11. end
  12.  
  13. -- backwards compatibility, may remove later
  14. local eeprom = component.list("eeprom")()
  15. computer.getBootAddress = function()
  16. return boot_invoke(eeprom, "getData")
  17. end
  18. computer.setBootAddress = function(address)
  19. return boot_invoke(eeprom, "setData", address)
  20. end
  21.  
  22. do
  23. local screen = component.list("screen")()
  24. local gpu = component.list("gpu")()
  25. if gpu and screen then
  26. boot_invoke(gpu, "bind", screen)
  27. end
  28. end
  29. local function tryLoadFrom(address)
  30. local handle, reason = boot_invoke(address, "open", "/init.lua")
  31. if not handle then
  32. return nil, reason
  33. end
  34. local buffer = ""
  35. repeat
  36. local data, reason = boot_invoke(address, "read", handle, math.maxinteger or math.huge)
  37. if not data and reason then
  38. return nil, reason
  39. end
  40. buffer = buffer .. (data or "")
  41. until not data
  42. boot_invoke(address, "close", handle)
  43. return load(buffer, "=init")
  44. end
  45. local reason
  46. if computer.getBootAddress() then
  47. init, reason = tryLoadFrom(computer.getBootAddress())
  48. end
  49. if not init then
  50. computer.setBootAddress()
  51. for address in component.list("filesystem") do
  52. init, reason = tryLoadFrom(address)
  53. if init then
  54. computer.setBootAddress(address)
  55. break
  56. end
  57. end
  58. end
  59. if not init then
  60. error("Cannot Boot OS")
  61. end
  62. computer.beep(1000, 0.10)
  63. end
  64. return init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement