.fixed ROM file extension detection (again)

.improved audio/video synchronization for PAL games in 50Hz TV modes (now use VSYNC like NTSC games in 60hz modes)
This commit is contained in:
ekeeke31 2011-04-28 00:09:40 +00:00
parent 8ef3139f9e
commit f9beafa96c
5 changed files with 78 additions and 39 deletions

View File

@ -292,8 +292,8 @@ int FileSelector(void)
/* get ROM filename without extension */
sprintf (text, "%s", filelist[selection].filename);
int i = strlen(text) - 1;
while (i && (text[i] != '.')) i--;
if (i) text[i] = 0;
while ((i > 0) && (text[i] != '.')) i--;
if (i > 0) text[i] = 0;
/* ROM database informations */
sprintf (fname, "%s/db/%s.xml", DEFAULT_PATH, text);

View File

@ -1033,7 +1033,6 @@ static const uint16 vc_table[4][2] =
static void systemmenu ()
{
int ret, quit = 0;
float framerate;
u8 *temp;
gui_menu *m = &menu_system;
gui_item *items = m->items;
@ -1104,9 +1103,17 @@ static void systemmenu ()
memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize());
}
/* reinitialize all timings */
framerate = vdp_pal ? 50.0 : ((config.tv_mode == 1) ? 60.0 : ((config.render || interlaced) ? 59.94 : (1000000.0/16715.0)));
audio_init(snd.sample_rate, framerate);
/* reinitialize audio timings */
if (vdp_pal)
{
audio_init(snd.sample_rate, (config.tv_mode == 0) ? 50.0 : (config.render ? 50.00 : (1000000.0/19967.5)));
}
else
{
audio_init(snd.sample_rate, (config.tv_mode == 1) ? 60.0 : (config.render ? 59.94 : (1000000.0/16715.0)));
}
/* reinitialize system emulation */
system_init();
/* restore YM2612 context */
@ -1244,7 +1251,6 @@ static void videomenu ()
{
u16 state[2];
int ret, quit = 0;
float framerate;
u8 *temp;
gui_menu *m = &menu_video;
gui_item *items = m->items;
@ -1344,8 +1350,16 @@ static void videomenu ()
}
/* reinitialize audio timings */
framerate = (config.tv_mode == 1) ? 60.0 : ((config.render || interlaced) ? 59.94 : (1000000.0/16715.0));
audio_init(snd.sample_rate, framerate);
if (vdp_pal)
{
audio_init(snd.sample_rate, (config.tv_mode == 0) ? 50.0 : (config.render ? 50.00 : (1000000.0/19967.5)));
}
else
{
audio_init(snd.sample_rate, (config.tv_mode == 1) ? 60.0 : (config.render ? 59.94 : (1000000.0/16715.0)));
}
/* reinitialize sound chip emulation */
sound_init();
/* restore YM2612 context */
@ -1379,8 +1393,16 @@ static void videomenu ()
}
/* reinitialize audio timings */
framerate = (config.tv_mode == 1) ? 60.0 : ((config.render || interlaced) ? 59.94 : (1000000.0/16715.0));
audio_init(snd.sample_rate, framerate);
if (vdp_pal)
{
audio_init(snd.sample_rate, (config.tv_mode == 0) ? 50.0 : (config.render ? 50.00 : (1000000.0/19967.5)));
}
else
{
audio_init(snd.sample_rate, (config.tv_mode == 1) ? 60.0 : (config.render ? 59.94 : (1000000.0/16715.0)));
}
/* reinitialize sound chip emulation */
sound_init();
/* restore YM2612 context */
@ -3151,7 +3173,9 @@ void menu_execute(void)
/* Autosave SRAM */
if (config.s_auto & 1)
{
slot_autosave(0,config.s_device);
}
#ifdef HW_RVL
/* Wiimote shutdown */

View File

@ -150,8 +150,8 @@ void gx_audio_Start(void)
AUDIO_RegisterDMACallback(NULL);
DSP_Halt();
/* when not using 60hz mode, frame emulation is synchronized with Audio Interface DMA */
if (gc_pal | vdp_pal)
/* when TV mode does not match emulated video mode, frame emulation is synchronized with Audio Interface DMA */
if (gc_pal != vdp_pal)
{
AUDIO_RegisterDMACallback(ai_callback);
}

View File

