crazy hypno + added sleep cmd

pull/21/head
Ondřej Hruška 3 years ago
parent 532df6eb04
commit 01068ea001
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 12
      crsn/src/asm/parse/parse_data.rs
  2. 4
      crsn/src/builtin/defs.rs
  3. 4
      crsn/src/builtin/exec.rs
  4. 6
      crsn/src/builtin/parse.rs
  5. 14
      launcher/src/main.rs

@ -6,6 +6,7 @@ use crate::asm::data::{DataDisp, Rd, RdData, reg, Wr, WrData};
use crate::asm::data::literal::Label;
use crate::asm::error::CrsnError;
use crate::asm::parse::sexp_expect::expect_string_atom;
use std::borrow::Cow;
/// Parse a label
pub fn parse_label(name: Option<Sexp>) -> Result<Label, CrsnError> {
@ -47,12 +48,17 @@ pub fn parse_data_disp(tok: Option<Sexp>) -> Result<DataDisp, CrsnError> {
}
pub fn parse_u64(literal: &str) -> anyhow::Result<u64> {
if let Some(hex) = literal.strip_prefix("0x") {
let mut without_underscores = Cow::Borrowed(literal);
if without_underscores.contains('_') {
without_underscores = without_underscores.replace('_', "").into();
}
if let Some(hex) = without_underscores.strip_prefix("0x") {
Ok(u64::from_str_radix(hex, 16)?)
} else if let Some(hex) = literal.strip_prefix("0b") {
} else if let Some(hex) = without_underscores.strip_prefix("0b") {
Ok(u64::from_str_radix(hex, 2)?)
} else {
Ok(u64::from_str_radix(literal, 10)?)
Ok(u64::from_str_radix(&without_underscores, 10)?)
}
}

@ -8,6 +8,10 @@ pub enum BuiltinOp {
Nop,
/// Stop execution
Halt,
/// Sleep
Sleep {
micros: Rd,
},
/// Mark a jump target.
Label(Label),
/// Jump to a label

@ -6,6 +6,7 @@ use crate::module::{EvalRes, OpTrait};
use crate::runtime::fault::Fault;
use crate::runtime::frame::StackFrame;
use crate::runtime::run_thread::{state::RunState, ThreadInfo};
use std::time::Duration;
impl OpTrait for BuiltinOp {
fn execute(&self, info: &ThreadInfo, state: &mut RunState) -> Result<EvalRes, Fault> {
@ -137,6 +138,9 @@ impl OpTrait for BuiltinOp {
let x = state.read(*src)?;
state.frame.status.load(x);
}
BuiltinOp::Sleep { micros } => {
std::thread::sleep(Duration::from_micros(state.read(*micros)?))
}
BuiltinOp::Drop(obj) => {
let x = state.read(Rd::new(RdData::Register(obj.reg())))?;

@ -38,6 +38,12 @@ impl CrsnExtension for BuiltinOps {
BuiltinOp::Halt
}
"sleep" => {
BuiltinOp::Sleep {
micros: args.next_rd()?,
}
}
"j" => {
let dest = parse_label(args.next())?;
BuiltinOp::Jump(dest)

@ -77,29 +77,29 @@ fn main() {
let program = "
(
(main
(sc-init 640 480)
(sc-init 800 600)
(sc-opt 1 0) ; auto blit
(sc-opt 2 60) ; frame rate
(ld r0 39) ; x
(ld r0 5) ; x
(ld r1 0) ; y
(ld r2 1) ; dx
(ld r3 1) ; dy
(ld r5 0xffffff)
(ld r5 0x3300ff)
(:loop)
(add r5 0x010001)
(add r5 0x000001)
(and r5 0xffffff)
(sc-px r0 r1 r5)
(sc-blit 0)
(add r0 r2)
(add r1 r3)
(cmp r0 639 (eq? (ld r2 -1)))
(cmp r0 799 (eq? (ld r2 -1)))
(cmp r0 0 (eq? (ld r2 1)))
(cmp r1 479 (eq? (ld r3 -1)))
(cmp r1 599 (eq? (ld r3 -1)))
(cmp r1 0 (eq? (ld r3 1)))
(sc-blit 0)
(j :loop)
)
)

Loading…
Cancel
Save