···11# D Starter Project Template
2233-This is a D TIC-80 starter template. To build the D source files:
33+## Pre-requisites
44+55+- [LDC](https://wiki.dlang.org/LDC)
66+- [WASI libc](https://github.com/WebAssembly/wasi-libc)
77+88+### WASI libc
99+1010+WASI libc's [README](https://github.com/WebAssembly/wasi-libc#usage) states
1111+that "the easiest way to get started with this is to use wask-sdk, which
1212+includes a build of WASI libc in its sysroot."
1313+1414+Just [building WASI libc from source](https://github.com/WebAssembly/wasi-libc#building-from-source)
1515+works too, for the purpose of programming TIC-80 games in D. Let's say you
1616+install into ```$HOME/wasi-sdk/share/wasi-sysroot```, which then look like this:
417518```
66-% ./build.sh
1919+% ls -l
2020+total 12
2121+drwxr-xr-x 10 pierce pierce 4096 Apr 24 16:19 include/
2222+drwxr-xr-x 3 pierce pierce 4096 Apr 24 16:19 lib/
2323+drwxr-xr-x 3 pierce pierce 4096 Apr 24 16:19 share/
724```
82599-To import the resulting WASM file into a cartridge:
2626+## Files in this template
2727+2828+- ```buildcart.sh``` - convenience script to build and run the game cartridge
2929+- ```buildwasm.sh``` - convenience script to build and run the Wasm program
3030+- ```dub.json``` - D's dub package description file
3131+- ```Makefile``` - convenience Makefile that invokes ```dub```
3232+- ```wasmdemo.wasmp``` - TIC-80 Wasm 'script' file. Note the embedded game assets data at the end of the file.
3333+3434+## Building your game
3535+3636+Define the environment variable WASI_SDK_PATH; e.g., if you installed WASI
3737+libc into ```$HOME/wasi-sdk/share/wasi-sysroot```, then ```export WASI_SDK_PATH=$HOME/wasi-sdk```.
3838+3939+Edit ```src/main.d``` to implement your game. You are of course free to
4040+organize your code in more than one D source file.
4141+4242+If you create sprites, map, music, etc., for your game, remember to
4343+replace the game asset data at the end of ```wasmdemo.wasmp``` with
4444+your creations.
4545+4646+To build the Wasm file, execute ```make```. This generates ```cart.wasm```
4747+in the current directory. To run:
10481149```
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
5050+% tic80 --fs . --cmd 'load wasmdemo.wasmp & import binary cart.wasm & run & exit'
1751```
18521919-Or, on the command line:
5353+The script ```buildwasm.sh``` contains above steps as a convenience.
5454+5555+To build a TIC-80 cartridge, first build the Wasm file, then build the
5656+cartridge file:
20572158```
2259% tic80 --fs . --cmd 'load wasmdemo.wasmp & import binary cart.wasm & save game.tic & exit'
2360```
24612525-Now, run ```game.tic```:
6262+You can then run your cartridge as follows:
26632764```
2865% tic80 --fs . --cmd 'load game.tic & run & exit'
2966```
30676868+The script ```buildcart.sh``` does the above steps as a convenience.
6969+