@emu198x/zx-spectrum 0.4.0 → 0.4.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.
package/README.md CHANGED
@@ -47,6 +47,7 @@ the browser will blur the pixels.
47
47
  | `tick(elapsedMs)` | Run elapsed real time and draw. Returns frames run. |
48
48
  | `loadSnapshot(bytes, format)` | Load a `.sna` or `.z80` snapshot. |
49
49
  | `load(slot, kind, bytes)` | Load media — for example a tape into `tape-1`. |
50
+ | `autoload(maxBootFrames)` | Load the tape in `tape-1`: type `LOAD ""` and press play. A machine that has already run is reset first; the tape stays in. |
50
51
  | `keyDown(code)` / `keyUp(code)` | Feed a DOM `KeyboardEvent.code`. |
51
52
  | `setAudioEnabled(on)` | Start or stop audio. |
52
53
  | `configureAudio(rate, channels, capacity)` | Match the page's `AudioContext`. |
@@ -73,7 +74,10 @@ The permission is Cliff Lawson's, for Amstrad plc, on comp.sys.sinclair,
73
74
  31 August 1999:
74
75
  <https://web.archive.org/web/20180828125931/http://www.worldofspectrum.org/permits/amstrad-roms.txt>
75
76
 
76
- The ROM image is included unmodified, and no charge is made for it. The
77
+ The ROM image is included unmodified, and no charge is made for it. Versions
78
+ 0.1.0 to 0.4.0 carried a 48K image with 272 bytes changed in the ROM's unused
79
+ area, from address `0x386E`; use 0.4.1 or later, which carries the unmodified
80
+ image (SHA1 `5ea7c2b824672e914525d1d5c419d71b84a426a2`). The
77
81
  permission covers the Sinclair 48K and 128K ROMs and Amstrad's +2/+2A/+3
78
82
  machines. It does not extend to the ZX80, ZX81, Interface 1 or 2, Timex
79
83
  machines, or Spectrum clones.
