-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.zig
31 lines (26 loc) · 851 Bytes
/
main.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const std = @import("std");
const vm = @import("./vm/vm.zig");
const asmlib = @import("./asm/asm.zig");
pub fn main() !void {
if (std.os.argv.len < 3) {
std.debug.print("Usage: run [.rom] or build [.asm]\n", .{});
return;
}
const mode: []const u8 = std.mem.span(std.os.argv[1]);
const file_path: []const u8 = std.mem.span(std.os.argv[2]);
if (std.mem.eql(u8, mode, "build")) {
try asmlib.assemble(std.heap.page_allocator, file_path);
} else if (std.mem.eql(u8, mode, "run")) {
try run_vm(file_path);
} else {
std.debug.print("Usage: run [.rom] or build [.asm]\n", .{});
return;
}
}
pub fn run_vm(rom_path: []const u8) !void {
var state = try vm.VMState.init(rom_path);
var can_step = true;
while (can_step) {
can_step = try state.step();
}
}