-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add project template based on wasm4 Wat template
- Loading branch information
Showing
4 changed files
with
127 additions
and
0 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
!LICENCE | ||
!/**/ | ||
!*.* | ||
!Makefile | ||
*.asm | ||
*.wat | ||
*.wasm | ||
|
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,66 @@ | ||
ifndef WABT_PATH | ||
$(error Download Wabt (https://github.com/WebAssembly/wabt) and set $$WABT_PATH) | ||
endif | ||
|
||
4ORTH = 4orth | ||
|
||
ifeq (, $(shell command -v $(4ORTH))) | ||
$(error Download 4orth (https://github.com/FrankWPA/4orth) and add it to $$PATH) | ||
endif | ||
|
||
4ORTH_PATH = $(shell command -v $(4ORTH)) | ||
4ORTH_DIR = $(shell dirname -- "$(4ORTH_PATH)") | ||
4ORTH_FLAGS = -I $(4ORTH_DIR) -I $(4ORTH_DIR)/std | ||
4ORTH_COMMAND := com -s | ||
|
||
ifeq ($(b), 1) | ||
4ORTH_COMMAND := $(4ORTH_COMMAND) -b | ||
endif | ||
|
||
ifeq ($(r), 1) | ||
4ORTH_COMMAND := $(4ORTH_COMMAND) -r | ||
endif | ||
|
||
# Optional dependency from binaryen for smaller builds | ||
WASM_OPT = wasm-opt | ||
WASM_OPT_FLAGS = -Oz | ||
|
||
ifeq ($(opt), 1) | ||
ifeq (, $(shell command -v $(WASM_OPT))) | ||
$(error Using the subcommand -opt requires $(WASM_OPT) from binaryen) | ||
endif | ||
4ORTH_COMMAND := $(4ORTH_COMMAND) -opt | ||
endif | ||
|
||
ifeq ($(OS), Windows_NT) | ||
$(error 4orth compiler only supports Linux) | ||
else | ||
MKDIR_BUILD = mkdir -p build | ||
RMDIR = rm -rf | ||
endif | ||
|
||
all: build/cart.wasm | ||
|
||
# Build cart.wasm from main.porth and run wasm-opt | ||
.PHONY: build/cart.wasm | ||
build/cart.wasm: main.porth | ||
@$(MKDIR_BUILD) | ||
$(4ORTH) $(4ORTH_FLAGS) $(4ORTH_COMMAND) $< | ||
mv main.wat build/cart.wat | ||
mv main.wasm build/cart.wasm | ||
ifeq ($(b), 1) | ||
mv main build/cart | ||
endif | ||
ifneq ($(opt), 1) | ||
ifneq ($(DEBUG), 1) | ||
ifeq (, $(shell command -v $(WASM_OPT))) | ||
@echo Tip: $(WASM_OPT) was not found. Install it from binaryen for smaller builds! | ||
else | ||
$(WASM_OPT) $(WASM_OPT_FLAGS) $@ -o $@ | ||
endif | ||
endif | ||
endif | ||
|
||
.PHONY: clean | ||
clean: | ||
$(RMDIR) build |
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,26 @@ | ||
# hello-world | ||
|
||
A game written in Porth for the [WASM-4](https://wasm4.org) fantasy console. | ||
|
||
## Building | ||
|
||
Build the cart by running: | ||
|
||
```shell | ||
make | ||
``` | ||
|
||
Then run it with: | ||
|
||
```shell | ||
w4 run build/cart.wasm | ||
``` | ||
|
||
For more info about setting up WASM-4, see the [quickstart guide](https://wasm4.org/docs/getting-started/setup?code-lang=wat#quickstart). | ||
|
||
## Links | ||
|
||
- [Documentation](https://wasm4.org/docs): Learn more about WASM-4. | ||
- [Snake Tutorial](https://wasm4.org/docs/tutorials/snake/goal): Learn how to build a complete game | ||
with a step-by-step tutorial. | ||
- [GitHub](https://github.com/aduros/wasm4): Submit an issue or PR. Contributions are welcome! |
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,34 @@ | ||
include "wasm4.porth" | ||
|
||
const smiley "\\c3\\81\\24\\24\\00\\24\\99\\c3"c end | ||
|
||
const hello "Hello from Porth!"c end | ||
const blink "Press X to blink"c end | ||
|
||
proc main in end | ||
|
||
proc update in | ||
memory $gamepad sizeof(u8) end | ||
|
||
// DRAW_COLORS = 2 | ||
2 $DRAW_COLORS !16 | ||
|
||
// text("Hello from Wat!", 10, 10); | ||
10 10 hello text | ||
|
||
// u8 gamepad = $GAMEPAD1; | ||
$GAMEPAD1 @8 $gamepad !8 | ||
|
||
// if (gamepad & BUTTON_1) { | ||
// $DRAW_COLORS = 4; | ||
// } | ||
$gamepad @8 $BUTTON_1 and cast(bool) if | ||
4 $DRAW_COLORS !16 | ||
end | ||
|
||
// blit(smiley, 76, 76, 8, 8, $BLIT_1BPP); | ||
$BLIT_1BPP 8 8 76 76 smiley blit | ||
|
||
// text("Press X to blink", 16, 90); | ||
90 16 blink text | ||
end |