read program from file; fmt, cleanup

This commit is contained in:
2020-09-29 13:27:54 +02:00
parent 01068ea001
commit c37408c7a2
21 changed files with 529 additions and 143 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
use crsn::asm::data::{Rd, RdObj, Wr};
use crsn::asm::data::Rd;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ScreenOp {
+18 -21
View File
@@ -1,18 +1,15 @@
use std::collections::{HashMap, VecDeque};
use std::ops::Sub;
use std::time::{Duration, Instant};
use minifb::{ScaleMode, Window, WindowOptions};
use crsn::asm::data::literal::Value;
use crsn::asm::instr::Cond;
use crsn::module::{CrsnExtension, EvalRes, OpTrait};
use crsn::module::{EvalRes, OpTrait};
use crsn::runtime::fault::Fault;
use crsn::runtime::run_thread::{state::RunState, ThreadInfo};
use crate::defs::ScreenOp;
use minifb::{Window, WindowOptions, ScaleMode};
use parking_lot::Mutex;
use std::sync::Arc;
use std::time::{Instant, Duration};
use std::ops::Sub;
use crsn::utils::UncheckedOptionExt;
#[derive(Debug)]
struct Opts {
@@ -27,7 +24,7 @@ struct Backend {
buffer: Vec<u32>,
window: Option<Window>,
last_render: Instant,
opts: Opts
opts: Opts,
}
impl Default for Backend {
@@ -41,19 +38,19 @@ impl Default for Backend {
opts: Opts {
auto_blit: true,
frame_rate: Duration::from_micros(16600),
}
},
}
}
}
const OPT_AUTO_BLIT : u64 = 1;
const OPT_FRAME_RATE : u64 = 2;
const OPT_AUTO_BLIT: u64 = 1;
const OPT_FRAME_RATE: u64 = 2;
// Hack for Window
unsafe impl std::marker::Send for Backend { }
unsafe impl std::marker::Send for Backend {}
impl OpTrait for ScreenOp {
fn execute(&self, info: &ThreadInfo, state: &mut RunState) -> Result<EvalRes, Fault> {
fn execute(&self, _info: &ThreadInfo, state: &mut RunState) -> Result<EvalRes, Fault> {
let eres = EvalRes::default();
match self {
ScreenOp::ScreenInit { width, height } => {
@@ -64,11 +61,11 @@ impl OpTrait for ScreenOp {
ScreenOp::SetOpt { opt, val } => {
let opt = state.read(*opt)?;
let val = state.read(*val)?;
let backend : &mut Backend = state.ext_mut();
let backend: &mut Backend = state.ext_mut();
match opt {
OPT_AUTO_BLIT => {
backend.opts.auto_blit = (val != 0);
backend.opts.auto_blit = val != 0;
debug!("Set auto blit to {:?}", backend.opts.auto_blit);
}
OPT_FRAME_RATE => {
@@ -83,7 +80,7 @@ impl OpTrait for ScreenOp {
}
ScreenOp::Blit { force } => {
let force = state.read(*force)?;
let backend : &mut Backend = state.ext_mut();
let backend: &mut Backend = state.ext_mut();
if force != 0 {
blit(backend)
@@ -96,7 +93,7 @@ impl OpTrait for ScreenOp {
let y = state.read(*y)?;
let color = state.read(*color)?;
let backend : &mut Backend = state.ext_mut();
let backend: &mut Backend = state.ext_mut();
if x >= backend.width as u64 || y >= backend.height as u64 {
state.set_flag(Cond::Overflow, true);
@@ -104,7 +101,7 @@ impl OpTrait for ScreenOp {
}
match &mut backend.window {
Some(w) => {
Some(_w) => {
let index = y * backend.width as u64 + x;
if index as usize > backend.buffer.len() {
warn!("Screen set pixel out of bounds");
@@ -130,7 +127,7 @@ impl OpTrait for ScreenOp {
}
fn init(state: &mut RunState, width: Value, height: Value) -> Result<(), Fault> {
let mut window = Window::new(
let window = Window::new(
"Croissant",
width as usize,
height as usize,
@@ -142,7 +139,7 @@ fn init(state: &mut RunState, width: Value, height: Value) -> Result<(), Fault>
).expect("Unable to create window"); // TODO fault
let backend : &mut Backend = state.ext_mut();
let backend: &mut Backend = state.ext_mut();
if backend.window.is_some() {
return Err(Fault::NotAllowed("Screen already initialized".into()));
+3 -3
View File
@@ -1,10 +1,10 @@
#[macro_use]
extern crate log;
use crsn::module::{CrsnExtension, ParseOpRes};
use crsn::asm::parse::arg_parser::ArgParser;
use crsn::asm::instr::Op;
use crsn::asm::error::CrsnError;
use crsn::asm::instr::Op;
use crsn::asm::parse::arg_parser::ArgParser;
use crsn::module::{CrsnExtension, ParseOpRes};
mod defs;
mod parse;