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;
}

ASSEMBLE OWN PC

Note: You can find the meaning of an abbreviation at the end of this article under the heading Jargon Buster.

Step 1: Installing the motherboardp1010185.jpg

Make sure you have all the components in place and a nice, clean and big enough place to work with.
Put your antic-static wrist strap on to prevent your components from getting affected. Make sure your hands are clean before starting. First we will be installing the motherboard which is a piece of cake to install.
  • Open the side doors of the cabinet
  • Lay the cabinet on its side
  • Put the motherboard in place
  • Drive in all the required screws
Tip: Most motherboards come with an antistatic bag. It is advisable to put the motherboard on it for some time and then remove it from the antistatic bag before placing it in the cabinet.

 

 

 

 

Step 2: Installing the CPU

CPU is the heart of a computer so make sure you handle it properly and do not drop it or mishandle it. Also try not to touch the pins frequently so that they do not get dirty. Get hold of your motherboard and CPU manual. You need to place the CPU on the dotted white patch of the motherboard in a particular fashion for it to fit properly. There is a golden mark on the CPU to help you assist. Consult both your motherboard and CPU manual to see which position it fits exactly or you could also use try all the 4 positions.

016b1.jpg

  • Lift the CPU lever on the motherboard
  • Place the CPU properly on the motherboard
  • Pull down the lever to secure the CPU in place
Warning: Do not try to push the CPU into the motherboard!
Got the thermal compound? Now is the time to use it. Take small amount of it and carefully apply it on the top surface of the processor. Be careful not to put it on the neighboring parts of the motherboard. If you do so clean it immediately using the cloth.
Tip: Thermal compounds should be changed once every six months for optimal performance.

 

 

 

 

 

Step 3: Installing the heat sink

0181.jpgAfter installing the processor we proceed to installing the heat sink. There are different kinds of heat sinks that are bundled with the processor and each has a different way of installation. Look into your CPU manual for instructions on how to install it properly.
  • Place the heat sink on the processor
  • Put the jacks in place
  • Secure the heat sink with the lever
After this you will need to connect the cable of the heat sink on the motherboard. Again look into the motherboard manual on where to connect it and then connect it to the right port to get your heat sink in operational mode.

 

 

 

 

 

 

Step 4: Installing the RAMinstallingram.gif

Installing the RAM is also an easy job. The newer RAMs ie. DDR RAMs are easy to install as you don’t have to worry about placing which side where into the slot. The older ones, SDRAMs are plagued by this problem.
If you want to use dual channel configuration then consult your manual on which slots to use to achieve that result.
  • Push down the RAM into the slot
  • Make sure the both the clips hold the RAM properly

 

 

 

 

 

Step 5: Installing the power supplypsu1.jpg

We will now install the power supply as the components we install after this will require power cables to be connected to them. There is not much to be done to install a PSU.
  • Place the PSU into the cabinet
  • Put the screws in place tightly
Tip: Some PSU have extra accessories that come bundled with it. Consult your PSU manual to see how to install them.

 

 

 

 

 

 

Step 6: Installing the video card

110665-2107p146-5b.jpg

First you will need to find out whether your video card is AGP or PCI-E. AGP graphics cards have become redundant and are being phased out of the market quickly. So if you bought a spanking new card it will certainly be a PCI-E.
  • Remove the back plate on the cabinet corresponding to the graphics card
  • Push the card into the slot
  • Secure the card with a screw
  • Plug in the power connection from PSU (if required)
High-end graphics cards need dedicated power supply and if your graphics card needs one then connect the appropriate wire from PSU into the graphics card.

 

 

 

 

 

 

Step 7: Installing the hard disk042b.jpg

Hard disk is another fragile component of the computer and needs to handled carefully.
  • Place the hard drive into the bay
  • Secure the drive with screws
  • Connect the power cable from PSU
  • Connect the data cable from motherboard into the drive





If your hard drive is a SATA one then connect one end of SATA cable into the motherboard and other into the SATA port on the hard disk. If your hard disk is PATA type then use the IDE cable instead of the SATA cable.ide-sata.jpg
Tip: If your PSU does not support SATA power supply then you will need to get an converter which will convert your standard IDE power connector to a SATA power connector.

 

 

 

 

 

Step 8: Installing optical drive

The installation an optical drive is exactly similar to an hard drive.027.jpg
  • Place the optical drive into the bay
  • Drive in the screws
  • Connect the power cable and data cable
Tip: When installing multiple optical drives take care of jumper settings. Make sure you make one as primary and other slave by using the jumper. This is not applicable if the drives are SATA drives.

 

 

 

 

 

Step 9: Connecting various cables

First we will finish setting up internal components and then get on to the external ones. You will need to consult your motherboard manual for finding the appropriate port for connecting various cables at the right places on the motherboard.
  • Connect the large ATX power connector to the power supply port on your motherboard041a.jpg
  • Next get hold of the smaller square power connector which supplies power to the processor and connect it to the appropriate port by taking help from your motherboard manual
  • Connect the cabinet cables for power,reset button in the appropriate port of the motherboard
  • Connect the front USB/audio panel cable in the motherboard
  • Plug the cable of cabinet fans






