This commit is contained in:
Jeeves 2024-04-22 11:38:03 -06:00
parent 9155b5a686
commit d4a3a6fb77

View file

@ -48,10 +48,11 @@ pub fn main() !void {
} }
pub const Uxn = struct { pub const Uxn = struct {
mem: Memory, mem: Memory = .{ .m = undefined },
ws: Stack, ws: Stack = .{ .s = undefined },
rs: Stack, rs: Stack = .{ .s = undefined },
pc: u16, pc: u16,
dev: [0x100]u8,
const Memory = struct { const Memory = struct {
m: [0x10000]u8, m: [0x10000]u8,
@ -491,11 +492,6 @@ pub const Uxn = struct {
fn ldz(self: *Uxn, stack: *Stack, comptime T: type, comptime keep: bool) void { fn ldz(self: *Uxn, stack: *Stack, comptime T: type, comptime keep: bool) void {
const addr = if (keep) stack.peek(u8) else stack.pop(u8); const addr = if (keep) stack.peek(u8) else stack.pop(u8);
stack.push(T, self.mem.peek(T, addr)); stack.push(T, self.mem.peek(T, addr));
// switch (T) {
// u8 => stack.push(T, self.mem[addr]),
// u16 => {},
// else => unreachable,
// }
} }
fn stz(self: *Uxn, stack: *Stack, comptime T: type, comptime keep: bool) void { fn stz(self: *Uxn, stack: *Stack, comptime T: type, comptime keep: bool) void {
@ -615,3 +611,22 @@ test "stack push/pop" {
try std.testing.expectEqual(0xAA, stack.pop(u8)); try std.testing.expectEqual(0xAA, stack.pop(u8));
try std.testing.expectEqual(0xABCD, stack.pop(u16)); try std.testing.expectEqual(0xABCD, stack.pop(u16));
} }
// test "arithmetic instructions" {
// var uxn = Uxn{
// .mem = .{ .m = undefined },
// .ws = .{ .s = undefined },
// .rs = .{ .s = undefined },
// .pc = 0,
// };
// uxn.mem.m[0] = 0x18;
// uxn.mem.m[1] = 0x19;
// uxn.mem.m[2] = 0x1A;
// uxn.mem.m[3] = 0x1B;
// uxn.ws.push(u8, 4);
// uxn.ws.push(u8, 20);
// uxn.ws.push(u8, 6);
// uxn.loop();
// uxn.loop();
// try std.testing.expectEqual(18, uxn.ws.pop(u8));
// }