Browse Source

[web] preload refactors

master
asie 4 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 @@
4 4
 <meta charset=utf-8>
5 5
 <style type="text/css">
6 6
 * { border: 0; margin: 0; padding: 0; }
7
-canvas { width: 100%; height: 100%; display: block; }
7
+#zeta_canvas { width: 100%; height: 100%; display: block; }
8 8
 </style>
9 9
 </head>
10 10
 <body>
11
-<canvas id="zzt_canvas" width="640" height="350"></canvas>
12
-<script type="text/javascript" src="./zzt_preload.js"></script>
11
+<canvas id="zeta_canvas" width="640" height="350"></canvas>
12
+<script type="text/javascript" src="./zeta_preload.js"></script>
13 13
 <script type="text/javascript">
14
-zzt_emu_load("./", {
14
+Zeta({
15
+	render: {
16
+		canvas: document.getElementById("zeta_canvas")
17
+	},
18
+	dev: true,
19
+	path: "./",
15 20
 	files: [
16 21
 		["zzt.zip", function(f) {
17 22
 			let fl = f.toLowerCase();
@@ -20,6 +25,8 @@ zzt_emu_load("./", {
20 25
 		"my_game.zip"
21 26
 	],
22 27
 	arg: "MY_GAME.ZZT"
28
+}, function(zeta) {
29
+
23 30
 });
24 31
 </script>
25 32
 </body>

+ 16
- 12
web/zeta.js View File

@@ -17,11 +17,8 @@
17 17
  * along with Zeta.  If not, see <http://www.gnu.org/licenses/>.
18 18
  */
19 19
 
20
-var canvas = document.getElementById('zzt_canvas');
21
-var ctx = canvas.getContext('2d', {alpha: false});
22
-ctx.imageSmoothingEnabled = false;
23
-
24
-var audio, emu, render;
20
+var canvas, ctx, audio, emu, render;
21
+var zeta_options = {};
25 22
 
26 23
 var date_s = Date.now();
27 24
 var time_ms = function() { return Date.now() - date_s; }
@@ -273,14 +270,17 @@ var vfs_done = function() {
273 270
 		}
274 271
 	}
275 272
 
276
-	video_blink = !vfs.contains("BLINKX.COM");
273
+	if (!zeta_options.render.hasOwnProperty("blink")) {
274
+		zeta_options.render.blink = !vfs.contains("BLINKX.COM");
275
+	}
277 276
 
277
+	render = ZetaRender.toCanvas(zeta_options.render.canvas, zeta_options.render);
278 278
 	vfs_arg = (vfs_arg || "").toUpperCase();
279 279
 
280 280
 	draw_progress(1.0);
281 281
 	ZetaNative().then(function(c) {
282 282
 		emu = c;
283
-		audio = ZetaAudio.createStreamBased(emu);
283
+		audio = ZetaAudio.createOscillatorBased();
284 284
 
285 285
 		var buffer = emu._malloc(vfs_arg.length + 1);
286 286
 		var heap = new Uint8Array(emu.HEAPU8.buffer, buffer, vfs_arg.length + 1);
@@ -318,8 +318,6 @@ function speakerg_off() {
318 318
 	if (audio != undefined) audio.off();
319 319
 }
320 320
 
321
-canvas.contentEditable = true;
322
-
323 321
 /* var check_modifiers = function(event) {
324 322
 	if (event.shiftKey) emu._zzt_kmod_set(0x01); else emu._zzt_kmod_clear(0x01);
325 323
 	if (event.ctrlKey) emu._zzt_kmod_set(0x04); else emu._zzt_kmod_clear(0x04);
@@ -463,9 +461,13 @@ var attach_mouse_handler = function(o) {
463 461
 	});
464 462
 }
465 463
 
466
-function zzt_emu_create(options) {
467
-	// TODO: hook blink, charset override
468
-	render = ZetaRender.toCanvas(canvas, {});
464
+function zeta_emu_create(options) {
465
+	zeta_options = options;
466
+	canvas = options.render.canvas;
467
+	canvas.contentEditable = true;
468
+	ctx = canvas.getContext('2d', {alpha: false});
469
+	ctx.imageSmoothingEnabled = false;
470
+
469 471
 	attach_mouse_handler(canvas);
470 472
 
471 473
 	vfs_files = options.files;
@@ -485,4 +487,6 @@ function zzt_emu_create(options) {
485 487
 			}, vfs_on_loaded);
486 488
 		}
487 489
 	}
490
+
491
+	return {};
488 492
 }

+ 38
- 27
web/zeta_preload.js View File

@@ -17,43 +17,54 @@
17 17
  * along with Zeta.  If not, see <http://www.gnu.org/licenses/>.
18 18
  */
19 19
 
20
-var canvas = null;
21
-var ctx = null;
20
+Zeta = function(options, callback) {
21
+	var options = options;
22
+	if (!options.render) throw "Missing option: render!";
23
+	if (!options.render.canvas) throw "Missing option: render.canvas!";
24
+	if (!options.path) throw "Missing option: path!";
25
+	if (!options.files) throw "Missing option: files!";
22 26
 
23
-var scripts_array = [];
24
-var zzt_opts = {};
25
-var script_ldr = function() {
26
-	if (scripts_array.length == 0) {
27
-		zzt_emu_create(zzt_opts);
28
-		return;
27
+	var scripts_array = [];
28
+	var script_ldr = function() {
29
+		if (scripts_array.length == 0) {
30
+			callback(zeta_emu_create(options));
31
+		} else {
32
+			var scrSrc = scripts_array.shift();
33
+			var scr = document.createElement("script");
34
+			scr.onload = script_ldr;
35
+			scr.src = scrSrc;
36
+			document.body.appendChild(scr);
37
+		}
29 38
 	}
30 39
 
31
-	var s = scripts_array.shift();
32
-	var scr = document.createElement("script");
33
-	scr.onload = script_ldr;
34
-	scr.src = s;
35
-	document.body.appendChild(scr);
36
-}
37
-
38
-function zzt_emu_load(path, options) {
39
-	var canvas = document.getElementById('zzt_canvas');
40
+	var canvas = options.render.canvas;
40 41
 	canvas.tabindex=1;
41
-
42 42
 	var ctx = canvas.getContext('2d', {alpha: false});
43 43
 
44
-	zzt_opts = options;
45
-	zzt_opts.path = path;
46
-
47 44
 	var imgload = new Image();
48 45
 	imgload.onload = function() {
49 46
 		ctx.imageSmoothingEnabled = false;
50 47
 		ctx.drawImage(imgload,0,0,320,175,(canvas.width - 640)/2,(canvas.height - 350)/2,640,350);
51 48
 	};
52
-	imgload.src = path+"loading.png";
53
-	scripts_array = [
54
-		path+"uzip.min.js",
55
-		path+"zeta_native.js",
56
-		path+"zeta.min.js"
57
-	];
49
+	imgload.src = options.path+"loading.png";
50
+
51
+	if (options.dev) {
52
+		scripts_array = [
53
+			options.path+"uzip.min.js",
54
+			options.path+"zeta_native.js",
55
+			options.path+"zeta_vfs.js",
56
+			options.path+"zeta_render.js",
57
+			options.path+"zeta_audio.js",
58
+			options.path+"zeta_kbdmap.js",
59
+			options.path+"zeta.js"
60
+		];
61
+	} else {
62
+		scripts_array = [
63
+			options.path+"uzip.min.js",
64
+			options.path+"zeta_native.js",
65
+			options.path+"zeta.min.js"
66
+		];
67
+	}
68
+
58 69
 	script_ldr();
59 70
 }

+ 12
- 15
zeta_wasm.sh View File

@@ -2,11 +2,11 @@
2 2
 if [ ! -d build ]; then mkdir build; fi
3 3
 if [ ! -d build/web ]; then mkdir build/web; fi
4 4
 
5
-rm build/zeta86.js
6
-rm build/zeta86.js.mem
7
-rm build/zeta86.wasm
8
-rm build/zeta86.wasm.map
9
-rm build/zeta86.wast
5
+rm build/zeta_native.js
6
+rm build/zeta_native.js.mem
7
+rm build/zeta_native.wasm
8
+rm build/zeta_native.wasm.map
9
+rm build/zeta_native.wast
10 10
 
11 11
 xxd -i res/8x14.bin > res/8x14.c
12 12
 
@@ -14,22 +14,19 @@ emcc -O3 --js-library src/emscripten_glue.js \
14 14
   -s ENVIRONMENT=web \
15 15
   -s 'EXPORTED_FUNCTIONS=["_malloc"]' \
16 16
   -s 'EXTRA_EXPORTED_RUNTIME_METHODS=["AsciiToString"]' \
17
-  -s WASM=1 -s MODULARIZE=1 -s 'EXPORT_NAME="Zeta"' \
17
+  -s WASM=1 -s MODULARIZE=1 -s 'EXPORT_NAME="ZetaNative"' \
18 18
   -s ALLOW_MEMORY_GROWTH=0 -s ASSERTIONS=0 \
19 19
   -s 'MALLOC="emmalloc"' -s NO_FILESYSTEM=1 \
20 20
   -s TOTAL_MEMORY=4194304 -s TOTAL_STACK=262144 \
21 21
   -s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE="[]" \
22 22
   -DNO_MEMSET \
23
-  src/cpu.c src/zzt.c res/8x14.c
23
+  src/cpu.c src/zzt.c res/8x14.c src/audio_stream.c
24 24
 
25
-mv a.out.js build/zeta86.js
26
-mv a.out.js.mem build/zeta86.js.mem
27
-mv a.out.wasm build/zeta86.wasm
28
-mv a.out.wasm.map build/zeta86.wasm.map
29
-mv a.out.wast build/zeta86.wast
30
-sed -i -e "s/a\.out/zeta86/g" build/zeta86.js
25
+mv a.out.js build/zeta_native.js
26
+mv a.out.wasm build/zeta_native.wasm
27
+sed -i -e "s/a\.out/zeta_native/g" build/zeta_native.js
31 28
 
32 29
 rm build/web/*
33 30
 cp web/* build/web/
34
-cp build/zeta86.js build/web/
35
-cp build/zeta86.wasm build/web/
31
+cp build/zeta_native.js build/web/
32
+cp build/zeta_native.wasm build/web/

Loading…
Cancel
Save