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

feat: initial palette update operation

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