@wasm-gaming/fbneo-wasm 0.1.2 → 0.3.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/README.md +112 -69
- package/dist/fbneo/app/app.css +112 -0
- package/dist/fbneo/app/app.js +646 -0
- package/dist/fbneo/engine-specs.js +646 -0
- package/dist/fbneo/fbneo.js +2 -0
- package/dist/fbneo/fbneo.options.d.ts +72 -19
- package/dist/fbneo/fbneo.options.d.ts.map +1 -1
- package/dist/fbneo/fbneo.options.js +49 -48
- package/dist/fbneo/fbneo.options.js.map +1 -1
- package/dist/fbneo/fbneo.sdk.d.ts +157 -8
- package/dist/fbneo/fbneo.sdk.d.ts.map +1 -1
- package/dist/fbneo/fbneo.sdk.js +641 -181
- package/dist/fbneo/fbneo.sdk.js.map +1 -1
- package/dist/fbneo/fbneo.wasm +4 -0
- package/dist/fbneo/romset.d.ts +0 -0
- package/dist/fbneo/romset.d.ts.map +1 -1
- package/dist/fbneo/romset.js.map +1 -1
- package/{data → dist/fbneo}/romsets/atari.json +5036 -118
- package/{data → dist/fbneo}/romsets/capcom.json +3392 -848
- package/{data → dist/fbneo}/romsets/cave.json +460 -115
- package/{data → dist/fbneo}/romsets/channelf.json +200 -50
- package/{data → dist/fbneo}/romsets/coleco.json +2650 -658
- package/{data → dist/fbneo}/romsets/cps3.json +240 -60
- package/{data → dist/fbneo}/romsets/dataeast.json +1352 -338
- package/{data → dist/fbneo}/romsets/galaxian.json +1192 -298
- package/dist/fbneo/romsets/gba.json +197 -0
- package/{data → dist/fbneo}/romsets/index.json +16 -12
- package/{data → dist/fbneo}/romsets/irem.json +796 -199
- package/{data → dist/fbneo}/romsets/konami.json +1644 -411
- package/{data → dist/fbneo}/romsets/megadrive.json +11899 -2926
- package/{data → dist/fbneo}/romsets/midway.json +560 -140
- package/{data → dist/fbneo}/romsets/msx.json +7204 -1798
- package/{data → dist/fbneo}/romsets/neogeo.json +2704 -614
- package/{data → dist/fbneo}/romsets/nes.json +12815 -3155
- package/{data → dist/fbneo}/romsets/pce.json +1952 -488
- package/{data → dist/fbneo}/romsets/pgm.json +796 -199
- package/{data → dist/fbneo}/romsets/pgm2.json +32 -8
- package/{data → dist/fbneo}/romsets/pre90s.json +10002 -2084
- package/{data → dist/fbneo}/romsets/psikyo.json +160 -40
- package/{data → dist/fbneo}/romsets/pst90s.json +6400 -1597
- package/{data → dist/fbneo}/romsets/sega.json +2756 -658
- package/{data → dist/fbneo}/romsets/sg1000.json +1032 -255
- package/{data → dist/fbneo}/romsets/sms.json +6012 -1503
- package/{data → dist/fbneo}/romsets/snes.json +10991 -2816
- package/{data → dist/fbneo}/romsets/spectrum.json +13579 -3361
- package/{data → dist/fbneo}/romsets/taito.json +2496 -624
- package/{data → dist/fbneo}/romsets/toaplan.json +576 -144
- package/package.json +10 -15
- package/src/app/app.css +112 -0
- package/src/app/app.js +646 -0
- package/src/fbneo.options.ts +119 -63
- package/src/fbneo.sdk.ts +712 -211
- package/src/romset.ts +0 -0
- package/dist/fbneo/fbneo.manifest.d.ts +0 -4
- package/dist/fbneo/fbneo.manifest.d.ts.map +0 -1
- package/dist/fbneo/fbneo.manifest.js +0 -33
- package/dist/fbneo/fbneo.manifest.js.map +0 -1
- package/dist/manifest.json +0 -91
- package/src/fbneo.manifest.ts +0 -38
package/dist/fbneo/fbneo.sdk.js
CHANGED
|
@@ -1,199 +1,659 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The engine package's entry point: an `EngineSDK` for FBNeo (FinalBurn Neo), the
|
|
3
|
+
* arcade emulator.
|
|
4
|
+
*
|
|
5
|
+
* ```js
|
|
6
|
+
* import FbneoSDK from '@wasm-gaming/fbneo-wasm';
|
|
7
|
+
*
|
|
8
|
+
* const play = await new FbneoSDK()
|
|
9
|
+
* .options({ driver: 'mslug' }) // or romFileName: 'mslug.zip'
|
|
10
|
+
* .assets({ rom: () => readZip(), bios: () => readBios() })
|
|
11
|
+
* .storage({ namespace: 'mslug' }) // → OPFS fbneo/mslug/
|
|
12
|
+
* .mount(document.querySelector('#stage'))
|
|
13
|
+
* .start();
|
|
14
|
+
*
|
|
15
|
+
* play.pause('menu'); play.resume('menu');
|
|
16
|
+
* await play.restart(); // soft reset
|
|
17
|
+
* await play.destroy(); // saves flushed, loop stopped
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Everything a host drives is the contract's (`@wasm-gaming/engine-specs`); what is
|
|
21
|
+
* this engine's own: {@link FbneoConfig} and friends, owner-aware
|
|
22
|
+
* {@link FbneoPlay.pause} / {@link FbneoPlay.resume}, {@link FbneoPlay.states},
|
|
23
|
+
* {@link FbneoPlay.storagePath} and the `saves` event.
|
|
24
|
+
*
|
|
25
|
+
* Saves: the build points FBNeo's NVRAM/EEPROM and hiscore paths at MEMFS `/save`.
|
|
26
|
+
* The SDK seeds it from OPFS `fbneo/<namespace>/` before boot and mirrors it back
|
|
27
|
+
* after asking FBNeo to write (`web_persist`): every 10 s, on pause, when the page is
|
|
28
|
+
* hidden and on destroy. Upstream only wrote at exit, which a web page never reaches.
|
|
29
|
+
*/
|
|
30
|
+
import { EnginePlayBase, EngineSDKBase, EventEmitter, } from './engine-specs.js';
|
|
31
|
+
import { FBNEO_SPEC, FBNEO_VIDEO, } from './fbneo.options.js';
|
|
32
|
+
export { FBNEO_SPEC, FBNEO_VIDEO } from './fbneo.options.js';
|
|
33
|
+
import { parseZipEntries } from './romset.js';
|
|
34
|
+
const ENGINE_ID = 'fbneo';
|
|
35
|
+
const DEFAULT_STORAGE_NAMESPACE = 'default';
|
|
36
|
+
const SAVE_DIR = '/save';
|
|
37
|
+
/**
|
|
38
|
+
* FBNeo's ROM search paths (src/burner/sdl/drv.cpp): the absolute one is always
|
|
39
|
+
* searched; `/roms` covers the cwd-relative `roms/` with the cwd at `/`.
|
|
40
|
+
*/
|
|
41
|
+
const ROM_DIRS = ['/usr/local/share/roms', '/roms'];
|
|
42
|
+
const SAVE_INTERVAL_MS = 10_000;
|
|
43
|
+
/** How long a ROM set may take to load before start() gives up. */
|
|
44
|
+
const LOAD_TIMEOUT_MS = 30_000;
|
|
45
|
+
/**
|
|
46
|
+
* Where an engine keeps one namespace: `<engineId>/<namespace>`, relative to the OPFS
|
|
47
|
+
* root. Identical to the other engines': segments cleaned, `.` and `..` dropped,
|
|
48
|
+
* anything outside `[A-Za-z0-9._-]` → `_`, nothing usable → `default`; a leading
|
|
49
|
+
* `<engineId>/` is stripped once.
|
|
50
|
+
*/
|
|
51
|
+
export function storagePath(engineId, namespace) {
|
|
52
|
+
const segments = typeof namespace === 'string'
|
|
53
|
+
? namespace
|
|
54
|
+
.split('/')
|
|
55
|
+
.map((segment) => segment.trim())
|
|
56
|
+
.filter((segment) => segment && segment !== '.' && segment !== '..')
|
|
57
|
+
.map((segment) => segment.replace(/[^A-Za-z0-9._-]/g, '_'))
|
|
58
|
+
: [];
|
|
59
|
+
const prefixed = segments.length > 1 && segments[0] === engineId;
|
|
60
|
+
if (prefixed)
|
|
61
|
+
segments.shift();
|
|
62
|
+
const cleaned = segments.join('/') || DEFAULT_STORAGE_NAMESPACE;
|
|
63
|
+
return { namespace: cleaned, path: `${engineId}/${cleaned}`, prefixed };
|
|
19
64
|
}
|
|
20
|
-
|
|
21
|
-
|
|
65
|
+
/**
|
|
66
|
+
* The FBNeo driver for a session: `driver` when given, else the ROM file name's stem
|
|
67
|
+
* (`mslug.zip`, `C:\roms\mslug.7z` → `mslug`). Empty when neither says.
|
|
68
|
+
*/
|
|
69
|
+
export function driverName(options) {
|
|
70
|
+
const explicit = options.driver?.trim();
|
|
71
|
+
if (explicit)
|
|
72
|
+
return explicit;
|
|
73
|
+
const base = (options.romFileName ?? '').replace(/^.*[\\/]/, '');
|
|
74
|
+
return base.replace(/\.(zip|7z)$/i, '').trim();
|
|
75
|
+
}
|
|
76
|
+
async function opfsDir(path, create) {
|
|
77
|
+
if (typeof navigator === 'undefined' || !navigator.storage?.getDirectory)
|
|
22
78
|
return null;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
79
|
+
try {
|
|
80
|
+
let dir = await navigator.storage.getDirectory();
|
|
81
|
+
for (const segment of path.split('/').filter(Boolean)) {
|
|
82
|
+
dir = await dir.getDirectoryHandle(segment, { create });
|
|
83
|
+
}
|
|
84
|
+
return dir;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
32
89
|
}
|
|
33
|
-
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
90
|
+
async function resolveAsset(asset) {
|
|
91
|
+
const value = typeof asset === 'function' ? await asset() : asset;
|
|
92
|
+
if (value == null)
|
|
93
|
+
return null;
|
|
94
|
+
if (value instanceof Uint8Array)
|
|
95
|
+
return value;
|
|
96
|
+
if (value instanceof ArrayBuffer)
|
|
97
|
+
return new Uint8Array(value);
|
|
98
|
+
throw new TypeError('fbneo: an asset must be a Uint8Array, an ArrayBuffer or a thunk returning one');
|
|
37
99
|
}
|
|
100
|
+
function sameBytes(a, b) {
|
|
101
|
+
if (!a || a.length !== b.length)
|
|
102
|
+
return false;
|
|
103
|
+
for (let i = 0; i < a.length; i++)
|
|
104
|
+
if (a[i] !== b[i])
|
|
105
|
+
return false;
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
const AES_WORLD_CRC = 'd27a71f1'; // neo-epo.bin
|
|
109
|
+
const UNIBIOS_40_CRC = 'a7aab458'; // uni-bios_4_0.rom
|
|
38
110
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* `attachTo` (a container the SDK mounts its own canvas into). Legacy `canvas`
|
|
42
|
-
* is still accepted as a defensive fallback for hosts built against 0.1.x.
|
|
111
|
+
* How to boot a Neo Geo as the AES (the home console) with the BIOS zip at hand: the
|
|
112
|
+
* real AES World BIOS when it is there, else Universe BIOS 4.0 in AES mode, else null.
|
|
43
113
|
*/
|
|
44
|
-
function
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (existing)
|
|
53
|
-
return existing;
|
|
54
|
-
const created = document.createElement('canvas');
|
|
55
|
-
attachTo.appendChild(created);
|
|
56
|
-
return created;
|
|
57
|
-
}
|
|
58
|
-
throw new Error('fbneo: config.canvasEl or config.attachTo is required');
|
|
114
|
+
export function neoGeoAesBios(entries) {
|
|
115
|
+
const crcs = new Set(entries.map((entry) => entry.crc.toLowerCase()));
|
|
116
|
+
if (crcs.has(AES_WORLD_CRC))
|
|
117
|
+
return { bios: 'aes', dips: [['BIOS', 'AES World']] };
|
|
118
|
+
if (crcs.has(UNIBIOS_40_CRC)) {
|
|
119
|
+
return { bios: 'unibios', dips: [['BIOS', 'Universe BIOS (Hack, Ver. 4.0)'], ['Unibios mode', 'AES']] };
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
59
122
|
}
|
|
123
|
+
/** The player's save-state slots: 0-3. */
|
|
124
|
+
export const STATE_SLOTS = 4;
|
|
60
125
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
126
|
+
* The *unsaved* suspend point: written when the player leaves, offered when they come
|
|
127
|
+
* back, and saved into a numbered slot only when they ask.
|
|
63
128
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
129
|
+
export const AUTO_STATE_SLOT = 9;
|
|
130
|
+
const nextFrame = () => new Promise((resolve) => requestAnimationFrame(() => resolve()));
|
|
131
|
+
const mtimeOf = (value) => value instanceof Date ? value.getTime() : typeof value === 'number' ? value : 0;
|
|
132
|
+
/** The live engine: one booted FBNeo and its session. */
|
|
133
|
+
export class FbneoPlay extends EnginePlayBase {
|
|
134
|
+
#module = null;
|
|
135
|
+
#destroyed = false;
|
|
136
|
+
#pauseOwner = null;
|
|
137
|
+
#driver = '';
|
|
138
|
+
#neogeo = null;
|
|
139
|
+
#canvas = null;
|
|
140
|
+
#ownsCanvas = false;
|
|
141
|
+
#box = null;
|
|
142
|
+
#boxObserver = null;
|
|
143
|
+
#canvasObserver = null;
|
|
144
|
+
#namespace = DEFAULT_STORAGE_NAMESPACE;
|
|
145
|
+
#storagePath = `${ENGINE_ID}/${DEFAULT_STORAGE_NAMESPACE}`;
|
|
146
|
+
#persist = true;
|
|
147
|
+
#saveTimer = null;
|
|
148
|
+
#lastSaved = new Map();
|
|
149
|
+
#flushing = null;
|
|
150
|
+
#onHidden = () => {
|
|
151
|
+
if (document.visibilityState === 'hidden')
|
|
152
|
+
void this.flushSaves();
|
|
153
|
+
};
|
|
154
|
+
constructor(init, events) {
|
|
155
|
+
super(FBNEO_SPEC, init, events);
|
|
156
|
+
}
|
|
157
|
+
/** The normalised namespace this session uses. */
|
|
158
|
+
get namespace() {
|
|
159
|
+
return this.#namespace;
|
|
160
|
+
}
|
|
161
|
+
/** Where this session's saves live, relative to the OPFS root: `fbneo/<namespace>`. */
|
|
162
|
+
get storagePath() {
|
|
163
|
+
return this.#storagePath;
|
|
164
|
+
}
|
|
165
|
+
/** The driver (ROM-set short name) this session booted. */
|
|
166
|
+
get driver() {
|
|
167
|
+
return this.#driver;
|
|
168
|
+
}
|
|
169
|
+
/** How a Neo Geo set was booted as the AES: `{ mode, bios, card }`; null otherwise. */
|
|
170
|
+
get neogeo() {
|
|
171
|
+
return this.#neogeo;
|
|
172
|
+
}
|
|
173
|
+
/** Who holds the pause, or null while running. */
|
|
174
|
+
get pausedBy() {
|
|
175
|
+
return this.#pauseOwner;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* The current frame as a PNG (also while paused: the picture is kept). Null when
|
|
179
|
+
* there is nothing to read.
|
|
180
|
+
*/
|
|
181
|
+
async snapshot() {
|
|
182
|
+
const canvas = this.#canvas;
|
|
183
|
+
if (!canvas || !this.#module)
|
|
184
|
+
return null;
|
|
185
|
+
await nextFrame();
|
|
186
|
+
const copy = document.createElement('canvas');
|
|
187
|
+
copy.width = canvas.width || FBNEO_VIDEO.width;
|
|
188
|
+
copy.height = canvas.height || FBNEO_VIDEO.height;
|
|
189
|
+
copy.getContext('2d')?.drawImage(canvas, 0, 0, copy.width, copy.height);
|
|
190
|
+
return new Promise((resolve) => copy.toBlob((blob) => resolve(blob), 'image/png'));
|
|
191
|
+
}
|
|
192
|
+
/** Save states — see {@link FbneoStates}. */
|
|
193
|
+
get states() {
|
|
194
|
+
const Module = this.#requireModule();
|
|
195
|
+
const { FS } = Module;
|
|
196
|
+
const file = (name) => `${SAVE_DIR}/${name}`;
|
|
197
|
+
const exists = (name) => {
|
|
198
|
+
try {
|
|
199
|
+
FS.stat(file(name));
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
const stateName = (slot) => `slot_${slot}.fs`;
|
|
207
|
+
const mtime = (name) => {
|
|
208
|
+
try {
|
|
209
|
+
return mtimeOf(FS.stat(file(name)).mtime);
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
const checkSlot = (slot) => {
|
|
216
|
+
if (slot === AUTO_STATE_SLOT || (Number.isInteger(slot) && slot >= 0 && slot < STATE_SLOTS))
|
|
217
|
+
return slot;
|
|
218
|
+
throw new RangeError(`fbneo: a state slot is 0-${STATE_SLOTS - 1} or ${AUTO_STATE_SLOT}, not ${slot}`);
|
|
219
|
+
};
|
|
220
|
+
const isLocked = (slot) => exists(`slot_${slot}.lock`);
|
|
221
|
+
const refuseLocked = (slot) => {
|
|
222
|
+
if (isLocked(slot))
|
|
223
|
+
throw new Error(`fbneo: state slot ${slot} is locked`);
|
|
224
|
+
};
|
|
225
|
+
// Removed files have to leave OPFS too: the mirror only ever writes.
|
|
226
|
+
const forget = async (names) => {
|
|
227
|
+
for (const name of names) {
|
|
228
|
+
try {
|
|
229
|
+
FS.unlink(file(name));
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
/* not there */
|
|
233
|
+
}
|
|
234
|
+
this.#lastSaved.delete(name);
|
|
235
|
+
}
|
|
236
|
+
const dir = this.#persist ? await opfsDir(this.#storagePath, false) : null;
|
|
237
|
+
for (const name of names)
|
|
238
|
+
await dir?.removeEntry(name).catch(() => { });
|
|
239
|
+
};
|
|
240
|
+
const get = (slot) => {
|
|
241
|
+
checkSlot(slot);
|
|
242
|
+
const savedAt = mtime(stateName(slot));
|
|
243
|
+
let thumbnail = null;
|
|
244
|
+
if (savedAt !== null && exists(`slot_${slot}.png`)) {
|
|
245
|
+
thumbnail = new Blob([new Uint8Array(FS.readFile(file(`slot_${slot}.png`)))], { type: 'image/png' });
|
|
246
|
+
}
|
|
247
|
+
return { slot, savedAt: savedAt === null ? null : new Date(savedAt), thumbnail, locked: isLocked(slot) };
|
|
248
|
+
};
|
|
249
|
+
return {
|
|
250
|
+
list: () => Array.from({ length: STATE_SLOTS }, (_, slot) => get(slot)),
|
|
251
|
+
get,
|
|
252
|
+
save: async (slot, options = {}) => {
|
|
253
|
+
checkSlot(slot);
|
|
254
|
+
refuseLocked(slot);
|
|
255
|
+
// FBNeo writes the state at once (between frames: JS only runs while its loop sleeps).
|
|
256
|
+
if (!Module._web_save_state(slot))
|
|
257
|
+
throw new Error('fbneo: the state could not be saved (no game running?)');
|
|
258
|
+
if (options.thumbnail) {
|
|
259
|
+
FS.writeFile(file(`slot_${slot}.png`), new Uint8Array(await options.thumbnail.arrayBuffer()));
|
|
260
|
+
}
|
|
261
|
+
else
|
|
262
|
+
await forget([`slot_${slot}.png`]);
|
|
263
|
+
await this.flushSaves();
|
|
264
|
+
},
|
|
265
|
+
load: (slot) => {
|
|
266
|
+
checkSlot(slot);
|
|
267
|
+
if (mtime(stateName(slot)) === null)
|
|
268
|
+
return false;
|
|
269
|
+
return Module._web_load_state(slot) !== 0;
|
|
270
|
+
},
|
|
271
|
+
copy: async (from, to) => {
|
|
272
|
+
checkSlot(from);
|
|
273
|
+
checkSlot(to);
|
|
274
|
+
refuseLocked(to);
|
|
275
|
+
if (mtime(stateName(from)) === null)
|
|
276
|
+
throw new Error(`fbneo: state slot ${from} is empty`);
|
|
277
|
+
await forget([stateName(to), `slot_${to}.png`]);
|
|
278
|
+
FS.writeFile(file(stateName(to)), new Uint8Array(FS.readFile(file(stateName(from)))));
|
|
279
|
+
if (exists(`slot_${from}.png`)) {
|
|
280
|
+
FS.writeFile(file(`slot_${to}.png`), new Uint8Array(FS.readFile(file(`slot_${from}.png`))));
|
|
281
|
+
}
|
|
282
|
+
await this.flushSaves();
|
|
283
|
+
},
|
|
284
|
+
lock: async (slot, locked) => {
|
|
285
|
+
checkSlot(slot);
|
|
286
|
+
if (locked) {
|
|
287
|
+
if (mtime(stateName(slot)) === null)
|
|
288
|
+
throw new Error(`fbneo: state slot ${slot} is empty`);
|
|
289
|
+
FS.writeFile(file(`slot_${slot}.lock`), new Uint8Array([1]));
|
|
290
|
+
await this.flushSaves();
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
await forget([`slot_${slot}.lock`]);
|
|
294
|
+
this.emit('saves', { files: [`slot_${slot}.lock`] });
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
remove: async (slot) => {
|
|
298
|
+
checkSlot(slot);
|
|
299
|
+
refuseLocked(slot);
|
|
300
|
+
const names = [stateName(slot), `slot_${slot}.png`];
|
|
301
|
+
await forget(names);
|
|
302
|
+
this.emit('saves', { files: names });
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
#requireModule() {
|
|
307
|
+
if (!this.#module)
|
|
308
|
+
throw new Error('fbneo: the engine is not running — start() it first');
|
|
309
|
+
return this.#module;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Freeze emulation and sound. The first caller owns the pause, and only that
|
|
313
|
+
* owner's {@link resume} lifts it, so an overlay cannot resume a game the host had
|
|
314
|
+
* already frozen. Saves are flushed, since a paused game is often a closed one.
|
|
315
|
+
*/
|
|
316
|
+
pause(owner = 'host') {
|
|
317
|
+
const Module = this.#module;
|
|
318
|
+
if (!Module || this.#pauseOwner)
|
|
319
|
+
return;
|
|
320
|
+
this.#pauseOwner = owner;
|
|
321
|
+
Module._web_set_paused(1);
|
|
322
|
+
void Module.SDL2?.audioContext?.suspend();
|
|
323
|
+
void this.flushSaves();
|
|
324
|
+
this.emit('pause', { owner });
|
|
325
|
+
}
|
|
326
|
+
resume(owner = 'host') {
|
|
327
|
+
const Module = this.#module;
|
|
328
|
+
if (!Module || this.#pauseOwner !== owner)
|
|
329
|
+
return;
|
|
330
|
+
this.#pauseOwner = null;
|
|
331
|
+
void Module.SDL2?.audioContext?.resume();
|
|
332
|
+
Module._web_set_paused(0);
|
|
333
|
+
this.emit('resume', { owner });
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Ask FBNeo to write its NVRAM, then copy whatever changed in `/save` to OPFS
|
|
337
|
+
* `fbneo/<namespace>/`. Emits `saves` with the files that moved. Safe to call any
|
|
338
|
+
* time; overlapping calls share one flush.
|
|
339
|
+
*/
|
|
340
|
+
flushSaves() {
|
|
341
|
+
this.#flushing ??= this.#flush().finally(() => {
|
|
342
|
+
this.#flushing = null;
|
|
343
|
+
});
|
|
344
|
+
return this.#flushing;
|
|
345
|
+
}
|
|
346
|
+
// ---- Contract hooks ----
|
|
347
|
+
mounted(target) {
|
|
348
|
+
if (target instanceof HTMLCanvasElement) {
|
|
349
|
+
this.#canvas = target;
|
|
350
|
+
this.#ownsCanvas = false;
|
|
351
|
+
this.#box = target.parentElement;
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
this.#canvas = document.createElement('canvas');
|
|
355
|
+
this.#ownsCanvas = true;
|
|
356
|
+
this.#box = target;
|
|
357
|
+
target.appendChild(this.#canvas);
|
|
358
|
+
}
|
|
359
|
+
const canvas = this.#canvas;
|
|
360
|
+
// Emscripten's SDL2 finds its window by id, and measures the element: no border or
|
|
361
|
+
// padding on the canvas itself, or SDL creates a tiny window.
|
|
66
362
|
canvas.id = 'canvas';
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
363
|
+
if (!canvas.width)
|
|
364
|
+
canvas.width = FBNEO_VIDEO.width;
|
|
365
|
+
if (!canvas.height)
|
|
366
|
+
canvas.height = FBNEO_VIDEO.height;
|
|
367
|
+
canvas.tabIndex = 0;
|
|
368
|
+
canvas.style.border = '0';
|
|
369
|
+
canvas.style.padding = '0';
|
|
370
|
+
canvas.style.display = 'block';
|
|
371
|
+
canvas.addEventListener('contextmenu', (event) => event.preventDefault());
|
|
372
|
+
void this.#applyFilter();
|
|
373
|
+
if (this.#box && this.#ownsCanvas) {
|
|
374
|
+
this.#boxObserver?.disconnect();
|
|
375
|
+
this.#boxObserver = new ResizeObserver(() => this.#fit());
|
|
376
|
+
this.#boxObserver.observe(this.#box);
|
|
377
|
+
// FBNeo sizes the canvas to each game's picture (vertical games too): refit then.
|
|
378
|
+
this.#canvasObserver?.disconnect();
|
|
379
|
+
this.#canvasObserver = new MutationObserver(() => this.#fit());
|
|
380
|
+
this.#canvasObserver.observe(canvas, { attributes: true, attributeFilter: ['width', 'height'] });
|
|
381
|
+
this.#fit();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
async open(_options) {
|
|
385
|
+
if (this.#destroyed) {
|
|
386
|
+
throw new Error('fbneo: this engine has been destroyed and cannot be started again in this page — build a new FbneoSDK in a new page');
|
|
387
|
+
}
|
|
388
|
+
if (this.#module) {
|
|
389
|
+
// Already running: a restart is the machine's soft reset.
|
|
390
|
+
if (this.#pauseOwner)
|
|
391
|
+
this.resume(this.#pauseOwner);
|
|
392
|
+
this.#module._web_reset();
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
await this.#boot();
|
|
396
|
+
}
|
|
397
|
+
patched(kind, patch) {
|
|
398
|
+
if (kind === 'config' && 'renderFilter' in patch)
|
|
399
|
+
void this.#applyFilter();
|
|
400
|
+
}
|
|
401
|
+
async close() {
|
|
402
|
+
if (this.#saveTimer)
|
|
403
|
+
clearInterval(this.#saveTimer);
|
|
404
|
+
this.#saveTimer = null;
|
|
405
|
+
document.removeEventListener('visibilitychange', this.#onHidden);
|
|
406
|
+
window.removeEventListener('pagehide', this.#onHidden);
|
|
407
|
+
const Module = this.#module;
|
|
408
|
+
if (Module) {
|
|
409
|
+
await this.flushSaves();
|
|
410
|
+
const context = Module.SDL2?.audioContext;
|
|
411
|
+
try {
|
|
412
|
+
Module._web_set_paused(1);
|
|
413
|
+
// Ends FBNeo's loop: it exits the game its own way (NVRAM written, sound closed).
|
|
414
|
+
Module._web_quit();
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
/* already gone */
|
|
418
|
+
}
|
|
419
|
+
// FBNeo's exit closes the AudioContext on the loop's next turn; close it here only
|
|
420
|
+
// if it didn't (closing it first makes FBNeo's own close throw).
|
|
421
|
+
const deadline = performance.now() + 1000;
|
|
422
|
+
while (context && context.state !== 'closed' && performance.now() < deadline) {
|
|
423
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
424
|
+
}
|
|
425
|
+
if (context && context.state !== 'closed')
|
|
426
|
+
await context.close().catch(() => { });
|
|
427
|
+
}
|
|
428
|
+
this.#boxObserver?.disconnect();
|
|
429
|
+
this.#boxObserver = null;
|
|
430
|
+
this.#canvasObserver?.disconnect();
|
|
431
|
+
this.#canvasObserver = null;
|
|
432
|
+
if (this.#ownsCanvas)
|
|
433
|
+
this.#canvas?.remove();
|
|
434
|
+
this.#canvas = null;
|
|
435
|
+
this.#module = null;
|
|
436
|
+
this.#pauseOwner = null;
|
|
437
|
+
this.#destroyed = true;
|
|
438
|
+
}
|
|
439
|
+
// ---- Boot ----
|
|
440
|
+
async #boot() {
|
|
441
|
+
const config = await this.#values('config');
|
|
442
|
+
const options = await this.#values('options');
|
|
443
|
+
const assets = await this.#values('assets');
|
|
444
|
+
const storage = await this.#values('storage');
|
|
445
|
+
if (!this.#canvas) {
|
|
446
|
+
throw new Error('fbneo: mount() an element (or a canvas) before start()');
|
|
447
|
+
}
|
|
448
|
+
const driver = driverName(options);
|
|
449
|
+
if (!driver) {
|
|
450
|
+
throw new Error('fbneo: which game is it? Pass options.driver (the FBNeo short name, e.g. "mslug") ' +
|
|
451
|
+
'or options.romFileName named after it (mslug.zip).');
|
|
452
|
+
}
|
|
453
|
+
const rom = await resolveAsset(assets.rom);
|
|
454
|
+
if (!rom)
|
|
455
|
+
throw new Error('fbneo: no ROM set — hand one over as assets.rom (bytes or a thunk)');
|
|
456
|
+
const bios = await resolveAsset(assets.bios);
|
|
457
|
+
this.#driver = driver;
|
|
458
|
+
const resolved = storagePath(ENGINE_ID, storage.namespace);
|
|
459
|
+
this.#namespace = resolved.namespace;
|
|
460
|
+
this.#storagePath = resolved.path;
|
|
461
|
+
this.#persist = storage.persist !== null;
|
|
462
|
+
const jsUrl = config.jsUrl ?? new URL('./fbneo.js', import.meta.url).href;
|
|
463
|
+
const wasmUrl = config.wasmUrl ?? new URL('./fbneo.wasm', import.meta.url).href;
|
|
464
|
+
const { default: createFbneoModule } = (await import(/* @vite-ignore */ jsUrl));
|
|
465
|
+
// The context SDL will use, made first so it keeps its picture between frames:
|
|
466
|
+
// FBNeo draws from timers, not animation frames, so without this snapshot() (the
|
|
467
|
+
// app's suspend-point frames) reads a cleared buffer. SDL gets this one back.
|
|
468
|
+
this.#canvas.getContext('webgl', { preserveDrawingBuffer: true, antialias: false });
|
|
469
|
+
let failed = null;
|
|
470
|
+
// FBNeo reports a set it could not load only on stdout (then main() returns).
|
|
471
|
+
let refused = null;
|
|
472
|
+
const Module = await createFbneoModule({
|
|
473
|
+
canvas: this.#canvas,
|
|
474
|
+
noInitialRun: true,
|
|
475
|
+
locateFile: (path) => (path.endsWith('.wasm') ? wasmUrl : new URL(path, jsUrl).href),
|
|
476
|
+
print: (text) => {
|
|
477
|
+
if (/error loading your selected game/i.test(text))
|
|
478
|
+
refused = text;
|
|
479
|
+
console.log('[fbneo]', text);
|
|
480
|
+
},
|
|
481
|
+
printErr: (text) => console.warn('[fbneo]', text),
|
|
482
|
+
onAbort: (what) => failed?.(new Error(`fbneo: aborted — ${String(what)}`)),
|
|
483
|
+
});
|
|
484
|
+
this.#module = Module;
|
|
485
|
+
failed = (error) => this.emit('error', error);
|
|
486
|
+
const { FS } = Module;
|
|
487
|
+
// FBNeo finds a game by `<driver>.zip` in its ROM paths, and matches the files
|
|
488
|
+
// inside by name/CRC: whatever the player named the file, it lands as that.
|
|
489
|
+
for (const dir of ROM_DIRS) {
|
|
490
|
+
FS.mkdirTree(dir);
|
|
491
|
+
FS.writeFile(`${dir}/${driver}.zip`, rom);
|
|
492
|
+
if (bios)
|
|
493
|
+
FS.writeFile(`${dir}/neogeo.zip`, bios);
|
|
494
|
+
}
|
|
495
|
+
FS.mkdirTree(SAVE_DIR);
|
|
496
|
+
if (this.#persist)
|
|
497
|
+
await this.#restoreSaves();
|
|
498
|
+
// callMain() returns at FBNeo's first yield, before the set is loaded: wait for
|
|
499
|
+
// the game to run, or for FBNeo to say it refused the set, so a bad set is an
|
|
500
|
+
// error here and not a black screen.
|
|
501
|
+
Module.callMain([driver]);
|
|
502
|
+
const deadline = performance.now() + LOAD_TIMEOUT_MS;
|
|
503
|
+
while (!Module._web_running() && !refused && performance.now() < deadline) {
|
|
504
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
505
|
+
}
|
|
506
|
+
if (!Module._web_running()) {
|
|
507
|
+
throw new Error(refused
|
|
508
|
+
? `fbneo: FBNeo could not load "${driver}" — the ROM set is incomplete, is not that driver, or needs a BIOS (neogeo.zip for Neo Geo)`
|
|
509
|
+
: `fbneo: "${driver}" did not start within ${LOAD_TIMEOUT_MS / 1000} s`);
|
|
510
|
+
}
|
|
511
|
+
if (options.neogeo === 'aes')
|
|
512
|
+
await this.#bootAes(Module, bios);
|
|
513
|
+
if (this.#persist) {
|
|
514
|
+
this.#saveTimer = setInterval(() => void this.flushSaves(), SAVE_INTERVAL_MS);
|
|
515
|
+
document.addEventListener('visibilitychange', this.#onHidden);
|
|
516
|
+
window.addEventListener('pagehide', this.#onHidden);
|
|
517
|
+
}
|
|
518
|
+
this.#fit();
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Neo Geo as the AES: pick the BIOS from the BIOS zip, set the driver's BIOS settings,
|
|
522
|
+
* insert the game's memory card and reset, so the machine boots that BIOS (FBNeo
|
|
523
|
+
* loads it at reset). A set that isn't Neo Geo has no "BIOS" setting: left as is.
|
|
524
|
+
*/
|
|
525
|
+
async #bootAes(Module, bios) {
|
|
526
|
+
let choice = null;
|
|
82
527
|
try {
|
|
83
|
-
|
|
528
|
+
choice = bios ? neoGeoAesBios(parseZipEntries(bios)) : null;
|
|
84
529
|
}
|
|
85
530
|
catch {
|
|
86
|
-
|
|
531
|
+
choice = null; // not a zip: no BIOS to choose from
|
|
87
532
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
...DEFAULT_FBNEO_OPTIONS,
|
|
95
|
-
...rawOptions,
|
|
96
|
-
romFileName: rawOptions?.romFileName ??
|
|
97
|
-
rawOptions?.fileName ??
|
|
98
|
-
DEFAULT_FBNEO_OPTIONS.romFileName,
|
|
99
|
-
};
|
|
100
|
-
const romBytes = toUint8(assets?.rom ?? assets?.data);
|
|
101
|
-
if (!romBytes) {
|
|
102
|
-
throw new Error('fbneo: no ROM bytes provided — pass assets.rom (an arcade ROM zip)');
|
|
103
|
-
}
|
|
104
|
-
const biosBytes = toUint8(assets?.bios);
|
|
105
|
-
const canvas = prepareCanvas(resolveCanvas(config), opts.renderFilter);
|
|
106
|
-
// FBNeo boots a game by its ROM-set short name ("driver", e.g. "mslug") and
|
|
107
|
-
// searches its ROM paths for a matching `<driver>.zip`. Prefer an explicit
|
|
108
|
-
// `options.driver`; otherwise derive it from the ROM filename (stripping the
|
|
109
|
-
// extension). Whatever the source, the zip is mounted as `<driver>.zip` so the
|
|
110
|
-
// name FBNeo looks up and the name on disk always agree.
|
|
111
|
-
const driver = (opts.driver || driverFromFileName(opts.romFileName)).trim();
|
|
112
|
-
if (!driver || driver === 'game') {
|
|
113
|
-
throw new Error('fbneo: could not determine the ROM-set name. Pass options.driver (the FBNeo ' +
|
|
114
|
-
'short name, e.g. "mslug") or name the ROM file after it (e.g. mslug.zip).');
|
|
115
|
-
}
|
|
116
|
-
const romFileName = `${driver}.zip`;
|
|
117
|
-
const jsUrl = config.jsUrl ?? new URL('./fbneo.js', import.meta.url).href;
|
|
118
|
-
const wasmUrl = config.wasmUrl ?? new URL('./fbneo.wasm', jsUrl).href;
|
|
119
|
-
let modRef = null;
|
|
120
|
-
let readyResolve = () => { };
|
|
121
|
-
const readyPromise = new Promise((resolve) => {
|
|
122
|
-
readyResolve = resolve;
|
|
123
|
-
});
|
|
124
|
-
// FBNeo's default ROM search paths (src/burner/sdl/drv.cpp) are the absolute
|
|
125
|
-
// "/usr/local/share/roms/" and the cwd-relative "roms/". Under Emscripten the
|
|
126
|
-
// cwd is not guaranteed to be "/", so write to the absolute path (always
|
|
127
|
-
// searched) as well as "/roms/". FBNeo matches ROM files inside each zip by
|
|
128
|
-
// name/CRC, so the zip must be named after the driver.
|
|
129
|
-
const romDirs = ['/usr/local/share/roms', '/roms'];
|
|
130
|
-
const writeRoms = (mod) => {
|
|
131
|
-
for (const dir of romDirs) {
|
|
132
|
-
mod.FS.mkdirTree(dir);
|
|
133
|
-
mod.FS.writeFile(`${dir}/${romFileName}`, romBytes);
|
|
134
|
-
if (biosBytes)
|
|
135
|
-
mod.FS.writeFile(`${dir}/neogeo.zip`, biosBytes);
|
|
533
|
+
const setDip = (group, option) => Module.ccall('web_set_dip', 'number', ['string', 'string'], [group, option]) === 1;
|
|
534
|
+
if (!choice) {
|
|
535
|
+
// Only a Neo Geo driver has the setting; anything else plays as it always has.
|
|
536
|
+
if (!setDip('BIOS', 'AES World'))
|
|
537
|
+
return;
|
|
538
|
+
throw new Error('fbneo: Neo Geo as the AES needs a BIOS zip (neogeo.zip) with the AES BIOS (neo-epo.bin) or Universe BIOS 4.0');
|
|
136
539
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
readyResolve();
|
|
163
|
-
await readyPromise;
|
|
164
|
-
let running = false;
|
|
165
|
-
const boot = () => {
|
|
166
|
-
if (running)
|
|
540
|
+
for (const [group, option] of choice.dips) {
|
|
541
|
+
if (!setDip(group, option)) {
|
|
542
|
+
if (group === 'BIOS')
|
|
543
|
+
return; // not a Neo Geo set
|
|
544
|
+
throw new Error(`fbneo: this FBNeo build has no "${group}: ${option}" setting`);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
const card = Module._web_memcard_insert() === 1;
|
|
548
|
+
// The settings reach the driver on the next frame; the BIOS is loaded at reset.
|
|
549
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
550
|
+
Module._web_reset();
|
|
551
|
+
this.#neogeo = { mode: 'aes', bios: choice.bios, card };
|
|
552
|
+
}
|
|
553
|
+
/** The plain values behind one payload's descriptors. */
|
|
554
|
+
async #values(kind) {
|
|
555
|
+
const described = (await this[kind]());
|
|
556
|
+
const out = {};
|
|
557
|
+
for (const [key, property] of Object.entries(described))
|
|
558
|
+
out[key] = property.value;
|
|
559
|
+
return out;
|
|
560
|
+
}
|
|
561
|
+
// ---- Saves ----
|
|
562
|
+
async #restoreSaves() {
|
|
563
|
+
const dir = await opfsDir(this.#storagePath, false);
|
|
564
|
+
if (!dir || !this.#module)
|
|
167
565
|
return;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
566
|
+
const iterable = dir;
|
|
567
|
+
for await (const [name, handle] of iterable.entries()) {
|
|
568
|
+
if (handle.kind !== 'file')
|
|
569
|
+
continue;
|
|
570
|
+
const bytes = new Uint8Array(await (await handle.getFile()).arrayBuffer());
|
|
571
|
+
this.#module.FS.writeFile(`${SAVE_DIR}/${name}`, bytes);
|
|
572
|
+
this.#lastSaved.set(name, bytes);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
async #flush() {
|
|
576
|
+
const Module = this.#module;
|
|
577
|
+
if (!Module || !this.#persist)
|
|
578
|
+
return;
|
|
579
|
+
try {
|
|
580
|
+
Module._web_persist();
|
|
581
|
+
}
|
|
582
|
+
catch (e) {
|
|
583
|
+
console.warn('[fbneo] persist failed', e);
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
const changed = [];
|
|
587
|
+
for (const name of Module.FS.readdir(SAVE_DIR)) {
|
|
588
|
+
if (name === '.' || name === '..')
|
|
589
|
+
continue;
|
|
590
|
+
const path = `${SAVE_DIR}/${name}`;
|
|
591
|
+
if (!Module.FS.isFile(Module.FS.stat(path).mode))
|
|
592
|
+
continue;
|
|
593
|
+
const bytes = new Uint8Array(Module.FS.readFile(path));
|
|
594
|
+
if (!sameBytes(this.#lastSaved.get(name), bytes))
|
|
595
|
+
changed.push([name, bytes]);
|
|
596
|
+
}
|
|
597
|
+
if (changed.length === 0)
|
|
598
|
+
return;
|
|
599
|
+
const dir = await opfsDir(this.#storagePath, true);
|
|
600
|
+
if (!dir)
|
|
601
|
+
return;
|
|
602
|
+
const written = [];
|
|
603
|
+
for (const [name, bytes] of changed) {
|
|
604
|
+
try {
|
|
605
|
+
const writable = await (await dir.getFileHandle(name, { create: true })).createWritable();
|
|
606
|
+
await writable.write(bytes);
|
|
607
|
+
await writable.close();
|
|
608
|
+
this.#lastSaved.set(name, bytes);
|
|
609
|
+
written.push(name);
|
|
610
|
+
}
|
|
611
|
+
catch (e) {
|
|
612
|
+
console.warn(`[fbneo] could not persist ${name}`, e);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (written.length)
|
|
616
|
+
this.emit('saves', { files: written });
|
|
617
|
+
}
|
|
618
|
+
// ---- Picture ----
|
|
619
|
+
/** Scale the canvas to fit its box, keeping the picture's own proportions. */
|
|
620
|
+
#fit() {
|
|
621
|
+
const canvas = this.#canvas;
|
|
622
|
+
const box = this.#box;
|
|
623
|
+
if (!canvas || !box || !this.#ownsCanvas)
|
|
624
|
+
return;
|
|
625
|
+
const { width, height } = box.getBoundingClientRect();
|
|
626
|
+
const w = canvas.width || FBNEO_VIDEO.width;
|
|
627
|
+
const h = canvas.height || FBNEO_VIDEO.height;
|
|
628
|
+
if (!width || !height)
|
|
629
|
+
return;
|
|
630
|
+
const scale = Math.min(width / w, height / h);
|
|
631
|
+
canvas.style.width = `${Math.floor(w * scale)}px`;
|
|
632
|
+
canvas.style.height = `${Math.floor(h * scale)}px`;
|
|
633
|
+
}
|
|
634
|
+
async #applyFilter() {
|
|
635
|
+
const canvas = this.#canvas;
|
|
636
|
+
if (!canvas)
|
|
637
|
+
return;
|
|
638
|
+
const { renderFilter } = await this.#values('config');
|
|
639
|
+
canvas.style.imageRendering = renderFilter === 'smooth' ? 'auto' : 'pixelated';
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* The factory a host constructs: static identity, the configuration chain, and a
|
|
644
|
+
* `start()` that boots FBNeo and opens a session.
|
|
645
|
+
*/
|
|
646
|
+
export class FbneoSDK extends EngineSDKBase {
|
|
647
|
+
static id = ENGINE_ID;
|
|
648
|
+
/** Kept in step with package.json by `node scripts/sync-version.mjs`. */
|
|
649
|
+
static version = '0.3.0';
|
|
650
|
+
static name = 'FinalBurn Neo';
|
|
651
|
+
static description = 'FBNeo, the arcade emulator (Capcom CPS-1/2/3, SNK Neo Geo, Sega System 16 and more), compiled to WebAssembly. Ships no games: the player provides the ROM sets, and they never leave their browser.';
|
|
652
|
+
createPlay(init, events) {
|
|
653
|
+
return new FbneoPlay(init, events);
|
|
654
|
+
}
|
|
197
655
|
}
|
|
198
|
-
|
|
656
|
+
/** CI's conformance line: if this class stops satisfying the contract, `make test` fails. */
|
|
657
|
+
export const FBNEO_ENGINE = FbneoSDK;
|
|
658
|
+
export default FbneoSDK;
|
|
199
659
|
//# sourceMappingURL=fbneo.sdk.js.map
|