diff --git a/w4/api.go b/w4/api.go index de810a6..8db8899 100644 --- a/w4/api.go +++ b/w4/api.go @@ -14,7 +14,7 @@ type Size struct { Height u8 } -// Flags used with [Blit] and [BLitSub]. +// Flags used with [Blit] and [BlitSub]. type BlitFlags u8 const ( @@ -33,9 +33,13 @@ type Tone struct { StartFreq uint // End wave frequency in hertz, used to describe a pitch slide effect. + // + // https://wasm4.org/docs/guides/audio#frequency-slide EndFreq uint // Volume of the sustain duration, between 0 and 100. + // + // https://wasm4.org/docs/guides/audio#volume SustainVol u8 // Volume of the attack duration, between 0 and 100. @@ -47,15 +51,23 @@ type Tone struct { // Duration of the tone in frames (1/60th of a second), up to 255 frames. // Sustain time of ADSR envelope. + // + // https://wasm4.org/docs/guides/audio#adsr-envelope Sustain u8 // Attack time of ADSR envelope. + // + // https://wasm4.org/docs/guides/audio#adsr-envelope Attack u8 // Decay time of ADSR envelope. + // + // https://wasm4.org/docs/guides/audio#adsr-envelope Decay u8 // Release time of ADSR envelope. + // + // https://wasm4.org/docs/guides/audio#adsr-envelope Release u8 } @@ -68,6 +80,9 @@ const ( Noise Channel = 3 ) +// The duty cycle of the tone. +// +// https://wasm4.org/docs/guides/audio#duty-cycle type DutyCycle u8 const ( @@ -77,6 +92,9 @@ const ( DutyCycle3p4 DutyCycle = 12 ) +// Panning +// +// https://wasm4.org/docs/guides/audio#panning type Pan u8 const ( @@ -85,22 +103,10 @@ const ( Right Pan = 32 ) -type ToneFlags u8 - -const ( - TonePulse1 = 0 - TonePulse2 = 1 - ToneTriangle = 2 - ToneNoise = 3 - ToneMode1 = 0 - ToneMode2 = 4 - ToneMode3 = 8 - ToneMode4 = 12 -) - // Copies pixels to the framebuffer. // -// https://wasm4.org/docs/reference/functions#blit-spriteptr-x-y-width-height-flags +// - https://wasm4.org/docs/guides/sprites +// - https://wasm4.org/docs/reference/functions#blit-spriteptr-x-y-width-height-flags func Blit(sprite []byte, p Point, s Size, f BlitFlags) { blit(&sprite[0], p.X, p.Y, s.Width, s.Height, u8(f)) } @@ -156,14 +162,16 @@ func DrawRect(p Point, s Size) { // // The font is 8x8 pixels per character. // -// https://wasm4.org/docs/reference/functions#text-str-x-y +// - https://wasm4.org/docs/reference/functions#text-str-x-y +// - https://wasm4.org/docs/guides/text func DrawText(text string, p Point) { textUtf8(text, p.X, p.Y) } // Play a sound tone. // -// https://wasm4.org/docs/reference/functions#tone-frequency-duration-volume-flags +// - https://wasm4.org/docs/guides/audio +// - https://wasm4.org/docs/reference/functions#tone-frequency-duration-volume-flags func PlayTone(t Tone) { flags := u8(t.Channel) | u8(t.DutyCycle) | u8(t.Pan) freq := (uint32(t.StartFreq) << 8) | uint32(t.EndFreq) @@ -183,11 +191,15 @@ func Trace(text string) { // Reads bytes from persistent storage into the buffer. // // Make sure the buffer has cap enough to fit the data. +// +// https://wasm4.org/docs/guides/saving-data?code-lang=go#reading-data-from-disk func Load(buf []byte) uint { return diskR(&buf[0], len(buf)) } // Writes bytes from the buffer into persistent storage. +// +// https://wasm4.org/docs/guides/saving-data?code-lang=go#writing-data-to-disk func Save(buf []byte) uint { return diskW(&buf[0], len(buf)) } diff --git a/w4/memory.go b/w4/memory.go index dc918c5..09fb41a 100644 --- a/w4/memory.go +++ b/w4/memory.go @@ -12,6 +12,8 @@ var offset uintptr = 4 var memory = (*[6556]byte)(unsafe.Pointer(offset)) // BGR888 color in the palette. +// +// https://wasm4.org/docs/guides/basic-drawing#the-palette-register type Color struct { // Red channel, from 0 to 255. R u8 @@ -29,6 +31,8 @@ type palette struct{} // // Which colors from the palette are used to draw a specific element // is controlled by [DrawColors]. +// +// https://wasm4.org/docs/guides/basic-drawing#the-palette-register var Palette = palette{} // Get a color from the palette. @@ -59,6 +63,8 @@ func (palette) Set(c1, c2, c3, c4 Color) { } // A color from the palette used bu draw functions. +// +// https://wasm4.org/docs/guides/basic-drawing#the-draw_colors-register type DrawColor u8 const ( @@ -83,6 +89,8 @@ const ( type drawColors struct{} // Defines which colors from the palette should be used by the draw functions. +// +// https://wasm4.org/docs/guides/basic-drawing#the-draw_colors-register var DrawColors = drawColors{} // Set all four draw colors. @@ -143,11 +151,15 @@ type gamepads []gamepad // - The first one is always available and is the local player. // - The second one can be either a local hotseat player or a remote one. // - Gamepads 3 and 4 are always remote players. +// +// https://wasm4.org/docs/guides/user-input#gamepad var Gamepads = gamepads{0x12, 0x13, 0x14, 0x15} type mouse struct{} // The mouse position and mouse buttons (left, right, and middle) state. +// +// https://wasm4.org/docs/guides/user-input#mouse var Mouse = mouse{} // X coordinate of the mouse cursor on the display. @@ -193,6 +205,8 @@ func (systemFlags) HideGamepadOverlay(v bool) { type netplay struct{} // Multiplayer state. +// +// https://wasm4.org/docs/guides/multiplayer#the-netplay-memory-register var NetPlay = netplay{} // Local player index (0 to 3). @@ -210,4 +224,6 @@ func (netplay) Active() bool { type frameBuffer [6400]byte // Array of 160x160 pixels, with each pixel packed into 2 bits (colors 0 to 3). +// +// https://wasm4.org/docs/guides/basic-drawing#direct-framebuffer-access var FrameBuffer = memory[0xa0-offset:]