- MS-DOS API
-
The MS-DOS API is an API used originally in MS-DOS/PC-DOS, and later by other DOS systems. Most calls to the DOS API invoke software interrupt 21h (INT 21h). By calling INT 21h with a subfunction number in the AH processor register and other parameters in other registers, one invokes various DOS services. DOS services include keyboard input, video output, disk file access, executing programs, memory allocation, and various other things. The subfunctions provided in the first release of MS-DOS in 1981 were strongly oriented to compatibility with CP/M. A major revamp of the DOS API (partially influenced by certain Unix concepts) was undertaken for the release of MS-DOS 2.0 in 1983, adding numerous new subfunctions to deal with file I/O using abstract "handles" and support for subdirectories. In these new subfunctions, strings are usually terminated by a NUL byte (ASCIIZ). In MS-DOS version 3.1 (released in 1985), several subfunctions were added for dealing with networks. In MS-DOS version 4, calls were introduced to manage expanded memory according to the Lotus-Intel-Microsoft specification.
There are various implementations of the DOS API, including PC-DOS, MS-DOS, DR-DOS, FreeDOS, PTS-DOS, and others. The DOS API is based on the BIOS, and DOS routines often internally access BIOS interrupt calls.
DOS extenders along with the DOS Protected Mode Interface (DPMI) extend the DOS API to either 16-bit or 32-bit protected mode. The MS-DOS API is partially dependent on x86 code, hence DOS cannot be ported to other processor architectures.
Contents
The MS-DOS API and Windows
Microsoft Windows versions 1.0 through 3.1 were graphical shells that ran on MS-DOS and relied on the MS-DOS API (though using its own API for Windows programs). Windows 9x was also DOS-based, but used a custom version of MS-DOS, mainly as a bootloader. It did not use the MS-DOS API much after booting. However, Windows 9x provided the DOS API to programs running within a command shell window. Earlier Windows 9x versions (at least through the first edition of Windows 98) also can be booted into plain CLI "DOS mode" with no GUI and no Windows system services, for running pure DOS programs. The Windows 9x DOS versions (numbered 7.0 and above) include several new service subfunctions for dealing with long filenames (LFNs).
Windows NT and the systems based on it (e.g. Windows XP and Windows Vista) are not based on MS-DOS, but use a virtual machine, NTVDM, to handle the DOS API. NTVDM works by running a DOS program in virtual 8086 mode (an emulation of real mode within protected mode available on 80386 and higher processors). DOSEMU for Linux uses a similar approach.
Common DOS services
Some basic INT 21h function calls present since DOS version 2.0:
Subfunction
(hex)Service Parameters Returns AH = 00 DOS 1+
Terminate programNever [1] AH = 01 DOS 1+
Read character from STDINAL=character read [2] AH = 02 DOS 1+
Write character to STDOUTDL=character [3] AH = 09 DOS 1+
Write string to STDOUTDS:DX=pointer to '$' terminated string [4] AH = 3C DOS 2+
Create or truncate fileCX=file attributes ; DS:DX->ASCIIZ filename CF=1 on error ; AX=error code ; AX=file handle [5] AH = 3D DOS 2+
Open existing fileAL=access and sharing modes ; DS:DX->ASCIIZ ; CL=attribute mask CF=1 on error ; AX=error code ; AX=file handle [6] AH = 3F DOS 2+
Read from file or deviceBX=file handle ; CX=bytes to read ; DS:DX->data CF=1 on error ; AX=error code or bytes read [7] AH = 40 DOS 2+
Write to file or deviceBX=file handle ; CX=bytes to write ; DS:DX->data CF=1 on error ; AX=error code or bytes written [8] AH = 3E DOS 2+
Close fileBX=file handle CF=1 on error ; AX=error code [9] AH = 42 DOS 2+
Set file positionAL=origin of move, 0-start, 1-current, 2-end ; BX=file handle ; CX:DX=(signed) offset CF=1 on error ; AX=error code ; DX:AX=position from beginning [10] Operating systems with support for the MS-DOS API
- MS-DOS - Most widespread incarnation
- PC-DOS - IBM version
- DR-DOS - Digital Research clone
- ROM-DOS - Read only memory version
- FreeDOS - Free, open source
- Microsoft Windows - 1.x, 2.x, 3.x, and 9x were based on DOS
Programs with support for the MS-DOS API
- NTVDM.EXE for Windows NT
- DOSEMU for Linux
- DOSBox
See also
- BIOS interrupt call
- Ralf Brown's Interrupt List
- Comparison of x86 DOS operating systems
- DOS/4GW
- DOS MZ executable
References
- wustl.edu - Description of MS-DOS services
- The New Peter Norton Programmer's Guide to the IBM PC & PS/2 by Peter Norton and Richard Wilton, Microsoft Press, 1987 ISBN 1-55615-131-4.
- ctyme.com - INT Calls by function
- antionline.com - Programming example code
- ^ "Int 21/AH=00h". http://www.ctyme.com/intr/rb-2551.htm. 090912 ctyme.com
- ^ "Int 21/AH=01h". http://www.ctyme.com/intr/rb-2552.htm. 090912 ctyme.com
- ^ "Int 21/AH=02h". http://www.ctyme.com/intr/rb-2554.htm. 090912 ctyme.com
- ^ "Int 21/AH=09h". http://www.ctyme.com/intr/rb-2562.htm. 090912 ctyme.com
- ^ "Int 21/AH=3Ch, Creat". http://www.ctyme.com/intr/rb-2778.htm. 090911 ctyme.com
- ^ "Int 21/AH=3Dh, Open". http://www.ctyme.com/intr/rb-2779.htm. 090911 ctyme.com
- ^ "Int 21/AH=3Fh, Read". http://www.ctyme.com/intr/rb-2783.htm. 090911 ctyme.com
- ^ "Int 21/AH=40h, Write". http://www.ctyme.com/intr/rb-2791.htm. 090911 ctyme.com
- ^ "Int 21/AH=3Eh, Close". http://www.ctyme.com/intr/rb-2782.htm. 090911 ctyme.com
- ^ "Int 21/AH=42h, Lseek". http://www.ctyme.com/intr/rb-2799.htm. 090911 ctyme.com
Categories:- DOS technology
- Operating system APIs
- X86 architecture
- Interrupts
Wikimedia Foundation. 2010.