@ -1329,24 +1329,26 @@ void gx_video_Stop(void)
/* Menu mode -> Emulation mode */
void gx_video_Start(void)
{
/* 50Hz/60Hz mode */
if ((config.tv_mode == 1) || ((config.tv_mode == 2) && vdp_pal))
{
gc_pal = 1;
}
else
{
gc_pal = 0;
}
#ifdef HW_RVL
VIDEO_SetTrapFilter(config.trap);
VIDEO_SetGamma((int)(config.gamma * 10.0));
#endif
/* TV mode */
if ((config.tv_mode == 1) || ((config.tv_mode == 2) && vdp_pal))
{
/* 50 Hz */
gc_pal = 1;
}
else
{
/* 60 Hz */
gc_pal = 0;
}
/* VSYNC callbacks */
/* in 60hz mode, frame emulation is synchronized with Video Interrupt */
if (!gc_pal && !vdp_pal)
/* If TV mode matches emulated video mode, frame emulation is synchronized with Video Interrupt */
if (gc_pal == vdp_pal)
{
VIDEO_SetPreRetraceCallback(vi_callback);
}

View File

@ -174,8 +174,8 @@ static void run_emulation(void)
/* check interlaced mode change */
if (bitmap.viewport.changed & 4)
{
/* in original 60hz modes, audio is synced with framerate */
if (!config.render && !vdp_pal && (config.tv_mode != 1))
/* VSYNC "original" mode */
if (!config.render && (gc_pal == vdp_pal))
{
u8 *temp = memalign(32,YM2612GetContextSize());
if (temp)
@ -184,7 +184,16 @@ static void run_emulation(void)
memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize());
/* framerate has changed, reinitialize audio timings */
if (vdp_pal)
{
audio_init(SAMPLERATE_48KHZ, interlaced ? 50.00 : (1000000.0/19967.5));
}
else
{
audio_init(SAMPLERATE_48KHZ, interlaced ? 59.94 : (1000000.0/16715.0));
}
/* reinitialize sound chip emulation */
sound_init();
/* restore YM2612 context */
@ -219,8 +228,8 @@ void reloadrom (int size, char *name)
/* ROM filename without extension*/
sprintf(rom_filename,"%s",name);
int i = strlen(rom_filename) - 1;
while (i && (rom_filename[i] != '.')) i--;
if (i) rom_filename[i] = 0;
while ((i > 0) && (rom_filename[i] != '.')) i--;
if (i > 0) rom_filename[i] = 0;
if (hotswap)
{
@ -237,16 +246,20 @@ void reloadrom (int size, char *name)
}
else
{
/* initialize audio emulation */
/* Initialize audio emulation */
/* To prevent any sound skipping, sound chips must run at the exact same speed as the rest of emulation (see sound.c) */
/* In 60hz video modes with NTSC emulation, we need perfect synchronization with video hardware interrupt (VSYNC) */
/* Wii & GC framerate has been measured to be exactly 59.94 fps in 240i/480i/480p video modes, ~59.825 fps in 240p */
/* In other modes, emulation is synchronized with audio hardware instead and we use default framerates (50Hz for PAL, 60Hz for NTSC). */
float framerate = vdp_pal ? 50.0 : ((config.tv_mode == 1) ? 60.0 : (config.render ? 59.94 : (1000000.0/16715.0)));
/* output samplerate has been measured to be ~48044 samples/sec on GC, 48000 samples/sec on Wii */
audio_init(SAMPLERATE_48KHZ, framerate);
/* When TV output mode matches emulated video mode, we use video hardware interrupt (VSYNC) and exact framerates for perfect synchronization */
/* In 60Hz TV modes, Wii & GC framerates have been measured to be 59.94 (interlaced or progressive) and ~59.825 fps (non-interlaced) */
/* In 50Hz TV modes, Wii & GC framerates have been measured to be 50.00 (interlaced) and ~50.845 fps (non-interlaced) */
/* When modes does not match, emulation is synchronized with audio hardware interrupt (DMA) and we use default framerates (50Hz for PAL, 60Hz for NTSC). */
if (vdp_pal)
{
audio_init(SAMPLERATE_48KHZ, (config.tv_mode == 0) ? 50.0 : (config.render ? 50.00 : (1000000.0/19967.5)));
}
else
{
audio_init(SAMPLERATE_48KHZ, (config.tv_mode == 1) ? 60.0 : (config.render ? 59.94 : (1000000.0/16715.0)));
}
/* system power ON */
system_init ();