/**
 * Controller_Config_Save(): Copy the new controller config to the main Gens config.
 */
void Controller_Config_Save(void)
{
	GtkWidget *check_teamplayer_1, *check_teamplayer_2;
	GtkWidget *combobox_padtype_1;
	GtkWidget *combobox_padtype_1B;
	GtkWidget *combobox_padtype_1C;
	GtkWidget *combobox_padtype_1D;
	GtkWidget *combobox_padtype_2;
	GtkWidget *combobox_padtype_2B;
	GtkWidget *combobox_padtype_2C;
	GtkWidget *combobox_padtype_2D;
	
	// Copy the new controller key configuration.
	memcpy(input->m_keyMap, keyConfig, sizeof(input->m_keyMap));

	// Set the controller types.
	// (Controller_1_Type & 0x10) == Teamplayer enabled
	// (Controller_1_Type & 0x01) == 6-button
	// TODO: Clean up controller type handling.
	
	// Set the Teamplayer options.
	check_teamplayer_1 = lookup_widget(controller_config_window, "check_teamplayer_1");
	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_teamplayer_1)))
		Controller_1_Type |= 0x10;
	else
		Controller_1_Type &= ~0x10;
	
	check_teamplayer_2 = lookup_widget(controller_config_window, "check_teamplayer_2");
	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_teamplayer_2)))
		Controller_2_Type |= 0x10;
	else
		Controller_2_Type &= ~0x10;
	
	// Set 3/6 button options.
	combobox_padtype_1 = lookup_widget(controller_config_window, "combobox_padtype_1");
	if (gtk_combo_box_get_active(GTK_COMBO_BOX(combobox_padtype_1)) == 1)
		Controller_1_Type |= 0x01;
	else
		Controller_1_Type &= ~0x01;
	
	combobox_padtype_1B = lookup_widget(controller_config_window, "combobox_padtype_1B");
	if (gtk_combo_box_get_active(GTK_COMBO_BOX(combobox_padtype_1B)) == 1)
		Controller_1B_Type |= 0x01;
	else
		Controller_1B_Type &= ~0x01;
	
	combobox_padtype_1C = lookup_widget(controller_config_window, "combobox_padtype_1C");
	if (gtk_combo_box_get_active(GTK_COMBO_BOX(combobox_padtype_1C)) == 1)
		Controller_1C_Type |= 0x01;
	else
		Controller_1C_Type &= ~0x01;
	
	combobox_padtype_1D = lookup_widget(controller_config_window, "combobox_padtype_1D");
	if (gtk_combo_box_get_active(GTK_COMBO_BOX(combobox_padtype_1D)) == 1)
		Controller_1D_Type |= 0x01;
	else
		Controller_1D_Type &= ~0x01;
	
	combobox_padtype_2 = lookup_widget(controller_config_window, "combobox_padtype_2");
	if (gtk_combo_box_get_active(GTK_COMBO_BOX(combobox_padtype_2)) == 1)
		Controller_2_Type |= 0x01;
	else
		Controller_2_Type &= ~0x01;
	
	combobox_padtype_2B = lookup_widget(controller_config_window, "combobox_padtype_2B");
	if (gtk_combo_box_get_active(GTK_COMBO_BOX(combobox_padtype_2B)) == 1)
		Controller_2B_Type |= 0x01;
	else
		Controller_2B_Type &= ~0x01;
	
	combobox_padtype_2C = lookup_widget(controller_config_window, "combobox_padtype_2C");
	if (gtk_combo_box_get_active(GTK_COMBO_BOX(combobox_padtype_2C)) == 1)
		Controller_2C_Type |= 0x01;
	else
		Controller_2C_Type &= ~0x01;
	
	combobox_padtype_2D = lookup_widget(controller_config_window, "combobox_padtype_2D");
	if (gtk_combo_box_get_active(GTK_COMBO_BOX(combobox_padtype_2D)) == 1)
		Controller_2D_Type |= 0x01;
	else
		Controller_2D_Type &= ~0x01;
	
	// Rebuild the I/O table for teamplayer.
	Make_IO_Table();
}
예제 #2
0
/**
 * load(): Load Gens configuration.
 * @param filename Configuration filename.
 * @param Game_Active ???
 */
