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