add error print, allow entering null

This commit is contained in:
5225225 2020-06-06 21:37:02 +01:00
parent f438280d6c
commit ad17d8f8b2
1 changed files with 5 additions and 2 deletions

View File

@ -68,7 +68,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) => self.SIN[v as usize] = val, Arg::SIN(v) => {},
Arg::SMAIN(v) => self.SMAIN[v as usize] = val, Arg::SMAIN(v) => self.SMAIN[v as usize] = val,
} }
} }
@ -458,6 +458,7 @@ impl Arg {
impl Machine { impl Machine {
fn step(&mut self) -> bool { fn step(&mut self) -> bool {
let (ci, inc_by) = parse_instruction(&self.SCODE[(self.IP as usize)..]); let (ci, inc_by) = parse_instruction(&self.SCODE[(self.IP as usize)..]);
eprintln!("{:?}", ci);
//dbg!(&ci); //dbg!(&ci);
let oc = ci.def.opcode(); let oc = ci.def.opcode();
@ -545,9 +546,11 @@ impl Machine {
self.RSTAT.set(Flags::FZERO, val == 0); self.RSTAT.set(Flags::FZERO, val == 0);
} }
OP::READ => { OP::READ => {
let input = 0; let mut input = 0;
std::io::stdin().read(&mut [input]).unwrap(); std::io::stdin().read(&mut [input]).unwrap();
if input == b'~' { input = 0; }
self.write(ci.args[0], input as u16); self.write(ci.args[0], input as u16);
self.RSTAT.set(Flags::FZERO, input == 0); self.RSTAT.set(Flags::FZERO, input == 0);
} }