HMODULE LoadLibrarySystem(const std::wstring& library_name, std::wstring* out_path) { std::unique_ptr<wchar_t[]> system_directory(new wchar_t[MAX_PATH]); GetSystemDirectoryW(system_directory.get(), MAX_PATH); std::wstring lib_path(system_directory.get()); StringPathAppend(&lib_path, library_name); if (out_path) *out_path = lib_path; return LoadLibraryW(lib_path.c_str()); }
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 }
bool retro_load_game(const struct retro_game_info *info) { enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_XRGB8888; if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) { if (log_cb) log_cb(RETRO_LOG_INFO, "[ProSystem]: XRGB8888 is not supported.\n"); return false; } struct retro_input_descriptor desc[] = { { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Left" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "Up" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Down" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Right" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "1" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "2" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Console Reset" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Console Select" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Console Pause" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "Left Difficulty" }, { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "Right Difficulty" }, { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Left" }, { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "Up" }, { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Down" }, { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "1" }, { 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "2" }, { 0 }, }; environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc); memset(keyboard_data, 0, sizeof(keyboard_data)); // Difficulty switches: Left position = (B)eginner, Right position = (A)dvanced // Left difficulty switch defaults to left position, "(B)eginner" keyboard_data[15] = 1; // Right difficulty switch defaults to right position, "(A)dvanced", which fixes Tower Toppler keyboard_data[16] = 0; const char *system_directory_c = NULL; if (cartridge_Load((const uint8_t*)info->data, info->size)) { environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &system_directory_c); if (!system_directory_c) { if (log_cb) log_cb(RETRO_LOG_WARN, "[ProSystem]: no system directory defined, unable to look for ProSystem.dat\n"); database_enabled = false; } else { std::string system_directory(system_directory_c); std::string database_file_path = system_directory + "/ProSystem.dat"; std::ifstream database_file(database_file_path.c_str()); if (!database_file.is_open()) { if (log_cb) log_cb(RETRO_LOG_WARN, "[ProSystem]: ProSystem.dat not found, cannot load internal ROM database\n"); database_enabled = false; } else { database_filename = database_file_path; database_enabled = true; } } // BIOS is optional std::string system_directory(system_directory_c); std::string bios_file_path = system_directory + "/7800 BIOS (U).rom"; if (bios_Load(bios_file_path.c_str())) bios_enabled = true; database_Load(cartridge_digest); prosystem_Reset(); display_ResetPalette32(); return true; } return false; }