@ecmaos-apps/doom-src 0.0.0-stage → 0.1.0-ecmaos.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +8 -2
  2. package/build/build.sh +52 -0
  3. package/build/doomecma.c +188 -0
  4. package/build/doomsound.c +156 -0
  5. package/build/runtime.sh +18 -0
  6. package/package.json +55 -4
  7. package/share/licenses/doom/SOURCE +48 -0
  8. package/sources/SDL3-3.4.18.tar.gz +0 -0
  9. package/sources/doomgeneric-e257a09527062bfb986b6e5e0780839b6cbd5b71.tar.gz +0 -0
  10. package/sources/freedoom-0.13.0.zip +0 -0
  11. package/sources/libxkbcommon-xkbcommon-1.13.2.tar.gz +0 -0
  12. package/sources/wayland-1.26.0.tar.xz +0 -0
  13. package/toolchain/emscripten-version +1 -0
  14. package/toolchain/rust-wali-version +3 -0
  15. package/toolchain/wali/asyncify-reach.mjs +107 -0
  16. package/toolchain/wali/asyncify.sh +57 -0
  17. package/toolchain/wali/build-sysroot.sh +158 -0
  18. package/toolchain/wali/patches/compiler-rt/0001-wasm-compare-result.patch +18 -0
  19. package/toolchain/wali/patches/musl/0001-environment-through-imports.patch +143 -0
  20. package/toolchain/wali/patches/musl/0002-setjmp-with-wasm-exceptions.patch +133 -0
  21. package/toolchain/wali/patches/musl/0003-unknown-syscall-is-enosys.patch +31 -0
  22. package/toolchain/wali/patches/musl/0004-return-from-main-is-exit.patch +53 -0
  23. package/toolchain/wali/patches/musl/0005-posix-spawn-through-the-host.patch +278 -0
  24. package/toolchain/wali/patches/musl/0006-detached-thread-frees-its-stack.patch +34 -0
  25. package/toolchain/wali/patches/musl/0007-wordexp-without-fork.patch +62 -0
  26. package/toolchain/wali/patches/musl/0008-progname-from-argv.patch +34 -0
  27. package/toolchain/wali/patches/musl/0009-no-basename-in-string-h.patch +15 -0
  28. package/toolchain/wali/patches/musl/0010-ssize-max-is-pointer-sized.patch +15 -0
  29. package/toolchain/wali/patches/musl/0011-startup-without-malloc.patch +85 -0
  30. package/toolchain/wali/patches/musl/0012-floatscan-fixes-from-musl.patch +39 -0
  31. package/toolchain/wali/patches/musl/0013-strptime-from-musl-with-glibc-s-and-z.patch +169 -0
  32. package/toolchain/wali/patches/musl/0014-wordexp-fixes-from-musl.patch +43 -0
  33. package/toolchain/wali/patches/musl/0015-long-double-is-ieee-quad.patch +202 -0
  34. package/toolchain/wali/patches/musl/0016-wordexp-nocmd-and-undef.patch +285 -0
  35. package/toolchain/wali/rust.sh +116 -0
  36. package/toolchain/wali/signal-checks.mjs +373 -0
  37. package/toolchain/wali-version +13 -0
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
- # Temporary Holding Version
1
+ # @ecmaos-apps/doom-src
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Corresponding Source of `@ecmaos-apps/doom` 0.1.0-ecmaos.2 (GPL-2.0-or-later AND Zlib AND MIT AND BSD-3-Clause): everything needed to build the `doom.wasm` it ships.
4
+
5
+ - `sources/` - the upstream archives, each checked against the sha256 in `package.json` (`ecmaos.archives`)
6
+ - `build/` - the scripts that turn them into the program (our changes to the source are in them)
7
+ - `toolchain/` - the pins of the compiler and libc the program is built with, and the patches to WALI's musl and compiler-rt (`wali/`)
8
+
9
+ Installed with `apt source doom` or `install @ecmaos-apps/doom-src`.
package/build/build.sh ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env bash
2
+ # SPDX-License-Identifier: GPL-2.0-or-later
3
+ # Rebuilds programs/doom.wasm: id Software's Doom for ecmaOS. The engine is doomgeneric (GPL-2.0, a portable
4
+ # cut of the Doom source release; https://github.com/ozkl/doomgeneric) and the platform layer is doomecma.c, which
5
+ # draws into a window on SDL 3 on its Wayland driver, with doomsound.c as the engine's sound module. SDL, libwayland
6
+ # and libxkbcommon are built by the shared scripts of @ecmaos/coreutils (core/utils/wasm/lib/sdl.sh, wayland.sh and
7
+ # xkbcommon.sh in the repository; wasm/lib/ in that npm package), from the archives pinned here in programs/manifest.json.
8
+ # The engine is software rendered; no game data is included (see the doom manual page for where to get a WAD).
9
+ #
10
+ # Built on WALI's musl (`utils/check-wali.sh`), with the libraries built the same way, and run by /bin/wali. Needs
11
+ # cmake, ninja, pkg-config, bison, and the libxml2 and expat development files (wayland.sh builds its own wayland-scanner from them). The result is committed, so only run this to change
12
+ # it. No music: the engine's music module does nothing.
13
+ set -euo pipefail
14
+ source "$(dirname "$0")/../../../../utils/check-wali.sh"
15
+
16
+ HERE=$(cd "$(dirname "$0")" && pwd)
17
+ SOURCES="$HERE/../../scripts/sources.mjs"
18
+ LIB=$HERE/../../../utils/wasm/lib
19
+ COMMIT=$(node "$SOURCES" version doom doomgeneric)
20
+ DOOMGENERIC_ARCHIVE=$(node "$SOURCES" fetch doom doomgeneric)
21
+ SDL_ARCHIVE=$(node "$SOURCES" fetch doom sdl)
22
+ WAYLAND_ARCHIVE=$(node "$SOURCES" fetch doom wayland)
23
+ XKBCOMMON_ARCHIVE=$(node "$SOURCES" fetch doom xkbcommon)
24
+ source "$LIB/wayland.sh"
25
+ source "$LIB/xkbcommon.sh"
26
+ source "$LIB/sdl.sh"
27
+ [ "$SDL" = "$(node "$SOURCES" version doom sdl)" ] && [ "$WAYLAND" = "$(node "$SOURCES" version doom wayland)" ] &&
28
+ [ "$XKBCOMMON" = "$(node "$SOURCES" version doom xkbcommon)" ] ||
29
+ { echo "doom: the SDL, libwayland or libxkbcommon version in $LIB differs from programs/manifest.json" >&2; exit 1; }
30
+ OUT=$HERE/../../programs/doom.wasm
31
+ if [ -n "${DOOM_WORK:-}" ]; then WORK=$DOOM_WORK; mkdir -p "$WORK"; else WORK=$(mktemp -d); trap 'rm -rf "$WORK"' EXIT; fi # DOOM_WORK keeps the SDL build between runs
32
+
33
+ if [ -f "$WORK/prefix/lib/libSDL3.a" ] && [ -n "${DOOM_WORK:-}" ]; then
34
+ SDL_INC="-I$WORK/prefix/include"; SDL_LIB="-L$WORK/prefix/lib -lSDL3"
35
+ SDL_DEPS_LIB="-L$WORK/prefix/lib -lwayland-cursor -lwayland-egl -lwayland-client -lxkbcommon"
36
+ else
37
+ build_wayland "$WORK" wali
38
+ build_xkbcommon "$WORK" wali
39
+ build_sdl "$WORK" wali
40
+ fi
41
+
42
+ [ -d "$WORK/doomgeneric-$COMMIT" ] || ( cd "$WORK" && tar xzf "$DOOMGENERIC_ARCHIVE" )
43
+ SRC=$WORK/doomgeneric-$COMMIT/doomgeneric
44
+ # every engine file but the other platforms' layers and the sound and music modules (SDL_mixer and Allegro)
45
+ ENGINE_SOURCES=$(cd "$SRC" && ls *.c | grep -v -e '^doomgeneric_' -e '^i_allegro' -e '^i_sdlmusic\.c$' -e '^i_sdlsound\.c$' -e '^icon\.c$' | sed "s|^|$SRC/|")
46
+ # i_sound.c includes SDL_mixer.h when sound is on; doomsound.c is the sound module instead, so the header is empty
47
+ mkdir -p "$WORK/stub" && : > "$WORK/stub/SDL_mixer.h"
48
+ "$WALI_CC" $ENGINE_SOURCES "$HERE/doomecma.c" "$HERE/doomsound.c" -I"$SRC" -I"$WORK/stub" -DFEATURE_SOUND $SDL_INC -O2 -w -DNORMALUNIX -DLINUX -D_DEFAULT_SOURCE \
49
+ ${DOOM_EXTRA:-} $SDL_LIB $SDL_DEPS_LIB -o "$WORK/doom.wasm"
50
+ cp "$WORK/doom.wasm" "$OUT"
51
+ ls -l "$OUT"
52
+ echo "built with $WALI_TOOLCHAIN"
@@ -0,0 +1,188 @@
1
+ /* SPDX-License-Identifier: GPL-2.0-or-later
2
+ * doomecma: the platform layer that puts doomgeneric (id Software's Doom engine, see build.sh) in an ecmaOS window on
3
+ * SDL 3 (its Wayland driver, see wasm/lib/sdl.sh). The engine draws 640x400 in 32 bit color into DG_ScreenBuffer; each
4
+ * frame is scaled into the window's software surface, so the window can be resized. Keys follow Doom's own (Ctrl fires,
5
+ * Space opens doors, Alt strafes, Shift runs). Escape opens the menu; closing the window quits.
6
+ * Usage: doom [-iwad FILE] [engine options]. Needs wlcomp running. Without XDG_RUNTIME_DIR it uses /run/user/UID.
7
+ * The engine as built looks for a WAD only in the current directory, so main() adds the places Doom looks on Unix
8
+ * (DOOMWADDIR, DOOMWADPATH, /usr/share/games/doom, where the package puts Freedoom) when -iwad is not given and the
9
+ * current directory has none. */
10
+ #include <SDL3/SDL.h>
11
+ #include <ctype.h>
12
+ #include <stdio.h>
13
+ #include <stdlib.h>
14
+ #include <string.h>
15
+ #include <unistd.h>
16
+ #include "doomkeys.h"
17
+ #include "doomgeneric.h"
18
+
19
+ static SDL_Window *window;
20
+ static SDL_Surface *frame;
21
+
22
+ #define KEYQUEUE_SIZE 64
23
+ static unsigned short key_queue[KEYQUEUE_SIZE];
24
+ static unsigned int key_write, key_read;
25
+
26
+ static unsigned char doom_key(SDL_Keycode key)
27
+ {
28
+ switch (key) {
29
+ case SDLK_RETURN: return KEY_ENTER;
30
+ case SDLK_ESCAPE: return KEY_ESCAPE;
31
+ case SDLK_TAB: return KEY_TAB;
32
+ case SDLK_BACKSPACE: return KEY_BACKSPACE;
33
+ case SDLK_LEFT: return KEY_LEFTARROW;
34
+ case SDLK_RIGHT: return KEY_RIGHTARROW;
35
+ case SDLK_UP: return KEY_UPARROW;
36
+ case SDLK_DOWN: return KEY_DOWNARROW;
37
+ case SDLK_LCTRL: case SDLK_RCTRL: return KEY_FIRE;
38
+ case SDLK_SPACE: return KEY_USE;
39
+ case SDLK_LSHIFT: case SDLK_RSHIFT: return KEY_RSHIFT;
40
+ case SDLK_LALT: case SDLK_RALT: return KEY_LALT;
41
+ case SDLK_F1: return KEY_F1;
42
+ case SDLK_F2: return KEY_F2;
43
+ case SDLK_F3: return KEY_F3;
44
+ case SDLK_F4: return KEY_F4;
45
+ case SDLK_F5: return KEY_F5;
46
+ case SDLK_F6: return KEY_F6;
47
+ case SDLK_F7: return KEY_F7;
48
+ case SDLK_F8: return KEY_F8;
49
+ case SDLK_F9: return KEY_F9;
50
+ case SDLK_F10: return KEY_F10;
51
+ case SDLK_F11: return KEY_F11;
52
+ case SDLK_F12: return KEY_F12;
53
+ case SDLK_PAUSE: return KEY_PAUSE;
54
+ case SDLK_EQUALS: case SDLK_PLUS: return KEY_EQUALS;
55
+ case SDLK_MINUS: return KEY_MINUS;
56
+ default: return key < 128 ? (unsigned char)tolower((int)key) : 0;
57
+ }
58
+ }
59
+
60
+ static void push_key(int pressed, SDL_Keycode sym)
61
+ {
62
+ unsigned char key = doom_key(sym);
63
+ if (!key) return;
64
+ key_queue[key_write] = (unsigned short)((pressed << 8) | key);
65
+ key_write = (key_write + 1) % KEYQUEUE_SIZE;
66
+ }
67
+
68
+ void DG_Init(void)
69
+ {
70
+ if (!getenv("XDG_RUNTIME_DIR") || !*getenv("XDG_RUNTIME_DIR")) {
71
+ char dir[64];
72
+ snprintf(dir, sizeof dir, "/run/user/%d", (int)getuid());
73
+ setenv("XDG_RUNTIME_DIR", dir, 1);
74
+ }
75
+ SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "0"); /* the window surface is the Wayland driver's own, not a renderer's texture */
76
+ if (!SDL_Init(SDL_INIT_VIDEO)) { fprintf(stderr, "doom: %s (is wlcomp running?)\n", SDL_GetError()); exit(1); }
77
+ }
78
+
79
+ /* The window waits for the first frame: the engine reads the whole WAD before it draws, and a window that is not
80
+ * answering the compositor for that long is not one it keeps. */
81
+ static void make_window(void)
82
+ {
83
+ window = SDL_CreateWindow("DOOM", DOOMGENERIC_RESX, DOOMGENERIC_RESY, SDL_WINDOW_RESIZABLE);
84
+ if (!window) { fprintf(stderr, "doom: %s\n", SDL_GetError()); exit(1); }
85
+ frame = SDL_CreateSurfaceFrom(DOOMGENERIC_RESX, DOOMGENERIC_RESY, SDL_PIXELFORMAT_XRGB8888, DG_ScreenBuffer, DOOMGENERIC_RESX * 4);
86
+ if (!frame) { fprintf(stderr, "doom: %s\n", SDL_GetError()); exit(1); }
87
+ }
88
+
89
+ void DG_DrawFrame(void)
90
+ {
91
+ if (!window) make_window();
92
+ SDL_Event e;
93
+ while (SDL_PollEvent(&e)) {
94
+ if (e.type == SDL_EVENT_QUIT || e.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED) exit(0);
95
+ if (e.type == SDL_EVENT_KEY_DOWN && !e.key.repeat) push_key(1, e.key.key);
96
+ if (e.type == SDL_EVENT_KEY_UP) push_key(0, e.key.key);
97
+ }
98
+ SDL_Surface *screen = SDL_GetWindowSurface(window);
99
+ if (!screen) { fprintf(stderr, "doom: no window surface: %s\n", SDL_GetError()); return; }
100
+ SDL_BlitSurfaceScaled(frame, NULL, screen, NULL, SDL_SCALEMODE_NEAREST);
101
+ SDL_UpdateWindowSurface(window);
102
+ }
103
+
104
+ void DG_SleepMs(uint32_t ms) { SDL_Delay(ms); }
105
+ uint32_t DG_GetTicksMs(void) { return (uint32_t)SDL_GetTicks(); }
106
+
107
+ int DG_GetKey(int *pressed, unsigned char *key)
108
+ {
109
+ if (key_read == key_write) return 0;
110
+ unsigned short data = key_queue[key_read];
111
+ key_read = (key_read + 1) % KEYQUEUE_SIZE;
112
+ *pressed = data >> 8;
113
+ *key = data & 0xff;
114
+ return 1;
115
+ }
116
+
117
+ void DG_SetWindowTitle(const char *title) { if (window) SDL_SetWindowTitle(window, title); }
118
+
119
+ /* The IWAD names the engine tries, in its order */
120
+ static const char *const iwad_names[] = { "doom2.wad", "plutonia.wad", "tnt.wad", "doom.wad", "doom1.wad", "chex.wad", "hacx.wad", "freedm.wad", "freedoom2.wad", "freedoom1.wad", NULL };
121
+
122
+ static int readable(const char *path) { return access(path, R_OK) == 0; }
123
+
124
+ /* The first IWAD in `dir` (a directory), in the engine's order, in a malloc'd path; NULL if none */
125
+ static char *iwad_in(const char *dir)
126
+ {
127
+ for (int i = 0; iwad_names[i]; i++) {
128
+ size_t n = strlen(dir) + strlen(iwad_names[i]) + 2;
129
+ char *path = malloc(n);
130
+ if (!path) return NULL;
131
+ snprintf(path, n, "%s/%s", dir, iwad_names[i]);
132
+ if (readable(path)) return path;
133
+ free(path);
134
+ }
135
+ return NULL;
136
+ }
137
+
138
+ /* Where an IWAD is when -iwad was not given and the current directory has none: DOOMWADDIR (a directory, or the file
139
+ * itself), the directories of DOOMWADPATH, then the system directories. NULL to leave it to the engine. */
140
+ static char *find_iwad(void)
141
+ {
142
+ for (int i = 0; iwad_names[i]; i++) if (readable(iwad_names[i])) return NULL;
143
+ const char *dir = getenv("DOOMWADDIR");
144
+ if (dir && *dir) {
145
+ if (readable(dir) && access(dir, X_OK) != 0) return strdup(dir);
146
+ char *found = iwad_in(dir);
147
+ if (found) return found;
148
+ }
149
+ const char *list = getenv("DOOMWADPATH");
150
+ while (list && *list) {
151
+ size_t n = strcspn(list, ":");
152
+ char *entry = strndup(list, n);
153
+ if (entry && *entry) {
154
+ char *found = readable(entry) && access(entry, X_OK) != 0 ? strdup(entry) : iwad_in(entry);
155
+ if (found) { free(entry); return found; }
156
+ }
157
+ free(entry);
158
+ list += n + (list[n] == ':');
159
+ }
160
+ static const char *const system_dirs[] = { "/usr/share/games/doom", "/usr/local/share/games/doom", NULL };
161
+ for (int i = 0; system_dirs[i]; i++) {
162
+ char *found = iwad_in(system_dirs[i]);
163
+ if (found) return found;
164
+ }
165
+ return NULL;
166
+ }
167
+
168
+ int main(int argc, char **argv)
169
+ {
170
+ int given = 0;
171
+ for (int i = 1; i < argc; i++) if (!strcmp(argv[i], "-iwad")) given = 1;
172
+ if (!given) {
173
+ char *iwad = find_iwad();
174
+ if (iwad) {
175
+ char **extended = malloc(sizeof(char *) * (argc + 3));
176
+ if (extended) {
177
+ memcpy(extended, argv, sizeof(char *) * argc);
178
+ extended[argc] = "-iwad";
179
+ extended[argc + 1] = iwad;
180
+ extended[argc + 2] = NULL;
181
+ argv = extended;
182
+ argc += 2;
183
+ }
184
+ }
185
+ }
186
+ doomgeneric_Create(argc, argv);
187
+ for (;;) doomgeneric_Tick();
188
+ }
@@ -0,0 +1,156 @@
1
+ /* SPDX-License-Identifier: GPL-2.0-or-later
2
+ * Sound effects for doom on ecmaOS: a small mixer behind doomgeneric's sound_module_t, played through an SDL 3 audio stream
3
+ * (SDL_mixer is not available). Doom's sounds are 8-bit mono lumps; each channel steps through its lump at the lump's rate,
4
+ * panned and scaled by the engine's volume and separation, and the sum goes to the stream as 16-bit stereo. The engine calls
5
+ * Update about 35 times a second, which keeps a few tics of audio queued. There is no music yet: its module does nothing. */
6
+ #include <SDL3/SDL.h>
7
+ #include <stdlib.h>
8
+ #include <string.h>
9
+ #include "doomtype.h"
10
+ #include "deh_str.h"
11
+ #include "i_sound.h"
12
+ #include "m_misc.h"
13
+ #include "w_wad.h"
14
+ #include "z_zone.h"
15
+
16
+ #define RATE 22050
17
+ #define CHANNELS 16
18
+ #define QUEUE_FRAMES (RATE / 35 * 4) /* about four tics queued */
19
+
20
+ int use_libsamplerate = 0;
21
+ float libsamplerate_scale = 0.65f;
22
+
23
+ typedef struct { const byte *data; int length, rate; } sample_t;
24
+ typedef struct { const sample_t *sample; unsigned pos, step; int left, right; } voice_t; /* pos and step are 16.16 */
25
+
26
+ static SDL_AudioStream *stream;
27
+ static voice_t voices[CHANNELS];
28
+ static boolean prefix = true;
29
+
30
+ static void pan(voice_t *v, int vol, int sep)
31
+ {
32
+ int l = (254 - sep) * vol / 127, r = sep * vol / 127; /* 0..127 for vol at 127 and sep in the middle */
33
+ v->left = l > 127 ? 127 : l < 0 ? 0 : l;
34
+ v->right = r > 127 ? 127 : r < 0 ? 0 : r;
35
+ }
36
+
37
+ static boolean snd_init(boolean use_sfx_prefix)
38
+ {
39
+ prefix = use_sfx_prefix;
40
+ if (!SDL_InitSubSystem(SDL_INIT_AUDIO)) return false;
41
+ SDL_AudioSpec spec = { SDL_AUDIO_S16, 2, RATE };
42
+ stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, NULL, NULL);
43
+ if (!stream) return false;
44
+ SDL_ResumeAudioStreamDevice(stream);
45
+ return true;
46
+ }
47
+
48
+ static void snd_shutdown(void)
49
+ {
50
+ if (stream) SDL_DestroyAudioStream(stream);
51
+ stream = NULL;
52
+ }
53
+
54
+ static int snd_lump(sfxinfo_t *sfx)
55
+ {
56
+ char name[9];
57
+ if (sfx->link) sfx = sfx->link;
58
+ if (prefix) M_snprintf(name, sizeof name, "ds%s", DEH_String(sfx->name));
59
+ else M_StringCopy(name, DEH_String(sfx->name), sizeof name);
60
+ return W_GetNumForName(name);
61
+ }
62
+
63
+ /* the lump is a 8 byte header (3, 0, rate, length) around the samples; DMX leaves out 16 bytes at each end */
64
+ static const sample_t *load(sfxinfo_t *sfx)
65
+ {
66
+ if (sfx->driver_data) return sfx->driver_data;
67
+ int lump = sfx->lumpnum;
68
+ const byte *d = W_CacheLumpNum(lump, PU_STATIC);
69
+ unsigned size = W_LumpLength(lump);
70
+ if (size < 8 || d[0] != 3 || d[1] != 0) return NULL;
71
+ unsigned length = d[4] | d[5] << 8 | d[6] << 16 | (unsigned)d[7] << 24;
72
+ if (length > size - 8 || length <= 48) return NULL;
73
+ sample_t *s = malloc(sizeof *s);
74
+ s->data = d + 8 + 16;
75
+ s->length = length - 32;
76
+ s->rate = d[2] | d[3] << 8;
77
+ if (s->rate <= 0) s->rate = 11025;
78
+ sfx->driver_data = s;
79
+ return s;
80
+ }
81
+
82
+ static int snd_start(sfxinfo_t *sfx, int channel, int vol, int sep)
83
+ {
84
+ if (!stream || channel < 0 || channel >= CHANNELS) return -1;
85
+ const sample_t *s = load(sfx);
86
+ if (!s) return -1;
87
+ voice_t *v = &voices[channel];
88
+ v->sample = NULL;
89
+ v->pos = 0;
90
+ v->step = (unsigned)((unsigned long long)s->rate * 65536 / RATE);
91
+ pan(v, vol, sep);
92
+ v->sample = s;
93
+ return channel;
94
+ }
95
+
96
+ static void snd_update_params(int channel, int vol, int sep)
97
+ {
98
+ if (channel >= 0 && channel < CHANNELS) pan(&voices[channel], vol, sep);
99
+ }
100
+
101
+ static void snd_stop(int channel)
102
+ {
103
+ if (channel >= 0 && channel < CHANNELS) voices[channel].sample = NULL;
104
+ }
105
+
106
+ static boolean snd_playing(int channel)
107
+ {
108
+ return channel >= 0 && channel < CHANNELS && voices[channel].sample != NULL;
109
+ }
110
+
111
+ static void snd_update(void)
112
+ {
113
+ if (!stream) return;
114
+ int queued = SDL_GetAudioStreamQueued(stream) / 4;
115
+ while (queued < QUEUE_FRAMES) {
116
+ Sint16 out[2 * 256];
117
+ int n = QUEUE_FRAMES - queued < 256 ? QUEUE_FRAMES - queued : 256;
118
+ for (int i = 0; i < n; i++) {
119
+ int l = 0, r = 0;
120
+ for (int c = 0; c < CHANNELS; c++) {
121
+ voice_t *v = &voices[c];
122
+ if (!v->sample) continue;
123
+ unsigned at = v->pos >> 16;
124
+ if ((int)at >= v->sample->length) { v->sample = NULL; continue; }
125
+ int x = ((int)v->sample->data[at] - 128) << 8; /* 8-bit unsigned to 16-bit signed */
126
+ l += x * v->left / 127 / 2; /* each voice at most half scale, so a couple together do not clip at once */
127
+ r += x * v->right / 127 / 2;
128
+ v->pos += v->step;
129
+ }
130
+ out[2 * i] = l > 32767 ? 32767 : l < -32768 ? -32768 : l;
131
+ out[2 * i + 1] = r > 32767 ? 32767 : r < -32768 ? -32768 : r;
132
+ }
133
+ SDL_PutAudioStreamData(stream, out, n * 4);
134
+ queued += n;
135
+ }
136
+ }
137
+
138
+ static snddevice_t devices[] = { SNDDEVICE_SB, SNDDEVICE_PAS, SNDDEVICE_GUS, SNDDEVICE_WAVEBLASTER, SNDDEVICE_SOUNDCANVAS, SNDDEVICE_AWE32 };
139
+
140
+ sound_module_t DG_sound_module = {
141
+ devices, sizeof devices / sizeof devices[0],
142
+ snd_init, snd_shutdown, snd_lump, snd_update, snd_update_params, snd_start, snd_stop, snd_playing, NULL,
143
+ };
144
+
145
+ static boolean mus_init(void) { return true; }
146
+ static void mus_none(void) {}
147
+ static void mus_volume(int v) { (void)v; }
148
+ static void *mus_register(void *d, int l) { (void)d; (void)l; return NULL; }
149
+ static void mus_unregister(void *h) { (void)h; }
150
+ static void mus_play(void *h, boolean loop) { (void)h; (void)loop; }
151
+ static boolean mus_playing(void) { return false; }
152
+
153
+ music_module_t DG_music_module = {
154
+ devices, sizeof devices / sizeof devices[0],
155
+ mus_init, mus_none, mus_volume, mus_none, mus_none, mus_register, mus_unregister, mus_play, mus_none, mus_playing, mus_none,
156
+ };
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env bash
2
+ # SPDX-License-Identifier: BSD-3-Clause
3
+ # Rebuilds programs/doom-runtime.tar.gz: the Freedoom game data (BSD-3-Clause) that doom plays by default, installed
4
+ # as /usr/share/games/doom/freedoom1.wad (a place the engine looks for a WAD) with Freedoom's license and credits in
5
+ # /usr/share/licenses/freedoom. The archive is the one pinned in programs/manifest.json; the WAD is not changed.
6
+ set -euo pipefail
7
+ HERE=$(cd "$(dirname "$0")" && pwd)
8
+ SOURCES="$HERE/../../scripts/sources.mjs"
9
+ ARCHIVE=$(node "$SOURCES" fetch doom freedoom)
10
+ VERSION=$(node "$SOURCES" version doom freedoom)
11
+ WORK=$(mktemp -d); trap 'rm -rf "$WORK"' EXIT
12
+ unzip -q "$ARCHIVE" -d "$WORK/src"
13
+ ROOT=$WORK/root
14
+ mkdir -p "$ROOT/usr/share/games/doom" "$ROOT/usr/share/licenses/freedoom"
15
+ cp "$WORK/src/freedoom-$VERSION/freedoom1.wad" "$ROOT/usr/share/games/doom/"
16
+ cp "$WORK/src/freedoom-$VERSION/COPYING.txt" "$WORK/src/freedoom-$VERSION/CREDITS.txt" "$ROOT/usr/share/licenses/freedoom/"
17
+ tar --owner=0 --group=0 --numeric-owner --sort=name --mtime=@0 -C "$ROOT" -cf - . | gzip -9n > "$HERE/../../programs/doom-runtime.tar.gz"
18
+ ls -l "$HERE/../../programs/doom-runtime.tar.gz"
package/package.json CHANGED
@@ -1,6 +1,57 @@
1
1
  {
2
2
  "name": "@ecmaos-apps/doom-src",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-ecmaos.2",
4
+ "description": "The source of @ecmaos-apps/doom: doom, id Software's Doom (doomgeneric) in a window on SDL 3, with the Freedoom game data (needs wlcomp running)",
5
+ "license": "GPL-2.0-or-later AND Zlib AND MIT AND BSD-3-Clause",
6
+ "homepage": "https://github.com/ozkl/doomgeneric",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/ecmaos/ecmaos",
10
+ "directory": "core/utils-copyleft"
11
+ },
12
+ "keywords": [
13
+ "ecmaos",
14
+ "source",
15
+ "doom"
16
+ ],
17
+ "files": [
18
+ "sources",
19
+ "build",
20
+ "toolchain",
21
+ "share",
22
+ "README.md"
23
+ ],
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "ecmaos": {
28
+ "sourceOf": "@ecmaos-apps/doom@0.1.0-ecmaos.2",
29
+ "archives": {
30
+ "doomgeneric-e257a09527062bfb986b6e5e0780839b6cbd5b71.tar.gz": {
31
+ "sha256": "26f8f60daa6c6e4d3c01e5eac9fb700d592dede803d13ac848154ff356b2a2e7",
32
+ "url": "https://github.com/ozkl/doomgeneric/archive/e257a09527062bfb986b6e5e0780839b6cbd5b71.tar.gz",
33
+ "license": "GPL-2.0-or-later"
34
+ },
35
+ "SDL3-3.4.18.tar.gz": {
36
+ "sha256": "9c75cf16330322c217dedd2e0609f1124f1b54b8633e763467b4684d0f4334a3",
37
+ "url": "https://github.com/libsdl-org/SDL/releases/download/release-3.4.18/SDL3-3.4.18.tar.gz",
38
+ "license": "Zlib"
39
+ },
40
+ "wayland-1.26.0.tar.xz": {
41
+ "sha256": "64176eaa46e4969903e286f8e5ef8331affc17fdf03ac9b58381d2b23162b7a3",
42
+ "url": "https://gitlab.freedesktop.org/wayland/wayland/-/releases/1.26.0/downloads/wayland-1.26.0.tar.xz",
43
+ "license": "MIT"
44
+ },
45
+ "libxkbcommon-xkbcommon-1.13.2.tar.gz": {
46
+ "sha256": "acc4d5f7c3cbba5f9f8d08d8bdbeede84ecede46792f47929aa9321873385528",
47
+ "url": "https://github.com/xkbcommon/libxkbcommon/archive/refs/tags/xkbcommon-1.13.2.tar.gz",
48
+ "license": "MIT"
49
+ },
50
+ "freedoom-0.13.0.zip": {
51
+ "sha256": "3f9b264f3e3ce503b4fb7f6bdcb1f419d93c7b546f4df3e874dd878db9688f59",
52
+ "url": "https://github.com/freedoom/freedoom/releases/download/v0.13.0/freedoom-0.13.0.zip",
53
+ "license": "BSD-3-Clause"
54
+ }
55
+ }
56
+ }
57
+ }
@@ -0,0 +1,48 @@
1
+ doom 0.1.0 (GPL-2.0-or-later AND Zlib AND MIT AND BSD-3-Clause)
2
+
3
+ programs/doom.wasm is built from the upstream source below, with the changes listed under it. Together they
4
+ are the complete corresponding source of the binary; this is the offer of it.
5
+
6
+ Upstream source
7
+ doomgeneric-e257a09527062bfb986b6e5e0780839b6cbd5b71.tar.gz (doomgeneric e257a09527062bfb986b6e5e0780839b6cbd5b71, GPL-2.0-or-later)
8
+ sha256 26f8f60daa6c6e4d3c01e5eac9fb700d592dede803d13ac848154ff356b2a2e7
9
+ from https://github.com/ozkl/doomgeneric/archive/e257a09527062bfb986b6e5e0780839b6cbd5b71.tar.gz
10
+ SDL3-3.4.18.tar.gz (sdl 3.4.18, Zlib)
11
+ sha256 9c75cf16330322c217dedd2e0609f1124f1b54b8633e763467b4684d0f4334a3
12
+ from https://github.com/libsdl-org/SDL/releases/download/release-3.4.18/SDL3-3.4.18.tar.gz
13
+ wayland-1.26.0.tar.xz (wayland 1.26.0, MIT)
14
+ sha256 64176eaa46e4969903e286f8e5ef8331affc17fdf03ac9b58381d2b23162b7a3
15
+ from https://gitlab.freedesktop.org/wayland/wayland/-/releases/1.26.0/downloads/wayland-1.26.0.tar.xz
16
+ libxkbcommon-xkbcommon-1.13.2.tar.gz (xkbcommon 1.13.2, MIT)
17
+ sha256 acc4d5f7c3cbba5f9f8d08d8bdbeede84ecede46792f47929aa9321873385528
18
+ from https://github.com/xkbcommon/libxkbcommon/archive/refs/tags/xkbcommon-1.13.2.tar.gz
19
+ freedoom-0.13.0.zip (freedoom 0.13.0, BSD-3-Clause)
20
+ sha256 3f9b264f3e3ce503b4fb7f6bdcb1f419d93c7b546f4df3e874dd878db9688f59
21
+ from https://github.com/freedoom/freedoom/releases/download/v0.13.0/freedoom-0.13.0.zip
22
+
23
+ Changes and build scripts (in wasm/ of the package, and in the repository under core/utils-copyleft/wasm/)
24
+ wasm/doom/build.sh
25
+ the build: compiles the doomgeneric engine without its other platform layers and its SDL_mixer sound and music modules
26
+ wasm/doom/doomecma.c
27
+ new file, linked into the program: the platform layer, which draws the engine's frames into a window on SDL 3 and turns SDL key events into Doom keys, and looks for a WAD in DOOMWADDIR, DOOMWADPATH and /usr/share/games/doom when -iwad is not given and the current directory has none
28
+ wasm/doom/doomsound.c
29
+ new file, linked into the program: the engine's sound module, a mixer that plays the sound effect lumps through an SDL 3 audio stream
30
+ core/utils/wasm/lib/sdl.sh (in the repository; wasm/lib/sdl.sh and wasm/lib/sdl-gl/ in the npm package @ecmaos/coreutils)
31
+ builds SDL as a static library for a Unix program on Wayland: a software window surface for its Wayland driver, audio and joystick drivers of its own, and the other changes its header lists
32
+ core/utils/wasm/lib/wayland.sh (in the repository; wasm/lib/wayland.sh in the npm package @ecmaos/coreutils)
33
+ builds libwayland-client, -cursor and -egl as static libraries, with listener calls made without libffi
34
+ core/utils/wasm/lib/xkbcommon.sh (in the repository; wasm/lib/xkbcommon.sh in the npm package @ecmaos/coreutils)
35
+ builds libxkbcommon as a static library without meson; a missing Compose table is logged at debug level
36
+ wasm/doom/runtime.sh
37
+ packs freedoom1.wad from the Freedoom release into programs/doom-runtime.tar.gz, which installs it as /usr/share/games/doom/freedoom1.wad, where the engine looks for a WAD; the WAD itself is not changed
38
+
39
+ The changes were made in 2026; the repository history dates each one.
40
+
41
+ Toolchain: WALI's musl and the LLVM runtimes (musl 243ec00c3ffb910375db487d7eb24ea76d1e2c9f, LLVM 23.1.3), with the patches in utils/wali/patches;
42
+ utils/wali-version in the repository pins them, and utils/wali/build-sysroot.sh builds them. Its compiler then
43
+ puts a signal check in each loop of the linked program (utils/wali/signal-checks.mjs).
44
+
45
+ Where to get it
46
+ - /sources/doomgeneric-e257a09527062bfb986b6e5e0780839b6cbd5b71.tar.gz on the site that served this program, and the other archives listed above in the same place
47
+ - the sources/ and wasm/ directories of the npm package @ecmaos/coreutils-copyleft, in the version that holds this file
48
+ - https://github.com/ecmaos/ecmaos (core/utils-copyleft), at the tag of the release that holds this file
Binary file
Binary file
Binary file
@@ -0,0 +1 @@
1
+ 6.0.9
@@ -0,0 +1,3 @@
1
+ # The Rust toolchain that builds the Rust programs for WALI (utils/wali/rust.sh): wasm32-wali-linux-musl is a tier-3
2
+ # target, so it is a pinned nightly with rust-src, whose std is built with the program (-Z build-std).
3
+ RUST_TOOLCHAIN=nightly-2026-10-25