Hi,
Very good tutorial, and it is helpful for me to understand how the interrupt service routine works.
I have a question: How can I test these code? Should I use DOS , win98, or XP?
Thank you very much.
Eric Huang
| |
|
Welcome to AstaHost - Dear Guest | |
Posted 10 March 2011 - 07:34 AM
Hi,
Very good tutorial, and it is helpful for me to understand how the interrupt service routine works.
I have a question: How can I test these code? Should I use DOS , win98, or XP?
Thank you very much.
Eric Huang
Posted 15 March 2010 - 08:48 AM
Posted 15 December 2009 - 06:43 AM
#include<stdio.H>
#include<conio.H>
int main (void)
{
unsigned port =0;
int value;
value = output(port, 'c') ;
printf( "value %c sent to port number %dand",value,port);
return 0;
}
-reply by kingsley
Posted 11 March 2008 - 05:41 AM
Posted 03 March 2008 - 05:54 PM
Posted 16 April 2006 - 09:01 AM
Posted 16 April 2006 - 08:42 AM
A) int* (*ptr)() b[b][/b]) int* (*ptr)(int*,char) c)int *[](*ptr)(int *[],char *)[/color]Back to writing ISR s
[color=green]#include<dos.h>
#include<conio.h>
char far *scr=(char far*) 0xb8000000l; // Address of VDU for //monochrome displays use 0xb0000000l
void interrupt our(); // define an ISR our
void interrupt (*prev)(); //define a pointer to the location in IVT
void main()
{
prev=getvect(9); // Save previous value in IVT in the pointer
setvect(9,our); // Set IVT to our ISR
getch(); // u know that!
}
void interrupt our()
{
int i=0;
for (i=0;i<4000;i++)
{
if(i%2==0)
{
if(i>127)
scr[i]=i-127;
else
scr[i]=i;
}
else
scr[i]=i%16; //(I think only 16 colors are present in text mode)
}
(*prev)(); // necessary unless u know everything this interrupt does.
}[/color]The above program creates an ISR for the keyboard interrupt( number 9). When we are inside an ISR we can’t generate another interrupt since we can handle only 1 interrupt at 1 time. Therefore we have written directly to the VDU in the our ISR. Since there are 80 cols and 25 rows => (80 X 25 =2000) memory locations. Each row/col entry comprises of a 2 byte value( that's why looping 4000 times). The even byte (1st byte) gives the value present at that location while the odd byte (2nd byte) gives its color and other attributes such as blinking, intensity etc. [color=green]
#include<dos.h>
#include<stdio.h>
#include<conio.h>
struct INTERRUPT
{
unsigned bp,di,si,ds,es,dx,cx,bx,ax,ip,cs,fl;
};
struct INTERRUPT r1;
void interrupt (*prev)();
void interrupt myfunc(struct INTERRUPT r)
{
r1=r;
/*int i=0;
cout<<"HELLO WORLD";
i=i*5;
cout<<"iis="<<i;
*/
//cout<<"\nHELLO WORLD ONCE AGAIN";
(*prev)();
}
void main()
{
/*cout<<"\nAddress of myfunc="<< (void*)(myfunc)<<"\n";
cout<<"\nAddress of myfunc2="<< (void*)(myfunc2)<<"\n";
*/
int i=20;
clrscr();
prev=getvect(9);
setvect(9,myfunc);
//myfunc();
while(i>0)
{
printf("VALUES OF R1 ARE\n");
printf("\nbp=%x,di=%x,si=%x,ds=%x,es=%x,dx=%x,cx=%x,bx=%x,ax,ip=%x,cs=%x,fl=%x",
r1.bp,r1.di,r1.si,r1.ds,r1.es,r1.dx,r1.cx,r1.bx,r1.ax,r1.ip,r1.cs,r1.fl);
getch();
i--;
}
}[/color]
[color=green]#include<dos.h>
#include<conio.h>
#include<stdio.h>
char far *scr=(char far*)0xB8000000l;
struct INTERRUPT
{
unsigned bp,di,si,ds,es,dx,cx,bx,ax,ip,cs,fl;
};
struct INTERRUPT r1;
char contents[49][80];
int counter=0,busy=0;
// unsigned ip,fl,c;
void interrupt (*prev)();
void printToMemory(char *msg,int row,int col)
{
int i=0,j=0,status=0,k=0;
for(k=0;k<strlen(msg);k++)
{
if(row>49)
{
row=49;
//col=0;
for(i=0;i<49;i++)
{
for(j=0;j<80;j++)
contents[i][j]=scr[160*(i+1)+2*j];
}
status=1;
}
if(col>79)
{
if(row<49)
row++;
col=0;
}
if(status==1)
{
for(i=0;i<49;i++)
{
for(j=0;j<80;j++)
scr[160*i+2*j]=contents[i][j];
}
}
// else col++;
scr[160*row+2*col]=msg[k];
col++;
}
}
void printToMemory2(char *msg,int *row,int col)
{
int i=0;
if(*row>49)
*row=8;
for(i=0;i<strlen(msg);i++)
{
scr[160*(*row)+2*col]=msg[i];
col++;
}
}
void interrupt our(struct INTERRUPT r)
{
static int i=8;
char str[20],str2[20];
if(counter==18 && busy==0)
{
busy=1;
counter=0;
itoa(r.ip,str,16);
itoa(r.cs,str2,16);//WHY NEGATIVE VALUES IN CS?? DECLARED IT AS UNSIGNED!!
strcat(str2,":");
strcat(str2,str);
r1=r;
//r1.ip=atoi(str); //Should hold value OF IP that's in str
printToMemory(str2,i,8);
//printToMemory2(str2,&i,8);
i++;
busy=0;
}
else
{
counter++;
if(counter>18)
counter=0;
}
(*prev)();
}
void main()
{
int i=0;
prev=getvect(8);
setvect(8,our);
clrscr();
for(i=0;i<30000;i++);
printf("THE OUTPUT YOU SEE IS IN THE FORM CS:IP(or CODE_SEGMENT:PROGRAM COUNTER)");
printf("\n TO CHANGE THE OUTPUT FROM DECIMAL TYPE 16 in PLACE OF 10 in itoa()");
printf("\n Don't USE printf inside the ISR our.SINCE printf also uses an INTERRUPT");
//cout<<"AX="<<r1.ax<<"\nBX="<<r1.bx<<"\nCX="<<r1.cx<<"\nDX="<<r1.dx;
printf("\nCS=%x \nDS=%d \nIP=%x",r1.cs,r1.ds,r1.ip);
getch();
}[/color]That’s all for now try some programs by getting info on various interrupts. Note that all are not defined by the BIOS and are user defined interrupts like interrupt 0x21 this is defined by DOS not the bios. However you can use it and any other up until 255 (0-255 total interrupts).
Community Forum Software by IP.Board
Licensed to: Xisto Corporation

