Pages

Saturday, December 25, 2010

C SOURCE CODES

mouse events
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
union REGS i,o;
void main()
 {
    int gd=DETECT,gm,x,y,maxx=630,maxy=451,button;
    initgraph(&gd,&gm," ");
    rectangle(0,90,maxx,maxy);
    setviewport(1,91,maxx-1,maxy-1,1);
    gotoxy(33,1);
    printf("Mouse Events");
    i.x.ax=0;
    int86(0x33,&i,&o);
    if(o.x.ax==0)
     {
        restorecrtmode();
        printf("Mouse Driver is not loaded.");
     }
    restrictmouseptr(1,91,maxx,maxy-1);
    i.x.ax=1;
    int86(0x33,&i,&o);
    gotoxy(1,3);
    printf("Left Button ");
    gotoxy(25,3);
    printf("Rigth Button ");
    gotoxy(50,5);
    printf("press any key to exit.........");
      while(!kbhit())
      {
        getmousepos(&button,&x,&y);
        gotoxy(1,5);
        if((button&1)==1)
        printf("Key is Pressed  ");
        else
        printf("Key is Released  ");
        gotoxy(25,5);
        if ((button&2)==2)
        printf("Key is Pressed  ");
        else
        printf("Key is Released  ");
        gotoxy(65,3);
        printf("x= %d  y= %d ",x,y);
      }
  }
    restrictmouseptr(int x1,int y1,int x2,int y2)
      {
        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);
      }
    getmousepos(int *button,int *x,int *y)
      {
        i.x.ax=3;
        int86(0x33,&i,&o);
        *button=o.x.bx;
        *x=o.x.cx;
        *y=o.x.dx;
      }
Digital circuit control by lpt port


#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
#include<stdlib.h>
#include<bios.h>
#define port 0x0378

char ch;
void display(int,int,int,int);
void dispbutton(int);
void click(int,int,int,int);
void status(int,int,int,int);
void reset(int*,int*,int*,int*);

int x,y,button;
union REGS i,o;

initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}

void showmouseptr()
{
 i.x.ax=1;
int86(0x33,&i,&o);
}

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

 void hidemouseptr()
 {
 i.x.ax=2;
 int86(0x33,&i,&o);
}


void main()
{clrscr();
 int s1=0,s2=0,s3=0,s4=0;
 int gdriver=DETECT,gmode,ercode;
 initgraph(&gdriver,&gmode,"");
 ercode=graphresult();
 if(ercode!=0){printf("error code:%s",grapherrormsg(ercode));
           getch();}
 display(s1,s2,s3,s4);
 initmouse();showmouseptr();
 while(ch!=27)
      {getmousepos(&button,&x,&y);
       if(button==1)
         {if(x>80&&x<180&&y>100&&y<140)ch='1';
          if(x>200&&x<300&&y>100&&y<140)ch='2';
          if(x>320&&x<420&&y>100&&y<140)ch='3';
          if(x>440&&x<540&&y>100&&y<140)ch='4';
          if(x>440&&x<540&&y>300&&y<340)ch=32;
          if(x>80&&x<180&&y>300&&y<340)ch=27;

         }


       if(kbhit())ch=getch();
       switch(ch)
             {case '1':{s1=!s1;
                        click(s1,s2,s3,s4);
                        outportb(port,1);delay(500);outport(port,0);
                        ch='0';break;
                   }
          case '2':{s2=!s2;
                click(s1,s2,s3,s4);
                        outportb(port,2);delay(500);outport(port,0);
                        ch='0';break;
                   }
              case '3':{s3=!s3;
                    click(s1,s2,s3,s4);
                        outportb(port,4);delay(500);outport(port,0);
                ch='0';break;
                   }
          case '4':{s4=!s4;
                    click(s1,s2,s3,s4);
                        outportb(port,8);delay(500);outport(port,0);
                    ch='0';break;
                   }
              case 32:{click(s1,s2,s3,s4);
                       reset(&s1,&s2,&s3,&s4);
                       ch='0';break;
                       }
          case 27: {click(s1,s2,s3,s4);
                        reset(&s1,&s2,&s3,&s4);
                        closegraph();exit(0);}
             }

      }
}

