Ejemplo n.º 1
0
bool MDFNI_InitializeModules(const std::vector<MDFNGI *> &ExternalSystems)
{
    static MDFNGI *InternalSystems[] =
    {
#ifdef WANT_NES_EMU
        &EmulatedNES,
#endif

#ifdef WANT_SNES_EMU
        &EmulatedSNES,
#endif

#ifdef WANT_GB_EMU
        &EmulatedGB,
#endif

#ifdef WANT_GBA_EMU
        &EmulatedGBA,
#endif

#ifdef WANT_PCE_EMU
        &EmulatedPCE,
#endif

#ifdef WANT_PCE_FAST_EMU
        &EmulatedPCE_Fast,
#endif

#ifdef WANT_LYNX_EMU
        &EmulatedLynx,
#endif

#ifdef WANT_MD_EMU
        &EmulatedMD,
#endif

#ifdef WANT_PCFX_EMU
        &EmulatedPCFX,
#endif

#ifdef WANT_NGP_EMU
        &EmulatedNGP,
#endif

#ifdef WANT_PSX_EMU
        &EmulatedPSX,
#endif

#ifdef WANT_VB_EMU
        &EmulatedVB,
#endif

#ifdef WANT_WSWAN_EMU
        &EmulatedWSwan,
#endif

#ifdef WANT_SMS_EMU
        &EmulatedSMS,
        &EmulatedGG,
#endif

        &EmulatedCDPlay
    };
    std::string i_modules_string, e_modules_string;

    for(unsigned int i = 0; i < sizeof(InternalSystems) / sizeof(MDFNGI *); i++)
    {
        AddSystem(InternalSystems[i]);
        if(i)
            i_modules_string += " ";
        i_modules_string += std::string(InternalSystems[i]->shortname);
    }

    for(unsigned int i = 0; i < ExternalSystems.size(); i++)
    {
        AddSystem(ExternalSystems[i]);
        if(i)
            i_modules_string += " ";
        e_modules_string += std::string(ExternalSystems[i]->shortname);
    }

    MDFNI_printf(_("Internal emulation modules: %s\n"), i_modules_string.c_str());
    MDFNI_printf(_("External emulation modules: %s\n"), e_modules_string.c_str());


    for(unsigned int i = 0; i < MDFNSystems.size(); i++)
        MDFNSystemsPrio.push_back(MDFNSystems[i]);

    MDFNSystemsPrio.sort(MDFNSystemsPrio_CompareFunc);

#if 0
    std::string a_modules;

std::list<MDFNGI *>:
    iterator it;

    for(it = MDFNSystemsPrio.
             f
#endif

             CDUtility::CDUtility_Init();

            return(1);
}

int MDFNI_Initialize(const char *basedir, const std::vector<MDFNSetting> &DriverSettings)
{
    // FIXME static
    static std::vector<MDFNSetting> dynamic_settings;

    if(!MDFN_RunMathTests())
    {
        return(0);
    }


    memset(PortDataCache, 0, sizeof(PortDataCache));
    memset(PortDataLenCache, 0, sizeof(PortDataLenCache));
    memset(PortDeviceCache, 0, sizeof(PortDeviceCache));

    lzo_init();

    MDFNI_SetBaseDirectory(basedir);

    MDFN_InitFontData();

    // Generate dynamic settings
    for(unsigned int i = 0; i < MDFNSystems.size(); i++)
    {
        MDFNSetting setting;
        const char *sysname;

        sysname = (const char *)MDFNSystems[i]->shortname;

        if(!MDFNSystems[i]->soundchan)
            printf("0 sound channels for %s????\n", sysname);

        if(MDFNSystems[i]->soundchan == 2)
        {
            BuildDynamicSetting(&setting, sysname, "forcemono", MDFNSF_COMMON_TEMPLATE | MDFNSF_CAT_SOUND, CSD_forcemono, MDFNST_BOOL, "0");
            dynamic_settings.push_back(setting);
        }

        BuildDynamicSetting(&setting, sysname, "enable", MDFNSF_COMMON_TEMPLATE, CSD_enable, MDFNST_BOOL, "1");
        dynamic_settings.push_back(setting);

        BuildDynamicSetting(&setting, sysname, "tblur", MDFNSF_COMMON_TEMPLATE | MDFNSF_CAT_VIDEO, CSD_tblur, MDFNST_BOOL, "0");
        dynamic_settings.push_back(setting);

        BuildDynamicSetting(&setting, sysname, "tblur.accum", MDFNSF_COMMON_TEMPLATE | MDFNSF_CAT_VIDEO, CSD_tblur_accum, MDFNST_BOOL, "0");
        dynamic_settings.push_back(setting);

        BuildDynamicSetting(&setting, sysname, "tblur.accum.amount", MDFNSF_COMMON_TEMPLATE | MDFNSF_CAT_VIDEO, CSD_tblur_accum_amount, MDFNST_FLOAT, "50", "0", "100");
        dynamic_settings.push_back(setting);
    }

    if(DriverSettings.size())
        MDFN_MergeSettings(DriverSettings);

    // First merge all settable settings, then load the settings from the SETTINGS FILE OF DOOOOM
    MDFN_MergeSettings(MednafenSettings);
    MDFN_MergeSettings(dynamic_settings);
    MDFN_MergeSettings(MDFNMP_Settings);


    for(unsigned int x = 0; x < MDFNSystems.size(); x++)
    {
        if(MDFNSystems[x]->Settings)
            MDFN_MergeSettings(MDFNSystems[x]->Settings);
    }

    MDFN_MergeSettings(RenamedSettings);

    if(!MFDN_LoadSettings(basedir))
        return(0);

#ifdef WANT_DEBUGGER
    MDFNDBG_Init();
#endif

    return(1);
}

void MDFNI_Kill(void)
{
    MDFN_SaveSettings();
}

static double multiplier_save, volume_save;
static std::vector<int16> SoundBufPristine;

static void ProcessAudio(EmulateSpecStruct *espec)
{
    if(espec->SoundVolume != 1)
        volume_save = espec->SoundVolume;

    if(espec->soundmultiplier != 1)
        multiplier_save = espec->soundmultiplier;

    if(espec->SoundBuf && espec->SoundBufSize)
    {
        int16 *const SoundBuf = espec->SoundBuf + espec->SoundBufSizeALMS * MDFNGameInfo->soundchan;
        int32 SoundBufSize = espec->SoundBufSize - espec->SoundBufSizeALMS;
        const int32 SoundBufMaxSize = espec->SoundBufMaxSize - espec->SoundBufSizeALMS;


        if(qtrecorder && (volume_save != 1 || multiplier_save != 1))
        {
            int32 orig_size = SoundBufPristine.size();

            SoundBufPristine.resize(orig_size + SoundBufSize * MDFNGameInfo->soundchan);
            for(int i = 0; i < SoundBufSize * MDFNGameInfo->soundchan; i++)
                SoundBufPristine[orig_size + i] = SoundBuf[i];
        }

        if(espec->NeedSoundReverse)
        {
            int16 *yaybuf = SoundBuf;
            int32 slen = SoundBufSize;

            if(MDFNGameInfo->soundchan == 1)
            {
                for(int x = 0; x < (slen / 2); x++)
                {
                    int16 cha = yaybuf[slen - x - 1];
                    yaybuf[slen - x - 1] = yaybuf[x];
                    yaybuf[x] = cha;
                }
            }
            else if(MDFNGameInfo->soundchan == 2)
            {
                for(int x = 0; x < (slen * 2) / 2; x++)
                {
                    int16 cha = yaybuf[slen * 2 - (x&~1) - ((x&1) ^ 1) - 1];
                    yaybuf[slen * 2 - (x&~1) - ((x&1) ^ 1) - 1] = yaybuf[x];
                    yaybuf[x] = cha;
                }
            }
        }

        try
        {
            if(wavrecorder)
                wavrecorder->WriteSound(SoundBuf, SoundBufSize);
        }
        catch(std::exception &e)
        {
            MDFND_PrintError(e.what());
            delete wavrecorder;
            wavrecorder = NULL;
        }

        if(multiplier_save != LastSoundMultiplier)
        {
            ff_resampler.time_ratio(multiplier_save, 0.9965);
            LastSoundMultiplier = multiplier_save;
        }

        if(multiplier_save != 1)
        {
            if(FFDiscard)
            {
                if(SoundBufSize >= multiplier_save)
                    SoundBufSize /= multiplier_save;
            }
            else
            {
                if(MDFNGameInfo->soundchan == 2)
                {
                    assert(ff_resampler.max_write() >= SoundBufSize * 2);

                    for(int i = 0; i < SoundBufSize * 2; i++)
                        ff_resampler.buffer()[i] = SoundBuf[i];
                }
                else
                {
                    assert(ff_resampler.max_write() >= SoundBufSize * 2);

                    for(int i = 0; i < SoundBufSize; i++)
                    {
                        ff_resampler.buffer()[i * 2] = SoundBuf[i];
                        ff_resampler.buffer()[i * 2 + 1] = 0;
                    }
                }
                ff_resampler.write(SoundBufSize * 2);

                int avail = ff_resampler.avail();
                int real_read = std::min((int)(SoundBufMaxSize * MDFNGameInfo->soundchan), avail);

                if(MDFNGameInfo->soundchan == 2)
                    SoundBufSize = ff_resampler.read(SoundBuf, real_read ) >> 1;
                else
                    SoundBufSize = ff_resampler.read_mono_hack(SoundBuf, real_read );

                avail -= real_read;

                if(avail > 0)
                {
                    printf("ff_resampler.avail() > espec->SoundBufMaxSize * MDFNGameInfo->soundchan - %d\n", avail);
                    ff_resampler.clear();
                }
            }
        }

        if(volume_save != 1)
        {
            if(volume_save < 1)
            {
                int volume = (int)(16384 * volume_save);

                for(int i = 0; i < SoundBufSize * MDFNGameInfo->soundchan; i++)
                    SoundBuf[i] = (SoundBuf[i] * volume) >> 14;
            }
            else
            {
Ejemplo n.º 2
0
void MDFNI_Kill(void)
{
 MDFN_SaveSettings(settings_file_path.c_str());
 MDFN_KillSettings();
}