1
0
mirror of https://github.com/Adorable-Catgirl/Zorya-NEO.git synced 2024-11-23 18:58:06 +11:00
Zorya-NEO/mods/vdev_vbios/init.lua

84 lines
1.8 KiB
Lua
Raw Normal View History

2020-03-12 09:19:08 +11:00
local vdev = krequire("util_vcomponent")
local utils = krequire("utils")
local thd = krequire("thd")
local comp = component
local eeprom = {}
local lua_code = [[
--#include "luabios.lua"
]]
2020-03-13 08:01:05 +11:00
--#include "crc32.lua"
2020-03-12 09:19:08 +11:00
local function generate_vbios(f_, path)
local fs = comp.proxy(f_)
if not fs.exists(path) then
fs.makeDirectory(path)
end
if not fs.exists(path.."/code.lua") then
local h = fs.open(path.."/code.lua", "wb")
fs.write(h, lua_code)
fs.close(h)
end
if not fs.exists(path.."/data.bin") then
local h = fs.open(path.."/data.bin", "wb")
fs.write(h, "")
fs.close(h)
end
if not fs.exists(path.."/label.txt") then
local h = fs.open(path.."/label.txt", "wb")
fs.write(h, "Lua BIOS")
fs.close(h)
end
local tbl = {
get = function()
local h = fs.open(path.."/code.lua", "rb")
return utils.readfile(f_, h)
end,
getData = function()
local h = fs.open(path.."/data.bin", "rb")
return utils.readfile(f_, h)
end,
getLabel = function()
local h = fs.open(path.."/label.txt", "rb")
return utils.readfile(f_, h)
end,
set = function(data)
local h = fs.open(path.."/code.lua", "wb")
fs.write(h, data)
fs.close(h)
end,
setData = function(data)
local h = fs.open(path.."/data.bin", "wb")
fs.write(h, data)
fs.close(h)
end,
setLabel = function(label)
local h = fs.open(path.."/label.txt", "wb")
fs.write(h, label:sub(1, 16))
fs.close(h)
end,
getDataSize = function()
return fs.spaceTotal()
end,
getSize = function()
return fs.spaceTotal()
end,
getChecksum = function()
2020-03-13 08:01:05 +11:00
return crc32(tbl.get())
2020-03-12 09:19:08 +11:00
end,
makeReadonly = function()
return
end
}
vdev.register("vdev-ZY_VBIOS", "eeprom", tbl)
local nice = function()
--#include "machine.lua"
end
return nice, tbl
end
return generate_vbios