home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.tar / ftp.whtech.com / Geneve / 9640news / CAT36 / EMULSRC.ZIP / SOUND.C < prev    next >
Text File  |  1993-04-22  |  1KB  |  56 lines

  1. /*
  2. **  SOUND chip emulation.
  3. **  This section partly emulates sound generator 1, by playing each
  4. **  specified frequency for 500 milliseconds.
  5. */
  6.  
  7. void sound_access(word data)
  8. {
  9.     static word fcode=0,lastaccess=0;
  10.     word soundbyte;
  11.  
  12.     soundbyte=data>>8;
  13.  
  14.     if (((soundbyte&0xC0)==0)&&(lastaccess==0x80))
  15.         fcode=(fcode&0xF)|(soundbyte<<4);
  16.     if ((soundbyte&0xF0)==0x80) fcode=(fcode&0x3F0)|(soundbyte&0xF);
  17.     if (((soundbyte&0xF0)==0x90)&&(soundbyte!=0x9F))
  18.         my_sound((word)((float)111860.8/(float)fcode));
  19.     lastaccess=soundbyte&0xF0;
  20. }
  21.  
  22. void sound_handler(void)
  23. {
  24. int duration;
  25. duration=*(mem+0x41e7)>>8;
  26. if (duration)
  27. {
  28.     if (!--duration)
  29.     {
  30.         word soundlist,listlen;
  31.         soundlist=*(mem+0x41e6);
  32.         listlen=soundbyte(soundlist++);
  33.         if (listlen)
  34.         {
  35.             while(listlen--)
  36.             sound_access(soundbyte(soundlist++)<<8);
  37.             duration=soundbyte(soundlist++);
  38.         }
  39.         else
  40.                 {
  41.              soundlist=(soundbyte(soundlist++)<<8)|
  42.                     soundbyte(soundlist);
  43.              duration=1;
  44.         }
  45.         *(mem+0x41e6)=soundlist;
  46.     }
  47.     *(mem+0x41e7)=(*(mem+0x41e7)&0xFF)|(duration<<8);
  48. }
  49. }
  50.  
  51.  
  52. byte soundbyte(word address)
  53. {
  54.     if (*(mem+R14)&1)    return(*(vdp+address));
  55.     else             return(*(grom+address));
  56. }