From 397a4d53ad7ce3aeffb14d015c199fdfe129f715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Sun, 13 Nov 2022 23:50:36 +0000 Subject: [PATCH] fet: new ram structure --- examples/web/gb.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/examples/web/gb.ts b/examples/web/gb.ts index 5b0c961e..a34c1e6b 100644 --- a/examples/web/gb.ts +++ b/examples/web/gb.ts @@ -199,11 +199,21 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { this.gameBoy?.ppu_mode() === PpuMode.VBlank && this.gameBoy?.ppu_frame() !== lastFrame ) { + // updates the reference to the last frame index + // to be used for comparison in the next tick lastFrame = this.gameBoy?.ppu_frame(); // triggers the frame event indicating that // a new frame is now available for drawing this.trigger("frame"); + + // @todo this has to be structureed in a better way + if (this.cartridge && this.cartridge.has_battery()) { + const ramData = this.cartridge.ram_data_eager(); + const decoder = new TextDecoder("utf8"); + const ramDataB64 = btoa(decoder.decode(ramData)); + localStorage.setItem(this.cartridge.title(), ramDataB64) + } } } @@ -289,6 +299,10 @@ export class GameboyEmulator extends EmulatorBase implements Emulator { this.gameBoy.load_boot_default(); const cartridge = this.gameBoy.load_rom_ws(romData!); + // in case there's a battery involved tries to obtain + if (cartridge.has_battery()) { + } + // updates the ROM name in case there's extra information // coming from the cartridge romName = cartridge.title() ? cartridge.title() : romName; -- GitLab