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

83 lines
1.9 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 crate::defs::ScreenOp;
pub(crate) fn parse<'a>(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::immediate(0) // black
},
}
}
"sc-px" => {
ScreenOp::SetPixel {
x: args.next_rd()?,
y: args.next_rd()?,
color: args.next_rd()?,
}
}
"sc-opt" => {
ScreenOp::SetOpt {
opt: args.next_rd()?,
val: args.next_rd()?,
}
}
"sc-blit" => {
ScreenOp::Blit {
force: if args.have_more() {
args.next_rd()?
} else {
Rd::immediate(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));
}
}))
}