From f38116fd507c2949e2ea5ce79530a46458268227 Mon Sep 17 00:00:00 2001 From: speedy-lex <78314533+speedy-lex@users.noreply.github.com> Date: Wed, 2 Jul 2025 16:43:42 +0200 Subject: [PATCH 1/7] fix the build script --- build.zig | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/build.zig b/build.zig index 127d871..840f553 100644 --- a/build.zig +++ b/build.zig @@ -80,10 +80,6 @@ pub fn build(b: *std.Build) void { addEngineSources(engineStatic); - const install = b.getInstallStep(); - - b.installArtifact(engineStatic); - const engineShared = b.addSharedLibrary(.{ .name = "neonucleus", .target = target, @@ -92,15 +88,11 @@ pub fn build(b: *std.Build) void { addEngineSources(engineShared); - b.installArtifact(engineShared); - const engineStep = b.step("engine", "Builds the engine as a static library"); engineStep.dependOn(&engineStatic.step); - engineStep.dependOn(install); const sharedStep = b.step("shared", "Builds the engine as a shared library"); sharedStep.dependOn(&engineShared.step); - sharedStep.dependOn(install); const emulator = b.addExecutable(.{ .name = "neonucleus", @@ -129,13 +121,10 @@ pub fn build(b: *std.Build) void { // forces us to link in everything too emulator.linkLibrary(engineStatic); - b.installArtifact(emulator); b.step("emulator", "Builds the emulator").dependOn(&emulator.step); const run_cmd = b.addRunArtifact(emulator); - run_cmd.step.dependOn(install); - if (b.args) |args| { run_cmd.addArgs(args); } From 1f2b9bedcaed2e96f2f689c68eb709759aed0348 Mon Sep 17 00:00:00 2001 From: Speedy_Lex <78314533+speedy-lex@users.noreply.github.com> Date: Thu, 3 Jul 2025 00:03:40 +0200 Subject: [PATCH 2/7] make the build script great again --- build.zig | 31 ++++++++++++++++++++++++++++--- run.bat | 4 ---- 2 files changed, 28 insertions(+), 7 deletions(-) delete mode 100644 run.bat diff --git a/build.zig b/build.zig index 840f553..75f25d1 100644 --- a/build.zig +++ b/build.zig @@ -63,6 +63,23 @@ fn compileTheRightLua(b: *std.Build, c: *std.Build.Step.Compile, version: LuaVer .files = files.items, }); } +fn addRunArtifact(b: *std.Build, os: std.Target.Os.Tag, exe: *std.Build.Step.Compile) *std.Build.Step.Run { + if (os == .windows) { + // do this so that windows can find dll's + return b.addSystemCommand(&[_][]const u8{ + b.getInstallPath(.bin, exe.name), + }); + } else { + return b.addRunArtifact(exe); + } +} +fn getSharedEngineName(os: std.Target.Os.Tag) []const u8 { + if (os == .windows) { + return "neonucleusdll"; + } else { + return "neonucleus"; + } +} pub fn build(b: *std.Build) void { const os = builtin.target.os.tag; @@ -81,7 +98,7 @@ pub fn build(b: *std.Build) void { addEngineSources(engineStatic); const engineShared = b.addSharedLibrary(.{ - .name = "neonucleus", + .name = getSharedEngineName(os), .target = target, .optimize = optimize, }); @@ -90,9 +107,11 @@ pub fn build(b: *std.Build) void { const engineStep = b.step("engine", "Builds the engine as a static library"); engineStep.dependOn(&engineStatic.step); + engineStep.dependOn(&b.addInstallArtifact(engineStatic, .{}).step); const sharedStep = b.step("shared", "Builds the engine as a shared library"); sharedStep.dependOn(&engineShared.step); + sharedStep.dependOn(&b.addInstallArtifact(engineShared, .{}).step); const emulator = b.addExecutable(.{ .name = "neonucleus", @@ -121,15 +140,21 @@ pub fn build(b: *std.Build) void { // forces us to link in everything too emulator.linkLibrary(engineStatic); - b.step("emulator", "Builds the emulator").dependOn(&emulator.step); + const emulatorStep = b.step("emulator", "Builds the emulator"); + emulatorStep.dependOn(&emulator.step); + emulatorStep.dependOn(&b.addInstallArtifact(emulator, .{}).step); + if (os == .windows) { + emulatorStep.dependOn(&b.addInstallBinFile(b.path("raylib/lib/raylib.dll"), "raylib.dll").step); + } - const run_cmd = b.addRunArtifact(emulator); + var run_cmd = addRunArtifact(b, os, emulator); if (b.args) |args| { run_cmd.addArgs(args); } const run_step = b.step("run", "Run the emulator"); + run_step.dependOn(emulatorStep); run_step.dependOn(&run_cmd.step); const lib_unit_tests = b.addTest(.{ diff --git a/run.bat b/run.bat deleted file mode 100644 index 620dd00..0000000 --- a/run.bat +++ /dev/null @@ -1,4 +0,0 @@ -@echo off -zig build -copy raylib\lib\raylib.dll zig-out\bin -zig build run \ No newline at end of file From 8a21766a2a0a359d8b1fa8dbea8248c98e21b14a Mon Sep 17 00:00:00 2001 From: Speedy_Lex <78314533+speedy-lex@users.noreply.github.com> Date: Thu, 3 Jul 2025 00:20:52 +0200 Subject: [PATCH 3/7] update .gitignore --- .gitignore | 2 +- data/OpenOS/tmp/event.log | 42 --------------------------------------- 2 files changed, 1 insertion(+), 43 deletions(-) delete mode 100644 data/OpenOS/tmp/event.log diff --git a/.gitignore b/.gitignore index d4f39c6..8b001d3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ zig-out/ !data/.gitkeep .vscode/ raylib/ -lua/ +*.log diff --git a/data/OpenOS/tmp/event.log b/data/OpenOS/tmp/event.log deleted file mode 100644 index 6fc1027..0000000 --- a/data/OpenOS/tmp/event.log +++ /dev/null @@ -1,42 +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') From 0e82beb6f600ae102b03004b1e78c4ee5fe59be3 Mon Sep 17 00:00:00 2001 From: Speedy_Lex <78314533+speedy-lex@users.noreply.github.com> Date: Thu, 3 Jul 2025 00:24:17 +0200 Subject: [PATCH 4/7] check off drive component from TODO.md --- TODO.md | 1 - 1 file changed, 1 deletion(-) diff --git a/TODO.md b/TODO.md index 0c8e139..dda476a 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,5 @@ # Parity with Vanilla OC (only the stuff that makes sense for an emulator) -- Unmanaged drives (the `drive` component) - `computer` component - `modem` component - `tunnel` component From f8eb00c05d07b953e1c646292e4d7ddd5a4c839a Mon Sep 17 00:00:00 2001 From: Speedy_Lex <78314533+speedy-lex@users.noreply.github.com> Date: Thu, 3 Jul 2025 10:23:01 +0200 Subject: [PATCH 5/7] fix gpu + update openos --- data/OpenOS/bin/flash.lua | 28 +++++++++++++++++++++++----- data/OpenOS/bin/sh.lua | 5 ----- data/OpenOS/boot/04_component.lua | 1 - data/OpenOS/init.lua | 5 +---- data/OpenOS/lib/core/boot.lua | 15 +++++++-------- data/OpenOS/lib/core/cursor.lua | 6 ------ data/OpenOS/lib/event.lua | 2 +- data/OpenOS/lib/tty.lua | 2 +- src/components/gpu.c | 4 ++++ 9 files changed, 37 insertions(+), 31 deletions(-) diff --git a/data/OpenOS/bin/flash.lua b/data/OpenOS/bin/flash.lua index f8ecf47..13e080e 100644 --- a/data/OpenOS/bin/flash.lua +++ b/data/OpenOS/bin/flash.lua @@ -15,6 +15,8 @@ end local function printRom() local eeprom = component.eeprom io.write(eeprom.get()) + + return nil end local function readRom() @@ -37,6 +39,8 @@ local function readRom() if not options.q then io.write("All done!\nThe label is '" .. eeprom.getLabel() .. "'.\n") end + + return nil end 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") end - eeprom.set(bios) + local result, reason = eeprom.set(bios) + if reason then + return nil, reason + end local label = args[2] if not options.q and not label then @@ -68,7 +75,11 @@ local function writeRom() label = io.read() end 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 io.write("Set label to '" .. eeprom.getLabel() .. "'.\n") end @@ -77,12 +88,19 @@ local function writeRom() if not options.q then io.write("All done! You can remove the EEPROM and re-insert the previous one now.\n") end + + return nil end +local result, reason if options.l then - printRom() + result, reason = printRom() elseif options.r then - readRom() + result, reason = readRom() else - writeRom() + result, reason = writeRom() end +if reason then + io.stderr:write(reason..'\n') + return 1 +end \ No newline at end of file diff --git a/data/OpenOS/bin/sh.lua b/data/OpenOS/bin/sh.lua index 9f882e9..d4e4dd9 100644 --- a/data/OpenOS/bin/sh.lua +++ b/data/OpenOS/bin/sh.lua @@ -3,16 +3,11 @@ local tty = require("tty") local text = require("text") local sh = require("sh") -debugprint("a") - local args = shell.parse(...) shell.prime() -debugprint("b") - if #args == 0 then - debugprint("c") local has_profile local input_handler = {hint = sh.hintHandler} while true do diff --git a/data/OpenOS/boot/04_component.lua b/data/OpenOS/boot/04_component.lua index 177c39a..14da828 100644 --- a/data/OpenOS/boot/04_component.lua +++ b/data/OpenOS/boot/04_component.lua @@ -73,7 +73,6 @@ end function component.setPrimary(componentType, address) checkArg(1, componentType, "string") checkArg(2, address, "string", "nil") - debugprint("setPrimary", componentType, address) if address ~= nil then address = component.get(address, componentType) assert(address, "no such component") diff --git a/data/OpenOS/init.lua b/data/OpenOS/init.lua index 59a8973..ef35e5f 100644 --- a/data/OpenOS/init.lua +++ b/data/OpenOS/init.lua @@ -14,13 +14,10 @@ do end while true do - debugprint("grabbing shell") - local result, reason = xpcall(assert(require("shell").getShell()), function(msg) + local result, reason = xpcall(require("shell").getShell(), function(msg) return tostring(msg).."\n"..debug.traceback() end) - debugprint("resumed", result, reason) 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.write("Press any key to continue.\n") os.sleep(0.5) diff --git a/data/OpenOS/lib/core/boot.lua b/data/OpenOS/lib/core/boot.lua index ec83d87..34c966c 100644 --- a/data/OpenOS/lib/core/boot.lua +++ b/data/OpenOS/lib/core/boot.lua @@ -1,7 +1,7 @@ -- called from /init.lua local raw_loadfile = ... -_G._OSVERSION = "OpenOS 1.8.8" +_G._OSVERSION = "OpenOS 1.8.9" -- luacheck: globals component computer unicode _OSVERSION local component = component @@ -73,7 +73,12 @@ local function dofile(file) status("> " .. file) local program, reason = raw_loadfile(file) 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 error(reason) end @@ -139,12 +144,6 @@ end 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. require("event").pull(1, "init") -- Allow init processing. - -require("tty").bind(component.gpu) _G.runlevel = 1 diff --git a/data/OpenOS/lib/core/cursor.lua b/data/OpenOS/lib/core/cursor.lua index 5f337d9..a8aff3a 100644 --- a/data/OpenOS/lib/core/cursor.lua +++ b/data/OpenOS/lib/core/cursor.lua @@ -1,14 +1,8 @@ -debugprint("loading cursor") local unicode = require("unicode") -debugprint("loaded unicode") local kb = require("keyboard") -debugprint("loaded keyboard") local tty = require("tty") -debugprint("loaded tty") local text = require("text") -debugprint("loaded text") local computer = require("computer") -debugprint("loaded computer") local keys = kb.keys local core_cursor = {} diff --git a/data/OpenOS/lib/event.lua b/data/OpenOS/lib/event.lua index 1ad8b46..7c7ab7e 100644 --- a/data/OpenOS/lib/event.lua +++ b/data/OpenOS/lib/event.lua @@ -143,7 +143,7 @@ function event.pullFiltered(...) local deadline = computer.uptime() + (seconds or math.huge) repeat local waitTime = deadline - computer.uptime() - if waitTime <= 0 then + if waitTime < 0 then break end local signal = table.pack(computer.pullSignal(waitTime)) diff --git a/data/OpenOS/lib/tty.lua b/data/OpenOS/lib/tty.lua index 8248e02..455307b 100644 --- a/data/OpenOS/lib/tty.lua +++ b/data/OpenOS/lib/tty.lua @@ -221,7 +221,7 @@ function tty.keyboard() -- changes to this design should avoid this on every key hit -- 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 return window.keyboard diff --git a/src/components/gpu.c b/src/components/gpu.c index c46aaf1..0e71d6e 100644 --- a/src/components/gpu.c +++ b/src/components/gpu.c @@ -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(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) { 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, "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, "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, "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"); From 21129aab20cdba7730e7d62b3b89ed791efa4d77 Mon Sep 17 00:00:00 2001 From: Speedy_Lex <78314533+speedy-lex@users.noreply.github.com> Date: Thu, 3 Jul 2025 10:39:16 +0200 Subject: [PATCH 6/7] fix windows build order --- build.zig | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/build.zig b/build.zig index 75f25d1..d997247 100644 --- a/build.zig +++ b/build.zig @@ -66,9 +66,13 @@ fn compileTheRightLua(b: *std.Build, c: *std.Build.Step.Compile, version: LuaVer fn addRunArtifact(b: *std.Build, os: std.Target.Os.Tag, exe: *std.Build.Step.Compile) *std.Build.Step.Run { if (os == .windows) { // do this so that windows can find dll's - return b.addSystemCommand(&[_][]const u8{ - b.getInstallPath(.bin, exe.name), - }); + const installed = b.addInstallArtifact(exe, .{}); + + // run the installed executable by path + const exe_path = b.getInstallPath(.bin, exe.name); + const run_cmd = b.addSystemCommand(&[_][]const u8{exe_path}); + run_cmd.step.dependOn(&installed.step); + return run_cmd; } else { return b.addRunArtifact(exe); } From e422013538aa057d6108f812ec5249d8002feee2 Mon Sep 17 00:00:00 2001 From: Speedy_Lex <78314533+speedy-lex@users.noreply.github.com> Date: Thu, 3 Jul 2025 12:06:26 +0200 Subject: [PATCH 7/7] static link raylib --- build.zig | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/build.zig b/build.zig index d997247..b84206d 100644 --- a/build.zig +++ b/build.zig @@ -63,20 +63,6 @@ fn compileTheRightLua(b: *std.Build, c: *std.Build.Step.Compile, version: LuaVer .files = files.items, }); } -fn addRunArtifact(b: *std.Build, os: std.Target.Os.Tag, exe: *std.Build.Step.Compile) *std.Build.Step.Run { - if (os == .windows) { - // do this so that windows can find dll's - const installed = b.addInstallArtifact(exe, .{}); - - // run the installed executable by path - const exe_path = b.getInstallPath(.bin, exe.name); - const run_cmd = b.addSystemCommand(&[_][]const u8{exe_path}); - run_cmd.step.dependOn(&installed.step); - return run_cmd; - } else { - return b.addRunArtifact(exe); - } -} fn getSharedEngineName(os: std.Target.Os.Tag) []const u8 { if (os == .windows) { return "neonucleusdll"; @@ -125,10 +111,12 @@ pub fn build(b: *std.Build) void { emulator.linkLibC(); 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 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 { emulator.linkSystemLibrary("raylib"); } @@ -147,11 +135,8 @@ pub fn build(b: *std.Build) void { const emulatorStep = b.step("emulator", "Builds the emulator"); emulatorStep.dependOn(&emulator.step); emulatorStep.dependOn(&b.addInstallArtifact(emulator, .{}).step); - if (os == .windows) { - emulatorStep.dependOn(&b.addInstallBinFile(b.path("raylib/lib/raylib.dll"), "raylib.dll").step); - } - var run_cmd = addRunArtifact(b, os, emulator); + var run_cmd = b.addRunArtifact(emulator); if (b.args) |args| { run_cmd.addArgs(args);