diff --git a/Cargo.lock b/Cargo.lock index 3dacab7..c05b229 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1543,6 +1543,7 @@ dependencies = [ "pico-args", "uw8-tool", "wasmtime", + "wat", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 6bdc23d..e2a01cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,4 +12,5 @@ minifb = "0.19" notify = "4" pico-args = "0.4" curlywas = { git = "https://github.com/exoticorn/curlywas.git", rev = "196719b" } +wat = "1" uw8-tool = { path = "uw8-tool" } \ No newline at end of file diff --git a/examples/wat/xorscroll.wat b/examples/wat/xorscroll.wat new file mode 100644 index 0000000..fdbc09a --- /dev/null +++ b/examples/wat/xorscroll.wat @@ -0,0 +1,26 @@ +(module + (import "env" "memory" (memory 4)) + (func (export "upd") + (local $i i32) ;; local variables are zero initialized + + (loop $pixels + local.get $i ;; pixel index to write to + + (i32.rem_u (local.get $i) (i32.const 320)) ;; x + (i32.div_u (i32.load (i32.const 64)) (i32.const 10)) ;; time / 10 + i32.add + + (i32.div_u (local.get $i) (i32.const 320)) ;; y + + i32.xor ;; (x + time / 10) ^ y + (i32.shr_u (i32.const 3)) ;; .. >> 3 + (i32.and (i32.const 127)) ;; .. & 127 + + i32.store8 offset=120 ;; store at pixel index + 120 + + (i32.add (local.get $i) (i32.const 1)) ;; i + 1 + local.tee $i ;; write it back but keep it on the stack + (br_if $pixels (i32.lt_s (i32.const 76800))) ;; branch to start of loop if i < 320*240 + ) + ) +) diff --git a/platform/src/font.png b/platform/src/font.png index 06c2f99..b262f4b 100644 Binary files a/platform/src/font.png and b/platform/src/font.png differ diff --git a/src/main.rs b/src/main.rs index 48d0ff9..7a13599 100644 --- a/src/main.rs +++ b/src/main.rs @@ -97,7 +97,11 @@ fn load_cart(filename: &Path, uw8: &mut MicroW8, config: &Config) -> Result<()> if cart[0] >= 10 { let src = String::from_utf8(cart)?; - cart = curlywas::compile_str(&src, filename, curlywas::Options::default())?; + cart = if src.chars().find(|c| !c.is_whitespace()) == Some('(') { + wat::parse_str(src)? + } else { + curlywas::compile_str(&src, filename, curlywas::Options::default())? + }; } if config.pack {