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/lib.rs

162 lines
7.1 KiB

#[macro_use]
extern crate log;
use crsn::asm::error::CrsnError;
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, OPT_UPSCALE};
use minifb::Key;
mod defs;
mod parse;
mod exec;
#[derive(Debug, Clone)]
pub struct ScreenOps;
impl ScreenOps {
pub fn new() -> Box<dyn CrsnExtension> {
Box::new(Self)
}
}
impl CrsnExtension for ScreenOps {
fn name(&self) -> &'static str {
"screen"
}
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" | "SCREEN_AUTOBLIT" => Some(OPT_AUTO_BLIT),
"SCREEN_FPS" => Some(OPT_FRAME_RATE),
"SCREEN_UPSCALE" => Some(OPT_UPSCALE),
"MBTN_LEFT" => Some(0),
"MBTN_RIGHT" => Some(1),
"MBTN_MIDDLE" | "MBTN_MID" => Some(2),
"KEY_0" => Some(Key::Key0 as Value), // 0
"KEY_1" => Some(Key::Key1 as Value),
"KEY_2" => Some(Key::Key2 as Value),
"KEY_3" => Some(Key::Key3 as Value),
"KEY_4" => Some(Key::Key4 as Value),
"KEY_5" => Some(Key::Key5 as Value),
"KEY_6" => Some(Key::Key6 as Value),
"KEY_7" => Some(Key::Key7 as Value),
"KEY_8" => Some(Key::Key8 as Value),
"KEY_9" => Some(Key::Key9 as Value), // 9
"KEY_A" => Some(Key::A as Value), // 10
"KEY_B" => Some(Key::B as Value),
"KEY_C" => Some(Key::C as Value),
"KEY_D" => Some(Key::D as Value),
"KEY_E" => Some(Key::E as Value),
"KEY_F" => Some(Key::F as Value), // 15
"KEY_G" => Some(Key::G as Value),
"KEY_H" => Some(Key::H as Value),
"KEY_I" => Some(Key::I as Value),
"KEY_J" => Some(Key::J as Value),
"KEY_K" => Some(Key::K as Value), // 20
"KEY_L" => Some(Key::L as Value),
"KEY_M" => Some(Key::M as Value),
"KEY_N" => Some(Key::N as Value),
"KEY_O" => Some(Key::O as Value),
"KEY_P" => Some(Key::P as Value), // 25
"KEY_Q" => Some(Key::Q as Value),
"KEY_R" => Some(Key::R as Value),
"KEY_S" => Some(Key::S as Value),
"KEY_T" => Some(Key::T as Value),
"KEY_U" => Some(Key::U as Value), // 30
"KEY_V" => Some(Key::V as Value),
"KEY_W" => Some(Key::W as Value),
"KEY_X" => Some(Key::X as Value),
"KEY_Y" => Some(Key::Y as Value),
"KEY_Z" => Some(Key::Z as Value), // 35
"KEY_F1" => Some(Key::F1 as Value), // 36
"KEY_F2" => Some(Key::F2 as Value),
"KEY_F3" => Some(Key::F3 as Value),
"KEY_F4" => Some(Key::F4 as Value),
"KEY_F5" => Some(Key::F5 as Value), // 40
"KEY_F6" => Some(Key::F6 as Value),
"KEY_F7" => Some(Key::F7 as Value),
"KEY_F8" => Some(Key::F8 as Value),
"KEY_F9" => Some(Key::F9 as Value),
"KEY_F10" => Some(Key::F10 as Value), // 45
"KEY_F11" => Some(Key::F11 as Value),
"KEY_F12" => Some(Key::F12 as Value),
"KEY_F13" => Some(Key::F13 as Value),
"KEY_F14" => Some(Key::F14 as Value),
"KEY_F15" => Some(Key::F15 as Value), // 50
"KEY_Down" => Some(Key::Down as Value), // 51
"KEY_Left" => Some(Key::Left as Value), // 52
"KEY_Right" => Some(Key::Right as Value), // 53
"KEY_Up" => Some(Key::Up as Value), // 54
"KEY_Apos" => Some(Key::Apostrophe as Value),
"KEY_Backtick" => Some(Key::Backquote as Value), // 56 (a backtick)
"KEY_Backslash" => Some(Key::Backslash as Value), // 57
"KEY_Comma" => Some(Key::Comma as Value),
"KEY_Equal" => Some(Key::Equal as Value),
"KEY_BracketL" => Some(Key::LeftBracket as Value), // 60 [
"KEY_Minus" => Some(Key::Minus as Value),
"KEY_Period" => Some(Key::Period as Value),
"KEY_BracketR" => Some(Key::RightBracket as Value), // 63 ] *This does not work due to a bug in the library we use - PR is sent upstream https://github.com/emoon/rust_minifb/pull/222*
"KEY_Semicolon" => Some(Key::Semicolon as Value),
"KEY_Slash" => Some(Key::Slash as Value), // 65
"KEY_Backspace" => Some(Key::Backspace as Value),
"KEY_Delete" => Some(Key::Delete as Value),
"KEY_End" => Some(Key::End as Value),
"KEY_Enter" => Some(Key::Enter as Value),
"KEY_Escape" => Some(Key::Escape as Value), // 70
"KEY_Home" => Some(Key::Home as Value),
"KEY_Insert" => Some(Key::Insert as Value),
"KEY_Menu" => Some(Key::Menu as Value),
"KEY_PageDown" => Some(Key::PageDown as Value),
"KEY_PageUp" => Some(Key::PageUp as Value),
"KEY_Pause" => Some(Key::Pause as Value), // 76
"KEY_Space" => Some(Key::Space as Value),
"KEY_Tab" => Some(Key::Tab as Value),
"KEY_NumLock" => Some(Key::NumLock as Value),
"KEY_CapsLock" => Some(Key::CapsLock as Value),
"KEY_ScrollLock" => Some(Key::ScrollLock as Value),
"KEY_ShiftL" => Some(Key::LeftShift as Value),
"KEY_ShiftR" => Some(Key::RightShift as Value),
"KEY_CtrlL" => Some(Key::LeftCtrl as Value),
"KEY_CtrlR" => Some(Key::RightCtrl as Value),
"KEY_KP0" => Some(Key::NumPad0 as Value), // 86
"KEY_KP1" => Some(Key::NumPad1 as Value),
"KEY_KP2" => Some(Key::NumPad2 as Value),
"KEY_KP3" => Some(Key::NumPad3 as Value),
"KEY_KP4" => Some(Key::NumPad4 as Value),
"KEY_KP5" => Some(Key::NumPad5 as Value),
"KEY_KP6" => Some(Key::NumPad6 as Value),
"KEY_KP7" => Some(Key::NumPad7 as Value),
"KEY_KP8" => Some(Key::NumPad8 as Value),
"KEY_KP9" => Some(Key::NumPad9 as Value),
"KEY_KPDot" => Some(Key::NumPadDot as Value),
"KEY_KPSlash" => Some(Key::NumPadSlash as Value),
"KEY_KPAsterisk" => Some(Key::NumPadAsterisk as Value),
"KEY_KPMinus" => Some(Key::NumPadMinus as Value),
"KEY_KPPlus" => Some(Key::NumPadPlus as Value),
"KEY_KPEnter" => Some(Key::NumPadEnter as Value), // 100
"KEY_AltL" => Some(Key::LeftAlt as Value),
"KEY_AltR" => Some(Key::RightAlt as Value),
"KEY_WinL" | "KEY_SuperL" | "KEY_MetaL" => Some(Key::LeftSuper as Value),
"KEY_WinR" | "KEY_SuperR" | "KEY_MetaR" => Some(Key::RightSuper as Value),
_ => None
}
}
}