Skip to content
Snippets Groups Projects
Verified Commit 40f2e2cc authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: initial palette update operation

parent 33e8e59c
No related branches found
No related tags found
No related merge requests found
Pipeline #1536 passed
......@@ -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();
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment