From 976889e9c4dcbc141aa7b60c6337f4926051b325 Mon Sep 17 00:00:00 2001 From: Mohamed Akram Date: Wed, 18 Sep 2024 08:03:47 +0400 Subject: [PATCH] Add wasm target --- .github/workflows/pages.yml | 2 +- .gitignore | 2 ++ Makefile | 11 ++++++++++- README.md | 7 ++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 43aeb9f..8000ef6 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -33,7 +33,7 @@ jobs: - name: Setup emsdk uses: mymindstorm/setup-emsdk@v14 - name: Build Space Travel - run: emcc st.c -s USE_SDL=2 -o html/st.js + run: make wasm - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: diff --git a/.gitignore b/.gitignore index 6de6262..35b9086 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ *.obj *.dll *.exe +*.wasm /st +/html/st.js diff --git a/Makefile b/Makefile index 7aa7481..b070978 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ INSTALL = install MKDIR = mkdir -p +EMCC = emcc prefix = /usr/local bindir = $(prefix)/bin @@ -16,9 +17,17 @@ prefix=. # \ !endif LDLIBS = -lm -lSDL2 + all: st$(EXEEXT) + +wasm: html/st.js + +html/st.js: st.c + $(EMCC) -s USE_SDL=2 -o $@ st.c + clean: - $(RM) st$(EXEEXT) + $(RM) st$(EXEEXT) html/st.js html/*.wasm + install: st$(EXEEXT) $(DESTDIR)$(bindir) $(INSTALL) st$(EXEEXT) "$(DESTDIR)$(bindir)" diff --git a/README.md b/README.md index 6fecd67..ef1d3e4 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,8 @@ This is a C port of Ken Thompson's [Space Travel](https://en.wikipedia.org/wiki/Space_Travel_\(video_game\)), ported from PDP-7 assembly. The original source files are in `src/cmd/st*.s` -in the [pdp7-unix](https://github.com/DoctorWkt/pdp7-unix) repository. +in the [pdp7-unix](https://github.com/DoctorWkt/pdp7-unix) repository. The game +is available to [play online](https://akr.am/st) via WebAssembly. ## Install @@ -13,6 +14,10 @@ Run `make` to build `st`. Run `make install` to install to `/usr/local/bin`. +Run `make wasm` (requires [Emscripten](https://emscripten.org)) to build a +WebAssembly version of the game. To play it, launch a web server via +`python3 -m http.server -d html` and go to http://localhost:8000. + ## Controls | Key | Action |