home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 25 / GNOME_DEMO.iso / amiga / music / mikmod.lzx / mikmod / mplayer.c < prev    next >
C/C++ Source or Header  |  1999-01-06  |  29KB  |  1,330 lines

  1. /*
  2.  
  3. Name:
  4. MPLAYER.C
  5.  
  6. Description:
  7. The actual modplaying routines
  8.  
  9. Portability:
  10. All systems - all compilers
  11.  
  12. */
  13. #include <stdlib.h>
  14. #include "mikmod.h"
  15.  
  16. UNIMOD *pf;                     /* <- this modfile is being played */
  17. UWORD reppos;                   /* patternloop position */
  18. UWORD repcnt;                   /* times to loop */
  19. UWORD vbtick;                   /* tick counter */
  20. UWORD patbrk;                   /* position where to start a new pattern */
  21. UBYTE patdly;                   /* patterndelay counter */
  22. UBYTE patdly2;                  /* patterndelay counter */
  23. UWORD numrow;                   /* number of rows on current pattern */
  24. SWORD  posjmp;                   /*      flag to indicate a position jump is needed...
  25.                             changed since 1.00: now also indicates the
  26.                             direction the position has to jump to:
  27.  
  28.                             0: Don't do anything
  29.                             1: Jump back 1 position
  30.                             2: Restart on current position
  31.                             3: Jump forward 1 position
  32.                         */
  33. int   forbid;                   /* forbidflag */
  34. static int isfirst;
  35.  
  36. /*
  37.     Set forbid to 1 when you want to modify any of the mp_sngpos, mp_patpos etc.
  38.     variables and clear it when you're done. This prevents getting strange
  39.     results due to intermediate interrupts.
  40. */
  41.  
  42.  
  43. AUDTMP mp_audio[32];    /* max 32 channels */
  44. UBYTE  mp_bpm;                  /* beats-per-minute speed */
  45. UWORD  mp_patpos;               /* current row number (0-255) */
  46. SWORD  mp_sngpos;               /* current song position */
  47. UWORD  mp_sngspd;               /* current songspeed */
  48. UWORD  mp_channel;              /* channel it's working on */
  49. BOOL   mp_extspd=1;             /* extended speed flag, default enabled */
  50. BOOL   mp_panning=1;    /* panning flag, default enabled */
  51. BOOL   mp_loop=0;               /* loop module ? */
  52. UBYTE  mp_volume=100;   /* song volume (0-100) */
  53. AUDTMP *a;                              /* current AUDTMP it's working on */
  54.  
  55.  
  56. UWORD mytab[12]={
  57.     1712*16,1616*16,1524*16,1440*16,1356*16,1280*16,
  58.     1208*16,1140*16,1076*16,1016*16,960*16,907*16
  59. };
  60.  
  61. static UBYTE VibratoTable[32]={
  62.     0,24,49,74,97,120,141,161,
  63.     180,197,212,224,235,244,250,253,
  64.     255,253,250,244,235,224,212,197,
  65.     180,161,141,120,97,74,49,24
  66. };
  67.  
  68.  
  69. /* linear periods to frequency translation table: */
  70.  
  71. UWORD lintab[768]={
  72. 16726,16741,16756,16771,16786,16801,16816,16832,16847,16862,16877,16892,16908,16923,16938,16953,
  73. 16969,16984,16999,17015,17030,17046,17061,17076,17092,17107,17123,17138,17154,17169,17185,17200,
  74. 17216,17231,17247,17262,17278,17293,17309,17325,17340,17356,17372,17387,17403,17419,17435,17450,
  75. 17466,17482,17498,17513,17529,17545,17561,17577,17593,17608,17624,17640,17656,17672,17688,17704,
  76. 17720,17736,17752,17768,17784,17800,17816,17832,17848,17865,17881,17897,17913,17929,17945,17962,
  77. 17978,17994,18010,18027,18043,18059,18075,18092,18108,18124,18141,18157,18174,18190,18206,18223,
  78. 18239,18256,18272,18289,18305,18322,18338,18355,18372,18388,18405,18421,18438,18455,18471,18488,
  79. 18505,18521,18538,18555,18572,18588,18605,18622,18639,18656,18672,18689,18706,18723,18740,18757,
  80. 18774,18791,18808,18825,18842,18859,18876,18893,18910,18927,18944,18961,18978,18995,19013,19030,
  81. 19047,19064,19081,19099,19116,19133,19150,19168,19185,19202,19220,19237,19254,19272,19289,19306,
  82. 19324,19341,19359,19376,19394,19411,19429,19446,19464,19482,19499,19517,19534,19552,19570,19587,
  83. 19605,19623,19640,19658,19676,19694,19711,19729,19747,19765,19783,19801,19819,19836,19854,19872,
  84. 19890,19908,19926,19944,19962,19980,19998,20016,20034,20052,20071,20089,20107,20125,20143,20161,
  85. 20179,20198,20216,20234,20252,20271,20289,20307,20326,20344,20362,20381,20399,20418,20436,20455,
  86. 20473,20492,20510,20529,20547,20566,20584,20603,20621,20640,20659,20677,20696,20715,20733,20752,
  87. 20771,20790,20808,20827,20846,20865,20884,20902,20921,20940,20959,20978,20997,21016,21035,21054,
  88. 21073,21092,21111,21130,21149,21168,21187,21206,21226,21245,21264,21283,21302,21322,21341,21360,
  89. 21379,21399,21418,21437,21457,21476,21496,21515,21534,21554,21573,21593,21612,21632,21651,21671,
  90. 21690,21710,21730,21749,21769,21789,21808,21828,21848,21867,21887,21907,21927,21946,21966,21986,
  91. 22006,22026,22046,22066,22086,22105,22125,22145,22165,22185,22205,22226,22246,22266,22286,22306,
  92. 22326,22346,22366,22387,22407,22427,22447,22468,22488,22508,22528,22549,22569,22590,22610,22630,
  93. 22651,22671,22692,22712,22733,22753,22774,22794,22815,22836,22856,22877,22897,22918,22939,22960,
  94. 22980,23001,23022,23043,23063,23084,23105,23126,23147,23168,23189,23210,23230,23251,23272,23293,
  95. 23315,23336,23357,23378,23399,23420,23441,23462,23483,23505,23526,23547,23568,23590,23611,23632,
  96. 23654,23675,23696,23718,23739,23761,23782,23804,23825,23847,23868,23890,23911,23933,23954,23976,
  97. 23998,24019,24041,24063,24084,24106,24128,24150,24172,24193,24215,24237,24259,24281,24303,24325,
  98. 24347,24369,24391,24413,24435,24457,24479,24501,24523,24545,24567,24590,24612,24634,24656,24679,
  99. 24701,24723,24746,24768,24790,24813,24835,24857,24880,24902,24925,24947,24970,24992,25015,25038,
  100. 25060,25083,25105,25128,25151,25174,25196,25219,25242,25265,25287,25310,25333,25356,25379,25402,
  101. 25425,25448,25471,25494,25517,25540,25563,25586,25609,25632,25655,25678,25702,25725,25748,25771,
  102. 25795,25818,25841,25864,25888,25911,25935,25958,25981,26005,26028,26052,26075,26099,26123,26146,
  103. 26170,26193,26217,26241,26264,26288,26312,26336,26359,26383,26407,26431,26455,26479,26502,26526,
  104. 26550,26574,26598,26622,26646,26670,26695,26719,26743,26767,26791,26815,26839,26864,26888,26912,
  105. 26937,26961,26985,27010,27034,27058,27083,27107,27132,27156,27181,27205,27230,27254,27279,27304,
  106. 27328,27353,27378,27402,27427,27452,27477,27502,27526,27551,27576,27601,27626,27651,27676,27701,
  107. 27726,27751,27776,27801,27826,27851,27876,27902,27927,27952,27977,28003,28028,28053,28078,28104,
  108. 28129,28155,28180,28205,28231,28256,28282,28307,28333,28359,28384,28410,28435,28461,28487,28513,
  109. 28538,28564,28590,28616,28642,28667,28693,28719,28745,28771,28797,28823,28849,28875,28901,28927,
  110. 28953,28980,29006,29032,29058,29084,29111,29137,29163,29190,29216,29242,29269,29295,29322,29348,
  111. 29375,29401,29428,29454,29481,29507,29534,29561,29587,29614,29641,29668,29694,29721,29748,29775,
  112. 29802,29829,29856,29883,29910,29937,29964,29991,30018,30045,30072,30099,30126,30154,30181,30208,
  113. 30235,30263,30290,30317,30345,30372,30400,30427,30454,30482,30509,30537,30565,30592,30620,30647,
  114. 30675,30703,30731,30758,30786,30814,30842,30870,30897,30925,30953,30981,31009,31037,31065,31093,
  115. 31121,31149,31178,31206,31234,31262,31290,31319,31347,31375,31403,31432,31460,31489,31517,31546,
  116. 31574,31602,31631,31660,31688,31717,31745,31774,31803,31832,31860,31889,31918,31947,31975,32004,
  117. 32033,32062,32091,32120,32149,32178,32207,32236,32265,32295,32324,32353,32382,32411,32441,32470,
  118. 32499,32529,32558,32587,32617,32646,32676,32705,32735,32764,32794,32823,32853,32883,32912,32942,
  119. 32972,33002,33031,33061,33091,33121,33151,33181,33211,33241,33271,33301,33331,33361,33391,33421
  120. };
  121.  
  122.  
  123.  
  124.  
  125. #define LOGFAC 2*16
  126.  
  127. UWORD logtab[]={
  128.     LOGFAC*907,LOGFAC*900,LOGFAC*894,LOGFAC*887,LOGFAC*881,LOGFAC*875,LOGFAC*868,LOGFAC*862,
  129.     LOGFAC*856,LOGFAC*850,LOGFAC*844,LOGFAC*838,LOGFAC*832,LOGFAC*826,LOGFAC*820,LOGFAC*814,
  130.     LOGFAC*808,LOGFAC*802,LOGFAC*796,LOGFAC*791,LOGFAC*785,LOGFAC*779,LOGFAC*774,LOGFAC*768,
  131.     LOGFAC*762,LOGFAC*757,LOGFAC*752,LOGFAC*746,LOGFAC*741,LOGFAC*736,LOGFAC*730,LOGFAC*725,
  132.     LOGFAC*720,LOGFAC*715,LOGFAC*709,LOGFAC*704,LOGFAC*699,LOGFAC*694,LOGFAC*689,LOGFAC*684,
  133.     LOGFAC*678,LOGFAC*675,LOGFAC*670,LOGFAC*665,LOGFAC*660,LOGFAC*655,LOGFAC*651,LOGFAC*646,
  134.     LOGFAC*640,LOGFAC*636,LOGFAC*632,LOGFAC*628,LOGFAC*623,LOGFAC*619,LOGFAC*614,LOGFAC*610,
  135.     LOGFAC*604,LOGFAC*601,LOGFAC*597,LOGFAC*592,LOGFAC*588,LOGFAC*584,LOGFAC*580,LOGFAC*575,
  136.     LOGFAC*570,LOGFAC*567,LOGFAC*563,LOGFAC*559,LOGFAC*555,LOGFAC*551,LOGFAC*547,LOGFAC*543,
  137.     LOGFAC*538,LOGFAC*535,LOGFAC*532,LOGFAC*528,LOGFAC*524,LOGFAC*520,LOGFAC*516,LOGFAC*513,
  138.     LOGFAC*508,LOGFAC*505,LOGFAC*502,LOGFAC*498,LOGFAC*494,LOGFAC*491,LOGFAC*487,LOGFAC*484,
  139.     LOGFAC*480,LOGFAC*477,LOGFAC*474,LOGFAC*470,LOGFAC*467,LOGFAC*463,LOGFAC*460,LOGFAC*457,
  140.     LOGFAC*453,LOGFAC*450,LOGFAC*447,LOGFAC*443,LOGFAC*440,LOGFAC*437,LOGFAC*434,LOGFAC*431
  141. };
  142.  
  143.  
  144. SWORD Interpolate(SWORD p,SWORD p1,SWORD p2,SWORD v1,SWORD v2)
  145. {
  146.     SWORD dp,dv,di;
  147.  
  148.     if(p1==p2) return v1;
  149.  
  150.     dv=v2-v1;
  151.     dp=p2-p1;
  152.     di=p-p1;
  153.  
  154.     return v1 + ((SLONG)(di*dv) / dp);
  155. }
  156.  
  157.  
  158. UWORD getlinearperiod(UBYTE note,UWORD fine)
  159. {
  160.     return((10L*12*16*4)-((UWORD)note*16*4)-(fine/2)+64);
  161. }
  162.  
  163.  
  164. UWORD getlogperiod(UBYTE note,UWORD fine)
  165. {
  166.     UBYTE n,o;
  167.     UWORD p1,p2,i;
  168.  
  169.     n=note%12;
  170.     o=note/12;
  171.     i=(n<<3)+(fine>>4);                     /* n*8 + fine/16 */
  172.  
  173.     p1=logtab[i];
  174.     p2=logtab[i+1];
  175.  
  176.     return(Interpolate(fine/16,0,15,p1,p2)>>o);
  177. }
  178.  
  179.  
  180. UWORD getoldperiod(UBYTE note,UWORD c2spd)
  181. {
  182.     UBYTE n,o;
  183.     ULONG period;
  184.  
  185.     if(!c2spd) return 4242;         /* <- prevent divide overflow.. (42 eheh) */
  186.  
  187.     n=note%12;
  188.     o=note/12;
  189.     period=((8363L*mytab[n]) >> o )/c2spd;
  190.     return period;
  191. }
  192.  
  193.  
  194.  
  195. UWORD GetPeriod(UBYTE note,UWORD c2spd)
  196. {
  197.     if(pf->flags&UF_XMPERIODS){
  198.         return (pf->flags&UF_LINEAR) ? getlinearperiod(note,c2spd) : getlogperiod(note,c2spd);
  199.     }
  200.     return(getoldperiod(note,c2spd));
  201. }
  202.  
  203.  
  204.  
  205. void DoEEffects(UBYTE dat)
  206. {
  207.     UBYTE nib;
  208.  
  209.     nib=dat&0xf;
  210.  
  211.     switch(dat>>4){
  212.  
  213.         case 0x0:       /* filter toggle, not supported */
  214.                 break;
  215.  
  216.         case 0x1:       /* fineslide up */
  217.                 if(!vbtick) a->tmpperiod-=(nib<<2);
  218.                 break;
  219.  
  220.         case 0x2:       /* fineslide dn */
  221.                 if(!vbtick) a->tmpperiod+=(nib<<2);
  222.                 break;
  223.  
  224.         case 0x3:       /* glissando ctrl */
  225.                 a->glissando=nib;
  226.                 break;
  227.  
  228.         case 0x4:       /* set vibrato waveform */
  229.                 a->wavecontrol&=0xf0;
  230.                 a->wavecontrol|=nib;
  231.                 break;
  232.  
  233.         case 0x5:       /* set finetune */
  234. /*                              a->c2spd=finetune[nib]; */
  235. /*                              a->tmpperiod=GetPeriod(a->note,pf->samples[a->sample].transpose,a->c2spd); */
  236.                 break;
  237.  
  238.         case 0x6:       /* set patternloop */
  239.  
  240.                 if(vbtick) break;
  241.  
  242.                 /* hmm.. this one is a real kludge. But now it
  243.                    works. */
  244.  
  245.                 if(nib){                /* set reppos or repcnt ? */
  246.  
  247.                     /* set repcnt, so check if repcnt already is set,
  248.                        which means we are already looping */
  249.  
  250.                     if(repcnt>0)
  251.                         repcnt--;               /* already looping, decrease counter */
  252.                     else
  253.                         repcnt=nib;             /* not yet looping, so set repcnt */
  254.  
  255.                     if(repcnt)                      /* jump to reppos if repcnt>0 */
  256.                         mp_patpos=reppos;
  257.                 }
  258.                 else{
  259.                     reppos=mp_patpos-1;     /* set reppos */
  260.                 }
  261.                 break;
  262.  
  263.  
  264.         case 0x7:       /* set tremolo waveform */
  265.                 a->wavecontrol&=0x0f;
  266.                 a->wavecontrol|=nib<<4;
  267.                 break;
  268.  
  269.         case 0x8:       /* not used */
  270.                 if(mp_panning) a->panning=nib<<4;
  271.                 break;
  272.  
  273.         case 0x9:       /* retrig note */
  274.  
  275.                 /* only retrigger if
  276.                    data nibble > 0 */
  277.  
  278.                 if(nib>0){
  279.                     if(a->retrig==0){
  280.  
  281.                         /* when retrig counter reaches 0,
  282.                            reset counter and restart the sample */
  283.  
  284.                         a->kick=1;
  285.                         a->retrig=nib;
  286.                     }
  287.                     a->retrig--; /* countdown */
  288.                 }
  289.                 break;
  290.  
  291.         case 0xa:       /* fine volume slide up */
  292.                 if(vbtick) break;
  293.  
  294.                 a->tmpvolume+=nib;
  295.                 if(a->tmpvolume>64) a->tmpvolume=64;
  296.                 break;
  297.  
  298.         case 0xb:       /* fine volume slide dn */
  299.                 if(vbtick) break;
  300.  
  301.                 a->tmpvolume-=nib;
  302.                 if(a->tmpvolume<0) a->tmpvolume=0;
  303.                 break;
  304.  
  305.         case 0xc:       /* cut note */
  306.  
  307.                 /* When vbtick reaches the cut-note value,
  308.                    turn the volume to zero ( Just like
  309.                    on the amiga) */
  310.  
  311.                 if(vbtick>=nib){
  312.                     a->tmpvolume=0;                 /* just turn the volume down */
  313.                 }
  314.                 break;
  315.  
  316.         case 0xd:       /* note delay */
  317.  
  318.                 /* delay the start of the
  319.                    sample until vbtick==nib */
  320.  
  321.                 if(vbtick==nib){
  322.                     a->kick=1;
  323.                 }
  324.                 else a->kick=0;
  325.                 break;
  326.  
  327.         case 0xe:       /* pattern delay */
  328.                 if(vbtick) break;
  329.                 if(!patdly2) patdly=nib+1;                              /* only once (when vbtick=0) */
  330.                 break;
  331.  
  332.         case 0xf:       /* invert loop, not supported */
  333.                 break;
  334.     }
  335. }
  336.  
  337.  
  338. void DoVibrato(void)
  339. {
  340.     UBYTE q;
  341.     UWORD temp;
  342.  
  343.     q=(a->vibpos>>2)&0x1f;
  344.  
  345.     switch(a->wavecontrol&3){
  346.  
  347.         case 0: /* sine */
  348.             temp=VibratoTable[q];
  349.             break;
  350.  
  351.         case 1: /* ramp down */
  352.             q<<=3;
  353.             if(a->vibpos<0) q=255-q;
  354.             temp=q;
  355.             break;
  356.  
  357.         case 2: /* square wave */
  358.             temp=255;
  359.             break;
  360.     }
  361.  
  362.     temp*=a->vibdepth;
  363.     temp>>=7;
  364.     temp<<=2;
  365.  
  366.     if(a->vibpos>=0)
  367.         a->period=a->tmpperiod+temp;
  368.     else
  369.         a->period=a->tmpperiod-temp;
  370.  
  371.     if(vbtick) a->vibpos+=a->vibspd;        /* do not update when vbtick==0 */
  372. }
  373.  
  374.  
  375.  
  376. void DoTremolo(void)
  377. {
  378.     UBYTE q;
  379.     UWORD temp;
  380.  
  381.     q=(a->trmpos>>2)&0x1f;
  382.  
  383.     switch((a->wavecontrol>>4)&3){
  384.  
  385.         case 0: /* sine */
  386.             temp=VibratoTable[q];
  387.             break;
  388.  
  389.         case 1: /* ramp down */
  390.             q<<=3;
  391.             if(a->trmpos<0) q=255-q;
  392.             temp=q;
  393.             break;
  394.  
  395.         case 2: /* square wave */
  396.             temp=255;
  397.             break;
  398.     }
  399.  
  400.     temp*=a->trmdepth;
  401.     temp>>=6;
  402.  
  403.     if(a->trmpos>=0){
  404.         a->volume=a->tmpvolume+temp;
  405.         if(a->volume>64) a->volume=64;
  406.     }
  407.     else{
  408.         a->volume=a->tmpvolume-temp;
  409.         if(a->volume<0) a->volume=0;
  410.     }
  411.  
  412.     if(vbtick) a->trmpos+=a->trmspd;        /* do not update when vbtick==0 */
  413. }
  414.  
  415.  
  416. void DoVolSlide(UBYTE dat)
  417. {
  418.     if(!vbtick) return;             /* do not update when vbtick==0 */
  419.  
  420.     a->tmpvolume+=dat>>4;           /* volume slide */
  421.     a->tmpvolume-=dat&0xf;
  422.     if(a->tmpvolume<0) a->tmpvolume=0;
  423.     if(a->tmpvolume>64) a->tmpvolume=64;
  424. }
  425.  
  426.  
  427.  
  428. void DoS3MVolSlide(UBYTE inf)
  429. {
  430.     UBYTE lo,hi;
  431.  
  432.     if(inf){
  433.         a->s3mvolslide=inf;
  434.     }
  435.     inf=a->s3mvolslide;
  436.  
  437.     lo=inf&0xf;
  438.     hi=inf>>4;
  439.  
  440.     if(hi==0){
  441.         a->tmpvolume-=lo;
  442.     }
  443.     else if(lo==0){
  444.         a->tmpvolume+=hi;
  445.     }
  446.     else if(hi==0xf){
  447.         if(!vbtick) a->tmpvolume-=lo;
  448.     }
  449.     else if(lo==0xf){
  450.         if(!vbtick) a->tmpvolume+=hi;
  451.     }
  452.  
  453.     if(a->tmpvolume<0) a->tmpvolume=0;
  454.     if(a->tmpvolume>64) a->tmpvolume=64;
  455. }
  456.  
  457.  
  458.  
  459. void DoXMVolSlide(UBYTE inf)
  460. {
  461.     UBYTE lo,hi;
  462.  
  463.     if(inf){
  464.         a->s3mvolslide=inf;
  465.     }
  466.     inf=a->s3mvolslide;
  467.  
  468.     if(!vbtick) return;
  469.  
  470.     lo=inf&0xf;
  471.     hi=inf>>4;
  472.  
  473.     if(hi==0)
  474.         a->tmpvolume-=lo;
  475.     else
  476.         a->tmpvolume+=hi;
  477.  
  478.     if(a->tmpvolume<0) a->tmpvolume=0;
  479.     if(a->tmpvolume>64) a->tmpvolume=64;
  480. }
  481.  
  482.  
  483. void DoXMPanSlide(UBYTE inf)
  484. {
  485.     UBYTE lo,hi;
  486.     SWORD pan;
  487.  
  488.  
  489.     if(inf!=0) a->pansspd=inf;
  490.     else inf=a->pansspd;
  491.  
  492.     if(!vbtick) return;
  493.  
  494.     lo=inf&0xf;
  495.     hi=inf>>4;
  496.  
  497.     /* slide right has absolute priority: */
  498.  
  499.     if(hi) lo=0;
  500.  
  501.     pan=a->panning;
  502.  
  503.     pan-=lo;
  504.     pan+=hi;
  505.  
  506.     if(pan<0) pan=0;
  507.     if(pan>255) pan=255;
  508.  
  509.     a->panning=pan;
  510. }
  511.  
  512.  
  513.  
  514. void DoS3MSlideDn(UBYTE inf)
  515. {
  516.     UBYTE hi,lo;
  517.  
  518.     if(inf!=0) a->slidespeed=inf;
  519.     else inf=a->slidespeed;
  520.  
  521.     hi=inf>>4;
  522.     lo=inf&0xf;
  523.  
  524.     if(hi==0xf){
  525.         if(!vbtick) a->tmpperiod+=(UWORD)lo<<2;
  526.     }
  527.     else if(hi==0xe){
  528.         if(!vbtick) a->tmpperiod+=lo;
  529.     }
  530.     else{
  531.         if(vbtick) a->tmpperiod+=(UWORD)inf<<2;
  532.     }
  533. }
  534.  
  535.  
  536.  
  537. void DoS3MSlideUp(UBYTE inf)
  538. {
  539.     UBYTE hi,lo;
  540.  
  541.     if(inf!=0) a->slidespeed=inf;
  542.     else inf=a->slidespeed;
  543.  
  544.     hi=inf>>4;
  545.     lo=inf&0xf;
  546.  
  547.     if(hi==0xf){
  548.         if(!vbtick) a->tmpperiod-=(UWORD)lo<<2;
  549.     }
  550.     else if(hi==0xe){
  551.         if(!vbtick) a->tmpperiod-=lo;
  552.     }
  553.     else{
  554.         if(vbtick) a->tmpperiod-=(UWORD)inf<<2;
  555.     }
  556. }
  557.  
  558.  
  559.  
  560. void DoS3MTremor(UBYTE inf)
  561. {
  562.     UBYTE on,off;
  563.  
  564.     on=(inf>>4)+1;
  565.     off=(inf&0xf)+1;
  566.  
  567.     a->s3mtremor%=(on+off);
  568.     a->volume=(a->s3mtremor < on ) ? a->tmpvolume:0;
  569.     a->s3mtremor++;
  570. }
  571.  
  572.  
  573.  
  574. void DoS3MRetrig(UBYTE inf)
  575. {
  576.     UBYTE hi,lo;
  577.  
  578.     hi=inf>>4;
  579.     lo=inf&0xf;
  580.  
  581.     if(lo){
  582.         a->s3mrtgslide=hi;
  583.         a->s3mrtgspeed=lo;
  584.     }
  585.  
  586.     if(hi){
  587.         a->s3mrtgslide=hi;
  588.     }
  589.  
  590.     /* only retrigger if
  591.        lo nibble > 0 */
  592.  
  593.     if(a->s3mrtgspeed>0){
  594.         if(a->retrig==0){
  595.  
  596.             /* when retrig counter reaches 0,
  597.                reset counter and restart the sample */
  598.  
  599.             a->kick=1;
  600.             a->retrig=a->s3mrtgspeed;
  601.  
  602.             if(vbtick){                     /* don't slide on first retrig */
  603.                 switch(a->s3mrtgslide){
  604.  
  605.                     case 1:
  606.                     case 2:
  607.                     case 3:
  608.                     case 4:
  609.                     case 5:
  610.                         a->tmpvolume-=(1<<(a->s3mrtgslide-1));
  611.                         break;
  612.  
  613.                     case 6:
  614.                         a->tmpvolume=(2*a->tmpvolume)/3;
  615.                         break;
  616.  
  617.                     case 7:
  618.                         a->tmpvolume=a->tmpvolume>>1;
  619.                         break;
  620.  
  621.                     case 9:
  622.                     case 0xa:
  623.                     case 0xb:
  624.                     case 0xc:
  625.                     case 0xd:
  626.                         a->tmpvolume+=(1<<(a->s3mrtgslide-9));
  627.                         break;
  628.  
  629.                     case 0xe:
  630.                         a->tmpvolume=(3*a->tmpvolume)/2;
  631.                         break;
  632.  
  633.                     case 0xf:
  634.                         a->tmpvolume=a->tmpvolume<<1;
  635.                         break;
  636.                 }
  637.                 if(a->tmpvolume<0) a->tmpvolume=0;
  638.                 if(a->tmpvolume>64) a->tmpvolume=64;
  639.             }
  640.         }
  641.         a->retrig--; /* countdown */
  642.     }
  643. }
  644.  
  645.  
  646. void DoS3MSpeed(UBYTE speed)
  647. {
  648.     if(vbtick || patdly2) return;
  649.  
  650.     if(speed){                      /* <- v0.44 bugfix */
  651.         mp_sngspd=speed;
  652.         vbtick=0;
  653.     }
  654. }
  655.  
  656.  
  657. void DoS3MTempo(UBYTE tempo)
  658. {
  659.     if(vbtick || patdly2) return;
  660.     mp_bpm=tempo;
  661. }
  662.  
  663.  
  664. void DoToneSlide(void)
  665. {
  666.     int dist,t;
  667.  
  668.     if(!vbtick){
  669.         a->tmpperiod=a->period;
  670.         return;
  671.     }
  672.  
  673.     /* We have to slide a->period towards a->wantedperiod, so
  674.        compute the difference between those two values */
  675.  
  676.     dist=a->period-a->wantedperiod;
  677.  
  678.     if( dist==0 ||                          /* if they are equal */
  679.         a->portspeed>abs(dist) ){       /* or if portamentospeed is too big */
  680.  
  681.         a->period=a->wantedperiod;      /* make tmpperiod equal tperiod */
  682.     }
  683.     else if(dist>0){                                /* dist>0 ? */
  684.         a->period-=a->portspeed;        /* then slide up */
  685.     }
  686.     else
  687.         a->period+=a->portspeed;        /* dist<0 -> slide down */
  688.  
  689. /*      if(a->glissando){
  690.  
  691.          If glissando is on, find the nearest
  692.            halfnote to a->tmpperiod
  693.  
  694.         for(t=0;t<60;t++){
  695.             if(a->tmpperiod>=npertab[a->finetune][t]) break;
  696.         }
  697.  
  698.         a->period=npertab[a->finetune][t];
  699.     }
  700.     else
  701. */
  702.     a->tmpperiod=a->period;
  703. }
  704.  
  705.  
  706. void DoPTEffect0(UBYTE dat)
  707. {
  708.     UBYTE note;
  709.  
  710.     note=a->note;
  711.  
  712.     if(dat!=0){
  713.         switch(vbtick%3){
  714.             case 1:
  715.                 note+=(dat>>4); break;
  716.             case 2:
  717.                 note+=(dat&0xf); break;
  718.         }
  719.         a->period=GetPeriod(note+a->transpose,a->c2spd);
  720.         a->ownper=1;
  721.     }
  722. }
  723.  
  724.  
  725. void PlayNote(void)
  726. {
  727.     INSTRUMENT *i;
  728.     SAMPLE *s;
  729.     UWORD period;
  730.     UBYTE inst,c;
  731.     UBYTE note;
  732.  
  733.     if(a->row==NULL) return;
  734.  
  735.     UniSetRow(a->row);
  736.  
  737.     while(c=UniGetByte()){
  738.  
  739.         switch(c){
  740.  
  741.             case UNI_NOTE:
  742.                 note=UniGetByte();
  743.  
  744.                 if(note==96){                   /* key off ? */
  745.                     a->keyon=0;
  746.                     if(a->i && !(a->i->volflg & EF_ON)){
  747.                         a->tmpvolume=0;
  748.                     }
  749.                 }
  750.                 else{
  751.                     a->note=note;
  752.  
  753.                     period=GetPeriod(note+a->transpose,a->c2spd);
  754.  
  755.                     a->wantedperiod=period;
  756.                     a->tmpperiod=period;
  757.  
  758.                     a->kick=1;
  759.                     a->start=0;
  760.  
  761.                     /* retrig tremolo and vibrato waves ? */
  762.  
  763.                     if(!(a->wavecontrol&0x80)) a->trmpos=0;
  764.                     if(!(a->wavecontrol&0x08)) a->vibpos=0;
  765.                 }
  766.                 break;
  767.  
  768.             case UNI_INSTRUMENT:
  769.                 inst=UniGetByte();
  770.                 if(inst>=pf->numins) break;             /* <- safety valve */
  771.  
  772.                 a->sample=inst;
  773.  
  774.                 i=&pf->instruments[inst];
  775.                 a->i=i;
  776.  
  777.                 if(i->samplenumber[a->note]>=i->numsmp) break;
  778.  
  779.                 s=&i->samples[i->samplenumber[a->note]];
  780.                 a->s=s;
  781.  
  782.                 /* channel or instrument determined panning ? */
  783.  
  784.                 if(s->flags& SF_OWNPAN){
  785.                     a->panning=s->panning;
  786.                 }
  787.                 else{
  788.                     a->panning=pf->panning[mp_channel];
  789.                 }
  790.  
  791.                 a->transpose=s->transpose;
  792.                 a->handle=s->handle;
  793.                 a->tmpvolume=s->volume;
  794.                 a->volume=s->volume;
  795.                 a->c2spd=s->c2spd;
  796.                 a->retrig=0;
  797.                 a->s3mtremor=0;
  798.  
  799.                 period=GetPeriod(a->note+a->transpose,a->c2spd);
  800.  
  801.                 a->wantedperiod=period;
  802.                 a->tmpperiod=period;
  803.                 break;
  804.  
  805.             default:
  806.                 UniSkipOpcode(c);
  807.                 break;
  808.         }
  809.     }
  810. }
  811.  
  812.  
  813.  
  814.  
  815. void PlayEffects(void)
  816. {
  817.     UBYTE c,dat;
  818.  
  819.     if(a->row==NULL) return;
  820.  
  821.     UniSetRow(a->row);
  822.  
  823.     a->ownper=0;
  824.     a->ownvol=0;
  825.  
  826.     while(c=UniGetByte()){
  827.  
  828.         switch(c){
  829.  
  830.             case UNI_NOTE:
  831.             case UNI_INSTRUMENT:
  832.                 UniSkipOpcode(c);
  833.                 break;
  834.  
  835.             case UNI_PTEFFECT0:
  836.                 DoPTEffect0(UniGetByte());
  837.                 break;
  838.  
  839.             case UNI_PTEFFECT1:
  840.                 dat=UniGetByte();
  841.                 if(dat!=0) a->slidespeed=(UWORD)dat<<2;
  842.                 if(vbtick) a->tmpperiod-=a->slidespeed;
  843.                 break;
  844.  
  845.             case UNI_PTEFFECT2:
  846.                 dat=UniGetByte();
  847.                 if(dat!=0) a->slidespeed=(UWORD)dat<<2;
  848.                 if(vbtick) a->tmpperiod+=a->slidespeed;
  849.                 break;
  850.  
  851.             case UNI_PTEFFECT3:
  852.                 dat=UniGetByte();
  853.                 a->kick=0;                              /* temp XM fix */
  854.                 if(dat!=0){
  855.                     a->portspeed=dat;
  856.                     a->portspeed<<=2;
  857.                 }
  858.                 DoToneSlide();
  859.                 a->ownper=1;
  860.                 break;
  861.  
  862.             case UNI_PTEFFECT4:
  863.                 dat=UniGetByte();
  864.                 if(dat&0x0f) a->vibdepth=dat&0xf;
  865.                 if(dat&0xf0) a->vibspd=(dat&0xf0)>>2;
  866.                 DoVibrato();
  867.                 a->ownper=1;
  868.                 break;
  869.  
  870.             case UNI_PTEFFECT5:
  871.                 dat=UniGetByte();
  872.                 a->kick=0;
  873.                 DoToneSlide();
  874.                 DoVolSlide(dat);
  875.                 a->ownper=1;
  876.                 break;
  877.  
  878.             case UNI_PTEFFECT6:
  879.                 dat=UniGetByte();
  880.                 DoVibrato();
  881.                 DoVolSlide(dat);
  882.                 a->ownper=1;
  883.                 break;
  884.  
  885.             case UNI_PTEFFECT7:
  886.                 dat=UniGetByte();
  887.                 if(dat&0x0f) a->trmdepth=dat&0xf;
  888.                 if(dat&0xf0) a->trmspd=(dat&0xf0)>>2;
  889.                 DoTremolo();
  890.                 a->ownvol=1;
  891.                 break;
  892.  
  893.             case UNI_PTEFFECT8:
  894.                 dat=UniGetByte();
  895.                 if(mp_panning) a->panning=dat;
  896.                 break;
  897.  
  898.             case UNI_PTEFFECT9:
  899.                 dat=UniGetByte();
  900.                 if(dat) a->soffset=(UWORD)dat<<8;       /* <- 0.43 fix.. */
  901.                 a->start=a->soffset;
  902.                 if(a->start>a->s->length) a->start=a->s->length;
  903.                 break;
  904.  
  905.             case UNI_PTEFFECTA:
  906.                 DoVolSlide(UniGetByte());
  907.                 break;
  908.  
  909.             case UNI_PTEFFECTB:
  910.                 dat=UniGetByte();
  911.                 if(patdly2) break;
  912.                 patbrk=0;
  913.                 mp_sngpos=dat-1;
  914.                 posjmp=3;
  915.                 break;
  916.  
  917.             case UNI_PTEFFECTC:
  918.                 dat=UniGetByte();
  919.                 if(vbtick) break;
  920.                 if(dat>64) dat=64;
  921.                 a->tmpvolume=dat;
  922.                 break;
  923.  
  924.             case UNI_PTEFFECTD:
  925.                 dat=UniGetByte();
  926.                 if(patdly2) break;
  927.                 {
  928.                     int hi=(dat&0xf0)>>4;
  929.                     int     lo=(dat&0xf);
  930.                     patbrk=(hi*10)+lo;
  931.                 }
  932.                 if(patbrk>64) patbrk=64;        /* <- v0.42 fix */
  933.                 posjmp=3;
  934.                 break;
  935.  
  936.             case UNI_PTEFFECTE:
  937.                 DoEEffects(UniGetByte());
  938.                 break;
  939.  
  940.             case UNI_PTEFFECTF:
  941.                 dat=UniGetByte();
  942.  
  943.                 if(vbtick || patdly2) break;
  944.  
  945.                 if(mp_extspd && dat>=0x20){
  946.                     mp_bpm=dat;
  947.                 }
  948.                 else{
  949.                     if(dat){                        /* <- v0.44 bugfix */
  950.                         mp_sngspd=dat;
  951.                         vbtick=0;
  952.                     }
  953.                 }
  954.                 break;
  955.  
  956.             case UNI_S3MEFFECTD:
  957.                 DoS3MVolSlide(UniGetByte());
  958.                 break;
  959.  
  960.             case UNI_S3MEFFECTE:
  961.                 DoS3MSlideDn(UniGetByte());
  962.                 break;
  963.  
  964.             case UNI_S3MEFFECTF:
  965.                 DoS3MSlideUp(UniGetByte());
  966.                 break;
  967.  
  968.             case UNI_S3MEFFECTI:
  969.                 DoS3MTremor(UniGetByte());
  970.                 a->ownvol=1;
  971.                 break;
  972.  
  973.             case UNI_S3MEFFECTQ:
  974.                 DoS3MRetrig(UniGetByte());
  975.                 break;
  976.  
  977.             case UNI_S3MEFFECTA:
  978.                 DoS3MSpeed(UniGetByte());
  979.                 break;
  980.  
  981.             case UNI_S3MEFFECTT:
  982.                 DoS3MTempo(UniGetByte());
  983.                 break;
  984.  
  985.             case UNI_XMEFFECTA:
  986.                 DoXMVolSlide(UniGetByte());
  987.                 break;
  988.  
  989.             case UNI_XMEFFECTP:
  990.                 DoXMPanSlide(UniGetByte());
  991.                 break;
  992.  
  993.             default:
  994.                 UniSkipOpcode(c);
  995.                 break;
  996.         }
  997.     }
  998.  
  999.     if(!a->ownper){
  1000.         a->period=a->tmpperiod;
  1001.     }
  1002.  
  1003.     if(!a->ownvol){
  1004.         a->volume=a->tmpvolume;
  1005.     }
  1006. }
  1007.  
  1008.  
  1009.  
  1010.  
  1011. SWORD InterpolateEnv(SWORD p,ENVPT *a,ENVPT *b)
  1012. {
  1013.     return(Interpolate(p,a->pos,b->pos,a->val,b->val));
  1014. }
  1015.  
  1016.  
  1017. SWORD DoPan(SWORD envpan,SWORD pan)
  1018. {
  1019.     return(pan + (((envpan-128)*(128-abs(pan-128)))/128));
  1020. }
  1021.  
  1022. SWORD DoVol(ULONG a,SWORD b,SWORD c)
  1023. {
  1024.     a*=b;
  1025.     a*=c;
  1026.  
  1027.     return(a>>23);
  1028. }
  1029.  
  1030.  
  1031. void StartEnvelope(ENVPR *t,UBYTE flg,UBYTE pts,UBYTE sus,UBYTE beg,UBYTE end,ENVPT *p)
  1032. {
  1033.     t->flg=flg;
  1034.     t->pts=pts;
  1035.     t->sus=sus;
  1036.     t->beg=beg;
  1037.     t->end=end;
  1038.     t->env=p;
  1039.     t->p=0;
  1040.     t->a=0;
  1041.     t->b=1;
  1042. }
  1043.  
  1044.  
  1045.  
  1046. SWORD ProcessEnvelope(ENVPR *t,SWORD v,UBYTE keyon)
  1047. {
  1048.     if(t->flg & EF_ON){
  1049.  
  1050.         /* panning active? -> copy variables */
  1051.  
  1052.         UBYTE a,b;
  1053.         UWORD p;
  1054.  
  1055.         a=t->a;
  1056.         b=t->b;
  1057.         p=t->p;
  1058.  
  1059.         /* compute the envelope value between points a and b */
  1060.  
  1061.         v=InterpolateEnv(p,&t->env[a],&t->env[b]);
  1062.  
  1063.         /* Should we sustain? (sustain flag on, key-on, point a is the sustain
  1064.            point, and the pointer is exactly on point a) */
  1065.  
  1066.         if((t->flg & EF_SUSTAIN) && keyon && a==t->sus && p==t->env[a].pos){
  1067.             /* do nothing */
  1068.         }
  1069.         else{
  1070.             /* don't sustain, so increase pointer. */
  1071.  
  1072.             p++;
  1073.  
  1074.             /* pointer reached point b? */
  1075.  
  1076.             if(p >= t->env[b].pos){
  1077.  
  1078.                 /* shift points a and b */
  1079.  
  1080.                 a=b; b++;
  1081.  
  1082.                 if(t->flg & EF_LOOP){
  1083.                     if(b > t->end){
  1084.                         a=t->beg;
  1085.                         b=a+1;
  1086.                         p=t->env[a].pos;
  1087.                     }
  1088.                 }
  1089.                 else{
  1090.                     if(b >= t->pts){
  1091.                         b--;
  1092.                         p--;
  1093.                     }
  1094.                 }
  1095.             }
  1096.         }
  1097.         t->a=a;
  1098.         t->b=b;
  1099.         t->p=p;
  1100.     }
  1101.     return v;
  1102. }
  1103.  
  1104. /*
  1105. long GetFreq2(long period)
  1106. {
  1107.     float frequency;
  1108.  
  1109.     frequency=8363.0*pow(2,((6*12*16*4.0)-period)/(12*16*4.0));
  1110.     return(floor(frequency));
  1111. }
  1112. */
  1113.  
  1114. long GetFreq2(long period)
  1115. {
  1116.     int okt;
  1117.     long frequency;
  1118.     period=7680-period;
  1119.     okt=period/768;
  1120.     frequency=lintab[period%768];
  1121.     frequency<<=2;
  1122.     return(frequency>>(7-okt));
  1123. }
  1124.  
  1125. void MP_HandleTick(void)
  1126. {
  1127.     int z,t,tr;
  1128.  
  1129.     if(isfirst){           
  1130.         /* don't handle the very first ticks, this allows the
  1131.            other hardware to settle down so we don't loose any 
  1132.            starting notes
  1133.         */
  1134.         isfirst--;
  1135.         return;
  1136.     }
  1137.  
  1138.     if(forbid) return;      /* don't go any further when forbid is true */
  1139.  
  1140.     if(MP_Ready()) return;
  1141.  
  1142.     if(++vbtick>=mp_sngspd){
  1143.  
  1144.         mp_patpos++;
  1145.         vbtick=0;
  1146.  
  1147.         if(patdly){
  1148.             patdly2=patdly;
  1149.             patdly=0;
  1150.         }
  1151.  
  1152.         if(patdly2){
  1153.  
  1154.             /* patterndelay active */
  1155.  
  1156.             if(--patdly2){
  1157.                 mp_patpos--;    /* so turn back mp_patpos by 1 */
  1158.             }
  1159.         }
  1160.  
  1161.         /* Do we have to get a new patternpointer ?
  1162.            (when mp_patpos reaches 64 or when
  1163.            a patternbreak is active) */
  1164.  
  1165.         if( mp_patpos == numrow ) posjmp=3;
  1166.  
  1167.  
  1168.         if( posjmp ){
  1169.             mp_patpos=patbrk;
  1170.             mp_sngpos+=(posjmp-2);
  1171.             patbrk=posjmp=0;
  1172.             if(mp_sngpos>=pf->numpos){
  1173.                 if(!mp_loop) return;
  1174.                 mp_sngpos=pf->reppos;
  1175.             }
  1176.             if(mp_sngpos<0) mp_sngpos=pf->numpos-1;
  1177.         }
  1178.  
  1179.  
  1180.         if(!patdly2){
  1181.  
  1182.             for(t=0;t<pf->numchn;t++){
  1183.  
  1184.                 tr=pf->patterns[(pf->positions[mp_sngpos]*pf->numchn)+t];
  1185.                 numrow=pf->pattrows[pf->positions[mp_sngpos]];
  1186.  
  1187.                 mp_channel=t;
  1188.                 a=&mp_audio[t];
  1189.                 a->row=(tr<pf->numtrk) ? UniFindRow(pf->tracks[tr],mp_patpos) : NULL;
  1190.  
  1191.                 PlayNote();
  1192.             }
  1193.         }
  1194.     }
  1195.  
  1196.     /* Update effects */
  1197.  
  1198.     for(t=0;t<pf->numchn;t++){
  1199.         mp_channel=t;
  1200.         a=&mp_audio[t];
  1201.         PlayEffects();
  1202.     }
  1203.  
  1204.     for(t=0;t<pf->numchn;t++){
  1205.         INSTRUMENT *i;
  1206.         SAMPLE *s;
  1207.         SWORD envpan,envvol;
  1208.  
  1209.         a=&mp_audio[t];
  1210.         i=a->i;
  1211.         s=a->s;
  1212.  
  1213.         if(i==NULL || s==NULL) continue;
  1214.  
  1215.         if(a->period<40) a->period=40;
  1216.         if(a->period>8000) a->period=8000;
  1217.  
  1218.         if(a->kick){
  1219.             MD_VoicePlay(t,a->handle,a->start,s->length,s->loopstart,s->loopend,s->flags);
  1220.             a->kick=0;
  1221.             a->keyon=1;
  1222.  
  1223.             a->fadevol=32767;
  1224.  
  1225.             StartEnvelope(&a->venv,i->volflg,i->volpts,i->volsus,i->volbeg,i->volend,i->volenv);
  1226.             StartEnvelope(&a->penv,i->panflg,i->panpts,i->pansus,i->panbeg,i->panend,i->panenv);
  1227.         }
  1228.  
  1229.         envvol=ProcessEnvelope(&a->venv,256,a->keyon);
  1230.         envpan=ProcessEnvelope(&a->penv,128,a->keyon);
  1231.  
  1232.         MD_VoiceSetVolume(t,(DoVol(a->fadevol,envvol,a->volume)*mp_volume)/100);
  1233.  
  1234.         if(s->flags& SF_OWNPAN){
  1235.             MD_VoiceSetPanning(t,DoPan(envpan,a->panning));
  1236.         }
  1237.         else{
  1238.             MD_VoiceSetPanning(t,a->panning);
  1239.         }
  1240.  
  1241.         if(pf->flags&UF_LINEAR)
  1242.             MD_VoiceSetFrequency(t,GetFreq2(a->period));
  1243.         else
  1244.             MD_VoiceSetFrequency(t,(3579546UL<<2)/a->period);
  1245.  
  1246.         /*  if key-off, start substracting
  1247.             fadeoutspeed from fadevol: */
  1248.  
  1249.         if(!a->keyon){
  1250.             a->fadevol-=i->volfade;
  1251.             if(a->fadevol<0) a->fadevol=0;
  1252.         }
  1253.     }
  1254. }
  1255.  
  1256.  
  1257.  
  1258. void MP_Init(UNIMOD *m)
  1259. {
  1260.     int t;
  1261.  
  1262.     pf=m;
  1263.     reppos=0;
  1264.     repcnt=0;
  1265.     mp_sngpos=0;
  1266.     mp_sngspd=m->initspeed;
  1267.  
  1268.     vbtick=mp_sngspd;
  1269.     patdly=0;
  1270.     patdly2=0;
  1271.     mp_bpm=m->inittempo;
  1272.  
  1273.     forbid=0;
  1274.     mp_patpos=0;
  1275.     posjmp=2;               /* <- make sure the player fetches the first note */
  1276.     patbrk=0;
  1277.  
  1278.     isfirst=2;              /* delay start by 2 ticks */
  1279.  
  1280.     /* Make sure the player doesn't start with garbage: */
  1281.  
  1282.     for(t=0;t<pf->numchn;t++){
  1283.         mp_audio[t].kick=0;
  1284.         mp_audio[t].tmpvolume=0;
  1285.         mp_audio[t].retrig=0;
  1286.         mp_audio[t].wavecontrol=0;
  1287.         mp_audio[t].glissando=0;
  1288.         mp_audio[t].soffset=0;
  1289.     }
  1290. }
  1291.  
  1292.  
  1293.  
  1294. int MP_Ready(void)
  1295. {
  1296.     return(mp_sngpos>=pf->numpos);
  1297. }
  1298.  
  1299.  
  1300. void MP_NextPosition(void)
  1301. {
  1302.     forbid=1;
  1303.     posjmp=3;
  1304.     patbrk=0;
  1305.     vbtick=mp_sngspd;
  1306.     forbid=0;
  1307. }
  1308.  
  1309.  
  1310. void MP_PrevPosition(void)
  1311. {
  1312.     forbid=1;
  1313.     posjmp=1;
  1314.     patbrk=0;
  1315.     vbtick=mp_sngspd;
  1316.     forbid=0;
  1317. }
  1318.  
  1319.  
  1320. void MP_SetPosition(UWORD pos)
  1321. {
  1322.     if(pos>=pf->numpos) pos=pf->numpos;
  1323.     forbid=1;
  1324.     posjmp=2;
  1325.     patbrk=0;
  1326.     mp_sngpos=pos;
  1327.     vbtick=mp_sngspd;
  1328.     forbid=0;
  1329. }
  1330.