home *** CD-ROM | disk | FTP | other *** search
/ PC Underground / UNDERGROUND.ISO / sound / sfxpro / timer.c < prev   
Encoding:
C/C++ Source or Header  |  1995-08-15  |  2.9 KB  |  167 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <malloc.h>
  5. #include <dos.h>
  6. #include <i86.h>
  7.  
  8.  
  9. typedef unsigned short int word;
  10. typedef unsigned int dword;
  11. typedef unsigned char uchar;
  12. typedef signed char schar;
  13.  
  14. struct xmheader  {
  15.   char                xm_id[17];
  16.   char                module_name[20];
  17.   char                One_a;
  18.   char                tracker_name[20];
  19.   uchar               version_number_lo; 
  20.   uchar               version_number_hi; 
  21.   dword               header_size;
  22.   word                song_length;
  23.   word                restart_position;
  24.   word                num_channels;
  25.   word                num_patterns;
  26.   word                num_instruments;
  27.   word                flags;
  28.   word                default_tempo;
  29.   word                default_bpm;
  30.   char                pat_table[256];
  31. };
  32.  
  33.  
  34. void (__interrupt __far *prev_int_1c)();
  35.  
  36. extern char  BPM,Speed;
  37. extern char  Row,Pattern;
  38. extern struct xmheader      xmh;
  39.  
  40. double ticks_to_wait;
  41. double wticks;
  42. double TBPM;
  43.  
  44. short int Actual_Tick;
  45. char  Pause_Timer_Var;
  46. char  volticks;
  47.  
  48. int env_ticks;
  49.  
  50. void Process_TickEffects()
  51. {
  52.  unsigned int i;
  53.  char *scrn;
  54.  
  55.  for (i = 0; i < xmh.num_channels; i++) {
  56.    process_effects(i);
  57.  }
  58. }
  59.  
  60.  
  61. void Process_Row()
  62. {
  63.   process_patternrow();
  64. }
  65.  
  66. void Process_Envelopes()
  67. {
  68.  Process_Pan_Env();
  69.  if (volticks < 1) {
  70.    volticks ++;
  71.  }
  72.  else
  73.  {
  74.    volticks = 0;
  75.    Process_Vol_Env();
  76.  }
  77. }
  78.  
  79. void __interrupt __far timer_rtn()
  80. {
  81.   if (Pause_Timer_Var != 1) {
  82.     Process_Envelopes();
  83.     wticks++;
  84.     if (wticks > ticks_to_wait) {
  85.       wticks -= ticks_to_wait;                     
  86.       Process_TickEffects();          // Process Tick - Effects
  87.       Actual_Tick++;
  88.       if (Actual_Tick > Speed) {
  89.         Actual_Tick = 0;
  90.         Process_Row();                // Next row
  91.       }
  92.     }
  93.   }
  94. }
  95.  
  96. void init_timer()
  97. {
  98.   wticks = 0;
  99.   volticks = 0;
  100.   env_ticks = 0;
  101.   prev_int_1c = _dos_getvect(0x1c);
  102.   _disable;
  103.   outp(0x43,0x36);
  104.   outp(0x40,177);
  105.   outp(0x40,45);
  106.   _dos_setvect(0x1c, timer_rtn);
  107.   _enable;
  108. }
  109.  
  110. void reset_timer()
  111. {
  112.   _disable;
  113.   outp(0x43,0x36);
  114.   outp(0x40,0);
  115.   outp(0x40,0);
  116.   _dos_setvect(0x1c, prev_int_1c);
  117.   _enable;
  118. }
  119.  
  120. void Pause_Timer()
  121. {
  122.   Pause_Timer_Var = 1;
  123. }
  124.  
  125. void Continue_Timer()
  126. {
  127.   Pause_Timer_Var = 0;
  128. }
  129.  
  130. void Set_Timer_Defaults()
  131. {
  132.  BPM = 125;
  133.  Speed = 6;
  134.  Actual_Tick = 0;
  135.  Row = 0;
  136.  Pattern = 0;
  137.  
  138.  TBPM = BPM;
  139. // ticks_to_wait = (96,5*5) / (TBPM * 2);
  140.  ticks_to_wait = 510 / (TBPM * 2);
  141. }
  142.  
  143. void SetTimer(unsigned short int bpms,unsigned short int speedy)
  144. {
  145.  BPM = bpms;
  146.  Speed = speedy;
  147.  
  148.  TBPM = BPM;
  149.  ticks_to_wait = 510 / (TBPM * 2);
  150. }
  151.  
  152. void Set_BPM(unsigned short int bpms)
  153. {
  154.  BPM = bpms;
  155.  
  156.  TBPM = BPM;
  157.  ticks_to_wait = 510 / (TBPM * 2);
  158. }
  159.  
  160. void Set_Speed(unsigned short int speedy)
  161. {
  162.  Speed = speedy;
  163.  
  164.  TBPM = BPM;
  165.  ticks_to_wait = 510 / (TBPM * 2);
  166. }
  167.