And finish the fundamental ops
This commit is contained in:
parent
6ee73379bb
commit
d74018e762
1 changed files with 52 additions and 41 deletions
93
src/vm.rs
93
src/vm.rs
|
@ -366,8 +366,9 @@ impl Uxn {
|
||||||
// JCN1 cnd8 addr8 (relative)
|
// JCN1 cnd8 addr8 (relative)
|
||||||
let delta = wst.borrow_mut().pop1()? as i8;
|
let delta = wst.borrow_mut().pop1()? as i8;
|
||||||
let cnd = wst.borrow_mut().pop1()?;
|
let cnd = wst.borrow_mut().pop1()?;
|
||||||
|
let delta = wst.borrow_mut().pop1()? as i8;
|
||||||
if cnd != 0 {
|
if cnd != 0 {
|
||||||
self.pc += delta;
|
self.pc = self.pc.wrapping_add(delta as u16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(_, _, 2, 0x0d) => {
|
(_, _, 2, 0x0d) => {
|
||||||
|
@ -381,7 +382,8 @@ impl Uxn {
|
||||||
(_, _, 0, 0x0e) => {
|
(_, _, 0, 0x0e) => {
|
||||||
// JSR1 addr8 (relative)
|
// JSR1 addr8 (relative)
|
||||||
rst.borrow_mut().push2(self.pc);
|
rst.borrow_mut().push2(self.pc);
|
||||||
self.pc += (wst.borrow_mut().pop1()? as i8);
|
let delta = wst.borrow_mut().pop1()? as i8;
|
||||||
|
self.pc = self.pc.wrapping_add(delta as u16);
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x0e) => {
|
(_, _, 1, 0x0e) => {
|
||||||
// JSR2 addr16 (absolute)
|
// JSR2 addr16 (absolute)
|
||||||
|
@ -398,218 +400,227 @@ impl Uxn {
|
||||||
}
|
}
|
||||||
(_, _, 0, 0x10) => {
|
(_, _, 0, 0x10) => {
|
||||||
// LDZ1 a -- b8
|
// LDZ1 a -- b8
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let val = self.memory.borrow().get1(wst.pop1()? as u16)?;
|
let val = self.memory.borrow().get1(wst.pop1()? as u16)?;
|
||||||
wst.push1(val)?;
|
wst.push1(val)?;
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x10) => {
|
(_, _, 1, 0x10) => {
|
||||||
// LDZ2 a -- b16
|
// LDZ2 a -- b16
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let val = self.memory.borrow().get2(wst.pop1()? as u16)?;
|
let val = self.memory.borrow().get2(wst.pop1()? as u16)?;
|
||||||
wst.push2(val)?;
|
wst.push2(val)?;
|
||||||
}
|
}
|
||||||
(_, _, 0, 0x11) => {
|
(_, _, 0, 0x11) => {
|
||||||
// STZ1 val addr8 --
|
// STZ1 val addr8 --
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let addr = wst.pop1()?;
|
let addr = wst.pop1()?;
|
||||||
let val = wst.pop1()?;
|
let val = wst.pop1()?;
|
||||||
self.memory.borrow_mut().set1(addr as u16, val);
|
self.memory.borrow_mut().set1(addr as u16, val);
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x11) => {
|
(_, _, 1, 0x11) => {
|
||||||
// STZ2 val16 addr8 --
|
// STZ2 val16 addr8 --
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let addr = wst.pop1()?;
|
let addr = wst.pop1()?;
|
||||||
let val = wst.pop2()?;
|
let val = wst.pop2()?;
|
||||||
self.memory.borrow_mut().set2(addr as u16, val);
|
self.memory.borrow_mut().set2(addr as u16, val);
|
||||||
}
|
}
|
||||||
(_, _, 0, 0x12) => {
|
(_, _, 0, 0x12) => {
|
||||||
// LDR1 addr8 -- a8
|
// LDR1 addr8 -- a8
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let delta = wst.pop1()? as i8;
|
let delta = wst.pop1()? as i8;
|
||||||
let val = self.memory.borrow().get1(self.pc + delta)?;
|
let val = self.memory.borrow().get1(self.pc.wrapping_add(delta as u16))?;
|
||||||
wst.push1(val)?;
|
wst.push1(val)?;
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x12) => {
|
(_, _, 1, 0x12) => {
|
||||||
// LDR2 addr8 -- a16
|
// LDR2 addr8 -- a16
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let delta = wst.pop1()? as i8;
|
let delta = wst.pop1()? as i8;
|
||||||
let val = self.memory.borrow().get2(self.pc + delta)?;
|
let val = self.memory.borrow().get2(self.pc.wrapping_add(delta as u16))?;
|
||||||
wst.push2(val)?;
|
wst.push2(val)?;
|
||||||
}
|
}
|
||||||
(_, _, 0, 0x13) => {
|
(_, _, 0, 0x13) => {
|
||||||
// STR1 val8 addr8
|
// STR1 val8 addr8
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let delta = wst.pop1()? as i8;
|
let delta = wst.pop1()?;
|
||||||
let val = wst.pop1()?;
|
let val = wst.pop1()?;
|
||||||
self.memory.borrow_mut().set1(self.pc + delta, val);
|
self.memory.borrow_mut().set1(self.pc.wrapping_add(delta as u16), val);
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x13) => {
|
(_, _, 1, 0x13) => {
|
||||||
// STR2 val16 addr8
|
// STR2 val16 addr8
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let delta = wst.pop1()? as i8;
|
let delta = wst.pop1()? as i8;
|
||||||
let val = wst.pop2()?;
|
let val = wst.pop2()?;
|
||||||
self.memory.borrow_mut().set2(self.pc + delta, val);
|
self.memory.borrow_mut().set2(self.pc.wrapping_add(delta as u16), val);
|
||||||
}
|
}
|
||||||
(_, _, 0, 0x14) => {
|
(_, _, 0, 0x14) => {
|
||||||
// LDA1 a16 -- a8
|
// LDA1 a16 -- a8
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let addr = wst.pop2()?;
|
let addr = wst.pop2()?;
|
||||||
let val = self.memory.borrow_mut().get1(addr)?;
|
let val = self.memory.borrow_mut().get1(addr)?;
|
||||||
wst.push1(val)?;
|
wst.push1(val)?;
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x14) => {
|
(_, _, 1, 0x14) => {
|
||||||
// LDA2 a16 -- a16
|
// LDA2 a16 -- a16
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let addr = wst.pop2()?;
|
let addr = wst.pop2()?;
|
||||||
let val = self.memory.borrow_mut().get2(addr)?;
|
let val = self.memory.borrow_mut().get2(addr)?;
|
||||||
wst.push2(val)?;
|
wst.push2(val)?;
|
||||||
}
|
}
|
||||||
(_, _, 0, 0x15) => {
|
(_, _, 0, 0x15) => {
|
||||||
// STA1 val a16 --
|
// STA1 val a16 --
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let addr = wst.pop2()?;
|
let addr = wst.pop2()?;
|
||||||
let val = wst.pop1()?;
|
let val = wst.pop1()?;
|
||||||
self.memory.borrow_mut().set1(addr, val)?;
|
self.memory.borrow_mut().set1(addr, val)?;
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x15) => {
|
(_, _, 1, 0x15) => {
|
||||||
// STA1 val a16 --
|
// STA1 val a16 --
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let addr = wst.pop2()?;
|
let addr = wst.pop2()?;
|
||||||
let val = wst.pop2()?;
|
let val = wst.pop2()?;
|
||||||
self.memory.borrow_mut().set2(addr, val)?;
|
self.memory.borrow_mut().set2(addr, val)?;
|
||||||
}
|
}
|
||||||
(_, _, 0, 0x16) => {
|
(_, _, 0, 0x16) => {
|
||||||
// DEI1 port8 -- a8
|
// DEI1 port8 -- a8
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let port = wst.pop1()?;
|
let port = wst.pop1()?;
|
||||||
wst.push1(self.dei1(port));
|
wst.push1(self.dei1(port));
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x16) => {
|
(_, _, 1, 0x16) => {
|
||||||
// DEI2 port8 -- a16
|
// DEI2 port8 -- a16
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let port = wst.pop1()?;
|
let port = wst.pop1()?;
|
||||||
wst.push2(self.dei2(port));
|
wst.push2(self.dei2(port));
|
||||||
}
|
}
|
||||||
(_, _, 0, 0x17) => {
|
(_, _, 0, 0x17) => {
|
||||||
// DEO1 a8 port8 --
|
// DEO1 a8 port8 --
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let port = wst.pop1()?;
|
let port = wst.pop1()?;
|
||||||
let val = wst.pop1()?;
|
let val = wst.pop1()?;
|
||||||
self.deo1(port, val);
|
self.deo1(port, val);
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x17) => {
|
(_, _, 1, 0x17) => {
|
||||||
// DEO2 a16 port8 --
|
// DEO2 a16 port8 --
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let port = wst.pop1()?;
|
let port = wst.pop1()?;
|
||||||
let val = wst.pop2()?;
|
let val = wst.pop2()?;
|
||||||
self.deo2(port, val);
|
self.deo2(port, val);
|
||||||
}
|
}
|
||||||
(_, _, 0, 0x18) => {
|
(_, _, 0, 0x18) => {
|
||||||
// ADD1 a b -- c
|
// ADD1 a b -- c
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let b = wst.pop1()?;
|
let b = wst.pop1()?;
|
||||||
let a = wst.pop1()?;
|
let a = wst.pop1()?;
|
||||||
wst.push1(a + b)?;
|
wst.push1(a + b)?;
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x18) => {
|
(_, _, 1, 0x18) => {
|
||||||
// ADD2 a16 b16 -- c16
|
// ADD2 a16 b16 -- c16
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let b = wst.pop2()?;
|
let b = wst.pop2()?;
|
||||||
let a = wst.pop2()?;
|
let a = wst.pop2()?;
|
||||||
wst.push2(a + b)?;
|
wst.push2(a + b)?;
|
||||||
}
|
}
|
||||||
(_, _, 0, 0x19) => {
|
(_, _, 0, 0x19) => {
|
||||||
// SUB1 a b -- c
|
// SUB1 a b -- c
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let b = wst.pop1()?;
|
let b = wst.pop1()?;
|
||||||
let a = wst.pop1()?;
|
let a = wst.pop1()?;
|
||||||
wst.push1(a - b)?;
|
wst.push1(a - b)?;
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x19) => {
|
(_, _, 1, 0x19) => {
|
||||||
// SUB2 a16 b16 -- c16
|
// SUB2 a16 b16 -- c16
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let b = wst.pop2()?;
|
let b = wst.pop2()?;
|
||||||
let a = wst.pop2()?;
|
let a = wst.pop2()?;
|
||||||
wst.push2(a - b)?;
|
wst.push2(a - b)?;
|
||||||
}
|
}
|
||||||
(_, _, 0, 0x1a) => {
|
(_, _, 0, 0x1a) => {
|
||||||
// MUL1 a b -- c
|
// MUL1 a b -- c
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let b = wst.pop1()?;
|
let b = wst.pop1()?;
|
||||||
let a = wst.pop1()?;
|
let a = wst.pop1()?;
|
||||||
wst.push1(a * b)?;
|
wst.push1(a * b)?;
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x1a) => {
|
(_, _, 1, 0x1a) => {
|
||||||
// MUL2 a16 b16 -- c16
|
// MUL2 a16 b16 -- c16
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let b = wst.pop2()?;
|
let b = wst.pop2()?;
|
||||||
let a = wst.pop2()?;
|
let a = wst.pop2()?;
|
||||||
wst.push2(a * b)?;
|
wst.push2(a * b)?;
|
||||||
}
|
}
|
||||||
(_, _, 0, 0x1b) => {
|
(_, _, 0, 0x1b) => {
|
||||||
// DIV1 a b -- c
|
// DIV1 a b -- c
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let b = wst.pop1()?;
|
let b = wst.pop1()?;
|
||||||
let a = wst.pop1()?;
|
let a = wst.pop1()?;
|
||||||
wst.push1(a / b)?;
|
wst.push1(a / b)?;
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x1b) => {
|
(_, _, 1, 0x1b) => {
|
||||||
// DIV2 a16 b16 -- c16
|
// DIV2 a16 b16 -- c16
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let b = wst.pop2()?;
|
let b = wst.pop2()?;
|
||||||
let a = wst.pop2()?;
|
let a = wst.pop2()?;
|
||||||
wst.push2(a / b)?;
|
wst.push2(a / b)?;
|
||||||
}
|
}
|
||||||
(_, _, 0, 0x1c) => {
|
(_, _, 0, 0x1c) => {
|
||||||
// AND1 a8 b8 -- c8
|
// AND1 a8 b8 -- c8
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let b = wst.pop1()?;
|
let b = wst.pop1()?;
|
||||||
let a = wst.pop1()?;
|
let a = wst.pop1()?;
|
||||||
wst.push1(a & b)?;
|
wst.push1(a & b)?;
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x1c) => {
|
(_, _, 1, 0x1c) => {
|
||||||
// AND2 a16 b16 -- c16
|
// AND2 a16 b16 -- c16
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let b = wst.pop2()?;
|
let b = wst.pop2()?;
|
||||||
let a = wst.pop2()?;
|
let a = wst.pop2()?;
|
||||||
wst.push2(a & b)?;
|
wst.push2(a & b)?;
|
||||||
}
|
}
|
||||||
(_, _, 0, 0x1d) => {
|
(_, _, 0, 0x1d) => {
|
||||||
// OR1 a8 b8 -- c8
|
// OR1 a8 b8 -- c8
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let b = wst.pop1()?;
|
let b = wst.pop1()?;
|
||||||
let a = wst.pop1()?;
|
let a = wst.pop1()?;
|
||||||
wst.push1(a | b)?;
|
wst.push1(a | b)?;
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x1d) => {
|
(_, _, 1, 0x1d) => {
|
||||||
// OR2 a16 b16 -- c16
|
// OR2 a16 b16 -- c16
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let b = wst.pop2()?;
|
let b = wst.pop2()?;
|
||||||
let a = wst.pop2()?;
|
let a = wst.pop2()?;
|
||||||
wst.push2(a | b)?;
|
wst.push2(a | b)?;
|
||||||
}
|
}
|
||||||
(_, _, 0, 0x1e) => {
|
(_, _, 0, 0x1e) => {
|
||||||
// XOR1 a8 b8 -- c8
|
// XOR1 a8 b8 -- c8
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let b = wst.pop1()?;
|
let b = wst.pop1()?;
|
||||||
let a = wst.pop1()?;
|
let a = wst.pop1()?;
|
||||||
wst.push1(a ^ b)?;
|
wst.push1(a ^ b)?;
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x1e) => {
|
(_, _, 1, 0x1e) => {
|
||||||
// XOR2 a16 b16 -- c16
|
// XOR2 a16 b16 -- c16
|
||||||
let wst = wst.borrow_mut();
|
let mut wst = wst.borrow_mut();
|
||||||
let b = wst.pop2()?;
|
let b = wst.pop2()?;
|
||||||
let a = wst.pop2()?;
|
let a = wst.pop2()?;
|
||||||
wst.push2(a ^ b)?;
|
wst.push2(a ^ b)?;
|
||||||
}
|
}
|
||||||
(_, _, 0, 0x1f) => {
|
(_, _, 0, 0x1f) => {
|
||||||
// SFT1
|
// SFT1 a shift8 -- b
|
||||||
unimplemented!()
|
let mut wst = wst.borrow_mut();
|
||||||
|
let shift = wst.pop1()?;
|
||||||
|
let [left, right] = [shift >> 4, shift & 0xF];
|
||||||
|
let a = wst.pop1()?;
|
||||||
|
wst.push1((a >> right) << left)?;
|
||||||
}
|
}
|
||||||
(_, _, 1, 0x1f) => {
|
(_, _, 1, 0x1f) => {
|
||||||
// SFT2
|
// SFT2 a shift8 -- b
|
||||||
unimplemented!()
|
let mut wst = wst.borrow_mut();
|
||||||
|
let shift = wst.pop1()?;
|
||||||
|
let [left, right] = [shift >> 4, shift & 0xF];
|
||||||
|
let a = wst.pop2()?;
|
||||||
|
wst.push2((a >> right) << left)?;
|
||||||
}
|
}
|
||||||
|
_ => unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue