@emu198x/zx-spectrum 0.1.0 → 0.3.0

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.
@@ -118,10 +118,32 @@ export class Spectrum {
118
118
  * parse.
119
119
  */
120
120
  loadSnapshot(bytes: Uint8Array, format: string): void;
121
+ mediaSlots(): string[];
121
122
  /**
122
123
  * The machine's media slots, for a page that wants to name one.
124
+ * Asks the machine a question, and hands back the answer as JSON.
125
+ *
126
+ * The same query surface the headless session and the MCP server use, so
127
+ * a page sees what a script sees rather than a browser-only subset. The
128
+ * paths a Spectrum answers include `cpu.pc`, `cpu.halted`, `cpu.iff1`,
129
+ * `cpu.instructions_retired`, `screen.text.lines`, `tape.playing` and
130
+ * `boot.detected`.
131
+ *
132
+ * This is what lets a lesson say *why* a machine stopped rather than
133
+ * offering a reset and moving on: a program that ran past its own last
134
+ * instruction has a `cpu.pc` outside the bytes it was assembled into, and
135
+ * one that halted with interrupts disabled is `cpu.halted` with
136
+ * `cpu.iff1` false. Both are mistakes a unit is teaching against.
137
+ *
138
+ * JSON rather than a native value: the answers are already JSON inside
139
+ * the query layer, and a page parses one string more cheaply than this
140
+ * crate grows a serialisation dependency.
141
+ *
142
+ * # Errors
143
+ *
144
+ * Returns a JavaScript error if the machine does not know the path.
123
145
  */
124
- mediaSlots(): string[];
146
+ query(path: string): string;
125
147
  /**
126
148
  * Starts or stops machine audio.
127
149
  */
@@ -163,10 +185,11 @@ export interface InitOutput {
163
185
  readonly spectrum_load: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
164
186
  readonly spectrum_loadSnapshot: (a: number, b: number, c: number, d: number, e: number) => [number, number];
165
187
  readonly spectrum_mediaSlots: (a: number) => [number, number];
188
+ readonly spectrum_query: (a: number, b: number, c: number) => [number, number, number, number];
166
189
  readonly spectrum_setAudioEnabled: (a: number, b: number) => void;
167
190
  readonly spectrum_tick: (a: number, b: number) => [number, number, number];
168
- readonly wasm_bindgen_aa0ad12a6f6b153a___convert__closures_____invoke___wasm_bindgen_aa0ad12a6f6b153a___JsValue__core_f0fd674eaa06beef___result__Result_____wasm_bindgen_aa0ad12a6f6b153a___JsError___true_: (a: number, b: number, c: any) => [number, number];
169
- readonly wasm_bindgen_aa0ad12a6f6b153a___convert__closures_____invoke___js_sys_33d4c80ea43e39ff___Function_fn_wasm_bindgen_aa0ad12a6f6b153a___JsValue_____wasm_bindgen_aa0ad12a6f6b153a___sys__Undefined___js_sys_33d4c80ea43e39ff___Function_fn_wasm_bindgen_aa0ad12a6f6b153a___JsValue_____wasm_bindgen_aa0ad12a6f6b153a___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
191
+ 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];
192
+ 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;
170
193
  readonly __wbindgen_exn_store: (a: number) => void;
171
194
  readonly __externref_table_alloc: () => number;
172
195
  readonly __wbindgen_externrefs: WebAssembly.Table;
@@ -214,7 +214,6 @@ export class Spectrum {
214
214
  }
215
215
  }
216
216
  /**
217
- * The machine's media slots, for a page that wants to name one.
218
217
  * @returns {string[]}
219
218
  */
