diff --git a/Cargo.lock b/Cargo.lock index 9c37f8b..3dacab7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -426,11 +426,12 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "curlywas" version = "0.1.0" -source = "git+https://github.com/exoticorn/curlywas.git?rev=d62bc8bf86cff65145d5aea045b81122bc15d709#d62bc8bf86cff65145d5aea045b81122bc15d709" +source = "git+https://github.com/exoticorn/curlywas.git?rev=196719b#196719b35ef377cb7e001554b27ac5de013dcf2b" dependencies = [ "anyhow", "ariadne", "chumsky", + "pico-args", "wasm-encoder", "wasmparser 0.81.0", ] diff --git a/Cargo.toml b/Cargo.toml index 8cbbd05..6bdc23d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,5 +11,5 @@ anyhow = "1" minifb = "0.19" notify = "4" pico-args = "0.4" -curlywas = { git = "https://github.com/exoticorn/curlywas.git", rev = "d62bc8bf86cff65145d5aea045b81122bc15d709" } +curlywas = { git = "https://github.com/exoticorn/curlywas.git", rev = "196719b" } uw8-tool = { path = "uw8-tool" } \ No newline at end of file diff --git a/platform/Cargo.lock b/platform/Cargo.lock index ed42583..2d513c7 100644 --- a/platform/Cargo.lock +++ b/platform/Cargo.lock @@ -146,11 +146,12 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "curlywas" version = "0.1.0" -source = "git+https://github.com/exoticorn/curlywas.git?rev=c0140d0#c0140d0671e81b57e8fd142c66c675a659fd50f8" +source = "git+https://github.com/exoticorn/curlywas.git?rev=196719b#196719b35ef377cb7e001554b27ac5de013dcf2b" dependencies = [ "anyhow", "ariadne", "chumsky", + "pico-args", "wasm-encoder", "wasmparser", ] diff --git a/platform/Cargo.toml b/platform/Cargo.toml index fb6e338..12ec78c 100644 --- a/platform/Cargo.toml +++ b/platform/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -curlywas = { git="https://github.com/exoticorn/curlywas.git", rev="c0140d0" } +curlywas = { git="https://github.com/exoticorn/curlywas.git", rev="196719b" } uw8-tool = { path="../uw8-tool" } anyhow = "1" lodepng = "3.4" \ No newline at end of file diff --git a/platform/bin/loader.wasm b/platform/bin/loader.wasm index dc8fc96..727985b 100644 Binary files a/platform/bin/loader.wasm and b/platform/bin/loader.wasm differ diff --git a/platform/bin/platform.uw8 b/platform/bin/platform.uw8 index c1ba9e9..3109472 100644 Binary files a/platform/bin/platform.uw8 and b/platform/bin/platform.uw8 differ diff --git a/platform/src/loader.cwa b/platform/src/loader.cwa index 7540fe8..2bccfbb 100644 --- a/platform/src/loader.cwa +++ b/platform/src/loader.cwa @@ -3,7 +3,7 @@ import "env.memory" memory(4); global mut base_end: i32 = 0; export fn load_uw8(module_size: i32) -> i32 { - let lazy version = ?0 - 1; + let lazy version = 0?0 - 1; if version < 0 { return module_size; } @@ -21,10 +21,10 @@ export fn load_uw8(module_size: i32) -> i32 { let src = 0x1e001; loop sections { - if src < module_end & (base_start >= base_end | ?src <= ?base_start) { + if src < module_end & (base_start >= base_end | src?0 <= base_start?0) { let lazy length2 = copy_section(dest, src); dest = dest + length2; - if base_start < base_end & ?src == ?base_start { + if base_start < base_end & src?0 == base_start?0 { base_start = base_start + section_size(base_start); } src = src + length2; @@ -47,7 +47,7 @@ fn section_size(ptr: i32) -> i32 { let l = 0; let shift = 0; loop size { - let lazy b = ?p; + let lazy b = p?0; l = l | ((b & 127) << shift); shift = shift + 7; p = p + 1; @@ -65,7 +65,7 @@ fn copy_section(dest: i32, src: i32) -> i32 { fn copy(dest: i32, src: i32, len: i32) { if len > 0 { loop bytes { - ?(dest + (len := len - 1)) = ?(src + len); + (dest + (len := len - 1))?0 = (src + len)?0; branch_if len: bytes } } @@ -142,7 +142,7 @@ fn upkr_bit(context_index: i32) -> i32 { loop refill { if upkr_state < 1<<16 { - upkr_state = (upkr_state << 8) | ?upkr_src_ptr; + upkr_state = (upkr_state << 8) | upkr_src_ptr?0; upkr_src_ptr = upkr_src_ptr + 1; branch refill; } diff --git a/platform/src/main.rs b/platform/src/main.rs index 288465a..3ae45ec 100644 --- a/platform/src/main.rs +++ b/platform/src/main.rs @@ -11,13 +11,13 @@ fn main() -> Result<()> { convert_font()?; println!("Compiling loader module"); - let loader = curlywas::compile_file("src/loader.cwa")?; + let loader = curlywas::compile_file("src/loader.cwa", curlywas::Options::default())?; File::create("bin/loader.wasm")?.write_all(&loader)?; println!("Loader (including base module): {} bytes", loader.len()); println!("Compiling platform module"); - let platform = curlywas::compile_file("src/platform.cwa")?; + let platform = curlywas::compile_file("src/platform.cwa", curlywas::Options::default())?; println!("Compressing platform module"); let platform = uw8_tool::pack( &platform, diff --git a/platform/src/platform.cwa b/platform/src/platform.cwa index e986fdc..c2ffa81 100644 --- a/platform/src/platform.cwa +++ b/platform/src/platform.cwa @@ -135,6 +135,89 @@ export fn circle(cx: f32, cy: f32, radius: f32, col: i32) { } } +export fn line(x1: f32, y1: f32, x2: f32, y2: f32, col: i32) { + let swapTmp: f32; + if x1 > x2 { + swapTmp = x1; + x1 = x2; + x2 = swapTmp; + swapTmp = y1; + y1 = y2; + y2 = swapTmp; + } + if x1 < 0 as f32 & x2 >= 0 as f32 { + y1 = y1 + (y2 - y1) * -x1 / (x2 - x1); + x1 = 0 as f32; + } + if x1 < 320 as f32 & x2 >= 320 as f32 { + y2 = y2 + (y2 - y1) * (320 as f32 - x2) / (x2 - x1); + x2 = 320 as f32; + } + + if y1 > y2 { + swapTmp = x1; + x1 = x2; + x2 = swapTmp; + swapTmp = y1; + y1 = y2; + y2 = swapTmp; + } + if y1 < 0 as f32 & y2 >= 0 as f32 { + x1 = x1 + (x2 - x1) * -y1 / (y2 - y1); + y1 = 0 as f32; + } + if y1 < 240 as f32 & y2 >= 240 as f32 { + x2 = x2 + (x2 - x1) * (240 as f32 - y2) / (y2 - y1); + y2 = 240 as f32; + } + + let lazy dx = x2 - x1; + let lazy dy = y2 - y1; + let max_axis: f32; + let p: f32; + if abs(dx) >= dy { + max_axis = dx; + p = x1; + } else { + max_axis = dy; + p = y1; + } + + let steps = floor(p + max_axis) as i32 - floor(p) as i32; + p = floor(p) + 0.5 - p; + if max_axis < 0 as f32 { + steps = -steps; + p = -p; + max_axis = -max_axis; + } + dx = dx / max_axis; + dy = dy / max_axis; + + let f = min(max_axis, max(0 as f32, p)); + setPixel((x1 + f * dx) as i32, (y1 + f * dy) as i32, col); + + if !steps { + return; + } + + x1 = x1 + (1 as f32 + p) * dx; + y1 = y1 + (1 as f32 + p) * dy; + + p = p + steps as f32; + + loop pixels { + if steps := steps - 1 { + setPixel(x1 as i32, y1 as i32, col); + x1 = x1 + dx; + y1 = y1 + dy; + branch pixels; + } + } + + f = min(max_axis, p) - p; + setPixel((x1 + f * dx) as i32, (y1 + f * dy) as i32, col); +} + ////////// // TEXT // ////////// diff --git a/src/main.rs b/src/main.rs index a6e311e..48d0ff9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -97,7 +97,7 @@ 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)?; + cart = curlywas::compile_str(&src, filename, curlywas::Options::default())?; } if config.pack { diff --git a/uw8-tool/src/base_module.rs b/uw8-tool/src/base_module.rs index 1085adb..c59a93b 100644 --- a/uw8-tool/src/base_module.rs +++ b/uw8-tool/src/base_module.rs @@ -76,6 +76,7 @@ impl BaseModule { add_function(&mut functions, &type_map, "hline", &[I32, I32, I32, I32], None); add_function(&mut functions, &type_map, "rectangle", &[F32, F32, F32, F32, I32], None); add_function(&mut functions, &type_map, "circle", &[F32, F32, F32, I32], None); + add_function(&mut functions, &type_map, "line", &[F32, F32, F32, F32, I32], None); add_function(&mut functions, &type_map, "time", &[], Some(F32)); add_function(&mut functions, &type_map, "isButtonPressed", &[I32], Some(I32));