-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
122 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# 版权 @2024 P5-hello 作者。保留所有权利。 | ||
|
||
dev: | ||
go run ../../../main.go build -target=wasm4 . | ||
|
||
run: | ||
go run ../../../main.go run -target=wasm4 . | ||
|
||
clean: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# WASM4 例子 | ||
|
||
https://wasm4.org/docs/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// 版权 @2024 W4-hello 作者。保留所有权利。 | ||
|
||
import "wasm4" | ||
|
||
global smiley = []byte{ | ||
0b11000011, | ||
0b10000001, | ||
0b00100100, | ||
0b00100100, | ||
0b00000000, | ||
0b00100100, | ||
0b10011001, | ||
0b11000011, | ||
} | ||
|
||
func init { | ||
wasm4.Update = update | ||
} | ||
|
||
func Update() { | ||
wasm4.DrawColors.SetPrimary(wasm4.Primary) | ||
wasm4.DrawText("Hello from Wa!", wasm4.Point{X: 10, Y: 10}) | ||
if wasm4.Gamepad.X() { | ||
wasm4.DrawColors.SetPrimary(wasm4.Dark) | ||
} | ||
wasm4.Blit(smiley, wasm4.Point{X: 76, Y: 76}, wasm4.Size{Width: 8, Height: 8}, 0) | ||
wasm4.DrawText("Press X to blink", wasm4.Point{X: 16, Y: 90}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# 版权 @2024 magnifying-glass 作者。保留所有权利。 | ||
|
||
name = "w4app" | ||
pkgpath = "w4app" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
;; Copyright 2023 The Wa Authors. All rights reserved. | ||
|
||
;; 打印字符串 | ||
(func $$runtime.waPuts (param $str i32) (param $len i32) | ||
;; {{$$runtime.waPuts/body/begin}} | ||
|
||
(local $sp i32) | ||
(local $p_iov i32) | ||
(local $p_nwritten i32) | ||
(local $stdout i32) | ||
|
||
;; 保存栈指针状态 | ||
global.get $__stack_ptr | ||
local.set $sp | ||
|
||
;; 分配 iov 结构体 | ||
i32.const 8 | ||
call $runtime.stackAlloc | ||
local.set $p_iov | ||
|
||
;; 返回地址 | ||
i32.const 4 | ||
call $runtime.stackAlloc | ||
local.set $p_nwritten | ||
|
||
;; 设置字符串指针和长度 | ||
local.get $p_iov | ||
local.get $str | ||
i32.store offset=0 align=1 | ||
|
||
local.get $p_iov | ||
local.get $len | ||
i32.store offset=4 align=1 | ||
|
||
;; 标准输出 | ||
i32.const 1 | ||
local.set $stdout | ||
|
||
;; 输出字符串 | ||
local.get $stdout | ||
local.get $p_iov | ||
i32.const 1 | ||
local.get $p_nwritten | ||
call $$runtime.fdWrite | ||
|
||
;; 重置栈指针 | ||
local.get $sp | ||
global.set $__stack_ptr | ||
drop | ||
|
||
;; {{$$runtime.waPuts/body/end}} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// 版权 @2022 凹语言 作者。保留所有权利。 | ||
|
||
import "syscall/wasm4" | ||
|
||
const WAOS = "wasm4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// 版权 @2024 凹语言 作者。保留所有权利。 |