Sam Lantinga - Sat Oct 3 13:33:36 PDT 2009
authorSam Lantinga <slouken@libsdl.org>
Sat, 03 Oct 2009 20:43:33 +0000
changeset 419e27fe0bfe470
parent 418 e03597bc19a9
child 420 2594a266fc8b
Sam Lantinga - Sat Oct 3 13:33:36 PDT 2009
* MOD support uses libmikmod and is dynamically loaded by default
CHANGES
configure.in
dynamic_mod.c
dynamic_mod.h
mikmod/AUTHORS
mikmod/COPYING.LESSER
mikmod/README
mikmod/drv_nos.c
mikmod/load_669.c
mikmod/load_amf.c
mikmod/load_dsm.c
mikmod/load_far.c
mikmod/load_gdm.c
mikmod/load_imf.c
mikmod/load_it.c
mikmod/load_m15.c
mikmod/load_med.c
mikmod/load_mod.c
mikmod/load_mtm.c
mikmod/load_okt.c
mikmod/load_s3m.c
mikmod/load_stm.c
mikmod/load_stx.c
mikmod/load_ult.c
mikmod/load_uni.c
mikmod/load_xm.c
mikmod/mdreg.c
mikmod/mdriver.c
mikmod/mikmod.h
mikmod/mikmod_build.h
mikmod/mikmod_internals.h
mikmod/mloader.c
mikmod/mlreg.c
mikmod/mlutil.c
mikmod/mmalloc.c
mikmod/mmerror.c
mikmod/mmio.c
mikmod/mplayer.c
mikmod/munitrk.c
mikmod/mwav.c
mikmod/npertab.c
mikmod/sloader.c
mikmod/virtch.c
mikmod/virtch2.c
mikmod/virtch_common.c
music.c
music_mod.c
music_mod.h
     1.1 --- a/CHANGES	Sat Oct 03 10:53:24 2009 +0000
     1.2 +++ b/CHANGES	Sat Oct 03 20:43:33 2009 +0000
     1.3 @@ -1,4 +1,6 @@
     1.4  1.2.9:
     1.5 +Sam Lantinga - Sat Oct  3 13:33:36 PDT 2009
     1.6 + * MOD support uses libmikmod and is dynamically loaded by default
     1.7  Sam Lantinga - Sat Oct  3 02:49:41 PDT 2009
     1.8   * Added TIMIDITY_CFG environment variable to fully locate timidity.cfg
     1.9  O.Sezer - 2009-10-02 08:41:50 PDT 
     2.1 --- a/configure.in	Sat Oct 03 10:53:24 2009 +0000
     2.2 +++ b/configure.in	Sat Oct 03 20:43:33 2009 +0000
     2.3 @@ -152,6 +152,7 @@
     2.4      SOURCES="$SOURCES $srcdir/music_cmd.c"
     2.5      EXTRA_CFLAGS="$EXTRA_CFLAGS -DCMD_MUSIC"
     2.6  fi
     2.7 +
     2.8  AC_ARG_ENABLE([music-wave],
     2.9  AC_HELP_STRING([--enable-music-wave], [enable streaming WAVE music [[default=yes]]]),
    2.10                [], [enable_music_wave=yes])
    2.11 @@ -159,22 +160,27 @@
    2.12      SOURCES="$SOURCES $srcdir/wavestream.c"
    2.13      EXTRA_CFLAGS="$EXTRA_CFLAGS -DWAV_MUSIC"
    2.14  fi
    2.15 -no_libmikmod=yes
    2.16 -libmikmod_maj=3
    2.17 -libmikmod_min=1
    2.18 -libmikmod_rev=10
    2.19 -libmikmod_ver="$libmikmod_maj.$libmikmod_min.$libmikmod_rev"
    2.20 -AC_ARG_ENABLE([music-libmikmod],
    2.21 -AC_HELP_STRING([--enable-music-libmikmod], [enable MOD music via external libmikmod [[default=no]]]),
    2.22 -              [], [enable_music_libmikmod=no])
    2.23 -if test x$enable_music_libmikmod = xyes; then
    2.24 +
    2.25 +AC_ARG_ENABLE([music-mod],
    2.26 +AC_HELP_STRING([--enable-music-mod], [enable MOD music via mikmod [[default=yes]]]),
    2.27 +              [], [enable_music_mod=yes])
    2.28 +AC_ARG_ENABLE([music-mod-shared],
    2.29 +AC_HELP_STRING([--enable-music-mod-shared], [dynamically load MOD support [[default=yes]]]),
    2.30 +              [], [enable_music_mod_shared=yes])
    2.31 +if test x$enable_music_mod = xyes; then
    2.32 +    have_libmikmod=no
    2.33 +    libmikmod_maj=3
    2.34 +    libmikmod_min=1
    2.35 +    libmikmod_rev=10
    2.36 +    libmikmod_ver="$libmikmod_maj.$libmikmod_min.$libmikmod_rev"
    2.37      AC_PATH_PROG(LIBMIKMOD_CONFIG, libmikmod-config, no, [$PATH])
    2.38      if test "$LIBMIKMOD_CONFIG" != "no" ; then
    2.39 -        no_libmikmod=no
    2.40 +        
    2.41          CFLAGS_SAVED="$CFLAGS"
    2.42          LIBS_SAVED="$LIBS"
    2.43          CFLAGS="$CFLAGS -DLIBMIKMOD_MUSIC `$LIBMIKMOD_CONFIG --cflags`"
    2.44          LIBS="$LIBS `$LIBMIKMOD_CONFIG --libs`"
    2.45 +        have_libmikmod=yes
    2.46          AC_MSG_CHECKING([for libmikmod - version >= $libmikmod_ver])
    2.47          AC_TRY_RUN([
    2.48  #include "mikmod.h"
    2.49 @@ -182,36 +188,48 @@
    2.50  
    2.51  int main(int argc, char **argv)
    2.52  {
    2.53 -    long maj=$libmikmod_maj,min=$libmikmod_min,rev=$libmikmod_rev,ver=MikMod_GetVersion();
    2.54 -    /*printf("(%d.%d.%d) ",ver>>16,(ver>>8)&0xff,ver&0xff);*/
    2.55 -    if(ver>=((maj<<16)|(min<<8)|(rev))) {
    2.56 -        printf("yes\n");
    2.57 -        return 0;
    2.58 -    }
    2.59 -    printf("no\n*** libmikmod is older than %d.%d.%d, not using.\n",maj,min,rev);
    2.60 -    return 1;
    2.61 +long maj=$libmikmod_maj,min=$libmikmod_min,rev=$libmikmod_rev,ver=MikMod_GetVersion();
    2.62 +/*printf("(%d.%d.%d) ",ver>>16,(ver>>8)&0xff,ver&0xff);*/
    2.63 +if(ver>=((maj<<16)|(min<<8)|(rev))) {
    2.64 +    printf("yes\n");
    2.65 +    return 0;
    2.66  }
    2.67 -], , , [echo $ac_n "cross compiling; assumed OK... $ac_c"])
    2.68 +printf("no\n*** libmikmod is older than %d.%d.%d, not using.\n",maj,min,rev);
    2.69 +return 1;
    2.70 +}
    2.71 +], [], have_libmikmod=no; CFLAGS="$CFLAGS_SAVED"; LIBS="$LIBS_SAVED",
    2.72 +        [echo $ac_n "cross compiling; assumed OK... $ac_c"])
    2.73      fi
    2.74 -    CFLAGS="$CFLAGS_SAVED"
    2.75 -    LIBS="$LIBS_SAVED"
    2.76 +
    2.77 +    if test x$have_libmikmod = xyes; then
    2.78 +        case "$host" in
    2.79 +            *-*-darwin*)
    2.80 +                mikmod_lib=[`find_lib libmikmod*.dylib`]
    2.81 +                ;;
    2.82 +            *-*-cygwin* | *-*-mingw32*)
    2.83 +                mikmod_lib=[`find_lib "mikmod*.dll"`]
    2.84 +                ;;
    2.85 +            *)
    2.86 +                mikmod_lib=[`find_lib "libmikmod*.so.[0-9]"`]
    2.87 +                if test x$mikmod_lib = x; then
    2.88 +                    mikmod_lib=[`find_lib "libmikmod*.so.[0-9]*"`]
    2.89 +                fi
    2.90 +                ;;
    2.91 +        esac
    2.92 +        SOURCES="$SOURCES $srcdir/*_mod.c"
    2.93 +        EXTRA_CFLAGS="$EXTRA_CFLAGS -DMOD_MUSIC `$LIBMIKMOD_CONFIG --cflags`"
    2.94 +        if test x$enable_music_mod_shared = xyes && test x$mikmod_lib != x; then
    2.95 +            echo "-- dynamic libmikmod -> $mikmod_lib"
    2.96 +            EXTRA_CFLAGS="$EXTRA_CFLAGS -DMOD_DYNAMIC=\\\"$mikmod_lib\\\""
    2.97 +        else
    2.98 +            EXTRA_LDFLAGS="$EXTRA_LDFLAGS `$LIBMIKMOD_CONFIG --libs`"
    2.99 +        fi
   2.100 +    else
   2.101 +        AC_MSG_WARN([*** Unable to find MikMod library (http://mikmod.raphnet.net/)])
   2.102 +        AC_MSG_WARN([MOD support disabled])
   2.103 +    fi
   2.104  fi
   2.105  
   2.106 -AC_ARG_ENABLE([music-mod],
   2.107 -AC_HELP_STRING([--enable-music-mod], [enable MOD music via mikmod [[default=yes]]]),
   2.108 -              [], [enable_music_mod=yes])
   2.109 -if test x$enable_music_mod = xyes; then
   2.110 -    EXTRA_CFLAGS="$EXTRA_CFLAGS -DMOD_MUSIC"
   2.111 -    SOURCES="$SOURCES $srcdir/music_mod.c"
   2.112 -
   2.113 -    if test x$enable_music_libmikmod = xyes; then
   2.114 -        EXTRA_CFLAGS="$EXTRA_CFLAGS -DLIBMIKMOD_MUSIC `$LIBMIKMOD_CONFIG --cflags`"
   2.115 -        EXTRA_LDFLAGS="$EXTRA_LDFLAGS `$LIBMIKMOD_CONFIG --libs`"
   2.116 -    else
   2.117 -        EXTRA_CFLAGS="$EXTRA_CFLAGS -I\$(srcdir)/mikmod"
   2.118 -        SOURCES="$SOURCES $srcdir/mikmod/*.c"
   2.119 -    fi
   2.120 -fi
   2.121  AC_ARG_ENABLE([music-midi],
   2.122  AC_HELP_STRING([--enable-music-midi], [enable MIDI music via timidity [[default=yes]]]),
   2.123                [], [enable_music_midi=yes])
   2.124 @@ -262,11 +280,12 @@
   2.125          fi
   2.126      fi
   2.127  fi
   2.128 +
   2.129  AC_ARG_ENABLE([music-ogg],
   2.130  AC_HELP_STRING([--enable-music-ogg], [enable Ogg Vorbis music [[default=yes]]]),
   2.131                [], [enable_music_ogg=yes])
   2.132  AC_ARG_ENABLE(music-ogg-tremor,
   2.133 -[  --enable-music-ogg-tremor   enable OGG music via libtremor [[default=no]]],
   2.134 +AC_HELP_STRING([--enable-music-ogg-tremor], [enable OGG Vorbis music via libtremor [[default=no]]]),
   2.135                [], enable_music_ogg_tremor=no)
   2.136  AC_ARG_ENABLE([music-ogg-shared],
   2.137  AC_HELP_STRING([--enable-music-ogg-shared], [dynamically load Ogg Vorbis support [[default=yes]]]),
   2.138 @@ -304,6 +323,9 @@
   2.139              else
   2.140                  EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lvorbisidec"
   2.141              fi
   2.142 +        else
   2.143 +            AC_MSG_WARN([*** Unable to find Ogg Vorbis Tremor library (http://www.xiph.org/)])
   2.144 +            AC_MSG_WARN([Ogg Vorbis support disabled])
   2.145          fi
   2.146      else
   2.147          AC_CHECK_HEADER([vorbis/vorbisfile.h], [have_ogg_hdr=yes])
   2.148 @@ -331,9 +353,13 @@
   2.149              else
   2.150                  EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lvorbisfile -lvorbis -logg"
   2.151              fi
   2.152 +        else
   2.153 +            AC_MSG_WARN([*** Unable to find Ogg Vorbis library (http://www.xiph.org/)])
   2.154 +            AC_MSG_WARN([Ogg Vorbis support disabled])
   2.155          fi
   2.156      fi
   2.157  fi
   2.158 +
   2.159  libflac_ver=8
   2.160  AC_ARG_ENABLE([music-flac],
   2.161  AC_HELP_STRING([--enable-music-flac], [enable FLAC music [[default=yes]]]),
   2.162 @@ -359,50 +385,53 @@
   2.163  #endif
   2.164  }
   2.165  ], have_flac_ver=yes, have_flac_ver=no)
   2.166 -		LIBS="$LIBS_SAVED"
   2.167 -		AC_MSG_RESULT($have_flac_ver)
   2.168 -		if test x$have_flac_ver = xno; then
   2.169 -			echo "*** FLAC support has been disabled."
   2.170 -		else
   2.171 -			AC_CHECK_HEADER([FLAC/stream_decoder.h], [have_flac_hdr=yes])
   2.172 -			AC_CHECK_LIB([FLAC], [FLAC__stream_decoder_new], [have_flac_lib=yes])
   2.173 -			if test x$have_flac_hdr = xyes -a x$have_flac_lib = xyes; then	
   2.174 -			    case "$host" in
   2.175 -			        *-*-darwin*)
   2.176 -			            flac_lib=[`find_lib FLAC*.dylib`]
   2.177 -			            ;;
   2.178 -			        *-*-cygwin* | *-*-mingw32*)
   2.179 -			            flac_lib=[`find_lib "libFLAC*.dll"`]
   2.180 -			            ;;
   2.181 -			        *)
   2.182 -			            flac_lib=[`find_lib "libFLAC.so.[0-9]"`]
   2.183 -			            if test x$flac_lib = x; then
   2.184 -			                flac_lib=[`find_lib "libFLAC.so.[0-9]*"`]
   2.185 -			            fi
   2.186 -			            ;;
   2.187 -			    esac
   2.188 -			    SOURCES="$SOURCES $srcdir/*_flac.c"
   2.189 -			    EXTRA_CFLAGS="$EXTRA_CFLAGS -DFLAC_MUSIC"
   2.190 -			    if test x$enable_music_flac_shared = xyes && test x$flac_lib != x; then
   2.191 -			        echo "-- dynamic libFLAC -> $flac_lib"
   2.192 -			        EXTRA_CFLAGS="$EXTRA_CFLAGS -DFLAC_DYNAMIC=\\\"$flac_lib\\\""
   2.193 -			    else
   2.194 -			        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lFLAC"
   2.195 -			    fi
   2.196 -			fi
   2.197 -		fi
   2.198 -	fi
   2.199 +        LIBS="$LIBS_SAVED"
   2.200 +        AC_MSG_RESULT($have_flac_ver)
   2.201 +    fi
   2.202 +
   2.203 +    if test x$have_flac_ver = xyes; then
   2.204 +        AC_CHECK_HEADER([FLAC/stream_decoder.h], [have_flac_hdr=yes])
   2.205 +        AC_CHECK_LIB([FLAC], [FLAC__stream_decoder_new], [have_flac_lib=yes])
   2.206 +        if test x$have_flac_hdr = xyes -a x$have_flac_lib = xyes; then    
   2.207 +            case "$host" in
   2.208 +                *-*-darwin*)
   2.209 +                    flac_lib=[`find_lib libFLAC*.dylib`]
   2.210 +                    ;;
   2.211 +                *-*-cygwin* | *-*-mingw32*)
   2.212 +                    flac_lib=[`find_lib "libFLAC*.dll"`]
   2.213 +                    ;;
   2.214 +                *)
   2.215 +                    flac_lib=[`find_lib "libFLAC.so.[0-9]"`]
   2.216 +                    if test x$flac_lib = x; then
   2.217 +                        flac_lib=[`find_lib "libFLAC.so.[0-9]*"`]
   2.218 +                    fi
   2.219 +                    ;;
   2.220 +            esac
   2.221 +            SOURCES="$SOURCES $srcdir/*_flac.c"
   2.222 +            EXTRA_CFLAGS="$EXTRA_CFLAGS -DFLAC_MUSIC"
   2.223 +            if test x$enable_music_flac_shared = xyes && test x$flac_lib != x; then
   2.224 +                echo "-- dynamic libFLAC -> $flac_lib"
   2.225 +                EXTRA_CFLAGS="$EXTRA_CFLAGS -DFLAC_DYNAMIC=\\\"$flac_lib\\\""
   2.226 +            else
   2.227 +                EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lFLAC"
   2.228 +            fi
   2.229 +        fi
   2.230 +    else
   2.231 +        AC_MSG_WARN([*** Unable to find FLAC library (http://flac.sourceforge.net/)])
   2.232 +        AC_MSG_WARN([FLAC support disabled])
   2.233 +    fi
   2.234  fi
   2.235 +
   2.236  AC_ARG_ENABLE(music-mp3,
   2.237 -[  --enable-music-mp3      enable MP3 music via smpeg [[default=yes]]],
   2.238 -              , enable_music_mp3=yes)
   2.239 +AC_HELP_STRING([--enable-music-mp3], [enable MP3 music via smpeg [[default=yes]]]),
   2.240 +              [], enable_music_mp3=yes)
   2.241 +AC_ARG_ENABLE([music-mp3-shared],
   2.242 +AC_HELP_STRING([--enable-music-mp3-shared], [dynamically load MP3 support [[default=yes]]]),
   2.243 +              [], [enable_music_mp3_shared=yes])
   2.244  if test x$enable_music_mp3 = xyes; then
   2.245      SMPEG_VERSION=0.4.3
   2.246      AM_PATH_SMPEG($SMPEG_VERSION, have_smpeg=yes, have_smpeg=no)
   2.247      if test x$have_smpeg = xyes; then
   2.248 -        AC_ARG_ENABLE([music-mp3-shared],
   2.249 -AC_HELP_STRING([--enable-music-mp3-shared], [dynamically load MP3 support [[default=yes]]]),
   2.250 -                      [], [enable_music_mp3_shared=yes])
   2.251          case "$host" in
   2.252              *-*-darwin*)
   2.253                  smpeg_lib=[`find_lib libsmpeg*.dylib`]
   2.254 @@ -425,8 +454,11 @@
   2.255          else
   2.256              EXTRA_LDFLAGS="$EXTRA_LDFLAGS $SMPEG_LIBS"
   2.257          fi
   2.258 +    else
   2.259 +        AC_MSG_WARN([*** Unable to find SMPEG library (http://icculus.org/smpeg/)])
   2.260      fi
   2.261  fi
   2.262 +
   2.263  AC_ARG_ENABLE(music-mp3-mad-gpl,
   2.264  AC_HELP_STRING([--enable-music-mp3-mad-gpl], [enable MP3 music via libmad GPL code [[default=no]]]),
   2.265                    [], [enable_music_mp3_mad_gpl=no])
   2.266 @@ -444,9 +476,15 @@
   2.267          SOURCES="$SOURCES $srcdir/music_mad.c"
   2.268          EXTRA_CFLAGS="$EXTRA_CFLAGS -DMP3_MAD_MUSIC"
   2.269          EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lmad"
   2.270 +    else
   2.271 +        AC_MSG_WARN([*** Unable to find MAD library (http://www.underbit.com/products/mad/)])
   2.272      fi
   2.273  fi
   2.274  
   2.275 +if test x$have_smpeg != xyes -a x$have_libmad != xyes; then
   2.276 +    AC_MSG_WARN([MP3 support disabled])
   2.277 +fi
   2.278 +
   2.279  OBJECTS=`echo $SOURCES | sed 's,[[^ ]]*/\([[^ ]]*\)\.c,$(objects)/\1.lo,g'`
   2.280  OBJECTS=`echo $OBJECTS | sed 's,[[^ ]]*/\([[^ ]]*\)\.rc,$(objects)/\1.o,g'`
   2.281  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/dynamic_mod.c	Sat Oct 03 20:43:33 2009 +0000
     3.3 @@ -0,0 +1,276 @@
     3.4 +/*
     3.5 +    SDL_mixer:  An audio mixer library based on the SDL library
     3.6 +    Copyright (C) 1997-2009 Sam Lantinga
     3.7 +
     3.8 +    This library is free software; you can redistribute it and/or
     3.9 +    modify it under the terms of the GNU Library General Public
    3.10 +    License as published by the Free Software Foundation; either
    3.11 +    version 2 of the License, or (at your option) any later version.
    3.12 +
    3.13 +    This library is distributed in the hope that it will be useful,
    3.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 +    Library General Public License for more details.
    3.17 +
    3.18 +    You should have received a copy of the GNU Library General Public
    3.19 +    License along with this library; if not, write to the Free
    3.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.21 +
    3.22 +    Sam Lantinga
    3.23 +    slouken@libsdl.org
    3.24 +*/
    3.25 +
    3.26 +#ifdef MOD_MUSIC
    3.27 +
    3.28 +#include "SDL_loadso.h"
    3.29 +
    3.30 +#include "dynamic_mod.h"
    3.31 +
    3.32 +mikmod_loader mikmod = {
    3.33 +	0, NULL
    3.34 +};
    3.35 +
    3.36 +#ifdef MOD_DYNAMIC
    3.37 +int Mix_InitMOD()
    3.38 +{
    3.39 +	if ( mikmod.loaded == 0 ) {
    3.40 +		mikmod.handle = SDL_LoadObject(MOD_DYNAMIC);
    3.41 +		if ( mikmod.handle == NULL ) {
    3.42 +			return -1;
    3.43 +		}
    3.44 +		mikmod.MikMod_Exit =
    3.45 +			(void (*)(void))
    3.46 +			SDL_LoadFunction(mikmod.handle, "MikMod_Exit");
    3.47 +		if ( mikmod.MikMod_Exit == NULL ) {
    3.48 +			SDL_UnloadObject(mikmod.handle);
    3.49 +			return -1;
    3.50 +		}
    3.51 +		mikmod.MikMod_InfoDriver =
    3.52 +			(CHAR* (*)(void))
    3.53 +			SDL_LoadFunction(mikmod.handle, "MikMod_InfoDriver");
    3.54 +		if ( mikmod.MikMod_InfoDriver == NULL ) {
    3.55 +			SDL_UnloadObject(mikmod.handle);
    3.56 +			return -1;
    3.57 +		}
    3.58 +		mikmod.MikMod_InfoLoader =
    3.59 +			(CHAR* (*)(void))
    3.60 +			SDL_LoadFunction(mikmod.handle, "MikMod_InfoLoader");
    3.61 +		if ( mikmod.MikMod_InfoLoader == NULL ) {
    3.62 +			SDL_UnloadObject(mikmod.handle);
    3.63 +			return -1;
    3.64 +		}
    3.65 +		mikmod.MikMod_Init =
    3.66 +			(BOOL (*)(CHAR*))
    3.67 +			SDL_LoadFunction(mikmod.handle, "MikMod_Init");
    3.68 +		if ( mikmod.MikMod_Init == NULL ) {
    3.69 +			SDL_UnloadObject(mikmod.handle);
    3.70 +			return -1;
    3.71 +		}
    3.72 +		mikmod.MikMod_RegisterAllLoaders =
    3.73 +			(void (*)(void))
    3.74 +			SDL_LoadFunction(mikmod.handle, "MikMod_RegisterAllLoaders");
    3.75 +		if ( mikmod.MikMod_RegisterAllLoaders == NULL ) {
    3.76 +			SDL_UnloadObject(mikmod.handle);
    3.77 +			return -1;
    3.78 +		}
    3.79 +		mikmod.MikMod_RegisterDriver =
    3.80 +			(void (*)(struct MDRIVER*))
    3.81 +			SDL_LoadFunction(mikmod.handle, "MikMod_RegisterDriver");
    3.82 +		if ( mikmod.MikMod_RegisterDriver == NULL ) {
    3.83 +			SDL_UnloadObject(mikmod.handle);
    3.84 +			return -1;
    3.85 +		}
    3.86 +		mikmod.MikMod_errno =
    3.87 +			(int*)
    3.88 +			SDL_LoadFunction(mikmod.handle, "MikMod_errno");
    3.89 +		if ( mikmod.MikMod_errno == NULL ) {
    3.90 +			SDL_UnloadObject(mikmod.handle);
    3.91 +			return -1;
    3.92 +		}
    3.93 +		mikmod.MikMod_strerror =
    3.94 +			(char* (*)(int))
    3.95 +			SDL_LoadFunction(mikmod.handle, "MikMod_strerror");
    3.96 +		if ( mikmod.MikMod_strerror == NULL ) {
    3.97 +			SDL_UnloadObject(mikmod.handle);
    3.98 +			return -1;
    3.99 +		}
   3.100 +		mikmod.Player_Active =
   3.101 +			(BOOL (*)(void))
   3.102 +			SDL_LoadFunction(mikmod.handle, "Player_Active");
   3.103 +		if ( mikmod.Player_Active == NULL ) {
   3.104 +			SDL_UnloadObject(mikmod.handle);
   3.105 +			return -1;
   3.106 +		}
   3.107 +		mikmod.Player_Free =
   3.108 +			(void (*)(MODULE*))
   3.109 +			SDL_LoadFunction(mikmod.handle, "Player_Free");
   3.110 +		if ( mikmod.Player_Free == NULL ) {
   3.111 +			SDL_UnloadObject(mikmod.handle);
   3.112 +			return -1;
   3.113 +		}
   3.114 +		mikmod.Player_LoadGeneric =
   3.115 +			(MODULE* (*)(MREADER*,int,BOOL))
   3.116 +			SDL_LoadFunction(mikmod.handle, "Player_LoadGeneric");
   3.117 +		if ( mikmod.Player_LoadGeneric == NULL ) {
   3.118 +			SDL_UnloadObject(mikmod.handle);
   3.119 +			return -1;
   3.120 +		}
   3.121 +		mikmod.Player_SetPosition =
   3.122 +			(void (*)(UWORD))
   3.123 +			SDL_LoadFunction(mikmod.handle, "Player_SetPosition");
   3.124 +		if ( mikmod.Player_SetPosition == NULL ) {
   3.125 +			SDL_UnloadObject(mikmod.handle);
   3.126 +			return -1;
   3.127 +		}
   3.128 +		mikmod.Player_SetVolume =
   3.129 +			(void (*)(SWORD))
   3.130 +			SDL_LoadFunction(mikmod.handle, "Player_SetVolume");
   3.131 +		if ( mikmod.Player_SetVolume == NULL ) {
   3.132 +			SDL_UnloadObject(mikmod.handle);
   3.133 +			return -1;
   3.134 +		}
   3.135 +		mikmod.Player_Start =
   3.136 +			(void (*)(MODULE*))
   3.137 +			SDL_LoadFunction(mikmod.handle, "Player_Start");
   3.138 +		if ( mikmod.Player_Start == NULL ) {
   3.139 +			SDL_UnloadObject(mikmod.handle);
   3.140 +			return -1;
   3.141 +		}
   3.142 +		mikmod.Player_Stop =
   3.143 +			(void (*)(void))
   3.144 +			SDL_LoadFunction(mikmod.handle, "Player_Stop");
   3.145 +		if ( mikmod.Player_Stop == NULL ) {
   3.146 +			SDL_UnloadObject(mikmod.handle);
   3.147 +			return -1;
   3.148 +		}
   3.149 +		mikmod.VC_WriteBytes =
   3.150 +			(ULONG (*)(SBYTE*,ULONG))
   3.151 +			SDL_LoadFunction(mikmod.handle, "VC_WriteBytes");
   3.152 +		if ( mikmod.VC_WriteBytes == NULL ) {
   3.153 +			SDL_UnloadObject(mikmod.handle);
   3.154 +			return -1;
   3.155 +		}
   3.156 +		mikmod.drv_nos =
   3.157 +			(MDRIVER*)
   3.158 +			SDL_LoadFunction(mikmod.handle, "drv_nos");
   3.159 +		if ( mikmod.drv_nos == NULL ) {
   3.160 +			SDL_UnloadObject(mikmod.handle);
   3.161 +			return -1;
   3.162 +		}
   3.163 +		mikmod.md_device =
   3.164 +			(UWORD*)
   3.165 +			SDL_LoadFunction(mikmod.handle, "md_device");
   3.166 +		if ( mikmod.md_device == NULL ) {
   3.167 +			SDL_UnloadObject(mikmod.handle);
   3.168 +			return -1;
   3.169 +		}
   3.170 +		mikmod.md_mixfreq =
   3.171 +			(UWORD*)
   3.172 +			SDL_LoadFunction(mikmod.handle, "md_mixfreq");
   3.173 +		if ( mikmod.md_mixfreq == NULL ) {
   3.174 +			SDL_UnloadObject(mikmod.handle);
   3.175 +			return -1;
   3.176 +		}
   3.177 +		mikmod.md_mode =
   3.178 +			(UWORD*)
   3.179 +			SDL_LoadFunction(mikmod.handle, "md_mode");
   3.180 +		if ( mikmod.md_mode == NULL ) {
   3.181 +			SDL_UnloadObject(mikmod.handle);
   3.182 +			return -1;
   3.183 +		}
   3.184 +		mikmod.md_musicvolume =
   3.185 +			(UBYTE*)
   3.186 +			SDL_LoadFunction(mikmod.handle, "md_musicvolume");
   3.187 +		if ( mikmod.md_musicvolume == NULL ) {
   3.188 +			SDL_UnloadObject(mikmod.handle);
   3.189 +			return -1;
   3.190 +		}
   3.191 +		mikmod.md_pansep =
   3.192 +			(UBYTE*)
   3.193 +			SDL_LoadFunction(mikmod.handle, "md_pansep");
   3.194 +		if ( mikmod.md_pansep == NULL ) {
   3.195 +			SDL_UnloadObject(mikmod.handle);
   3.196 +			return -1;
   3.197 +		}
   3.198 +		mikmod.md_reverb =
   3.199 +			(UBYTE*)
   3.200 +			SDL_LoadFunction(mikmod.handle, "md_reverb");
   3.201 +		if ( mikmod.md_reverb == NULL ) {
   3.202 +			SDL_UnloadObject(mikmod.handle);
   3.203 +			return -1;
   3.204 +		}
   3.205 +		mikmod.md_sndfxvolume =
   3.206 +			(UBYTE*)
   3.207 +			SDL_LoadFunction(mikmod.handle, "md_sndfxvolume");
   3.208 +		if ( mikmod.md_sndfxvolume == NULL ) {
   3.209 +			SDL_UnloadObject(mikmod.handle);
   3.210 +			return -1;
   3.211 +		}
   3.212 +		mikmod.md_volume =
   3.213 +			(UBYTE*)
   3.214 +			SDL_LoadFunction(mikmod.handle, "md_volume");
   3.215 +		if ( mikmod.md_volume == NULL ) {
   3.216 +			SDL_UnloadObject(mikmod.handle);
   3.217 +			return -1;
   3.218 +		}
   3.219 +	}
   3.220 +	++mikmod.loaded;
   3.221 +
   3.222 +	return 0;
   3.223 +}
   3.224 +void Mix_QuitMOD()
   3.225 +{
   3.226 +	if ( mikmod.loaded == 0 ) {
   3.227 +		return;
   3.228 +	}
   3.229 +	if ( mikmod.loaded == 1 ) {
   3.230 +		SDL_UnloadObject(mikmod.handle);
   3.231 +	}
   3.232 +	--mikmod.loaded;
   3.233 +}
   3.234 +#else
   3.235 +int Mix_InitMOD()
   3.236 +{
   3.237 +	if ( mikmod.loaded == 0 ) {
   3.238 +		mikmod.MikMod_Exit = MikMod_Exit;
   3.239 +		mikmod.MikMod_InfoDriver = MikMod_InfoDriver;
   3.240 +		mikmod.MikMod_InfoLoader = MikMod_InfoLoader;
   3.241 +		mikmod.MikMod_Init = MikMod_Init;
   3.242 +		mikmod.MikMod_RegisterAllLoaders = MikMod_RegisterAllLoaders;
   3.243 +		mikmod.MikMod_RegisterDriver = MikMod_RegisterDriver;
   3.244 +		mikmod.MikMod_errno = &MikMod_errno;
   3.245 +		mikmod.MikMod_strerror = MikMod_strerror;
   3.246 +		mikmod.Player_Active = Player_Active;
   3.247 +		mikmod.Player_Free = Player_Free;
   3.248 +		mikmod.Player_LoadGeneric = Player_LoadGeneric;
   3.249 +		mikmod.Player_SetPosition = Player_SetPosition;
   3.250 +		mikmod.Player_SetVolume = Player_SetVolume;
   3.251 +		mikmod.Player_Start = Player_Start;
   3.252 +		mikmod.Player_Stop = Player_Stop;
   3.253 +		mikmod.VC_WriteBytes = VC_WriteBytes;
   3.254 +		mikmod.drv_nos = &drv_nos;
   3.255 +		mikmod.md_device = &md_device;
   3.256 +		mikmod.md_mixfreq = &md_mixfreq;
   3.257 +		mikmod.md_mode = &md_mode;
   3.258 +		mikmod.md_musicvolume = &md_musicvolume;
   3.259 +		mikmod.md_pansep = &md_pansep;
   3.260 +		mikmod.md_reverb = &md_reverb;
   3.261 +		mikmod.md_sndfxvolume = &md_sndfxvolume;
   3.262 +		mikmod.md_volume = &md_volume;
   3.263 +	}
   3.264 +	++mikmod.loaded;
   3.265 +
   3.266 +	return 0;
   3.267 +}
   3.268 +void Mix_QuitMOD()
   3.269 +{
   3.270 +	if ( mikmod.loaded == 0 ) {
   3.271 +		return;
   3.272 +	}
   3.273 +	if ( mikmod.loaded == 1 ) {
   3.274 +	}
   3.275 +	--mikmod.loaded;
   3.276 +}
   3.277 +#endif /* MOD_DYNAMIC */
   3.278 +
   3.279 +#endif /* MOD_MUSIC */
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/dynamic_mod.h	Sat Oct 03 20:43:33 2009 +0000
     4.3 @@ -0,0 +1,63 @@
     4.4 +/*
     4.5 +    SDL_mixer:  An audio mixer library based on the SDL library
     4.6 +    Copyright (C) 1997-2009 Sam Lantinga
     4.7 +
     4.8 +    This library is free software; you can redistribute it and/or
     4.9 +    modify it under the terms of the GNU Library General Public
    4.10 +    License as published by the Free Software Foundation; either
    4.11 +    version 2 of the License, or (at your option) any later version.
    4.12 +
    4.13 +    This library is distributed in the hope that it will be useful,
    4.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.16 +    Library General Public License for more details.
    4.17 +
    4.18 +    You should have received a copy of the GNU Library General Public
    4.19 +    License along with this library; if not, write to the Free
    4.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.21 +
    4.22 +    Sam Lantinga
    4.23 +    slouken@libsdl.org
    4.24 +*/
    4.25 +
    4.26 +#ifdef MOD_MUSIC
    4.27 +
    4.28 +#include "mikmod.h"
    4.29 +
    4.30 +typedef struct {
    4.31 +	int loaded;
    4.32 +	void *handle;
    4.33 +
    4.34 +	void (*MikMod_Exit)(void);
    4.35 +	CHAR* (*MikMod_InfoDriver)(void);
    4.36 +	CHAR* (*MikMod_InfoLoader)(void);
    4.37 +	BOOL (*MikMod_Init)(CHAR*);
    4.38 +	void (*MikMod_RegisterAllLoaders)(void);
    4.39 +	void (*MikMod_RegisterDriver)(struct MDRIVER*);
    4.40 +	int* MikMod_errno;
    4.41 +	char* (*MikMod_strerror)(int);
    4.42 +	BOOL (*Player_Active)(void);
    4.43 +	void (*Player_Free)(MODULE*);
    4.44 +	MODULE* (*Player_LoadGeneric)(MREADER*,int,BOOL);
    4.45 +	void (*Player_SetPosition)(UWORD);
    4.46 +	void (*Player_SetVolume)(SWORD);
    4.47 +	void (*Player_Start)(MODULE*);
    4.48 +	void (*Player_Stop)(void);
    4.49 +	ULONG (*VC_WriteBytes)(SBYTE*,ULONG);
    4.50 +	struct MDRIVER* drv_nos;
    4.51 +	UWORD* md_device;
    4.52 +	UWORD* md_mixfreq;
    4.53 +	UWORD* md_mode;
    4.54 +	UBYTE* md_musicvolume;
    4.55 +	UBYTE* md_pansep;
    4.56 +	UBYTE* md_reverb;
    4.57 +	UBYTE* md_sndfxvolume;
    4.58 +	UBYTE* md_volume;
    4.59 +} mikmod_loader;
    4.60 +
    4.61 +extern mikmod_loader mikmod;
    4.62 +
    4.63 +extern int Mix_InitMOD();
    4.64 +extern void Mix_QuitMOD();
    4.65 +
    4.66 +#endif
     5.1 --- a/mikmod/AUTHORS	Sat Oct 03 10:53:24 2009 +0000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,124 +0,0 @@
     5.4 -libmikmod main authors
     5.5 -----------------------
     5.6 -
     5.7 -* Jean-Paul Mikkers (MikMak) <mikmak@via.nl>
     5.8 -  wrote MikMod and maintained it until version 3.
     5.9 -* Jake Stine (Air Richter) <dracoirs@epix.net>
    5.10 -  [email doesn't work anymore...]
    5.11 -  made decisive contributions to the code (esp. IT support) and
    5.12 -  maintained MikMod version 3 until it was discontinued. He still works
    5.13 -  on the WinAmp module plugin, roughly based on MikMod.
    5.14 -* Miod Vallat <miod@mikmod.org>
    5.15 -  current overbooked libmikmod maintainer (since version 3.0.4), made
    5.16 -  an audit of the code resulting in many bugs fixed.
    5.17 -
    5.18 -Previous Unix maintainers
    5.19 --------------------------
    5.20 -
    5.21 -* Steve McIntyre <steven@chiark.greenend.org.uk>
    5.22 -  maintained MikMod'Unix version 2. Used to maintain the Debian package
    5.23 -  for MikMod.
    5.24 -* Peter Amstutz <tetron@student.umass.edu>
    5.25 -  maintained MikMod'Unix version 3 up to version 3.0.3.
    5.26 -  
    5.27 -General contributors
    5.28 ---------------------
    5.29 -
    5.30 -* Arne de Bruijn <arne@knoware.nl>
    5.31 -  wrote the compressed IT sample support.
    5.32 -* Shlomi Fish <shlomif@vipe.technion.ac.il>
    5.33 -  wrote the Java port, bug fixes.
    5.34 -* Juan Linietsky <coding@reduz.com.ar>
    5.35 -  overall bug fixes.
    5.36 -* Claudio Matsuoka <claudio@helllabs.org>
    5.37 -  wrote the STX loader and submitted bug fixes.
    5.38 -* Sebastiaan A. Megens <samegens@xs4all.nl>
    5.39 -  fixed various bugs (memory leaks, endianness issues, etc).
    5.40 -* ``UFO'' <ufo303@poczta.onet.pl>
    5.41 -  wrote the OKT loader.
    5.42 -* Kev Vance <kvance@zeux.org>
    5.43 -  wrote the GDM loader.
    5.44 -
    5.45 -* Paul Fisher made decisive contributions and improvements.
    5.46 -* Alexander Kerkhove fixed an ULT panning effect bug.
    5.47 -* ``Kodiak'' helped on the interfaces of libmikmod.
    5.48 -* Sylvain Marchand make MikMod more portable and GCC compilable.
    5.49 -
    5.50 -
    5.51 -Contributors on the Unix side
    5.52 ------------------------------
    5.53 -
    5.54 -* Douglas Carmichael <dcarmich@mcs.com>
    5.55 -  ported MikMod to FreeBSD.
    5.56 -* Chris Conn <cconn@tohs.abacom.com>
    5.57 -  wrote the OSS driver.
    5.58 -* Roine Gustaffson <e93_rog@e.kth.se>
    5.59 -  wrote the Digital AudioFile driver.
    5.60 -* Stephan Kanthak <kanthak@informatik.rwth-aachen.de>
    5.61 -  wrote the SGI driver.
    5.62 -* Lutz Vieweg <lkv@mania.robin.de>
    5.63 -  wrote the AIX and HP-UX drivers.
    5.64 -* Valtteri Vuorikoski <vuori@sci.fi>
    5.65 -  wrote the Sun driver.
    5.66 -* Andy Lo A Foe <andy@alsa-project.org>
    5.67 -  wrote the Ultra driver (for the Gravis Ultrasound sound card).
    5.68 -* C Ray C <crayc@pyro.net>
    5.69 -  updated the Ultra driver to work with libmikmod 3.
    5.70 -* ``MenTaLguY'' <mental@kludge.org>
    5.71 -  autoconfized the Unix libmikmod distribution.
    5.72 -* Tobias Gloth <gloth@geomagic.com>
    5.73 -  created the new I/O interface, made the code MT-safe and submitted bug fixes.
    5.74 -* Simon Hosie <gumboot@clear.net.nz>
    5.75 -  wrote the piped output driver, and submitted speed optimizations and bugfixes
    5.76 -  for the software mixer.
    5.77 -* Gerd Rausch <gerd@alf.gun.de>
    5.78 -  wrote the sam9407 driver.
    5.79 -* Joseph Carter <knghtbrd@debian.org>
    5.80 -  maintains the Debian package for MikMod and libmikmod, submitted
    5.81 -  bugfixes.
    5.82 -
    5.83 -Contributors on the Windows side
    5.84 ---------------------------------
    5.85 -
    5.86 -* Brian McKinney <Brian.McKinney@colorado.edu>
    5.87 -  created the DirectSound driver.
    5.88 -* Bjornar Henden <bhenden@online.no>
    5.89 -  created the Multimedia API windows driver.
    5.90 -
    5.91 -Contributors on the Dos side
    5.92 -----------------------------
    5.93 -
    5.94 -Their code isn't there anymore, but they contributed to the success of
    5.95 -libmikmod...
    5.96 -
    5.97 -* Jean-Philippe Ajirent wrote the EMS memory routines.
    5.98 -* Peter Breitling ported MikMod to DJGPP.
    5.99 -* Arnout Cosman wrote the PAS driver.
   5.100 -* Mario Koeppen wrote the WSS driver.
   5.101 -* Mike Leibow wrote the GUS driver.
   5.102 -* Jeremy McDonald wrote a fast assembly-language mixer.
   5.103 -* Steffen Rusitschka and Vince Vu wrote the AWE driver.
   5.104 -
   5.105 -Contributors on the Macintosh side
   5.106 -----------------------------------
   5.107 -
   5.108 -* Anders Bjoerklund <afb@algonet.se>
   5.109 -  ported libmikmod to the Macintosh.
   5.110 -
   5.111 -Contributors on the OS/2 side
   5.112 ------------------------------
   5.113 -
   5.114 -* Stefan Tibus <Stefan_Tibus@ThePentagon.com>
   5.115 -  ported libmikmod to OS/2.
   5.116 -* Andrew Zabolotny <bit@eltech.ru>
   5.117 -  improved the existing OS/2 drivers.
   5.118 -
   5.119 -Contributors on the BeOS side
   5.120 ------------------------------
   5.121 -
   5.122 -* Thomas Neumann <tneumann@polycode.dk>
   5.123 -  integrated libmikmod into his BeOS APlayer, and contributed many bug fixes.
   5.124 -
   5.125 --- 
   5.126 -If your name is missing, don't hesitate to remind me at
   5.127 -<miod@mikmod.org>
     6.1 --- a/mikmod/COPYING.LESSER	Sat Oct 03 10:53:24 2009 +0000
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,504 +0,0 @@
     6.4 -		  GNU LESSER GENERAL PUBLIC LICENSE
     6.5 -		       Version 2.1, February 1999
     6.6 -
     6.7 - Copyright (C) 1991, 1999 Free Software Foundation, Inc.
     6.8 -     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     6.9 - Everyone is permitted to copy and distribute verbatim copies
    6.10 - of this license document, but changing it is not allowed.
    6.11 -
    6.12 -[This is the first released version of the Lesser GPL.  It also counts
    6.13 - as the successor of the GNU Library Public License, version 2, hence
    6.14 - the version number 2.1.]
    6.15 -
    6.16 -			    Preamble
    6.17 -
    6.18 -  The licenses for most software are designed to take away your
    6.19 -freedom to share and change it.  By contrast, the GNU General Public
    6.20 -Licenses are intended to guarantee your freedom to share and change
    6.21 -free software--to make sure the software is free for all its users.
    6.22 -
    6.23 -  This license, the Lesser General Public License, applies to some
    6.24 -specially designated software packages--typically libraries--of the
    6.25 -Free Software Foundation and other authors who decide to use it.  You
    6.26 -can use it too, but we suggest you first think carefully about whether
    6.27 -this license or the ordinary General Public License is the better
    6.28 -strategy to use in any particular case, based on the explanations below.
    6.29 -
    6.30 -  When we speak of free software, we are referring to freedom of use,
    6.31 -not price.  Our General Public Licenses are designed to make sure that
    6.32 -you have the freedom to distribute copies of free software (and charge
    6.33 -for this service if you wish); that you receive source code or can get
    6.34 -it if you want it; that you can change the software and use pieces of
    6.35 -it in new free programs; and that you are informed that you can do
    6.36 -these things.
    6.37 -
    6.38 -  To protect your rights, we need to make restrictions that forbid
    6.39 -distributors to deny you these rights or to ask you to surrender these
    6.40 -rights.  These restrictions translate to certain responsibilities for
    6.41 -you if you distribute copies of the library or if you modify it.
    6.42 -
    6.43 -  For example, if you distribute copies of the library, whether gratis
    6.44 -or for a fee, you must give the recipients all the rights that we gave
    6.45 -you.  You must make sure that they, too, receive or can get the source
    6.46 -code.  If you link other code with the library, you must provide
    6.47 -complete object files to the recipients, so that they can relink them
    6.48 -with the library after making changes to the library and recompiling
    6.49 -it.  And you must show them these terms so they know their rights.
    6.50 -
    6.51 -  We protect your rights with a two-step method: (1) we copyright the
    6.52 -library, and (2) we offer you this license, which gives you legal
    6.53 -permission to copy, distribute and/or modify the library.
    6.54 -
    6.55 -  To protect each distributor, we want to make it very clear that
    6.56 -there is no warranty for the free library.  Also, if the library is
    6.57 -modified by someone else and passed on, the recipients should know
    6.58 -that what they have is not the original version, so that the original
    6.59 -author's reputation will not be affected by problems that might be
    6.60 -introduced by others.
    6.61 -
    6.62 -  Finally, software patents pose a constant threat to the existence of
    6.63 -any free program.  We wish to make sure that a company cannot
    6.64 -effectively restrict the users of a free program by obtaining a
    6.65 -restrictive license from a patent holder.  Therefore, we insist that
    6.66 -any patent license obtained for a version of the library must be
    6.67 -consistent with the full freedom of use specified in this license.
    6.68 -
    6.69 -  Most GNU software, including some libraries, is covered by the
    6.70 -ordinary GNU General Public License.  This license, the GNU Lesser
    6.71 -General Public License, applies to certain designated libraries, and
    6.72 -is quite different from the ordinary General Public License.  We this
    6.73 -license for certain libraries in order to permit linking those
    6.74 -libraries into non-free programs.
    6.75 -
    6.76 -  When a program is linked with a library, whether statically or using
    6.77 -a shared library, the combination of the two is legally speaking a
    6.78 -combined work, a derivative of the original library.  The ordinary
    6.79 -General Public License therefore permits such linking only if the
    6.80 -entire combination fits its criteria of freedom.  The Lesser General
    6.81 -Public License permits more lax criteria for linking other code with
    6.82 -the library.
    6.83 -
    6.84 -  We call this license the "Lesser" General Public License because it
    6.85 -does Less to protect the user's freedom than the ordinary General
    6.86 -Public License.  It also provides other free software developers Less
    6.87 -of an advantage over competing non-free programs.  These disadvantages
    6.88 -are the reason we use the ordinary General Public License for many
    6.89 -libraries.  However, the Lesser license provides advantages in certain
    6.90 -special circumstances.
    6.91 -
    6.92 -  For example, on rare occasions, there may be a special need to
    6.93 -encourage widest possible use of a certain library, so that it becomes
    6.94 -a de-facto standard.  To achieve this, non-free programs must be
    6.95 -allowed to use the library.  A more frequent case is that a free
    6.96 -library does the same job as widely used non-free libraries.  In this
    6.97 -case, there is little to gain by limiting the free library to free
    6.98 -software only, so we use the Lesser General Public License.
    6.99 -
   6.100 -  Another cases, permission to use a particular library in non-free
   6.101 -programs enables a greater number of people to use a large body of
   6.102 -free software.  For example, permission to use the GNU C Library in
   6.103 -non-free programs enables many more people to use the whole GNU
   6.104 -operating system, as well as its variant, the GNU/Linux operating
   6.105 -system.
   6.106 -
   6.107 -  Although the Lesser General Public License is Less protective of the
   6.108 -users' freedom, it does insure that the user of a program that is
   6.109 -linked with the Library has the freedom and the wherewithal to run
   6.110 -that program using a modified version of the Library.
   6.111 -
   6.112 -  The precise terms and conditions for copying, distribution and
   6.113 -modification follow.  Pay close attention to the difference between a
   6.114 -"work based on the library" and a "work that uses the library".  The
   6.115 -former contains code derived from the library, whereas the latter must
   6.116 -be combined with the library in order to run.
   6.117 -
   6.118 -		  GNU LESSER GENERAL PUBLIC LICENSE
   6.119 -   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
   6.120 -
   6.121 -  0. This License Agreement applies to any software library or other
   6.122 -program which contains a notice placed by the copyright holder or
   6.123 -other authorized party saying it may be distributed under the terms of
   6.124 -this Lesser General Public License (also called "this License").
   6.125 -Each licensee is addressed as "you".
   6.126 -
   6.127 -  A "library" means a collection of software functions and/or data
   6.128 -prepared so as to be conveniently linked with application programs
   6.129 -(which use some of those functions and data) to form executables.
   6.130 -
   6.131 -  The "Library", below, refers to any such software library or work
   6.132 -which has been distributed under these terms.  A "work based on the
   6.133 -Library" means either the Library or any derivative work under
   6.134 -copyright law: that is to say, a work containing the Library or a
   6.135 -portion of it, either verbatim or with modifications and/or translated
   6.136 -straightforwardly into another language.  (Hereinafter, translation is
   6.137 -included without limitation in the term "modification".)
   6.138 -
   6.139 -  "Source code" for a work means the preferred form of the work for
   6.140 -making modifications to it.  For a library, complete source code means
   6.141 -all the source code for all modules it contains, plus any associated
   6.142 -interface definition files, plus the scripts used to control compilation
   6.143 -and installation of the library.
   6.144 -
   6.145 -  Activities other than copying, distribution and modification are not
   6.146 -covered by this License; they are outside its scope.  The act of
   6.147 -running a program using the Library is not restricted, and output from
   6.148 -such a program is covered only if its contents constitute a work based
   6.149 -on the Library (independent of the use of the Library in a tool for
   6.150 -writing it).  Whether that is true depends on what the Library does
   6.151 -and what the program that uses the Library does.
   6.152 -  
   6.153 -  1. You may copy and distribute verbatim copies of the Library's
   6.154 -complete source code as you receive it, in any medium, provided that
   6.155 -you conspicuously and appropriately publish on each copy an
   6.156 -appropriate copyright notice and disclaimer of warranty; keep intact
   6.157 -all the notices that refer to this License and to the absence of any
   6.158 -warranty; and distribute a copy of this License along with the
   6.159 -Library.
   6.160 -
   6.161 -  You may charge a fee for the physical act of transferring a copy,
   6.162 -and you may at your option offer warranty protection in exchange for a
   6.163 -fee.
   6.164 -
   6.165 -  2. You may modify your copy or copies of the Library or any portion
   6.166 -of it, thus forming a work based on the Library, and copy and
   6.167 -distribute such modifications or work under the terms of Section 1
   6.168 -above, provided that you also meet all of these conditions:
   6.169 -
   6.170 -    a) The modified work must itself be a software library.
   6.171 -
   6.172 -    b) You must cause the files modified to carry prominent notices
   6.173 -    stating that you changed the files and the date of any change.
   6.174 -
   6.175 -    c) You must cause the whole of the work to be licensed at no
   6.176 -    charge to all third parties under the terms of this License.
   6.177 -
   6.178 -    d) If a facility in the modified Library refers to a function or a
   6.179 -    table of data to be supplied by an application program that uses
   6.180 -    the facility, other than as an argument passed when the facility
   6.181 -    is invoked, then you must make a good faith effort to ensure that,
   6.182 -    in the event an application does not supply such function or
   6.183 -    table, the facility still operates, and performs whatever part of
   6.184 -    its purpose remains meaningful.
   6.185 -
   6.186 -    (For example, a function in a library to compute square roots has
   6.187 -    a purpose that is entirely well-defined independent of the
   6.188 -    application.  Therefore, Subsection 2d requires that any
   6.189 -    application-supplied function or table used by this function must
   6.190 -    be optional: if the application does not supply it, the square
   6.191 -    root function must still compute square roots.)
   6.192 -
   6.193 -These requirements apply to the modified work as a whole.  If
   6.194 -identifiable sections of that work are not derived from the Library,
   6.195 -and can be reasonably considered independent and separate works in
   6.196 -themselves, then this License, and its terms, do not apply to those
   6.197 -sections when you distribute them as separate works.  But when you
   6.198 -distribute the same sections as part of a whole which is a work based
   6.199 -on the Library, the distribution of the whole must be on the terms of
   6.200 -this License, whose permissions for other licensees extend to the
   6.201 -entire whole, and thus to each and every part regardless of who wrote
   6.202 -it.
   6.203 -
   6.204 -Thus, it is not the intent of this section to claim rights or contest
   6.205 -your rights to work written entirely by you; rather, the intent is to
   6.206 -exercise the right to control the distribution of derivative or
   6.207 -collective works based on the Library.
   6.208 -
   6.209 -In addition, mere aggregation of another work not based on the Library
   6.210 -with the Library (or with a work based on the Library) on a volume of
   6.211 -a storage or distribution medium does not bring the other work under
   6.212 -the scope of this License.
   6.213 -
   6.214 -  3. You may opt to apply the terms of the ordinary GNU General Public
   6.215 -License instead of this License to a given copy of the Library.  To do
   6.216 -this, you must alter all the notices that refer to this License, so
   6.217 -that they refer to the ordinary GNU General Public License, version 2,
   6.218 -instead of to this License.  (If a newer version than version 2 of the
   6.219 -ordinary GNU General Public License has appeared, then you can specify
   6.220 -that version instead if you wish.)  Do not make any other change in
   6.221 -these notices.
   6.222 -
   6.223 -  Once this change is made in a given copy, it is irreversible for
   6.224 -that copy, so the ordinary GNU General Public License applies to all
   6.225 -subsequent copies and derivative works made from that copy.
   6.226 -
   6.227 -  This option is useful when you wish to copy part of the code of
   6.228 -the Library into a program that is not a library.
   6.229 -
   6.230 -  4. You may copy and distribute the Library (or a portion or
   6.231 -derivative of it, under Section 2) in object code or executable form
   6.232 -under the terms of Sections 1 and 2 above provided that you accompany
   6.233 -it with the complete corresponding machine-readable source code, which
   6.234 -must be distributed under the terms of Sections 1 and 2 above on a
   6.235 -medium customarily used for software interchange.
   6.236 -
   6.237 -  If distribution of object code is made by offering access to copy
   6.238 -from a designated place, then offering equivalent access to copy the
   6.239 -source code from the same place satisfies the requirement to
   6.240 -distribute the source code, even though third parties are not
   6.241 -compelled to copy the source along with the object code.
   6.242 -
   6.243 -  5. A program that contains no derivative of any portion of the
   6.244 -Library, but is designed to work with the Library by being compiled or
   6.245 -linked with it, is called a "work that uses the Library".  Such a
   6.246 -work, in isolation, is not a derivative work of the Library, and
   6.247 -therefore falls outside the scope of this License.
   6.248 -
   6.249 -  However, linking a "work that uses the Library" with the Library
   6.250 -creates an executable that is a derivative of the Library (because it
   6.251 -contains portions of the Library), rather than a "work that uses the
   6.252 -library".  The executable is therefore covered by this License.
   6.253 -Section 6 states terms for distribution of such executables.
   6.254 -
   6.255 -  When a "work that uses the Library" uses material from a header file
   6.256 -that is part of the Library, the object code for the work may be a
   6.257 -derivative work of the Library even though the source code is not.
   6.258 -Whether this is true is especially significant if the work can be
   6.259 -linked without the Library, or if the work is itself a library.  The
   6.260 -threshold for this to be true is not precisely defined by law.
   6.261 -
   6.262 -  If such an object file uses only numerical parameters, data
   6.263 -structure layouts and accessors, and small macros and small inline
   6.264 -functions (ten lines or less in length), then the use of the object
   6.265 -file is unrestricted, regardless of whether it is legally a derivative
   6.266 -work.  (Executables containing this object code plus portions of the
   6.267 -Library will still fall under Section 6.)
   6.268 -
   6.269 -  Otherwise, if the work is a derivative of the Library, you may
   6.270 -distribute the object code for the work under the terms of Section 6.
   6.271 -Any executables containing that work also fall under Section 6,
   6.272 -whether or not they are linked directly with the Library itself.
   6.273 -
   6.274 -  6. As an exception to the Sections above, you may also combine or
   6.275 -link a "work that uses the Library" with the Library to produce a
   6.276 -work containing portions of the Library, and distribute that work
   6.277 -under terms of your choice, provided that the terms permit
   6.278 -modification of the work for the customer's own use and reverse
   6.279 -engineering for debugging such modifications.
   6.280 -
   6.281 -  You must give prominent notice with each copy of the work that the
   6.282 -Library is used in it and that the Library and its use are covered by
   6.283 -this License.  You must supply a copy of this License.  If the work
   6.284 -during execution displays copyright notices, you must include the
   6.285 -copyright notice for the Library among them, as well as a reference
   6.286 -directing the user to the copy of this License.  Also, you must do one
   6.287 -of these things:
   6.288 -
   6.289 -    a) Accompany the work with the complete corresponding
   6.290 -    machine-readable source code for the Library including whatever
   6.291 -    changes were used in the work (which must be distributed under
   6.292 -    Sections 1 and 2 above); and, if the work is an executable linked
   6.293 -    with the Library, with the complete machine-readable "work that
   6.294 -    uses the Library", as object code and/or source code, so that the
   6.295 -    user can modify the Library and then relink to produce a modified
   6.296 -    executable containing the modified Library.  (It is understood
   6.297 -    that the user who changes the contents of definitions files in the
   6.298 -    Library will not necessarily be able to recompile the application
   6.299 -    to use the modified definitions.)
   6.300 -
   6.301 -    b) Use a suitable shared library mechanism for linking with the
   6.302 -    Library.  A suitable mechanism is one that (1) uses at run time a
   6.303 -    copy of the library already present on the user's computer system,
   6.304 -    rather than copying library functions into the executable, and (2)
   6.305 -    will operate properly with a modified version of the library, if
   6.306 -    the user installs one, as long as the modified version is
   6.307 -    interface-compatible with the version that the work was made with.
   6.308 -
   6.309 -    c) Accompany the work with a written offer, valid for at
   6.310 -    least three years, to give the same user the materials
   6.311 -    specified in Subsection 6a, above, for a charge no more
   6.312 -    than the cost of performing this distribution.
   6.313 -
   6.314 -    d) If distribution of the work is made by offering access to copy
   6.315 -    from a designated place, offer equivalent access to copy the above
   6.316 -    specified materials from the same place.
   6.317 -
   6.318 -    e) Verify that the user has already received a copy of these
   6.319 -    materials or that you have already sent this user a copy.
   6.320 -
   6.321 -  For an executable, the required form of the "work that uses the
   6.322 -Library" must include any data and utility programs needed for
   6.323 -reproducing the executable from it.  However, as a special exception,
   6.324 -the materials to be distributed need not include anything that is
   6.325 -normally distributed (in either source or binary form) with the major
   6.326 -components (compiler, kernel, and so on) of the operating system on
   6.327 -which the executable runs, unless that component itself accompanies
   6.328 -the executable.
   6.329 -
   6.330 -  It may happen that this requirement contradicts the license
   6.331 -restrictions of other proprietary libraries that do not normally
   6.332 -accompany the operating system.  Such a contradiction means you cannot
   6.333 -use both them and the Library together in an executable that you
   6.334 -distribute.
   6.335 -
   6.336 -  7. You may place library facilities that are a work based on the
   6.337 -Library side-by-side in a single library together with other library
   6.338 -facilities not covered by this License, and distribute such a combined
   6.339 -library, provided that the separate distribution of the work based on
   6.340 -the Library and of the other library facilities is otherwise
   6.341 -permitted, and provided that you do these two things:
   6.342 -
   6.343 -    a) Accompany the combined library with a copy of the same work
   6.344 -    based on the Library, uncombined with any other library
   6.345 -    facilities.  This must be distributed under the terms of the
   6.346 -    Sections above.
   6.347 -
   6.348 -    b) Give prominent notice with the combined library of the fact
   6.349 -    that part of it is a work based on the Library, and explaining
   6.350 -    where to find the accompanying uncombined form of the same work.
   6.351 -
   6.352 -  8. You may not copy, modify, sublicense, link with, or distribute
   6.353 -the Library except as expressly provided under this License.  Any
   6.354 -attempt otherwise to copy, modify, sublicense, link with, or
   6.355 -distribute the Library is void, and will automatically terminate your
   6.356 -rights under this License.  However, parties who have received copies,
   6.357 -or rights, from you under this License will not have their licenses
   6.358 -terminated so long as such parties remain in full compliance.
   6.359 -
   6.360 -  9. You are not required to accept this License, since you have not
   6.361 -signed it.  However, nothing else grants you permission to modify or
   6.362 -distribute the Library or its derivative works.  These actions are
   6.363 -prohibited by law if you do not accept this License.  Therefore, by
   6.364 -modifying or distributing the Library (or any work based on the
   6.365 -Library), you indicate your acceptance of this License to do so, and
   6.366 -all its terms and conditions for copying, distributing or modifying
   6.367 -the Library or works based on it.
   6.368 -
   6.369 -  10. Each time you redistribute the Library (or any work based on the
   6.370 -Library), the recipient automatically receives a license from the
   6.371 -original licensor to copy, distribute, link with or modify the Library
   6.372 -subject to these terms and conditions.  You may not impose any further
   6.373 -restrictions on the recipients' exercise of the rights granted herein.
   6.374 -You are not responsible for enforcing compliance by third parties with
   6.375 -this License.
   6.376 -
   6.377 -  11. If, as a consequence of a court judgment or allegation of patent
   6.378 -infringement or for any other reason (not limited to patent issues),
   6.379 -conditions are imposed on you (whether by court order, agreement or
   6.380 -otherwise) that contradict the conditions of this License, they do not
   6.381 -excuse you from the conditions of this License.  If you cannot
   6.382 -distribute so as to satisfy simultaneously your obligations under this
   6.383 -License and any other pertinent obligations, then as a consequence you
   6.384 -may not distribute the Library at all.  For example, if a patent
   6.385 -license would not permit royalty-free redistribution of the Library by
   6.386 -all those who receive copies directly or indirectly through you, then
   6.387 -the only way you could satisfy both it and this License would be to
   6.388 -refrain entirely from distribution of the Library.
   6.389 -
   6.390 -If any portion of this section is held invalid or unenforceable under any
   6.391 -particular circumstance, the balance of the section is intended to apply,
   6.392 -and the section as a whole is intended to apply in other circumstances.
   6.393 -
   6.394 -It is not the purpose of this section to induce you to infringe any
   6.395 -patents or other property right claims or to contest validity of any
   6.396 -such claims; this section has the sole purpose of protecting the
   6.397 -integrity of the free software distribution system which is
   6.398 -implemented by public license practices.  Many people have made
   6.399 -generous contributions to the wide range of software distributed
   6.400 -through that system in reliance on consistent application of that
   6.401 -system; it is up to the author/donor to decide if he or she is willing
   6.402 -to distribute software through any other system and a licensee cannot
   6.403 -impose that choice.
   6.404 -
   6.405 -This section is intended to make thoroughly clear what is believed to
   6.406 -be a consequence of the rest of this License.
   6.407 -
   6.408 -  12. If the distribution and/or use of the Library is restricted in
   6.409 -certain countries either by patents or by copyrighted interfaces, the
   6.410 -original copyright holder who places the Library under this License may add
   6.411 -an explicit geographical distribution limitation excluding those countries,
   6.412 -so that distribution is permitted only in or among countries not thus
   6.413 -excluded.  In such case, this License incorporates the limitation as if
   6.414 -written in the body of this License.
   6.415 -
   6.416 -  13. The Free Software Foundation may publish revised and/or new
   6.417 -versions of the Lesser General Public License from time to time.
   6.418 -Such new versions will be similar in spirit to the present version,
   6.419 -but may differ in detail to address new problems or concerns.
   6.420 -
   6.421 -Each version is given a distinguishing version number.  If the Library
   6.422 -specifies a version number of this License which applies to it and
   6.423 -"any later version", you have the option of following the terms and
   6.424 -conditions either of that version or of any later version published by
   6.425 -the Free Software Foundation.  If the Library does not specify a
   6.426 -license version number, you may choose any version ever published by
   6.427 -the Free Software Foundation.
   6.428 -
   6.429 -  14. If you wish to incorporate parts of the Library into other free
   6.430 -programs whose distribution conditions are incompatible with these,
   6.431 -write to the author to ask for permission.  For software which is
   6.432 -copyrighted by the Free Software Foundation, write to the Free
   6.433 -Software Foundation; we sometimes make exceptions for this.  Our
   6.434 -decision will be guided by the two goals of preserving the free status
   6.435 -of all derivatives of our free software and of promoting the sharing
   6.436 -and reuse of software generally.
   6.437 -
   6.438 -			    NO WARRANTY
   6.439 -
   6.440 -  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
   6.441 -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
   6.442 -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
   6.443 -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
   6.444 -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
   6.445 -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   6.446 -PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
   6.447 -LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
   6.448 -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
   6.449 -
   6.450 -  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
   6.451 -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
   6.452 -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
   6.453 -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
   6.454 -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
   6.455 -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
   6.456 -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
   6.457 -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
   6.458 -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
   6.459 -DAMAGES.
   6.460 -
   6.461 -		     END OF TERMS AND CONDITIONS
   6.462 -
   6.463 -           How to Apply These Terms to Your New Libraries
   6.464 -
   6.465 -  If you develop a new library, and you want it to be of the greatest
   6.466 -possible use to the public, we recommend making it free software that
   6.467 -everyone can redistribute and change.  You can do so by permitting
   6.468 -redistribution under these terms (or, alternatively, under the terms of the
   6.469 -ordinary General Public License).
   6.470 -
   6.471 -  To apply these terms, attach the following notices to the library.  It is
   6.472 -safest to attach them to the start of each source file to most effectively
   6.473 -convey the exclusion of warranty; and each file should have at least the
   6.474 -"copyright" line and a pointer to where the full notice is found.
   6.475 -
   6.476 -    <one line to give the library's name and a brief idea of what it does.>
   6.477 -    Copyright (C) <year>  <name of author>
   6.478 -
   6.479 -    This library is free software; you can redistribute it and/or
   6.480 -    modify it under the terms of the GNU Lesser General Public
   6.481 -    License as published by the Free Software Foundation; either
   6.482 -    version 2 of the License, or (at your option) any later version.
   6.483 -
   6.484 -    This library is distributed in the hope that it will be useful,
   6.485 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   6.486 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   6.487 -    Lesser General Public License for more details.
   6.488 -
   6.489 -    You should have received a copy of the GNU Lesser General Public
   6.490 -    License along with this library; if not, write to the Free
   6.491 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   6.492 -
   6.493 -Also add information on how to contact you by electronic and paper mail.
   6.494 -
   6.495 -You should also get your employer (if you work as a programmer) or your
   6.496 -school, if any, to sign a "copyright disclaimer" for the library, if
   6.497 -necessary.  Here is a sample; alter the names:
   6.498 -
   6.499 -  Yoyodyne, Inc., hereby disclaims all copyright interest in the
   6.500 -  library `Frob' (a library for tweaking knobs) written by James Random Hacker.
   6.501 -
   6.502 -  <signature of Ty Coon>, 1 April 1990
   6.503 -  Ty Coon, President of Vice
   6.504 -
   6.505 -That's all there is to it!
   6.506 -
   6.507 -
     7.1 --- a/mikmod/README	Sat Oct 03 10:53:24 2009 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,13 +0,0 @@
     7.4 -
     7.5 - --> MikMod Sound Libraries Version 3.1.12
     7.6 -
     7.7 ---
     7.8 -This version of the library is based on the official UNIX MikMod
     7.9 -library version 3.1.12, found at: http://mikmod.raphnet.net/
    7.10 -
    7.11 -It has been stripped down for inclusion with Simple DirectMedia Layer,
    7.12 -but the missing drivers and file loaders can be plugged right in from
    7.13 -the MikMod 3.1.12 archive.
    7.14 -
    7.15 -See COPYING.LESSER for copying information
    7.16 ---
     8.1 --- a/mikmod/drv_nos.c	Sat Oct 03 10:53:24 2009 +0000
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,116 +0,0 @@
     8.4 -/*	MikMod sound library
     8.5 -	(c) 1998, 1999, 2000 Miodrag Vallat and others - see file AUTHORS for
     8.6 -	complete list.
     8.7 -
     8.8 -	This library is free software; you can redistribute it and/or modify
     8.9 -	it under the terms of the GNU Library General Public License as
    8.10 -	published by the Free Software Foundation; either version 2 of
    8.11 -	the License, or (at your option) any later version.
    8.12 -
    8.13 -	This program is distributed in the hope that it will be useful,
    8.14 -	but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 -	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.16 -	GNU Library General Public License for more details.
    8.17 -
    8.18 -	You should have received a copy of the GNU Library General Public
    8.19 -	License along with this library; if not, write to the Free Software
    8.20 -	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    8.21 -	02111-1307, USA.
    8.22 -*/
    8.23 -
    8.24 -/*==============================================================================
    8.25 -
    8.26 -  $Id$
    8.27 -
    8.28 -  Driver for no output
    8.29 -
    8.30 -==============================================================================*/
    8.31 -
    8.32 -/*
    8.33 -
    8.34 -	Written by Jean-Paul Mikkers <mikmak@via.nl>
    8.35 -
    8.36 -*/
    8.37 -
    8.38 -#ifdef HAVE_CONFIG_H
    8.39 -#include "config.h"
    8.40 -#endif
    8.41 -#define SDL_MIXER_ONLY
    8.42 -
    8.43 -#ifdef HAVE_UNISTD_H
    8.44 -#include <unistd.h>
    8.45 -#endif
    8.46 -
    8.47 -#include "mikmod_internals.h"
    8.48 -
    8.49 -#define ZEROLEN 32768
    8.50 -
    8.51 -#ifndef SDL_MIXER_ONLY
    8.52 -static	SBYTE *zerobuf=NULL;
    8.53 -#endif
    8.54 -
    8.55 -static BOOL NS_IsThere(void)
    8.56 -{
    8.57 -	return 1;
    8.58 -}
    8.59 -
    8.60 -static BOOL NS_Init(void)
    8.61 -{
    8.62 -#ifndef SDL_MIXER_ONLY
    8.63 -	zerobuf=(SBYTE*)_mm_malloc(ZEROLEN);
    8.64 -#endif
    8.65 -	return VC_Init();
    8.66 -}
    8.67 -
    8.68 -static void NS_Exit(void)
    8.69 -{
    8.70 -	VC_Exit();
    8.71 -#ifndef SDL_MIXER_ONLY
    8.72 -	_mm_free(zerobuf);
    8.73 -#endif
    8.74 -}
    8.75 -
    8.76 -static void NS_Update(void)
    8.77 -{
    8.78 -#ifndef SDL_MIXER_ONLY
    8.79 -	if (zerobuf)
    8.80 -		VC_WriteBytes(zerobuf,ZEROLEN);
    8.81 -#endif
    8.82 -}
    8.83 -
    8.84 -MIKMODAPI MDRIVER drv_nos={
    8.85 -	NULL,
    8.86 -	"No Sound",
    8.87 -	"Nosound Driver v3.0",
    8.88 -	255,255,
    8.89 -	"nosound",
    8.90 -
    8.91 -	NULL,
    8.92 -	NS_IsThere,
    8.93 -	VC_SampleLoad,
    8.94 -	VC_SampleUnload,
    8.95 -	VC_SampleSpace,
    8.96 -	VC_SampleLength,
    8.97 -	NS_Init,
    8.98 -	NS_Exit,
    8.99 -	NULL,
   8.100 -	VC_SetNumVoices,
   8.101 -	VC_PlayStart,
   8.102 -	VC_PlayStop,
   8.103 -	NS_Update,
   8.104 -	NULL,
   8.105 -	VC_VoiceSetVolume,
   8.106 -	VC_VoiceGetVolume,
   8.107 -	VC_VoiceSetFrequency,
   8.108 -	VC_VoiceGetFrequency,
   8.109 -	VC_VoiceSetPanning,
   8.110 -	VC_VoiceGetPanning,
   8.111 -	VC_VoicePlay,
   8.112 -	VC_VoiceStop,
   8.113 -	VC_VoiceStopped,
   8.114 -	VC_VoiceGetPosition,
   8.115 -	VC_VoiceRealVolume
   8.116 -};
   8.117 -
   8.118 -
   8.119 -/* ex:set ts=4: */
     9.1 --- a/mikmod/load_669.c	Sat Oct 03 10:53:24 2009 +0000
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,368 +0,0 @@
     9.4 -/*	MikMod sound library
     9.5 -	(c) 1998, 1999, 2000, 2001, 2002 Miodrag Vallat and others - see file
     9.6 -	AUTHORS for complete list.
     9.7 -
     9.8 -	This library is free software; you can redistribute it and/or modify
     9.9 -	it under the terms of the GNU Library General Public License as
    9.10 -	published by the Free Software Foundation; either version 2 of
    9.11 -	the License, or (at your option) any later version.
    9.12 - 
    9.13 -	This program is distributed in the hope that it will be useful,
    9.14 -	but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 -	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    9.16 -	GNU Library General Public License for more details.
    9.17 - 
    9.18 -	You should have received a copy of the GNU Library General Public
    9.19 -	License along with this library; if not, write to the Free Software
    9.20 -	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    9.21 -	02111-1307, USA.
    9.22 -*/
    9.23 -
    9.24 -/*==============================================================================
    9.25 -
    9.26 -  $Id: load_669.c,v 1.1.1.1 2004/06/01 12:16:17 raph Exp $
    9.27 -
    9.28 -  Composer 669 module loader
    9.29 -
    9.30 -==============================================================================*/
    9.31 -
    9.32 -#ifdef HAVE_CONFIG_H
    9.33 -#include "config.h"
    9.34 -#endif
    9.35 -
    9.36 -#ifdef HAVE_UNISTD_H
    9.37 -#include <unistd.h>
    9.38 -#endif
    9.39 -
    9.40 -#include <stdio.h>
    9.41 -#ifdef HAVE_MEMORY_H
    9.42 -#include <memory.h>
    9.43 -#endif
    9.44 -#include <string.h>
    9.45 -
    9.46 -#include "mikmod_internals.h"
    9.47 -
    9.48 -#ifdef SUNOS
    9.49 -extern int fprintf(FILE *, const char *, ...);
    9.50 -#endif
    9.51 -
    9.52 -/*========== Module structure */
    9.53 -
    9.54 -/* header */
    9.55 -typedef struct S69HEADER {   
    9.56 -	UBYTE	marker[2];
    9.57 -	CHAR	message[108];
    9.58 -	UBYTE	nos;
    9.59 -	UBYTE	nop;
    9.60 -	UBYTE	looporder;
    9.61 -	UBYTE	orders[0x80];
    9.62 -	UBYTE	tempos[0x80];
    9.63 -	UBYTE	breaks[0x80];
    9.64 -} S69HEADER;
    9.65 -
    9.66 -/* sample information */
    9.67 -typedef struct S69SAMPLE {
    9.68 -	CHAR	filename[13];
    9.69 -	SLONG	length;
    9.70 -	SLONG	loopbeg;
    9.71 -	SLONG	loopend;
    9.72 -} S69SAMPLE;
    9.73 -
    9.74 -/* encoded note */
    9.75 -typedef struct S69NOTE {
    9.76 -	UBYTE	a,b,c;
    9.77 -} S69NOTE;
    9.78 -
    9.79 -/*========== Loader variables */
    9.80 -
    9.81 -/* current pattern */
    9.82 -static	S69NOTE* s69pat=NULL;
    9.83 -/* Module header */
    9.84 -static	S69HEADER* mh=NULL;
    9.85 -
    9.86 -/* file type identification */
    9.87 -static	CHAR* S69_Version[]={
    9.88 -	"Composer 669",
    9.89 -	"Extended 669"
    9.90 -};
    9.91 -
    9.92 -/*========== Loader code */
    9.93 -
    9.94 -BOOL S69_Test(void)
    9.95 -{
    9.96 -	UBYTE buf[0x80];
    9.97 -
    9.98 -	if(!_mm_read_UBYTES(buf,2,modreader))
    9.99 -		return 0;
   9.100 -	/* look for id */
   9.101 -	if(!memcmp(buf,"if",2) || !memcmp(buf,"JN",2)) {
   9.102 -		int i;
   9.103 -
   9.104 -		/* skip song message */
   9.105 -		_mm_fseek(modreader,108,SEEK_CUR);
   9.106 -		/* sanity checks */
   9.107 -		if(_mm_read_UBYTE(modreader) > 64) return 0;
   9.108 -		if(_mm_read_UBYTE(modreader) > 128) return 0;
   9.109 -		if(_mm_read_UBYTE(modreader) > 127) return 0;
   9.110 -		/* check order table */
   9.111 -		if(!_mm_read_UBYTES(buf,0x80,modreader)) return 0;
   9.112 -		for(i=0;i<0x80;i++)
   9.113 -			if((buf[i]>=0x80)&&(buf[i]!=0xff)) return 0;
   9.114 -		/* check tempos table */
   9.115 -		if(!_mm_read_UBYTES(buf,0x80,modreader)) return 0;
   9.116 -		for(i=0;i<0x80;i++)
   9.117 -			if((!buf[i])||(buf[i]>32)) return 0;
   9.118 -		/* check pattern length table */
   9.119 -		if(!_mm_read_UBYTES(buf,0x80,modreader)) return 0;
   9.120 -		for(i=0;i<0x80;i++)
   9.121 -			if(buf[i]>0x3f) return 0;
   9.122 -	} else
   9.123 -		return 0;
   9.124 -
   9.125 -	return 1;
   9.126 -}
   9.127 -
   9.128 -BOOL S69_Init(void)
   9.129 -{
   9.130 -	if(!(s69pat=(S69NOTE *)_mm_malloc(64*8*sizeof(S69NOTE)))) return 0;
   9.131 -	if(!(mh=(S69HEADER *)_mm_malloc(sizeof(S69HEADER)))) return 0;
   9.132 -
   9.133 -	return 1;
   9.134 -}
   9.135 -
   9.136 -void S69_Cleanup(void)
   9.137 -{
   9.138 -	_mm_free(s69pat);
   9.139 -	_mm_free(mh);
   9.140 -}
   9.141 -
   9.142 -static BOOL S69_LoadPatterns(void)
   9.143 -{
   9.144 -	int track,row,channel;
   9.145 -	UBYTE note,inst,vol,effect,lastfx,lastval;
   9.146 -	S69NOTE *cur;
   9.147 -	int tracks=0;
   9.148 -	
   9.149 -	if(!AllocPatterns()) return 0;
   9.150 -	if(!AllocTracks()) return 0;
   9.151 -
   9.152 -	for(track=0;track<of.numpat;track++) {
   9.153 -		/* set pattern break locations */
   9.154 -		of.pattrows[track]=mh->breaks[track]+1;
   9.155 -
   9.156 -		/* load the 669 pattern */
   9.157 -		cur=s69pat;
   9.158 -		for(row=0;row<64;row++) {
   9.159 -			for(channel=0;channel<8;channel++,cur++) {
   9.160 -				cur->a = _mm_read_UBYTE(modreader);
   9.161 -				cur->b = _mm_read_UBYTE(modreader);
   9.162 -				cur->c = _mm_read_UBYTE(modreader);
   9.163 -			}
   9.164 -		}
   9.165 -
   9.166 -		if(_mm_eof(modreader)) {
   9.167 -			_mm_errno = MMERR_LOADING_PATTERN;
   9.168 -			return 0;
   9.169 -		}
   9.170 -
   9.171 -		/* translate the pattern */
   9.172 -		for(channel=0;channel<8;channel++) {
   9.173 -			UniReset();
   9.174 -			/* set pattern tempo */
   9.175 -			UniPTEffect(0xf,78);
   9.176 -			UniPTEffect(0xf,mh->tempos[track]);
   9.177 -
   9.178 -			lastfx=0xff,lastval=0;
   9.179 -
   9.180 -			for(row=0;row<=mh->breaks[track];row++) {
   9.181 -				int a,b,c;
   9.182 -
   9.183 -				/* fetch the encoded note */
   9.184 -				a=s69pat[(row*8)+channel].a;
   9.185 -				b=s69pat[(row*8)+channel].b;
   9.186 -				c=s69pat[(row*8)+channel].c;
   9.187 -
   9.188 -				/* decode it */
   9.189 -				note=a>>2;
   9.190 -				inst=((a&0x3)<<4)|((b&0xf0)>>4);
   9.191 -				vol=b&0xf;
   9.192 -
   9.193 -				if (a<0xff) {
   9.194 -					if (a<0xfe) {
   9.195 -						UniInstrument(inst);
   9.196 -						UniNote(note+2*OCTAVE);
   9.197 -						lastfx=0xff; /* reset background effect memory */
   9.198 -					}
   9.199 -					UniPTEffect(0xc,vol<<2);
   9.200 -				}
   9.201 -
   9.202 -				if ((c!=0xff)||(lastfx!=0xff)) {
   9.203 -					if(c==0xff)
   9.204 -						c=lastfx,effect=lastval;
   9.205 -					else
   9.206 -						effect=c&0xf;
   9.207 -
   9.208 -					switch(c>>4) {
   9.209 -						case 0: /* porta up */
   9.210 -							UniPTEffect(0x1,effect);
   9.211 -							lastfx=c,lastval=effect;
   9.212 -							break;
   9.213 -						case 1: /* porta down */
   9.214 -							UniPTEffect(0x2,effect);
   9.215 -							lastfx=c,lastval=effect;
   9.216 -							break;
   9.217 -						case 2: /* porta to note */
   9.218 -							UniPTEffect(0x3,effect);
   9.219 -							lastfx=c,lastval=effect;
   9.220 -							break;
   9.221 -						case 3: /* frequency adjust */
   9.222 -							/* DMP converts this effect to S3M FF1. Why not ? */
   9.223 -							UniEffect(UNI_S3MEFFECTF,0xf0|effect);
   9.224 -							break;
   9.225 -						case 4: /* vibrato */
   9.226 -							UniPTEffect(0x4,effect);
   9.227 -							lastfx=c,lastval=effect;
   9.228 -							break;
   9.229 -						case 5: /* set speed */
   9.230 -							if (effect)
   9.231 -								UniPTEffect(0xf,effect);
   9.232 -							else 
   9.233 -							  if(mh->marker[0]!=0x69) {
   9.234 -#ifdef MIKMOD_DEBUG
   9.235 -								fprintf(stderr,"\r669: unsupported super fast tempo at pat=%d row=%d chan=%d\n",
   9.236 -								       track,row,channel);
   9.237 -#endif
   9.238 -							}
   9.239 -							break;
   9.240 -					}
   9.241 -				}
   9.242 -				UniNewline();
   9.243 -			}
   9.244 -			if(!(of.tracks[tracks++]=UniDup())) return 0;
   9.245 -		}
   9.246 -	}
   9.247 -
   9.248 -	return 1;
   9.249 -}
   9.250 -
   9.251 -BOOL S69_Load(BOOL curious)
   9.252 -{
   9.253 -	int i;
   9.254 -	SAMPLE *current;
   9.255 -	S69SAMPLE sample;
   9.256 -
   9.257 -	/* module header */
   9.258 -	_mm_read_UBYTES(mh->marker,2,modreader);
   9.259 -	_mm_read_UBYTES(mh->message,108,modreader);
   9.260 -	mh->nos=_mm_read_UBYTE(modreader);
   9.261 -	mh->nop=_mm_read_UBYTE(modreader);
   9.262 -	mh->looporder=_mm_read_UBYTE(modreader);
   9.263 -	_mm_read_UBYTES(mh->orders,0x80,modreader);
   9.264 -	for(i=0;i<0x80;i++)
   9.265 -		if ((mh->orders[i]>=0x80)&&(mh->orders[i]!=0xff)) {
   9.266 -			_mm_errno=MMERR_NOT_A_MODULE;
   9.267 -			return 1;
   9.268 -		}
   9.269 -	_mm_read_UBYTES(mh->tempos,0x80,modreader);
   9.270 -	for(i=0;i<0x80;i++)
   9.271 -		if ((!mh->tempos[i])||(mh->tempos[i]>32)) {
   9.272 -			_mm_errno=MMERR_NOT_A_MODULE;
   9.273 -			return 1;
   9.274 -		}
   9.275 -	_mm_read_UBYTES(mh->breaks,0x80,modreader);
   9.276 -	for(i=0;i<0x80;i++)
   9.277 -		if (mh->breaks[i]>0x3f) {
   9.278 -			_mm_errno=MMERR_NOT_A_MODULE;
   9.279 -			return 1;
   9.280 -		}
   9.281 -
   9.282 -	/* set module variables */
   9.283 -	of.initspeed=4;
   9.284 -	of.inittempo=78;
   9.285 -	of.songname=DupStr(mh->message,36,1);
   9.286 -	of.modtype=strdup(S69_Version[memcmp(mh->marker,"JN",2)==0]);
   9.287 -	of.numchn=8;
   9.288 -	of.numpat=mh->nop;
   9.289 -	of.numins=of.numsmp=mh->nos;
   9.290 -	of.numtrk=of.numchn*of.numpat;
   9.291 -	of.flags=UF_XMPERIODS|UF_LINEAR;
   9.292 -
   9.293 -	for(i=   35;(i>=   0)&&(mh->message[i]==' ');i--) mh->message[i]=0;
   9.294 -	for(i=36+35;(i>=36+0)&&(mh->message[i]==' ');i--) mh->message[i]=0;
   9.295 -	for(i=72+35;(i>=72+0)&&(mh->message[i]==' ');i--) mh->message[i]=0;
   9.296 -	if((mh->message[0])||(mh->message[36])||(mh->message[72]))
   9.297 -		if((of.comment=(CHAR*)_mm_malloc(3*(36+1)+1))) {
   9.298 -			strncpy(of.comment,mh->message,36);
   9.299 -			strcat(of.comment,"\r");
   9.300 -			if (mh->message[36]) strncat(of.comment,mh->message+36,36);
   9.301 -			strcat(of.comment,"\r");
   9.302 -			if (mh->message[72]) strncat(of.comment,mh->message+72,36);
   9.303 -			strcat(of.comment,"\r");
   9.304 -			of.comment[3*(36+1)]=0;
   9.305 -		}
   9.306 -
   9.307 -	if(!AllocPositions(0x80)) return 0;
   9.308 -	for(i=0;i<0x80;i++) {
   9.309 -		if(mh->orders[i]>=mh->nop) break;
   9.310 -		of.positions[i]=mh->orders[i];
   9.311 -	}
   9.312 -	of.numpos=i;
   9.313 -	of.reppos=mh->looporder<of.numpos?mh->looporder:0;
   9.314 -
   9.315 -	if(!AllocSamples()) return 0;
   9.316 -	current=of.samples;
   9.317 -
   9.318 -	for(i=0;i<of.numins;i++) {
   9.319 -		/* sample information */
   9.320 -		_mm_read_UBYTES((UBYTE*)sample.filename,13,modreader);
   9.321 -		sample.length=_mm_read_I_SLONG(modreader);
   9.322 -		sample.loopbeg=_mm_read_I_SLONG(modreader);
   9.323 -		sample.loopend=_mm_read_I_SLONG(modreader);
   9.324 -		if (sample.loopend==0xfffff) sample.loopend=0;
   9.325 -
   9.326 -		if((sample.length<0)||(sample.loopbeg<-1)||(sample.loopend<-1)) {
   9.327 -			_mm_errno = MMERR_LOADING_HEADER;
   9.328 -			return 0;
   9.329 -		}
   9.330 -
   9.331 -		current->samplename=DupStr(sample.filename,13,1);
   9.332 -		current->seekpos=0;
   9.333 -		current->speed=0;
   9.334 -		current->length=sample.length;
   9.335 -		current->loopstart=sample.loopbeg;
   9.336 -		current->loopend=sample.loopend;
   9.337 -		current->flags=(sample.loopbeg<sample.loopend)?SF_LOOP:0;
   9.338 -		current->volume=64;
   9.339 -
   9.340 -		current++;
   9.341 -	}
   9.342 -
   9.343 -	if(!S69_LoadPatterns()) return 0;
   9.344 -
   9.345 -	return 1;
   9.346 -}
   9.347 -
   9.348 -CHAR *S69_LoadTitle(void)
   9.349 -{
   9.350 -	CHAR s[36];
   9.351 -
   9.352 -	_mm_fseek(modreader,2,SEEK_SET);
   9.353 -	if(!_mm_read_UBYTES(s,36,modreader)) return NULL;
   9.354 -
   9.355 -	return(DupStr(s,36,1));
   9.356 -}
   9.357 -
   9.358 -/*========== Loader information */
   9.359 -
   9.360 -MIKMODAPI MLOADER load_669={
   9.361 -	NULL,
   9.362 -	"669",
   9.363 -	"669 (Composer 669, Unis 669)",
   9.364 -	S69_Init,
   9.365 -	S69_Test,
   9.366 -	S69_Load,
   9.367 -	S69_Cleanup,
   9.368 -	S69_LoadTitle
   9.369 -};
   9.370 -
   9.371 -/* ex:set ts=4: */
    10.1 --- a/mikmod/load_amf.c	Sat Oct 03 10:53:24 2009 +0000
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,569 +0,0 @@
    10.4 -/*	MikMod sound library
    10.5 -	(c) 1998, 1999, 2000, 2001, 2002 Miodrag Vallat and others - see file
    10.6 -	AUTHORS for complete list.
    10.7 -
    10.8 -	This library is free software; you can redistribute it and/or modify
    10.9 -	it under the terms of the GNU Library General Public License as
   10.10 -	published by the Free Software Foundation; either version 2 of
   10.11 -	the License, or (at your option) any later version.
   10.12 - 
   10.13 -	This program is distributed in the hope that it will be useful,
   10.14 -	but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.15 -	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10.16 -	GNU Library General Public License for more details.
   10.17 - 
   10.18 -	You should have received a copy of the GNU Library General Public
   10.19 -	License along with this library; if not, write to the Free Software
   10.20 -	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   10.21 -	02111-1307, USA.
   10.22 -*/
   10.23 -
   10.24 -/*==============================================================================
   10.25 -
   10.26 -  $Id: load_amf.c,v 1.1.1.1 2004/06/01 12:16:17 raph Exp $
   10.27 -
   10.28 -  DMP Advanced Module Format loader
   10.29 -
   10.30 -==============================================================================*/
   10.31 -
   10.32 -#ifdef HAVE_CONFIG_H
   10.33 -#include "config.h"
   10.34 -#endif
   10.35 -
   10.36 -#ifdef HAVE_UNISTD_H
   10.37 -#include <unistd.h>
   10.38 -#endif
   10.39 -
   10.40 -#include <stdio.h>
   10.41 -#ifdef HAVE_MEMORY_H
   10.42 -#include <memory.h>
   10.43 -#endif
   10.44 -#include <string.h>
   10.45 -
   10.46 -#include "mikmod_internals.h"
   10.47 -
   10.48 -#ifdef SUNOS
   10.49 -extern int fprintf(FILE *, const char *, ...);
   10.50 -#endif
   10.51 -
   10.52 -/*========== Module structure */
   10.53 -
   10.54 -typedef struct AMFHEADER {
   10.55 -	UBYTE id[3];			/* AMF file marker */
   10.56 -	UBYTE version;			/* upper major, lower nibble minor version number */
   10.57 -	CHAR  songname[32];		/* ASCIIZ songname */
   10.58 -	UBYTE numsamples;		/* number of samples saved */
   10.59 -	UBYTE numorders;
   10.60 -	UWORD numtracks;		/* number of tracks saved */
   10.61 -	UBYTE numchannels;		/* number of channels used  */
   10.62 -	SBYTE panpos[32];		/* voice pan positions */
   10.63 -	UBYTE songbpm;
   10.64 -	UBYTE songspd;
   10.65 -} AMFHEADER;
   10.66 -
   10.67 -typedef struct AMFSAMPLE {
   10.68 -	UBYTE type;
   10.69 -	CHAR  samplename[32];
   10.70 -	CHAR  filename[13];
   10.71 -	ULONG offset;
   10.72 -	ULONG length;
   10.73 -	UWORD c2spd;
   10.74 -	UBYTE volume;
   10.75 -	ULONG reppos;
   10.76 -	ULONG repend;
   10.77 -} AMFSAMPLE;
   10.78 -
   10.79 -typedef struct AMFNOTE {
   10.80 -	UBYTE note,instr,volume,fxcnt;
   10.81 -	UBYTE effect[3];
   10.82 -	SBYTE parameter[3];
   10.83 -} AMFNOTE;
   10.84 -
   10.85 -/*========== Loader variables */
   10.86 -
   10.87 -static AMFHEADER *mh = NULL;
   10.88 -#define AMFTEXTLEN 22
   10.89 -static CHAR AMF_Version[AMFTEXTLEN+1] = "DSMI Module Format 0.0";
   10.90 -static AMFNOTE *track = NULL;
   10.91 -
   10.92 -/*========== Loader code */
   10.93 -
   10.94 -BOOL AMF_Test(void)
   10.95 -{
   10.96 -	UBYTE id[3],ver;
   10.97 -
   10.98 -	if(!_mm_read_UBYTES(id,3,modreader)) return 0;
   10.99 -	if(memcmp(id,"AMF",3)) return 0;
  10.100 -
  10.101 -	ver=_mm_read_UBYTE(modreader);
  10.102 -	if((ver>=10)&&(ver<=14)) return 1;
  10.103 -	return 0;
  10.104 -}
  10.105 -
  10.106 -BOOL AMF_Init(void)
  10.107 -{
  10.108 -	if(!(mh=(AMFHEADER*)_mm_malloc(sizeof(AMFHEADER)))) return 0;
  10.109 -	if(!(track=(AMFNOTE*)_mm_calloc(64,sizeof(AMFNOTE)))) return 0;
  10.110 -
  10.111 -	return 1;
  10.112 -}
  10.113 -
  10.114 -void AMF_Cleanup(void)
  10.115 -{
  10.116 -	_mm_free(mh);
  10.117 -	_mm_free(track);
  10.118 -}
  10.119 -
  10.120 -static BOOL AMF_UnpackTrack(MREADER* modreader)
  10.121 -{
  10.122 -	ULONG tracksize;
  10.123 -	UBYTE row,cmd;
  10.124 -	SBYTE arg;
  10.125 -
  10.126 -	/* empty track */
  10.127 -	memset(track,0,64*sizeof(AMFNOTE));
  10.128 -
  10.129 -	/* read packed track */
  10.130 -	if (modreader) {
  10.131 -		tracksize=_mm_read_I_UWORD(modreader);
  10.132 -		tracksize+=((ULONG)_mm_read_UBYTE(modreader))<<16;
  10.133 -		if (tracksize)
  10.134 -			while(tracksize--) {
  10.135 -				row=_mm_read_UBYTE(modreader);
  10.136 -				cmd=_mm_read_UBYTE(modreader);
  10.137 -				arg=_mm_read_SBYTE(modreader);
  10.138 -				/* unexpected end of track */
  10.139 -				if(!tracksize) {
  10.140 -					if((row==0xff)&&(cmd==0xff)&&(arg==-1))
  10.141 -						break;
  10.142 -					/* the last triplet should be FF FF FF, but this is not
  10.143 -					   always the case... maybe a bug in m2amf ? 
  10.144 -					else
  10.145 -						return 0;
  10.146 -					*/
  10.147 -
  10.148 -				}
  10.149 -				/* invalid row (probably unexpected end of row) */
  10.150 -				if (row>=64)
  10.151 -					return 0;
  10.152 -				if (cmd<0x7f) {
  10.153 -					/* note, vol */
  10.154 -					track[row].note=cmd;
  10.155 -					track[row].volume=(UBYTE)arg+1;
  10.156 -				} else
  10.157 -				  if (cmd==0x7f) {
  10.158 -					/* duplicate row */
  10.159 -					if ((arg<0)&&(row+arg>=0)) {
  10.160 -						memcpy(track+row,track+(row+arg),sizeof(AMFNOTE));
  10.161 -					}
  10.162 -				} else
  10.163 -				  if (cmd==0x80) {
  10.164 -					/* instr */
  10.165 -					track[row].instr=arg+1;
  10.166 -				} else
  10.167 -				  if (cmd==0x83) {
  10.168 -					/* volume without note */
  10.169 -					track[row].volume=(UBYTE)arg+1;
  10.170 -				} else 
  10.171 -				  if (cmd==0xff) {
  10.172 -					/* apparently, some M2AMF version fail to estimate the
  10.173 -					   size of the compressed patterns correctly, and end
  10.174 -					   up with blanks, i.e. dead triplets. Those are marked
  10.175 -					   with cmd == 0xff. Let's ignore them. */
  10.176 -				} else
  10.177 -				  if(track[row].fxcnt<3) {
  10.178 -					/* effect, param */
  10.179 -					if(cmd>0x97)
  10.180 -						return 0;
  10.181 -					track[row].effect[track[row].fxcnt]=cmd&0x7f;
  10.182 -					track[row].parameter[track[row].fxcnt]=arg;
  10.183 -					track[row].fxcnt++;
  10.184 -				} else
  10.185 -					return 0;
  10.186 -			}
  10.187 -	}
  10.188 -	return 1;
  10.189 -}
  10.190 -
  10.191 -static UBYTE* AMF_ConvertTrack(void)
  10.192 -{
  10.193 -	int row,fx4memory=0;
  10.194 -
  10.195 -	/* convert track */
  10.196 -	UniReset();
  10.197 -	for (row=0;row<64;row++) {
  10.198 -		if (track[row].instr)  UniInstrument(track[row].instr-1);
  10.199 -		if (track[row].note>OCTAVE) UniNote(track[row].note-OCTAVE);
  10.200 -
  10.201 -		/* AMF effects */
  10.202 -		while(track[row].fxcnt--) {
  10.203 -			SBYTE inf=track[row].parameter[track[row].fxcnt];
  10.204 -
  10.205 -			switch(track[row].effect[track[row].fxcnt]) {
  10.206 -				case 1: /* Set speed */
  10.207 -					UniEffect(UNI_S3MEFFECTA,inf);
  10.208 -					break;
  10.209 -				case 2: /* Volume slide */
  10.210 -					if(inf) {
  10.211 -						UniWriteByte(UNI_S3MEFFECTD);
  10.212 -						if (inf>=0)
  10.213 -							UniWriteByte((inf&0xf)<<4);
  10.214 -						else
  10.215 -							UniWriteByte((-inf)&0xf);
  10.216 -					}
  10.217 -					break;
  10.218 -				/* effect 3, set channel volume, done in UnpackTrack */
  10.219 -				case 4: /* Porta up/down */
  10.220 -					if(inf) {
  10.221 -						if(inf>0) {
  10.222 -							UniEffect(UNI_S3MEFFECTE,inf);
  10.223 -							fx4memory=UNI_S3MEFFECTE;
  10.224 -						} else {
  10.225 -							UniEffect(UNI_S3MEFFECTF,-inf);
  10.226 -							fx4memory=UNI_S3MEFFECTF;
  10.227 -						}
  10.228 -					} else if(fx4memory)
  10.229 -						UniEffect(fx4memory,0);
  10.230 -					break;
  10.231 -				/* effect 5, "Porta abs", not supported */
  10.232 -				case 6: /* Porta to note */
  10.233 -					UniEffect(UNI_ITEFFECTG,inf);
  10.234 -					break;
  10.235 -				case 7: /* Tremor */
  10.236 -					UniEffect(UNI_S3MEFFECTI,inf);
  10.237 -					break;
  10.238 -				case 8: /* Arpeggio */
  10.239 -					UniPTEffect(0x0,inf);
  10.240 -					break;
  10.241 -				case 9: /* Vibrato */
  10.242 -					UniPTEffect(0x4,inf);
  10.243 -					break;
  10.244 -				case 0xa: /* Porta + Volume slide */
  10.245 -					UniPTEffect(0x3,0);
  10.246 -					if(inf) {
  10.247 -						UniWriteByte(UNI_S3MEFFECTD);
  10.248 -						if (inf>=0)
  10.249 -							UniWriteByte((inf&0xf)<<4);
  10.250 -						else
  10.251 -							UniWriteByte((-inf)&0xf);
  10.252 -					}
  10.253 -					break;
  10.254 -				case 0xb: /* Vibrato + Volume slide */
  10.255 -					UniPTEffect(0x4,0);
  10.256 -					if(inf) {
  10.257 -						UniWriteByte(UNI_S3MEFFECTD);
  10.258 -						if (inf>=0)
  10.259 -							UniWriteByte((inf&0xf)<<4);
  10.260 -						else
  10.261 -							UniWriteByte((-inf)&0xf);
  10.262 -					}
  10.263 -					break;
  10.264 -				case 0xc: /* Pattern break (in hex) */
  10.265 -					UniPTEffect(0xd,inf);
  10.266 -					break;
  10.267 -				case 0xd: /* Pattern jump */
  10.268 -					UniPTEffect(0xb,inf);
  10.269 -					break;
  10.270 -				/* effect 0xe, "Sync", not supported */
  10.271 -				case 0xf: /* Retrig */
  10.272 -					UniEffect(UNI_S3MEFFECTQ,inf&0xf);
  10.273 -					break;
  10.274 -				case 0x10: /* Sample offset */
  10.275 -					UniPTEffect(0x9,inf);
  10.276 -					break;
  10.277 -				case 0x11: /* Fine volume slide */
  10.278 -					if(inf) {
  10.279 -						UniWriteByte(UNI_S3MEFFECTD);
  10.280 -						if (inf>=0)
  10.281 -							UniWriteByte((inf&0xf)<<4|0xf);
  10.282 -						else
  10.283 -							UniWriteByte(0xf0|((-inf)&0xf));
  10.284 -					}
  10.285 -					break;
  10.286 -				case 0x12: /* Fine portamento */
  10.287 -					if(inf) {
  10.288 -						if(inf>0) {
  10.289 -							UniEffect(UNI_S3MEFFECTE,0xf0|(inf&0xf));
  10.290 -							fx4memory=UNI_S3MEFFECTE;
  10.291 -						} else {
  10.292 -							UniEffect(UNI_S3MEFFECTF,0xf0|((-inf)&0xf));
  10.293 -							fx4memory=UNI_S3MEFFECTF;
  10.294 -						}
  10.295 -					} else if(fx4memory)
  10.296 -						UniEffect(fx4memory,0);
  10.297 -					break;
  10.298 -				case 0x13: /* Delay note */
  10.299 -					UniPTEffect(0xe,0xd0|(inf&0xf));
  10.300 -					break;
  10.301 -				case 0x14: /* Note cut */
  10.302 -					UniPTEffect(0xc,0);
  10.303 -					track[row].volume=0;
  10.304 -					break;
  10.305 -				case 0x15: /* Set tempo */
  10.306 -					UniEffect(UNI_S3MEFFECTT,inf);
  10.307 -					break;
  10.308 -				case 0x16: /* Extra fine portamento */
  10.309 -					if(inf) {
  10.310 -						if(inf>0) {
  10.311 -							UniEffect(UNI_S3MEFFECTE,0xe0|((inf>>2)&0xf));
  10.312 -							fx4memory=UNI_S3MEFFECTE;
  10.313 -						} else {
  10.314 -							UniEffect(UNI_S3MEFFECTF,0xe0|(((-inf)>>2)&0xf));
  10.315 -							fx4memory=UNI_S3MEFFECTF;
  10.316 -						}
  10.317 -					} else if(fx4memory)
  10.318 -						UniEffect(fx4memory,0);
  10.319 -					break;
  10.320 -				case 0x17: /* Panning */
  10.321 -					if (inf>64)
  10.322 -						UniEffect(UNI_ITEFFECTS0,0x91); /* surround */
  10.323 -					else
  10.324 -						UniPTEffect(0x8,(inf==64)?255:(inf+64)<<1);
  10.325 -					of.flags |= UF_PANNING;
  10.326 -					break;
  10.327 -			}
  10.328 -			
  10.329 -		}
  10.330 -		if (track[row].volume) UniVolEffect(VOL_VOLUME,track[row].volume-1);
  10.331 -		UniNewline();
  10.332 -	}
  10.333 -	return UniDup();
  10.334 -}
  10.335 -
  10.336 -BOOL AMF_Load(BOOL curious)
  10.337 -{
  10.338 -	int t,u,realtrackcnt,realsmpcnt,defaultpanning;
  10.339 -	AMFSAMPLE s;
  10.340 -	SAMPLE *q;
  10.341 -	UWORD *track_remap;
  10.342 -	ULONG samplepos;
  10.343 -	int channel_remap[16];
  10.344 -
  10.345 -	/* try to read module header  */
  10.346 -	_mm_read_UBYTES(mh->id,3,modreader);
  10.347 -	mh->version     =_mm_read_UBYTE(modreader);
  10.348 -	_mm_read_string(mh->songname,32,modreader);
  10.349 -	mh->numsamples  =_mm_read_UBYTE(modreader);
  10.350 -	mh->numorders   =_mm_read_UBYTE(modreader);
  10.351 -	mh->numtracks   =_mm_read_I_UWORD(modreader);
  10.352 -	mh->numchannels =_mm_read_UBYTE(modreader);
  10.353 -	if((!mh->numchannels)||(mh->numchannels>(mh->version>=12?32:16))) {
  10.354 -		_mm_errno=MMERR_NOT_A_MODULE;
  10.355 -		return 0;
  10.356 -	}
  10.357 -
  10.358 -	if(mh->version>=11) {
  10.359 -		memset(mh->panpos,0,32);
  10.360 -		_mm_read_SBYTES(mh->panpos,(mh->version>=13)?32:16,modreader);
  10.361 -	} else
  10.362 -		_mm_read_UBYTES(channel_remap,16,modreader);
  10.363 -
  10.364 -	if (mh->version>=13) {
  10.365 -		mh->songbpm=_mm_read_UBYTE(modreader);
  10.366 -		if(mh->songbpm<32) {
  10.367 -			_mm_errno=MMERR_NOT_A_MODULE;
  10.368 -			return 0;
  10.369 -		}
  10.370 -		mh->songspd=_mm_read_UBYTE(modreader);
  10.371 -		if(mh->songspd>32) {
  10.372 -			_mm_errno=MMERR_NOT_A_MODULE;
  10.373 -			return 0;
  10.374 -		}
  10.375 -	} else {
  10.376 -		mh->songbpm=125;
  10.377 -		mh->songspd=6;
  10.378 -	}
  10.379 -
  10.380 -	if(_mm_eof(modreader)) {
  10.381 -		_mm_errno = MMERR_LOADING_HEADER;
  10.382 -		return 0;
  10.383 -	}
  10.384 -
  10.385 -	/* set module variables */
  10.386 -	of.initspeed = mh->songspd;
  10.387 -	of.inittempo = mh->songbpm;
  10.388 -	AMF_Version[AMFTEXTLEN-3]='0'+(mh->version/10);
  10.389 -	AMF_Version[AMFTEXTLEN-1]='0'+(mh->version%10);
  10.390 -	of.modtype   = strdup(AMF_Version);
  10.391 -	of.numchn    = mh->numchannels;
  10.392 -	of.numtrk    = mh->numorders*mh->numchannels;
  10.393 -	if (mh->numtracks>of.numtrk)
  10.394 -		of.numtrk=mh->numtracks;
  10.395 -	of.numtrk++;	/* add room for extra, empty track */
  10.396 -	of.songname  = DupStr(mh->songname,32,1);
  10.397 -	of.numpos    = mh->numorders;
  10.398 -	of.numpat    = mh->numorders;
  10.399 -	of.reppos    = 0;
  10.400 -	of.flags    |= UF_S3MSLIDES;
  10.401 -	/* XXX whenever possible, we should try to determine the original format.
  10.402 -	   Here we assume it was S3M-style wrt bpmlimit... */
  10.403 -	of.bpmlimit = 32;
  10.404 -	
  10.405 -	/*
  10.406 -	 * Play with the panning table. Although the AMF format embeds a
  10.407 -	 * panning table, if the module was a MOD or an S3M with default
  10.408 -	 * panning and didn't use any panning commands, don't flag
  10.409 -	 * UF_PANNING, to use our preferred panning table for this case.
  10.410 -	 */
  10.411 -	defaultpanning = 1;
  10.412 -	for (t = 0; t < 32; t++) {
  10.413 -		if (mh->panpos[t] > 64) {
  10.414 -			of.panning[t] = PAN_SURROUND;
  10.415 -			defaultpanning = 0;
  10.416 -		} else
  10.417 -			if (mh->panpos[t] == 64)
  10.418 -				of.panning[t] = PAN_RIGHT;
  10.419 -			else
  10.420 -				of.panning[t] = (mh->panpos[t] + 64) << 1;
  10.421 -	}
  10.422 -	if (defaultpanning) {
  10.423 -		for (t = 0; t < of.numchn; t++)
  10.424 -			if (of.panning[t] == (((t + 1) & 2) ? PAN_RIGHT : PAN_LEFT)) {
  10.425 -				defaultpanning = 0;	/* not MOD canonical panning */
  10.426 -				break;
  10.427 -			}
  10.428 -	}
  10.429 -	if (defaultpanning)
  10.430 -		of.flags |= UF_PANNING;
  10.431 -
  10.432 -	of.numins=of.numsmp=mh->numsamples;
  10.433 -
  10.434 -	if(!AllocPositions(of.numpos)) return 0;
  10.435 -	for(t=0;t<of.numpos;t++)
  10.436 -		of.positions[t]=t;
  10.437 -
  10.438 -	if(!AllocTracks()) return 0;
  10.439 -	if(!AllocPatterns()) return 0;
  10.440 -
  10.441 -	/* read AMF order table */
  10.442 -	for (t=0;t<of.numpat;t++) {
  10.443 -		if (mh->version>=14)
  10.444 -			/* track size */
  10.445 -			of.pattrows[t]=_mm_read_I_UWORD(modreader);
  10.446 -		if (mh->version>=10)
  10.447 -			_mm_read_I_UWORDS(of.patterns+(t*of.numchn),of.numchn,modreader);
  10.448 -		else
  10.449 -			for(u=0;u<of.numchn;u++)
  10.450 -				of.patterns[t*of.numchn+channel_remap[u]]=_mm_read_I_UWORD(modreader);
  10.451 -	}
  10.452 -	if(_mm_eof(modreader)) {
  10.453 -		_mm_errno = MMERR_LOADING_HEADER;
  10.454 -		return 0;
  10.455 -	}
  10.456 -
  10.457 -	/* read sample information */
  10.458 -	if(!AllocSamples()) return 0;
  10.459 -	q=of.samples;
  10.460 -	for(t=0;t<of.numins;t++) {
  10.461 -		/* try to read sample info */
  10.462 -		s.type=_mm_read_UBYTE(modreader);
  10.463 -		_mm_read_string(s.samplename,32,modreader);
  10.464 -		_mm_read_string(s.filename,13,modreader);
  10.465 -		s.offset    =_mm_read_I_ULONG(modreader);
  10.466 -		s.length    =_mm_read_I_ULONG(modreader);
  10.467 -		s.c2spd     =_mm_read_I_UWORD(modreader);
  10.468 -		if(s.c2spd==8368) s.c2spd=8363;
  10.469 -		s.volume    =_mm_read_UBYTE(modreader);
  10.470 -		if(mh->version>=11) {
  10.471 -			s.reppos    =_mm_read_I_ULONG(modreader);
  10.472 -			s.repend    =_mm_read_I_ULONG(modreader);
  10.473 -		} else {
  10.474 -			s.reppos    =_mm_read_I_UWORD(modreader);
  10.475 -			s.repend    =s.length;
  10.476 -		}
  10.477 -
  10.478 -		if(_mm_eof(modreader)) {
  10.479 -			_mm_errno = MMERR_LOADING_SAMPLEINFO; 
  10.480 -			return 0;
  10.481 -		}
  10.482 -
  10.483 -		q->samplename = DupStr(s.samplename,32,1);
  10.484 -		q->speed     = s.c2spd;
  10.485 -		q->volume    = s.volume;
  10.486 -		if (s.type) {
  10.487 -			q->seekpos   = s.offset;
  10.488 -			q->length    = s.length;
  10.489 -			q->loopstart = s.reppos;
  10.490 -			q->loopend   = s.repend;
  10.491 -			if((s.repend-s.reppos)>2) q->flags |= SF_LOOP;
  10.492 -		}
  10.493 -		q++;
  10.494 -	}
  10.495 -
  10.496 -	/* read track table */
  10.497 -	if(!(track_remap=_mm_calloc(mh->numtracks+1,sizeof(UWORD))))
  10.498 -		return 0;
  10.499 -	_mm_read_I_UWORDS(track_remap+1,mh->numtracks,modreader);
  10.500 -	if(_mm_eof(modreader)) {
  10.501 -		free(track_remap);
  10.502 -		_mm_errno=MMERR_LOADING_TRACK;
  10.503 -		return 0;
  10.504 -	}
  10.505 -
  10.506 -	for(realtrackcnt=t=0;t<=mh->numtracks;t++)
  10.507 -		if (realtrackcnt<track_remap[t])
  10.508 -			realtrackcnt=track_remap[t];
  10.509 -	for(t=0;t<of.numpat*of.numchn;t++)
  10.510 -		of.patterns[t]=(of.patterns[t]<=mh->numtracks)?
  10.511 -		               track_remap[of.patterns[t]]-1:realtrackcnt;
  10.512 -
  10.513 -	free(track_remap);
  10.514 -
  10.515 -	/* unpack tracks */
  10.516 -	for(t=0;t<realtrackcnt;t++) {
  10.517 -		if(_mm_eof(modreader)) {
  10.518 -			_mm_errno = MMERR_LOADING_TRACK;
  10.519 -			return 0;
  10.520 -		}
  10.521 -		if (!AMF_UnpackTrack(modreader)) {
  10.522 -			_mm_errno = MMERR_LOADING_TRACK;
  10.523 -			return 0;
  10.524 -		}
  10.525 -		if(!(of.tracks[t]=AMF_ConvertTrack()))
  10.526 -			return 0;
  10.527 -	}
  10.528 -	/* add an extra void track */
  10.529 -	UniReset();
  10.530 -	for(t=0;t<64;t++) UniNewline();
  10.531 -	of.tracks[realtrackcnt++]=UniDup();
  10.532 -	for(t=realtrackcnt;t<of.numtrk;t++) of.tracks[t]=NULL;
  10.533 -
  10.534 -	/* compute sample offsets */
  10.535 -	samplepos=_mm_ftell(modreader);
  10.536 -	for(realsmpcnt=t=0;t<of.numsmp;t++)
  10.537 -		if(realsmpcnt<of.samples[t].seekpos)
  10.538 -			realsmpcnt=of.samples[t].seekpos;
  10.539 -	for(t=1;t<=realsmpcnt;t++) {
  10.540 -		q=of.samples;
  10.541 -		while(q->seekpos!=t) q++;
  10.542 -		q->seekpos=samplepos;
  10.543 -		samplepos+=q->length;
  10.544 -	}
  10.545 -		
  10.546 -	return 1;
  10.547 -}
  10.548 -
  10.549 -CHAR *AMF_LoadTitle(void)
  10.550 -{
  10.551 -	CHAR s[32];
  10.552 -
  10.553 -	_mm_fseek(modreader,4,SEEK_SET);
  10.554 -	if(!_mm_read_UBYTES(s,32,modreader)) return NULL;
  10.555 -
  10.556 -	return(DupStr(s,32,1));
  10.557 -}
  10.558 -
  10.559 -/*========== Loader information */
  10.560 -
  10.561 -MIKMODAPI MLOADER load_amf={
  10.562 -	NULL,
  10.563 -	"AMF",
  10.564 -	"AMF (DSMI Advanced Module Format)",
  10.565 -	AMF_Init,
  10.566 -	AMF_Test,
  10.567 -	AMF_Load,
  10.568 -	AMF_Cleanup,
  10.569 -	AMF_LoadTitle
  10.570 -};
  10.571 -
  10.572 -/* ex:set ts=4: */
    11.1 --- a/mikmod/load_dsm.c	Sat Oct 03 10:53:24 2009 +0000
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,364 +0,0 @@
    11.4 -/*	MikMod sound library
    11.5 -	(c) 1998, 1999, 2000, 2001, 2002 Miodrag Vallat and others - see file
    11.6 -	AUTHORS for complete list.
    11.7 -
    11.8 -	This library is free software; you can redistribute it and/or modify
    11.9 -	it under the terms of the GNU Library General Public License as
   11.10 -	published by the Free Software Foundation; either version 2 of
   11.11 -	the License, or (at your option) any later version.
   11.12 - 
   11.13 -	This program is distributed in the hope that it will be useful,
   11.14 -	but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.15 -	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.16 -	GNU Library General Public License for more details.
   11.17 - 
   11.18 -	You should have received a copy of the GNU Library General Public
   11.19 -	License along with this library; if not, write to the Free Software
   11.20 -	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   11.21 -	02111-1307, USA.
   11.22 -*/
   11.23 -
   11.24 -/*==============================================================================
   11.25 -
   11.26 -  $Id: load_dsm.c,v 1.1.1.1 2004/06/01 12:16:17 raph Exp $
   11.27 -
   11.28 -  DSIK internal format (DSM) module loader
   11.29 -
   11.30 -==============================================================================*/
   11.31 -
   11.32 -#ifdef HAVE_CONFIG_H
   11.33 -#include "config.h"
   11.34 -#endif
   11.35 -
   11.36 -#ifdef HAVE_UNISTD_H
   11.37 -#include <unistd.h>
   11.38 -#endif
   11.39 -
   11.40 -#include <stdio.h>
   11.41 -#ifdef HAVE_MEMORY_H
   11.42 -#include <memory.h>
   11.43 -#endif
   11.44 -#include <string.h>
   11.45 -
   11.46 -#include "mikmod_internals.h"
   11.47 -
   11.48 -#ifdef SUNOS
   11.49 -extern int fprintf(FILE *, const char *, ...);
   11.50 -#endif
   11.51 -
   11.52 -/*========== Module structure */
   11.53 -
   11.54 -#define DSM_MAXCHAN (16)
   11.55 -#define DSM_MAXORDERS (128)
   11.56 -
   11.57 -typedef struct DSMSONG {
   11.58 -	CHAR	songname[28];
   11.59 -	UWORD	version;
   11.60 -	UWORD	flags;
   11.61 -	ULONG	reserved2;
   11.62 -	UWORD	numord;
   11.63 -	UWORD	numsmp;
   11.64 -	UWORD	numpat;
   11.65 -	UWORD	numtrk;
   11.66 -	UBYTE	globalvol;
   11.67 -	UBYTE	mastervol;
   11.68 -	UBYTE	speed;
   11.69 -	UBYTE	bpm;
   11.70 -	UBYTE	panpos[DSM_MAXCHAN];
   11.71 -	UBYTE	orders[DSM_MAXORDERS];
   11.72 -} DSMSONG;
   11.73 -
   11.74 -typedef struct DSMINST {
   11.75 -	CHAR	filename[13];
   11.76 -	UWORD	flags;
   11.77 -	UBYTE	volume;
   11.78 -	ULONG	length;
   11.79 -	ULONG	loopstart;
   11.80 -	ULONG	loopend;
   11.81 -	ULONG	reserved1;
   11.82 -	UWORD	c2spd;
   11.83 -	UWORD	period;
   11.84 -	CHAR	samplename[28];
   11.85 -} DSMINST;
   11.86 -
   11.87 -typedef struct DSMNOTE {
   11.88 -	UBYTE	note,ins,vol,cmd,inf;
   11.89 -} DSMNOTE;
   11.90 -
   11.91 -#define DSM_SURROUND (0xa4)
   11.92 -
   11.93 -/*========== Loader variables */
   11.94 -
   11.95 -static	CHAR* SONGID="SONG";
   11.96 -static	CHAR* INSTID="INST";
   11.97 -static	CHAR* PATTID="PATT";
   11.98 -
   11.99 -static	UBYTE blockid[4];
  11.100 -static	ULONG blockln;
  11.101 -static	ULONG blocklp;
  11.102 -static	DSMSONG* mh=NULL;
  11.103 -static	DSMNOTE* dsmbuf=NULL;
  11.104 -
  11.105 -static	CHAR DSM_Version[]="DSIK DSM-format";
  11.106 -
  11.107 -static	unsigned char DSMSIG[4+4]={'R','I','F','F','D','S','M','F'};
  11.108 -
  11.109 -/*========== Loader code */
  11.110 -
  11.111 -BOOL DSM_Test(void)
  11.112 -{
  11.113 -	UBYTE id[12];
  11.114 -
  11.115 -	if(!_mm_read_UBYTES(id,12,modreader)) return 0;
  11.116 -	if(!memcmp(id,DSMSIG,4) && !memcmp(id+8,DSMSIG+4,4)) return 1;
  11.117 -
  11.118 -	return 0;
  11.119 -}
  11.120 -
  11.121 -BOOL DSM_Init(void)
  11.122 -{
  11.123 -	if(!(dsmbuf=(DSMNOTE *)_mm_malloc(DSM_MAXCHAN*64*sizeof(DSMNOTE)))) return 0;
  11.124 -	if(!(mh=(DSMSONG *)_mm_calloc(1,sizeof(DSMSONG)))) return 0;
  11.125 -	return 1;
  11.126 -}
  11.127 -
  11.128 -void DSM_Cleanup(void)
  11.129 -{
  11.130 -	_mm_free(dsmbuf);
  11.131 -	_mm_free(mh);
  11.132 -}
  11.133 -
  11.134 -static BOOL GetBlockHeader(void)
  11.135 -{
  11.136 -	/* make sure we're at the right position for reading the
  11.137 -	   next riff block, no matter how many bytes read */
  11.138 -	_mm_fseek(modreader, blocklp+blockln, SEEK_SET);
  11.139 -   
  11.140 -	while(1) {
  11.141 -		_mm_read_UBYTES(blockid,4,modreader);
  11.142 -		blockln=_mm_read_I_ULONG(modreader);
  11.143 -		if(_mm_eof(modreader)) {
  11.144 -			_mm_errno = MMERR_LOADING_HEADER;
  11.145 -			return 0;
  11.146 -		}
  11.147 -
  11.148 -		if(memcmp(blockid,SONGID,4) && memcmp(blockid,INSTID,4) &&
  11.149 -		   memcmp(blockid,PATTID,4)) {
  11.150 -#ifdef MIKMOD_DEBUG
  11.151 -				fprintf(stderr,"\rDSM: Skipping unknown block type %4.4s\n",blockid);
  11.152 -#endif
  11.153 -				_mm_fseek(modreader, blockln, SEEK_CUR);
  11.154 -		} else
  11.155 -			break;
  11.156 -	}
  11.157 -
  11.158 -	blocklp = _mm_ftell(modreader);
  11.159 -
  11.160 -	return 1;
  11.161 -}
  11.162 -
  11.163 -static BOOL DSM_ReadPattern(void)
  11.164 -{
  11.165 -	int flag,row=0;
  11.166 -	SWORD length;
  11.167 -	DSMNOTE *n;
  11.168 -
  11.169 -	/* clear pattern data */
  11.170 -	memset(dsmbuf,255,DSM_MAXCHAN*64*sizeof(DSMNOTE));
  11.171 -	length=_mm_read_I_SWORD(modreader);
  11.172 -
  11.173 -	while(row<64) {
  11.174 -		flag=_mm_read_UBYTE(modreader);
  11.175 -		if((_mm_eof(modreader))||(--length<0)) {
  11.176 -			_mm_errno = MMERR_LOADING_PATTERN;
  11.177 -			return 0;
  11.178 -		}
  11.179 -
  11.180 -		if(flag) {
  11.181 -			n=&dsmbuf[((flag&0xf)*64)+row];
  11.182 -			if(flag&0x80) n->note=_mm_read_UBYTE(modreader);
  11.183 -			if(flag&0x40) n->ins=_mm_read_UBYTE(modreader);
  11.184 -			if(flag&0x20) n->vol=_mm_read_UBYTE(modreader);
  11.185 -			if(flag&0x10) {
  11.186 -				n->cmd=_mm_read_UBYTE(modreader);
  11.187 -				n->inf=_mm_read_UBYTE(modreader);
  11.188 -			}
  11.189 -		} else
  11.190 -			row++;
  11.191 -	}
  11.192 -
  11.193 -	return 1;
  11.194 -}
  11.195 -
  11.196 -static UBYTE *DSM_ConvertTrack(DSMNOTE *tr)
  11.197 -{
  11.198 -	int t;
  11.199 -	UBYTE note,ins,vol,cmd,inf;
  11.200 -
  11.201 -	UniReset();
  11.202 -	for(t=0;t<64;t++) {
  11.203 -		note=tr[t].note;
  11.204 -		ins=tr[t].ins;
  11.205 -		vol=tr[t].vol;
  11.206 -		cmd=tr[t].cmd;
  11.207 -		inf=tr[t].inf;
  11.208 -
  11.209 -		if(ins!=0 && ins!=255) UniInstrument(ins-1);
  11.210 -		if(note!=255) UniNote(note-1); /* normal note */
  11.211 -		if(vol<65) UniPTEffect(0xc,vol);
  11.212 -
  11.213 -		if(cmd!=255) {
  11.214 -			if(cmd==0x8) {
  11.215 -				if(inf==DSM_SURROUND)
  11.216 -					UniEffect(UNI_ITEFFECTS0,0x91);
  11.217 -				else
  11.218 -				  if(inf<=0x80) {
  11.219 -					inf=(inf<0x80)?inf<<1:255;
  11.220 -					UniPTEffect(cmd,inf);
  11.221 -				}
  11.222 -			} else
  11.223 -			  if(cmd==0xb) {
  11.224 -				if(inf<=0x7f) UniPTEffect(cmd,inf);
  11.225 -			} else {
  11.226 -				/* Convert pattern jump from Dec to Hex */
  11.227 -				if(cmd == 0xd)
  11.228 -					inf = (((inf&0xf0)>>4)*10)+(inf&0xf);
  11.229 -				UniPTEffect(cmd,inf);
  11.230 -			}
  11.231 -		}
  11.232 -		UniNewline();
  11.233 -	}
  11.234 -	return UniDup();
  11.235 -}
  11.236 -
  11.237 -BOOL DSM_Load(BOOL curious)
  11.238 -{
  11.239 -	int t;
  11.240 -	DSMINST s;
  11.241 -	SAMPLE *q;
  11.242 -	int cursmp=0,curpat=0,track=0;
  11.243 -
  11.244 -	blocklp=0;
  11.245 -	blockln=12;
  11.246 -
  11.247 -	if(!GetBlockHeader()) return 0;
  11.248 -	if(memcmp(blockid,SONGID,4)) {
  11.249 -		_mm_errno = MMERR_LOADING_HEADER;
  11.250 -		return 0;
  11.251 -	}
  11.252 -
  11.253 -	_mm_read_UBYTES(mh->songname,28,modreader);
  11.254 -	mh->version=_mm_read_I_UWORD(modreader);
  11.255 -	mh->flags=_mm_read_I_UWORD(modreader);
  11.256 -	mh->reserved2=_mm_read_I_ULONG(modreader);
  11.257 -	mh->numord=_mm_read_I_UWORD(modreader);
  11.258 -	mh->numsmp=_mm_read_I_UWORD(modreader);
  11.259 -	mh->numpat=_mm_read_I_UWORD(modreader);
  11.260 -	mh->numtrk=_mm_read_I_UWORD(modreader);
  11.261 -	mh->globalvol=_mm_read_UBYTE(modreader);
  11.262 -	mh->mastervol=_mm_read_UBYTE(modreader);
  11.263 -	mh->speed=_mm_read_UBYTE(modreader);
  11.264 -	mh->bpm=_mm_read_UBYTE(modreader);
  11.265 -	_mm_read_UBYTES(mh->panpos,DSM_MAXCHAN,modreader);
  11.266 -	_mm_read_UBYTES(mh->orders,DSM_MAXORDERS,modreader);
  11.267 -
  11.268 -	/* set module variables */
  11.269 -	of.initspeed=mh->speed;
  11.270 -	of.inittempo=mh->bpm;
  11.271 -	of.modtype=strdup(DSM_Version);
  11.272 -	of.numchn=mh->numtrk;
  11.273 -	of.numpat=mh->numpat;
  11.274 -	of.numtrk=of.numchn*of.numpat;
  11.275 -	of.songname=DupStr(mh->songname,28,1); /* make a cstr of songname */
  11.276 -	of.reppos=0;
  11.277 -	of.flags |= UF_PANNING;
  11.278 -	/* XXX whenever possible, we should try to determine the original format.
  11.279 -	   Here we assume it was S3M-style wrt bpmlimit... */
  11.280 -	of.bpmlimit = 32;
  11.281 -
  11.282 -	for(t=0;t<DSM_MAXCHAN;t++)
  11.283 -		of.panning[t]=mh->panpos[t]==DSM_SURROUND?PAN_SURROUND:
  11.284 -		              mh->panpos[t]<0x80?(mh->panpos[t]<<1):255;
  11.285 -
  11.286 -	if(!AllocPositions(mh->numord)) return 0;
  11.287 -	of.numpos=0;
  11.288 -	for(t=0;t<mh->numord;t++) {
  11.289 -		int order=mh->orders[t];
  11.290 -		if(order==255) order=LAST_PATTERN;
  11.291 -		of.positions[of.numpos]=order;
  11.292 -		if(mh->orders[t]<254) of.numpos++;
  11.293 -	}
  11.294 -
  11.295 -	of.numins=of.numsmp=mh->numsmp;
  11.296 -
  11.297 -	if(!AllocSamples()) return 0;
  11.298 -	if(!AllocTracks()) return 0;
  11.299 -	if(!AllocPatterns()) return 0;
  11.300 -
  11.301 -	while(cursmp<of.numins||curpat<of.numpat) {
  11.302 -		if(!GetBlockHeader()) return 0;
  11.303 -		if(!memcmp(blockid,INSTID,4) && cursmp<of.numins) {
  11.304 -			q=&of.samples[cursmp];
  11.305 -
  11.306 -			/* try to read sample info */
  11.307 -			_mm_read_UBYTES(s.filename,13,modreader);
  11.308 -			s.flags=_mm_read_I_UWORD(modreader);
  11.309 -			s.volume=_mm_read_UBYTE(modreader);
  11.310 -			s.length=_mm_read_I_ULONG(modreader);
  11.311 -			s.loopstart=_mm_read_I_ULONG(modreader);
  11.312 -			s.loopend=_mm_read_I_ULONG(modreader);
  11.313 -			s.reserved1=_mm_read_I_ULONG(modreader);
  11.314 -			s.c2spd=_mm_read_I_UWORD(modreader);
  11.315 -			s.period=_mm_read_I_UWORD(modreader);
  11.316 -			_mm_read_UBYTES(s.samplename,28,modreader);
  11.317 -
  11.318 -			q->samplename=DupStr(s.samplename,28,1);
  11.319 -			q->seekpos=_mm_ftell(modreader);
  11.320 -			q->speed=s.c2spd;
  11.321 -			q->length=s.length;
  11.322 -			q->loopstart=s.loopstart;
  11.323 -			q->loopend=s.loopend;
  11.324 -			q->volume=s.volume;
  11.325 -
  11.326 -			if(s.flags&1) q->flags|=SF_LOOP;
  11.327 -			if(s.flags&2) q->flags|=SF_SIGNED;
  11.328 -			/* (s.flags&4) means packed sample,
  11.329 -			   but did they really exist in dsm ?*/
  11.330 -			cursmp++;
  11.331 -		} else
  11.332 -		  if(!memcmp(blockid,PATTID,4) && curpat<of.numpat) {
  11.333 -			DSM_ReadPattern();
  11.334 -			for(t=0;t<of.numchn;t++)
  11.335 -				if(!(of.tracks[track++]=DSM_ConvertTrack(&dsmbuf[t*64]))) return 0;
  11.336 -			curpat++;
  11.337 -		}
  11.338 -	}
  11.339 -
  11.340 -	return 1;
  11.341 -}
  11.342 -
  11.343 -CHAR *DSM_LoadTitle(void)
  11.344 -{
  11.345 -	CHAR s[28];
  11.346 -
  11.347 -	_mm_fseek(modreader,12,SEEK_SET);
  11.348 -	if(!_mm_read_UBYTES(s,28,modreader)) return NULL;
  11.349 -   
  11.350 -	return(DupStr(s,28,1));
  11.351 -}
  11.352 -
  11.353 -/*========== Loader information */
  11.354 -
  11.355 -MIKMODAPI MLOADER load_dsm={
  11.356 -	NULL,
  11.357 -	"DSM",
  11.358 -	"DSM (DSIK internal format)",
  11.359 -	DSM_Init,
  11.360 -	DSM_Test,
  11.361 -	DSM_Load,
  11.362 -	DSM_Cleanup,
  11.363 -	DSM_LoadTitle
  11.364 -};
  11.365 -
  11.366 -
  11.367 -/* ex:set ts=4: */
    12.1 --- a/mikmod/load_far.c	Sat Oct 03 10:53:24 2009 +0000
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,346 +0,0 @@
    12.4 -/*	MikMod sound library
    12.5 -	(c) 1998, 1999, 2000, 2001, 2002 Miodrag Vallat and others - see file
    12.6 -	AUTHORS for complete list.
    12.7 -
    12.8 -	This library is free software; you can redistribute it and/or modify
    12.9 -	it under the terms of the GNU Library General Public License as
   12.10 -	published by the Free Software Foundation; either version 2 of
   12.11 -	the License, or (at your option) any later version.
   12.12 - 
   12.13 -	This program is distributed in the hope that it will be useful,
   12.14 -	but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.15 -	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.16 -	GNU Library General Public License for more details.
   12.17 - 
   12.18 -	You should have received a copy of the GNU Library General Public
   12.19 -	License along with this library; if not, write to the Free Software
   12.20 -	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   12.21 -	02111-1307, USA.
   12.22 -*/
   12.23 -
   12.24 -/*==============================================================================
   12.25 -
   12.26 -  $Id: load_far.c,v 1.1.1.1 2004/06/01 12:16:17 raph Exp $
   12.27 -
   12.28 -  Farandole (FAR) module loader
   12.29 -
   12.30 -==============================================================================*/
   12.31 -
   12.32 -#ifdef HAVE_CONFIG_H
   12.33 -#include "config.h"
   12.34 -#endif
   12.35 -
   12.36 -#ifdef HAVE_UNISTD_H
   12.37 -#include <unistd.h>
   12.38 -#endif
   12.39 -
   12.40 -#include <stdio.h>
   12.41 -#ifdef HAVE_MEMORY_H
   12.42 -#include <memory.h>
   12.43 -#endif
   12.44 -#include <string.h>
   12.45 -
   12.46 -#include "mikmod_internals.h"
   12.47 -
   12.48 -#ifdef SUNOS
   12.49 -extern int fprintf(FILE *, const char *, ...);
   12.50 -#endif
   12.51 -
   12.52 -/*========== Module structure */
   12.53 -
   12.54 -typedef struct FARHEADER1 {
   12.55 -	UBYTE id[4];			/* file magic */
   12.56 -	CHAR  songname[40];		/* songname */
   12.57 -	CHAR  blah[3];			/* 13,10,26 */
   12.58 -	UWORD headerlen;		/* remaining length of header in bytes */
   12.59 -	UBYTE version;
   12.60 -	UBYTE onoff[16];
   12.61 -	UBYTE edit1[9];
   12.62 -	UBYTE speed;
   12.63 -	UBYTE panning[16];
   12.64 -	UBYTE edit2[4];
   12.65 -	UWORD stlen;
   12.66 -} FARHEADER1;
   12.67 -
   12.68 -typedef struct FARHEADER2 {
   12.69 -	UBYTE orders[256];
   12.70 -	UBYTE numpat;
   12.71 -	UBYTE snglen;
   12.72 -	UBYTE loopto;
   12.73 -	UWORD patsiz[256];
   12.74 -} FARHEADER2;
   12.75 -
   12.76 -typedef struct FARSAMPLE {
   12.77 -	CHAR  samplename[32];
   12.78 -	ULONG length;
   12.79 -	UBYTE finetune;
   12.80 -	UBYTE volume;
   12.81 -	ULONG reppos;
   12.82 -	ULONG repend;
   12.83 -	UBYTE type;
   12.84 -	UBYTE loop;
   12.85 -} FARSAMPLE;
   12.86 -
   12.87 -typedef struct FARNOTE {
   12.88 -	UBYTE note,ins,vol,eff;
   12.89 -} FARNOTE;
   12.90 -
   12.91 -/*========== Loader variables */
   12.92 -
   12.93 -static	CHAR FAR_Version[] = "Farandole";
   12.94 -static	FARHEADER1 *mh1 = NULL;
   12.95 -static	FARHEADER2 *mh2 = NULL;
   12.96 -static	FARNOTE *pat = NULL;
   12.97 -
   12.98 -static	unsigned char FARSIG[4+3]={'F','A','R',0xfe,13,10,26};
   12.99 -
  12.100 -/*========== Loader code */
  12.101 -
  12.102 -BOOL FAR_Test(void)
  12.103 -{
  12.104 -	UBYTE id[47];
  12.105 -
  12.106 -	if(!_mm_read_UBYTES(id,47,modreader)) return 0;
  12.107 -	if((memcmp(id,FARSIG,4))||(memcmp(id+44,FARSIG+4,3))) return 0;
  12.108 -	return 1;
  12.109 -}
  12.110 -
  12.111 -BOOL FAR_Init(void)
  12.112 -{
  12.113 -	if(!(mh1 = (FARHEADER1*)_mm_malloc(sizeof(FARHEADER1)))) return 0;
  12.114 -	if(!(mh2 = (FARHEADER2*)_mm_malloc(sizeof(FARHEADER2)))) return 0;
  12.115 -	if(!(pat = (FARNOTE*)_mm_malloc(256*16*4*sizeof(FARNOTE)))) return 0;
  12.116 -
  12.117 -	return 1;
  12.118 -}
  12.119 -
  12.120 -void FAR_Cleanup(void)
  12.121 -{
  12.122 -	_mm_free(mh1);
  12.123 -	_mm_free(mh2);
  12.124 -	_mm_free(pat);
  12.125 -}
  12.126 -
  12.127 -static UBYTE *FAR_ConvertTrack(FARNOTE* n,int rows)
  12.128 -{
  12.129 -	int t,vibdepth=1;
  12.130 -
  12.131 -	UniReset();
  12.132 -	for(t=0;t<rows;t++) {
  12.133 -		if(n->note) {
  12.134 -			UniInstrument(n->ins);
  12.135 -			UniNote(n->note+3*OCTAVE-1);
  12.136 -		}
  12.137 -		if (n->vol&0xf) UniPTEffect(0xc,(n->vol&0xf)<<2);
  12.138 -		if (n->eff)
  12.139 -			switch(n->eff>>4) {
  12.140 -				case 0x3: /* porta to note */
  12.141 -					UniPTEffect(0x3,(n->eff&0xf)<<4);
  12.142 -					break;
  12.143 -				case 0x4: /* retrigger */
  12.144 -					UniPTEffect(0x0e, 0x90 | (n->eff & 0x0f));
  12.145 -					break;
  12.146 -				case 0x5: /* set vibrato depth */
  12.147 -					vibdepth=n->eff&0xf;
  12.148 -					break;
  12.149 -				case 0x6: /* vibrato */
  12.150 -					UniPTEffect(0x4,((n->eff&0xf)<<4)|vibdepth);
  12.151 -					break;
  12.152 -				case 0x7: /* volume slide up */
  12.153 -					UniPTEffect(0xa,(n->eff&0xf)<<4);
  12.154 -					break;
  12.155 -				case 0x8: /* volume slide down */
  12.156 -					UniPTEffect(0xa,n->eff&0xf);
  12.157 -					break;
  12.158 -				case 0xb: /* panning */
  12.159 -					UniPTEffect(0xe,0x80|(n->eff&0xf));
  12.160 -					break;
  12.161 -				case 0xf: /* set speed */
  12.162 -					UniPTEffect(0xf,n->eff&0xf);
  12.163 -					break;
  12.164 -
  12.165 -				/* others not yet implemented */
  12.166 -				default:
  12.167 -#ifdef MIKMOD_DEBUG
  12.168 -					fprintf(stderr,"\rFAR: unsupported effect %02X\n",n->eff);
  12.169 -#endif
  12.170 -					break;
  12.171 -			}
  12.172 -
  12.173 -		UniNewline();
  12.174 -		n+=16;
  12.175 -	}
  12.176 -	return UniDup();
  12.177 -}
  12.178 -
  12.179 -BOOL FAR_Load(BOOL curious)
  12.180 -{
  12.181 -	int t,u,tracks=0;
  12.182 -	SAMPLE *q;
  12.183 -	FARSAMPLE s;
  12.184 -	FARNOTE *crow;
  12.185 -	UBYTE smap[8];
  12.186 -
  12.187 -	/* try to read module header (first part) */
  12.188 -	_mm_read_UBYTES(mh1->id,4,modreader);
  12.189 -	_mm_read_SBYTES(mh1->songname,40,modreader);
  12.190 -	_mm_read_SBYTES(mh1->blah,3,modreader);
  12.191 -	mh1->headerlen = _mm_read_I_UWORD (modreader);
  12.192 -	mh1->version   = _mm_read_UBYTE (modreader);
  12.193 -	_mm_read_UBYTES(mh1->onoff,16,modreader);
  12.194 -	_mm_read_UBYTES(mh1->edit1,9,modreader);
  12.195 -	mh1->speed     = _mm_read_UBYTE(modreader);
  12.196 -	_mm_read_UBYTES(mh1->panning,16,modreader);
  12.197 -	_mm_read_UBYTES(mh1->edit2,4,modreader);
  12.198 -	mh1->stlen     = _mm_read_I_UWORD (modreader);
  12.199 -
  12.200 -	/* init modfile data */
  12.201 -	of.modtype   = strdup(FAR_Version);
  12.202 -	of.songname  = DupStr(mh1->songname,40,1);
  12.203 -	of.numchn    = 16;
  12.204 -	of.initspeed = mh1->speed;
  12.205 -	of.inittempo = 80;
  12.206 -	of.reppos    = 0;
  12.207 -	of.flags    |= UF_PANNING;
  12.208 -	for(t=0;t<16;t++) of.panning[t]=mh1->panning[t]<<4;
  12.209 -
  12.210 -	/* read songtext into comment field */
  12.211 -	if(mh1->stlen)
  12.212 -		if (!ReadLinedComment(mh1->stlen, 66)) return 0;
  12.213 -
  12.214 -	/* try to read module header (second part) */
  12.215 -	_mm_read_UBYTES(mh2->orders,256,modreader);
  12.216 -	mh2->numpat        = _mm_read_UBYTE(modreader);
  12.217 -	mh2->snglen        = _mm_read_UBYTE(modreader);
  12.218 -	mh2->loopto        = _mm_read_UBYTE(modreader);
  12.219 -	_mm_read_I_UWORDS(mh2->patsiz,256,modreader);
  12.220 -
  12.221 -	of.numpos = mh2->snglen;
  12.222 -	if(!AllocPositions(of.numpos)) return 0;
  12.223 -	for(t=0;t<of.numpos;t++) {
  12.224 -		if(mh2->orders[t]==0xff) break;
  12.225 -		of.positions[t] = mh2->orders[t];
  12.226 -	}
  12.227 -
  12.228 -	/* count number of patterns stored in file */
  12.229 -	of.numpat = 0;
  12.230 -	for(t=0;t<256;t++)
  12.231 -		if(mh2->patsiz[t])
  12.232 -			if((t+1)>of.numpat) of.numpat=t+1;
  12.233 -	of.numtrk = of.numpat*of.numchn;
  12.234 -
  12.235 -	/* seek across eventual new data */
  12.236 -	_mm_fseek(modreader,mh1->headerlen-(869+mh1->stlen),SEEK_CUR);
  12.237 -
  12.238 -	/* alloc track and pattern structures */
  12.239 -	if(!AllocTracks()) return 0;
  12.240 -	if(!AllocPatterns()) return 0;
  12.241 -
  12.242 -	for(t=0;t<of.numpat;t++) {
  12.243 -		UBYTE rows=0,tempo;
  12.244 -
  12.245 -		memset(pat,0,256*16*4*sizeof(FARNOTE));
  12.246 -		if(mh2->patsiz[t]) {
  12.247 -			rows  = _mm_read_UBYTE(modreader);
  12.248 -			tempo = _mm_read_UBYTE(modreader);
  12.249 -
  12.250 -			crow = pat;
  12.251 -			/* file often allocates 64 rows even if there are less in pattern */
  12.252 -			if (mh2->patsiz[t]<2+(rows*16*4)) {
  12.253 -				_mm_errno = MMERR_LOADING_PATTERN;
  12.254 -				return 0;
  12.255 -			}
  12.256 -			for(u=(mh2->patsiz[t]-2)/4;u;u--,crow++) {
  12.257 -				crow->note = _mm_read_UBYTE(modreader);
  12.258 -				crow->ins  = _mm_read_UBYTE(modreader);
  12.259 -				crow->vol  = _mm_read_UBYTE(modreader);
  12.260 -				crow->eff  = _mm_read_UBYTE(modreader);
  12.261 -			}
  12.262 -
  12.263 -			if(_mm_eof(modreader)) {
  12.264 -				_mm_errno = MMERR_LOADING_PATTERN;
  12.265 -				return 0;
  12.266 -			}
  12.267 -
  12.268 -			crow=pat;
  12.269 -			of.pattrows[t] = rows;
  12.270 -			for(u=16;u;u--,crow++)
  12.271 -				if(!(of.tracks[tracks++]=FAR_ConvertTrack(crow,rows))) {
  12.272 -					_mm_errno=MMERR_LOADING_PATTERN;
  12.273 -					return 0;
  12.274 -				}
  12.275 -		} else
  12.276 -			tracks+=16;
  12.277 -	}
  12.278 -
  12.279 -	/* read sample map */
  12.280 -	if(!_mm_read_UBYTES(smap,8,modreader)) {
  12.281 -		_mm_errno = MMERR_LOADING_HEADER;
  12.282 -		return 0;
  12.283 -	}
  12.284 -
  12.285 -	/* count number of samples used */
  12.286 -	of.numins = 0;
  12.287 -	for(t=0;t<64;t++)
  12.288 -		if(smap[t>>3]&(1<<(t&7))) of.numins=t+1;
  12.289 -	of.numsmp = of.numins;             
  12.290 -
  12.291 -	/* alloc sample structs */
  12.292 -	if(!AllocSamples()) return 0;
  12.293 -
  12.294 -	q = of.samples;
  12.295 -	for(t=0;t<of.numsmp;t++) {
  12.296 -		q->speed      = 8363;
  12.297 -		q->flags      = SF_SIGNED;
  12.298 -		if(smap[t>>3]&(1<<(t&7))) {
  12.299 -			_mm_read_SBYTES(s.samplename,32,modreader);
  12.300 -			s.length   = _mm_read_I_ULONG(modreader);
  12.301 -			s.finetune = _mm_read_UBYTE(modreader);
  12.302 -			s.volume   = _mm_read_UBYTE(modreader);
  12.303 -			s.reppos   = _mm_read_I_ULONG(modreader);
  12.304 -			s.repend   = _mm_read_I_ULONG(modreader);
  12.305 -			s.type     = _mm_read_UBYTE(modreader);
  12.306 -			s.loop     = _mm_read_UBYTE(modreader);
  12.307 -
  12.308 -			q->samplename = DupStr(s.samplename,32,1);
  12.309 -			q->length     = s.length;
  12.310 -			q->loopstart  = s.reppos;
  12.311 -			q->loopend    = s.repend;
  12.312 -			q->volume     = s.volume<<2;
  12.313 -
  12.314 -			if(s.type&1) q->flags|=SF_16BITS;
  12.315 -			if(s.loop&8) q->flags|=SF_LOOP;
  12.316 -
  12.317 -			q->seekpos    = _mm_ftell(modreader);
  12.318 -			_mm_fseek(modreader,q->length,SEEK_CUR);
  12.319 -		} else 
  12.320 -			q->samplename = DupStr(NULL,0,0);
  12.321 -		q++;
  12.322 -	}
  12.323 -	return 1;
  12.324 -}
  12.325 -
  12.326 -CHAR *FAR_LoadTitle(void)
  12.327 -{
  12.328 -	CHAR s[40];
  12.329 -
  12.330 -	_mm_fseek(modreader,4,SEEK_SET);
  12.331 -	if(!_mm_read_UBYTES(s,40,modreader)) return NULL;
  12.332 -   
  12.333 -	return(DupStr(s,40,1));
  12.334 -}
  12.335 -
  12.336 -/*========== Loader information */
  12.337 -
  12.338 -MIKMODAPI MLOADER load_far={
  12.339 -	NULL,
  12.340 -	"FAR",
  12.341 -	"FAR (Farandole Composer)",
  12.342 -	FAR_Init,
  12.343 -	FAR_Test,
  12.344 -	FAR_Load,
  12.345 -	FAR_Cleanup,
  12.346 -	FAR_LoadTitle
  12.347 -};
  12.348 -
  12.349 -/* ex:set ts=4: */
    13.1 --- a/mikmod/load_gdm.c	Sat Oct 03 10:53:24 2009 +0000
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,558 +0,0 @@
    13.4 -/*	MikMod sound library
    13.5 -	(c) 1998, 1999, 2000, 2001, 2002 Miodrag Vallat and others - see file
    13.6 -	AUTHORS for complete list.
    13.7 -
    13.8 -	This library is free software;you can redistribute it and/or modify
    13.9 -	it under the terms of the GNU Library General Public License as
   13.10 -	published by the Free Software Foundation;either version 2 of
   13.11 -	the License,or (at your option) any later version.
   13.12 -
   13.13 -	This program is distributed in the hope that it will be useful,
   13.14 -	but WITHOUT ANY WARRANTY;without even the implied warranty of
   13.15 -	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13.16 -	GNU Library General Public License for more details.
   13.17 -
   13.18 -	You should have received a copy of the GNU Library General Public
   13.19 -	License along with this library;if not,write to the Free Software
   13.20 -	Foundation,Inc.,59 Temple Place - Suite 330,Boston,MA
   13.21 -	02111-1307,USA.
   13.22 -*/
   13.23 -
   13.24 -/*==============================================================================
   13.25 -
   13.26 -  $Id: load_gdm.c,v 1.1.1.1 2004/06/01 12:16:17 raph Exp $
   13.27 -
   13.28 -  General DigiMusic (GDM) module loader
   13.29 -
   13.30 -==============================================================================*/
   13.31 -
   13.32 -/*
   13.33 -
   13.34 -	Written by Kev Vance<kvance@zeux.org>
   13.35 -	based on the file format description written by 'MenTaLguY'
   13.36 -	                                                        <mental@kludge.org>
   13.37 -
   13.38 -*/
   13.39 -
   13.40 -#ifdef HAVE_CONFIG_H
   13.41 -#include "config.h"
   13.42 -#endif
   13.43 -
   13.44 -#ifdef HAVE_UNISTD_H
   13.45 -#include <unistd.h>
   13.46 -#endif
   13.47 -
   13.48 -#include <stdio.h>
   13.49 -#ifdef HAVE_MEMORY_H
   13.50 -#include <memory.h>
   13.51 -#endif
   13.52 -#include <string.h>
   13.53 -
   13.54 -#include "mikmod_internals.h"
   13.55 -
   13.56 -#ifdef SUNOS
   13.57 -extern int fprintf(FILE *, const char *, ...);
   13.58 -#endif
   13.59 -
   13.60 -typedef struct GDMNOTE {
   13.61 -	UBYTE note;
   13.62 -	UBYTE samp;
   13.63 -	struct {
   13.64 -		UBYTE effect;
   13.65 -		UBYTE param;
   13.66 -	} effect[4];
   13.67 -} GDMNOTE;
   13.68 -
   13.69 -typedef GDMNOTE GDMTRACK[64];
   13.70 -
   13.71 -typedef struct GDMHEADER {
   13.72 -	CHAR  id1[4];
   13.73 -	CHAR  songname[32];
   13.74 -	CHAR  author[32];
   13.75 -	CHAR  eofmarker[3];
   13.76 -	CHAR  id2[4];
   13.77 -
   13.78 -	UBYTE majorver;
   13.79 -	UBYTE minorver;
   13.80 -	UWORD trackerid;
   13.81 -	UBYTE t_majorver;
   13.82 -	UBYTE t_minorver;
   13.83 -	UBYTE pantable[32];
   13.84 -	UBYTE mastervol;
   13.85 -	UBYTE mastertempo;
   13.86 -	UBYTE masterbpm;
   13.87 -	UWORD flags;
   13.88 -
   13.89 -	ULONG orderloc;
   13.90 -	UBYTE ordernum;
   13.91 -	ULONG patternloc;
   13.92 -	UBYTE patternnum;
   13.93 -	ULONG samhead;
   13.94 -	ULONG samdata;
   13.95 -	UBYTE samnum;
   13.96 -	ULONG messageloc;
   13.97 -	ULONG messagelen;
   13.98 -	ULONG scrollyloc;
   13.99 -	UWORD scrollylen;
  13.100 -	ULONG graphicloc;
  13.101 -	UWORD graphiclen;
  13.102 -} GDMHEADER;
  13.103 -
  13.104 -typedef struct GDMSAMPLE {
  13.105 -	CHAR  sampname[32];
  13.106 -	CHAR  filename[13];
  13.107 -	UBYTE ems;
  13.108 -	ULONG length;
  13.109 -	ULONG loopbeg;
  13.110 -	ULONG loopend;
  13.111 -	UBYTE flags;
  13.112 -	UWORD c4spd;
  13.113 -	UBYTE vol;
  13.114 -	UBYTE pan;
  13.115 -} GDMSAMPLE;
  13.116 -
  13.117 -static GDMHEADER *mh=NULL;	/* pointer to GDM header */
  13.118 -static GDMNOTE *gdmbuf=NULL;	/* pointer to a complete GDM pattern */
  13.119 -
  13.120 -CHAR GDM_Version[]="General DigiMusic 1.xx";
  13.121 -
  13.122 -BOOL GDM_Test(void)
  13.123 -{
  13.124 -	/* test for gdm magic numbers */
  13.125 -	UBYTE id[4];
  13.126 -
  13.127 -	_mm_fseek(modreader,0x00,SEEK_SET);
  13.128 -	if (!_mm_read_UBYTES(id,4,modreader))
  13.129 -		return 0;
  13.130 -	if (!memcmp(id,"GDM\xfe",4)) {
  13.131 -		_mm_fseek(modreader,71,SEEK_SET);
  13.132 -		if (!_mm_read_UBYTES(id,4,modreader))
  13.133 -			return 0;
  13.134 -		if (!memcmp(id,"GMFS",4))
  13.135 -			return 1;
  13.136 -	}
  13.137 -	return 0;
  13.138 -}
  13.139 -
  13.140 -BOOL GDM_Init(void)
  13.141 -{
  13.142 -	if (!(gdmbuf=(GDMNOTE*)_mm_malloc(32*64*sizeof(GDMNOTE)))) return 0;
  13.143 -	if (!(mh=(GDMHEADER*)_mm_malloc(sizeof(GDMHEADER)))) return 0;
  13.144 -
  13.145 -	return 1;
  13.146 -}
  13.147 -
  13.148 -void GDM_Cleanup(void)
  13.149 -{
  13.150 -	_mm_free(mh);
  13.151 -	_mm_free(gdmbuf);
  13.152 -}
  13.153 -
  13.154 -BOOL GDM_ReadPattern(void)
  13.155 -{
  13.156 -	int pos,flag,ch,i,maxch;
  13.157 -	GDMNOTE n;
  13.158 -	UWORD length,x=0;
  13.159 -
  13.160 -	/* get pattern length */
  13.161 -	length=_mm_read_I_UWORD(modreader)-2;
  13.162 -
  13.163 -	/* clear pattern data */
  13.164 -	memset(gdmbuf,255,32*64*sizeof(GDMNOTE));
  13.165 -	pos=0;
  13.166 -	maxch=0;
  13.167 -
  13.168 -	while (x<length) {
  13.169 -		memset(&n,255,sizeof(GDMNOTE));
  13.170 -		flag=_mm_read_UBYTE(modreader);
  13.171 -		x++;
  13.172 -
  13.173 -		if (_mm_eof(modreader)) {
  13.174 -			_mm_errno=MMERR_LOADING_PATTERN;
  13.175 -			return 0;
  13.176 -		}
  13.177 -
  13.178 -		ch=flag&31;
  13.179 -		if (ch>maxch) maxch=ch;
  13.180 -		if (!flag) {
  13.181 -			pos++;
  13.182 -			continue;
  13.183 -		}
  13.184 -		if (flag&0x60) {
  13.185 -			if (flag&0x20) {
  13.186 -				/* new note */
  13.187 -				n.note=_mm_read_UBYTE(modreader)&127;
  13.188 -				n.samp=_mm_read_UBYTE(modreader);
  13.189 -				x +=2;
  13.190 -			}
  13.191 -			if (flag&0x40) {
  13.192 -				do {
  13.193 -					/* effect channel set */
  13.194 -					i=_mm_read_UBYTE(modreader);
  13.195 -					n.effect[i>>6].effect=i&31;
  13.196 -					n.effect[i>>6].param=_mm_read_UBYTE(modreader);
  13.197 -					x +=2;
  13.198 -				} while (i&32);
  13.199 -			}
  13.200 -			memcpy(gdmbuf+(64U*ch)+pos,&n,sizeof(GDMNOTE));
  13.201 -		}
  13.202 -	}
  13.203 -	return 1;
  13.204 -}
  13.205 -
  13.206 -UBYTE *GDM_ConvertTrack(GDMNOTE*tr)
  13.207 -{
  13.208 -	int t,i=0;
  13.209 -	UBYTE note,ins,inf;
  13.210 -
  13.211 -	UniReset();
  13.212 -	for (t=0;t<64;t++) {
  13.213 -		note=tr[t].note;
  13.214 -		ins=tr[t].samp;
  13.215 -
  13.216 -		if ((ins)&&(ins!=255))
  13.217 -			UniInstrument(ins-1);
  13.218 -		if (note!=255) {
  13.219 -			UniNote(((note>>4)*OCTAVE)+(note&0xf)-1);
  13.220 -		}
  13.221 -		for (i=0;i<4;i++) {
  13.222 -			inf = tr[t].effect[i].param;
  13.223 -			switch (tr[t].effect[i].effect) {
  13.224 -				case 1:	/* toneslide up */
  13.225 -					UniEffect(UNI_S3MEFFECTF,inf);
  13.226 -					break;
  13.227 -				case 2:	/* toneslide down */
  13.228 -					UniEffect(UNI_S3MEFFECTE,inf);
  13.229 -					break;
  13.230 -				case 3:	/* glissando to note */
  13.231 -					UniEffect(UNI_ITEFFECTG,inf);
  13.232 -					break;
  13.233 -				case 4:	/* vibrato */
  13.234 -					UniEffect(UNI_ITEFFECTH,inf);
  13.235 -					break;
  13.236 -				case 5:	/* portamento+volslide */
  13.237 -					UniEffect(UNI_ITEFFECTG,0);
  13.238 -					UniEffect(UNI_S3MEFFECTD,inf);
  13.239 -					break;
  13.240 -				case 6:	/* vibrato+volslide */
  13.241 -					UniEffect(UNI_ITEFFECTH,0);
  13.242 -					UniEffect(UNI_S3MEFFECTD,inf);
  13.243 -					break;
  13.244 -				case 7:	/* tremolo */
  13.245 -					UniEffect(UNI_S3MEFFECTR,inf);
  13.246 -					break;
  13.247 -				case 8:	/* tremor */
  13.248 -					UniEffect(UNI_S3MEFFECTI,inf);
  13.249 -					break;
  13.250 -				case 9:	/* offset */
  13.251 -					UniPTEffect(0x09,inf);
  13.252 -					break;
  13.253 -				case 0x0a:	/* volslide */
  13.254 -					UniEffect(UNI_S3MEFFECTD,inf);
  13.255 -					break;
  13.256 -				case 0x0b:	/* jump to order */
  13.257 -					UniPTEffect(0x0b,inf);
  13.258 -					break;
  13.259 -				case 0x0c:	/* volume set */
  13.260 -					UniPTEffect(0x0c,inf);
  13.261 -					break;
  13.262 -				case 0x0d:	/* pattern break */
  13.263 -					UniPTEffect(0x0d,inf);
  13.264 -					break;
  13.265 -				case 0x0e:	/* extended */
  13.266 -					switch (inf&0xf0) {
  13.267 -						case 0x10:	/* fine portamento up */
  13.268 -							UniEffect(UNI_S3MEFFECTF, 0x0f|((inf<<4)&0x0f));
  13.269 -							break;
  13.270 -						case 0x20:	/* fine portamento down */
  13.271 -							UniEffect(UNI_S3MEFFECTE, 0xf0|(inf&0x0f));
  13.272 -							break;
  13.273 -						case 0x30:	/* glissando control */
  13.274 -							UniEffect(SS_GLISSANDO, inf&0x0f);
  13.275 -							break;
  13.276 -						case 0x40:	/* vibrato waveform */
  13.277 -							UniEffect(SS_VIBWAVE, inf&0x0f);
  13.278 -							break;
  13.279 -						case 0x50:	/* set c4spd */
  13.280 -							UniEffect(SS_FINETUNE, inf&0x0f);
  13.281 -							break;
  13.282 -						case 0x60:	/* loop fun */
  13.283 -							UniEffect(UNI_ITEFFECTS0, (inf&0x0f)|0xb0);
  13.284 -							break;
  13.285 -						case 0x70:	/* tremolo waveform */
  13.286 -							UniEffect(SS_TREMWAVE, inf&0x0f);
  13.287 -							break;
  13.288 -						case 0x80:	/* extra fine porta up */
  13.289 -							UniEffect(UNI_S3MEFFECTF, 0x0e|((inf<<4)&0x0f));
  13.290 -							break;
  13.291 -						case 0x90:	/* extra fine porta down */
  13.292 -							UniEffect(UNI_S3MEFFECTE, 0xe0|(inf&0x0f));
  13.293 -							break;
  13.294 -						case 0xa0:	/* fine volslide up */
  13.295 -							UniEffect(UNI_S3MEFFECTD, 0x0f|((inf<<4)&0x0f));
  13.296 -							break;
  13.297 -						case 0xb0:	/* fine volslide down */
  13.298 -							UniEffect(UNI_S3MEFFECTE, 0xf0|(inf&0x0f));
  13.299 -							break;
  13.300 -						case 0xc0:	/* note cut */
  13.301 -						case 0xd0:	/* note delay */
  13.302 -						case 0xe0:	/* extend row */
  13.303 -							UniPTEffect(0xe,inf);
  13.304 -							break;
  13.305 -					}
  13.306 -					break;
  13.307 -				case 0x0f:	/* set tempo */
  13.308 -					UniEffect(UNI_S3MEFFECTA,inf);
  13.309 -					break;
  13.310 -				case 0x10:	/* arpeggio */
  13.311 -					UniPTEffect(0x0,inf);
  13.312 -					break;
  13.313 -				case 0x12:	/* retrigger */
  13.314 -					UniEffect(UNI_S3MEFFECTQ,inf);
  13.315 -					break;
  13.316 -				case 0x13:	/* set global volume */
  13.317 -					UniEffect(UNI_XMEFFECTG,inf<<1);
  13.318 -					break;
  13.319 -				case 0x14:	/* fine vibrato */
  13.320 -					UniEffect(UNI_ITEFFECTU,inf);
  13.321 -					break;
  13.322 -				case 0x1e:	/* special */
  13.323 -					switch (inf&0xf0) {
  13.324 -						case 8:	/* set pan position */
  13.325 -							if (inf >=128)
  13.326 -								UniPTEffect(0x08,255);
  13.327 -							else
  13.328 -								UniPTEffect(0x08,inf<<1);
  13.329 -							break;
  13.330 -					}
  13.331 -					break;
  13.332 -				case 0x1f:	/* set bpm */
  13.333 -					if (inf >=0x20)
  13.334 -						UniEffect(UNI_S3MEFFECTT,inf);
  13.335 -					break;
  13.336 -			}
  13.337 -		}
  13.338 -		UniNewline();
  13.339 -	}
  13.340 -	return UniDup();
  13.341 -}
  13.342 -
  13.343 -BOOL GDM_Load(BOOL curious)
  13.344 -{
  13.345 -	int i,x,u,track;
  13.346 -	SAMPLE *q;
  13.347 -	GDMSAMPLE s;
  13.348 -	ULONG position;
  13.349 -
  13.350 -	/* read header */
  13.351 -	_mm_read_string(mh->id1,4,modreader);
  13.352 -	_mm_read_string(mh->songname,32,modreader);
  13.353 -	_mm_read_string(mh->author,32,modreader);
  13.354 -	_mm_read_string(mh->eofmarker,3,modreader);
  13.355 -	_mm_read_string(mh->id2,4,modreader);
  13.356 -
  13.357 -	mh->majorver=_mm_read_UBYTE(modreader);
  13.358 -	mh->minorver=_mm_read_UBYTE(modreader);
  13.359 -	mh->trackerid=_mm_read_I_UWORD(modreader);
  13.360 -	mh->t_majorver=_mm_read_UBYTE(modreader);
  13.361 -	mh->t_minorver=_mm_read_UBYTE(modreader);
  13.362 -	_mm_read_UBYTES(mh->pantable,32,modreader);
  13.363 -	mh->mastervol=_mm_read_UBYTE(modreader);
  13.364 -	mh->mastertempo=_mm_read_UBYTE(modreader);
  13.365 -	mh->masterbpm=_mm_read_UBYTE(modreader);
  13.366 -	mh->flags=_mm_read_I_UWORD(modreader);
  13.367 -
  13.368 -	mh->orderloc=_mm_read_I_ULONG(modreader);
  13.369 -	mh->ordernum=_mm_read_UBYTE(modreader);
  13.370 -	mh->patternloc=_mm_read_I_ULONG(modreader);
  13.371 -	mh->patternnum=_mm_read_UBYTE(modreader);
  13.372 -	mh->samhead=_mm_read_I_ULONG(modreader);
  13.373 -	mh->samdata=_mm_read_I_ULONG(modreader);
  13.374 -	mh->samnum=_mm_read_UBYTE(modreader);
  13.375 -	mh->messageloc=_mm_read_I_ULONG(modreader);
  13.376 -	mh->messagelen=_mm_read_I_ULONG(modreader);
  13.377 -	mh->scrollyloc=_mm_read_I_ULONG(modreader);
  13.378 -	mh->scrollylen=_mm_read_I_UWORD(modreader);
  13.379 -	mh->graphicloc=_mm_read_I_ULONG(modreader);
  13.380 -	mh->graphiclen=_mm_read_I_UWORD(modreader);
  13.381 -
  13.382 -	/* have we ended abruptly? */
  13.383 -	if (_mm_eof(modreader)) {
  13.384 -		_mm_errno=MMERR_LOADING_HEADER;
  13.385 -		return 0;
  13.386 -	}
  13.387 -
  13.388 -	/* any orders? */
  13.389 -	if(mh->ordernum==255) {
  13.390 -		_mm_errno=MMERR_LOADING_PATTERN;
  13.391 -		return 0;
  13.392 -	}
  13.393 -
  13.394 -	/* now we fill */
  13.395 -	of.modtype=strdup(GDM_Version);
  13.396 -	of.modtype[18]=mh->majorver+'0';
  13.397 -	of.modtype[20]=mh->minorver/10+'0';
  13.398 -	of.modtype[21]=mh->minorver%10+'0';
  13.399 -	of.songname=DupStr(mh->songname,32,0);
  13.400 -	of.numpat=mh->patternnum+1;
  13.401 -	of.reppos=0;
  13.402 -	of.numins=of.numsmp=mh->samnum+1;
  13.403 -	of.initspeed=mh->mastertempo;
  13.404 -	of.inittempo=mh->masterbpm;
  13.405 -	of.initvolume=mh->mastervol<<1;
  13.406 -	of.flags|=UF_S3MSLIDES | UF_PANNING;
  13.407 -	/* XXX whenever possible, we should try to determine the original format.
  13.408 -	   Here we assume it was S3M-style wrt bpmlimit... */
  13.409 -	of.bpmlimit = 32;
  13.410 -
  13.411 -	/* read the order data */
  13.412 -	if (!AllocPositions(mh->ordernum+1)) {
  13.413 -		_mm_errno=MMERR_OUT_OF_MEMORY;
  13.414 -		return 0;
  13.415 -	}
  13.416 -
  13.417 -	_mm_fseek(modreader,mh->orderloc,SEEK_SET);
  13.418 -	for (i=0;i<mh->ordernum+1;i++)
  13.419 -		of.positions[i]=_mm_read_UBYTE(modreader);
  13.420 -
  13.421 -	of.numpos=0;
  13.422 -	for (i=0;i<mh->ordernum+1;i++) {
  13.423 -		int order=of.positions[i];
  13.424 -		if(order==255) order=LAST_PATTERN;
  13.425 -		of.positions[of.numpos]=order;
  13.426 -		if (of.positions[i]<254) of.numpos++;
  13.427 -	}
  13.428 -
  13.429 -	/* have we ended abruptly yet? */
  13.430 -	if (_mm_eof(modreader)) {
  13.431 -		_mm_errno=MMERR_LOADING_HEADER;
  13.432 -		return 0;
  13.433 -	}
  13.434 -
  13.435 -	/* time to load the samples */
  13.436 -	if (!AllocSamples()) {
  13.437 -		_mm_errno=MMERR_OUT_OF_MEMORY;
  13.438 -		return 0;
  13.439 -	}
  13.440 -
  13.441 -	q=of.samples;
  13.442 -	position=mh->samdata;
  13.443 -
  13.444 -	/* seek to instrument position */
  13.445 -	_mm_fseek(modreader,mh->samhead,SEEK_SET);
  13.446 -
  13.447 -	for (i=0;i<of.numins;i++) {
  13.448 -		/* load sample info */
  13.449 -		_mm_read_UBYTES(s.sampname,32,modreader);
  13.450 -		_mm_read_UBYTES(s.filename,12,modreader);
  13.451 -		s.ems=_mm_read_UBYTE(modreader);
  13.452 -		s.length=_mm_read_I_ULONG(modreader);
  13.453 -		s.loopbeg=_mm_read_I_ULONG(modreader);
  13.454 -		s.loopend=_mm_read_I_ULONG(modreader);
  13.455 -		s.flags=_mm_read_UBYTE(modreader);
  13.456 -		s.c4spd=_mm_read_I_UWORD(modreader);
  13.457 -		s.vol=_mm_read_UBYTE(modreader);
  13.458 -		s.pan=_mm_read_UBYTE(modreader);
  13.459 -
  13.460 -		if (_mm_eof(modreader)) {
  13.461 -			_mm_errno=MMERR_LOADING_SAMPLEINFO;
  13.462 -			return 0;
  13.463 -		}
  13.464 -		q->samplename=DupStr(s.sampname,32,0);
  13.465 -		q->speed=s.c4spd;
  13.466 -		q->length=s.length;
  13.467 -		q->loopstart=s.loopbeg;
  13.468 -		q->loopend=s.loopend;
  13.469 -		q->volume=s.vol;
  13.470 -		q->panning=s.pan;
  13.471 -		q->seekpos=position;
  13.472 -
  13.473 -		position +=s.length;
  13.474 -
  13.475 -		if (s.flags&1)
  13.476 -			q->flags |=SF_LOOP;
  13.477 -		if (s.flags&2)
  13.478 -			q->flags |=SF_16BITS;
  13.479 -		if (s.flags&16)
  13.480 -			q->flags |=SF_STEREO;
  13.481 -		q++;
  13.482 -	}
  13.483 -
  13.484 -	/* set the panning */
  13.485 -	for (i=x=0;i<32;i++) {
  13.486 -		of.panning[i]=mh->pantable[i];
  13.487 -		if (!of.panning[i])
  13.488 -			of.panning[i]=PAN_LEFT;
  13.489 -		else if (of.panning[i]==8)
  13.490 -			of.panning[i]=PAN_CENTER;
  13.491 -		else if (of.panning[i]==15)
  13.492 -			of.panning[i]=PAN_RIGHT;
  13.493 -		else if (of.panning[i]==16)
  13.494 -			of.panning[i]=PAN_SURROUND;
  13.495 -		else if (of.panning[i]==255)
  13.496 -			of.panning[i]=128;
  13.497 -		else
  13.498 -			of.panning[i]<<=3;
  13.499 -		if (mh->pantable[i]!=255)
  13.500 -			x=i;
  13.501 -	}
  13.502 -
  13.503 -	of.numchn=x+1;
  13.504 -	if (of.numchn<1)
  13.505 -		of.numchn=1;	/* for broken counts */
  13.506 -
  13.507 -	/* load the pattern info */
  13.508 -	of.numtrk=of.numpat*of.numchn;
  13.509 -
  13.510 -	/* jump to patterns */
  13.511 -	_mm_fseek(modreader,mh->patternloc,SEEK_SET);
  13.512 -
  13.513 -	if (!AllocTracks()) {
  13.514 -		_mm_errno=MMERR_OUT_OF_MEMORY;
  13.515 -		return 0;
  13.516 -	}
  13.517 -
  13.518 -	if (!AllocPatterns()) {
  13.519 -		_mm_errno=MMERR_OUT_OF_MEMORY;
  13.520 -		return 0;
  13.521 -	}
  13.522 -
  13.523 -	for (i=track=0;i<of.numpat;i++) {
  13.524 -		if (!GDM_ReadPattern()) {
  13.525 -			_mm_errno=MMERR_LOADING_PATTERN;
  13.526 -			return 0;
  13.527 -		}
  13.528 -		for (u=0;u<of.numchn;u++,track++) {
  13.529 -			of.tracks[track]=GDM_ConvertTrack(&gdmbuf[u<<6]);
  13.530 -			if (!of.tracks[track]) {
  13.531 -				_mm_errno=MMERR_LOADING_TRACK;
  13.532 -				return 0;
  13.533 -			}
  13.534 -		}
  13.535 -	}
  13.536 -	return 1;
  13.537 -}
  13.538 -
  13.539 -CHAR *GDM_LoadTitle(void)
  13.540 -{
  13.541 -	CHAR s[32];
  13.542 -
  13.543 -	_mm_fseek(modreader,4,SEEK_SET);
  13.544 -	if (!_mm_read_UBYTES(s,32,modreader)) return NULL;
  13.545 -
  13.546 -	return DupStr(s,28,0);
  13.547 -}
  13.548 -
  13.549 -MIKMODAPI MLOADER load_gdm=
  13.550 -{
  13.551 -	NULL,
  13.552 -	"GDM",
  13.553 -	"GDM (General DigiMusic)",
  13.554 -	GDM_Init,
  13.555 -	GDM_Test,
  13.556 -	GDM_Load,
  13.557 -	GDM_Cleanup,
  13.558 -	GDM_LoadTitle
  13.559 -};
  13.560 -
  13.561 -/* ex:set ts=4: */
    14.1 --- a/mikmod/load_imf.c	Sat Oct 03 10:53:24 2009 +0000
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,738 +0,0 @@
    14.4 -/*	MikMod sound library
    14.5 -	(c) 1998, 1999, 2000, 2001, 2002 Miodrag Vallat and others - see file
    14.6 -	AUTHORS for complete list.
    14.7 -
    14.8 -	This library is free software; you can redistribute it and/or modify
    14.9 -	it under the terms of the GNU Library General Public License as
   14.10 -	published by the Free Software Foundation; either version 2 of
   14.11 -	the License, or (at your option) any later version.
   14.12 -
   14.13 -	This program is distributed in the hope that it will be useful,
   14.14 -	but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.15 -	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14.16 -	GNU Library General Public License for more details.
   14.17 -
   14.18 -	You should have received a copy of the GNU Library General Public
   14.19 -	License along with this library; if not, write to the Free Software
   14.20 -	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   14.21 -	02111-1307, USA.
   14.22 -*/
   14.23 -
   14.24 -/*==============================================================================
   14.25 -
   14.26 -  $Id: load_imf.c,v 1.1.1.1 2004/06/01 12:16:17 raph Exp $
   14.27 -
   14.28 -  Imago Orpheus (IMF) module loader
   14.29 -
   14.30 -==============================================================================*/
   14.31 -
   14.32 -#ifdef HAVE_CONFIG_H
   14.33 -#include "config.h"
   14.34 -#endif
   14.35 -
   14.36 -#ifdef HAVE_UNISTD_H
   14.37 -#include <unistd.h>
   14.38 -#endif
   14.39 -
   14.40 -#include <stdio.h>
   14.41 -#ifdef HAVE_MEMORY_H
   14.42 -#include <memory.h>
   14.43 -#endif
   14.44 -#include <string.h>
   14.45 -
   14.46 -#include "mikmod_internals.h"
   14.47 -
   14.48 -#ifdef SUNOS
   14.49 -extern int fprintf(FILE *, const char *, ...);
   14.50 -#endif
   14.51 -
   14.52 -/*========== Module structure */
   14.53 -
   14.54 -/* module header */
   14.55 -typedef struct IMFHEADER {
   14.56 -	CHAR  songname[32];
   14.57 -	UWORD ordnum;
   14.58 -	UWORD patnum;
   14.59 -	UWORD insnum;
   14.60 -	UWORD flags;
   14.61 -	UBYTE initspeed;
   14.62 -	UBYTE inittempo;
   14.63 -	UBYTE mastervol;
   14.64 -	UBYTE mastermult;
   14.65 -	UBYTE orders[256];
   14.66 -} IMFHEADER;
   14.67 -
   14.68 -/* channel settings */
   14.69 -typedef struct IMFCHANNEL {
   14.70 -	CHAR  name[12];
   14.71 -	UBYTE chorus;
   14.72 -	UBYTE reverb;
   14.73 -	UBYTE pan;
   14.74 -	UBYTE status;
   14.75 -} IMFCHANNEL;
   14.76 -
   14.77 -/* instrument header */
   14.78 -#define IMFNOTECNT (10*OCTAVE)
   14.79 -#define IMFENVCNT (16*2)
   14.80 -typedef struct IMFINSTHEADER {
   14.81 -	CHAR  name[32];
   14.82 -	UBYTE what[IMFNOTECNT];
   14.83 -	UWORD volenv[IMFENVCNT];
   14.84 -	UWORD panenv[IMFENVCNT];
   14.85 -	UWORD pitenv[IMFENVCNT];
   14.86 -	UBYTE volpts;
   14.87 -	UBYTE volsus;
   14.88 -	UBYTE volbeg;
   14.89 -	UBYTE volend;
   14.90 -	UBYTE volflg;
   14.91 -	UBYTE panpts;
   14.92 -	UBYTE pansus;
   14.93 -	UBYTE panbeg;
   14.94 -	UBYTE panend;
   14.95 -	UBYTE panflg;
   14.96 -	UBYTE pitpts;
   14.97 -	UBYTE pitsus;
   14.98 -	UBYTE pitbeg;
   14.99 -	UBYTE pitend;
  14.100 -	UBYTE pitflg;
  14.101 -	UWORD volfade;
  14.102 -	UWORD numsmp;
  14.103 -	ULONG signature;
  14.104 -} IMFINSTHEADER;
  14.105 -
  14.106 -/* sample header */
  14.107 -typedef struct IMFWAVHEADER {
  14.108 -	CHAR  samplename[13];
  14.109 -	ULONG length;
  14.110 -	ULONG loopstart;
  14.111 -	ULONG loopend;
  14.112 -	ULONG samplerate;
  14.113 -	UBYTE volume;
  14.114 -	UBYTE pan;
  14.115 -	UBYTE flags;
  14.116 -} IMFWAVHEADER;
  14.117 -
  14.118 -typedef struct IMFNOTE {
  14.119 -	UBYTE note,ins,eff1,dat1,eff2,dat2;
  14.120 -} IMFNOTE;
  14.121 -
  14.122 -/*========== Loader variables */
  14.123 -
  14.124 -static	CHAR IMF_Version[]="Imago Orpheus";
  14.125 -
  14.126 -static	IMFNOTE *imfpat=NULL;
  14.127 -static	IMFHEADER *mh=NULL;
  14.128 -
  14.129 -/*========== Loader code */
  14.130 -
  14.131 -BOOL IMF_Test(void)
  14.132 -{
  14.133 -	UBYTE id[4];
  14.134 -
  14.135 -	_mm_fseek(modreader,0x3c,SEEK_SET);
  14.136 -	if(!_mm_read_UBYTES(id,4,modreader)) return 0;
  14.137 -	if(!memcmp(id,"IM10",4)) return 1;
  14.138 -	return 0;
  14.139 -}
  14.140 -
  14.141 -BOOL IMF_Init(void)
  14.142 -{
  14.143 -	if(!(imfpat=(IMFNOTE*)_mm_malloc(32*256*sizeof(IMFNOTE)))) return 0;
  14.144 -	if(!(mh=(IMFHEADER*)_mm_malloc(sizeof(IMFHEADER)))) return 0;
  14.145 -
  14.146 -	return 1;
  14.147 -}
  14.148 -
  14.149 -void IMF_Cleanup(void)
  14.150 -{
  14.151 -	FreeLinear();
  14.152 -
  14.153 -	_mm_free(imfpat);
  14.154 -	_mm_free(mh);
  14.155 -}
  14.156 -
  14.157 -static BOOL IMF_ReadPattern(SLONG size,UWORD rows)
  14.158 -{
  14.159 -	int row=0,flag,ch;
  14.160 -	IMFNOTE *n,dummy;
  14.161 -
  14.162 -	/* clear pattern data */
  14.163 -	memset(imfpat,255,32*256*sizeof(IMFNOTE));
  14.164 -
  14.165 -	while((size>0)&&(row<rows)) {
  14.166 -		flag=_mm_read_UBYTE(modreader);size--;
  14.167 -
  14.168 -		if(_mm_eof(modreader)) {
  14.169 -			_mm_errno=MMERR_LOADING_PATTERN;
  14.170 -			return 0;
  14.171 -		}
  14.172 -
  14.173 -		if(flag) {
  14.174 -			ch=remap[flag&31];
  14.175 -
  14.176 -			if(ch!=-1)
  14.177 -				n=&imfpat[256*ch+row];
  14.178 -			else
  14.179 -				n=&dummy;
  14.180 -
  14.181 -			if(flag&32) {
  14.182 -				n->note=_mm_read_UBYTE(modreader);
  14.183 -				if(n->note>=0xa0) n->note=0xa0; /* note off */
  14.184 -				n->ins =_mm_read_UBYTE(modreader);
  14.185 -				size-=2;
  14.186 -			}
  14.187 -			if(flag&64) {
  14.188 -				size-=2;
  14.189 -				n->eff2=_mm_read_UBYTE(modreader);
  14.190 -				n->dat2=_mm_read_UBYTE(modreader);
  14.191 -			}
  14.192 -			if(flag&128) {
  14.193 -				n->eff1=_mm_read_UBYTE(modreader);
  14.194 -				n->dat1=_mm_read_UBYTE(modreader);
  14.195 -				size-=2;
  14.196 -			}
  14.197 -		} else row++;
  14.198 -	}
  14.199 -	if((size)||(row!=rows)) {
  14.200 -		_mm_errno=MMERR_LOADING_PATTERN;
  14.201 -		return 0;
  14.202 -	}
  14.203 -	return 1;
  14.204 -}
  14.205 -
  14.206 -static void IMF_ProcessCmd(UBYTE eff,UBYTE inf)
  14.207 -{
  14.208 -	if((eff)&&(eff!=255))
  14.209 -		switch (eff) {
  14.210 -			case 0x01:	/* set tempo */
  14.211 -				UniEffect(UNI_S3MEFFECTA,inf);
  14.212 -				break;
  14.213 -			case 0x02:	/* set BPM */
  14.214 -				if(inf>=0x20) UniEffect(UNI_S3MEFFECTT,inf);
  14.215 -				break;
  14.216 -			case 0x03:	/* tone portamento */
  14.217 -				UniEffect(UNI_ITEFFECTG,inf);
  14.218 -				break;
  14.219 -			case 0x04:	/* porta + volslide */
  14.220 -				UniEffect(UNI_ITEFFECTG,inf);
  14.221 -				UniEffect(UNI_S3MEFFECTD,0);
  14.222 -				break;
  14.223 -			case 0x05:	/* vibrato */
  14.224 -				UniEffect(UNI_XMEFFECT4,inf);
  14.225 -				break;
  14.226 -			case 0x06:	/* vibrato + volslide */
  14.227 -				UniEffect(UNI_XMEFFECT6,inf);
  14.228 -				break;
  14.229 -			case 0x07:	/* fine vibrato */
  14.230 -				UniEffect(UNI_ITEFFECTU,inf);
  14.231 -				break;
  14.232 -			case 0x08:	/* tremolo */
  14.233 -				UniEffect(UNI_S3MEFFECTR,inf);
  14.234 -				break;
  14.235 -			case 0x09:	/* arpeggio */
  14.236 -				UniPTEffect(0x0,inf);
  14.237 -				break;
  14.238 -			case 0x0a:	/* panning */
  14.239 -				UniPTEffect(0x8,(inf>=128)?255:(inf<<1));
  14.240 -				break;
  14.241 -			case 0x0b:	/* pan slide */
  14.242 -				UniEffect(UNI_XMEFFECTP,inf);
  14.243 -				break;
  14.244 -			case 0x0c:	/* set channel volume */
  14.245 -				if(inf<=64) UniPTEffect(0xc,inf);
  14.246 -				break;
  14.247 -			case 0x0d:	/* volume slide */
  14.248 -				UniEffect(UNI_S3MEFFECTD,inf);
  14.249 -				break;
  14.250 -			case 0x0e:	/* fine volume slide */
  14.251 -				if(inf) {
  14.252 -					if(inf>>4)
  14.253 -						UniEffect(UNI_S3MEFFECTD,0x0f|inf);
  14.254 -					else
  14.255 -						UniEffect(UNI_S3MEFFECTD,0xf0|inf);
  14.256 -				} else
  14.257 -					UniEffect(UNI_S3MEFFECTD,0);
  14.258 -				break;
  14.259 -			case 0x0f:	/* set finetune */
  14.260 -				UniPTEffect(0xe,0x50|(inf>>4));
  14.261 -				break;
  14.262 -#ifdef MIKMOD_DEBUG
  14.263 -			case 0x10:	/* note slide up */
  14.264 -			case 0x11:	/* not slide down */
  14.265 -				fprintf(stderr,"\rIMF effect 0x10/0x11 (note slide)"
  14.266 -				               " not implemented (eff=%2X inf=%2X)\n",eff,inf);
  14.267 -				break;
  14.268 -#endif
  14.269 -			case 0x12:	/* slide up */
  14.270 -				UniEffect(UNI_S3MEFFECTF,inf);
  14.271 -				break;
  14.272 -			case 0x13:	/* slide down */
  14.273 -				UniEffect(UNI_S3MEFFECTE,inf);
  14.274 -				break;
  14.275 -			case 0x14:	/* fine slide up */
  14.276 -				if (inf) {
  14.277 -					if (inf<0x40)
  14.278 -						UniEffect(UNI_S3MEFFECTF,0xe0|(inf>>2));
  14.279 -					else
  14.280 -						UniEffect(UNI_S3MEFFECTF,0xf0|(inf>>4));
  14.281 -				} else
  14.282 -					UniEffect(UNI_S3MEFFECTF,0);
  14.283 -				break;
  14.284 -			case 0x15:	/* fine slide down */
  14.285 -				if (inf) {
  14.286 -					if (inf<0x40)
  14.287 -						UniEffect(UNI_S3MEFFECTE,0xe0|(inf>>2));
  14.288 -					else
  14.289 -						UniEffect(UNI_S3MEFFECTE,0xf0|(inf>>4));
  14.290 -				} else
  14.291 -					UniEffect(UNI_S3MEFFECTE,0);
  14.292 -				break;
  14.293 -			/* 0x16 set filter cutoff (awe32) */
  14.294 -			/* 0x17 filter side + resonance (awe32) */
  14.295 -			case 0x18:	/* sample offset */
  14.296 -				UniPTEffect(0x9,inf);
  14.297 -				break;
  14.298 -#ifdef MIKMOD_DEBUG
  14.299 -			case 0x19:	/* set fine sample offset */
  14.300 -				fprintf(stderr,"\rIMF effect 0x19 (fine sample offset)"
  14.301 -				               " not implemented (inf=%2X)\n",inf);
  14.302 -				break;
  14.303 -#endif
  14.304 -			case 0x1a:	/* keyoff */
  14.305 -				UniWriteByte(UNI_KEYOFF);
  14.306 -				break;
  14.307 -			case 0x1b:	/* retrig */
  14.308 -				UniEffect(UNI_S3MEFFECTQ,inf);
  14.309 -				break;
  14.310 -			case 0x1c:	/* tremor */
  14.311 -				UniEffect(UNI_S3MEFFECTI,inf);
  14.312 -				break;
  14.313 -			case 0x1d:	/* position jump */
  14.314 -				UniPTEffect(0xb,inf);
  14.315 -				break;
  14.316 -			case 0x1e:	/* pattern break */
  14.317 -				UniPTEffect(0xd,(inf>>4)*10+(inf&0xf));
  14.318 -				break;
  14.319 -			case 0x1f:	/* set master volume */
  14.320 -				if(inf<=64) UniEffect(UNI_XMEFFECTG,inf<<1);
  14.321 -				break;
  14.322 -			case 0x20:	/* master volume slide */
  14.323 -				UniEffect(UNI_XMEFFECTH,inf);
  14.324 -				break;
  14.325 -			case 0x21:	/* extended effects */
  14.326 -				switch(inf>>4) {
  14.327 -					case 0x1:	/* set filter */
  14.328 -					case 0x5:	/* vibrato waveform */
  14.329 -					case 0x8:	/* tremolo waveform */
  14.330 -						UniPTEffect(0xe,inf-0x10);
  14.331 -						break;
  14.332 -					case 0xa:	/* pattern loop */
  14.333 -						UniPTEffect(0xe,0x60|(inf&0xf));
  14.334 -						break;
  14.335 -					case 0xb:	/* pattern delay */
  14.336 -						UniPTEffect(0xe,0xe0|(inf&0xf));
  14.337 -						break;
  14.338 -					case 0x3:	/* glissando */
  14.339 -					case 0xc:	/* note cut */
  14.340 -					case 0xd:	/* note delay */
  14.341 -					case 0xf:	/* invert loop */
  14.342 -						UniPTEffect(0xe,inf);
  14.343 -						break;
  14.344 -					case 0xe:	/* ignore envelope */
  14.345 -						UniEffect(UNI_ITEFFECTS0, 0x77);    /* vol */
  14.346 -						UniEffect(UNI_ITEFFECTS0, 0x79);    /* pan */
  14.347 -						UniEffect(UNI_ITEFFECTS0, 0x7b);    /* pit */
  14.348 -						break;
  14.349 -				}
  14.350 -				break;
  14.351 -			/* 0x22 chorus (awe32) */
  14.352 -			/* 0x23 reverb (awe32) */
  14.353 -		}
  14.354 -}
  14.355 -
  14.356 -static UBYTE* IMF_ConvertTrack(IMFNOTE* tr,UWORD rows)
  14.357 -{
  14.358 -	int t;
  14.359 -	UBYTE note,ins;
  14.360 -
  14.361 -	UniReset();
  14.362 -	for(t=0;t<rows;t++) {
  14.363 -		note=tr[t].note;
  14.364 -		ins=tr[t].ins;
  14.365 -
  14.366 -		if((ins)&&(ins!=255)) UniInstrument(ins-1);
  14.367 -		if(note!=255) {
  14.368 -			if(note==0xa0) {
  14.369 -				UniPTEffect(0xc,0); /* Note cut */
  14.370 -				if(tr[t].eff1==0x0c) tr[t].eff1=0;
  14.371 -				if(tr[t].eff2==0x0c) tr[t].eff2=0;
  14.372 -			} else
  14.373 -				UniNote(((note>>4)*OCTAVE)+(note&0xf));
  14.374 -		}
  14.375 -
  14.376 -		IMF_ProcessCmd(tr[t].eff1,tr[t].dat1);
  14.377 -		IMF_ProcessCmd(tr[t].eff2,tr[t].dat2);
  14.378 -		UniNewline();
  14.379 -	}
  14.380 -	return UniDup();
  14.381 -}
  14.382 -
  14.383 -BOOL IMF_Load(BOOL curious)
  14.384 -{
  14.385 -#define IMF_SMPINCR 64
  14.386 -	int t,u,track=0,oldnumsmp;
  14.387 -	IMFCHANNEL channels[32];
  14.388 -	INSTRUMENT *d;
  14.389 -	SAMPLE *q;
  14.390 -	IMFWAVHEADER *wh=NULL,*s=NULL;
  14.391 -	ULONG *nextwav=NULL;
  14.392 -	UWORD wavcnt=0;
  14.393 -	UBYTE id[4];
  14.394 -
  14.395 -	/* try to read the module header */
  14.396 -	_mm_read_string(mh->songname,32,modreader);
  14.397 -	mh->ordnum=_mm_read_I_UWORD(modreader);
  14.398 -	mh->patnum=_mm_read_I_UWORD(modreader);
  14.399 -	mh->insnum=_mm_read_I_UWORD(modreader);
  14.400 -	mh->flags =_mm_read_I_UWORD(modreader);
  14.401 -	_mm_fseek(modreader,8,SEEK_CUR);
  14.402 -	mh->initspeed =_mm_read_UBYTE(modreader);
  14.403 -	mh->inittempo =_mm_read_UBYTE(modreader);
  14.404 -	mh->mastervol =_mm_read_UBYTE(modreader);
  14.405 -	mh->mastermult=_mm_read_UBYTE(modreader);
  14.406 -	_mm_fseek(modreader,64,SEEK_SET);
  14.407 -
  14.408 -	if(_mm_eof(modreader)) {
  14.409 -		_mm_errno = MMERR_LOADING_HEADER;
  14.410 -		return 0;
  14.411 -	}
  14.412 -
  14.413 -	/* set module variables */
  14.414 -	of.songname=DupStr(mh->songname,31,1);
  14.415 -	of.modtype=strdup(IMF_Version);
  14.416 -	of.numpat=mh->patnum;
  14.417 -	of.numins=mh->insnum;
  14.418 -	of.reppos=0;
  14.419 -	of.initspeed=mh->initspeed;
  14.420 -	of.inittempo=mh->inittempo;
  14.421 -	of.initvolume=mh->mastervol<<1;
  14.422 -	of.flags |= UF_INST | UF_ARPMEM | UF_PANNING;
  14.423 -	if(mh->flags&1) of.flags |= UF_LINEAR;
  14.424 -	of.bpmlimit=32;
  14.425 -
  14.426 -	/* read channel information */
  14.427 -	of.numchn=0;
  14.428 -	memset(remap,-1,32*sizeof(UBYTE));
  14.429 -	for(t=0;t<32;t++) {
  14.430 -		_mm_read_string(channels[t].name,12,modreader);
  14.431 -		channels[t].chorus=_mm_read_UBYTE(modreader);
  14.432 -		channels[t].reverb=_mm_read_UBYTE(modreader);
  14.433 -		channels[t].pan   =_mm_read_UBYTE(modreader);
  14.434 -		channels[t].status=_mm_read_UBYTE(modreader);
  14.435 -	}
  14.436 -	/* bug in Imago Orpheus ? If only channel 1 is enabled, in fact we have to
  14.437 -	   enable 16 channels */
  14.438 -	if(!channels[0].status) {
  14.439 -		for(t=1;t<16;t++) if(channels[t].status!=1) break;
  14.440 -		if(t==16) for(t=1;t<16;t++) channels[t].status=0;
  14.441 -	}
  14.442 -	for(t=0;t<32;t++) {
  14.443 -		if(channels[t].status!=2)
  14.444 -			remap[t]=of.numchn++;
  14.445 -		else
  14.446 -			remap[t]=-1;
  14.447 -	}
  14.448 -	for(t=0;t<32;t++)
  14.449 -		if(remap[t]!=-1) {
  14.450 -			of.panning[remap[t]]=channels[t].pan;
  14.451 -			of.chanvol[remap[t]]=channels[t].status?0:64;
  14.452 -		}
  14.453 -
  14.454 -	if(_mm_eof(modreader)) {
  14.455 -		_mm_errno = MMERR_LOADING_HEADER;
  14.456 -		return 0;
  14.457 -	}
  14.458 -
  14.459 -	/* read order list */
  14.460 -	_mm_read_UBYTES(mh->orders,256,modreader);
  14.461 -	if(_mm_eof(modreader)) {
  14.462 -		_mm_errno = MMERR_LOADING_HEADER;
  14.463 -		return 0;
  14.464 -	}
  14.465 -
  14.466 -	of.numpos=0;
  14.467 -	for(t=0;t<mh->ordnum;t++)
  14.468 -		if(mh->orders[t]!=0xff) of.numpos++;
  14.469 -	if(!AllocPositions(of.numpos)) return 0;
  14.470 -	for(t=u=0;t<mh->ordnum;t++)
  14.471 -		if(mh->orders[t]!=0xff) of.positions[u++]=mh->orders[t];
  14.472 -
  14.473 -	/* load pattern info */
  14.474 -	of.numtrk=of.numpat*of.numchn;
  14.475 -	if(!AllocTracks()) return 0;
  14.476 -	if(!AllocPatterns()) return 0;
  14.477 -
  14.478 -	for(t=0;t<of.numpat;t++) {
  14.479 -		SLONG size;
  14.480 -		UWORD rows;
  14.481 -
  14.482 -		size=(SLONG)_mm_read_I_UWORD(modreader);
  14.483 -		rows=_mm_read_I_UWORD(modreader);
  14.484 -		if((rows>256)||(size<4)) {
  14.485 -			_mm_errno=MMERR_LOADING_PATTERN;
  14.486 -			return 0;
  14.487 -		}
  14.488 -
  14.489 -		of.pattrows[t]=rows;
  14.490 -		if(!IMF_ReadPattern(size-4,rows)) return 0;
  14.491 -		for(u=0;u<of.numchn;u++)
  14.492 -			if(!(of.tracks[track++]=IMF_ConvertTrack(&imfpat[u*256],rows)))
  14.493 -				return 0;
  14.494 -	}
  14.495 -
  14.496 -	/* load instruments */
  14.497 -	if(!AllocInstruments()) return 0;
  14.498 -	d=of.instruments;
  14.499 -
  14.500 -	for(oldnumsmp=t=0;t<of.numins;t++) {
  14.501 -		IMFINSTHEADER ih;
  14.502 -
  14.503 -		memset(d->samplenumber,0xff,INSTNOTES*sizeof(UWORD));
  14.504 -
  14.505 -		/* read instrument header */
  14.506 -		_mm_read_string(ih.name,32,modreader);
  14.507 -		d->insname=DupStr(ih.name,31,1);
  14.508 -		_mm_read_UBYTES(ih.what,IMFNOTECNT,modreader);
  14.509 -		_mm_fseek(modreader,8,SEEK_CUR);
  14.510 -		_mm_read_I_UWORDS(ih.volenv,IMFENVCNT,modreader);
  14.511 -		_mm_read_I_UWORDS(ih.panenv,IMFENVCNT,modreader);
  14.512 -		_mm_read_I_UWORDS(ih.pitenv,IMFENVCNT,modreader);
  14.513 -
  14.514 -#if defined __STDC__ || defined _MSC_VER
  14.515 -#define IMF_FinishLoadingEnvelope(name)					\
  14.516 -		ih. name##pts=_mm_read_UBYTE(modreader);		\
  14.517 -		ih. name##sus=_mm_read_UBYTE(modreader);		\
  14.518 -		ih. name##beg=_mm_read_UBYTE(modreader);		\
  14.519 -		ih. name##end=_mm_read_UBYTE(modreader);		\
  14.520 -		ih. name##flg=_mm_read_UBYTE(modreader);		\
  14.521 -		_mm_read_UBYTE(modreader);						\
  14.522 -		_mm_read_UBYTE(modreader);						\
  14.523 -		_mm_read_UBYTE(modreader)
  14.524 -#else
  14.525 -#define IMF_FinishLoadingEnvelope(name)				\
  14.526 -		ih. name/**/pts=_mm_read_UBYTE(modreader);	\
  14.527 -		ih. name/**/sus=_mm_read_UBYTE(modreader);	\
  14.528 -		ih. name/**/beg=_mm_read_UBYTE(modreader);	\
  14.529 -		ih. name/**/end=_mm_read_UBYTE(modreader);	\
  14.530 -		ih. name/**/flg=_mm_read_UBYTE(modreader);	\
  14.531 -		_mm_read_UBYTE(modreader);					\
  14.532 -		_mm_read_UBYTE(modreader);					\
  14.533 -		_mm_read_UBYTE(modreader)
  14.534 -#endif
  14.535 -
  14.536 -		IMF_FinishLoadingEnvelope(vol);
  14.537 -		IMF_FinishLoadingEnvelope(pan);
  14.538 -		IMF_FinishLoadingEnvelope(pit);
  14.539 -
  14.540 -		ih.volfade=_mm_read_I_UWORD(modreader);
  14.541 -		ih.numsmp =_mm_read_I_UWORD(modreader);
  14.542 -
  14.543 -		_mm_read_UBYTES(id,4,modreader);
  14.544 -		/* Looks like Imago Orpheus forgets the signature for empty
  14.545 -		   instruments following a multi-sample instrument... */
  14.546 -		if(memcmp(id,"II10",4) && 
  14.547 -		   (oldnumsmp && memcmp(id,"\x0\x0\x0\x0",4))) {
  14.548 -			if(nextwav) free(nextwav);
  14.549 -			if(wh) free(wh);
  14.550 -			_mm_errno=MMERR_LOADING_SAMPLEINFO;
  14.551 -			return 0;
  14.552 -		}
  14.553 -		oldnumsmp=ih.numsmp;
  14.554 -
  14.555 -		if((ih.numsmp>16)||(ih.volpts>IMFENVCNT/2)||(ih.panpts>IMFENVCNT/2)||
  14.556 -		   (ih.pitpts>IMFENVCNT/2)||(_mm_eof(modreader))) {
  14.557 -			if(nextwav) free(nextwav);
  14.558 -			if(wh) free(wh);
  14.559 -			_mm_errno=MMERR_LOADING_SAMPLEINFO;
  14.560 -			return 0;
  14.561 -		}
  14.562 -
  14.563 -		for(u=0;u<IMFNOTECNT;u++)
  14.564 -			d->samplenumber[u]=ih.what[u]>ih.numsmp?0xffff:ih.what[u]+of.numsmp;
  14.565 -		d->volfade=ih.volfade;
  14.566 -
  14.567 -#if defined __STDC__ || defined _MSC_VER
  14.568 -#define IMF_ProcessEnvelope(name) 									\
  14.569 -		for (u = 0; u < (IMFENVCNT >> 1); u++) {					\
  14.570 -			d-> name##env[u].pos = ih. name##env[u << 1];			\
  14.571 -			d-> name##env[u].val = ih. name##env[(u << 1)+ 1];		\
  14.572 -		}															\
  14.573 -		if (ih. name##flg&1) d-> name##flg|=EF_ON;					\
  14.574 -		if (ih. name##flg&2) d-> name##flg|=EF_SUSTAIN;				\
  14.575 -		if (ih. name##flg&4) d-> name##flg|=EF_LOOP;				\
  14.576 -		d-> name##susbeg=d-> name##susend=ih. name##sus;			\
  14.577 -		d-> name##beg=ih. name##beg;								\
  14.578 -		d-> name##end=ih. name##end;								\
  14.579 -		d-> name##pts=ih. name##pts;								\
  14.580 -																	\
  14.581 -		if ((d-> name##flg&EF_ON)&&(d-> name##pts<2))				\
  14.582 -			d-> name##flg&=~EF_ON
  14.583 -#else
  14.584 -#define IMF_ProcessEnvelope(name) 									\
  14.585 -		for (u = 0; u < (IMFENVCNT >> 1); u++) {					\
  14.586 -			d-> name/**/env[u].pos = ih. name/**/env[u << 1];		\
  14.587 -			d-> name/**/env[u].val = ih. name/**/env[(u << 1)+ 1];	\
  14.588 -		}															\
  14.589 -		if (ih. name/**/flg&1) d-> name/**/flg|=EF_ON;				\
  14.590 -		if (ih. name/**/flg&2) d-> name/**/flg|=EF_SUSTAIN;			\
  14.591 -		if (ih. name/**/flg&4) d-> name/**/flg|=EF_LOOP;			\
  14.592 -		d-> name/**/susbeg=d-> name/**/susend=ih. name/**/sus;		\
  14.593 -		d-> name/**/beg=ih. name/**/beg;							\
  14.594 -		d-> name/**/end=ih. name/**/end;							\
  14.595 -		d-> name/**/pts=ih. name/**/pts;							\
  14.596 -																	\
  14.597 -		if ((d-> name/**/flg&EF_ON)&&(d-> name/**/pts<2))			\
  14.598 -			d-> name/**/flg&=~EF_ON
  14.599 -#endif
  14.600 -
  14.601 -		IMF_ProcessEnvelope(vol);
  14.602 -		IMF_ProcessEnvelope(pan);
  14.603 -		IMF_ProcessEnvelope(pit);
  14.604 -#undef IMF_ProcessEnvelope
  14.605 -
  14.606 -		if(ih.pitflg&1) {
  14.607 -			d->pitflg&=~EF_ON;
  14.608 -#ifdef MIKMOD_DEBUG
  14.609 -			fprintf(stderr, "\rFilter envelopes not supported yet\n");
  14.610 -#endif
  14.611 -		}
  14.612 -
  14.613 -		/* gather sample information */
  14.614 -		for(u=0;u<ih.numsmp;u++,s++) {
  14.615 -			/* allocate more room for sample information if necessary */
  14.616 -			if(of.numsmp+u==wavcnt) {
  14.617 -				wavcnt+=IMF_SMPINCR;
  14.618 -				if(!(nextwav=realloc(nextwav,wavcnt*sizeof(ULONG)))) {
  14.619 -					if(wh) free(wh);
  14.620 -					_mm_errno=MMERR_OUT_OF_MEMORY;
  14.621 -					return 0;
  14.622 -				}
  14.623 -				if(!(wh=realloc(wh,wavcnt*sizeof(IMFWAVHEADER)))) {
  14.624 -					free(nextwav);
  14.625 -					_mm_errno=MMERR_OUT_OF_MEMORY;
  14.626 -					return 0;
  14.627 -				}
  14.628 -				s=wh+(wavcnt-IMF_SMPINCR);
  14.629 -			}
  14.630 -
  14.631 -			_mm_read_string(s->samplename,13,modreader);
  14.632 -			_mm_read_UBYTE(modreader);_mm_read_UBYTE(modreader);_mm_read_UBYTE(modreader);
  14.633 -			s->length    =_mm_read_I_ULONG(modreader);
  14.634 -			s->loopstart =_mm_read_I_ULONG(modreader);
  14.635 -			s->loopend   =_mm_read_I_ULONG(modreader);
  14.636 -			s->samplerate=_mm_read_I_ULONG(modreader);
  14.637 -			s->volume    =_mm_read_UBYTE(modreader)&0x7f;
  14.638 -			s->pan       =_mm_read_UBYTE(modreader);
  14.639 -			_mm_fseek(modreader,14,SEEK_CUR);
  14.640 -			s->flags     =_mm_read_UBYTE(modreader);
  14.641 -			_mm_fseek(modreader,11,SEEK_CUR);
  14.642 -			_mm_read_UBYTES(id,4,modreader);
  14.643 -			if(((memcmp(id,"IS10",4))&&(memcmp(id,"IW10",4)))||
  14.644 -			   (_mm_eof(modreader))) {
  14.645 -				free(nextwav);free(wh);
  14.646 -				_mm_errno=MMERR_LOADING_SAMPLEINFO;
  14.647 -				return 0;
  14.648 -			}
  14.649 -			nextwav[of.numsmp+u]=_mm_ftell(modreader);
  14.650 -			_mm_fseek(modreader,s->length,SEEK_CUR);
  14.651 -		}
  14.652 -
  14.653 -		of.numsmp+=ih.numsmp;
  14.654 -		d++;
  14.655 -	}
  14.656 -
  14.657 -	/* sanity check */
  14.658 -	if(!of.numsmp) {
  14.659 -		if(nextwav) free(nextwav);
  14.660 -		if(wh) free(wh);
  14.661 -		_mm_errno=MMERR_LOADING_SAMPLEINFO;
  14.662 -		return 0;
  14.663 -	}
  14.664 -
  14.665 -	/* load samples */
  14.666 -	if(!AllocSamples()) {
  14.667 -		free(nextwav);free(wh);
  14.668 -		return 0;
  14.669 -	}
  14.670 -	if(!AllocLinear()) {
  14.671 -		free(nextwav);free(wh);
  14.672 -		return 0;
  14.673 -	}
  14.674 -	q=of.samples;
  14.675 -	s=wh;
  14.676 -	for(u=0;u<of.numsmp;u++,s++,q++) {
  14.677 -		q->samplename=DupStr(s->samplename,12,1);
  14.678 -		q->length   =s->length;
  14.679 -		q->loopstart=s->loopstart;
  14.680 -		q->loopend  =s->loopend;
  14.681 -		q->volume   =s->volume;
  14.682 -		q->speed    =s->samplerate;
  14.683 -		if(of.flags&UF_LINEAR)
  14.684 -			q->speed=speed_to_finetune(s->samplerate<<1,u);
  14.685 -		q->panning  =s->pan;
  14.686 -		q->seekpos  =nextwav[u];
  14.687 -
  14.688 -		q->flags|=SF_SIGNED;
  14.689 -		if(s->flags&0x1) q->flags|=SF_LOOP;
  14.690 -		if(s->flags&0x2) q->flags|=SF_BIDI;
  14.691 -		if(s->flags&0x8) q->flags|=SF_OWNPAN;
  14.692 -		if(s->flags&0x4) {
  14.693 -			q->flags|=SF_16BITS;
  14.694 -			q->length   >>=1;
  14.695 -			q->loopstart>>=1;
  14.696 -			q->loopend  >>=1;
  14.697 -		}
  14.698 -	}
  14.699 -
  14.700 -	d=of.instruments;
  14.701 -	s=wh;
  14.702 -	for(u=0;u<of.numins;u++,d++) {
  14.703 -		for(t=0;t<IMFNOTECNT;t++) {
  14.704 -			if(d->samplenumber[t]>=of.numsmp)
  14.705 -				d->samplenote[t]=255;
  14.706 -			else if (of.flags&UF_LINEAR) {
  14.707 -				int note=(int)d->samplenote[u]+noteindex[d->samplenumber[u]];
  14.708 -				d->samplenote[u]=(note<0)?0:(note>255?255:note);
  14.709 -			} else
  14.710 -				d->samplenote[t]=t;
  14.711 -		}
  14.712 -	}
  14.713 -
  14.714 -	free(wh);free(nextwav);
  14.715 -	return 1;
  14.716 -}
  14.717 -
  14.718 -CHAR *IMF_LoadTitle(void)
  14.719 -{
  14.720 -	CHAR s[31];
  14.721 -
  14.722 -	_mm_fseek(modreader,0,SEEK_SET);
  14.723 -	if(!_mm_read_UBYTES(s,31,modreader)) return NULL;
  14.724 -
  14.725 -	return(DupStr(s,31,1));
  14.726 -}
  14.727 -
  14.728 -/*========== Loader information */
  14.729 -
  14.730 -MIKMODAPI MLOADER load_imf={
  14.731 -	NULL,
  14.732 -	"IMF",
  14.733 -	"IMF (Imago Orpheus)",
  14.734 -	IMF_Init,
  14.735 -	IMF_Test,
  14.736 -	IMF_Load,
  14.737 -	IMF_Cleanup,
  14.738 -	IMF_LoadTitle
  14.739 -};
  14.740 -
  14.741 -/* ex:set ts=4: */
    15.1 --- a/mikmod/load_it.c	Sat Oct 03 10:53:24 2009 +0000
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,1008 +0,0 @@
    15.4 -/*	MikMod sound library
    15.5 -	(c) 1998, 1999, 2000, 2001, 2002 Miodrag Vallat and others - see file
    15.6 -	AUTHORS for complete list.
    15.7 -
    15.8 -	This library is free software; you can redistribute it and/or modify
    15.9 -	it under the terms of the GNU Library General Public License as
   15.10 -	published by the Free Software Foundation; either version 2 of
   15.11 -	the License, or (at your option) any later version.
   15.12 - 
   15.13 -	This program is distributed in the hope that it will be useful,
   15.14 -	but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.15 -	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15.16 -	GNU Library General Public License for more details.
   15.17 - 
   15.18 -	You should have received a copy of the GNU Library General Public
   15.19 -	License along with this library; if not, write to the Free Software
   15.20 -	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   15.21 -	02111-1307, USA.
   15.22 -*/
   15.23 -
   15.24 -/*==============================================================================
   15.25 -
   15.26 -  $Id$
   15.27 -
   15.28 -  Impulse tracker (IT) module loader
   15.29 -
   15.30 -==============================================================================*/
   15.31 -
   15.32 -#ifdef HAVE_CONFIG_H
   15.33 -#include "config.h"
   15.34 -#endif
   15.35 -
   15.36 -#ifdef HAVE_UNISTD_H
   15.37 -#include <unistd.h>
   15.38 -#endif
   15.39 -
   15.40 -#include <ctype.h>
   15.41 -#include <stdio.h>
   15.42 -#ifdef HAVE_MEMORY_H
   15.43 -#include <memory.h>
   15.44 -#endif
   15.45 -#include <string.h>
   15.46 -
   15.47 -#include "mikmod_internals.h"
   15.48 -
   15.49 -#ifdef SUNOS
   15.50 -extern int fprintf(FILE *, const char *, ...);
   15.51 -extern int toupper(int);
   15.52 -#endif
   15.53 -
   15.54 -/*========== Module structure */
   15.55 -
   15.56 -/* header */
   15.57 -typedef struct ITHEADER {
   15.58 -	CHAR	songname[26];
   15.59 -	UBYTE	blank01[2];
   15.60 -	UWORD	ordnum;
   15.61 -	UWORD	insnum;
   15.62 -	UWORD	smpnum;
   15.63 -	UWORD	patnum;
   15.64 -	UWORD	cwt;		/* Created with tracker (y.xx = 0x0yxx) */
   15.65 -	UWORD	cmwt;		/* Compatible with tracker ver > than val. */
   15.66 -	UWORD	flags;
   15.67 -	UWORD	special;	/* bit 0 set = song message attached */
   15.68 -	UBYTE	globvol;
   15.69 -	UBYTE	mixvol;		/* mixing volume [ignored] */
   15.70 -	UBYTE	initspeed;
   15.71 -	UBYTE	inittempo;
   15.72 -	UBYTE	pansep;		/* panning separation between channels */
   15.73 -	UBYTE	zerobyte;       
   15.74 -	UWORD	msglength;
   15.75 -	ULONG	msgoffset;
   15.76 -	UBYTE	blank02[4];
   15.77 -	UBYTE	pantable[64];
   15.78 -	UBYTE	voltable[64];
   15.79 -} ITHEADER;
   15.80 -
   15.81 -/* sample information */
   15.82 -typedef struct ITSAMPLE {
   15.83 -	CHAR	filename[12];
   15.84 -	UBYTE	zerobyte;
   15.85 -	UBYTE	globvol;
   15.86 -	UBYTE	flag;
   15.87 -	UBYTE	volume;
   15.88 -	UBYTE	panning;
   15.89 -	CHAR	sampname[28];
   15.90 -	UWORD	convert;	/* sample conversion flag */
   15.91 -	ULONG	length;
   15.92 -	ULONG	loopbeg;
   15.93 -	ULONG	loopend;
   15.94 -	ULONG	c5spd;
   15.95 -	ULONG	susbegin;
   15.96 -	ULONG	susend;
   15.97 -	ULONG	sampoffset;
   15.98 -	UBYTE	vibspeed;
   15.99 -	UBYTE	vibdepth;
  15.100 -	UBYTE	vibrate;
  15.101 -	UBYTE	vibwave;	/* 0=sine, 1=rampdown, 2=square, 3=random (speed ignored) */
  15.102 -} ITSAMPLE;
  15.103 -
  15.104 -/* instrument information */
  15.105 -
  15.106 -#define ITENVCNT 25
  15.107 -#define ITNOTECNT 120
  15.108 -typedef struct ITINSTHEADER {
  15.109 -	ULONG	size;			/* (dword) Instrument size */
  15.110 -	CHAR	filename[12];	/* (char) Instrument filename */
  15.111 -	UBYTE	zerobyte;		/* (byte) Instrument type (always 0) */
  15.112 -	UBYTE	volflg;
  15.113 -	UBYTE	volpts;   
  15.114 -	UBYTE	volbeg;			/* (byte) Volume loop start (node) */
  15.115 -	UBYTE	volend;			/* (byte) Volume loop end (node) */
  15.116 -	UBYTE	volsusbeg;		/* (byte) Volume sustain begin (node) */
  15.117 -	UBYTE	volsusend;		/* (byte) Volume Sustain end (node) */
  15.118 -	UBYTE	panflg;
  15.119 -	UBYTE	panpts;  
  15.120 -	UBYTE	panbeg;			/* (byte) channel loop start (node) */
  15.121 -	UBYTE	panend;			/* (byte) channel loop end (node) */
  15.122 -	UBYTE	pansusbeg;		/* (byte) channel sustain begin (node) */
  15.123 -	UBYTE	pansusend;		/* (byte) channel Sustain end (node) */
  15.124 -	UBYTE	pitflg;
  15.125 -	UBYTE	pitpts;   
  15.126 -	UBYTE	pitbeg;			/* (byte) pitch loop start (node) */
  15.127 -	UBYTE	pitend;			/* (byte) pitch loop end (node) */
  15.128 -	UBYTE	pitsusbeg;		/* (byte) pitch sustain begin (node) */
  15.129 -	UBYTE	pitsusend;		/* (byte) pitch Sustain end (node) */
  15.130 -	UWORD	blank;
  15.131 -	UBYTE	globvol;
  15.132 -	UBYTE	chanpan;
  15.133 -	UWORD	fadeout;		/* Envelope end / NNA volume fadeout */
  15.134 -	UBYTE	dnc;			/* Duplicate note check */
  15.135 -	UBYTE	dca;			/* Duplicate check action */
  15.136 -	UBYTE	dct;			/* Duplicate check type */
  15.137 -	UBYTE	nna;			/* New Note Action [0,1,2,3] */
  15.138 -	UWORD	trkvers;		/* tracker version used to save [files only] */
  15.139 -	UBYTE	ppsep;			/* Pitch-pan Separation */
  15.140 -	UBYTE	ppcenter;		/* Pitch-pan Center */
  15.141 -	UBYTE	rvolvar;		/* random volume varations */
  15.142 -	UBYTE	rpanvar;		/* random panning varations */
  15.143 -	UWORD	numsmp;			/* Number of samples in instrument [files only] */
  15.144 -	CHAR	name[26];		/* Instrument name */
  15.145 -	UBYTE	blank01[6];
  15.146 -	UWORD	samptable[ITNOTECNT];/* sample for each note [note / samp pairs] */
  15.147 -	UBYTE	volenv[200];	     /* volume envelope (IT 1.x stuff) */
  15.148 -	UBYTE	oldvoltick[ITENVCNT];/* volume tick position (IT 1.x stuff) */
  15.149 -	UBYTE	volnode[ITENVCNT];   /* amplitude of volume nodes */
  15.150 -	UWORD	voltick[ITENVCNT];   /* tick value of volume nodes */
  15.151 -	SBYTE	pannode[ITENVCNT];   /* panenv - node points */
  15.152 -	UWORD	pantick[ITENVCNT];   /* tick value of panning nodes */
  15.153 -	SBYTE	pitnode[ITENVCNT];   /* pitchenv - node points */
  15.154 -	UWORD	pittick[ITENVCNT];   /* tick value of pitch nodes */
  15.155 -} ITINSTHEADER;                       
  15.156 -
  15.157 -/* unpacked note */
  15.158 -
  15.159 -typedef struct ITNOTE {
  15.160 -	UBYTE note,ins,volpan,cmd,inf;
  15.161 -} ITNOTE;
  15.162 -
  15.163 -/*========== Loader data */
  15.164 -
  15.165 -static ULONG *paraptr=NULL;	/* parapointer array (see IT docs) */
  15.166 -static ITHEADER *mh=NULL;
  15.167 -static ITNOTE *itpat=NULL;	/* allocate to space for one full pattern */
  15.168 -static UBYTE *mask=NULL;	/* arrays allocated to 64 elements and used for */
  15.169 -static ITNOTE *last=NULL;	/* uncompressing IT's pattern information */
  15.170 -static int numtrk=0;
  15.171 -static unsigned int old_effect;		/* if set, use S3M old-effects stuffs */
  15.172 -   
  15.173 -static CHAR* IT_Version[]={
  15.174 -	"ImpulseTracker  .  ",
  15.175 -	"Compressed ImpulseTracker  .  ",
  15.176 -	"ImpulseTracker 2.14p3",
  15.177 -	"Compressed ImpulseTracker 2.14p3",
  15.178 -	"ImpulseTracker 2.14p4",
  15.179 -	"Compressed ImpulseTracker 2.14p4",
  15.180 -};
  15.181 -
  15.182 -/* table for porta-to-note command within volume/panning column */
  15.183 -static UBYTE portatable[10]= {0,1,4,8,16,32,64,96,128,255};
  15.184 -
  15.185 -/*========== Loader code */
  15.186 -
  15.187 -BOOL IT_Test(void)
  15.188 -{
  15.189 -	UBYTE id[4];
  15.190 -
  15.191 -	if(!_mm_read_UBYTES(id,4,modreader)) return 0;
  15.192 -	if(!memcmp(id,"IMPM",4)) return 1;
  15.193 -	return 0;
  15.194 -}
  15.195 -
  15.196 -BOOL IT_Init(void)
  15.197 -{
  15.198 -	if(!(mh=(ITHEADER*)_mm_malloc(sizeof(ITHEADER)))) return 0;
  15.199 -	if(!(poslookup=(UBYTE*)_mm_malloc(256*sizeof(UBYTE)))) return 0;
  15.200 -	if(!(itpat=(ITNOTE*)_mm_malloc(200*64*sizeof(ITNOTE)))) return 0;
  15.201 -	if(!(mask=(UBYTE*)_mm_malloc(64*sizeof(UBYTE)))) return 0;
  15.202 -	if(!(last=(ITNOTE*)_mm_malloc(64*sizeof(ITNOTE)))) return 0;
  15.203 -
  15.204 -	return 1;
  15.205 -}
  15.206 -
  15.207 -void IT_Cleanup(void)
  15.208 -{
  15.209 -	FreeLinear();
  15.210 -
  15.211 -	_mm_free(mh);
  15.212 -	_mm_free(poslookup);
  15.213 -	_mm_free(itpat);
  15.214 -	_mm_free(mask);
  15.215 -	_mm_free(last);
  15.216 -	_mm_free(paraptr);
  15.217 -	_mm_free(origpositions);
  15.218 -}
  15.219 -
  15.220 -/* Because so many IT files have 64 channels as the set number used, but really
  15.221 -   only use far less (usually from 8 to 24 still), I had to make this function,
  15.222 -   which determines the number of channels that are actually USED by a pattern.
  15.223 - 
  15.224 -   NOTE: You must first seek to the file location of the pattern before calling
  15.225 -         this procedure.
  15.226 -
  15.227 -   Returns 1 on error
  15.228 -*/
  15.229 -static BOOL IT_GetNumChannels(UWORD patrows)
  15.230 -{
  15.231 -	int row=0,flag,ch;
  15.232 -
  15.233 -	do {
  15.234 -		if((flag=_mm_read_UBYTE(modreader))==EOF) {
  15.235 -			_mm_errno=MMERR_LOADING_PATTERN;
  15.236 -			return 1;
  15.237 -		}
  15.238 -		if(!flag)
  15.239 -			row++;
  15.240 -		else {
  15.241 -			ch=(flag-1)&63;
  15.242 -			remap[ch]=0;
  15.243 -			if(flag & 128) mask[ch]=_mm_read_UBYTE(modreader);
  15.244 -			if(mask[ch]&1)   _mm_read_UBYTE(modreader);
  15.245 -			if(mask[ch]&2)   _mm_read_UBYTE(modreader);
  15.246 -			if(mask[ch]&4)   _mm_read_UBYTE(modreader);
  15.247 -			if(mask[ch]&8) { _mm_read_UBYTE(modreader);_mm_read_UBYTE(modreader); }
  15.248 -		}
  15.249 -	} while(row<patrows);
  15.250 -
  15.251 -	return 0;
  15.252 -}
  15.253 -
  15.254 -static UBYTE* IT_ConvertTrack(ITNOTE* tr,UWORD numrows)
  15.255 -{
  15.256 -	int t;
  15.257 -	UBYTE note,ins,volpan;
  15.258 -
  15.259 -	UniReset();
  15.260 -
  15.261 -	for(t=0;t<numrows;t++) {
  15.262 -		note=tr[t*of.numchn].note;
  15.263 -		ins=tr[t*of.numchn].ins;
  15.264 -		volpan=tr[t*of.numchn].volpan;
  15.265 -
  15.266 -		if(note!=255) {
  15.267 -			if(note==253)
  15.268 -				UniWriteByte(UNI_KEYOFF);
  15.269 -			else if(note==254) {
  15.270 -				UniPTEffect(0xc,-1);	/* note cut command */
  15.271 -				volpan=255;
  15.272 -			} else
  15.273 -				UniNote(note);
  15.274 -		}
  15.275 -
  15.276 -		if((ins)&&(ins<100))
  15.277 -			UniInstrument(ins-1);
  15.278 -		else if(ins==253)
  15.279 -			UniWriteByte(UNI_KEYOFF);
  15.280 -		else if(ins!=255) { /* crap */
  15.281 -			_mm_errno=MMERR_LOADING_PATTERN;
  15.282 -			return NULL;
  15.283 -		}
  15.284 -
  15.285 -		/* process volume / panning column
  15.286 -		   volume / panning effects do NOT all share the same memory address
  15.287 -		   yet. */
  15.288 -		if(volpan<=64) 
  15.289 -			UniVolEffect(VOL_VOLUME,volpan);
  15.290 -		else if(volpan==65) /* fine volume slide up (65-74) - A0 case */
  15.291 -			UniVolEffect(VOL_VOLSLIDE,0);
  15.292 -		else if(volpan<=74)	{ /* fine volume slide up (65-74) - general case */
  15.293 -			UniVolEffect(VOL_VOLSLIDE,0x0f+((volpan-65)<<4));
  15.294 -		} else if(volpan==75)	/* fine volume slide down (75-84) - B0 case */
  15.295 -			UniVolEffect(VOL_VOLSLIDE,0);
  15.296 -		else if(volpan<=84) {	/* fine volume slide down (75-84) - general case*/
  15.297 -			UniVolEffect(VOL_VOLSLIDE,0xf0+(volpan-75));
  15.298 -		} else if(volpan<=94)	/* volume slide up (85-94) */
  15.299 -			UniVolEffect(VOL_VOLSLIDE,((volpan-85)<<4));
  15.300 -		else if(volpan<=104)/* volume slide down (95-104) */
  15.301 -			UniVolEffect(VOL_VOLSLIDE,(volpan-95));
  15.302 -		else if(volpan<=114)/* pitch slide down (105-114) */
  15.303 -			UniVolEffect(VOL_PITCHSLIDEDN,(volpan-105));
  15.304 -		else if(volpan<=124)/* pitch slide up (115-124) */
  15.305 -			UniVolEffect(VOL_PITCHSLIDEUP,(volpan-115));
  15.306 -		else if(volpan<=127) { /* crap */
  15.307 -			_mm_errno=MMERR_LOADING_PATTERN;
  15.308 -			return NULL;
  15.309 -		} else if(volpan<=192)
  15.310 -			UniVolEffect(VOL_PANNING,((volpan-128)==64)?255:((volpan-128)<<2));
  15.311 -		else if(volpan<=202)/* portamento to note */
  15.312 -			UniVolEffect(VOL_PORTAMENTO,portatable[volpan-193]);
  15.313 -		else if(volpan<=212)/* vibrato */
  15.314 -			UniVolEffect(VOL_VIBRATO,(volpan-203));
  15.315 -		else if((volpan!=239)&&(volpan!=255)) { /* crap */
  15.316 -			_mm_errno=MMERR_LOADING_PATTERN;
  15.317 -			return NULL;
  15.318 -		}
  15.319 -
  15.320 -		S3MIT_ProcessCmd(tr[t*of.numchn].cmd,tr[t*of.numchn].inf,
  15.321 -		    old_effect|S3MIT_IT);
  15.322 -
  15.323 -		UniNewline();
  15.324 -	}
  15.325 -	return UniDup();
  15.326 -}
  15.327 -
  15.328 -static BOOL IT_ReadPattern(UWORD patrows)
  15.329 -{
  15.330 -	int row=0,flag,ch,blah;
  15.331 -	ITNOTE *itt=itpat,dummy,*n,*l;
  15.332 -
  15.333 -	memset(itt,255,200*64*sizeof(ITNOTE));
  15.334 -
  15.335 -	do {
  15.336 -		if((flag=_mm_read_UBYTE(modreader))==EOF) {
  15.337 -			_mm_errno = MMERR_LOADING_PATTERN;
  15.338 -			return 0;
  15.339 -		}
  15.340 -		if(!flag) {
  15.341 -			itt=&itt[of.numchn];
  15.342 -			row++;
  15.343 -		} else {
  15.344 -			ch=remap[(flag-1)&63];
  15.345 -			if(ch!=-1) {
  15.346 -				n=&itt[ch];
  15.347 -				l=&last[ch];
  15.348 -			} else 
  15.349 -				n=l=&dummy;
  15.350 -
  15.351 -			if(flag&128) mask[ch]=_mm_read_UBYTE(modreader);
  15.352 -			if(mask[ch]&1)
  15.353 -				/* convert IT note off to internal note off */
  15.354 -				if((l->note=n->note=_mm_read_UBYTE(modreader))==255) 
  15.355 -					l->note=n->note=253;
  15.356 -			if(mask[ch]&2)
  15.357 -				l->ins=n->ins=_mm_read_UBYTE(modreader);
  15.358 -			if(mask[ch]&4)
  15.359 -				l->volpan=n->volpan=_mm_read_UBYTE(modreader);
  15.360 -			if(mask[ch]&8) {
  15.361 -				l->cmd=n->cmd=_mm_read_UBYTE(modreader);
  15.362 -				l->inf=n->inf=_mm_read_UBYTE(modreader);
  15.363 -			}
  15.364 -			if(mask[ch]&16)
  15.365 -				n->note=l->note;
  15.366 -			if(mask[ch]&32)
  15.367 -				n->ins=l->ins;
  15.368 -			if(mask[ch]&64)
  15.369 -				n->volpan=l->volpan;
  15.370 -			if(mask[ch]&128) {
  15.371 -				n->cmd=l->cmd;
  15.372 -				n->inf=l->inf;
  15.373 -			}
  15.374 -		}
  15.375 -	} while(row<patrows);
  15.376 -
  15.377 -	for(blah=0;blah<of.numchn;blah++) {
  15.378 -		if(!(of.tracks[numtrk++]=IT_ConvertTrack(&itpat[blah],patrows)))
  15.379 -			return 0;
  15.380 -	}
  15.381 -
  15.382 -	return 1;
  15.383 -}
  15.384 -
  15.385 -static void LoadMidiString(MREADER* modreader,CHAR* dest)
  15.386 -{
  15.387 -	CHAR *cur,*last;
  15.388 -
  15.389 -	_mm_read_UBYTES(dest,32,modreader);
  15.390 -	cur=last=dest;
  15.391 -	/* remove blanks and uppercase all */
  15.392 -	while(*last) {
  15.393 -		if(isalnum((int)*last)) *(cur++)=toupper((int)*last);
  15.394 -		last++;
  15.395 -	}
  15.396 -	*cur=0;
  15.397 -}
  15.398 -
  15.399 -/* Load embedded midi information for resonant filters */
  15.400 -static void IT_LoadMidiConfiguration(MREADER* modreader)
  15.401 -{
  15.402 -	int i;
  15.403 -
  15.404 -	memset(filtermacros,0,sizeof(filtermacros));
  15.405 -	memset(filtersettings,0,sizeof(filtersettings));
  15.406 -
  15.407 -	if (modreader) { /* information is embedded in file */
  15.408 -		UWORD dat;
  15.409 -		CHAR midiline[33];
  15.410 -
  15.411 -		dat=_mm_read_I_UWORD(modreader);
  15.412 -		_mm_fseek(modreader,8*dat+0x120,SEEK_CUR);
  15.413 -
  15.414 -		/* read midi macros */
  15.415 -		for(i=0;i<UF_MAXMACRO;i++) {
  15.416 -			LoadMidiString(modreader,midiline);
  15.417 -			if((!strncmp(midiline,"F0F00",5))&&
  15.418 -			   ((midiline[5]=='0')||(midiline[5]=='1')))
  15.419 -					filtermacros[i]=(midiline[5]-'0')|0x80;
  15.420 -		}
  15.421 -
  15.422 -		/* read standalone filters */
  15.423 -		for(i=0x80;i<0x100;i++) {
  15.424 -			LoadMidiString(modreader,midiline);
  15.425 -			if((!strncmp(midiline,"F0F00",5))&&
  15.426 -			   ((midiline[5]=='0')||(midiline[5]=='1'))) {
  15.427 -				filtersettings[i].filter=(midiline[5]-'0')|0x80;
  15.428 -				dat=(midiline[6])?(midiline[6]-'0'):0;
  15.429 -				if(midiline[7])dat=(dat<<4)|(midiline[7]-'0');
  15.430 -				filtersettings[i].inf=dat;
  15.431 -			}
  15.432 -		}
  15.433 -	} else { /* use default information */
  15.434 -		filtermacros[0]=FILT_CUT;
  15.435 -		for(i=0x80;i<0x90;i++) {
  15.436 -			filtersettings[i].filter=FILT_RESONANT;
  15.437 -			filtersettings[i].inf=(i&0x7f)<<3;
  15.438 -		}
  15.439 -	}
  15.440 -	activemacro=0;
  15.441 -	for(i=0;i<0x80;i++) {
  15.442 -		filtersettings[i].filter=filtermacros[0];
  15.443 -		filtersettings[i].inf=i;
  15.444 -	}
  15.445 -}
  15.446 -
  15.447 -BOOL IT_Load(BOOL curious)
  15.448 -{
  15.449 -	int t,u,lp;
  15.450 -	INSTRUMENT *d;
  15.451 -	SAMPLE *q;
  15.452 -	BOOL compressed=0;
  15.453 -
  15.454 -	numtrk=0;
  15.455 -	filters=0;
  15.456 -
  15.457 -	/* try to read module header */
  15.458 -	_mm_read_I_ULONG(modreader);	/* kill the 4 byte header */
  15.459 -	_mm_read_string(mh->songname,26,modreader);
  15.460 -	_mm_read_UBYTES(mh->blank01,2,modreader);
  15.461 -	mh->ordnum      =_mm_read_I_UWORD(modreader);
  15.462 -	mh->insnum      =_mm_read_I_UWORD(modreader);
  15.463 -	mh->smpnum      =_mm_read_I_UWORD(modreader);
  15.464 -	mh->patnum      =_mm_read_I_UWORD(modreader);
  15.465 -	mh->cwt         =_mm_read_I_UWORD(modreader);
  15.466 -	mh->cmwt        =_mm_read_I_UWORD(modreader);
  15.467 -	mh->flags       =_mm_read_I_UWORD(modreader);
  15.468 -	mh->special     =_mm_read_I_UWORD(modreader);
  15.469 -	mh->globvol     =_mm_read_UBYTE(modreader);
  15.470 -	mh->mixvol      =_mm_read_UBYTE(modreader);
  15.471 -	mh->initspeed   =_mm_read_UBYTE(modreader);
  15.472 -	mh->inittempo   =_mm_read_UBYTE(modreader);
  15.473 -	mh->pansep      =_mm_read_UBYTE(modreader);
  15.474 -	mh->zerobyte    =_mm_read_UBYTE(modreader);
  15.475 -	mh->msglength   =_mm_read_I_UWORD(modreader);
  15.476 -	mh->msgoffset   =_mm_read_I_ULONG(modreader);
  15.477 -	_mm_read_UBYTES(mh->blank02,4,modreader);
  15.478 -	_mm_read_UBYTES(mh->pantable,64,modreader);
  15.479 -	_mm_read_UBYTES(mh->voltable,64,modreader);
  15.480 -
  15.481 -	if(_mm_eof(modreader)) {
  15.482 -		_mm_errno=MMERR_LOADING_HEADER;
  15.483 -		return 0;
  15.484 -	}
  15.485 -
  15.486 -	/* set module variables */
  15.487 -	of.songname    = DupStr(mh->songname,26,0); /* make a cstr of songname  */
  15.488 -	of.reppos      = 0;
  15.489 -	of.numpat      = mh->patnum;
  15.490 -	of.numins      = mh->insnum;
  15.491 -	of.numsmp      = mh->smpnum;
  15.492 -	of.initspeed   = mh->initspeed;
  15.493 -	of.inittempo   = mh->inittempo;
  15.494 -	of.initvolume  = mh->globvol;
  15.495 -	of.flags      |= UF_BGSLIDES | UF_ARPMEM;
  15.496 -	if (!(mh->flags & 1))
  15.497 -			of.flags |= UF_PANNING;
  15.498 -	of.bpmlimit=32;
  15.499 -
  15.500 -	if(mh->songname[25]) {
  15.501 -		of.numvoices=1+mh->songname[25];
  15.502 -#ifdef MIKMOD_DEBUG
  15.503 -		fprintf(stderr,"Embedded IT limitation to %d voices\n",of.numvoices);
  15.504 -#endif
  15.505 -	}
  15.506 -
  15.507 -	/* set the module type */
  15.508 -	/* 2.17 : IT 2.14p4 */
  15.509 -	/* 2.16 : IT 2.14p3 with resonant filters */
  15.510 -	/* 2.15 : IT 2.14p3 (improved compression) */
  15.511 -	if((mh->cwt<=0x219)&&(mh->cwt>=0x217))
  15.512 -		of.modtype=strdup(IT_Version[mh->cmwt<0x214?4:5]);
  15.513 -	else if (mh->cwt>=0x215)
  15.514 -		of.modtype=strdup(IT_Version[mh->cmwt<0x214?2:3]);
  15.515 -	else {
  15.516 -		of.modtype     = strdup(IT_Version[mh->cmwt<0x214?0:1]);
  15.517 -		of.modtype[mh->cmwt<0x214?15:26] = (mh->cwt>>8)+'0';
  15.518 -		of.modtype[mh->cmwt<0x214?17:28] = ((mh->cwt>>4)&0xf)+'0';
  15.519 -		of.modtype[mh->cmwt<0x214?18:29] = ((mh->cwt)&0xf)+'0';
  15.520 -	}
  15.521 -
  15.522 -	if(mh->flags&8)
  15.523 -		of.flags |= UF_XMPERIODS | UF_LINEAR;
  15.524 -
  15.525 -	if((mh->cwt>=0x106)&&(mh->flags&16))
  15.526 -		old_effect=S3MIT_OLDSTYLE;
  15.527 -	else
  15.528 -		old_effect=0;
  15.529 -
  15.530 -	/* set panning positions */
  15.531 -	if (mh->flags & 1)
  15.532 -		for(t=0;t<64;t++) {
  15.533 -			mh->pantable[t]&=0x7f;
  15.534 -			if(mh->pantable[t]<64)
  15.535 -				of.panning[t]=mh->pantable[t]<<2;
  15.536 -			else if(mh->pantable[t]==64)
  15.537 -				of.panning[t]=255;
  15.538 -			else if(mh->pantable[t]==100)
  15.539 -				of.panning[t]=PAN_SURROUND;
  15.540 -			else if(mh->pantable[t]==127)
  15.541 -				of.panning[t]=PAN_CENTER;
  15.542 -			else {
  15.543 -				_mm_errno=MMERR_LOADING_HEADER;
  15.544 -				return 0;
  15.545 -			}
  15.546 -		}
  15.547 -	else
  15.548 -		for(t=0;t<64;t++)
  15.549 -			of.panning[t]=PAN_CENTER;
  15.550 -
  15.551 -	/* set channel volumes */
  15.552 -	memcpy(of.chanvol,mh->voltable,64);
  15.553 -
  15.554 -	/* read the order data */
  15.555 -	if(!AllocPositions(mh->ordnum)) return 0;
  15.556 -	if(!(origpositions=_mm_calloc(mh->ordnum,sizeof(UWORD)))) return 0;
  15.557 -
  15.558 -	for(t=0;t<mh->ordnum;t++) {
  15.559 -		origpositions[t]=_mm_read_UBYTE(modreader);
  15.560 -		if((origpositions[t]>mh->patnum)&&(origpositions[t]<254))
  15.561 -			origpositions[t]=255;
  15.562 -	}
  15.563 -
  15.564 -	if(_mm_eof(modreader)) {
  15.565 -		_mm_errno = MMERR_LOADING_HEADER;
  15.566 -		return 0;
  15.567 -	}
  15.568 -
  15.569 -	poslookupcnt=mh->ordnum;
  15.570 -	S3MIT_CreateOrders(curious);
  15.571 -
  15.572 -	if(!(paraptr=(ULONG*)_mm_malloc((mh->insnum+mh->smpnum+of.numpat)*
  15.573 -	                               sizeof(ULONG)))) return 0;
  15.574 -
  15.575 -	/* read the instrument, sample, and pattern parapointers */
  15.576 -	_mm_read_I_ULONGS(paraptr,mh->insnum+mh->smpnum+of.numpat,modreader);
  15.577 -
  15.578 -	if(_mm_eof(modreader)) {
  15.579 -		_mm_errno = MMERR_LOADING_HEADER;
  15.580 -		return 0;
  15.581 -	}
  15.582 -
  15.583 -	/* Check for and load midi information for resonant filters */
  15.584 -	if(mh->cmwt>=0x216) {
  15.585 -		if(mh->special&8) {
  15.586 -			IT_LoadMidiConfiguration(modreader);
  15.587 -			if(_mm_eof(modreader)) {
  15.588 -				_mm_errno = MMERR_LOADING_HEADER;
  15.589 -				return 0;
  15.590 -			}
  15.591 -		} else
  15.592 -			IT_LoadMidiConfiguration(NULL);
  15.593 -		filters=1;
  15.594 -	}
  15.595 -
  15.596 -	/* Check for and load song comment */
  15.597 -	if((mh->special&1)&&(mh->cwt>=0x104)&&(mh->msglength)) {
  15.598 -		_mm_fseek(modreader,(long)(mh->msgoffset),SEEK_SET);
  15.599 -		if(!ReadComment(mh->msglength)) return 0;
  15.600 -	}
  15.601 -
  15.602 -	if(!(mh->flags&4)) of.numins=of.numsmp;
  15.603 -	if(!AllocSamples()) return 0;
  15.604 -
  15.605 -	if(!AllocLinear()) return 0;
  15.606 -
  15.607 -	/* Load all samples */
  15.608 -	q = of.samples;
  15.609 -	for(t=0;t<mh->smpnum;t++) {
  15.610 -		ITSAMPLE s;
  15.611 -
  15.612 -		/* seek to sample position */
  15.613 -		_mm_fseek(modreader,(long)(paraptr[mh->insnum+t]+4),SEEK_SET);
  15.614 -
  15.615 -		/* load sample info */
  15.616 -		_mm_read_string(s.filename,12,modreader);
  15.617 -		s.zerobyte    = _mm_read_UBYTE(modreader);
  15.618 -		s.globvol     = _mm_read_UBYTE(modreader);
  15.619 -		s.flag        = _mm_read_UBYTE(modreader);
  15.620 -		s.volume      = _mm_read_UBYTE(modreader);
  15.621 -		_mm_read_string(s.sampname,26,modreader);
  15.622 -		s.convert     = _mm_read_UBYTE(modreader);
  15.623 -		s.panning     = _mm_read_UBYTE(modreader);
  15.624 -		s.length      = _mm_read_I_ULONG(modreader);
  15.625 -		s.loopbeg     = _mm_read_I_ULONG(modreader);
  15.626 -		s.loopend     = _mm_read_I_ULONG(modreader);
  15.627 -		s.c5spd       = _mm_read_I_ULONG(modreader);
  15.628 -		s.susbegin    = _mm_read_I_ULONG(modreader);
  15.629 -		s.susend      = _mm_read_I_ULONG(modreader);
  15.630 -		s.sampoffset  = _mm_read_I_ULONG(modreader);
  15.631 -		s.vibspeed    = _mm_read_UBYTE(modreader);
  15.632 -		s.vibdepth    = _mm_read_UBYTE(modreader);
  15.633 -		s.vibrate     = _mm_read_UBYTE(modreader);
  15.634 -		s.vibwave     = _mm_read_UBYTE(modreader);
  15.635 -
  15.636 -		/* Generate an error if c5spd is > 512k, or samplelength > 256 megs
  15.637 -		   (nothing would EVER be that high) */
  15.638 -
  15.639 -		if(_mm_eof(modreader)||(s.c5spd>0x7ffffL)||(s.length>0xfffffffUL)) {
  15.640 -			_mm_errno = MMERR_LOADING_SAMPLEINFO;
  15.641 -			return 0;
  15.642 -		}
  15.643 -
  15.644 -		/* Reality check for sample loop information */
  15.645 -		if((s.flag&16)&&
  15.646 -		   ((s.loopbeg>0xfffffffUL)||(s.loopend>0xfffffffUL))) {
  15.647 -			_mm_errno = MMERR_LOADING_SAMPLEINFO;
  15.648 -			return 0;
  15.649 -		}
  15.650 -
  15.651 -		q->samplename = DupStr(s.sampname,26,0);
  15.652 -		q->speed      = s.c5spd / 2;
  15.653 -		q->panning    = ((s.panning&127)==64)?255:(s.panning&127)<<2;
  15.654 -		q->length     = s.length;
  15.655 -		q->loopstart  = s.loopbeg;
  15.656 -		q->loopend    = s.loopend;
  15.657 -		q->volume     = s.volume;
  15.658 -		q->globvol    = s.globvol;
  15.659 -		q->seekpos    = s.sampoffset;
  15.660 -
  15.661 -		/* Convert speed to XM linear finetune */
  15.662 -		if(of.flags&UF_LINEAR)
  15.663 -			q->speed=speed_to_finetune(s.c5spd,t);
  15.664 -
  15.665 -		if(s.panning&128) q->flags|=SF_OWNPAN;
  15.666 -
  15.667 -		if(s.vibrate) {
  15.668 -			q->vibflags |= AV_IT;
  15.669 -			q->vibtype   = s.vibwave;
  15.670 -			q->vibsweep  = s.vibrate * 2;
  15.671 -			q->vibdepth  = s.vibdepth;
  15.672 -			q->vibrate   = s.vibspeed;
  15.673 -		}
  15.674 -
  15.675 -		if(s.flag&2) q->flags|=SF_16BITS;
  15.676 -		if((s.flag&8)&&(mh->cwt>=0x214)) {
  15.677 -			q->flags|=SF_ITPACKED;
  15.678 -			compressed=1;
  15.679 -		}
  15.680 -		if(s.flag&16) q->flags|=SF_LOOP;
  15.681 -		if(s.flag&64) q->flags|=SF_BIDI;
  15.682 -
  15.683 -		if(mh->cwt>=0x200) {
  15.684 -			if(s.convert&1) q->flags|=SF_SIGNED;
  15.685 -			if(s.convert&4) q->flags|=SF_DELTA;   
  15.686 -		}
  15.687 -		q++;
  15.688 -	}
  15.689 -
  15.690 -	/* Load instruments if instrument mode flag enabled */
  15.691 -	if(mh->flags&4) {
  15.692 -		if(!AllocInstruments()) return 0;
  15.693 -		d=of.instruments;
  15.694 -		of.flags|=UF_NNA|UF_INST;
  15.695 -
  15.696 -		for(t=0;t<mh->insnum;t++) {
  15.697 -			ITINSTHEADER ih;
  15.698 -
  15.699 -			/* seek to instrument position */
  15.700 -			_mm_fseek(modreader,paraptr[t]+4,SEEK_SET);
  15.701 -
  15.702 -			/* load instrument info */
  15.703 -			_mm_read_string(ih.filename,12,modreader);
  15.704 -			ih.zerobyte  = _mm_read_UBYTE(modreader);
  15.705 -			if(mh->cwt<0x200) {
  15.706 -				/* load IT 1.xx inst header */
  15.707 -				ih.volflg    = _mm_read_UBYTE(modreader);
  15.708 -				ih.volbeg    = _mm_read_UBYTE(modreader);
  15.709 -				ih.volend    = _mm_read_UBYTE(modreader);
  15.710 -				ih.volsusbeg = _mm_read_UBYTE(modreader);
  15.711 -				ih.volsusend = _mm_read_UBYTE(modreader);
  15.712 -				_mm_read_I_UWORD(modreader);
  15.713 -				ih.fadeout   = _mm_read_I_UWORD(modreader);
  15.714 -				ih.nna       = _mm_read_UBYTE(modreader);
  15.715 -				ih.dnc       = _mm_read_UBYTE(modreader);
  15.716 -			} else {
  15.717 -				/* Read IT200+ header */
  15.718 -				ih.nna       = _mm_read_UBYTE(modreader);
  15.719 -				ih.dct       = _mm_read_UBYTE(modreader);
  15.720 -				ih.dca       = _mm_read_UBYTE(modreader);
  15.721 -				ih.fadeout   = _mm_read_I_UWORD(modreader);
  15.722 -				ih.ppsep     = _mm_read_UBYTE(modreader);
  15.723 -				ih.ppcenter  = _mm_read_UBYTE(modreader);
  15.724 -				ih.globvol   = _mm_read_UBYTE(modreader);
  15.725 -				ih.chanpan   = _mm_read_UBYTE(modreader);
  15.726 -				ih.rvolvar   = _mm_read_UBYTE(modreader);
  15.727 -				ih.rpanvar   = _mm_read_UBYTE(modreader);
  15.728 -			}
  15.729 -
  15.730 -			ih.trkvers   = _mm_read_I_UWORD(modreader);
  15.731 -			ih.numsmp    = _mm_read_UBYTE(modreader);
  15.732 -			_mm_read_UBYTE(modreader);
  15.733 -			_mm_read_string(ih.name,26,modreader);
  15.734 -			_mm_read_UBYTES(ih.blank01,6,modreader);
  15.735 -			_mm_read_I_UWORDS(ih.samptable,ITNOTECNT,modreader);
  15.736 -			if(mh->cwt<0x200) {
  15.737 -				/* load IT 1xx volume envelope */
  15.738 -				_mm_read_UBYTES(ih.volenv,200,modreader);
  15.739 -				for(lp=0;lp<ITENVCNT;lp++) {
  15.740 -					ih.oldvoltick[lp] = _mm_read_UBYTE(modreader);
  15.741 -					ih.volnode[lp]    = _mm_read_UBYTE(modreader);
  15.742 -				} 
  15.743 -			} else {
  15.744 -				/* load IT 2xx volume, pan and pitch envelopes */
  15.745 -#if defined __STDC__ || defined _MSC_VER
  15.746 -#define IT_LoadEnvelope(name,type) 										\
  15.747 -				ih. name##flg   =_mm_read_UBYTE(modreader);				\
  15.748 -				ih. name##pts   =_mm_read_UBYTE(modreader);				\
  15.749 -				ih. name##beg   =_mm_read_UBYTE(modreader);				\
  15.750 -				ih. name##end   =_mm_read_UBYTE(modreader);				\
  15.751 -				ih. name##susbeg=_mm_read_UBYTE(modreader);				\
  15.752 -				ih. name##susend=_mm_read_UBYTE(modreader);				\
  15.753 -				for(lp=0;lp<ITENVCNT;lp++) {							\
  15.754 -					ih. name##node[lp]=_mm_read_##type (modreader);		\
  15.755 -					ih. name##tick[lp]=_mm_read_I_UWORD(modreader);		\
  15.756 -				}														\
  15.757 -				_mm_read_UBYTE(modreader)
  15.758 -#else
  15.759 -#define IT_LoadEnvelope(name,type) 										\
  15.760 -				ih. name/**/flg   =_mm_read_UBYTE(modreader);			\
  15.761 -				ih. name/**/pts   =_mm_read_UBYTE(modreader);			\
  15.762 -				ih. name/**/beg   =_mm_read_UBYTE(modreader);			\
  15.763 -				ih. name/**/end   =_mm_read_UBYTE(modreader);			\
  15.764 -				ih. name/**/susbeg=_mm_read_UBYTE(modreader);			\
  15.765 -				ih. name/**/susend=_mm_read_UBYTE(modreader);			\
  15.766 -				for(lp=0;lp<ITENVCNT;lp++) {							\
  15.767 -					ih. name/**/node[lp]=_mm_read_/**/type (modreader);	\
  15.768 -					ih. name/**/tick[lp]=_mm_read_I_UWORD(modreader);	\
  15.769 -				}														\
  15.770 -				_mm_read_UBYTE(modreader)
  15.771 -#endif
  15.772 -
  15.773 -				IT_LoadEnvelope(vol,UBYTE);
  15.774 -				IT_LoadEnvelope(pan,SBYTE);
  15.775 -				IT_LoadEnvelope(pit,SBYTE);
  15.776 -#undef IT_LoadEnvelope
  15.777 -			}
  15.778 - 
  15.779 -			if(_mm_eof(modreader)) {
  15.780 -				_mm_errno = MMERR_LOADING_SAMPLEINFO;
  15.781 -				return 0;
  15.782 -			}
  15.783 -
  15.784 -			d->volflg|=EF_VOLENV;
  15.785 -			d->insname = DupStr(ih.name,26,0);
  15.786 -			d->nnatype = ih.nna & NNA_MASK;
  15.787 -
  15.788 -			if(mh->cwt<0x200) {
  15.789 -				d->volfade=ih.fadeout<< 6;
  15.790 -				if(ih.dnc) {
  15.791 -					d->dct=DCT_NOTE;
  15.792 -					d->dca=DCA_CUT;
  15.793 -				}
  15.794 -
  15.795 -				if(ih.volflg&1) d->volflg|=EF_ON;
  15.796 -				if(ih.volflg&2) d->volflg|=EF_LOOP;
  15.797 -				if(ih.volflg&4) d->volflg|=EF_SUSTAIN;      
  15.798 -
  15.799 -				/* XM conversion of IT envelope Array */
  15.800 -				d->volbeg    = ih.volbeg;   
  15.801 -				d->volend    = ih.volend;
  15.802 -				d->volsusbeg = ih.volsusbeg;
  15.803 -				d->volsusend = ih.volsusend;
  15.804 -
  15.805 -				if(ih.volflg&1) {
  15.806 -					for(u=0;u<ITENVCNT;u++)
  15.807 -						if(ih.oldvoltick[d->volpts]!=0xff) {
  15.808 -							d->volenv[d->volpts].val=(ih.volnode[d->volpts]<<2);
  15.809 -							d->volenv[d->volpts].pos=ih.oldvoltick[d->volpts];
  15.810 -							d->volpts++;
  15.811 -						} else
  15.812 -							break;
  15.813 -				}  
  15.814 -			} else {
  15.815 -				d->panning=((ih.chanpan&127)==64)?255:(ih.chanpan&127)<<2;
  15.816 -				if(!(ih.chanpan&128)) d->flags|=IF_OWNPAN;
  15.817 -
  15.818 -				if(!(ih.ppsep & 128)) {
  15.819 -					d->pitpansep=ih.ppsep<<2;
  15.820 -					d->pitpancenter=ih.ppcenter;
  15.821 -					d->flags|=IF_PITCHPAN;
  15.822 -				}
  15.823 -				d->globvol=ih.globvol>>1;
  15.824 -				d->volfade=ih.fadeout<<5;
  15.825 -				d->dct    =ih.dct;
  15.826 -				d->dca    =ih.dca;
  15.827 -
  15.828 -				if(mh->cwt>=0x204) {
  15.829 -					d->rvolvar = ih.rvolvar;
  15.830 -					d->rpanvar = ih.rpanvar;
  15.831 -				}
  15.832 -
  15.833 -#if defined __STDC__ || defined _MSC_VER
  15.834 -#define IT_ProcessEnvelope(name) 										\
  15.835 -				if(ih. name##flg&1) d-> name##flg|=EF_ON;				\
  15.836 -				if(ih. name##flg&2) d-> name##flg|=EF_LOOP;				\
  15.837 -				if(ih. name##flg&4) d-> name##flg|=EF_SUSTAIN;			\
  15.838 -				d-> name##pts=ih. name##pts;							\
  15.839 -				d-> name##beg=ih. name##beg;							\
  15.840 -				d-> name##end=ih. name##end;							\
  15.841 -				d-> name##susbeg=ih. name##susbeg;						\
  15.842 -				d-> name##susend=ih. name##susend;						\
  15.843 -																		\
  15.844 -				for(u=0;u<ih. name##pts;u++)							\
  15.845 -					d-> name##env[u].pos=ih. name##tick[u];				\
  15.846 -																		\
  15.847 -				if((d-> name##flg&EF_ON)&&(d-> name##pts<2))			\
  15.848 -					d-> name##flg&=~EF_ON
  15.849 -#else
  15.850 -#define IT_ProcessEnvelope(name) 									\
  15.851 -				if(ih. name/**/flg&1) d-> name/**/flg|=EF_ON;		\
  15.852 -				if(ih. name/**/flg&2) d-> name/**/flg|=EF_LOOP;		\
  15.853 -				if(ih. name/**/flg&4) d-> name/**/flg|=EF_SUSTAIN;	\
  15.854 -				d-> name/**/pts=ih. name/**/pts;					\
  15.855 -				d-> name/**/beg=ih. name/**/beg;					\
  15.856 -				d-> name/**/end=ih. name/**/end;					\
  15.857 -				d-> name/**/susbeg=ih. name/**/susbeg;				\
  15.858 -				d-> name/**/susend=ih. name/**/susend;				\
  15.859 -																	\
  15.860 -				for(u=0;u<ih. name/**/pts;u++)						\
  15.861 -					d-> name/**/env[u].pos=ih. name/**/tick[u];		\
  15.862 -																	\
  15.863 -				if((d-> name/**/flg&EF_ON)&&(d-> name/**/pts<2))	\
  15.864 -					d-> name/**/flg&=~EF_ON
  15.865 -#endif
  15.866 -
  15.867 -				IT_ProcessEnvelope(vol);
  15.868 -				for(u=0;u<ih.volpts;u++)
  15.869 -					d->volenv[u].val=(ih.volnode[u]<<2);
  15.870 -
  15.871 -				IT_ProcessEnvelope(pan);
  15.872 -				for(u=0;u<ih.panpts;u++)
  15.873 -					d->panenv[u].val=
  15.874 -					  ih.pannode[u]==32?255:(ih.pannode[u]+32)<<2;
  15.875 -
  15.876 -				IT_ProcessEnvelope(pit);
  15.877 -				for(u=0;u<ih.pitpts;u++)
  15.878 -					d->pitenv[u].val=ih.pitnode[u]+32;
  15.879 -#undef IT_ProcessEnvelope
  15.880 -
  15.881 -				if(ih.pitflg&0x80) {
  15.882 -					/* filter envelopes not supported yet */
  15.883 -					d->pitflg&=~EF_ON;
  15.884 -					ih.pitpts=ih.pitbeg=ih.pitend=0;
  15.885 -#ifdef MIKMOD_DEBUG
  15.886 -					{
  15.887 -						static int warn=0;
  15.888 -						
  15.889 -						if(!warn)
  15.890 -							fprintf(stderr, "\rFilter envelopes not supported yet\n");
  15.891 -						warn=1;
  15.892 -					}
  15.893 -#endif
  15.894 -				}
  15.895 -			}
  15.896 -
  15.897 -			for(u=0;u<ITNOTECNT;u++) {
  15.898 -				d->samplenote[u]=(ih.samptable[u]&255);
  15.899 -				d->samplenumber[u]=
  15.900 -				  (ih.samptable[u]>>8)?((ih.samptable[u]>>8)-1):0xffff;
  15.901 -				if(d->samplenumber[u]>=of.numsmp)
  15.902 -					d->samplenote[u]=255;
  15.903 -				else if (of.flags&UF_LINEAR) {
  15.904 -					int note=(int)d->samplenote[u]+noteindex[d->samplenumber[u]];
  15.905 -					d->samplenote[u]=(note<0)?0:(note>255?255:note);
  15.906 -				}
  15.907 -			}
  15.908 -
  15.909 -			d++;                  
  15.910 -		}
  15.911 -	} else if(of.flags & UF_LINEAR) {
  15.912 -		if(!AllocInstruments()) return 0;
  15.913 -		d=of.instruments;
  15.914 -		of.flags|=UF_INST;
  15.915 -
  15.916 -		for(t=0;t<mh->smpnum;t++,d++)
  15.917 -			for(u=0;u<ITNOTECNT;u++) {
  15.918 -				if(d->samplenumber[u]>=of.numsmp)
  15.919 -					d->samplenote[u]=255;
  15.920 -				else {
  15.921 -					int note=(int)d->samplenote[u]+noteindex[d->samplenumber[u]];
  15.922 -					d->samplenote[u]=(note<0)?0:(note>255?255:note);
  15.923 -				}
  15.924 -			}
  15.925 -	}
  15.926 -
  15.927 -	/* Figure out how many channels this song actually uses */
  15.928 -	of.numchn=0;
  15.929 -	memset(remap,-1,UF_MAXCHAN*sizeof(UBYTE));
  15.930 -	for(t=0;t<of.numpat;t++) {
  15.931 -		UWORD packlen;
  15.932 -
  15.933 -		/* seek to pattern position */
  15.934 -		if(paraptr[mh->insnum+mh->smpnum+t]) { /* 0 -> empty 64 row pattern */
  15.935 -			_mm_fseek(modreader,((long)paraptr[mh->insnum+mh->smpnum+t]),SEEK_SET);
  15.936 -			_mm_read_I_UWORD(modreader);
  15.937 -			/* read pattern length (# of rows)
  15.938 -			   Impulse Tracker never creates patterns with less than 32 rows,
  15.939 -			   but some other trackers do, so we only check for more than 256
  15.940 -			   rows */
  15.941 -			packlen=_mm_read_I_UWORD(modreader);
  15.942 -			if(packlen>256) {
  15.943 -				_mm_errno=MMERR_LOADING_PATTERN;
  15.944 -				return 0;
  15.945 -			}
  15.946 -			_mm_read_I_ULONG(modreader);
  15.947 -			if(IT_GetNumChannels(packlen)) return 0;
  15.948 -		}
  15.949 -	}
  15.950 -
  15.951 -	/* give each of them a different number */
  15.952 -	for(t=0;t<UF_MAXCHAN;t++) 
  15.953 -		if(!remap[t])
  15.954 -			remap[t]=of.numchn++;
  15.955 -
  15.956 -	of.numtrk = of.numpat*of.numchn;
  15.957 -	if(of.numvoices)
  15.958 -		if (of.numvoices<of.numchn) of.numvoices=of.numchn;
  15.959 -
  15.960 -	if(!AllocPatterns()) return 0;
  15.961 -	if(!AllocTracks()) return 0;
  15.962 -
  15.963 -	for(t=0;t<of.numpat;t++) {
  15.964 -		UWORD packlen;
  15.965 -
  15.966 -		/* seek to pattern position */
  15.967 -		if(!paraptr[mh->insnum+mh->smpnum+t]) { /* 0 -> empty 64 row pattern */
  15.968 -			of.pattrows[t]=64;
  15.969 -			for(u=0;u<of.numchn;u++) {
  15.970 -				int k;
  15.971 -
  15.972 -				UniReset();
  15.973 -				for(k=0;k<64;k++) UniNewline();
  15.974 -				of.tracks[numtrk++]=UniDup();
  15.975 -			}
  15.976 -		} else {
  15.977 -			_mm_fseek(modreader,((long)paraptr[mh->insnum+mh->smpnum+t]),SEEK_SET);
  15.978 -			packlen=_mm_read_I_UWORD(modreader);
  15.979 -			of.pattrows[t]=_mm_read_I_UWORD(modreader);
  15.980 -			_mm_read_I_ULONG(modreader);
  15.981 -			if(!IT_ReadPattern(of.pattrows[t])) return 0;
  15.982 -		}
  15.983 -	}
  15.984 -
  15.985 -	return 1;
  15.986 -}
  15.987 -
  15.988 -CHAR *IT_LoadTitle(void)
  15.989 -{
  15.990 -	CHAR s[26];
  15.991 -
  15.992 -	_mm_fseek(modreader,4,SEEK_SET);
  15.993 -	if(!_mm_read_UBYTES(s,26,modreader)) return NULL;
  15.994 -   
  15.995 -	return(DupStr(s,26,0));
  15.996 -}
  15.997 -
  15.998 -/*========== Loader information */
  15.999 -
 15.1000 -MIKMODAPI MLOADER load_it={
 15.1001 -	NULL,
 15.1002 -	"IT",
 15.1003 -	"IT (Impulse Tracker)",
 15.1004 -	IT_Init,
 15.1005 -	IT_Test,
 15.1006 -	IT_Load,
 15.1007 -	IT_Cleanup,
 15.1008 -	IT_LoadTitle
 15.1009 -};
 15.1010 -
 15.1011 -/* ex:set ts=4: */
    16.1 --- a/mikmod/load_m15.c	Sat Oct 03 10:53:24 2009 +0000
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,505 +0,0 @@
    16.4 -/*	MikMod sound library
    16.5 -	(c) 1998, 1999, 2000, 2001, 2002 Miodrag Vallat and others - see file
    16.6 -	AUTHORS for complete list.
    16.7 -
    16.8 -	This library is free software; you can redistribute it and/or modify
    16.9 -	it under the terms of the GNU Library General Public License as
   16.10 -	published by the Free Software Foundation; either version 2 of
   16.11 -	the License, or (at your option) any later version.
   16.12 - 
   16.13 -	This program is distributed in the hope that it will be useful,
   16.14 -	but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.15 -	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16.16 -	GNU Library General Public License for more details.
   16.17 - 
   16.18 -	You should have received a copy of the GNU Library General Public
   16.19 -	License along with this library; if not, write to the Free Software
   16.20 -	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   16.21 -	02111-1307, USA.
   16.22 -*/
   16.23 -
   16.24 -/*==============================================================================
   16.25 -
   16.26 -  $Id: load_m15.c,v 1.1.1.1 2004/06/01 12:16:17 raph Exp $
   16.27 -
   16.28 -  15 instrument MOD loader
   16.29 -  Also supports Ultimate Sound Tracker (old M15 format)
   16.30 -
   16.31 -==============================================================================*/
   16.32 -
   16.33 -#ifdef HAVE_CONFIG_H
   16.34 -#include "config.h"
   16.35 -#endif
   16.36 -
   16.37 -#ifdef HAVE_UNISTD_H
   16.38 -#include <unistd.h>
   16.39 -#endif
   16.40 -
   16.41 -#include <ctype.h>
   16.42 -#include <stdio.h>
   16.43 -#ifdef HAVE_MEMORY_H
   16.44 -#include <memory.h>
   16.45 -#endif
   16.46 -#include <string.h>
   16.47 -
   16.48 -#include "mikmod_internals.h"
   16.49 -
   16.50 -#ifdef SUNOS
   16.51 -extern int fprintf(FILE *, const char *, ...);
   16.52 -#endif
   16.53 -
   16.54 -/*========== Module Structure */
   16.55 -
   16.56 -typedef struct MSAMPINFO {
   16.57 -	CHAR  samplename[23];	/* 22 in module, 23 in memory */
   16.58 -	UWORD length;
   16.59 -	UBYTE finetune;
   16.60 -	UBYTE volume;
   16.61 -	UWORD reppos;
   16.62 -	UWORD replen;
   16.63 -} MSAMPINFO;
   16.64 -
   16.65 -typedef struct MODULEHEADER {
   16.66 -	CHAR      songname[21];		/* the songname.., 20 in module, 21 in memory */
   16.67 -	MSAMPINFO samples[15];		/* all sampleinfo */
   16.68 -	UBYTE     songlength;		/* number of patterns used */
   16.69 -	UBYTE     magic1;       	/* should be 127 */
   16.70 -	UBYTE     positions[128];	/* which pattern to play at pos */
   16.71 -} MODULEHEADER;
   16.72 -
   16.73 -typedef struct MODNOTE {
   16.74 -	UBYTE a,b,c,d;
   16.75 -} MODNOTE;
   16.76 -
   16.77 -/*========== Loader variables */
   16.78 -
   16.79 -static MODULEHEADER *mh = NULL;
   16.80 -static MODNOTE *patbuf = NULL;
   16.81 -static BOOL ust_loader = 0;		/* if TRUE, load as an ust module. */
   16.82 -
   16.83 -/* known file formats which can confuse the loader */
   16.84 -#define REJECT 2
   16.85 -static char *signatures[REJECT]={
   16.86 -	"CAKEWALK",	/* cakewalk midi files */
   16.87 -	"SZDD"		/* Microsoft compressed files */
   16.88 -};
   16.89 -static int siglen[REJECT]={8,4};
   16.90 -
   16.91 -/*========== Loader code */
   16.92 -
   16.93 -static BOOL LoadModuleHeader(MODULEHEADER *mh)
   16.94 -{
   16.95 -	int t,u;
   16.96 -
   16.97 -	_mm_read_string(mh->songname,20,modreader);
   16.98 -	mh->songname[20]=0;	/* just in case */
   16.99 -
  16.100 -	/* sanity check : title should contain printable characters and a bunch
  16.101 -	   of null chars */
  16.102 -	for(t=0;t<20;t++)
  16.103 -		if((mh->songname[t])&&(mh->songname[t]<32)) return 0;
  16.104 -	for(t=0;(mh->songname[t])&&(t<20);t++);
  16.105 -	if(t<20) for(;t<20;t++) if(mh->songname[t]) return 0;
  16.106 -
  16.107 -	for(t=0;t<15;t++) {
  16.108 -		MSAMPINFO *s=&mh->samples[t];
  16.109 -
  16.110 -		_mm_read_string(s->samplename,22,modreader);
  16.111 -		s->samplename[22]=0;	/* just in case */
  16.112 -		s->length   =_mm_read_M_UWORD(modreader);
  16.113 -		s->finetune =_mm_read_UBYTE(modreader);
  16.114 -		s->volume   =_mm_read_UBYTE(modreader);
  16.115 -		s->reppos   =_mm_read_M_UWORD(modreader);
  16.116 -		s->replen   =_mm_read_M_UWORD(modreader);
  16.117 -
  16.118 -		/* sanity check : sample title should contain printable characters and
  16.119 -		   a bunch of null chars */
  16.120 -		for(u=0;u<20;u++)
  16.121 -			if((s->samplename[u])&&(s->samplename[u]</*32*/14)) return 0;
  16.122 -		for(u=0;(s->samplename[u])&&(u<20);u++);
  16.123 -		if(u<20) for(;u<20;u++) if(s->samplename[u]) return 0;
  16.124 -
  16.125 -		/* sanity check : finetune values */
  16.126 -		if(s->finetune>>4) return 0;
  16.127 -	}
  16.128 -
  16.129 -	mh->songlength  =_mm_read_UBYTE(modreader);
  16.130 -	mh->magic1      =_mm_read_UBYTE(modreader);	/* should be 127 */
  16.131 -
  16.132 -	/* sanity check : no more than 128 positions, restart position in range */
  16.133 -	if((!mh->songlength)||(mh->songlength>128)) return 0;
  16.134 -	/* values encountered so far are 0x6a and 0x78 */
  16.135 -	if(((mh->magic1&0xf8)!=0x78)&&(mh->magic1!=0x6a)&&(mh->magic1>mh->songlength)) return 0;
  16.136 -
  16.137 -	_mm_read_UBYTES(mh->positions,128,modreader);
  16.138 -
  16.139 -	/* sanity check : pattern range is 0..63 */
  16.140 -	for(t=0;t<128;t++)
  16.141 -		if(mh->positions[t]>63) return 0;
  16.142 -
  16.143 -	return(!_mm_eof(modreader));
  16.144 -}
  16.145 -
  16.146 -/* Checks the patterns in the modfile for UST / 15-inst indications.
  16.147 -   For example, if an effect 3xx is found, it is assumed that the song 
  16.148 -   is 15-inst.  If a 1xx effect has dat greater than 0x20, it is UST.   
  16.149 -
  16.150 -   Returns:  0 indecisive; 1 = UST; 2 = 15-inst                               */
  16.151 -static int CheckPatternType(int numpat)
  16.152 -{
  16.153 -	int t;
  16.154 -	UBYTE eff, dat;
  16.155 -
  16.156 -	for(t=0;t<numpat*(64U*4);t++) {
  16.157 -		/* Load the pattern into the temp buffer and scan it */
  16.158 -		_mm_read_UBYTE(modreader);_mm_read_UBYTE(modreader);
  16.159 -		eff = _mm_read_UBYTE(modreader);
  16.160 -		dat = _mm_read_UBYTE(modreader);
  16.161 -
  16.162 -		switch(eff) {
  16.163 -			case 1:
  16.164 -				if(dat>0x1f) return 1;
  16.165 -				if(dat<0x3)  return 2;
  16.166 -				break;
  16.167 -			case 2:
  16.168 -				if(dat>0x1f) return 1;
  16.169 -				return 2;
  16.170 -			case 3:
  16.171 -				if (dat) return 2;
  16.172 -				break;
  16.173 -			default:
  16.174 -				return 2;
  16.175 -		}
  16.176 -	}
  16.177 -	return 0;
  16.178 -}
  16.179 -
  16.180 -static BOOL M15_Test(void)
  16.181 -{
  16.182 -	int t, numpat;
  16.183 -	MODULEHEADER mh;
  16.184 -
  16.185 -	ust_loader = 0;
  16.186 -	if(!LoadModuleHeader(&mh)) return 0;
  16.187 -
  16.188 -	/* reject other file types */
  16.189 -	for(t=0;t<REJECT;t++)
  16.190 -		if(!memcmp(mh.songname,signatures[t],siglen[t])) return 0;
  16.191 -
  16.192 -	if(mh.magic1>127) return 0;
  16.193 -	if((!mh.songlength)||(mh.songlength>mh.magic1)) return 0;
  16.194 -
  16.195 -	for(t=0;t<15;t++) {
  16.196 -		/* all finetunes should be zero */
  16.197 -		if(mh.samples[t].finetune) return 0;
  16.198 -
  16.199 -		/* all volumes should be <= 64 */
  16.200 -		if(mh.samples[t].volume>64) return 0;
  16.201 -
  16.202 -		/* all instrument names should begin with s, st-, or a number */
  16.203 -		if((mh.samples[t].samplename[0]=='s')||
  16.204 -		   (mh.samples[t].samplename[0]=='S')) {
  16.205 -			if((memcmp(mh.samples[t].samplename,"st-",3)) &&
  16.206 -			   (memcmp(mh.samples[t].samplename,"ST-",3)) &&
  16.207 -			   (*mh.samples[t].samplename))
  16.208 -				ust_loader = 1;
  16.209 -		} else
  16.210 -		  if(!isdigit((int)mh.samples[t].samplename[0]))
  16.211 -				ust_loader = 1;
  16.212 -
  16.213 -		if(mh.samples[t].length>4999||mh.samples[t].reppos>9999) {
  16.214 -			ust_loader = 0;
  16.215 -			if(mh.samples[t].length>32768) return 0;
  16.216 -		}
  16.217 -
  16.218 -		/* if loop information is incorrect as words, but correct as bytes,
  16.219 -		   this is likely to be an ust-style module */
  16.220 -		if((mh.samples[t].reppos+mh.samples[t].replen>mh.samples[t].length)&&
  16.221 -		   (mh.samples[t].reppos+mh.samples[t].replen<(mh.samples[t].length<<1))){
  16.222 -			ust_loader = 1;
  16.223 -			return 1;
  16.224 -		}
  16.225 -
  16.226 -		if(!ust_loader) return 1; 
  16.227 -	}
  16.228 -
  16.229 -	for(numpat=0,t=0;t<mh.songlength;t++) 
  16.230 -		if(mh.positions[t]>numpat)
  16.231 -			numpat = mh.positions[t];
  16.232 -	numpat++;
  16.233 -	switch(CheckPatternType(numpat)) {
  16.234 -		case 0:   /* indecisive, so check more clues... */
  16.235 -			break;
  16.236 -		case 1:
  16.237 -			ust_loader = 1;
  16.238 -			break;
  16.239 -		case 2:
  16.240 -			ust_loader = 0;
  16.241 -			break;
  16.242 -	}
  16.243 -	return 1;
  16.244 -}
  16.245 -
  16.246 -static BOOL M15_Init(void)
  16.247 -{
  16.248 -	if(!(mh=(MODULEHEADER*)_mm_malloc(sizeof(MODULEHEADER)))) return 0;
  16.249 -	return 1;
  16.250 -}
  16.251 -
  16.252 -static void M15_Cleanup(void)
  16.253 -{
  16.254 -	_mm_free(mh);
  16.255 -	_mm_free(patbuf);
  16.256 -}
  16.257 -
  16.258 -/*
  16.259 -Old (amiga) noteinfo:
  16.260 -
  16.261 - _____byte 1_____   byte2_    _____byte 3_____   byte4_
  16.262 -/                \ /      \  /                \ /      \
  16.263 -0000          0000-00000000  0000          0000-00000000
  16.264 -
  16.265 -Upper four    12 bits for    Lower four    Effect command.
  16.266 -bits of sam-  note period.   bits of sam-
  16.267 -ple number.                  ple number.
  16.268 -*/
  16.269 -
  16.270 -static UBYTE M15_ConvertNote(MODNOTE* n, UBYTE lasteffect)
  16.271 -{
  16.272 -	UBYTE instrument,effect,effdat,note;
  16.273 -	UWORD period;
  16.274 -	UBYTE lastnote=0;
  16.275 -
  16.276 -	/* decode the 4 bytes that make up a single note */
  16.277 -	instrument = n->c>>4;
  16.278 -	period     = (((UWORD)n->a&0xf)<<8)+n->b;
  16.279 -	effect     = n->c&0xf;
  16.280 -	effdat     = n->d;
  16.281 -
  16.282 -	/* Convert the period to a note number */
  16.283 -	note=0;
  16.284 -	if(period) {
  16.285 -		for(note=0;note<7*OCTAVE;note++)
  16.286 -			if(period>=npertab[note]) break;
  16.287 -		if(note==7*OCTAVE) note=0;
  16.288 -		else note++;
  16.289 -	}
  16.290 -
  16.291 -	if(instrument) {
  16.292 -		/* if instrument does not exist, note cut */
  16.293 -		if((instrument>15)||(!mh->samples[instrument-1].length)) {
  16.294 -			UniPTEffect(0xc,0);
  16.295 -			if(effect==0xc) effect=effdat=0;
  16.296 -		} else {
  16.297 -			/* if we had a note, then change instrument... */
  16.298 -			if(note)
  16.299 -				UniInstrument(instrument-1);
  16.300 -			/* ...otherwise, only adjust volume... */
  16.301 -			else {
  16.302 -				/* ...unless an effect was specified, which forces a new note
  16.303 -				   to be played */
  16.304 -				if(effect||effdat) {
  16.305 -					UniInstrument(instrument-1);
  16.306 -					note=lastnote;
  16.307 -				} else
  16.308 -					UniPTEffect(0xc,mh->samples[instrument-1].volume&0x7f);
  16.309 -			}
  16.310 -		}
  16.311 -	}
  16.312 -	if(note) {
  16.313 -		UniNote(note+2*OCTAVE-1);
  16.314 -		lastnote=note;
  16.315 -	}
  16.316 -
  16.317 -	/* Convert pattern jump from Dec to Hex */
  16.318 -	if(effect == 0xd)
  16.319 -		effdat=(((effdat&0xf0)>>4)*10)+(effdat&0xf);
  16.320 -
  16.321 -	/* Volume slide, up has priority */
  16.322 -	if((effect==0xa)&&(effdat&0xf)&&(effdat&0xf0))
  16.323 -		effdat&=0xf0;
  16.324 -
  16.325 -	/* Handle ``heavy'' volumes correctly */
  16.326 -	if ((effect == 0xc) && (effdat > 0x40))
  16.327 -		effdat = 0x40;
  16.328 -
  16.329 -	if(ust_loader) {
  16.330 -		switch(effect) {
  16.331 -			case 0:
  16.332 -			case 3:
  16.333 -				break;
  16.334 -			case 1:
  16.335 -				UniPTEffect(0,effdat);
  16.336 -				break;
  16.337 -			case 2:  
  16.338 -				if(effdat&0xf) UniPTEffect(1,effdat&0xf);
  16.339 -				else if(effdat>>2)  UniPTEffect(2,effdat>>2);
  16.340 -				break;
  16.341 -			default:
  16.342 -				UniPTEffect(effect,effdat);
  16.343 -				break;
  16.344 -		}
  16.345 -	} else {
  16.346 -		/* An isolated 100, 200 or 300 effect should be ignored (no
  16.347 -		   "standalone" porta memory in mod files). However, a sequence
  16.348 -		   such as 1XX, 100, 100, 100 is fine. */
  16.349 -		if ((!effdat) && ((effect == 1)||(effect == 2)||(effect ==3)) &&
  16.350 -			(lasteffect < 0x10) && (effect != lasteffect))
  16.351 -			effect = 0;
  16.352 -
  16.353 -		UniPTEffect(effect,effdat);
  16.354 -	}
  16.355 -	if (effect == 8)
  16.356 -		of.flags |= UF_PANNING;
  16.357 -	
  16.358 -	return effect;
  16.359 -}
  16.360 -
  16.361 -static UBYTE *M15_ConvertTrack(MODNOTE* n)
  16.362 -{
  16.363 -	int t;
  16.364 -	UBYTE lasteffect = 0x10;	/* non existant effect */
  16.365 -
  16.366 -	UniReset();
  16.367 -	for(t=0;t<64;t++) {
  16.368 -		lasteffect = M15_ConvertNote(n,lasteffect);
  16.369 -		UniNewline();
  16.370 -		n+=4;
  16.371 -	}
  16.372 -	return UniDup();
  16.373 -}
  16.374 -
  16.375 -/* Loads all patterns of a modfile and converts them into the 3 byte format. */
  16.376 -static BOOL M15_LoadPatterns(void)
  16.377 -{
  16.378 -	int t,s,tracks=0;
  16.379 -
  16.380 -	if(!AllocPatterns()) return 0;
  16.381 -	if(!AllocTracks()) return 0;
  16.382 -
  16.383 -	/* Allocate temporary buffer for loading and converting the patterns */
  16.384 -	if(!(patbuf=(MODNOTE*)_mm_calloc(64U*4,sizeof(MODNOTE)))) return 0;
  16.385 -
  16.386 -	for(t=0;t<of.numpat;t++) {
  16.387 -		/* Load the pattern into the temp buffer and convert it */
  16.388 -		for(s=0;s<(64U*4);s++) {
  16.389 -			patbuf[s].a=_mm_read_UBYTE(modreader);
  16.390 -			patbuf[s].b=_mm_read_UBYTE(modreader);
  16.391 -			patbuf[s].c=_mm_read_UBYTE(modreader);
  16.392 -			patbuf[s].d=_mm_read_UBYTE(modreader);
  16.393 -		}
  16.394 -
  16.395 -		for(s=0;s<4;s++)
  16.396 -			if(!(of.tracks[tracks++]=M15_ConvertTrack(patbuf+s))) return 0;
  16.397 -	}
  16.398 -	return 1;
  16.399 -}
  16.400 -
  16.401 -static BOOL M15_Load(BOOL curious)
  16.402 -{
  16.403 -	int t,scan;
  16.404 -	SAMPLE *q;
  16.405 -	MSAMPINFO *s;
  16.406 -
  16.407 -	/* try to read module header */
  16.408 -	if(!LoadModuleHeader(mh)) {
  16.409 -		_mm_errno = MMERR_LOADING_HEADER;
  16.410 -		return 0;
  16.411 -	}
  16.412 -
  16.413 -	if(ust_loader)
  16.414 -		of.modtype = strdup("Ultimate Soundtracker");
  16.415 -	else
  16.416 -		of.modtype = strdup("Soundtracker");
  16.417 -
  16.418 -	/* set module variables */
  16.419 -	of.initspeed = 6;
  16.420 -	of.inittempo = 125;
  16.421 -	of.numchn    = 4;				
  16.422 -	of.songname  = DupStr(mh->songname,21,1);
  16.423 -	of.numpos    = mh->songlength;
  16.424 -	of.reppos    = 0;
  16.425 -
  16.426 -	/* Count the number of patterns */
  16.427 -	of.numpat = 0;
  16.428 -	for(t=0;t<of.numpos;t++)
  16.429 -		if(mh->positions[t]>of.numpat)
  16.430 -			of.numpat=mh->positions[t];
  16.431 -	/* since some old modules embed extra patterns, we have to check the
  16.432 -	   whole list to get the samples' file offsets right - however we can find
  16.433 -	   garbage here, so check carefully */
  16.434 -	scan=1;
  16.435 -	for(t=of.numpos;t<128;t++)
  16.436 -		if(mh->positions[t]>=0x80) scan=0;
  16.437 -	if (scan)
  16.438 -		for(t=of.numpos;t<128;t++) {
  16.439 -			if(mh->positions[t]>of.numpat)
  16.440 -				of.numpat=mh->positions[t];
  16.441 -			if((curious)&&(mh->positions[t])) of.numpos=t+1;
  16.442 -		}
  16.443 -	of.numpat++;
  16.444 -	of.numtrk = of.numpat*of.numchn;
  16.445 -
  16.446 -	if(!AllocPositions(of.numpos)) return 0;
  16.447 -	for(t=0;t<of.numpos;t++)
  16.448 -		of.positions[t]=mh->positions[t];
  16.449 -
  16.450 -	/* Finally, init the sampleinfo structures */
  16.451 -	of.numins=of.numsmp=15;
  16.452 -	if(!AllocSamples()) return 0;
  16.453 -
  16.454 -	s = mh->samples;
  16.455 -	q = of.samples;
  16.456 -
  16.457 -	for(t=0;t<of.numins;t++) {
  16.458 -		/* convert the samplename */
  16.459 -		q->samplename = DupStr(s->samplename,23,1);
  16.460 -
  16.461 -		/* init the sampleinfo variables and convert the size pointers */
  16.462 -		q->speed     = finetune[s->finetune&0xf];
  16.463 -		q->volume    = s->volume;
  16.464 -		if(ust_loader)
  16.465 -			q->loopstart = s->reppos;
  16.466 -		else
  16.467 -			q->loopstart = s->reppos<<1;
  16.468 -		q->loopend   = q->loopstart+(s->replen<<1);
  16.469 -		q->length    = s->length<<1;
  16.470 -
  16.471 -		q->flags = SF_SIGNED;
  16.472 -	   	if(ust_loader) q->flags |= SF_UST_LOOP;
  16.473 -		if(s->replen>2) q->flags |= SF_LOOP;
  16.474 -
  16.475 -		s++;
  16.476 -		q++;
  16.477 -	}
  16.478 -
  16.479 -	if(!M15_LoadPatterns()) return 0;
  16.480 -	ust_loader = 0;
  16.481 -
  16.482 -	return 1;
  16.483 -}
  16.484 -
  16.485 -static CHAR *M15_LoadTitle(void)
  16.486 -{
  16.487 -	CHAR s[21];
  16.488 -
  16.489 -	_mm_fseek(modreader,0,SEEK_SET);
  16.490 -	if(!_mm_read_UBYTES(s,20,modreader)) return NULL;
  16.491 -	s[20]=0;	/* just in case */
  16.492 -	return(DupStr(s,21,1));
  16.493 -}
  16.494 -
  16.495 -/*========== Loader information */
  16.496 -
  16.497 -MIKMODAPI MLOADER load_m15={
  16.498 -	NULL,
  16.499 -	"15-instrument module",
  16.500 -	"MOD (15 instrument)",
  16.501 -	M15_Init,
  16.502 -	M15_Test,
  16.503 -	M15_Load,
  16.504 -	M15_Cleanup,
  16.505 -	M15_LoadTitle
  16.506 -};
  16.507 -
  16.508 -/* ex:set ts=4: */
    17.1 --- a/mikmod/load_med.c	Sat Oct 03 10:53:24 2009 +0000
    17.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.3 @@ -1,719 +0,0 @@
    17.4 -/*	MikMod sound library
    17.5 -	(c) 1998, 1999, 2000, 2001, 2002 Miodrag Vallat and others - see file
    17.6 -	AUTHORS for complete list.
    17.7 -
    17.8 -	This library is free software; you can redistribute it and/or modify
    17.9 -	it under the terms of the GNU Library General Public License as
   17.10 -	published by the Free Software Foundation; either version 2 of
   17.11 -	the License, or (at your option) any later version.
   17.12 - 
   17.13 -	This program is distributed in the hope that it will be useful,
   17.14 -	but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.15 -	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17.16 -	GNU Library General Public License for more details.
   17.17 - 
   17.18 -	You should have received a copy of the GNU Library General Public
   17.19 -	License along with this library; if not, write to the Free Software
   17.20 -	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   17.21 -	02111-1307, USA.
   17.22 -*/
   17.23 -
   17.24 -/*==============================================================================
   17.25 -
   17.26 -  $Id: load_med.c,v 1.1.1.1 2004/06/01 12:16:17 raph Exp $
   17.27 -
   17.28 -  Amiga MED module loader
   17.29 -
   17.30 -==============================================================================*/
   17.31 -
   17.32 -#ifdef HAVE_CONFIG_H
   17.33 -#include "config.h"
   17.34 -#endif
   17.35 -
   17.36 -#ifdef HAVE_UNISTD_H
   17.37 -#include <unistd.h>
   17.38 -#endif
   17.39 -
   17.40 -#include <stdio.h>
   17.41 -#ifdef HAVE_MEMORY_H
   17.42 -#include <memory.h>
   17.43 -#endif
   17.44 -#include <string.h>
   17.45 -
   17.46 -#include "mikmod_internals.h"
   17.47 -
   17.48 -#ifdef SUNOS
   17.49 -extern int fprintf(FILE *, const char *, ...);
   17.50 -#endif
   17.51 -
   17.52 -/*========== Module information */
   17.53 -
   17.54 -typedef struct MEDHEADER {
   17.55 -	ULONG id;
   17.56 -	ULONG modlen;
   17.57 -	ULONG MEDSONGP;				/* struct MEDSONG *song; */
   17.58 -	UWORD psecnum;				/* for the player routine, MMD2 only */
   17.59 -	UWORD pseq;					/*  "   "   "   " */
   17.60 -	ULONG MEDBlockPP;			/* struct MEDBlock **blockarr; */
   17.61 -	ULONG reserved1;
   17.62 -	ULONG MEDINSTHEADERPP;		/* struct MEDINSTHEADER **smplarr; */
   17.63 -	ULONG reserved2;
   17.64 -	ULONG MEDEXPP;				/* struct MEDEXP *expdata; */
   17.65 -	ULONG reserved3;
   17.66 -	UWORD pstate;				/* some data for the player routine */
   17.67 -	UWORD pblock;
   17.68 -	UWORD pline;
   17.69 -	UWORD pseqnum;
   17.70 -	SWORD actplayline;
   17.71 -	UBYTE counter;
   17.72 -	UBYTE extra_songs;			/* number of songs - 1 */
   17.73 -} MEDHEADER;
   17.74 -
   17.75 -typedef struct MEDSAMPLE {
   17.76 -	UWORD rep, replen;			/* offs: 0(s), 2(s) */
   17.77 -	UBYTE midich;				/* offs: 4(s) */
   17.78 -	UBYTE midipreset;			/* offs: 5(s) */
   17.79 -	UBYTE svol;					/* offs: 6(s) */
   17.80 -	SBYTE strans;				/* offs: 7(s) */
   17.81 -} MEDSAMPLE;
   17.82 -
   17.83 -typedef struct MEDSONG {
   17.84 -	MEDSAMPLE sample[63];		/* 63 * 8 bytes = 504 bytes */
   17.85 -	UWORD numblocks;			/* offs: 504 */
   17.86 -	UWORD songlen;				/* offs: 506 */
   17.87 -	UBYTE playseq[256];			/* offs: 508 */
   17.88 -	UWORD deftempo;				/* offs: 764 */
   17.89 -	SBYTE playtransp;			/* offs: 766 */
   17.90 -	UBYTE flags;				/* offs: 767 */
   17.91 -	UBYTE flags2;				/* offs: 768 */
   17.92 -	UBYTE tempo2;				/* offs: 769 */
   17.93 -	UBYTE trkvol[16];			/* offs: 770 */
   17.94 -	UBYTE mastervol;			/* offs: 786 */
   17.95 -	UBYTE numsamples;			/* offs: 787 */
   17.96 -} MEDSONG;
   17.97 -
   17.98 -typedef struct MEDEXP {
   17.99 -	ULONG nextmod;				/* pointer to next module */
  17.100 -	ULONG exp_smp;				/* pointer to MEDINSTEXT array */
  17.101 -	UWORD s_ext_entries;
  17.102 -	UWORD s_ext_entrsz;
  17.103 -	ULONG annotxt;				/* pointer to annotation text */
  17.104 -	ULONG annolen;
  17.105 -	ULONG iinfo;				/* pointer to MEDINSTINFO array */
  17.106 -	UWORD i_ext_entries;
  17.107 -	UWORD i_ext_entrsz;
  17.108 -	ULONG jumpmask;
  17.109 -	ULONG rgbtable;
  17.110 -	ULONG channelsplit;
  17.111 -	ULONG n_info;
  17.112 -	ULONG songname;				/* pointer to songname */
  17.113 -	ULONG songnamelen;
  17.114 -	ULONG dumps;
  17.115 -	ULONG reserved2[7];
  17.116 -} MEDEXP;
  17.117 -
  17.118 -typedef struct MMD0NOTE {
  17.119 -	UBYTE a, b, c;
  17.120 -} MMD0NOTE;
  17.121 -
  17.122 -typedef struct MMD1NOTE {
  17.123 -	UBYTE a, b, c, d;
  17.124 -} MMD1NOTE;
  17.125 -
  17.126 -typedef struct MEDINSTHEADER {
  17.127 -	ULONG length;
  17.128 -	SWORD type;
  17.129 -	/* Followed by actual data */
  17.130 -} MEDINSTHEADER;
  17.131 -
  17.132 -typedef struct MEDINSTEXT {
  17.133 -	UBYTE hold;
  17.134 -	UBYTE decay;
  17.135 -	UBYTE suppress_midi_off;
  17.136 -	SBYTE finetune;
  17.137 -} MEDINSTEXT;
  17.138 -
  17.139 -typedef struct MEDINSTINFO {
  17.140 -	UBYTE name[40];
  17.141 -} MEDINSTINFO;
  17.142 -
  17.143 -/*========== Loader variables */
  17.144 -
  17.145 -#define MMD0_string 0x4D4D4430
  17.146 -#define MMD1_string 0x4D4D4431
  17.147 -
  17.148 -static MEDHEADER *mh = NULL;
  17.149 -static MEDSONG *ms = NULL;
  17.150 -static MEDEXP *me = NULL;
  17.151 -static ULONG *ba = NULL;
  17.152 -static MMD0NOTE *mmd0pat = NULL;
  17.153 -static MMD1NOTE *mmd1pat = NULL;
  17.154 -
  17.155 -static BOOL decimalvolumes;
  17.156 -static BOOL bpmtempos;
  17.157 -
  17.158 -#define d0note(row,col) mmd0pat[((row)*(UWORD)of.numchn)+(col)]
  17.159 -#define d1note(row,col) mmd1pat[((row)*(UWORD)of.numchn)+(col)]
  17.160 -
  17.161 -static CHAR MED_Version[] = "OctaMED (MMDx)";
  17.162 -
  17.163 -/*========== Loader code */
  17.164 -
  17.165 -BOOL MED_Test(void)
  17.166 -{
  17.167 -	UBYTE id[4];
  17.168 -
  17.169 -	if (!_mm_read_UBYTES(id, 4, modreader))
  17.170 -		return 0;
  17.171 -	if ((!memcmp(id, "MMD0", 4)) || (!memcmp(id, "MMD1", 4)))
  17.172 -		return 1;
  17.173 -	return 0;
  17.174 -}
  17.175 -
  17.176 -BOOL MED_Init(void)
  17.177 -{
  17.178 -	if (!(me = (MEDEXP *)_mm_malloc(sizeof(MEDEXP))))
  17.179 -		return 0;
  17.180 -	if (!(mh = (MEDHEADER *)_mm_malloc(sizeof(MEDHEADER))))
  17.181 -		return 0;
  17.182 -	if (!(ms = (MEDSONG *)_mm_malloc(sizeof(MEDSONG))))
  17.183 -		return 0;
  17.184 -	return 1;
  17.185 -}
  17.186 -
  17.187 -void MED_Cleanup(void)
  17.188 -{
  17.189 -	_mm_free(me);
  17.190 -	_mm_free(mh);
  17.191 -	_mm_free(ms);
  17.192 -	_mm_free(ba);
  17.193 -	_mm_free(mmd0pat);
  17.194 -	_mm_free(mmd1pat);
  17.195 -}
  17.196 -
  17.197 -static void EffectCvt(UBYTE eff, UBYTE dat)
  17.198 -{
  17.199 -	switch (eff) {
  17.200 -		/* 0x0 0x1 0x2 0x3 0x4 PT effects */
  17.201 -	  case 0x5:				/* PT vibrato with speed/depth nibbles swapped */
  17.202 -		UniPTEffect(0x4, (dat >> 4) | ((dat & 0xf) << 4));
  17.203 -		break;
  17.204 -		/* 0x6 0x7 not used */
  17.205 -	  case 0x6:
  17.206 -	  case 0x7:
  17.207 -		break;
  17.208 -	  case 0x8:				/* midi hold/decay */
  17.209 -		break;
  17.210 -	  case 0x9:
  17.211 -		if (bpmtempos) {
  17.212 -			if (!dat)
  17.213 -				dat = of.initspeed;
  17.214 -			UniEffect(UNI_S3MEFFECTA, dat);
  17.215 -		} else {
  17.216 -			if (dat <= 0x20) {
  17.217 -				if (!dat)
  17.218 -					dat = of.initspeed;
  17.219 -				else
  17.220 -					dat /= 4;
  17.221 -				UniPTEffect(0xf, dat);
  17.222 -			} else
  17.223 -				UniEffect(UNI_MEDSPEED, ((UWORD)dat * 125) / (33 * 4));
  17.224 -		}
  17.225 -		break;
  17.226 -		/* 0xa 0xb PT effects */
  17.227 -	  case 0xc:
  17.228 -		if (decimalvolumes)
  17.229 -			dat = (dat >> 4) * 10 + (dat & 0xf);
  17.230 -		UniPTEffect(0xc, dat);
  17.231 -		break;
  17.232 -	  case 0xd:				/* same as PT volslide */
  17.233 -		UniPTEffect(0xa, dat);
  17.234 -		break;
  17.235 -	  case 0xe:				/* synth jmp - midi */
  17.236 -		break;
  17.237 -	  case 0xf:
  17.238 -		switch (dat) {
  17.239 -		  case 0:				/* patternbreak */
  17.240 -			UniPTEffect(0xd, 0);
  17.241 -			break;
  17.242 -		  case 0xf1:			/* play note twice */
  17.243 -			UniWriteByte(UNI_MEDEFFECTF1);
  17.244 -			break;
  17.245 -		  case 0xf2:			/* delay note */
  17.246 -			UniWriteByte(UNI_MEDEFFECTF2);
  17.247 -			break;
  17.248 -		  case 0xf3:			/* play note three times */
  17.249 -			UniWriteByte(UNI_MEDEFFECTF3);
  17.250 -			break;
  17.251 -		  case 0xfe:			/* stop playing */
  17.252 -			UniPTEffect(0xb, of.numpat);
  17.253 -			break;
  17.254 -		  case 0xff:			/* note cut */
  17.255 -			UniPTEffect(0xc, 0);
  17.256 -			break;
  17.257 -		  default:
  17.258 -			if (dat <= 10)
  17.259 -				UniPTEffect(0xf, dat);
  17.260 -			else if (dat <= 240) {
  17.261 -				if (bpmtempos)
  17.262 -					UniPTEffect(0xf, (dat < 32) ? 32 : dat);
  17.263 -				else
  17.264 -					UniEffect(UNI_MEDSPEED, ((UWORD)dat * 125) / 33);
  17.265 -			}
  17.266 -		}
  17.267 -		break;
  17.268 -	  default:					/* all normal PT effects are handled here */
  17.269 -		UniPTEffect(eff, dat);
  17.270 -		break;
  17.271 -	}
  17.272 -}
  17.273 -
  17.274 -static UBYTE *MED_Convert1(int count, int col)
  17.275 -{
  17.276 -	int t;
  17.277 -	UBYTE inst, note, eff, dat;
  17.278 -	MMD1NOTE *n;
  17.279 -
  17.280 -	UniReset();
  17.281 -	for (t = 0; t < count; t++) {
  17.282 -		n = &d1note(t, col);
  17.283 -
  17.284 -		note = n->a & 0x7f;
  17.285 -		inst = n->b & 0x3f;
  17.286 -		eff = n->c & 0xf;
  17.287 -		dat = n->d;
  17.288 -
  17.289 -		if (inst)
  17.290 -			UniInstrument(inst - 1);
  17.291 -		if (note)
  17.292 -			UniNote(note + 3 * OCTAVE - 1);
  17.293 -		EffectCvt(eff, dat);
  17.294 -		UniNewline();
  17.295 -	}
  17.296 -	return UniDup();
  17.297 -}
  17.298 -
  17.299 -static UBYTE *MED_Convert0(int count, int col)
  17.300 -{
  17.301 -	int t;
  17.302 -	UBYTE a, b, inst, note, eff, dat;
  17.303 -	MMD0NOTE *n;
  17.304 -
  17.305 -	UniReset();
  17.306 -	for (t = 0; t < count; t++) {
  17.307 -		n = &d0note(t, col);
  17.308 -		a = n->a;
  17.309 -		b = n->b;
  17.310 -
  17.311 -		note = a & 0x3f;
  17.312 -		a >>= 6;
  17.313 -		a = ((a & 1) << 1) | (a >> 1);
  17.314 -		inst = (b >> 4) | (a << 4);
  17.315 -		eff = b & 0xf;
  17.316 -		dat = n->c;
  17.317 -
  17.318 -		if (inst)
  17.319 -			UniInstrument(inst - 1);
  17.320 -		if (note)
  17.321 -			UniNote(note + 3 * OCTAVE - 1);
  17.322 -		EffectCvt(eff, dat);
  17.323 -		UniNewline();
  17.324 -	}
  17.325 -	return UniDup();
  17.326 -}
  17.327 -
  17.328 -static BOOL LoadMEDPatterns(void)
  17.329 -{
  17.330 -	int t, row, col;
  17.331 -	UWORD numtracks, numlines, maxlines = 0, track = 0;
  17.332 -	MMD0NOTE *mmdp;
  17.333 -
  17.334 -	/* first, scan patterns to see how many channels are used */
  17.335 -	for (t = 0; t < of.numpat; t++) {
  17.336 -		_mm_fseek(modreader, ba[t], SEEK_SET);
  17.337 -		numtracks = _mm_read_UBYTE(modreader);
  17.338 -		numlines = _mm_read_UBYTE(modreader);
  17.339 -
  17.340 -		if (numtracks > of.numchn)
  17.341 -			of.numchn = numtracks;
  17.342 -		if (numlines > maxlines)
  17.343 -			maxlines = numlines;
  17.344 -	}
  17.345 -
  17.346 -	of.numtrk = of.numpat * of.numchn;
  17.347 -	if (!AllocTracks())
  17.348 -		return 0;
  17.349 -	if (!AllocPatterns())
  17.350 -		return 0;
  17.351 -
  17.352 -	if (!
  17.353 -		(mmd0pat =
  17.354 -		 (MMD0NOTE *)_mm_calloc(of.numchn * (maxlines + 1),
  17.355 -								sizeof(MMD0NOTE)))) return 0;
  17.356 -
  17.357 -	/* second read: read and convert patterns */
  17.358 -	for (t = 0; t < of.numpat; t++) {
  17.359 -		_mm_fseek(modreader, ba[t], SEEK_SET);
  17.360 -		numtracks = _mm_read_UBYTE(modreader);
  17.361 -		numlines = _mm_read_UBYTE(modreader);
  17.362 -
  17.363 -		of.pattrows[t] = ++numlines;
  17.364 -		memset(mmdp = mmd0pat, 0, of.numchn * maxlines * sizeof(MMD0NOTE));
  17.365 -		for (row = numlines; row; row--) {
  17.366 -			for (col = numtracks; col; col--, mmdp++) {
  17.367 -				mmdp->a = _mm_read_UBYTE(modreader);
  17.368 -				mmdp->b = _mm_read_UBYTE(modreader);
  17.369 -				mmdp->c = _mm_read_UBYTE(modreader);
  17.370 -			}
  17.371 -		}
  17.372 -
  17.373 -		for (col = 0; col < of.numchn; col++)
  17.374 -			of.tracks[track++] = MED_Convert0(numlines, col);
  17.375 -	}
  17.376 -	return 1;
  17.377 -}
  17.378 -
  17.379 -static BOOL LoadMMD1Patterns(void)
  17.380 -{
  17.381 -	int t, row, col;
  17.382 -	UWORD numtracks, numlines, maxlines = 0, track = 0;
  17.383 -	MMD1NOTE *mmdp;
  17.384 -
  17.385 -	/* first, scan patterns to see how many channels are used */
  17.386 -	for (t = 0; t < of.numpat; t++) {
  17.387 -		_mm_fseek(modreader, ba[t], SEEK_SET);
  17.388 -		numtracks = _mm_read_M_UWORD(modreader);
  17.389 -		numlines = _mm_read_M_UWORD(modreader);
  17.390 -		if (numtracks > of.numchn)
  17.391 -			of.numchn = numtracks;
  17.392 -		if (numlines > maxlines)
  17.393 -			maxlines = numlines;
  17.394 -	}
  17.395 -
  17.396 -	of.numtrk = of.numpat * of.numchn;
  17.397 -	if (!AllocTracks())
  17.398 -		return 0;
  17.399 -	if (!AllocPatterns())
  17.400 -		return 0;
  17.401 -
  17.402 -	if (!
  17.403 -		(mmd1pat =
  17.404 -		 (MMD1NOTE *)_mm_calloc(of.numchn * (maxlines + 1),
  17.405 -								sizeof(MMD1NOTE)))) return 0;
  17.406 -
  17.407 -	/* second read: really read and convert patterns */
  17.408 -	for (t = 0; t < of.numpat; t++) {
  17.409 -		_mm_fseek(modreader, ba[t], SEEK_SET);
  17.410 -		numtracks = _mm_read_M_UWORD(modreader);
  17.411 -		numlines = _mm_read_M_UWORD(modreader);
  17.412 -
  17.413 -		_mm_fseek(modreader, sizeof(ULONG), SEEK_CUR);
  17.414 -		of.pattrows[t] = ++numlines;
  17.415 -		memset(mmdp = mmd1pat, 0, of.numchn * maxlines * sizeof(MMD1NOTE));
  17.416 -
  17.417 -		for (row = numlines; row; row--) {
  17.418 -			for (col = numtracks; col; col--, mmdp++) {
  17.419 -				mmdp->a = _mm_read_UBYTE(modreader);
  17.420 -				mmdp->b = _mm_read_UBYTE(modreader);
  17.421 -				mmdp->c = _mm_read_UBYTE(modreader);
  17.422 -				mmdp->d = _mm_read_UBYTE(modreader);
  17.423 -			}
  17.424 -		}
  17.425 -
  17.426 -		for (col = 0; col < of.numchn; col++)
  17.427 -			of.tracks[track++] = MED_Convert1(numlines, col);
  17.428 -	}
  17.429 -	return 1;
  17.430 -}
  17.431 -
  17.432 -BOOL MED_Load(BOOL curious)
  17.433 -{
  17.434 -	int t;
  17.435 -	ULONG sa[64];
  17.436 -	MEDINSTHEADER s;
  17.437 -	SAMPLE *q;
  17.438 -	MEDSAMPLE *mss;
  17.439 -
  17.440 -	/* try to read module header */
  17.441 -	mh->id = _mm_read_M_ULONG(modreader);
  17.442 -	mh->modlen = _mm_read_M_ULONG(modreader);
  17.443 -	mh->MEDSONGP = _mm_read_M_ULONG(modreader);
  17.444 -	mh->psecnum = _mm_read_M_UWORD(modreader);
  17.445 -	mh->pseq = _mm_read_M_UWORD(modreader);
  17.446 -	mh->MEDBlockPP = _mm_read_M_ULONG(modreader);
  17.447 -	mh->reserved1 = _mm_read_M_ULONG(modreader);
  17.448 -	mh->MEDINSTHEADERPP = _mm_read_M_ULONG(modreader);
  17.449 -	mh->reserved2 = _mm_read_M_ULONG(modreader);
  17.450 -	mh->MEDEXPP = _mm_read_M_ULONG(modreader);
  17.451 -	mh->reserved3 = _mm_read_M_ULONG(modreader);
  17.452 -	mh->pstate = _mm_read_M_UWORD(modreader);
  17.453 -	mh->pblock = _mm_read_M_UWORD(modreader);
  17.454 -	mh->pline = _mm_read_M_UWORD(modreader);
  17.455 -	mh->pseqnum = _mm_read_M_UWORD(modreader);
  17.456 -	mh->actplayline = _mm_read_M_SWORD(modreader);
  17.457 -	mh->counter = _mm_read_UBYTE(modreader);
  17.458 -	mh->extra_songs = _mm_read_UBYTE(modreader);
  17.459 -
  17.460 -	/* Seek to MEDSONG struct */
  17.461 -	_mm_fseek(modreader, mh->MEDSONGP, SEEK_SET);
  17.462 -
  17.463 -	/* Load the MED Song Header */
  17.464 -	mss = ms->sample;			/* load the sample data first */
  17.465 -	for (t = 63; t; t--, mss++) {
  17.466 -		mss->rep = _mm_read_M_UWORD(modreader);
  17.467 -		mss->replen = _mm_read_M_UWORD(modreader);
  17.468 -		mss->midich = _mm_read_UBYTE(modreader);
  17.469 -		mss->midipreset = _mm_read_UBYTE(modreader);
  17.470 -		mss->svol = _mm_read_UBYTE(modreader);
  17.471 -		mss->strans = _mm_read_SBYTE(modreader);
  17.472 -	}
  17.473 -
  17.474 -	ms->numblocks = _mm_read_M_UWORD(modreader);
  17.475 -	ms->songlen = _mm_read_M_UWORD(modreader);
  17.476 -	_mm_read_UBYTES(ms->playseq, 256, modreader);
  17.477 -	ms->deftempo = _mm_read_M_UWORD(modreader);
  17.478 -	ms->playtransp = _mm_read_SBYTE(modreader);
  17.479 -	ms->flags = _mm_read_UBYTE(modreader);
  17.480 -	ms->flags2 = _mm_read_UBYTE(modreader);
  17.481 -	ms->tempo2 = _mm_read_UBYTE(modreader);
  17.482 -	_mm_read_UBYTES(ms->trkvol, 16, modreader);
  17.483 -	ms->mastervol = _mm_read_UBYTE(modreader);
  17.484 -	ms->numsamples = _mm_read_UBYTE(modreader);
  17.485 -
  17.486 -	/* check for a bad header */
  17.487 -	if (_mm_eof(modreader)) {
  17.488 -		_mm_errno = MMERR_LOADING_HEADER;
  17.489 -		return 0;
  17.490 -	}
  17.491 -
  17.492 -	/* load extension structure */
  17.493 -	if (mh->MEDEXPP) {
  17.494 -		_mm_fseek(modreader, mh->MEDEXPP, SEEK_SET);
  17.495 -		me->nextmod = _mm_read_M_ULONG(modreader);
  17.496 -		me->exp_smp = _mm_read_M_ULONG(modreader);
  17.497 -		me->s_ext_entries = _mm_read_M_UWORD(modreader);
  17.498 -		me->s_ext_entrsz = _mm_read_M_UWORD(modreader);
  17.499 -		me->annotxt = _mm_read_M_ULONG(modreader);
  17.500 -		me->annolen = _mm_read_M_ULONG(modreader);
  17.501 -		me->iinfo = _mm_read_M_ULONG(modreader);
  17.502 -		me->i_ext_entries = _mm_read_M_UWORD(modreader);
  17.503 -		me->i_ext_entrsz = _mm_read_M_UWORD(modreader);
  17.504 -		me->jumpmask = _mm_read_M_ULONG(modreader);
  17.505 -		me->rgbtable = _mm_read_M_ULONG(modreader);
  17.506 -		me->channelsplit = _mm_read_M_ULONG(modreader);
  17.507 -		me->n_info = _mm_read_M_ULONG(modreader);
  17.508 -		me->songname = _mm_read_M_ULONG(modreader);
  17.509 -		me->songnamelen = _mm_read_M_ULONG(modreader);
  17.510 -		me->dumps = _mm_read_M_ULONG(modreader);
  17.511 -	}
  17.512 -
  17.513 -	/* seek to and read the samplepointer array */
  17.514 -	_mm_fseek(modreader, mh->MEDINSTHEADERPP, SEEK_SET);
  17.515 -	if (!_mm_read_M_ULONGS(sa, ms->numsamples, modreader)) {
  17.516 -		_mm_errno = MMERR_LOADING_HEADER;
  17.517 -		return 0;
  17.518 -	}
  17.519 -
  17.520 -	/* alloc and read the blockpointer array */
  17.521 -	if (!(ba = (ULONG *)_mm_calloc(ms->numblocks, sizeof(ULONG))))
  17.522 -		return 0;
  17.523 -	_mm_fseek(modreader, mh->MEDBlockPP, SEEK_SET);
  17.524 -	if (!_mm_read_M_ULONGS(ba, ms->numblocks, modreader)) {
  17.525 -		_mm_errno = MMERR_LOADING_HEADER;
  17.526 -		return 0;
  17.527 -	}
  17.528 -
  17.529 -	/* copy song positions */
  17.530 -	if (!AllocPositions(ms->songlen))
  17.531 -		return 0;
  17.532 -	for (t = 0; t < ms->songlen; t++)
  17.533 -		of.positions[t] = ms->playseq[t];
  17.534 -
  17.535 -	decimalvolumes = (ms->flags & 0x10) ? 0 : 1;
  17.536 -	bpmtempos = (ms->flags2 & 0x20) ? 1 : 0;
  17.537 -
  17.538 -	if (bpmtempos) {
  17.539 -		int bpmlen = (ms->flags2 & 0x1f) + 1;
  17.540 -		of.initspeed = ms->tempo2;
  17.541 -		of.inittempo = ms->deftempo * bpmlen / 4;
  17.542 -
  17.543 -		if (bpmlen != 4) {
  17.544 -			/* Let's do some math : compute GCD of BPM beat length and speed */
  17.545 -			int a, b;
  17.546 -
  17.547 -			a = bpmlen;
  17.548 -			b = ms->tempo2;
  17.549 -
  17.550 -			if (a > b) {
  17.551 -				t = b;
  17.552 -				b = a;
  17.553 -				a = t;
  17.554 -			}
  17.555 -			while ((a != b) && (a)) {
  17.556 -				t = a;
  17.557 -				a = b - a;
  17.558 -				b = t;
  17.559 -				if (a > b) {
  17.560 -					t = b;
  17.561 -					b = a;
  17.562 -					a = t;
  17.563 -				}
  17.564 -			}
  17.565 -
  17.566 -			of.initspeed /= b;
  17.567 -			of.inittempo = ms->deftempo * bpmlen / (4 * b);
  17.568 -		}
  17.569 -	} else {
  17.570 -		of.initspeed = ms->tempo2;
  17.571 -		of.inittempo = ms->deftempo ? ((UWORD)ms->deftempo * 125) / 33 : 128;
  17.572 -		if ((ms->deftempo <= 10) && (ms->deftempo))
  17.573 -			of.inittempo = (of.inittempo * 33) / 6;
  17.574 -		of.flags |= UF_HIGHBPM;
  17.575 -	}
  17.576 -	MED_Version[12] = mh->id;
  17.577 -	of.modtype = strdup(MED_Version);
  17.578 -	of.numchn = 0;				/* will be counted later */
  17.579 -	of.numpat = ms->numblocks;
  17.580 -	of.numpos = ms->songlen;
  17.581 -	of.numins = ms->numsamples;
  17.582 -	of.numsmp = of.numins;
  17.583 -	of.reppos = 0;
  17.584 -	if ((mh->MEDEXPP) && (me->songname) && (me->songnamelen)) {
  17.585 -		char *name;
  17.586 -
  17.587 -		_mm_fseek(modreader, me->songname, SEEK_SET);
  17.588 -		name = _mm_malloc(me->songnamelen);
  17.589 -		_mm_read_UBYTES(name, me->songnamelen, modreader);
  17.590 -		of.songname = DupStr(name, me->songnamelen, 1);
  17.591 -		free(name);
  17.592 -	} else
  17.593 -		of.songname = DupStr(NULL, 0, 0);
  17.594 -	if ((mh->MEDEXPP) && (me->annotxt) && (me->annolen)) {
  17.595 -		_mm_fseek(modreader, me->annotxt, SEEK_SET);
  17.596 -		ReadComment(me->annolen);
  17.597 -	}
  17.598 -
  17.599 -	if (!AllocSamples())
  17.600 -		return 0;
  17.601 -	q = of.samples;
  17.602 -	for (t = 0; t < of.numins; t++) {
  17.603 -		q->flags = SF_SIGNED;
  17.604 -		q->volume = 64;
  17.605 -		if (sa[t]) {
  17.606 -			_mm_fseek(modreader, sa[t], SEEK_SET);
  17.607 -			s.length = _mm_read_M_ULONG(modreader);
  17.608 -			s.type = _mm_read_M_SWORD(modreader);
  17.609 -
  17.610 -			if (s.type) {
  17.611 -#ifdef MIKMOD_DEBUG
  17.612 -				fprintf(stderr, "\rNon-sample instruments not supported in MED loader yet\n");
  17.613 -#endif
  17.614 -				if (!curious) {
  17.615 -					_mm_errno = MMERR_MED_SYNTHSAMPLES;
  17.616 -					return 0;
  17.617 -				}
  17.618 -				s.length = 0;
  17.619 -			}
  17.620 -
  17.621 -			if (_mm_eof(modreader)) {
  17.622 -				_mm_errno = MMERR_LOADING_SAMPLEINFO;
  17.623 -				return 0;
  17.624 -			}
  17.625 -
  17.626 -			q->length = s.length;
  17.627 -			q->seekpos = _mm_ftell(modreader);
  17.628 -			q->loopstart = ms->sample[t].rep << 1;
  17.629 -			q->loopend = q->loopstart + (ms->sample[t].replen << 1);
  17.630 -
  17.631 -			if (ms->sample[t].replen > 1)
  17.632 -				q->flags |= SF_LOOP;
  17.633 -
  17.634 -			/* don't load sample if length>='MMD0'...
  17.635 -			   such kluges make libmikmod's code unique !!! */
  17.636 -			if (q->length >= MMD0_string)
  17.637 -				q->length = 0;
  17.638 -		} else
  17.639 -			q->length = 0;
  17.640 -
  17.641 -		if ((mh->MEDEXPP) && (me->exp_smp) &&
  17.642 -			(t < me->s_ext_entries) && (me->s_ext_entrsz >= 4)) {
  17.643 -			MEDINSTEXT ie;
  17.644 -
  17.645 -			_mm_fseek(modreader, me->exp_smp + t * me->s_ext_entrsz,
  17.646 -					  SEEK_SET);
  17.647 -			ie.hold = _mm_read_UBYTE(modreader);
  17.648 -			ie.decay = _mm_read_UBYTE(modreader);
  17.649 -			ie.suppress_midi_off = _mm_read_UBYTE(modreader);
  17.650 -			ie.finetune = _mm_read_SBYTE(modreader);
  17.651 -
  17.652 -			q->speed = finetune[ie.finetune & 0xf];
  17.653 -		} else
  17.654 -			q->speed = 8363;
  17.655 -
  17.656 -		if ((mh->MEDEXPP) && (me->iinfo) &&
  17.657 -			(t < me->i_ext_entries) && (me->i_ext_entrsz >= 40)) {
  17.658 -			MEDINSTINFO ii;
  17.659 -
  17.660 -			_mm_fseek(modreader, me->iinfo + t * me->i_ext_entrsz, SEEK_SET);
  17.661 -			_mm_read_UBYTES(ii.name, 40, modreader);
  17.662 -			q->samplename = DupStr((char*)ii.name, 40, 1);
  17.663 -		} else
  17.664 -			q->samplename = NULL;
  17.665 -
  17.666 -		q++;
  17.667 -	}
  17.668 -
  17.669 -	if (mh->id == MMD0_string) {
  17.670 -		if (!LoadMEDPatterns()) {
  17.671 -			_mm_errno = MMERR_LOADING_PATTERN;
  17.672 -			return 0;
  17.673 -		}
  17.674 -	} else if (mh->id == MMD1_string) {
  17.675 -		if (!LoadMMD1Patterns()) {
  17.676 -			_mm_errno = MMERR_LOADING_PATTERN;
  17.677 -			return 0;
  17.678 -		}
  17.679 -	} else {
  17.680 -		_mm_errno = MMERR_NOT_A_MODULE;
  17.681 -		return 0;
  17.682 -	}
  17.683 -	return 1;
  17.684 -}
  17.685 -
  17.686 -CHAR *MED_LoadTitle(void)
  17.687 -{
  17.688 -	ULONG posit, namelen;
  17.689 -	CHAR *name, *retvalue = NULL;
  17.690 -	
  17.691 -	_mm_fseek(modreader, 0x20, SEEK_SET);
  17.692 -	posit = _mm_read_M_ULONG(modreader);
  17.693 -	
  17.694 -	if (posit) {
  17.695 -		_mm_fseek(modreader, posit + 0x2C, SEEK_SET);
  17.696 -		posit = _mm_read_M_ULONG(modreader);
  17.697 -		namelen = _mm_read_M_ULONG(modreader);
  17.698 -
  17.699 -		_mm_fseek(modreader, posit, SEEK_SET);
  17.700 -		name = _mm_malloc(namelen);
  17.701 -		_mm_read_UBYTES(name, namelen, modreader);
  17.702 -		retvalue = DupStr(name, namelen, 1);
  17.703 -		free(name);
  17.704 -	}
  17.705 -
  17.706 -	return retvalue;
  17.707 -}
  17.708 -
  17.709 -/*========== Loader information */
  17.710 -
  17.711 -MIKMODAPI MLOADER load_med = {
  17.712 -	NULL,
  17.713 -	"MED",
  17.714 -	"MED (OctaMED)",
  17.715 -	MED_Init,
  17.716 -	MED_Test,
  17.717 -	MED_Load,
  17.718 -	MED_Cleanup,
  17.719 -	MED_LoadTitle
  17.720 -};
  17.721 -
  17.722 -/* ex:set ts=4: */
    18.1 --- a/mikmod/load_mod.c	Sat Oct 03 10:53:24 2009 +0000
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,512 +0,0 @@
    18.4 -/*	MikMod sound library
    18.5 -	(c) 1998, 1999, 2000, 2001, 2002 Miodrag Vallat and others - see file
    18.6 -	AUTHORS for complete list.
    18.7 -
    18.8 -	This library is free software; you can redistribute it and/or modify
    18.9 -	it under the terms of the GNU Library General Public License as
   18.10 -	published by the Free Software Foundation; either version 2 of
   18.11 -	the License, or (at your option) any later version.
   18.12 - 
   18.13 -	This program is distributed in the hope that it will be useful,
   18.14 -	but WITHOUT ANY WARRANTY; without even the implied warranty of
   18.15 -	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18.16 -	GNU Library General Public License for more details.
   18.17 - 
   18.18 -	You should have received a copy of the GNU Library General Public
   18.19 -	License along with this library; if not, write to the Free Software
   18.20 -	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   18.21 -	02111-1307, USA.
   18.22 -*/
   18.23 -
   18.24 -/*==============================================================================
   18.25 -
   18.26 -  $Id$
   18.27 -
   18.28 -  Generic MOD loader (Protracker, StarTracker, FastTracker, etc)
   18.29 -
   18.30 -==============================================================================*/
   18.31 -
   18.32 -#ifdef HAVE_CONFIG_H
   18.33 -#include "config.h"
   18.34 -#endif
   18.35 -
   18.36 -#ifdef HAVE_UNISTD_H
   18.37 -#include <unistd.h>
   18.38 -#endif
   18.39 -
   18.40 -#include <ctype.h>
   18.41 -#include <stdio.h>
   18.42 -#ifdef HAVE_MEMORY_H
   18.43 -#include <memory.h>
   18.44 -#endif
   18.45 -#include <string.h>
   18.46 -
   18.47 -#include "mikmod_internals.h"
   18.48 -
   18.49 -#ifdef SUNOS
   18.50 -extern int fprintf(FILE *, const char *, ...);
   18.51 -#endif
   18.52 -
   18.53 -/*========== Module structure */
   18.54 -
   18.55 -typedef struct MSAMPINFO {
   18.56 -	CHAR samplename[23];		/* 22 in module, 23 in memory */
   18.57 -	UWORD length;
   18.58 -	UBYTE finetune;
   18.59 -	UBYTE volume;
   18.60 -	UWORD reppos;
   18.61 -	UWORD replen;
   18.62 -} MSAMPINFO;
   18.63 -
   18.64 -typedef struct MODULEHEADER {
   18.65 -	CHAR songname[21];			/* the songname.. 20 in module, 21 in memory */
   18.66 -	MSAMPINFO samples[31];		/* all sampleinfo */
   18.67 -	UBYTE songlength;			/* number of patterns used */
   18.68 -	UBYTE magic1;				/* should be 127 */
   18.69 -	UBYTE positions[128];		/* which pattern to play at pos */
   18.70 -	UBYTE magic2[4];			/* string "M.K." or "FLT4" or "FLT8" */
   18.71 -} MODULEHEADER;
   18.72 -
   18.73 -typedef struct MODTYPE {
   18.74 -	CHAR id[5];
   18.75 -	UBYTE channels;
   18.76 -	CHAR *name;
   18.77 -} MODTYPE;
   18.78 -
   18.79 -typedef struct MODNOTE {
   18.80 -	UBYTE a, b, c, d;
   18.81 -} MODNOTE;
   18.82 -
   18.83 -/*========== Loader variables */
   18.84 -
   18.85 -#define MODULEHEADERSIZE 0x438
   18.86 -
   18.87 -static CHAR protracker[] = "Protracker";
   18.88 -static CHAR startrekker[] = "Startrekker";
   18.89 -static CHAR fasttracker[] = "Fasttracker";
   18.90 -static CHAR oktalyser[] = "Oktalyser";
   18.91 -static CHAR oktalyzer[] = "Oktalyzer";
   18.92 -static CHAR taketracker[] = "TakeTracker";
   18.93 -static CHAR orpheus[] = "Imago Orpheus (MOD format)";
   18.94 -
   18.95 -static MODULEHEADER *mh = NULL;
   18.96 -static MODNOTE *patbuf = NULL;
   18.97 -static int modtype, trekker;
   18.98 -
   18.99 -/*========== Loader code */
  18.100 -
  18.101 -/* given the module ID, determine the number of channels and the tracker
  18.102 -   description ; also alters modtype */
  18.103 -static BOOL MOD_CheckType(UBYTE *id, UBYTE *numchn, CHAR **descr)
  18.104 -{
  18.105 -	modtype = trekker = 0;
  18.106 -
  18.107 -	/* Protracker and variants */
  18.108 -	if ((!memcmp(id, "M.K.", 4)) || (!memcmp(id, "M!K!", 4))) {
  18.109 -		*descr = protracker;
  18.110 -		modtype = 0;
  18.111 -		*numchn = 4;
  18.112 -		return 1;
  18.113 -	}
  18.114 -	
  18.115 -	/* Star Tracker */
  18.116 -	if (((!memcmp(id, "FLT", 3)) || (!memcmp(id, "EXO", 3))) &&
  18.117 -		(isdigit(id[3]))) {
  18.118 -		*descr = startrekker;
  18.119 -		modtype = trekker = 1;
  18.120 -		*numchn = id[3] - '0';
  18.121 -		if (*numchn == 4 || *numchn == 8)
  18.122 -			return 1;
  18.123 -#ifdef MIKMOD_DEBUG
  18.124 -		else
  18.125 -			fprintf(stderr, "\rUnknown FLT%d module type\n", *numchn);
  18.126 -#endif
  18.127 -		return 0;
  18.128 -	}
  18.129 -
  18.130 -	/* Oktalyzer (Amiga) */
  18.131 -	if (!memcmp(id, "OKTA", 4)) {
  18.132 -		*descr = oktalyzer;
  18.133 -		modtype = 1;
  18.134 -		*numchn = 8;
  18.135 -		return 1;
  18.136 -	}
  18.137 -
  18.138 -	/* Oktalyser (Atari) */
  18.139 -	if (!memcmp(id, "CD81", 4)) {
  18.140 -		*descr = oktalyser;
  18.141 -		modtype = 1;
  18.142 -		*numchn = 8;
  18.143 -		return 1;
  18.144 -	}
  18.145 -
  18.146 -	/* Fasttracker */
  18.147 -	if ((!memcmp(id + 1, "CHN", 3)) && (isdigit(id[0]))) {
  18.148 -		*descr = fasttracker;
  18.149 -		modtype = 1;
  18.150 -		*numchn = id[0] - '0';
  18.151 -		return 1;
  18.152 -	}
  18.153 -	/* Fasttracker or Taketracker */
  18.154 -	if (((!memcmp(id + 2, "CH", 2)) || (!memcmp(id + 2, "CN", 2)))
  18.155 -		&& (isdigit(id[0])) && (isdigit(id[1]))) {
  18.156 -		if (id[3] == 'H') {
  18.157 -			*descr = fasttracker;
  18.158 -			modtype = 2;		/* this can also be Imago Orpheus */
  18.159 -		} else {
  18.160 -			*descr = taketracker;
  18.161 -			modtype = 1;
  18.162 -		}
  18.163 -		*numchn = (id[0] - '0') * 10 + (id[1] - '0');
  18.164 -		return 1;
  18.165 -	}
  18.166 -
  18.167 -	return 0;
  18.168 -}
  18.169 -
  18.170 -static BOOL MOD_Test(void)
  18.171 -{
  18.172 -	UBYTE id[4], numchn;
  18.173 -	CHAR *descr;
  18.174 -
  18.175 -	_mm_fseek(modreader, MODULEHEADERSIZE, SEEK_SET);
  18.176 -	if (!_mm_read_UBYTES(id, 4, modreader))
  18.177 -		return 0;
  18.178 -
  18.179 -	if (MOD_CheckType(id, &numchn, &descr))
  18.180 -		return 1;
  18.181 -
  18.182 -	return 0;
  18.183 -}
  18.184 -
  18.185 -static BOOL MOD_Init(void)
  18.186 -{
  18.187 -	if (!(mh = (MODULEHEADER *)_mm_malloc(sizeof(MODULEHEADER))))
  18.188 -		return 0;
  18.189 -	return 1;
  18.190 -}
  18.191 -
  18.192 -static void MOD_Cleanup(void)
  18.193 -{
  18.194 -	_mm_free(mh);
  18.195 -	_mm_free(patbuf);
  18.196 -}
  18.197 -
  18.198 -/*
  18.199 -Old (amiga) noteinfo:
  18.200 -
  18.201 -_____byte 1_____   byte2_    _____byte 3_____   byte4_
  18.202 -/                \ /      \  /                \ /      \
  18.203 -0000          0000-00000000  0000          0000-00000000
  18.204 -
  18.205 -Upper four    12 bits for    Lower four    Effect command.
  18.206 -bits of sam-  note period.   bits of sam-
  18.207 -ple number.                  ple number.
  18.208 -
  18.209 -*/
  18.210 -
  18.211 -static UBYTE ConvertNote(MODNOTE *n, UBYTE lasteffect)
  18.212 -{
  18.213 -	UBYTE instrument, effect, effdat, note;
  18.214 -	UWORD period;
  18.215 -	UBYTE lastnote = 0;
  18.216 -
  18.217 -	/* extract the various information from the 4 bytes that make up a note */
  18.218 -	instrument = (n->a & 0x10) | (n->c >> 4);
  18.219 -	period = (((UWORD)n->a & 0xf) << 8) + n->b;
  18.220 -	effect = n->c & 0xf;
  18.221 -	effdat = n->d;
  18.222 -
  18.223 -	/* Convert the period to a note number */
  18.224 -	note = 0;
  18.225 -	if (period) {
  18.226 -		for (note = 0; note < 7 * OCTAVE; note++)
  18.227 -			if (period >= npertab[note])
  18.228 -				break;
  18.229 -		if (note == 7 * OCTAVE)
  18.230 -			note = 0;
  18.231 -		else
  18.232 -			note++;
  18.233 -	}
  18.234 -
  18.235 -	if (instrument) {
  18.236 -		/* if instrument does not exist, note cut */
  18.237 -		if ((instrument > 31) || (!mh->samples[instrument - 1].length)) {
  18.238 -			UniPTEffect(0xc, 0);
  18.239 -			if (effect == 0xc)
  18.240 -				effect = effdat = 0;
  18.241 -		} else {
  18.242 -			/* Protracker handling */
  18.243 -			if (!modtype) {
  18.244 -				/* if we had a note, then change instrument... */
  18.245 -				if (note)
  18.246 -					UniInstrument(instrument - 1);
  18.247 -				/* ...otherwise, only adjust volume... */
  18.248 -				else {
  18.249 -					/* ...unless an effect was specified, which forces a new
  18.250 -					   note to be played */
  18.251 -					if (effect || effdat) {
  18.252 -						UniInstrument(instrument - 1);
  18.253 -						note = lastnote;
  18.254 -					} else
  18.255 -						UniPTEffect(0xc,
  18.256 -									mh->samples[instrument -
  18.257 -												1].volume & 0x7f);
  18.258 -				}
  18.259 -			} else {
  18.260 -				/* Fasttracker handling */
  18.261 -				UniInstrument(instrument - 1);
  18.262 -				if (!note)
  18.263 -					note = lastnote;
  18.264 -			}
  18.265 -		}
  18.266 -	}
  18.267 -	if (note) {
  18.268 -		UniNote(note + 2 * OCTAVE - 1);
  18.269 -		lastnote = note;
  18.270 -	}
  18.271 -
  18.272 -	/* Convert pattern jump from Dec to Hex */
  18.273 -	if (effect == 0xd)
  18.274 -		effdat = (((effdat & 0xf0) >> 4) * 10) + (effdat & 0xf);
  18.275 -
  18.276 -	/* Volume slide, up has priority */
  18.277 -	if ((effect == 0xa) && (effdat & 0xf) && (effdat & 0xf0))
  18.278 -		effdat &= 0xf0;
  18.279 -
  18.280 -	/* Handle ``heavy'' volumes correctly */
  18.281 -	if ((effect == 0xc) && (effdat > 0x40))
  18.282 -		effdat = 0x40;
  18.283 -	
  18.284 -	/* An isolated 100, 200 or 300 effect should be ignored (no
  18.285 -	   "standalone" porta memory in mod files). However, a sequence such
  18.286 -	   as 1XX, 100, 100, 100 is fine. */
  18.287 -	if ((!effdat) && ((effect == 1)||(effect == 2)||(effect ==3)) &&
  18.288 -		(lasteffect < 0x10) && (effect != lasteffect))
  18.289 -		effect = 0;
  18.290 -
  18.291 -	UniPTEffect(effect, effdat);
  18.292 -	if (effect == 8)
  18.293 -		of.flags |= UF_PANNING;
  18.294 -	
  18.295 -	return effect;
  18.296 -}
  18.297 -
  18.298 -static UBYTE *ConvertTrack(MODNOTE *n, int numchn)
  18.299 -{
  18.300 -	int t;
  18.301 -	UBYTE lasteffect = 0x10;	/* non existant effect */
  18.302 -
  18.303 -	UniReset();
  18.304 -	for (t = 0; t < 64; t++) {
  18.305 -		lasteffect = ConvertNote(n,lasteffect);
  18.306 -		UniNewline();
  18.307 -		n += numchn;
  18.308 -	}
  18.309 -	return UniDup();
  18.310 -}
  18.311 -
  18.312 -/* Loads all patterns of a modfile and converts them into the 3 byte format. */
  18.313 -static BOOL ML_LoadPatterns(void)
  18.314 -{
  18.315 -	int t, s, tracks = 0;
  18.316 -
  18.317 -	if (!AllocPatterns())
  18.318 -		return 0;
  18.319 -	if (!AllocTracks())
  18.320 -		return 0;
  18.321 -	
  18.322 -	/* Allocate temporary buffer for loading and converting the patterns */
  18.323 -	if (!(patbuf = (MODNOTE *)_mm_calloc(64U * of.numchn, sizeof(MODNOTE))))
  18.324 -		return 0;
  18.325 -
  18.326 -	if (trekker && of.numchn == 8) {
  18.327 -		/* Startrekker module dual pattern */
  18.328 -		for (t = 0; t < of.numpat; t++) {
  18.329 -			for (s = 0; s < (64U * 4); s++) {
  18.330 -				patbuf[s].a = _mm_read_UBYTE(modreader);
  18.331 -				patbuf[s].b = _mm_read_UBYTE(modreader);
  18.332 -				patbuf[s].c = _mm_read_UBYTE(modreader);
  18.333 -				patbuf[s].d = _mm_read_UBYTE(modreader);
  18.334 -			}
  18.335 -			for (s = 0; s < 4; s++)
  18.336 -				if (!(of.tracks[tracks++] = ConvertTrack(patbuf + s, 4)))
  18.337 -					return 0;
  18.338 -			for (s = 0; s < (64U * 4); s++) {
  18.339 -				patbuf[s].a = _mm_read_UBYTE(modreader);
  18.340 -				patbuf[s].b = _mm_read_UBYTE(modreader);
  18.341 -				patbuf[s].c = _mm_read_UBYTE(modreader);
  18.342 -				patbuf[s].d = _mm_read_UBYTE(modreader);
  18.343 -			}
  18.344 -			for (s = 0; s < 4; s++)
  18.345 -				if (!(of.tracks[tracks++] = ConvertTrack(patbuf + s, 4)))
  18.346 -					return 0;
  18.347 -		}
  18.348 -	} else {
  18.349 -		/* Generic module pattern */
  18.350 -		for (t = 0; t < of.numpat; t++) {
  18.351 -			/* Load the pattern into the temp buffer and convert it */
  18.352 -			for (s = 0; s < (64U * of.numchn); s++) {
  18.353 -				patbuf[s].a = _mm_read_UBYTE(modreader);
  18.354 -				patbuf[s].b = _mm_read_UBYTE(modreader);
  18.355 -				patbuf[s].c = _mm_read_UBYTE(modreader);
  18.356 -				patbuf[s].d = _mm_read_UBYTE(modreader);
  18.357 -			}
  18.358 -			for (s = 0; s < of.numchn; s++)
  18.359 -				if (!(of.tracks[tracks++] = ConvertTrack(patbuf + s, of.numchn)))
  18.360 -					return 0;
  18.361 -		}
  18.362 -	}
  18.363 -	return 1;
  18.364 -}
  18.365 -
  18.366 -static BOOL MOD_Load(BOOL curious)
  18.367 -{
  18.368 -	int t, scan;
  18.369 -	SAMPLE *q;
  18.370 -	MSAMPINFO *s;
  18.371 -	CHAR *descr;
  18.372 -
  18.373 -	/* try to read module header */
  18.374 -	_mm_read_string((CHAR *)mh->songname, 20, modreader);
  18.375 -	mh->songname[20] = 0;		/* just in case */
  18.376 -
  18.377 -	for (t = 0; t < 31; t++) {
  18.378 -		s = &mh->samples[t];
  18.379 -		_mm_read_string(s->samplename, 22, modreader);
  18.380 -		s->samplename[22] = 0;	/* just in case */
  18.381 -		s->length = _mm_read_M_UWORD(modreader);
  18.382 -		s->finetune = _mm_read_UBYTE(modreader);
  18.383 -		s->volume = _mm_read_UBYTE(modreader);
  18.384 -		s->reppos = _mm_read_M_UWORD(modreader);
  18.385 -		s->replen = _mm_read_M_UWORD(modreader);
  18.386 -	}
  18.387 -
  18.388 -	mh->songlength = _mm_read_UBYTE(modreader);
  18.389 -
  18.390 -	/* this fixes mods which declare more than 128 positions. 
  18.391 -	 * eg: beatwave.mod */
  18.392 -	if (mh->songlength > 128) { mh->songlength = 128; }
  18.393 -	
  18.394 -	mh->magic1 = _mm_read_UBYTE(modreader);
  18.395 -	_mm_read_UBYTES(mh->positions, 128, modreader);
  18.396 -	_mm_read_UBYTES(mh->magic2, 4, modreader);
  18.397 -
  18.398 -	if (_mm_eof(modreader)) {
  18.399 -		_mm_errno = MMERR_LOADING_HEADER;
  18.400 -		return 0;
  18.401 -	}
  18.402 -
  18.403 -	/* set module variables */
  18.404 -	of.initspeed = 6;
  18.405 -	of.inittempo = 125;
  18.406 -	if (!(MOD_CheckType(mh->magic2, &of.numchn, &descr))) {
  18.407 -		_mm_errno = MMERR_NOT_A_MODULE;
  18.408 -		return 0;
  18.409 -	}
  18.410 -	if (trekker && of.numchn == 8)
  18.411 -		for (t = 0; t < 128; t++)
  18.412 -			/* if module pretends to be FLT8, yet the order table
  18.413 -			   contains odd numbers, chances are it's a lying FLT4... */
  18.414 -			if (mh->positions[t] & 1) {
  18.415 -				of.numchn = 4;
  18.416 -				break;
  18.417 -			}
  18.418 -	if (trekker && of.numchn == 8)
  18.419 -		for (t = 0; t < 128; t++)
  18.420 -			mh->positions[t] >>= 1;
  18.421 -
  18.422 -	of.songname = DupStr(mh->songname, 21, 1);
  18.423 -	of.numpos = mh->songlength;
  18.424 -	of.reppos = 0;
  18.425 -
  18.426 -	/* Count the number of patterns */
  18.427 -	of.numpat = 0;
  18.428 -	for (t = 0; t < of.numpos; t++)
  18.429 -		if (mh->positions[t] > of.numpat)
  18.430 -			of.numpat = mh->positions[t];
  18.431 -
  18.432 -	/* since some old modules embed extra patterns, we have to check the
  18.433 -	   whole list to get the samples' file offsets right - however we can find
  18.434 -	   garbage here, so check carefully */
  18.435 -	scan = 1;
  18.436 -	for (t = of.numpos; t < 128; t++)
  18.437 -		if (mh->positions[t] >= 0x80)
  18.438 -			scan = 0;
  18.439 -	if (scan)
  18.440 -		for (t = of.numpos; t < 128; t++) {
  18.441 -			if (mh->positions[t] > of.numpat)
  18.442 -				of.numpat = mh->positions[t];
  18.443 -			if ((curious) && (mh->positions[t]))
  18.444 -				of.numpos = t + 1;
  18.445 -		}
  18.446 -	of.numpat++;
  18.447 -	of.numtrk = of.numpat * of.numchn;
  18.448 -
  18.449 -	if (!AllocPositions(of.numpos))
  18.450 -		return 0;
  18.451 -	for (t = 0; t < of.numpos; t++)
  18.452 -		of.positions[t] = mh->positions[t];
  18.453 -
  18.454 -	/* Finally, init the sampleinfo structures  */
  18.455 -	of.numins = of.numsmp = 31;
  18.456 -	if (!AllocSamples())
  18.457 -		return 0;
  18.458 -	s = mh->samples;
  18.459 -	q = of.samples;
  18.460 -	for (t = 0; t < of.numins; t++) {
  18.461 -		/* convert the samplename */
  18.462 -		q->samplename = DupStr(s->samplename, 23, 1);
  18.463 -		/* init the sampleinfo variables and convert the size pointers */
  18.464 -		q->speed = finetune[s->finetune & 0xf];
  18.465 -		q->volume = s->volume & 0x7f;
  18.466 -		q->loopstart = (ULONG)s->reppos << 1;
  18.467 -		q->loopend = q->loopstart + ((ULONG)s->replen << 1);
  18.468 -		q->length = (ULONG)s->length << 1;
  18.469 -		q->flags = SF_SIGNED;
  18.470 -		/* Imago Orpheus creates MODs with 16 bit samples, check */
  18.471 -		if ((modtype == 2) && (s->volume & 0x80)) {
  18.472 -			q->flags |= SF_16BITS;
  18.473 -			descr = orpheus;
  18.474 -		}
  18.475 -		if (s->replen > 2)
  18.476 -			q->flags |= SF_LOOP;
  18.477 -
  18.478 -		s++;
  18.479 -		q++;
  18.480 -	}
  18.481 -
  18.482 -	of.modtype = strdup(descr);
  18.483 -
  18.484 -	if (!ML_LoadPatterns())
  18.485 -		return 0;
  18.486 -	
  18.487 -	return 1;
  18.488 -}
  18.489 -
  18.490 -static CHAR *MOD_LoadTitle(void)
  18.491 -{
  18.492 -	CHAR s[21];
  18.493 -
  18.494 -	_mm_fseek(modreader, 0, SEEK_SET);
  18.495 -	if (!_mm_read_UBYTES(s, 20, modreader))
  18.496 -		return NULL;
  18.497 -	s[20] = 0;					/* just in case */
  18.498 -
  18.499 -	return (DupStr(s, 21, 1));
  18.500 -}
  18.501 -
  18.502 -/*========== Loader information */
  18.503 -
  18.504 -MIKMODAPI MLOADER load_mod = {
  18.505 -	NULL,
  18.506 -	"Standard module",
  18.507 -	"MOD (31 instruments)",
  18.508 -	MOD_Init,
  18.509 -	MOD_Test,
  18.510 -	MOD_Load,
  18.511 -	MOD_Cleanup,
  18.512 -	MOD_LoadTitle
  18.513 -};
  18.514 -
  18.515 -/* ex:set ts=4: */
    19.1 --- a/mikmod/load_mtm.c	Sat Oct 03 10:53:24 2009 +0000
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,285 +0,0 @@
    19.4 -/*	MikMod sound library
    19.5 -	(c) 1998, 1999, 2000, 2001, 2002 Miodrag Vallat and others - see file
    19.6 -	AUTHORS for complete list.
    19.7 -
    19.8 -	This library is free software; you can redistribute it and/or modify
    19.9 -	it under the terms of the GNU Library General Public License as
   19.10 -	published by the Free Software Foundation; either version 2 of
   19.11 -	the License, or (at your option) any later version.
   19.12 - 
   19.13 -	This program is distributed in the hope that it will be useful,
   19.14 -	but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.15 -	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19.16 -	GNU Library General Public License for more details.
   19.17 - 
   19.18 -	You should have received a copy of the GNU Library General Public
   19.19 -	License along with this library; if not, write to the Free Software
   19.20 -	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   19.21 -	02111-1307, USA.
   19.22 -*/
   19.23 -
   19.24 -/*==============================================================================
   19.25 -
   19.26 -  $Id: load_mtm.c,v 1.1.1.1 2004/06/01 12:16:17 raph Exp $
   19.27 -
   19.28 -  MTM module loader
   19.29 -
   19.30 -==============================================================================*/
   19.31 -
   19.32 -#ifdef HAVE_CONFIG_H
   19.33 -#include "config.h"
   19.34 -#endif
   19.35 -
   19.36 -#ifdef HAVE_UNISTD_H
   19.37 -#include <unistd.h>
   19.38 -#endif
   19.39 -
   19.40 -#include <stdio.h>
   19.41 -#ifdef HAVE_MEMORY_H
   19.42 -#include <memory.h>
   19.43 -#endif
   19.44 -#include <string.h>
   19.45 -
   19.46 -#include "mikmod_internals.h"
   19.47 -
   19.48 -#ifdef SUNOS
   19.49 -extern int fprintf(FILE *, const char *, ...);
   19.50 -#endif
   19.51 -
   19.52 -/*========== Module structure */
   19.53 -
   19.54 -typedef struct MTMHEADER {
   19.55 -	UBYTE id[3];			/* MTM file marker */
   19.56 -	UBYTE version;			/* upper major, lower nibble minor version number */
   19.57 -	CHAR  songname[20];		/* ASCIIZ songname */
   19.58 -	UWORD numtracks;		/* number of tracks saved */
   19.59 -	UBYTE lastpattern;		/* last pattern number saved */
   19.60 -	UBYTE lastorder;		/* last order number to play (songlength-1) */
   19.61 -	UWORD commentsize;		/* length of comment field */
   19.62 -	UBYTE numsamples;		/* number of samples saved  */
   19.63 -	UBYTE attribute;		/* attribute byte (unused) */
   19.64 -	UBYTE beatspertrack;
   19.65 -	UBYTE numchannels;		/* number of channels used  */
   19.66 -	UBYTE panpos[32];		/* voice pan positions */
   19.67 -} MTMHEADER;
   19.68 -
   19.69 -typedef struct MTMSAMPLE {
   19.70 -	CHAR  samplename[22];
   19.71 -	ULONG length;
   19.72 -	ULONG reppos;
   19.73 -	ULONG repend;
   19.74 -	UBYTE finetune;
   19.75 -	UBYTE volume;
   19.76 -	UBYTE attribute;
   19.77 -} MTMSAMPLE;
   19.78 -
   19.79 -typedef struct MTMNOTE {
   19.80 -	UBYTE a,b,c;
   19.81 -} MTMNOTE;
   19.82 -
   19.83 -/*========== Loader variables */
   19.84 -
   19.85 -static MTMHEADER *mh = NULL;
   19.86 -static MTMNOTE *mtmtrk = NULL;
   19.87 -static UWORD pat[32];
   19.88 -
   19.89 -static CHAR MTM_Version[] = "MTM";
   19.90 -
   19.91 -/*========== Loader code */
   19.92 -
   19.93 -BOOL MTM_Test(void)
   19.94 -{
   19.95 -	UBYTE id[3];
   19.96 -
   19.97 -	if(!_mm_read_UBYTES(id,3,modreader)) return 0;
   19.98 -	if(!memcmp(id,"MTM",3)) return 1;
   19.99 -	return 0;
  19.100 -}
  19.101 -
  19.102 -BOOL MTM_Init(void)
  19.103 -{
  19.104 -	if(!(mtmtrk=(MTMNOTE*)_mm_calloc(64,sizeof(MTMNOTE)))) return 0;
  19.105 -	if(!(mh=(MTMHEADER*)_mm_malloc(sizeof(MTMHEADER)))) return 0;
  19.106 -
  19.107 -	return 1;
  19.108 -}
  19.109 -
  19.110 -void MTM_Cleanup(void)
  19.111 -{
  19.112 -	_mm_free(mtmtrk);
  19.113 -	_mm_free(mh);
  19.114 -}
  19.115 -
  19.116 -static UBYTE* MTM_Convert(void)
  19.117 -{
  19.118 -	int t;
  19.119 -	UBYTE a,b,inst,note,eff,dat;
  19.120 -
  19.121 -	UniReset();
  19.122 -	for(t=0;t<64;t++) {
  19.123 -		a=mtmtrk[t].a;
  19.124 -		b=mtmtrk[t].b;
  19.125 -		inst=((a&0x3)<<4)|(b>>4);
  19.126 -		note=a>>2;
  19.127 -		eff=b&0xf;
  19.128 -		dat=mtmtrk[t].c;
  19.129 -
  19.130 -		if(inst) UniInstrument(inst-1);
  19.131 -		if(note) UniNote(note+2*OCTAVE);
  19.132 -
  19.133 -		/* MTM bug workaround : when the effect is volslide, slide-up *always*
  19.134 -		   overrides slide-down. */
  19.135 -		if(eff==0xa && (dat&0xf0)) dat&=0xf0;
  19.136 -
  19.137 -		/* Convert pattern jump from Dec to Hex */
  19.138 -		if(eff==0xd)
  19.139 -			dat=(((dat&0xf0)>>4)*10)+(dat&0xf);
  19.140 -		UniPTEffect(eff,dat);
  19.141 -		UniNewline();
  19.142 -	}
  19.143 -	return UniDup();
  19.144 -}
  19.145 -
  19.146 -BOOL MTM_Load(BOOL curious)
  19.147 -{
  19.148 -	int t,u;
  19.149 -	MTMSAMPLE s;
  19.150 -	SAMPLE *q;
  19.151 -
  19.152 -	/* try to read module header  */
  19.153 -	_mm_read_UBYTES(mh->id,3,modreader);
  19.154 -	mh->version     =_mm_read_UBYTE(modreader);
  19.155 -	_mm_read_string(mh->songname,20,modreader);
  19.156 -	mh->numtracks   =_mm_read_I_UWORD(modreader);
  19.157 -	mh->lastpattern =_mm_read_UBYTE(modreader);
  19.158 -	mh->lastorder   =_mm_read_UBYTE(modreader);
  19.159 -	mh->commentsize =_mm_read_I_UWORD(modreader);
  19.160 -	mh->numsamples  =_mm_read_UBYTE(modreader);
  19.161 -	mh->attribute   =_mm_read_UBYTE(modreader);
  19.162 -	mh->beatspertrack=_mm_read_UBYTE(modreader);
  19.163 -	mh->numchannels =_mm_read_UBYTE(modreader);
  19.164 -	_mm_read_UBYTES(mh->panpos,32,modreader);
  19.165 -
  19.166 -	if(_mm_eof(modreader)) {
  19.167 -		_mm_errno = MMERR_LOADING_HEADER;
  19.168 -		return 0;
  19.169 -	}
  19.170 -
  19.171 -	/* set module variables */
  19.172 -	of.initspeed = 6;
  19.173 -	of.inittempo = 125;
  19.174 -	of.modtype   = strdup(MTM_Version);
  19.175 -	of.numchn    = mh->numchannels;
  19.176 -	of.numtrk    = mh->numtracks+1;           /* get number of channels */
  19.177 -	of.songname  = DupStr(mh->songname,20,1); /* make a cstr of songname */
  19.178 -	of.numpos    = mh->lastorder+1;           /* copy the songlength */
  19.179 -	of.numpat    = mh->lastpattern+1;
  19.180 -	of.reppos    = 0;
  19.181 -	of.flags    |= UF_PANNING;
  19.182 -	for(t=0;t<32;t++) of.panning[t]=mh->panpos[t]<< 4;
  19.183 -	of.numins=of.numsmp=mh->numsamples;
  19.184 -
  19.185 -	if(!AllocSamples()) return 0;
  19.186 -	q=of.samples;
  19.187 -	for(t=0;t<of.numins;t++) {
  19.188 -		/* try to read sample info */
  19.189 -		_mm_read_string(s.samplename,22,modreader);
  19.190 -		s.length    =_mm_read_I_ULONG(modreader);
  19.191 -		s.reppos    =_mm_read_I_ULONG(modreader);
  19.192 -		s.repend    =_mm_read_I_ULONG(modreader);
  19.193 -		s.finetune  =_mm_read_UBYTE(modreader);
  19.194 -		s.volume    =_mm_read_UBYTE(modreader);
  19.195 -		s.attribute =_mm_read_UBYTE(modreader);
  19.196 -
  19.197 -		if(_mm_eof(modreader)) {
  19.198 -			_mm_errno = MMERR_LOADING_SAMPLEINFO; 
  19.199 -			return 0;
  19.200 -		}
  19.201 -
  19.202 -		q->samplename = DupStr(s.samplename,22,1);
  19.203 -		q->seekpos   = 0;
  19.204 -		q->speed     = finetune[s.finetune];
  19.205 -		q->length    = s.length;
  19.206 -		q->loopstart = s.reppos;
  19.207 -		q->loopend   = s.repend;
  19.208 -		q->volume    = s.volume;
  19.209 -		if((s.repend-s.reppos)>2) q->flags |= SF_LOOP;
  19.210 -
  19.211 -		if(s.attribute&1) {
  19.212 -			/* If the sample is 16-bits, convert the length and replen
  19.213 -			   byte-values into sample-values */
  19.214 -			q->flags|=SF_16BITS;
  19.215 -			q->length>>=1;
  19.216 -			q->loopstart>>=1;
  19.217 -			q->loopend>>=1;
  19.218 -		}
  19.219 -		q++;
  19.220 -	}
  19.221 -
  19.222 -	if(!AllocPositions(of.numpos)) return 0;
  19.223 -	for(t=0;t<of.numpos;t++)
  19.224 -		of.positions[t]=_mm_read_UBYTE(modreader);
  19.225 -	for(;t<128;t++) _mm_read_UBYTE(modreader);
  19.226 -	if(_mm_eof(modreader)) {
  19.227 -		_mm_errno = MMERR_LOADING_HEADER;
  19.228 -		return 0;
  19.229 -	}
  19.230 -
  19.231 -	if(!AllocTracks()) return 0;
  19.232 -	if(!AllocPatterns()) return 0;
  19.233 -
  19.234 -	of.tracks[0]=MTM_Convert();		/* track 0 is empty */
  19.235 -	for(t=1;t<of.numtrk;t++) {
  19.236 -		int s;
  19.237 -
  19.238 -		for(s=0;s<64;s++) {
  19.239 -			mtmtrk[s].a=_mm_read_UBYTE(modreader);
  19.240 -			mtmtrk[s].b=_mm_read_UBYTE(modreader);
  19.241 -			mtmtrk[s].c=_mm_read_UBYTE(modreader);
  19.242 -		}
  19.243 -
  19.244 -		if(_mm_eof(modreader)) {
  19.245 -			_mm_errno = MMERR_LOADING_TRACK;
  19.246 -			return 0;
  19.247 -		}
  19.248 -
  19.249 -		if(!(of.tracks[t]=MTM_Convert())) return 0;
  19.250 -	}
  19.251 -
  19.252 -	for(t=0;t<of.numpat;t++) {
  19.253 -		_mm_read_I_UWORDS(pat,32,modreader);
  19.254 -		for(u=0;u<of.numchn;u++)
  19.255 -			of.patterns[((long)t*of.numchn)+u]=pat[u];
  19.256 -	}
  19.257 -
  19.258 -	/* read comment field */
  19.259 -	if(mh->commentsize)
  19.260 -		if(!ReadLinedComment(mh->commentsize, 40)) return 0;
  19.261 -
  19.262 -	return 1;
  19.263 -}
  19.264 -
  19.265 -CHAR *MTM_LoadTitle(void)
  19.266 -{
  19.267 -	CHAR s[20];
  19.268 -
  19.269 -	_mm_fseek(modreader,4,SEEK_SET);
  19.270 -	if(!_mm_read_UBYTES(s,20,modreader)) return NULL;
  19.271 -
  19.272 -	return(DupStr(s,20,1));
  19.273 -}
  19.274 -
  19.275 -/*========== Loader information */
  19.276 -
  19.277 -MIKMODAPI MLOADER load_mtm={
  19.278 -	NULL,
  19.279 -	"MTM",
  19.280 -	"MTM (MultiTracker Module editor)",
  19.281 -	MTM_Init,
  19.282 -	MTM_Test,
  19.283 -	MTM_Load,
  19.284 -	MTM_Cleanup,
  19.285 -	MTM_LoadTitle
  19.286 -};
  19.287 -
  19.288 -/* ex:set ts=4: */
    20.1 --- a/mikmod/load_okt.c	Sat Oct 03 10:53:24 2009 +0000
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,460 +0,0 @@
    20.4 -/*	MikMod sound library
    20.5 -	(c) 1998, 1999, 2000, 2001, 2002 Miodrag Vallat and others - see file
    20.6 -	AUTHORS for complete list.
    20.7 -
    20.8 -	This library is free software; you can redistribute it and/or modify
    20.9 -	it under the terms of the GNU Library General Public License as
   20.10 -	published by the Free Software Foundation; either version 2 of
   20.11 -	the License, or (at your option) any later version.
   20.12 -
   20.13 -	This program is distributed in the hope that it will be useful,
   20.14 -	but WITHOUT ANY WARRANTY; without even the implied warranty of
   20.15 -	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20.16 -	GNU Library General Public License for more details.
   20.17 -
   20.18 -	You should have received a copy of the GNU Library General Public
   20.19 -	License along with this library; if not, write to the Free Software
   20.20 -	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   20.21 -	02111-1307, USA.
   20.22 -*/
   20.23 -
   20.24 -/*==============================================================================
   20.25 -
   20.26 -  $Id: load_okt.c,v 1.1.1.1 2004/06/01 12:16:17 raph Exp $
   20.27 -
   20.28 -  Oktalyzer (OKT) module loader
   20.29 -
   20.30 -==============================================================================*/
   20.31 -
   20.32 -/*
   20.33 -	Written by UFO <ufo303@poczta.onet.pl>
   20.34 -	based on the file description compiled by Harald Zappe
   20.35 -	                                                      <zappe@gaea.sietec.de>
   20.36 -
   20.37 -*/
   20.38 -
   20.39 -#ifdef HAVE_CONFIG_H
   20.40 -#include "config.h"
   20.41 -#endif
   20.42 -
   20.43 -#ifdef HAVE_UNISTD_H
   20.44 -#include <unistd.h>
   20.45 -#endif
   20.46 -
   20.47 -#include <stdio.h>
   20.48 -#ifdef HAVE_MEMORY_H
   20.49 -#include <memory.h>
   20.50 -#endif
   20.51 -#include <string.h>
   20.52 -
   20.53 -#include "mikmod_internals.h"
   20.54 -
   20.55 -#ifdef SUNOS
   20.56 -extern int fprintf(FILE *, const char *, ...);
   20.57 -#endif
   20.58 -
   20.59 -/*========== Module blocks */
   20.60 -
   20.61 -/* sample information */
   20.62 -typedef struct OKTSAMPLE {
   20.63 -	CHAR sampname[20];
   20.64 -	ULONG len;
   20.65 -	UWORD loopbeg;
   20.66 -	UWORD looplen;
   20.67 -	UBYTE volume;
   20.68 -} OKTSAMPLE;
   20.69 -
   20.70 -typedef struct OKTNOTE {
   20.71 -	UBYTE note, ins, eff, dat;
   20.72 -} OKTNOTE;
   20.73 -
   20.74 -/*========== Loader variables */
   20.75 -
   20.76 -static OKTNOTE *okttrk = NULL;
   20.77 -
   20.78 -/*========== Loader code */
   20.79 -
   20.80 -BOOL OKT_Test(void)
   20.81 -{
   20.82 -	CHAR id[8];
   20.83 -
   20.84 -	if (!_mm_read_UBYTES(id, 8, modreader))
   20.85 -		return 0;
   20.86 -	if (!memcmp(id, "OKTASONG", 8))
   20.87 -		return 1;
   20.88 -
   20.89 -	return 0;
   20.90 -}
   20.91 -
   20.92 -/*	Pattern analysis routine.
   20.93 -	Effects not implemented (yet) : (in decimal)
   20.94 -	11 Arpeggio 4: Change note every 50Hz tick between N,H,N,L
   20.95 -	12 Arpeggio 5: Change note every 50Hz tick between H,H,N
   20.96 -                   N = normal note being played in this channel (1-36)
   20.97 -                   L = normal note number minus upper four bits of 'data'.
   20.98 -                   H = normal note number plus  lower four bits of 'data'.
   20.99 -    13 Decrease note number by 'data' once per tick.
  20.100 -    17 Increase note number by 'data' once per tick.
  20.101 -    21 Decrease note number by 'data' once per line.
  20.102 -    30 Increase note number by 'data' once per line.
  20.103 -*/
  20.104 -static UBYTE *OKT_ConvertTrack(UBYTE patrows)
  20.105 -{
  20.106 -	int t;
  20.107 -	UBYTE ins, note, eff, dat;
  20.108 -
  20.109 -	UniReset();
  20.110 -	for (t = 0; t < patrows; t++) {
  20.111 -		note = okttrk[t].note;
  20.112 -		ins = okttrk[t].ins;
  20.113 -		eff = okttrk[t].eff;
  20.114 -		dat = okttrk[t].dat;
  20.115 -
  20.116 -		if (note) {
  20.117 -			UniNote(note + 3 * OCTAVE - 1);
  20.118 -			UniInstrument(ins);
  20.119 -		}
  20.120 -
  20.121 -		if (eff)
  20.122 -			switch (eff) {
  20.123 -			case 1:				/* Porta Up */
  20.124 -				UniPTEffect(0x1, dat);
  20.125 -				break;
  20.126 -			case 2:				/* Portamento Down */
  20.127 -				UniPTEffect(0x2, dat);
  20.128 -				break;
  20.129 -			/* case 9: what is this? */
  20.130 -			case 10:			/* Arpeggio 3 */
  20.131 -			case 11:			/* Arpeggio 4 */
  20.132 -			case 12:			/* Arpeggio 5 */
  20.133 -				UniWriteByte(UNI_OKTARP);
  20.134 -				UniWriteByte(eff + 3 - 10);
  20.135 -				UniWriteByte(dat);
  20.136 -				break;
  20.137 -			case 15:			/* Amiga filter toggle, ignored */
  20.138 -				break;
  20.139 -			case 25:			/* Pattern Jump */
  20.140 -				dat = (dat >> 4) * 10 + (dat & 0x0f);
  20.141 -				UniPTEffect(0xb, dat);
  20.142 -				break;
  20.143 -			case 27:			/* Release - similar to Keyoff */
  20.144 -				UniWriteByte(UNI_KEYOFF);
  20.145 -				break;
  20.146 -			case 28:			/* Set Tempo */
  20.147 -				UniPTEffect(0xf, dat & 0x0f);
  20.148 -				break;
  20.149 -			case 31:			/* volume Control */
  20.150 -				if (dat <= 0x40)
  20.151 -					UniPTEffect(0xc, dat);
  20.152 -				else if (dat <= 0x50)
  20.153 -					UniEffect(UNI_XMEFFECTA, (dat - 0x40));	/* fast fade out */
  20.154 -				else if (dat <= 0x60)
  20.155 -					UniEffect(UNI_XMEFFECTA, (dat - 0x50) << 4);	/* fast fade in */
  20.156 -				else if (dat <= 0x70)
  20.157 -					UniEffect(UNI_XMEFFECTEB, (dat - 0x60));	/* slow fade out */
  20.158 -				else if (dat <= 0x80)
  20.159 -					UniEffect(UNI_XMEFFECTEA, (dat - 0x70));	/* slow fade in */
  20.160 -				break;
  20.161 -#ifdef MIKMOD_DEBUG
  20.162 -			default:
  20.163 -				fprintf(stderr, "\rUnimplemented effect (%02d,%02x)\n",
  20.164 -						eff, dat);
  20.165 -#endif
  20.166 -			}
  20.167 -
  20.168 -		UniNewline();
  20.169 -	}
  20.170 -	return UniDup();
  20.171 -}
  20.172 -
  20.173 -/* Read "channel modes" i.e. channel number and panning information */
  20.174 -static void OKT_doCMOD(void)
  20.175 -{
  20.176 -	/* amiga channel panning table */
  20.177 -	UBYTE amigapan[4] = { 0x00, 0xff, 0xff, 0x00 };
  20.178 -	int t;
  20.179 -
  20.180 -	of.numchn = 0;
  20.181 -	of.flags |= UF_PANNING;
  20.182 -
  20.183 -	for (t = 0; t < 4; t++)
  20.184 -		if (_mm_read_M_UWORD(modreader)) {
  20.185 -			/* two channels tied to the same Amiga hardware voice */
  20.186 -			of.panning[of.numchn++] = amigapan[t];
  20.187 -			of.panning[of.numchn++] = amigapan[t];
  20.188 -		} else
  20.189 -			/* one channel tied to the Amiga hardware voice */
  20.190 -			of.panning[of.numchn++] = amigapan[t];
  20.191 -}
  20.192 -
  20.193 -/* Read sample information */
  20.194 -static BOOL OKT_doSAMP(int len)
  20.195 -{
  20.196 -	int t;
  20.197 -	SAMPLE *q;
  20.198 -	OKTSAMPLE s;
  20.199 -
  20.200 -	of.numins = of.numsmp = (len / 0x20);
  20.201 -	if (!AllocSamples())
  20.202 -		return 0;
  20.203 -
  20.204 -	for (t = 0, q = of.samples; t < of.numins; t++, q++) {
  20.205 -		_mm_read_UBYTES(s.sampname, 20, modreader);
  20.206 -		s.len = _mm_read_M_ULONG(modreader);
  20.207 -		s.loopbeg = _mm_read_M_UWORD(modreader) * 2;
  20.208 -		s.looplen = _mm_read_M_UWORD(modreader) * 2;
  20.209 -		_mm_read_UBYTE(modreader);
  20.210 -		s.volume = _mm_read_UBYTE(modreader);
  20.211 -		_mm_read_M_UWORD(modreader);
  20.212 -
  20.213 -		if (_mm_eof(modreader)) {
  20.214 -			_mm_errno = MMERR_LOADING_SAMPLEINFO;
  20.215 -			return 0;
  20.216 -		}
  20.217 -
  20.218 -		if (!s.len)
  20.219 -			q->seekpos = q->length = q->loopstart = q->loopend = q->flags = 0;
  20.220 -		else {
  20.221 -			s.len--;
  20.222 -			/* sanity checks */
  20.223 -			if (s.loopbeg > s.len)
  20.224 -				s.loopbeg = s.len;
  20.225 -			if (s.loopbeg + s.looplen > s.len)
  20.226 -				s.looplen = s.len - s.loopbeg;
  20.227 -			if (s.looplen < 2)
  20.228 -				s.looplen = 0;
  20.229 -
  20.230 -			q->length = s.len;
  20.231 -			q->loopstart = s.loopbeg;
  20.232 -			q->loopend = s.looplen + q->loopstart;
  20.233 -			q->volume = s.volume;
  20.234 -			q->flags = SF_SIGNED;
  20.235 -
  20.236 -			if (s.looplen)
  20.237 -				q->flags |= SF_LOOP;
  20.238 -		}
  20.239 -		q->samplename = DupStr(s.sampname, 20, 1);
  20.240 -		q->speed = 8287;
  20.241 -	}
  20.242 -	return 1;
  20.243 -}
  20.244 -
  20.245 -/* Read speed information */
  20.246 -static void OKT_doSPEE(void)
  20.247 -{
  20.248 -	int tempo = _mm_read_M_UWORD(modreader);
  20.249 -
  20.250 -	of.initspeed = tempo;
  20.251 -}
  20.252 -
  20.253 -/* Read song length information */
  20.254 -static void OKT_doSLEN(void)
  20.255 -{
  20.256 -	of.numpat = _mm_read_M_UWORD(modreader);
  20.257 -}
  20.258 -
  20.259 -/* Read pattern length information */
  20.260 -static void OKT_doPLEN(void)
  20.261 -{
  20.262 -	of.numpos = _mm_read_M_UWORD(modreader);
  20.263 -}
  20.264 -
  20.265 -/* Read order table */
  20.266 -static BOOL OKT_doPATT(void)
  20.267 -{
  20.268 -	int t;
  20.269 -
  20.270 -	if (!of.numpos || !AllocPositions(of.numpos))
  20.271 -		return 0;
  20.272 -
  20.273 -	for (t = 0; t < 128; t++)
  20.274 -		if (t < of.numpos)
  20.275 -			of.positions[t] = _mm_read_UBYTE(modreader);
  20.276 -		else
  20.277 -			break;
  20.278 -
  20.279 -	return 1;
  20.280 -}
  20.281 -
  20.282 -static BOOL OKT_doPBOD(int patnum)
  20.283 -{
  20.284 -	char *patbuf;
  20.285 -	int rows, i;
  20.286 -	int u;
  20.287 -
  20.288 -	if (!patnum) {
  20.289 -		of.numtrk = of.numpat * of.numchn;
  20.290 -
  20.291 -		if (!AllocTracks() || !AllocPatterns())
  20.292 -			return 0;
  20.293 -	}
  20.294 -
  20.295 -	/* Read pattern */
  20.296 -	of.pattrows[patnum] = rows = _mm_read_M_UWORD(modreader);
  20.297 -
  20.298 -	if (!(okttrk = (OKTNOTE *) _mm_calloc(rows, sizeof(OKTNOTE))) ||
  20.299 -	    !(patbuf = (char *)_mm_calloc(rows * of.numchn, sizeof(OKTNOTE))))
  20.300 -		return 0;
  20.301 -	_mm_read_UBYTES(patbuf, rows * of.numchn * sizeof(OKTNOTE), modreader);
  20.302 -	if (_mm_eof(modreader)) {
  20.303 -		_mm_errno = MMERR_LOADING_PATTERN;
  20.304 -		return 0;
  20.305 -	}
  20.306 -
  20.307 -	for (i = 0; i < of.numchn; i++) {
  20.308 -		for (u = 0; u < rows; u++) {
  20.309 -			okttrk[u].note = patbuf[(u * of.numchn + i) * sizeof(OKTNOTE)];
  20.310 -			okttrk[u].ins = patbuf[(u * of.numchn + i) * sizeof(OKTNOTE) + 1];
  20.311 -			okttrk[u].eff = patbuf[(u * of.numchn + i) * sizeof(OKTNOTE) + 2];
  20.312 -			okttrk[u].dat = patbuf[(u * of.numchn + i) * sizeof(OKTNOTE) + 3];
  20.313 -		}
  20.314 -
  20.315 -		if (!(of.tracks[patnum * of.numchn + i] = OKT_ConvertTrack(rows)))
  20.316 -			return 0;
  20.317 -	}
  20.318 -	_mm_free(patbuf);
  20.319 -	_mm_free(okttrk);
  20.320 -	return 1;
  20.321 -}
  20.322 -
  20.323 -static void OKT_doSBOD(int insnum)
  20.324 -{
  20.325 -	of.samples[insnum].seekpos = _mm_ftell(modreader);
  20.326 -}
  20.327 -
  20.328 -BOOL OKT_Load(BOOL curious)
  20.329 -{
  20.330 -	UBYTE id[4];
  20.331 -	ULONG len;
  20.332 -	ULONG fp;
  20.333 -	BOOL seen_cmod = 0, seen_samp = 0, seen_slen = 0, seen_plen = 0, seen_patt
  20.334 -			= 0, seen_spee = 0;
  20.335 -	int patnum = 0, insnum = 0;
  20.336 -
  20.337 -	/* skip OKTALYZER header */
  20.338 -	_mm_fseek(modreader, 8, SEEK_SET);
  20.339 -	of.songname = strdup("");
  20.340 -
  20.341 -	of.modtype = strdup("Amiga Oktalyzer");
  20.342 -	of.numpos = of.reppos = 0;
  20.343 -	
  20.344 -	/* default values */
  20.345 -	of.initspeed = 6;
  20.346 -	of.inittempo = 125;
  20.347 -	
  20.348 -	while (1) {
  20.349 -		/* read block header */
  20.350 -		_mm_read_UBYTES(id, 4, modreader);
  20.351 -		len = _mm_read_M_ULONG(modreader);
  20.352 -		
  20.353 -		if (_mm_eof(modreader))
  20.354 -			break;
  20.355 -		fp = _mm_ftell(modreader);
  20.356 -		
  20.357 -		if (!memcmp(id, "CMOD", 4)) {
  20.358 -			if (!seen_cmod) {
  20.359 -				OKT_doCMOD();
  20.360 -				seen_cmod = 1;
  20.361 -			} else {
  20.362 -				_mm_errno = MMERR_LOADING_HEADER;
  20.363 -				return 0;
  20.364 -			}
  20.365 -		} else if (!memcmp(id, "SAMP", 4)) {
  20.366 -			if (!seen_samp && OKT_doSAMP(len))
  20.367 -				seen_samp = 1;
  20.368 -			else {
  20.369 -				_mm_errno = MMERR_LOADING_HEADER;
  20.370 -				return 0;
  20.371 -			}
  20.372 -		} else if (!memcmp(id, "SPEE", 4)) {
  20.373 -			if (!seen_spee) {
  20.374 -				OKT_doSPEE();
  20.375 -				seen_spee = 1;
  20.376 -			} else {
  20.377 -				_mm_errno = MMERR_LOADING_HEADER;
  20.378 -				return 0;
  20.379 -			}
  20.380 -		} else if (!memcmp(id, "SLEN", 4)) {
  20.381 -			if (!seen_slen) {
  20.382 -				OKT_doSLEN();
  20.383 -				seen_slen = 1;
  20.384 -			} else {
  20.385 -				_mm_errno = MMERR_LOADING_HEADER;
  20.386 -				return 0;
  20.387 -			}
  20.388 -		} else if (!memcmp(id, "PLEN", 4)) {
  20.389 -			if (!seen_plen) {
  20.390 -				OKT_doPLEN();
  20.391 -				seen_plen = 1;
  20.392 -			} else {
  20.393 -				_mm_errno = MMERR_LOADING_HEADER;
  20.394 -				return 0;
  20.395 -			}
  20.396 -		} else if (!memcmp(id, "PATT", 4)) {
  20.397 -			if (!seen_plen) {
  20.398 -				_mm_errno = MMERR_LOADING_HEADER;
  20.399 -				return 0;
  20.400 -			}
  20.401 -			if (!seen_patt && OKT_doPATT())
  20.402 -				seen_patt = 1;
  20.403 -			else {
  20.404 -				_mm_errno = MMERR_LOADING_HEADER;
  20.405 -				return 0;
  20.406 -			}
  20.407 -		} else if (!memcmp(id,"PBOD", 4)) {
  20.408 -			/* need to know numpat and numchn */
  20.409 -			if (!seen_slen || !seen_cmod || (patnum >= of.numpat)) {
  20.410 -				_mm_errno = MMERR_LOADING_HEADER;
  20.411 -				return 0;
  20.412 -			}
  20.413 -			if (!OKT_doPBOD(patnum++)) {
  20.414 -				_mm_errno = MMERR_LOADING_PATTERN;
  20.415 -				return 0;
  20.416 -			}
  20.417 -		} else if (!memcmp(id,"SBOD",4)) {
  20.418 -			/* need to know numsmp */
  20.419 -			if (!seen_samp) {
  20.420 -				_mm_errno = MMERR_LOADING_HEADER;
  20.421 -				return 0;
  20.422 -			}
  20.423 -			while ((insnum < of.numins) && !of.samples[insnum].length)
  20.424 -				insnum++;
  20.425 -			if (insnum >= of.numins) {
  20.426 -				_mm_errno = MMERR_LOADING_HEADER;
  20.427 -				return 0;
  20.428 -			}
  20.429 -			OKT_doSBOD(insnum++);
  20.430 -		}
  20.431 -
  20.432 -		/* goto next block start position */
  20.433 -		_mm_fseek(modreader, fp + len, SEEK_SET);
  20.434 -	}
  20.435 -
  20.436 -	if (!seen_cmod || !seen_samp || !seen_patt ||
  20.437 -		!seen_slen || !seen_plen || (patnum != of.numpat)) {
  20.438 -		_mm_errno = MMERR_LOADING_HEADER;
  20.439 -		return 0;
  20.440 -	}
  20.441 -
  20.442 -	return 1;
  20.443 -}
  20.444 -
  20.445 -CHAR *OKT_LoadTitle(void)
  20.446 -{
  20.447 -	return strdup("");
  20.448 -}
  20.449 -
  20.450 -/*========== Loader information */
  20.451 -
  20.452 -MIKMODAPI MLOADER load_okt = {
  20.453 -	NULL,
  20.454 -	"OKT",
  20.455 -	"OKT (Amiga Oktalyzer)",
  20.456 -	NULL,
  20.457 -	OKT_Test,
  20.458 -	OKT_Load,
  20.459 -	NULL,
  20.460 -	OKT_LoadTitle
  20.461 -};
  20.462 -
  20.463 -/* ex:set ts=4: */
    21.1 --- a/mikmod/load_s3m.c	Sat Oct 03 10:53:24 2009 +0000
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,470 +0,0 @@
    21.4 -/*	MikMod sound library
    21.5 -	(c) 1998, 1999, 2000, 2001, 2002 Miodrag Vallat and others - see file
    21.6 -	AUTHORS for complete list.
    21.7 -
    21.8 -	This library is free software; you can redistribute it and/or modify
    21.9 -	it under the terms of the GNU Library General Public License as
   21.10 -	published by the Free Software Foundation; either version 2 of
   21.11 -	the License, or (at your option) any later version.
   21.12 - 
   21.13 -	This program is distributed in the hope that it will be useful,
   21.14 -	but WITHOUT ANY WARRANTY; without even the implied warranty of
   21.15 -	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   21.16 -	GNU Library General Public License for more details.
   21.17 - 
   21.18 -	You should have received a copy of the GNU Library General Public
   21.19 -	License along with this library; if not, write to the Free Software
   21.20 -	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   21.21 -	02111-1307, USA.
   21.22 -*/
   21.23 -
   21.24 -/*==============================================================================
   21.25 -
   21.26 -  $Id$
   21.27 -
   21.28 -  Screamtracker (S3M) module loader
   21.29 -
   21.30 -==============================================================================*/
   21.31 -
   21.32 -#ifdef HAVE_CONFIG_H
   21.33 -#include "config.h"
   21.34 -#endif
   21.35 -
   21.36 -#ifdef HAVE_UNISTD_H
   21.37 -#include <unistd.h>
   21.38 -#endif
   21.39 -
   21.40 -#include <stdio.h>
   21.41 -#ifdef HAVE_MEMORY_H
   21.42 -#include <memory.h>
   21.43 -#endif
   21.44 -#include <string.h>
   21.45 -
   21.46 -#include "mikmod_internals.h"
   21.47 -
   21.48 -#ifdef SUNOS
   21.49 -extern int fprintf(FILE *, const char *, ...);
   21.50 -#endif
   21.51 -
   21.52 -/*========== Module structure */
   21.53 -
   21.54 -/* header */
   21.55 -typedef struct S3MHEADER {
   21.56 -	CHAR  songname[28];
   21.57 -	UBYTE t1a;
   21.58 -	UBYTE type;
   21.59 -	UBYTE unused1[2];
   21.60 -	UWORD ordnum;
   21.61 -	UWORD insnum;
   21.62 -	UWORD patnum;
   21.63 -	UWORD flags;
   21.64 -	UWORD tracker;
   21.65 -	UWORD fileformat;
   21.66 -	CHAR  scrm[4];
   21.67 -	UBYTE mastervol;
   21.68 -	UBYTE initspeed;
   21.69 -	UBYTE inittempo;
   21.70 -	UBYTE mastermult;
   21.71 -	UBYTE ultraclick;
   21.72 -	UBYTE pantable;
   21.73 -	UBYTE unused2[8];
   21.74 -	UWORD special;
   21.75 -	UBYTE channels[32];
   21.76 -} S3MHEADER;
   21.77 -
   21.78 -/* sample information */
   21.79 -typedef struct S3MSAMPLE {
   21.80 -	UBYTE type;
   21.81 -	CHAR  filename[12];
   21.82 -	UBYTE memsegh;
   21.83 -	UWORD memsegl;
   21.84 -	ULONG length;
   21.85 -	ULONG loopbeg;
   21.86 -	ULONG loopend;
   21.87 -	UBYTE volume;
   21.88 -	UBYTE dsk;
   21.89 -	UBYTE pack;
   21.90 -	UBYTE flags;
   21.91 -	ULONG c2spd;
   21.92 -	UBYTE unused[12];
   21.93 -	CHAR  sampname[28];
   21.94 -	CHAR  scrs[4];
   21.95 -} S3MSAMPLE;
   21.96 -
   21.97 -typedef struct S3MNOTE {
   21.98 -	UBYTE note,ins,vol,cmd,inf;
   21.99 -} S3MNOTE;
  21.100 -
  21.101 -/*========== Loader variables */
  21.102 -
  21.103 -static S3MNOTE   *s3mbuf  = NULL; /* pointer to a complete S3M pattern */
  21.104 -static S3MHEADER *mh      = NULL;
  21.105 -static UWORD     *paraptr = NULL; /* parapointer array (see S3M docs) */
  21.106 -static unsigned int tracker;	/* tracker id */
  21.107 -
  21.108 -/* tracker identifiers */
  21.109 -#define NUMTRACKERS 4
  21.110 -static CHAR* S3M_Version[] = {
  21.111 -	"Screamtracker x.xx",
  21.112 -	"Imago Orpheus x.xx (S3M format)",
  21.113 -	"Impulse Tracker x.xx (S3M format)",
  21.114 -	"Unknown tracker x.xx (S3M format)",
  21.115 -	"Impulse Tracker 2.14p3 (S3M format)",
  21.116 -	"Impulse Tracker 2.14p4 (S3M format)"
  21.117 -};
  21.118 -/* version number position in above array */
  21.119 -static int numeric[NUMTRACKERS]={14,14,16,16};
  21.120 -
  21.121 -/*========== Loader code */
  21.122 -
  21.123 -BOOL S3M_Test(void)
  21.124 -{
  21.125 -	UBYTE id[4];
  21.126 -
  21.127 -	_mm_fseek(modreader,0x2c,SEEK_SET);
  21.128 -	if(!_mm_read_UBYTES(id,4,modreader)) return 0;
  21.129 -	if(!memcmp(id,"SCRM",4)) return 1;
  21.130 -	return 0;
  21.131 -}
  21.132 -
  21.133 -BOOL S3M_Init(void)
  21.134 -{
  21.135 -	if(!(s3mbuf=(S3MNOTE*)_mm_malloc(32*64*sizeof(S3MNOTE)))) return 0;
  21.136 -	if(!(mh=(S3MHEADER*)_mm_malloc(sizeof(S3MHEADER)))) return 0;
  21.137 -	if(!(poslookup=(UBYTE*)_mm_malloc(sizeof(UBYTE)*256))) return 0;
  21.138 -	memset(poslookup,-1,256);
  21.139 -
  21.140 -	return 1;
  21.141 -}
  21.142 -
  21.143 -void S3M_Cleanup(void)
  21.144 -{
  21.145 -	_mm_free(s3mbuf);
  21.146 -	_mm_free(paraptr);
  21.147 -	_mm_free(poslookup);
  21.148 -	_mm_free(mh);
  21.149 -	_mm_free(origpositions);
  21.150 -}
  21.151 -
  21.152 -/* Because so many s3m files have 16 channels as the set number used, but really
  21.153 -   only use far less (usually 8 to 12 still), I had to make this function, which
  21.154 -   determines the number of channels that are actually USED by a pattern.
  21.155 -
  21.156 -   For every channel that's used, it sets the appropriate array entry of the
  21.157 -   global variable 'remap'
  21.158 -
  21.159 -   NOTE: You must first seek to the file location of the pattern before calling
  21.160 -         this procedure.
  21.161 -
  21.162 -   Returns 1 on fail.                                                         */
  21.163 -static BOOL S3M_GetNumChannels(void)
  21.164 -{
  21.165 -	int row=0,flag,ch;
  21.166 -
  21.167 -	while(row<64) {
  21.168 -		flag=_mm_read_UBYTE(modreader);
  21.169 -
  21.170 -		if(_mm_eof(modreader)) {
  21.171 -			_mm_errno = MMERR_LOADING_PATTERN;
  21.172 -			return 1;
  21.173 -		}
  21.174 -
  21.175 -		if(flag) {
  21.176 -			ch=flag&31;
  21.177 -			if(mh->channels[ch]<32) remap[ch] = 0;
  21.178 -			if(flag&32) {_mm_read_UBYTE(modreader);_mm_read_UBYTE(modreader);}
  21.179 -			if(flag&64) _mm_read_UBYTE(modreader);
  21.180 -			if(flag&128){_mm_read_UBYTE(modreader);_mm_read_UBYTE(modreader);}
  21.181 -		} else row++;
  21.182 -	}
  21.183 -	return 0;
  21.184 -}    
  21.185 -
  21.186 -static BOOL S3M_ReadPattern(void)
  21.187 -{
  21.188 -	int row=0,flag,ch;
  21.189 -	S3MNOTE *n,dummy;
  21.190 -
  21.191 -	/* clear pattern data */
  21.192 -	memset(s3mbuf,255,32*64*sizeof(S3MNOTE));
  21.193 -
  21.194 -	while(row<64) {
  21.195 -		flag=_mm_read_UBYTE(modreader);
  21.196 -
  21.197 -		if(_mm_eof(modreader)) {
  21.198 -			_mm_errno = MMERR_LOADING_PATTERN;
  21.199 -			return 0;
  21.200 -		}
  21.201 -
  21.202 -		if(flag) {
  21.203 -			ch=remap[flag&31];
  21.204 -
  21.205 -			if(ch!=-1)
  21.206 -				n=&s3mbuf[(64U*ch)+row];
  21.207 -			else
  21.208 -				n=&dummy;
  21.209 -
  21.210 -			if(flag&32) {
  21.211 -				n->note=_mm_read_UBYTE(modreader);
  21.212 -				n->ins=_mm_read_UBYTE(modreader);
  21.213 -			}
  21.214 -			if(flag&64) {
  21.215 -				n->vol=_mm_read_UBYTE(modreader);
  21.216 -				if (n->vol>64) n->vol=64;
  21.217 -			}
  21.218 -			if(flag&128) {
  21.219 -				n->cmd=_mm_read_UBYTE(modreader);
  21.220 -				n->inf=_mm_read_UBYTE(modreader);
  21.221 -			}
  21.222 -		} else row++;
  21.223 -	}
  21.224 -	return 1;
  21.225 -}
  21.226 -
  21.227 -static UBYTE* S3M_ConvertTrack(S3MNOTE* tr)
  21.228 -{
  21.229 -	int t;
  21.230 -
  21.231 -	UniReset();
  21.232 -	for(t=0;t<64;t++) {
  21.233 -		UBYTE note,ins,vol;
  21.234 -
  21.235 -		note=tr[t].note;
  21.236 -		ins=tr[t].ins;
  21.237 -		vol=tr[t].vol;
  21.238 -
  21.239 -		if((ins)&&(ins!=255)) UniInstrument(ins-1);
  21.240 -		if(note!=255) {
  21.241 -			if(note==254) {
  21.242 -				UniPTEffect(0xc,0);	/* note cut command */
  21.243 -				vol=255;
  21.244 -			} else
  21.245 -				UniNote(((note>>4)*OCTAVE)+(note&0xf));	/* normal note */
  21.246 -		}
  21.247 -		if(vol<255) UniPTEffect(0xc,vol);
  21.248 -
  21.249 -		S3MIT_ProcessCmd(tr[t].cmd,tr[t].inf,
  21.250 -			tracker == 1 ? S3MIT_OLDSTYLE | S3MIT_SCREAM : S3MIT_OLDSTYLE);
  21.251 -		UniNewline();
  21.252 -	}
  21.253 -	return UniDup();
  21.254 -}
  21.255 -
  21.256 -BOOL S3M_Load(BOOL curious)
  21.257 -{
  21.258 -	int t,u,track = 0;
  21.259 -	SAMPLE *q;
  21.260 -	UBYTE pan[32];
  21.261 -
  21.262 -	/* try to read module header */
  21.263 -	_mm_read_string(mh->songname,28,modreader);
  21.264 -	mh->t1a         =_mm_read_UBYTE(modreader);
  21.265 -	mh->type        =_mm_read_UBYTE(modreader);
  21.266 -	_mm_read_UBYTES(mh->unused1,2,modreader);
  21.267 -	mh->ordnum      =_mm_read_I_UWORD(modreader);
  21.268 -	mh->insnum      =_mm_read_I_UWORD(modreader);
  21.269 -	mh->patnum      =_mm_read_I_UWORD(modreader);
  21.270 -	mh->flags       =_mm_read_I_UWORD(modreader);
  21.271 -	mh->tracker     =_mm_read_I_UWORD(modreader);
  21.272 -	mh->fileformat  =_mm_read_I_UWORD(modreader);
  21.273 -	_mm_read_string(mh->scrm,4,modreader);
  21.274 -	mh->mastervol   =_mm_read_UBYTE(modreader);
  21.275 -	mh->initspeed   =_mm_read_UBYTE(modreader);
  21.276 -	mh->inittempo   =_mm_read_UBYTE(modreader);
  21.277 -	mh->mastermult  =_mm_read_UBYTE(modreader);
  21.278 -	mh->ultraclick  =_mm_read_UBYTE(modreader);
  21.279 -	mh->pantable    =_mm_read_UBYTE(modreader);
  21.280 -	_mm_read_UBYTES(mh->unused2,8,modreader);
  21.281 -	mh->special     =_mm_read_I_UWORD(modreader);
  21.282 -	_mm_read_UBYTES(mh->channels,32,modreader);
  21.283 -
  21.284 -	if(_mm_eof(modreader)) {
  21.285 -		_mm_errno = MMERR_LOADING_HEADER;
  21.286 -		return 0;
  21.287 -	}
  21.288 -
  21.289 -	/* then we can decide the module type */
  21.290 -	tracker=mh->tracker>>12;
  21.291 -	if((!tracker)||(tracker>=NUMTRACKERS))
  21.292 -		tracker=NUMTRACKERS-1; /* unknown tracker */
  21.293 -	else {
  21.294 -		if(mh->tracker>=0x3217)
  21.295 -			tracker=NUMTRACKERS+1; /* IT 2.14p4 */
  21.296 -		else if(mh->tracker>=0x3216)
  21.297 -			tracker=NUMTRACKERS; /* IT 2.14p3 */
  21.298 -		else tracker--;
  21.299 -	}
  21.300 -	of.modtype = strdup(S3M_Version[tracker]);
  21.301 -	if(tracker<NUMTRACKERS) {
  21.302 -		of.modtype[numeric[tracker]] = ((mh->tracker>>8) &0xf)+'0';
  21.303 -		of.modtype[numeric[tracker]+2] = ((mh->tracker>>4)&0xf)+'0';
  21.304 -		of.modtype[numeric[tracker]+3] = ((mh->tracker)&0xf)+'0';
  21.305 -	}
  21.306 -	/* set module variables */
  21.307 -	of.songname    = DupStr(mh->songname,28,0);
  21.308 -	of.numpat      = mh->patnum;
  21.309 -	of.reppos      = 0;
  21.310 -	of.numins      = of.numsmp = mh->insnum;
  21.311 -	of.initspeed   = mh->initspeed;
  21.312 -	of.inittempo   = mh->inittempo;
  21.313 -	of.initvolume  = mh->mastervol<<1;
  21.314 -	of.flags      |= UF_ARPMEM | UF_PANNING;
  21.315 -	if((mh->tracker==0x1300)||(mh->flags&64))
  21.316 -		of.flags|=UF_S3MSLIDES;
  21.317 -	of.bpmlimit    = 32;
  21.318 -
  21.319 -	/* read the order data */
  21.320 -	if(!AllocPositions(mh->ordnum)) return 0;
  21.321 -	if(!(origpositions=_mm_calloc(mh->ordnum,sizeof(UWORD)))) return 0;
  21.322 -
  21.323 -	for(t=0;t<mh->ordnum;t++) {
  21.324 -		origpositions[t]=_mm_read_UBYTE(modreader);
  21.325 -		if((origpositions[t]>=mh->patnum)&&(origpositions[t]<254))
  21.326 -			origpositions[t]=255/*mh->patnum-1*/;
  21.327 -	}
  21.328 -
  21.329 -	if(_mm_eof(modreader)) {
  21.330 -		_mm_errno = MMERR_LOADING_HEADER;
  21.331 -		return 0;
  21.332 -	}
  21.333 -
  21.334 -	poslookupcnt=mh->ordnum;
  21.335 -	S3MIT_CreateOrders(curious);
  21.336 -
  21.337 -	if(!(paraptr=(UWORD*)_mm_malloc((of.numins+of.numpat)*sizeof(UWORD))))
  21.338 -		return 0;
  21.339 -
  21.340 -	/* read the instrument+pattern parapointers */
  21.341 -	_mm_read_I_UWORDS(paraptr,of.numins+of.numpat,modreader);
  21.342 -
  21.343 -	if(mh->pantable==252) {
  21.344 -		/* read the panning table (ST 3.2 addition.  See below for further
  21.345 -		   portions of channel panning [past reampper]). */
  21.346 -		_mm_read_UBYTES(pan,32,modreader);
  21.347 -	}
  21.348 -
  21.349 -	if(_mm_eof(modreader)) {
  21.350 -		_mm_errno = MMERR_LOADING_HEADER;
  21.351 -		return 0;
  21.352 -	}
  21.353 -
  21.354 -	/* load samples */
  21.355 -	if(!AllocSamples()) return 0;
  21.356 -	q = of.samples;
  21.357 -	for(t=0;t<of.numins;t++) {
  21.358 -		S3MSAMPLE s;
  21.359 -
  21.360 -		/* seek to instrument position */
  21.361 -		_mm_fseek(modreader,((long)paraptr[t])<<4,SEEK_SET);
  21.362 -		/* and load sample info */
  21.363 -		s.type      =_mm_read_UBYTE(modreader);
  21.364 -		_mm_read_string(s.filename,12,modreader);
  21.365 -		s.memsegh   =_mm_read_UBYTE(modreader);
  21.366 -		s.memsegl   =_mm_read_I_UWORD(modreader);
  21.367 -		s.length    =_mm_read_I_ULONG(modreader);
  21.368 -		s.loopbeg   =_mm_read_I_ULONG(modreader);
  21.369 -		s.loopend   =_mm_read_I_ULONG(modreader);
  21.370 -		s.volume    =_mm_read_UBYTE(modreader);
  21.371 -		s.dsk       =_mm_read_UBYTE(modreader);
  21.372 -		s.pack      =_mm_read_UBYTE(modreader);
  21.373 -		s.flags     =_mm_read_UBYTE(modreader);
  21.374 -		s.c2spd     =_mm_read_I_ULONG(modreader);
  21.375 -		_mm_read_UBYTES(s.unused,12,modreader);
  21.376 -		_mm_read_string(s.sampname,28,modreader);
  21.377 -		_mm_read_string(s.scrs,4,modreader);
  21.378 -
  21.379 -		/* ScreamTracker imposes a 64000 bytes (not 64k !) limit */