From 9a4356c70e05fd111d93ed443248c39af2d94c0d Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Tue, 27 May 2014 08:12:26 +0000 Subject: [PATCH 1/3] makefile.odx: Build with more optimisations on the GCW Zero toolchain. --- makefile.odx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile.odx b/makefile.odx index 2d2b23e..84e44c3 100644 --- a/makefile.odx +++ b/makefile.odx @@ -70,7 +70,7 @@ F_OPTS = -fpermissive -falign-functions -falign-loops -falign-labels -falign-jum -ftree-vectorize -fweb -frename-registers ifeq "$(OSTYPE)" "gcw0" -CFLAGS = -D_GCW0_ -G0 -O3 -march=mips32 -mtune=mips32r2 -Isrc -Isrc/$(MAMEOS) -Isrc/zlib -mhard-float -mbranch-likely -mno-mips16 $(W_OPTS) $(F_OPTS) +CFLAGS = -D_GCW0_ -G0 -O3 -Isrc -Isrc/$(MAMEOS) -Isrc/zlib $(W_OPTS) $(F_OPTS) else CFLAGS = -D_GCW0_ -G0 -O3 -march=mips32 -mtune=mips32 -Isrc -Isrc/$(MAMEOS) -Isrc/zlib -msoft-float --mbranch-likely -mno-mips16 $(W_OPTS) $(F_OPTS) endif From 1db32be4345a19083940644b9227cd7a8d0cd8c3 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Tue, 27 May 2014 08:13:14 +0000 Subject: [PATCH 2/3] odx: Improve audio buffering, at the cost of a bit of lag. When starting a game, buffer enough of it so that an underrun doesn't occur every 2 seconds. Then refill the buffer in the same way if an underrun occurs so that more underruns don't occur. --- src/odx/minimal.cpp | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/odx/minimal.cpp b/src/odx/minimal.cpp index c9350ae..883c193 100644 --- a/src/odx/minimal.cpp +++ b/src/odx/minimal.cpp @@ -50,6 +50,8 @@ unsigned char odx_keys[OD_KEY_MAX]; SDL_Joystick *odx_joyanalog; #endif +int odx_sound_filling; + extern int master_volume; signed int axis_x=0, axis_y=0; @@ -180,6 +182,7 @@ void odx_sound_play(void *buff, int len) if( odx_sndlen+len > odx_audio_buffer_len ) { // Overrun + printf("Audio: overrun occurred, %5d/%5d\n", odx_sndlen+len, odx_audio_buffer_len); odx_sndlen = 0; SDL_UnlockMutex(sndlock); return; @@ -196,17 +199,33 @@ void odx_sound_play(void *buff, int len) static void odx_sound_callback(void *data, Uint8 *stream, int len) { SDL_LockMutex(sndlock); - - if( odx_sndlen < len ) { + + if ( odx_sound_filling && odx_sndlen < len * 3 / 2 ) { + printf("Audio: filling up...\n"); + memset( stream, 0, len ); + SDL_UnlockMutex(sndlock); + return; + } + else if ( odx_sound_filling ) { + printf("Audio: done filling up\n"); + odx_sound_filling = 0; + } + // - - FILL LINE - - + // Before here, if we had insufficient sound, we'd keep on filling + // first. After here, if we have insufficient sound, we drain it then + // start filling it up. + if ( odx_sndlen < len ) { + printf("Audio: filling up after underrun, %4d/%4d\n", odx_sndlen, len); + odx_sound_filling = 1; memcpy( stream, data, odx_sndlen ); memset( stream+odx_sndlen, 0, len-odx_sndlen ); odx_sndlen = 0; - SDL_UnlockMutex(sndlock); - return; } - memcpy( stream, data, len ); - odx_sndlen -= len; - memcpy( data, data + len, odx_sndlen ); + else { + memcpy( stream, data, len ); + odx_sndlen -= len; + memcpy( data, data + len, odx_sndlen ); + } SDL_UnlockMutex(sndlock); } @@ -234,6 +253,8 @@ void odx_sound_thread_start(void) SDL_CloseAudio(); exit(1); } + + odx_sound_filling = 1; SDL_PauseAudio(0); } From e7011e6190a93be80fb3bd325ecd89bf01b5da32 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Tue, 27 May 2014 08:14:26 +0000 Subject: [PATCH 3/3] odx: Use triple-buffering (on the GCW Zero) if SDL_TRIPLEBUF is defined. This allows more CPU to be spent emulating frames, thus increasing FPS, instead of waiting for the secondary buffer to be free if a game is being emulated between 30 and 60 FPS and the CPU usage is not 100%. --- src/odx/minimal.cpp | 32 +++++++++++++++++++++++--------- src/odx/minimal.h | 1 + 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/odx/minimal.cpp b/src/odx/minimal.cpp index 883c193..08a476d 100644 --- a/src/odx/minimal.cpp +++ b/src/odx/minimal.cpp @@ -284,7 +284,13 @@ void odx_init(int ticks_per_second, int bpp, int rate, int bits, int stereo, int /* General video & audio stuff */ SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO); - video = SDL_SetVideoMode(320, 240, 16, SDL_DOUBLEBUF | SDL_HWSURFACE ); + video = SDL_SetVideoMode(320, 240, 16, SDL_HWSURFACE | +#ifdef SDL_TRIPLEBUF + SDL_TRIPLEBUF +#else + SDL_DOUBLEBUF +#endif + ); if(video == NULL) { fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError()); exit(1); @@ -330,7 +336,7 @@ void odx_init(int ticks_per_second, int bpp, int rate, int bits, int stereo, int odx_video_color8(255,255,255,255); odx_video_setpalette(); - odx_clear_video(); + odx_clear_video_multibuf(); } void odx_deinit(void) @@ -373,7 +379,7 @@ void odx_set_video_mode(int bpp,int width,int height) exit(1); } */ - odx_clear_video(); + odx_clear_video_multibuf(); //od_screen16=(unsigned short *) layer->pixels; od_screen16=(unsigned short *) video->pixels; @@ -381,13 +387,18 @@ void odx_set_video_mode(int bpp,int width,int height) } void odx_clear_video() { - if (SDL_MUSTLOCK(video)) SDL_LockSurface(video); - //SDL_FillRect( layer, NULL, 0 ); SDL_FillRect( video, NULL, 0 ); - if (SDL_MUSTLOCK(video)) SDL_UnlockSurface(video); odx_video_flip(); } +void odx_clear_video_multibuf() { + odx_clear_video(); + odx_clear_video(); +#ifdef SDL_TRIPLEBUF + odx_clear_video(); +#endif +} + // Font: THIN8X8.pf : Exported from PixelFontEdit 2.7.0 static const unsigned char fontdata8x8[2048] = { @@ -576,11 +587,14 @@ void odx_printf_init(void) static void odx_text_log(char *texto) { if (!log) { - odx_clear_video(); - odx_clear_video(); // do twice to avoid flickering + odx_clear_video_multibuf(); } + // do as many times as we have buffers to avoid flickering odx_text(od_screen16,0,log,texto,255); odx_video_flip(); - odx_text(od_screen16,0,log,texto,255); odx_video_flip(); // do twice to avoid flickering + odx_text(od_screen16,0,log,texto,255); odx_video_flip(); +#ifdef SDL_TRIPLEBUF + odx_text(od_screen16,0,log,texto,255); odx_video_flip(); +#endif log+=8; if(log>239) log=0; } diff --git a/src/odx/minimal.h b/src/odx/minimal.h index 42d0fcc..3bd193b 100644 --- a/src/odx/minimal.h +++ b/src/odx/minimal.h @@ -84,6 +84,7 @@ extern void odx_deinit(void); extern void odx_set_clock(int mhz); extern void odx_set_video_mode(int bpp,int width,int height); extern void odx_clear_video(); +extern void odx_clear_video_multibuf(); extern void odx_printf(char* fmt, ...); extern void odx_printf_init(void);