From 9155b5a686802a3b5e6aa4eadedd3ef76465f903 Mon Sep 17 00:00:00 2001 From: Jeeves Date: Mon, 22 Apr 2024 10:55:25 -0600 Subject: [PATCH] stack and mem tests --- src/main.zig | 175 +++++++++------------------------------------------ 1 file changed, 29 insertions(+), 146 deletions(-) diff --git a/src/main.zig b/src/main.zig index 47ac9a2..a75ea3b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -14,7 +14,7 @@ pub fn main() !void { if (rom_path) |path| { var file = try std.fs.cwd().openFile(path, .{}); defer file.close(); - const rom = try file.readToEndAlloc(allocator, 0xFFFF); + const rom = try file.readToEndAlloc(allocator, 0xFF00); defer allocator.free(rom); const mem: [0x10000]u8 = undefined; @@ -59,7 +59,7 @@ pub const Uxn = struct { pub fn peek(self: *Memory, comptime T: type, idx: u16) T { return switch (T) { u8 => self.m[idx], - u16 => self.m[idx], + u16 => @as(u16, @intCast(self.m[idx])) << 8 | self.m[idx +% 1], else => unreachable, }; } @@ -67,7 +67,10 @@ pub const Uxn = struct { pub fn poke(self: *Memory, comptime T: type, idx: u16, val: T) void { switch (T) { u8 => self.m[idx] = val, - u16 => {}, + u16 => { + self.m[idx] = @truncate(val >> 8); + self.m[idx +% 1] = @truncate(val & 0xFF); + }, else => unreachable, } } @@ -80,7 +83,7 @@ pub const Uxn = struct { pub fn peek(self: *Stack, comptime T: type) T { return switch (T) { u8 => self.s[self.sp], - u16 => @intCast(self.s[self.sp]), // but actually do the conversion + u16 => @as(u16, @intCast(self.s[self.sp])) << 8 | self.s[self.sp +% 1], else => unreachable, }; } @@ -88,37 +91,22 @@ pub const Uxn = struct { pub fn poke(self: *Stack, comptime T: type, v: T) void { switch (T) { u8 => self.s[self.sp] = v, - u16 => {}, + u16 => { + self.s[self.sp] = @truncate(v >> 8); + self.s[self.sp +% 1] = @truncate(v & 0xFF); + }, else => unreachable, } } pub fn pop(self: *Stack, comptime T: type) T { - switch (T) { - u8 => { - self.sp -%= 1; - return self.s[self.sp +% 1]; - }, - u16 => { - self.sp -%= 2; - return self.s[self.sp +% 1]; - }, - else => unreachable, - } + self.sp -%= @intCast(@divExact(@typeInfo(T).Int.bits, 8)); + return self.peek(T); } pub fn push(self: *Stack, comptime T: type, v: T) void { - switch (T) { - u8 => { - self.sp +%= 1; - self.s[self.sp] = v; - }, - u16 => { - self.sp +%= 2; - self.s[self.sp] = @truncate(v); - }, - else => unreachable, - } + self.poke(T, v); + self.sp +%= @intCast(@divExact(@typeInfo(T).Int.bits, 8)); } }; @@ -612,123 +600,18 @@ pub const Uxn = struct { } }; -test "uxnasm" { - const rom = [_]u8{ - 0xa0, 0x01, 0x07, 0x80, 0x10, 0x37, 0x00, 0x80, 0x12, 0x16, 0x06, 0x20, 0x00, 0x05, 0x02, 0x60, - 0x00, 0x65, 0x00, 0x60, 0x00, 0x01, 0x00, 0x80, 0x20, 0x8a, 0x0c, 0x04, 0x02, 0x80, 0x20, 0x07, - 0x80, 0xfb, 0x13, 0x26, 0xa0, 0x20, 0x20, 0x28, 0x20, 0x00, 0x42, 0x80, 0x20, 0x09, 0x20, 0x00, - 0x1c, 0x06, 0x80, 0x5b, 0x08, 0x20, 0x00, 0x1a, 0x06, 0x80, 0x5d, 0x08, 0x20, 0x00, 0x13, 0x06, - 0x80, 0x28, 0x08, 0x20, 0x00, 0x29, 0x06, 0x80, 0x29, 0x08, 0x20, 0x00, 0x22, 0x80, 0x01, 0x20, - 0x00, 0x02, 0x02, 0x6c, 0x80, 0x20, 0x07, 0x80, 0xfb, 0x13, 0x26, 0xa0, 0x20, 0x20, 0x28, 0x20, - 0x00, 0x0b, 0x02, 0x80, 0x00, 0xa0, 0x08, 0x6b, 0xb5, 0x21, 0x80, 0xf9, 0x33, 0x22, 0x6c, 0x80, - 0x28, 0x19, 0xa0, 0x01, 0x4e, 0x15, 0x6c, 0xa0, 0x01, 0x66, 0x34, 0x21, 0x26, 0xa0, 0x04, 0x1a, - 0x35, 0xa0, 0x04, 0x51, 0x35, 0xa0, 0x08, 0x6b, 0x60, 0x04, 0x6d, 0x80, 0x01, 0x60, 0x00, 0x91, - 0x20, 0x00, 0x85, 0x80, 0x00, 0x60, 0x00, 0x89, 0x20, 0x00, 0x7d, 0xa0, 0x80, 0x00, 0x80, 0x62, - 0x30, 0x21, 0x38, 0xa0, 0x81, 0x00, 0x94, 0x80, 0x18, 0x17, 0x21, 0xa9, 0x20, 0xff, 0xf7, 0x22, - 0x22, 0xa0, 0x04, 0x1a, 0x34, 0xa0, 0x04, 0x51, 0x34, 0xa1, 0x21, 0x14, 0x20, 0x00, 0x26, 0xa0, - 0x00, 0x03, 0x38, 0x94, 0x80, 0x41, 0x19, 0x80, 0x1a, 0x0b, 0x20, 0x00, 0x18, 0x26, 0xa0, 0x06, - 0x5e, 0x60, 0x03, 0xd1, 0x20, 0x00, 0x0e, 0xa0, 0x06, 0x52, 0x60, 0x04, 0x3d, 0x26, 0x60, 0x04, - 0x3e, 0xa0, 0x0a, 0x19, 0x17, 0x60, 0x03, 0xb1, 0x21, 0xaa, 0x20, 0xff, 0xcc, 0x22, 0x22, 0xa0, - 0x06, 0x64, 0x60, 0x04, 0x25, 0x80, 0x62, 0x30, 0xa0, 0x00, 0xff, 0x39, 0x60, 0x04, 0x26, 0xa0, - 0x06, 0x74, 0x60, 0x04, 0x15, 0xa0, 0x04, 0x34, 0x34, 0x60, 0x04, 0x19, 0xa0, 0x06, 0x80, 0x60, - 0x04, 0x08, 0xa0, 0x06, 0x7c, 0x60, 0x04, 0x02, 0xa0, 0x80, 0x66, 0x10, 0x1d, 0x80, 0x0f, 0x17, - 0x6c, 0x80, 0x67, 0x11, 0xa0, 0x01, 0x00, 0x60, 0x01, 0x24, 0x80, 0x00, 0xa0, 0x05, 0x6a, 0x15, - 0xa0, 0x06, 0x5e, 0x60, 0x01, 0x94, 0xa0, 0x08, 0x6b, 0x26, 0x80, 0x64, 0x31, 0x26, 0x60, 0x00, - 0x13, 0x80, 0x66, 0x10, 0x20, 0x00, 0x08, 0x60, 0x03, 0x4f, 0x21, 0x94, 0x20, 0xff, 0xea, 0x22, - 0x80, 0x66, 0x10, 0x6c, 0x94, 0x80, 0x08, 0x13, 0xa0, 0x07, 0x6b, 0xa0, 0x07, 0x3b, 0x94, 0x80, - 0x00, 0x09, 0x20, 0x00, 0x04, 0x23, 0x21, 0x34, 0x2c, 0xa0, 0x00, 0x03, 0x38, 0xaa, 0x20, 0xff, - 0xed, 0x22, 0x22, 0x60, 0x02, 0x71, 0x20, 0x00, 0x8f, 0x60, 0x02, 0x81, 0x20, 0x00, 0x6e, 0x40, - 0x00, 0x4e, 0x21, 0x60, 0x01, 0xf3, 0x40, 0x00, 0xc5, 0x21, 0x60, 0x01, 0xec, 0x80, 0x60, 0x30, - 0x38, 0x40, 0x00, 0xba, 0x21, 0x40, 0x01, 0x32, 0x21, 0x60, 0x01, 0x0c, 0x40, 0x01, 0x5a, 0x80, - 0x80, 0x60, 0x00, 0x9b, 0x21, 0x60, 0x02, 0x1b, 0x40, 0x00, 0x94, 0x80, 0x80, 0x60, 0x00, 0x8f, - 0x21, 0x60, 0x01, 0xce, 0x03, 0x40, 0x00, 0x87, 0x80, 0xa0, 0x60, 0x00, 0x82, 0x21, 0x60, 0x01, - 0xc1, 0x40, 0x00, 0x77, 0x21, 0x80, 0x20, 0x40, 0x00, 0x65, 0x21, 0x80, 0x40, 0x40, 0x00, 0x5f, - 0x80, 0x60, 0x40, 0x00, 0x5a, 0x21, 0x40, 0x00, 0x1a, 0x21, 0x40, 0x00, 0x0a, 0x22, 0x40, 0x02, - 0xa1, 0x6c, 0x94, 0x60, 0x00, 0x59, 0x21, 0x94, 0x20, 0xff, 0xf7, 0x22, 0x6c, 0x60, 0x02, 0x1e, - 0x40, 0x00, 0x4c, 0x26, 0x60, 0x02, 0xa7, 0x03, 0x06, 0x80, 0x04, 0x08, 0x80, 0x50, 0x1f, 0x80, - 0x80, 0x1d, 0x60, 0x00, 0x3a, 0x40, 0x00, 0x05, 0x26, 0x60, 0x02, 0x92, 0x03, 0x06, 0x80, 0x02, - 0x09, 0x20, 0x00, 0x08, 0x02, 0x60, 0x02, 0xca, 0x03, 0x40, 0x00, 0x23, 0x80, 0x04, 0x09, 0x20, - 0x00, 0x06, 0x60, 0x02, 0xbd, 0x40, 0x00, 0x13, 0x22, 0xa0, 0x06, 0x9d, 0x40, 0x00, 0x23, 0x60, - 0x00, 0x0d, 0x60, 0x01, 0x4d, 0x80, 0x60, 0x30, 0x21, 0x21, 0x39, 0x04, 0x60, 0x00, 0x00, 0x06, - 0x80, 0x60, 0x30, 0xa1, 0x2f, 0xa0, 0x80, 0x00, 0x38, 0x15, 0x60, 0x00, 0x31, 0x6f, 0x80, 0x60, - 0x31, 0x6c, 0xa0, 0x06, 0x88, 0x60, 0x02, 0xc2, 0x60, 0x02, 0xbf, 0xa0, 0x20, 0x19, 0x17, 0x80, - 0x64, 0x30, 0x60, 0x02, 0xba, 0xa0, 0x06, 0x6f, 0x60, 0x02, 0xaf, 0x80, 0x00, 0x30, 0x60, 0x02, - 0xae, 0xa0, 0x2e, 0x19, 0x17, 0xa0, 0x0a, 0x19, 0x17, 0xa0, 0x01, 0x66, 0x11, 0x6c, 0x20, 0x00, - 0x01, 0x6c, 0x80, 0x67, 0x10, 0x20, 0x00, 0x01, 0x6c, 0x80, 0x60, 0x30, 0x26, 0x07, 0x20, 0x00, - 0x06, 0xa0, 0x06, 0xce, 0x60, 0xff, 0xbb, 0xa0, 0x80, 0x00, 0x2b, 0x20, 0x00, 0x06, 0xa0, 0x06, - 0xa4, 0x60, 0xff, 0xae, 0x80, 0x62, 0x31, 0x6c, 0x26, 0x60, 0x01, 0xf2, 0xa0, 0x00, 0x30, 0x60, - 0x01, 0xec, 0x38, 0xa0, 0x00, 0x30, 0x2b, 0x20, 0x00, 0x06, 0xa0, 0x06, 0xb5, 0x40, 0xff, 0x92, - 0xa0, 0x00, 0x00, 0x60, 0x02, 0x45, 0xa0, 0x00, 0x30, 0x6c, 0x26, 0xc0, 0x00, 0x94, 0x80, 0x2f, - 0x08, 0x20, 0x00, 0x09, 0x94, 0xcf, 0x11, 0x41, 0x21, 0x94, 0x20, 0xff, 0xf0, 0x22, 0x80, 0x00, - 0x4f, 0x11, 0xa0, 0x00, 0x00, 0xa0, 0x00, 0x30, 0x60, 0x02, 0x20, 0xa0, 0x2f, 0x00, 0xa0, 0x00, - 0x30, 0x60, 0x01, 0xa5, 0xa1, 0x80, 0xc9, 0x33, 0x35, 0x80, 0x67, 0x10, 0x20, 0x00, 0x02, 0x22, - 0x6c, 0x60, 0x00, 0xe3, 0x20, 0x00, 0x34, 0x60, 0x00, 0xf3, 0x20, 0x00, 0x2e, 0x26, 0x60, 0x00, - 0x38, 0x21, 0x1d, 0x20, 0x00, 0x2c, 0x80, 0x60, 0x30, 0xa0, 0x00, 0x00, 0xaf, 0x61, 0x61, 0x35, - 0x80, 0x00, 0xef, 0x61, 0x15, 0x26, 0xef, 0x60, 0x01, 0xe1, 0x60, 0x01, 0x71, 0x6f, 0x38, 0x21, - 0x80, 0xe7, 0x33, 0xa0, 0x00, 0x00, 0x21, 0x80, 0xfa, 0x33, 0x6c, 0x22, 0xa0, 0x06, 0xc7, 0x40, - 0xff, 0x10, 0x22, 0xa0, 0x06, 0x93, 0x40, 0xff, 0x09, 0x80, 0x11, 0x33, 0xa0, 0x04, 0x1a, 0x34, - 0xa0, 0x00, 0x00, 0xa8, 0x20, 0x00, 0x16, 0xa0, 0x00, 0x03, 0x38, 0x26, 0xa0, 0x00, 0x00, 0x60, - 0x01, 0x43, 0x20, 0x00, 0x0e, 0x60, 0x01, 0x31, 0x21, 0xaa, 0x20, 0xff, 0xe6, 0x22, 0x22, 0xa0, - 0xff, 0xff, 0x6c, 0xa0, 0x00, 0x03, 0x39, 0x23, 0x6c, 0x60, 0x00, 0x6b, 0x20, 0x01, 0x63, 0x40, - 0x00, 0x11, 0x94, 0x80, 0x7b, 0x09, 0x20, 0x00, 0x04, 0x22, 0x60, 0x00, 0xdc, 0x80, 0x67, 0x10, - 0x20, 0x00, 0x29, 0x94, 0x80, 0x26, 0x09, 0x20, 0x00, 0x04, 0x21, 0x60, 0xff, 0x0a, 0x94, 0x80, - 0x2f, 0x09, 0x20, 0x00, 0x04, 0x21, 0x60, 0xfe, 0xff, 0x60, 0xff, 0x9d, 0xa1, 0xa0, 0x00, 0x00, - 0x28, 0x20, 0x00, 0x09, 0xa1, 0x21, 0x94, 0x01, 0x05, 0x05, 0x15, 0x34, 0x6c, 0xa0, 0x06, 0xab, - 0x40, 0xfe, 0x8f, 0x60, 0xff, 0xbc, 0x80, 0x60, 0x30, 0x21, 0x21, 0x39, 0x26, 0xa0, 0x00, 0x80, - 0x38, 0x02, 0x20, 0x00, 0x02, 0x03, 0x6c, 0x80, 0x67, 0x10, 0x20, 0x00, 0x06, 0xa0, 0x06, 0xbe, - 0x60, 0xfe, 0x6f, 0x22, 0x80, 0xff, 0x6c, 0x26, 0x94, 0x60, 0x00, 0xde, 0x01, 0x20, 0x00, 0x04, - 0x22, 0x80, 0x00, 0x6c, 0x21, 0x94, 0x20, 0xff, 0xef, 0x22, 0x80, 0x01, 0x6c, 0x26, 0x60, 0x00, - 0x0d, 0x20, 0x00, 0x07, 0x26, 0xa0, 0x07, 0x38, 0x40, 0x00, 0xb0, 0x80, 0x01, 0x6c, 0x26, 0x80, - 0x0e, 0x33, 0xa0, 0x20, 0x00, 0x80, 0x00, 0x07, 0x80, 0x03, 0x1a, 0xa0, 0x06, 0xd8, 0x38, 0xa0, - 0x00, 0x00, 0x60, 0x00, 0x96, 0x20, 0x00, 0x0a, 0x01, 0x8a, 0x20, 0xff, 0xe8, 0x22, 0x22, 0x80, - 0x00, 0x6c, 0x03, 0x06, 0x80, 0x00, 0x08, 0x80, 0x70, 0x1f, 0x1d, 0x0f, 0xa0, 0x00, 0x03, 0x38, - 0x94, 0x20, 0x00, 0x03, 0x22, 0x4f, 0x6c, 0x94, 0x80, 0x32, 0x09, 0x20, 0x00, 0x03, 0xc0, 0x20, - 0x5d, 0x94, 0x80, 0x6b, 0x09, 0x20, 0x00, 0x03, 0xc0, 0x80, 0x5d, 0x94, 0x80, 0x72, 0x09, 0x20, - 0x00, 0x03, 0xc0, 0x40, 0x5d, 0x21, 0x40, 0xff, 0xd7, 0x80, 0x00, 0x81, 0x80, 0xfb, 0x13, 0x06, - 0xa0, 0x07, 0x6b, 0xa1, 0x80, 0xfa, 0x33, 0x15, 0x80, 0x21, 0x18, 0x80, 0x18, 0x13, 0xa0, 0x05, - 0x94, 0x6c, 0x80, 0xec, 0x32, 0xa0, 0x00, 0x01, 0x39, 0x94, 0x60, 0xff, 0xeb, 0x60, 0xfe, 0x69, - 0x80, 0xde, 0x33, 0x6c, 0xce, 0xbb, 0x00, 0x00, 0x21, 0x94, 0x20, 0xff, 0xfb, 0x6c, 0x26, 0x60, - 0xff, 0xf7, 0x24, 0x39, 0x6c, 0x2f, 0x94, 0x20, 0x00, 0x05, 0x14, 0x54, 0x4f, 0x08, 0x6c, 0x94, - 0xd4, 0x4f, 0x09, 0x20, 0xff, 0xf4, 0x21, 0x61, 0x40, 0xff, 0xeb, 0x2f, 0xd4, 0x94, 0x4f, 0x09, - 0x20, 0x00, 0x02, 0x61, 0x21, 0x74, 0x34, 0x6f, 0x28, 0x6c, 0x80, 0x30, 0x19, 0x06, 0x80, 0x0a, - 0x0b, 0x20, 0x00, 0x0d, 0x80, 0x27, 0x19, 0x06, 0x80, 0x10, 0x0b, 0x20, 0x00, 0x03, 0x02, 0x80, - 0xff, 0x6c, 0xe0, 0x00, 0x00, 0xc0, 0x40, 0x7f, 0x94, 0x60, 0xff, 0xde, 0xc0, 0x00, 0x0f, 0x78, - 0x21, 0x94, 0x20, 0xff, 0xf0, 0x22, 0x6f, 0x6c, 0x80, 0x00, 0x05, 0x05, 0x94, 0x80, 0x20, 0x0a, - 0x20, 0x00, 0x01, 0x95, 0x21, 0x94, 0x20, 0xff, 0xf3, 0x15, 0x6c, 0x2f, 0x94, 0x80, 0x00, 0xef, - 0x35, 0x61, 0x21, 0x94, 0x20, 0xff, 0xf5, 0x22, 0x62, 0x6c, 0x94, 0x80, 0x19, 0x17, 0x21, 0x94, - 0x20, 0xff, 0xf7, 0x22, 0x6c, 0xa0, 0x27, 0x10, 0xe0, 0x00, 0xfb, 0xbb, 0xa0, 0x00, 0x0a, 0xbb, - 0x3a, 0x39, 0x44, 0x88, 0x07, 0xcf, 0x08, 0x1c, 0x20, 0x00, 0x08, 0x06, 0x80, 0x30, 0x18, 0x80, - 0x19, 0x17, 0x41, 0x22, 0xa0, 0x00, 0x0a, 0x3b, 0x44, 0x41, 0xcf, 0x20, 0xff, 0xdd, 0x62, 0x22, - 0x22, 0x6c, 0x2d, 0x2d, 0x20, 0x55, 0x6e, 0x75, 0x73, 0x65, 0x64, 0x3a, 0x20, 0x00, 0x52, 0x45, - 0x53, 0x45, 0x54, 0x00, 0x41, 0x73, 0x73, 0x65, 0x6d, 0x62, 0x6c, 0x65, 0x64, 0x20, 0x00, 0x20, - 0x69, 0x6e, 0x20, 0x00, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73, 0x28, 0x00, 0x29, 0x2e, 0x0a, 0x00, - 0x20, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x00, 0x21, 0x21, 0x20, 0x45, 0x72, 0x72, 0x6f, 0x72, - 0x3a, 0x20, 0x00, 0x44, 0x75, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x65, 0x00, 0x4e, 0x75, 0x6d, - 0x62, 0x65, 0x72, 0x00, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x00, 0x52, 0x65, 0x66, 0x65, 0x72, - 0x65, 0x6e, 0x63, 0x65, 0x00, 0x53, 0x75, 0x62, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x00, 0x44, 0x69, - 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x00, 0x53, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0x00, 0x5a, 0x65, - 0x72, 0x6f, 0x2d, 0x70, 0x61, 0x67, 0x65, 0x00, 0x4c, 0x49, 0x54, 0x49, 0x4e, 0x43, 0x50, 0x4f, - 0x50, 0x4e, 0x49, 0x50, 0x53, 0x57, 0x50, 0x52, 0x4f, 0x54, 0x44, 0x55, 0x50, 0x4f, 0x56, 0x52, - 0x45, 0x51, 0x55, 0x4e, 0x45, 0x51, 0x47, 0x54, 0x48, 0x4c, 0x54, 0x48, 0x4a, 0x4d, 0x50, 0x4a, - 0x43, 0x4e, 0x4a, 0x53, 0x52, 0x53, 0x54, 0x48, 0x4c, 0x44, 0x5a, 0x53, 0x54, 0x5a, 0x4c, 0x44, - 0x52, 0x53, 0x54, 0x52, 0x4c, 0x44, 0x41, 0x53, 0x54, 0x41, 0x44, 0x45, 0x49, 0x44, 0x45, 0x4f, - 0x41, 0x44, 0x44, 0x53, 0x55, 0x42, 0x4d, 0x55, 0x4c, 0x44, 0x49, 0x56, 0x41, 0x4e, 0x44, 0x4f, - 0x52, 0x41, 0x45, 0x4f, 0x52, 0x53, 0x46, 0x54, 0x42, 0x52, 0x4b, 0x7c, 0x02, 0x82, 0x24, 0x02, - 0x89, 0x40, 0x02, 0x94, 0x26, 0x02, 0x98, 0x23, 0x02, 0xd5, 0x7d, 0x02, 0xdd, 0x2c, 0x02, 0x9f, - 0x5f, 0x02, 0xa4, 0x2e, 0x02, 0xab, 0x2d, 0x02, 0xb0, 0x3b, 0x02, 0xb8, 0x3d, 0x02, 0xbd, 0x3f, - 0x02, 0xc4, 0x21, 0x02, 0xca, 0x22, 0x02, 0xd9, 0x7e, 0x02, 0xe1, - }; - - const mem: [0xFFFF]u8 = undefined; - const ws: [0xFF]u8 = undefined; - const rs: [0xFF]u8 = undefined; - var uxn = Uxn{ - .mem = .{ .m = mem }, - .ws = .{ .s = ws, .sp = 0 }, - .rs = .{ .s = rs, .sp = 0 }, - .pc = 0x100, - }; - @memcpy(uxn.mem.m[0x100 .. 0x100 + rom.len], &rom); - - while (true) uxn.loop(); +test "memory peek/poke" { + var mem = Uxn.Memory{ .m = undefined }; + mem.poke(u16, 0, 0xABCD); + mem.poke(u8, 2, 0xAA); + try std.testing.expectEqual(0xABCD, mem.peek(u16, 0)); + try std.testing.expectEqual(0xAA, mem.peek(u8, 2)); +} + +test "stack push/pop" { + var stack = Uxn.Stack{ .s = undefined }; + stack.push(u16, 0xABCD); + stack.push(u8, 0xAA); + try std.testing.expectEqual(0xAA, stack.pop(u8)); + try std.testing.expectEqual(0xABCD, stack.pop(u16)); }