From 2a4995c21f297c73a0ff703f84656b13f4218e3f Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 7 Jan 2011 17:59:53 +0100 Subject: [PATCH] Starting Win32 support. --- Makefile | 2 +- Makefile.win32 | 58 ++++++++++++++++++++++++++++++++++++++++++++++ conf/config_file.c | 2 +- config.def.h | 16 ++++++++++--- driver.c | 3 +++ dynamic.c | 5 ++++ general.h | 11 +++++++-- gfx/gl.c | 5 +++- hqflt/filters.h | 2 ++ settings.c | 7 ++++++ ssnes.c | 11 +++++++-- ssnes.cfg | 12 +++++----- 12 files changed, 118 insertions(+), 16 deletions(-) create mode 100644 Makefile.win32 diff --git a/Makefile b/Makefile index 31cfd447da..1c42120fc7 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ TARGET = ssnes OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o LIBS = -DEFINES = +DEFINES = -DHAVE_CONFIG_H ifeq ($(HAVE_SRC), 1) LIBS += $(SRC_LIBS) diff --git a/Makefile.win32 b/Makefile.win32 new file mode 100644 index 0000000000..0e717c06c6 --- /dev/null +++ b/Makefile.win32 @@ -0,0 +1,58 @@ +TARGET = ssnes.exe +OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o + +CC = gcc +CXX = g++ + +HAVE_SRC = 1 +HAVE_SDL = 1 +libsnes = -lsnes + +LIBS = +DEFINES = -I. -DHAVE_SRC -DHAVE_SDL +LDFLAGS = -L. + +SRC_LIBS = -lsamplerate-0 +SDL_LIBS = -lSDLmain -lSDL + +ifeq ($(HAVE_SRC), 1) + LIBS += $(SRC_LIBS) + DEFINES += $(SRC_CFLAGS) +endif + +ifeq ($(HAVE_SDL), 1) + OBJ += gfx/gl.o input/sdl.o audio/sdl.o audio/buffer.o + LIBS += $(SDL_LIBS) -lopengl32 + DEFINES += $(SDL_CFLAGS) +endif + +LIBS += $(libsnes) + +CFLAGS = -Wall -O3 -g -std=gnu99 -I. + +all: $(TARGET) + +$(TARGET): $(OBJ) + $(CXX) -o $@ $(OBJ) $(LIBS) $(LDFLAGS) + +%.o: %.c + $(CC) $(CFLAGS) $(DEFINES) -c -o $@ $< + +install: $(TARGET) + install -m755 $(TARGET) $(DESTDIR)$(PREFIX)/bin + install -m644 ssnes.cfg $(DESTDIR)/etc/ssnes.cfg + +uninstall: $(TARGET) + rm -rf $(DESTDIR)/$(PREFIX)/bin/$(TARGET) + +clean: + rm -f *.o + rm -f audio/*.o + rm -f conf/*.o + rm -f gfx/*.o + rm -f record/*.o + rm -f hqflt/*.o + rm -f hqflt/snes_ntsc/*.o + rm -f $(TARGET) + +.PHONY: all install uninstall clean diff --git a/conf/config_file.c b/conf/config_file.c index 441256f9cd..dc945c2e6a 100644 --- a/conf/config_file.c +++ b/conf/config_file.c @@ -132,7 +132,7 @@ static void print_config(config_file_t *conf) struct entry_list *tmp = conf->entries; while (tmp != NULL) { - printf("Key: \"%s\", Value: \"%s\"\n", tmp->key, tmp->value); + SSNES_LOG("Config => Key: \"%s\", Value: \"%s\"\n", tmp->key, tmp->value); tmp = tmp->next; } } diff --git a/config.def.h b/config.def.h index fea34b99a7..1a0e8881b0 100644 --- a/config.def.h +++ b/config.def.h @@ -22,14 +22,24 @@ #ifndef __CONFIG_DEF_H #define __CONFIG_DEF_H -#include #include #include "libsnes.hpp" #include "driver.h" + +#ifdef HAVE_CONFIG_H #include "config.h" +#endif + +#ifdef HAVE_SDL +#include +#else +#error HAVE_SDL is not defined! +#endif #ifdef HAVE_SRC #include +#else +#error HAVE_SRC is not defined! #endif @@ -104,7 +114,7 @@ static const unsigned out_rate = 48000; // Input samplerate from libSNES. // Lower this (slightly) if you are experiencing frequent audio dropouts while vsync is enabled. -static const unsigned in_rate = 31950; +static const unsigned in_rate = 31980; // Audio device (e.g. hw:0,0 or /dev/audio). If NULL, will use defaults. static const char* audio_device = NULL; @@ -127,7 +137,7 @@ static const bool audio_sync = true; // Axis threshold (between 0.0 and 1.0) // How far an axis must be tilted to result in a button press -#define AXIS_THRESHOLD 0.8 +#define AXIS_THRESHOLD 0.5 #define AXIS_NEG(x) ((uint32_t)(x << 16) | 0xFFFF) #define AXIS_POS(x) ((uint32_t)(x) | 0xFFFF0000U) diff --git a/driver.c b/driver.c index fafb0139d1..67ce93c661 100644 --- a/driver.c +++ b/driver.c @@ -21,7 +21,10 @@ #include #include #include "hqflt/filters.h" + +#ifdef HAVE_CONFIG_H #include "config.h" +#endif static const audio_driver_t *audio_drivers[] = { #ifdef HAVE_ALSA diff --git a/dynamic.c b/dynamic.c index 5c8ff14ceb..54bf5a1177 100644 --- a/dynamic.c +++ b/dynamic.c @@ -18,7 +18,12 @@ #include "dynamic.h" #include "general.h" #include + +#ifdef HAVE_CONFIG_H #include "config.h" +#endif + +#include #ifdef HAVE_DYNAMIC #include diff --git a/general.h b/general.h index 9488c56327..ef1bfffbb3 100644 --- a/general.h +++ b/general.h @@ -23,7 +23,11 @@ #include "driver.h" #include #include "record/ffemu.h" + +#ifdef HAVE_CONFIG_H #include "config.h" +#endif + #ifdef HAVE_SRC #include #endif @@ -103,14 +107,17 @@ extern struct global g_extern; #define SSNES_LOG(msg, args...) do { \ if (g_extern.verbose) \ fprintf(stderr, "SSNES: " msg, ##args); \ + fflush(stderr); \ } while(0) #define SSNES_ERR(msg, args...) do { \ - fprintf(stderr, "SSNES [ERROR] :: " msg, ##args); \ + fprintf(stderr, "SSNES [ERROR] :: " msg, ##args); \ + fflush(stderr); \ } while(0) #define SSNES_WARN(msg, args...) do { \ - fprintf(stderr, "SSNES [WARN] :: " msg, ##args); \ + fprintf(stderr, "SSNES [WARN] :: " msg, ##args); \ + fflush(stderr); \ } while(0) #endif diff --git a/gfx/gl.c b/gfx/gl.c index 49f7773008..1044615bf8 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -24,7 +24,10 @@ #include #include #include "general.h" + +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #define NO_SDL_GLEXT #include @@ -276,7 +279,7 @@ static void gl_set_nonblock_state(void *data, bool state) { SSNES_LOG("GL VSync => %s\n", state ? "off" : "on"); #ifdef _WIN32 - static BOOL (APIENTRY wgl_swap_interval*)(int) = NULL; + static BOOL (APIENTRY *wgl_swap_interval)(int) = NULL; if (!wgl_swap_interval) SSNES_WARN("SDL VSync toggling seems to be broken, attempting to use WGL VSync call directly instead.\n"); if (!wgl_swap_interval) wgl_swap_interval = (BOOL (APIENTRY*)(int)) wglGetProcAddress("wglSwapIntervalEXT"); diff --git a/hqflt/filters.h b/hqflt/filters.h index 439b3f3727..0e73b294f2 100644 --- a/hqflt/filters.h +++ b/hqflt/filters.h @@ -19,7 +19,9 @@ #ifndef __FILTERS_H #define __FILTERS_H +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifdef HAVE_FILTER diff --git a/settings.c b/settings.c index b0df409ba7..5337f042c7 100644 --- a/settings.c +++ b/settings.c @@ -21,7 +21,11 @@ #include #include #include "hqflt/filters.h" + +#ifdef HAVE_CONFIG_H #include "config.h" +#endif + #include struct settings g_settings; @@ -60,6 +64,9 @@ static void set_defaults(void) case AUDIO_AL: def_audio = "openal"; break; + case AUDIO_SDL: + def_audio = "sdl"; + break; default: break; } diff --git a/ssnes.c b/ssnes.c index 2043640e5f..af3a1b724c 100644 --- a/ssnes.c +++ b/ssnes.c @@ -223,6 +223,12 @@ static void fill_pathname(char *out_path, char *in_path, const char *replace) #define FFMPEG_HELP_QUARK #endif +#ifdef _WIN32 +#define SSNES_DEFAULT_CONF_PATH_STR "\n\tDefaults to ssnes.cfg in same directory as ssnes.exe" +#else +#define SSNES_DEFAULT_CONF_PATH_STR " Defaults to $XDG_CONFIG_HOME/ssnes/ssnes.cfg" +#endif + static void print_help(void) { puts("================================================="); @@ -231,7 +237,8 @@ static void print_help(void) puts("Usage: ssnes [rom file] [-h/--help | -s/--save" FFMPEG_HELP_QUARK "]"); puts("\t-h/--help: Show this help message"); puts("\t-s/--save: Path for save file (*.srm). Required when rom is input from stdin"); - puts("\t-c/--config: Path for config file. Defaults to $XDG_CONFIG_HOME/ssnes/ssnes.cfg"); + puts("\t-c/--config: Path for config file." SSNES_DEFAULT_CONF_PATH_STR); + #ifdef HAVE_FFMPEG puts("\t-r/--record: Path to record video file. Settings for video/audio codecs are found in config file."); #endif @@ -354,7 +361,7 @@ int main(int argc, char *argv[]) SSNES_ERR("Could not read ROM file.\n"); exit(1); } - SSNES_LOG("ROM size: %zi bytes\n", rom_len); + SSNES_LOG("ROM size: %d bytes\n", (int)rom_len); if (g_extern.rom_file != NULL) fclose(g_extern.rom_file); diff --git a/ssnes.cfg b/ssnes.cfg index 2d38075cd4..ec4a31fc04 100644 --- a/ssnes.cfg +++ b/ssnes.cfg @@ -10,8 +10,8 @@ # video_yscale = 3.0 # Fullscreen resolution -# video_fullscreen_x = 1280 -# video_fullscreen_y = 720 + video_fullscreen_x = 1920 + video_fullscreen_y = 1200 # Start in fullscreen. Can be changed at runtime. # video_fullscreen = false @@ -43,16 +43,16 @@ # audio_enable = true # Audio output samplerate. -# audio_out_rate = 48000 + audio_out_rate = 48000 # Audio input samplerate from libsnes. # Lower this (slightly) if you are experiencing frequent audio dropouts while vsync is enabled. # Conversely, increase this slightly if you are experiencing good audio, # but lots of dropped frames. Reasonable values for this is 32000 +/- 100 Hz. -# audio_in_rate = 31950 + audio_in_rate = 31980 # Audio driver backend. Depending on configuration possible candidates are: alsa, oss, rsound, roar, openal -# audio_driver = alsa +# audio_driver = sdl # Override the default audio device the audio_driver uses. # audio_device = @@ -61,7 +61,7 @@ # audio_sync = true # Desired audio latency in milliseconds. Might not be honored if driver can't provide given latency. -# audio_latency = 64 + audio_latency = 16 # libsamplerate quality. Valid values are from 1 to 5. These values map to zero_order_hold, linear, sinc_fastest, sinc_medium and sinc_best. # audio_src_quality =