src/SDL.c
author Ryan C. Gordon <icculus@icculus.org>
Tue, 27 Sep 2005 12:14:17 +0000
changeset 1147 b580f7201543
parent 769 b8d311d90021
child 1190 173c063d4f55
permissions -rw-r--r--
From: "Alex Volkov" <avcp-sdlmail@usa.net>
To: "'A list for developers using the SDL library. \(includesSDL-announce\)'" <sdl@libsdl.org>
Date: Mon, 19 Sep 2005 18:59:43 -0400
Subject: [SDL] [patch] Volume multiplier bug in

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