?? 裴遠華.cpp
字號:
#include <dos.h> // getvect() and setvect()
#include <conio.h> // kbhit()
#include <stdlib.h> // exit(0)
#include <stdio.h> // printf()
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
// 聲明歌曲“Yesterday once more”的音樂頻率
short int nFreq[] =
{
262,262,294,
330,392,392,330,392,330,
440,392,330,330,392,
440,294,330,392,
440,330,392,
440,660,588,523,494,
392,330,392,330,
262,262,294,
330,392,392,330,392,330,
440,392,330,330,392,
440,494,330,392,440,
494,588,
523,494,440,494,523,494,
523,494,440,440,494,
523,523,440,523,588,
523,588,
660,660,660,660,588,523,
494,523,494,440,330,392,
523,588,
660,660,660,660,660,588,523,
494,523,494,440,330,392,
440,494,
523,494,523,588,523,494,
523,494,523,588,523,588,
660,660,588,523,440,
330,349,330,392,
262,330,330,294,262,294,
330,
0 // 設置0為歌曲結束符
};
// 聲明歌曲“Yesterday once more”的音樂時延
short int nTimeDelay[] =
{
4,4,4,
8,8,4,4,4,4,
8,12,4,4,4,
8,8,4,12,
16,4,4,
8,8,4,8,12,
4,4,8,16,
4,4,4,
4,8,8,4,4,4,
4,8,12,4,4,
8,8,4,8,12,
8,8,
4,4,12,4,4,4,
4,8,12,4,4,
8,8,4,8,12,
8,8,
4,4,4,8,4,4,
4,4,4,8,4,24,
4,4,
4,4,4,4,8,4,4,
4,4,4,12,4,24,
4,4,
4,4,4,12,4,4,
4,4,4,12,4,4,
8,8,4,8,12,
8,8,4,24,
4,4,4,2,6,4,
24
};
// 聲明歌曲“Yesterday once more”的歌詞
char a[]="\nWhen I was young\nI~d lis-ten to the ra-di-o wait-ing for my favo-rite songs\nWhen they played I~d sing a-long\nIt made me smile\nThose were such hap-py times and not so long a go\nHow I won-dered where they~d gone\nBut they~er back a-gain just like a long lost friend\nAll the song I love so well\nEv-ery sha la la la ev-ery wo wo wo wo still shines\nEv-ery shing a ling a ling that they~re starting to sing so fine\nWhen they get to the part where she~s break-ing her heart\nIt can real-ly made me cry just like be-fore\nIt~-s yes-ter-day once more";
const unsigned long CLK = 1193180; // 聲明時鐘頻率
const unsigned char INTR = 0X1C; // 聲明中斷號
short int *pFreq; // pointer of frequency
short int *pTimeDelay; // pointer of time delay
char *iterator;//pointer of song
void interrupt (*oldhandler)(__CPPARGS);
void interrupt handler(__CPPARGS)
{
// decrease the global counter
(*pTimeDelay) -- ; // time delay decrease
oldhandler(); // call the old routine
}
int Playing(void);
void main(void)
{
printf("\nYesterday once more");
Playing();
}
int Playing(void)
{
// save the old interrupt vector
oldhandler = getvect(INTR);
// install the new interrupt handler
setvect(INTR, handler);
outportb( 0x303, 0x90); // 設置8255 的工作模式
outportb( 0x303, 0x0c); // 置pc6=0 禁止8253通道2的gate引腳
outportb( 0x303, 0x00); // 置pc0=0 禁止7408
// set 8253's control word, select channel 2,
// make it work at mode 3, binary counting
// first send to low byte, then send to high byte
outportb( 0x307, 0xb6);
pFreq = nFreq; // 取歌曲的第一個音頻
pTimeDelay = nTimeDelay; // 取歌曲的第一個時延
iterator=a;//取歌詞的第一個字符地址
// 未遇歌曲結束符或未按任意鍵則繼續循環
while ( *pFreq && !kbhit())
{
// 置8253通道2 的計數初值
// first send to low byte
outportb( 0x306, (unsigned char)(CLK / *pFreq % 256));
// then send to high byte
outportb( 0x306, (unsigned char)(CLK / *pFreq / 256));
//set 8255's PC6=1 and PC0=1
outportb( 0x303, 0x01);
outportb( 0x303, 0x0d);
while ( *pTimeDelay){}; //等待延時到
// set 8255's PC6=0 and PC0=0
outportb( 0x303, 0x0c);
outportb( 0x303, 0x00);
while(*iterator>='a'&&*iterator<='z'||*iterator>='A'&&*iterator <='Z'||*iterator=='~')
{printf("%c",*iterator);
iterator++;
}
while(*iterator ==' ')
{printf("%c",*iterator);
iterator ++;
}
if(*iterator =='-')
iterator++;
if(*iterator =='\n')
{printf("%c",*iterator);
iterator++;
} //顯示歌詞
// get the next frequency and time delay
pFreq++;
pTimeDelay++;
} // 歌曲結束或按了任意鍵
// set 8255.PC6=0 pc0=0
outportb( 0x303, 0x0c);
outportb( 0x303, 0x00);
// reset the old interrupt handler
setvect(INTR,oldhandler);
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -