dynamic_mod.c
changeset 777 92882ef2ab81
parent 776 07b8e286bc03
child 778 05c93f7af403
     1.1 --- a/dynamic_mod.c	Mon Oct 16 02:16:47 2017 -0700
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,297 +0,0 @@
     1.4 -/*
     1.5 -  SDL_mixer:  An audio mixer library based on the SDL library
     1.6 -  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
     1.7 -
     1.8 -  This software is provided 'as-is', without any express or implied
     1.9 -  warranty.  In no event will the authors be held liable for any damages
    1.10 -  arising from the use of this software.
    1.11 -
    1.12 -  Permission is granted to anyone to use this software for any purpose,
    1.13 -  including commercial applications, and to alter it and redistribute it
    1.14 -  freely, subject to the following restrictions:
    1.15 -
    1.16 -  1. The origin of this software must not be misrepresented; you must not
    1.17 -     claim that you wrote the original software. If you use this software
    1.18 -     in a product, an acknowledgment in the product documentation would be
    1.19 -     appreciated but is not required.
    1.20 -  2. Altered source versions must be plainly marked as such, and must not be
    1.21 -     misrepresented as being the original software.
    1.22 -  3. This notice may not be removed or altered from any source distribution.
    1.23 -*/
    1.24 -
    1.25 -#ifdef MOD_MUSIC
    1.26 -
    1.27 -#include "SDL_loadso.h"
    1.28 -#include "SDL_mixer.h"
    1.29 -#include "dynamic_mod.h"
    1.30 -
    1.31 -mikmod_loader mikmod = {
    1.32 -    0, NULL
    1.33 -};
    1.34 -
    1.35 -#ifdef MOD_DYNAMIC
    1.36 -int Mix_InitMOD()
    1.37 -{
    1.38 -    if ( mikmod.loaded == 0 ) {
    1.39 -        mikmod.handle = SDL_LoadObject(MOD_DYNAMIC);
    1.40 -        if ( mikmod.handle == NULL ) {
    1.41 -            return -1;
    1.42 -        }
    1.43 -        mikmod.MikMod_Exit =
    1.44 -            (void (*)(void))
    1.45 -            SDL_LoadFunction(mikmod.handle, "MikMod_Exit");
    1.46 -        if ( mikmod.MikMod_Exit == NULL ) {
    1.47 -            SDL_UnloadObject(mikmod.handle);
    1.48 -            return -1;
    1.49 -        }
    1.50 -        mikmod.MikMod_InfoDriver =
    1.51 -            (CHAR* (*)(void))
    1.52 -            SDL_LoadFunction(mikmod.handle, "MikMod_InfoDriver");
    1.53 -        if ( mikmod.MikMod_InfoDriver == NULL ) {
    1.54 -            SDL_UnloadObject(mikmod.handle);
    1.55 -            return -1;
    1.56 -        }
    1.57 -        mikmod.MikMod_InfoLoader =
    1.58 -            (CHAR* (*)(void))
    1.59 -            SDL_LoadFunction(mikmod.handle, "MikMod_InfoLoader");
    1.60 -        if ( mikmod.MikMod_InfoLoader == NULL ) {
    1.61 -            SDL_UnloadObject(mikmod.handle);
    1.62 -            return -1;
    1.63 -        }
    1.64 -        mikmod.MikMod_Init =
    1.65 -            (int (*)(MIKMOD3_CONST CHAR*))
    1.66 -            SDL_LoadFunction(mikmod.handle, "MikMod_Init");
    1.67 -        if ( mikmod.MikMod_Init == NULL ) {
    1.68 -            SDL_UnloadObject(mikmod.handle);
    1.69 -            return -1;
    1.70 -        }
    1.71 -        mikmod.MikMod_RegisterAllLoaders =
    1.72 -            (void (*)(void))
    1.73 -            SDL_LoadFunction(mikmod.handle, "MikMod_RegisterAllLoaders");
    1.74 -        if ( mikmod.MikMod_RegisterAllLoaders == NULL ) {
    1.75 -            SDL_UnloadObject(mikmod.handle);
    1.76 -            return -1;
    1.77 -        }
    1.78 -        mikmod.MikMod_RegisterDriver =
    1.79 -            (void (*)(struct MDRIVER*))
    1.80 -            SDL_LoadFunction(mikmod.handle, "MikMod_RegisterDriver");
    1.81 -        if ( mikmod.MikMod_RegisterDriver == NULL ) {
    1.82 -            SDL_UnloadObject(mikmod.handle);
    1.83 -            return -1;
    1.84 -        }
    1.85 -        mikmod.MikMod_errno =
    1.86 -            (int*)
    1.87 -            SDL_LoadFunction(mikmod.handle, "MikMod_errno");
    1.88 -        if ( mikmod.MikMod_errno == NULL ) {
    1.89 -            SDL_UnloadObject(mikmod.handle);
    1.90 -            return -1;
    1.91 -        }
    1.92 -        mikmod.MikMod_strerror =
    1.93 -            (MIKMOD3_CONST char* (*)(int))
    1.94 -            SDL_LoadFunction(mikmod.handle, "MikMod_strerror");
    1.95 -        if ( mikmod.MikMod_strerror == NULL ) {
    1.96 -            SDL_UnloadObject(mikmod.handle);
    1.97 -            return -1;
    1.98 -        }
    1.99 -        mikmod.MikMod_free =
   1.100 -            (void (*)(void*))
   1.101 -            SDL_LoadFunction(mikmod.handle, "MikMod_free");
   1.102 -        if ( mikmod.MikMod_free == NULL ) {
   1.103 -            /* libmikmod 3.1 and earlier doesn't have it */
   1.104 -            mikmod.MikMod_free = free;
   1.105 -        }
   1.106 -        mikmod.Player_Active =
   1.107 -            (BOOL (*)(void))
   1.108 -            SDL_LoadFunction(mikmod.handle, "Player_Active");
   1.109 -        if ( mikmod.Player_Active == NULL ) {
   1.110 -            SDL_UnloadObject(mikmod.handle);
   1.111 -            return -1;
   1.112 -        }
   1.113 -        mikmod.Player_Free =
   1.114 -            (void (*)(MODULE*))
   1.115 -            SDL_LoadFunction(mikmod.handle, "Player_Free");
   1.116 -        if ( mikmod.Player_Free == NULL ) {
   1.117 -            SDL_UnloadObject(mikmod.handle);
   1.118 -            return -1;
   1.119 -        }
   1.120 -        mikmod.Player_LoadGeneric =
   1.121 -            (MODULE* (*)(MREADER*,int,BOOL))
   1.122 -            SDL_LoadFunction(mikmod.handle, "Player_LoadGeneric");
   1.123 -        if ( mikmod.Player_LoadGeneric == NULL ) {
   1.124 -            SDL_UnloadObject(mikmod.handle);
   1.125 -            return -1;
   1.126 -        }
   1.127 -        mikmod.Player_SetPosition =
   1.128 -            (void (*)(UWORD))
   1.129 -            SDL_LoadFunction(mikmod.handle, "Player_SetPosition");
   1.130 -        if ( mikmod.Player_SetPosition == NULL ) {
   1.131 -            SDL_UnloadObject(mikmod.handle);
   1.132 -            return -1;
   1.133 -        }
   1.134 -        mikmod.Player_SetVolume =
   1.135 -            (void (*)(SWORD))
   1.136 -            SDL_LoadFunction(mikmod.handle, "Player_SetVolume");
   1.137 -        if ( mikmod.Player_SetVolume == NULL ) {
   1.138 -            SDL_UnloadObject(mikmod.handle);
   1.139 -            return -1;
   1.140 -        }
   1.141 -        mikmod.Player_Start =
   1.142 -            (void (*)(MODULE*))
   1.143 -            SDL_LoadFunction(mikmod.handle, "Player_Start");
   1.144 -        if ( mikmod.Player_Start == NULL ) {
   1.145 -            SDL_UnloadObject(mikmod.handle);
   1.146 -            return -1;
   1.147 -        }
   1.148 -        mikmod.Player_Stop =
   1.149 -            (void (*)(void))
   1.150 -            SDL_LoadFunction(mikmod.handle, "Player_Stop");
   1.151 -        if ( mikmod.Player_Stop == NULL ) {
   1.152 -            SDL_UnloadObject(mikmod.handle);
   1.153 -            return -1;
   1.154 -        }
   1.155 -        mikmod.VC_WriteBytes =
   1.156 -            (ULONG (*)(SBYTE*,ULONG))
   1.157 -            SDL_LoadFunction(mikmod.handle, "VC_WriteBytes");
   1.158 -        if ( mikmod.VC_WriteBytes == NULL ) {
   1.159 -            SDL_UnloadObject(mikmod.handle);
   1.160 -            return -1;
   1.161 -        }
   1.162 -        mikmod.drv_nos =
   1.163 -            (MDRIVER*)
   1.164 -            SDL_LoadFunction(mikmod.handle, "drv_nos");
   1.165 -        if ( mikmod.drv_nos == NULL ) {
   1.166 -            SDL_UnloadObject(mikmod.handle);
   1.167 -            return -1;
   1.168 -        }
   1.169 -        mikmod.md_device =
   1.170 -            (UWORD*)
   1.171 -            SDL_LoadFunction(mikmod.handle, "md_device");
   1.172 -        if ( mikmod.md_device == NULL ) {
   1.173 -            SDL_UnloadObject(mikmod.handle);
   1.174 -            return -1;
   1.175 -        }
   1.176 -        mikmod.md_mixfreq =
   1.177 -            (UWORD*)
   1.178 -            SDL_LoadFunction(mikmod.handle, "md_mixfreq");
   1.179 -        if ( mikmod.md_mixfreq == NULL ) {
   1.180 -            SDL_UnloadObject(mikmod.handle);
   1.181 -            return -1;
   1.182 -        }
   1.183 -        mikmod.md_mode =
   1.184 -            (UWORD*)
   1.185 -            SDL_LoadFunction(mikmod.handle, "md_mode");
   1.186 -        if ( mikmod.md_mode == NULL ) {
   1.187 -            SDL_UnloadObject(mikmod.handle);
   1.188 -            return -1;
   1.189 -        }
   1.190 -        mikmod.md_musicvolume =
   1.191 -            (UBYTE*)
   1.192 -            SDL_LoadFunction(mikmod.handle, "md_musicvolume");
   1.193 -        if ( mikmod.md_musicvolume == NULL ) {
   1.194 -            SDL_UnloadObject(mikmod.handle);
   1.195 -            return -1;
   1.196 -        }
   1.197 -        mikmod.md_pansep =
   1.198 -            (UBYTE*)
   1.199 -            SDL_LoadFunction(mikmod.handle, "md_pansep");
   1.200 -        if ( mikmod.md_pansep == NULL ) {
   1.201 -            SDL_UnloadObject(mikmod.handle);
   1.202 -            return -1;
   1.203 -        }
   1.204 -        mikmod.md_reverb =
   1.205 -            (UBYTE*)
   1.206 -            SDL_LoadFunction(mikmod.handle, "md_reverb");
   1.207 -        if ( mikmod.md_reverb == NULL ) {
   1.208 -            SDL_UnloadObject(mikmod.handle);
   1.209 -            return -1;
   1.210 -        }
   1.211 -        mikmod.md_sndfxvolume =
   1.212 -            (UBYTE*)
   1.213 -            SDL_LoadFunction(mikmod.handle, "md_sndfxvolume");
   1.214 -        if ( mikmod.md_sndfxvolume == NULL ) {
   1.215 -            SDL_UnloadObject(mikmod.handle);
   1.216 -            return -1;
   1.217 -        }
   1.218 -        mikmod.md_volume =
   1.219 -            (UBYTE*)
   1.220 -            SDL_LoadFunction(mikmod.handle, "md_volume");
   1.221 -        if ( mikmod.md_volume == NULL ) {
   1.222 -            SDL_UnloadObject(mikmod.handle);
   1.223 -            return -1;
   1.224 -        }
   1.225 -    }
   1.226 -    ++mikmod.loaded;
   1.227 -
   1.228 -    return 0;
   1.229 -}
   1.230 -void Mix_QuitMOD()
   1.231 -{
   1.232 -    if ( mikmod.loaded == 0 ) {
   1.233 -        return;
   1.234 -    }
   1.235 -    if ( mikmod.loaded == 1 ) {
   1.236 -        SDL_UnloadObject(mikmod.handle);
   1.237 -    }
   1.238 -    --mikmod.loaded;
   1.239 -}
   1.240 -#else
   1.241 -int Mix_InitMOD()
   1.242 -{
   1.243 -    if ( mikmod.loaded == 0 ) {
   1.244 -#ifdef __MACOSX__
   1.245 -        extern void Player_Start(MODULE*) __attribute__((weak_import));
   1.246 -        if ( Player_Start == NULL )
   1.247 -        {
   1.248 -            /* Missing weakly linked framework */
   1.249 -            Mix_SetError("Missing mikmod.framework");
   1.250 -            return -1;
   1.251 -        }
   1.252 -#endif // __MACOSX__
   1.253 -
   1.254 -        mikmod.MikMod_Exit = MikMod_Exit;
   1.255 -        mikmod.MikMod_InfoDriver = MikMod_InfoDriver;
   1.256 -        mikmod.MikMod_InfoLoader = MikMod_InfoLoader;
   1.257 -        mikmod.MikMod_Init = MikMod_Init;
   1.258 -        mikmod.MikMod_RegisterAllLoaders = MikMod_RegisterAllLoaders;
   1.259 -        mikmod.MikMod_RegisterDriver = MikMod_RegisterDriver;
   1.260 -        mikmod.MikMod_errno = &MikMod_errno;
   1.261 -        mikmod.MikMod_strerror = MikMod_strerror;
   1.262 -#if LIBMIKMOD_VERSION < ((3<<16)|(2<<8))
   1.263 -        mikmod.MikMod_free = free;
   1.264 -#else
   1.265 -        mikmod.MikMod_free = MikMod_free;
   1.266 -#endif
   1.267 -        mikmod.Player_Active = Player_Active;
   1.268 -        mikmod.Player_Free = Player_Free;
   1.269 -        mikmod.Player_LoadGeneric = Player_LoadGeneric;
   1.270 -        mikmod.Player_SetPosition = Player_SetPosition;
   1.271 -        mikmod.Player_SetVolume = Player_SetVolume;
   1.272 -        mikmod.Player_Start = Player_Start;
   1.273 -        mikmod.Player_Stop = Player_Stop;
   1.274 -        mikmod.VC_WriteBytes = VC_WriteBytes;
   1.275 -        mikmod.drv_nos = &drv_nos;
   1.276 -        mikmod.md_device = &md_device;
   1.277 -        mikmod.md_mixfreq = &md_mixfreq;
   1.278 -        mikmod.md_mode = &md_mode;
   1.279 -        mikmod.md_musicvolume = &md_musicvolume;
   1.280 -        mikmod.md_pansep = &md_pansep;
   1.281 -        mikmod.md_reverb = &md_reverb;
   1.282 -        mikmod.md_sndfxvolume = &md_sndfxvolume;
   1.283 -        mikmod.md_volume = &md_volume;
   1.284 -    }
   1.285 -    ++mikmod.loaded;
   1.286 -
   1.287 -    return 0;
   1.288 -}
   1.289 -void Mix_QuitMOD()
   1.290 -{
   1.291 -    if ( mikmod.loaded == 0 ) {
   1.292 -        return;
   1.293 -    }
   1.294 -    if ( mikmod.loaded == 1 ) {
   1.295 -    }
   1.296 -    --mikmod.loaded;
   1.297 -}
   1.298 -#endif /* MOD_DYNAMIC */
   1.299 -
   1.300 -#endif /* MOD_MUSIC */