You are done with installing the internal components of the PC. Close the side doors of the cabinet and get it upright and place it on your computer table. Get the rest of the PC components like monitor, keyboard, mouse, speakers etc. which we will connect now.
  • Connect the VGA cable of the monitor into the VGA port029a.jpg
  • If mouse/keyboard are PS/2 then connect them to PS/2 ports or else use the USB port
  • Connect the speaker cable in the audio port
  • Plug in the power cable from PSU into the UPS
  • Also plug in the power cable of the monitor
You are now done with setting up your PC. Power on and see your rig boot to glory.

 

 

 

 

 

Step 10: Installing the OS and drivers

We are done with the hardware part. Now get your favorite OS disks ready and the CD that came with your motherboard.
  • Set the first boot device to CD/DVD drive in BIOS
  • Pop in the OS disk
  • Reboot the PC
  • Install the OS
  • Install drivers from motherboard CD (applicable only to Windows OS)
Voila! You have your PC up and running. Enjoy your journey with your self assembled rig!

MAKING OWN IR CAMERA

The camera

The camera used for this experiment was a Sweex USB Webcam this camera was chosen for it's price and availability. IE I didn't mind too much if I killed it and it was sat on the desk at the time.

The adverts at the top should show some providers of cheap webcams, and buying from these people will help to pay my hosting costs.

As an added bonus, but nothing to do with this project, this camera works fine under Linux with a 2.6 Kernel (I'm using 2.6.8) using the sonixcam driver from
here
.








Conversion

Step 1 (Sweex specific)

Remove the crappy plastic stand. - try not to lose the little rubber bits from the holes in the camera sides. I think they are supposed to stop it from tilting upwards under the weight of the wire. Shame they don't work really.

Step 2 (possibly also Sweex specific)

Remove the screws. If your chosen
victim
webcam is held together in some other way you'll have to figure it out yourself.

Step 3 (Probably not Sweex specific)

Prize the casing apart.

Step 4 (Kind of Sweex Specific)

If the Lens will not unscrew without removing the PCB (Like on the Sweex) then remove the PCB. It probably only slides in anyway.

Step 5 (Almost certainly not Sweex specific)

Unscrew the lens assembly from it's holder. The focus on most webcams is achieved using the screw thread that is also used to hold the lens in. Turning it enough times will unscrew it completely. All camera's I've ever met won't let you do this without opening the case. The bit that comes out of the sweex looks like this.







Step 6 (Doesn't appear to be Sweex specific)

Looking at the lens assembly in the picture you can see a small square of glass stuck in the back. Though it appears clear in the picture above, it has a red tint to the eye as shown here.






I've looked in a Creative camera and seen the same thing there but theirs is round. This piece of glass is the Infra Red Filter. It stops IR light getting through to the sensor. For our purpose this is bad so remove this piece of glass. Removing a square one like the Sweex is easy but I suspect the creative round one is harder.

Mitch White has this to say on the Alaris weeCam ...the filter is actually "painted" on one of the lenses. At first I thought I wouldn't be able to remove the filter, but I tried scratching at it with my fingernail, and it started to come off! So, after scratching off all the redish stuff, I reassembled the camera and it works perfectly!


Ken R has converted a Creative camera though not the same as mine. Click here for his instructions on adapting the lens assembly.
Newer Sweex models and many others have a lens design with a cross section like this.






Don't you just love MS Paint.
On here, the red is the IR filter, the green bit on here is a small plastic collar that holds things together. It looks at first glace like the same piece of plastic as the main lens holder assembly. This can be removed by levering it out with a sharp knife. This collar can be used to hold the new IR pass filter in place later.

Step 7 (Not at all sweex specific)

Now we need to make a new filter only we want one that blocks visible light and only lets IR through.

Dig out your holiday snaps and look at the negatives. NOTE: they must be colour negatives, black and white ones won't work. Find a bit of absolute black, you can usually find a bit before the real photo's start. Make sure it's really black, a part of a normal photo may not be good enough.

Cut two small bits out similar in size to the IR filter that you just removed.







Step 8 (Also not at all sweex specific)

Fit the two bits of film where the old filter was.







Step 9 (No idea if it's Sweex specific)

Do something to hold the bits of film in place. I used a little bit of wire as shown rather blurredly here. If you use superglue for this be careful not to get any on the actual lens or the part of the negatives that the IR light will pass through.







Step 10 (I'm getting fed up of saying whether it's Sweex specific or not.)

Screw the lens back into the camera PCB.

Step 10

Re-assemble the rest of the camera.

Step 11

Make sure you're using real sunlight or tungsten lighting. Those new fangled high efficency bulbs give out very little IR light.