diff --git a/examples/web/index.ts b/examples/web/index.ts index 72242663ea4fccc30e4c7185173a3ce085784803..85367731500fbf7db2369265d1c74ac792d40e28 100644 --- a/examples/web/index.ts +++ b/examples/web/index.ts @@ -33,6 +33,11 @@ const BACKGROUNDS = [ "3a5a40" ]; +const PALETTES = [ + ["ffffff", "c0c0c0", "606060", "000000"], + ["b6a571", "8b7e56", "554d35", "201d13"] +]; + const KEYS_NAME: Record<string, number> = { ArrowUp: PadKey.Up, ArrowDown: PadKey.Down, @@ -73,6 +78,7 @@ class GameboyEmulator extends EmulatorBase implements Emulator { private fps: number = 0; private frameStart: number = new Date().getTime(); private frameCount: number = 0; + private paletteIndex: number = 0; private romName: string | null = null; private romData: Uint8Array | null = null; @@ -286,13 +292,8 @@ class GameboyEmulator extends EmulatorBase implements Emulator { break; } - //Â @TODO replace this with something more flexible - this.gameBoy.set_palette_colors_ws([ - "b6a571", - "8b7e56", - "554d35", - "201d13" - ]); + // runs the initial palette update operation + this.updatePalette(); // resets the Game Boy engine to restore it into // a valid state ready to be used @@ -464,6 +465,12 @@ class GameboyEmulator extends EmulatorBase implements Emulator { this.gameBoy?.key_lift(keyCode); } + updatePalette() { + this.gameBoy?.set_palette_colors_ws(PALETTES[this.paletteIndex]); + this.paletteIndex += 1; + this.paletteIndex %= PALETTES.length; + } + benchmark(count = 50000000) { let cycles = 0; this.pause(); diff --git a/examples/web/react/app.tsx b/examples/web/react/app.tsx index 111f3a0efd062da5164e54d4322228fd7ef469ea..183910f3665676ec69ec2ab2bd887f0637765064 100644 --- a/examples/web/react/app.tsx +++ b/examples/web/react/app.tsx @@ -222,6 +222,8 @@ export interface Emulator extends ObservableI { keyLift(key: string): void; + updatePalette(): void; + /** * Runs a benchmark operation in the emulator, effectively * measuring the performance of it. @@ -483,7 +485,7 @@ export const App: FC<AppProps> = ({ setBackgroundIndex((backgroundIndex + 1) % backgrounds.length); }; const onPaletteClick = () => { - console.info("palette"); + emulator.updatePalette(); }; const onUploadFile = async (file: File) => { const arrayBuffer = await file.arrayBuffer();