mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 11:16:42 +01:00
Merge 937ccf60c9 into fb3fd5e8bb
This commit is contained in:
6
examples/tinygo/build.sh
Executable file
6
examples/tinygo/build.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
tinygo build -o cart.wasm -target target.json ./main.go
|
||||
uw8 filter-exports cart.wasm cart.wasm && \
|
||||
#wasm-opt -Oz --fast-math --strip-producers -o cart.wasm cart.wasm && \
|
||||
uw8 pack -l 9 cart.wasm cart.uw8
|
||||
38
examples/tinygo/main.go
Normal file
38
examples/tinygo/main.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"math"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
//go:wasm-module env
|
||||
//export atan2
|
||||
func atan2(x, y float32) float32
|
||||
|
||||
//go:wasm-module env
|
||||
//export time
|
||||
func time() float32
|
||||
|
||||
func sqrt(v float32) float32 {
|
||||
return float32(math.Sqrt(float64(v)))
|
||||
}
|
||||
|
||||
var FRAMEBUFFER = (*[320 * 240]byte)(unsafe.Pointer(uintptr(120)))
|
||||
|
||||
//export upd
|
||||
func upd() {
|
||||
var i int
|
||||
for i < 320*240 {
|
||||
t := time() * 63.0
|
||||
x := float32(i%320 - 160)
|
||||
y := float32(i/320 - 120)
|
||||
d := float32(40000.0) / sqrt(x*x+y*y)
|
||||
u := atan2(x, y) * 512.0 / 3.141
|
||||
c := uint8((int(d+t*2.0) ^ int(u+t)) >> 4)
|
||||
FRAMEBUFFER[i] = c
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
}
|
||||
23
examples/tinygo/target.json
Normal file
23
examples/tinygo/target.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"llvm-target": "wasm32--wasi",
|
||||
"build-tags": [ "tinygo.wasm" ],
|
||||
"goos": "js",
|
||||
"goarch": "wasm",
|
||||
"linker": "wasm-ld",
|
||||
"libc": "wasi-libc",
|
||||
"cflags": [
|
||||
"--target=wasm32--wasi",
|
||||
"--sysroot={root}/lib/wasi-libc/sysroot",
|
||||
"-Oz"
|
||||
],
|
||||
"ldflags": [
|
||||
"--no-entry",
|
||||
"--export-all",
|
||||
"--import-memory",
|
||||
"--initial-memory=262144",
|
||||
"--global-base=81920",
|
||||
"-zstack-size=4096",
|
||||
"--strip-all"
|
||||
],
|
||||
"wasm-abi": "js"
|
||||
}
|
||||
Reference in New Issue
Block a user