mirror of
https://github.com/exoticorn/curlywas.git
synced 2026-01-20 11:46:43 +01:00
move examples into subfolder, added wasm4 skip_ahead
This commit is contained in:
35
examples/microw8/random.cwa
Normal file
35
examples/microw8/random.cwa
Normal file
@@ -0,0 +1,35 @@
|
||||
import "env.memory" memory(4);
|
||||
|
||||
global mut randomState: i64 = 37i64;
|
||||
|
||||
fn random() -> i32 {
|
||||
(random64() >> 32i64) as i32
|
||||
}
|
||||
|
||||
fn random64() -> i64 {
|
||||
let state: i64;
|
||||
randomState = (state := (
|
||||
state := randomState ^ (randomState >> 12i64)
|
||||
) ^ (state << 25i64)
|
||||
) ^ (state >> 27i64);
|
||||
randomState * 2685821657736338717i64
|
||||
}
|
||||
|
||||
fn randomf() -> f32 {
|
||||
f32.reinterpret_i32(1065353216 | (random() >> 9)) - 1 as f32
|
||||
}
|
||||
|
||||
fn seed(s: i32) {
|
||||
randomState = (s as i64 << 32i64) ^ ((63 - s) as i64);
|
||||
randomState = random64();
|
||||
randomState = random64();
|
||||
}
|
||||
|
||||
export fn tic(time: i32) {
|
||||
let i: i32;
|
||||
loop pixels {
|
||||
seed(i + (time / 100) * 320);
|
||||
i?120 = (randomf() * 256 as f32 + time as f32 / 10 as f32) as i32;
|
||||
branch_if (i := i + 1) < 320*256: pixels
|
||||
}
|
||||
}
|
||||
14
examples/microw8/tunnel.cwa
Normal file
14
examples/microw8/tunnel.cwa
Normal file
@@ -0,0 +1,14 @@
|
||||
import "env.memory" memory(4);
|
||||
import "env.atan2" fn atan2(f32, f32) -> f32;
|
||||
|
||||
export fn tic(time: i32) {
|
||||
let i: i32;
|
||||
loop screen {
|
||||
let defer t = time as f32 / 10 as f32;
|
||||
let defer x = (i % 320) as f32 - 160.1;
|
||||
let defer y = (i / 320 - 128) as f32;
|
||||
|
||||
i?120 = ((20000 as f32 / sqrt(x * x + y * y) + t) as i32 ^ (atan2(x, y) * 512 as f32 / 3.141 + t) as i32);
|
||||
branch_if (i := i + 1) < 320*256: screen
|
||||
}
|
||||
}
|
||||
62
examples/wasm4/skipahead.cwa
Normal file
62
examples/wasm4/skipahead.cwa
Normal file
@@ -0,0 +1,62 @@
|
||||
import "env.memory" memory(1);
|
||||
|
||||
import "env.rect" fn rect(i32, i32, i32, i32);
|
||||
import "env.oval" fn oval(i32, i32, i32, i32);
|
||||
|
||||
global mut pz: f32 = 0.0;
|
||||
global mut px: f32 = 2.0;
|
||||
global mut py: f32 = 0.0;
|
||||
global mut s: f32 = 0.0;
|
||||
global mut f: f32 = 0.0;
|
||||
|
||||
fn xorshift(state: i32) -> i32 {
|
||||
100902443 * (
|
||||
(state :=
|
||||
(state := state ^ (state << 13))
|
||||
^ (state >> 17))
|
||||
^ (state << 5)
|
||||
)
|
||||
}
|
||||
|
||||
export fn update() {
|
||||
let y: i32;
|
||||
loop lines {
|
||||
let z = (200 as f32 / (y := y + 1) as f32 + pz) as i32;
|
||||
let x = (xorshift(xorshift(xorshift(z))) & 3) as f32 / 2 as f32 - px;
|
||||
let w = 6 as f32 / sqrt(z as f32);
|
||||
let rx = 80 + (y as f32 * x) as i32;
|
||||
let rw = (y as f32 * w) as i32;
|
||||
|
||||
let defer c = ((z & 1) + 2) * 17;
|
||||
?20 = c;
|
||||
rect(rx, y, rw, y / 9);
|
||||
?20 = c + 17;
|
||||
rect(rx, y + 1, rw, y / 9);
|
||||
|
||||
if y == 120 & py > 0.0 {
|
||||
if x+w < 0.0 | x > 0.0 {
|
||||
return;
|
||||
}
|
||||
py = 0.0;
|
||||
s = 0.0;
|
||||
f = 0.8;
|
||||
}
|
||||
|
||||
branch_if y < 160: lines;
|
||||
};
|
||||
|
||||
?20 = 50;
|
||||
oval(80 - 11, 114 - 11 + py as i32, 22, 22);
|
||||
?20 = 17;
|
||||
oval(80 - 6, 114 - 6 + py as i32, 6, 6);
|
||||
let defer pad = ?22;
|
||||
let defer control_speed = 0.03;
|
||||
px = px + (((pad >> 5) & 1) - ((pad >> 4) & 1)) as f32 * control_speed;
|
||||
if pad & 1 {
|
||||
s = s - f - control_speed;
|
||||
}
|
||||
s = s + 0.1;
|
||||
py = py + s;
|
||||
pz = pz + 0.05;
|
||||
f = f * 0.7;
|
||||
}
|
||||
12
random.cwa
12
random.cwa
@@ -1,12 +0,0 @@
|
||||
import "env.memory" memory(4);
|
||||
import "env.random" fn random() -> i32;
|
||||
import "env.randomSeed" fn seed(i32);
|
||||
|
||||
export fn tic(time: i32) {
|
||||
let i: i32;
|
||||
loop pixels {
|
||||
seed(i + (time / 100) * 320);
|
||||
i?120 = random();
|
||||
branch_if (i := i + 1) < 320*256: pixels
|
||||
}
|
||||
}
|
||||
@@ -619,8 +619,8 @@ fn emit_expression<'a>(ctx: &mut FunctionContext<'a>, expr: &'a ast::Expression)
|
||||
ast::Expr::Return { value } => {
|
||||
if let Some(value) = value {
|
||||
emit_expression(ctx, value);
|
||||
ctx.function.instruction(&Instruction::Return);
|
||||
}
|
||||
ctx.function.instruction(&Instruction::Return);
|
||||
}
|
||||
ast::Expr::Error => unreachable!(),
|
||||
}
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
import "env.memory" memory(8);
|
||||
|
||||
export fn load_uw8(module_start: i32, module_end: i32, base_start: i32, base_end: i32) -> i32 {
|
||||
if ?module_start == 0 {
|
||||
let defer length = module_end - module_start;
|
||||
copy(base_end, module_start, length);
|
||||
return base_end + length;
|
||||
}
|
||||
|
||||
copy(base_end, base_start, 8);
|
||||
base_start = base_start + 8;
|
||||
let dest = base_end + 8;
|
||||
let src = module_start + 1;
|
||||
|
||||
loop sections {
|
||||
if src < module_end & (base_start >= base_end | ?src <= ?base_start) {
|
||||
let defer length2 = copy_section(dest, src);
|
||||
dest = dest + length2;
|
||||
if base_start < base_end & ?src == ?base_start {
|
||||
base_start = base_start + section_size(base_start);
|
||||
}
|
||||
src = src + length2;
|
||||
branch sections;
|
||||
}
|
||||
|
||||
if base_start < base_end {
|
||||
let defer length3 = copy_section(dest, base_start);
|
||||
dest = dest + length3;
|
||||
base_start = base_start + length3;
|
||||
branch sections;
|
||||
}
|
||||
}
|
||||
|
||||
dest
|
||||
}
|
||||
|
||||
fn section_size(ptr: i32) -> i32 {
|
||||
let p = ptr + 1;
|
||||
let l = 0;
|
||||
let shift = 0;
|
||||
loop size {
|
||||
let defer b = ?p;
|
||||
l = l | ((b & 127) << shift);
|
||||
shift = shift + 7;
|
||||
p = p + 1;
|
||||
branch_if b & 128: size;
|
||||
}
|
||||
p - ptr + l
|
||||
}
|
||||
|
||||
fn copy_section(dest: i32, src: i32) -> i32 {
|
||||
let defer length = section_size(src);
|
||||
copy(dest, src, length);
|
||||
length
|
||||
}
|
||||
|
||||
fn copy(dest: i32, src: i32, len: i32) {
|
||||
if len > 0 {
|
||||
loop bytes {
|
||||
?(dest + (len := len - 1)) = ?(src + len);
|
||||
branch_if len: bytes
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user