From 537cda5335b068a14078a4d9d5fe1b16dac4c47e Mon Sep 17 00:00:00 2001 From: Marcus Ramse Date: Wed, 17 Apr 2024 16:12:21 +0000 Subject: [PATCH] Add Note Mode to templates --- cli/assets/templates/assemblyscript/src/wasm4.ts | 1 + cli/assets/templates/c/src/wasm4.h | 1 + cli/assets/templates/c3/cart/src/wasm4.c3 | 1 + cli/assets/templates/d/source/wasm4.d | 1 + cli/assets/templates/go/w4/wasm4.go | 1 + cli/assets/templates/nelua/src/wasm4.nelua | 1 + cli/assets/templates/nim/src/cart/wasm4.nim | 1 + cli/assets/templates/odin/src/w4/wasm4_wasm32.odin | 12 ++++++++---- cli/assets/templates/penne/src/wasm4.pn | 1 + cli/assets/templates/rust/src/wasm4.rs | 1 + cli/assets/templates/wat/main.wat | 1 + cli/assets/templates/zig/src/wasm4.zig | 1 + 12 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cli/assets/templates/assemblyscript/src/wasm4.ts b/cli/assets/templates/assemblyscript/src/wasm4.ts index e29ed870..83b62ac0 100644 --- a/cli/assets/templates/assemblyscript/src/wasm4.ts +++ b/cli/assets/templates/assemblyscript/src/wasm4.ts @@ -121,6 +121,7 @@ export const TONE_MODE3: u32 = 8; export const TONE_MODE4: u32 = 12; export const TONE_PAN_LEFT: u32 = 16; export const TONE_PAN_RIGHT: u32 = 32; +export const TONE_NOTE_MODE: u32 = 64; // ┌───────────────────────────────────────────────────────────────────────────┐ // │ │ diff --git a/cli/assets/templates/c/src/wasm4.h b/cli/assets/templates/c/src/wasm4.h index abfb43ab..0c8796d3 100644 --- a/cli/assets/templates/c/src/wasm4.h +++ b/cli/assets/templates/c/src/wasm4.h @@ -117,6 +117,7 @@ void tone (uint32_t frequency, uint32_t duration, uint32_t volume, uint32_t flag #define TONE_MODE4 12 #define TONE_PAN_LEFT 16 #define TONE_PAN_RIGHT 32 +#define TONE_NOTE_MODE 64 // ┌───────────────────────────────────────────────────────────────────────────┐ // │ │ diff --git a/cli/assets/templates/c3/cart/src/wasm4.c3 b/cli/assets/templates/c3/cart/src/wasm4.c3 index 60c55c40..c5627f35 100644 --- a/cli/assets/templates/c3/cart/src/wasm4.c3 +++ b/cli/assets/templates/c3/cart/src/wasm4.c3 @@ -97,6 +97,7 @@ const TONE_MODE3 = 8; const TONE_MODE4 = 12; const TONE_PAN_LEFT = 16; const TONE_PAN_RIGHT = 32; +const TONE_NOTE_MODE = 64; // ┌───────────────────────────────────────────────────────────────────────────┐ // │ │ diff --git a/cli/assets/templates/d/source/wasm4.d b/cli/assets/templates/d/source/wasm4.d index 0414dfcd..866ccb74 100644 --- a/cli/assets/templates/d/source/wasm4.d +++ b/cli/assets/templates/d/source/wasm4.d @@ -101,6 +101,7 @@ enum toneMode3 = 8; enum toneMode4 = 12; enum tonePanLeft = 16; enum tonePanRight = 32; +enum toneNoteMode = 64; // ┌───────────────────────────────────────────────────────────────────────────┐ // │ │ diff --git a/cli/assets/templates/go/w4/wasm4.go b/cli/assets/templates/go/w4/wasm4.go index 877c35ec..f6962e58 100644 --- a/cli/assets/templates/go/w4/wasm4.go +++ b/cli/assets/templates/go/w4/wasm4.go @@ -111,6 +111,7 @@ const TONE_MODE3 = 8 const TONE_MODE4 = 12 const TONE_PAN_LEFT = 16 const TONE_PAN_RIGHT = 32 +const TONE_NOTE_MODE = 64 // ┌───────────────────────────────────────────────────────────────────────────┐ // │ │ diff --git a/cli/assets/templates/nelua/src/wasm4.nelua b/cli/assets/templates/nelua/src/wasm4.nelua index d8240bac..2bbd29ba 100644 --- a/cli/assets/templates/nelua/src/wasm4.nelua +++ b/cli/assets/templates/nelua/src/wasm4.nelua @@ -122,6 +122,7 @@ global TONE_MODE3 = 8 global TONE_MODE4 = 12 global TONE_PAN_LEFT = 16 global TONE_PAN_RIGHT = 32 +global TONE_NOTE_MODE = 64 -- ┌───────────────────────────────────────────────────────────────────────────┐ -- │ │ diff --git a/cli/assets/templates/nim/src/cart/wasm4.nim b/cli/assets/templates/nim/src/cart/wasm4.nim index 4a89492a..49c438b4 100644 --- a/cli/assets/templates/nim/src/cart/wasm4.nim +++ b/cli/assets/templates/nim/src/cart/wasm4.nim @@ -48,6 +48,7 @@ const TONE_MODE4* = 12 TONE_PAN_LEFT* = 16 TONE_PAN_RIGHT* = 32 + TONE_NOTE_MODE* = 64 {.push importc, codegenDecl: "__attribute__((import_name(\"$2\"))) $1 $2$3".} proc blit*(data: ptr uint8; x: int32; y: int32; width: uint32; height: uint32; diff --git a/cli/assets/templates/odin/src/w4/wasm4_wasm32.odin b/cli/assets/templates/odin/src/w4/wasm4_wasm32.odin index 7f947d0a..3184f66e 100644 --- a/cli/assets/templates/odin/src/w4/wasm4_wasm32.odin +++ b/cli/assets/templates/odin/src/w4/wasm4_wasm32.odin @@ -118,6 +118,10 @@ Tone_Pan :: enum u32 { Left = 16, Right = 32, } +Tone_Mode :: enum u32 { + Frequency = 0, + Note = 64, +} Tone_Duration :: struct { attack: u8, // in frames @@ -135,13 +139,13 @@ foreign wasm4 { } // Plays a sound tone. -tone :: proc "c" (frequency: u32, duration: u32, volume_percent: u32, channel: Tone_Channel, duty_cycle := Tone_Duty_Cycle.Eigth, pan := Tone_Pan.Center) { - flags := u32(channel) | u32(duty_cycle) | u32(pan) +tone :: proc "c" (frequency: u32, duration: u32, volume_percent: u32, channel: Tone_Channel, duty_cycle := Tone_Duty_Cycle.Eigth, pan := Tone_Pan.Center, tone_mode := Tone_Mode.Frequency) { + flags := u32(channel) | u32(duty_cycle) | u32(pan) | u32(tone_mode) internal_tone(frequency, duration, volume_percent, flags) } -tone_complex :: proc "c" (start_frequency, end_frequency: u16, duration: Tone_Duration, volume_percent: u32, channel: Tone_Channel, duty_cycle := Tone_Duty_Cycle.Eigth, pan := Tone_Pan.Center) { - flags := u32(channel) | u32(duty_cycle) | u32(pan) +tone_complex :: proc "c" (start_frequency, end_frequency: u16, duration: Tone_Duration, volume_percent: u32, channel: Tone_Channel, duty_cycle := Tone_Duty_Cycle.Eigth, pan := Tone_Pan.Center, tone_mode := Tone_Mode.Frequency) { + flags := u32(channel) | u32(duty_cycle) | u32(pan) | u32(tone_mode) frequency := u32(start_frequency) | u32(end_frequency)<<16 duration_in_frames := u32(duration.attack)<<24 | u32(duration.delay)<<16 | u32(duration.release)<<8 | u32(duration.sustain) diff --git a/cli/assets/templates/penne/src/wasm4.pn b/cli/assets/templates/penne/src/wasm4.pn index b096bf44..cfeb3ccb 100644 --- a/cli/assets/templates/penne/src/wasm4.pn +++ b/cli/assets/templates/penne/src/wasm4.pn @@ -103,6 +103,7 @@ pub const TONE_MODE3: u32 = 8; pub const TONE_MODE4: u32 = 12; pub const TONE_PAN_LEFT: u32 = 16; pub const TONE_PAN_RIGHT: u32 = 32; +pub const TONE_NOTE_MODE: u32 = 64; // ┌───────────────────────────────────────────────────────────────────────────┐ // │ │ diff --git a/cli/assets/templates/rust/src/wasm4.rs b/cli/assets/templates/rust/src/wasm4.rs index eb378192..1342cbdd 100644 --- a/cli/assets/templates/rust/src/wasm4.rs +++ b/cli/assets/templates/rust/src/wasm4.rs @@ -193,6 +193,7 @@ pub const TONE_MODE3: u32 = 8; pub const TONE_MODE4: u32 = 12; pub const TONE_PAN_LEFT: u32 = 16; pub const TONE_PAN_RIGHT: u32 = 32; +pub const TONE_NOTE_MODE: u32 = 64; // ┌───────────────────────────────────────────────────────────────────────────┐ // │ │ diff --git a/cli/assets/templates/wat/main.wat b/cli/assets/templates/wat/main.wat index 59ef7eab..d418a67d 100644 --- a/cli/assets/templates/wat/main.wat +++ b/cli/assets/templates/wat/main.wat @@ -109,6 +109,7 @@ (global $TONE_MODE4 i32 (i32.const 12)) (global $TONE_PAN_LEFT i32 (i32.const 16)) (global $TONE_PAN_RIGHT i32 (i32.const 32)) +(global $TONE_NOTE_MODE i32 (i32.const 64)) ;; smiley diff --git a/cli/assets/templates/zig/src/wasm4.zig b/cli/assets/templates/zig/src/wasm4.zig index e5c40c5e..25f836dd 100644 --- a/cli/assets/templates/zig/src/wasm4.zig +++ b/cli/assets/templates/zig/src/wasm4.zig @@ -100,6 +100,7 @@ pub const TONE_MODE3: u32 = 8; pub const TONE_MODE4: u32 = 12; pub const TONE_PAN_LEFT: u32 = 16; pub const TONE_PAN_RIGHT: u32 = 32; +pub const TONE_NOTE_MODE: u32 = 64; // ┌───────────────────────────────────────────────────────────────────────────┐ // │ │