dynamic_mod.c
changeset 419 e27fe0bfe470
child 470 5cebd6c5be2d
equal deleted inserted replaced
418:e03597bc19a9 419:e27fe0bfe470
       
     1 /*
       
     2     SDL_mixer:  An audio mixer library based on the SDL library
       
     3     Copyright (C) 1997-2009 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 MOD_MUSIC
       
    24 
       
    25 #include "SDL_loadso.h"
       
    26 
       
    27 #include "dynamic_mod.h"
       
    28 
       
    29 mikmod_loader mikmod = {
       
    30 	0, NULL
       
    31 };
       
    32 
       
    33 #ifdef MOD_DYNAMIC
       
    34 int Mix_InitMOD()
       
    35 {
       
    36 	if ( mikmod.loaded == 0 ) {
       
    37 		mikmod.handle = SDL_LoadObject(MOD_DYNAMIC);
       
    38 		if ( mikmod.handle == NULL ) {
       
    39 			return -1;
       
    40 		}
       
    41 		mikmod.MikMod_Exit =
       
    42 			(void (*)(void))
       
    43 			SDL_LoadFunction(mikmod.handle, "MikMod_Exit");
       
    44 		if ( mikmod.MikMod_Exit == NULL ) {
       
    45 			SDL_UnloadObject(mikmod.handle);
       
    46 			return -1;
       
    47 		}
       
    48 		mikmod.MikMod_InfoDriver =
       
    49 			(CHAR* (*)(void))
       
    50 			SDL_LoadFunction(mikmod.handle, "MikMod_InfoDriver");
       
    51 		if ( mikmod.MikMod_InfoDriver == NULL ) {
       
    52 			SDL_UnloadObject(mikmod.handle);
       
    53 			return -1;
       
    54 		}
       
    55 		mikmod.MikMod_InfoLoader =
       
    56 			(CHAR* (*)(void))
       
    57 			SDL_LoadFunction(mikmod.handle, "MikMod_InfoLoader");
       
    58 		if ( mikmod.MikMod_InfoLoader == NULL ) {
       
    59 			SDL_UnloadObject(mikmod.handle);
       
    60 			return -1;
       
    61 		}
       
    62 		mikmod.MikMod_Init =
       
    63 			(BOOL (*)(CHAR*))
       
    64 			SDL_LoadFunction(mikmod.handle, "MikMod_Init");
       
    65 		if ( mikmod.MikMod_Init == NULL ) {
       
    66 			SDL_UnloadObject(mikmod.handle);
       
    67 			return -1;
       
    68 		}
       
    69 		mikmod.MikMod_RegisterAllLoaders =
       
    70 			(void (*)(void))
       
    71 			SDL_LoadFunction(mikmod.handle, "MikMod_RegisterAllLoaders");
       
    72 		if ( mikmod.MikMod_RegisterAllLoaders == NULL ) {
       
    73 			SDL_UnloadObject(mikmod.handle);
       
    74 			return -1;
       
    75 		}
       
    76 		mikmod.MikMod_RegisterDriver =
       
    77 			(void (*)(struct MDRIVER*))
       
    78 			SDL_LoadFunction(mikmod.handle, "MikMod_RegisterDriver");
       
    79 		if ( mikmod.MikMod_RegisterDriver == NULL ) {
       
    80 			SDL_UnloadObject(mikmod.handle);
       
    81 			return -1;
       
    82 		}
       
    83 		mikmod.MikMod_errno =
       
    84 			(int*)
       
    85 			SDL_LoadFunction(mikmod.handle, "MikMod_errno");
       
    86 		if ( mikmod.MikMod_errno == NULL ) {
       
    87 			SDL_UnloadObject(mikmod.handle);
       
    88 			return -1;
       
    89 		}
       
    90 		mikmod.MikMod_strerror =
       
    91 			(char* (*)(int))
       
    92 			SDL_LoadFunction(mikmod.handle, "MikMod_strerror");
       
    93 		if ( mikmod.MikMod_strerror == NULL ) {
       
    94 			SDL_UnloadObject(mikmod.handle);
       
    95 			return -1;
       
    96 		}
       
    97 		mikmod.Player_Active =
       
    98 			(BOOL (*)(void))
       
    99 			SDL_LoadFunction(mikmod.handle, "Player_Active");
       
   100 		if ( mikmod.Player_Active == NULL ) {
       
   101 			SDL_UnloadObject(mikmod.handle);
       
   102 			return -1;
       
   103 		}
       
   104 		mikmod.Player_Free =
       
   105 			(void (*)(MODULE*))
       
   106 			SDL_LoadFunction(mikmod.handle, "Player_Free");
       
   107 		if ( mikmod.Player_Free == NULL ) {
       
   108 			SDL_UnloadObject(mikmod.handle);
       
   109 			return -1;
       
   110 		}
       
   111 		mikmod.Player_LoadGeneric =
       
   112 			(MODULE* (*)(MREADER*,int,BOOL))
       
   113 			SDL_LoadFunction(mikmod.handle, "Player_LoadGeneric");
       
   114 		if ( mikmod.Player_LoadGeneric == NULL ) {
       
   115 			SDL_UnloadObject(mikmod.handle);
       
   116 			return -1;
       
   117 		}
       
   118 		mikmod.Player_SetPosition =
       
   119 			(void (*)(UWORD))
       
   120 			SDL_LoadFunction(mikmod.handle, "Player_SetPosition");
       
   121 		if ( mikmod.Player_SetPosition == NULL ) {
       
   122 			SDL_UnloadObject(mikmod.handle);
       
   123 			return -1;
       
   124 		}
       
   125 		mikmod.Player_SetVolume =
       
   126 			(void (*)(SWORD))
       
   127 			SDL_LoadFunction(mikmod.handle, "Player_SetVolume");
       
   128 		if ( mikmod.Player_SetVolume == NULL ) {
       
   129 			SDL_UnloadObject(mikmod.handle);
       
   130 			return -1;
       
   131 		}
       
   132 		mikmod.Player_Start =
       
   133 			(void (*)(MODULE*))
       
   134 			SDL_LoadFunction(mikmod.handle, "Player_Start");
       
   135 		if ( mikmod.Player_Start == NULL ) {
       
   136 			SDL_UnloadObject(mikmod.handle);
       
   137 			return -1;
       
   138 		}
       
   139 		mikmod.Player_Stop =
       
   140 			(void (*)(void))
       
   141 			SDL_LoadFunction(mikmod.handle, "Player_Stop");
       
   142 		if ( mikmod.Player_Stop == NULL ) {
       
   143 			SDL_UnloadObject(mikmod.handle);
       
   144 			return -1;
       
   145 		}
       
   146 		mikmod.VC_WriteBytes =
       
   147 			(ULONG (*)(SBYTE*,ULONG))
       
   148 			SDL_LoadFunction(mikmod.handle, "VC_WriteBytes");
       
   149 		if ( mikmod.VC_WriteBytes == NULL ) {
       
   150 			SDL_UnloadObject(mikmod.handle);
       
   151 			return -1;
       
   152 		}
       
   153 		mikmod.drv_nos =
       
   154 			(MDRIVER*)
       
   155 			SDL_LoadFunction(mikmod.handle, "drv_nos");
       
   156 		if ( mikmod.drv_nos == NULL ) {
       
   157 			SDL_UnloadObject(mikmod.handle);
       
   158 			return -1;
       
   159 		}
       
   160 		mikmod.md_device =
       
   161 			(UWORD*)
       
   162 			SDL_LoadFunction(mikmod.handle, "md_device");
       
   163 		if ( mikmod.md_device == NULL ) {
       
   164 			SDL_UnloadObject(mikmod.handle);
       
   165 			return -1;
       
   166 		}
       
   167 		mikmod.md_mixfreq =
       
   168 			(UWORD*)
       
   169 			SDL_LoadFunction(mikmod.handle, "md_mixfreq");
       
   170 		if ( mikmod.md_mixfreq == NULL ) {
       
   171 			SDL_UnloadObject(mikmod.handle);
       
   172 			return -1;
       
   173 		}
       
   174 		mikmod.md_mode =
       
   175 			(UWORD*)
       
   176 			SDL_LoadFunction(mikmod.handle, "md_mode");
       
   177 		if ( mikmod.md_mode == NULL ) {
       
   178 			SDL_UnloadObject(mikmod.handle);
       
   179 			return -1;
       
   180 		}
       
   181 		mikmod.md_musicvolume =
       
   182 			(UBYTE*)
       
   183 			SDL_LoadFunction(mikmod.handle, "md_musicvolume");
       
   184 		if ( mikmod.md_musicvolume == NULL ) {
       
   185 			SDL_UnloadObject(mikmod.handle);
       
   186 			return -1;
       
   187 		}
       
   188 		mikmod.md_pansep =
       
   189 			(UBYTE*)
       
   190 			SDL_LoadFunction(mikmod.handle, "md_pansep");
       
   191 		if ( mikmod.md_pansep == NULL ) {
       
   192 			SDL_UnloadObject(mikmod.handle);
       
   193 			return -1;
       
   194 		}
       
   195 		mikmod.md_reverb =
       
   196 			(UBYTE*)
       
   197 			SDL_LoadFunction(mikmod.handle, "md_reverb");
       
   198 		if ( mikmod.md_reverb == NULL ) {
       
   199 			SDL_UnloadObject(mikmod.handle);
       
   200 			return -1;
       
   201 		}
       
   202 		mikmod.md_sndfxvolume =
       
   203 			(UBYTE*)
       
   204 			SDL_LoadFunction(mikmod.handle, "md_sndfxvolume");
       
   205 		if ( mikmod.md_sndfxvolume == NULL ) {
       
   206 			SDL_UnloadObject(mikmod.handle);
       
   207 			return -1;
       
   208 		}
       
   209 		mikmod.md_volume =
       
   210 			(UBYTE*)
       
   211 			SDL_LoadFunction(mikmod.handle, "md_volume");
       
   212 		if ( mikmod.md_volume == NULL ) {
       
   213 			SDL_UnloadObject(mikmod.handle);
       
   214 			return -1;
       
   215 		}
       
   216 	}
       
   217 	++mikmod.loaded;
       
   218 
       
   219 	return 0;
       
   220 }
       
   221 void Mix_QuitMOD()
       
   222 {
       
   223 	if ( mikmod.loaded == 0 ) {
       
   224 		return;
       
   225 	}
       
   226 	if ( mikmod.loaded == 1 ) {
       
   227 		SDL_UnloadObject(mikmod.handle);
       
   228 	}
       
   229 	--mikmod.loaded;
       
   230 }
       
   231 #else
       
   232 int Mix_InitMOD()
       
   233 {
       
   234 	if ( mikmod.loaded == 0 ) {
       
   235 		mikmod.MikMod_Exit = MikMod_Exit;
       
   236 		mikmod.MikMod_InfoDriver = MikMod_InfoDriver;
       
   237 		mikmod.MikMod_InfoLoader = MikMod_InfoLoader;
       
   238 		mikmod.MikMod_Init = MikMod_Init;
       
   239 		mikmod.MikMod_RegisterAllLoaders = MikMod_RegisterAllLoaders;
       
   240 		mikmod.MikMod_RegisterDriver = MikMod_RegisterDriver;
       
   241 		mikmod.MikMod_errno = &MikMod_errno;
       
   242 		mikmod.MikMod_strerror = MikMod_strerror;
       
   243 		mikmod.Player_Active = Player_Active;
       
   244 		mikmod.Player_Free = Player_Free;
       
   245 		mikmod.Player_LoadGeneric = Player_LoadGeneric;
       
   246 		mikmod.Player_SetPosition = Player_SetPosition;
       
   247 		mikmod.Player_SetVolume = Player_SetVolume;
       
   248 		mikmod.Player_Start = Player_Start;
       
   249 		mikmod.Player_Stop = Player_Stop;
       
   250 		mikmod.VC_WriteBytes = VC_WriteBytes;
       
   251 		mikmod.drv_nos = &drv_nos;
       
   252 		mikmod.md_device = &md_device;
       
   253 		mikmod.md_mixfreq = &md_mixfreq;
       
   254 		mikmod.md_mode = &md_mode;
       
   255 		mikmod.md_musicvolume = &md_musicvolume;
       
   256 		mikmod.md_pansep = &md_pansep;
       
   257 		mikmod.md_reverb = &md_reverb;
       
   258 		mikmod.md_sndfxvolume = &md_sndfxvolume;
       
   259 		mikmod.md_volume = &md_volume;
       
   260 	}
       
   261 	++mikmod.loaded;
       
   262 
       
   263 	return 0;
       
   264 }
       
   265 void Mix_QuitMOD()
       
   266 {
       
   267 	if ( mikmod.loaded == 0 ) {
       
   268 		return;
       
   269 	}
       
   270 	if ( mikmod.loaded == 1 ) {
       
   271 	}
       
   272 	--mikmod.loaded;
       
   273 }
       
   274 #endif /* MOD_DYNAMIC */
       
   275 
       
   276 #endif /* MOD_MUSIC */