-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathmemory.js
701 lines (564 loc) · 20.7 KB
/
memory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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
163
164
165
166
167
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
import { idbKeyval } from './idb';
// Import worker stuff
import { WORKER_MESSAGE_TYPE, MEMORY_TYPE } from '../worker/constants';
import { getEventData } from '../worker/util';
// Fetch rom
import { fetchROMAsByteArray } from '../wasmboy/fetchrom';
// import Functions involving GB and WasmBoy memory
import { getSaveState } from './state.js';
import { initializeAutoSave } from './autosave.js';
const BOOT_ROM_KEY = 'boot-rom-';
class WasmBoyMemoryService {
constructor() {
this.worker = undefined;
this.maxNumberOfAutoSaveStates = undefined;
this.saveStateCallback = undefined;
this.loadedCartridgeMemoryState = {
ROM: false,
RAM: false,
BOOT: false
};
// Our different types of memory
this.bootRom = undefined;
this.cartridgeRom = undefined;
this.cartridgeRomFileName = undefined;
this.cartridgeHeader = undefined;
this.cartridgeRam = undefined;
this.gameboyMemory = undefined;
this.paletteMemory = undefined;
this.internalState = undefined;
// Going to set the key for idbKeyval as the cartridge header.
// Then, for each cartridge, it will return an object.
// there will be a cartridgeRam Key, settings Key, and a saveState key
// Not going to make one giant object, as we want to keep idb transactions light and fast
this.WASMBOY_UNLOAD_STORAGE = 'WASMBOY_UNLOAD_STORAGE';
// Define some constants since calls to wasm are expensive
this.WASMBOY_GAME_BYTES_LOCATION = 0;
this.WASMBOY_GAME_RAM_BANKS_LOCATION = 0;
this.WASMBOY_INTERNAL_STATE_SIZE = 0;
this.WASMBOY_INTERNAL_STATE_LOCATION = 0;
this.WASMBOY_INTERNAL_MEMORY_SIZE = 0;
this.WASMBOY_INTERNAL_MEMORY_LOCATION = 0;
this.WASMBOY_PALETTE_MEMORY_SIZE = 0;
this.WASMBOY_PALETTE_MEMORY_LOCATION = 0;
// Define some other constants
this.SUPPORTED_BOOT_ROM_TYPES = {
GB: 'GB',
GBC: 'GBC'
};
}
initialize(headless, maxNumberOfAutoSaveStates, saveStateCallback) {
this.maxNumberOfAutoSaveStates = maxNumberOfAutoSaveStates;
this.saveStateCallback = saveStateCallback;
const initializeTask = async () => {
await this._initializeConstants();
if (!headless) {
await initializeAutoSave.call(this);
}
};
return initializeTask();
}
setWorker(worker) {
this.worker = worker;
// Also set our handler
this.worker.addMessageListener(event => {
const eventData = getEventData(event);
switch (eventData.message.type) {
case WORKER_MESSAGE_TYPE.UPDATED: {
// Simply set our memory
const memoryTypes = Object.keys(eventData.message);
delete memoryTypes.type;
if (memoryTypes.includes(MEMORY_TYPE.BOOT_ROM)) {
this.bootRom = new Uint8Array(eventData.message[MEMORY_TYPE.BOOT_ROM]);
}
if (memoryTypes.includes(MEMORY_TYPE.CARTRIDGE_ROM)) {
this.cartridgeRom = new Uint8Array(eventData.message[MEMORY_TYPE.CARTRIDGE_ROM]);
}
if (memoryTypes.includes(MEMORY_TYPE.CARTRIDGE_RAM)) {
this.cartridgeRam = new Uint8Array(eventData.message[MEMORY_TYPE.CARTRIDGE_RAM]);
}
if (memoryTypes.includes(MEMORY_TYPE.GAMEBOY_MEMORY)) {
this.gameboyMemory = new Uint8Array(eventData.message[MEMORY_TYPE.GAMEBOY_MEMORY]);
}
if (memoryTypes.includes(MEMORY_TYPE.PALETTE_MEMORY)) {
this.paletteMemory = new Uint8Array(eventData.message[MEMORY_TYPE.PALETTE_MEMORY]);
}
if (memoryTypes.includes(MEMORY_TYPE.INTERNAL_STATE)) {
this.internalState = new Uint8Array(eventData.message[MEMORY_TYPE.INTERNAL_STATE]);
}
return;
}
}
});
}
// Function to get all cartridge objects
// Saved in our indexed db
getSavedMemory() {
const getSavedMemoryTask = async () => {
const memory = [];
const keys = await idbKeyval.keys();
for (let i = 0; i < keys.length; i++) {
const cartridgeObject = await idbKeyval.get(keys[i]);
memory.push(cartridgeObject);
}
return memory;
};
return getSavedMemoryTask();
}
getLoadedCartridgeMemoryState() {
return this.loadedCartridgeMemoryState;
}
clearMemory() {
// Clear Wasm memory
// https://docs.google.com/spreadsheets/d/17xrEzJk5-sCB9J2mMJcVnzhbE-XH_NvczVSQH9OHvRk/edit?usp=sharing
return this.worker
.postMessage({
type: WORKER_MESSAGE_TYPE.CLEAR_MEMORY
})
.then(event => {
this.loadedCartridgeMemoryState.ROM = false;
this.loadedCartridgeMemoryState.RAM = false;
// Reset everything
this.cartridgeRom = undefined;
this.cartridgeHeader = undefined;
this.cartridgeRam = undefined;
this.gameboyMemory = undefined;
this.paletteMemory = undefined;
this.internalState = undefined;
});
}
isValidBootROMType(type) {
return Object.keys(this.SUPPORTED_BOOT_ROM_TYPES).some(bootROMTypeKey => {
return this.SUPPORTED_BOOT_ROM_TYPES[bootROMTypeKey] === type;
});
}
async addBootROM(type, file, fetchHeaders, additionalInfo) {
type = type.toUpperCase();
if (!this.isValidBootROMType(type)) {
throw new Error('Invalid Boot ROM type');
}
// Get our fetch rom object
const fetchROMObject = await fetchROMAsByteArray(file, fetchHeaders);
// Remove any keys we don't want to allow
// Overriding in the additionalInfo
if (additionalInfo) {
delete additionalInfo.name;
delete additionalInfo.ROM;
}
let name = 'Game Boy';
if (this.SUPPORTED_BOOT_ROM_TYPES.GBC === type) {
name = 'Game Boy Color';
}
const bootROMObject = {
ROM: fetchROMObject.ROM,
name,
type,
date: Date.now(),
...additionalInfo
};
await idbKeyval.set(BOOT_ROM_KEY + type, bootROMObject);
}
async getBootROMs() {
const bootROMs = [];
for (let bootROMType in this.SUPPORTED_BOOT_ROM_TYPES) {
const bootROMObject = await idbKeyval.get(BOOT_ROM_KEY + bootROMType);
if (bootROMObject) {
bootROMs.push(bootROMObject);
}
}
return bootROMs;
}
async loadBootROMIfAvailable(type) {
if (!idbKeyval) {
// TODO: Allow headless Boot ROMs
return;
}
type = type.toUpperCase();
if (!this.isValidBootROMType(type)) {
throw new Error('Invalid Boot ROM type');
}
// Try to get the boot rom object
const bootROMObject = await idbKeyval.get(BOOT_ROM_KEY + type);
if (!bootROMObject) {
// Return silently
return;
}
const workerMemoryObject = {};
workerMemoryObject[MEMORY_TYPE.BOOT_ROM] = bootROMObject.ROM.buffer;
// Don't pass the rom as a transferrable, since,
// We want to keep a copy of it for reset
await this.worker
.postMessage({
type: WORKER_MESSAGE_TYPE.SET_MEMORY,
...workerMemoryObject
})
.then(event => {
this.loadedCartridgeMemoryState.BOOT = true;
});
// Also get our cartridge header
await this.worker
.postMessage({
type: WORKER_MESSAGE_TYPE.GET_MEMORY,
memoryTypes: [MEMORY_TYPE.BOOT_ROM]
})
.then(event => {
const eventData = getEventData(event);
this.bootRom = new Uint8Array(eventData.message[MEMORY_TYPE.BOOT_ROM]);
});
}
loadCartridgeRom(ROM, fileName) {
const loadTask = async () => {
const workerMemoryObject = {};
workerMemoryObject[MEMORY_TYPE.CARTRIDGE_ROM] = ROM.buffer;
// Don't pass the rom as a transferrable, since,
// We want to keep a copy of it for reset
await this.worker
.postMessage({
type: WORKER_MESSAGE_TYPE.SET_MEMORY,
...workerMemoryObject
})
.then(event => {
this.loadedCartridgeMemoryState.ROM = true;
});
// Also get our cartridge header
await this.worker
.postMessage({
type: WORKER_MESSAGE_TYPE.GET_MEMORY,
memoryTypes: [MEMORY_TYPE.CARTRIDGE_ROM, MEMORY_TYPE.CARTRIDGE_HEADER]
})
.then(event => {
const eventData = getEventData(event);
this.cartridgeRom = new Uint8Array(eventData.message[MEMORY_TYPE.CARTRIDGE_ROM]);
this.cartridgeRomFileName = fileName;
this.cartridgeHeader = new Uint8Array(eventData.message[MEMORY_TYPE.CARTRIDGE_HEADER]);
});
};
return loadTask();
}
saveLoadedCartridge(additionalInfo) {
const saveLoadedCartridgeRomTask = async () => {
if (!this.cartridgeHeader) {
throw new Error('Error parsing the cartridge header');
}
let cartridgeObject = await idbKeyval.get(this.cartridgeHeader);
if (!cartridgeObject) {
cartridgeObject = {};
}
const cartridgeInfo = await this.getCartridgeInfo();
// Remove any keys we don't want to allow
// Overriding in the additionalInfo
if (additionalInfo) {
delete additionalInfo.ROM;
delete additionalInfo.header;
}
// In the rare chance we don't know the name, set to unkown.
let fileName = this.cartridgeRomFileName || 'Unknown';
cartridgeObject.cartridgeRom = {
ROM: this.cartridgeRom,
header: this.cartridgeHeader,
fileName: fileName,
date: Date.now(),
...additionalInfo
};
cartridgeObject.cartridgeInfo = cartridgeInfo;
if (this.cartridgeRam) {
await this.saveCartridgeRam();
}
await idbKeyval.set(this.cartridgeHeader, cartridgeObject);
return cartridgeObject;
};
return saveLoadedCartridgeRomTask();
}
deleteSavedCartridge(cartridge) {
const deleteLoadedCartridgeTask = async () => {
const cartridgeHeader = cartridge.cartridgeInfo.header;
if (!cartridgeHeader) {
throw new Error('Error parsing the cartridge header');
}
let cartridgeObject = await idbKeyval.get(cartridgeHeader);
if (!cartridgeObject) {
throw new Error('Could not find the passed cartridge');
}
delete cartridgeObject.cartridgeRom;
await idbKeyval.set(cartridgeHeader, cartridgeObject);
return cartridgeObject;
};
return deleteLoadedCartridgeTask();
}
// Function to save the cartridge ram
// This emulates the cartridge having a battery to
// Keep things like Pokemon Save data in memory
// Also allows passing in a a Uint8Array header and ram to be set manually
saveCartridgeRam(passedHeader, passedCartridgeRam) {
const saveCartridgeRamTask = async () => {
// Get the entire header in byte memory
// Each version of a rom can have similar title and checksums
// Therefore comparing all of it should help with this :)
// https://drive.google.com/file/d/0B7y-o-Uytiv9OThXWXFCM1FPbGs/view
let header;
let cartridgeRam;
if (passedHeader && passedCartridgeRam) {
header = passedHeader;
cartridgeRam = passedCartridgeRam;
} else {
header = this.cartridgeHeader;
cartridgeRam = this.cartridgeRam;
}
if (!header || !cartridgeRam) {
throw new Error('Error parsing the cartridgeRam or cartridge header');
}
// Get our cartridge object
let cartridgeObject = await idbKeyval.get(header);
if (!cartridgeObject) {
cartridgeObject = {};
}
// Set the cartridgeRam to our cartridgeObject
cartridgeObject.cartridgeRam = cartridgeRam;
await idbKeyval.set(header, cartridgeObject);
};
return saveCartridgeRamTask();
}
// function to load the cartridge ram
// opposite of above
loadCartridgeRam() {
const loadCartridgeRamTask = async () => {
const header = this.cartridgeHeader;
if (!header) {
throw new Error('Error parsing the cartridge header');
}
const cartridgeObject = await idbKeyval.get(header);
if (!cartridgeObject || !cartridgeObject.cartridgeRam) {
return;
}
// Set the cartridgeRam
// Don't transfer, because we want to keep a reference to it
const workerMemoryObject = {};
workerMemoryObject[MEMORY_TYPE.CARTRIDGE_RAM] = cartridgeObject.cartridgeRam.buffer;
await this.worker
.postMessage({
type: WORKER_MESSAGE_TYPE.SET_MEMORY,
...workerMemoryObject
})
.then(event => {
this.loadedCartridgeMemoryState.RAM = true;
this.cartridgeRam = cartridgeObject.cartridgeRam;
});
};
return loadCartridgeRamTask();
}
// Function to save the state to the indexeddb
saveState(passedHeader, passedSaveState) {
const saveStateTask = async () => {
// Get our save state
let saveState;
let header;
if (passedHeader && passedSaveState) {
saveState = passedSaveState;
header = passedHeader;
} else {
saveState = getSaveState.call(this);
header = this.cartridgeHeader;
}
if (!header) {
throw new Error('Error parsing the cartridge header');
}
let cartridgeObject = await idbKeyval.get(header);
if (!cartridgeObject) {
cartridgeObject = {};
}
if (!cartridgeObject.saveStates) {
cartridgeObject.saveStates = [];
}
// Check if we are auto
if (saveState.isAuto && this.maxNumberOfAutoSaveStates && this.maxNumberOfAutoSaveStates > 0) {
// Make sure we are not exceeding the max number of auto save states
const autoSaveStates = [];
cartridgeObject.saveStates.forEach(savedState => {
if (savedState.isAuto) {
autoSaveStates.push(savedState);
}
});
// Sort auto save states by date
autoSaveStates.sort((a, b) => {
if (a.date < b.date) {
return -1;
}
if (a.date > b.date) {
return 1;
}
return 0;
});
while (autoSaveStates.length > 0 && autoSaveStates.length + 1 > this.maxNumberOfAutoSaveStates) {
const autoSaveState = autoSaveStates.shift();
// Find the save state
const saveStateIndex = this._indexOfSaveStateIndexInSaveStates(autoSaveState, cartridgeObject.saveStates);
cartridgeObject.saveStates.splice(saveStateIndex, 1);
}
if (this.maxNumberOfAutoSaveStates > 0) {
cartridgeObject.saveStates.push(saveState);
}
} else {
cartridgeObject.saveStates.push(saveState);
}
await idbKeyval.set(header, cartridgeObject);
return saveState;
};
return saveStateTask();
}
loadState(saveState) {
const loadStateTask = async () => {
const header = this.cartridgeHeader;
if (!header) {
throw new Error('Error getting the cartridge header');
}
if (!saveState) {
const cartridgeObject = await idbKeyval.get(header);
if (!cartridgeObject || !cartridgeObject.saveStates) {
throw new Error('No Save State passed, and no cartridge object found');
return;
}
saverState = cartridgeObject.saveStates[0];
}
const workerMemoryObject = {};
workerMemoryObject[MEMORY_TYPE.CARTRIDGE_RAM] = saveState.wasmboyMemory.cartridgeRam.buffer;
workerMemoryObject[MEMORY_TYPE.GAMEBOY_MEMORY] = saveState.wasmboyMemory.gameBoyMemory.buffer;
workerMemoryObject[MEMORY_TYPE.PALETTE_MEMORY] = saveState.wasmboyMemory.wasmBoyPaletteMemory.buffer;
workerMemoryObject[MEMORY_TYPE.INTERNAL_STATE] = saveState.wasmboyMemory.wasmBoyInternalState.buffer;
await this.worker.postMessage(
{
type: WORKER_MESSAGE_TYPE.SET_MEMORY,
...workerMemoryObject
},
[
workerMemoryObject[MEMORY_TYPE.CARTRIDGE_RAM],
workerMemoryObject[MEMORY_TYPE.GAMEBOY_MEMORY],
workerMemoryObject[MEMORY_TYPE.PALETTE_MEMORY],
workerMemoryObject[MEMORY_TYPE.INTERNAL_STATE]
]
);
await this.worker
.postMessage({
type: WORKER_MESSAGE_TYPE.GET_MEMORY,
memoryTypes: [MEMORY_TYPE.CARTRIDGE_RAM, MEMORY_TYPE.GAMEBOY_MEMORY, MEMORY_TYPE.PALETTE_MEMORY, MEMORY_TYPE.INTERNAL_STATE]
})
.then(event => {
const eventData = getEventData(event);
this.cartridgeRam = eventData.message[MEMORY_TYPE.CARTRIDGE_RAM];
this.gameboyMemory = eventData.message[MEMORY_TYPE.GAMEBOY_MEMORY];
this.paletteMemory = eventData.message[MEMORY_TYPE.PALETTE_MEMORY];
this.internalState = eventData.message[MEMORY_TYPE.INTERNAL_STATE];
});
};
return loadStateTask();
}
deleteState(saveState, passedHeader) {
const deleteStateTask = async () => {
if (!saveState) {
throw new Error('You must provide a save state to delete');
return;
}
let header;
if (passedHeader) {
header = passedHeader;
} else if (this.cartridgeHeader) {
header = this.cartridgeHeader;
}
if (!header) {
throw new Error('Please load a ROM, or pass a Cartridge header...');
return;
}
let cartridgeObject = await idbKeyval.get(header);
if (!cartridgeObject || !cartridgeObject.saveStates) {
throw new Error('No save states found for the Cartridge...');
return;
}
// Find the save state
const saveStateIndex = this._indexOfSaveStateIndexInSaveStates(saveState, cartridgeObject.saveStates);
// If not found, throw an error
if (saveStateIndex < 0) {
throw new Error('Could not find the passed save state for the related cartridge...');
return;
}
cartridgeObject.saveStates.splice(saveStateIndex, 1);
await idbKeyval.set(header, cartridgeObject);
return saveState;
};
return deleteStateTask();
}
// Function to return the current cartridge object
getCartridgeObject() {
return idbKeyval.get(this.cartridgeHeader);
}
// Function to return all informationh aboyut the currently loaded cart.
// This will include, the ROM, the RAM, the header, and the indivudal pieces of the header
// See: http://gbdev.gg8.se/wiki/articles/The_Cartridge_Header
getCartridgeInfo() {
if (!this.loadedCartridgeMemoryState.ROM) {
return Promise.reject('No ROM has been loaded');
}
let getCartridgeInfoTask = async () => {
const cartridgeInfo = {};
cartridgeInfo.header = this.cartridgeHeader;
cartridgeInfo.ROM = this.cartridgeRom;
cartridgeInfo.RAM = this.cartridgeRam;
// Now parse our header for additional information
cartridgeInfo.nintendoLogo = cartridgeInfo.ROM.slice(0x104, 0x134);
cartridgeInfo.title = cartridgeInfo.ROM.slice(0x134, 0x144);
cartridgeInfo.titleAsString = String.fromCharCode.apply(null, cartridgeInfo.title);
cartridgeInfo.manufacturerCode = cartridgeInfo.ROM.slice(0x13f, 0x143);
cartridgeInfo.CGBFlag = cartridgeInfo.ROM[0x143];
cartridgeInfo.newLicenseeCode = cartridgeInfo.ROM.slice(0x144, 0x146);
cartridgeInfo.SGBFlag = cartridgeInfo.ROM[0x146];
cartridgeInfo.cartridgeType = cartridgeInfo.ROM[0x147];
cartridgeInfo.ROMSize = cartridgeInfo.ROM[0x148];
cartridgeInfo.RAMSize = cartridgeInfo.ROM[0x149];
cartridgeInfo.destinationCode = cartridgeInfo.ROM[0x14a];
cartridgeInfo.oldLicenseeCode = cartridgeInfo.ROM[0x14b];
cartridgeInfo.maskROMVersionNumber = cartridgeInfo.ROM[0x14c];
cartridgeInfo.headerChecksum = cartridgeInfo.ROM[0x14d];
cartridgeInfo.globalChecksum = cartridgeInfo.ROM.slice(0x14e, 0x150);
return cartridgeInfo;
};
return getCartridgeInfoTask();
}
_initializeConstants() {
// Initialize our cached wasm constants
return this.worker
.postMessage({
type: WORKER_MESSAGE_TYPE.GET_CONSTANTS
})
.then(event => {
const eventData = getEventData(event);
Object.keys(this).forEach(key => {
if (eventData.message[key] !== undefined) {
this[key] = eventData.message[key];
}
});
});
}
_indexOfSaveStateIndexInSaveStates(saveState, saveStates) {
// Find the save state
let saveStateIndex = saveStates.indexOf(saveState);
if (saveStateIndex < 0) {
const keysCheck = (a, b) => {
return JSON.stringify(Object.keys(a)) === JSON.stringify(Object.keys(b));
};
const dateCheck = (a, b) => {
return a.date === b.date;
};
const autoCheck = (a, b) => {
return a.isAuto === b.isAuto;
};
saveStates.some((savedState, index) => {
if (keysCheck(saveState, savedState) && dateCheck(saveState, savedState) && autoCheck(saveState, savedState)) {
saveStateIndex = index;
return true;
}
return false;
});
}
return saveStateIndex;
}
}
// Create a singleton to export
export const WasmBoyMemory = new WasmBoyMemoryService();