Thursday 9 May 2013

Micky Mouse Program

#include<graphics.h>
#include<dos.h>
#include<conio.h>
#include<alloc.h>
void  *buf;
void firstleft();
void secondleft();
void main()
{
int gd=DETECT,gm,i=0,x,y,area;
initgraph(&gd,&gm,"tc:\bgi");\put your directory contains egavga.bgi
rectangle(0,0,getmaxx(),getmaxy());
arc(240,120,40,140,70);
ellipse(165,80,10,280,20,20);
ellipse(315,80,-100,170,20,20);
arc(235,120,163,215,70);
arc(245,120,-35,17,70);
ellipse(193,178,85,280,40,20);
ellipse(283,178,-100,95,40,20);
ellipse(238,199,180,0,39,50);
ellipse(213,123,44,240,33,40);
ellipse(262,123,-60,135,33,40);
ellipse(210,123,0,360,13,20);//left eye
ellipse(265,123,0,360,13,20);//right eye
ellipse(210,133,0,360,10,10);//left eye ball
ellipse(265,133,0,360,10,10);//right eye ball
ellipse(210,133,0,360,3,3);//left eye ball
ellipse(265,133,0,360,3,3);//right eye ball
ellipse(238,160,0,360,10,13);//nose
arc(240,125,228,312,68);//mouth
arc(240,120,230,310,72);//mouth
setfillstyle(1,4);
floodfill(238,160,15);//nose
setfillstyle(1,15);
floodfill(210,113,15);
floodfill(265,113,15);
setfillstyle(1,9);
floodfill(210,100,15);
setfillstyle(1,1);
floodfill(315,80,15);
moveto(203,220);
lineto(203,260);
lineto(183,260);
lineto(183,350);
lineto(293,350);
lineto(293,260);
lineto(273,260);
lineto(273,220);

Analog clock and calendar

#include<stdio.h>
#include<math.h>
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<dos.h>
#include<string.h>
//CLOCK CLASS
class clock
{
int h,m,s,thetamin,thetasec;
struct  time t;
public:
void time();
};
void clock::time()
{
int x=540,y=280,r=200,i;
char n[12][3]={"3","2","1","12","11","10","9","8","7","6","5","4"};
struct REGPACK reg;

setcolor(15);
circle(x,y,88);
circle(x,y,89);
setcolor(6);
settextstyle(5,0,1);
for(i=0;i<12;i++)
{
if(i!=3)
outtextxy(x+(r-132)*cos(M_PI/6*i)-8,y-(r-132)*sin(M_PI/6*i)-16,n[i]);
else
outtextxy(x+(r-132)*cos(M_PI/6*i)-10,y-(r-132)*sin(M_PI/6*i)-16,n[i]);
}
gettime(&t);

printf("

























");
printf("%2d:%02d:%02d",t.ti_hour, t.ti_min,t.ti_sec);

reg.r_ax=3;
intr(0x33,®);
while(reg.r_bx!=1)
{
reg.r_ax=3;
intr(0x33,®);
setcolor(5);
setfillstyle(1,3);
circle(x,y,4);
floodfill(x,y,5);
gettime(&t);
if(t.ti_min!=m)
{
setcolor(0);
line(x,y,x+(r-150)*cos(thetamin*(M_PI/180)),y-(r-150)*sin(thetamin*(M_PI/1
80)));
circle(x+(r-200)*cos(thetamin*(M_PI/180)),y-(r-200)*sin(thetamin*(M_PI/180
)),10);
line(x,y,x+(r-165)*cos(M_PI/6*h-((m/2)*(M_PI/180))),y-(r-165)*sin(M_PI/6*h
-((m/2)*(M_PI/180))));
circle(x+(r-200)*cos(M_PI/6*h-((m/2)*(M_PI/180))),y-(r-200)*sin(M_PI/6*h-(
(m/2)*(M_PI/180))),10);
}
if(t.ti_hour>12)
t.ti_hour=t.ti_hour-12;
if(t.ti_hour<4)
h=abs(t.ti_hour-3);
else
h=15-t.ti_hour;
m=t.ti_min;
if(t.ti_min<=15)
thetamin=(15-t.ti_min)*6;
else
thetamin=450-t.ti_min*6;
if(t.ti_sec<=15)
thetasec=(15-t.ti_sec)*6;
else
thetasec=450-t.ti_sec*6;
setcolor(3);
line(x,y,x+(r-165)*cos(M_PI/6*h-((m/2)*(M_PI/180))),y-(r-165)*sin(M_PI/6*h
-((m/2)*(M_PI/180))));
circle(x+(r-200)*cos(M_PI/6*h-((m/2)*(M_PI/180))),y-(r-200)*sin(M_PI/6*h-(
(m/2)*(M_PI/180))),5);
line(x,y,x+(r-150)*cos(thetamin*(M_PI/180)),y-(r-150)*sin(thetamin*(M_PI/1
80)));
circle(x+(r-200)*cos(thetamin*(M_PI/180)),y-(r-200)*sin(thetamin*(M_PI/180
)),5);
setcolor(15);
line(x,y,x+(r-145)*cos(thetasec*(M_PI/180)),y-(r-145)*sin(thetasec*(M_PI/1
80)));
delay(100);
setcolor(0);
line(x,y,x+(r-145)*cos(thetasec*(M_PI/180)),y-(r-145)*sin(thetasec*(M_PI/1
80)));
}

}
//CALENDAR CLASS
class calendar
{
int mon,year,d;
static int s;
clock t;
public:
calendar()
{
year=2006;
mon=5;
   }
   int tday();
   void reqmon();
   void cal();
   void chose();
   displaymenu(char **month,int count,int x1,int y1);
   getresponse(char **month,int width,int count,int x1,int y1);
   highlight(char **month,int ch,int h,int x1,int y1,int width);
   dehighlight(char **month,int ch,int h,int x1,int y1,int width);
};
int calendar:: tday()
{
int t,total=1;
int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
   for(t=1;t<year;t++)
   {
    if(t%4==0)
    total=total+366;
    else
    total=total+365;
    }
  if(year%4==0)
  days[1]=29;
     for(t=0;t<mon-1;t++)
     {
     total=total+days[t];
     }
  d=total%7;
  return d;
  }
void calendar::reqmon()
{

int q,r,x1=40,y1=210;
int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
char st2[3],st3[9],st4[5];

  q=days[mon-1];
  settextstyle(1,0,2);
  setcolor(YELLOW);
  for(r=1;r<=d;r++)
  {
     x1+=62;
     s++;
  }
  for(r=1;r<=q;r++)
  {
     itoa(r,st2,10);
     if(s>=6)
     {
outtextxy(x1,y1,st2);
y1+=30;
x1=40;
s=0;
continue;
     }
     outtextxy(x1,y1,st2);
     x1+=60;
     s++;
  }
  s=0;
  chose();

}
 void calendar::cal()
 {
  cleardevice();
  setgraphmode(getgraphmode());
  int l=17,t=175,r=70,b=235,g,x=25,y=177;
  char *day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  char st1[4];
  setbkcolor(0);
  setcolor(5);
  settextstyle(1,0,7);
  outtextxy(40,5,"Calendar & Clock");
  setfillstyle(3,BLUE);
  bar(10,165,440,395);
  setfillstyle(1,0);
  bar3d(l,t,r,b,0,0);
  bar3d(l,t+30,r,b+30,0,0);
  bar3d(l,t+60,r,b+60,0,0);
  bar3d(l,t+90,r,b+90,0,0);
  bar3d(l,t+120,r,b+120,0,0);
  bar3d(l,t+150,r,b+150,0,0);
  bar3d(l,t+180,r,b+150,0,0);
  bar3d(l+60,t,r+60,b,0,0);
  bar3d(l+60,t+30,r+60,b+30,0,0);
  bar3d(l+60,t+60,r+60,b+60,0,0);
  bar3d(l+60,t+90,r+60,b+90,0,0);
  bar3d(l+60,t+120,r+60,b+120,0,0);
  bar3d(l+60,t+150,r+60,b+150,0,0);
  bar3d(l+60,t+180,r+60,b+150,0,0);
  bar3d(l+120,t,r+120,b,0,0);
  bar3d(l+120,t+30,r+120,b+30,0,0);
  bar3d(l+120,t+60,r+120,b+60,0,0);
  bar3d(l+120,t+90,r+120,b+90,0,0);
  bar3d(l+120,t+120,r+120,b+120,0,0);
  bar3d(l+120,t+150,r+120,b+150,0,0);
  bar3d(l+120,t+180,r+120,b+150,0,0);
  bar3d(l+180,t,r+180,b,0,0);
  bar3d(l+180,t+30,r+180,b+30,0,0);
  bar3d(l+180,t+60,r+180,b+60,0,0);
  bar3d(l+180,t+90,r+180,b+90,0,0);
  bar3d(l+180,t+120,r+180,b+120,0,0);
  bar3d(l+180,t+150,r+180,b+150,0,0);
  bar3d(l+180,t+180,r+180,b+150,0,0);
  bar3d(l+240,t,r+240,b,0,0);
  bar3d(l+240,t+30,r+240,b+30,0,0);
  bar3d(l+240,t+60,r+240,b+60,0,0);
  bar3d(l+240,t+90,r+240,b+90,0,0);
  bar3d(l+240,t+120,r+240,b+120,0,0);
  bar3d(l+240,t+150,r+240,b+150,0,0);
  bar3d(l+240,t+180,r+240,b+150,0,0);
  bar3d(l+300,t,r+300,b,0,0);
  bar3d(l+300,t+30,r+300,b+30,0,0);
  bar3d(l+300,t+60,r+300,b+60,0,0);
  bar3d(l+300,t+90,r+300,b+90,0,0);
  bar3d(l+300,t+120,r+300,b+120,0,0);
  bar3d(l+300,t+150,r+300,b+150,0,0);
  bar3d(l+300,t+180,r+300,b+150,0,0);
  bar3d(l+360,t,r+360,b,0,0);
  bar3d(l+360,t+30,r+360,b+30,0,0);
  bar3d(l+360,t+60,r+360,b+60,0,0);
  bar3d(l+360,t+90,r+360,b+90,0,0);
  bar3d(l+360,t+120,r+360,b+120,0,0);
  bar3d(l+360,t+150,r+360,b+150,0,0);
  bar3d(l+360,t+180,r+360,b+150,0,0);
  settextstyle(1,0,2);
  setcolor(GREEN);
  for(g=0;g<7;g++)
  {
     strcpy(st1,day[g]);
     outtextxy(x,y,st1);
     x+=60;
  }
 }

void calendar::chose()
{
int width=0,i,count,xx,yy;
char st[5];
char
*month[]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST
","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};
struct REGPACK reg;

rectangle(0,0,getmaxx(),getmaxy());
count=sizeof(month)/sizeof(char *);
setcolor(BROWN);
settextstyle(1,0,1);
rectangle(40,90,225,125);
setcolor(CYAN);
outtextxy(45,95,month[mon-1]);
setcolor(BROWN);
rectangle(180,95,220,120);
settextstyle(1,1,1);
setcolor(CYAN);
outtextxy(185,100,"<");

itoa(year,st,10);
settextstyle(1,0,1);
rectangle(250,85,380,130);
setcolor(BROWN);
outtextxy(255,95,st);

setcolor(CYAN);
rectangle(340,90,375,105);
setcolor(BROWN);
settextstyle(1,1,1);
outtextxy(345,91,">");

setcolor(CYAN);
rectangle(340,110,375,125);
setcolor(BROWN);
settextstyle(1,1,1);
outtextxy(345,111,"<");

xx=getmaxx();
yy=30;
setfillstyle(1,3);
rectangle(xx-30,yy-25,xx-4,yy);
settextstyle(0,0,2);
outtextxy(xx-24,yy-20,"x");
reg.r_ax=1;
intr(0x33,®);
t.time();
while(!kbhit())
{
reg.r_ax=3;
intr(0x33,®);
if(reg.r_bx==1)
{
while(reg.r_bx==1)
{
reg.r_ax=3;
intr(0x33,®);
}
 if( reg.r_cx<=220 && reg.r_cx>=180 && reg.r_dx<=120 && reg.r_dx>=95 )
 {
  settextstyle(3,0,3);
  displaymenu(month,count,45,130);
  for(i=0;i<count;i++)
  {
  if(textwidth(month[i])>width)
  width=textwidth(month[i]);
  }
  while(mon!=13)
  {
  mon=getresponse(month,width,count,45,130);
  tday();
  cal();
  reqmon();

Egg Game in C

#include"dos.h"
#include"graphics.h"
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<dos.h>
#include<stdlib.h>
#include<iostream.h>
 union REGS i,o;
 main()
 {
   int initmouse();
   int restrictmouseptr(int,int,int,int);
   int getmousepos(int *,int *,int *);
   int showmouseptr();

  int gd=DETECT,gm,maxx,maxy,x,y,button;
  initgraph(&gd,&gm,"");

  int count=0;
  maxx=getmaxx();
  maxy=getmaxy();

  setbkcolor(1);
  setviewport(0,0,maxx,maxy,1);
  gotoxy(26,1);

  if(initmouse()==0)
   {
    closegraph();
    restorecrtmode();
//to go back to normal graphics mode or deleting viewport.
    printf("
mouse driver not loaded");
    exit(1);
   }
  restrictmouseptr(0,getmaxy()-20,maxx,getmaxy()-15);

   int a=30;int b=0;
  setcolor(0);
  setfillstyle(1,15);
  int score=0;
  count=20;
  int s=5;
  int level=0;
  char name[40];
  gotoxy(5,2);
  cout<<"PLEASE ENTER YOUR SWEET NAME::-";
  gets(name);
  gotoxy(5,2);
  cout<<"
";


  while(!kbhit())
   {
     getmousepos(&button,&x,&y);

      setcolor(15);
       setfillstyle(1,15);
       fillellipse(a,b,10,15);
       if((b>getmaxy()-20)&&(b<=getmaxy()-15))
// For checking the egg position.

{
if(a>=(x-20)&&(a<=(x+60)))
   {
     score+=10;
     gotoxy(320,2);
     textcolor(13);
     cout<<"your score: "<<score;

   }
}
       if(b>getmaxy()+40)
       {
b=0;
a=random(getmaxx());
gotoxy(10,2);
cout<<"eggs left: "<<count;
count--;
if(count==-1)
 {
  gotoxy(32,10);
  cout<<"LEVEL COMPLETED.";
  level++;
  if(level==4)
  {
  goto varun;
  }
  count=10;
  s++;
  getch();
  gotoxy(32,10);
 cout<<"                ";
 }
       }
       setcolor(10);
       line(x,getmaxy(),x+40,getmaxy());
       line(x,getmaxy(),x-20,getmaxy()-20);
       line(x+40,getmaxy(),x+60,getmaxy()-20);
       line(x-20,getmaxy()-20,x+60,getmaxy()-20);
       delay(10);

       setcolor(0);
       line(x,getmaxy(),x+40,getmaxy());
       line(x,getmaxy(),x-20,getmaxy()-20);
       line(x+40,getmaxy(),x+60,getmaxy()-20);
       line(x-20,getmaxy()-20,x+60,getmaxy()-20);
       setfillstyle(1,0);
       fillellipse(a,b,10,15);
b+=s;
     }
    varun:
    gotoxy(30,12);
    cout<<"EXCELLENT WORK "<<name;
    gotoxy(33,15);
    cout<<"GAME OVER.   ";
    gotoxy(32,18);
    cout<<"YOUR SCORE:"<<score;
    gotoxy(58,24);
    cout<<"COMPOSED BY:";
    gotoxy(55,25);
    cout<<"VARUN KUMAR SONKER";
    gotoxy(30,10);
    cout<<"GREATEST SCORE::"<< 540;

Snake Game in C

#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <time.h>

check();
end();
win();
int m[500],n[500],con=20;
clock_t start,stop;
void main(void)
{

int gd=DETECT,gm,ch,maxx,maxy,x=13,y=14,p,q,spd=100;

initgraph(&gd,&gm,"..\bgi");

setcolor(WHITE);
settextstyle(3,0,6);
outtextxy(200,2," SNAKE 2 ");
settextstyle(6,0,2);
outtextxy(20,80," Use Arrow Keys To Direct The Snake ");
outtextxy(20,140," Avoid The Head Of Snake Not To Hit Any Part Of Snake
");
outtextxy(20,160," Pick The Beats Untill You Win The Game ");
outtextxy(20,200," Press 'Esc' Anytime To Exit ");
outtextxy(20,220," Press Any Key To Continue ");
ch=getch();
if(ch==27) exit(0);
cleardevice();
maxx=getmaxx();
maxy=getmaxy();

randomize();

p=random(maxx);
int temp=p%13;
p=p-temp;
q=random(maxy);
temp=q%14;
q=q-temp;



 start=clock();
int a=0,i=0,j,t;
while(1)
{

 setcolor(WHITE);
 setfillstyle(SOLID_FILL,con+5);
 circle(p,q,5);
 floodfill(p,q,WHITE);

   if( kbhit() )
   {
     ch=getch(); if(ch==0) ch=getch();
     if(ch==72&& a!=2) a=1;
     if(ch==80&& a!=1) a=2;
     if(ch==75&& a!=4) a=3;
     if(ch==77&& a!=3) a=4;
      }
       else
     {
     if(ch==27
     ) break;
     }

       if(i<20){
    m[i]=x;
    n[i]=y;
    i++;
      }

if(i>=20)

{
 for(j=con;j>=0;j--){
 m[1+j]=m[j];
 n[1+j]=n[j];
 }
  m[0]=x;
  n[0]=y;

  setcolor(WHITE);
  setfillstyle(SOLID_FILL,con);
  circle(m[0],n[0],8);
  floodfill(m[0],n[0],WHITE);

  setcolor(WHITE);
  for(j=1;j<con;j++){
 setfillstyle(SOLID_FILL,con+j%3);
  circle(m[j],n[j],5);
  floodfill(m[j],n[j],WHITE);
     }
       delay(spd);

 setcolor(BLACK);
 setfillstyle(SOLID_FILL,BLACK);
  circle(m[0],n[0],8);
  floodfill(m[0],n[0],BLACK);

  setcolor(BLACK);
 setfillstyle(SOLID_FILL,BLACK);
  circle(m[j],n[j],5);
  floodfill(m[j],n[j],BLACK);

  }
     stop=clock();
     t=(stop-start)/CLK_TCK;
     printf(" TIME %d sec   ",t);
     printf("SCORE %d
",con-5);
     check();

    if(x==p&&y==q) { con=con+5; if(spd>=5) spd=spd-5; else spd=5;
     if(con>490) win();
     p=random(maxx); temp=p%13;  p=p-temp;
     q=random(maxy); temp=q%14;   q=q-temp;
   }
    if(a==1)  y =  y-14; if(y<0) { temp=maxy%14;y=maxy-temp;}
    if(a==2)  y =  y+14; if(y>maxy) y=0;
    if(a==3)  x =  x-13; if(x<0) { temp=maxx%13;x=maxx-temp;}
    if(a==4)  x =  x+13; if(x>maxx) x=0;
    if(a==0){  y = y+14 ;  x=x+13; }
}

 }


Chess for two humans


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void blk(int,int);
void display();
//enum bool{TRUE,FALSE};
/*void main()                   //MAIN FUNCTION
{
display();
getch();
} */
void display()     //DISPLAY TO SHOW THE BOARD
{
int gd=DETECT,gm,i,j,l,m,b;
char pattern[]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
int arrodd[32][2]={ {0,0},{100,0},{200,0},{300,0},{50,50},{150,50}
 ,{250,50},{350,50},{0,100},{100,100},{200,100},{300,100}
 ,{50,150},{150,150},{250,150},{350,150},{0,200},{100,200}
 ,{200,200},{300,200},{50,250},{150,250},{250,250},{350,250},
 {0,300},{100,300},{200,300},{300,300},{50,350},{150,350},
 {250,350},{350,350} };
int
arrevn[33][2]={{50,0},{150,0},{250,0},{350,0},{0,50},{100,50},{200,50},
   {300,50},{50,100},{150,100},{250,100},{350,100},{0,150},
   {100,150},{200,150},{300,150},{50,200},{150,200},{250,200},
   {350,200},{0,250},{100,250},{200,250},{300,250},{50,300},
   {150,300},{250,300},{350,300},{0,350},{100,350},{200,350},
   {300,350}};


clrscr();
initgraph(&gd,&gm,"");
for(i=0;i<=400;i=i+50)  //to draw vertical lines of the chess board.
{
line(i,0,i,400);
}
for(j=0;j<=400;j=j+50)  //to draw the horizontal lines of the chess
board.
{
line(0,j,400,j);
}
blk(420,0);
blk(420,250);
line(0,430,0,460);   //to draw the display at the bottom
line(0,430,400,430);
line(0,460,400,460);
line(400,430,400,460);
settextstyle(7,HORIZ_DIR,3);
setfillpattern(&pattern,GREEN);
for(b=0;b<=31;b++)
{
bar(arrodd[b][0],arrodd[b][1],arrodd[b][0]+50,arrodd[b][1]+50);
rectangle(arrodd[b][0],arrodd[b][1],arrodd[b][0]+50,arrodd[b][1]+50);
}
setfillpattern(&pattern,DARKGRAY);
for(m=0;m<=31;m++)
{
bar(arrevn[m][0],arrevn[m][1],arrevn[m][0]+50,arrevn[m][1]+50);
rectangle(arrevn[m][0],arrevn[m][1],arrevn[m][0]+50,arrevn[m][1]+50);
}
}
 void blk(int q,int r)
{
int y,z;
for(y=q;y<=(q+200);y=y+50)
{ line(y,r,y,r+200);}
for(z=r;z<=(r+200);z=z+50)
{ line(q,z,q+200,z);}
}



//Source file//
#include<akhchs.c>      //we used akhchs.c as header file
#include<stdio.h>
#include<conio.h>
#include<dos.h>
char pos[8][8],color[8][8];
void assign(char*,char*);
struct block{ //structure for every block
    int curx,cury;
    char clr,blkcolor;
   };
union REGS i,o;                 //for hardware interaction
char getblkcolor(int,int,int,int,char); //functions prototype
char chkpawnmov(struct block* selected,int x3,int y3);
char chkrookmov(struct block* selected,int x3,int y3);
char chkknightmov(struct block* selected,int x3,int y3);
char chkbishopmov(struct block* selected,int x3,int y3);
char chkqueenmov(struct block* selected,int x3,int y3);
char chkkingmov(struct block* selected,int x3,int y3);
void checkpwn(int,int);
void main()
{
int i1,j1,button,x,y,x1,y1,x2,y2,x3,y3,ch,i=0,j=0,z=1,turn=0;
struct block
*selected,pw[8],pb[8],rookw[2],rookb[2],bishopw[2],bishopb[2];
struct block kingw,kingb,queenw,queenb,knightw[2],knightb[2];
char id,nwblkclr,move='i';
assign(pos,color);
clrscr();
display();                            //for showing chess board
design();
setspare();   //for drawing rook etc.
setposw(pw);                        //sets position of black and
setposb(pb);                    //white pawns with color
setposrw(rookw,bishopw,knightw,&kingw,&queenw);//sets position of
whites
setposrb(rookb,bishopb,knightb,&kingb,&queenb);//sete position of
blacks
//restrictmouseptr(0,0,400,400);     //restricts pointer of mouse in
the
area specified there.
showmouseptr();
while(z)
{
i=i+1;
setcolor(WHITE);
if(turn%2==0) //means white's turn
 outtextxy(100,430,"white's turn");
else if(turn%2!=0) //means black's turn
 outtextxy(100,430,"black's turn");
while(i)
    {
     if(kbhit())
      {
      ch=getch();
      if(ch=='
')                //escape at pressing enter.
       exit(0);
      }
     getmousepos(&button,&x,&y);  //gets click position of mouse
if((button== 001))
{
  sound(1000);
  i=i-1;
  delay(50);
  nosound();
  delay(500);
}
    }
x1=relposx(x)/50;
y1=relposy(y)/50;
gotoxy(6,28);
if(x1==pw[0].curx && y1==pw[0].cury )
{  selected=&pw[0]; id='p'; }
else if(x1==pw[1].curx && y1==pw[1].cury )
{  selected=&pw[1]; id='p'; }
else if(x1==pw[2].curx && y1==pw[2].cury )
{  selected=&pw[2]; id='p';  }
else if(x1==pw[3].curx && y1==pw[3].cury )
{  selected=&pw[3]; id='p';  }
else if(x1==pw[4].curx && y1==pw[4].cury )
{  selected=&pw[4]; id='p';  }
else if(x1==pw[5].curx && y1==pw[5].cury )
{  selected=&pw[5]; id='p';  }
else if(x1==pw[6].curx && y1==pw[6].cury )
{  selected=&pw[6]; id='p';  }
else if(x1==pw[7].curx && y1==pw[7].cury )
{  selected=&pw[7]; id='p';  }
else if(x1==pb[0].curx && y1==pb[0].cury )
{  selected=&pb[0]; id='p';  }
else if(x1==pb[1].curx && y1==pb[1].cury )
{  selected=&pb[1]; id='p';  }
else if(x1==pb[2].curx && y1==pb[2].cury )
{  selected=&pb[2]; id='p';  }
else if(x1==pb[3].curx && y1==pb[3].cury )
{  selected=&pb[3]; id='p';  }
else if(x1==pb[4].curx && y1==pb[4].cury )
{  selected=&pb[4]; id='p';  }
else if(x1==pb[5].curx && y1==pb[5].cury )
{  selected=&pb[5]; id='p';  }
else if(x1==pb[6].curx && y1==pb[6].cury )
{  selected=&pb[6]; id='p';  }
else if(x1==pb[7].curx && y1==pb[7].cury )
{  selected=&pb[7]; id='p';  }
else if(x1==rookw[0].curx && y1==rookw[0].cury)
{  selected=&rookw[0]; id='r';  }
else if(x1==rookw[1].curx && y1==rookw[1].cury)
{  selected=&rookw[1]; id='r';  }
else if(x1==rookb[0].curx && y1==rookb[0].cury)
{  selected=&rookb[0]; id='r';  }
else if(x1==rookb[1].curx && y1==rookb[1].cury)
{  selected=&rookb[1]; id='r';  }
else if(x1==bishopw[0].curx && y1==bishopw[0].cury)
{  selected=&bishopw[0];id='b'; }
else if(x1==bishopw[1].curx && y1==bishopw[1].cury)
{  selected=&bishopw[1];id='b'; }
else if(x1==bishopb[0].curx && y1==bishopb[0].cury)
{  selected=&bishopb[0];id='b'; }
else if(x1==bishopb[1].curx && y1==bishopb[1].cury)
{  selected=&bishopb[1];id='b'; }
else if(x1==kingw.curx && y1==kingw.cury)
{  selected=&kingw; id='g';  }
else if(x1==queenw.curx && y1==queenw.cury)
{  selected=&queenw; id='q';  }
else if(x1==kingb.curx && y1==kingb.cury)
{  selected=&kingb; id='g';  }
else if(x1==queenb.curx && y1==queenb.cury)
{  selected=&queenb; id='q';  }
else if(x1==knightw[0].curx && y1==knightw[0].cury)
{  selected=&knightw[0];id='k'; }
else if(x1==knightw[1].curx && y1==knightw[1].cury)
{  selected=&knightw[1];id='k'; }
else if(x1==knightb[0].curx && y1==knightb[0].cury)
{  selected=&knightb[0];id='k'; }
else if(x1==knightb[1].curx && y1==knightb[1].cury)
{  selected=&knightb[1];id='k'; }
if((turn%2==0 && selected->clr=='b')||(turn%2!=0 &&
selected->clr=='w'))
exit();
turn=turn+1;
    j=j+1;
    while(j)
    {
if(kbhit())
      {
      ch=getch();
      if(ch=='
')                //escape at pressing enter.
       exit(0);
      }
getmousepos(&button,&x2,&y2);  //gets click position of mouse
if((button== 001))
{
sound(500);
j=j-1;
delay(100);
nosound();
delay(500);
}
   }
   x3=relposx(x2)/50; //gives standard x coordinate
   y3=relposy(y2)/50; //gives standard y coordinate
   nwblkclr=getblkcolor(x1,y1,x3,y3,selected->blkcolor);//get
destination
block's color;
   gotoxy(6,28);
   bottom();  //clears bottom display
     if(id=='p')       //wheteher pawn?
     {
 move= chkpawnmov(selected,x3,y3);
  if(move=='v')
  {
  draw(x3,y3,selected,nwblkclr,'p');
  checkpwn(x3,y3);
  }
      }
    else if(id=='r')  //whether rook?
     {
  move=chkrookmov(selected,x3,y3);
  if(move=='v' )
  {
 draw(x3,y3,selected,nwblkclr,'r');
  }
     }
    else if(id=='k') //whether knight?
    {
 move= chkknightmov(selected,x3,y3);
 if(move=='v' )
 {
 draw(x3,y3,selected,nwblkclr,'k');
 }

    }
    else if(id=='b')  //whether bishop?
    {
 move=chkbishopmov(selected,x3,y3);
  if(move=='v')
  {
  draw(x3,y3,selected,nwblkclr,'b');
  }
    }
    else if(id=='q')  //whether queen?
    {
 move=chkqueenmov(selected,x3,y3);
 if(move=='v')
 draw(x3,y3,selected,nwblkclr,'q');
     }
     else if(id=='g')  //whether king?
    {
 move=chkkingmov(selected,x3,y3);
 if(move=='v')
 draw(x3,y3,selected,nwblkclr,'g');
     }
      if(move=='i') turn=turn-1;
    }
  getch();
}

getmousepos(int *button,int* x,int* y) //gets mouse position.
{
 i.x.ax=3;
 int86(0x33,&i,&o);
 *button=o.x.bx;
 *x=o.x.cx;
 *y=o.x.dx;
 return;
}

showmouseptr()       //shows pointer in graphics mode.
{
 i.x.ax=1;
 int86(0x33,&i,&o);
 return;
}

void hidemouseptr()    //hides pointer
{
i.x.ax=0;
int86(0x33,&i,&o);
return;
}
restrictmouseptr(int x1,int y1,int x2,int y2)      //restrict pointer
 {
 i.x.ax=7;
 i.x.cx=x1;
 i.x.dx=x2;
 int86(0x33,&i,&o);
 i.x.ax=8;
 i.x.cx=y1;
 i.x.dx=y2;
 int86(0x33,&i,&o);
 return;
}
setposw(struct block* pawnw) //sete each white pawn.
{ int count,togl;
for(count=0,togl=0;count<=7;count++,togl++)
{
pawnw->curx=count;
pawnw->cury=6;
pawnw->clr='b';
if(togl%2==0)
pawnw->blkcolor='g';
else if(togl%2==1)
pawnw->blkcolor='m';
pawnw++;
}
 return;
}
setposb(struct block* pawnb) //sets each black pawn.
{
 int count,togl;
for(count=0,togl=0;count<=7;count++,togl++)
{
pawnb->curx=count;
pawnb->cury=1;
pawnb->clr='w';
if(togl%2==0)
pawnb->blkcolor='m';
else if(togl%2==1)
pawnb->blkcolor='g';
pawnb++;
       }
  return;
}
char chkpawnmov(struct block* selected,int x3,int y3)
{  char mov,id,c; //checks each pawn (black and white) move.
  id=pos[x3][y3];   //anybody?
  c=color[x3][y3];    //color?
  if(selected->clr=='w') //white pawn?
  {
if(x3==selected->curx && y3==selected->cury+1 ) //move 1
{ if(id=='n')           //id is none when no body is there
mov='v';
}
else if( (x3==selected->curx+1 || x3==selected->curx-1) &&
y3==selected->cury+1)
{
if(id!='n' && c=='b')               //black present?
{
mov='v';
send(id,c);
}
}
  }
  else if(selected->clr=='b')
 {
if(x3==selected->curx  &&  y3==selected->cury-1) //black and white
both
not there?
{         if(id=='n')
   mov='v';
}
else if((x3==selected->curx-1 || x3==selected->curx+1) &&
y3==selected->cury-1)
{   if(id!='n' && c=='w' ) //white there
  {
  mov='v'; //valid move
  send(id,c);
  }
}
 }
 else
 { //no action at invalid move.
mov='i';
 }
 return(mov);
}
setposrw(struct block* rookw,struct block* bishopw,struct block*
knightw,struct block* kingw,struct block* queenw)
{ //it sets the white rook,knight,bishop etc.
 int i;
 rookw->curx=rookw->cury=7;
 rookw->clr='w';
 rookw->blkcolor='m';
 rookw++;
 rookw->curx=7;rookw->cury=7;
 rookw->clr='w';
 rookw->blkcolor='g';
 bishopw->curx=2;
 bishopw->cury=7;
 bishopw->clr='w';
 bishopw->blkcolor='m';
 bishopw++;
 bishopw->curx=5;
 bishopw->cury=7;
 bishopw->clr='w';
 bishopw->blkcolor='g';
 knightw->curx=1;
 knightw->cury=7;
 knightw->clr='w';
 knightw->blkcolor='g';
 knightw++;
 knightw->curx=6;
 knightw->cury=7;
 knightw->clr='w';
 knightw->blkcolor='m';
 kingw->curx=3;kingw->cury=7;
 kingw->clr='w';kingw->blkcolor='m';
 queenw->curx=4;queenw->cury=7;
 queenw->clr='w';queenw->blkcolor='g';
 return;
}
setposrb(struct block* rookb,struct block* bishopb,struct block*
knightb,struct block* kingb,struct block* queenb)
{ //it sets the current coords of black rook,bishop,knight etc.
 int i;
 rookb->curx=0;rookb->cury=0;
 rookb->clr='b';
 rookb->blkcolor='g';
 rookb++;
 rookb->curx=7;rookb->cury=0;
 rookb->clr='b';
 rookb->blkcolor='m';
 bishopb->curx=2;
 bishopb->cury=0;
 bishopb->clr='b';
 bishopb->blkcolor='g';
 bishopb++;
 bishopb->curx=5;
 bishopb->cury=0;
 bishopb->clr='b';
 bishopb->blkcolor='m';
 knightb->curx=1;
 knightb->cury=0;
 knightb->clr='b';
 knightb->blkcolor='m';
 knightb++;
 knightb->curx=6;
 knightb->cury=0;
 knightb->clr='b';
 knightb->blkcolor='g';
 kingb->curx=3;kingb->cury=0;
 kingb->clr='b';kingb->blkcolor='m';
 queenb->curx=4;queenb->cury=0;
 queenb->clr='b';queenb->blkcolor='g';
 return;
}
draw(int x3,int y3,struct block* selected,char nwblkclr,char id1)
{
  int nx3,ny3,ncx,ncy;
  nx3=x3*50; ny3=y3*50; ncx=(selected->curx)*50;
ncy=(selected->cury)*50;
 if(nwblkclr=='g')       //CLEAR NEW POSITION
 setfillpattern(pattern,GREEN);
 else if(nwblkclr=='m')
 setfillpattern(pattern,MAGENTA);
 hidemouseptr();   //necessary to avoid the effect of mouse pointer.
 bar(nx3,ny3,nx3+50,ny3+50);
 setcolor(WHITE);
 rectangle(nx3,ny3,nx3+50,ny3+50);
 if(selected->blkcolor=='g')           //CLEAR PREVIOUS POSITION
 setfillpattern(pattern,GREEN);
 else if(selected->blkcolor=='m')
 setfillpattern(pattern,MAGENTA);   //clear the previous pos.
 bar(ncx,ncy,ncx+50,ncy+50);
 setcolor(WHITE);
 rectangle(ncx,ncy,ncx+50,ncy+50);
 if(id1=='p')   //if pawn was selected then draw the pawn at new
position.
 { if(selected->clr=='w')
pawndraw(nx3,ny3,0);   // 0 for white.
else if(selected->clr=='b')
pawndraw(nx3,ny3,1);

 }
else if(id1=='r') //if rook was selected
 { if(selected->clr=='w')
rookdraw(nx3,ny3,0);   // 0 for white.
else if(selected->clr=='b')
rookdraw(nx3,ny3,1);
 }
 else if(id1=='k') //if knight was selected
 {      if(selected->clr=='w')
drawknite(nx3,ny3,0);   // 0 for white.
else if(selected->clr=='b')
drawknite(nx3,ny3,1);
 }
 else if(id1=='b') //if bishop was selected
 {      if(selected->clr=='w')
drawbishop(nx3,ny3,0);   // 0 for white.
else if(selected->clr=='b')
drawbishop(nx3,ny3,1);
 }
 else if(id1=='g')
 {      if(selected->clr=='w')
drawking(nx3,ny3,0);   // 0 for white.
else if(selected->clr=='b')
drawking(nx3,ny3,1);
 }
 else if(id1=='q')
 {      if(selected->clr=='w')
drawqueen(nx3,ny3,0);   // 0 for white.
else if(selected->clr=='b')
drawqueen(nx3,ny3,1);
 }
showmouseptr();
pos[selected->curx][selected->cury]='n';
color[selected->curx][selected->cury]='n'; //welcome back  mr.
pointer.
selected->curx=x3;
selected->cury=y3;
selected->blkcolor=nwblkclr;
pos[x3][y3]=id1;
color[x3][y3]=selected->clr;
return;
}
char chkrookmov(struct block* selected,int x3,int y3)
{                //checks rook move for black and white as both have
same
moves.
 int i;
 char id,c,mov='v';
 if( (x3==selected->curx) || (y3==selected->cury) )
 {
if(x3>selected->curx && y3==selected->cury)
{
for(i=selected->curx+1;i<x3;i++)
{
id=pos[i][y3];
// c=color[i][y3];
if(id!='n') //if black or white present move is invalid
{
 mov='i';
}
}
}
       else if(x3<selected->curx && y3==selected->cury)
{
for(i=selected->curx-1;i>x3;i--)
{
id=pos[i][y3];
// c=color[i][y3];
if(id!='n') //if black or white
{
 mov='i';
}
}
}

       else if(x3==selected->curx && y3>selected->cury)
{
for(i=selected->cury+1;i<y3;i++)
{
id=pos[x3][i];
  // c=color[x3][i];
if(id!='n') //if black or white
{
 mov='i';
}
}
}
       else if(x3==selected->curx && y3<selected->cury)
{
for(i=selected->cury-1;i>y3;i--)
{
id=pos[x3][i];
    // c=color[x3][i];
if(id!='n') //if black or white
{
 mov='i';
}
}
}
   if(mov=='v')
   {
   id=pos[x3][y3];
   c=color[x3][y3];
   if(id!='n' && c=='b' && selected->clr=='w')           //means black
at
x3,y3
   {
      mov='v';
      send(id,c);
   }
   else if(id!='n' && c=='w' && selected->clr=='b')      //means white
there
   {
      mov='v';
      send(id,c);
   }
   else if(id=='n')//none of the white or black even at x3 & y3?
     mov='v';
   else
     mov='i';
   }
   }
   else mov='i';

return(mov);
}
char chkknightmov(struct block* selected,int x3,int y3)
{
 //knight's moves are not affected if some entity lies in the way.
 //it just jumps over them.Atmost only eight moves are possible.
 int i,posk[8][2];
 char id,c,mov='i';
 posk[0][0]=selected->curx+1;
 posk[0][1]=selected->cury-2;
 posk[1][0]=selected->curx-1;
 posk[1][1]=selected->cury-2;
 posk[2][0]=selected->curx+1;
 posk[2][1]=selected->cury+2;
 posk[3][0]=selected->curx-1;
 posk[3][1]=selected->cury+2;
 posk[4][0]=selected->curx+2;
 posk[4][1]=selected->cury-1;
 posk[5][0]=selected->curx+2;
 posk[5][1]=selected->cury+1;
 posk[6][0]=selected->curx-2;
 posk[6][1]=selected->cury+1;
 posk[7][0]=selected->curx-2;
 posk[7][1]=selected->cury-1;
 for(i=0;i<=7;i++)
 {
  if(x3==posk[i][0] && y3==posk[i][1])
  {
   id=pos[x3][y3];
   c=color[x3][y3];
  if(id!='n'&& c=='b' && selected->clr=='w')
  {
   mov='v';             //means black is there.
   send(id,c);
  }
  else if(id!='n'&&c=='w' && selected->clr=='b')
  {
   mov='v'; //means white is there.
   send(id,c);
  }
  else if(id=='n')
   mov='v'; //means it is blank.
  }
 }
  return(mov);
}
char chkbishopmov(struct block* selected,int x3,int y3)
{
 int m,n,m1,n1,i,j;
 char mov,id,c;
 m=x3-selected->curx;
 n=y3-selected->cury;
 if(abs(m)==abs(n))
 {  if(m>0 && n<0)//move 1
{ for(i=selected->curx+1,j=selected->cury-1;(i<x3 && j>y3);i=i++,j--)
{
    id=pos[i][j];
//     c=color[i][j];
    if(id!='n')
    mov='i';
}
}
if(m>0 && n>0)//move 2
{ for(i=selected->curx+1,j=selected->cury+1;(i<x3 && j<y3);i++,j++)
{
    id=pos[i][j];
//     c=color[i][j];
    if(id!='n')
    mov='i';
}
}
if(m<0 && n<0)//move 3
{ for(i=selected->curx-1,j=selected->cury-1;(i!=x3 && j!=y3);i--,j--)
{
    id=pos[i][j];
//     c=color[i][j];
    if(id!='n')
    mov='i';
}
}
if(m<0 && n>0)//move 4
{ for(i=selected->curx-1,j=selected->cury+1;(i>x3 && j<y3);i--,j++)
{
    id=pos[i][j];
//     c=color[i][j];
    if(id!='n')
    mov='i';
}
}
if(mov!='i') //..that no body is in the way,now at x3 y3?
{
id=pos[x3][y3];
c=color[x3][y3];
if(id!='n'&& c=='b')           //means black at x3,y3
{
   if(selected->clr=='w')
   {
     mov='v';
     send(id,c);
   }
   else
     mov='i';
}
else if(id!='n'&& c=='w')      //means white there
{
   if(selected->clr=='b')
   {
     mov='v';
     send(id,c);
   }
   else
   { mov='i';}

}
else if(id=='n')//none of the white or black even at x3 & y3?
mov='v';
}
 } //means not at the x cross.
 else
 {
  mov='i';
 }
 return(mov);
}
char chkqueenmov(struct block* selected,int x3,int y3)
{
 char mov1,mov2,mov3='i',id,c;
 mov1=chkrookmov(selected,x3,y3);
 mov2=chkbishopmov(selected,x3,y3);
 if(mov1=='v' || mov2=='v')              //move is valid and color is
checked already.
 {
 mov3='v';
 }
 return(mov3);
}
char chkkingmov(struct block* selected,int x3,int y3)
{
 char id,c,mov='i';
 id=pos[x3][y3];
 c=pos[x3][y3];
 if(x3==selected->curx+1 && y3==selected->cury-1) //move 1
 {
if(id=='n')
mov='v';
else if(selected->clr=='w' && id!='n' && c=='b')//means black there.
{
mov='v';
send(id,c);
}
else if(selected->clr=='b' && id!='n' && c=='w')//means white there.
{
mov='v';
send(id,c);
}
 }
 else if(x3==selected->curx-1 && y3==selected->cury-1)  //move 2
 {
if(id=='n')
mov='v';
else if(selected->clr=='w' && id!='n' && c=='b')//means black there.
{
mov='v';
send(id,c);
}
else if(selected->clr=='b' && id!='n' && c=='w')//means white there.
{
mov='v';
send(id,c);
}
 }
 else if(x3==selected->curx-1 && y3==selected->cury+1)  //move 3
 {
if(id=='n')
mov='v';
else if(selected->clr=='w' && id!='n' && c=='b')//means black there.
{
mov='v';
send(id,c);
}
else if(selected->clr=='b' && id!='n' && c=='w') //means white there.
{
mov='v';
send(id,c);
}
 }
 else if(x3==selected->curx+1 && y3==selected->cury+1)  //move 4
 {
if(id=='n' )
mov='v';
else if(selected->clr=='w' && id!='n' && c=='b')//means black there.
{
mov='v';
send(id,c);
}
else if(selected->clr=='b' && id!='n' && c=='w')//means white there.
{
mov='v';
send(id,c);
}
 }
 else if(x3==selected->curx+1 && y3==selected->cury)     //move 5
 {
if(id=='n')
mov='v';
else if(selected->clr=='w' && id!='n' && c=='b')//means black there.
{
mov='v';
send(id,c);
}
else if(selected->clr=='b' && id!='n' && c=='w') //means white there.
{
mov='v';
send(id,c);
}
 }
 else if(x3==selected->curx && y3==selected->cury-1)     //move 6
 {
if(id=='n')
mov='v';
else if(selected->clr=='w' && id!='n' && c=='b')//means black there.
{
mov='v';
send(id,c);
}
else if(selected->clr=='b' && id!='n' && c=='w')//means white there.
{
mov='v';
send(id,c);
}
 }
 else if(x3==selected->curx-1 && y3==selected->cury)     //move 7
 {
if(id=='n')
mov='v';
else if(selected->clr=='w' && id!='n' && c=='b')//means black there.
{
mov='v';
send(id,c);
}
else if(selected->clr=='b' && id!='n' && c=='w')//means white there.
{
mov='v';
send(id,c);
}
 }
 else if(x3==selected->curx && y3==selected->cury+1)     //move 8
 {
if(id=='n')
mov='v';
else if(selected->clr=='w' && id!='n' && c=='b')//means black there.
{
mov='v';
send(id,c);
}
else if(selected->clr=='b' && id!='n' && c=='w')//means white there.
{
mov='v';
send(id,c);
}
 }
 else //means move is not valid
 { mov='i';}
 return(mov);
}
void assign(char* post,char* col)
{ int i;
  char
val1[64]={"rpnnnnprkpnnnnpkbpnnnnpbgpnnnnpqqpnnnnpgbpnnnnpbkpnnnnpkrpnnnnpr"};
  char
val2[64]={"wwnnnnbbwwnnnnbbwwnnnnbbwwnnnnbbwwnnnnbbwwnnnnbbwwnnnnbbwwnnnnbb"};
  for(i=0;i<=63;i++,post++,col++)
  {  *post=val1[i]; *col=val2[i]; }
}
void checkpwn(int x3,int y3)
{
 char a;
 a=color[x3][y3];//whether pawn is white or black?
 bottom();
 setcolor(WHITE);
 if(a=='w' && (x3>=0 && x3<=7) && y3==7)
 {
  outtextxy(100,430,"well done white..press w");
  getch();    bottom();
 }
 else if(a=='b' && (x3>=0 && x3<=7) && y3==0)
 {
 outtextxy(100,430,"well done black..press b");
 getch();     bottom();
 }
 return;
}

WAV file player


//WARNING: You need a HUGE memory model to run this.

#include "ALLOC.H"
#include "DOS.H"
#include "CONIO.H"
#include "STDIO.H"

void main()
{
 char *name;
 printf("
 Enter the file name...:");
 scanf("%s",name);


 playwav(name,1.0);

}


void playwav(char wavefile[14],float delaytime);
struct WaveData {
  unsigned int SoundLength, Frequency;
  char *Sample;
};


struct HeaderType {
  long         RIFF;      //RIFF header
  char         NI1 [18];  //not important

  unsigned int Channels;  //channels 1 = mono; 2 = stereo
  long         Frequency; //sample frequency
  char         NI2 [6];   //not important
  char         BitRes;    //bit resolution 8/16 bit
  char         NI3 [12];  //not important
} Header;





struct WaveData Voice;         //Pointer to wave file


unsigned int    Base;          //Sound Blaster base address


char            WaveFile [25]; //File name for the wave file to be
played


/ Checks to see if a Sound Blaster exists at a given address, returns
  true if Sound Blaster found, false if not.
/
int ResetDSP(unsigned int Test)
{
  //Reset the DSP
  outportb (Test + 0x6, 1);
  delay(10);
  outportb (Test + 0x6, 0);
  delay(10);
  //Check if (reset was succesfull
  if ((inportb(Test + 0xE) & 0x80 == 0x80) && (inportb(Test + 0xA) ==
0xAA))
  {
    //DSP was found
    Base = Test;
    return (1);
  }
  else
    //No DSP was found
    return (0);
}


/ Send a byte to the DSP (Digital Signal Processor) on the Sound
Blaster
/
void WriteDSP(unsigned char Value)
{
  //Wait for the DSP to be ready to accept data
  while ((inportb(Base + 0xC) & 0x80) == 0x80);
  //Send byte

  outportb (Base + 0xC, Value);
}


/ Plays a part of the memory/

void PlayBack (struct WaveData *Wave)
{
  long          LinearAddress;
  unsigned int  Page, OffSet;
  unsigned char TimeConstant;


  TimeConstant = (65536 - (256000000 / Wave->Frequency)) >> 8;
  WriteDSP(0x40);                  //DSP-command 40h - Set sample
frequency
  WriteDSP(TimeConstant);          //Write time constant


  //Convert pointer to linear address
  LinearAddress = FP_SEG (Wave->Sample);
  LinearAddress = (LinearAddress << 4) + FP_OFF (Wave->Sample);
  Page = LinearAddress >> 16;      //Calculate page
  OffSet = LinearAddress & 0xFFFF; //Calculate offset in the page
  /*
      Note - this procedure only works with DMA channel 1
  */
  outportb (0x0A, 5);              //Mask DMA channel 1
  outportb (0x0C, 0);              //Clear byte pointer
  outportb (0x0B, 0x49);           //Set mode
  /*
      The mode consists of the following:
      0x49 = binary 01 00 10 01
                    |  |  |  |
                    |  |  |  +- DMA channel 01
                    |  |  +---- Read operation (the DSP reads from
memory)
                    |  +------- Single cycle mode
                    +---------- Block mode
  */


  outportb (0x02, OffSet & 0x100); //Write the offset to the DMA
controller
  outportb (0x02, OffSet >> 8);


  outportb (0x83, Page);           //Write the page to the DMA
controller


  outportb (0x03, Wave->SoundLength & 0x100);
  outportb (0x03, Wave->SoundLength >> 8);


  outportb (0x0A, 1);              //Unmask DMA channel



  WriteDSP(0x14);                  // DSP-command 14h - Single cycle
playback
  WriteDSP(Wave->SoundLength & 0xFF);
  WriteDSP(Wave->SoundLength >> 8);
}


/ Loads a wave file into memory.
 This procedure expects a _very_ standard wave header.
 It doesn't perform much error checking.
/
int LoadVoice (struct WaveData *Voice, char *FileName)
{
  FILE *WAVFile;


  //If it can't be opened...
  WAVFile = fopen(FileName, "rb");
  if (WAVFile == NULL) {
    //..display error message


    return (0);
  }


  //Return length of file for sound length minus 48 bytes for .WAV
header
  fseek(WAVFile, 0L, SEEK_END);
  Voice->SoundLength = ftell (WAVFile) - 48;
  fseek(WAVFile, 0L, SEEK_SET);


  //Check RIFF header
  if (Voice->SoundLength > 32000) {




    if (Voice->SoundLength > 64000) {


      Voice->SoundLength = 64000;
    }
  }
  free(Voice->Sample);
  Voice->Sample = (char *)malloc(Voice->SoundLength); //Assign memory
  if (!Voice->Sample) {

    return (0);
  }


  //Load the sample data
  fread(&Header, 46, 1, WAVFile);


  //Check RIFF header
  if (Header.RIFF != 0x46464952) {
    printf ("Not a wave file
");
    return (0);
  }


  //Check channels
  if (Header.Channels != 1) {
    printf ("Not a mono wave file
");
    return (0);
  }


  //Check bit resolution
  if (Header.BitRes != 8) {
    printf ("Not an 8-bit wave file
");
    return (0);
  }


  Voice->Frequency = Header.Frequency;


  //Load the sample data
  fread(Voice->Sample, Voice->SoundLength + 2, 1, WAVFile);


  fclose (WAVFile); //Close the file


  return (1);
}


void playwav (char wavefile[14], float delaytime  )
{
  delaytime=1.0;
  if (ResetDSP (0x220)) {
    //at 220h
    printf ("");
  } else {
    if (ResetDSP (0x240)) {

      //at 240h
      printf ("");
    } else {
      //or none at all
      printf ("");
      return;
    }
  }




  //Load wave file
  if (LoadVoice (&Voice, wavefile)) {


    //Start playback
    PlayBack (&Voice);


    delay(delaytime*1000);


    //Stops DMA-transfer
    WriteDSP (0xD0);
  }
}

Bouncing Ball


#include<graphics.h>
#include<conio.h>
#include<alloc.h>
#include<dos.h>
#include<stdlib.h>
void *ball;

void image()
{
//ball
setcolor(RED);
setfillstyle(SOLID_FILL,RED);
fillellipse(10,10,10,10);
ball=malloc(imagesize(0,0,20,20));
getimage(0,0,20,20,ball);
cleardevice();

}


void main()
{
int gm,gd=DETECT;
initgraph(&gd,&gm,"");
int l=getmaxx()/2,r=0,t=0,b=0;
int x=1,y=1;
int s=0,key=0;
int xstep=1,ystep=1;

image();
setbkcolor(GREEN);

while(key!=27)
{


while(!kbhit()){
putimage(l,t,ball,XOR_PUT);
delay(5);
putimage(l,t,ball,XOR_PUT);

if(l>=getmaxx()||l<=0){x*=-1;sound(1000);s=0;xstep=x*(random(4)+1);ystep=y
*(random(3)+1);if(l<=0)l=0;else l=getmaxx();}

if(t>=getmaxy()||t<=0){y*=-1;sound(1000);s=0;ystep=y*(random(4)+1);xstep=x
*(random(3)+1);if(t<=0)t=0;else t=getmaxy();}
l+=x+xstep;
t+=y+ystep;
s++;
if(s==5)
{nosound();}
}
key=getch();

}
closegraph();
}

Notepad


import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.io.*;
public class Editor extends Frame
    {
     String filename;
     TextArea tx;
     Clipboard clip = getToolkit().getSystemClipboard();
     Editor()
         {
         setLayout(new GridLayout(1,1));
         tx = new TextArea();
         add(tx);
         MenuBar mb = new MenuBar();
         Menu F = new Menu("file");
         MenuItem n = new MenuItem("New");
         MenuItem o = new MenuItem("Open");
         MenuItem s = new MenuItem("Save");
         MenuItem e = new MenuItem("Exit");
         n.addActionListener(new New());
         F.add(n);
         o.addActionListener(new Open());
         F.add(o);
         s.addActionListener(new Save());
         F.add(s);
         e.addActionListener(new Exit());
         F.add(e);
         mb.add(F);
         Menu E = new Menu("Edit");
         MenuItem cut = new MenuItem("Cut");
         MenuItem copy = new MenuItem("Copy");
         MenuItem paste = new MenuItem("Paste");
         cut.addActionListener(new Cut());
         E.add(cut);
         copy.addActionListener(new Copy());
         E.add(copy);
         paste.addActionListener(new Paste());
         E.add(paste);
         mb.add(E);
         setMenuBar(mb);
       
         mylistener mylist = new mylistener();
         addWindowListener(mylist);
     }
    
     class mylistener extends WindowAdapter
         {
         public void windowClosing (WindowEvent e)
             {
             System.exit(0);
         }
     }
   
     class New implements ActionListener
         {
         public void actionPerformed(ActionEvent e)
             {
             tx.setText(" ");
             setTitle(filename);
         }
     }
    
     class Open implements ActionListener
         {
         public void actionPerformed(ActionEvent e)
             {
             FileDialog fd = new FileDialog(Editor.this, "select File",FileDialog.LOAD);
             fd.show();
             if (fd.getFile()!=null)
                 {
                 filename = fd.getDirectory() + fd.getFile();
                 setTitle(filename);
                 ReadFile();
             }
             tx.requestFocus();
         }
     }
    
     class Save implements ActionListener
         {
         public void actionPerformed(ActionEvent e)
             {
             FileDialog fd = new FileDialog(Editor.this,"Save File",FileDialog.SAVE);
             fd.show();
             if (fd.getFile()!=null)
                 {
                 filename = fd.getDirectory() + fd.getFile();
                 setTitle(filename);
                 try
                     {
                     DataOutputStream d = new DataOutputStream(new FileOutputStream(filename));
                     String line = tx.getText();
                     BufferedReader br = new BufferedReader(new StringReader(line));
                     while((line = br.readLine())!=null)
                         {
                         d.writeBytes(line + "\r\n");
                         d.close();
                     }
                 }
                 catch(Exception ex)
                     {
                     System.out.println("File not found");
                 }
                 tx.requestFocus();
             }
         }
     }
    
     class Exit implements ActionListener
         {
         public void actionPerformed(ActionEvent e)
             {
             System.exit(0);
         }
     }
     void ReadFile()
         {
         BufferedReader d;
         StringBuffer sb = new StringBuffer();
         try
             {
             d = new BufferedReader(new FileReader(filename));
             String line;
             while((line=d.readLine())!=null)
             sb.append(line + "\n");
             tx.setText(sb.toString());
             d.close();
         }
         catch(FileNotFoundException fe)
             {
             System.out.println("File not Found");
         }
         catch(IOException ioe){}
     }
   
     class Cut implements ActionListener
         {
         public void actionPerformed(ActionEvent e)
             {
             String sel = tx.getSelectedText();
             StringSelection ss = new StringSelection(sel);
             clip.setContents(ss,ss);
             tx.replaceRange(" ",tx.getSelectionStart(),tx.getSelectionEnd());
         }
     }
    
     class Copy implements ActionListener
         {
         public void actionPerformed(ActionEvent e)
             {
             String sel = tx.getSelectedText();
             StringSelection clipString = new StringSelection(sel);
             clip.setContents(clipString,clipString);
         }
     }
    
     class Paste implements ActionListener
         {
         public void actionPerformed(ActionEvent e)
             {
             Transferable cliptran = clip.getContents(Editor.this);
             try
                 {
                 String sel = (String) cliptran.getTransferData(DataFlavor.stringFlavor);
                 tx.replaceRange(sel,tx.getSelectionStart(),tx.getSelectionEnd());
             }
             catch(Exception exc)
                 {
                 System.out.println("not string flavour");
             }
         }
     }
    
     public static void main(String args[])
         {
         Frame f = new Editor();
         f.setSize(500,400);
         f.setVisible(true);
         f.show();
     }
}