Browse Source

[web] preload refactors

kvm
asie 10 months ago
parent
commit
d353bb15ac
5 changed files with 77 additions and 58 deletions
  1. BIN
      web/ascii.png
  2. 11
    4
      web/index.html
  3. 16
    12
      web/zeta.js
  4. 38
    27
      web/zeta_preload.js
  5. 12
    15
      zeta_wasm.sh

BIN
web/ascii.png View File


+ 11
- 4
web/index.html View File

@@ -4,14 +4,19 @@
<meta charset=utf-8>
<style type="text/css">
* { border: 0; margin: 0; padding: 0; }
canvas { width: 100%; height: 100%; display: block; }
#zeta_canvas { width: 100%; height: 100%; display: block; }
</style>
</head>
<body>
<canvas id="zzt_canvas" width="640" height="350"></canvas>
<script type="text/javascript" src="./zzt_preload.js"></script>
<canvas id="zeta_canvas" width="640" height="350"></canvas>
<script type="text/javascript" src="./zeta_preload.js"></script>
<script type="text/javascript">
zzt_emu_load("./", {
Zeta({
render: {
canvas: document.getElementById("zeta_canvas")
},
dev: true,
path: "./",
files: [
["zzt.zip", function(f) {
let fl = f.toLowerCase();
@@ -20,6 +25,8 @@ zzt_emu_load("./", {
"my_game.zip"
],
arg: "MY_GAME.ZZT"
}, function(zeta) {

});
</script>
</body>

+ 16
- 12
web/zeta.js View File

@@ -17,11 +17,8 @@
* along with Zeta. If not, see <http://www.gnu.org/licenses/>.
*/

var canvas = document.getElementById('zzt_canvas');
var ctx = canvas.getContext('2d', {alpha: false});
ctx.imageSmoothingEnabled = false;

var audio, emu, render;
var canvas, ctx, audio, emu, render;
var zeta_options = {};

var date_s = Date.now();
var time_ms = function() { return Date.now() - date_s; }
@@ -273,14 +270,17 @@ var vfs_done = function() {
}
}

video_blink = !vfs.contains("BLINKX.COM");
if (!zeta_options.render.hasOwnProperty("blink")) {
zeta_options.render.blink = !vfs.contains("BLINKX.COM");
}

render = ZetaRender.toCanvas(zeta_options.render.canvas, zeta_options.render);
vfs_arg = (vfs_arg || "").toUpperCase();

draw_progress(1.0);
ZetaNative().then(function(c) {
emu = c;
audio = ZetaAudio.createStreamBased(emu);
audio = ZetaAudio.createOscillatorBased();

var buffer = emu._malloc(vfs_arg.length + 1);
var heap = new Uint8Array(emu.HEAPU8.buffer, buffer, vfs_arg.length + 1);
@@ -318,8 +318,6 @@ function speakerg_off() {
if (audio != undefined) audio.off();
}

canvas.contentEditable = true;

/* var check_modifiers = function(event) {
if (event.shiftKey) emu._zzt_kmod_set(0x01); else emu._zzt_kmod_clear(0x01);
if (event.ctrlKey) emu._zzt_kmod_set(0x04); else emu._zzt_kmod_clear(0x04);
@@ -463,9 +461,13 @@ var attach_mouse_handler = function(o) {
});
}

function zzt_emu_create(options) {
// TODO: hook blink, charset override
render = ZetaRender.toCanvas(canvas, {});
function zeta_emu_create(options) {
zeta_options = options;
canvas = options.render.canvas;
canvas.contentEditable = true;
ctx = canvas.getContext('2d', {alpha: false});
ctx.imageSmoothingEnabled = false;

attach_mouse_handler(canvas);

vfs_files = options.files;
@@ -485,4 +487,6 @@ function zzt_emu_create(options) {
}, vfs_on_loaded);
}
}

return {};
}

+ 38
- 27
web/zeta_preload.js View File

@@ -17,43 +17,54 @@
* along with Zeta. If not, see <http://www.gnu.org/licenses/>.
*/

var canvas = null;
var ctx = null;
Zeta = function(options, callback) {
var options = options;
if (!options.render) throw "Missing option: render!";
if (!options.render.canvas) throw "Missing option: render.canvas!";
if (!options.path) throw "Missing option: path!";
if (!options.files) throw "Missing option: files!";

var scripts_array = [];
var zzt_opts = {};
var script_ldr = function() {
if (scripts_array.length == 0) {
zzt_emu_create(zzt_opts);
return;
var scripts_array = [];
var script_ldr = function() {
if (scripts_array.length == 0) {
callback(zeta_emu_create(options));
} else {
var scrSrc = scripts_array.shift();
var scr = document.createElement("script");
scr.onload = script_ldr;
scr.src = scrSrc;
document.body.appendChild(scr);
}
}

var s = scripts_array.shift();
var scr = document.createElement("script");
scr.onload = script_ldr;
scr.src = s;
document.body.appendChild(scr);
}

function zzt_emu_load(path, options) {
var canvas = document.getElementById('zzt_canvas');
var canvas = options.render.canvas;
canvas.tabindex=1;

var ctx = canvas.getContext('2d', {alpha: false});

zzt_opts = options;
zzt_opts.path = path;

var imgload = new Image();
imgload.onload = function() {
ctx.imageSmoothingEnabled = false;
ctx.drawImage(imgload,0,0,320,175,(canvas.width - 640)/2,(canvas.height - 350)/2,640,350);
};
imgload.src = path+"loading.png";
scripts_array = [
path+"uzip.min.js",
path+"zeta_native.js",
path+"zeta.min.js"
];
imgload.src = options.path+"loading.png";

if (options.dev) {
scripts_array = [
options.path+"uzip.min.js",
options.path+"zeta_native.js",
options.path+"zeta_vfs.js",
options.path+"zeta_render.js",
options.path+"zeta_audio.js",
options.path+"zeta_kbdmap.js",
options.path+"zeta.js"
];
} else {
scripts_array = [
options.path+"uzip.min.js",
options.path+"zeta_native.js",
options.path+"zeta.min.js"
];
}

script_ldr();
}

+ 12
- 15
zeta_wasm.sh View File

@@ -2,11 +2,11 @@
if [ ! -d build ]; then mkdir build; fi
if [ ! -d build/web ]; then mkdir build/web; fi

rm build/zeta86.js
rm build/zeta86.js.mem
rm build/zeta86.wasm
rm build/zeta86.wasm.map
rm build/zeta86.wast
rm build/zeta_native.js
rm build/zeta_native.js.mem
rm build/zeta_native.wasm
rm build/zeta_native.wasm.map
rm build/zeta_native.wast

xxd -i res/8x14.bin > res/8x14.c

@@ -14,22 +14,19 @@ emcc -O3 --js-library src/emscripten_glue.js \
-s ENVIRONMENT=web \
-s 'EXPORTED_FUNCTIONS=["_malloc"]' \
-s 'EXTRA_EXPORTED_RUNTIME_METHODS=["AsciiToString"]' \
-s WASM=1 -s MODULARIZE=1 -s 'EXPORT_NAME="Zeta"' \
-s WASM=1 -s MODULARIZE=1 -s 'EXPORT_NAME="ZetaNative"' \
-s ALLOW_MEMORY_GROWTH=0 -s ASSERTIONS=0 \
-s 'MALLOC="emmalloc"' -s NO_FILESYSTEM=1 \
-s TOTAL_MEMORY=4194304 -s TOTAL_STACK=262144 \
-s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE="[]" \
-DNO_MEMSET \
src/cpu.c src/zzt.c res/8x14.c
src/cpu.c src/zzt.c res/8x14.c src/audio_stream.c

mv a.out.js build/zeta86.js
mv a.out.js.mem build/zeta86.js.mem
mv a.out.wasm build/zeta86.wasm
mv a.out.wasm.map build/zeta86.wasm.map
mv a.out.wast build/zeta86.wast
sed -i -e "s/a\.out/zeta86/g" build/zeta86.js
mv a.out.js build/zeta_native.js
mv a.out.wasm build/zeta_native.wasm
sed -i -e "s/a\.out/zeta_native/g" build/zeta_native.js

rm build/web/*
cp web/* build/web/
cp build/zeta86.js build/web/
cp build/zeta86.wasm build/web/
cp build/zeta_native.js build/web/
cp build/zeta_native.wasm build/web/

Loading…
Cancel
Save