Skip to content

Commit

Permalink
Added support for GBC Colorization for GB Games (#263)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
torch2424 authored Feb 19, 2019
1 parent a0c7f49 commit f678854
Show file tree
Hide file tree
Showing 18 changed files with 2,449 additions and 354 deletions.
2 changes: 1 addition & 1 deletion core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export class Config {
// Boot Rom
static enableBootRom: boolean = false;

// GBC Preference
// GBC Options
static useGbcWhenAvailable: boolean = true;

// Batch Processing
Expand Down
20 changes: 14 additions & 6 deletions core/debug/debug-graphics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
getTileDataAddress,
drawPixelsFromLineOfTile,
getMonochromeColorFromPalette,
getColorizedGbHexColorFromPalette,
getRedFromHexColor,
getGreenFromHexColor,
getBlueFromHexColor,
getRgbColorFromPalette,
getColorComponentFromRgb,
loadFromVramBank
Expand Down Expand Up @@ -170,13 +174,17 @@ export function drawBackgroundMapToWasmMemory(showColor: i32): void {
store<u8>(offset + 2, <u8>blue);
} else {
// Only rendering camera for now, so coordinates are for the camera.
// Get the rgb value for the color Id, will be repeated into R, G, B
let monochromeColor: i32 = getMonochromeColorFromPalette(paletteColorId, Graphics.memoryLocationBackgroundPalette);
// Get the rgb value for the color Id, will be repeated into R, G, B (if not colorized)
let hexColor: i32 = getColorizedGbHexColorFromPalette(paletteColorId, Graphics.memoryLocationBackgroundPalette);

for (let i: i32 = 0; i < 3; i++) {
let offset: i32 = BACKGROUND_MAP_LOCATION + pixelStart + i;
store<u8>(offset, <u8>monochromeColor);
}
let offset: i32 = BACKGROUND_MAP_LOCATION + pixelStart;

// Red
store<u8>(offset + 0, <u8>getRedFromHexColor(hexColor));
// Green
store<u8>(offset + 1, <u8>getGreenFromHexColor(hexColor));
// Blue
store<u8>(offset + 2, <u8>getBlueFromHexColor(hexColor));
}
}
}
Expand Down
18 changes: 12 additions & 6 deletions core/graphics/backgroundWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { FRAME_LOCATION } from '../constants';
import { Cpu } from '../cpu/index';
import { Config } from '../config';
import { Graphics, loadFromVramBank, setPixelOnFrame, getRgbPixelStart } from './graphics';
import { getMonochromeColorFromPalette, getRgbColorFromPalette, getColorComponentFromRgb } from './palette';
import {
getMonochromeColorFromPalette,
getColorizedGbHexColorFromPalette,
getRgbColorFromPalette,
getColorComponentFromRgb
} from './palette';
import { getRedFromHexColor, getGreenFromHexColor, getBlueFromHexColor } from './colors';
import { addPriorityforPixel, getPriorityforPixel } from './priority';
import { TileCache, drawPixelsFromLineOfTile, getTileDataAddress } from './tiles';
// Assembly script really not feeling the reexport
Expand Down Expand Up @@ -238,11 +244,11 @@ function drawMonochromePixelFromTileId(

// FINALLY, RENDER THAT PIXEL!
// Only rendering camera for now, so coordinates are for the camera.
// Get the rgb value for the color Id, will be repeated into R, G, B
let monochromeColor: i32 = getMonochromeColorFromPalette(paletteColorId, Graphics.memoryLocationBackgroundPalette);
setPixelOnFrame(xPixel, yPixel, 0, monochromeColor);
setPixelOnFrame(xPixel, yPixel, 1, monochromeColor);
setPixelOnFrame(xPixel, yPixel, 2, monochromeColor);
// Get the rgb value for the color Id, will be repeated into R, G, B. if not colorized
let hexColor: i32 = getColorizedGbHexColorFromPalette(paletteColorId, Graphics.memoryLocationBackgroundPalette);
setPixelOnFrame(xPixel, yPixel, 0, getRedFromHexColor(hexColor));
setPixelOnFrame(xPixel, yPixel, 1, getGreenFromHexColor(hexColor));
setPixelOnFrame(xPixel, yPixel, 2, getBlueFromHexColor(hexColor));

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

0 comments on commit f678854

Please sign in to comment.