@thenick775/mgba-wasm 2.5.0 → 2.5.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 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
- This core uses threads, you must serve these files in a way that supports cross origin isolation:
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
- See the feature/wasm [README](https://github.com/thenick775/mgba/tree/feature/wasm#readme) for further details such as:
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
- - embedding and usage in vanilla javascript
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
- | 'FATAL'
65
- | 'ERROR'
66
- | 'WARN'
67
- | 'INFO'
68
- | 'DEBUG'
69
- | 'STUB'
70
- | 'GAME ERROR';
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;
@@ -328,6 +328,20 @@ declare namespace mGBA {
328
328
  */
329
329
  loadState(slot: number): boolean;
330
330
 
331
+ /**
332
+ * Loads a save state from a given slot using explicit binary literal flags.
333
+ *
334
+ * @deprecated Prefer `loadState(slot)`. This is an old/raw API and may be
335
+ * removed in a future major version.
336
+ *
337
+ * If `flags` is omitted, the runtime uses its default load mask.
338
+ *
339
+ * @param slot - State slot index.
340
+ * @param flags - Bitmask controlling which save state sections are restored.
341
+ * @returns True if the state loaded successfully, otherwise false.
342
+ */
343
+ loadStateSlot(slot: number, flags?: number): boolean;
344
+
331
345
  /**
332
346
  * Forces an auto save state capture immediately.
333
347
  *
@@ -403,6 +417,20 @@ declare namespace mGBA {
403
417
  */
404
418
  saveState(slot: number): boolean;
405
419
 
420
+ /**
421
+ * Saves a save state to a given slot using explicit binary literal flags.
422
+ *
423
+ * @deprecated Prefer `saveState(slot)`. This is an old/raw API and may be
424
+ * removed in a future major version.
425
+ *
426
+ * If `flags` is omitted, the runtime uses its default save mask.
427
+ *
428
+ * @param slot - State slot index.
429
+ * @param flags - Bitmask controlling which save state sections are written.
430
+ * @returns True if the state saved successfully, otherwise false.
431
+ */
432
+ saveStateSlot(slot: number, flags?: number): boolean;
433
+
406
434
  /**
407
435
  * Captures a screenshot and writes it to the screenshots directory.
408
436
  *
package/dist/mgba.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thenick775/mgba-wasm",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "description": "mGBA emulator compiled to webassembly",
5
5
  "main": "./dist/mgba.js",
6
6
  "types": "./dist/mgba.d.ts",
@@ -15,7 +15,14 @@
15
15
  "build:image": "cd ./docker && docker build -t local-mgba/wasm:2.0 . && echo 'Image Built Successfully!'",
16
16
  "prepare": "mkdir -p ./dist && cp -r ../../../build-wasm/wasm/* ./dist/ || { echo 'Copy failed'; exit 1; }",
17
17
  "prepack": "npm run prepare",
18
- "clean": "rm -rf ./dist"
18
+ "clean": "rm -rf ./dist",
19
+ "typedoc": "typedoc --options typedoc.json"
20
+ },
21
+ "devDependencies": {
22
+ "@types/emscripten": "^1.41.5",
23
+ "typedoc": "^0.28.20",
24
+ "typedoc-github-theme": "^0.4.0",
25
+ "typescript": "^6.0.3"
19
26
  },
20
27
  "repository": {
21
28
  "type": "git",