This commit is contained in:
5225225 2020-06-06 22:59:03 +01:00
parent eee9bd4ec2
commit e16e71b04a
1 changed files with 151 additions and 155 deletions

View File

@ -1,6 +1,6 @@
use byteorder::{ReadBytesExt, LE}; use byteorder::{ReadBytesExt, LE};
use std::convert::{TryFrom, TryInto};
use std::io::Cursor; use std::io::Cursor;
use std::convert::{TryInto, TryFrom};
use std::io::Read; use std::io::Read;
struct Machine { struct Machine {
@ -40,9 +40,9 @@ impl Machine {
Register::RY => self.RY = val, Register::RY => self.RY = val,
Register::RZ => self.RZ = val, Register::RZ => self.RZ = val,
Register::RTRGT => self.RTRGT = val, Register::RTRGT => self.RTRGT = val,
Register::RSTAT => {}, // writes have no effect Register::RSTAT => {} // writes have no effect
Register::RCALL => {}, Register::RCALL => {}
Register::NULL => {}, Register::NULL => {}
} }
} }
@ -69,7 +69,7 @@ impl Machine {
fn write(&mut self, a: Arg, val: u16) { fn write(&mut self, a: Arg, val: u16) {
match a { match a {
Arg::Register(r) => self.write_reg(r, val), Arg::Register(r) => self.write_reg(r, val),
Arg::SIN(v) => {}, Arg::SIN(v) => {}
Arg::SMAIN(v) => self.SMAIN[v as usize] = val, Arg::SMAIN(v) => self.SMAIN[v as usize] = val,
} }
} }
@ -100,7 +100,6 @@ impl Register {
} }
} }
bitflags::bitflags! { bitflags::bitflags! {
struct Flags: u16 { struct Flags: u16 {
const FZERO = 0b0000000000000001; const FZERO = 0b0000000000000001;
@ -167,8 +166,6 @@ RCPF = 0x043 ,
impl std::convert::Into<OP> for u16 { impl std::convert::Into<OP> for u16 {
fn into(self) -> OP { fn into(self) -> OP {
match self { match self {
0x000 => OP::HALT, 0x000 => OP::HALT,
0x001 => OP::NOOP, 0x001 => OP::NOOP,
0x002 => OP::INC, 0x002 => OP::INC,
@ -413,9 +410,7 @@ fn parse_instruction(mut bytes: &[u16]) -> (Instruction, usize) {
}; };
match aflg { match aflg {
AFLG::Register => { AFLG::Register => args.push(Arg::Register(registers.remove(0))),
args.push(Arg::Register(registers.remove(0)))
},
AFLG::SIN => { AFLG::SIN => {
args.push(Arg::SIN(bytes[0])); args.push(Arg::SIN(bytes[0]));
bytes = &bytes[1..]; bytes = &bytes[1..];
@ -429,8 +424,6 @@ fn parse_instruction(mut bytes: &[u16]) -> (Instruction, usize) {
} }
} }
(Instruction { def, args }, consumed) (Instruction { def, args }, consumed)
} }
@ -471,7 +464,7 @@ impl Machine {
match oc { match oc {
OP::HALT => return false, OP::HALT => return false,
OP::NOOP => {}, OP::NOOP => {}
OP::XOR => { OP::XOR => {
let arg0 = self.read(ci.args[0]); let arg0 = self.read(ci.args[0]);
let arg1 = self.read(ci.args[1]); let arg1 = self.read(ci.args[1]);
@ -649,7 +642,10 @@ impl Machine {
self.write(ci.args[0], val); self.write(ci.args[0], val);
self.RSTAT.set(Flags::FZERO, val == 0); self.RSTAT.set(Flags::FZERO, val == 0);
} }
_ => { eprintln!("unsupported opcode {:?}", oc); return false; } _ => {
eprintln!("unsupported opcode {:?}", oc);
return false;
}
} }
if should_inc_ip { if should_inc_ip {