void PaletteDialog::setSettingsFile(QString const &filename, QString const &romTitle) { saveToSettingsFile(); settingsFile_ = filename; defaultScheme_ = findGbcTitlePal(romTitle.toLatin1().data()) ? romTitle : tr("Global Palette"); QSettings settings(savedir_ + settingsFile_, QSettings::IniFormat); loadSettings(settings); }
static void check_variables(void) { struct retro_variable var = {0}; var.key = "gb_colorization"; if (!environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || !var.value) return; if (gb.isCgb()) return; // else it is a GB-mono game -> set a color palette bool gb_colorization_old = gb_colorization_enable; if (strcmp(var.value, "disabled") == 0) gb_colorization_enable = false; else if (strcmp(var.value, "enabled") == 0) gb_colorization_enable = true; //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.) // 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")); } } 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 = gambatte::gbcToRgb32(gbc_bios_palette[palnum * 4 + colornum]); gb.setDmgPaletteColor(palnum, colornum, rgb32); } } }
static void check_palette(void) { unsigned rgb32 = 0; const char *system_directory_c = NULL; environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &system_directory_c); if (!system_directory_c) { if (log_cb) log_cb(RETRO_LOG_WARN, "[Gambatte]: no system directory defined, unable to look for custom palettes.\n"); return; } std::string system_directory(system_directory_c); std::string custom_palette_path = system_directory + "/palettes/" + basename(rom_path) + ".pal"; std::ifstream palette_file(custom_palette_path.c_str()); // try to open the palette file in read-only mode if (!palette_file.is_open()) { // try again with the internal game name from the ROM header custom_palette_path = system_directory + "/palettes/" + std::string(internal_game_name) + ".pal"; palette_file.open(custom_palette_path.c_str()); } 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 custom_palette_path = system_directory + "/palettes/" + "default.pal"; palette_file.open(custom_palette_path.c_str()); } if (!palette_file.is_open()) return; // unable to find any custom palette file #if 0 if (log_cb) fprintf(RETRO_LOG_INFO, "[Gambatte]: using custom palette %s.\n", custom_palette_path.c_str()); #endif unsigned line_count = 0; for (std::string line; getline(palette_file, line); ) // iterate over file lines { line_count++; if (line[0]=='[') // skip ini sections continue; if (line[0]==';') // skip ini comments continue; if (line[0]=='\n') // skip empty lines continue; if (line.find("=") == std::string::npos) { if (log_cb) log_cb(RETRO_LOG_ERROR, "[Gambatte]: error in %s, line %d (color left as default).\n", custom_palette_path.c_str(), line_count); continue; // current line does not contain a palette color definition, so go to next line } // Supposed to be a typo here. if (startswith(line, "slectedScheme=")) continue; std::string line_value = line.substr(line.find("=") + 1); // extract the color value string std::stringstream ss(line_value); // convert the color value to int ss >> rgb32; if (!ss) { if (log_cb) log_cb(RETRO_LOG_ERROR, "[Gambatte]: unable to read palette color in %s, line %d (color left as default).\n", custom_palette_path.c_str(), line_count); continue; } #ifdef VIDEO_RGB565 rgb32=(rgb32&0x0000F8)>>3 |//red (rgb32&0x00FC00)>>5 |//green (rgb32&0xF80000)>>8;//blue #endif if (startswith(line, "Background0=")) gb.setDmgPaletteColor(0, 0, rgb32); else if (startswith(line, "Background1=")) gb.setDmgPaletteColor(0, 1, rgb32); else if (startswith(line, "Background2=")) gb.setDmgPaletteColor(0, 2, rgb32); else if (startswith(line, "Background3=")) gb.setDmgPaletteColor(0, 3, rgb32); else if (startswith(line, "Sprite%2010=")) gb.setDmgPaletteColor(1, 0, rgb32); else if (startswith(line, "Sprite%2011=")) gb.setDmgPaletteColor(1, 1, rgb32); else if (startswith(line, "Sprite%2012=")) gb.setDmgPaletteColor(1, 2, rgb32); else if (startswith(line, "Sprite%2013=")) gb.setDmgPaletteColor(1, 3, rgb32); else if (startswith(line, "Sprite%2020=")) gb.setDmgPaletteColor(2, 0, rgb32); else if (startswith(line, "Sprite%2021=")) gb.setDmgPaletteColor(2, 1, rgb32); else if (startswith(line, "Sprite%2022=")) gb.setDmgPaletteColor(2, 2, rgb32); else if (startswith(line, "Sprite%2023=")) gb.setDmgPaletteColor(2, 3, rgb32); else if (log_cb) log_cb(RETRO_LOG_ERROR, "[Gambatte]: error in %s, line %d (color left as default).\n", custom_palette_path.c_str(), line_count); } // endfor }