home *** CD-ROM | disk | FTP | other *** search
/ PC Loisirs 18 / cd.iso / sharewar / mikm202 / source / loaders / uniload.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-18  |  1.8 KB  |  131 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "mtypes.h"
  5. #include "mloader.h"
  6.  
  7.  
  8. BOOL UNI_Test(void)
  9. {
  10.     char id[4];
  11.  
  12.     rewind(modfp);
  13.     if(!fread(id,4,1,modfp)) return 0;
  14.     if(!memcmp(id,"UN04",4)) return 1;
  15.     return 0;
  16. }
  17.  
  18.  
  19. BOOL UNI_Init(void)
  20. {
  21.     return 1;
  22. }
  23.  
  24.  
  25. void UNI_Cleanup(void)
  26. {
  27.     ;
  28. }
  29.  
  30.  
  31. char *StrRead(void)
  32. {
  33.     char *s;
  34.     UWORD len=0;
  35.  
  36.     fread(&len,sizeof(UWORD),1,modfp);
  37.  
  38.     if(!len) return NULL;
  39.  
  40.     s=malloc(len+1);
  41.     fread(s,len,1,modfp);
  42.     s[len]=0;
  43.  
  44.     return s;
  45. }
  46.  
  47.  
  48. UBYTE *TrkRead(void)
  49. {
  50.     UBYTE *t;
  51.     UWORD len;
  52.  
  53.     fread(&len,sizeof(UWORD),1,modfp);
  54.     t=malloc(len);
  55.     fread(t,len,1,modfp);
  56.     return t;
  57. }
  58.  
  59.  
  60.  
  61. BOOL UNI_Load(void)
  62. {
  63.     int t,u;
  64.  
  65.     fseek(modfp,4,SEEK_SET);
  66.  
  67.     // try to read module header
  68.  
  69.     if(!fread(&of,sizeof(UNIHEADER),1,modfp)){
  70.         myerr=ERROR_LOADING_HEADER;
  71.         return 0;
  72.     }
  73.  
  74.     of.songname=StrRead();
  75.     of.modtype=StrRead();
  76.     of.comment=StrRead();   // <- new since UN01
  77.  
  78.     if(!AllocInstruments()) return 0;
  79.  
  80.     if(!AllocTracks()) return 0;
  81.     if(!AllocPatterns()) return 0;
  82.  
  83.     // Read sampleinfos
  84.  
  85.     for(t=0;t<of.numins;t++){
  86.  
  87.         INSTRUMENT *i=&of.instruments[t];
  88.  
  89.         fread(i,sizeof(UNIINSTRUMENT),1,modfp);
  90.         i->insname=StrRead();
  91.  
  92.         if(!AllocSamples(i)) return 0;
  93.  
  94.         for(u=0;u<i->numsmp;u++){
  95.  
  96.             SAMPLE *s=&i->samples[u];
  97.  
  98.             fread(s,sizeof(UNISAMPLE),1,modfp);
  99.             s->samplename=StrRead();
  100.             s->seekpos=0;
  101.         }
  102.     }
  103.  
  104.     // Read patterns
  105.  
  106.     fread(of.pattrows,sizeof(UWORD),of.numpat,modfp);
  107.     fread(of.patterns,sizeof(UWORD),of.numpat*of.numchn,modfp);
  108.  
  109.     // Read tracks
  110.  
  111.     for(t=0;t<of.numtrk;t++){
  112.         of.tracks[t]=TrkRead();
  113.     }
  114.  
  115.     return 1;
  116. }
  117.  
  118.  
  119.  
  120.  
  121.  
  122. LOADER uniload={
  123.     NULL,
  124.     "UNI",
  125.     "UNI loader v0.2",
  126.     UNI_Init,
  127.     UNI_Test,
  128.     UNI_Load,
  129.     UNI_Cleanup
  130. };
  131.