Misplaced Pages

DOS API: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Browse history interactively← Previous editNext edit →Content deleted Content addedVisualWikitext
Revision as of 15:05, 22 June 2012 editAsmpgmr (talk | contribs)920 edits remove incorrect sentence about EMS in DOS 4.0; EMS is a separate spec and not part of the DOS API← Previous edit Revision as of 15:32, 22 June 2012 edit undoAsmpgmr (talk | contribs)920 edits add list of DOS interrupt vectors; add official MS-DOS Programmer's ReferenceNext 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.


]s along with the ] (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. ]s along with the ] (DPMI) extend the DOS API to either 16-bit or 32-bit protected mode.


==The MS-DOS API and Windows== ==The MS-DOS API and Windows==
Line 10: Line 10:


] and the systems based on it (e.g. ] and ]) are not based on MS-DOS, but use a ], ], to handle the DOS API. NTVDM works by running a DOS program in ] (an emulation of ] within ] available on ] and higher processors). ] for ] uses a similar approach. ] and the systems based on it (e.g. ] and ]) are not based on MS-DOS, but use a ], ], to handle the DOS API. NTVDM works by running a DOS program in ] (an emulation of ] within ] available on ] and higher processors). ] for ] uses a similar approach.

==Interrupt vectors used by DOS==
{| class="wikitable" border="1"
|-
!Interrupt vector
!Description
!Version
|-
|{{Code|20h}}
|Terminate program
|1.0+
|-
|{{Code|21h}}
|Main DOS API
|1.0+
|-
|{{Code|22h}}
|Program terminate address
|1.0+
|-
|{{Code|23h}}
|Control-C handler address
|1.0+
|-
|{{Code|24h}}
|Critical error handler address
|1.0+
|-
|{{Code|25h}}
|Absolute disk read
|1.0+
|-
|{{Code|26h}}
|Absolute disk write
|1.0+
|-
|{{Code|27h}}
|Terminate and stay resident
|1.0+
|-
|{{Code|28h}}
|Idle callout
|2.0+
|-
|{{Code|29h}}
|Fast console output
|2.0+
|-
|{{Code|2Ah}}
|Networking and critical section
|3.0+
|-
|{{Code|2Bh}}
|Unused
|
|-
|{{Code|2Ch}}
|Unused
|
|-
|{{Code|2Dh}}
|Unused
|
|-
|{{Code|2Eh}}
|Reload transient (COMMAND.COM)
|2.0+
|-
|{{Code|2Fh}}
|Multiplex
|3.0+
|}



==Common DOS services== ==Common DOS services==
Line 92: Line 165:
==References== ==References==
* *
* ''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. * ''Microsoft MS-DOS Programmer's Reference - The Official Technical Reference to MS-DOS'', Microsoft Press, 1993 ISBN 1556155468.
* *
* <!-- Poor, find better! -->
{{Reflist}} {{Reflist}}



Revision as of 15:32, 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.

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 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.

Interrupt vectors used by DOS

Interrupt vector Description Version
20h Terminate program 1.0+
21h Main DOS API 1.0+
22h Program terminate address 1.0+
23h Control-C handler address 1.0+
24h Critical error handler address 1.0+
25h Absolute disk read 1.0+
26h Absolute disk write 1.0+
27h Terminate and stay resident 1.0+
28h Idle callout 2.0+
29h Fast console output 2.0+
2Ah Networking and critical section 3.0+
2Bh Unused
2Ch Unused
2Dh Unused
2Eh Reload transient (COMMAND.COM) 2.0+
2Fh Multiplex 3.0+


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

Programs with support for the MS-DOS API

See also

References

  1. "Int 21/AH=00h". 090912 ctyme.com
  2. "Int 21/AH=01h". 090912 ctyme.com
  3. "Int 21/AH=02h". 090912 ctyme.com
  4. "Int 21/AH=09h". 090912 ctyme.com
  5. "Int 21/AH=3Ch, Creat". 090911 ctyme.com
  6. "Int 21/AH=3Dh, Open". 090911 ctyme.com
  7. "Int 21/AH=3Eh, Close". 090911 ctyme.com
  8. "Int 21/AH=3Fh, Read". 090911 ctyme.com
  9. "Int 21/AH=40h, Write". 090911 ctyme.com
  10. "Int 21/AH=42h, Lseek". 090911 ctyme.com
Categories: