Files @ r2505:e634a07afb03
Branch filter:

Location: cpp/openttd-patchpack/source/sdl.c - annotation

bjarni
(svn r3031) forgot 1 file and two lines in rev 3029 (mac midi stuff)
r2186:5ee653b1b5e1
r2186:5ee653b1b5e1
r0:d63b455452f6
r2189:2faee8988cf3
r2189:2faee8988cf3
r2189:2faee8988cf3
r1891:c5c5466afa35
r2171:969c16b625b3
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r443:d725253d3289
r443:d725253d3289
r454:b4b05b479105
r454:b4b05b479105
r443:d725253d3289
r443:d725253d3289
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r2171:969c16b625b3
r0:d63b455452f6
r2183:34cce39e9f47
r0:d63b455452f6
r0:d63b455452f6
r193:6aa65dc5a4b4
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r2171:969c16b625b3
r0:d63b455452f6
r1301:421c809ec9f3
r0:d63b455452f6
r2171:969c16b625b3
r0:d63b455452f6
r2183:34cce39e9f47
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r2171:969c16b625b3
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r444:d4c9cbf8395a
r444:d4c9cbf8395a
r444:d4c9cbf8395a
r444:d4c9cbf8395a
r444:d4c9cbf8395a
r444:d4c9cbf8395a
r444:d4c9cbf8395a
r444:d4c9cbf8395a
r444:d4c9cbf8395a
r444:d4c9cbf8395a
r444:d4c9cbf8395a
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r2171:969c16b625b3
r0:d63b455452f6
r2171:969c16b625b3
r423:c15cfc680b31
r1301:421c809ec9f3
r423:c15cfc680b31
r423:c15cfc680b31
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r423:c15cfc680b31
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r444:d4c9cbf8395a
r444:d4c9cbf8395a
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r2171:969c16b625b3
r0:d63b455452f6
r423:c15cfc680b31
r0:d63b455452f6
r0:d63b455452f6
r0:d63b455452f6
r423:c15cfc680b31
r443:d725253d3289
r444:d4c9cbf8395a
r444:d4c9cbf8395a
r423:c15cfc680b31
r0:d63b455452f6
r0:d63b455452f6
r2189:2faee8988cf3
r2189:2faee8988cf3
/* $Id$ */

#include "stdafx.h"

#ifdef WITH_SDL

#include "openttd.h"
#include "sdl.h"
#include <SDL.h>

#ifdef UNIX
#include <signal.h>

#ifdef __MORPHOS__
	// The system supplied definition of SIG_DFL is wrong on MorphOS
	#undef SIG_DFL
	#define SIG_DFL (void (*)(int))0
#endif
#endif

static int _sdl_usage;

#ifdef DYNAMICALLY_LOADED_SDL

#include "win32.h"

#define M(x) x "\0"
static const char sdl_files[] =
	M("sdl.dll")
	M("SDL_Init")
	M("SDL_InitSubSystem")
	M("SDL_GetError")
	M("SDL_QuitSubSystem")
	M("SDL_UpdateRect")
	M("SDL_UpdateRects")
	M("SDL_SetColors")
	M("SDL_WM_SetCaption")
	M("SDL_ShowCursor")
	M("SDL_FreeSurface")
	M("SDL_PollEvent")
	M("SDL_WarpMouse")
	M("SDL_GetTicks")
	M("SDL_OpenAudio")
	M("SDL_PauseAudio")
	M("SDL_CloseAudio")
	M("SDL_LockSurface")
	M("SDL_UnlockSurface")
	M("SDL_GetModState")
	M("SDL_Delay")
	M("SDL_Quit")
	M("SDL_SetVideoMode")
	M("SDL_EnableKeyRepeat")
	M("SDL_EnableUNICODE")
	M("SDL_VideoDriverName")
	M("SDL_ListModes")
	M("SDL_GetKeyState")
	M("")
;
#undef M

SDLProcs sdl_proc;

static const char *LoadSdlDLL(void)
{
	if (sdl_proc.SDL_Init != NULL)
		return NULL;
	if (!LoadLibraryList((Function*)&sdl_proc, sdl_files))
		return "Unable to load sdl.dll";
	return NULL;
}

#endif // DYNAMICALLY_LOADED_SDL


#ifdef UNIX
static void SdlAbort(int sig)
{
	/* Own hand-made parachute for the cases of failed assertions. */
	SDL_CALL SDL_Quit();

	switch (sig) {
		case SIGSEGV:
		case SIGFPE:
			signal(sig, SIG_DFL);
			raise(sig);
			break;

		default:
			break;
	}
}
#endif


const char* SdlOpen(uint32 x)
{
#ifdef DYNAMICALLY_LOADED_SDL
	{
		const char *s = LoadSdlDLL();
		if (s != NULL) return s;
	}
#endif
	if (_sdl_usage++ == 0) {
		if (SDL_CALL SDL_Init(x) == -1)
			return SDL_CALL SDL_GetError();
	} else if (x != 0) {
		if (SDL_CALL SDL_InitSubSystem(x) == -1)
			return SDL_CALL SDL_GetError();
	}

#ifdef UNIX
	signal(SIGABRT, SdlAbort);
	signal(SIGSEGV, SdlAbort);
	signal(SIGFPE, SdlAbort);
#endif

	return NULL;
}

void SdlClose(uint32 x)
{
	if (x != 0)
		SDL_CALL SDL_QuitSubSystem(x);
	if (--_sdl_usage == 0) {
		SDL_CALL SDL_Quit();
		#ifdef UNIX
		signal(SIGABRT, SIG_DFL);
		signal(SIGSEGV, SIG_DFL);
		signal(SIGFPE, SIG_DFL);
		#endif
	}
}

#endif