home *** CD-ROM | disk | FTP | other *** search
/ Audio 4.94 - Over 11,000 Files / audio-11000.iso / amiga / midi / med210.lhw / in.adf / Source / med210src.lzh / med-tied.c < prev    next >
C/C++ Source or Header  |  1990-06-23  |  21KB  |  596 lines

  1. /* MED - musiikkieditori ⌐ 1989, 1990 by Teijo Kinnunen */
  2. /* med-tied.c: TiedostojenkΣsittelytoiminnot */
  3. #include <dos.h>
  4. #include "med.h"
  5. #include "medproto.h"
  6.  
  7. #define ID(a,b,c,d) ((long)a << 24|(long)b << 16|(long)c << 8|d)
  8. extern struct Kappale far song;
  9. typedef LONG Fixed;
  10. typedef LONG IFFP;
  11. typedef IFFP ClientProc();
  12. typedef struct _ClientFrame {
  13.     ClientProc *getList,*getProp,*getForm,*getCat; } ClientFrame;
  14. typedef struct { ULONG oneShotHiSamples, repeatHiSamples, samplesPerHiCycle;
  15.     UWORD samplesPerSec; UBYTE ctOctave, sCompression; Fixed volume; }
  16.     Voice8Header;
  17. typedef struct {
  18.    ClientFrame clientFrame;
  19.    UBYTE foundVHDR;
  20.    UBYTE pad1;
  21.    Voice8Header sampHdr;
  22.    } SVXFrame;
  23. extern SVXFrame smusFrame;
  24. extern BYTE *buf;
  25. extern int szBuf;
  26. extern UBYTE samplenum,blocks,lastmidic,lastmidip;
  27. extern UWORD lastrep,lastreplen;
  28. extern struct Screen *screen;
  29. extern struct Window *window;
  30. extern struct ViewPort *vp;
  31. extern struct Lohko far *lohko[];
  32. extern char kappaleennimi[];
  33. static union { struct SoundTrackerKappale oldst; struct Kappale200 oldsng; } far old;
  34. extern struct Gadget far gadget3[],far gadget7[];
  35. extern struct Soitin *sample[];
  36. IFFP __stdargs ReadSample(LONG);
  37. static BOOL loadingsong = FALSE;
  38. static BOOL __regargs LataaLohkot(BOOL);
  39. static char * __regargs LoadST(void);
  40. static char * __regargs Load112(void);
  41. static char * __regargs LataaIFFSoitin(void);
  42. static void Change3to5(void);
  43. BPTR fh = NULL;
  44. static char *prevsn;
  45.  
  46. BOOL NewInstrument(ULONG size,UBYTE num)
  47. {
  48.     if(sample[num]) {
  49.         FreeMem((void *)sample[num],sample[num]->length +
  50.         sizeof(struct Soitin));
  51.         sample[num] = NULL;
  52.     }
  53.     sample[num] = AllocMem(size + sizeof(struct Soitin),
  54.                 MEMF_PUBLIC|MEMF_CHIP|MEMF_CLEAR);
  55.     if(!sample[num]) return(TRUE);
  56.     sample[num]->length = size;
  57.     return(FALSE);
  58. }
  59.  
  60. char *LoadInstrument(char *name,BOOL src)
  61. {
  62.     ULONG length;
  63.     char latausnimi[100],tunnus[5];
  64.     struct SongSample *ss = &song.sample[samplenum];
  65.     if(*name == '\0') return(AskName());
  66.     if(src) ConstructDirName(ss->sname,latausnimi);
  67.     else strcpy(latausnimi,name);
  68.     if(!loadingsong) {
  69.         if(!ss->svol) ss->svol = 64;
  70.         ss->rep = lastrep;
  71.         ss->replen = lastreplen;
  72.         if(lastmidic) {
  73.             ss->midich = lastmidic;
  74.             ss->midipreset = lastmidip;
  75.             Ilmoita("OK.");
  76.             return(NOERR);
  77.         }
  78.     }
  79.     if(gadget7[20].GadgetID & 0x1000) stccpy(ss->sname,latausnimi,39);
  80.     if(!(fh = Open2(latausnimi,MODE_OLDFILE))) return(DISKERR);
  81.     if(Read(fh,tunnus,4) != 4) return("Too short.");
  82.     tunnus[4] = '\0';
  83.     if(!strcmp(tunnus,"FORM")) {
  84.         char *res = LataaIFFSoitin();
  85.         if(!src) PaivitaSoittimennimi();
  86.         return(res);
  87.     }
  88.     Ilmoita("Loading raw sample...");
  89.     Seek(fh,0,OFFSET_END);
  90.     length = Seek(fh,0,OFFSET_BEGINNING);
  91.     if(NewInstrument(length,samplenum)) return(nomem);
  92.     if(Read(fh,(char *)(sample[samplenum]) + sizeof(struct Soitin),
  93.         length) != length) {
  94.         FreeMem((void *)sample[samplenum],
  95.                 sample[samplenum]->length + sizeof(struct Soitin));
  96.         sample[samplenum] = NULL;
  97.         return(DISKERR);
  98.     }
  99.     if(fh) Close(fh);
  100.     fh = NULL;
  101.     if(!src) PaivitaSoittimennimi();
  102.     return(NOERR);
  103. }
  104.  
  105. char *LoadSong(char *nimi)
  106. {
  107.     UWORD scnt,mod = FALSE;
  108.     char *loadres;
  109.     ULONG id;
  110.     if(*nimi == '\0') return(AskName());
  111.     if(!(fh = Open2(nimi,MODE_OLDFILE))) return(DISKERR);
  112.     if(Read(fh,(void *)&id,4) != 4) return("Not a song!");
  113.     if(id == ID('P','A','C','K')) return("I don't load packed songs.");
  114.     if((id & 0xffffff00) == ID('M','E','D',0) && (id & 0xff) > 4)
  115.         return("You need a newer MED.");
  116.     Seek(fh,0,OFFSET_BEGINNING);
  117.     if(prevsn = (char *)AllocMem(63 * 40,MEMF_PUBLIC|MEMF_CLEAR)) {
  118.         for(scnt = 0; scnt < 63; scnt++)
  119.             strcpy(prevsn + scnt * 40,song.sample[scnt].sname);
  120.     }
  121.     if(AlustaKappale(FALSE)) return(nomem);
  122.     NollaaVarit();
  123.     blocks = 0;
  124.     if(id == ID('M','E','D',2)) {
  125.         if(loadres = Load112()) return(loadres);
  126.         Change3to5();
  127.     } else if(id == ID('M','E','D',3)) {
  128.         if(loadres = Load200Song()) return(loadres);
  129.         LoadRGB4(vp,song.rgb,4);    
  130.         Change3to5();
  131.     } else if(id == ID('M','E','D',4)) {
  132.         if(loadres = Load210Song()) return(loadres);
  133.         LoadRGB4(vp,song.rgb,4);
  134.     } else if(id == ID('M','M','D','0')) {
  135.         if(loadres = LoadMod()) return(loadres);
  136.         mod = TRUE;
  137.     } else {
  138.         if(id == ID('S','O','N','G')) Ilmoita("Loading SoundFX-song...");
  139.         else Ilmoita("Loading SoundTracker-song...");
  140.         if(loadres = LoadST()) return(loadres);
  141.     }
  142.     AsetaSuodatin();
  143.     DispVolAndSldType();
  144.     UpdateJumpGadgets();
  145.     PaivitaNaytto(TRUE);
  146.     samplenum = 0;
  147.     SetTempo(song.deftempo);
  148.     PaivitaSoittimennimi();
  149.     loadingsong = TRUE; /*vasta nyt voi virherequesterissa jatkaa*/
  150.     StripPaths();
  151.     if(song.flags & FLAG_INSTRSATT) {
  152.         loadres = LoadAttachedInstrs();
  153.         Ilmoita("Song + samples loaded.");
  154.     }
  155.     if(fh) { Close(fh); fh = 0L; }
  156.     if(!mod && !(song.flags & FLAG_INSTRSATT) && !(loadres = LoadSongSamples()))
  157.         Ilmoita("Loaded.");
  158.     samplenum = 0;
  159.     PaivitaSoittimennimi();
  160.     loadingsong = FALSE;
  161.     return(loadres);
  162. }
  163.  
  164. static BOOL __regargs LataaLohkot(st)
  165. BOOL st; /* SoundTracker ?? */
  166. {
  167.     long jaljella = Seek(fh,0,OFFSET_END),lpt1 = 1024,lpt2 = 1028;
  168.     BOOL error = FALSE;
  169.     ULONG *convblk = AllocMem(1024 + 4,MEMF_PUBLIC|MEMF_CLEAR);
  170.     if(!convblk) return(TRUE);    /* no memory */
  171.     jaljella = Seek(fh,jaljella,OFFSET_BEGINNING) - jaljella;
  172.     for(;;) {
  173.         if(blocks >= 100) return(TRUE); /* Apua...ei enΣΣ!!!! */
  174.         memset((void *)convblk,0,1028);
  175.         if(st) {
  176.             *convblk = 0L;
  177.             if(lpt1 > jaljella) lpt1 = jaljella;
  178.             if(Read(fh,(char *)(convblk + 1),lpt1)
  179.                 < lpt1) { error = TRUE; break; }
  180.             if((jaljella -= 1024) <= 0) break; /* 0 jΣljellΣ */
  181.         } else {
  182.             if(lpt2 > jaljella) lpt2 = jaljella;
  183.             if(Read(fh,(char *)convblk,lpt2) < lpt2)
  184.                 { error = TRUE; break; }
  185.             if((jaljella -= 1028) <= 0) break;
  186.         }
  187.         ConvertTo200((UBYTE *)convblk,(UBYTE *)lohko[blocks],FALSE);
  188.         if(AllocBlock((UWORD)++blocks,4,64)) {
  189.             error = TRUE; /* Out of memory!!*/
  190.             break;
  191.         }
  192.         TulostaLohkoJaSoitin();
  193.     }
  194.     ConvertTo200((UBYTE *)convblk,(UBYTE *)lohko[blocks],FALSE);
  195.     blocks++;
  196.     FreeMem((void *)convblk,1028);
  197.     return(error);
  198. }
  199.  
  200. BOOL diskerr(char *txt)
  201. {
  202.     char virheteksti[45];
  203.     if(fh) { Close(fh); fh = 0L; }
  204.     if(txt == NOERR) return(FALSE);
  205.     DisplayBeep(screen);
  206.     if(txt == DISKERR) {
  207.         switch(IoErr()) {
  208.             case 103: txt = "Insufficient free store"; break;
  209.             case 202: txt = "Object in use"; break;
  210.             case 203: txt = "Object already exists"; break;
  211.             case 204: txt = "Directory not found"; break;
  212.             case 205: txt = "Object not found"; break;
  213.             case 210: txt = "Invalid filename"; break;
  214.             case 212: txt = "Object not of required type"; break;
  215.             case 213: txt = "Disk not validated"; break;
  216.             case 214: txt = "Disk write-protected"; break;
  217.             case 216: txt = "Directory not empty"; break;
  218.             case 218: txt = "Device not mounted"; break;
  219.             case 221: txt = "Disk full"; break;
  220.             case 222: txt = "Protected from deletion"; break;
  221.             case 223: txt = "Protected from writing"; break;
  222.             case 224: txt = "Protected from reading"; break;
  223.             case 225: txt = "Not a DOS disk"; break;
  224.             case 226: txt = "No disk in drive"; break;
  225.             default:  txt = "Failed.";
  226.         }
  227.         strcpy(virheteksti,"E: ");
  228.         strcat(virheteksti,txt);
  229.         txt = virheteksti;
  230.     }
  231.     if(prevsn) { FreeMem(prevsn,63 * 40); prevsn = 0L; }
  232.     Ilmoita(txt);
  233.     return(TRUE);
  234. }
  235.  
  236. static char * __regargs LataaIFFSoitin()
  237. {
  238.     Seek(fh,0,OFFSET_BEGINNING);
  239.     Ilmoita("Loading IFF-sample...");
  240.     if(sample[samplenum]) {
  241.         FreeMem((void *)sample[samplenum],
  242.             sample[samplenum]->length + sizeof(struct Soitin));
  243.         sample[samplenum] = NULL;
  244.     }
  245.     buf = NULL; szBuf = NULL;
  246.     (void)ReadSample((LONG)fh);
  247.     if(fh) Close(fh);
  248.     fh = 0L;
  249.     if(!buf) return("Failed to load.");
  250.     sample[samplenum] = (struct Soitin *)buf;
  251.     sample[samplenum]->length = szBuf;
  252.     switch(smusFrame.sampHdr.ctOctave) {
  253.         case 5:    sample[samplenum]->type = IFF5OCT;    break;
  254.         case 3:    sample[samplenum]->type = IFF3OCT;    break;
  255.         default: sample[samplenum]->type = 0;
  256.     }
  257.     if(loadingsong); /* <- tiedot ovat jo kappaleessa */
  258.     else if(smusFrame.sampHdr.repeatHiSamples) {
  259.         song.sample[samplenum].rep = smusFrame.sampHdr.oneShotHiSamples / 2;
  260.         song.sample[samplenum].replen = smusFrame.sampHdr.repeatHiSamples / 2;
  261.         song.sample[samplenum].svol = 64; /* TΣysillΣ vaan */
  262.     } else {
  263.         song.sample[samplenum].rep = 0;
  264.         song.sample[samplenum].replen = 0;
  265.         song.sample[samplenum].svol = 64;
  266.     }
  267.     return(NOERR);
  268. }
  269.  
  270. void ConvertTo200(UBYTE *from,UBYTE *to,BOOL st24conv)
  271. {
  272.     extern UWORD periodit[];
  273.     register UWORD testper,count;
  274.     register UBYTE newnotenum = 0,instrG_V = 0;
  275.     from += 4;    /* skip 4 bytes */
  276.     to += BLKHDRSZ;
  277.     for(count = 0; count < (64 * 4); count++) {
  278.         testper = *((UWORD *)from);
  279.         from += 2;
  280.         newnotenum = instrG_V = 0;
  281.         if(testper & 0x9000) { testper &= ~0x9000; instrG_V = 1; }
  282.         if(testper)    while(testper < periodit[newnotenum++]);
  283.         if(instrG_V) newnotenum |= 0x80;
  284.         *to++ = newnotenum;
  285.         if(st24conv) { /* convert some ST2.4's cmds to MED equivalents */
  286.             newnotenum = *from++; /* reuse var "newnotenum" */
  287.             if((newnotenum & 0x0f) == 0xd) { /* 0Dxx -> 0F00 */
  288.                 *to++ = (newnotenum & 0xf0) | 0xf;
  289.                 *to++ = 0;
  290.                 from++;
  291.                 continue; /* SoundTracker's Pattern Break */
  292.             } else if((newnotenum & 0x0f) == 0xa) /*Axx->Dxx*/
  293.                 *to++ = (newnotenum & 0xf0) | 0xd;
  294.             else *to++ = newnotenum;
  295.         } else *to++ = *from++;
  296.         *to++ = *from++;
  297.     }
  298. }
  299.  
  300. void DeleteSamplesNotUsed()
  301. { /* this is the routine which preserves the old samples */
  302.     struct Soitin *oldsamples[63];
  303.     UBYTE scnt,scnt2,*tstptr;
  304.     for(scnt = 0; scnt < 63; scnt++) {
  305.         oldsamples[scnt] = sample[scnt]; sample[scnt] = 0L;
  306.     }
  307.     if(!(song.flags & FLAG_INSTRSATT)) {
  308.         for(scnt = 0; scnt < 63; scnt++) {
  309.             if(song.sample[scnt].sname[0]) {
  310.                 for(scnt2 = 0; scnt2 < 63; scnt2++) {
  311.                     tstptr = prevsn + 40 * scnt2;
  312.                     if(*tstptr && !stricmp(song.
  313.                         sample[scnt].sname,tstptr)) {
  314.                         sample[scnt] = oldsamples[scnt2];
  315.                         oldsamples[scnt2] = 0L;
  316.                         *tstptr = '\0';
  317.                         break;
  318.                     }
  319.                 }
  320.             }
  321.         }
  322.     }
  323.     if(prevsn) { FreeMem(prevsn,63 * 40); prevsn = 0L; }
  324.     for(scnt = 0; scnt < 63; scnt++)
  325.         if(oldsamples[scnt]) FreeMem((void *)oldsamples[scnt],
  326.             oldsamples[scnt]->length + sizeof(struct Soitin));
  327. }
  328.  
  329. void clrxtoy(UBYTE x,UBYTE y)
  330. {
  331.     register UBYTE scnt;
  332.     for(scnt = x; scnt < y; scnt++) {
  333.         song.sample[scnt].sname[0] = 0;
  334.         song.sample[scnt].rep = song.sample[scnt].replen = 0;
  335.         song.sample[scnt].svol = song.sample[scnt].strans = 0;
  336.     }
  337. }
  338.  
  339. static char * __regargs Load112()
  340. {
  341.     register UBYTE scnt;
  342.     Ilmoita("Loading MED1.12-song...");
  343.     if(Read(fh,(char *)&old,sizeof(struct Kappale111)) <
  344.         sizeof(struct Kappale111)) return(DISKERR);
  345.     for(scnt = 0; scnt < 31; scnt++) {
  346.         strcpy(song.sample[scnt].sname,old.oldsng.soitin[scnt+1]);
  347.         song.sample[scnt].svol = old.oldsng.soittimenvoimakkuus[scnt+1];
  348.         song.sample[scnt].rep = old.oldsng.stoisto[scnt+1] / 2;
  349.         song.sample[scnt].replen = old.oldsng.stoistonpit[scnt+1] / 2;
  350.         song.sample[scnt].strans = 0;
  351.     }
  352.     song.numblocks = blocks;
  353.     memcpy((void *)song.playseq,(void *)old.oldsng.soittojarjestys,100);
  354.     song.songlen = old.oldsng.kappaleen_pituus;
  355.     song.deftempo = old.oldsng.tempo;
  356.     song.flags = (UBYTE)(old.oldsng.liput);
  357.     song.sliding = old.oldsng.vaihtoja;
  358.     song.jumpmask = old.oldsng.hyppysoitin >> 1;
  359.     LoadRGB4(vp,old.oldsng.rgb,4);
  360.     DeleteSamplesNotUsed();
  361.     clrxtoy(31,63);
  362.     if(LataaLohkot(FALSE)) return(DISKERR);
  363.     return(NOERR);
  364. }
  365.  
  366. static char * __regargs LoadST()
  367. {
  368.     register UBYTE scnt;
  369.     if(Read(fh,(char *)&old,sizeof(struct SoundTrackerKappale)) <
  370.         sizeof(struct SoundTrackerKappale)) return(DISKERR);
  371.     for(scnt = 0; scnt < 15; scnt++) {
  372.         song.sample[scnt].svol = old.oldst.st_ins[scnt].sti_vol;
  373.         song.sample[scnt].rep = old.oldst.st_ins[scnt].sti_repeat / 2;
  374.         song.sample[scnt].replen = old.oldst.st_ins[scnt].sti_replen;
  375.         song.sample[scnt].strans = 0;
  376.         strcpy(song.sample[scnt].sname,old.oldst.st_ins[scnt].sti_nimi);
  377.     }
  378.     song.numblocks = blocks;
  379.     song.deftempo = 6;
  380.     song.songlen = old.oldst.st_kappaleen_pit;
  381.     song.flags |= FLAG_STSLIDE;
  382.     memcpy((void *)(song.playseq),(void *)(old.oldst.st_lohkojarj),128);
  383.     DeleteSamplesNotUsed();
  384.     clrxtoy(15,63);
  385.     if(LataaLohkot(TRUE)) return(DISKERR);
  386.     return(NOERR);
  387. }
  388.  
  389. void StripPaths()
  390. {
  391.     UBYTE node[FNSIZE],scnt;
  392.     if(!(gadget7[21].GadgetID & 0x1000)) return;
  393.     for(scnt = 0; scnt < 63; scnt++) {
  394.         stcgfn(node,song.sample[scnt].sname);
  395.         strcpy(song.sample[scnt].sname,node);
  396.     }
  397. }
  398.  
  399. char *DoSave() /* request the save format and call save function */
  400. {
  401. static UWORD chip pic[] = { /* w = 128, h = 51 */
  402. 0x7fff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xfc00,
  403. 0x3fff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xfc00,
  404. 0x3fff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xfc00,
  405. 0x3fff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xfc00,
  406. 0x3fff,0x3171,0x91e2,0xa3e7,0x6a3c,0x666e,0xd8ff,0xfc00,
  407. 0x3ffe,0xf777,0x7bf6,0xafde,0xaafd,0xdaa4,0xadbf,0xfc00,
  408. 0x3fff,0x3373,0x7bf6,0x27e6,0x2a7c,0xda6a,0x8dff,0xfc00,
  409. 0x3fff,0xd777,0x7bf6,0xaffa,0xb6fd,0xdaae,0xadbf,0xfc00,
  410. 0x3ffe,0x3111,0x9bf6,0xa3c6,0xb63d,0xe6ae,0xadff,0xfc00,
  411. 0x3fff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xfc00,
  412. 0x3bff,0xffff,0xffff,0xffef,0xffff,0xffff,0xffff,0xfc00,
  413. 0x3bff,0xffff,0xffff,0xffef,0xffff,0xffff,0xffff,0xfc00,
  414. 0x3bff,0xfe73,0x6cff,0xffee,0x6d9f,0xcdba,0x6e33,0xfc00,
  415. 0x3bff,0xfded,0x2bff,0xffed,0xe57d,0xba92,0xaeef,0xfc00,
  416. 0x3bff,0xfe6d,0x4a7f,0xffee,0x6948,0xd8aa,0x6e77,0xfc00,
  417. 0x3bff,0xffad,0x6b7f,0xffef,0xad6d,0xeaba,0xeefb,0xfc00,
  418. 0x3bff,0xfc73,0x6cff,0xffec,0x6d9f,0x9aba,0xe227,0xfc00,
  419. 0x3bff,0xffff,0xffff,0xffef,0xffff,0xffff,0xffff,0xfc00,
  420. 0x3800,0x0,0x0,0x20,0x0,0x0,0x0,0xfc00,
  421. 0x3bff,0xffff,0xffff,0xffef,0xffff,0xffff,0xffff,0xfc00,
  422. 0x3bff,0xffff,0xffff,0xffef,0xffff,0xffff,0xffff,0xfc00,
  423. 0x3bff,0xdd99,0xb5c7,0xffef,0xe47e,0xeccd,0xae3f,0xfc00,
  424. 0x3bff,0xc96a,0xb5df,0xffef,0xdefe,0x4b55,0xaeff,0xfc00,
  425. 0x3bff,0xd56a,0xb5cf,0xffef,0xe6e6,0xab55,0xae7f,0xfc00,
  426. 0x3bff,0xdd6a,0xb5df,0xffef,0xfafe,0xeb55,0xaeff,0xfc00,
  427. 0x3bff,0xdd99,0xcc47,0xffef,0xc6fe,0xecce,0x623f,0xfc00,
  428. 0x3bff,0xffff,0xffff,0xffef,0xffff,0xffff,0xffff,0xfc00,
  429. 0x3800,0x0,0x0,0x20,0x0,0x0,0x0,0xfc00,
  430. 0x3bff,0xffff,0x7fff,0xffff,0xffff,0xffff,0xffff,0xfc00,
  431. 0x3bff,0xffff,0x7fff,0xffff,0xffff,0xffff,0xffff,0xfc00,
  432. 0x3be6,0x7bdf,0x799e,0xe7ff,0xffff,0xffff,0xffff,0xfc00,
  433. 0x3bda,0xbb9f,0x76ae,0xfbff,0xffff,0xffff,0xffff,0xfc00,
  434. 0x3bda,0x7bdf,0x769e,0xf7ff,0xffff,0xffff,0xffff,0xfc00,
  435. 0x3bda,0xabdf,0x76aa,0xefff,0xffff,0xffff,0xffff,0xfc00,
  436. 0x3be6,0x778f,0x799d,0xe3ff,0xffff,0xffff,0xffff,0xfc00,
  437. 0x3bff,0xffff,0x7fff,0xffff,0xffff,0xffff,0xffff,0xfc00,
  438. 0x3800,0x1,0x0,0x3f,0xffff,0xffff,0xffff,0xfc00,
  439. 0x3fff,0xffff,0xffff,0xffff,0xff7f,0xffff,0xffff,0xfc00,
  440. 0x3bff,0xffff,0xffff,0xffff,0xff3f,0xffff,0xffff,0xfc00,
  441. 0x3bff,0xffff,0xffff,0xffff,0xff3f,0xffff,0xffff,0xfc00,
  442. 0x3bff,0xd99b,0x7fff,0xffff,0xff3f,0x9b6c,0x8bff,0xfc00,
  443. 0x3bff,0xd769,0x7fff,0xffff,0xff3f,0x752b,0xbbff,0xfc00,
  444. 0x3bff,0xd76a,0x7fff,0xffff,0xff3f,0x714b,0x9bff,0xfc00,
  445. 0x3bff,0xd76b,0x7fff,0xffff,0xff3f,0x756b,0xbbff,0xfc00,
  446. 0x3bff,0xd99b,0x7fff,0xffff,0xff3f,0x956c,0x88ff,0xfc00,
  447. 0x3bff,0xffff,0xffff,0xffff,0xff3f,0xffff,0xffff,0xfc00,
  448. 0x3800,0x0,0x7,0xffff,0xff00,0x0,0x1,0xfc00,
  449. 0x3fff,0xffff,0xffff,0xffff,0xff00,0x0,0x0,0xfc00,
  450. 0x3fff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xfc00,
  451. 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc00,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x400,
  452. /*------ plane # 1: --------*/
  453. 0x8000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
  454. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xf000,
  455. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xf000,
  456. 0xffff,0x3171,0x91e2,0xa3e7,0x6a3c,0x666e,0xd8ff,0xf000,
  457. 0xfffe,0xf777,0x7bf6,0xafde,0xaafd,0xdaa4,0xadbf,0xf000,
  458. 0xffff,0x3373,0x7bf6,0x27e6,0x2a7c,0xda6a,0x8dff,0xf000,
  459. 0xffff,0xd777,0x7bf6,0xaffa,0xb6fd,0xdaae,0xadbf,0xf000,
  460. 0xfffe,0x3111,0x9bf6,0xa3c6,0xb63d,0xe6ae,0xadff,0xf000,
  461. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xf000,
  462. 0xfc00,0x0,0x0,0x10,0x0,0x0,0x0,0x7000,
  463. 0xffff,0xffff,0xffff,0xffdf,0xffff,0xffff,0xffff,0x7000,
  464. 0xffff,0xfe73,0x6cff,0xffde,0x6d9f,0xcdba,0x6e33,0x7000,
  465. 0xffff,0xfded,0x2bff,0xffdd,0xe57d,0xba92,0xaeef,0x7000,
  466. 0xffff,0xfe6d,0x4a7f,0xffde,0x6948,0xd8aa,0x6e77,0x7000,
  467. 0xffff,0xffad,0x6b7f,0xffdf,0xad6d,0xeaba,0xeefb,0x7000,
  468. 0xffff,0xfc73,0x6cff,0xffdc,0x6d9f,0x9aba,0xe227,0x7000,
  469. 0xffff,0xffff,0xffff,0xffdf,0xffff,0xffff,0xffff,0x7000,
  470. 0xffff,0xffff,0xffff,0xffdf,0xffff,0xffff,0xffff,0x7000,
  471. 0xfc00,0x0,0x0,0x10,0x0,0x0,0x0,0x7000,
  472. 0xffff,0xffff,0xffff,0xffdf,0xffff,0xffff,0xffff,0x7000,
  473. 0xffff,0xdd99,0xb5c7,0xffdf,0xe47e,0xeccd,0xae3f,0x7000,
  474. 0xffff,0xc96a,0xb5df,0xffdf,0xdefe,0x4b55,0xaeff,0x7000,
  475. 0xffff,0xd56a,0xb5cf,0xffdf,0xe6e6,0xab55,0xae7f,0x7000,
  476. 0xffff,0xdd6a,0xb5df,0xffdf,0xfafe,0xeb55,0xaeff,0x7000,
  477. 0xffff,0xdd99,0xcc47,0xffdf,0xc6fe,0xecce,0x623f,0x7000,
  478. 0xffff,0xffff,0xffff,0xffdf,0xffff,0xffff,0xffff,0x7000,
  479. 0xffff,0xffff,0xffff,0xffdf,0xffff,0xffff,0xffff,0x7000,
  480. 0xfc00,0x0,0x8000,0x1f,0xffff,0xffff,0xffff,0xf000,
  481. 0xffff,0xfffe,0xffff,0xffdf,0xffff,0xffff,0xffff,0xf000,
  482. 0xffe6,0x7bfe,0xf99e,0xffdf,0xffff,0xffff,0xffff,0xf000,
  483. 0xffda,0xbbfe,0xf6ae,0xffdf,0xffff,0xffff,0xffff,0xf000,
  484. 0xffda,0x7bfe,0xf69e,0xffdf,0xffff,0xffff,0xffff,0xf000,
  485. 0xffda,0xabfe,0xf6aa,0xffdf,0xffff,0xffff,0xffff,0xf000,
  486. 0xffe6,0x77fe,0xf99d,0xffdf,0xffff,0xffff,0xffff,0xf000,
  487. 0xffff,0xfffe,0xffff,0xffdf,0xffff,0xffff,0xffff,0xf000,
  488. 0xffff,0xfffe,0xffff,0xffdf,0xffff,0xffff,0xffff,0xf000,
  489. 0xffff,0xffff,0xffff,0xffff,0xff80,0x0,0x0,0x7000,
  490. 0xfc00,0x0,0x3,0xffff,0xffc0,0x0,0x0,0x7000,
  491. 0xffff,0xffff,0xfffb,0xffff,0xffff,0xffff,0xfffe,0x7000,
  492. 0xffff,0xd99b,0x7ffb,0xffff,0xffff,0x9b6c,0x8bfe,0x7000,
  493. 0xffff,0xd769,0x7ffb,0xffff,0xffff,0x752b,0xbbfe,0x7000,
  494. 0xffff,0xd76a,0x7ffb,0xffff,0xffff,0x714b,0x9bfe,0x7000,
  495. 0xffff,0xd76b,0x7ffb,0xffff,0xffff,0x756b,0xbbfe,0x7000,
  496. 0xffff,0xd99b,0x7ffb,0xffff,0xffff,0x956c,0x88fe,0x7000,
  497. 0xffff,0xffff,0xfffb,0xffff,0xffff,0xffff,0xfffe,0x7000,
  498. 0xffff,0xffff,0xfffb,0xffff,0xffff,0xffff,0xfffe,0x7000,
  499. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0x7000,
  500. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xf000,
  501. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xf000,
  502. 0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xf800 };
  503. static BYTE icon = -1;
  504. static struct Gadget far wgd[] = {
  505.     { &wgd[1],6,11,52,7,GADGHNONE,GADGIMMEDIATE,BOOLGADGET,NULL,NULL,
  506.     NULL,NULL,NULL,0,NULL },    /* song */
  507.     { &wgd[2],60,11,52,7,GADGHNONE,GADGIMMEDIATE,BOOLGADGET,NULL,NULL,
  508.     NULL,NULL,NULL,1,NULL },    /* song + samples */
  509.     { &wgd[3],6,20,52,7,GADGHNONE,GADGIMMEDIATE,BOOLGADGET,NULL,NULL,
  510.     NULL,NULL,NULL,2,NULL },    /* module */
  511.     { &wgd[4],6,29,25,7,GADGHNONE,GADGIMMEDIATE,BOOLGADGET,NULL,NULL,
  512.     NULL,NULL,NULL,3,NULL },    /* obj1 */
  513.     { &wgd[5],35,29,25,7,GADGHNONE,GADGIMMEDIATE,BOOLGADGET,NULL,NULL,
  514.     NULL,NULL,NULL,4,NULL },    /* obj2 */
  515.     { &wgd[6],60,20,52,7,GADGHNONE,GADGIMMEDIATE,BOOLGADGET,NULL,NULL,
  516.     NULL,NULL,NULL,5,NULL },    /* ST/NT-module */
  517.     { &wgd[7],6,39,39,7,GADGHNONE,GADGIMMEDIATE,BOOLGADGET,NULL,NULL,
  518.     NULL,NULL,NULL,6,NULL },    /* icon */
  519.     { NULL,74,39,37,7,GADGHNONE,GADGIMMEDIATE,BOOLGADGET,NULL,NULL,
  520.     NULL,NULL,NULL,7,NULL }    /* cancel */
  521. };
  522. static struct NewWindow far wnw = { 101,2,118,51,0,0,GADGETDOWN|RAWKEY,
  523.     SMART_REFRESH|ACTIVATE|BORDERLESS|NOCAREREFRESH|RMBTRAP,&wgd[0],0L,0L,0L,0L,
  524.     0,0,0,0,CUSTOMSCREEN };
  525.     WORD sel = -1;
  526.     static struct Image far img = { 0,0,118,51,2,pic,0x3,0x0,0L };
  527.     struct IntuiMessage *m;
  528.     struct Window *w; /* and now...let the code begin!!! */
  529.     wnw.Screen = screen;
  530.     if(!(w = OpenWindow(&wnw))) return(nomem);
  531.     DrawImage(w->RPort,&img,0,0);
  532.     SetDrMd(w->RPort,COMPLEMENT);
  533.     w->RPort->Mask = 0x3;
  534.     if(icon) RectFill(w->RPort,6,39,44,45);
  535.     for(;;) {
  536.         WaitPort(w->UserPort);
  537.         m = (struct IntuiMessage *)GetMsg(w->UserPort);
  538.         if(m->Class == RAWKEY && m->Code == 0x45) return(NOERR); /* esc */
  539.         else if(m->Class == GADGETDOWN) {
  540.             if(m->IAddress == (APTR)(&wgd[6])) {
  541.                 icon = !icon;
  542.                 RectFill(w->RPort,6,39,44,45);
  543.             } else sel = ((struct Gadget *)(m->IAddress))->
  544.                     GadgetID;
  545.         }
  546.         ReplyMsg((struct Message *)m);
  547.         if(sel != -1) break;
  548.     }
  549.     CloseWindow(w);
  550.     switch(sel) {
  551.         case 0: return(SaveSong(kappaleennimi,FALSE,icon));
  552.         case 1: return(SaveSong(kappaleennimi,TRUE,icon));
  553.         case 2: return(SaveMod(kappaleennimi));
  554.         case 3: return(WriteObj(kappaleennimi,0));
  555.         case 4: return(WriteObj(kappaleennimi,1));
  556.         case 5: return(SaveSTMod(kappaleennimi));
  557.     }
  558.     return(NOERR);
  559. }
  560.  
  561. char *DelFile()
  562. {
  563.     LONG succ;
  564.     extern BPTR currdir;
  565.     BPTR prevdir;
  566.     char delname[FMSIZE];
  567.     strcpy(delname,kappaleennimi);
  568.     Ilmoita("Really want to delete??");
  569.     if(!Continue()) return("All right!! Not deleted.");
  570.     if(currdir) prevdir = CurrentDir(currdir);
  571.     succ = DeleteFile(delname);
  572.     if(succ) RemFilename(delname); /* delete from requester */
  573.     strcat(delname,".info");
  574.     DeleteFile(delname); /* don't care if it doesn't exist!! */
  575.     if(currdir) CurrentDir(prevdir);
  576.     if(!succ) return(DISKERR);
  577.     Ilmoita("Deleted.");
  578.     return(NOERR);
  579. }
  580.  
  581. static void Change3to5() /* old MED vibrato */
  582. {
  583.     UWORD blk;
  584.     UBYTE *ptr,*end;
  585.     for(blk = 0; blk < blocks; blk++) {
  586.         ptr = lohko[blk]->music;
  587.         end = ptr + 3 * (lohko[blk]->lines + 1) * lohko[blk]->numtracks;
  588.         while(ptr < end) {
  589.             if((*(ptr+1) & 0x0f) == 0x03) {
  590.                 *(ptr+1) &= 0xf0; *(ptr+1) |= 0x05;
  591.             }
  592.             ptr += 3;
  593.         }
  594.     }
  595. }
  596.