void display(int s1,int s2,int s3,int s4)
{setbkcolor(9);setcolor(1);
 rectangle(5,5,635,475);rectangle(10,10,630,470);
 dispbutton(1);dispbutton(2);dispbutton(3);dispbutton(4);
 dispbutton(5);dispbutton(6);
 status(s1,s2,s3,s4);
 setcolor(1);
 outtextxy(100,115,"SWITCH 1");
 outtextxy(220,115,"SWITCH 2");
 outtextxy(340,115,"SWITCH 3");
 outtextxy(460,115,"SWITCH 4");
 outtextxy(115,315,"EXIT");
 outtextxy(470,315,"RESET");
}

void dispbutton(int n)
{int x1,y1,x2,y2;
 if(n==1){x1=80;y1=100;x2=180;y2=140;}
 if(n==2){x1=200;y1=100;x2=300;y2=140;}
 if(n==3){x1=320;y1=100;x2=420;y2=140;}
 if(n==4){x1=440;y1=100;x2=540;y2=140;}
 if(n==5){x1=80;y1=300;x2=180;y2=340;}
 if(n==6){x1=440;y1=300;x2=540;y2=340;}
 setfillstyle(SOLID_FILL,7);
 bar(x1,y1,x2,y2);
 setcolor(15);
 line(x1,y1,x2,y1);line(x1,y1,x1,y2);
 setcolor(8);
 line(x2,y1,x2,y2);line(x1,y2,x2,y2);
}

void click(int s1,int s2,int s3,int s4)
{int x1,y1,x2,y2;
 if(ch=='1'){x1=80;y1=100;x2=180;y2=140;}
 if(ch=='2'){x1=200;y1=100;x2=300;y2=140;}
 if(ch=='3'){x1=320;y1=100;x2=420;y2=140;}
 if(ch=='4'){x1=440;y1=100;x2=540;y2=140;}
 if(ch==27){x1=80;y1=300;x2=180;y2=340;}
 if(ch==32){x1=440;y1=300;x2=540;y2=340;}
 hidemouseptr();
 setcolor(15);line(x2,y1,x2,y2);line(x1,y2,x2,y2);
 setcolor(8);line(x1,y1,x2,y1);line(x1,y1,x1,y2);
 sound(50);delay(75);nosound();
 setcolor(15);line(x1,y1,x2,y1);line(x1,y1,x1,y2);
 setcolor(8);line(x2,y1,x2,y2);line(x1,y2,x2,y2);
 showmouseptr();
 status(s1,s2,s3,s4);

}

void status(int s1,int s2,int s3,int s4)
{setcolor(4);setfillstyle(SOLID_FILL,4);
 circle(130,200,10);
 circle(250,200,10);
 circle(370,200,10);
 circle(490,200,10);
 if(s1==1)floodfill(130,200,4);
 else {setcolor(0);setfillstyle(SOLID_FILL,0);circle(130,200,10);
       floodfill(130,200,0);
       setcolor(4);circle(130,200,10);setfillstyle(SOLID_FILL,4);
      }
 if(s2==1)floodfill(250,200,4);
 else {setcolor(0);setfillstyle(SOLID_FILL,0);circle(250,200,10);
       floodfill(250,200,0);
       setcolor(4);circle(250,200,10);setfillstyle(SOLID_FILL,4);
      }
 if(s3==1)floodfill(370,200,4);
 else {setcolor(0);setfillstyle(SOLID_FILL,0);circle(370,200,10);
       floodfill(370,200,0);
       setcolor(4);circle(370,200,10);setfillstyle(SOLID_FILL,4);
      }
 if(s4==1)floodfill(490,200,4);
 else {setcolor(0);setfillstyle(SOLID_FILL,0);circle(490,200,10);
       floodfill(490,200,0);
       setcolor(4);circle(490,200,10);
      }
}

void reset(int *s1,int *s2,int *s3,int *s4)
{if(*s1==1)
   {outportb(port,1);delay(500);outport(port,0);}
 if(*s2==1)
   {outportb(port,2);delay(500);outport(port,0);}
 if(*s3==1)
   {outportb(port,4);delay(500);outport(port,0);}
 if(*s4==1)
   {outportb(port,8);delay(500);outport(port,0);}
 *s1=0;*s2=0;*s3=0;*s4=0;
 status(*s1,*s2,*s3,*s4);
}

reading serial port
#include<stdio.h>
#include<conio.h>
#include<dos.h>

