mirror of
https://github.com/libretro/gambatte-libretro.git
synced 2024-11-23 16:00:06 +00:00
Merge pull request #26 from Alcaro/master
Add a core option for color correction.
This commit is contained in:
commit
365b58d4cb
@ -100,6 +100,9 @@ public:
|
||||
void loadState(const void *data);
|
||||
size_t stateSize() const;
|
||||
|
||||
void setColorCorrection(bool enable);
|
||||
video_pixel_t gbcToRgb32(const unsigned bgr15);
|
||||
|
||||
private:
|
||||
struct Priv;
|
||||
Priv *const p_;
|
||||
@ -108,8 +111,6 @@ private:
|
||||
GB(const GB &);
|
||||
GB & operator=(const GB &);
|
||||
};
|
||||
|
||||
video_pixel_t gbcToRgb32(const unsigned bgr15);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -118,6 +118,7 @@ void retro_set_environment(retro_environment_t cb)
|
||||
static const struct retro_variable vars[] = {
|
||||
{ "gb_gbamode", "GBA mode; disabled|enabled" },
|
||||
{ "gb_colorization", "GB Colorization; disabled|enabled" },
|
||||
{ "gbc_color_correction", "Color correction; enabled|disabled" },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
@ -322,7 +323,12 @@ static void check_palette(void)
|
||||
|
||||
static void check_variables(void)
|
||||
{
|
||||
bool colorCorrection=true;
|
||||
struct retro_variable var = {0};
|
||||
var.key = "gbc_color_correction";
|
||||
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value && !strcmp(var.value, "disabled")) colorCorrection=false;
|
||||
gb.setColorCorrection(colorCorrection);
|
||||
|
||||
var.key = "gb_colorization";
|
||||
|
||||
if (!environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || !var.value)
|
||||
@ -362,21 +368,21 @@ static void check_variables(void)
|
||||
{
|
||||
for (unsigned colornum = 0; colornum < 4; ++colornum)
|
||||
{
|
||||
rgb32 = gambatte::gbcToRgb32(gbc_bios_palette[palnum * 4 + colornum]);
|
||||
rgb32 = gb.gbcToRgb32(gbc_bios_palette[palnum * 4 + colornum]);
|
||||
gb.setDmgPaletteColor(palnum, colornum, rgb32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned pow2ceil(unsigned n) {
|
||||
--n;
|
||||
n |= n >> 1;
|
||||
n |= n >> 2;
|
||||
n |= n >> 4;
|
||||
n |= n >> 8;
|
||||
++n;
|
||||
--n;
|
||||
n |= n >> 1;
|
||||
n |= n >> 2;
|
||||
n |= n >> 4;
|
||||
n |= n >> 8;
|
||||
++n;
|
||||
|
||||
return n;
|
||||
return n;
|
||||
}
|
||||
|
||||
bool retro_load_game(const struct retro_game_info *info)
|
||||
|
@ -88,6 +88,9 @@ public:
|
||||
void setDmgPaletteColor(unsigned palNum, unsigned colorNum, unsigned rgb32) {
|
||||
memory.setDmgPaletteColor(palNum, colorNum, rgb32);
|
||||
}
|
||||
|
||||
void display_setColorCorrection(bool enable) { memory.display_setColorCorrection(enable); }
|
||||
video_pixel_t display_gbcToRgb32(const unsigned bgr15) { return memory.display_gbcToRgb32(bgr15); }
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -145,6 +145,9 @@ public:
|
||||
}
|
||||
|
||||
void setDmgPaletteColor(unsigned palNum, unsigned colorNum, unsigned long rgb32);
|
||||
|
||||
void display_setColorCorrection(bool enable) { display.createPaletteLookup(enable); }
|
||||
video_pixel_t display_gbcToRgb32(const unsigned bgr15) { return display.gbcToRgb32(bgr15); }
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -122,5 +122,13 @@ size_t GB::stateSize() const {
|
||||
return StateSaver::stateSize(state);
|
||||
}
|
||||
|
||||
void GB::setColorCorrection(bool enable) {
|
||||
p_->cpu.display_setColorCorrection(enable);
|
||||
}
|
||||
|
||||
video_pixel_t GB::gbcToRgb32(const unsigned bgr15) {
|
||||
return p_->cpu.display_gbcToRgb32(bgr15);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
||||
#include<stdio.h>
|
||||
namespace gambatte {
|
||||
|
||||
void LCD::setDmgPalette(video_pixel_t *const palette, const video_pixel_t *const dmgColors, const unsigned data) {
|
||||
@ -30,21 +31,45 @@ void LCD::setDmgPalette(video_pixel_t *const palette, const video_pixel_t *const
|
||||
palette[3] = dmgColors[data >> 6 & 3];
|
||||
}
|
||||
|
||||
video_pixel_t gbcToRgb32(const unsigned bgr15) {
|
||||
video_pixel_t LCD::gbcToRgb32(const unsigned bgr15) {
|
||||
return gbcToRgbLookup[bgr15];
|
||||
}
|
||||
|
||||
static video_pixel_t gbcToRgbCalc(const unsigned bgr15, bool colorCorrection) {
|
||||
if (colorCorrection) {
|
||||
#ifdef VIDEO_RGB565
|
||||
//If (whatever made the Gambatte devs create this somewhat arcane configuration) is not a concern, it can be replaced with simply 'return bgr15'.
|
||||
const unsigned r = bgr15 & 0x1F;
|
||||
const unsigned g = bgr15 >> 5 & 0x1F;
|
||||
const unsigned b = bgr15 >> 10 & 0x1F;
|
||||
const unsigned r = bgr15 & 0x1F;
|
||||
const unsigned g = bgr15 >> 5 & 0x1F;
|
||||
const unsigned b = bgr15 >> 10 & 0x1F;
|
||||
|
||||
return (((r * 13 + g * 2 + b + 8) << 7) & 0xF800) | ((g * 3 + b + 1) >> 1) << 5 | ((r * 3 + g * 2 + b * 11 + 8) >> 4);
|
||||
return (((r * 13 + g * 2 + b + 8) << 7) & 0xF800) | ((g * 3 + b + 1) >> 1) << 5 | ((r * 3 + g * 2 + b * 11 + 8) >> 4);
|
||||
#else
|
||||
const unsigned r = bgr15 & 0x1F;
|
||||
const unsigned g = bgr15 >> 5 & 0x1F;
|
||||
const unsigned b = bgr15 >> 10 & 0x1F;
|
||||
const unsigned r = bgr15 & 0x1F;
|
||||
const unsigned g = bgr15 >> 5 & 0x1F;
|
||||
const unsigned b = bgr15 >> 10 & 0x1F;
|
||||
|
||||
return ((r * 13 + g * 2 + b) >> 1) << 16 | (g * 3 + b) << 9 | (r * 3 + g * 2 + b * 11) >> 1;
|
||||
return ((r * 13 + g * 2 + b) >> 1) << 16 | (g * 3 + b) << 9 | (r * 3 + g * 2 + b * 11) >> 1;
|
||||
#endif
|
||||
} else {
|
||||
#ifdef VIDEO_RGB565
|
||||
const unsigned r = bgr15 & 0x1F;
|
||||
const unsigned g = bgr15 >> 5 & 0x1F;
|
||||
const unsigned b = bgr15 >> 10 & 0x1F;
|
||||
|
||||
return r<<11 | g<<6 | b;
|
||||
#else
|
||||
const unsigned r = bgr15 & 0x1F;
|
||||
const unsigned g = bgr15 >> 5 & 0x1F;
|
||||
const unsigned b = bgr15 >> 10 & 0x1F;
|
||||
|
||||
return r<<16 | g<<8 | b;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void LCD::createPaletteLookup(bool colorCorrection) {
|
||||
for (unsigned i=0;i<0x8000;i++) gbcToRgbLookup[i]=gbcToRgbCalc(i, colorCorrection);
|
||||
refreshPalettes();
|
||||
}
|
||||
/*static unsigned long gbcToRgb16(const unsigned bgr15) {
|
||||
const unsigned r = bgr15 & 0x1F;
|
||||
@ -99,6 +124,8 @@ LCD::LCD(const unsigned char *const oamram, const unsigned char *const vram, con
|
||||
|
||||
reset(oamram, false);
|
||||
setVideoBuffer(0, 160);
|
||||
|
||||
createPaletteLookup(true);
|
||||
}
|
||||
|
||||
void LCD::reset(const unsigned char *const oamram, const bool cgb) {
|
||||
@ -377,7 +404,7 @@ bool LCD::cgbpAccessible(const unsigned long cycleCounter) {
|
||||
|| cycleCounter >= m0TimeOfCurrentLine(cycleCounter) + 3 - isDoubleSpeed();
|
||||
}
|
||||
|
||||
static void doCgbColorChange(unsigned char *const pdata,
|
||||
void LCD::doCgbColorChange(unsigned char *const pdata,
|
||||
video_pixel_t *const palette, unsigned index, const unsigned data) {
|
||||
pdata[index] = data;
|
||||
index >>= 1;
|
||||
|
@ -150,6 +150,10 @@ class LCD {
|
||||
void doCgbBgColorChange(unsigned index, unsigned data, unsigned long cycleCounter);
|
||||
void doCgbSpColorChange(unsigned index, unsigned data, unsigned long cycleCounter);
|
||||
|
||||
video_pixel_t gbcToRgbLookup[0x8000];
|
||||
void doCgbColorChange(unsigned char *const pdata,
|
||||
video_pixel_t *const palette, unsigned index, const unsigned data);
|
||||
|
||||
public:
|
||||
LCD(const unsigned char *oamram, const unsigned char *vram_in, VideoInterruptRequester memEventRequester);
|
||||
void reset(const unsigned char *oamram, bool cgb);
|
||||
@ -246,6 +250,9 @@ public:
|
||||
|
||||
bool isCgb() const { return ppu.cgb(); }
|
||||
bool isDoubleSpeed() const { return ppu.lyCounter().isDoubleSpeed(); }
|
||||
|
||||
void createPaletteLookup(bool colorCorrection);
|
||||
video_pixel_t gbcToRgb32(const unsigned bgr15);
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user