···33This directory contains starter projects (and libs) for the compiled languages we support via `script: wasm`. Currently this list includes:
4455- Zig (low-level)
66+- D (low-level)
6778We could easily support these as well, with contributor help:
89910- C
1011- C++
1111-- D
1212- Go
1313- Nelua
1414- Nim
+30
templates/d/README.md
···11+# D Starter Project Template
22+33+This is a D TIC-80 starter template. To build the D source files:
44+55+```
66+% ./build.sh
77+```
88+99+To import the resulting WASM file into a cartridge:
1010+1111+```
1212+tic80 --fs .
1313+tic80 prompt> load wasmdemo.wasmp
1414+tic80 prompt> import binary cart.wasm
1515+tic80 prompt> save game.tic
1616+tic80 prompt> exit
1717+```
1818+1919+Or, on the command line:
2020+2121+```
2222+% tic80 --fs . --cmd 'load wasmdemo.wasmp & import binary cart.wasm & save game.tic & exit'
2323+```
2424+2525+Now, run ```game.tic```:
2626+2727+```
2828+% tic80 --fs . --cmd 'load game.tic & run & exit'
2929+```
3030+
···11+import tic80;
22+33+extern(C):
44+55+int t, x, y;
66+const char* m = "HELLO WORLD FROM D!";
77+88+void BOOT() {
99+ t = 1;
1010+ x = 96;
1111+ y = 24;
1212+}
1313+1414+void TIC() {
1515+ if (btn(0) > 0) { y--; }
1616+ if (btn(1) > 0) { y++; }
1717+ if (btn(2) > 0) { x--; }
1818+ if (btn(3) > 0) { x++; }
1919+2020+ cls(13);
2121+ spr(1+t%60/30*2, x, y, null, 0, 3, 0, 0, 2, 2);
2222+ print(m, 60, 84, 15, 1, 1, 0);
2323+ t++;
2424+}
+60
templates/d/src/tic80.d
···11+module tic80;
22+33+extern(C):
44+55+struct MouseData {
66+ short x; short y;
77+ short scrollx; short scrolly;
88+ bool left; bool middle; bool right;
99+}
1010+1111+const int WIDTH = 240;
1212+const int HEIGHT = 136;
1313+1414+int btn(int id);
1515+bool btnp(int id, int hold, int period);
1616+void circ(int x, int y, int radius, int color);
1717+void circb(int x, int y, int radius, int color);
1818+void clip(int x, int y, int w, int h);
1919+void cls(int color);
2020+void exit();
2121+void elli(int x, int y, int a, int b, int color);
2222+void ellib(int x, int y, int a, int b, int color);
2323+bool fget(int id, ubyte flag);
2424+int font(char* text, int x, int y, ubyte transcolors, int colorcount, int width, int height, bool fixed, int scale);
2525+bool fset(int id, ubyte flag, bool value);
2626+bool key(int keycode);
2727+bool keyp(int keycode, int hold, int period);
2828+void line(int x0, int y0, int x1, int y1, int color);
2929+void map(int x, int y, int w, int h, int sx, int sy, ubyte transcolors, int colorcount, int scale, int remap);
3030+void memcpy(uint copyto, uint copyfrom, uint length);
3131+void memset(uint addr, ubyte value, uint length);
3232+int mget(int x, int y);
3333+void mouse(MouseData* data);
3434+void mset(int x, int y, bool value);
3535+void music(int track, int frame, int row, bool loop, bool sustain, int tempo, int speed);
3636+ubyte peek(int addr, int bits);
3737+int print(const char* txt, int x, int y, int color, int fixed, int scale, int alt);
3838+ubyte peek4(uint addr4);
3939+ubyte peek2(uint addr2);
4040+ubyte peek1(uint bitaddr);
4141+void pix(int x, int y, int color);
4242+uint pmem(uint index, uint value);
4343+void poke(uint addr, ubyte value, int bits);
4444+void poke4(uint addr4, ubyte value);
4545+void poke2(uint addr2, ubyte value);
4646+void poke1(uint bitaddr, ubyte value);
4747+void rect(int x, int y, int w, int h, int color);
4848+void rectb(int x, int y, int w, int h, int color);
4949+void reset();
5050+void sfx(int id, int note, int octave, int duration, int channel, int volumeLeft, int volumeRight, int speed);
5151+void spr(int id, int x, int y, uint* transcolors, uint colorcount, int scale, int flip, int rotate, int w, int h);
5252+void sync(int mask, int bank, bool tocart);
5353+void trace(const char* txt, int color);
5454+void textri(float x1, float y1, float x2, float y2, float x3, float y3, float u1, float v1, float u2, float v2, float u3, float v3, int texsrc, ubyte transcolors, int colorcount, float z1, float z2, float z3, bool persp);
5555+void tri(float x1, float y1, float x2, float y2, float x3, float y3, int color);
5656+void trib(float x1, float y1, float x2, float y2, float x3, float y3, int color);
5757+int time();
5858+int tstamp();
5959+int vbank(int bank);
6060+
+57
templates/d/wasmdemo.wasmp
···11+-- desc: WASM Introduction
22+-- script: wasm
33+44+"""""""""""""""""""""""""""""""""""""""
55+WASM is a binary format. The demo
66+binary code is embedded in this
77+cartridge, the source code is not.
88+Run the cart to see the demo.
99+1010+This demo exits for completeness, but
1111+you can't (yet) develop WASM projects
1212+using the built-in editor.
1313+1414+The code used to build this project
1515+can be found in the TIC-80 repo:
1616+1717+https://github.com/nesbox/TIC-80/templates/d
1818+1919+This demo was built with D, but many
2020+languages are supported. You simply
2121+build your project with your external
2222+compiler, then import the final WASM
2323+binary into your cartridge:
2424+2525+ import binary out.wasm
2626+2727+See README.md for details.
2828+2929+To learn more visit our Wiki and
3030+the 'Getting Started with WASM' page.
3131+3232+"
3333+-- <TILES>
3434+-- 001:eccccccccc888888caaaaaaaca888888cacccccccacc0ccccacc0ccccacc0ccc
3535+-- 002:ccccceee8888cceeaaaa0cee888a0ceeccca0ccc0cca0c0c0cca0c0c0cca0c0c
3636+-- 003:eccccccccc888888caaaaaaaca888888cacccccccacccccccacc0ccccacc0ccc
3737+-- 004:ccccceee8888cceeaaaa0cee888a0ceeccca0cccccca0c0c0cca0c0c0cca0c0c
3838+-- 017:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec
3939+-- 018:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee
4040+-- 019:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec
4141+-- 020:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee
4242+-- </TILES>
4343+4444+-- <WAVES>
4545+-- 000:00000000ffffffff00000000ffffffff
4646+-- 001:0123456789abcdeffedcba9876543210
4747+-- 002:0123456789abcdef0123456789abcdef
4848+-- </WAVES>
4949+5050+-- <SFX>
5151+-- 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000
5252+-- </SFX>
5353+5454+-- <PALETTE>
5555+-- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
5656+-- </PALETTE>
5757+