summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/forth/vm.rs6
-rwxr-xr-xsrc/lib.rs8
2 files changed, 11 insertions, 3 deletions
diff --git a/src/forth/vm.rs b/src/forth/vm.rs
index 564a647..25ed516 100644
--- a/src/forth/vm.rs
+++ b/src/forth/vm.rs
@@ -4,9 +4,9 @@ use std::ops::Index;
pub type DataStackType = isize;
-const MIN_SPEED: DataStackType = 0;
-const MAX_SPEED: DataStackType = 10;
-const UNITS_PER_ROTATION: DataStackType = 360;
+pub const MIN_SPEED: DataStackType = 0;
+pub const MAX_SPEED: DataStackType = 10;
+pub const UNITS_PER_ROTATION: DataStackType = 360;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum OpCode {
diff --git a/src/lib.rs b/src/lib.rs
index 2aedfff..240acf1 100755
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -135,6 +135,14 @@ impl ExportedVM {
vm.ip.offset = 0;
}
+ pub fn setheading(&mut self, v: forth::vm::DataStackType) {
+ let Some(vm) = &mut self.vm else {
+ return;
+ };
+ use forth::vm::UNITS_PER_ROTATION;
+ vm.heading = (UNITS_PER_ROTATION + (v % UNITS_PER_ROTATION)) % UNITS_PER_ROTATION;
+ }
+
pub fn trans(&mut self) -> Result<js_sys::Object, JsValue> {
let vm = (&mut self.vm).as_mut().ok_or(Error::NoVM)?;
let res = js_sys::Map::new();