2022-12-24 08:25:49 +00:00
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::rc::Rc;
|
|
|
|
|
|
|
|
use uxn::device::buff::BuffDevice;
|
2022-12-24 03:41:44 +00:00
|
|
|
use uxn::isa::Icode;
|
|
|
|
use uxn::vm::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_brk() {
|
|
|
|
let mut vm = Uxn::of1(&[Icode::BRK]);
|
|
|
|
assert_eq!(vm.step(), Err(UxnError::Break));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_lit() {
|
|
|
|
let mut vm = Uxn::of1(&[Icode::LIT, 0x01, Icode::BRK]);
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0x01));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_lit2() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0xFF, 0xAA,
|
|
|
|
Icode::BRK, // BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0xFFAA));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_litr() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::RETURN, 0xAA,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.rst.borrow().peek1(), Ok(0xAA));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_inc() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0xFF, 0xAA,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0xFFAA));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_pop1() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xFF,
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::POP,
|
|
|
|
Icode::LIT, 0xBB,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0xFFBB));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_pop2() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xFF,
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::LIT, 0xBB,
|
|
|
|
Icode::POP | Icode::SHORT,
|
|
|
|
Icode::LIT, 0xCC,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0xFFCC));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_popk() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xFF,
|
|
|
|
Icode::POP | Icode::KEEP,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_nip() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::LIT, 0xBB,
|
|
|
|
Icode::NIP,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xBB));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_nip2() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0xAA, 0x00,
|
|
|
|
Icode::LIT | Icode::SHORT, 0xBB, 0x00,
|
|
|
|
Icode::NIP | Icode::SHORT,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0xBB00));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_nipk() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::LIT, 0xBB,
|
|
|
|
Icode::NIP | Icode::KEEP,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0xAA));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(1), Ok(0xBB));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(2), Ok(0xBB));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xBB));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_swp() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::LIT, 0xBB,
|
|
|
|
Icode::SWP,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0xBB));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(1), Ok(0xAA));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xAA));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_swp2() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0xAA, 0x00,
|
|
|
|
Icode::LIT | Icode::SHORT, 0xBB, 0x00,
|
|
|
|
Icode::SWP | Icode::SHORT,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get2(0), Ok(0xBB00));
|
|
|
|
assert_eq!(vm.wst.borrow().get2(2), Ok(0xAA00));
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0xAA00));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_swpk() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::LIT, 0xBB,
|
|
|
|
Icode::SWP | Icode::KEEP,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0xAA));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(1), Ok(0xBB));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(2), Ok(0xBB));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(3), Ok(0xAA));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xAA));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rot() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::LIT, 0xBB,
|
|
|
|
Icode::LIT, 0xCC,
|
|
|
|
Icode::ROT,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0xBB));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(1), Ok(0xCC));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(2), Ok(0xAA));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xAA));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_rot_cycle() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::LIT, 0xBB,
|
|
|
|
Icode::LIT, 0xCC,
|
|
|
|
Icode::ROT,
|
|
|
|
Icode::ROT,
|
|
|
|
Icode::ROT,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0xAA));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(1), Ok(0xBB));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(2), Ok(0xCC));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xCC));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_dup() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::LIT, 0xBB,
|
|
|
|
Icode::DUP,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0xAA));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(1), Ok(0xBB));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(2), Ok(0xBB));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xBB));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ovr() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::LIT, 0xBB,
|
|
|
|
Icode::OVR,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0xAA));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(1), Ok(0xBB));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(2), Ok(0xAA));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xAA));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_eql_neg() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::LIT, 0xBB,
|
|
|
|
Icode::EQL,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0x00));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0x00));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_eql_pos() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::EQL,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0x01));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0x01));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_neq_neg() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::NEQ,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0x00));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0x00));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_neq_pos() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::LIT, 0xBB,
|
|
|
|
Icode::NEQ,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0x01));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0x01));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_gth_neg() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0x00,
|
|
|
|
Icode::LIT, 0x01,
|
|
|
|
Icode::GTH,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0x00));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0x00));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_gth_pos() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0x01,
|
|
|
|
Icode::LIT, 0x00,
|
|
|
|
Icode::GTH,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0x01));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0x01));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_lth_neg() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0x01,
|
|
|
|
Icode::LIT, 0x00,
|
|
|
|
Icode::LTH,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0x00));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0x00));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_lth_pos() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0x00,
|
|
|
|
Icode::LIT, 0x01,
|
|
|
|
Icode::LTH,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0x01));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0x01));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_jmprp() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::LIT, 0x03,
|
|
|
|
Icode::JMP,
|
|
|
|
Icode::POP,
|
|
|
|
Icode::LIT, 0xFF,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0xAA));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xAA));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_jmpa() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0x01, 0x10, Icode::JMP | Icode::SHORT,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
Icode::LIT, 0xAA,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0xAA));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xAA));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_jmprn() {
|
|
|
|
// Negative relative jup
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0x01, 0x10, Icode::JMP | Icode::SHORT,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
// Negative relative jump target
|
|
|
|
Icode::LIT, 0xAA, Icode::BRK, 0x00,
|
|
|
|
|
|
|
|
// Absolute jump target
|
|
|
|
Icode::LIT, -7i8 as u8, Icode::JMP,
|
|
|
|
|
|
|
|
// Wrong arm
|
|
|
|
Icode::LIT, 0xFF,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0xAA));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xAA));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_jmpc_true() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0x01,
|
|
|
|
Icode::LIT, 0x03,
|
|
|
|
Icode::JCN,
|
|
|
|
// Fall through
|
|
|
|
Icode::LIT, 0xFF, Icode::BRK,
|
|
|
|
|
|
|
|
// Target
|
|
|
|
Icode::LIT, 0xAA, Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0xAA));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xAA));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_jmpc_false() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0x00,
|
|
|
|
Icode::LIT, 0x03,
|
|
|
|
Icode::JCN,
|
|
|
|
// Fall through
|
|
|
|
Icode::LIT, 0xFF, Icode::BRK,
|
|
|
|
|
|
|
|
// Target
|
|
|
|
Icode::LIT, 0xAA, Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0xFF));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_jsr() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0x05, Icode::JSR, 0x00,
|
|
|
|
// Fall through
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
// Target
|
|
|
|
Icode::LIT, 0xAA, Icode::BRK, 0x00,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0xAA));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xAA));
|
|
|
|
|
|
|
|
assert_eq!(vm.rst.borrow().get2(0), Ok(0x0103));
|
|
|
|
assert_eq!(vm.rst.borrow().peek2(), Ok(0x0103));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_jsra() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0x01, 0x08, Icode::JSR | Icode::SHORT,
|
|
|
|
// Fall through
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
// Target
|
|
|
|
Icode::LIT, 0xAA, Icode::BRK, 0x00,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0xAA));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xAA));
|
|
|
|
|
|
|
|
assert_eq!(vm.rst.borrow().get2(0), Ok(0x0104));
|
|
|
|
assert_eq!(vm.rst.borrow().peek2(), Ok(0x0104));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sth() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0x01, 0x08, Icode::STH,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().get1(0), Ok(0x01));
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0x01));
|
|
|
|
|
|
|
|
assert_eq!(vm.rst.borrow().get1(0), Ok(0x08));
|
|
|
|
assert_eq!(vm.rst.borrow().peek1(), Ok(0x08));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sth2() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0x01, 0x08, Icode::STH | Icode::SHORT,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.rst.borrow().get2(0), Ok(0x0108));
|
|
|
|
assert_eq!(vm.rst.borrow().peek2(), Ok(0x0108));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ldz() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0x0b, Icode::LDZ, Icode::BRK,
|
|
|
|
]);
|
|
|
|
vm.sta1(0x000b, 0xFF).unwrap();
|
|
|
|
}
|
|
|
|
// Make sure the write took
|
|
|
|
assert_eq!(vm.lda1(0x00b).unwrap(), 0xFF);
|
|
|
|
// Run the example
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 1);
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ldz2() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0x0b, Icode::LDZ | Icode::SHORT, Icode::BRK,
|
|
|
|
]);
|
|
|
|
vm.sta2(0x000b, 0xFFEE).unwrap();
|
|
|
|
}
|
|
|
|
// Make sure the write took
|
|
|
|
assert_eq!(vm.lda1(0x00b).unwrap(), 0xFF);
|
|
|
|
// Run the example
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 2);
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0xFFEE));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stz() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xFF, Icode::LIT, 0x0b,
|
|
|
|
Icode::STZ, Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 0);
|
|
|
|
assert_eq!(vm.lda1(0x000b), Ok(0xFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stz2() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xFF, Icode::LIT, 0x0b,
|
|
|
|
Icode::STZ, Icode::BRK,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 0);
|
|
|
|
assert_eq!(vm.lda1(0x000b), Ok(0xFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ldr() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0x01, Icode::LDR, Icode::BRK,
|
|
|
|
0xFF,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 1);
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ldr2() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0x01, Icode::LDR | Icode::SHORT, Icode::BRK,
|
|
|
|
0xFF, 0xEE
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 2);
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0xFFEE));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_str() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xEE, Icode::LIT, 0x03,
|
|
|
|
Icode::STR, Icode::BRK, 0x00, 0x00,
|
|
|
|
0xFF, // Will be overwritten
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 0);
|
|
|
|
assert_eq!(vm.lda1(0x0108), Ok(0xEE));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_str2() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0xEE, 0xDD, Icode::LIT,
|
|
|
|
0x02, Icode::STR | Icode::SHORT, Icode::BRK, 0x00,
|
|
|
|
0xFF, 0xFF // Will be overwritten
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 0);
|
|
|
|
assert_eq!(vm.lda2(0x0108), Ok(0xEEDD));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_lda() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0x01, 0x08, Icode::LDA,
|
|
|
|
Icode::BRK, 0x00, 0x00, 0x00,
|
|
|
|
0xEE,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 1);
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xEE));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_lda2() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0x01, 0x08, Icode::LDA | Icode::SHORT,
|
|
|
|
Icode::BRK, 0x00, 0x00, 0x00,
|
|
|
|
0xEE, 0xDD,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 2);
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0xEEDD));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sta() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT, 0xFF, Icode::NOP, Icode::NOP,
|
|
|
|
Icode::LIT | Icode::SHORT, 0x01, 0x0c, Icode::NOP,
|
|
|
|
Icode::STA, Icode::BRK, 0x00, 0x00,
|
|
|
|
0x00,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 0);
|
|
|
|
assert_eq!(vm.lda1(0x010c), Ok(0xFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sta2() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0xFF, 0xEE, Icode::NOP,
|
|
|
|
Icode::LIT | Icode::SHORT, 0x01, 0x0c, Icode::NOP,
|
|
|
|
Icode::STA | Icode::SHORT, Icode::BRK, Icode::NOP,
|
|
|
|
0x00, 0x00,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 0);
|
|
|
|
assert_eq!(vm.lda2(0x010c), Ok(0xFFEE));
|
|
|
|
}
|
2022-12-24 07:26:33 +00:00
|
|
|
|
2022-12-24 08:25:49 +00:00
|
|
|
#[test]
|
|
|
|
fn test_dei() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
2022-12-26 04:49:05 +00:00
|
|
|
Icode::LIT, 0x30,
|
|
|
|
Icode::DEI,
|
|
|
|
Icode::BRK,
|
2022-12-24 08:25:49 +00:00
|
|
|
]);
|
|
|
|
let dev = Rc::new(RefCell::new(BuffDevice::new()));
|
|
|
|
vm.devices[3] = dev.clone();
|
2022-12-26 04:49:05 +00:00
|
|
|
vm.deo1(0x30, 0xFF).unwrap();
|
2022-12-24 08:25:49 +00:00
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 1);
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_dei2() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
2022-12-26 04:49:05 +00:00
|
|
|
Icode::LIT, 0x30,
|
|
|
|
Icode::DEI | Icode::SHORT,
|
|
|
|
Icode::BRK,
|
2022-12-24 08:25:49 +00:00
|
|
|
]);
|
|
|
|
let dev = Rc::new(RefCell::new(BuffDevice::new()));
|
|
|
|
vm.devices[3] = dev.clone();
|
2022-12-26 04:49:05 +00:00
|
|
|
vm.deo2(0x30, 0xFFEE).unwrap();
|
2022-12-24 08:25:49 +00:00
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 2);
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0xFFEE));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_deo() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0xFF, 0x30, Icode::DEO, Icode::BRK,
|
|
|
|
]);
|
|
|
|
let dev = Rc::new(RefCell::new(BuffDevice::new()));
|
|
|
|
vm.devices[3] = dev.clone();
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 0);
|
|
|
|
assert_eq!(vm.dei1(0x30), Ok(0xFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_deo2() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0xFF, 0xEE,
|
|
|
|
Icode::LIT, 0x30,
|
|
|
|
Icode::DEO | Icode::SHORT,
|
|
|
|
Icode::BRK,
|
|
|
|
]);
|
|
|
|
let dev = Rc::new(RefCell::new(BuffDevice::new()));
|
|
|
|
vm.devices[3] = dev.clone();
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 0);
|
|
|
|
assert_eq!(vm.dei2(0x30), Ok(0xFFEE));
|
|
|
|
}
|
|
|
|
|
2022-12-24 07:26:33 +00:00
|
|
|
#[test]
|
|
|
|
fn test_add() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0xFF, 0x01, Icode::ADD, Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 1);
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0x00));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_add2() {
|
|
|
|
// The incantation for adding a u8 to a u16 is probably something involving using [ LIT #00 SWP ] but yeesh.
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0xFF, 0x00,
|
|
|
|
Icode::LIT, 0x01,
|
|
|
|
|
|
|
|
// Promote u8 to u16 by stuffing an #00 in there. Yes coulda used a bigger lit but playing with the upcast.
|
|
|
|
Icode::LIT, 0x0,
|
|
|
|
Icode::SWP,
|
|
|
|
|
|
|
|
// u16 + u16
|
|
|
|
Icode::ADD | Icode::SHORT,
|
|
|
|
Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 2);
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0xFF01));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sub() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0xFF, 0x01, Icode::SUB, Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 1);
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xFE));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sub2() {
|
|
|
|
// The incantation for adding a u8 to a u16 is probably something involving using [ LIT #00 SWP ] but yeesh.
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0xFF, 0xFF,
|
|
|
|
Icode::LIT, 0x01,
|
|
|
|
|
|
|
|
// Promote u8 to u16 by stuffing an #00 in there. Yes coulda used a bigger lit but playing with the upcast.
|
|
|
|
Icode::LIT, 0x0,
|
|
|
|
Icode::SWP,
|
|
|
|
|
|
|
|
Icode::SUB | Icode::SHORT,
|
|
|
|
Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 2);
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0xFFFE));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_mul() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0x4, 0x4, Icode::MUL, Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 1);
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0x10));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_mul2() {
|
|
|
|
// The incantation for adding a u8 to a u16 is probably something involving using [ LIT #00 SWP ] but yeesh.
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0xFF, 0xFF,
|
|
|
|
Icode::LIT, 0x01,
|
|
|
|
|
|
|
|
// Promote u8 to u16 by stuffing an #00 in there. Yes coulda used a bigger lit but playing with the upcast.
|
|
|
|
Icode::LIT, 0x0,
|
|
|
|
Icode::SWP,
|
|
|
|
|
|
|
|
Icode::MUL | Icode::SHORT,
|
|
|
|
Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 2);
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0xFFFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_div() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0x10, 0x4, Icode::DIV, Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 1);
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0x4));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_div2() {
|
|
|
|
// The incantation for adding a u8 to a u16 is probably something involving using [ LIT #00 SWP ] but yeesh.
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0x10, 0x00,
|
|
|
|
Icode::LIT, 0x2,
|
|
|
|
|
|
|
|
// Promote u8 to u16 by stuffing an #00 in there. Yes coulda used a bigger lit but playing with the upcast.
|
|
|
|
Icode::LIT, 0x0,
|
|
|
|
Icode::SWP,
|
|
|
|
|
|
|
|
Icode::DIV | Icode::SHORT,
|
|
|
|
Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 2);
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0x0800));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_and() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0xF, 0x1, Icode::AND, Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 1);
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0x1));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_and2() {
|
|
|
|
// The incantation for adding a u8 to a u16 is probably something involving using [ LIT #00 SWP ] but yeesh.
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0x10, 0x03,
|
|
|
|
Icode::LIT, 0x2,
|
|
|
|
|
|
|
|
// Promote u8 to u16 by stuffing an #00 in there. Yes coulda used a bigger lit but playing with the upcast.
|
|
|
|
Icode::LIT, 0x0,
|
|
|
|
Icode::SWP,
|
|
|
|
|
|
|
|
Icode::AND | Icode::SHORT,
|
|
|
|
Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 2);
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0x0002));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_or() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0xF, 0x1,
|
|
|
|
Icode::OR,
|
|
|
|
Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 1);
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xF));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_or2() {
|
|
|
|
// The incantation for adding a u8 to a u16 is probably something involving using [ LIT #00 SWP ] but yeesh.
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0x10, 0x03,
|
|
|
|
Icode::LIT, 0x2,
|
|
|
|
|
|
|
|
// Promote u8 to u16 by stuffing an #00 in there. Yes coulda used a bigger lit but playing with the upcast.
|
|
|
|
Icode::LIT, 0x0,
|
|
|
|
Icode::SWP,
|
|
|
|
|
|
|
|
Icode::OR | Icode::SHORT,
|
|
|
|
Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 2);
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0x1003));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_xor() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0xF, 0x1,
|
|
|
|
Icode::XOR,
|
|
|
|
Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 1);
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0xE));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_xor2() {
|
|
|
|
// The incantation for adding a u8 to a u16 is probably something involving using [ LIT #00 SWP ] but yeesh.
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0x10, 0x03,
|
|
|
|
Icode::LIT, 0x2,
|
|
|
|
|
|
|
|
// Promote u8 to u16 by stuffing an #00 in there. Yes coulda used a bigger lit but playing with the upcast.
|
|
|
|
Icode::LIT, 0x0,
|
|
|
|
Icode::SWP,
|
|
|
|
|
|
|
|
Icode::XOR | Icode::SHORT,
|
|
|
|
Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 2);
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0x1001));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sft_l() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0x0F, 0x10,
|
|
|
|
Icode::SFT,
|
|
|
|
Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 1);
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0x1E));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sft_r() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0x0F, 0x01,
|
|
|
|
Icode::SFT,
|
|
|
|
Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 1);
|
|
|
|
assert_eq!(vm.wst.borrow().peek1(), Ok(0x07));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_sft_rl2() {
|
|
|
|
nofmt::pls! {
|
|
|
|
let mut vm = Uxn::of1(&[
|
|
|
|
Icode::LIT | Icode::SHORT, 0x80, 0x01,
|
|
|
|
Icode::LIT, 0x21, // Shift truncates, so this will unset all the bits
|
|
|
|
Icode::SFT | Icode::SHORT,
|
|
|
|
Icode::BRK
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
assert_eq!(vm.run(64), Err(UxnError::Break));
|
|
|
|
assert_eq!(vm.wst.borrow().idx(), 2);
|
|
|
|
assert_eq!(vm.wst.borrow().peek2(), Ok(0x0000));
|
|
|
|
}
|