src/SDL_loadso.c
author Ryan C. Gordon <icculus@icculus.org>
Tue, 27 Sep 2005 12:14:17 +0000
changeset 1147 b580f7201543
parent 1135 cf6133247d34
child 1152 51a8702d8ecd
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 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    29 /* System dependent library loading routines                           */
    30 
    31 #include <stdio.h>
    32 #if defined(USE_DLOPEN)
    33 # include <dlfcn.h>
    34 #elif defined(WIN32)
    35 # include <windows.h>
    36 #elif defined(__BEOS__)
    37 # include <be/kernel/image.h>
    38 #elif defined(macintosh)
    39 # include <string.h>
    40 #define OLDP2C 1
    41 # include <Strings.h>
    42 # include <CodeFragments.h>
    43 # include <Errors.h>
    44 #elif defined(__MINT__) && defined(ENABLE_LDG)
    45 # include <gem.h>
    46 # include <ldg.h>
    47 #else
    48 /*#error Unsupported dynamic link environment*/
    49 #endif /* system type */
    50 
    51 #include "SDL_types.h"
    52 #include "SDL_error.h"
    53 #include "SDL_loadso.h"
    54 
    55 void *SDL_LoadObject(const char *sofile)
    56 {
    57 	void *handle = NULL;
    58 	const char *loaderror = "SDL_LoadObject() not implemented";
    59 #if defined(USE_DLOPEN)
    60 /* * */
    61 	handle = dlopen(sofile, RTLD_NOW);
    62 	loaderror = (char *)dlerror();
    63 #elif defined(WIN32)
    64 /* * */
    65 	char errbuf[512];
    66 
    67 	handle = (void *)LoadLibrary(sofile);
    68 
    69 	/* Generate an error message if all loads failed */
    70 	if ( handle == NULL ) {
    71 		FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
    72 					FORMAT_MESSAGE_FROM_SYSTEM),
    73 				NULL, GetLastError(), 
    74 				MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    75 				errbuf, SDL_TABLESIZE(errbuf), NULL);
    76 		loaderror = errbuf;
    77 	}
    78 #elif defined(__BEOS__)
    79 /* * */
    80 	image_id library_id;
    81 
    82 	library_id = load_add_on(sofile);
    83 	if ( library_id == B_ERROR ) {
    84 		loaderror = "BeOS error";
    85 	} else {
    86 		handle = (void *)(library_id);
    87 	}
    88 #elif defined(macintosh)
    89 /* * */
    90 	CFragConnectionID library_id;
    91 	Ptr mainAddr;
    92 	Str255 errName;
    93 	OSErr error;
    94 	char psofile[512];
    95 
    96 	strncpy(psofile, sofile, SDL_TABLESIZE(psofile));
    97 	psofile[SDL_TABLESIZE(psofile)-1] = '\0';
    98 	error = GetSharedLibrary(C2PStr(psofile), kCompiledCFragArch,
    99 			kLoadCFrag, &library_id, &mainAddr, errName);
   100 	switch (error) {
   101 		case noErr:
   102 			loaderror = NULL;
   103 			break;
   104 		case cfragNoLibraryErr:
   105 			loaderror = "Library not found";
   106 			break;
   107 		case cfragUnresolvedErr:
   108 			loaderror = "Unabled to resolve symbols";
   109 			break;
   110 		case cfragNoPrivateMemErr:
   111 		case cfragNoClientMemErr:
   112 			loaderror = "Out of memory";
   113 			break;
   114 		default:
   115 			loaderror = "Unknown Code Fragment Manager error";
   116 			break;
   117 	}
   118 	if ( loaderror == NULL ) {
   119 		handle = (void *)(library_id);
   120 	}
   121 #elif defined(__MINT__) && defined(ENABLE_LDG)
   122 /* * */
   123 	handle = (void *)ldg_open((char *)sofile, ldg_global);
   124 #endif /* system type */
   125 
   126 	if ( handle == NULL ) {
   127 		SDL_SetError("Failed loading %s: %s", sofile, loaderror);
   128 	}
   129 	return(handle);
   130 }
   131 
   132 void *SDL_LoadFunction(void *handle, const char *name)
   133 {
   134 	void *symbol = NULL;
   135 	const char *loaderror = "SDL_LoadFunction not implemented";
   136 #if defined(USE_DLOPEN)
   137 /* * */
   138 	symbol = dlsym(handle, name);
   139 	if ( symbol == NULL ) {
   140 		loaderror = (char *)dlerror();
   141 	}
   142 #elif defined(WIN32)
   143 /* * */
   144 	char errbuf[512];
   145 
   146 	symbol = (void *)GetProcAddress((HMODULE)handle, name);
   147 	if ( symbol == NULL ) {
   148 		FormatMessage((FORMAT_MESSAGE_IGNORE_INSERTS |
   149 					FORMAT_MESSAGE_FROM_SYSTEM),
   150 				NULL, GetLastError(), 
   151 				MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
   152 				errbuf, SDL_TABLESIZE(errbuf), NULL);
   153 		loaderror = errbuf;
   154 	}
   155 #elif defined(__BEOS__)
   156 /* * */
   157 	image_id library_id = (image_id)handle;
   158 	if ( get_image_symbol(library_id,
   159 		name, B_SYMBOL_TYPE_TEXT, &symbol) != B_NO_ERROR ) {
   160 		loaderror = "Symbol not found";
   161 	}
   162 #elif defined(macintosh)
   163 /* * */
   164 	CFragSymbolClass class;
   165 	CFragConnectionID library_id = (CFragConnectionID)handle;
   166 	char pname[512];
   167 
   168 	strncpy(pname, name, SDL_TABLESIZE(pname));
   169 	pname[SDL_TABLESIZE(pname)-1] = '\0';
   170 	if ( FindSymbol(library_id, C2PStr(pname),
   171 	                (char **)&symbol, &class) != noErr ) {
   172 		loaderror = "Symbol not found";
   173 	}
   174 #elif defined(__MINT__) && defined(ENABLE_LDG)
   175 /* * */
   176 	symbol = (void *)ldg_find((char *)name, (LDG *)handle);
   177 #endif /* system type */
   178 
   179 	if ( symbol == NULL ) {
   180 		SDL_SetError("Failed loading %s: %s", name, loaderror);
   181 	}
   182 	return(symbol);
   183 }
   184 
   185 void SDL_UnloadObject(void *handle)
   186 {
   187 #if defined(__BEOS__)
   188 	image_id library_id;
   189 #elif defined(macintosh)
   190 	CFragConnectionID library_id;
   191 #endif
   192 	if ( handle == NULL ) {
   193 		return;
   194 	}
   195 #if defined(USE_DLOPEN)
   196 /* * */
   197 	dlclose(handle);
   198 #elif defined(WIN32)
   199 /* * */
   200 	FreeLibrary((HMODULE)handle);
   201 #elif defined(__BEOS__)
   202 /* * */
   203 	library_id = (image_id)handle;
   204 	unload_add_on(library_id);
   205 #elif defined(macintosh)
   206 /* * */
   207 	library_id = (CFragConnectionID)handle;
   208 	CloseConnection(&library_id);
   209 #elif defined(__MINT__) && defined(ENABLE_LDG)
   210 /* * */
   211 	ldg_close((LDG *)handle, ldg_global);
   212 #endif /* system type */
   213 }