Search This Blog

Showing posts with label interrupt. Show all posts
Showing posts with label interrupt. Show all posts

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 Display SCAN and ASCII Codes of Keys on Keyboard Using 8086 Interrupt

output of C program source code to find scan code and ASCII code of any key pressed on keyboard asci ascii A 65 97 32 30 keyboard code using 8086 interrupt 16 0x16 16h INT16 int86 int86x
Output (ASCII and SCAN code) when a is pressed
This program displays SCAN code and ASCII code of any key pressed on the keyboard. We use inregs is made zero in the program. Then interrupt 16h is called using int86() function in dos.h. The arguments are interrupt number (in hexadecimal ; in C 0x16) pointer to input register and pointer to output register.
The interrupt stores scan code in higher byte of accumulator and ASCII code in lower byte of accumulator.

8086 interrupt number 16h (hexadecimal) to read a keystroke from keyboard. The condition for this interrupt is that the higher byte of accumulator (AH) should be 00h.

#include<stdio.h>
#include<dos.h>
#include<conio.h>
void main()
{
union REGS inregs,outregs; //declaring 2 register files
clrscr();
inregs.h.ah=0x0; //pre-requisite for desired operation of interrupt 16h
int86(0x16,&inregs,&outregs); //calling interrupt 16h
printf("\nScan Code :%d\nASCII code:%d\n",outregs.h.ah,outregs.h.al);
getch();
}