@orkosinha/gb-emu 0.1.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.
package/gb_emu.js ADDED
@@ -0,0 +1,1282 @@
1
+ /* @ts-self-types="./gb_emu.d.ts" */
2
+
3
+ export class GameBoy {
4
+ __destroy_into_raw() {
5
+ const ptr = this.__wbg_ptr;
6
+ this.__wbg_ptr = 0;
7
+ GameBoyFinalization.unregister(this);
8
+ return ptr;
9
+ }
10
+ free() {
11
+ const ptr = this.__destroy_into_raw();
12
+ wasm.__wbg_gameboy_free(ptr, 0);
13
+ }
14
+ /**
15
+ * @returns {boolean}
16
+ */
17
+ apu_ch1_dac() {
18
+ const ret = wasm.gameboy_apu_ch1_dac(this.__wbg_ptr);
19
+ return ret !== 0;
20
+ }
21
+ /**
22
+ * @returns {number}
23
+ */
24
+ apu_ch1_duty() {
25
+ const ret = wasm.gameboy_apu_ch1_duty(this.__wbg_ptr);
26
+ return ret;
27
+ }
28
+ /**
29
+ * @returns {number}
30
+ */
31
+ apu_ch1_duty_pos() {
32
+ const ret = wasm.gameboy_apu_ch1_duty_pos(this.__wbg_ptr);
33
+ return ret;
34
+ }
35
+ /**
36
+ * @returns {boolean}
37
+ */
38
+ apu_ch1_enabled() {
39
+ const ret = wasm.gameboy_apu_ch1_enabled(this.__wbg_ptr);
40
+ return ret !== 0;
41
+ }
42
+ /**
43
+ * @returns {boolean}
44
+ */
45
+ apu_ch1_env_add() {
46
+ const ret = wasm.gameboy_apu_ch1_env_add(this.__wbg_ptr);
47
+ return ret !== 0;
48
+ }
49
+ /**
50
+ * @returns {number}
51
+ */
52
+ apu_ch1_env_period() {
53
+ const ret = wasm.gameboy_apu_ch1_env_period(this.__wbg_ptr);
54
+ return ret;
55
+ }
56
+ /**
57
+ * @returns {number}
58
+ */
59
+ apu_ch1_freq_hz() {
60
+ const ret = wasm.gameboy_apu_ch1_freq_hz(this.__wbg_ptr);
61
+ return ret;
62
+ }
63
+ /**
64
+ * @returns {number}
65
+ */
66
+ apu_ch1_freq_reg() {
67
+ const ret = wasm.gameboy_apu_ch1_freq_reg(this.__wbg_ptr);
68
+ return ret;
69
+ }
70
+ /**
71
+ * @returns {boolean}
72
+ */
73
+ apu_ch1_len_en() {
74
+ const ret = wasm.gameboy_apu_ch1_len_en(this.__wbg_ptr);
75
+ return ret !== 0;
76
+ }
77
+ /**
78
+ * @returns {number}
79
+ */
80
+ apu_ch1_length() {
81
+ const ret = wasm.gameboy_apu_ch1_length(this.__wbg_ptr);
82
+ return ret;
83
+ }
84
+ /**
85
+ * MIDI note number for CH1 frequency (255 = unknown/out of range).
86
+ * @returns {number}
87
+ */
88
+ apu_ch1_midi_note() {
89
+ const ret = wasm.gameboy_apu_ch1_midi_note(this.__wbg_ptr);
90
+ return ret;
91
+ }
92
+ /**
93
+ * @returns {number}
94
+ */
95
+ apu_ch1_shadow_freq() {
96
+ const ret = wasm.gameboy_apu_ch1_shadow_freq(this.__wbg_ptr);
97
+ return ret;
98
+ }
99
+ /**
100
+ * @returns {boolean}
101
+ */
102
+ apu_ch1_sweep_neg() {
103
+ const ret = wasm.gameboy_apu_ch1_sweep_neg(this.__wbg_ptr);
104
+ return ret !== 0;
105
+ }
106
+ /**
107
+ * @returns {number}
108
+ */
109
+ apu_ch1_sweep_period() {
110
+ const ret = wasm.gameboy_apu_ch1_sweep_period(this.__wbg_ptr);
111
+ return ret;
112
+ }
113
+ /**
114
+ * @returns {number}
115
+ */
116
+ apu_ch1_sweep_shift() {
117
+ const ret = wasm.gameboy_apu_ch1_sweep_shift(this.__wbg_ptr);
118
+ return ret;
119
+ }
120
+ /**
121
+ * @returns {number}
122
+ */
123
+ apu_ch1_volume() {
124
+ const ret = wasm.gameboy_apu_ch1_volume(this.__wbg_ptr);
125
+ return ret;
126
+ }
127
+ /**
128
+ * @returns {boolean}
129
+ */
130
+ apu_ch2_dac() {
131
+ const ret = wasm.gameboy_apu_ch2_dac(this.__wbg_ptr);
132
+ return ret !== 0;
133
+ }
134
+ /**
135
+ * @returns {number}
136
+ */
137
+ apu_ch2_duty() {
138
+ const ret = wasm.gameboy_apu_ch2_duty(this.__wbg_ptr);
139
+ return ret;
140
+ }
141
+ /**
142
+ * @returns {number}
143
+ */
144
+ apu_ch2_duty_pos() {
145
+ const ret = wasm.gameboy_apu_ch2_duty_pos(this.__wbg_ptr);
146
+ return ret;
147
+ }
148
+ /**
149
+ * @returns {boolean}
150
+ */
151
+ apu_ch2_enabled() {
152
+ const ret = wasm.gameboy_apu_ch2_enabled(this.__wbg_ptr);
153
+ return ret !== 0;
154
+ }
155
+ /**
156
+ * @returns {boolean}
157
+ */
158
+ apu_ch2_env_add() {
159
+ const ret = wasm.gameboy_apu_ch2_env_add(this.__wbg_ptr);
160
+ return ret !== 0;
161
+ }
162
+ /**
163
+ * @returns {number}
164
+ */
165
+ apu_ch2_env_period() {
166
+ const ret = wasm.gameboy_apu_ch2_env_period(this.__wbg_ptr);
167
+ return ret;
168
+ }
169
+ /**
170
+ * @returns {number}
171
+ */
172
+ apu_ch2_freq_hz() {
173
+ const ret = wasm.gameboy_apu_ch2_freq_hz(this.__wbg_ptr);
174
+ return ret;
175
+ }
176
+ /**
177
+ * @returns {number}
178
+ */
179
+ apu_ch2_freq_reg() {
180
+ const ret = wasm.gameboy_apu_ch2_freq_reg(this.__wbg_ptr);
181
+ return ret;
182
+ }
183
+ /**
184
+ * @returns {boolean}
185
+ */
186
+ apu_ch2_len_en() {
187
+ const ret = wasm.gameboy_apu_ch2_len_en(this.__wbg_ptr);
188
+ return ret !== 0;
189
+ }
190
+ /**
191
+ * @returns {number}
192
+ */
193
+ apu_ch2_length() {
194
+ const ret = wasm.gameboy_apu_ch2_length(this.__wbg_ptr);
195
+ return ret;
196
+ }
197
+ /**
198
+ * @returns {number}
199
+ */
200
+ apu_ch2_midi_note() {
201
+ const ret = wasm.gameboy_apu_ch2_midi_note(this.__wbg_ptr);
202
+ return ret;
203
+ }
204
+ /**
205
+ * @returns {number}
206
+ */
207
+ apu_ch2_volume() {
208
+ const ret = wasm.gameboy_apu_ch2_volume(this.__wbg_ptr);
209
+ return ret;
210
+ }
211
+ /**
212
+ * @returns {boolean}
213
+ */
214
+ apu_ch3_dac() {
215
+ const ret = wasm.gameboy_apu_ch3_dac(this.__wbg_ptr);
216
+ return ret !== 0;
217
+ }
218
+ /**
219
+ * @returns {boolean}
220
+ */
221
+ apu_ch3_enabled() {
222
+ const ret = wasm.gameboy_apu_ch3_enabled(this.__wbg_ptr);
223
+ return ret !== 0;
224
+ }
225
+ /**
226
+ * @returns {number}
227
+ */
228
+ apu_ch3_freq_hz() {
229
+ const ret = wasm.gameboy_apu_ch3_freq_hz(this.__wbg_ptr);
230
+ return ret;
231
+ }
232
+ /**
233
+ * @returns {number}
234
+ */
235
+ apu_ch3_freq_reg() {
236
+ const ret = wasm.gameboy_apu_ch3_freq_reg(this.__wbg_ptr);
237
+ return ret;
238
+ }
239
+ /**
240
+ * @returns {boolean}
241
+ */
242
+ apu_ch3_len_en() {
243
+ const ret = wasm.gameboy_apu_ch3_len_en(this.__wbg_ptr);
244
+ return ret !== 0;
245
+ }
246
+ /**
247
+ * @returns {number}
248
+ */
249
+ apu_ch3_length() {
250
+ const ret = wasm.gameboy_apu_ch3_length(this.__wbg_ptr);
251
+ return ret;
252
+ }
253
+ /**
254
+ * @returns {number}
255
+ */
256
+ apu_ch3_midi_note() {
257
+ const ret = wasm.gameboy_apu_ch3_midi_note(this.__wbg_ptr);
258
+ return ret;
259
+ }
260
+ /**
261
+ * @returns {number}
262
+ */
263
+ apu_ch3_vol_code() {
264
+ const ret = wasm.gameboy_apu_ch3_vol_code(this.__wbg_ptr);
265
+ return ret;
266
+ }
267
+ /**
268
+ * @returns {number}
269
+ */
270
+ apu_ch3_wave_pos() {
271
+ const ret = wasm.gameboy_apu_ch3_wave_pos(this.__wbg_ptr);
272
+ return ret;
273
+ }
274
+ /**
275
+ * Raw wave RAM as 16 bytes (32 × 4-bit nibbles).
276
+ * @returns {Uint8Array}
277
+ */
278
+ apu_ch3_wave_ram() {
279
+ const ret = wasm.gameboy_apu_ch3_wave_ram(this.__wbg_ptr);
280
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
281
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
282
+ return v1;
283
+ }
284
+ /**
285
+ * @returns {number}
286
+ */
287
+ apu_ch4_clock_div() {
288
+ const ret = wasm.gameboy_apu_ch4_clock_div(this.__wbg_ptr);
289
+ return ret;
290
+ }
291
+ /**
292
+ * @returns {number}
293
+ */
294
+ apu_ch4_clock_shift() {
295
+ const ret = wasm.gameboy_apu_ch4_clock_shift(this.__wbg_ptr);
296
+ return ret;
297
+ }
298
+ /**
299
+ * @returns {boolean}
300
+ */
301
+ apu_ch4_dac() {
302
+ const ret = wasm.gameboy_apu_ch4_dac(this.__wbg_ptr);
303
+ return ret !== 0;
304
+ }
305
+ /**
306
+ * @returns {boolean}
307
+ */
308
+ apu_ch4_enabled() {
309
+ const ret = wasm.gameboy_apu_ch4_enabled(this.__wbg_ptr);
310
+ return ret !== 0;
311
+ }
312
+ /**
313
+ * @returns {boolean}
314
+ */
315
+ apu_ch4_env_add() {
316
+ const ret = wasm.gameboy_apu_ch4_env_add(this.__wbg_ptr);
317
+ return ret !== 0;
318
+ }
319
+ /**
320
+ * @returns {number}
321
+ */
322
+ apu_ch4_env_period() {
323
+ const ret = wasm.gameboy_apu_ch4_env_period(this.__wbg_ptr);
324
+ return ret;
325
+ }
326
+ /**
327
+ * @returns {number}
328
+ */
329
+ apu_ch4_freq_hz() {
330
+ const ret = wasm.gameboy_apu_ch4_freq_hz(this.__wbg_ptr);
331
+ return ret;
332
+ }
333
+ /**
334
+ * @returns {boolean}
335
+ */
336
+ apu_ch4_len_en() {
337
+ const ret = wasm.gameboy_apu_ch4_len_en(this.__wbg_ptr);
338
+ return ret !== 0;
339
+ }
340
+ /**
341
+ * @returns {number}
342
+ */
343
+ apu_ch4_length() {
344
+ const ret = wasm.gameboy_apu_ch4_length(this.__wbg_ptr);
345
+ return ret;
346
+ }
347
+ /**
348
+ * @returns {number}
349
+ */
350
+ apu_ch4_lfsr() {
351
+ const ret = wasm.gameboy_apu_ch4_lfsr(this.__wbg_ptr);
352
+ return ret;
353
+ }
354
+ /**
355
+ * @returns {boolean}
356
+ */
357
+ apu_ch4_lfsr_short() {
358
+ const ret = wasm.gameboy_apu_ch4_lfsr_short(this.__wbg_ptr);
359
+ return ret !== 0;
360
+ }
361
+ /**
362
+ * @returns {number}
363
+ */
364
+ apu_ch4_volume() {
365
+ const ret = wasm.gameboy_apu_ch4_volume(this.__wbg_ptr);
366
+ return ret;
367
+ }
368
+ /**
369
+ * Current frame sequencer step (0–7). Drives length/sweep/envelope clocks.
370
+ * @returns {number}
371
+ */
372
+ apu_frame_seq_step() {
373
+ const ret = wasm.gameboy_apu_frame_seq_step(this.__wbg_ptr);
374
+ return ret;
375
+ }
376
+ /**
377
+ * @returns {number}
378
+ */
379
+ apu_nr50() {
380
+ const ret = wasm.gameboy_apu_nr50(this.__wbg_ptr);
381
+ return ret;
382
+ }
383
+ /**
384
+ * @returns {number}
385
+ */
386
+ apu_nr51() {
387
+ const ret = wasm.gameboy_apu_nr51(this.__wbg_ptr);
388
+ return ret;
389
+ }
390
+ /**
391
+ * @returns {number}
392
+ */
393
+ apu_nr52() {
394
+ const ret = wasm.gameboy_apu_nr52(this.__wbg_ptr);
395
+ return ret;
396
+ }
397
+ /**
398
+ * @returns {boolean}
399
+ */
400
+ apu_powered() {
401
+ const ret = wasm.gameboy_apu_powered(this.__wbg_ptr);
402
+ return ret !== 0;
403
+ }
404
+ /**
405
+ * Clear the sample buffer after the host has consumed it.
406
+ */
407
+ audio_clear_samples() {
408
+ wasm.gameboy_audio_clear_samples(this.__wbg_ptr);
409
+ }
410
+ /**
411
+ * Number of f32 values in the sample buffer (pairs of L/R samples).
412
+ * @returns {number}
413
+ */
414
+ audio_sample_buffer_len() {
415
+ const ret = wasm.gameboy_audio_sample_buffer_len(this.__wbg_ptr);
416
+ return ret >>> 0;
417
+ }
418
+ /**
419
+ * Pointer to the interleaved stereo f32 sample buffer (L, R, L, R, …).
420
+ * Valid until the next call to `step_frame`.
421
+ * @returns {number}
422
+ */
423
+ audio_sample_buffer_ptr() {
424
+ const ret = wasm.gameboy_audio_sample_buffer_ptr(this.__wbg_ptr);
425
+ return ret >>> 0;
426
+ }
427
+ /**
428
+ * Target sample rate in Hz (44 100).
429
+ * @returns {number}
430
+ */
431
+ audio_sample_rate() {
432
+ const ret = wasm.gameboy_audio_sample_rate(this.__wbg_ptr);
433
+ return ret >>> 0;
434
+ }
435
+ /**
436
+ * Derive the contrast level (0-15) from the current dither matrix, or -1 if unknown.
437
+ * @returns {number}
438
+ */
439
+ camera_contrast() {
440
+ const ret = wasm.gameboy_camera_contrast(this.__wbg_ptr);
441
+ return ret;
442
+ }
443
+ /**
444
+ * Length of the camera live view buffer.
445
+ * @returns {number}
446
+ */
447
+ camera_live_len() {
448
+ const ret = wasm.gameboy_camera_live_len(this.__wbg_ptr);
449
+ return ret >>> 0;
450
+ }
451
+ /**
452
+ * Pointer to the camera live view RGBA buffer (128x112x4 bytes).
453
+ * @returns {number}
454
+ */
455
+ camera_live_ptr() {
456
+ const ret = wasm.gameboy_camera_live_ptr(this.__wbg_ptr);
457
+ return ret >>> 0;
458
+ }
459
+ /**
460
+ * Read a camera hardware register (0x00-0x7F, corresponding to A000-A07F).
461
+ * @param {number} index
462
+ * @returns {number}
463
+ */
464
+ camera_reg(index) {
465
+ const ret = wasm.gameboy_camera_reg(this.__wbg_ptr, index);
466
+ return ret;
467
+ }
468
+ /**
469
+ * Clear the serial output buffer.
470
+ */
471
+ clear_serial_output() {
472
+ wasm.gameboy_clear_serial_output(this.__wbg_ptr);
473
+ }
474
+ /**
475
+ * @returns {number}
476
+ */
477
+ cpu_a() {
478
+ const ret = wasm.gameboy_cpu_a(this.__wbg_ptr);
479
+ return ret;
480
+ }
481
+ /**
482
+ * @returns {number}
483
+ */
484
+ cpu_bc() {
485
+ const ret = wasm.gameboy_cpu_bc(this.__wbg_ptr);
486
+ return ret;
487
+ }
488
+ /**
489
+ * @returns {number}
490
+ */
491
+ cpu_de() {
492
+ const ret = wasm.gameboy_cpu_de(this.__wbg_ptr);
493
+ return ret;
494
+ }
495
+ /**
496
+ * @returns {number}
497
+ */
498
+ cpu_f() {
499
+ const ret = wasm.gameboy_cpu_f(this.__wbg_ptr);
500
+ return ret;
501
+ }
502
+ /**
503
+ * @returns {boolean}
504
+ */
505
+ cpu_halted() {
506
+ const ret = wasm.gameboy_cpu_halted(this.__wbg_ptr);
507
+ return ret !== 0;
508
+ }
509
+ /**
510
+ * @returns {number}
511
+ */
512
+ cpu_hl() {
513
+ const ret = wasm.gameboy_cpu_hl(this.__wbg_ptr);
514
+ return ret;
515
+ }
516
+ /**
517
+ * @returns {boolean}
518
+ */
519
+ cpu_ime() {
520
+ const ret = wasm.gameboy_cpu_ime(this.__wbg_ptr);
521
+ return ret !== 0;
522
+ }
523
+ /**
524
+ * @returns {number}
525
+ */
526
+ cpu_pc() {
527
+ const ret = wasm.gameboy_cpu_pc(this.__wbg_ptr);
528
+ return ret;
529
+ }
530
+ /**
531
+ * @returns {number}
532
+ */
533
+ cpu_sp() {
534
+ const ret = wasm.gameboy_cpu_sp(this.__wbg_ptr);
535
+ return ret;
536
+ }
537
+ /**
538
+ * Decode a GB Camera saved photo slot to RGBA pixel data.
539
+ * Slots 1-30 = saved photos. Returns empty if slot is unoccupied.
540
+ * @param {number} slot
541
+ * @returns {Uint8Array}
542
+ */
543
+ decode_camera_photo(slot) {
544
+ const ret = wasm.gameboy_decode_camera_photo(this.__wbg_ptr, slot);
545
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
546
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
547
+ return v1;
548
+ }
549
+ /**
550
+ * @returns {number}
551
+ */
552
+ frame_buffer_len() {
553
+ const ret = wasm.gameboy_frame_buffer_len(this.__wbg_ptr);
554
+ return ret >>> 0;
555
+ }
556
+ /**
557
+ * @returns {number}
558
+ */
559
+ frame_buffer_ptr() {
560
+ const ret = wasm.gameboy_frame_buffer_ptr(this.__wbg_ptr);
561
+ return ret >>> 0;
562
+ }
563
+ /**
564
+ * Colour of `color` (0–3) in BG `palette` (0–7) as 0xRRGGBB.
565
+ * @param {number} palette
566
+ * @param {number} color
567
+ * @returns {number}
568
+ */
569
+ get_bg_palette_color(palette, color) {
570
+ const ret = wasm.gameboy_get_bg_palette_color(this.__wbg_ptr, palette, color);
571
+ return ret >>> 0;
572
+ }
573
+ /**
574
+ * @returns {Uint8Array}
575
+ */
576
+ get_cartridge_ram() {
577
+ const ret = wasm.gameboy_get_cartridge_ram(this.__wbg_ptr);
578
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
579
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
580
+ return v1;
581
+ }
582
+ /**
583
+ * Get debug info about the emulator state and log to console.
584
+ * @returns {string}
585
+ */
586
+ get_debug_info() {
587
+ let deferred1_0;
588
+ let deferred1_1;
589
+ try {
590
+ const ret = wasm.gameboy_get_debug_info(this.__wbg_ptr);
591
+ deferred1_0 = ret[0];
592
+ deferred1_1 = ret[1];
593
+ return getStringFromWasm0(ret[0], ret[1]);
594
+ } finally {
595
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
596
+ }
597
+ }
598
+ /**
599
+ * Get frame count for debugging.
600
+ * @returns {number}
601
+ */
602
+ get_frame_count() {
603
+ const ret = wasm.gameboy_get_frame_count(this.__wbg_ptr);
604
+ return ret >>> 0;
605
+ }
606
+ /**
607
+ * Get total instruction count for debugging.
608
+ * @returns {bigint}
609
+ */
610
+ get_instruction_count() {
611
+ const ret = wasm.gameboy_get_instruction_count(this.__wbg_ptr);
612
+ return BigInt.asUintN(64, ret);
613
+ }
614
+ /**
615
+ * Colour of `color` (0–3) in OBJ `palette` (0–7) as 0xRRGGBB.
616
+ * @param {number} palette
617
+ * @param {number} color
618
+ * @returns {number}
619
+ */
620
+ get_obj_palette_color(palette, color) {
621
+ const ret = wasm.gameboy_get_obj_palette_color(this.__wbg_ptr, palette, color);
622
+ return ret >>> 0;
623
+ }
624
+ /**
625
+ * Get serial output as a string (for test ROM debugging).
626
+ * @returns {string}
627
+ */
628
+ get_serial_output() {
629
+ let deferred1_0;
630
+ let deferred1_1;
631
+ try {
632
+ const ret = wasm.gameboy_get_serial_output(this.__wbg_ptr);
633
+ deferred1_0 = ret[0];
634
+ deferred1_1 = ret[1];
635
+ return getStringFromWasm0(ret[0], ret[1]);
636
+ } finally {
637
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
638
+ }
639
+ }
640
+ /**
641
+ * BCPS: BG palette index register (bit 7 = auto-increment, bits 5–0 = byte address).
642
+ * @returns {number}
643
+ */
644
+ io_bcps() {
645
+ const ret = wasm.gameboy_io_bcps(this.__wbg_ptr);
646
+ return ret;
647
+ }
648
+ /**
649
+ * @returns {number}
650
+ */
651
+ io_bgp() {
652
+ const ret = wasm.gameboy_io_bgp(this.__wbg_ptr);
653
+ return ret;
654
+ }
655
+ /**
656
+ * @returns {number}
657
+ */
658
+ io_div() {
659
+ const ret = wasm.gameboy_io_div(this.__wbg_ptr);
660
+ return ret;
661
+ }
662
+ /**
663
+ * HDMA5: DMA status — 0xFF = idle; otherwise H-blank DMA active, bits 6–0 = remaining blocks − 1.
664
+ * @returns {number}
665
+ */
666
+ io_hdma5() {
667
+ const ret = wasm.gameboy_io_hdma5(this.__wbg_ptr);
668
+ return ret;
669
+ }
670
+ /**
671
+ * @returns {number}
672
+ */
673
+ io_ie() {
674
+ const ret = wasm.gameboy_io_ie(this.__wbg_ptr);
675
+ return ret;
676
+ }
677
+ /**
678
+ * @returns {number}
679
+ */
680
+ io_if() {
681
+ const ret = wasm.gameboy_io_if(this.__wbg_ptr);
682
+ return ret;
683
+ }
684
+ /**
685
+ * @returns {number}
686
+ */
687
+ io_joypad() {
688
+ const ret = wasm.gameboy_io_joypad(this.__wbg_ptr);
689
+ return ret;
690
+ }
691
+ /**
692
+ * KEY1: speed-switch register (bit 7 = current speed, bit 0 = armed).
693
+ * @returns {number}
694
+ */
695
+ io_key1() {
696
+ const ret = wasm.gameboy_io_key1(this.__wbg_ptr);
697
+ return ret;
698
+ }
699
+ /**
700
+ * @returns {number}
701
+ */
702
+ io_lcdc() {
703
+ const ret = wasm.gameboy_io_lcdc(this.__wbg_ptr);
704
+ return ret;
705
+ }
706
+ /**
707
+ * @returns {number}
708
+ */
709
+ io_ly() {
710
+ const ret = wasm.gameboy_io_ly(this.__wbg_ptr);
711
+ return ret;
712
+ }
713
+ /**
714
+ * @returns {number}
715
+ */
716
+ io_lyc() {
717
+ const ret = wasm.gameboy_io_lyc(this.__wbg_ptr);
718
+ return ret;
719
+ }
720
+ /**
721
+ * @returns {number}
722
+ */
723
+ io_obp0() {
724
+ const ret = wasm.gameboy_io_obp0(this.__wbg_ptr);
725
+ return ret;
726
+ }
727
+ /**
728
+ * @returns {number}
729
+ */
730
+ io_obp1() {
731
+ const ret = wasm.gameboy_io_obp1(this.__wbg_ptr);
732
+ return ret;
733
+ }
734
+ /**
735
+ * OCPS: OBJ palette index register (same layout as BCPS).
736
+ * @returns {number}
737
+ */
738
+ io_ocps() {
739
+ const ret = wasm.gameboy_io_ocps(this.__wbg_ptr);
740
+ return ret;
741
+ }
742
+ /**
743
+ * OPRI: Object priority mode (bit 0: 0 = CGB coordinate order, 1 = DMG OAM order).
744
+ * @returns {number}
745
+ */
746
+ io_opri() {
747
+ const ret = wasm.gameboy_io_opri(this.__wbg_ptr);
748
+ return ret;
749
+ }
750
+ /**
751
+ * @returns {number}
752
+ */
753
+ io_scx() {
754
+ const ret = wasm.gameboy_io_scx(this.__wbg_ptr);
755
+ return ret;
756
+ }
757
+ /**
758
+ * @returns {number}
759
+ */
760
+ io_scy() {
761
+ const ret = wasm.gameboy_io_scy(this.__wbg_ptr);
762
+ return ret;
763
+ }
764
+ /**
765
+ * @returns {number}
766
+ */
767
+ io_stat() {
768
+ const ret = wasm.gameboy_io_stat(this.__wbg_ptr);
769
+ return ret;
770
+ }
771
+ /**
772
+ * SVBK: current WRAM bank (1–7; bank 0 maps to 1).
773
+ * @returns {number}
774
+ */
775
+ io_svbk() {
776
+ const ret = wasm.gameboy_io_svbk(this.__wbg_ptr);
777
+ return ret;
778
+ }
779
+ /**
780
+ * @returns {number}
781
+ */
782
+ io_tac() {
783
+ const ret = wasm.gameboy_io_tac(this.__wbg_ptr);
784
+ return ret;
785
+ }
786
+ /**
787
+ * @returns {number}
788
+ */
789
+ io_tima() {
790
+ const ret = wasm.gameboy_io_tima(this.__wbg_ptr);
791
+ return ret;
792
+ }
793
+ /**
794
+ * @returns {number}
795
+ */
796
+ io_tma() {
797
+ const ret = wasm.gameboy_io_tma(this.__wbg_ptr);
798
+ return ret;
799
+ }
800
+ /**
801
+ * VBK: current VRAM bank (0 or 1).
802
+ * @returns {number}
803
+ */
804
+ io_vbk() {
805
+ const ret = wasm.gameboy_io_vbk(this.__wbg_ptr);
806
+ return ret;
807
+ }
808
+ /**
809
+ * @returns {number}
810
+ */
811
+ io_wx() {
812
+ const ret = wasm.gameboy_io_wx(this.__wbg_ptr);
813
+ return ret;
814
+ }
815
+ /**
816
+ * @returns {number}
817
+ */
818
+ io_wy() {
819
+ const ret = wasm.gameboy_io_wy(this.__wbg_ptr);
820
+ return ret;
821
+ }
822
+ /**
823
+ * Check if the loaded ROM is a Game Boy Camera cartridge.
824
+ * @returns {boolean}
825
+ */
826
+ is_camera() {
827
+ const ret = wasm.gameboy_is_camera(this.__wbg_ptr);
828
+ return ret !== 0;
829
+ }
830
+ /**
831
+ * Check if camera image is ready for capture.
832
+ * @returns {boolean}
833
+ */
834
+ is_camera_ready() {
835
+ const ret = wasm.gameboy_is_camera_ready(this.__wbg_ptr);
836
+ return ret !== 0;
837
+ }
838
+ /**
839
+ * @returns {boolean}
840
+ */
841
+ is_cgb_mode() {
842
+ const ret = wasm.gameboy_is_cgb_mode(this.__wbg_ptr);
843
+ return ret !== 0;
844
+ }
845
+ /**
846
+ * @returns {boolean}
847
+ */
848
+ is_mbc7() {
849
+ const ret = wasm.gameboy_is_mbc7(this.__wbg_ptr);
850
+ return ret !== 0;
851
+ }
852
+ /**
853
+ * @param {Uint8Array} data
854
+ */
855
+ load_cartridge_ram(data) {
856
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
857
+ const len0 = WASM_VECTOR_LEN;
858
+ wasm.gameboy_load_cartridge_ram(this.__wbg_ptr, ptr0, len0);
859
+ }
860
+ /**
861
+ * @param {Uint8Array} rom_data
862
+ * @param {boolean} cgb_mode
863
+ */
864
+ load_rom(rom_data, cgb_mode) {
865
+ const ptr0 = passArray8ToWasm0(rom_data, wasm.__wbindgen_malloc);
866
+ const len0 = WASM_VECTOR_LEN;
867
+ const ret = wasm.gameboy_load_rom(this.__wbg_ptr, ptr0, len0, cgb_mode);
868
+ if (ret[1]) {
869
+ throw takeFromExternrefTable0(ret[0]);
870
+ }
871
+ }
872
+ /**
873
+ * Log a message to the browser console.
874
+ * @param {string} msg
875
+ */
876
+ log(msg) {
877
+ const ptr0 = passStringToWasm0(msg, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
878
+ const len0 = WASM_VECTOR_LEN;
879
+ wasm.gameboy_log(this.__wbg_ptr, ptr0, len0);
880
+ }
881
+ /**
882
+ * Log detailed VRAM tile data for debugging.
883
+ */
884
+ log_vram_info() {
885
+ wasm.gameboy_log_vram_info(this.__wbg_ptr);
886
+ }
887
+ /**
888
+ * Convert a MIDI note number (0–127) to a note name string like "C-4" or "A#3".
889
+ * @param {number} note
890
+ * @returns {string}
891
+ */
892
+ static midi_to_note_name(note) {
893
+ let deferred1_0;
894
+ let deferred1_1;
895
+ try {
896
+ const ret = wasm.gameboy_midi_to_note_name(note);
897
+ deferred1_0 = ret[0];
898
+ deferred1_1 = ret[1];
899
+ return getStringFromWasm0(ret[0], ret[1]);
900
+ } finally {
901
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
902
+ }
903
+ }
904
+ constructor() {
905
+ const ret = wasm.gameboy_new();
906
+ this.__wbg_ptr = ret >>> 0;
907
+ GameBoyFinalization.register(this, this.__wbg_ptr, this);
908
+ return this;
909
+ }
910
+ /**
911
+ * @returns {number}
912
+ */
913
+ ppu_cycles() {
914
+ const ret = wasm.gameboy_ppu_cycles(this.__wbg_ptr);
915
+ return ret >>> 0;
916
+ }
917
+ /**
918
+ * @returns {number}
919
+ */
920
+ ppu_line() {
921
+ const ret = wasm.gameboy_ppu_line(this.__wbg_ptr);
922
+ return ret;
923
+ }
924
+ /**
925
+ * @returns {number}
926
+ */
927
+ ppu_mode() {
928
+ const ret = wasm.gameboy_ppu_mode(this.__wbg_ptr);
929
+ return ret;
930
+ }
931
+ /**
932
+ * @param {number} addr
933
+ * @returns {number}
934
+ */
935
+ read_byte(addr) {
936
+ const ret = wasm.gameboy_read_byte(this.__wbg_ptr, addr);
937
+ return ret;
938
+ }
939
+ /**
940
+ * @param {number} addr
941
+ * @param {number} len
942
+ * @returns {Uint8Array}
943
+ */
944
+ read_range(addr, len) {
945
+ const ret = wasm.gameboy_read_range(this.__wbg_ptr, addr, len);
946
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
947
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
948
+ return v1;
949
+ }
950
+ /**
951
+ * Read bytes from VRAM at address `addr` (0x8000–0x9FFF) from an explicit bank (0 or 1).
952
+ * Does not modify the emulator's VBK register — safe to call at any time.
953
+ * @param {number} bank
954
+ * @param {number} addr
955
+ * @param {number} len
956
+ * @returns {Uint8Array}
957
+ */
958
+ read_vram_bank(bank, addr, len) {
959
+ const ret = wasm.gameboy_read_vram_bank(this.__wbg_ptr, bank, addr, len);
960
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
961
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
962
+ return v1;
963
+ }
964
+ /**
965
+ * Feed a new tilt reading for MBC7 (Kirby's Tilt 'n' Tumble).
966
+ *
967
+ * `x` and `y` are signed offsets from flat (0 = no tilt).
968
+ * Scale: ±0x1000 ≈ ±1g. The WASM host converts DeviceMotion m/s² to this unit.
969
+ * @param {number} x
970
+ * @param {number} y
971
+ */
972
+ set_accelerometer(x, y) {
973
+ wasm.gameboy_set_accelerometer(this.__wbg_ptr, x, y);
974
+ }
975
+ /**
976
+ * @param {number} button
977
+ * @param {boolean} pressed
978
+ */
979
+ set_button(button, pressed) {
980
+ wasm.gameboy_set_button(this.__wbg_ptr, button, pressed);
981
+ }
982
+ /**
983
+ * Set camera image data from webcam.
984
+ * Expects 128x112 pixels as raw 8-bit grayscale (0=black, 255=white).
985
+ * @param {Uint8Array} data
986
+ */
987
+ set_camera_image(data) {
988
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
989
+ const len0 = WASM_VECTOR_LEN;
990
+ wasm.gameboy_set_camera_image(this.__wbg_ptr, ptr0, len0);
991
+ }
992
+ step_frame() {
993
+ wasm.gameboy_step_frame(this.__wbg_ptr);
994
+ }
995
+ /**
996
+ * Execute a single CPU instruction, return cycles consumed.
997
+ * @returns {number}
998
+ */
999
+ step_instruction() {
1000
+ const ret = wasm.gameboy_step_instruction(this.__wbg_ptr);
1001
+ return ret >>> 0;
1002
+ }
1003
+ /**
1004
+ * Update the camera live view buffer if the capture has changed.
1005
+ * Returns true if the buffer was updated.
1006
+ * @returns {boolean}
1007
+ */
1008
+ update_camera_live() {
1009
+ const ret = wasm.gameboy_update_camera_live(this.__wbg_ptr);
1010
+ return ret !== 0;
1011
+ }
1012
+ }
1013
+ if (Symbol.dispose) GameBoy.prototype[Symbol.dispose] = GameBoy.prototype.free;
1014
+
1015
+ /**
1016
+ * Initialize panic hook for better error messages in WASM.
1017
+ * This is called once when the WASM module is instantiated.
1018
+ */
1019
+ export function init_panic_hook() {
1020
+ wasm.init_panic_hook();
1021
+ }
1022
+
1023
+ function __wbg_get_imports() {
1024
+ const import0 = {
1025
+ __proto__: null,
1026
+ __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
1027
+ throw new Error(getStringFromWasm0(arg0, arg1));
1028
+ },
1029
+ __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
1030
+ let deferred0_0;
1031
+ let deferred0_1;
1032
+ try {
1033
+ deferred0_0 = arg0;
1034
+ deferred0_1 = arg1;
1035
+ console.error(getStringFromWasm0(arg0, arg1));
1036
+ } finally {
1037
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
1038
+ }
1039
+ },
1040
+ __wbg_log_524eedafa26daa59: function(arg0) {
1041
+ console.log(arg0);
1042
+ },
1043
+ __wbg_new_227d7c05414eb861: function() {
1044
+ const ret = new Error();
1045
+ return ret;
1046
+ },
1047
+ __wbg_now_16f0c993d5dd6c27: function() {
1048
+ const ret = Date.now();
1049
+ return ret;
1050
+ },
1051
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
1052
+ const ret = arg1.stack;
1053
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1054
+ const len1 = WASM_VECTOR_LEN;
1055
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1056
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1057
+ },
1058
+ __wbg_warn_69424c2d92a2fa73: function(arg0) {
1059
+ console.warn(arg0);
1060
+ },
1061
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
1062
+ // Cast intrinsic for `Ref(String) -> Externref`.
1063
+ const ret = getStringFromWasm0(arg0, arg1);
1064
+ return ret;
1065
+ },
1066
+ __wbindgen_init_externref_table: function() {
1067
+ const table = wasm.__wbindgen_externrefs;
1068
+ const offset = table.grow(4);
1069
+ table.set(0, undefined);
1070
+ table.set(offset + 0, undefined);
1071
+ table.set(offset + 1, null);
1072
+ table.set(offset + 2, true);
1073
+ table.set(offset + 3, false);
1074
+ },
1075
+ };
1076
+ return {
1077
+ __proto__: null,
1078
+ "./gb_emu_bg.js": import0,
1079
+ };
1080
+ }
1081
+
1082
+ const GameBoyFinalization = (typeof FinalizationRegistry === 'undefined')
1083
+ ? { register: () => {}, unregister: () => {} }
1084
+ : new FinalizationRegistry(ptr => wasm.__wbg_gameboy_free(ptr >>> 0, 1));
1085
+
1086
+ function getArrayU8FromWasm0(ptr, len) {
1087
+ ptr = ptr >>> 0;
1088
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
1089
+ }
1090
+
1091
+ let cachedDataViewMemory0 = null;
1092
+ function getDataViewMemory0() {
1093
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
1094
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
1095
+ }
1096
+ return cachedDataViewMemory0;
1097
+ }
1098
+
1099
+ function getStringFromWasm0(ptr, len) {
1100
+ ptr = ptr >>> 0;
1101
+ return decodeText(ptr, len);
1102
+ }
1103
+
1104
+ let cachedUint8ArrayMemory0 = null;
1105
+ function getUint8ArrayMemory0() {
1106
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
1107
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
1108
+ }
1109
+ return cachedUint8ArrayMemory0;
1110
+ }
1111
+
1112
+ function passArray8ToWasm0(arg, malloc) {
1113
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
1114
+ getUint8ArrayMemory0().set(arg, ptr / 1);
1115
+ WASM_VECTOR_LEN = arg.length;
1116
+ return ptr;
1117
+ }
1118
+
1119
+ function passStringToWasm0(arg, malloc, realloc) {
1120
+ if (realloc === undefined) {
1121
+ const buf = cachedTextEncoder.encode(arg);
1122
+ const ptr = malloc(buf.length, 1) >>> 0;
1123
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
1124
+ WASM_VECTOR_LEN = buf.length;
1125
+ return ptr;
1126
+ }
1127
+
1128
+ let len = arg.length;
1129
+ let ptr = malloc(len, 1) >>> 0;
1130
+
1131
+ const mem = getUint8ArrayMemory0();
1132
+
1133
+ let offset = 0;
1134
+
1135
+ for (; offset < len; offset++) {
1136
+ const code = arg.charCodeAt(offset);
1137
+ if (code > 0x7F) break;
1138
+ mem[ptr + offset] = code;
1139
+ }
1140
+ if (offset !== len) {
1141
+ if (offset !== 0) {
1142
+ arg = arg.slice(offset);
1143
+ }
1144
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
1145
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
1146
+ const ret = cachedTextEncoder.encodeInto(arg, view);
1147
+
1148
+ offset += ret.written;
1149
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
1150
+ }
1151
+
1152
+ WASM_VECTOR_LEN = offset;
1153
+ return ptr;
1154
+ }
1155
+
1156
+ function takeFromExternrefTable0(idx) {
1157
+ const value = wasm.__wbindgen_externrefs.get(idx);
1158
+ wasm.__externref_table_dealloc(idx);
1159
+ return value;
1160
+ }
1161
+
1162
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1163
+ cachedTextDecoder.decode();
1164
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
1165
+ let numBytesDecoded = 0;
1166
+ function decodeText(ptr, len) {
1167
+ numBytesDecoded += len;
1168
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
1169
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
1170
+ cachedTextDecoder.decode();
1171
+ numBytesDecoded = len;
1172
+ }
1173
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
1174
+ }
1175
+
1176
+ const cachedTextEncoder = new TextEncoder();
1177
+
1178
+ if (!('encodeInto' in cachedTextEncoder)) {
1179
+ cachedTextEncoder.encodeInto = function (arg, view) {
1180
+ const buf = cachedTextEncoder.encode(arg);
1181
+ view.set(buf);
1182
+ return {
1183
+ read: arg.length,
1184
+ written: buf.length
1185
+ };
1186
+ };
1187
+ }
1188
+
1189
+ let WASM_VECTOR_LEN = 0;
1190
+
1191
+ let wasmModule, wasm;
1192
+ function __wbg_finalize_init(instance, module) {
1193
+ wasm = instance.exports;
1194
+ wasmModule = module;
1195
+ cachedDataViewMemory0 = null;
1196
+ cachedUint8ArrayMemory0 = null;
1197
+ wasm.__wbindgen_start();
1198
+ return wasm;
1199
+ }
1200
+
1201
+ async function __wbg_load(module, imports) {
1202
+ if (typeof Response === 'function' && module instanceof Response) {
1203
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
1204
+ try {
1205
+ return await WebAssembly.instantiateStreaming(module, imports);
1206
+ } catch (e) {
1207
+ const validResponse = module.ok && expectedResponseType(module.type);
1208
+
1209
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
1210
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
1211
+
1212
+ } else { throw e; }
1213
+ }
1214
+ }
1215
+
1216
+ const bytes = await module.arrayBuffer();
1217
+ return await WebAssembly.instantiate(bytes, imports);
1218
+ } else {
1219
+ const instance = await WebAssembly.instantiate(module, imports);
1220
+
1221
+ if (instance instanceof WebAssembly.Instance) {
1222
+ return { instance, module };
1223
+ } else {
1224
+ return instance;
1225
+ }
1226
+ }
1227
+
1228
+ function expectedResponseType(type) {
1229
+ switch (type) {
1230
+ case 'basic': case 'cors': case 'default': return true;
1231
+ }
1232
+ return false;
1233
+ }
1234
+ }
1235
+
1236
+ function initSync(module) {
1237
+ if (wasm !== undefined) return wasm;
1238
+
1239
+
1240
+ if (module !== undefined) {
1241
+ if (Object.getPrototypeOf(module) === Object.prototype) {
1242
+ ({module} = module)
1243
+ } else {
1244
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
1245
+ }
1246
+ }
1247
+
1248
+ const imports = __wbg_get_imports();
1249
+ if (!(module instanceof WebAssembly.Module)) {
1250
+ module = new WebAssembly.Module(module);
1251
+ }
1252
+ const instance = new WebAssembly.Instance(module, imports);
1253
+ return __wbg_finalize_init(instance, module);
1254
+ }
1255
+
1256
+ async function __wbg_init(module_or_path) {
1257
+ if (wasm !== undefined) return wasm;
1258
+
1259
+
1260
+ if (module_or_path !== undefined) {
1261
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1262
+ ({module_or_path} = module_or_path)
1263
+ } else {
1264
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
1265
+ }
1266
+ }
1267
+
1268
+ if (module_or_path === undefined) {
1269
+ module_or_path = new URL('gb_emu_bg.wasm', import.meta.url);
1270
+ }
1271
+ const imports = __wbg_get_imports();
1272
+
1273
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
1274
+ module_or_path = fetch(module_or_path);
1275
+ }
1276
+
1277
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
1278
+
1279
+ return __wbg_finalize_init(instance, module);
1280
+ }
1281
+
1282
+ export { initSync, __wbg_init as default };