Search This Blog

C Program Using 8086 Interrupts to Restrict Mouse Pointer Into a Circle of Given Center and Radius

C Program Using 8086 Interrupts to Restrict Mouse Pointer Into a Circle of Given Center and Radius. The mouse ponter will be restricted to a circle of user specified center and radius using the interrupt 33 of 8086 in c complier. I have tested this program in Turbo C compiler.
How to restrict mouse cursor or pointer within a user specified circle Using 8086 INT33 service interrupts arrow mice radius centre Turbo c program Turbo C++ code source code without thread screen rectangle
Mouse pointer restricted into a circle in Turbo C


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

void main()
{
int x,y,tx,ty,r;
union REGS inreg, outreg;
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
clrscr();
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode,"C:\\TC\\BGI\\" );
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
setcolor(getmaxcolor());
printf("\nEnter the center of circle. x and y");
scanf("%d%d",&x,&y);
printf("\nEnter the radius of circle");
scanf("%d",&r);
clrscr();
circle(x,y,r);
inreg.x.ax=0x1;
int86(0x33,&inreg,&outreg);
inreg.x.ax=0x7;
inreg.x.cx=x-r;
inreg.x.dx=x+r;
int86(0x33,&inreg,&outreg);
inreg.x.ax=0x8;
inreg.x.cx=y-r;
inreg.x.dx=y+r;
int86(0x33,&inreg,&outreg);
do
{
inreg.x.ax=0x3;
int86(0x33,&inreg,&outreg);
tx=outreg.x.cx;
ty=outreg.x.dx;
if((tx-x)*(tx-x)+(ty-y)*(ty-y)>r*r)
{
if(tx<=x)
{
if(ty<y)
do{tx++; ty++;}while((tx-x)*(tx-x)+(ty-y)*(ty-y)>=r*r);
else
do{tx++; ty--;}while((tx-x)*(tx-x)+(ty-y)*(ty-y)>=r*r);
}
else
{
if(ty<=y)
do{tx--; ty++;}while((tx-x)*(tx-x)+(ty-y)*(ty-y)>=r*r);
else
do{tx--; ty--;}while((tx-x)*(tx-x)+(ty-y)*(ty-y)>=r*r);
}
inreg.x.ax=0x4;
inreg.x.cx=tx;
inreg.x.dx=ty;
int86(0x33,&inreg,&outreg);
}
}while(1);
}

C Program to Display and Set System Time and Date Using 8086 Interrupts

This is a C Program to Display and Set System Time and Date Using 8086 Interrupts. Interrupt number 21 (in hexadecimal) is used to:
C program to get system time and date and also to set it using 8086 interrupt INT 21 interrupt 0x21 21h int86() function call interrupts in C program
Output of c Program to get and set system time and date 

  • Get System time
  • Set System time
  • Get System Date
  • Set System Date
To Get system date:
- Call interrupt 0x21 (hexadecimal) 
- AH (higher byte of accumulator) should be made equal to 2A (hex) before calling interrupt
Output:



  • day in DL
  • Month in DH
  • Year in CX

To set System Date:

- Call interrupt 0x21 (hexadecimal) 
- AH (higher byte of accumulator) should be made equal to 2B (hex) before calling interrupt
- Before Calling interrupt, store:
  • Year in CX
  • Month in DH
  • Day in DL
To Get system time:
- Call interrupt 0x21 (hexadecimal) 
- AH (higher byte of accumulator) should be made equal to 2C (hex) before calling interrupt
Output:
  • Hours in CH
  • Minutes in CL
  • Seconds in DH
  • 1/100 th of a second in DL







To set System Time:







- Call interrupt 0x21 (hexadecimal) 


- AH (higher byte of accumulator) should be made equal to 2D (hex) before calling interrupt

- Before Calling interrupt, store:


  • Hour in CH 

  • Minutes in CL

  • Seconds in DH 

  • 1/100 th of second in DL




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

