This commit is contained in:
IonutParau 2025-07-03 12:25:54 +02:00
commit 3b733e0708
15 changed files with 57 additions and 97 deletions

2
.gitignore vendored
View File

@ -3,4 +3,4 @@ zig-out/
!data/.gitkeep !data/.gitkeep
.vscode/ .vscode/
raylib/ raylib/
lua/ *.log

View File

@ -1,6 +1,5 @@
# Parity with Vanilla OC (only the stuff that makes sense for an emulator) # Parity with Vanilla OC (only the stuff that makes sense for an emulator)
- Unmanaged drives (the `drive` component)
- `computer` component - `computer` component
- `modem` component - `modem` component
- `tunnel` component - `tunnel` component

View File

@ -63,6 +63,13 @@ fn compileTheRightLua(b: *std.Build, c: *std.Build.Step.Compile, version: LuaVer
.files = files.items, .files = files.items,
}); });
} }
fn getSharedEngineName(os: std.Target.Os.Tag) []const u8 {
if (os == .windows) {
return "neonucleusdll";
} else {
return "neonucleus";
}
}
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const os = builtin.target.os.tag; const os = builtin.target.os.tag;
@ -80,27 +87,21 @@ pub fn build(b: *std.Build) void {
addEngineSources(engineStatic); addEngineSources(engineStatic);
const install = b.getInstallStep();
b.installArtifact(engineStatic);
const engineShared = b.addSharedLibrary(.{ const engineShared = b.addSharedLibrary(.{
.name = "neonucleus", .name = getSharedEngineName(os),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
addEngineSources(engineShared); addEngineSources(engineShared);
b.installArtifact(engineShared);
const engineStep = b.step("engine", "Builds the engine as a static library"); const engineStep = b.step("engine", "Builds the engine as a static library");
engineStep.dependOn(&engineStatic.step); engineStep.dependOn(&engineStatic.step);
engineStep.dependOn(install); engineStep.dependOn(&b.addInstallArtifact(engineStatic, .{}).step);
const sharedStep = b.step("shared", "Builds the engine as a shared library"); const sharedStep = b.step("shared", "Builds the engine as a shared library");
sharedStep.dependOn(&engineShared.step); sharedStep.dependOn(&engineShared.step);
sharedStep.dependOn(install); sharedStep.dependOn(&b.addInstallArtifact(engineShared, .{}).step);
const emulator = b.addExecutable(.{ const emulator = b.addExecutable(.{
.name = "neonucleus", .name = "neonucleus",
@ -110,10 +111,12 @@ pub fn build(b: *std.Build) void {
emulator.linkLibC(); emulator.linkLibC();
if (os == .windows) { if (os == .windows) {
// use the msvc win64 dll versions and copy them to raylib/ and lua/ // use the mingw-w64 version and copy files to raylib/
// get raylib from https://github.com/raysan5/raylib/releases // get raylib from https://github.com/raysan5/raylib/releases
emulator.addIncludePath(b.path("raylib/include")); emulator.addIncludePath(b.path("raylib/include"));
emulator.addObjectFile(b.path("raylib/lib/raylibdll.lib")); emulator.addObjectFile(b.path("raylib/lib/libraylib.a"));
emulator.linkSystemLibrary("GDI32");
emulator.linkSystemLibrary("WinMM");
} else { } else {
emulator.linkSystemLibrary("raylib"); emulator.linkSystemLibrary("raylib");
} }
@ -129,18 +132,18 @@ pub fn build(b: *std.Build) void {
// forces us to link in everything too // forces us to link in everything too
emulator.linkLibrary(engineStatic); emulator.linkLibrary(engineStatic);
b.installArtifact(emulator); const emulatorStep = b.step("emulator", "Builds the emulator");
b.step("emulator", "Builds the emulator").dependOn(&emulator.step); emulatorStep.dependOn(&emulator.step);
emulatorStep.dependOn(&b.addInstallArtifact(emulator, .{}).step);
const run_cmd = b.addRunArtifact(emulator); var run_cmd = b.addRunArtifact(emulator);
run_cmd.step.dependOn(install);
if (b.args) |args| { if (b.args) |args| {
run_cmd.addArgs(args); run_cmd.addArgs(args);
} }
const run_step = b.step("run", "Run the emulator"); const run_step = b.step("run", "Run the emulator");
run_step.dependOn(emulatorStep);
run_step.dependOn(&run_cmd.step); run_step.dependOn(&run_cmd.step);
const lib_unit_tests = b.addTest(.{ const lib_unit_tests = b.addTest(.{

View File

@ -15,6 +15,8 @@ end
local function printRom() local function printRom()
local eeprom = component.eeprom local eeprom = component.eeprom
io.write(eeprom.get()) io.write(eeprom.get())
return nil
end end
local function readRom() local function readRom()
@ -37,6 +39,8 @@ local function readRom()
if not options.q then if not options.q then
io.write("All done!\nThe label is '" .. eeprom.getLabel() .. "'.\n") io.write("All done!\nThe label is '" .. eeprom.getLabel() .. "'.\n")
end end
return nil
end end
local function writeRom() local function writeRom()
@ -60,7 +64,10 @@ local function writeRom()
io.write("Please do NOT power down or restart your computer during this operation!\n") io.write("Please do NOT power down or restart your computer during this operation!\n")
end end
eeprom.set(bios) local result, reason = eeprom.set(bios)
if reason then
return nil, reason
end
local label = args[2] local label = args[2]
if not options.q and not label then if not options.q and not label then
@ -68,7 +75,11 @@ local function writeRom()
label = io.read() label = io.read()
end end
if label and #label > 0 then if label and #label > 0 then
eeprom.setLabel(label) local result, reason = eeprom.setLabel(label)
if reason then
return nil, reason
end
if not options.q then if not options.q then
io.write("Set label to '" .. eeprom.getLabel() .. "'.\n") io.write("Set label to '" .. eeprom.getLabel() .. "'.\n")
end end
@ -77,12 +88,19 @@ local function writeRom()
if not options.q then if not options.q then
io.write("All done! You can remove the EEPROM and re-insert the previous one now.\n") io.write("All done! You can remove the EEPROM and re-insert the previous one now.\n")
end end
return nil
end end
local result, reason
if options.l then if options.l then
printRom() result, reason = printRom()
elseif options.r then elseif options.r then
readRom() result, reason = readRom()
else else
writeRom() result, reason = writeRom()
end
if reason then
io.stderr:write(reason..'\n')
return 1
end end

View File

@ -3,16 +3,11 @@ local tty = require("tty")
local text = require("text") local text = require("text")
local sh = require("sh") local sh = require("sh")
debugprint("a")
local args = shell.parse(...) local args = shell.parse(...)
shell.prime() shell.prime()
debugprint("b")
if #args == 0 then if #args == 0 then
debugprint("c")
local has_profile local has_profile
local input_handler = {hint = sh.hintHandler} local input_handler = {hint = sh.hintHandler}
while true do while true do

View File

@ -73,7 +73,6 @@ end
function component.setPrimary(componentType, address) function component.setPrimary(componentType, address)
checkArg(1, componentType, "string") checkArg(1, componentType, "string")
checkArg(2, address, "string", "nil") checkArg(2, address, "string", "nil")
debugprint("setPrimary", componentType, address)
if address ~= nil then if address ~= nil then
address = component.get(address, componentType) address = component.get(address, componentType)
assert(address, "no such component") assert(address, "no such component")

0
data/OpenOS/etc/edit.cfg Normal file
View File

View File

@ -14,13 +14,10 @@ do
end end
while true do while true do
debugprint("grabbing shell") local result, reason = xpcall(require("shell").getShell(), function(msg)
local result, reason = xpcall(assert(require("shell").getShell()), function(msg)
return tostring(msg).."\n"..debug.traceback() return tostring(msg).."\n"..debug.traceback()
end) end)
debugprint("resumed", result, reason)
if not result then if not result then
debugprint((reason ~= nil and tostring(reason) or "unknown error") .. "\n")
io.stderr:write((reason ~= nil and tostring(reason) or "unknown error") .. "\n") io.stderr:write((reason ~= nil and tostring(reason) or "unknown error") .. "\n")
io.write("Press any key to continue.\n") io.write("Press any key to continue.\n")
os.sleep(0.5) os.sleep(0.5)

View File

@ -1,7 +1,7 @@
-- called from /init.lua -- called from /init.lua
local raw_loadfile = ... local raw_loadfile = ...
_G._OSVERSION = "OpenOS 1.8.8" _G._OSVERSION = "OpenOS 1.8.9"
-- luacheck: globals component computer unicode _OSVERSION -- luacheck: globals component computer unicode _OSVERSION
local component = component local component = component
@ -73,7 +73,12 @@ local function dofile(file)
status("> " .. file) status("> " .. file)
local program, reason = raw_loadfile(file) local program, reason = raw_loadfile(file)
if program then if program then
return program() local result = table.pack(pcall(program))
if result[1] then
return table.unpack(result, 2, result.n)
else
error(result[2])
end
else else
error(reason) error(reason)
end end
@ -139,12 +144,6 @@ end
status("Initializing system...") status("Initializing system...")
require("event").listen("component_added", debugprint)
require("event").listen("component_available", debugprint)
require("event").listen("term_available", debugprint)
computer.pushSignal("init") -- so libs know components are initialized. computer.pushSignal("init") -- so libs know components are initialized.
require("event").pull(1, "init") -- Allow init processing. require("event").pull(1, "init") -- Allow init processing.
--require("tty").bind(component.gpu)
_G.runlevel = 1 _G.runlevel = 1

View File

@ -1,14 +1,8 @@
debugprint("loading cursor")
local unicode = require("unicode") local unicode = require("unicode")
debugprint("loaded unicode")
local kb = require("keyboard") local kb = require("keyboard")
debugprint("loaded keyboard")
local tty = require("tty") local tty = require("tty")
debugprint("loaded tty")
local text = require("text") local text = require("text")
debugprint("loaded text")
local computer = require("computer") local computer = require("computer")
debugprint("loaded computer")
local keys = kb.keys local keys = kb.keys
local core_cursor = {} local core_cursor = {}

View File

@ -143,7 +143,7 @@ function event.pullFiltered(...)
local deadline = computer.uptime() + (seconds or math.huge) local deadline = computer.uptime() + (seconds or math.huge)
repeat repeat
local waitTime = deadline - computer.uptime() local waitTime = deadline - computer.uptime()
if waitTime <= 0 then if waitTime < 0 then
break break
end end
local signal = table.pack(computer.pullSignal(waitTime)) local signal = table.pack(computer.pullSignal(waitTime))

View File

@ -221,7 +221,7 @@ function tty.keyboard()
-- changes to this design should avoid this on every key hit -- changes to this design should avoid this on every key hit
-- this is expensive (slow!) -- this is expensive (slow!)
window.keyboard = assert(component.invoke(screen, "getKeyboards"))[1] or system_keyboard window.keyboard = component.invoke(screen, "getKeyboards")[1] or system_keyboard
end end
return window.keyboard return window.keyboard

View File

@ -1,44 +0,0 @@
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')
boot/91_gpu.lua:14: attempt to call a nil value (field 'getDepth')

View File

@ -1,4 +0,0 @@
@echo off
zig build
copy raylib\lib\raylib.dll zig-out\bin
zig build run

View File

@ -413,6 +413,9 @@ void nni_gpu_getViewport(nni_gpu *gpu, void *_, nn_component *component, nn_comp
nn_return(computer, nn_values_integer(w)); nn_return(computer, nn_values_integer(w));
nn_return(computer, nn_values_integer(h)); nn_return(computer, nn_values_integer(h));
} }
void nni_gpu_getDepth(nni_gpu *gpu, void *_, nn_component *component, nn_computer *computer) {
nn_return(computer, nn_values_integer(8));
}
void nn_loadGraphicsCardTable(nn_universe *universe) { void nn_loadGraphicsCardTable(nn_universe *universe) {
nn_componentTable *gpuTable = nn_newComponentTable(nn_getAllocator(universe), "gpu", NULL, NULL, (void *)nni_gpuDeinit); nn_componentTable *gpuTable = nn_newComponentTable(nn_getAllocator(universe), "gpu", NULL, NULL, (void *)nni_gpuDeinit);
@ -429,6 +432,7 @@ void nn_loadGraphicsCardTable(nn_universe *universe) {
nn_defineMethod(gpuTable, "setForeground", true, (void *)nni_gpu_setForeground, NULL, "setForeground(color: integer, isPalette: boolean): integer, integer? - Sets the current foreground color. Returns the old one and palette index if applicable."); nn_defineMethod(gpuTable, "setForeground", true, (void *)nni_gpu_setForeground, NULL, "setForeground(color: integer, isPalette: boolean): integer, integer? - Sets the current foreground color. Returns the old one and palette index if applicable.");
nn_defineMethod(gpuTable, "getBackground", true, (void *)nni_gpu_getBackground, NULL, "setBackground(color: integer, isPalette: boolean): integer, integer? - Sets the current background color. Returns the old one and palette index if applicable."); nn_defineMethod(gpuTable, "getBackground", true, (void *)nni_gpu_getBackground, NULL, "setBackground(color: integer, isPalette: boolean): integer, integer? - Sets the current background color. Returns the old one and palette index if applicable.");
nn_defineMethod(gpuTable, "getForeground", true, (void *)nni_gpu_getForeground, NULL, "setForeground(color: integer, isPalette: boolean): integer, integer? - Sets the current foreground color. Returns the old one and palette index if applicable."); nn_defineMethod(gpuTable, "getForeground", true, (void *)nni_gpu_getForeground, NULL, "setForeground(color: integer, isPalette: boolean): integer, integer? - Sets the current foreground color. Returns the old one and palette index if applicable.");
nn_defineMethod(gpuTable, "getDepth", true, (void *)nni_gpu_getDepth, NULL, "getDepth(): number - The currently set color depth of the GPU/screen, in bits. Can be 1, 4 or 8.");
nn_defineMethod(gpuTable, "fill", true, (void *)nni_gpu_fill, NULL, "fill(x: integer, y: integer, w: integer, h: integer, s: string)"); nn_defineMethod(gpuTable, "fill", true, (void *)nni_gpu_fill, NULL, "fill(x: integer, y: integer, w: integer, h: integer, s: string)");
nn_defineMethod(gpuTable, "copy", true, (void *)nni_gpu_copy, NULL, "copy(x: integer, y: integer, w: integer, h: integer, tx: integer, ty: integer) - Copies stuff"); nn_defineMethod(gpuTable, "copy", true, (void *)nni_gpu_copy, NULL, "copy(x: integer, y: integer, w: integer, h: integer, tx: integer, ty: integer) - Copies stuff");
nn_defineMethod(gpuTable, "getViewport", true, (void *)nni_gpu_getViewport, NULL, "getViewport(): integer, integer - Gets the current viewport resolution"); nn_defineMethod(gpuTable, "getViewport", true, (void *)nni_gpu_getViewport, NULL, "getViewport(): integer, integer - Gets the current viewport resolution");