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

其他智力游戏

开发平台:

Visual C++

  1. #define TIMER_CPP
  2. #include <dos.h>
  3. #include "timer.h"
  4. #include <stdlib.h>
  5. long Time;
  6. void interrupt (*oldtimer)(...);
  7. void interrupt NewTimer(...);
  8. void setspeed(int freq){ //  65536>freq>18.2
  9. unsigned i;
  10. if(freq)i=(int)(11931817l/freq/10);
  11. else i=0;
  12. asm{
  13. cli
  14. mov dx,0x43
  15. mov al,0x36
  16. out dx,al
  17. sub dx,3
  18. mov ax,i
  19. out dx,al
  20. mov al,ah
  21. out dx,al
  22. sti
  23. }
  24. }
  25. void speedback(){asm{
  26. cli
  27. mov dx,0x43
  28. mov al,0x36
  29. out dx,al
  30. sub dx,3
  31. mov al,0
  32. out dx,al
  33. out dx,al
  34. sti
  35. }}
  36. int n,p,cur;
  37. void installTimer(){
  38. setspeed(50);
  39. // music
  40. initPiano();
  41. n=0,p=0,cur=0;
  42. curTime=0;
  43. Time=1;
  44. gamespeed=2;
  45. oldtimer=getvect(INTR_TIME);
  46. setvect(INTR_TIME,NewTimer);
  47. }
  48. void uninstallTimer(){
  49. speedback();
  50. free(music);
  51. setvect(INTR_TIME,oldtimer);
  52. }
  53. void interrupt NewTimer(...){
  54.  // int i,j;
  55. // if(){
  56. if(!p){
  57. p=1;
  58. WriteFM(0x04,0x80);
  59. WriteFM(0x03,216);
  60. WriteFM(0x04,0x42);
  61. }
  62. if((ReadFM()&0xe0)>=0xa0){
  63. WriteFM(0x04,0x82);
  64. p++;
  65. if(p==3){FMSoundOFF(music[cur].note,music[cur].octave);p=0;}
  66. }
  67. if(curTime>Time){
  68. if(!p){delayFM(1);FMSoundOFF(music[cur].note,music[cur].octave);}
  69. timerstatus=READY;
  70. Time=curTime+music[n].time;
  71. FMSound(music[n].note,music[n].octave);
  72. cur=n++;
  73. if(n==length)n=0;
  74. //playnote(0,100,mu[(n++)%12],4,1,0,5,gamespeed);
  75. }
  76. curTime++;// newtim();
  77. oldtimer();
  78. }
  79. void delay_Timer(long d){
  80. d+=curTime;
  81. while(curTime<d);
  82. }