This commit is contained in:
2025-09-29 14:13:43 -04:00
parent abd573f686
commit 701bfa5198
9 changed files with 79 additions and 32 deletions

View File

@@ -8,7 +8,7 @@ function object.getMachineEvent()
return nil
end
local event = INTERNAL_EVENT_QUEUE[1]
INTERNAL_EVENT_QUEUE[1]=nil
INTERNAL_EVENT_QUEUE={table.unpack(INTERNAL_EVENT_QUEUE, 2)}
return table.unpack(event)
end

View File

@@ -2,8 +2,8 @@ local fss = {}
local object = {}
local uObject = {}
local function getFs(self)
return fss[tostring(self.__UDATA_id)]
local function getFs(disk)
return fss[tostring(disk.__UDATA_id)]
end
local function normalize(path)
@@ -75,23 +75,25 @@ end
function uObject:readBytes(start, length)
local f = getFs(self)
local file=fs.open(f, "r")
local data=fs.readAll()
local data=file.readAll()
file.close()
return data:sub(start, start+length)
return data:sub(start+1, start+length)
end
function uObject:writeBytes(start, dat)
local f = getFs(self)
local file=fs.open(f, "r")
local data=fs.readAll()
local data=file.readAll()
file.close()
file = fs.open(f, "w")
file.write(data:sub(1, start)..dat..data:sub(start+1+#dat, #data))
file.close()
return data:sub(1, start)..dat..data:sub(start+#dat, #data)
end
function uObject:getSize()
local f = getFs(self)
local file=fs.open(f, "r")
local data=fs.readAll()
local data=file.readAll()
file.close()
return #data
end

View File

@@ -0,0 +1,4 @@
akeys = {}
akeys[keys.enter] = "\n"
akeys[keys.tab] = "\t"
akeys[keys.backspace] = "\b"

View File

@@ -1,6 +1,6 @@
local screen = {}
local function write(sText)
function write(sText)
local w, h = term.getSize()
local x, y = term.getCursorPos()
@@ -56,7 +56,7 @@ local function write(sText)
return nLinesPrinted
end
function screen.print(...)
function print(...)
local nLinesPrinted = 0
local nLimit = select("#", ...)
for n = 1, nLimit do
@@ -69,7 +69,11 @@ function screen.print(...)
nLinesPrinted = nLinesPrinted + write("\n")
end
function screen.printInline(...)
function screen.print(...)
print(...)
end
function printInline(...)
local nLinesPrinted = 0
local nLimit = select("#", ...)
for n = 1, nLimit do
@@ -77,8 +81,12 @@ function screen.printInline(...)
nLinesPrinted = nLinesPrinted + write(s)
end
end
function screen.printInline(...)
printInline(...)
end
function screen.clear()
term.setCursorPos(1,1)
term.clear()
end

View File

@@ -39,6 +39,13 @@ function string.split(str, delim, maxResultCountOrNil)
return rv
end
function _VG.sleep(nTime)
local timer = os.startTimer(nTime or 0)
repeat
local _, param = coroutine.yield("timer")
until param == timer
end
INTERNAL_DISKS={}
INTERNAL_SCREENS={}
INTERNAL_NET={}
@@ -52,7 +59,7 @@ function addEventRaw(...)
end
function newComponent(type, object)
local id = tostring(#INTERNAL_COMPONENT_REGESTRY+1)
local id = #INTERNAL_COMPONENT_REGESTRY+1
INTERNAL_COMPONENT_REGESTRY[id] = {type=type, object=object}
addEventRaw("componentAdded", type, object)
return {
@@ -73,19 +80,23 @@ function _VG.component.list()
local i = 0
return function()
i=i+1
return INTERNAL_COMPONENT_REGESTRY[tostring(i)].type, INTERNAL_COMPONENT_REGESTRY[tostring(i)].object
if INTERNAL_COMPONENT_REGESTRY[i] then
return INTERNAL_COMPONENT_REGESTRY[i]["type"], INTERNAL_COMPONENT_REGESTRY[i]["object"]
else
return
end
end
end
function _VG.component.getFirst(type)
local object={}
for i,v in pairs(INTERNAL_COMPONENT_REGESTRY) do
if INTERNAL_COMPONENT_REGESTRY[tostring(i)].type == type then
object=INTERNAL_COMPONENT_REGESTRY[tostring(i)]
if INTERNAL_COMPONENT_REGESTRY[i].type == type then
object=INTERNAL_COMPONENT_REGESTRY[i]
break
end
end
return object.object
return object["object"]
end
for i,v in ipairs(fs.list("/AceVM/components/")) do
@@ -99,4 +110,31 @@ local file=fs.open("/computers/0/bios.lua","r")
local bios=file.readAll()
file.close()
file=nil
load(bios,"@bios",nil,_VG)()
local func = load(bios,"@bios",nil,_VG)
if not func then error("BIOS ERR") end
local BIOS_CORO = coroutine.create(func)
debug.sethook(BIOS_CORO, function() coroutine.yield("CC:TWEAKED", "CORO_TIMEOUT") end, "l", 20)
while true do
local ret = {coroutine.resume(BIOS_CORO)}
if ret[1] == false then
os.shutdown()
end
local timer = os.startTimer(0)
local exit = false
repeat
local event = {coroutine.yield()}
if event[1] == "timer" and event[2] == timer then
exit=true
elseif event[1]=="timer"or nil then
elseif event[1]=="key" then
addEventRaw("keyPressed", 1, event[2])
if akeys[event[2]] then
addEventRaw("keyTyped", 1, keys[event[2]])
end
elseif event[1]=="char" then
addEventRaw("keyTyped", 1, event[2])
elseif event[1]=="key_up" then
addEventRaw("keyReleased", 1, event[2])
end
until exit
end