UNPKG

wasmboy

Version:

Gameboy / Gameboy Color Emulator written for Web Assembly using AssemblyScript. Shell/Debugger in Preact

45 lines (36 loc) 1.32 kB
// Functions here are depedent on WasmBoyMemory state. // Thus me bound using .bind() on functions import { WasmBoyPlugins } from '../plugins/plugins'; // Will save the state in parts, to easy memory map changes: // https://docs.google.com/spreadsheets/d/17xrEzJk5-sCB9J2mMJcVnzhbE-XH_NvczVSQH9OHvRk/edit?usp=sharing const WASMBOY_SAVE_STATE_SCHEMA = { wasmboyMemory: { wasmBoyInternalState: [], wasmBoyPaletteMemory: [], gameBoyMemory: [], cartridgeRam: [] }, date: undefined, isAuto: undefined }; // Function to return a save state of the current memory export function getSaveState() { // Save our internal wasmboy state to memory // Should be done whenever we send back memory // this.wasmInstance.exports.saveState(); let saveState = Object.assign({}, WASMBOY_SAVE_STATE_SCHEMA); saveState.wasmboyMemory.wasmBoyInternalState = this.internalState; saveState.wasmboyMemory.wasmBoyPaletteMemory = this.paletteMemory; saveState.wasmboyMemory.gameBoyMemory = this.gameboyMemory; saveState.wasmboyMemory.cartridgeRam = this.cartridgeRam; saveState.date = Date.now(); saveState.isAuto = false; if (this.saveStateCallback) { this.saveStateCallback(saveState); } WasmBoyPlugins.runHook({ key: 'saveState', params: [saveState] }); return saveState; }