Croissant Runtime
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
crsn/crsn_screen/src/parse.rs

97 lines
2.5 KiB

use crsn::asm::data::Rd;
use crsn::asm::error::CrsnError;
use crsn::asm::instr::op::OpKind;
use crsn::asm::parse::arg_parser::TokenParser;
use crsn::module::ParseRes;
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" => {
ScreenOp::ScreenInit {
width: args.next_rd()?,
height: args.next_rd()?,
}
}
"sc-erase" => {
ScreenOp::Erase {
color: if args.len() > 0 {
args.next_rd()?
} else {
Rd::new_imm(0) // black
},
}
}
"sc-px" => {
ScreenOp::SetPixel {
x: args.next_rd()?,
y: args.next_rd()?,
color: args.next_rd()?,
}
}
"sc-opt" => {
let (val, valopt) = args.next_value()?;
ScreenOp::SetOpt {
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()?,
}
}
"sc-blit" => {
ScreenOp::Blit {
force: if args.have_more() {
args.next_rd()?
} else {
Rd::new_imm(1)
},
}
}
"sc-poll" => {
ScreenOp::Update
}
"sc-mouse" => {
ScreenOp::GetMouse {
x: args.next_wr()?,
y: args.next_wr()?,
}
}
"sc-key" => {
ScreenOp::TestKey {
pressed: args.next_wr()?,
code: args.next_rd()?,
}
}
"sc-mbtn" => {
ScreenOp::TestMouse {
pressed: args.next_wr()?,
button: args.next_rd()?,
}
}
_other => {
return Ok(ParseRes::Unknown(args));
}
}))
}