add opcode test license, finish op.inc
This commit is contained in:
parent
6d2cb973d1
commit
9c84ed1f1a
1 changed files with 44 additions and 7 deletions
51
src/uxn.zig
51
src/uxn.zig
|
@ -683,29 +683,66 @@ fn sft(stack: *Stack, comptime T: type, comptime keep: bool) void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adaptation of https://git.sr.ht/~rabbits/uxn-utils/tree/096fb78a781dcb0454083c3eda89298b98a5187f/item/cli/opctest/src/opctest.tal
|
||||||
|
//
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// Copyright (c) Devine Lu Linvega
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
|
||||||
test "op" {
|
test "op" {
|
||||||
var uxn = try Uxn.init(std.testing.allocator);
|
var uxn = try Uxn.init(std.testing.allocator);
|
||||||
defer uxn.deinit(std.testing.allocator);
|
defer uxn.deinit(std.testing.allocator);
|
||||||
|
|
||||||
const rom = [_]u8{
|
const rom = [_]u8{
|
||||||
0x01, 0x01, 0x01, 0x01,
|
0x01, 0x01, 0x01, 0x01,
|
||||||
|
0x21, 0x21, 0x21, 0x21,
|
||||||
0x00,
|
0x00,
|
||||||
};
|
};
|
||||||
@memcpy(uxn.mem.m[0x100 .. rom.len + 0x100], &rom);
|
@memcpy(uxn.mem.m[0x100 .. rom.len + 0x100], &rom);
|
||||||
|
|
||||||
std.debug.print("op.inc\n", .{});
|
std.debug.print("op.inc\n", .{});
|
||||||
uxn.ws.push(u8, 0x01);
|
uxn.ws.push(u16, 0x0000);
|
||||||
uxn.ws.push(u8, 0xff);
|
uxn.ws.push(u16, 0xfffe);
|
||||||
uxn.ws.push(u8, 0xfe);
|
uxn.ws.push(u16, 0xffff);
|
||||||
|
uxn.ws.push(u16, 0x0001);
|
||||||
uxn.ws.push(u8, 0x00);
|
uxn.ws.push(u8, 0x00);
|
||||||
|
uxn.ws.push(u8, 0xfe);
|
||||||
|
uxn.ws.push(u8, 0xff);
|
||||||
|
uxn.ws.push(u8, 0x01);
|
||||||
_ = uxn.eval();
|
_ = uxn.eval();
|
||||||
try std.testing.expectEqual(0x01, uxn.ws.pop(u8));
|
try std.testing.expectEqual(0x02, uxn.ws.pop(u8));
|
||||||
_ = uxn.eval();
|
|
||||||
try std.testing.expectEqual(0xff, uxn.ws.pop(u8));
|
|
||||||
_ = uxn.eval();
|
_ = uxn.eval();
|
||||||
try std.testing.expectEqual(0x00, uxn.ws.pop(u8));
|
try std.testing.expectEqual(0x00, uxn.ws.pop(u8));
|
||||||
_ = uxn.eval();
|
_ = uxn.eval();
|
||||||
try std.testing.expectEqual(0x02, uxn.ws.pop(u8));
|
try std.testing.expectEqual(0xff, uxn.ws.pop(u8));
|
||||||
|
_ = uxn.eval();
|
||||||
|
try std.testing.expectEqual(0x01, uxn.ws.pop(u8));
|
||||||
|
_ = uxn.eval();
|
||||||
|
try std.testing.expectEqual(0x0002, uxn.ws.pop(u16));
|
||||||
|
_ = uxn.eval();
|
||||||
|
try std.testing.expectEqual(0x0000, uxn.ws.pop(u16));
|
||||||
|
_ = uxn.eval();
|
||||||
|
try std.testing.expectEqual(0xffff, uxn.ws.pop(u16));
|
||||||
|
_ = uxn.eval();
|
||||||
|
try std.testing.expectEqual(0x0001, uxn.ws.pop(u16));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn formatInstruction(
|
pub fn formatInstruction(
|
||||||
|
|
Loading…
Add table
Reference in a new issue