-
Notifications
You must be signed in to change notification settings - Fork 202
Add Grain language support #712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| *.wasm |
This file contains hidden or 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 @@ | ||
| build: | ||
| grain compile --release --elide-type-info \ | ||
| --import-memory --use-start-section --memory-base 8192 \ | ||
| --initial-memory-pages 1 --maximum-memory-pages 1 \ | ||
| --wasi-polyfill bindings/wasm4-wasi-polyfill.gr -I bindings \ | ||
| app/main.gr -o cart.wasm | ||
|
|
||
| clean: | ||
| find -name '*.wasm' | xargs rm |
This file contains hidden or 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,15 @@ | ||
| # Grain bindings for WASM-4 | ||
|
|
||
| Requires grain 0.6 or higher. Tested with Grain 0.6.3. For fast compiling, be sure to [build Grain from source](https://grain-lang.org/docs/getting_grain#Building-Grain-from-Source). | ||
|
|
||
| For original template source, see: | ||
|
|
||
| - https://github.com/ospencer/wasm4-gr | ||
|
|
||
| Tips and source here are copied from there. | ||
|
|
||
| ## Tips to fit within 64k | ||
|
|
||
| This limitation is part of the fun. Grain's extensive `Number` type brings in quite a bit of support code, so avoiding it (and standard libraries that depend on it) is the best way to keep the cartridge size small. This includes the math operations provided by `Pervasives`, like `+` and `==`, but conveniently, the WASM-4 API uses the `Uint8` and `Uint16` types. The `hello-world.gr` example is only 7k, and even with a number of sprites and a good chunk of music data, the `music.gr` example is 21k. | ||
|
|
||
| Good luck and have fun! |
This file contains hidden or 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,49 @@ | ||
| module HelloWorld | ||
|
|
||
| from "wasm4" include Wasm4 as W4 | ||
| from "uint8" include Uint8 | ||
| use Uint8.{ (+), (-), (&), (>), (==) } | ||
|
|
||
| let smiley = b"\xc3\x81\x24\x24\x00\x24\x99\xc3" | ||
|
|
||
| let itsDangerous = "IT'S DANGEROUS\n TO GO ALONE!" | ||
|
|
||
| let mut x = 76us | ||
| let mut y = 76us | ||
|
|
||
| let mut frame = 0us | ||
|
|
||
| provide let update = () => { | ||
| if (frame == 108us) { | ||
| frame = 0us | ||
| } | ||
|
|
||
| // Load the gamepad | ||
| let gamepad = W4.gamepad1() | ||
|
|
||
| // Move the player location | ||
| if ((gamepad & W4._BUTTON_LEFT) > 0us) { | ||
| x -= 1us | ||
| } | ||
| if ((gamepad & W4._BUTTON_RIGHT) > 0us) { | ||
| x += 1us | ||
| } | ||
| if ((gamepad & W4._BUTTON_UP) > 0us) { | ||
| y -= 1us | ||
| } | ||
| if ((gamepad & W4._BUTTON_DOWN) > 0us) { | ||
| y += 1us | ||
| } | ||
|
|
||
| // Swap to color 2 | ||
| W4.drawColors(2uS) | ||
| // Write the text | ||
| W4.text(itsDangerous, 24us, 50us) | ||
|
|
||
| // Swap to color 3 | ||
| W4.drawColors(3uS) | ||
| // Draw the sprite | ||
| W4.blit(smiley, x, y, 8us, 8us, W4._BLIT_1BPP) | ||
|
|
||
| frame += 1us | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested a variation of this example using png2src output instead of the manual things here, and it worked for me.
The original example here also worked for me. I used a manually built Grain 0.6.3.