The functions intdos and intdosx execute DOS interrupt 0x21 to invoke a specified DOS function. The value of inregs->h.ah specifies the DOS function to be invoked. The function intdosx also copies the segregs ->ds and segregs ->es values into the corresponding registers before invoking the DOS function and then restores DS.
This feature of the functions allows the programs that use far pointers or a large data memory model specify which segment is to be used for the function execution. With intdosx function you can invoke a DOS function that takes a value of DS different from the default data segment and/or takes an argument in ES.
Both the functions return the value of AX after completion of the DOS function call and if the carry flag is set (outregs -> x.cflag != 0), it indicates that an error occurred.
After the interrupt 0x21 returns the functions copy the current register values to outregs, status of the carry flag to the x.cflag field in outregs and value of the 8086 flags register to the x.flags field in outregs. Both inregs and outregs can point to the same structure. Let us see the examples of these functions.
The example of the use of intdos function has been given below. This program obtains the selected information about the floppy (1.44Mb, 3½ inch floppy disk) disk drive. This program provides the allocation information of a floppy disk.
/* The get drive allocation information for disk usage */
#include <dos.h> /* for intdos() and union REGS */
#include <stdio.h> /* for printf() */
union REGS inregs, outregs;
void main()
{
inregs.h.ah = 0x36; /* get disk free space
function number */
inregs.h.dl = 0x01; /* drive A: */
intdos(&inregs, &outregs);
printf("%d sectors/cluster,\n%d clusters,\n%d bytes/sector,
\n%d total clusters",
outregs.x.ax,outregs.x.bx,
outregs.x.cx, outregs.x.dx);
getch();
}
And output of the program will be like this:
1 sectors/cluster,
1933 clusters,
512 bytes/sector,
2843 total clusters |
|