AMAZING NEW FEATURES ldn, bfio

This commit is contained in:
2020-10-11 01:35:19 +02:00
parent 74e3716ce4
commit 4062ff4d09
17 changed files with 400 additions and 109 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
use crsn::asm::data::{Rd, Wr};
use crsn::asm::data::literal::Value;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ScreenOp {
@@ -31,7 +32,7 @@ pub enum ScreenOp {
force: Rd,
},
SetOpt {
opt: Rd,
opt: Value,
val: Rd,
},
}
+5 -7
View File
@@ -46,8 +46,8 @@ impl Default for Backend {
}
}
const OPT_AUTO_BLIT: u64 = 1;
const OPT_FRAME_RATE: u64 = 2;
pub const OPT_AUTO_BLIT: u64 = 1;
pub const OPT_FRAME_RATE: u64 = 2;
// Hack for Window
unsafe impl std::marker::Send for Backend {}
@@ -72,11 +72,10 @@ impl OpTrait for ScreenOp {
ScreenOp::SetOpt { opt, val } => {
state.clear_status();
let opt = state.read(opt)?;
let val = state.read(val)?;
let backend: &mut Backend = state.ext_mut();
match opt {
match *opt {
OPT_AUTO_BLIT => {
backend.opts.auto_blit = val != 0;
debug!("Set auto blit to {:?}", backend.opts.auto_blit);
@@ -85,9 +84,8 @@ impl OpTrait for ScreenOp {
backend.opts.frame_rate = Duration::from_micros(1_000_000 as u64 / val);
debug!("Set frame rate to {:?}", backend.opts.frame_rate);
}
other => {
warn!("Bad screen opt: {}", other);
state.set_flag(Flag::Invalid, true);
_other => {
unreachable!()
}
}
}
+13
View File
@@ -6,6 +6,8 @@ use crsn::asm::instr::op::OpKind;
use crsn::asm::parse::arg_parser::TokenParser;
use crsn::module::{CrsnExtension, ParseRes};
use crsn::sexp::SourcePosition;
use crsn::asm::data::literal::Value;
use crate::exec::{OPT_AUTO_BLIT, OPT_FRAME_RATE};
mod defs;
mod parse;
@@ -28,4 +30,15 @@ impl CrsnExtension for ScreenOps {
fn parse_op<'a>(&self, pos: &SourcePosition, keyword: &str, args: TokenParser<'a>) -> Result<ParseRes<'a, OpKind>, CrsnError> {
parse::parse(pos, keyword, args)
}
/// Get value of an extension-provided constant.
/// This constant may be an object handle, or a constant value used as argument in some other instruction.
fn get_constant_value<'a>(&self, name: &str) -> Option<Value>
{
match name {
"SCREEN_AUTO_BLIT" => Some(OPT_AUTO_BLIT),
"SCREEN_FPS" => Some(OPT_FRAME_RATE),
_ => None
}
}
}
+15 -1
View File
@@ -7,6 +7,9 @@ use crsn::sexp::SourcePosition;
use crate::defs::ScreenOp;
use super::exec::OPT_AUTO_BLIT;
use super::exec::OPT_FRAME_RATE;
pub(crate) fn parse<'a>(_pos: &SourcePosition, keyword: &str, mut args: TokenParser<'a>) -> Result<ParseRes<'a, OpKind>, CrsnError> {
Ok(ParseRes::ext(match keyword {
"sc-init" => {
@@ -35,8 +38,19 @@ pub(crate) fn parse<'a>(_pos: &SourcePosition, keyword: &str, mut args: TokenPar
}
"sc-opt" => {
let (val, valopt) = args.next_value()?;
ScreenOp::SetOpt {
opt: args.next_rd()?,
opt: match val {
OPT_AUTO_BLIT => {
OPT_AUTO_BLIT // TODO use enum
}
OPT_FRAME_RATE => {
OPT_FRAME_RATE
}
_ => {
return Err(CrsnError::Parse("Bad screen option".into(), valopt));
}
},
val: args.next_rd()?,
}
}