2024-04-20 06:05:30 -06:00
|
|
|
const std = @import("std");
|
|
|
|
|
2024-04-22 13:55:32 -06:00
|
|
|
const Uxn = @import("uxn.zig");
|
2025-03-04 19:18:44 -07:00
|
|
|
// TODO combine with uxn.zig
|
2024-04-24 08:13:45 -06:00
|
|
|
const UxnFmt = @import("uxn-instructions.zig");
|
2024-04-22 13:55:32 -06:00
|
|
|
|
2024-04-20 06:05:30 -06:00
|
|
|
pub fn main() !void {
|
2024-04-21 07:04:15 -06:00
|
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
|
|
defer _ = gpa.deinit();
|
|
|
|
const allocator = gpa.allocator();
|
|
|
|
|
|
|
|
var args = try std.process.argsWithAllocator(allocator);
|
|
|
|
defer args.deinit();
|
|
|
|
_ = args.next();
|
|
|
|
const rom_path = args.next();
|
|
|
|
|
|
|
|
if (rom_path) |path| {
|
|
|
|
var file = try std.fs.cwd().openFile(path, .{});
|
|
|
|
defer file.close();
|
2024-04-22 10:55:25 -06:00
|
|
|
const rom = try file.readToEndAlloc(allocator, 0xFF00);
|
2024-04-21 07:04:15 -06:00
|
|
|
defer allocator.free(rom);
|
|
|
|
|
2024-04-22 13:55:32 -06:00
|
|
|
var uxn = Uxn{ .pc = 0x100 };
|
|
|
|
@memcpy(uxn.mem.m[0x100 .. rom.len + 0x100], rom);
|
2024-04-20 06:05:30 -06:00
|
|
|
|
2024-04-22 02:48:55 -06:00
|
|
|
var running = true;
|
|
|
|
while (running) {
|
2024-04-24 08:13:45 -06:00
|
|
|
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]) });
|
2024-04-22 13:55:32 -06:00
|
|
|
if (uxn.eval()) running = false;
|
2024-04-22 02:48:55 -06:00
|
|
|
}
|
2024-04-21 07:04:15 -06:00
|
|
|
} else return error.NoRom;
|
2024-04-20 06:05:30 -06:00
|
|
|
}
|