Skip to content

Commit 586a320

Browse files
authored
Merge pull request #488 from Interlisp/incorporate-wasm-changes
Incorporate wasm changes
2 parents b666b1b + e93e3c8 commit 586a320

File tree

7 files changed

+86
-0
lines changed

7 files changed

+86
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ cmake-build-*/**
1919
*.x86_64-x/**
2020
*.x86_64-sdl/**
2121
*.x86_64/**
22+
*.wasm/**
23+
*.wasm-wasm/**
2224
*.armv7l-x/**
2325
*.armv7l/**
2426
*.aarch64-x/**

bin/makefile-emscripten.wasm-wasm

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Options for Emscripten, WASM and SDL
2+
3+
CC = emcc $(CLANG_CFLAGS)
4+
5+
XFILES = $(OBJECTDIR)sdl.o
6+
7+
XFLAGS = -DSDL -sUSE_SDL=2
8+
9+
# OPTFLAGS is normally -O2.
10+
OPTFLAGS = -O2
11+
DFLAGS = $(XFLAGS) -DRELEASE=351 -DMAIKO_ENABLE_NETHUB
12+
13+
MEDLEY?=../../medley
14+
SYSOUT?=$(MEDLEY)/loadups/full.sysout
15+
16+
LD = emcc
17+
LDFLAGS = -sUSE_SDL=2 -sASYNCIFY -sALLOW_MEMORY_GROWTH -sEXIT_RUNTIME=1 \
18+
--preload-file $(SYSOUT)@medley/loadups/full.sysout \
19+
--preload-file $(MEDLEY)/loadups/whereis.hash@medley/loadups/whereis.hash \
20+
--preload-file $(MEDLEY)/greetfiles/MEDLEYDIR-INIT.LCOM@usr/local/lde/site-init.lisp \
21+
--preload-file $(MEDLEY)/docs/@medley/docs \
22+
--preload-file $(MEDLEY)/doctools/@medley/doctools \
23+
--preload-file $(MEDLEY)/greetfiles/@medley/greetfiles \
24+
--preload-file $(MEDLEY)/internal/@medley/internal \
25+
--preload-file $(MEDLEY)/sources/@medley/sources \
26+
--preload-file $(MEDLEY)/library/@medley/library \
27+
--preload-file $(MEDLEY)/lispusers/@medley/lispusers \
28+
--preload-file $(MEDLEY)/fonts/@medley/fonts
29+
30+
LDELDFLAGS =
31+
32+
OBJECTDIR = ../$(RELEASENAME)/
33+
34+
default : ../$(OSARCHNAME)/ldesdl.js

bin/makeright

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ case "$display" in
7474
sdl) releasename=${osversion}.${architecture}-${display}
7575
ldename=ldesdl
7676
;;
77+
wasm) osversion=emscripten
78+
architecture=wasm
79+
releasename=${osversion}.${architecture}-${display}
80+
ldename=ldesdl.js
81+
;;
7782
*) echo "display-option: $display is not supported."
7883
exit
7984
;;

inc/maiko/platform.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@
8383
# define MAIKO_OS_DETECTED 1
8484
#endif
8585

86+
#ifdef __EMSCRIPTEN__
87+
# define MAIKO_OS_LINUX 1
88+
# define MAIKO_OS_EMSCRIPTEN 1
89+
# define MAIKO_OS_NAME "Emscripten"
90+
# define MAIKO_EMULATE_TIMER_INTERRUPTS 1
91+
# define MAIKO_EMULATE_ASYNC_INTERRUPTS 1
92+
# define MAIKO_OS_UNIX_LIKE 1
93+
# define MAIKO_OS_DETECTED
94+
# define MAIKO_ARCH_NAME "WebAssembly"
95+
# define MAIKO_ARCH_WORD_BITS 32
96+
# define MAIKO_ARCH_DETECTED 1
97+
#endif
98+
8699
/* __x86_64__: GNU C, __x86_64: Sun Studio, _M_AMD64: Visual Studio */
87100
#if defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64)
88101
# define MAIKO_ARCH_X86_64 1

src/lde.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!doctype html>
2+
<!-- Based on https://github.com/timhutton/sdl-canvas-wasm/blob/main/index.html -->
3+
<!-- html to set up WebAssembly module for Medley running in a browser -->
4+
<html>
5+
<head>
6+
<meta charset="utf-8">
7+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
8+
</head>
9+
<body>
10+
<div style="text-align: center;">
11+
<canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas>
12+
</div>
13+
<script type="text/javascript">
14+
var width = 32*Math.trunc(Math.min(Math.max(window.innerWidth, 512), 1664)/32);
15+
var height = Math.min(Math.max(window.innerHeight, 512), 1260);
16+
var Module = {
17+
preRun: [ function() {ENV.MEDLEYDIR = "{DSK}<medley>";} ],
18+
arguments: ["medley/loadups/full.sysout","-sc", width+"x"+height, "-nh-host", "127.0.0.1"],
19+
canvas: (function() { return document.getElementById('canvas'); })()
20+
};
21+
</script>
22+
<script src="ldesdl.js"></script>
23+
</body>
24+
</html>

src/timer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ void subr_settime(LispPTR args[])
288288
dosday.year = uxtime.tm_year;
289289
dosday.dayofweek = uxtime.tm_wday;
290290
_dos_setdate(&dosday);
291+
#elif defined(MAIKO_OS_EMSCRIPTEN)
292+
(void)args[0];
291293
#else
292294
struct timeval timev;
293295
timev.tv_sec = *((int *)NativeAligned4FromLAddr(args[0])) - UNIX_ALTO_TIME_DIFF;

src/xc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
/* */
2121
/************************************************************************/
2222

23+
#ifdef MAIKO_OS_EMSCRIPTEN
24+
#include <emscripten.h>
25+
#endif
2326
#include <signal.h>
2427
#include <stdint.h>
2528
#include <stdio.h>
@@ -286,6 +289,9 @@ op_ufn : {
286289
Irq_Stk_End = 0;
287290
#if defined(MAIKO_EMULATE_ASYNC_INTERRUPTS)
288291
IO_Signalled = TRUE;
292+
#endif
293+
#ifdef MAIKO_OS_EMSCRIPTEN
294+
emscripten_sleep(1);
289295
#endif
290296
pseudoTimerAsyncCountdown = insnsCountdownForTimerAsyncEmulation;
291297
}

0 commit comments

Comments
 (0)