From 8f5d6b38c673847a30277236565bb438127472b9 Mon Sep 17 00:00:00 2001 From: ekeeke31 Date: Wed, 27 Jan 2010 07:12:26 +0000 Subject: [PATCH] updated win32/sdl code --- source/unused/dos/dos.c | 7 ++--- source/unused/win/Makefile | 9 +++++- source/unused/win/main.c | 56 ++++++++++++++++++++++---------------- 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/source/unused/dos/dos.c b/source/unused/dos/dos.c index de77f20..eab598c 100644 --- a/source/unused/dos/dos.c +++ b/source/unused/dos/dos.c @@ -368,17 +368,14 @@ void dos_update_input(void) vdp_pal ^= 1; /* save YM2612 context */ - unsigned char *temp = memalign(32,YM2612GetContextSize()); + unsigned char *temp = malloc(YM2612GetContextSize()); if (temp) memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize()); /* reinitialize all timings */ - audio_init(snd.sample_rate, framerate); + audio_init(snd.sample_rate, snd.frame_rate); system_init(); - /* restore SRAM */ - memfile_autoload(config.sram_auto,-1); - /* restore YM2612 context */ if (temp) { diff --git a/source/unused/win/Makefile b/source/unused/win/Makefile index 96df525..f049a84 100644 --- a/source/unused/win/Makefile +++ b/source/unused/win/Makefile @@ -7,12 +7,19 @@ # Defines : # LSB_FIRST : for little endian systems. # X86_ASM : enable x86 assembly optimizations +# LOGERROR +# LOGVDP +# LOGSOUND NAME = gen_sdl.exe CC = gcc 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 LIBS = `sdl-config --libs` -lz -lm diff --git a/source/unused/win/main.c b/source/unused/win/main.c index f24cfcd..3317606 100644 --- a/source/unused/win/main.c +++ b/source/unused/win/main.c @@ -90,17 +90,22 @@ static void sdl_sound_update() int i; short* p; - SDL_LockAudio(); - p = (short*)sdl_sound.current_pos; - for(i = 0; i < snd.buffer_size; ++i) { - *p = snd.buffer[0][i]; - ++p; - *p = snd.buffer[1][i]; - ++p; + int size = audio_update(); + + if (use_sound) + { + SDL_LockAudio(); + p = (short*)sdl_sound.current_pos; + for(i = 0; i < size; ++i) { + *p = snd.buffer[0][i]; + ++p; + *p = snd.buffer[1][i]; + ++p; + } + sdl_sound.current_pos = (char*)p; + sdl_sound.current_emulated_samples += size * 2 * sizeof(short); + SDL_UnlockAudio(); } - sdl_sound.current_pos = (char*)p; - sdl_sound.current_emulated_samples += snd.buffer_size * 2 * sizeof(short); - SDL_UnlockAudio(); } static void sdl_sound_close() @@ -196,20 +201,28 @@ static void sdl_video_close() struct { SDL_sem* sem_sync; + unsigned ticks; } sdl_sync; /* sync */ static Uint32 sdl_sync_timer_callback(Uint32 interval) { - /*char caption[100]; + SDL_SemPost(sdl_sync.sem_sync); + char caption[100]; char region[10]; if (region_code == REGION_USA) sprintf(region,"USA"); else if (region_code == REGION_EUROPE) sprintf(region,"EUR"); 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_SemPost(sdl_sync.sem_sync); + + sdl_sync.ticks++; + 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; } @@ -220,6 +233,7 @@ static int sdl_sync_init() return 0; } sdl_sync.sem_sync = SDL_CreateSemaphore(0); + sdl_sync.ticks = 0; return 1; } @@ -305,17 +319,14 @@ static int sdl_control_update(SDLKey keystate) vdp_pal ^= 1; /* save YM2612 context */ - unsigned char *temp = memalign(32,YM2612GetContextSize()); + unsigned char *temp = malloc(YM2612GetContextSize()); if (temp) memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize()); /* reinitialize all timings */ - audio_init(snd.sample_rate, framerate); + audio_init(snd.sample_rate, snd.frame_rate); system_init(); - /* restore SRAM */ - memfile_autoload(config.sram_auto,-1); - /* restore YM2612 context */ if (temp) { @@ -536,7 +547,8 @@ int main (int argc, char **argv) SDL_UnlockSurface(sdl_video.surf_bitmap); /* 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(); /* load SRAM */ @@ -576,9 +588,7 @@ int main (int argc, char **argv) } 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) {