commit d9e65e92be8063874c34c1c154421982d40c8621 Author: Jase Williams Date: Sun Feb 2 05:30:04 2025 -0500 first commit diff --git a/BIOS.lua b/BIOS.lua new file mode 100644 index 0000000..401e9df --- /dev/null +++ b/BIOS.lua @@ -0,0 +1,50 @@ +local AWEFS_version = "01" + +local drive = component.list("drive", true)() +local eeprom = component.list("eeprom")() +component.invoke(eeprom, "setData", drive) +drive = component.proxy(drive) + + +local function readBytes(driveProxy,offset, count) + local buffer = "" + for i = 1, count do + local byte = math.abs(driveProxy.readByte(offset)) + buffer = buffer .. utf8.char(byte) + offset = offset + 1 + end + return buffer +end + +local function tryLoad(driveProxy) + local signature = readBytes(driveProxy,1,8) + if signature ~= "AWEFS " then + return false, nil, "mismatched signature" + end + local version = readBytes(driveProxy,9,2) + if version ~= AWEFS_version then + return false, nil, "mismatched version" + end + + local bootSec = readBytes(driveProxy,65,959) + local sn = readBytes(driveProxy,11,8) + + bootSec = bootSec:gsub("%\0","") + + local init, err = load( + bootSec, string.format("=%s",sn), "bt", _G) + + return true,init,err,sn +end + +local success,init,err, sn = tryLoad(drive) + +if not success then + error(err) +end + +if not init then + error("no bootable medium found :( " .. err) +end + +return init(drive.address,sn,drive,readBytes) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..dd40652 --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +# AWEfs + +The Awesome Wonderful Entertaining File System + +made for The Awesome Wonderful Operating System and AWEkernel + +## Format version 1 + +### Header + +#### Sector 1 +Header and Boot sector - 512 Bytes - Offset 1 +| Name | Size | Purpose | +|-----------------|------------|-------------------------------------------------------| +| Signature | 8 Bytes | Should be to "AWEFS " | +| Version | 2 Bytes | Set to version of AWEFS (right now 01) | +| Serial number | 8 Bytes | Anything (i.e TestDisk) | +| Reserved | 46 Bytes | Reserved | +| Boot sector | 448 Bytes | Lua code (offset 65) | + +#### Sector 2 +Boot sector - 512 Bytes - Offset 513 +| Name | Size | Purpose | +|-----------------|------------|-------------------------------------------------------| +| Boot sector | 512 Bytes | Lua code, extends sector 1 | + +#### Sector 3-5 +Unmanaged data - 1.5 KiB - Offset 1025 +| Name | Size | Purpose | +|-----------------|------------|-------------------------------------------------------| +| Boot sector | 512 Bytes | Lua code, extends sector 1 | + +#### Sector 6-10 +File table - 2.5 KiB - Offset 2502 +| Name | Size | Purpose | +|-----------------|------------|-------------------------------------------------------| +| Signature | 8 Bytes | Should be "FILES " | +| Padding/Reserved| 3 Bytes | Empty | +| File table | 2533 Bytes | See File Declaration | +| End of filetable| 16 Bytes | Should be "EOFTEOFTEOFTEOFT" | + +#### Sector 11-x +File table - Rest - Offset 5062 +| Name | Size | Purpose | +|-----------------|------------|-------------------------------------------------------| +| Data | Rest of disk| Files | + + +### File Declaration in FileTable + +| Name | Size | Purpose | +|-----------------|------------|-------------------------------------------------------| +| File name | 16 Bytes | i.e "FILENAME.txt " | +| File Offset | 8 Bytes | Offset of file | +| Size | 2 Bytes | Size of file to load in sectors | +| Reserved | 6 Bytes | Reserved | + +### File +| Name | Size | Purpose | +|-----------------|------------|-------------------------------------------------------| +| Start file head.| 9 Bytes | "STARTFILE" | +| Data | Defined | Data | \ No newline at end of file diff --git a/createDisk.py b/createDisk.py new file mode 100644 index 0000000..2510129 --- /dev/null +++ b/createDisk.py @@ -0,0 +1,7 @@ +with open("disk.raw", "wb+") as f: + size = int(4194304 / 4) + print("creating disk of size " + str(size * 4) + " bytes") + for i in range(size): + print(f"\r{i*4}/{size*4}", end="") + f.write(b"\0" * 4) + print("\ndone") \ No newline at end of file diff --git a/disk.raw b/disk.raw new file mode 100644 index 0000000..db71f74 Binary files /dev/null and b/disk.raw differ diff --git a/files/SYSTEM.lua b/files/SYSTEM.lua new file mode 100644 index 0000000..c7f327b --- /dev/null +++ b/files/SYSTEM.lua @@ -0,0 +1,118 @@ +local address,serialnumber, + driveproxy,rb,readBytes,loadFileTable,findFile = ... + +Filetable = loadFileTable() + +function loadfile(file) + local fileIndex = findFile(file) + assert(fileIndex, "file \""..file.."\" not found") + + local fileData = Filetable[fileIndex] + assert(readBytes(fileData["offset"],9) == "STARTFILE", + "magic does not match") + + local data = readBytes(fileData["offset"]+9, + fileData["size"]*driveproxy.getSectorSize()-9) + + return load(data, "=" .. file, "bt", _G) +end + +local compo = component +local compu = computer + +_G.screen_x = 1 +_G.screen_y = 1 + +-- init gpu +screen = compo.list("screen", true)() +gpu = screen and compo.list("gpu", true)() + +if gpu then + gpu = compo.proxy(gpu) + _G.gpu = gpu + if not gpu.getScreen() then + gpu.bind(screen) + end + + _G.boot_screen = gpu.getScreen() + w, h = gpu.maxResolution() + + gpu.setResolution(w, h) + gpu.setBackground(0x000000) + gpu.setForeground(0xFFFFFF) + gpu.fill(1, 1, w, h, " ") +end + +function printk(msg,xOffset) + if gpu then + if xOffset==nil then + xOffset=0 + end + + if _G._JOURNAL then + _G.journal_add(msg) + end + gpu.set(1+xOffset, screen_y, msg) + if screen_y == h then + gpu.copy(1, 2, w, h - 1, 0, -1) + gpu.fill(1, h, w, 1, " ") + else + screen_y = screen_y + 1 + end + end +end + +function waitsleep(time) + local time_start = os.time() + + while true do + if os.time() - time_start >= time then + break + end + end +end + +printk("set hcf") + +function hcf() + local ts = os.time() + while 1 do + if os.time() - ts >= 0.5 then + coroutine.yield() + end + end +end + +printk("OSloader v2.1") + +-- start loading +printk("Setting important functions") + +_G.osloader = {} + +printk("set osloader.bootinvoke") + +osloader.bootinvoke = function(a, m, ...) + local r = table.pack(pcall(compu.invoke,a,m,...)) + if not r[1] then + return nil, r[2] + else + return table.unpack(r, 2, r.n) + end +end + +_G.BootAddress = address +printk(_G.BootAddress) + +printk("loading boot flags") +local flagsfile, reason = loadfile("/flags.lua") + +flagsfile() + +printk("loading kernel at /kernel...") + +local kernelfile, reason = loadfile("/kernel") + +kernelfile() + +hcf() \ No newline at end of file diff --git a/files/bs.lua b/files/bs.lua new file mode 100644 index 0000000..f4a7243 --- /dev/null +++ b/files/bs.lua @@ -0,0 +1,71 @@ +local a,sn,dp,rB=... +local function readBytes(off,count) + return rB(dp,off,count):gsub("%\0","") +end + +local FileTable = readBytes(2502,8) +if FileTable ~= "FILES " then + error("can't find filetable at offset 2502 " ..FileTable) +end +local function loadFileTable(offset) + local fileTable = {} + if not offset then + offset = 2513 + end + while true do + local Filename = readBytes(offset,16) + if Filename ~= "" then + if Filename == "EOFTEOFTEOFTEOFT" then + break + end + local file = { + ["name"]=Filename, + ["offset"]=tonumber(readBytes(offset+16,8),10), + ["size"]=tonumber(readBytes(offset+24,2),10) + } + table.insert(fileTable, file) + end + offset = offset + 32 + end + return fileTable +end +local fileTable = loadFileTable() + +-- the first file should be the file SYSTEM.lua +local function findFile(filename) + for i = 1, #fileTable do + if fileTable[i]["name"] == filename then + return i + end + end + return nil +end + +local fileIndex = findFile("SYSTEM.lua") +local Offset = fileTable[fileIndex]["offset"] +local Size = fileTable[fileIndex]["size"] +local FileHead = readBytes(Offset,9) + +if FileHead ~= "STARTFILE" then + error("filehead is not correct" .. FileHead) +end + +local data = readBytes(Offset+9,Size*dp.getSectorSize()-9) +local systemData, err = load(data, "=SYSTEM.lua", "bt", _G) + +if err then + error(err) +end + +if systemData == nil then + error("systemData is nil!") +end + +systemData(a,sn,dp,rB,readBytes,loadFileTable,findFile) + +local ts=os.time() +while 1 do + if os.time() - ts >= 0.5 then + coroutine.yield() + end +end diff --git a/files/kernel b/files/kernel new file mode 100755 index 0000000..dfb521e --- /dev/null +++ b/files/kernel @@ -0,0 +1,380 @@ +_G.kapi = {} +kapi.version = "5-devel_1-22-25-AWEFS" + +local component = component +local computer = computer +local unicode = unicode + +_G.component = nil +_G.computer = nil +_G.unicode = nil + +if not screen_x then + _G.screen_x = 1 +end +if not screen_y then + _G.screen_y = 1 +end + +function printk(msg) + if gpu then + local a, b = pcall(gpu.set, 1, screen_y, msg) + if not a then + end + if screen_y == h then + gpu.copy(1, 2, w, h - 1, 0, -1) + gpu.fill(1, h, w, 1, " ") + else + screen_y = screen_y + 1 + end + end +end +kapi.printk = printk + +printk("Kernel " .. kapi.version) + +function kapi.printsysinfo() + local freemem = computer.freeMemory() + local totalmem = computer.totalMemory() + print("System information\n\r") + + print(" /\\_/\\ Memory " .. totalmem .. "B\n\r") + print(" ( ^ ^ ) Free " .. freemem .. "b\n\r") + print(" \\ w / Used " .. totalmem - freemem .. "b\n\r") + print(" Uptime " .. computer.uptime() .. "S\n\r") + + print(" Arch. " .. computer.getArchitecture() .. "\n\r") + print(" Rootdisk " .. _G.BootAddress .."\n\n\r") + print(" Kernel " .. kapi.version .."\n\r") +end + +function kapi.panic(message, trace) + if _G._KFLAGS and _G._KFLAGS._PANIC_IS_ERROR then + error(message) + else + if _G.gpu ~= nil then + if gpu_driver.set_bg ~= nil then + gpu_driver.set_bg(0xff5555) + gpu_driver.set_fg(0xffffff) + screen_y = 1 + screen_x = 1 + print("Kernel Panic\r\n") + print("Kernel version " .. kapi.version .. "\r\n") + kapi.printsysinfo() + if trace ~= nil then + print(trace .. "\r\n") + else + print(debug.traceback() .. "\r\n") + end + print(message .. "\r\n") + print("Kernel Panic\r\n") + end + end + + computer.beep(200, 0.25) + computer.beep(300, 0.25) + computer.beep(400, 0.25) + computer.beep(500, 0.25) + + waitsleep(2) + + computer.beep(400, 0.1) + computer.beep(500, 0.1) + computer.beep(500, 0.1) + computer.beep(200, 0.1) + + hcf() + end +end + +kapi.loadfile = loadfile + +function kapi.dofile(path) + local program, reason = kapi.loadfile(path) + + if program then + local result = table.pack(pcall(program)) + if result[1] then + program = nil + reason = nil + return table.unpack(result, 2, result.n) + else + kapi.panic(result[2], debug.traceback()) + end + else + kapi.panic(reason, debug.traceback()) + end +end + +function kapi.dprintk(m) + if _G._KFLAGS._KERNEL_DEBUG then + if _G.gpu then + set_gpu_fg(0x6666ff) + set_gpu_bg(0x000000) + printk(m) + set_gpu_fg(0xffffff) + end + end +end + +function kapi.rom_invoke(root_key, method, ...) + if _G.BootAddress ~= "N/A" then + return component.invoke(_G.BootAddress, method, ...) + else + panic("Boot address is N/A", debug.traceback()) + end +end + +local w, h +local screen +local gpu + +_G.gpu_driver = {} +_G.screen_driver = {} + + +function gpu_driver.init() + screen = component.list("screen", true)() + gpu = screen and component.list("gpu", true)() + + if gpu and screen then + gpu = component.proxy(gpu) + _G.gpu = gpu + if not gpu.getScreen() then + gpu.bind(screen) + end + + _G.boot_screen = gpu.getScreen() + w, h = gpu.maxResolution() + + _G.screen_width = w + _G.screen_height = h + + gpu.setResolution(w, h) + gpu.setBackground(0x000000) + gpu.setForeground(0xFFFFFF) + if screen_y == nil then + gpu.fill(1, 1, w, h, " ") + end + end +end + +gpu_driver.init() + +function gpu_driver.clearscr() + if gpu then + gpu.setResolution(w, h) + gpu.setBackground(0x000000) + gpu.setForeground(0xFFFFFF) + gpu.fill(1, 1, w, h, " ") + end +end + +function gpu_driver.set_bg(color) + if gpu then + gpu.setBackground(color) + end +end +function gpu_driver.set_fg(color) + if gpu then + gpu.setForeground(color) + end +end + +function gpu_driver.scroll() + if gpu then + gpu.copy(1, 2, w, h - 1, 0, -1) + gpu.fill(1, h, w, 1, " ") + end + screen_y = screen_height - 1 +end + +function gpu_driver.newln() + screen_y = screen_y + 1 + if screen_y == screen_height then + gpu_driver.scroll() + else + screen_x = screen_x + 1 + end +end +function gpu_driver.carriageret() + screen_x = 1 +end + +function print(msg) + if gpu then + if msg ~= "string" then + msg = tostring(msg) + end + for i = 1, #msg do + local c = msg:sub(i, i) + if c == "\n" then + gpu_driver.newln() + elseif c == "\09" then + gpu_driver.carriageret() + screen_x = screen_x + 8 + elseif c == "\r" then + gpu_driver.carriageret() + else + if screen_x == screen_width then + screen_x = 1 + screen_y = screen_y + 1 + end + gpu.set(screen_x, screen_y, c) + end + + if screen_y == screen_height then + gpu_driver.scroll() + else + screen_x = screen_x + 1 + end + end + end + + return +end + +----------------------------------------------------------------------------------------------- +----------------------------------------------------------------------------------------------- +----------------------------------------------------------------------------------------------- + +if _KFLAGS._MODULES_ALLOWED then + local list = kapi.loadfile(_KFLAGS._MODULE_DIR .. "enabled.list")() + if list == nil then + printk("no " .. _KFLAGS._MODULE_DIR .. "enabled.list file") + else + for i in ipairs(list) do + kapi.loadfile(_KFLAGS._MODULE_DIR .. list[i])() + end + end +end + +printk("component lib") + +function component.isAvailable(componentType) + if component[componentType] then + return true + end + return false +end + +function component.get(address, componentType) + local comp = component.list(componentType) + + for a,_ in comp do + local s,e = string.find(a,address) + if s == 1 then + return a + end + end + return nil, "no such component" +end + +function component.getPrimary(componentType) + local prim = component[componentType] + if not prim then + error(string.format("no primary '%s' available", componentType)) + end + return prim +end + +function component.setPrimary(componentType, address) + if componentType == "filesystem" then + return + end + + address = component.get(address:sub(1,5), componentType) -- don't sub + component[componentType] = component.proxy(address) +end + +local components = component.list() +printk("Setting primary components") +for address, componentType in components do + component.setPrimary(componentType,address) +end + +local loaded = { + ["_G"] = _G, + ["bit32"] = bit32, + ["coroutine"] = coroutine, + ["math"] = math, + ["os"] = os, + ["package"] = package, + ["string"] = string, + ["table"] = table, + + ["computer"] = computer, + ["component"] = component, + ["unicode"] = unicode +} + +function unload_module(module) + if loaded[module] ~= nil then + loaded[module] = nil + end + return +end + +function require(module) + if loaded[module] then + return loaded[module] + end + local library, status, arg + + library = raw_loadfile("/lib/" .. module ..".lua") + + library, status = pcall(library, arg or module) + assert(library, string.format("module '%s' load failed:\n%s", module, status)) + loaded[module] = status + return status +end + +function requirepath(module) + if loaded[module] then + return loaded[module] + end + local library, status, arg + + library = raw_loadfile(module) + + library, status = pcall(library, arg or module) + assert(library, string.format("module '%s' load failed:\n%s", module, status)) + loaded[module] = status + return status +end + + +function Split(str) + local words = {} + for word in str:gmatch("%S+") do + table.insert(words, word) + end + return words + end + +function InArray(arr,elem) + for i in ipairs(arr) do + if tostring(arr[i]) == tostring(elem) then + return true + end + end + + return false +end + +-- Security. + + + +printk("Welcome to the AWEKernel") +printk(" /\\_/\\") +printk("( ^ ^ )") +printk("\\ w /") + +local f = kapi.loadfile(_KFLAGS._INIT_LOCATION) +local s, r = pcall(f) +if not s then + kapi.panic(r) +end + +kapi.panic("init killed") \ No newline at end of file diff --git a/files/openfetch b/files/openfetch new file mode 100644 index 0000000..f452323 --- /dev/null +++ b/files/openfetch @@ -0,0 +1,229 @@ +-- openfetch 1.4 | by ethernalsteve & Bs0Dd + +local component = require("component") +local computer = require("computer") +--local fs = require("filesystem") +local gpu = component.gpu + +local logos = { + { + " %%%%(///////(%%% ", + " %% (///%%%/(%%%%% ", + " %% (///%%%/(%%%%% ", + " %% (///////(%%%%% ", + " %%%%%%%%%%%%%%%%%%% ", + " %%%%%%%%%%%%%%%%%%% ", + " %% %% ", + " %% %% ", + " %%%%%%%%%%%%%%%%%%% ", + " %%%%%%%%%%%%%%%%% " + }, + { + " %%%%%(///////////////(%%%% ", + " %%%###(//////%%%%%%///(%%%%%%% ", + " %%%###(//////%%%%%%///(%%%%%%% ", + " %%%###(//////%%%%%%///(%%%%%%% ", + " %%%###(//////%%%%%%///(%%%%%%% ", + " %%%###(///////////////(%%%%%%% ", + " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ", + " %%%((((((((((((((((((((((((%%% ", + " %%%((((((((((((((((((((((((%%% ", + " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ", + " %%% %%% ", + " %%%////////////////////////%%% ", + " %%% %%% ", + " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ", + " %%%%%%%%%%%%%%%%%%%%%%%%%%%% " + }, + { + " %%%%%%%%%%(///////////////////////(%%%%%%% ", + " %%%%%%#####(///////////%%%%%%%/////(%%%%%%%%% ", + " %%%%%%#####(///////////%%%%%%%/////(%%%%%%%%%% ", + " %%%%%%#####(///////////%%%%%%%/////(%%%%%%%%%% ", + " %%%%%%#####(///////////%%%%%%%/////(%%%%%%%%%% ", + " %%%%%%#####(///////////%%%%%%%/////(%%%%%%%%%% ", + " %%%%%%#####(///////////%%%%%%%/////(%%%%%%%%%% ", + " %%%%%%#####(///////////////////////(%%%%%%%%%% ", + " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ", + " %%%%%%((((((((((((((((((((((((((((((((((%%%%%% ", + " %%%%%%((((((((((((((((((((((((((((((((((%%%%%% ", + " %%%%%%((((((((((((((((((((((((((((((((((%%%%%% ", + " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ", + " %%%%%% %%%%%% ", + " %%%%%% %%%%%% ", + " %%%%%% %%%%%% ", + " %%%%%%//////////////////////////////////%%%%%% ", + " %%%%%% %%%%%% ", + " %%%%%% %%%%%% ", + " %%%%%% %%%%%% ", + " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ", + " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% " + } +} + +local w, h = gpu.maxResolution() +local devs = component.computer.getDeviceInfo() +local gpuInfoStr + +local function getGPUTier() + local dp = gpu.maxDepth() + if dp == 8 then + return 3 + elseif dp == 4 then + return 2 + else + return 1 + end +end + +local function getModel(desc) + local name + for _, dev in pairs(devs) do + if dev.description == desc then + name = dev.product + break + end + end + return name +end + +local function getOS() + --if fs.exists("OS.lua") then + -- return "MineOS" + --elseif fs.exists("/lib/core") then + -- return "OpenOS" + --elseif fs.exists("/root") then + -- return "Plan9k" + --elseif fs.exists("/etc/system") then + -- return "BananaOS" + --end + return kapi.version +end + +local function getParsedUptime() + local seconds, minutes, hours = math.floor(computer.uptime()), 0, 0 + local time = "" + if seconds >= 60 then + minutes = math.floor(seconds / 60) + seconds = seconds % 60 + end + if minutes >= 60 then + hours = math.floor(minutes / 60) + minutes = minutes % 60 + end + if getGPUTier() == 1 then + time = time .. string.format("%02d:%02d:%02d", hours, minutes, seconds) + else + if hours == 1 then time = hours .. " hour, " + elseif hours >= 2 then time = hours .. " hours, " + end + if minutes == 1 then time = time .. minutes .. " min, " + elseif minutes >= 2 then time = time .. minutes .. " mins, " + end + time = time .. seconds .. " sec" + end + return time +end + +local logo = logos[getGPUTier()] +local function addCharacteristics() + local cpu, apu = getModel("CPU"), getModel("APU") + gpuInfoStr = 8 + + logo[2] = logo[2] .. "|OS:|" .. getOS() + logo[3] = logo[3] .. "|Uptime:|" .. getParsedUptime() + logo[4] = logo[4] .. "|Architecture:|" .. _VERSION + logo[5] = logo[5] .. "|Resolution:|" .. math.floor(w) .. "x" .. math.floor(h) + logo[6] = logo[6] .. "|Terminal:|" .. getModel("Text buffer") + if cpu ~= nil then logo[7] = logo[7] .. "|CPU:|" .. cpu:sub(0,11) .. ' (' .. cpu:match('%d') .. ' Tier)' + elseif apu ~= nil then logo[7] = logo[7] .. "|APU:|" .. apu:sub(0,11) .. ' (' .. apu:match('%d') .. ' Tier)' end + for _, dev in pairs(devs) do + if dev.description == "Graphics controller" then + logo[gpuInfoStr] = logo[gpuInfoStr] .. "|GPU:|" .. dev.product .. ' (' .. dev.product:match('%d') .. ' Tier)' + gpuInfoStr = gpuInfoStr + 1 + end + end + logo[gpuInfoStr] = logo[gpuInfoStr] .. "|Memory:|" .. math.floor(computer.totalMemory() / 1024 - computer.freeMemory() / 1024) .. " KB / " .. math.floor(computer.totalMemory() / 1024) .. " KB" +end + +local function drawPalette() + local palette = {{0x000000, 0x333333}, {0xCC0000, 0xFF0000}, {0x00CC00, 0x00FF00}, {0xCCCC00, 0xFFFF00}, + {0x0000CC, 0x0000FF}, {0xCC00CC, 0xFF00FF}, {0x00CCCC, 0x00FFFF}, {0xCCCCCC, 0xFFFFFF}} + local cur = #logo[1] + 2 + for _, color in pairs(palette) do + gpu.setForeground(color[1]) + gpu.set(cur, gpuInfoStr + 2, "███") + gpu.setForeground(color[2]) + gpu.set(cur, gpuInfoStr + 3, "███") + cur = cur + 3 + end +end + +gpu.setResolution(w, h) +addCharacteristics() +gpu.setBackground(0x000000) +gpu.fill(1, 1, w, h, " ") + +for i = 1, #logo do + local logoLine, tmp, f = {}, {}, false + logo[i]:gsub(".", function(c) table.insert(logoLine, c) end) + for ii = 1, #logoLine do + if f then + if string.match(logoLine[ii], "|") then + f = false + else + if string.match(logoLine[ii], ":") then + gpu.setForeground(0xffffff) + elseif getOS() == "MineOS" then + gpu.setForeground(0x32e3de) + elseif getOS() == "OpenOS" then + gpu.setForeground(0x30ff80) + elseif getOS() == "Plan9k" then + gpu.setForeground(0xff0000) + elseif getOS() == "BananaOS" then + gpu.setForeground(0xffff00) + end + gpu.set(ii, i, logoLine[ii]) + end + else + if logoLine[ii] == "%" then + if getOS() == "MineOS" then + gpu.setForeground(0x35ffff) + elseif getOS() == "OpenOS" then + gpu.setForeground(0x228822) + elseif getOS() == "Plan9k" then + gpu.setForeground(0xff0000) + elseif getOS() == "BananaOS" then + gpu.setForeground(0xcccc00) + end + gpu.set(ii, i, logoLine[ii]) + elseif logoLine[ii] == "/" then + gpu.setForeground(0xfffafa) + gpu.set(ii, i, logoLine[ii]) + elseif logoLine[ii] == "#" then + gpu.setForeground(0x585858) + gpu.set(ii, i, logoLine[ii]) + elseif logoLine[ii] == "(" then + gpu.setForeground(0xc0c0c0) + gpu.set(ii, i, logoLine[ii]) + elseif string.match(logoLine[ii], "|") then + f = true + else + gpu.setForeground(0xffffff) + gpu.set(ii, i, logoLine[ii]) + end + end + end +end + +drawPalette() + +if getOS() == "MineOS" then + gpu.set(1, #logo + 2 > 14 and #logo + 2 or 14, 'Press any key to exit.') + local evtype + while evtype ~= 'key_down' do + evtype = computer.pullSignal() + end +else + --require("term").setCursor(1, #logo + 2 > 14 and #logo + 2 or 14) +end \ No newline at end of file diff --git a/files/startup.lua b/files/startup.lua new file mode 100644 index 0000000..4797f5d --- /dev/null +++ b/files/startup.lua @@ -0,0 +1,155 @@ +local bsh = {} +local component = require("component") +local computer = require("computer") +local event = {} + +function event.pull(name, timeout) + local rawSignal = {} + local signals_recieved_in_mean_time = {} + local timeouts = 0 + if not timeout then + timeout = 99999999999 + end + + while rawSignal[1] ~= name do + -- pull any signal + rawSignal = table.pack(computer.pullSignal(0.1)) + + -- if no signal then add to time timeout + if rawSignal[1] == nil then + timeouts = timeouts + 0.1 + else + if rawSignal[1] ~= name then + -- not the signal, push to the signals we got in the mean time + table.insert(signals_recieved_in_mean_time,rawSignal) + else + -- got the signal + break + end + end + if timeouts >= timeout then + -- we never got the signal :( + return nil + end + end + + -- rethrow all signals... they weren't what we wanted + if #signals_recieved_in_mean_time > 0 then + for i in ipairs(signals_recieved_in_mean_time) do + computer.pushSignal(table.unpack(signals_recieved_in_mean_time[i])) + end + end + + return table.unpack(rawSignal) +end + +-- BUG: when in /bin directory, running something tries to run /binhello.lua +-- FEAT: autofill slashes, and .lua +-- FEAT: handle .. + +bsh.running = true + +local function keyin() + while true do + local _,_,letterAsciiCode,_,_ = event.pull("key_down") + return letterAsciiCode + end +end + +function Align(String,Number,append) + if not append then + append = " " + end + if #String > Number then + while #String > Number do + String = String:sub(1, -2) + end + String = String:sub(1, -5) .. "..." + end + if #String < Number then + while #String < Number do + String = String .. append + end + end + + return String +end + +function bsh.command(buffer) + local command = Split(buffer) + if command[1] == "ls" then + for i = 1, #Filetable do + print( + string.format("%s off %sb size%s(*512)\r\n", + Align(Filetable[i]["name"],16), + Align(tostring(Filetable[i]["offset"]),8), + Align(tostring(Filetable[i]["size"]),2))) + end + elseif command[1] == "clear" then + clearscr() + screen_x = 2 + screen_y = 1 + elseif command[1] == "exit" then + bsh.running = false + else + local file, err = loadfile(command[1]) + + if file == nil then + print("error while loading" .. tostring(err)) + return + end + + local success, result = pcall(file, command) + if not success then + print(result.."\r\n") + end + end +end + +local function prompt() + print(cwd .." #> ") +end + +if _G.cwd == nil then + _G.cwd = "/" +end + +print("bsh v2.1\r\n") + +local buffer = "" + +prompt() + +while bsh.running do + local nextkeycode = keyin() + if nextkeycode == nil then + nextkeycode = 0 + end + local nextkey = string.char(nextkeycode) + if nextkeycode == 13 then + print("\r\n") + local success, reason = pcall(bsh.command, buffer) + if not success then + print(reason) + end + buffer = "" + nextkeycode = nil + print("\r\n") + if _G.PROCESS_RUNNER then + coroutine.yield() + end + prompt() + elseif nextkeycode == 8 then + if #buffer ~= 0 then + buffer = buffer:sub(1, -2) + screen_x = screen_x - 1 + print(" ") + screen_x = screen_x - 1 + end + elseif nextkeycode == 16 then + -- ignore. + else + buffer = buffer .. nextkey + print(nextkey) + end +end \ No newline at end of file diff --git a/makeFile.sh b/makeFile.sh new file mode 100755 index 0000000..cdf1be3 --- /dev/null +++ b/makeFile.sh @@ -0,0 +1,4 @@ +uuid=e3429b06-1db7-4714-9677-7729f0d51104 +cp disk.raw $uuid.bin +gzip $uuid.bin +mv $uuid.bin.gz ../$uuid.bin \ No newline at end of file diff --git a/ocfs.txt b/ocfs.txt new file mode 100644 index 0000000..1fa0707 --- /dev/null +++ b/ocfs.txt @@ -0,0 +1,64 @@ +Version 01 + +Disk Header: + +Sector 1: Boot sector, 512 Bytes Offset 1 +AWEFS Header Signature : 8 Bytes : Should be set to "AWEFS " +AWEFS Version Signature: 2 Bytes : Can be anything, version number +S/N : 8 Bytes : Anything, i.e "abcd1234" (displayed as abcd-1234) +Reserved : 46 Bytes : Reserved +Boot sector : 448 Bytes : Lua code, offset 65 + +Sector 2: Boot sector, 512 Bytes Offset 513 +Boot sector : 512 Bytes : Lua code - extends Sector 1 + +Sector 3-5: Unmanaged data, 1.5 KiB Offset 1025 +Data : 1.5 KiB : Data, unmanaged, don't use + +Sector 6-10: File table, 2.5 KiB Offset 2502 +File table signature : 8 Bytes : Should be set to "FILES " +Padding : 3 Bytes : Should be null + +File Declaration: 32 Bytes +File name : 16 Bytes : i.e "FILENAME.txt " +File offset : 8 Bytes : Offset of file on disk +Size : 2 Bytes : How many sectors does the file take up +Reserved : 6 Bytes : Reserved + +End of file table : 16 Bytes : "EOFTEOFTEOFTEOFT" + + +Sector 11-x: Data, files, etc Offset (in theory 5062 12c6) + +File on disk : +Start file header : 9 Bytes : "STARTFILE" +Data : Defined : Defined in filetable + +Default Bios Behaivors and Todo: +TODO: + scan disks for bootable, (add bootable flag?) + +Behaivors: + Will pass along current drive's address, S/N, drive proxy, and + readBytes function (use local a,sn,dp,rB = ...) + + local ts = os.time() + while 1 do + if os.time() - ts >= 0.5 then + coroutine.yield() + end + end + + +Notes: + In theory, you can put files anywhere on disk. Instead of doing that, + please store files directly after the end of a file with the file with the largest + offset + (size * sectorSize) (i.e last file is at offset 4000 and size 1 sector, store next file at 4512) + + The 16 bytes for file name is very limiting. I will probably raise it, but it's fine right now + + Writing to disk will probably be okay, (loop thru filetable, find lowest offset using a + candidate system or something, then do the math to find the next offset. Issue with that + would be any deleted files before the file with the highest offset will never be reclaimed) + +003FFFF0