void main()
  {
    char data;
    int choice;
    clrscr();

  printf("Enter the choice to send or receive from COM1::");
  scanf("%d",&choice);


  if(choice==1)
    {
      printf("Enter data to send::");
      scanf("%c",data);
      inportb(0x03f8,data);
    }


  else
    {
data=outport(0x3f8);
printf("reding from  COM1::%d",data);

    }
getch();
}

pc based device control
Code :

    /* Computerised Electrical Equipment Control */
    /* PC BASED DEVICE CONTROLLER */

  #include<stdio.h>
  #include<conio.h>
  #include<dos.h>

  void main()
    {
    void tone(void);
    int p=0x0378;
    char ex[23]={"Created By Mrc"};
    int j;
    char ex1[34]={"For Further Details & Improvements"};
    int k;
    char ex2[43]={"Contact : E-mail : anbudanravi_krr@sify.com"};
    int l;
    char ex3[24]={"Programming Language : C"};
    int m;
    int u[10];
    int i;
    static a,b,c,d,e,f,g,h;
    char no;
    clrscr();
    textcolor(15);
    gotoxy(20,6);
    cprintf("PC BASED DEVICE CONTROLLER");
    textcolor(11);
    gotoxy(20,7);
    cprintf("~~~~~~~~~~~~~~~~~~~~~~~~~~");
    textcolor(11);
    gotoxy(10,10);
    cprintf("Equipment Number: 1   2   3   4   5   6   7   8");
    textcolor(11);
    gotoxy(10,12);
    cprintf("Status          : %d   %d   %d   %d   %d   %d   %d
%d",a,b,c,d,e,f,g,h);
    textcolor(10);
    gotoxy(9,16);
    cprintf("For 'ON' And 'OFF' An Equipment Press Corresponding Equipment
Number");
    textcolor(11);
    gotoxy(28,18);
    cprintf("Status 0 = OFF   Status 1 = ON");
    textcolor(12);
    gotoxy(32,20);
    cprintf("For EXIT Press 'E'
");
    no=getch();
    switch(no)
      {
        case '1' :
            a=!a;
            tone();
            outportb(p,1);
            delay(500);
            outport(p,0);
            break;
        case '2' :
            b=!b;
            tone();
            outportb(p,2);
            delay(500);
            outport(p,0);
            break;
        case '3' :
            c=!c;
            tone();
            outportb(p,4);
            delay(500);
            outport(p,0);
            break;
        case '4' :
            d=!d;
            tone();
            outportb(p,8);
            delay(500);
            outport(p,0);
            break;
        case '5' :
            e=!e;
            tone();
            outportb(p,16);
            delay(500);
            outport(p,0);
            break;
        case '6' :
            f=!f;
            tone();
            outportb(p,32);
            delay(500);
            outport(p,0);
            break;
        case '7' :
            g=!g;
            tone();
            outportb(p,64);
            delay(500);
            outport(p,0);
            break;
        case '8' :
            h=!h;
            tone();
            outportb(p,128);
            delay(500);
            outport(p,0);
            break;
        case 'e' :
            if((a|b|c|d|e|f|g|h)==1)
              {
                clrscr();
                textcolor(10);
                gotoxy(20,12);
                cprintf("Please SHUT DOWN All The Equipments");
                sound(200);
                delay(500);
                nosound();
                delay(3000);
                break;
              }
            else
              {
                clrscr();
                for(j=0;j<23;j++)
                  {
                textcolor(10);
                gotoxy(20+j,12);
                cprintf("%c",ex[j]);
                sound(3000+j);
                delay(30);
                nosound();
                  }
                for(m=0;m<23;m++)
                  {
                textcolor(10);
                gotoxy(20+m,13);
                cprintf("%c",ex3[m]);
                sound(1800+m);
                delay(30);
                nosound();
                  }
                for(k=0;k<34;k++)
                  {
                textcolor(10);
                gotoxy(20+k,14);
                cprintf("%c",ex1[k]);
                sound(2000+k);
                delay(30);
                nosound();
                  }
                for(l=0;l<40;l++)
                  {
                textcolor(10);
                gotoxy(20+l,15);
                cprintf("%c",ex2[l]);
                sound(2500+l);
                delay(30);
                nosound();
                  }
                printf("



 Press Any Key");
                getch();
                outportb(p,0);
              }
        case 'E' :
            if((a|b|c|d|e|f|g|h)==1)
              {
                clrscr();
                textcolor(10);
                gotoxy(20,12);
                cprintf("Please SHUT DOWN All The Equipments");
                sound(200);
                delay(500);
                nosound();
                delay(3000);
                break;
              }
            else
              {
                clrscr();
                for(j=0;j<23;j++)
                  {
                textcolor(10);
                gotoxy(20+j,12);
                cprintf("%c",ex[j]);
                sound(2500+j);
                delay(30);
                nosound();
                  }
                for(m=0;m<24;m++)
                  {
                textcolor(10);
                gotoxy(20+m,13);
                cprintf("%c",ex3[m]);
                sound(3500+m);
                delay(30);
                nosound();
                  }
                for(k=0;k<34;k++)
                  {
                textcolor(10);
                gotoxy(20+k,14);
                cprintf("%c",ex1[k]);
                sound(3000+k);
                delay(30);
                nosound();
                  }
                for(l=0;l<43;l++)
                  {
                textcolor(10);
                gotoxy(20+l,15);
                cprintf("%c",ex2[l]);
                sound(3500+l);
                delay(30);
                nosound();
                  }
                printf("



 Press Any Key");
                getch();
                outportb(p,0);
                exit(0);
              }

        default  :
            clrscr();
            sound(500);
            delay(100);
            nosound();
            textcolor(11);
            gotoxy(30,12);
            cprintf("Invalid Key Pressed");
            textcolor(11);
            gotoxy(33,14);
            cprintf("Wait 2 Seconds");
            delay(3000);
            break;
      }
    main();
    }

  void tone(void)
    {
    sound(1000);
    delay(100);
    nosound();
    }


electrical equipment control by pc
Code :
//Computerised electrical equpiment control system.
//Developped by: Bhaskar Mukherjee, B.Tech(ECE)
#include<stdio.h>
#include<conio.h>
#include<dos.h>

void main()
{
 void tone(void);
 int p=0x0378;
 char ex[50]="Created by BHASKAR MUKHERJEE.";
 int k;
 char ex1[50]= "Programming language used is : C";
 int m,j,l;
 char ex2[50]="ALL SYSTEMS SHUT DOWN SUCCESSFULLY." ;
 char ex3[50]="THANK YOU FOR USING THIS SOFTWARE.";
 int u[10];
 int i;
 static a,b,c,d,e,f,g,h;
 char no;
 clrscr();
 textcolor(15);gotoxy(20,6);
 cprintf("COMPUTERISED ELECTRICAL EQUPIMENT CONTROL");
 textcolor(11);
 gotoxy(20,7);
 cprintf("-----------------------------------------");
 textcolor(9); gotoxy(10,10);
 cprintf("EQUIPMENT NO.    1     2     3     4     5     6     7     
8");
 textcolor(9); gotoxy(10,12);
 cprintf("STATUS           %d     %d     %d     %d     %d     %d     %d
%d",a,b,c,d,e,f,g,h);
 textcolor(10); gotoxy(14,16);
 cprintf("
FOR 'ON'AND 'OFF' PRESS CORESSPONDING EQUIPMENT NUMBER.");
 textcolor(13);gotoxy(25,18);
 cprintf("
STATUS 0 = OFF   STATUS  1 = ON");
 textcolor(12); gotoxy(32,22);
 cprintf("FOR EXIT PRESS 'E'");
 no=getch();
    switch(no)
    {
      case '1':
       a=!a;
       tone();
       outportb(p,1);
       delay(500);
       outportb(p,0);
       break;

      case '2':
       b=!b;
       tone();
       outport(p,2);
       delay(500);
       outportb(p,0);
       break;

        case '3':
       c=!c;
       tone();
       outport(p,4);
       delay(500);
       outportb(p,0);
       break;

       case '4':
       d=!d;
       tone();
       outport(p,8);
       delay(500);
       outportb(p,0);
       break;

       case '5':
       e=!e;
       tone();
       outport(p,16);
       delay(500);
       outportb(p,0);
       break;

       case '6':
       f=!f;
       tone();
       outport(p,32);
       delay(500);
       outportb(p,0);
       break;

       case '7':
       g=!g;
       tone();
       outport(p,64);
       delay(500);
       outportb(p,0);
       break;

       case '8':
       h=!h;
       tone();
       outport(p,128);
       delay(500);
       outportb(p,0);
       break;

       case 'e':
        if((a||b||c||d||e||f||g||h)==1)
        {
         clrscr();
         textcolor(13); gotoxy(20,12);
         cprintf("
WARNING:PLEASE SHUT DOWN ALL THE EQUIPMENTS!");
         sound(200);
         delay(8500);
         nosound();
         break;
         }
        else
        {
          clrscr();
          for(j=0;j<35;j++)
           {
            textcolor(13); gotoxy(20+j,12);
            cprintf("%c",ex[j]);
            sound(3000+j);
            delay(30);
            nosound();
            }
            for(m=0;m<40;m++)
             {
              textcolor(10);  gotoxy(20+m,13);
              cprintf("%c",ex3[m]);
              sound(1800+m);
              delay(30);
              nosound();
              }

              for(k=0;k<34;k++)
             {
              textcolor(4);  gotoxy(20+k,14);
              cprintf("%c",ex1[k]);
              sound(2000+k);
              delay(30);
              nosound();
              }

              for(l=0;l<40;l++)
             {
              textcolor(3);  gotoxy(20+l,15);
              cprintf("%c",ex2[l]);
              sound(2500+l);
              delay(30);
              nosound();
              }
              window(10, 10, 80, 25);
              printf("


PRESS ANY KEY.");
              getch();
              outportb(p,0);
              exit(0);
              }

          case 'E':
             if((a||b||c||d||e||f||g||h)==1)
               {
            clrscr();
            textcolor(10); gotoxy(20,12);
            cprintf("PLEASE SHUT DOWN ALL THE EQUIPMENTS.");
            sound(200);
            delay(500);
            nosound();
            delay(3000);
            break;
               }

        else
        {
          clrscr();
          for(j=0;j<23;j++)
           {
            textcolor(5); gotoxy(20+j,12);
            cprintf("%c",ex[j]);
            sound(3000+j);
            delay(30);
            nosound();
            }
            for(m=0;m<23;m++)
             {
              textcolor(3);  gotoxy(20+m,13);
              cprintf("%c",ex3[m]);
              sound(1800+m);
              delay(30);
              nosound();
              }

              for(k=0;k<34;k++)
             {
              textcolor(11);  gotoxy(20+k,14);
              cprintf("%c",ex1[k]);
              sound(2000+k);
              delay(30);
              nosound();
              }

              for(l=0;l<40;l++)
             {
              textcolor(12);  gotoxy(20+l,15);
              cprintf("%c",ex2[l]);
              sound(2500+l);
              delay(30);
              nosound();
              }
              textcolor(12+BLINK);gotoxy(40,40);
              cprintf("


        PRESS ANY KEY.");
              getch();
              outportb(p,0);
              exit(0);
              }

          default:
              clrscr();
              sound(500);
              delay(100);
              nosound();
              textcolor(9); gotoxy(30,12);
              cprintf("INVALID KEY PRESSED.");
              textcolor(11); gotoxy(33,14);
              cprintf("
WAIT FOR 2 SECONDS.");
              delay(3000);
              break;
              }
              main();
              }
              void tone(void)
               {
            sound(1000);
            delay(100);
            nosound();
            }

turn caps lock on
#include<stdio.h>
void main()
{
char far *kb;
kb=(char far *)0x417;
*kb=112;
}


implement all display functions
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<process.h>
#include<iostream.h>
# include<ctype.h>
main()
{
 int choice;
 char cont='y';
 int a1q1(),a1q2(),a1q3(),a1q4(),a1q5(),a1q6(),a1q7(),a1q8(),a1q9(),a1q10();
 clrscr();
 gotoxy(24,3);
 while(cont=='y')
 {
  clrscr();
  printf("
---------------------------------------");
  printf("
|1.Get current Display Mode.          | ");
  printf("
|2.Character with chosen attribute.   | ");
  printf("
|3. Scroll the window up.             | ");
  printf("
|4.Scroll the window down.            | ");
  printf("
|5.Read the character & it's attribute| ");
  printf("
|6.Positioning the Cursor .           | ");
  printf("
|7.Selecting the Video Mode.          | ");
  printf("
|8.Selecting the type of the Cursor.  | ");
  printf("
|9.Reading the Cursor position        | ");
  printf("
|10.Select the page of the text.      | ");
  printf("
|11. Exit.                            | ");
  printf("
---------------------------------------");
  printf("

         Enter your choice [  ]");
  gotoxy(37,16);
  scanf("%d",&choice);
  switch(choice)
  {
   case 1:
      a1q1();
      break;
   case 2:
      a1q2();
      break;
   case 3:
      a1q3();
      break;
   case 4:
      a1q4();
      break;
   case 5:
      a1q5();
      break;
   case 6:
      a1q6();
      break;
   case 7:
      a1q7();
      break;
   case 8:
      a1q8();
      break;
   case 9:
      a1q9();
      break;
   case 10:
      a1q10();
      break;
   case 11:
      exit(0);
  }
 gotoxy(3,21);
 printf("
Do you want to continue[y/n]: [ ]");
 gotoxy(32,22);
 cin>>cont;
 }
 getch();
}
/****************************************************************************/
a1q1()
{
 clrscr();
 union REGS regs;
 regs.h.ah=0x0f;
 int86(0x10,®s,®s);
 int noofcol;
 int displaymode;
 int activetextpage;
 noofcol = regs.h.ah;
 displaymode = regs.h.al;
 activetextpage = regs.h.bh;
 printf("
");
 printf("    No. of Columns on Screen - %d
",noofcol);
 printf("    Display Mode - %d
",displaymode);
 printf("    The Active Text Page - %d
",activetextpage);
 return(0);
}
/****************************************************************************/
a1q2()
{
 clrscr();
 union REGS regs;
 regs.h.ah = 2;
 regs.h.dh = 0;
 regs.h.dl = 0;
 regs.h.bh = 0;
 int86(0x10,®s,®s);

 getch();

 regs.h.ah = 9;
 regs.h.bh = 0;
 regs.h.al = 65;
 regs.h.dl = 8;
 regs.h.cl = 2;
 regs.h.ch = 0;
 int86(0x10,®s,®s);
 return(0);
}
/****************************************************************************/
a1q3()
{
 clrscr();
 union REGS regs;
 regs.h.ah = 6;
 regs.h.al = 5;
 regs.h.bh = 8;
 regs.h.ch = 0;
 regs.h.cl = 0;
 regs.h.dh = 50;
 regs.h.dl = 50;
 int86(0x10,®s,®s);
 return(0);
}
/****************************************************************************/
a1q4()
{
 clrscr();
 union REGS regs;
 regs.h.ah = 7;
 regs.h.al = 5;
 regs.h.bh = 8;
 regs.h.ch = 0;
 regs.h.cl = 0;
 regs.h.dh = 50;
 regs.h.dl = 50;
 int86(0x10,®s,®s);
 return(0);
}
/****************************************************************************/
a1q5()
{
 clrscr();
 int x,y;
 union REGS regs;
 regs.h.ah = 2;
 regs.h.dh = 0;
 regs.h.dl = 0;
 regs.h.bh = 0;
 int86(0x10,®s,®s);

 getch();

 regs.h.ah = 8;
 regs.h.bh = 0;
 int86(0x10,®s,®s);
 x = regs.h.al;
 y = regs.h.ah;
 clrscr();
 printf("Ascii Character is - %d
",x);
 printf("The attribute of Character is - %d
",y);
 return(0);
}
/****************************************************************************/
a1q6()
{
 clrscr();
 int x,y;
 union REGS regs;
 printf("
 Enter the X-position - ");
 scanf("%d",&x);
 printf("
 Enter the Y-position - ");
 scanf("%d",&y);
 regs.h.ah = 2;
 regs.h.bh = 0;
 regs.h.dh = y;
 regs.h.dl = x;
 int86(0x10,®s,®s);
 return(0);
}
/****************************************************************************/
a1q7()
{
 clrscr();
 int choice;
 union REGS regs;
 printf("
 For CGA Mode(0-6).");
 printf("
 For Mono MOde(1).");
 printf("
 Select the Mode - ");
 scanf("%d",&choice);
 clrscr();
 regs.h.ah = 0;   /*Set cursor position*/
 regs.h.al = choice;
 int86(0x10,®s,®s);
 gotoxy(40,12);
 printf("    HAVE A NICE DAY");
 return(0);
}
/****************************************************************************/
a1q8()
{
 clrscr();
 int x,y;
 union REGS regs;
 printf("
 Enter the starting line of the cursor(0-4) - ");
 scanf("%d",&x);
 printf("
 Enter the ending line of the cursor - ");
 scanf("%d",&y);
 gotoxy(40,12);
 regs.h.ah = 1;
 regs.h.ch = x;
 regs.h.cl = y;
 int86(0x10,®s,®s);
 return(0);
 }
/****************************************************************************/
a1q9()
{
 clrscr();
 union REGS regs;
 regs.h.ah = 3;
 regs.h.bh = 9;
 regs.h.dh = 8;
 regs.h.dl = 27;
 int86(0x10,®s,®s);
 printf("
The row position of cursor on selected page - %d",regs.h.ch);
 printf("
The column position of cursor on selected page - %d",regs.h.cl);
 return(0);
}
/****************************************************************************/
a1q10()
{
 clrscr();
 union REGS regs;
 regs.h.ah = 5;
 regs.h.bh = 6;
 int86(0x10,®s,®s);
 return(0);
}
/****************************************************************************/

#include<stdio.h>
#include<conio.h>
#include<dos.h>

void main(void)
{
 clrscr();
 union REGS regs;
 regs.h.ah = 1;
 regs.h.dl = 0x80;
 int86(0x13,®s,®s);
 printf("
If successful operation then AH & AL register resets.");
 printf("
AH register - %d",regs.h.ah);
 printf("
AL register - %d",regs.h.al);
 printf("
Successful Operation.");
 getch();
}

  Program to implement Specify command.
#include<conio.h>
#include<stdio.h>
#include<dos.h>

void main()
{
int x;
int result;
clrscr();

// Step 1Put on the motor
outp(0x3f2,28);//Address of digital control port 0x3f2
//Step 2 Check whether the FDC is ready

result=inp(0x3f4); //Read the status of MSR
result=(result&128);

if(result==128)//Check whether FDC is ready
{
//Beginning of command phase
//Step 3 Input the command parameters
 outp(0x3f5,3);//Enter command parameters
 delay(200);
 outp(0x3f5,204); //Enter SRT(2-32 step of 2) HUT(4-512 in step of4)
 delay(300);
 outp(0x3f5,25);//Enter the HUT and NDM
 delay(300);
}
delay(1000);
 result=inp(0x3f5);
   printf("The value od data register is %d",result);

getch();
//Put off the motor
outp(0x3f2,0);


}

Program: To Implement Sense Drive Command.

#include<conio.h>
#include<stdio.h>
#include<dos.h>




void main()
{
int x;
int show;
clrscr();

        // Put on the motor
outp(0x3f2,28);//Address of digital control port 0x3f2

        // Check whether the FDC is ready
show=inp(0x3f4); //Read the status of MSR
show=(show&128);

if(show==128)//Check whether FDC is ready
{
        //Beginning of command phase
        // Input the command parameters
 outp(0x3f5,4);//Enter command parameters
 delay(200);
 outp(0x3f5,0); //Enter Head no and Drive no.
 delay(300);
}
delay(1000);
 show=inp(0x3f4);
 show=show&192;//Check whether it is in show phase
 if(show==192)
 {
  show=inp(0x3f5);//Read the status of
  printf("The registers are %d",show);
 }

getch();
        //Put off the motor
outp(0x3f2,0);
}
  Program for enabling and disabling the keyboard.
#include<stdio.h>
#include<conio.h>
#include<dos.h>

main()
{
 clrscr();
 outportb(0x64,0xAD);    /*Code for disabling the KEYBOARD*/
 printf("
Keyboard Disabled");
 delay(10000);
 clrscr();
 printf("
Keyboard Enabled");
 outportb(0x64,0xAE);    /*Code for enabling the KEYBOARD*/
 getch();

}
CREATING SOUND FROM PC
This example will play a sound depending on what a user selects from a menu . This uses the sound() function which may be part of the dos.h of your compiler
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
int menu(void);
main()
{
while(1)
{
/*get selection and execute the relevant statement*/
switch(menu())
{
case 1:
{
puts(“sound the speaker 1\n”);
sound(2000);
sleep(2);
nosound();
break;
}
case 2:
{
puts(“sound that speaker 2\n”);
sound(4000);
sleep(2);
nosound();
break;
}
case 3:
{
puts(“You are quitting\n”);
exit(0);
break;
}
default:
{
puts(“Invalid menu choice\n”);
break;
}
}
}
return 0
}
/*menu function*/
int menu(void)
{
int reply;
/*display menu options*/
puts(“Enter 1 for beep 1.\n”);
puts(“Enter 2 for beep 2.\n”);
puts(“Enter 3 to quit.\n”);
/*scan for user entry*/
scanf(“%d”, &reply);
return reply;
}

No comments:

Post a Comment

Leave your comment here