From adaecd14d484d309e4d9ba2353ae843ab5213aec Mon Sep 17 00:00:00 2001 From: neonloop Date: Wed, 10 Mar 2021 16:53:39 +0000 Subject: Initial trimui model s support --- shell/audio/alsa/sound_output.c | 4 ++++ shell/audio/oss/sound_output.c | 4 ++++ shell/audio/portaudio/sound_output.c | 4 ++++ shell/audio/sdl/sound_output.c | 19 +++++++++++++++++-- shell/audio/sound_output.h | 2 ++ shell/emu/core.c | 24 ++++++++++++++++++++++-- shell/headers/shared.h | 3 +++ shell/input/sdl/input.c | 2 +- shell/menu/menu.c | 16 ++++++++-------- shell/video/sdl/video_blit.c | 2 +- 10 files changed, 66 insertions(+), 14 deletions(-) (limited to 'shell') diff --git a/shell/audio/alsa/sound_output.c b/shell/audio/alsa/sound_output.c index 5173bb6..4da70a7 100644 --- a/shell/audio/alsa/sound_output.c +++ b/shell/audio/alsa/sound_output.c @@ -132,6 +132,10 @@ void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size) } } +bool Audio_Underrun_Likely() { + return false; +} + void Audio_Close() { if (handle) diff --git a/shell/audio/oss/sound_output.c b/shell/audio/oss/sound_output.c index 2d32b1f..39a7ba3 100644 --- a/shell/audio/oss/sound_output.c +++ b/shell/audio/oss/sound_output.c @@ -49,6 +49,10 @@ void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size) write(oss_audio_fd, buffer, buffer_size * 4 ); } +bool Audio_Underrun_Likely() { + return false; +} + void Audio_Close() { if (oss_audio_fd >= 0) diff --git a/shell/audio/portaudio/sound_output.c b/shell/audio/portaudio/sound_output.c index 226db5c..0c03c93 100644 --- a/shell/audio/portaudio/sound_output.c +++ b/shell/audio/portaudio/sound_output.c @@ -35,6 +35,10 @@ void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size) Pa_WriteStream( apu_stream, buffer, buffer_size); } +bool Audio_Underrun_Likely() { + return false; +} + void Audio_Close() { //Pa_Close(); diff --git a/shell/audio/sdl/sound_output.c b/shell/audio/sdl/sound_output.c index f14bb1d..ae1ab83 100644 --- a/shell/audio/sdl/sound_output.c +++ b/shell/audio/sdl/sound_output.c @@ -1,11 +1,14 @@ #include #include +#include #include #include #include #include "sound_output.h" +#define UNDERRUN_THRESHOLD 0.5 + static int32_t BUFFSIZE; static uint8_t *buffer; static uint32_t buf_read_pos = 0; @@ -36,14 +39,20 @@ static int32_t sdl_read_buffer(uint8_t* data, int32_t len) static void sdl_write_buffer(uint8_t* data, int32_t len) { + SDL_LockAudio(); for(uint32_t i = 0; i < len; i += 4) { - if(buffered_bytes == BUFFSIZE) return; // just drop samples + while (buffered_bytes == BUFFSIZE) { + SDL_UnlockAudio(); + usleep(1000); + SDL_LockAudio(); + } *(int32_t*)((char*)(buffer + buf_write_pos)) = *(int32_t*)((char*)(data + i)); //memcpy(buffer + buf_write_pos, data + i, 4); buf_write_pos = (buf_write_pos + 4) % BUFFSIZE; buffered_bytes += 4; } + SDL_UnlockAudio(); } void sdl_callback(void *unused, uint8_t *stream, int32_t len) @@ -90,9 +99,15 @@ uint32_t Audio_Init() void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size) { - SDL_LockAudio(); sdl_write_buffer(buffer, buffer_size * 4); +} + +bool Audio_Underrun_Likely() { + bool underrun_likely = false; + SDL_LockAudio(); + underrun_likely = buffered_bytes < BUFFSIZE * UNDERRUN_THRESHOLD; SDL_UnlockAudio(); + return underrun_likely; } void Audio_Close() diff --git a/shell/audio/sound_output.h b/shell/audio/sound_output.h index ba8a318..b770fbe 100644 --- a/shell/audio/sound_output.h +++ b/shell/audio/sound_output.h @@ -1,10 +1,12 @@ #ifndef SOUND_OUTPUT_H #define SOUND_OUTPUT_H +#include #include "shared.h" extern uint32_t Audio_Init(); extern void Audio_Write(int16_t* restrict buffer, uint32_t buffer_size); +extern bool Audio_Underrun_Likely(); extern void Audio_Close(); #endif diff --git a/shell/emu/core.c b/shell/emu/core.c index e20e43d..d4ff19d 100644 --- a/shell/emu/core.c +++ b/shell/emu/core.c @@ -274,6 +274,11 @@ static const uint32_t TblSkip[4][4] = { }; #endif +#ifdef AUDIO_FRAMESKIP +#define MAX_SKIP_COUNT 3 +static uint32_t SkipCnt = 0; +#endif + void Emulation_Run (void) { #ifndef USE_BLARGG_APU @@ -294,6 +299,21 @@ void Emulation_Run (void) #endif Settings.HardDisableAudio = false; +#ifdef AUDIO_FRAMESKIP + if (IPPU.RenderThisFrame) { + if (Audio_Underrun_Likely()) { + if (SkipCnt < MAX_SKIP_COUNT) { + SkipCnt++; + IPPU.RenderThisFrame = false; + } else { + SkipCnt = 0; + } + } + } else { + SkipCnt = 0; + } +#endif + S9xMainLoop(); #ifndef USE_BLARGG_APU @@ -310,12 +330,12 @@ void Emulation_Run (void) #endif -#ifdef FRAMESKIP +#if defined(FRAMESKIP) || defined(AUDIO_FRAMESKIP) if (IPPU.RenderThisFrame) { #endif Update_Video_Ingame(); -#ifdef FRAMESKIP +#if defined(FRAMESKIP) || defined(AUDIO_FRAMESKIP) IPPU.RenderThisFrame = false; } else diff --git a/shell/headers/shared.h b/shell/headers/shared.h index 968b9a2..0ceff9d 100644 --- a/shell/headers/shared.h +++ b/shell/headers/shared.h @@ -4,6 +4,9 @@ #if defined(BITTBOY) #define SOUND_OUTPUT_FREQUENCY 22050 #define SOUND_SAMPLES_SIZE 1024 +#elif defined(TRIMUI) +#define SOUND_OUTPUT_FREQUENCY 32000 +#define SOUND_SAMPLES_SIZE 1024 #elif defined(RS97) #define SOUND_OUTPUT_FREQUENCY 22050 #define SOUND_SAMPLES_SIZE 1024 diff --git a/shell/input/sdl/input.c b/shell/input/sdl/input.c index 885eaea..6ddc761 100644 --- a/shell/input/sdl/input.c +++ b/shell/input/sdl/input.c @@ -59,7 +59,7 @@ uint32_t S9xReadJoypad(int32_t port) case SDL_KEYDOWN: switch(event.key.keysym.sym) { - case SDLK_RCTRL: + case SDLK_ESCAPE: case SDLK_END: emulator_state = 1; break; diff --git a/shell/menu/menu.c b/shell/menu/menu.c index b79d5ab..a23ff59 100644 --- a/shell/menu/menu.c +++ b/shell/menu/menu.c @@ -81,16 +81,16 @@ static void config_load() option.config_buttons[0][2] = SDLK_DOWN; // DOWN option.config_buttons[0][3] = SDLK_LEFT; // LEFT - option.config_buttons[0][4] = SDLK_LCTRL; // A - option.config_buttons[0][5] = SDLK_LALT; // B + option.config_buttons[0][4] = SDLK_SPACE; // A + option.config_buttons[0][5] = SDLK_LCTRL; // B option.config_buttons[0][6] = SDLK_LSHIFT; // X - option.config_buttons[0][7] = SDLK_SPACE; // Y + option.config_buttons[0][7] = SDLK_LALT; // Y option.config_buttons[0][8] = SDLK_TAB; // L option.config_buttons[0][9] = SDLK_BACKSPACE; // R option.config_buttons[0][10] = SDLK_RETURN; // START - option.config_buttons[0][11] = SDLK_ESCAPE; // SELECT + option.config_buttons[0][11] = SDLK_RCTRL; // SELECT option.fullscreen = 1; } @@ -222,14 +222,14 @@ static void Input_Remapping() currentselection = 1; } break; - case SDLK_LCTRL: + case SDLK_SPACE: case SDLK_RETURN: pressed = 1; break; case SDLK_ESCAPE: option.config_buttons[controls_chosen][currentselection - 1] = 0; break; - case SDLK_LALT: + case SDLK_LCTRL: exit_input = 1; break; case SDLK_LEFT: @@ -439,11 +439,11 @@ void Menu() break; case SDLK_END: case SDLK_RCTRL: - case SDLK_LALT: + case SDLK_LCTRL: pressed = 1; currentselection = 1; break; - case SDLK_LCTRL: + case SDLK_SPACE: case SDLK_RETURN: pressed = 1; break; diff --git a/shell/video/sdl/video_blit.c b/shell/video/sdl/video_blit.c index 0e489c0..6a8f748 100644 --- a/shell/video/sdl/video_blit.c +++ b/shell/video/sdl/video_blit.c @@ -54,7 +54,7 @@ void Init_Video() SDL_ShowCursor(0); - sdl_screen = SDL_SetVideoMode(320, 240, 16, SDL_HWSURFACE); + sdl_screen = SDL_SetVideoMode(320, 240, 16, SDL_HWSURFACE | SDL_DOUBLEBUF); backbuffer = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 240, 16, 0,0,0,0); -- cgit v1.2.3