220
219
  mediaSlots() {
@@ -223,6 +222,52 @@ export class Spectrum {
223
222
  wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
224
223
  return v1;
225
224
  }
225
+ /**
226
+ * The machine's media slots, for a page that wants to name one.
227
+ * Asks the machine a question, and hands back the answer as JSON.
228
+ *
229
+ * The same query surface the headless session and the MCP server use, so
230
+ * a page sees what a script sees rather than a browser-only subset. The
231
+ * paths a Spectrum answers include `cpu.pc`, `cpu.halted`, `cpu.iff1`,
232
+ * `cpu.instructions_retired`, `screen.text.lines`, `tape.playing` and
233
+ * `boot.detected`.
234
+ *
235
+ * This is what lets a lesson say *why* a machine stopped rather than
236
+ * offering a reset and moving on: a program that ran past its own last
237
+ * instruction has a `cpu.pc` outside the bytes it was assembled into, and
238
+ * one that halted with interrupts disabled is `cpu.halted` with
239
+ * `cpu.iff1` false. Both are mistakes a unit is teaching against.
240
+ *
241
+ * JSON rather than a native value: the answers are already JSON inside
242
+ * the query layer, and a page parses one string more cheaply than this
243
+ * crate grows a serialisation dependency.
244
+ *
245
+ * # Errors
246
+ *
247
+ * Returns a JavaScript error if the machine does not know the path.
248
+ * @param {string} path
249
+ * @returns {string}
250
+ */
251
+ query(path) {
252
+ let deferred3_0;
253
+ let deferred3_1;
254
+ try {
255
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
256
+ const len0 = WASM_VECTOR_LEN;
257
+ const ret = wasm.spectrum_query(this.__wbg_ptr, ptr0, len0);
258
+ var ptr2 = ret[0];
259
+ var len2 = ret[1];
260
+ if (ret[3]) {
261
+ ptr2 = 0; len2 = 0;
262
+ throw takeFromExternrefTable0(ret[2]);
263
+ }
264
+ deferred3_0 = ptr2;
265
+ deferred3_1 = len2;
266
+ return getStringFromWasm0(ptr2, len2);
267
+ } finally {
268
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
269
+ }
270
+ }
226
271
  /**
227
272
  * Starts or stops machine audio.
228
273
  * @param {boolean} enabled
@@ -308,7 +353,7 @@ function __wbg_get_imports() {
308
353
  const a = state0.a;
309
354
  state0.a = 0;
310
355
  try {
311
- return wasm_bindgen_aa0ad12a6f6b153a___convert__closures_____invoke___js_sys_33d4c80ea43e39ff___Function_fn_wasm_bindgen_aa0ad12a6f6b153a___JsValue_____wasm_bindgen_aa0ad12a6f6b153a___sys__Undefined___js_sys_33d4c80ea43e39ff___Function_fn_wasm_bindgen_aa0ad12a6f6b153a___JsValue_____wasm_bindgen_aa0ad12a6f6b153a___sys__Undefined_______true_(a, state0.b, arg0, arg1);
356
+ return 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, state0.b, arg0, arg1);
312
357
  } finally {
313
358
  state0.a = a;
314
359
  }
@@ -372,8 +417,8 @@ function __wbg_get_imports() {
372
417
  return ret;
373
418
  },
374
419
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
375
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 21, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
376
- const ret = makeMutClosure(arg0, arg1, wasm_bindgen_aa0ad12a6f6b153a___convert__closures_____invoke___wasm_bindgen_aa0ad12a6f6b153a___JsValue__core_f0fd674eaa06beef___result__Result_____wasm_bindgen_aa0ad12a6f6b153a___JsError___true_);
420
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 23, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
421
+ const ret = makeMutClosure(arg0, arg1, wasm_bindgen_d6cb7d81ec28c0ae___convert__closures_____invoke___wasm_bindgen_d6cb7d81ec28c0ae___JsValue__core_f0fd674eaa06beef___result__Result_____wasm_bindgen_d6cb7d81ec28c0ae___JsError___true_);
377
422
  return ret;
378
423
  },
379
424
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
@@ -397,15 +442,15 @@ function __wbg_get_imports() {
397
442
  };
398
443
  }
399
444
 
400
- function wasm_bindgen_aa0ad12a6f6b153a___convert__closures_____invoke___wasm_bindgen_aa0ad12a6f6b153a___JsValue__core_f0fd674eaa06beef___result__Result_____wasm_bindgen_aa0ad12a6f6b153a___JsError___true_(arg0, arg1, arg2) {
401
- const ret = wasm.wasm_bindgen_aa0ad12a6f6b153a___convert__closures_____invoke___wasm_bindgen_aa0ad12a6f6b153a___JsValue__core_f0fd674eaa06beef___result__Result_____wasm_bindgen_aa0ad12a6f6b153a___JsError___true_(arg0, arg1, arg2);
445
+ function wasm_bindgen_d6cb7d81ec28c0ae___convert__closures_____invoke___wasm_bindgen_d6cb7d81ec28c0ae___JsValue__core_f0fd674eaa06beef___result__Result_____wasm_bindgen_d6cb7d81ec28c0ae___JsError___true_(arg0, arg1, arg2) {
446
+ const ret = wasm.wasm_bindgen_d6cb7d81ec28c0ae___convert__closures_____invoke___wasm_bindgen_d6cb7d81ec28c0ae___JsValue__core_f0fd674eaa06beef___result__Result_____wasm_bindgen_d6cb7d81ec28c0ae___JsError___true_(arg0, arg1, arg2);
402
447
  if (ret[1]) {
403
448
  throw takeFromExternrefTable0(ret[0]);
404
449
  }
405
450
  }
406
451
 
407
- function wasm_bindgen_aa0ad12a6f6b153a___convert__closures_____invoke___js_sys_33d4c80ea43e39ff___Function_fn_wasm_bindgen_aa0ad12a6f6b153a___JsValue_____wasm_bindgen_aa0ad12a6f6b153a___sys__Undefined___js_sys_33d4c80ea43e39ff___Function_fn_wasm_bindgen_aa0ad12a6f6b153a___JsValue_____wasm_bindgen_aa0ad12a6f6b153a___sys__Undefined_______true_(arg0, arg1, arg2, arg3) {
408
- wasm.wasm_bindgen_aa0ad12a6f6b153a___convert__closures_____invoke___js_sys_33d4c80ea43e39ff___Function_fn_wasm_bindgen_aa0ad12a6f6b153a___JsValue_____wasm_bindgen_aa0ad12a6f6b153a___sys__Undefined___js_sys_33d4c80ea43e39ff___Function_fn_wasm_bindgen_aa0ad12a6f6b153a___JsValue_____wasm_bindgen_aa0ad12a6f6b153a___sys__Undefined_______true_(arg0, arg1, arg2, arg3);
452
+ function 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_(arg0, arg1, arg2, arg3) {
453
+ wasm.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_(arg0, arg1, arg2, arg3);
409
454
  }
410
455
 
411
456
  const SpectrumFinalization = (typeof FinalizationRegistry === 'undefined')
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.1.0",
5
+ "version": "0.3.0",
6
6
  "license": "SEE LICENSE IN README.md",
7
7
  "repository": {
8
8
  "type": "git",