From c5b7872ab29834c8650a1b12bc30a279cb3e6d4b Mon Sep 17 00:00:00 2001 From: gram Date: Sun, 26 Jul 2026 21:12:15 +0200 Subject: [PATCH 1/4] add GetTime --- _examples/time/firefly.toml | 7 +++++++ _examples/time/go.mod | 9 +++++++++ _examples/time/go.sum | 2 ++ _examples/time/text.go | 22 ++++++++++++++++++++++ firefly/bindings.go | 3 +++ firefly/misc.go | 10 +++++++++- 6 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 _examples/time/firefly.toml create mode 100644 _examples/time/go.mod create mode 100644 _examples/time/go.sum create mode 100644 _examples/time/text.go diff --git a/_examples/time/firefly.toml b/_examples/time/firefly.toml new file mode 100644 index 0000000..614d597 --- /dev/null +++ b/_examples/time/firefly.toml @@ -0,0 +1,7 @@ +author_id = "demo" +app_id = "go-time" +author_name = "Demo" +app_name = "Time Demo (Go)" + +[files] +font = { path = "eg_6x10.fff", url = "https://fonts.fireflyzero.com/fonts/ascii/eg_6x10.fff" } diff --git a/_examples/time/go.mod b/_examples/time/go.mod new file mode 100644 index 0000000..d9b3b10 --- /dev/null +++ b/_examples/time/go.mod @@ -0,0 +1,9 @@ +module demotext + +go 1.24.0 + +replace github.com/firefly-zero/firefly-go => ../../ + +require github.com/firefly-zero/firefly-go v0.12.0 + +require github.com/orsinium-labs/tinymath v1.2.0 // indirect diff --git a/_examples/time/go.sum b/_examples/time/go.sum new file mode 100644 index 0000000..e8c4120 --- /dev/null +++ b/_examples/time/go.sum @@ -0,0 +1,2 @@ +github.com/orsinium-labs/tinymath v1.2.0 h1:mxbQzDQz00XQvPqPmIRCgXvYMyPCgCng1kYWfvjXr6M= +github.com/orsinium-labs/tinymath v1.2.0/go.mod h1:WPXX6ei3KSXG7JfA03a+ekCYaY9SWN4I+JRl2p6ck+A= diff --git a/_examples/time/text.go b/_examples/time/text.go new file mode 100644 index 0000000..e9a5078 --- /dev/null +++ b/_examples/time/text.go @@ -0,0 +1,22 @@ +package main + +import "github.com/firefly-zero/firefly-go/firefly" + +func init() { + firefly.Boot = boot + firefly.Render = render +} + +var font firefly.Font + +func boot() { + font = firefly.LoadFile("font", nil).Font() +} + +func render() { + firefly.ClearScreen(firefly.ColorWhite) + firefly.DrawText( + firefly.GetTime().String(), + font, firefly.Point{X: 10, Y: 60}, firefly.ColorDarkBlue, + ) +} diff --git a/firefly/bindings.go b/firefly/bindings.go index 2cc43c9..a163f80 100644 --- a/firefly/bindings.go +++ b/firefly/bindings.go @@ -161,6 +161,9 @@ func setSeed(seed uint32) //go:wasmimport misc get_random func getRandom() uint32 +//go:wasmimport misc get_time +func getTime() uint64 + //go:wasmimport misc get_name func getName(index uint32, ptr unsafe.Pointer) uint32 diff --git a/firefly/misc.go b/firefly/misc.go index 26de17b..7f6c6e0 100644 --- a/firefly/misc.go +++ b/firefly/misc.go @@ -1,6 +1,9 @@ package firefly -import "unsafe" +import ( + "time" + "unsafe" +) type Language uint16 @@ -201,6 +204,11 @@ func GetRandom() uint32 { return getRandom() } +// Get the time passed since the app was started. +func GetTime() time.Duration { + return time.Duration(getTime()) * time.Microsecond +} + // Get human-readable name of the given peer. func GetName(p Peer) string { buf := [16]byte{} From 42746b786ce46cf4e0771e2580dfa6e868abdcbf Mon Sep 17 00:00:00 2001 From: gram Date: Sun, 26 Jul 2026 21:12:33 +0200 Subject: [PATCH 2/4] update SDK in examples --- _examples/atlas/go.mod | 2 +- _examples/audio_file/go.mod | 2 +- _examples/audio_sine/go.mod | 2 +- _examples/canvas/go.mod | 2 +- _examples/debug/go.mod | 2 +- _examples/image/go.mod | 2 +- _examples/qr/go.mod | 2 +- _examples/scores/go.mod | 2 +- _examples/sprite/go.mod | 2 +- _examples/stash/go.mod | 2 +- _examples/text/go.mod | 2 +- _examples/time/go.mod | 2 +- _examples/touchpad/go.mod | 2 +- _examples/triangle/go.mod | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/_examples/atlas/go.mod b/_examples/atlas/go.mod index 63e8eb0..1ff4cf0 100644 --- a/_examples/atlas/go.mod +++ b/_examples/atlas/go.mod @@ -4,6 +4,6 @@ go 1.24.0 replace github.com/firefly-zero/firefly-go => ../../ -require github.com/firefly-zero/firefly-go v0.12.0 +require github.com/firefly-zero/firefly-go v0.13.0 require github.com/orsinium-labs/tinymath v1.2.0 // indirect diff --git a/_examples/audio_file/go.mod b/_examples/audio_file/go.mod index 85af38f..c1e7f10 100644 --- a/_examples/audio_file/go.mod +++ b/_examples/audio_file/go.mod @@ -4,6 +4,6 @@ go 1.24.0 replace github.com/firefly-zero/firefly-go => ../../ -require github.com/firefly-zero/firefly-go v0.12.0 +require github.com/firefly-zero/firefly-go v0.13.0 require github.com/orsinium-labs/tinymath v1.2.0 // indirect diff --git a/_examples/audio_sine/go.mod b/_examples/audio_sine/go.mod index 325203d..d7eb73d 100644 --- a/_examples/audio_sine/go.mod +++ b/_examples/audio_sine/go.mod @@ -4,6 +4,6 @@ go 1.24.0 replace github.com/firefly-zero/firefly-go => ../../ -require github.com/firefly-zero/firefly-go v0.12.0 +require github.com/firefly-zero/firefly-go v0.13.0 require github.com/orsinium-labs/tinymath v1.2.0 // indirect diff --git a/_examples/canvas/go.mod b/_examples/canvas/go.mod index c700d3f..5f75d3f 100644 --- a/_examples/canvas/go.mod +++ b/_examples/canvas/go.mod @@ -4,6 +4,6 @@ go 1.24.0 replace github.com/firefly-zero/firefly-go => ../../ -require github.com/firefly-zero/firefly-go v0.12.0 +require github.com/firefly-zero/firefly-go v0.13.0 require github.com/orsinium-labs/tinymath v1.2.0 // indirect diff --git a/_examples/debug/go.mod b/_examples/debug/go.mod index 1239b39..867fbbb 100644 --- a/_examples/debug/go.mod +++ b/_examples/debug/go.mod @@ -4,6 +4,6 @@ go 1.24.0 replace github.com/firefly-zero/firefly-go => ../../ -require github.com/firefly-zero/firefly-go v0.12.0 +require github.com/firefly-zero/firefly-go v0.13.0 require github.com/orsinium-labs/tinymath v1.2.0 // indirect diff --git a/_examples/image/go.mod b/_examples/image/go.mod index 0ca1b5b..5e4ddeb 100644 --- a/_examples/image/go.mod +++ b/_examples/image/go.mod @@ -4,6 +4,6 @@ go 1.24.0 replace github.com/firefly-zero/firefly-go => ../../ -require github.com/firefly-zero/firefly-go v0.12.0 +require github.com/firefly-zero/firefly-go v0.13.0 require github.com/orsinium-labs/tinymath v1.2.0 // indirect diff --git a/_examples/qr/go.mod b/_examples/qr/go.mod index 4a07508..6b8c92b 100644 --- a/_examples/qr/go.mod +++ b/_examples/qr/go.mod @@ -4,6 +4,6 @@ go 1.24.0 replace github.com/firefly-zero/firefly-go => ../../ -require github.com/firefly-zero/firefly-go v0.12.0 +require github.com/firefly-zero/firefly-go v0.13.0 require github.com/orsinium-labs/tinymath v1.2.0 // indirect diff --git a/_examples/scores/go.mod b/_examples/scores/go.mod index d9b3b10..db85f8a 100644 --- a/_examples/scores/go.mod +++ b/_examples/scores/go.mod @@ -4,6 +4,6 @@ go 1.24.0 replace github.com/firefly-zero/firefly-go => ../../ -require github.com/firefly-zero/firefly-go v0.12.0 +require github.com/firefly-zero/firefly-go v0.13.0 require github.com/orsinium-labs/tinymath v1.2.0 // indirect diff --git a/_examples/sprite/go.mod b/_examples/sprite/go.mod index 42dbfe6..09f6923 100644 --- a/_examples/sprite/go.mod +++ b/_examples/sprite/go.mod @@ -4,6 +4,6 @@ go 1.24.0 replace github.com/firefly-zero/firefly-go => ../../ -require github.com/firefly-zero/firefly-go v0.12.0 +require github.com/firefly-zero/firefly-go v0.13.0 require github.com/orsinium-labs/tinymath v1.2.0 // indirect diff --git a/_examples/stash/go.mod b/_examples/stash/go.mod index 4bd2371..9304a34 100644 --- a/_examples/stash/go.mod +++ b/_examples/stash/go.mod @@ -4,6 +4,6 @@ go 1.24.0 replace github.com/firefly-zero/firefly-go => ../../ -require github.com/firefly-zero/firefly-go v0.12.0 +require github.com/firefly-zero/firefly-go v0.13.0 require github.com/orsinium-labs/tinymath v1.2.0 // indirect diff --git a/_examples/text/go.mod b/_examples/text/go.mod index d9b3b10..db85f8a 100644 --- a/_examples/text/go.mod +++ b/_examples/text/go.mod @@ -4,6 +4,6 @@ go 1.24.0 replace github.com/firefly-zero/firefly-go => ../../ -require github.com/firefly-zero/firefly-go v0.12.0 +require github.com/firefly-zero/firefly-go v0.13.0 require github.com/orsinium-labs/tinymath v1.2.0 // indirect diff --git a/_examples/time/go.mod b/_examples/time/go.mod index d9b3b10..db85f8a 100644 --- a/_examples/time/go.mod +++ b/_examples/time/go.mod @@ -4,6 +4,6 @@ go 1.24.0 replace github.com/firefly-zero/firefly-go => ../../ -require github.com/firefly-zero/firefly-go v0.12.0 +require github.com/firefly-zero/firefly-go v0.13.0 require github.com/orsinium-labs/tinymath v1.2.0 // indirect diff --git a/_examples/touchpad/go.mod b/_examples/touchpad/go.mod index 0449ba5..3677904 100644 --- a/_examples/touchpad/go.mod +++ b/_examples/touchpad/go.mod @@ -4,6 +4,6 @@ go 1.24.0 replace github.com/firefly-zero/firefly-go => ../../ -require github.com/firefly-zero/firefly-go v0.12.0 +require github.com/firefly-zero/firefly-go v0.13.0 require github.com/orsinium-labs/tinymath v1.2.0 // indirect diff --git a/_examples/triangle/go.mod b/_examples/triangle/go.mod index 4788892..69bbb9f 100644 --- a/_examples/triangle/go.mod +++ b/_examples/triangle/go.mod @@ -4,6 +4,6 @@ go 1.24.0 replace github.com/firefly-zero/firefly-go => ../../ -require github.com/firefly-zero/firefly-go v0.12.0 +require github.com/firefly-zero/firefly-go v0.13.0 require github.com/orsinium-labs/tinymath v1.2.0 // indirect From 31a4528ed5242a7f3c7a77b3c7843a7b4372c01e Mon Sep 17 00:00:00 2001 From: gram Date: Sun, 26 Jul 2026 21:14:38 +0200 Subject: [PATCH 3/4] make Peers opaque type --- firefly/net.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/firefly/net.go b/firefly/net.go index 6fa8aec..cfab90f 100644 --- a/firefly/net.go +++ b/firefly/net.go @@ -63,7 +63,9 @@ var Combined = Peer{0xFF} // The list of peers online. // // Can be obtained using [GetPeers]. -type Peers uint32 +type Peers struct { + p uint32 +} // Stash is a serialized binary state of the app that you want to persist // between app runs and to be available in multiplayer. @@ -108,13 +110,13 @@ func (peers Peers) Iter() iter.Seq[Peer] { // Check if the given [Peer] is online. func (peers Peers) Contains(peer Peer) bool { - return peers>>peer.raw&1 != 0 + return peers.p>>peer.raw&1 != 0 } // Get how many peers are online. func (peers Peers) Len() int { // Should be converted by TinyGo in a single wasm instruction. - return bits.OnesCount32(uint32(peers)) + return bits.OnesCount32(peers.p) } // Get the peer corresponding to the local device. @@ -129,7 +131,7 @@ func GetMe() Me { // It can be used to detect if multiplayer is active: // if there is more than 1 peer, you're playing with friends. func GetPeers() Peers { - return Peers(getPeers()) + return Peers{getPeers()} } // Save the given [Stash]. From cb5c3da3336db129a788affec630fc9eceaa0078 Mon Sep 17 00:00:00 2001 From: gram Date: Mon, 27 Jul 2026 20:53:39 +0200 Subject: [PATCH 4/4] rename --- _examples/time/{text.go => time.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename _examples/time/{text.go => time.go} (100%) diff --git a/_examples/time/text.go b/_examples/time/time.go similarity index 100% rename from _examples/time/text.go rename to _examples/time/time.go