|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use simple_logger::SimpleLogger;
|
|
|
|
|
|
|
|
use crsn::asm::data::literal::Addr;
|
|
|
|
use crsn::runtime::run_thread::{RunThread, ThreadToken};
|
|
|
|
use crsn::runtime::run_thread;
|
|
|
|
use crsn_arith::ArithOps;
|
|
|
|
use crsn_stacks::StackOps;
|
|
|
|
use crsn_screen::ScreenOps;
|
|
|
|
use std::time::Duration;
|
|
|
|
use log::LevelFilter;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
SimpleLogger::new()
|
|
|
|
.with_level(LevelFilter::Warn)
|
|
|
|
.init().unwrap();
|
|
|
|
|
|
|
|
// ;(dec r0 (z? (ret)))
|
|
|
|
/*let program = "
|
|
|
|
(
|
|
|
|
(main
|
|
|
|
(ld r0 2)
|
|
|
|
(:again)
|
|
|
|
(dec r0)
|
|
|
|
(jif nz :again)
|
|
|
|
(fault \"that's it\")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
";*/
|
|
|
|
/*
|
|
|
|
let program = "
|
|
|
|
(
|
|
|
|
(main
|
|
|
|
(ld r0 2)
|
|
|
|
(call add2x r0 15)
|
|
|
|
(ld r0 res0)
|
|
|
|
(fault \"that's it\")
|
|
|
|
)
|
|
|
|
(add2x
|
|
|
|
(ld r0 arg0)
|
|
|
|
(ld r1 arg1)
|
|
|
|
(add r0 r1)
|
|
|
|
(add r0 r1)
|
|
|
|
(ret r0)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
";*/
|
|
|
|
|
|
|
|
/* let program = "
|
|
|
|
(
|
|
|
|
(main
|
|
|
|
(j :lbl)
|
|
|
|
(ld _ arg0)
|
|
|
|
(fault)
|
|
|
|
(:lbl)
|
|
|
|
(call fac 5)
|
|
|
|
(ld r0 res0)
|
|
|
|
)
|
|
|
|
(fac
|
|
|
|
(cmp arg0 2
|
|
|
|
(eq? (ret 2)))
|
|
|
|
(ld r0 arg0)
|
|
|
|
(dec r0)
|
|
|
|
(call fac r0)
|
|
|
|
(ld r0 arg0)
|
|
|
|
(mul r0 res0)
|
|
|
|
(ret r0)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
";*/
|
|
|
|
|
|
|
|
let program = "
|
|
|
|
(
|
|
|
|
(main
|
|
|
|
(sc-init 640 480)
|
|
|
|
|
|
|
|
(ld r0 39) ; x
|
|
|
|
(ld r1 0) ; y
|
|
|
|
|
|
|
|
(ld r2 1) ; dx
|
|
|
|
(ld r3 1) ; dy
|
|
|
|
|
|
|
|
(ld r5 0xffffff)
|
|
|
|
|
|
|
|
(:loop)
|
|
|
|
(add r5 0x123456)
|
|
|
|
(and r5 0xffffff)
|
|
|
|
(sc-px r0 r1 r5)
|
|
|
|
(add r0 r2)
|
|
|
|
(add r1 r3)
|
|
|
|
(cmp r0 639 (eq? (ld r2 -1)))
|
|
|
|
(cmp r0 0 (eq? (ld r2 1)))
|
|
|
|
(cmp r1 479 (eq? (ld r3 -1)))
|
|
|
|
(cmp r1 0 (eq? (ld r3 1)))
|
|
|
|
(j :loop)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
";
|
|
|
|
|
|
|
|
let parsers = Arc::new(vec![
|
|
|
|
ArithOps::new(),
|
|
|
|
StackOps::new(),
|
|
|
|
ScreenOps::new(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
let parsed = crsn::asm::assemble(program, parsers).unwrap();
|
|
|
|
|
|
|
|
let uniq = run_thread::new_uniq();
|
|
|
|
|
|
|
|
let mut thread1 = RunThread::new(ThreadToken(0), Some(uniq.clone()), parsed.clone(), Addr(0), &[]);
|
|
|
|
//thread1.set_speed(Duration::from_millis(250));
|
|
|
|
|
|
|
|
let _thread2 = RunThread::new(ThreadToken(1), Some(uniq), parsed.clone(), Addr(0), &[]);
|
|
|
|
|
|
|
|
let a = thread1.start();
|
|
|
|
//let b = thread2.start();
|
|
|
|
|
|
|
|
a.join().unwrap();
|
|
|
|
//b.join().unwrap();
|
|
|
|
}
|