FMMUSIC.C
上传用户:junwei_58
上传日期:2007-05-15
资源大小:79k
文件大小:1k
源码类别:

其他智力游戏

开发平台:

Visual C++

  1. #define FMMUSIC_C
  2. #include <dos.h>
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #include "fmmusic.h"
  6. #include "fmcreate.h"
  7. extern char *FMfilename;
  8. Note notetable[13]={_R,_C,_Ch,_D,_Dh,_E,_F,_Fh,_G,_Gh,_A,_Ah,_B,};
  9. int timetable[8]={_2_0*2, _2_0, _1_1, _1_2, _1_4, _1_8, _1_16, _1_32,};
  10. void WriteFM(char reg,char data){asm{
  11. mov dx,FM_PORT
  12. mov al,reg
  13. out dx,al
  14. inc dx
  15. mov al,data
  16. out dx,al
  17. }}
  18. char ReadFM(){asm{
  19. mov dx,FM_PORT
  20. in al,dx
  21. }}
  22. void FMSound(int freq,char block){
  23. WriteFM(0xa0,freq&0x00ff);
  24. WriteFM(0xb0,(block<<2)|((freq&0xff00)>>8)|0x20);
  25. }
  26. void FMSoundOFF(int freq,char block){
  27. WriteFM(0xa0,freq&0x00ff);
  28. WriteFM(0xb0,(block<<2)|((freq&0xff00)>>8));
  29. }
  30. void delayFM(int time){
  31. char i;
  32. WriteFM(0x04,0x80);
  33. WriteFM(0x03,216);
  34. WriteFM(0x04,0x42);
  35. for(i=1;i<time;i++){
  36. while(((char)ReadFM()&0xe0)<0xa0);
  37. WriteFM(0x04,0x82);
  38. }
  39. }
  40. int FMready(){
  41.  // char i;
  42. WriteFM(0x04,0x80);
  43. WriteFM(0x03,216);
  44. WriteFM(0x04,0x42);
  45. if(((char)ReadFM()&0xe0)>=0xa0){
  46. WriteFM(0x04,0x82);
  47. return 1;
  48. } else return 0;
  49. }
  50. void initPiano(){
  51. int n;
  52. WriteFM(1,0);
  53. WriteFM(8,0);
  54. WriteFM(0xbd,0);
  55. WriteFM(0x20,0x21);
  56. WriteFM(0x23,0x11);
  57. WriteFM(0x40,0x4c);
  58. WriteFM(0x43,0);
  59. WriteFM(0x60,0xd2);
  60. WriteFM(0x63,0xd2);
  61. WriteFM(0x80,0x32);
  62. WriteFM(0x83,0x11);
  63. WriteFM(0xe0,0);
  64. WriteFM(0xe3,0);
  65. WriteFM(0xc0,4);
  66. music=FMload(FMfilename,&length);
  67. }