@thenick775/mgba-wasm 2.5.0 → 2.6.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/README.md +123 -6
- package/dist/mgba.d.ts +67 -7
- package/dist/mgba.js +1 -1
- package/dist/mgba.wasm +0 -0
- package/dist/mgba.wasm.map +1 -1
- package/package.json +9 -2
package/README.md
CHANGED
|
@@ -2,8 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
This package is a bundled version of my [mGBA fork](https://github.com/thenick775/mgba/tree/feature/wasm) compiled to webassembly.
|
|
4
4
|
|
|
5
|
+
This core is framework agnostic, and can be instantiated in any framework, including vanilla javascript.
|
|
6
|
+
|
|
7
|
+
See the [api documentation](https://thenick775.github.io/mgba/) for in depth details.
|
|
8
|
+
|
|
5
9
|
This core currently powers [gbajs3](https://gba.nicholas-vancise.dev)!
|
|
6
10
|
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm i @thenick775/mgba-wasm
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## React
|
|
18
|
+
|
|
7
19
|
To instantiate the emulator using react:
|
|
8
20
|
|
|
9
21
|
```
|
|
@@ -33,17 +45,122 @@ export const useEmulator = (canvas: HTMLCanvasElement | null) => {
|
|
|
33
45
|
|
|
34
46
|
return emulator;
|
|
35
47
|
};
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Vanilla
|
|
51
|
+
|
|
52
|
+
In a vanilla javascript project with no bundler, first download the published package tarball:
|
|
36
53
|
|
|
54
|
+
```bash
|
|
55
|
+
npm pack @thenick775/mgba-wasm
|
|
37
56
|
```
|
|
38
57
|
|
|
39
|
-
|
|
58
|
+
Extract these files from `package/dist/` and serve them from the same origin as your page:
|
|
59
|
+
|
|
60
|
+
- `mgba.js`
|
|
61
|
+
- `mgba.wasm`
|
|
62
|
+
|
|
63
|
+
Then instantiate the emulator as follows:
|
|
64
|
+
|
|
65
|
+
```html
|
|
66
|
+
<canvas id="canvas" width="240" height="160"></canvas>
|
|
67
|
+
|
|
68
|
+
<script type="module">
|
|
69
|
+
import mGBA from "./mgba.js";
|
|
70
|
+
|
|
71
|
+
const canvas = document.getElementById("canvas");
|
|
72
|
+
const Module = await mGBA({ canvas });
|
|
73
|
+
await Module.FSInit();
|
|
74
|
+
|
|
75
|
+
console.log(
|
|
76
|
+
`version ${Module.version.projectName + " " + Module.version.projectVersion}`,
|
|
77
|
+
);
|
|
78
|
+
</script>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Cross-origin Isolation
|
|
82
|
+
|
|
83
|
+
This core uses threads, so the page serving these files must enable cross-origin isolation:
|
|
84
|
+
|
|
40
85
|
```
|
|
41
|
-
Cross-Origin-Opener-Policy same-origin
|
|
42
|
-
Cross-Origin-Embedder-Policy require-corp
|
|
86
|
+
Cross-Origin-Opener-Policy: same-origin
|
|
87
|
+
Cross-Origin-Embedder-Policy: require-corp
|
|
43
88
|
```
|
|
44
89
|
|
|
45
|
-
|
|
90
|
+
`mgba.js` must be same-origin with the page because the threaded runtime starts its pthread worker from that script URL.
|
|
91
|
+
|
|
92
|
+
## API
|
|
93
|
+
|
|
94
|
+
The core exposes the following contract in addition to some standard Emscripten `Module` utilities such as `Module.FS`. This is a stateful emulator runtime designed to be created once, retained by the host application, and driven through the imperative API below.
|
|
95
|
+
|
|
96
|
+
Lifecycle:
|
|
97
|
+
|
|
98
|
+
- `FSInit()`
|
|
99
|
+
- `FSSync()`
|
|
100
|
+
- `pauseGame()`
|
|
101
|
+
- `resumeGame()`
|
|
102
|
+
- `pauseAudio()`
|
|
103
|
+
- `resumeAudio()`
|
|
104
|
+
- `quickReload()`
|
|
105
|
+
- `quitGame()`
|
|
106
|
+
- `quitMgba()`
|
|
107
|
+
|
|
108
|
+
ROM and file management:
|
|
109
|
+
|
|
110
|
+
- `loadGame(romPath, savePathOverride)`
|
|
111
|
+
- `listRoms()`
|
|
112
|
+
- `listSaves()`
|
|
113
|
+
- `filePaths()`
|
|
114
|
+
- `uploadRom(file, callback)`
|
|
115
|
+
- `uploadSaveOrSaveState(file, callback)`
|
|
116
|
+
- `uploadCheats(file, callback)`
|
|
117
|
+
- `uploadPatch(file, callback)`
|
|
118
|
+
- `uploadScreenshot(file, callback)`
|
|
119
|
+
- `uploadAutoSaveState(autoSaveStateName, data)`
|
|
120
|
+
|
|
121
|
+
Input management:
|
|
122
|
+
|
|
123
|
+
- `bindKey(bindingName, inputName)`
|
|
124
|
+
- `buttonPress(name)`
|
|
125
|
+
- `buttonUnpress(name)`
|
|
126
|
+
- `toggleInput(enabled)`
|
|
127
|
+
|
|
128
|
+
Save data and save states:
|
|
129
|
+
|
|
130
|
+
- `getSave()`
|
|
131
|
+
- `saveState(slot)`
|
|
132
|
+
- `loadState(slot)`
|
|
133
|
+
- `saveStateSlot(slot, flags)`
|
|
134
|
+
- `loadStateSlot(slot, flags)`
|
|
135
|
+
- `forceAutoSaveState()`
|
|
136
|
+
- `loadAutoSaveState()`
|
|
137
|
+
- `getAutoSaveState()`
|
|
138
|
+
|
|
139
|
+
Audio, timing, and speed:
|
|
140
|
+
|
|
141
|
+
- `getVolume()`
|
|
142
|
+
- `setVolume(percent)`
|
|
143
|
+
- `getMainLoopTimingMode()`
|
|
144
|
+
- `getMainLoopTimingValue()`
|
|
145
|
+
- `setMainLoopTiming(mode, value)`
|
|
146
|
+
- `getFastForwardMultiplier()`
|
|
147
|
+
- `setFastForwardMultiplier(multiplier)`
|
|
148
|
+
- `screenshot(fileName)`
|
|
149
|
+
|
|
150
|
+
Callbacks and core settings:
|
|
151
|
+
|
|
152
|
+
- `addCoreCallbacks(coreCallbacks)`
|
|
153
|
+
- `autoLoadCheats()`
|
|
154
|
+
- `setLogger(callback)`
|
|
155
|
+
- `setCoreSettings(coreSettings)`
|
|
156
|
+
- `toggleRewind(toggle)`
|
|
157
|
+
|
|
158
|
+
See `dist/mgba.d.ts` for full signatures and inline documentation.
|
|
159
|
+
|
|
160
|
+
## Source
|
|
161
|
+
|
|
162
|
+
See the repo [README](https://github.com/thenick775/mgba/tree/feature/wasm#readme) for further details such as:
|
|
46
163
|
|
|
47
|
-
- available emulator interface methods
|
|
48
164
|
- building from source
|
|
49
|
-
-
|
|
165
|
+
- running the bundled demo
|
|
166
|
+
- repository and implementation details
|
package/dist/mgba.d.ts
CHANGED
|
@@ -61,13 +61,13 @@ declare namespace mGBA {
|
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
export type LogLevel =
|
|
64
|
-
|
|
|
65
|
-
|
|
|
66
|
-
|
|
|
67
|
-
|
|
|
68
|
-
|
|
|
69
|
-
|
|
|
70
|
-
|
|
|
64
|
+
| "FATAL"
|
|
65
|
+
| "ERROR"
|
|
66
|
+
| "WARN"
|
|
67
|
+
| "INFO"
|
|
68
|
+
| "DEBUG"
|
|
69
|
+
| "STUB"
|
|
70
|
+
| "GAME ERROR";
|
|
71
71
|
|
|
72
72
|
export type LogEntry = {
|
|
73
73
|
level: LogLevel;
|
|
@@ -75,6 +75,13 @@ declare namespace mGBA {
|
|
|
75
75
|
message: string;
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
+
export type LinkPlayer = 1 | 2; // TODO: more than 2 player support
|
|
79
|
+
|
|
80
|
+
export type LinkLocalStatus = {
|
|
81
|
+
running: boolean;
|
|
82
|
+
activePlayer: LinkPlayer | 0;
|
|
83
|
+
};
|
|
84
|
+
|
|
78
85
|
export type coreSettings = {
|
|
79
86
|
/**
|
|
80
87
|
* Number of frames to skip rendering between screen paints.
|
|
@@ -320,6 +327,31 @@ declare namespace mGBA {
|
|
|
320
327
|
*/
|
|
321
328
|
loadGame(romPath: string, savePathOverride?: string): boolean;
|
|
322
329
|
|
|
330
|
+
/**
|
|
331
|
+
* Starts a local linked GBA session. Version 1 supports two players.
|
|
332
|
+
*/
|
|
333
|
+
linkLocalStartSession(
|
|
334
|
+
player1RomPath: string,
|
|
335
|
+
player1SavePath: string | undefined,
|
|
336
|
+
player2RomPath: string,
|
|
337
|
+
player2SavePath?: string,
|
|
338
|
+
): boolean;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Stops the active local linked session.
|
|
342
|
+
*/
|
|
343
|
+
linkLocalStopSession(): void;
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Selects which linked player is rendered and controlled by normal input APIs.
|
|
347
|
+
*/
|
|
348
|
+
linkLocalSetActivePlayer(player: LinkPlayer): void;
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Gets the current local linked session status.
|
|
352
|
+
*/
|
|
353
|
+
linkLocalGetStatus(): LinkLocalStatus;
|
|
354
|
+
|
|
323
355
|
/**
|
|
324
356
|
* Loads a save state from a given slot.
|
|
325
357
|
*
|
|
@@ -328,6 +360,20 @@ declare namespace mGBA {
|
|
|
328
360
|
*/
|
|
329
361
|
loadState(slot: number): boolean;
|
|
330
362
|
|
|
363
|
+
/**
|
|
364
|
+
* Loads a save state from a given slot using explicit binary literal flags.
|
|
365
|
+
*
|
|
366
|
+
* @deprecated Prefer `loadState(slot)`. This is an old/raw API and may be
|
|
367
|
+
* removed in a future major version.
|
|
368
|
+
*
|
|
369
|
+
* If `flags` is omitted, the runtime uses its default load mask.
|
|
370
|
+
*
|
|
371
|
+
* @param slot - State slot index.
|
|
372
|
+
* @param flags - Bitmask controlling which save state sections are restored.
|
|
373
|
+
* @returns True if the state loaded successfully, otherwise false.
|
|
374
|
+
*/
|
|
375
|
+
loadStateSlot(slot: number, flags?: number): boolean;
|
|
376
|
+
|
|
331
377
|
/**
|
|
332
378
|
* Forces an auto save state capture immediately.
|
|
333
379
|
*
|
|
@@ -403,6 +449,20 @@ declare namespace mGBA {
|
|
|
403
449
|
*/
|
|
404
450
|
saveState(slot: number): boolean;
|
|
405
451
|
|
|
452
|
+
/**
|
|
453
|
+
* Saves a save state to a given slot using explicit binary literal flags.
|
|
454
|
+
*
|
|
455
|
+
* @deprecated Prefer `saveState(slot)`. This is an old/raw API and may be
|
|
456
|
+
* removed in a future major version.
|
|
457
|
+
*
|
|
458
|
+
* If `flags` is omitted, the runtime uses its default save mask.
|
|
459
|
+
*
|
|
460
|
+
* @param slot - State slot index.
|
|
461
|
+
* @param flags - Bitmask controlling which save state sections are written.
|
|
462
|
+
* @returns True if the state saved successfully, otherwise false.
|
|
463
|
+
*/
|
|
464
|
+
saveStateSlot(slot: number, flags?: number): boolean;
|
|
465
|
+
|
|
406
466
|
/**
|
|
407
467
|
* Captures a screenshot and writes it to the screenshots directory.
|
|
408
468
|
*
|