diff --git a/.gitignore b/.gitignore index 760a601098..d296741986 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,15 @@ *.o *.so *.dll -ssnes +/ssnes /config.h /config.mk /tools/ssnes-joyconfig +*.sdf +*.opensdf +*.suo +Debug +Release +ipch +*.user +*.filters diff --git a/Makefile b/Makefile index 5b87d987df..763ab95c8f 100644 --- a/Makefile +++ b/Makefile @@ -91,7 +91,7 @@ ifeq ($(HAVE_COREAUDIO), 1) endif ifeq ($(HAVE_SDL), 1) - OBJ += gfx/sdl.o gfx/sdlwrap.o input/sdl.o audio/sdl.o fifo_buffer.o + OBJ += gfx/sdl_gfx.o gfx/sdlwrap.o input/sdl_input.o audio/sdl_audio.o fifo_buffer.o DEFINES += $(SDL_CFLAGS) $(BSD_LOCAL_INC) LIBS += $(SDL_LIBS) @@ -133,7 +133,7 @@ else ifeq ($(HAVE_CG), 1) endif ifeq ($(HAVE_DYLIB), 1) - OBJ += gfx/ext.o audio/ext.o + OBJ += gfx/ext_gfx.o audio/ext_audio.o LIBS += $(DYLIB_LIB) endif diff --git a/Makefile.win b/Makefile.win index a2eb2015e1..7b2aa7a1a1 100644 --- a/Makefile.win +++ b/Makefile.win @@ -35,7 +35,7 @@ LDFLAGS = -L. -static-libgcc LDCXXFLAGS = -static-libstdc++ -s ifeq ($(HAVE_SDL), 1) - OBJ += gfx/sdl.o gfx/gl.o gfx/sdlwrap.o input/sdl.o audio/sdl.o fifo_buffer.o + OBJ += gfx/sdl_gfx.o gfx/gl.o gfx/sdlwrap.o input/sdl_input.o audio/sdl_audio.o fifo_buffer.o LIBS += -lSDL DEFINES += -ISDL -DHAVE_SDL endif @@ -112,7 +112,7 @@ ifeq ($(HAVE_FBO), 1) endif ifeq ($(HAVE_DYLIB), 1) - OBJ += gfx/ext.o audio/ext.o + OBJ += gfx/ext_gfx.o audio/ext_audio.o endif ifeq ($(HAVE_PYTHON), 1) diff --git a/audio/alsa.c b/audio/alsa.c index 40652b6913..a2220dbf34 100644 --- a/audio/alsa.c +++ b/audio/alsa.c @@ -16,10 +16,10 @@ */ -#include "driver.h" +#include "../driver.h" #include #include -#include "general.h" +#include "../general.h" #define TRY_ALSA(x) if (x < 0) { \ goto error; \ diff --git a/audio/dsound.c b/audio/dsound.c index f4228214ab..db8dfcc60b 100644 --- a/audio/dsound.c +++ b/audio/dsound.c @@ -15,7 +15,7 @@ * If not, see . */ -#include "driver.h" +#include "../driver.h" #include #include "../boolean.h" #include @@ -23,8 +23,8 @@ #include #include -#include "fifo_buffer.h" -#include "general.h" +#include "../fifo_buffer.h" +#include "../general.h" typedef struct dsound { diff --git a/audio/ext.c b/audio/ext_audio.c similarity index 98% rename from audio/ext.c rename to audio/ext_audio.c index 3d35d074c5..ece65b24b7 100644 --- a/audio/ext.c +++ b/audio/ext_audio.c @@ -19,9 +19,9 @@ #include "../boolean.h" #include #include -#include "driver.h" -#include "dynamic.h" -#include "general.h" +#include "../driver.h" +#include "../dynamic.h" +#include "../general.h" #include typedef struct audio_ext diff --git a/audio/hermite.c b/audio/hermite.c index f4fa3f76c0..718750183e 100644 --- a/audio/hermite.c +++ b/audio/hermite.c @@ -35,8 +35,8 @@ static inline float hermite_kernel(float mu1, float a, float b, float c, float d mu2 = mu1 * mu1; mu3 = mu2 * mu1; - m0 = (c - a) * 0.5; - m1 = (d - b) * 0.5; + m0 = (c - a) * 0.5f; + m1 = (d - b) * 0.5f; a0 = +2 * mu3 - 3 * mu2 + 1; a1 = mu3 - 2 * mu2 + mu1; @@ -71,7 +71,7 @@ void hermite_process(hermite_resampler_t *re, struct hermite_data *data) re->r_frac += r_step; for (unsigned i = 0; i < CHANNELS; i++) { - float res = hermite_kernel(re->r_frac, + float res = hermite_kernel((float)re->r_frac, re->chan_data[i][0], re->chan_data[i][1], re->chan_data[i][2], re->chan_data[i][3]); *out_data++ = res; } diff --git a/audio/jack.c b/audio/jack.c index c076ff726c..95481bfead 100644 --- a/audio/jack.c +++ b/audio/jack.c @@ -16,9 +16,9 @@ */ -#include "driver.h" +#include "../driver.h" #include -#include "general.h" +#include "../general.h" #include #include diff --git a/audio/openal.c b/audio/openal.c index 8b01e5a6ad..2104810554 100644 --- a/audio/openal.c +++ b/audio/openal.c @@ -15,8 +15,7 @@ * If not, see . */ - -#include "driver.h" +#include "../driver.h" #ifdef __APPLE__ #include diff --git a/audio/sdl.c b/audio/sdl_audio.c similarity index 98% rename from audio/sdl.c rename to audio/sdl_audio.c index a684131f0c..57682355e1 100644 --- a/audio/sdl.c +++ b/audio/sdl_audio.c @@ -16,7 +16,7 @@ */ -#include "driver.h" +#include "../driver.h" #include #include "../boolean.h" #include @@ -26,8 +26,8 @@ #include "SDL.h" #include "SDL_audio.h" #include "SDL_thread.h" -#include "general.h" -#include "fifo_buffer.h" +#include "../general.h" +#include "../fifo_buffer.h" typedef struct sdl_audio { diff --git a/audio/utils.c b/audio/utils.c index 9c68c23166..dab7d10751 100644 --- a/audio/utils.c +++ b/audio/utils.c @@ -18,7 +18,7 @@ void audio_convert_float_to_s16_C(int16_t *out, { for (size_t i = 0; i < samples; i++) { - int32_t val = in[i] * 0x8000; + int32_t val = (int32_t)(in[i] * 0x8000); out[i] = (val > 0x7FFF) ? 0x7FFF : (val < -0x8000 ? -0x8000 : (int16_t)val); } } diff --git a/audio/xaudio-c/xaudio.h b/audio/xaudio-c/xaudio.h index 395b75212c..71e6164e34 100644 --- a/audio/xaudio-c/xaudio.h +++ b/audio/xaudio-c/xaudio.h @@ -210,7 +210,11 @@ static inline HRESULT XAudio2Create(IXAudio2 **ppXAudio2) { IXAudio2 *pXAudio2; +#ifdef __cplusplus + HRESULT hr = CoCreateInstance(CLSID_XAudio2, NULL, CLSCTX_INPROC_SERVER, IID_IXAudio2, (void**)&pXAudio2); +#else HRESULT hr = CoCreateInstance(&CLSID_XAudio2, NULL, CLSCTX_INPROC_SERVER, &IID_IXAudio2, (void**)&pXAudio2); +#endif if (SUCCEEDED(hr)) { diff --git a/audio/xaudio.c b/audio/xaudio.c index fdfa7466c4..0eab5b8442 100644 --- a/audio/xaudio.c +++ b/audio/xaudio.c @@ -15,10 +15,10 @@ * If not, see . */ -#include "driver.h" +#include "../driver.h" #include #include "xaudio-c/xaudio-c.h" -#include "general.h" +#include "../general.h" typedef struct { diff --git a/bps.c b/bps.c index cbbb70c5c1..061e84e59e 100644 --- a/bps.c +++ b/bps.c @@ -19,6 +19,7 @@ #include "movie.h" #include #include "boolean.h" +#include "msvc/msvc_compat.h" enum bps_mode { diff --git a/conf/config_file.c b/conf/config_file.c index d8d751ab81..59573c030e 100644 --- a/conf/config_file.c +++ b/conf/config_file.c @@ -24,6 +24,7 @@ #include #include "../strl.h" #include "../posix_string.h" +#include "../msvc/msvc_compat.h" #if !defined(_WIN32) && !defined(__CELLOS_LV2__) #include // MAXPATHLEN diff --git a/driver.c b/driver.c index 152473fa33..4855f860bc 100644 --- a/driver.c +++ b/driver.c @@ -196,7 +196,7 @@ static void init_dsp_plugin(void) return; } - const ssnes_dsp_plugin_t* (*SSNES_API_CALLTYPE plugin_init)(void) = + const ssnes_dsp_plugin_t* (SSNES_API_CALLTYPE *plugin_init)(void) = (const ssnes_dsp_plugin_t *(SSNES_API_CALLTYPE*)(void))dylib_proc(g_extern.audio_data.dsp_lib, "ssnes_dsp_plugin_init"); if (!plugin_init) { @@ -404,8 +404,8 @@ static void init_filter(void) unsigned height = g_extern.system.geom.max_height; g_extern.filter.psize(&width, &height); - unsigned pow2_x = next_pow2(ceil(width)); - unsigned pow2_y = next_pow2(ceil(height)); + unsigned pow2_x = next_pow2(width); + unsigned pow2_y = next_pow2(height); unsigned maxsize = pow2_x > pow2_y ? pow2_x : pow2_y; g_extern.filter.scale = maxsize / SSNES_SCALE_BASE; diff --git a/driver.h b/driver.h index 9e42db6293..231a5495aa 100644 --- a/driver.h +++ b/driver.h @@ -23,7 +23,8 @@ #include "boolean.h" #include #include -#include +//#include +#include "msvc/msvc_compat.h" #include "input/keysym.h" #define AUDIO_CHUNK_SIZE_BLOCKING 64 diff --git a/file.c b/file.c index 7dae7ab349..e166695196 100644 --- a/file.c +++ b/file.c @@ -38,6 +38,9 @@ #include #include #include +#ifdef _MSC_VER +#define setmode _setmode +#endif #else #include #include diff --git a/general.h b/general.h index 55ed5571e5..9da36e0b6c 100644 --- a/general.h +++ b/general.h @@ -55,6 +55,7 @@ #elif defined(_WIN32) #define WIN32_LEAN_AND_MEAN #include +#include "msvc/msvc_compat.h" #endif #ifndef MAXPATHLEN diff --git a/getopt.c b/getopt.c index 83135f5481..dd73b34948 100644 --- a/getopt.c +++ b/getopt.c @@ -23,6 +23,8 @@ #include "boolean.h" #include #include +#include +#include "msvc/msvc_compat.h" char *optarg; int optind, opterr, optopt; @@ -131,10 +133,14 @@ static int parse_long(const struct option *longopts, char * const *argv) static void shuffle_block(char **begin, char **last, char **end) { ptrdiff_t len = last - begin; - const char *tmp[len]; + const char **tmp = (const char**)calloc(len, sizeof(const char*)); + assert(tmp); + memcpy(tmp, begin, sizeof(tmp)); memmove(begin, last, (end - last) * sizeof(char*)); memcpy(end - len, tmp, sizeof(tmp)); + + free(tmp); } int getopt_long(int argc, char *argv[], diff --git a/gfx/ext.c b/gfx/ext_gfx.c similarity index 99% rename from gfx/ext.c rename to gfx/ext_gfx.c index 9dd62d26ee..e9b7185434 100644 --- a/gfx/ext.c +++ b/gfx/ext_gfx.c @@ -22,8 +22,8 @@ #include "../boolean.h" #include #include -#include "dynamic.h" -#include "general.h" +#include "../dynamic.h" +#include "../general.h" #include "sdlwrap.h" #include "gfx_common.h" diff --git a/gfx/gfx_common.c b/gfx/gfx_common.c index a536e4ab9a..a54cd7f12b 100644 --- a/gfx/gfx_common.c +++ b/gfx/gfx_common.c @@ -17,7 +17,21 @@ #include "gfx_common.h" #include "../general.h" + +#ifndef _MSC_VER #include +#else +#include +#include +static void gettimeofday(struct timeval *val, void *dummy) +{ + (void)dummy; + DWORD msec = timeGetTime(); + uint64_t usec = msec * 1000; + val->tv_sec = usec / 1000000; + val->tv_usec = usec % 1000000; +} +#endif static float tv_to_fps(const struct timeval *tv, const struct timeval *new_tv, int frames) { @@ -73,7 +87,7 @@ bool gfx_window_title(char *buf, size_t size) #ifdef _WIN32 #include -#include "dynamic.h" +#include "../dynamic.h" // We only load this library once, so we let it be unloaded at application shutdown, // since unloading it early seems to cause issues on some systems. diff --git a/gfx/gl.c b/gfx/gl.c index b26c67f274..c1c6954ee4 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -21,7 +21,6 @@ #include #include "../libsnes.hpp" #include -#include #include #include "../general.h" #include @@ -39,7 +38,7 @@ #define NO_SDL_GLEXT #include "SDL.h" #include "SDL_opengl.h" -#include "input/ssnes_sdl_input.h" +#include "../input/ssnes_sdl_input.h" #ifdef HAVE_CG #include "shader_cg.h" @@ -85,6 +84,7 @@ static const GLfloat white_color[] = { 1, 1, 1, 1, }; +#define LOAD_SYM(sym) if (!p##sym) { SDL_SYM_WRAP(p##sym, #sym) } #ifdef HAVE_FBO #ifdef _WIN32 @@ -94,7 +94,6 @@ static PFNGLFRAMEBUFFERTEXTURE2DPROC pglFramebufferTexture2D = NULL; static PFNGLCHECKFRAMEBUFFERSTATUSPROC pglCheckFramebufferStatus = NULL; static PFNGLDELETEFRAMEBUFFERSPROC pglDeleteFramebuffers = NULL; -#define LOAD_SYM(sym) if (!p##sym) { SDL_SYM_WRAP(p##sym, #sym) } static bool load_fbo_proc(void) { LOAD_SYM(glGenFramebuffers); diff --git a/gfx/sdl.c b/gfx/sdl_gfx.c similarity index 99% rename from gfx/sdl.c rename to gfx/sdl_gfx.c index 02094eb758..b134ffe9f9 100644 --- a/gfx/sdl.c +++ b/gfx/sdl_gfx.c @@ -16,12 +16,12 @@ */ #include "SDL.h" -#include "driver.h" +#include "../driver.h" #include #include #include -#include "general.h" -#include "input/ssnes_sdl_input.h" +#include "../general.h" +#include "../input/ssnes_sdl_input.h" #include "gfx_common.h" #ifdef HAVE_CONFIG_H diff --git a/gfx/sdlwrap.c b/gfx/sdlwrap.c index e276e633b8..60a0367d73 100644 --- a/gfx/sdlwrap.c +++ b/gfx/sdlwrap.c @@ -17,7 +17,7 @@ #include "sdlwrap.h" #include "SDL_syswm.h" -#include "general.h" +#include "../general.h" #include #ifdef __APPLE__ diff --git a/input/sdl.c b/input/sdl_input.c similarity index 99% rename from input/sdl.c rename to input/sdl_input.c index 2c41491b1c..4b4123ed52 100644 --- a/input/sdl.c +++ b/input/sdl_input.c @@ -15,11 +15,11 @@ * If not, see . */ -#include "driver.h" +#include "../driver.h" #include "../gfx/sdlwrap.h" #include "../boolean.h" -#include "general.h" +#include "../general.h" #include #include #include "../libsnes.hpp" diff --git a/input/ssnes_dinput.h b/input/ssnes_dinput.h index d93665f532..900359f863 100644 --- a/input/ssnes_dinput.h +++ b/input/ssnes_dinput.h @@ -23,7 +23,7 @@ #include #include "../boolean.h" -#include "general.h" +#include "../general.h" // Piggyback joypad driver for SDL. diff --git a/input/ssnes_sdl_input.h b/input/ssnes_sdl_input.h index f1d59ff152..6f20979e82 100644 --- a/input/ssnes_sdl_input.h +++ b/input/ssnes_sdl_input.h @@ -19,7 +19,7 @@ #define __SSNES_SDL_INPUT_H #include "SDL.h" -#include "general.h" +#include "../general.h" #ifdef HAVE_DINPUT #include "ssnes_dinput.h" diff --git a/msvc/SSNES/SSNES.sln b/msvc/SSNES/SSNES.sln new file mode 100644 index 0000000000..fc5bba66fe --- /dev/null +++ b/msvc/SSNES/SSNES.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C++ Express 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SSNES", "SSNES\SSNES.vcxproj", "{032D1FA7-7AA5-47BB-B51B-68B75ADE729D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {032D1FA7-7AA5-47BB-B51B-68B75ADE729D}.Debug|Win32.ActiveCfg = Debug|Win32 + {032D1FA7-7AA5-47BB-B51B-68B75ADE729D}.Debug|Win32.Build.0 = Debug|Win32 + {032D1FA7-7AA5-47BB-B51B-68B75ADE729D}.Release|Win32.ActiveCfg = Release|Win32 + {032D1FA7-7AA5-47BB-B51B-68B75ADE729D}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/msvc/SSNES/SSNES/SSNES.vcxproj b/msvc/SSNES/SSNES/SSNES.vcxproj new file mode 100644 index 0000000000..afb17319a9 --- /dev/null +++ b/msvc/SSNES/SSNES/SSNES.vcxproj @@ -0,0 +1,171 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {032D1FA7-7AA5-47BB-B51B-68B75ADE729D} + Win32Proj + SSNES + + + + Application + true + MultiByte + + + Application + false + true + MultiByte + + + + + + + + + + + + + true + ssnes + + + false + ssnes + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + false + Precise + CompileAsCpp + /D HAVE_SDL /D PACKAGE_VERSION=\"0.9.3\" /D _CRT_SECURE_NO_WARNINGS /D HAVE_NETPLAY /D HAVE_THREADS /D HAVE_OPENGL /D HAVE_DYLIB /D HAVE_DYNAMIC /D HAVE_CG /D HAVE_XAUDIO /D HAVE_FBO /D HAVE_CONFIGFILE %(AdditionalOptions) + + + Console + true + SDL.lib;opengl32.lib;ws2_32.lib;dxguid.lib;dinput8.lib;cg.lib;cgGL.lib;winmm.lib;shlwapi.lib;dsound.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + /D HAVE_SDL /D PACKAGE_VERSION=\"0.9.3\" /D _CRT_SECURE_NO_WARNINGS /D HAVE_NETPLAY /D HAVE_THREADS /D HAVE_OPENGL /D HAVE_DYLIB /D HAVE_DYNAMIC /D HAVE_CG /D HAVE_XAUDIO /D HAVE_FBO /D HAVE_CONFIGFILE %(AdditionalOptions) + CompileAsCpp + Fast + + + Console + false + true + true + SDL.lib;opengl32.lib;ws2_32.lib;dxguid.lib;dinput8.lib;cg.lib;cgGL.lib;winmm.lib;shlwapi.lib;dsound.lib;%(AdditionalDependencies) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/msvc/msvc_compat.h b/msvc/msvc_compat.h new file mode 100644 index 0000000000..f193f2a47c --- /dev/null +++ b/msvc/msvc_compat.h @@ -0,0 +1,44 @@ +/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. + * Copyright (C) 2010-2011 - Hans-Kristian Arntzen + * + * Some code herein may be based on code found in BSNES. + * + * SSNES is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with SSNES. + * If not, see . + */ + +#ifndef __SSNES_MSVC_COMPAT_H +#define __SSNES_MSVC_COMPAT_H + +#ifdef _MSC_VER +#undef UNICODE +#include +#include +#if defined(_WIN32) +typedef signed long ssize_t; +#elif defined(_WIN64) +typedef signed long long ssize_t; +#endif + +#define snprintf _snprintf +#pragma warning(disable : 4800) +#pragma warning(disable : 4244) +#pragma warning(disable : 4305) +#pragma warning(disable : 4146) + +static inline float roundf(float in) +{ + return in >= 0.0f ? floorf(in + 0.5f) : ceilf(in - 0.5f); +} + +#endif +#endif + diff --git a/netplay.c b/netplay.c index 45b4022c68..2d24fa44fa 100644 --- a/netplay.c +++ b/netplay.c @@ -41,9 +41,8 @@ #include "message.h" #include #include -#include -#include +#include #ifdef _WIN32 // Woohoo, Winsock has headers from the STONE AGE! :D @@ -53,6 +52,7 @@ #else #define CONST_CAST #define NONCONST_CAST +#include #endif #define PREV_PTR(x) ((x) == 0 ? handle->buffer_size - 1 : (x) - 1) diff --git a/rewind.c b/rewind.c index dbc06295ca..2d0a79177a 100644 --- a/rewind.c +++ b/rewind.c @@ -43,13 +43,13 @@ static inline size_t nearest_pow2_size(size_t v) v |= v >> 1; v |= v >> 2; v |= v >> 4; -#if SIZE_MAX >= 0xffffu +#if SIZE_MAX >= UINT16_C(0xffff) v |= v >> 8; #endif -#if SIZE_MAX >= 0xfffffffflu +#if SIZE_MAX >= UINT32_C(0xffffffff) v |= v >> 16; #endif -#if SIZE_MAX >= 0xffffffffffffffffllu +#if SIZE_MAX >= UINT64_C(0xffffffffffffffff) v |= v >> 32; #endif v++; diff --git a/settings.c b/settings.c index 18b6815a98..6d7bdb7623 100644 --- a/settings.c +++ b/settings.c @@ -433,7 +433,7 @@ static void parse_config_file(void) CONFIG_GET_BOOL(rewind_enable, "rewind_enable"); if (config_get_int(conf, "rewind_buffer_size", &tmp_int)) - g_settings.rewind_buffer_size = tmp_int * 1000000LLU; + g_settings.rewind_buffer_size = tmp_int * UINT64_C(1000000); CONFIG_GET_INT(rewind_granularity, "rewind_granularity"); diff --git a/ssnes.c b/ssnes.c index 90fb540801..122ca707d5 100644 --- a/ssnes.c +++ b/ssnes.c @@ -39,6 +39,7 @@ #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include +#include "msvc/msvc_compat.h" #endif #ifdef __APPLE__ diff --git a/ups.c b/ups.c index e00028279d..7e1e2937af 100644 --- a/ups.c +++ b/ups.c @@ -17,6 +17,7 @@ #include "ups.h" #include "movie.h" +#include "msvc/msvc_compat.h" struct ups_data {