Skip to content

Commit f678854

Browse files
authored
Added support for GBC Colorization for GB Games (#263)
* Started adding colorization * Started adding more colors, everything working! * Got the color palettes working, and setting up function to switch between them all * Finished GBC Colorization
1 parent a0c7f49 commit f678854

File tree

18 files changed

+2449
-354
lines changed

18 files changed

+2449
-354
lines changed

core/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export class Config {
22
// Boot Rom
33
static enableBootRom: boolean = false;
44

5-
// GBC Preference
5+
// GBC Options
66
static useGbcWhenAvailable: boolean = true;
77

88
// Batch Processing

core/debug/debug-graphics.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import {
66
getTileDataAddress,
77
drawPixelsFromLineOfTile,
88
getMonochromeColorFromPalette,
9+
getColorizedGbHexColorFromPalette,
10+
getRedFromHexColor,
11+
getGreenFromHexColor,
12+
getBlueFromHexColor,
913
getRgbColorFromPalette,
1014
getColorComponentFromRgb,
1115
loadFromVramBank
@@ -170,13 +174,17 @@ export function drawBackgroundMapToWasmMemory(showColor: i32): void {
170174
store<u8>(offset + 2, <u8>blue);
171175
} else {
172176
// Only rendering camera for now, so coordinates are for the camera.
173-
// Get the rgb value for the color Id, will be repeated into R, G, B
174-
let monochromeColor: i32 = getMonochromeColorFromPalette(paletteColorId, Graphics.memoryLocationBackgroundPalette);
177+
// Get the rgb value for the color Id, will be repeated into R, G, B (if not colorized)
178+
let hexColor: i32 = getColorizedGbHexColorFromPalette(paletteColorId, Graphics.memoryLocationBackgroundPalette);
175179

176-
for (let i: i32 = 0; i < 3; i++) {
177-
let offset: i32 = BACKGROUND_MAP_LOCATION + pixelStart + i;
178-
store<u8>(offset, <u8>monochromeColor);
179-
}
180+
let offset: i32 = BACKGROUND_MAP_LOCATION + pixelStart;
181+
182+
// Red
183+
store<u8>(offset + 0, <u8>getRedFromHexColor(hexColor));
184+
// Green
185+
store<u8>(offset + 1, <u8>getGreenFromHexColor(hexColor));
186+
// Blue
187+
store<u8>(offset + 2, <u8>getBlueFromHexColor(hexColor));
180188
}
181189
}
182190
}

core/graphics/backgroundWindow.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { FRAME_LOCATION } from '../constants';
33
import { Cpu } from '../cpu/index';
44
import { Config } from '../config';
55
import { Graphics, loadFromVramBank, setPixelOnFrame, getRgbPixelStart } from './graphics';
6-
import { getMonochromeColorFromPalette, getRgbColorFromPalette, getColorComponentFromRgb } from './palette';
6+
import {
7+
getMonochromeColorFromPalette,
8+
getColorizedGbHexColorFromPalette,
9+
getRgbColorFromPalette,
10+
getColorComponentFromRgb
11+
} from './palette';
12+
import { getRedFromHexColor, getGreenFromHexColor, getBlueFromHexColor } from './colors';
713
import { addPriorityforPixel, getPriorityforPixel } from './priority';
814
import { TileCache, drawPixelsFromLineOfTile, getTileDataAddress } from './tiles';
915
// Assembly script really not feeling the reexport
@@ -238,11 +244,11 @@ function drawMonochromePixelFromTileId(
238244

239245
// FINALLY, RENDER THAT PIXEL!
240246
// Only rendering camera for now, so coordinates are for the camera.
241-
// Get the rgb value for the color Id, will be repeated into R, G, B
242-
let monochromeColor: i32 = getMonochromeColorFromPalette(paletteColorId, Graphics.memoryLocationBackgroundPalette);
243-
setPixelOnFrame(xPixel, yPixel, 0, monochromeColor);
244-
setPixelOnFrame(xPixel, yPixel, 1, monochromeColor);
245-
setPixelOnFrame(xPixel, yPixel, 2, monochromeColor);
247+
// Get the rgb value for the color Id, will be repeated into R, G, B. if not colorized
248+
let hexColor: i32 = getColorizedGbHexColorFromPalette(paletteColorId, Graphics.memoryLocationBackgroundPalette);
249+
setPixelOnFrame(xPixel, yPixel, 0, getRedFromHexColor(hexColor));
250+
setPixelOnFrame(xPixel, yPixel, 1, getGreenFromHexColor(hexColor));
251+
setPixelOnFrame(xPixel, yPixel, 2, getBlueFromHexColor(hexColor));
246252

247253
// Lastly, add the pixel to our background priority map
248254
// https://github.com/torch2424/wasmBoy/issues/51

0 commit comments

Comments
 (0)