Showing posts with label Hardware. Show all posts
Showing posts with label Hardware. Show all posts

Saturday, 9 August 2014

Hardware program to inverse the status of caps, num and scroll lock

This is a hardware program to inverse the status of the caps, num and scroll lock. If you have any doubts please let me know.

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

int main()
{
int c,n,s;
int far *p=(int far *)0x417;
int far *q=(int far *)0x418;
char text[50];
union REGS in, out;
clrscr();

c=*p&0x40;
s=*p&0x10;
n=*p&0x20;

if (c==0x40)
                        printf("\nCaps lock is ON");
else
                        printf("\nCaps lock is OFF");

if(n==0x20)
                        printf("\nNum lock is OFF");
else
                        printf("\nNum lock is ON");

if(s==0x10)
                        printf("\nScroll lock is ON");
else
                        printf("\nScroll lock is OFF");
printf("\nText before toggle: ");
gets(text);

*p=*p^0x70;
*q=*q^0x70;

printf("\nTOGGLE\n");

c=*p&0x40;
s=*p&0x10;
n=*p&0x20;

if (c==0x40)
                        printf("\nCaps lock is ON");
else
                        printf("\nCaps lock is OFF");

if(n==0x20)
                        printf("\nNum lock is OFF");
else
                        printf("\nNum lock is ON");

if(s==0x10)
                        printf("\nScroll lock is ON");
else
                        printf("\nScroll lock is OFF");

printf("\nText after toggle: ");
gets(text);
printf("\n Press any key to exit");
getch();

return 0;

}

Hardware program to implement the filling of a rectangle with a click

This is a hardware program to implement the filling of a rectangle on a click. If you have any doubts, please let me know. 

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

int main(void)
{
    clrscr();
   int gdriver = DETECT, gmode;
   int left, top, right, bottom,c,poly[8],x,y;
   union REGS in,out;
   initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi ");
   left = getmaxx() / 2 - 50;
   top = getmaxy() / 2 - 50;
   right = getmaxx() / 2 + 50;
   bottom = getmaxy() / 2 + 50;
   rectangle(left,top,right,bottom);
   in.x.ax=7;
   in.x.cx=left;
   in.x.dx=right;
   int86(0x33,&in,&out);
   in.x.ax=8;
   in.x.cx=top;
   in.x.dx=bottom;
   int86(0x33,&in,&out);
   in.x.ax=1;
   int86(0x33,&in,&out);
    poly[0]=left;
    poly[1]=top;
    poly[2]=left+100;
    poly[3]=top;
    poly[4]=right;
    poly[5]=bottom;
    poly[6]=right-100;
    poly[7]=bottom;
    printf("BUTTON STATUS");
    while(!kbhit())
    {
      in.x.ax=3;
      int86(0x33,&in,&out);
      c=out.x.bx;
      gotoxy(2,2);
      switch(c)
      {
      case 0:
                 break;
      case 1:
                 in.x.ax=2;
                 int86(0x33,&in,&out);
                 setfillstyle(SOLID_FILL,15);
                 fillpoly(4,poly);
                 in.x.ax=1;
                 int86(0x33,&in,&out);
                 printf("\nLEFT  PRESS");
                 break;
      case 2:
                 in.x.ax=2;
                 int86(0x33,&in,&out);
                 setfillstyle(SOLID_FILL,0);
                 fillpoly(4,poly);
                 in.x.ax=1;
                 int86(0x33,&in,&out);
                 printf("\nRIGHT PRESS");
                 break;
      }
      gotoxy(2,4);
      printf("\nPress any key to exit");
    }
    in.x.ax=0;
    int86(0x33,&in,&out);
    getch();
    closegraph();
    return 0;
}





Hardware lab program for ascii and scan values of a key

This is a hardware lab program to obtain the scan code and ascii code of a key. If you have any doubts, please let me know.


DEVELOPMENT:

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
            int ac,sc;
            union REGS in,out;
            do
{

                        clrscr();
                        printf("Enter a key");
                        in.x.ax=0;
                        int86(0x16,&in,&out);
                        sc=out.h.ah;
                        ac=out.h.al;
                        printf("\nKey: %c",ac);
                        printf("\n Scan code is:%d",sc);
                        printf("\n Ascii code is :%d",ac);
                        printf("\nPress any key to continue and 'e' to exit!\n");

}while(getch()!='e');

 }



Hardware lab program for Mouse co-ordinates as well as status

This is a C program to implement mouse co-ordinates as well as status of button click in the hardware lab.
If you have any doubts, please let me know.

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
     int x,y , z,x1,y1,z1;
     union REGS in,out;
     in.x.ax=1;
     int86(0x33,&in,&out);
     in.x.ax=3;
     int86(0x33,&in,&out);
     x1=out.x.cx;
     y1=out.x.dx;
     z1=out.x.bx;
    do
    {
        do
        {
              in.x.ax=1;
              int86(0x33,&in,&out);
              in.x.ax=3;
              int86(0x33,&in,&out);
              x=out.x.cx;
              y=out.x.dx;
              z=out.x.bx;
        }while((x==x1)&&(y==y1)&&(z==z1));
            clrscr();
            printf("MOUSE COORDINATES:");
            printf("\nx coordinate:%d\t ",x1);
            printf("\ny coordinate:%d\t ",y1);
            printf("\n\nBUTTON STATUS");
            switch(z1)
            {
                 case 0: printf("\nNo press\n");
                        break;
                 case 1:printf("\nLeft press\n");
                        break;
                 case 2:printf("\nRight press\n");
                        break;
                 case 3:printf("\nBoth press\n");
                break;
         }
         x1=x;
         y1=y;
             z1=z;
             printf("\n\nPress any key to exit..");
     }while(!kbhit());
     in.x.ax=2;
     int86(0x33,&in,&out);
}