rewrite the stdio module to be less broken. also add sehbang support

This commit is contained in:
2020-10-10 18:46:32 +02:00
parent 982ba27ed3
commit ace92a6411
21 changed files with 357 additions and 171 deletions
+12 -12
View File
@@ -4,7 +4,6 @@ use std::time::{Duration, Instant};
use minifb::{Key, MouseButton, MouseMode, ScaleMode, Window, WindowOptions};
use crsn::asm::data::literal::Value;
use crsn::asm::instr::Cond;
use crsn::module::{EvalRes, OpTrait};
use crsn::runtime::fault::Fault;
use crsn::runtime::run_thread::{state::RunState, ThreadInfo};
@@ -13,6 +12,7 @@ use crsn::sexp::Sexp;
use crsn::utils::A;
use crate::defs::ScreenOp;
use crsn::asm::instr::cond::Flag;
#[derive(Debug)]
struct Opts {
@@ -87,7 +87,7 @@ impl OpTrait for ScreenOp {
}
other => {
warn!("Bad screen opt: {}", other);
state.set_flag(Cond::Invalid, true);
state.set_flag(Flag::Invalid, true);
}
}
}
@@ -115,7 +115,7 @@ impl OpTrait for ScreenOp {
w.update();
}
None => {
state.set_flag(Cond::Invalid, true);
state.set_flag(Flag::Invalid, true);
}
}
}
@@ -129,7 +129,7 @@ impl OpTrait for ScreenOp {
let backend: &mut Backend = state.ext_mut();
if x >= backend.width as u64 || y >= backend.height as u64 {
state.set_flag(Cond::Overflow, true);
state.set_flag(Flag::Overflow, true);
return Ok(eres);
}
@@ -138,7 +138,7 @@ impl OpTrait for ScreenOp {
let index = y * backend.width as u64 + x;
if index as usize > backend.buffer.len() {
warn!("Screen set pixel out of bounds");
state.set_flag(Cond::Invalid, true);
state.set_flag(Flag::Invalid, true);
} else {
backend.buffer[index as usize] = color as u32;
@@ -148,7 +148,7 @@ impl OpTrait for ScreenOp {
}
}
None => {
state.set_flag(Cond::Invalid, true);
state.set_flag(Flag::Invalid, true);
}
}
}
@@ -162,7 +162,7 @@ impl OpTrait for ScreenOp {
debug!("mp = {:?}", mp);
match mp {
None => {
state.set_flag(Cond::Overflow, true);
state.set_flag(Flag::Overflow, true);
}
Some((xf, yf)) => {
let xval = xf.round() as u64;
@@ -174,7 +174,7 @@ impl OpTrait for ScreenOp {
}
}
None => {
state.set_flag(Cond::Invalid, true);
state.set_flag(Flag::Invalid, true);
}
}
}
@@ -187,7 +187,7 @@ impl OpTrait for ScreenOp {
Some(w) => {
match num {
None => {
state.set_flag(Cond::Invalid, true);
state.set_flag(Flag::Invalid, true);
}
Some(kn) => {
let down = w.is_key_down(kn) as u64;
@@ -197,7 +197,7 @@ impl OpTrait for ScreenOp {
}
}
None => {
state.set_flag(Cond::Invalid, true);
state.set_flag(Flag::Invalid, true);
}
}
}
@@ -210,7 +210,7 @@ impl OpTrait for ScreenOp {
1 => Some(MouseButton::Right),
2 => Some(MouseButton::Middle),
_ => {
state.set_flag(Cond::Invalid, true);
state.set_flag(Flag::Invalid, true);
None
}
};
@@ -225,7 +225,7 @@ impl OpTrait for ScreenOp {
}
}
None => {
state.set_flag(Cond::Invalid, true);
state.set_flag(Flag::Invalid, true);
}
}
}