@@ -27,6 +27,9 @@ export class Spectrum {
27
27
  * the editor prompt to be repainted before it is read, and for the 128K
28
28
  * family's loader to be listening before the tape rolls.
29
29
  *
30
+ * A machine that has already run is reset first, keeping the tape, so
31
+ * choosing a tape works however the machine has been used (#1569).
32
+ *
30
33
  * Returns the number of frames spent waiting for boot. Load a tape first.
31
34
  *
32
35
  * # Errors
@@ -43,7 +46,7 @@ export class Spectrum {
43
46
  /**
44
47
  * Builds a 48K attached to `canvas`, from ROM bytes the page supplies.
45
48
  *
46
- * Async even though nothing here awaits: restoring the GPU path (#1436)
49
+ * Async even though nothing here awaits: adopting the GPU path (#1414)
47
50
  * needs an adapter, and acquiring one is async. Shipping this synchronous
48
51
  * would make that a breaking change for every consumer.
49
52
  *
@@ -137,6 +140,10 @@ export class Spectrum {
137
140
  * Width and height of the machine's picture, as `[width, height]`.
138
141
  */
139
142
  frameSize(): Uint32Array;
143
+ /**
144
+ * Frame period derived from the machine profile.
145
+ */
146
+ frame_ms(): number;
140
147
  /**
141
148
  * Presses a key, from a DOM `KeyboardEvent.code`.
142
149
  *
@@ -206,6 +213,10 @@ export class Spectrum {
206
213
  * Rejects ranges extending beyond the 64 KiB address space.
207
214
  */
208
215
  readMemory(address: number, length: number): Uint8Array;
216
+ /**
217
+ * Restores compatible machine state, clearing pending host input/audio.
218
+ */
219
+ restore_state(bytes: Uint8Array): void;
209
220
  /**
210
221
  * Returns the executed routine events and whether the stop was reached.
211
222
  *
@@ -230,6 +241,10 @@ export class Spectrum {
230
241
  * outside the code, and ROM boot or prompt failures.
231
242
  */
232
243
  runCode(bytes: Uint8Array, origin: number, entry: number): void;
244
+ /**
245
+ * Exports the current machine state.
246
+ */
247
+ save_state(): Uint8Array;
233
248
  /**
234
249
  * Returns captured writes (including ROM writes) and saturation status.
235
250
  * Consumers can select the program's PC range without inventing a trace.
@@ -242,6 +257,12 @@ export class Spectrum {
242
257
  * Starts or stops machine audio.
243
258
  */
244
259
  setAudioEnabled(enabled: boolean): void;
260
+ /**
261
+ * Advances exactly one frame without drawing to a canvas.
262
+ * # Errors
263
+ * Returns the runtime's execution error.
264
+ */
265
+ step(): void;
245
266
  /**
246
267
  * Runs the machine for `elapsed_ms` of real time and draws the result.
247
268
  *
@@ -290,6 +311,7 @@ export interface InitOutput {
290
311
  readonly spectrum_enableScreenWriteTrace: (a: number, b: number, c: number) => [number, number];
291
312
  readonly spectrum_frameRgba: (a: number) => [number, number];
292
313
  readonly spectrum_frameSize: (a: number) => [number, number];
314
+ readonly spectrum_frame_ms: (a: number) => number;
293
315
  readonly spectrum_keyDown: (a: number, b: number, c: number) => number;
294
316
  readonly spectrum_keyUp: (a: number, b: number, c: number) => number;
295
317
  readonly spectrum_load: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
@@ -297,11 +319,14 @@ export interface InitOutput {
297
319
  readonly spectrum_mediaSlots: (a: number) => [number, number];
298
320
  readonly spectrum_query: (a: number, b: number, c: number) => [number, number, number, number];
299
321
  readonly spectrum_readMemory: (a: number, b: number, c: number) => [number, number, number, number];
322
+ readonly spectrum_restore_state: (a: number, b: number, c: number) => [number, number];
300
323
  readonly spectrum_routineTrace: (a: number) => [number, number, number, number];
301
324
  readonly spectrum_runBasic: (a: number, b: number, c: number) => [number, number];
302
325
  readonly spectrum_runCode: (a: number, b: number, c: number, d: number, e: number) => [number, number];
326
+ readonly spectrum_save_state: (a: number) => [number, number, number, number];
303
327
  readonly spectrum_screenWriteTrace: (a: number) => [number, number, number, number];
304
328
  readonly spectrum_setAudioEnabled: (a: number, b: number) => void;
329
+ readonly spectrum_step: (a: number) => [number, number];
305
330
  readonly spectrum_tick: (a: number, b: number) => [number, number, number];
306
331
  readonly wasm_bindgen_d6cb7d81ec28c0ae___convert__closures_____invoke___wasm_bindgen_d6cb7d81ec28c0ae___JsValue__core_f0fd674eaa06beef___result__Result_____wasm_bindgen_d6cb7d81ec28c0ae___JsError___true_: (a: number, b: number, c: any) => [number, number];
307
332
  readonly wasm_bindgen_d6cb7d81ec28c0ae___convert__closures_____invoke___js_sys_e5668971ffde892f___Function_fn_wasm_bindgen_d6cb7d81ec28c0ae___JsValue_____wasm_bindgen_d6cb7d81ec28c0ae___sys__Undefined___js_sys_e5668971ffde892f___Function_fn_wasm_bindgen_d6cb7d81ec28c0ae___JsValue_____wasm_bindgen_d6cb7d81ec28c0ae___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
@@ -45,6 +45,9 @@ export class Spectrum {
45
45
  * the editor prompt to be repainted before it is read, and for the 128K
46
46
  * family's loader to be listening before the tape rolls.
47
47
  *
48
+ * A machine that has already run is reset first, keeping the tape, so
49
+ * choosing a tape works however the machine has been used (#1569).
50
+ *
48
51
  * Returns the number of frames spent waiting for boot. Load a tape first.
49
52
  *
50
53
  * # Errors
@@ -74,7 +77,7 @@ export class Spectrum {
74
77
  /**
75
78
  * Builds a 48K attached to `canvas`, from ROM bytes the page supplies.
76
79
  *
77
- * Async even though nothing here awaits: restoring the GPU path (#1436)
80
+ * Async even though nothing here awaits: adopting the GPU path (#1414)
78
81
  * needs an adapter, and acquiring one is async. Shipping this synchronous
79
82
  * would make that a breaking change for every consumer.
80
83
  *
@@ -253,6 +256,14 @@ export class Spectrum {
253
256
  wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
254
257
  return v1;
255
258
  }
259
+ /**
260
+ * Frame period derived from the machine profile.
261
+ * @returns {number}
262
+ */
263
+ frame_ms() {
264
+ const ret = wasm.spectrum_frame_ms(this.__wbg_ptr);
265
+ return ret;
266
+ }
256
267
  /**
257
268
  * Presses a key, from a DOM `KeyboardEvent.code`.
258
269
  *
@@ -401,6 +412,18 @@ export class Spectrum {
401
412
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
402
413
  return v1;
403
414
  }
415
+ /**
416
+ * Restores compatible machine state, clearing pending host input/audio.
417
+ * @param {Uint8Array} bytes
418
+ */
419
+ restore_state(bytes) {
420
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
421
+ const len0 = WASM_VECTOR_LEN;
422
+ const ret = wasm.spectrum_restore_state(this.__wbg_ptr, ptr0, len0);
423
+ if (ret[1]) {
424
+ throw takeFromExternrefTable0(ret[0]);
425
+ }
426
+ }
404
427
  /**
405
428
  * Returns the executed routine events and whether the stop was reached.
406
429
  *
@@ -461,6 +484,19 @@ export class Spectrum {
461
484
  throw takeFromExternrefTable0(ret[0]);
462
485
  }
463
486
  }
487
+ /**
488
+ * Exports the current machine state.
489
+ * @returns {Uint8Array}
490
+ */
491
+ save_state() {
492
+ const ret = wasm.spectrum_save_state(this.__wbg_ptr);
493
+ if (ret[3]) {
494
+ throw takeFromExternrefTable0(ret[2]);
495
+ }
496
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
497
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
498
+ return v1;
499
+ }
464
500
  /**
465
501
  * Returns captured writes (including ROM writes) and saturation status.
466
502
  * Consumers can select the program's PC range without inventing a trace.
@@ -494,6 +530,17 @@ export class Spectrum {
494
530
  setAudioEnabled(enabled) {
495
531
  wasm.spectrum_setAudioEnabled(this.__wbg_ptr, enabled);
496
532
  }
533
+ /**
534
+ * Advances exactly one frame without drawing to a canvas.
535
+ * # Errors
536
+ * Returns the runtime's execution error.
537
+ */
538
+ step() {
539
+ const ret = wasm.spectrum_step(this.__wbg_ptr);
540
+ if (ret[1]) {
541
+ throw takeFromExternrefTable0(ret[0]);
542
+ }
543
+ }
497
544
  /**
498
545
  * Runs the machine for `elapsed_ms` of real time and draws the result.
499
546
  *
@@ -659,7 +706,7 @@ function __wbg_get_imports() {
659
706
  return ret;
660
707
  },
661
708
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
662
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 30, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
709
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 29, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
663
710
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen_d6cb7d81ec28c0ae___convert__closures_____invoke___wasm_bindgen_d6cb7d81ec28c0ae___JsValue__core_f0fd674eaa06beef___result__Result_____wasm_bindgen_d6cb7d81ec28c0ae___JsError___true_);
664
711
  return ret;
665
712
  },
Binary file
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@emu198x/zx-spectrum",
3
3
  "type": "module",
4
4
  "description": "ZX Spectrum in the browser, published to npm as @emu198x/zx-spectrum",
5
- "version": "0.4.0",
5
+ "version": "0.4.2",
6
6
  "license": "SEE LICENSE IN README.md",
7
7
  "repository": {
8
8
  "type": "git",