Update registers to be constants, add instructions to parser

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-01-27 18:41:33 -05:00
parent abf32665e2
commit b16974c7c4
4 changed files with 149 additions and 159 deletions

View File

@@ -34,7 +34,7 @@ impl Vm {
pub fn tick(&mut self) {
let inst = self.decode();
let ip = self.ip();
self.set_reg(Reg::Ip, ip + 1);
self.set_reg(IP, ip + 1);
self.execute(inst);
}
@@ -100,13 +100,13 @@ impl Vm {
}
pub fn ip(&self) -> Word {
self.get_reg(Reg::Ip)
self.get_reg(IP)
}
pub fn flags(&self) -> Flags {
// this is safe because it's OK if there are random bits flipped - this shouldn't happen
// anyway, but if it does, they're ignored
unsafe { Flags::from_bits_unchecked(self.get_reg(Reg::Flags)) }
unsafe { Flags::from_bits_unchecked(self.get_reg(FLAGS)) }
}
pub fn insert_flags(&mut self, flags: Flags) {
@@ -122,7 +122,7 @@ impl Vm {
}
pub fn set_flags(&mut self, flags: Flags) {
self.set_reg(Reg::Flags, flags.bits());
self.set_reg(FLAGS, flags.bits());
}
pub fn map_flags<F>(&mut self, mapping: F)
@@ -193,13 +193,13 @@ impl Vm {
Inst::Jz(r1) => {
if !self.flags().contains(Flags::COMPARE) {
let w1 = self.get_reg(r1);
self.set_reg(Reg::Ip, w1);
self.set_reg(IP, w1);
}
}
Inst::Jnz(r1) => {
if self.flags().contains(Flags::COMPARE) {
let w1 = self.get_reg(r1);
self.set_reg(Reg::Ip, w1);
self.set_reg(IP, w1);
}
}
Inst::Load(r1, r2) => {