this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add D bindings for WebAssembly.

+174 -1
+1 -1
templates/README.md
··· 3 3 This directory contains starter projects (and libs) for the compiled languages we support via `script: wasm`. Currently this list includes: 4 4 5 5 - Zig (low-level) 6 + - D (low-level) 6 7 7 8 We could easily support these as well, with contributor help: 8 9 9 10 - C 10 11 - C++ 11 - - D 12 12 - Go 13 13 - Nelua 14 14 - Nim
+30
templates/d/README.md
··· 1 + # D Starter Project Template 2 + 3 + This is a D TIC-80 starter template. To build the D source files: 4 + 5 + ``` 6 + % ./build.sh 7 + ``` 8 + 9 + To import the resulting WASM file into a cartridge: 10 + 11 + ``` 12 + tic80 --fs . 13 + tic80 prompt> load wasmdemo.wasmp 14 + tic80 prompt> import binary cart.wasm 15 + tic80 prompt> save game.tic 16 + tic80 prompt> exit 17 + ``` 18 + 19 + Or, on the command line: 20 + 21 + ``` 22 + % tic80 --fs . --cmd 'load wasmdemo.wasmp & import binary cart.wasm & save game.tic & exit' 23 + ``` 24 + 25 + Now, run ```game.tic```: 26 + 27 + ``` 28 + % tic80 --fs . --cmd 'load game.tic & run & exit' 29 + ``` 30 +
+2
templates/d/build.sh
··· 1 + #!/bin/sh 2 + (cd src; ldc2 -mtriple=wasm32-unknown-unknown-wasm -L-allow-undefined -L-no-entry -of=../cart.wasm main.d)
+24
templates/d/src/main.d
··· 1 + import tic80; 2 + 3 + extern(C): 4 + 5 + int t, x, y; 6 + const char* m = "HELLO WORLD FROM D!"; 7 + 8 + void BOOT() { 9 + t = 1; 10 + x = 96; 11 + y = 24; 12 + } 13 + 14 + void TIC() { 15 + if (btn(0) > 0) { y--; } 16 + if (btn(1) > 0) { y++; } 17 + if (btn(2) > 0) { x--; } 18 + if (btn(3) > 0) { x++; } 19 + 20 + cls(13); 21 + spr(1+t%60/30*2, x, y, null, 0, 3, 0, 0, 2, 2); 22 + print(m, 60, 84, 15, 1, 1, 0); 23 + t++; 24 + }
+60
templates/d/src/tic80.d
··· 1 + module tic80; 2 + 3 + extern(C): 4 + 5 + struct MouseData { 6 + short x; short y; 7 + short scrollx; short scrolly; 8 + bool left; bool middle; bool right; 9 + } 10 + 11 + const int WIDTH = 240; 12 + const int HEIGHT = 136; 13 + 14 + int btn(int id); 15 + bool btnp(int id, int hold, int period); 16 + void circ(int x, int y, int radius, int color); 17 + void circb(int x, int y, int radius, int color); 18 + void clip(int x, int y, int w, int h); 19 + void cls(int color); 20 + void exit(); 21 + void elli(int x, int y, int a, int b, int color); 22 + void ellib(int x, int y, int a, int b, int color); 23 + bool fget(int id, ubyte flag); 24 + int font(char* text, int x, int y, ubyte transcolors, int colorcount, int width, int height, bool fixed, int scale); 25 + bool fset(int id, ubyte flag, bool value); 26 + bool key(int keycode); 27 + bool keyp(int keycode, int hold, int period); 28 + void line(int x0, int y0, int x1, int y1, int color); 29 + void map(int x, int y, int w, int h, int sx, int sy, ubyte transcolors, int colorcount, int scale, int remap); 30 + void memcpy(uint copyto, uint copyfrom, uint length); 31 + void memset(uint addr, ubyte value, uint length); 32 + int mget(int x, int y); 33 + void mouse(MouseData* data); 34 + void mset(int x, int y, bool value); 35 + void music(int track, int frame, int row, bool loop, bool sustain, int tempo, int speed); 36 + ubyte peek(int addr, int bits); 37 + int print(const char* txt, int x, int y, int color, int fixed, int scale, int alt); 38 + ubyte peek4(uint addr4); 39 + ubyte peek2(uint addr2); 40 + ubyte peek1(uint bitaddr); 41 + void pix(int x, int y, int color); 42 + uint pmem(uint index, uint value); 43 + void poke(uint addr, ubyte value, int bits); 44 + void poke4(uint addr4, ubyte value); 45 + void poke2(uint addr2, ubyte value); 46 + void poke1(uint bitaddr, ubyte value); 47 + void rect(int x, int y, int w, int h, int color); 48 + void rectb(int x, int y, int w, int h, int color); 49 + void reset(); 50 + void sfx(int id, int note, int octave, int duration, int channel, int volumeLeft, int volumeRight, int speed); 51 + void spr(int id, int x, int y, uint* transcolors, uint colorcount, int scale, int flip, int rotate, int w, int h); 52 + void sync(int mask, int bank, bool tocart); 53 + void trace(const char* txt, int color); 54 + 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); 55 + void tri(float x1, float y1, float x2, float y2, float x3, float y3, int color); 56 + void trib(float x1, float y1, float x2, float y2, float x3, float y3, int color); 57 + int time(); 58 + int tstamp(); 59 + int vbank(int bank); 60 +
+57
templates/d/wasmdemo.wasmp
··· 1 + -- desc: WASM Introduction 2 + -- script: wasm 3 + 4 + """"""""""""""""""""""""""""""""""""""" 5 + WASM is a binary format. The demo 6 + binary code is embedded in this 7 + cartridge, the source code is not. 8 + Run the cart to see the demo. 9 + 10 + This demo exits for completeness, but 11 + you can't (yet) develop WASM projects 12 + using the built-in editor. 13 + 14 + The code used to build this project 15 + can be found in the TIC-80 repo: 16 + 17 + https://github.com/nesbox/TIC-80/templates/d 18 + 19 + This demo was built with D, but many 20 + languages are supported. You simply 21 + build your project with your external 22 + compiler, then import the final WASM 23 + binary into your cartridge: 24 + 25 + import binary out.wasm 26 + 27 + See README.md for details. 28 + 29 + To learn more visit our Wiki and 30 + the 'Getting Started with WASM' page. 31 + 32 + " 33 + -- <TILES> 34 + -- 001:eccccccccc888888caaaaaaaca888888cacccccccacc0ccccacc0ccccacc0ccc 35 + -- 002:ccccceee8888cceeaaaa0cee888a0ceeccca0ccc0cca0c0c0cca0c0c0cca0c0c 36 + -- 003:eccccccccc888888caaaaaaaca888888cacccccccacccccccacc0ccccacc0ccc 37 + -- 004:ccccceee8888cceeaaaa0cee888a0ceeccca0cccccca0c0c0cca0c0c0cca0c0c 38 + -- 017:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec 39 + -- 018:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee 40 + -- 019:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec 41 + -- 020:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee 42 + -- </TILES> 43 + 44 + -- <WAVES> 45 + -- 000:00000000ffffffff00000000ffffffff 46 + -- 001:0123456789abcdeffedcba9876543210 47 + -- 002:0123456789abcdef0123456789abcdef 48 + -- </WAVES> 49 + 50 + -- <SFX> 51 + -- 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000 52 + -- </SFX> 53 + 54 + -- <PALETTE> 55 + -- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57 56 + -- </PALETTE> 57 +