Abstract: This article mainly introduces another important topic of advanced application of C language: realization of disk induction technology. As HD-COPY software is the same, when you insert the floppy drive into the drive, it will help you perform the appropriate action without having to choose the function again. How is this implementation? How do you know if you insert a floppy disk in the drive? These are the contents discussed herein.
Keywords: int 08H, int 1ch, int 13h, interrupt call, disk induction technology
Many excellent software, such as HD-COPY, have a disk induction function, that is, when the software runs, the floppy drive will keep flashing to detect if the floppy is loaded into the drive, if this time the user is inserted into the drive, the program The response will be performed. So can we implement disk induction technology in our own software? The answer is affirmative, many technical literature is implemented in assembly language, where we don't discuss, we only analyze how to implement this with C language.
Basic design ideas are as follows: When the program is executed, the status of the floppy drive is constantly read, if the return labeled "drive is not empty", that is, the status value is not 80h (see the appendix in the above), execute a predefined good Functions, otherwise continue to get the status of the disk drive.
To get the status of the disk drive, you can use the INT 13H interrupt 04H function provided by the BIOS, which is used to perform disk sector detection (Verify Disk Septor). INT 13H Subfunction 04h input parameters and output parameters are as follows:
Feature number: int 13h
Sub function: AH = 04h
Input parameters
AH = 04h, Al = sector number, CH = track number, CL = sector number
DH = magnetic head number, DL = driver code (0 = a drive, ...)
Output parameters
Success: cflag = 0, AH = 0
Failure: cflag = ffh, AH = error code (reference to appendix above)
At this point, our design idea can be described as: repeatedly calling the 04H function of INT 13H to detect the status of 0 0-head 1 sectors of the floppy disk, if the return value of the AH is not 80h, the loop is running out to perform the corresponding function and operation. In order to provide the software of the software to provide a changing time interval, we can add an empty loop before each calling 04H, to achieve the delay. Below is a program that implements disk induction functions with C language, where important places have been annotated for readers.
#include
#include
Int VerifyDrive ()
{
Union regs regs; / * Define register variables * /
Regs.h.ah = 0x04; / * Define the function of 04H and set parameters * /
Regs.h.al = 1;
Regs.h.ch = 0;
Regs.h.cl = 1;
Regs.h.dh = 0;
Regs.h.dl = 0;
INT86 (0x13, & regs, & regs); / * call 13H interrupt * /
Return regs.h.ah; / * Returns the value of AH, the status of the floppy drive returns * /
}
Void myfunction () / * This function is the function you want to execute after inserting a disk, the user's own definition * /
{
/ * Todo: Add your program here * /
}
void main ()
{
Unsigned long i;
While (VerifyDrive () == 0x80)
For (i = 0; i <200000; i ); / * delay * / myfunction (); / * Call user function * /
}
After running the above program, the floppy drive is working until a floppy disk is inserted. We are the tag that the disk drive is ready to insert the disk, whether the disk is damaged is not the topic we care about, so if you insert a zero track damage floppy disk, the program can work normally.
We have initially realized the sensing technology of the disk, then there is a problem that the time used for different machine runs loop, then for the above program, if it is running on the general machine, it is provided to the user. When the disk delay is relatively long, if you run the above program on the high-end machine, the delay time provided to the user will be shorter. If the magnetic head is always in the state of reading, it is easy to damage the disk and the magnetic head when the disc is changed. Here is a relatively universal approach to solve this problem.
First briefly introduce the INT 08H and INT 1ch interrupts. INT 08H is a clock interrupt. When the computer is running, this interrupt time is generated, used to complete the refresh of the system clock. It still has a characteristic, which is called int 1ch interrupt approximately 18.2 times per second, which is completed by reading and writing to 0 channels of the 8254 system clock. For INT 1CH interruption, it only has one instruction: IRET, that is, INT 1CH interrupts do not do anything, only returns the call to the function. In this way, we only need to place a counter counter in the int 1ch interrupt in the C language, and let it add, if the value of the Counter is 18, clear the counter, that is, the value of the counter is from 0 It is approximately 1 second to get to 0 again.
We can define counters as global variables, judge its value in the main () function, if it is 17, then read the status of a floppy disk drive, in turn, our disk induction technology. Below is a program that uses C language call INT 1ch interrupt to implement disk induction technology, and important places have been annotated for readers.
#include
#include
#ifDef __cplusplus / * Judging whether the compiler is a C compiler to determine the interrupt function parameter * /
#define argument ...
#ELSE
#define argument
#ENDIF
INT Counter; / * Define global variables Counter * /
Void Install (* Funaddr) (Argument), INT Number / * Installing Interrupt Function * /
{
disable ();
SetVect (Number, Funaddr);
ENABLE ();
}
Void Interrupt New1Ch (argument) / * New INT 1CH function * /
{
Counter ; / * counter from * /
IF (counter == 18) counter = 0; / * If the value is 18, it is clear * /
}
INT VerifyDrive () / * Read Disk Status Function, in the same example * /
{
Union regs regs;
Regs.h.ah = 0x04;
Regs.h.al = 1;
Regs.h.ch = 0;
Regs.h.cl = 1;
Regs.h.dh = 0;
Regs.h.dl = 0;
INT86 (0x13, & regs, & regs);
Return regs.h.ah;
}
Void myfunction () / * This function is the function you want to perform after inserting a disk, the user's own definition * / {
/ * Todo: Add your program here * /
}
void main ()
{
Install (new1ch, 0x
1C
); / * Put new interrupt service program * /
While (1) / * program loop * /
IF (counter == 17) / * If the counter is 17, it has been proof for about 1 second * /
IF (VerifyDrive ()! = 0x80) / * If the floppy disk is inserted * /
{
MyFunction (); / * Call user function * /
Break;
}
}
The above procedures are for reference only. It is a core program that implements disk induction technology with C language. Interested readers can continue to improve the above procedures so that software they design has better stability and practicality.