diff --git a/.gitignore b/.gitignore index f27e682..feda423 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,6 @@ # Cheers! # -andrewrk -.zig-cache/ zig-cache/ zig-out/ /release/ diff --git a/build.zig b/build.zig index 3de63f4..dd1b4a6 100644 --- a/build.zig +++ b/build.zig @@ -4,16 +4,27 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const exe_mod = b.createModule(.{ - .root_source_file = b.path("src/main.zig"), + const silkdot = b.dependency("silkdot", .{ .target = target, .optimize = optimize, }); + // const lib = b.addStaticLibrary(.{ + // .name = "uzn", + // .root_source_file = b.path("src/root.zig"), + // .target = target, + // .optimize = optimize, + // }); + + // b.installArtifact(lib); + const exe = b.addExecutable(.{ .name = "uzn", - .root_module = exe_mod, + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, }); + exe.root_module.addImport("silkdot", silkdot.module("silkdot")); b.installArtifact(exe); const run_cmd = b.addRunArtifact(exe); @@ -21,16 +32,22 @@ pub fn build(b: *std.Build) void { if (b.args) |args| { run_cmd.addArgs(args); } - const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); + // const lib_unit_tests = b.addTest(.{ + // .root_source_file = b.path("src/root.zig"), + // .target = target, + // .optimize = optimize, + // }); + // const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); const exe_unit_tests = b.addTest(.{ - .root_module = exe_mod, + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, }); - const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests); - const test_step = b.step("test", "Run unit tests"); + // test_step.dependOn(&run_lib_unit_tests.step); test_step.dependOn(&run_exe_unit_tests.step); } diff --git a/build.zig.zon b/build.zig.zon index f353f37..fcb7c22 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,11 +1,70 @@ .{ .name = "uzn", + // This is a [Semantic Version](https://semver.org/). + // In a future version of Zig it will be used for package deduplication. .version = "0.0.0", - .minimum_zig_version = "0.14.0", - .dependencies = .{}, + + // This field is optional. + // This is currently advisory only; Zig does not yet do anything + // with this value. + //.minimum_zig_version = "0.11.0", + + // This field is optional. + // Each dependency must either provide a `url` and `hash`, or a `path`. + // `zig build --fetch` can be used to fetch all dependencies of a package, recursively. + // Once all dependencies are fetched, `zig build` no longer requires + // internet connectivity. + .dependencies = .{ + // See `zig fetch --save ` for a command-line interface for adding dependencies. + //.example = .{ + // // When updating this field to a new URL, be sure to delete the corresponding + // // `hash`, otherwise you are communicating that you expect to find the old hash at + // // the new URL. + // .url = "https://example.com/foo.tar.gz", + // + // // This is computed from the file contents of the directory of files that is + // // obtained after fetching `url` and applying the inclusion rules given by + // // `paths`. + // // + // // This field is the source of truth; packages do not come from a `url`; they + // // come from a `hash`. `url` is just one of many possible mirrors for how to + // // obtain a package matching this `hash`. + // // + // // Uses the [multihash](https://multiformats.io/multihash/) format. + // .hash = "...", + // + // // When this is provided, the package is found in a directory relative to the + // // build root. In this case the package's hash is irrelevant and therefore not + // // computed. This field and `url` are mutually exclusive. + // .path = "foo", + + // // When this is set to `true`, a package is declared to be lazily + // // fetched. This makes the dependency only get fetched if it is + // // actually used. + // .lazy = false, + //}, + .silkdot = .{ + .path = "../silkdot/", + }, + }, + + // Specifies the set of files and directories that are included in this package. + // Only files and directories listed here are included in the `hash` that + // is computed for this package. + // Paths are relative to the build root. Use the empty string (`""`) to refer to + // the build root itself. + // A directory listed here means that all files within, recursively, are included. .paths = .{ - "build.zig", - "build.zig.zon", - "src", + // This makes *all* files, recursively, included in this package. It is generally + // better to explicitly list the files and directories instead, to insure that + // fetching from tarballs, file system paths, and version control all result + // in the same contents hash. + "", + // For example... + //"build.zig", + //"build.zig.zon", + //"src", + //"LICENSE", + //"README.md", }, } diff --git a/flake.lock b/flake.lock index eed7c6e..db69ff2 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", "owner": "numtide", "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", "type": "github" }, "original": { @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1736817698, - "narHash": "sha256-1m+JP9RUsbeLVv/tF1DX3Ew9Vl/fatXnlh/g5k3jcSk=", + "lastModified": 1706063522, + "narHash": "sha256-o1m9en7ovSjyktXgX3n/6GJEwG06WYa/9Mfx5hTTf5g=", "owner": "nixos", "repo": "nixpkgs", - "rev": "2b1fca3296ddd1602d2c4f104a4050e006f4b0cb", + "rev": "95c1439b205d507f3cb88aae76e02cd6a01ac504", "type": "github" }, "original": { @@ -59,11 +59,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1740793510, - "narHash": "sha256-Jy/2/jTaoMXphijdV7v0zHc/ckBvz4ooYSKMdq54Sik=", + "lastModified": 1713576181, + "narHash": "sha256-vYvot66I7+58YjWaQldcZfNh4H2Mj2eE+PpYTjncBac=", "owner": "Cloudef", "repo": "zig2nix", - "rev": "6bd6fa7031ca0836490ccfcdc8414dd7fb12cfb5", + "rev": "59edca8316d1c395ac05474489b8ea9f26ebd53c", "type": "github" }, "original": { diff --git a/src/main.zig b/src/main.zig index 6314510..533ad64 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const silkdot = @import("silkdot"); const Uxn = @import("uxn.zig"); const UxnFmt = @import("uxn-instructions.zig"); @@ -22,10 +23,22 @@ pub fn main() !void { var uxn = Uxn{ .pc = 0x100 }; @memcpy(uxn.mem.m[0x100 .. rom.len + 0x100], rom); + // var term = try silkdot.Terminal.init(allocator); + // defer term.deinit(); + var running = true; while (running) { + // const events = try term.getEvents(); + // defer allocator.free(events); + // for (events) |ev| switch (ev) { + // .keyboard => { + // if (ev.keyboard.code == 'q') running = false; + // }, + // else => {}, + // }; std.debug.print("pc={X} code={X} op={s}\n", .{ uxn.pc, uxn.mem.m[uxn.pc], UxnFmt.fmtInstrs(uxn.mem.m[uxn.pc .. uxn.pc +% 1]) }); if (uxn.eval()) running = false; + // try term.draw(); } } else return error.NoRom; } diff --git a/src/uxn.zig b/src/uxn.zig index 1da3114..c81e3cf 100644 --- a/src/uxn.zig +++ b/src/uxn.zig @@ -54,13 +54,13 @@ const Stack = struct { } pub fn pop(self: *Stack, comptime T: type) T { - self.sp -%= @intCast(@divExact(@typeInfo(T).int.bits, 8)); + self.sp -%= @intCast(@divExact(@typeInfo(T).Int.bits, 8)); return self.peek(T); } pub fn push(self: *Stack, comptime T: type, v: T) void { self.poke(T, v); - self.sp +%= @intCast(@divExact(@typeInfo(T).int.bits, 8)); + self.sp +%= @intCast(@divExact(@typeInfo(T).Int.bits, 8)); } }; @@ -458,8 +458,6 @@ fn jsr(self: *Uxn, stack: *Stack, comptime T: type, comptime keep: bool) void { } } -// this one uses a bool instead of a *Stack, because it needs access to both stacks -// TODO now that I think about it, just use a bool everywhere fn sth(self: *Uxn, comptime swap: bool, comptime T: type, comptime keep: bool) void { var src = if (swap) self.rs else self.ws; var dst = if (swap) self.ws else self.rs;