调频电子琴的c源码

来源:互联网 发布:传智播客python视频 编辑:程序博客网 时间:2024/04/30 16:03

本程序可直接运行于TC2.0环境下

#include "stdio.h"
#include "dos.h"
#include "bios.h"
#include "graphics.h"
int ioport=0x388;
void writeFM(char reg,char data);
char readFM();
void FMsound(int frequency,int block);
void delayFM(int time);
void FMdelay(int time);
void FMsoundoff(int frequency,int block);
void bar3Dpress(int left,int top,int right,int bottom);
void bar3D(int left,int top,int right,int bottom);
void initpiano();
int key[21][2]={131,0x7a,147,0x78,165,0x63,175,
                0x76,196,0x62,220,0x6e,247,0x6d,
                262,0x61,294,0x73,330,0x64,349,0x66,
                392,0x67,440,0x68,494,0x6a,524,0x71,
                587,0x77,659,0x65,698,0x72,784,
                0x74,880,0x79,998,0x75};
void main()
{
 int gd=DETECT,gm,cursound=0,i;
 char input;
 char * mask;
 initgraph(&gd,&gm,"");
 cleardevice();
 setfillstyle(XHATCH_FILL,BLUE);
 bar(0,0,639,479);
 mask=(char *)malloc(imagesize(0,0,28,200));
 getimage(0,0,28,200,mask);
 bar3D(0,90,639,320);
 for(i=0;i<21;i++)
 {
  bar3D(i*30+5,200,i*30+32,300);
 }
 bar3D(5,100,630,190);
 settextstyle(0,0,3);
 setcolor(BLUE);
 outtextxy(172,122,"FM PIANO DELUX");
 setcolor(LIGHTBLUE);
 outtextxy(170,120,"FM PIANO DELUX");
 settextstyle(0,0,1);
 setcolor(BLACK);
 outtextxy(220,150,"Produced by suprman  99.9.6");
 outtextxy(220,165,"  Copyleft K.NET Software");
 initpiano();
 do
 {
  input=getch();
  for(i=0;i<21;i++)
  { if(key[i][1]==input)
    { /*putimage(i*30+5,200,mask,XOR_PUT);*/
      bar3Dpress(i*30+5,200,i*30+32,300);
      FMsoundoff(cursound,4);
      FMsound(key[i][0],4);
      cursound=key[i][0];
      FMdelay(1);
      bar3D(i*30+5,200,i*30+32,300);
      /*putimage(i*30+5,200,mask,XOR_PUT);*/
    }
  }
 }while(input!=27);
 closegraph();
 free(mask);
 }
 void writeFM(char reg,char data)
 { outportb(ioport,reg);
   delay(1);
   outportb(ioport+1,data);
   delay(2);
 }
 char readFM()
 { char data;
 data=inportb(ioport);
 return(data);
 }
 void FMsound(int frequency,int block)
 {int fnh,fnl,block2,blfnh,kblfnh,key;
  fnl=frequency&0x00ff;
  fnh=frequency&0xff00;
  fnh=fnh>>8;
  block2=block<<2;
  blfnh=fnh|block2;
  key=0x20;
  kblfnh=blfnh|key;
  writeFM(0xa0,fnl);
  writeFM(0xb0,kblfnh);
 }
 void delayFM(int time)
 { unsigned char sl,i;
   writeFM(0x04,0x80);
   writeFM(0x03,216);
   writeFM(0x04,0x42);
   for(i=1;i<time;i++)
   { do {sl=readFM();
         sl=sl&0x00e0;
     }while(sl<0xa0);
     writeFM(0x04,0x82);
     }
 }
 void FMdelay(int time)
 { int i;
   for(i=time;i>=0;i--)
   delayFM(5);
  }
 void FMsoundoff(int frequency,int block)
 {int fnh,fnl,block2,blfnh,kblfnh,key;
  fnh=frequency&0x00ff;
  fnh=fnh>>8;
  block2=block<<2;
  blfnh=fnh|block2;
  key=0x00;
  kblfnh=blfnh|key;
  writeFM(0xb0,kblfnh);
}
 void bar3Dpress(int left,int top,int right,int bottom)
{setfillstyle(SOLID_FILL,LIGHTGRAY);
 bar(left,top,right,bottom);
 setcolor(BLACK);
 line(left,top,left,bottom);
 line(left,top,right,top);
 setcolor(WHITE);
 line(right,top,right,bottom);
 line(left,bottom,right,bottom);
 }

 void bar3D(int left,int top,int right,int bottom)
{setfillstyle(SOLID_FILL,LIGHTGRAY);
 bar(left,top,right,bottom);
 setcolor(WHITE);
 line(left,top,left,bottom);
 line(left,top,right,top);
 setcolor(BLACK);
 line(right,top,right,bottom);
 line(left,bottom,right,bottom);
 }
 void initpiano()
 { writeFM(1,0);
   writeFM(8,0);
   writeFM(0xbd,0x00);
   writeFM(0x20+0,0x21);
   writeFM(0x20+3,0x11);
   writeFM(0x40+0,0x4c);
   writeFM(0x40+3,0x00);
   writeFM(0x60+0,0xd2);
   writeFM(0x60+3,0xd2);
   writeFM(0x80+0,0x32);
   writeFM(0x80+3,0x11);
   writeFM(0xe0+0,0x00);
   writeFM(0xe0+3,0x00);
   writeFM(0xc0+0,0x04);
  } 

其他文章:

.NET 与安全性—— 数据加密算法

在VC中使用 Flash 美化你的程序

C语言面试题大汇总

指定内存0X000000不能为只读的错误分析

CTDP linux 程序员手册 C和C++编程(5)其他一些系统限制


<script type="text/javascript">google_ad_client = "pub-2416224910262877";google_ad_width = 728;google_ad_height = 90;google_ad_format = "728x90_as";google_ad_channel = "";google_color_border = "E1771E";google_color_bg = "FFFFFF";google_color_link = "0000FF";google_color_text = "000000";google_color_url = "008000";</script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击