Microsoft KB Archive/62205

How to Get Current Drive in DOS or OS/2 Real Mode

PSS ID Number: Q62205 Article last modified on 06-07-1990

3.00 3.00a MS-DOS

Summary: Microsoft COBOL versions 3.00 and 3.00a can call a DOS interrupt to get the current drive. These versions of COBOL can call interrupts with the special subprogram X“84”. The DOS interrupt is 21Hex, function 19Hex and returns the current drive. This article gives an explanation and an example of how to call this interrupt from Microsoft COBOL versions 3.00 and 3.00a. This information applies to Microsoft COBOL Compiler versions 3.00 and 3.00a for MS-DOS.

More Information: Before calling the interrupt, the AH register (the upper byte of the AX register) must be set to 19Hex. The interrupt returns the number of the current drive in AL (the lower byte of the AX register). The drive numbers correspond to the letters of the alphabet (for example, 0 = A, 1 = B, etc.). For more information about calling interrupts from COBOL 3.00 and 3.00a, see Pages 8-4 and 8-5 of the “Microsoft COBOL Compiler 3.0: Operating Guide” included with the product. For more information about interrupt 21Hex, function 19Hex, see Page 367 of “Advanced MS-DOS Programming, 2nd Edition,” by Ray Duncan (Microsoft Press, 1988). The sample program below (GETDRIVE.CBL) reports the current drive. To compile and link, enter the following from the DOS command prompt: cobol getdrive; link getdrive;

Code Example
DATA DIVISION. WORKING-STORAGE SECTION. 01 AX. *  Function 19H (25 decimal) 05 A-H      PIC 99   COMP-X VALUE 25. 05 A-L      PIC 99   COMP-X. * Used to convert the drive number to a drive letter 01 Drive       REDEFINES AX PIC XX. 01 BX. 05 B-H      PIC 99   COMP-X. 05 B-L      PIC 99   COMP-X. 01 CX. 05 C-H      PIC 99   COMP-X. 05 C-L      PIC 99   COMP-X. 01 DX. 05 D-H      PIC 99   COMP-X. 05 D-L      PIC 99   COMP-X. * Initialize to interrupt 21H 01 Interrupt   PIC X           VALUE X&quot;21&quot;. * Load actual registers with passed parameters 01 Flag        PIC X           VALUE X&quot;FF&quot;. PROCEDURE DIVISION. *  Call interrupt to get current drive CALL X&quot;84&quot; USING Interrupt, Flag, AX, BX, CX, DX. *  Drive number 0 = drive letter A, but A has ASCII *  65      COMPUTE A-L = A-L + 65. DISPLAY &quot;Current drive is &quot; AT 2501. *  Drive(2:1) = A-L DISPLAY Drive(2:1) AT 2518. STOP RUN. Copyright Microsoft Corporation 1990.