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

其他智力游戏

开发平台:

Visual C++

  1. #define SBCMS_CPP
  2. #include "sbcms.h"
  3. #include <conio.h>
  4. void playnote(char voice,
  5. char ampl,
  6. char tone,
  7. char octave,
  8. char sort,
  9. char noiseclock,
  10. char envelope,
  11. unsigned duration){
  12. unsigned int cmsvoice,cmsport;
  13. char j,k;
  14. cmsport=baseport;
  15. cmsvoice=voice;
  16. if(voice>=6){
  17. voice -= 6;
  18. cmsport += 2;
  19. }
  20. outp(cmsport+1,voice);
  21. outp(cmsport,ampl);
  22. outp(cmsport+1,8+voice);
  23. outp(cmsport,tone);
  24. outp(cmsport+1,0x10+(voice/2));
  25. j=(octave<((voice&1)*4));
  26. outp(cmsport,j);
  27. outp(cmsport+1,0x16);
  28. k=(noiseclock<((voice/3)&1)*4);
  29. outp(cmsport,k);
  30. outp(cmsport+1,0x18+(voice/3));
  31. outp(cmsport,envelope);
  32. if(sort&2)cmsonfreq[cmsvoice]=1;
  33. if(sort&1)cmsonnoise[cmsvoice]=1;
  34. timevoice[cmsvoice]=duration;
  35. }
  36. void initMusic(){
  37. outp(baseport+1,0);
  38. outp(baseport,0xff);
  39. outp(baseport+1,0x14);
  40. outp(baseport,0);
  41. outp(baseport+1,0x8);
  42. outp(baseport,64);
  43. outp(baseport+1,0x10);
  44. outp(baseport,4);
  45. outp(baseport+1,0x15);
  46. outp(baseport,0);
  47. outp(baseport+1,0x1c);
  48. outp(baseport,1);
  49. //;oldtim=getvect(8);
  50. //;setvect(8,newtim);
  51. initcms();
  52. //;setvect(8,oldtim);
  53. //;SetTimer(newtim,100);
  54. }
  55. void interrupt newtim(...){
  56. //char freq;//,noise;
  57. int i;//,j;
  58. unsigned int cmsport;
  59. for(i=0;i<12;i++){
  60. if(cmsonfreq[i]||cmsonnoise[i]){
  61. if(timevoice[i]>0)timevoice[i]--;
  62. else{
  63. cmsonnoise[i]=0;
  64. cmsonfreq[i]=0;
  65. }
  66. }
  67. }
  68. freqtot=0;
  69. noisetot=0;
  70. cmsport=baseport;
  71. for(i=0;i<6;i++){
  72. if(cmsonfreq[i])freqtot+=(1<<i);
  73. if(cmsonnoise[i])noisetot+=(1<<i);
  74. }
  75. outp(cmsport+1,0x14);
  76. outp(cmsport,freqtot);
  77. outp(cmsport+1,0x15);
  78. outp(cmsport,noisetot);
  79. freqtot=0;
  80. noisetot=0;
  81. for(i=6;i<12;i++){
  82. if(cmsonfreq[i])freqtot+=(1<<(i-6));
  83. if(cmsonnoise[i])noisetot+=(1<<(i-6));
  84. }
  85. outp(cmsport+1,0x14);
  86. outp(cmsport,freqtot);
  87. outp(cmsport+3,0x14);
  88. outp(cmsport+2,freqtot);
  89. outp(cmsport+3,0x15);
  90. outp(cmsport+2,noisetot);
  91. // counter++;
  92. }
  93. void resetcms(){
  94. outp(baseport+1,0x1c);
  95. outp(baseport,2);
  96. outp(baseport+3,0x1c);
  97. outp(baseport+2,2);
  98. }
  99. void initcms(){
  100. int cnt;
  101. resetcms();
  102. outp(baseport+1,0x1c);
  103. outp(baseport,1);
  104. outp(baseport+3,0x1c);
  105. outp(baseport+1,1);
  106. for(cnt=0;cnt<12;cnt++){
  107. timevoice[cnt]=0;
  108. cmsonfreq[cnt]=0;
  109. cmsonnoise[cnt]=0;
  110. playnote(cnt,0,0,0,0,0,0,0);
  111. }
  112. }