dynamic_mod.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 31 Dec 2011 10:27:48 -0500
changeset 518 8bc9b5fd2aae
parent 472 463ba3222193
child 587 56cad6484b04
child 865 3ffb22a2755b
permissions -rw-r--r--
Happy New Year!
     1 /*
     2   SDL_mixer:  An audio mixer library based on the SDL library
     3   Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 
    22 #ifdef MOD_MUSIC
    23 
    24 #include "SDL_loadso.h"
    25 
    26 #include "dynamic_mod.h"
    27 
    28 mikmod_loader mikmod = {
    29 	0, NULL
    30 };
    31 
    32 #ifdef MOD_DYNAMIC
    33 int Mix_InitMOD()
    34 {
    35 	if ( mikmod.loaded == 0 ) {
    36 		mikmod.handle = SDL_LoadObject(MOD_DYNAMIC);
    37 		if ( mikmod.handle == NULL ) {
    38 			return -1;
    39 		}
    40 		mikmod.MikMod_Exit =
    41 			(void (*)(void))
    42 			SDL_LoadFunction(mikmod.handle, "MikMod_Exit");
    43 		if ( mikmod.MikMod_Exit == NULL ) {
    44 			SDL_UnloadObject(mikmod.handle);
    45 			return -1;
    46 		}
    47 		mikmod.MikMod_InfoDriver =
    48 			(CHAR* (*)(void))
    49 			SDL_LoadFunction(mikmod.handle, "MikMod_InfoDriver");
    50 		if ( mikmod.MikMod_InfoDriver == NULL ) {
    51 			SDL_UnloadObject(mikmod.handle);
    52 			return -1;
    53 		}
    54 		mikmod.MikMod_InfoLoader =
    55 			(CHAR* (*)(void))
    56 			SDL_LoadFunction(mikmod.handle, "MikMod_InfoLoader");
    57 		if ( mikmod.MikMod_InfoLoader == NULL ) {
    58 			SDL_UnloadObject(mikmod.handle);
    59 			return -1;
    60 		}
    61 		mikmod.MikMod_Init =
    62 			(BOOL (*)(CHAR*))
    63 			SDL_LoadFunction(mikmod.handle, "MikMod_Init");
    64 		if ( mikmod.MikMod_Init == NULL ) {
    65 			SDL_UnloadObject(mikmod.handle);
    66 			return -1;
    67 		}
    68 		mikmod.MikMod_RegisterAllLoaders =
    69 			(void (*)(void))
    70 			SDL_LoadFunction(mikmod.handle, "MikMod_RegisterAllLoaders");
    71 		if ( mikmod.MikMod_RegisterAllLoaders == NULL ) {
    72 			SDL_UnloadObject(mikmod.handle);
    73 			return -1;
    74 		}
    75 		mikmod.MikMod_RegisterDriver =
    76 			(void (*)(struct MDRIVER*))
    77 			SDL_LoadFunction(mikmod.handle, "MikMod_RegisterDriver");
    78 		if ( mikmod.MikMod_RegisterDriver == NULL ) {
    79 			SDL_UnloadObject(mikmod.handle);
    80 			return -1;
    81 		}
    82 		mikmod.MikMod_errno =
    83 			(int*)
    84 			SDL_LoadFunction(mikmod.handle, "MikMod_errno");
    85 		if ( mikmod.MikMod_errno == NULL ) {
    86 			SDL_UnloadObject(mikmod.handle);
    87 			return -1;
    88 		}
    89 		mikmod.MikMod_strerror =
    90 			(char* (*)(int))
    91 			SDL_LoadFunction(mikmod.handle, "MikMod_strerror");
    92 		if ( mikmod.MikMod_strerror == NULL ) {
    93 			SDL_UnloadObject(mikmod.handle);
    94 			return -1;
    95 		}
    96 		mikmod.Player_Active =
    97 			(BOOL (*)(void))
    98 			SDL_LoadFunction(mikmod.handle, "Player_Active");
    99 		if ( mikmod.Player_Active == NULL ) {
   100 			SDL_UnloadObject(mikmod.handle);
   101 			return -1;
   102 		}
   103 		mikmod.Player_Free =
   104 			(void (*)(MODULE*))
   105 			SDL_LoadFunction(mikmod.handle, "Player_Free");
   106 		if ( mikmod.Player_Free == NULL ) {
   107 			SDL_UnloadObject(mikmod.handle);
   108 			return -1;
   109 		}
   110 		mikmod.Player_LoadGeneric =
   111 			(MODULE* (*)(MREADER*,int,BOOL))
   112 			SDL_LoadFunction(mikmod.handle, "Player_LoadGeneric");
   113 		if ( mikmod.Player_LoadGeneric == NULL ) {
   114 			SDL_UnloadObject(mikmod.handle);
   115 			return -1;
   116 		}
   117 		mikmod.Player_SetPosition =
   118 			(void (*)(UWORD))
   119 			SDL_LoadFunction(mikmod.handle, "Player_SetPosition");
   120 		if ( mikmod.Player_SetPosition == NULL ) {
   121 			SDL_UnloadObject(mikmod.handle);
   122 			return -1;
   123 		}
   124 		mikmod.Player_SetVolume =
   125 			(void (*)(SWORD))
   126 			SDL_LoadFunction(mikmod.handle, "Player_SetVolume");
   127 		if ( mikmod.Player_SetVolume == NULL ) {
   128 			SDL_UnloadObject(mikmod.handle);
   129 			return -1;
   130 		}
   131 		mikmod.Player_Start =
   132 			(void (*)(MODULE*))
   133 			SDL_LoadFunction(mikmod.handle, "Player_Start");
   134 		if ( mikmod.Player_Start == NULL ) {
   135 			SDL_UnloadObject(mikmod.handle);
   136 			return -1;
   137 		}
   138 		mikmod.Player_Stop =
   139 			(void (*)(void))
   140 			SDL_LoadFunction(mikmod.handle, "Player_Stop");
   141 		if ( mikmod.Player_Stop == NULL ) {
   142 			SDL_UnloadObject(mikmod.handle);
   143 			return -1;
   144 		}
   145 		mikmod.VC_WriteBytes =
   146 			(ULONG (*)(SBYTE*,ULONG))
   147 			SDL_LoadFunction(mikmod.handle, "VC_WriteBytes");
   148 		if ( mikmod.VC_WriteBytes == NULL ) {
   149 			SDL_UnloadObject(mikmod.handle);
   150 			return -1;
   151 		}
   152 		mikmod.drv_nos =
   153 			(MDRIVER*)
   154 			SDL_LoadFunction(mikmod.handle, "drv_nos");
   155 		if ( mikmod.drv_nos == NULL ) {
   156 			SDL_UnloadObject(mikmod.handle);
   157 			return -1;
   158 		}
   159 		mikmod.md_device =
   160 			(UWORD*)
   161 			SDL_LoadFunction(mikmod.handle, "md_device");
   162 		if ( mikmod.md_device == NULL ) {
   163 			SDL_UnloadObject(mikmod.handle);
   164 			return -1;
   165 		}
   166 		mikmod.md_mixfreq =
   167 			(UWORD*)
   168 			SDL_LoadFunction(mikmod.handle, "md_mixfreq");
   169 		if ( mikmod.md_mixfreq == NULL ) {
   170 			SDL_UnloadObject(mikmod.handle);
   171 			return -1;
   172 		}
   173 		mikmod.md_mode =
   174 			(UWORD*)
   175 			SDL_LoadFunction(mikmod.handle, "md_mode");
   176 		if ( mikmod.md_mode == NULL ) {
   177 			SDL_UnloadObject(mikmod.handle);
   178 			return -1;
   179 		}
   180 		mikmod.md_musicvolume =
   181 			(UBYTE*)
   182 			SDL_LoadFunction(mikmod.handle, "md_musicvolume");
   183 		if ( mikmod.md_musicvolume == NULL ) {
   184 			SDL_UnloadObject(mikmod.handle);
   185 			return -1;
   186 		}
   187 		mikmod.md_pansep =
   188 			(UBYTE*)
   189 			SDL_LoadFunction(mikmod.handle, "md_pansep");
   190 		if ( mikmod.md_pansep == NULL ) {
   191 			SDL_UnloadObject(mikmod.handle);
   192 			return -1;
   193 		}
   194 		mikmod.md_reverb =
   195 			(UBYTE*)
   196 			SDL_LoadFunction(mikmod.handle, "md_reverb");
   197 		if ( mikmod.md_reverb == NULL ) {
   198 			SDL_UnloadObject(mikmod.handle);
   199 			return -1;
   200 		}
   201 		mikmod.md_sndfxvolume =
   202 			(UBYTE*)
   203 			SDL_LoadFunction(mikmod.handle, "md_sndfxvolume");
   204 		if ( mikmod.md_sndfxvolume == NULL ) {
   205 			SDL_UnloadObject(mikmod.handle);
   206 			return -1;
   207 		}
   208 		mikmod.md_volume =
   209 			(UBYTE*)
   210 			SDL_LoadFunction(mikmod.handle, "md_volume");
   211 		if ( mikmod.md_volume == NULL ) {
   212 			SDL_UnloadObject(mikmod.handle);
   213 			return -1;
   214 		}
   215 	}
   216 	++mikmod.loaded;
   217 
   218 	return 0;
   219 }
   220 void Mix_QuitMOD()
   221 {
   222 	if ( mikmod.loaded == 0 ) {
   223 		return;
   224 	}
   225 	if ( mikmod.loaded == 1 ) {
   226 		SDL_UnloadObject(mikmod.handle);
   227 	}
   228 	--mikmod.loaded;
   229 }
   230 #else
   231 int Mix_InitMOD()
   232 {
   233 	if ( mikmod.loaded == 0 ) {
   234 		mikmod.MikMod_Exit = MikMod_Exit;
   235 		mikmod.MikMod_InfoDriver = MikMod_InfoDriver;
   236 		mikmod.MikMod_InfoLoader = MikMod_InfoLoader;
   237 		mikmod.MikMod_Init = MikMod_Init;
   238 		mikmod.MikMod_RegisterAllLoaders = MikMod_RegisterAllLoaders;
   239 		mikmod.MikMod_RegisterDriver = MikMod_RegisterDriver;
   240 		mikmod.MikMod_errno = &MikMod_errno;
   241 		mikmod.MikMod_strerror = MikMod_strerror;
   242 		mikmod.Player_Active = Player_Active;
   243 		mikmod.Player_Free = Player_Free;
   244 		mikmod.Player_LoadGeneric = Player_LoadGeneric;
   245 		mikmod.Player_SetPosition = Player_SetPosition;
   246 		mikmod.Player_SetVolume = Player_SetVolume;
   247 		mikmod.Player_Start = Player_Start;
   248 		mikmod.Player_Stop = Player_Stop;
   249 		mikmod.VC_WriteBytes = VC_WriteBytes;
   250 		mikmod.drv_nos = &drv_nos;
   251 		mikmod.md_device = &md_device;
   252 		mikmod.md_mixfreq = &md_mixfreq;
   253 		mikmod.md_mode = &md_mode;
   254 		mikmod.md_musicvolume = &md_musicvolume;
   255 		mikmod.md_pansep = &md_pansep;
   256 		mikmod.md_reverb = &md_reverb;
   257 		mikmod.md_sndfxvolume = &md_sndfxvolume;
   258 		mikmod.md_volume = &md_volume;
   259 	}
   260 	++mikmod.loaded;
   261 
   262 	return 0;
   263 }
   264 void Mix_QuitMOD()
   265 {
   266 	if ( mikmod.loaded == 0 ) {
   267 		return;
   268 	}
   269 	if ( mikmod.loaded == 1 ) {
   270 	}
   271 	--mikmod.loaded;
   272 }
   273 #endif /* MOD_DYNAMIC */
   274 
   275 #endif /* MOD_MUSIC */