int Config::load(const string& filename, void* gameActive)
{
    int new_val, i;
    char buf[256];

#ifdef GENS_OS_WIN32
    SetCurrentDirectory(PathNames.Gens_EXE_Path);
#endif /* GENS_OS_WIN32 */

    INI cfg(filename);

    CRam_Flag = 1;

    // Paths
    cfg.getString("General", "ROM Path", PathNames.Gens_Path, Rom_Dir, sizeof(Rom_Dir));
    cfg.getString("General", "Save Path", PathNames.Gens_Path, State_Dir, sizeof(State_Dir));
    cfg.getString("General", "SRAM Path", PathNames.Gens_Path, SRAM_Dir, sizeof(SRAM_Dir));
    cfg.getString("General", "BRAM Path", PathNames.Gens_Path, BRAM_Dir, sizeof(BRAM_Dir));
    cfg.getString("General", "Dump Path", PathNames.Gens_Path, PathNames.Dump_WAV_Dir, sizeof(PathNames.Dump_WAV_Dir));
    cfg.getString("General", "Dump GYM Path", PathNames.Gens_Path, PathNames.Dump_GYM_Dir, sizeof(PathNames.Dump_GYM_Dir));
    cfg.getString("General", "Screen Shot Path", PathNames.Gens_Path, PathNames.Screenshot_Dir, sizeof(PathNames.Screenshot_Dir));
    cfg.getString("General", "Patch Path", PathNames.Gens_Path, Patch_Dir, sizeof(Patch_Dir));
    cfg.getString("General", "IPS Patch Path", PathNames.Gens_Path, IPS_Dir, sizeof(IPS_Dir));

    // Genesis BIOS
    cfg.getString("General", "Genesis BIOS", "", BIOS_Filenames.MD_TMSS, sizeof(BIOS_Filenames.MD_TMSS));

    // SegaCD BIOSes
    cfg.getString("General", "USA CD BIOS", "", BIOS_Filenames.SegaCD_US, sizeof(BIOS_Filenames.SegaCD_US));
    cfg.getString("General", "Europe CD BIOS", "", BIOS_Filenames.MegaCD_EU, sizeof(BIOS_Filenames.MegaCD_EU));
    cfg.getString("General", "Japan CD BIOS", "", BIOS_Filenames.MegaCD_JP, sizeof(BIOS_Filenames.MegaCD_JP));

    // 32X BIOSes
    cfg.getString("General", "32X 68000 BIOS", "", BIOS_Filenames._32X_MC68000, sizeof(BIOS_Filenames._32X_MC68000));
    cfg.getString("General", "32X Master SH2 BIOS", "", BIOS_Filenames._32X_MSH2, sizeof(BIOS_Filenames._32X_MSH2));
    cfg.getString("General", "32X Slave SH2 BIOS", "", BIOS_Filenames._32X_SSH2, sizeof(BIOS_Filenames._32X_SSH2));

    // Last 9 ROMs
    for (i = 0; i < 9; i++)
    {
        sprintf(buf, "ROM %d", i + 1);
        cfg.getString("General", buf, "", Recent_Rom[i], sizeof(Recent_Rom[i]));
    }

#ifdef GENS_CDROM
    // Physical CD-ROM support for SegaCD
#if defined(GENS_OS_WIN32)
    // Win32 ASPI uses a device ID number.
    cdromDeviceID = cfg.getInt("Options", "CD Drive", 0);
#elif defined(GENS_OS_UNIX)
    // Unix uses a device name.
    cfg.getString("General", "CD Drive", "/dev/cdrom", cdromDeviceName, sizeof(cdromDeviceName));
#endif /* GENS_OS_WIN32 / GENS_OS_UNIX */
    cdromSpeed = cfg.getInt("General", "CD Speed", 0);
#endif /* GENS_CDROM */

    Current_State = cfg.getInt("General", "State Number", 0);
    Language = cfg.getInt("General", "Language", 0);
    Window_Pos.x = cfg.getInt("General", "Window X", 0);
    Window_Pos.y = cfg.getInt("General", "Window Y", 0);
    Intro_Style = cfg.getInt("General", "Intro Style", 0);
    draw->setIntroEffectColor(cfg.getInt("General", "Free Mode Color", 7));
    Sleep_Time = cfg.getInt("General", "Allow Idle", 0) & 1;

    // Video adjustments
    Contrast_Level = cfg.getInt("Graphics", "Contrast", 100);
    Brightness_Level = cfg.getInt("Graphics", "Brightness", 100);
    Greyscale = cfg.getInt("Graphics", "Greyscale", 0);
    Invert_Color = cfg.getInt("Graphics", "Invert", 0);

    // Video settings
    Video.VSync_FS = cfg.getInt("Graphics", "Full Screen VSync", 0) & 1;
    Video.VSync_W = cfg.getInt("Graphics", "Windows VSync", 0) & 1;
    draw->setFullScreen(cfg.getBool("Graphics", "Full Screen", false));
    Video.borderColorEmulation = cfg.getBool("Graphics", "Border Color Emulation", true);
    Video.pauseTint = cfg.getBool("Graphics", "Pause Tint", true);

    // Renderer: Full Screen
    string renderTag = cfg.getString("Graphics", "Render Fullscreen", "");
    mapStrToInt::iterator renderMDP;
    if (renderTag.empty())
        Video.Render_FS = 1;
    else
    {
        std::transform(renderTag.begin(), renderTag.end(), renderTag.begin(), ::tolower);
        renderMDP = PluginMgr::tblRenderPlugins.find(renderTag);
        if (renderMDP == PluginMgr::tblRenderPlugins.end())
            Video.Render_FS = 1;
        else
            Video.Render_FS = (*renderMDP).second;
    }

    // Renderer: Windowed
    renderTag = cfg.getString("Graphics", "Render Windowed", "");
    if (renderTag.empty())
        Video.Render_W = 1;
    else
    {
        std::transform(renderTag.begin(), renderTag.end(), renderTag.begin(), ::tolower);
        renderMDP = PluginMgr::tblRenderPlugins.find(renderTag);
        if (renderMDP == PluginMgr::tblRenderPlugins.end())
            Video.Render_W = 1;
        else
            Video.Render_W = (*renderMDP).second;
    }

#ifndef GENS_OS_WIN32
    // TODO: Add a 555/565 override for Win32.
    bppOut = (unsigned char)(cfg.getInt("Graphics", "Bits Per Pixel", 32));
    if (bppOut != 15 && bppOut != 16 && bppOut != 32)
    {
        // Invalid bpp. Set it to 32 by default.
        bppOut = 32;
    }
    bppMD = bppOut;
#endif /* GENS_OS_WIN32 */

#ifdef GENS_OPENGL
    Video.OpenGL = cfg.getInt("Graphics", "Render OpenGL", 0);
    Video.Width_GL = cfg.getInt("Graphics", "OpenGL Width", 640);
    Video.Height_GL = cfg.getInt("Graphics", "OpenGL Height", 480);
    Video.glLinearFilter = cfg.getInt("Graphics", "OpenGL Filter", 0);

    // Set the OpenGL renderer.
    // NOTE: Don't do this while Gens is loading; otherwise, GTK+ raises an assert
    // because the window hasn't been created yet.
    if (is_gens_running())
        Options::setOpenGL(Video.OpenGL);
#endif

    //Set_Render(Full_Screen, -1, 1);

    // Recalculate the MD and 32X palettes using the new color and video mode settings.
    // NOTE: This is only done if Gens is currently running.
    // If Gens isn't running, then this is before Gens had a chance to parse
    // command line arguments, so things may change later.
    if (is_gens_running())
        Recalculate_Palettes();

    Options::setStretch(cfg.getInt("Graphics", "Stretch", 0));
#ifdef GENS_OS_WIN32
    Options::setSwRender(cfg.getBool("Graphics", "Software Blit", false));
#endif /* GENS_OS_WIN32 */
    Sprite_Over = cfg.getInt("Graphics", "Sprite Limit", 1);
    Frame_Skip = cfg.getInt("Graphics", "Frame Skip", -1);

    // Sound settings
    audio->setSoundRate(cfg.getInt("Sound", "Rate", 22050));
    audio->setStereo(cfg.getBool("Sound", "Stereo", true));

    if (cfg.getInt("Sound", "Z80 State", 1))
        Z80_State |= 1;
    else
        Z80_State &= ~1;

    // Only load the IC sound settings if sound can be initialized.
    new_val = cfg.getInt("Sound", "State", 1);
    if (new_val == audio->enabled() ||
            (new_val != audio->enabled() && Options::setSoundEnable(true)))
    {
        YM2612_Enable = cfg.getInt("Sound", "YM2612 State", 1);
        PSG_Enable = cfg.getInt("Sound", "PSG State", 1);
        DAC_Enable = cfg.getInt("Sound", "DAC State", 1);
        PCM_Enable = cfg.getInt("Sound", "PCM State", 1);
        PWM_Enable = cfg.getInt("Sound", "PWM State", 1);
        CDDA_Enable = cfg.getInt("Sound", "CDDA State", 1);

        // Improved sound options
        YM2612_Improv = cfg.getInt("Sound", "YM2612 Improvement", 0);
        DAC_Improv = cfg.getInt("Sound", "DAC Improvement", 0);
        PSG_Improv = cfg.getInt("Sound", "PSG Improvement", 0);
    }

    // Country codes
    Country = cfg.getInt("CPU", "Country", -1);
    Country_Order[0] = cfg.getInt("CPU", "Prefered Country 1", 0);
    Country_Order[1] = cfg.getInt("CPU", "Prefered Country 2", 1);
    Country_Order[2] = cfg.getInt("CPU", "Prefered Country 3", 2);
    Check_Country_Order();

    // CPU options

    SegaCD_Accurate = cfg.getInt("CPU", "Perfect synchro between main and sub CPU (Sega CD)", 0);
    MSH2_Speed = cfg.getInt("CPU", "Main SH2 Speed", 100);
    SSH2_Speed = cfg.getInt("CPU", "Slave SH2 Speed", 100);

    // Make sure the SH2 speeds aren't below 0.
    if (MSH2_Speed < 0)
        MSH2_Speed = 0;
    if (SSH2_Speed < 0)
        SSH2_Speed = 0;

    // Various settings
    draw->setFastBlur(cfg.getBool("Options", "Fast Blur", false));
    draw->setFPSEnabled(cfg.getBool("Options", "FPS", false));
    draw->setFPSStyle(cfg.getInt("Options", "FPS Style", 0));
    draw->setMsgEnabled(cfg.getBool("Options", "Message", true));
    draw->setMsgStyle(cfg.getInt("Options", "Message Style", 0));
    Show_LED = cfg.getInt("Options", "LED", 1);
    Auto_Fix_CS = cfg.getInt("Options", "Auto Fix Checksum", 0);
    Auto_Pause = cfg.getInt("Options", "Auto Pause", 0);

    // SegaCD BRAM cartridge size
    BRAM_Ex_Size = cfg.getInt("Options", "RAM Cart Size", 3);
    if (BRAM_Ex_Size == -1)
    {
        BRAM_Ex_State &= 1;
        BRAM_Ex_Size = 0;
    }
    else if (BRAM_Ex_Size < -1 || BRAM_Ex_Size > 3)
        BRAM_Ex_Size = 3;
    else
        BRAM_Ex_State |= 0x100;

    // Miscellaneous files
#if defined(__WIN32__)
    cfg.getString("Options", "7z Binary", "C:\\Program Files\\7-Zip\\7z.exe",
                  Misc_Filenames._7z_Binary, sizeof(Misc_Filenames._7z_Binary));
    cfg.getString("Options", "RAR Binary", "C:\\Program Files\\WinRAR\\Rar.exe",
                  Misc_Filenames.RAR_Binary, sizeof(Misc_Filenames.RAR_Binary));
#else /* !defined(__WIN32__) */
    cfg.getString("Options", "7z Binary", "/usr/bin/7z",
                  Misc_Filenames._7z_Binary, sizeof(Misc_Filenames._7z_Binary));
    cfg.getString("Options", "RAR Binary", "/usr/bin/rar",
                  Misc_Filenames.RAR_Binary, sizeof(Misc_Filenames.RAR_Binary));
#endif

    // Controller settings
    Controller_1_Type = cfg.getInt("Input", "P1.Type", 1);
    Controller_1B_Type = cfg.getInt("Input", "P1B.Type", 1);
    Controller_1C_Type = cfg.getInt("Input", "P1C.Type", 1);
    Controller_1D_Type = cfg.getInt("Input", "P1D.Type", 1);
    Controller_2_Type = cfg.getInt("Input", "P2.Type", 1);
    Controller_2B_Type = cfg.getInt("Input", "P2B.Type", 1);
    Controller_2C_Type = cfg.getInt("Input", "P2C.Type", 1);
    Controller_2D_Type = cfg.getInt("Input", "P2D.Type", 1);

    for (i = 0; i < 8; i++)
    {
        sprintf(buf, "%s.Up", PlayerNames[i]);
        input->m_keyMap[i].Up = cfg.getInt("Input", buf, keyDefault[i].Up);
        sprintf(buf, "%s.Down", PlayerNames[i]);
        input->m_keyMap[i].Down = cfg.getInt("Input", buf, keyDefault[i].Down);
        sprintf(buf, "%s.Left", PlayerNames[i]);
        input->m_keyMap[i].Left = cfg.getInt("Input", buf, keyDefault[i].Left);
        sprintf(buf, "%s.Right", PlayerNames[i]);
        input->m_keyMap[i].Right = cfg.getInt("Input", buf, keyDefault[i].Right);
        sprintf(buf, "%s.Start", PlayerNames[i]);
        input->m_keyMap[i].Start = cfg.getInt("Input", buf, keyDefault[i].Start);
        sprintf(buf, "%s.A", PlayerNames[i]);
        input->m_keyMap[i].A = cfg.getInt("Input", buf, keyDefault[i].A);
        sprintf(buf, "%s.B", PlayerNames[i]);
        input->m_keyMap[i].B = cfg.getInt("Input", buf, keyDefault[i].B);
        sprintf(buf, "%s.C", PlayerNames[i]);
        input->m_keyMap[i].C = cfg.getInt("Input", buf, keyDefault[i].C);
        sprintf(buf, "%s.Mode", PlayerNames[i]);
        input->m_keyMap[i].Mode = cfg.getInt("Input", buf, keyDefault[i].Mode);
        sprintf(buf, "%s.X", PlayerNames[i]);
        input->m_keyMap[i].X = cfg.getInt("Input", buf, keyDefault[i].X);
        sprintf(buf, "%s.Y", PlayerNames[i]);
        input->m_keyMap[i].Y = cfg.getInt("Input", buf, keyDefault[i].Y);
        sprintf(buf, "%s.Z", PlayerNames[i]);
        input->m_keyMap[i].Z = cfg.getInt("Input", buf, keyDefault[i].Z);
    }

    // Create the TeamPlayer I/O table.
    Make_IO_Table();

    // Done.
    return 1;
}