home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 25 / GNOME_DEMO.iso / amiga / music / mikmod.lzx / mikmod / load_uni.c < prev    next >
C/C++ Source or Header  |  2000-01-05  |  3KB  |  191 lines

  1. /*
  2.  
  3. Name:
  4. LOAD_UNI.C
  5.  
  6. Description:
  7. UNIMOD (mikmod's internal format) module loader.
  8.  
  9. Portability:
  10. All systems - all compilers (hopefully)
  11.  
  12. */
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include "mikmod.h"
  17.  
  18.  
  19. BOOL UNI_Test(void)
  20. {
  21.     char id[4];
  22.     if(!fread(id,4,1,modfp)) return 0;
  23.     if(!memcmp(id,"UN05",4)) return 1;
  24.     return 0;
  25. }
  26.  
  27.  
  28. BOOL UNI_Init(void)
  29. {
  30.     return 1;
  31. }
  32.  
  33.  
  34. void UNI_Cleanup(void)
  35. {
  36.     ;
  37. }
  38.  
  39.  
  40. char *StrRead(void)
  41. {
  42.     char *s;
  43.     UWORD len;
  44.  
  45.     len=_mm_read_I_UWORD(modfp);
  46.     if(!len) return NULL;
  47.  
  48.     s=malloc(len+1);
  49.     fread(s,len,1,modfp);
  50.     s[len]=0;
  51.  
  52.     return s;
  53. }
  54.  
  55.  
  56. UBYTE *TrkRead(void)
  57. {
  58.     UBYTE *t;
  59.     UWORD len;
  60.  
  61.     len=_mm_read_I_UWORD(modfp);
  62.     t=malloc(len);
  63.     fread(t,len,1,modfp);
  64.     return t;
  65. }
  66.  
  67.  
  68.  
  69. BOOL UNI_Load(void)
  70. {
  71.     int t,u;
  72.  
  73.     _mm_fseek(modfp,4,SEEK_SET);
  74.  
  75.     /* try to read module header */
  76.  
  77.     of.numchn    =_mm_read_UBYTE(modfp);
  78.     of.numpos    =_mm_read_I_UWORD(modfp);
  79.     of.reppos    =_mm_read_I_UWORD(modfp);
  80.     of.numpat    =_mm_read_I_UWORD(modfp);
  81.     of.numtrk    =_mm_read_I_UWORD(modfp);
  82.     of.numins    =_mm_read_I_UWORD(modfp);
  83.     of.initspeed=_mm_read_UBYTE(modfp);
  84.     of.inittempo=_mm_read_UBYTE(modfp);
  85.     _mm_read_UBYTES(of.positions,256,modfp);
  86.     _mm_read_UBYTES(of.panning,32,modfp);
  87.     of.flags    =_mm_read_UBYTE(modfp);
  88.  
  89.     if(feof(modfp)){
  90.         myerr=ERROR_LOADING_HEADER;
  91.         return 0;
  92.     }
  93.  
  94.     of.songname=StrRead();
  95.     of.modtype=StrRead();
  96.     of.comment=StrRead();   /* <- new since UN01 */
  97.  
  98. /*    printf("Song: %s\nModty: %s\n",of.songname,of.modtype);
  99. */
  100.  
  101.     if(!AllocInstruments()) return 0;
  102.     if(!AllocTracks()) return 0;
  103.     if(!AllocPatterns()) return 0;
  104.  
  105.     /* Read sampleinfos */
  106.  
  107.     for(t=0;t<of.numins;t++){
  108.  
  109.         INSTRUMENT *i=&of.instruments[t];
  110.  
  111.         i->numsmp=_mm_read_UBYTE(modfp);
  112.         _mm_read_UBYTES(i->samplenumber,96,modfp);
  113.  
  114.         i->volflg=_mm_read_UBYTE(modfp);
  115.         i->volpts=_mm_read_UBYTE(modfp);
  116.         i->volsus=_mm_read_UBYTE(modfp);
  117.         i->volbeg=_mm_read_UBYTE(modfp);
  118.         i->volend=_mm_read_UBYTE(modfp);
  119.  
  120.         for(u=0;u<12;u++){
  121.             i->volenv[u].pos=_mm_read_I_SWORD(modfp);
  122.             i->volenv[u].val=_mm_read_I_SWORD(modfp);
  123.         }
  124.  
  125.         i->panflg=_mm_read_UBYTE(modfp);
  126.         i->panpts=_mm_read_UBYTE(modfp);
  127.         i->pansus=_mm_read_UBYTE(modfp);
  128.         i->panbeg=_mm_read_UBYTE(modfp);
  129.         i->panend=_mm_read_UBYTE(modfp);
  130.  
  131.         for(u=0;u<12;u++){
  132.             i->panenv[u].pos=_mm_read_I_SWORD(modfp);
  133.             i->panenv[u].val=_mm_read_I_SWORD(modfp);
  134.         }
  135.  
  136.         i->vibtype    =_mm_read_UBYTE(modfp);
  137.         i->vibsweep    =_mm_read_UBYTE(modfp);
  138.         i->vibdepth    =_mm_read_UBYTE(modfp);
  139.         i->vibrate    =_mm_read_UBYTE(modfp);
  140.  
  141.         i->volfade    =_mm_read_I_UWORD(modfp);
  142.         i->insname    =StrRead();
  143.  
  144. /*        printf("Ins: %s\n",i->insname);
  145. */
  146.         if(!AllocSamples(i)) return 0;
  147.  
  148.         for(u=0;u<i->numsmp;u++){
  149.  
  150.             SAMPLE *s=&i->samples[u];
  151.  
  152.             s->c2spd    = _mm_read_I_UWORD(modfp);
  153.             s->transpose= _mm_read_SBYTE(modfp);
  154.             s->volume    = _mm_read_UBYTE(modfp);
  155.             s->panning    = _mm_read_UBYTE(modfp);
  156.             s->length    = _mm_read_I_ULONG(modfp);
  157.             s->loopstart= _mm_read_I_ULONG(modfp);
  158.             s->loopend    = _mm_read_I_ULONG(modfp);
  159.             s->flags    = _mm_read_I_UWORD(modfp);
  160.             s->seekpos    = 0;
  161.  
  162.             s->samplename=StrRead();
  163.         }
  164.     }
  165.  
  166.     /* Read patterns */
  167.  
  168.     _mm_read_I_UWORDS(of.pattrows,of.numpat,modfp);
  169.     _mm_read_I_UWORDS(of.patterns,of.numpat*of.numchn,modfp);
  170.  
  171.     /* Read tracks */
  172.  
  173.     for(t=0;t<of.numtrk;t++){
  174.         of.tracks[t]=TrkRead();
  175.     }
  176.  
  177.     return 1;
  178. }
  179.  
  180.  
  181. LOADER load_uni={
  182.     NULL,
  183.     "UNI",
  184.     "Portable UNI loader v0.3",
  185.     UNI_Init,
  186.     UNI_Test,
  187.     UNI_Load,
  188.     UNI_Cleanup
  189. };
  190.  
  191.