Revision as of 13:06, 22 June 2012 editAnonMoos (talk | contribs)Autopatrolled, Extended confirmed users, Pending changes reviewers71,937 editsNo edit summary← Previous edit | Revision as of 15:05, 22 June 2012 edit undoAsmpgmr (talk | contribs)920 edits remove incorrect sentence about EMS in DOS 4.0; EMS is a separate spec and not part of the DOS APINext edit → | ||
Line 1: | Line 1: | ||
The '''MS-DOS API''' is an ] used originally in ]/], and later by other ]<!--disambiguate--> systems. Most calls to the DOS API invoke ] 21h (] 21h). By calling INT 21h with a subfunction number in the AH ] 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 ]. 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 (]). In MS-DOS version 3.1 (released in 1985), several subfunctions were added for dealing with networks. |
The '''MS-DOS API''' is an ] used originally in ]/], and later by other ]<!--disambiguate--> systems. Most calls to the DOS API invoke ] 21h (] 21h). By calling INT 21h with a subfunction number in the AH ] 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 ]. 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 (]). In MS-DOS version 3.1 (released in 1985), several subfunctions were added for dealing with networks. | ||
There are various implementations of the DOS API, including ], ], ], ], ], and others. The DOS API is based on the ], and DOS routines often internally access ]s. | There are various implementations of the DOS API, including ], ], ], ], ], and others. The DOS API is based on the ], and DOS routines often internally access ]s. |
Revision as of 15:05, 22 June 2012
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.
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.
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 program |
Never | |
AH = 01 | DOS 1+ Read character from STDIN |
AL=character read | |
AH = 02 | DOS 1+ Write character to STDOUT |
DL=character | |
AH = 09 | DOS 1+ Write string to STDOUT |
DS:DX=pointer to '$' terminated string | |
AH = 3C | DOS 2+ Create or truncate file |
CX=file attributes ; DS:DX->ASCIIZ filename | CF=1 on error ; AX=error code ; AX=file handle |
AH = 3D | DOS 2+ Open existing file |
AL=access and sharing modes ; DS:DX->ASCIIZ filename ; CL=attribute mask | CF=1 on error ; AX=error code ; AX=file handle |
AH = 3E | DOS 2+ Close file |
BX=file handle | CF=1 on error ; AX=error code |
AH = 3F | DOS 2+ Read from file or device |
BX=file handle ; CX=bytes to read ; DS:DX->data | CF=1 on error ; AX=error code or bytes read |
AH = 40 | DOS 2+ Write to file or device |
BX=file handle ; CX=bytes to write ; DS:DX->data | CF=1 on error ; AX=error code or bytes written |
AH = 42 | DOS 2+ Set file position |
AL=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 |
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 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". 090912 ctyme.com
- "Int 21/AH=01h". 090912 ctyme.com
- "Int 21/AH=02h". 090912 ctyme.com
- "Int 21/AH=09h". 090912 ctyme.com
- "Int 21/AH=3Ch, Creat". 090911 ctyme.com
- "Int 21/AH=3Dh, Open". 090911 ctyme.com
- "Int 21/AH=3Eh, Close". 090911 ctyme.com
- "Int 21/AH=3Fh, Read". 090911 ctyme.com
- "Int 21/AH=40h, Write". 090911 ctyme.com
- "Int 21/AH=42h, Lseek". 090911 ctyme.com