From 0e5ca8a5743cff877fd84e0a18d02e669c3af5b0 Mon Sep 17 00:00:00 2001 From: Jeeves Date: Sun, 21 Apr 2024 07:04:15 -0600 Subject: [PATCH] rom arg --- src/main.zig | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/main.zig b/src/main.zig index ddf1e74..96b0187 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,21 +1,34 @@ const std = @import("std"); pub fn main() !void { - // var gpa = std.heap.GeneralPurposeAllocator(.{}){}; - // defer _ = gpa.deinit(); - // const allocator = gpa.allocator(); + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + defer _ = gpa.deinit(); + const allocator = gpa.allocator(); - const mem: [0xFFFF]u8 = undefined; - const ws: [0xFF]u8 = undefined; - const rs: [0xFF]u8 = undefined; - var uxn = Uxn{ - .mem = .{ .m = mem }, - .ws = .{ .s = ws }, - .rs = .{ .s = rs }, - .pc = 0x100, - }; + var args = try std.process.argsWithAllocator(allocator); + defer args.deinit(); + _ = args.next(); + const rom_path = args.next(); - while (true) uxn.loop(); + if (rom_path) |path| { + var file = try std.fs.cwd().openFile(path, .{}); + defer file.close(); + const rom = try file.readToEndAlloc(allocator, 0xFFFF); + defer allocator.free(rom); + + const mem: [0xFFFF]u8 = undefined; + const ws: [0xFF]u8 = undefined; + const rs: [0xFF]u8 = undefined; + var uxn = Uxn{ + .mem = .{ .m = mem }, + .ws = .{ .s = ws }, + .rs = .{ .s = rs }, + .pc = 0x100, + }; + @memcpy(uxn.mem.m[0x100 .. 0x100 + rom.len], rom); + + while (true) uxn.loop(); + } else return error.NoRom; } pub const Uxn = struct {