void main()
{
int day,month,year,tflag=0,dflag=0,hr,min,sec;
union REGS inreg,outreg;
DISDATE:printf("\nCurrent date:\n");
inreg.h.ah=0x2a;
int86(0x21,&inreg,&outreg);
printf("%d-%d-%d ",outreg.h.dl,outreg.h.dh,outreg.x.cx);
switch(outreg.h.al)
{
case 0:printf("Sunday");break;
case 1:printf("Monday");break;
case 2:printf("Tueday");break;
case 3:printf("Wednesday");break;
case 4:printf("Thursday");break;
case 5:printf("Friday");break;
case 6:printf("Sunday");break;
}
if(dflag==1)
goto SETTIME;
DISTIME:printf("\nCurrent Time:\n");
inreg.h.ah=0x2c;
int86(0x21,&inreg,&outreg);
printf("%d:%d:%d.%d ",outreg.h.ch,outreg.h.cl,outreg.h.dh,outreg.h.dl);
if(tflag==1)
goto END;
SETDATE:printf("\nSet Date.\nDay,Month and Year\n");
scanf("%d%d%d",&day,&month,&year);
inreg.h.ah=0x2b;
inreg.x.cx=year;
inreg.h.dh=month;
inreg.h.dl=day;
int86(0x21,&inreg,&outreg);
if(outreg.h.al==0x00)
{
dflag=1;
goto DISDATE;
}
else
{
printf("\nInvalid entry");
getch();
exit(0);
}
SETTIME:printf("\nSet Time. Enter Time.\nHour,Minutes and Seconds\n");
scanf("%d%d%d",&hr,&min,&sec);
inreg.h.ah=0x2d;
inreg.h.ch=hr;
inreg.h.dh=sec;
inreg.h.cl=min;
inreg.h.dl=0;
int86(0x21,&inreg,&outreg);
if(outreg.h.al==0x00)
{
tflag=1;
goto DISTIME;
}
else
{
printf("\nInvalid entry");
getch();
exit(0);
}
END: getch();
}

C Program To Implement Circular Linked List

C Program to implement circular linked list.

c program to implement circular linked list c or c++ program source code for linked list implementation with example



#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>

struct node
{
int info;
struct node *link;
}*last;
void create_list(int num);
void addatbeg(int num);
void addafter(int num,int pos);
void del(int num);
void display();
void main()
{
int choice,n,m,po,i;
last=NULL;
while(1)
{
printf("1.Create List\n");
printf("2.Add at begining\n");
printf("3.Add after \n");
printf("4.Delete\n");

printf("5.Display\n");
printf("6.Quit\n");
printf("Enter your choice : ");
scanf("%d",&choice);

switch(choice)
{
case 1: printf("How many nodes you want : ");
scanf("%d",&n);
for(i=0; i < n;i++)
{
printf("Enter the element : ");
scanf("%d",&m);
create_list(m);
}
break;
case 2: printf("Enter the element : ");
scanf("%d",&m);
addatbeg(m);
break;
case 3: printf("Enter the element : ");
scanf("%d",&m);
printf("nter the position after which this element is inserted: ");
scanf("%d",&po);
addafter(m,po);
break;
case 4: if(last == NULL)
{
printf("List underflow\n");
continue;
}
printf("Enter the number for deletion : ");
scanf("%d",&m);
del(m);
break;
case 5: display();
break;
case 6: exit(0);
default:printf("Wrong choice\n");
}
}
}
void create_list(int num)
{
struct node *temp;
temp=(node*)malloc(sizeof(struct node));
temp->info = num;
if(last == NULL)
{
last = temp;
temp->link = last;
}
else
{
temp->link = last->link;
last->link = temp;
last = temp;
}
}

void addatbeg(int num)
{
struct node *temp;
temp =(node*)malloc(sizeof(struct node));
temp->info = num;
temp->link = last->link;
last->link = temp;
}
void addafter(int num,int pos)
{
struct node
*temp,*q;
int i;
q = last->link;
for(i=0;i<pos-1;i++)
{
q = q->link;
if(q==last->link)
{
printf("There are less than %d elements\n",pos);
return;
}
}
temp =(node*)malloc(sizeof(struct node) );
temp->link = q->link;
temp->info = num;
q->link = temp;
if(q==last) //Element inserted at the end
last=temp;
}//End of addafter()

