Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local check = true
- local check_dalay = 1.5
- local invoke = component.invoke
- local component_list = component.list
- local cursor_x = 1
- local cursor_y = 1
- local eeprom = component_list("eeprom")()
- local screen = component_list("screen")()
- local gpu = component_list("gpu")()
- local bootF = {"/init.lua", "/OS.lua"}
- local function pinvoke(address, method, ...)
- local ok, result = pcall(invoke, address, method, ...)
- if ok then
- return result
- else
- return nil, result
- end
- end
- local function print(message, ...)
- if gpu and screen then
- local old_foreground = invoke(gpu, "getForeground")
- message = string.format(message, ...)
- for i = 1, #message, 1 do
- local char = string.sub(message, i, i)
- if char == "]" then
- invoke(gpu, "setForeground", old_foreground)
- end
- if char == '\n' then
- cursor_x = 1
- cursor_y = cursor_y + 1
- else
- invoke(gpu, "set", cursor_x, cursor_y, char)
- cursor_x = cursor_x + 1
- end
- if char == "[" then
- invoke(gpu, "setForeground", 0x55FF55)
- end
- end
- end
- end
- computer.getBootAddress = function()
- return pinvoke(eeprom, "getData")
- end
- computer.setBootAddress = function(address)
- return pinvoke(eeprom, "setData", address)
- end
- local function boot_drive(address)
- for _, name in pairs(bootF) do
- local handle = pinvoke(address, "open", name)
- if handle then
- local buffer = ""
- repeat
- local data, reason = invoke(address, "read", handle, math.maxinteger or math.huge)
- if not data and reason then
- return false
- end
- buffer = buffer .. (data or "")
- until not data
- invoke(address, "close", handle)
- local program, _ = load(buffer, "=init")
- if program then
- computer.setBootAddress(address)
- print("Booting OS...")
- computer.pullSignal(5)
- local ok, _ = pcall(program)
- if not ok then
- return false
- end
- else
- return false
- end
- return true
- end
- end
- return false
- end
- local function boot()
- local found = false
- if computer.getBootAddress() then
- found = boot_drive(computer.getBootAddress())
- end
- for address in component_list("filesystem") do
- found = boot_drive(address)
- end
- if not found then
- cursor_x = 1
- cursor_y = 9
- invoke(gpu, "setForeground", 0xAAAAAA)
- print("Disk Boot Fail\n\nPress Any Key...")
- while true do
- local signal = {computer.pullSignal()}
- if signal[1] == "key_down" then
- computer.shutdown(true)
- end
- end
- end
- end
- if gpu and screen then
- invoke(gpu, "bind", screen)
- local res_x, res_y = invoke(gpu, "maxResolution", screen)
- invoke(gpu, "setResolution", math.min(80,res_x), math.min(25, res_y))
- invoke(gpu, "setBackground", 0x000000)
- invoke(gpu, "setForeground", 0xAAAAAA)
- invoke(gpu, "fill", 1, 1, res_x, res_y, ' ')
- print("DaveBIOS Lua Edition v4.5\n")
- print("(C) DaveCorporation\n\n")
- invoke(gpu, "setForeground", 0x00AAAA)
- print("RAM [ 0000 KB OK ]\n")
- local devices_info = computer.getDeviceInfo()
- local gpu_info = devices_info[gpu]
- local cpu_info
- for _, info in pairs(devices_info) do
- if info.class == "processor" then
- cpu_info = info
- break
- end
- end
- print("CPU [ %s ]\n", cpu_info.product)
- print("Video [ %s ]\n", gpu_info.product)
- print("FDD [ 1 ]\n")
- if check then
- local memory_size = computer.totalMemory() / 1024
- cursor_y = 4
- for i = 0, memory_size, 512 do
- computer.pullSignal(check_dalay)
- cursor_x = 7
- print("[ %04d KB OK ]", i)
- end
- end
- cursor_x = 1
- cursor_y = 9
- invoke(gpu, "setForeground", 0xAAAAAA)
- boot()
- end
Advertisement
Advertisement