updated win32/sdl code

This commit is contained in:
ekeeke31 2010-01-27 07:12:26 +00:00
parent 2b78421402
commit 8f5d6b38c6
3 changed files with 43 additions and 29 deletions

View File

@ -368,17 +368,14 @@ void dos_update_input(void)
vdp_pal ^= 1; vdp_pal ^= 1;
/* save YM2612 context */ /* save YM2612 context */
unsigned char *temp = memalign(32,YM2612GetContextSize()); unsigned char *temp = malloc(YM2612GetContextSize());
if (temp) if (temp)
memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize()); memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize());
/* reinitialize all timings */ /* reinitialize all timings */
audio_init(snd.sample_rate, framerate); audio_init(snd.sample_rate, snd.frame_rate);
system_init(); system_init();
/* restore SRAM */
memfile_autoload(config.sram_auto,-1);
/* restore YM2612 context */ /* restore YM2612 context */
if (temp) if (temp)
{ {

View File

@ -7,12 +7,19 @@
# Defines : # Defines :
# LSB_FIRST : for little endian systems. # LSB_FIRST : for little endian systems.
# X86_ASM : enable x86 assembly optimizations # X86_ASM : enable x86 assembly optimizations
# LOGERROR
# LOGVDP
# LOGSOUND
NAME = gen_sdl.exe NAME = gen_sdl.exe
CC = gcc CC = gcc
CFLAGS = `sdl-config --cflags` -O6 -march=i686 -fomit-frame-pointer CFLAGS = `sdl-config --cflags` -O6 -march=i686 -fomit-frame-pointer
DEFINES = -DLSB_FIRST -DX86_ASM -DLOGERROR=1 -DLOGVDP=1 #-g -ggdb -pg
#-fomit-frame-pointer
#LDFLAGS = -g -ggdb -pg
DEFINES = -DLSB_FIRST -DX86_ASM
INCLUDES = -I. -I.. -I../z80 -I../m68k -I../sound -I../cart_hw -I../cart_hw/svp -I../ntsc INCLUDES = -I. -I.. -I../z80 -I../m68k -I../sound -I../cart_hw -I../cart_hw/svp -I../ntsc
LIBS = `sdl-config --libs` -lz -lm LIBS = `sdl-config --libs` -lz -lm

View File

@ -90,18 +90,23 @@ static void sdl_sound_update()
int i; int i;
short* p; short* p;
int size = audio_update();
if (use_sound)
{
SDL_LockAudio(); SDL_LockAudio();
p = (short*)sdl_sound.current_pos; p = (short*)sdl_sound.current_pos;
for(i = 0; i < snd.buffer_size; ++i) { for(i = 0; i < size; ++i) {
*p = snd.buffer[0][i]; *p = snd.buffer[0][i];
++p; ++p;
*p = snd.buffer[1][i]; *p = snd.buffer[1][i];
++p; ++p;
} }
sdl_sound.current_pos = (char*)p; sdl_sound.current_pos = (char*)p;
sdl_sound.current_emulated_samples += snd.buffer_size * 2 * sizeof(short); sdl_sound.current_emulated_samples += size * 2 * sizeof(short);
SDL_UnlockAudio(); SDL_UnlockAudio();
} }
}
static void sdl_sound_close() static void sdl_sound_close()
{ {
@ -196,20 +201,28 @@ static void sdl_video_close()
struct { struct {
SDL_sem* sem_sync; SDL_sem* sem_sync;
unsigned ticks;
} sdl_sync; } sdl_sync;
/* sync */ /* sync */
static Uint32 sdl_sync_timer_callback(Uint32 interval) static Uint32 sdl_sync_timer_callback(Uint32 interval)
{ {
/*char caption[100]; SDL_SemPost(sdl_sync.sem_sync);
char caption[100];
char region[10]; char region[10];
if (region_code == REGION_USA) sprintf(region,"USA"); if (region_code == REGION_USA) sprintf(region,"USA");
else if (region_code == REGION_EUROPE) sprintf(region,"EUR"); else if (region_code == REGION_EUROPE) sprintf(region,"EUR");
else sprintf(region,"JAP"); else sprintf(region,"JAP");
sprintf(caption, "Genesis Plus/SDL - %s (%s) - %d fps - 0x%04X", rominfo.international, region, vdp_rate, realchecksum);
SDL_WM_SetCaption(caption, NULL);*/ sdl_sync.ticks++;
SDL_SemPost(sdl_sync.sem_sync); if (sdl_sync.ticks == (vdp_pal ? 50 : 20))
{
int fps = vdp_pal ? (sdl_video.frames_rendered / 3) : sdl_video.frames_rendered;
sdl_sync.ticks = sdl_video.frames_rendered = 0;
sprintf(caption, "Genesis Plus/SDL - %s (%s) - 0x%04X - %d fps", rominfo.international, region, realchecksum, fps);
SDL_WM_SetCaption(caption, NULL);
}
return interval; return interval;
} }
@ -220,6 +233,7 @@ static int sdl_sync_init()
return 0; return 0;
} }
sdl_sync.sem_sync = SDL_CreateSemaphore(0); sdl_sync.sem_sync = SDL_CreateSemaphore(0);
sdl_sync.ticks = 0;
return 1; return 1;
} }
@ -305,17 +319,14 @@ static int sdl_control_update(SDLKey keystate)
vdp_pal ^= 1; vdp_pal ^= 1;
/* save YM2612 context */ /* save YM2612 context */
unsigned char *temp = memalign(32,YM2612GetContextSize()); unsigned char *temp = malloc(YM2612GetContextSize());
if (temp) if (temp)
memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize()); memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize());
/* reinitialize all timings */ /* reinitialize all timings */
audio_init(snd.sample_rate, framerate); audio_init(snd.sample_rate, snd.frame_rate);
system_init(); system_init();
/* restore SRAM */
memfile_autoload(config.sram_auto,-1);
/* restore YM2612 context */ /* restore YM2612 context */
if (temp) if (temp)
{ {
@ -537,6 +548,7 @@ int main (int argc, char **argv)
/* initialize emulation */ /* initialize emulation */
audio_init(SOUND_FREQUENCY, vdp_pal ? 50:60); audio_init(SOUND_FREQUENCY, vdp_pal ? 50:60);
//audio_init(SOUND_FREQUENCY, 1000000.0/16715.0);
system_init(); system_init();
/* load SRAM */ /* load SRAM */
@ -576,8 +588,6 @@ int main (int argc, char **argv)
} }
sdl_video_update(); sdl_video_update();
audio_update(snd.buffer_size);
if(use_sound)
sdl_sound_update(); sdl_sound_update();
if(!turbo_mode && sdl_sync.sem_sync && sdl_video.frames_rendered % 3 == 0) if(!turbo_mode && sdl_sync.sem_sync && sdl_video.frames_rendered % 3 == 0)