DorianH935

MDOS init.lua

Dec 23rd, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. -- init.lua - Bootstrap loader for Monolith Disk Operating System (M-DOS)
  2. -- This file loads OS.SYS and then executes COMMAND.PRG
  3.  
  4. local component = component
  5. local computer = computer
  6.  
  7. -- Find the boot filesystem
  8. local bootfs = component.proxy(computer.getBootAddress())
  9.  
  10. -- Find tmpfs for faster performance
  11. local tmpfs = nil
  12. local tmpAddr = computer.tmpAddress()
  13. if tmpAddr then
  14. tmpfs = component.proxy(tmpAddr)
  15. end
  16.  
  17. -- Load and execute OS.SYS to set up system environment
  18. local handle, reason = bootfs.open("OS.SYS", "r")
  19. if not handle then
  20. error("Failed to load OS.SYS: " .. tostring(reason))
  21. end
  22.  
  23. local ossys = ""
  24. repeat
  25. local chunk = bootfs.read(handle, math.huge)
  26. ossys = ossys .. (chunk or "")
  27. until not chunk
  28. bootfs.close(handle)
  29.  
  30. -- Copy OS.SYS to tmpfs for faster access
  31. if tmpfs then
  32. local tmpHandle = tmpfs.open("OS.SYS", "w")
  33. if tmpHandle then
  34. tmpfs.write(tmpHandle, ossys)
  35. tmpfs.close(tmpHandle)
  36. end
  37. end
  38.  
  39. -- Execute OS.SYS to initialize the system
  40. local init, reason = load(ossys, "=OS.SYS", "t", _G)
  41. if not init then
  42. error("Failed to parse OS.SYS: " .. tostring(reason))
  43. end
  44.  
  45. local ok, err = pcall(init)
  46. if not ok then
  47. error("Failed to initialize OS.SYS: " .. tostring(err))
  48. end
  49.  
  50. -- Now load and execute COMMAND.PRG
  51. handle, reason = bootfs.open("COMMAND.PRG", "r")
  52. if not handle then
  53. error("Failed to load COMMAND.PRG: " .. tostring(reason))
  54. end
  55.  
  56. local cmdprog = ""
  57. repeat
  58. local chunk = bootfs.read(handle, math.huge)
  59. cmdprog = cmdprog .. (chunk or "")
  60. until not chunk
  61. bootfs.close(handle)
  62.  
  63. -- Copy COMMAND.PRG to tmpfs
  64. if tmpfs then
  65. local tmpHandle = tmpfs.open("COMMAND.PRG", "w")
  66. if tmpHandle then
  67. tmpfs.write(tmpHandle, cmdprog)
  68. tmpfs.close(tmpHandle)
  69. end
  70. end
  71.  
  72. -- Execute COMMAND.PRG
  73. local command, reason = load(cmdprog, "=COMMAND.PRG", "t", _G)
  74. if not command then
  75. error("Failed to parse COMMAND.PRG: " .. tostring(reason))
  76. end
  77.  
  78. local ok, err = pcall(command)
  79. if not ok then
  80. error("Failed to start COMMAND.PRG: " .. tostring(err))
  81. end
Advertisement
Add Comment
Please, Sign In to add comment