System programming with c and unix
In the header file dos.h there are two important
structures and union (Remember this structure)
1. struct BYTEREGS {
unsigned char al, ah, bl, bh;
unsigned char cl, ch, dl, dh;
};
2. struct WORDREGS
{
unsigned int ax,
bx, cx, dx;
unsigned int si,
di, cflag, flags;
};
3. union REGS
{
struct WORDREGS x;
struct BYTEREGS h;
};
There is function
int86() which has been defined in dos.h header file. It is general
8086 software interrupt interface. It will better to explain it by an example.
Write a c program to display mouse pointer?
Write a c program to display mouse pointer?
#include<stdio.h>
#include<dos.h>
void main()
{
union REGS i,o;
i.x.ax=1;
int86(0x33,&i,&o);
getch();
}
Explanation: To write such program interrupt table is necessary.
Mouse interrupt Table |
It is a small part of interrupt table. It has four field input, output, service number and purpose,
now see the first line which is inside the rectangle. To display the mouse pointer assign ax equal to 1 i.e. service number while ax is define in the WORDREGS
struct WORDREGS {
unsigned int ax, bx, cx, dx;
unsigned int si,
di, cflag, flags;
};
And WORDRGS is define in
the union REGS
union REGS {
struct WORDREGS x;
struct BYTEREGS h;
};
So to access the ax
first declare a variable of REGS that is
REGS i,o;
To access the ax write i.x.ax (We are using structure variable i because ax is input, see interrupt table).
So, to display mouse pointer assign the value of service number:
i.x.ax=1;
To pass the information to microprocessor we use int86 function. It has three parameters
1. Interrupt number i.e. 0x33
2. union REGS
*inputregiste i.e. &i
3. union REGS
*outputregiste i.e. &o;
So write: int86
(0x33, &i, &o);
No comments:
Post a Comment