diff --git a/examples/include/microw8-api.cwa b/examples/include/microw8-api.cwa index 5d50279..ff74ebb 100644 --- a/examples/include/microw8-api.cwa +++ b/examples/include/microw8-api.cwa @@ -33,6 +33,7 @@ import "env.setCursorPosition" fn setCursorPosition(i32, i32); import "env.rectangle_outline" fn rectangle_outline(f32, f32, f32, f32, i32); import "env.circle_outline" fn circle_outline(f32, f32, f32, i32); import "env.exp" fn exp(f32) -> f32; +import "env.playNote" fn playNote(i32, i32); const TIME_MS = 0x40; const GAMEPAD = 0x44; diff --git a/examples/include/microw8-api.wat b/examples/include/microw8-api.wat index 7024a2d..116b669 100644 --- a/examples/include/microw8-api.wat +++ b/examples/include/microw8-api.wat @@ -33,6 +33,7 @@ (import "env" "rectangle_outline" (func $rectangle_outline (param f32) (param f32) (param f32) (param f32) (param i32))) (import "env" "circle_outline" (func $circle_outline (param f32) (param f32) (param f32) (param i32))) (import "env" "exp" (func $exp (param f32) (result f32))) +(import "env" "playNote" (func $playNote (param i32) (param i32))) ;; to use defines, include this file with a preprocessor ;; like gpp (https://logological.org/gpp). diff --git a/platform/bin/loader.wasm b/platform/bin/loader.wasm index 12115eb..e5a4279 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 ed7a546..24341b3 100644 Binary files a/platform/bin/platform.uw8 and b/platform/bin/platform.uw8 differ diff --git a/platform/src/platform.cwa b/platform/src/platform.cwa index 69e683e..90253a0 100644 --- a/platform/src/platform.cwa +++ b/platform/src/platform.cwa @@ -339,6 +339,11 @@ fn printSingleChar(char: i32) { return; } + if char == 7 { + 80?0 = 80?0 ^ 2; + return; + } + if char == 8 { textCursorX = textCursorX - 8; if !graphicsText & textCursorX < 0 { @@ -509,6 +514,26 @@ export fn setCursorPosition(x: i32, y: i32) { include "ges.cwa" +export fn playNote(channel: i32, note: i32) { + (channel * 6)?80 = (channel * 6)?80 & 0xfe ^ if note { + (channel * 6)?83 = note & 127; + 2 | !(note >> 7) + } else { + 0 + }; +} + +data 80 { + i8( + 0x80, 0xc0, 0, 81, 0xa0, 0x50, + 0xc4, 0, 0, 69, 0x60, 0x40, + 0x44, 0xb0, 0, 69, 0x90, 0x43, + 0x4, 0xf0, 0, 69, 0xa4, 0x44, + 0xff, 0xff, + 1, 1, 0, 100, 0, 100 + ) +} + /////////// // SETUP // /////////// @@ -565,17 +590,6 @@ start fn setup() { randomSeed(random()); } -data 80 { - i8( - 0, 128, 0, 69, 0x8, 0xc8, - 0, 128, 0, 69, 0x8, 0xc8, - 0, 128, 0, 69, 0x8, 0xc8, - 0, 128, 0, 69, 0x8, 0xc8, - 0xff, 0xff, - 1, 1, 0, 100, 0, 100 - ) -} - data 0x12c78 { i32(80) } diff --git a/uw8-tool/src/base_module.rs b/uw8-tool/src/base_module.rs index c9c042f..1e3a29c 100644 --- a/uw8-tool/src/base_module.rs +++ b/uw8-tool/src/base_module.rs @@ -166,6 +166,8 @@ impl BaseModule { add_function(&mut functions, &type_map, "exp", &[F32], Some(F32)); + add_function(&mut functions, &type_map, "playNote", &[I32, I32], None); + for i in functions.len()..64 { add_function( &mut functions, @@ -291,7 +293,10 @@ impl BaseModule { pub fn write_as_cwa>(&self, path: P) -> Result<()> { fn inner(mut file: File, base: &BaseModule) -> Result<()> { - writeln!(file, "// MicroW8 APIs, to be `include`d in CurlyWas sources")?; + writeln!( + file, + "// MicroW8 APIs, to be `include`d in CurlyWas sources" + )?; writeln!(file, "import \"env.memory\" memory({});", base.memory)?; writeln!(file)?; for &(module, ref name, type_id) in &base.function_imports { @@ -402,5 +407,5 @@ const CONSTANTS: &[(&str, u32)] = &[ ("BUTTON_A", 4), ("BUTTON_B", 5), ("BUTTON_X", 6), - ("BUTTON_Y", 7) + ("BUTTON_Y", 7), ];