mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 11:16:42 +01:00
tic(i32) => upd(), time(), first version of palette
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,15 @@
|
|||||||
import "env.memory" memory(4);
|
import "env.memory" memory(4);
|
||||||
|
|
||||||
|
import "env.cos" fn cos(f32) -> f32;
|
||||||
|
|
||||||
|
export fn time() -> i32 {
|
||||||
|
0!64
|
||||||
|
}
|
||||||
|
|
||||||
|
export fn ftime() -> f32 {
|
||||||
|
(0!64) as f32 / 1000 as f32
|
||||||
|
}
|
||||||
|
|
||||||
global mut randomState: i64 = 37i64;
|
global mut randomState: i64 = 37i64;
|
||||||
|
|
||||||
export fn random() -> i32 {
|
export fn random() -> i32 {
|
||||||
@@ -108,11 +118,58 @@ export fn circle(cx: f32, cy: f32, radius: f32, col: i32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
start fn setup() {
|
start fn setup() {
|
||||||
let i: i32;
|
let i: i32 = 12*16*3-1;
|
||||||
loop colors {
|
let avg: f32;
|
||||||
(i*4)!(120+320*240) = i * 0x10101;
|
loop gradients {
|
||||||
branch_if (i := i + 1) < 256: colors
|
let lazy scale = (i % 48) as f32 / 48 as f32;
|
||||||
|
let inline angle = i as f32 * (3.1416 / 1.5 - 3.1416 / (11.0 * 16.0 * 1.5));
|
||||||
|
let lazy c = 0.4 - cos(angle);
|
||||||
|
let inline ulimit = avg + 0.8;
|
||||||
|
let inline llimit = avg - 0.8;
|
||||||
|
let lazy a = max(llimit, min(ulimit, c)) * (scale + 0.05);
|
||||||
|
let lazy b = scale * scale * 0.8;
|
||||||
|
let inline v = (select(i < 11*16*3, max(0 as f32, min(a + b - a * b, 1 as f32)), scale) * 255 as f32) as i32;
|
||||||
|
(i%3 + i/3*4)?(120+320*240) = v;
|
||||||
|
avg = (avg + c) * 0.5;
|
||||||
|
|
||||||
|
branch_if i := i - 1: gradients;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i = 255;
|
||||||
|
loop expand_sweetie {
|
||||||
|
let lazy channel = i & 3;
|
||||||
|
let lazy index = i >> 2;
|
||||||
|
let lazy first_step = index >= 32;
|
||||||
|
let inline src1 = select(first_step, index % 32 / 2, index * 2);
|
||||||
|
let inline src2 = select(first_step, (index + 1) % 32 / 2, index * 2 + 1);
|
||||||
|
let inline c1 = (src1 * 4 + channel)?(120+320*240+192*4);
|
||||||
|
let inline c2 = (src2 * 4 + channel)?(120+320*240+192*4);
|
||||||
|
i?(120+320*240+192*4) = (c1 + c2) * (3 + first_step) / 8;
|
||||||
|
|
||||||
|
branch_if (i := i - 1) >= 0: expand_sweetie;
|
||||||
|
}
|
||||||
|
|
||||||
cls(0);
|
cls(0);
|
||||||
randomSeed(random());
|
randomSeed(random());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data 120+320*240+192*4 {
|
||||||
|
i32(
|
||||||
|
0x2c1c1a,
|
||||||
|
0x5d275d,
|
||||||
|
0x533eb1,
|
||||||
|
0x577def,
|
||||||
|
0x75cdff,
|
||||||
|
0x70f0a7,
|
||||||
|
0x64b738,
|
||||||
|
0x797125,
|
||||||
|
0x6f3629,
|
||||||
|
0xc95d3b,
|
||||||
|
0xf6a641,
|
||||||
|
0xf7ef73,
|
||||||
|
0xf4f4f4,
|
||||||
|
0xc2b094,
|
||||||
|
0x866c56,
|
||||||
|
0x573c33
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
19
src/lib.rs
19
src/lib.rs
@@ -19,7 +19,7 @@ pub struct MicroW8 {
|
|||||||
struct UW8Instance {
|
struct UW8Instance {
|
||||||
store: Store<()>,
|
store: Store<()>,
|
||||||
memory: Memory,
|
memory: Memory,
|
||||||
tic: TypedFunc<i32, ()>,
|
upd: TypedFunc<(), ()>,
|
||||||
start_time: Instant,
|
start_time: Instant,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,8 +76,10 @@ impl MicroW8 {
|
|||||||
|
|
||||||
let platform_data = include_bytes!("../platform/bin/platform.uw8");
|
let platform_data = include_bytes!("../platform/bin/platform.uw8");
|
||||||
memory.data_mut(&mut store)[..platform_data.len()].copy_from_slice(platform_data);
|
memory.data_mut(&mut store)[..platform_data.len()].copy_from_slice(platform_data);
|
||||||
let platform_length = load_uw8.call(&mut store, platform_data.len() as i32)? as u32 as usize;
|
let platform_length =
|
||||||
let platform_module = wasmtime::Module::new(&self.engine, &memory.data(&store)[..platform_length])?;
|
load_uw8.call(&mut store, platform_data.len() as i32)? as u32 as usize;
|
||||||
|
let platform_module =
|
||||||
|
wasmtime::Module::new(&self.engine, &memory.data(&store)[..platform_length])?;
|
||||||
|
|
||||||
memory.data_mut(&mut store)[..module.len()].copy_from_slice(module);
|
memory.data_mut(&mut store)[..module.len()].copy_from_slice(module);
|
||||||
let module_length = load_uw8.call(&mut store, module.len() as i32)? as u32 as usize;
|
let module_length = load_uw8.call(&mut store, module.len() as i32)? as u32 as usize;
|
||||||
@@ -121,12 +123,12 @@ impl MicroW8 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let instance = linker.instantiate(&mut store, &module)?;
|
let instance = linker.instantiate(&mut store, &module)?;
|
||||||
let tic = instance.get_typed_func::<i32, (), _>(&mut store, "tic")?;
|
let upd = instance.get_typed_func::<(), (), _>(&mut store, "upd")?;
|
||||||
|
|
||||||
self.instance = Some(UW8Instance {
|
self.instance = Some(UW8Instance {
|
||||||
store,
|
store,
|
||||||
memory,
|
memory,
|
||||||
tic,
|
upd,
|
||||||
start_time: Instant::now(),
|
start_time: Instant::now(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -135,10 +137,9 @@ impl MicroW8 {
|
|||||||
|
|
||||||
pub fn run_frame(&mut self) -> Result<()> {
|
pub fn run_frame(&mut self) -> Result<()> {
|
||||||
if let Some(mut instance) = self.instance.take() {
|
if let Some(mut instance) = self.instance.take() {
|
||||||
instance.tic.call(
|
instance.memory.data_mut(&mut instance.store)[64..68]
|
||||||
&mut instance.store,
|
.copy_from_slice(&(instance.start_time.elapsed().as_millis() as i32).to_le_bytes());
|
||||||
instance.start_time.elapsed().as_millis() as i32,
|
instance.upd.call(&mut instance.store, ())?;
|
||||||
)?;
|
|
||||||
|
|
||||||
let framebuffer = &instance.memory.data(&instance.store)[120..];
|
let framebuffer = &instance.memory.data(&instance.store)[120..];
|
||||||
let palette = &framebuffer[320 * 240..];
|
let palette = &framebuffer[320 * 240..];
|
||||||
|
|||||||
@@ -77,6 +77,9 @@ impl BaseModule {
|
|||||||
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, "time", &[], Some(I32));
|
||||||
|
add_function(&mut functions, &type_map, "ftime", &[], Some(F32));
|
||||||
|
|
||||||
for i in functions.len()..64 {
|
for i in functions.len()..64 {
|
||||||
add_function(
|
add_function(
|
||||||
&mut functions,
|
&mut functions,
|
||||||
@@ -105,8 +108,8 @@ impl BaseModule {
|
|||||||
types,
|
types,
|
||||||
function_imports: functions,
|
function_imports: functions,
|
||||||
global_imports,
|
global_imports,
|
||||||
functions: vec![lookup_type(&type_map, &[I32], None)],
|
functions: vec![lookup_type(&type_map, &[], None)],
|
||||||
exports: vec![("tic", first_function)],
|
exports: vec![("upd", first_function)],
|
||||||
memory: 4,
|
memory: 4,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -570,10 +570,6 @@ impl ImportSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if memory == 0 {
|
|
||||||
bail!("No memory import found");
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(ImportSection {
|
Ok(ImportSection {
|
||||||
memory,
|
memory,
|
||||||
functions,
|
functions,
|
||||||
|
|||||||
@@ -107,7 +107,8 @@ async function runModule(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
instance.exports.tic(Date.now() - startTime);
|
new Uint32Array(memory.buffer)[16] = Date.now() - startTime;
|
||||||
|
instance.exports.upd();
|
||||||
|
|
||||||
let palette = new Uint32Array(memory.buffer.slice(76920, 76920 + 1024));
|
let palette = new Uint32Array(memory.buffer.slice(76920, 76920 + 1024));
|
||||||
for (let i = 0; i < 320 * 240; ++i) {
|
for (let i = 0; i < 320 * 240; ++i) {
|
||||||
|
|||||||
Reference in New Issue
Block a user