diff --git a/Makefile b/Makefile index 57bdec9ae2..b22fdb4cff 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ ifeq ($(BUILD_FILTER), 1) OBJ += hqflt/snes_ntsc/snes_ntsc.o endif -CFLAGS = -Wall -O3 -std=gnu99 -Wno-unused-variable -I. $(DEFINES) +CFLAGS = -Wall -O0 -g -std=gnu99 -Wno-unused-variable -I. $(DEFINES) all: $(TARGET) diff --git a/driver.c b/driver.c index 5a4fc2f68b..9cd59a1375 100644 --- a/driver.c +++ b/driver.c @@ -37,36 +37,36 @@ void init_audio(void) { if (!audio_enable) { - audio_active = false; + g_extern.audio_active = false; return; } driver.audio_data = driver.audio->init(audio_device, out_rate, out_latency); if ( driver.audio_data == NULL ) - audio_active = false; + g_extern.audio_active = false; - if (!audio_sync && audio_active) + if (!audio_sync && g_extern.audio_active) driver.audio->set_nonblock_state(driver.audio_data, true); int err; - source = src_new(SAMPLERATE_QUALITY, 2, &err); - if (!source) - audio_active = false; + g_extern.source = src_new(SAMPLERATE_QUALITY, 2, &err); + if (!g_extern.source) + g_extern.audio_active = false; } void uninit_audio(void) { if (!audio_enable) { - audio_active = false; + g_extern.audio_active = false; return; } if ( driver.audio_data && driver.audio ) driver.audio->free(driver.audio_data); - if ( source ) - src_delete(source); + if ( g_extern.source ) + src_delete(g_extern.source); } void init_video_input(void) @@ -139,9 +139,6 @@ void uninit_video_input(void) driver.input->free(driver.input_data); } -bool video_active = true; -bool audio_active = true; - driver_t driver = { #if VIDEO_DRIVER == VIDEO_GL .video = &video_gl, diff --git a/driver.h b/driver.h index d5e215da9f..b17417012b 100644 --- a/driver.h +++ b/driver.h @@ -92,8 +92,6 @@ void uninit_video_input(void); void init_audio(void); void uninit_audio(void); -extern bool video_active; -extern bool audio_active; extern driver_t driver; //////////////////////////////////////////////// Backends diff --git a/general.h b/general.h index 06093dc95a..5f1331924f 100644 --- a/general.h +++ b/general.h @@ -23,14 +23,6 @@ #include #include "driver.h" -#define SSNES_LOG(msg, args...) do { \ - if (verbose) \ - fprintf(stderr, "SSNES: " msg, ##args); \ - } while(0) - -#define SSNES_ERR(msg, args...) do { \ - fprintf(stderr, "SSNES [ERROR] :: " msg, ##args); \ - } while(0) #define MAX_PLAYERS 2 #define MAX_BINDS 14 @@ -40,6 +32,7 @@ struct settings { float xscale; float yscale; + bool fullscreen; unsigned fullscreen_x; unsigned fullscreen_y; bool vsync; @@ -66,8 +59,26 @@ struct settings } input; }; +struct global +{ + bool verbose; + SRC_STATE *source; + bool audio_active; + bool video_active; +}; + void parse_config(void); extern struct settings g_settings; +extern struct global g_extern; + +#define SSNES_LOG(msg, args...) do { \ + if (g_extern.verbose) \ + fprintf(stderr, "SSNES: " msg, ##args); \ + } while(0) + +#define SSNES_ERR(msg, args...) do { \ + fprintf(stderr, "SSNES [ERROR] :: " msg, ##args); \ + } while(0) #endif diff --git a/settings.c b/settings.c index 9cbeb7e181..e40ffe2dc6 100644 --- a/settings.c +++ b/settings.c @@ -2,6 +2,7 @@ #include "conf/config_file.h" #include "config.h" #include +#include struct settings g_settings; @@ -9,12 +10,15 @@ static void set_defaults(void) { g_settings.video.xscale = xscale; g_settings.video.yscale = yscale; + g_settings.video.fullscreen = fullscreen; g_settings.video.fullscreen_x = fullscreen_x; g_settings.video.fullscreen_y = fullscreen_y; g_settings.video.vsync = vsync; - g_settings.video.smootn = video_smooth; + g_settings.video.smooth = video_smooth; g_settings.video.force_aspect = force_aspect; +#if HAVE_CG strncpy(g_settings.video.cg_shader_path, cg_shader_path, sizeof(g_settings.video.cg_shader_path) - 1); +#endif strncpy(g_settings.video.video_filter, "foo", sizeof(g_settings.video.video_filter) - 1); g_settings.audio.enable = audio_enable; @@ -126,7 +130,7 @@ void parse_config(void) if (config_get_int(conf, "audio_src_quality", &tmp_int)) { int quals[] = {SRC_ZERO_ORDER_HOLD, SRC_LINEAR, SRC_SINC_FASTEST, - SRC_SINC_MEDIUM, SRC_SINC_BEST}; + SRC_SINC_MEDIUM_QUALITY, SRC_SINC_BEST_QUALITY}; if (tmp_int > 0 && tmp_int < 6) g_settings.audio.src_quality = quals[tmp_int]; diff --git a/ssnes.c b/ssnes.c index 7ed812dd08..a35c3dd494 100644 --- a/ssnes.c +++ b/ssnes.c @@ -33,6 +33,10 @@ #include "hqflt/ntsc.h" #include "general.h" +struct global g_extern = { + .video_active = true, + .audio_active = true +}; // To avoid continous switching if we hold the button down, we require that the button must go from pressed, unpressed back to pressed to be able to toggle between then. @@ -46,9 +50,9 @@ void set_fast_forward_button(bool new_button_state) if (new_button_state && !old_button_state) { syncing_state = !syncing_state; - if (video_active) + if (g_extern.video_active) driver.video->set_nonblock_state(driver.video_data, syncing_state); - if (audio_active) + if (g_extern.audio_active) driver.audio->set_nonblock_state(driver.audio_data, (audio_sync) ? syncing_state : true); if (syncing_state) audio_chunk_size = AUDIO_CHUNK_SIZE_NONBLOCKING; @@ -79,7 +83,7 @@ static inline void process_frame (uint16_t * restrict out, const uint16_t * rest // Format received is 16-bit 0RRRRRGGGGGBBBBB static void video_frame(const uint16_t *data, unsigned width, unsigned height) { - if ( !video_active ) + if ( !g_extern.video_active ) return; #if VIDEO_FILTER == FILTER_HQ2X @@ -117,15 +121,14 @@ static void video_frame(const uint16_t *data, unsigned width, unsigned height) video_active = false; #else if ( !driver.video->frame(driver.video_data, data, width, height, (height == 448 || height == 478) ? 1024 : 2048) ) - video_active = false; + g_extern.video_active = false; #endif } -SRC_STATE* source = NULL; static void audio_sample(uint16_t left, uint16_t right) { - if ( !audio_active ) + if ( !g_extern.audio_active ) return; static float data[AUDIO_CHUNK_SIZE_NONBLOCKING]; @@ -148,14 +151,14 @@ static void audio_sample(uint16_t left, uint16_t right) src_data.end_of_input = 0; src_data.src_ratio = (double)out_rate / (double)in_rate; - src_process(source, &src_data); + src_process(g_extern.source, &src_data); src_float_to_short_array(outsamples, temp_outsamples, src_data.output_frames_gen * 2); if ( driver.audio->write(driver.audio_data, temp_outsamples, src_data.output_frames_gen * 4) < 0 ) { fprintf(stderr, "SSNES [ERROR]: Audio backend failed to write. Will continue without sound.\n"); - audio_active = false; + g_extern.audio_active = false; } data_ptr = 0; @@ -199,7 +202,6 @@ static void print_help(void) puts("\t-v/--verbose: Verbose logging"); } -bool fullscreen = START_FULLSCREEN; static FILE* rom_file = NULL; static char savefile_name_srm[256] = {0}; bool verbose = false; @@ -304,6 +306,7 @@ int main(int argc, char *argv[]) { snes_init(); parse_input(argc, argv); + parse_config(); void *rom_buf; ssize_t rom_len = 0; @@ -367,7 +370,7 @@ int main(int argc, char *argv[]) else if ( glfwGetKey( TOGGLE_FULLSCREEN ) ) { - fullscreen = !fullscreen; + g_settings.video.fullscreen = !g_settings.video.fullscreen; uninit_drivers(); init_drivers(); }