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 --- Makefile.trimui | 74 ++++++++++++++++++++++++++++++++++++ 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 +- 11 files changed, 140 insertions(+), 14 deletions(-) create mode 100644 Makefile.trimui diff --git a/Makefile.trimui b/Makefile.trimui new file mode 100644 index 0000000..20b03dd --- /dev/null +++ b/Makefile.trimui @@ -0,0 +1,74 @@ +GIT_VERSION := "$(shell git describe --abbrev=7 --dirty --always)" + +PRGNAME = snes9x + +VIDEO_BACKEND = sdl +INPUT_BACKEND = sdl +SOUND_BACKEND = sdl + +PREFIX = arm-buildroot-linux-gnueabi + +# define regarding OS, which compiler to use +CC = $(PREFIX)-gcc +STRIP = $(PREFIX)-strip +AS = $(PREFIX)-as +GASM = $(PREFIX)-g++ + +SYSROOT := $(shell $(CC) --print-sysroot) +SDL_CFLAGS := $(shell $(SYSROOT)/usr/bin/sdl-config --cflags) +SDL_LIBS := $(shell $(SYSROOT)/usr/bin/sdl-config --libs) + +# change compilation / linking flag options +CFLAGS = -DLSB_FIRST -DFAST_ALIGNED_LSB_WORD_ACCESS -I. -Ilibretro-common/include -Isrc -DINLINE="inline" -DRIGHTSHIFT_IS_SAR +CFLAGS += -Isource -I./shell/emu -I./shell/scalers -I./shell/emu -I./shell/audio -I./shell/menu -I./shell/video/sdl -I./shell/input -Ishell/headers + +CFLAGS += -Ofast -fsingle-precision-constant -fno-PIC -flto +ifndef PROFILE +CFLAGS += -falign-functions=1 -falign-jumps=1 -falign-loops=1 -falign-labels=1 +endif +CFLAGS += -mcpu=arm926ej-s -mtune=arm926ej-s +CFLAGS += -DNDEBUG -DLAGFIX -DAUDIO_FRAMESKIP -DNO_HIRES -DGIT_VERSION=\"$(GIT_VERSION)\" -DTRIMUI -fno-builtin -fno-exceptions -ffunction-sections -std=gnu99 +CFLAGS += -Wall -Wextra -pedantic -Wno-implicit-function-declaration -Wno-implicit-fallthrough -Wno-sign-compare -Wno-unused-variable -Wno-unused-function -Wno-uninitialized -Wno-strict-aliasing -Wno-overflow -fno-strict-overflow + +ifeq ($(PROFILE), YES) +CFLAGS += -fprofile-generate=./profile +else ifeq ($(PROFILE), APPLY) +CFLAGS += -fprofile-use -fprofile-dir=./profile -fbranch-probabilities +endif + +LDFLAGS = -lc -lgcc -lm $(SDL_LIBS) -no-pie -Wl,--as-needed -Wl,--gc-sections -s -flto +ifeq ($(SOUND_BACKEND), portaudio) +LDFLAGS += -lasound -lportaudio +endif +ifeq ($(SOUND_BACKEND), libao) +LDFLAGS += -lao +endif +ifeq ($(SOUND_BACKEND), alsa) +LDFLAGS += -lasound +endif +ifeq ($(SOUND_BACKEND), pulse) +LDFLAGS += -lpulse -lpulse-simple +endif + +ifeq ($(PROFILE), YES) +LDFLAGS += -lgcov +endif + +# Files to be compiled +SRCDIR = ./source ./shell/emu ./shell/scalers ./shell/audio/$(SOUND_BACKEND) ./shell/menu ./shell/video/$(VIDEO_BACKEND) ./shell/input/$(INPUT_BACKEND) ./shell/other +VPATH = $(SRCDIR) +SRC_C = $(foreach dir, $(SRCDIR), $(wildcard $(dir)/*.c)) +SRC_CP = $(foreach dir, $(SRCDIR), $(wildcard $(dir)/*.cpp)) +OBJ_C = $(notdir $(patsubst %.c, %.o, $(SRC_C))) +OBJ_CP = $(notdir $(patsubst %.cpp, %.o, $(SRC_CP))) +OBJS = $(OBJ_C) $(OBJ_CP) + +# Rules to make executable +$(PRGNAME): $(OBJS) + $(CC) $(CFLAGS) -o $(PRGNAME) $^ $(LDFLAGS) + +$(OBJ_C) : %.o : %.c + $(CC) $(CFLAGS) -c -o $@ $< + +clean: + rm -f $(PRGNAME)$(EXESUFFIX) *.o 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