Fixed on game reload and a custom palette was used, it was lost on reset.

Added option to use a custom global palette from Core Options.
This commit is contained in:
Juan Ruvalcaba 2014-07-17 17:14:16 -07:00
parent 2d6955e5b5
commit 44204a5ce5

View File

@ -123,7 +123,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" },
{ "gb_colorization", "GB Colorization; disabled|enabled|custom" },
{ "gbc_color_correction", "Color correction; enabled|disabled" },
{ NULL, NULL },
};
@ -211,7 +211,7 @@ static bool startswith(const std::string s1, const std::string prefix)
return s1.compare(0, prefix.length(), prefix) == 0;
}
static bool gb_colorization_enable = false;
static int gb_colorization_enable = 0;
static std::string rom_path;
char internal_game_name[17];
@ -240,10 +240,10 @@ static void check_palette(void)
palette_file.open(custom_palette_path.c_str());
}
if (!palette_file.is_open() && !findGbcTitlePal(internal_game_name))
if (!palette_file.is_open())// && !findGbcTitlePal(internal_game_name))
{
// try again with default.pal
// only if no specific title palette from the GBC BIOS is found
//- removed last line if colorization is enabled
custom_palette_path = system_directory + "/palettes/" + "default.pal";
palette_file.open(custom_palette_path.c_str());
}
@ -342,12 +342,14 @@ static void check_variables(void)
return;
// else it is a GB-mono game -> set a color palette
bool gb_colorization_old = gb_colorization_enable;
//bool gb_colorization_old = gb_colorization_enable;
if (strcmp(var.value, "disabled") == 0)
gb_colorization_enable = false;
gb_colorization_enable = 0;
else if (strcmp(var.value, "enabled") == 0)
gb_colorization_enable = true;
gb_colorization_enable = 1;
else if (strcmp(var.value, "custom") == 0)
gb_colorization_enable = 2;
//std::string internal_game_name = gb.romTitle(); // available only in latest Gambatte
//std::string internal_game_name = reinterpret_cast<const char *>(info->data + 0x134); // buggy with some games ("YOSSY NO COOKIE", "YOSSY NO PANEPON, etc.)
@ -355,26 +357,36 @@ static void check_variables(void)
// load a GBC BIOS builtin palette
unsigned short* gbc_bios_palette = NULL;
if (gb_colorization_enable)
{
gbc_bios_palette = const_cast<unsigned short*>(findGbcTitlePal(internal_game_name));
if (!gbc_bios_palette)
{
// no custom palette found, load the default (blue)
gbc_bios_palette = const_cast<unsigned short*>(findGbcDirPal("GBC - Blue"));
}
switch (gb_colorization_enable){
case 1:
gbc_bios_palette = const_cast<unsigned short*>(findGbcTitlePal(internal_game_name));
if (!gbc_bios_palette)
{
// no custom palette found, load the default (blue)
gbc_bios_palette = const_cast<unsigned short*>(findGbcDirPal("GBC - Blue"));
}
break;
case 2:
check_palette();
break;
default:
gbc_bios_palette = const_cast<unsigned short*>(findGbcDirPal("GBC - Grayscale"));
break;
}
else
gbc_bios_palette = const_cast<unsigned short*>(findGbcDirPal("GBC - Grayscale"));
unsigned rgb32 = 0;
for (unsigned palnum = 0; palnum < 3; ++palnum)
{
for (unsigned colornum = 0; colornum < 4; ++colornum)
{
rgb32 = gb.gbcToRgb32(gbc_bios_palette[palnum * 4 + colornum]);
gb.setDmgPaletteColor(palnum, colornum, rgb32);
}
//gambatte is using custom colorization then we have a previously palette loaded,
//skip this loop then
if (gb_colorization_enable != 2){
unsigned rgb32 = 0;
for (unsigned palnum = 0; palnum < 3; ++palnum)
{
for (unsigned colornum = 0; colornum < 4; ++colornum)
{
rgb32 = gb.gbcToRgb32(gbc_bios_palette[palnum * 4 + colornum]);
gb.setDmgPaletteColor(palnum, colornum, rgb32);
}
}
}
}
@ -433,7 +445,7 @@ bool retro_load_game(const struct retro_game_info *info)
log_cb(RETRO_LOG_INFO, "[Gambatte]: Got internal game name: %s.\n", internal_game_name);
check_variables();
check_palette();
//check_palette();
//Ugly hack alert: This entire thing depends upon cartridge.cpp and memptrs.cpp not changing in weird ways.
unsigned sramsize = gb.savedata_size();