Skip to content

Commit

Permalink
Merge pull request #12 from ktock/emscriptendelay
Browse files Browse the repository at this point in the history
emscripten: enable loop delay
  • Loading branch information
ktock authored Mar 9, 2023
2 parents 0214e72 + 9dbfffd commit feca9ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ COPY --link --from=assets /patches/tinyemu /tinyemu
WORKDIR /tinyemu
RUN make -j $(nproc) -f Makefile \
CONFIG_FS_NET= CONFIG_SDL= CONFIG_INT128= CONFIG_X86EMU= CONFIG_SLIRP= \
CC="emcc --embed-file /pack -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=${EMSCRIPTEN_INITIAL_MEMORY} -UEMSCRIPTEN -sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1" && \
CC="emcc --embed-file /pack -s WASM=1 -s ASYNCIFY=1 -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=${EMSCRIPTEN_INITIAL_MEMORY} -UEMSCRIPTEN -DON_BROWSER -sNO_EXIT_RUNTIME=1 -sFORCE_FILESYSTEM=1" && \
mkdir -p /out/ && mv temu /out/container.js && mv temu.wasm /out/

FROM scratch AS js
Expand Down
12 changes: 12 additions & 0 deletions patches/tinyemu/temu.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
#include "wasi.h"
#endif

#ifdef ON_BROWSER
#include <emscripten.h>
#endif

#ifndef _WIN32

typedef struct {
Expand Down Expand Up @@ -620,6 +624,11 @@ void virt_machine_run(VirtMachine *m, int enable_stdin)
#endif
tv.tv_sec = delay / 1000;
tv.tv_usec = (delay % 1000) * 1000;
#ifdef ON_BROWSER
// no timeout; TODO: remove this when sleep supports timeout
tv.tv_sec = 0;
tv.tv_usec = 0;
#endif
if (enable_stdin && init_done)
ret = select(fd_max + 1, &rfds, &wfds, NULL, &tv);
if (m->net) {
Expand All @@ -645,6 +654,9 @@ void virt_machine_run(VirtMachine *m, int enable_stdin)
sdl_refresh(m);
#endif

#ifdef ON_BROWSER
emscripten_sleep(delay);
#endif
virt_machine_interp(m, MAX_EXEC_CYCLE);
}

Expand Down

0 comments on commit feca9ee

Please sign in to comment.