@thenick775/mgba-wasm 2.4.0 → 2.4.1

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/dist/mgba.d.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  /// <reference types="emscripten" />
2
2
 
3
3
  declare namespace mGBA {
4
+ /**
5
+ * Common filesystem paths for the embedded virtual file system (IDBFS).
6
+ *
7
+ * These are the mount points/directories created by `FSInit` (ex. `/data/*`, `/autosave`, etc),
8
+ * these are needed for building paths when you’re reading/writing files via `Module.FS`.
9
+ */
4
10
  export interface filePaths {
5
11
  root: string;
6
12
  cheatsPath: string;
@@ -12,93 +18,507 @@ declare namespace mGBA {
12
18
  autosave: string;
13
19
  }
14
20
 
15
- // see: https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/state
16
- // interrupted is a valid property on iOS
17
- type ExtendedAudioContextState = AudioContextState | 'interrupted';
18
-
19
21
  export type coreCallbacks = {
22
+ /**
23
+ * Callback fired when the emulation core has triggered an alarm.
24
+ */
20
25
  alarmCallback?: (() => void) | null;
26
+
27
+ /**
28
+ * Callback fired when the emulation core has crashed.
29
+ */
21
30
  coreCrashedCallback?: (() => void) | null;
31
+
32
+ /**
33
+ * Callback fired when the emulation core has read input keys.
34
+ */
22
35
  keysReadCallback?: (() => void) | null;
36
+
37
+ /**
38
+ * Callback fired when the emulation core has updated its save data.
39
+ */
23
40
  saveDataUpdatedCallback?: (() => void) | null;
41
+
42
+ /**
43
+ * Callback fired when the emulation core has finished rendering a video frame.
44
+ */
24
45
  videoFrameEndedCallback?: (() => void) | null;
46
+
47
+ /**
48
+ * Callback fired when the emulation core has started rendering a video frame.
49
+ */
25
50
  videoFrameStartedCallback?: (() => void) | null;
51
+
52
+ /**
53
+ * Callback fired when the emulation core has captured an auto save state.
54
+ */
26
55
  autoSaveStateCapturedCallback?: (() => void) | null;
56
+
57
+ /**
58
+ * Callback fired when the emulation core has finished loading an auto save state.
59
+ */
27
60
  autoSaveStateLoadedCallback?: (() => void) | null;
28
61
  };
29
62
 
30
63
  export type coreSettings = {
64
+ /**
65
+ * Number of frames to skip rendering between screen paints.
66
+ *
67
+ * Typical values: `0..10`
68
+ *
69
+ * Default: 0
70
+ */
31
71
  frameSkip?: number;
72
+
73
+ /**
74
+ * Target base frames-per-second for the emulation core. Used by timing
75
+ * and frame-rate calculations.
76
+ *
77
+ * Typical values: 60, 30
78
+ *
79
+ * Default: 60
80
+ */
32
81
  baseFpsTarget?: number;
82
+
83
+ /**
84
+ * Maximum number of rewind states to keep in memory. Larger values allow
85
+ * longer rewind history at the cost of consumed memory. Value is a count of
86
+ * historical entries in the buffer.
87
+ *
88
+ * Typical values: `100..10000` is reasonable depending on memory pressure and
89
+ * the rewind interval.
90
+ *
91
+ * Default: 600
92
+ */
33
93
  rewindBufferCapacity?: number;
94
+
95
+ /**
96
+ * The speed at which rewind snapshots are taken. Larger numbers mean rewind happens faster.
97
+ *
98
+ * Typical values: `1..10`
99
+ *
100
+ * Default: 1
101
+ */
34
102
  rewindBufferInterval?: number;
103
+
104
+ /**
105
+ * Requested audio sample rate in Hz for the audio output.
106
+ * The core will attempt to use this rate, actual output depends on
107
+ * the host audio device (best effort).
108
+ *
109
+ * Typical values: 22050, 32000, 44100, 48000
110
+ *
111
+ * Default: 48000
112
+ */
35
113
  audioSampleRate?: number;
114
+
115
+ /**
116
+ * Preferred size, in samples, of the audio buffer. Smaller buffers reduce
117
+ * latency but increase the chance of underruns, larger buffers increase
118
+ * latency but are more stable.
119
+ *
120
+ * Typical values: `256..4096`
121
+ *
122
+ * Default: 1024
123
+ */
36
124
  audioBufferSize?: number;
125
+
126
+ /**
127
+ * Interval in seconds between periodic auto save state captures.
128
+ *
129
+ * Typical values: `10..30`
130
+ *
131
+ * Default: 30
132
+ */
37
133
  autoSaveStateTimerIntervalSeconds?: number;
134
+
135
+ /**
136
+ * If true, allows opposing directional inputs (ex. left + right) to be
137
+ * accepted simultaneously. When false, only a single directional input
138
+ * is accepted at a time.
139
+ *
140
+ * Default: true
141
+ */
38
142
  allowOpposingDirections?: boolean;
143
+
144
+ /**
145
+ * If true, synchronize the video frame rate to the host display refresh rate (vsync).
146
+ *
147
+ * Default: false
148
+ */
39
149
  videoSync?: boolean;
150
+
151
+ /**
152
+ * If true, synchronizes the video frame rate to the audio output speed.
153
+ *
154
+ * Default: false
155
+ */
40
156
  audioSync?: boolean;
157
+
158
+ /**
159
+ * If true, render video on a separate thread (if supported).
160
+ *
161
+ * Default: false
162
+ */
41
163
  threadedVideo?: boolean;
164
+
165
+ /**
166
+ * Enable/disable rewind support.
167
+ *
168
+ * Default: true
169
+ */
42
170
  rewindEnable?: boolean;
171
+
172
+ /**
173
+ * If true, the core will sync using discrete timestep increments based on
174
+ * the baseFpsTarget value rather than variable-step delta timing (audio/video).
175
+ *
176
+ * Default: true
177
+ */
43
178
  timestepSync?: boolean;
179
+
180
+ /**
181
+ * If true, show an on-screen true FPS counter overlay.
182
+ *
183
+ * Default: false
184
+ */
44
185
  showFpsCounter?: boolean;
186
+
187
+ /**
188
+ * Enable/disable periodic auto save state capture.
189
+ *
190
+ * Default: true
191
+ */
45
192
  autoSaveStateEnable?: boolean;
193
+
194
+ /**
195
+ * If true, attempts to load the latest auto save state after a game load/reset.
196
+ *
197
+ * Default: true
198
+ */
46
199
  restoreAutoSaveStateOnLoad?: boolean;
47
200
  };
48
201
 
49
202
  export interface mGBAEmulator extends EmscriptenModule {
50
203
  // custom methods from preamble
204
+ /**
205
+ * Attempts to automatically load cheats for the currently loaded game.
206
+ *
207
+ * @returns True if cheats were loaded successfully, otherwise false.
208
+ */
51
209
  autoLoadCheats(): boolean;
210
+
211
+ /**
212
+ * Binds a physical key (SDL key name) to a GBA input action.
213
+ *
214
+ * @param bindingName - SDL key name (ex. "Return", "Left", "Keypad X").
215
+ * @param inputName - GBA input/action (ex. "A", "B", "Start", "Up").
216
+ */
52
217
  bindKey(bindingName: string, inputName: string): void;
218
+
219
+ /**
220
+ * Presses a named emulated button.
221
+ *
222
+ * @param name - Button name to press (ex. "A", "B", "Start", "Select", "Up").
223
+ */
53
224
  buttonPress(name: string): void;
225
+
226
+ /**
227
+ * Releases (unpress) a named emulated button.
228
+ *
229
+ * @param name - Button name to release (ex. "A", "B", "Start", "Select", "Up").
230
+ */
54
231
  buttonUnpress(name: string): void;
232
+
233
+ /**
234
+ * Initializes the Emscripten filesystem and any runtime FS mounts needed by the emulator.
235
+ */
55
236
  FSInit(): Promise<void>;
237
+
238
+ /**
239
+ * Synchronizes filesystem state to the backing store (IDBFS).
240
+ */
56
241
  FSSync(): Promise<void>;
242
+
243
+ /**
244
+ * Gets the current fast forward multiplier.
245
+ *
246
+ * - `multiplier = 1` = normal speed
247
+ * - `multiplier > 1` = fast forward (`xN`)
248
+ * - `multiplier < 0` = slow down (`1/abs(N)`)
249
+ *
250
+ * @returns Current fast forward multiplier.
251
+ */
57
252
  getFastForwardMultiplier(): number;
253
+
254
+ /**
255
+ * Gets the current main loop timing mode.
256
+ *
257
+ * @returns Current timing mode value.
258
+ */
58
259
  getMainLoopTimingMode(): number;
260
+
261
+ /**
262
+ * Gets the current main loop timing value for the current mode.
263
+ *
264
+ * @returns Current timing value.
265
+ */
59
266
  getMainLoopTimingValue(): number;
267
+
268
+ /**
269
+ * Reads the currently loaded game save data.
270
+ *
271
+ * @returns Save data as bytes, or null if no save exists.
272
+ */
60
273
  getSave(): Uint8Array | null;
274
+
275
+ /**
276
+ * Gets the current audio volume multiplier.
277
+ *
278
+ * - `1.0` = 100%
279
+ * - Range is `0.0..2.0` (0%..200%)
280
+ *
281
+ * @returns Current volume multiplier.
282
+ */
61
283
  getVolume(): number;
284
+
285
+ /**
286
+ * Lists ROM file names under the game directory.
287
+ *
288
+ * @returns Directory entries from `filePaths().gamePath`.
289
+ */
62
290
  listRoms(): string[];
291
+
292
+ /**
293
+ * Lists save file names under the save directory.
294
+ *
295
+ * @returns Directory entries from `filePaths().savePath`.
296
+ */
63
297
  listSaves(): string[];
298
+
299
+ /**
300
+ * Loads a rom into the emulator and runs the game, optionally overriding the save path used.
301
+ *
302
+ * @param romPath - Path to the rom file within the emulated filesystem.
303
+ * @param savePathOverride - Optional override for the save path.
304
+ * @returns True if the game loaded successfully, otherwise false.
305
+ */
64
306
  loadGame(romPath: string, savePathOverride?: string): boolean;
307
+
308
+ /**
309
+ * Loads a save state from a given slot.
310
+ *
311
+ * @param slot - State slot index.
312
+ * @returns True if the state loaded successfully, otherwise false.
313
+ */
65
314
  loadState(slot: number): boolean;
315
+
316
+ /**
317
+ * Forces an auto save state capture immediately.
318
+ *
319
+ * @returns True if the auto save state was captured successfully, otherwise false.
320
+ */
66
321
  forceAutoSaveState(): boolean;
322
+
323
+ /**
324
+ * Loads the current auto save state (if present).
325
+ *
326
+ * @returns True if the auto save state loaded successfully, otherwise false.
327
+ */
67
328
  loadAutoSaveState(): boolean;
329
+
330
+ /**
331
+ * Reads the current auto save state from the filesystem (if present).
332
+ *
333
+ * @returns The auto save state name and bytes, or null if none exists.
334
+ */
68
335
  getAutoSaveState(): { autoSaveStateName: string; data: Uint8Array } | null;
336
+
337
+ /**
338
+ * Uploads auto save state data into the emulator filesystem.
339
+ *
340
+ * @param autoSaveStateName - Full auto save path to write to.
341
+ * @param data - Raw auto save state bytes.
342
+ */
69
343
  uploadAutoSaveState(
70
344
  autoSaveStateName: string,
71
- data: Uint8Array
345
+ data: Uint8Array,
72
346
  ): Promise<void>;
347
+
348
+ /**
349
+ * Pauses audio output without pausing emulation.
350
+ */
73
351
  pauseAudio(): void;
352
+
353
+ /**
354
+ * Pauses the game emulation.
355
+ */
74
356
  pauseGame(): void;
357
+
358
+ /**
359
+ * Performs a quick reload of the current ROM file.
360
+ */
75
361
  quickReload(): void;
362
+
363
+ /**
364
+ * Quits the currently running game session.
365
+ */
76
366
  quitGame(): void;
367
+
368
+ /**
369
+ * Exits the emulator runtime.
370
+ */
77
371
  quitMgba(): void;
372
+
373
+ /**
374
+ * Resumes audio output.
375
+ */
78
376
  resumeAudio(): void;
377
+
378
+ /**
379
+ * Resumes game emulation and audio.
380
+ */
79
381
  resumeGame(): void;
382
+
383
+ /**
384
+ * Saves a save state to a given slot.
385
+ *
386
+ * @param slot - State slot index.
387
+ * @returns True if the state saved successfully, otherwise false.
388
+ */
80
389
  saveState(slot: number): boolean;
390
+
391
+ /**
392
+ * Captures a screenshot and writes it to the screenshots directory.
393
+ *
394
+ * @param fileName - Optional custom screenshot file name.
395
+ * @returns True if screenshot was captured successfully, otherwise false.
396
+ */
81
397
  screenshot(fileName?: string): boolean;
398
+
399
+ /**
400
+ * Sets the current fast forward multiplier.
401
+ *
402
+ * - `multiplier = 1` = normal speed
403
+ * - `multiplier > 1` = fast forward (`xN`)
404
+ * - `multiplier < 0` = slow down (`1/abs(N)`)
405
+ *
406
+ * @param multiplier - The fast forward multiplier to apply.
407
+ */
82
408
  setFastForwardMultiplier(multiplier: number): void;
409
+
410
+ /**
411
+ * Sets the main loop timing mode and value.
412
+ *
413
+ * See: https://emscripten.org/docs/api_reference/emscripten.h.html#c.emscripten_set_main_loop_timing
414
+ *
415
+ * @param mode - Timing mode identifier.
416
+ * @param value - Timing value associated with the mode.
417
+ */
83
418
  setMainLoopTiming(mode: number, value: number): void;
419
+
420
+ /**
421
+ * Sets the audio volume multiplier.
422
+ *
423
+ * - `1.0` = 100%
424
+ * - Range is `0.0..2.0` (0%..200%)
425
+ *
426
+ * @param percent - Volume multiplier to apply.
427
+ */
84
428
  setVolume(percent: number): void;
429
+
430
+ /**
431
+ * Enables or disables keyboard input handling.
432
+ *
433
+ * @param enabled - If true input is accepted, if false input is ignored.
434
+ */
85
435
  toggleInput(enabled: boolean): void;
436
+
437
+ /**
438
+ * Uploads a cheats file into the emulator filesystem.
439
+ *
440
+ * @param file - Cheats file to upload.
441
+ * @param callback - Optional callback fired after upload completes.
442
+ */
86
443
  uploadCheats(file: File, callback?: () => void): void;
444
+
445
+ /**
446
+ * Uploads a patch file into the emulator filesystem.
447
+ *
448
+ * @param file - Patch file to upload.
449
+ * @param callback - Optional callback fired after upload completes.
450
+ */
87
451
  uploadPatch(file: File, callback?: () => void): void;
452
+
453
+ /**
454
+ * Uploads a ROM file into the emulator filesystem.
455
+ *
456
+ * @param file - ROM file to upload.
457
+ * @param callback - Optional callback fired after upload completes.
458
+ */
88
459
  uploadRom(file: File, callback?: () => void): void;
460
+
461
+ /**
462
+ * Uploads a save or save state file into the emulator filesystem.
463
+ *
464
+ * @param file - Save or state file to upload.
465
+ * @param callback - Optional callback fired after upload completes.
466
+ */
89
467
  uploadSaveOrSaveState(file: File, callback?: () => void): void;
468
+
469
+ /**
470
+ * Uploads a screenshot file into the emulator filesystem.
471
+ *
472
+ * @param file - Screenshot file to upload.
473
+ * @param callback - Optional callback fired after upload completes.
474
+ */
90
475
  uploadScreenshot(file: File, callback?: () => void): void;
476
+
477
+ /**
478
+ * Registers core callbacks for emulator lifecycle and custom events.
479
+ *
480
+ * @param coreCallbacks - Callback object to register.
481
+ */
91
482
  addCoreCallbacks(coreCallbacks: coreCallbacks): void;
483
+
484
+ /**
485
+ * Enables/disables active rewinding while the core is running.
486
+ *
487
+ * @param enabled - If true the core rewinds, if false rewind stops.
488
+ */
92
489
  toggleRewind(enabled: boolean): void;
490
+
491
+ /**
492
+ * Applies core settings to the emulator runtime.
493
+ *
494
+ * @param coreSettings - Settings object to apply.
495
+ */
93
496
  setCoreSettings(coreSettings: coreSettings): void;
497
+
94
498
  // custom variables
95
499
  version: {
96
500
  projectName: string;
97
501
  projectVersion: string;
98
502
  };
503
+
504
+ /**
505
+ * Returns common filesystem path strings used by this build.
506
+ */
99
507
  filePaths(): filePaths;
508
+
509
+ /**
510
+ * Last loaded ROM path set after `loadGame` succeeds.
511
+ */
100
512
  gameName?: string;
513
+
514
+ /**
515
+ * Save path used for the current game set after `loadGame` succeeds.
516
+ */
101
517
  saveName?: string;
518
+
519
+ /**
520
+ * Auto save state path and file name used for the current game set after `loadGame` succeeds.
521
+ */
102
522
  autoSaveStateName?: string;
103
523
  // extra exported runtime methods
104
524
  FS: typeof FS;
@@ -108,12 +528,33 @@ declare namespace mGBA {
108
528
  currentOutputBuffer: AudioBuffer;
109
529
  scriptProcessorNode: ScriptProcessorNode;
110
530
  };
111
- audioContext: Omit<AudioContext, 'state'> & {
112
- readonly state: ExtendedAudioContextState;
113
- };
531
+ audioContext: AudioContext;
114
532
  };
115
533
  }
116
534
 
535
+ /**
536
+ * Generates a web assembly mGBA module for the browser.
537
+ *
538
+ * This emulator core is meant to be used like a controlled frontend component:
539
+ * it bootstraps the emulator runtime, canvas wiring, keyboard events, and other autonomous
540
+ * functions using emscripten, exposing an imperative API used to control the core.
541
+ *
542
+ * The consuming UI then drives all actions after initialization using the API above, such as
543
+ * loading ROM/save files, pausing/resuming, settings, saves, etc.
544
+ *
545
+ * **Initialization flow:**
546
+ * - create a `<canvas />`
547
+ * - call `mGBA({ canvas })` to get the `Module`
548
+ * - call `await Module.FSInit()` once to mount + load persisted file system data
549
+ * - keep the `Module` accessible and call methods on it from your UI
550
+ *
551
+ * This core uses threads, your app must be served with cross-origin isolation enabled
552
+ * (`COOP: same-origin` + `COEP: require-corp`), otherwise it will not run correctly.
553
+ *
554
+ * @param options - Module options.
555
+ * @param options.canvas - Canvas used for video output.
556
+ * @returns The initialized emulator `Module`.
557
+ */
117
558
  // eslint-disable-next-line import/no-default-export
118
559
  export default function mGBA(options: {
119
560
  canvas: HTMLCanvasElement;
package/dist/mgba.wasm CHANGED
Binary file