void del(int num)
{
struct node *temp,*q;
if( last->link == last && last->info == num) //Only one element
{
temp=last;
last = NULL;
free(temp);
return;
}
q = last->link;
if(q->info == num)
{
temp = q;
last->link = q->link;
free(temp);
return;
}
while(q->link !=last)
{
if(q->link->info==num) //Element deleted in between
{
temp = q->link;
q->link = temp->link;
free(temp);
printf("%d deleted\n",num);
return;
}
q = q->link;
}
if(q->link->info==num) //Last element deleted q->link=last
{
temp = q->link;
q->link = last->link;
free(temp);
last = q;
return;
}
printf("Element %d not found\n",num);
}

void display()
{
struct node *q;
if(last == NULL)
{
printf("List is empty\n");
return;
}
q = last->link;
printf("List is :\n");
while(q != last)
{
printf("%d ", q->info);
q = q->link;
}
printf("%d\n",last->info);
}

C Program For Insertion And Deletion In Heap

C program code for Insertion and Deletion in a Heap.

#include <stdio.h>
#include<stdlib.h>
int arr[100],n;
void display();
void insert(int num,int loc);
void del(int num);

void main()
{
int choice,num;
n=0; //number of nodes in the heap
while(1) //loop for menu
{
printf("1.Insert\n");
printf("2.Delete\n");
printf("3.Display\n");
printf("4.Quit\n");
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the number to be inserted : ");
scanf("%d",&num);
insert(num,n);
n=n+1;
break;
case 2:
printf("Enter the number to be deleted : ");
scanf("%d",&num);
del(num);
break;
case 3:
display();
break;
case 4:
exit(0);
default: printf("Wrong choice\n");
}
}
}

void display()
{
int i;
if(n==0)
{
printf("Heap is empty\n");
return;
}
for(i=0;i<n;i++)
printf("%d ",arr[i]);
printf("\n");
}

void insert(int num,int loc)
{
int par;
while(loc>0)
{
par=(loc-1)/2;
if(num<=arr[par])
{
arr[loc]=num;
return;
}
arr[loc]=arr[par];
loc=par;
}
arr[0]=num; //assign num to the root node
}

void del(int num)
{
int left,right,i,temp,par;
for(i=0;i<n;i++)
{
if(num==arr[i])
break;
}
if(num!=arr[i])
{
printf("%d not found in heap\n",num);
return;
}
arr[i]=arr[n-1];
n=n-1;
par=(i-1)/2; //find parent of node i
if(arr[i] > arr[par])
{
insert( arr[i],i);
return;
}
left=2*i+1; //left child of i
right=2*i+2; // right child of i
while(right < n)
{
if(arr[i]>=arr[left] && arr[i]>=arr[right])
return;
if(arr[right]<=arr[left])
{
temp=arr[i];
arr[i]=arr[left];
arr[left]=temp;
i=left;
}
else
{
temp=arr[i];
arr[i]=arr[right];
arr[right]=temp;
i=right;
}
left=2*i+1;
right=2*i+2;
}
if( left==n-1 && arr[i]<arr[left] ) /* right==n */
{
temp=arr[i];
arr[i]=arr[left];
arr[left]=temp;
}
}

C Program To Represent Directed or Undirected Graph Using Adjacency Matrix

C program to represent directed or undirected graph using Adjacency matrix.

#include<stdio.h>
#include<conio.h>
#define max 20
int adj[max][max]; //Adjacency matrix
int n; //Denotes number of nodes in the graph
void main()
{

int max_edges,i,j,origin,destin;
char graph_type;
printf("Enter number of nodes : ");
scanf("%d",&n);
printf("Enter type of graph, directed or undirected.\n");
printf("Enter d for directed and u for undirected:\n ");
fflush(stdin);
scanf("%c",&graph_type);
if(graph_type=='u')
max_edges=n*(n-1)/2;
else
max_edges=n*(n-1);
for(i=1;i<=max_edges;i++)
{
printf("Enter edge %d( 0 0 to quit ) : ",i);
scanf("%d %d",&origin,&destin);
if( (origin==0) && (destin==0) )
break;
if( origin > n || destin > n || origin<=0 || destin<=0)
{
printf("Invalid edge!\n");
i--;
}
else
{
adj[origin][destin]=1;
if( graph_type=='u')
adj[destin][origin]=1;
}
}



printf("The adjacency matrix is :\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%4d",adj[i][j]);
printf("\n");
}
getch();
}