TIMER.CPP
资源名称:泡泡龙源代码.zip [点击查看]
上传用户:junwei_58
上传日期:2007-05-15
资源大小:79k
文件大小:1k
源码类别:
其他智力游戏
开发平台:
Visual C++
- #define TIMER_CPP
- #include <dos.h>
- #include "timer.h"
- #include <stdlib.h>
- long Time;
- void interrupt (*oldtimer)(...);
- void interrupt NewTimer(...);
- void setspeed(int freq){ // 65536>freq>18.2
- unsigned i;
- if(freq)i=(int)(11931817l/freq/10);
- else i=0;
- asm{
- cli
- mov dx,0x43
- mov al,0x36
- out dx,al
- sub dx,3
- mov ax,i
- out dx,al
- mov al,ah
- out dx,al
- sti
- }
- }
- void speedback(){asm{
- cli
- mov dx,0x43
- mov al,0x36
- out dx,al
- sub dx,3
- mov al,0
- out dx,al
- out dx,al
- sti
- }}
- int n,p,cur;
- void installTimer(){
- setspeed(50);
- // music
- initPiano();
- n=0,p=0,cur=0;
- curTime=0;
- Time=1;
- gamespeed=2;
- oldtimer=getvect(INTR_TIME);
- setvect(INTR_TIME,NewTimer);
- }
- void uninstallTimer(){
- speedback();
- free(music);
- setvect(INTR_TIME,oldtimer);
- }
- void interrupt NewTimer(...){
- // int i,j;
- // if(){
- if(!p){
- p=1;
- WriteFM(0x04,0x80);
- WriteFM(0x03,216);
- WriteFM(0x04,0x42);
- }
- if((ReadFM()&0xe0)>=0xa0){
- WriteFM(0x04,0x82);
- p++;
- if(p==3){FMSoundOFF(music[cur].note,music[cur].octave);p=0;}
- }
- if(curTime>Time){
- if(!p){delayFM(1);FMSoundOFF(music[cur].note,music[cur].octave);}
- timerstatus=READY;
- Time=curTime+music[n].time;
- FMSound(music[n].note,music[n].octave);
- cur=n++;
- if(n==length)n=0;
- //playnote(0,100,mu[(n++)%12],4,1,0,5,gamespeed);
- }
- curTime++;// newtim();
- oldtimer();
- }
- void delay_Timer(long d){
- d+=curTime;
- while(curTime<d);
- }