mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 11:16:42 +01:00
add line function to platform
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -426,11 +426,12 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "curlywas"
|
name = "curlywas"
|
||||||
version = "0.1.0"
|
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 = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"ariadne",
|
"ariadne",
|
||||||
"chumsky",
|
"chumsky",
|
||||||
|
"pico-args",
|
||||||
"wasm-encoder",
|
"wasm-encoder",
|
||||||
"wasmparser 0.81.0",
|
"wasmparser 0.81.0",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ anyhow = "1"
|
|||||||
minifb = "0.19"
|
minifb = "0.19"
|
||||||
notify = "4"
|
notify = "4"
|
||||||
pico-args = "0.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" }
|
uw8-tool = { path = "uw8-tool" }
|
||||||
3
platform/Cargo.lock
generated
3
platform/Cargo.lock
generated
@@ -146,11 +146,12 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "curlywas"
|
name = "curlywas"
|
||||||
version = "0.1.0"
|
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 = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"ariadne",
|
"ariadne",
|
||||||
"chumsky",
|
"chumsky",
|
||||||
|
"pico-args",
|
||||||
"wasm-encoder",
|
"wasm-encoder",
|
||||||
"wasmparser",
|
"wasmparser",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[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" }
|
uw8-tool = { path="../uw8-tool" }
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
lodepng = "3.4"
|
lodepng = "3.4"
|
||||||
Binary file not shown.
Binary file not shown.
@@ -3,7 +3,7 @@ import "env.memory" memory(4);
|
|||||||
global mut base_end: i32 = 0;
|
global mut base_end: i32 = 0;
|
||||||
|
|
||||||
export fn load_uw8(module_size: i32) -> i32 {
|
export fn load_uw8(module_size: i32) -> i32 {
|
||||||
let lazy version = ?0 - 1;
|
let lazy version = 0?0 - 1;
|
||||||
if version < 0 {
|
if version < 0 {
|
||||||
return module_size;
|
return module_size;
|
||||||
}
|
}
|
||||||
@@ -21,10 +21,10 @@ export fn load_uw8(module_size: i32) -> i32 {
|
|||||||
let src = 0x1e001;
|
let src = 0x1e001;
|
||||||
|
|
||||||
loop sections {
|
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);
|
let lazy length2 = copy_section(dest, src);
|
||||||
dest = dest + length2;
|
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);
|
base_start = base_start + section_size(base_start);
|
||||||
}
|
}
|
||||||
src = src + length2;
|
src = src + length2;
|
||||||
@@ -47,7 +47,7 @@ fn section_size(ptr: i32) -> i32 {
|
|||||||
let l = 0;
|
let l = 0;
|
||||||
let shift = 0;
|
let shift = 0;
|
||||||
loop size {
|
loop size {
|
||||||
let lazy b = ?p;
|
let lazy b = p?0;
|
||||||
l = l | ((b & 127) << shift);
|
l = l | ((b & 127) << shift);
|
||||||
shift = shift + 7;
|
shift = shift + 7;
|
||||||
p = p + 1;
|
p = p + 1;
|
||||||
@@ -65,7 +65,7 @@ fn copy_section(dest: i32, src: i32) -> i32 {
|
|||||||
fn copy(dest: i32, src: i32, len: i32) {
|
fn copy(dest: i32, src: i32, len: i32) {
|
||||||
if len > 0 {
|
if len > 0 {
|
||||||
loop bytes {
|
loop bytes {
|
||||||
?(dest + (len := len - 1)) = ?(src + len);
|
(dest + (len := len - 1))?0 = (src + len)?0;
|
||||||
branch_if len: bytes
|
branch_if len: bytes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,7 +142,7 @@ fn upkr_bit(context_index: i32) -> i32 {
|
|||||||
|
|
||||||
loop refill {
|
loop refill {
|
||||||
if upkr_state < 1<<16 {
|
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;
|
upkr_src_ptr = upkr_src_ptr + 1;
|
||||||
branch refill;
|
branch refill;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ fn main() -> Result<()> {
|
|||||||
convert_font()?;
|
convert_font()?;
|
||||||
|
|
||||||
println!("Compiling loader module");
|
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)?;
|
File::create("bin/loader.wasm")?.write_all(&loader)?;
|
||||||
|
|
||||||
println!("Loader (including base module): {} bytes", loader.len());
|
println!("Loader (including base module): {} bytes", loader.len());
|
||||||
|
|
||||||
println!("Compiling platform module");
|
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");
|
println!("Compressing platform module");
|
||||||
let platform = uw8_tool::pack(
|
let platform = uw8_tool::pack(
|
||||||
&platform,
|
&platform,
|
||||||
|
|||||||
@@ -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 //
|
// TEXT //
|
||||||
//////////
|
//////////
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ fn load_cart(filename: &Path, uw8: &mut MicroW8, config: &Config) -> Result<()>
|
|||||||
|
|
||||||
if cart[0] >= 10 {
|
if cart[0] >= 10 {
|
||||||
let src = String::from_utf8(cart)?;
|
let src = String::from_utf8(cart)?;
|
||||||
cart = curlywas::compile_str(&src)?;
|
cart = curlywas::compile_str(&src, filename, curlywas::Options::default())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.pack {
|
if config.pack {
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ impl BaseModule {
|
|||||||
add_function(&mut functions, &type_map, "hline", &[I32, I32, I32, I32], None);
|
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, "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, "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, "time", &[], Some(F32));
|
||||||
add_function(&mut functions, &type_map, "isButtonPressed", &[I32], Some(I32));
|
add_function(&mut functions, &type_map, "isButtonPressed", &[I32], Some(I32));
|
||||||
|
|||||||
Reference in New Issue
Block a user