src/SDL.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 21 Sep 2003 18:32:04 +0000
changeset 720 f90d80d68071
parent 557 0ce5a68278fd
child 769 b8d311d90021
permissions -rw-r--r--
N Sep 17 8791 Sam Lantinga Re: tks source released
Date: Sun, 07 Sep 2003 02:51:58 +0200
From: Stephane Marchesin
Subject: [SDL] Two little patches

Compiling SDL with a recent gcc (gcc 3.3.1, 3.3 doesn't have this
behaviour) gives some nasty warnings :

SDL_blit_A.c: In function `BlitRGBtoRGBSurfaceAlpha128MMX':
SDL_blit_A.c:223: warning: integer constant is too large for "long" type
SDL_blit_A.c:225: warning: integer constant is too large for "long" type
SDL_blit_A.c:227: warning: integer constant is too large for "long" type
[...]

The first attached patch (longlongfix.patch) tells gcc to really treat
those constants as unsigned long long and not long.

The second patch (nasinclude.patch) fixes an include problem I had while
compiling nas audio : when the <audio/audiolib.h> file lies in
/usr/X11R6/include, a -I/usr/X11R6/include option is needed or the file
isn't found.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@297
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@0
     6
    modify it under the terms of the GNU Library General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@0
     8
    version 2 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@0
    13
    Library General Public License for more details.
slouken@0
    14
slouken@0
    15
    You should have received a copy of the GNU Library General Public
slouken@0
    16
    License along with this library; if not, write to the Free
slouken@0
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@0
    22
slouken@0
    23
#ifdef SAVE_RCSID
slouken@0
    24
static char rcsid =
slouken@0
    25
 "@(#) $Id$";
slouken@0
    26
#endif
slouken@0
    27
slouken@0
    28
/* Initialization code for SDL */
slouken@0
    29
slouken@0
    30
#include <stdlib.h>		/* For getenv() */
slouken@557
    31
#ifdef ENABLE_PTH
slouken@557
    32
#include <pth.h>
slouken@557
    33
#endif
slouken@0
    34
slouken@0
    35
#include "SDL.h"
slouken@0
    36
#include "SDL_endian.h"
slouken@0
    37
#include "SDL_fatal.h"
slouken@0
    38
#ifndef DISABLE_VIDEO
slouken@0
    39
#include "SDL_leaks.h"
slouken@0
    40
#endif
slouken@0
    41
slouken@0
    42
/* Initialization/Cleanup routines */
slouken@0
    43
#ifndef DISABLE_JOYSTICK
slouken@0
    44
extern int  SDL_JoystickInit(void);
slouken@0
    45
extern void SDL_JoystickQuit(void);
slouken@0
    46
#endif
slouken@0
    47
#ifndef DISABLE_CDROM
slouken@0
    48
extern int  SDL_CDROMInit(void);
slouken@0
    49
extern void SDL_CDROMQuit(void);
slouken@0
    50
#endif
slouken@0
    51
#ifndef DISABLE_TIMERS
slouken@0
    52
extern void SDL_StartTicks(void);
slouken@0
    53
extern int  SDL_TimerInit(void);
slouken@0
    54
extern void SDL_TimerQuit(void);
slouken@0
    55
#endif
slouken@0
    56
slouken@0
    57
/* The current SDL version */
slouken@0
    58
static SDL_version version = 
slouken@0
    59
	{ SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL };
slouken@0
    60
slouken@0
    61
/* The initialized subsystems */
slouken@0
    62
static Uint32 SDL_initialized = 0;
slouken@0
    63
static Uint32 ticks_started = 0;
slouken@0
    64
slouken@0
    65
#ifdef CHECK_LEAKS
slouken@0
    66
int surfaces_allocated = 0;
slouken@0
    67
#endif
slouken@0
    68
slouken@0
    69
int SDL_InitSubSystem(Uint32 flags)
slouken@0
    70
{
slouken@0
    71
#ifndef DISABLE_VIDEO
slouken@0
    72
	/* Initialize the video/event subsystem */
slouken@0
    73
	if ( (flags & SDL_INIT_VIDEO) && !(SDL_initialized & SDL_INIT_VIDEO) ) {
slouken@0
    74
		if ( SDL_VideoInit(getenv("SDL_VIDEODRIVER"),
slouken@0
    75
		                   (flags&SDL_INIT_EVENTTHREAD)) < 0 ) {
slouken@0
    76
			return(-1);
slouken@0
    77
		}
slouken@0
    78
		SDL_initialized |= SDL_INIT_VIDEO;
slouken@0
    79
	}
slouken@0
    80
#else
slouken@0
    81
	if ( flags & SDL_INIT_VIDEO ) {
slouken@0
    82
		SDL_SetError("SDL not built with video support");
slouken@0
    83
		return(-1);
slouken@0
    84
	}
slouken@0
    85
#endif
slouken@0
    86
slouken@0
    87
#ifndef DISABLE_AUDIO
slouken@0
    88
	/* Initialize the audio subsystem */
slouken@0
    89
	if ( (flags & SDL_INIT_AUDIO) && !(SDL_initialized & SDL_INIT_AUDIO) ) {
slouken@0
    90
		if ( SDL_AudioInit(getenv("SDL_AUDIODRIVER")) < 0 ) {
slouken@0
    91
			return(-1);
slouken@0
    92
		}
slouken@0
    93
		SDL_initialized |= SDL_INIT_AUDIO;
slouken@0
    94
	}
slouken@0
    95
#else
slouken@0
    96
	if ( flags & SDL_INIT_AUDIO ) {
slouken@0
    97
		SDL_SetError("SDL not built with audio support");
slouken@0
    98
		return(-1);
slouken@0
    99
	}
slouken@0
   100
#endif
slouken@0
   101
slouken@0
   102
#ifndef DISABLE_TIMERS
slouken@0
   103
	/* Initialize the timer subsystem */
slouken@0
   104
	if ( ! ticks_started ) {
slouken@0
   105
		SDL_StartTicks();
slouken@0
   106
		ticks_started = 1;
slouken@0
   107
	}
slouken@0
   108
	if ( (flags & SDL_INIT_TIMER) && !(SDL_initialized & SDL_INIT_TIMER) ) {
slouken@0
   109
		if ( SDL_TimerInit() < 0 ) {
slouken@0
   110
			return(-1);
slouken@0
   111
		}
slouken@0
   112
		SDL_initialized |= SDL_INIT_TIMER;
slouken@0
   113
	}
slouken@0
   114
#else
slouken@0
   115
	if ( flags & SDL_INIT_TIMER ) {
slouken@0
   116
		SDL_SetError("SDL not built with timer support");
slouken@0
   117
		return(-1);
slouken@0
   118
	}
slouken@0
   119
#endif
slouken@0
   120
slouken@0
   121
#ifndef DISABLE_JOYSTICK
slouken@0
   122
	/* Initialize the joystick subsystem */
slouken@0
   123
	if ( (flags & SDL_INIT_JOYSTICK) &&
slouken@0
   124
	     !(SDL_initialized & SDL_INIT_JOYSTICK) ) {
slouken@0
   125
		if ( SDL_JoystickInit() < 0 ) {
slouken@0
   126
			return(-1);
slouken@0
   127
		}
slouken@0
   128
		SDL_initialized |= SDL_INIT_JOYSTICK;
slouken@0
   129
	}
slouken@0
   130
#else
slouken@0
   131
	if ( flags & SDL_INIT_JOYSTICK ) {
slouken@0
   132
		SDL_SetError("SDL not built with joystick support");
slouken@0
   133
		return(-1);
slouken@0
   134
	}
slouken@0
   135
#endif
slouken@0
   136
slouken@0
   137
#ifndef DISABLE_CDROM
slouken@0
   138
	/* Initialize the CD-ROM subsystem */
slouken@0
   139
	if ( (flags & SDL_INIT_CDROM) && !(SDL_initialized & SDL_INIT_CDROM) ) {
slouken@0
   140
		if ( SDL_CDROMInit() < 0 ) {
slouken@0
   141
			return(-1);
slouken@0
   142
		}
slouken@0
   143
		SDL_initialized |= SDL_INIT_CDROM;
slouken@0
   144
	}
slouken@0
   145
#else
slouken@0
   146
	if ( flags & SDL_INIT_CDROM ) {
slouken@0
   147
		SDL_SetError("SDL not built with cdrom support");
slouken@0
   148
		return(-1);
slouken@0
   149
	}
slouken@0
   150
#endif
slouken@0
   151
	return(0);
slouken@0
   152
}
slouken@0
   153
slouken@0
   154
int SDL_Init(Uint32 flags)
slouken@0
   155
{
slouken@397
   156
#if !defined(DISABLE_THREADS) && defined(ENABLE_PTH)
slouken@397
   157
	if (!pth_init()) {
slouken@397
   158
		return -1;
slouken@397
   159
	}
slouken@397
   160
#endif
slouken@397
   161
slouken@0
   162
	/* Clear the error message */
slouken@0
   163
	SDL_ClearError();
slouken@0
   164
slouken@0
   165
	/* Initialize the desired subsystems */
slouken@0
   166
	if ( SDL_InitSubSystem(flags) < 0 ) {
slouken@0
   167
		return(-1);
slouken@0
   168
	}
slouken@0
   169
slouken@0
   170
	/* Everything is initialized */
slouken@0
   171
	if ( !(flags & SDL_INIT_NOPARACHUTE) ) {
slouken@0
   172
		SDL_InstallParachute();
slouken@0
   173
	}
slouken@0
   174
	return(0);
slouken@0
   175
}
slouken@0
   176
slouken@0
   177
void SDL_QuitSubSystem(Uint32 flags)
slouken@0
   178
{
slouken@0
   179
	/* Shut down requested initialized subsystems */
slouken@0
   180
#ifndef DISABLE_CDROM
slouken@0
   181
	if ( (flags & SDL_initialized & SDL_INIT_CDROM) ) {
slouken@0
   182
		SDL_CDROMQuit();
slouken@0
   183
		SDL_initialized &= ~SDL_INIT_CDROM;
slouken@0
   184
	}
slouken@0
   185
#endif
slouken@0
   186
#ifndef DISABLE_JOYSTICK
slouken@0
   187
	if ( (flags & SDL_initialized & SDL_INIT_JOYSTICK) ) {
slouken@0
   188
		SDL_JoystickQuit();
slouken@0
   189
		SDL_initialized &= ~SDL_INIT_JOYSTICK;
slouken@0
   190
	}
slouken@0
   191
#endif
slouken@0
   192
#ifndef DISABLE_TIMERS
slouken@0
   193
	if ( (flags & SDL_initialized & SDL_INIT_TIMER) ) {
slouken@0
   194
		SDL_TimerQuit();
slouken@0
   195
		SDL_initialized &= ~SDL_INIT_TIMER;
slouken@0
   196
	}
slouken@0
   197
#endif
slouken@0
   198
#ifndef DISABLE_AUDIO
slouken@0
   199
	if ( (flags & SDL_initialized & SDL_INIT_AUDIO) ) {
slouken@0
   200
		SDL_AudioQuit();
slouken@0
   201
		SDL_initialized &= ~SDL_INIT_AUDIO;
slouken@0
   202
	}
slouken@0
   203
#endif
slouken@0
   204
#ifndef DISABLE_VIDEO
slouken@0
   205
	if ( (flags & SDL_initialized & SDL_INIT_VIDEO) ) {
slouken@0
   206
		SDL_VideoQuit();
slouken@0
   207
		SDL_initialized &= ~SDL_INIT_VIDEO;
slouken@0
   208
	}
slouken@0
   209
#endif
slouken@0
   210
}
slouken@0
   211
slouken@0
   212
Uint32 SDL_WasInit(Uint32 flags)
slouken@0
   213
{
slouken@0
   214
	if ( ! flags ) {
slouken@0
   215
		flags = SDL_INIT_EVERYTHING;
slouken@0
   216
	}
slouken@0
   217
	return (SDL_initialized&flags);
slouken@0
   218
}
slouken@0
   219
slouken@0
   220
void SDL_Quit(void)
slouken@0
   221
{
slouken@0
   222
	/* Quit all subsystems */
slouken@0
   223
	SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
slouken@0
   224
slouken@0
   225
#ifdef CHECK_LEAKS
slouken@0
   226
	/* Print the number of surfaces not freed */
slouken@0
   227
	if ( surfaces_allocated != 0 ) {
slouken@0
   228
		fprintf(stderr, "SDL Warning: %d SDL surfaces extant\n", 
slouken@0
   229
							surfaces_allocated);
slouken@0
   230
	}
slouken@0
   231
#endif
slouken@0
   232
slouken@0
   233
	/* Uninstall any parachute signal handlers */
slouken@0
   234
	SDL_UninstallParachute();
slouken@397
   235
slouken@397
   236
#if !defined(DISABLE_THREADS) && defined(ENABLE_PTH)
slouken@397
   237
	pth_kill();
slouken@397
   238
#endif
slouken@0
   239
}
slouken@0
   240
slouken@0
   241
/* Return the library version number */
slouken@0
   242
const SDL_version * SDL_Linked_Version(void)
slouken@0
   243
{
slouken@0
   244
	return(&version);
slouken@0
   245
}
slouken@0
   246
slouken@543
   247
#if defined(_WIN32_WCE) || (defined(__WATCOMC__) && defined(BUILD_DLL))
slouken@543
   248
/* Need to include DllMain() on Windows CE and Watcom C for some reason.. */
slouken@36
   249
#include <windows.h>
slouken@36
   250
slouken@36
   251
BOOL APIENTRY DllMain( HANDLE hModule, 
slouken@36
   252
                       DWORD  ul_reason_for_call, 
slouken@36
   253
                       LPVOID lpReserved )
slouken@36
   254
{
slouken@36
   255
	switch (ul_reason_for_call) {
slouken@36
   256
		case DLL_PROCESS_ATTACH:
slouken@36
   257
		case DLL_THREAD_ATTACH:
slouken@36
   258
		case DLL_THREAD_DETACH:
slouken@36
   259
		case DLL_PROCESS_DETACH:
slouken@36
   260
			break;
slouken@36
   261
	}
slouken@36
   262
	return TRUE;
slouken@36
   263
}
slouken@543
   264
#endif /* _WIN32_WCE and building DLL with Watcom C */