PCjs Advanced MS-DOS Programming
PCjs Advanced MS-DOS Programming
Directory of C:\PCJS.ORG\PUBS\PC\REFERENCE\MICROSOFT\MSPL13\MSDOS\ADVDOS
════════════════════════════════════════════════════════════════════════════
By Ray Duncan
════════════════════════════════════════════════════════════════════════════
PUBLISHED BY
Microsoft Press
A Division of Microsoft Corporation
16011 NE 36th Way, Box 97017, Redmond, Washington 98073-9717
Copyright (C) 1986, 1988 by Ray Duncan
Published 1986. Second edition 1988.
All rights reserved. No part of the contents of this book may be
reproduced or transmitted in any form or by any means without the written
permission of the publisher.
Library of Congress Cataloging in Publication Data
ISBN 1-55615-157-8
Printed and bound in the United States of America.
1 2 3 4 5 6 7 8 9 FGFG 3 2 1 0 9 8
Distributed to the book trade in the United States by Harper & Row.
──────────────────────────────────────────────────────────────────────────
Technical Editor: Mike Halvorson Production Editor: Mary Ann Jones
──────────────────────────────────────────────────────────────────────────
Dedication
For Carolyn
────────────────────────────────────────────────────────────────────────────
Contents
Acknowledgments
Introduction
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 2/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Chapter 15 Filters
Index
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 3/813
10/16/2018 PCjs: Advanced MS-DOS Programming
C Compiler switches
Linker switches
MAKE switches
Video attributes
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 4/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Acknowledgments
────────────────────────────────────────────────────────────────────────────
Introduction
This book is both a tutorial and a reference and is divided into four
sections, so that you can find information more easily. Section 1
discusses MS-DOS capabilities and services by functional group in the
context of common programming issues, such as user input, control of the
display, memory management, and file handling. Special classes of
programs, such as interrupt handlers, device drivers, and filters, have
their own chapters.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 5/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Sections 3 and 4 are references to IBM ROM BIOS, Microsoft Mouse driver,
and Lotus/Intel/Microsoft Expanded Memory Specification functions. The
entries in these two sections have the same form as in Section 2, except
that individual programming examples have been omitted.
The programs in this book were written with the marvelous Brief editor
from Solution Systems and assembled or compiled with Microsoft Macro
Assembler version 5.1 and Microsoft C Compiler version 5.1. They have been
tested under MS-DOS versions 2.1, 3.1, 3.3, and 4.0 on an 8088-based IBM
PC, an 80286-based IBM PC/AT, and an 80386-based IBM PS/2 Model 80. As far
as I am aware, they do not contain any software or hardware dependencies
that will prevent them from running properly on any IBM PC─compatible
machine running MS-DOS version 2.0 or later.
Readers who are familiar with the first edition will find many changes in
the second edition, but the general structure of the book remains the
same. Most of the material comparing MS-DOS to CP/M and UNIX/XENIX has
been removed; although these comparisons were helpful a few years ago,
MS-DOS has become its own universe and deserves to be considered on its
own terms.
A road map to vital figures and tables has been added, following the Table
of Contents, to help you quickly locate the layouts of the program segment
prefix, file control block, and the like.
The reference sections at the back of the book have been extensively
updated and enlarged and are now complete through MS-DOS version 4.0, the
IBM PS/2 Model 80 ROM BIOS and the VGA video adapter, the Microsoft Mouse
driver version 6.0, and the Lotus/Intel/Microsoft Expanded Memory
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 6/813
10/16/2018 PCjs: Advanced MS-DOS Programming
In the two years since Advanced MS-DOS Programming was first published,
hundreds of readers have been kind enough to send me their comments, and I
have tried to incorporate many of their suggestions in this new edition.
As before, please feel free to contact me via MCI Mail (user name LMI),
CompuServe (user ID 72406,1577), or BIX (user name rduncan).
────────────────────────────────────────────────────────────────────────────
SECTION 1 PROGRAMMING FOR MS-DOS
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Chapter 1 Genealogy of MS-DOS
In only seven years, MS-DOS has evolved from a simple program loader into
a sophisticated, stable operating system for personal computers that are
based on the Intel 8086 family of microprocessors (Figure 1-1). MS-DOS
supports networking, graphical user interfaces, and storage devices of
every description; it serves as the platform for thousands of application
programs; and it has over 10 million licensed users──dwarfing the combined
user bases of all of its competitors.
The progenitor of MS-DOS was an operating system called 86-DOS, which was
written by Tim Paterson for Seattle Computer Products in mid-1980. At that
time, Digital Research's CP/M-80 was the operating system most commonly
used on microcomputers based on the Intel 8080 and Zilog Z-80
microprocessors, and a wide range of application software (word
processors, database managers, and so forth) was available for use with
CP/M-80.
To ease the process of porting 8-bit CP/M-80 applications into the new
16-bit environment, 86-DOS was originally designed to mimic CP/M-80 in
both available functions and style of operation. Consequently, the
structures of 86-DOS's file control blocks, program segment prefixes, and
executable files were nearly identical to those of CP/M-80. Existing
CP/M-80 programs could be converted mechanically (by processing their
source-code files through a special translator program) and, after
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 7/813
10/16/2018 PCjs: Advanced MS-DOS Programming
conversion, would run under 86-DOS either immediately or with very little
hand editing.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 8/813
10/16/2018 PCjs: Advanced MS-DOS Programming
MS-DOS version 2.0 (equivalent to PC-DOS 2.0) was first released in March
1983. It was, in retrospect, a new operating system (though great care was
taken to maintain compatibility with MS-DOS version 1). It contained many
significant innovations and enhanced features, including those listed on
the following page.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 9/813
10/16/2018 PCjs: Advanced MS-DOS Programming
MS-DOS version 2.25, released in October 1985, was distributed in the Far
East but was never shipped by OEMs in the United States and Europe. In
this version, the international support for Japanese and Korean character
sets was extended even further, additional bugs were repaired, and many of
the system utilities were made compatible with MS-DOS version 3.0.
MS-DOS version 3.0 was introduced by IBM in August 1984 with the release
of the 80286-based PC/AT machines. It represented another major rewrite of
the entire operating system and included the important new features listed
on the following page.
MS-DOS version 3.1, which was released in November 1984, added support for
the sharing of files and printers across a network. Beginning with version
3.1, a new operating-system module called the redirector intercepts an
application program's requests for I/O and filters out the requests that
are directed to network devices, passing these requests to another machine
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 10/813
10/16/2018 PCjs: Advanced MS-DOS Programming
for processing.
Since version 3.1, the changes to MS-DOS have been evolutionary rather
than revolutionary. Version 3.2, which appeared in 1986, generalized the
definition of device drivers so that new media types (such as 3.5-inch
floppy disks) could be supported more easily. Version 3.3 was released in
1987, concurrently with the new IBM line of PS/2 personal computers, and
drastically expanded MS-DOS's multilanguage support for keyboard mappings,
printer character sets, and display fonts. Version 4.0, delivered in 1988,
was enhanced with a visual shell as well as support for very large file
systems.
While MS-DOS has been evolving, Microsoft has also put intense efforts
into the areas of user interfaces and multitasking operating systems.
Microsoft Windows, first shipped in 1985, provides a multitasking,
graphical user "desktop" for MS-DOS systems. Windows has won widespread
support among developers of complex graphics applications such as desktop
publishing and computer-aided design because it allows their programs to
take full advantage of whatever output devices are available without
introducing any hardware dependence.
┌─────────────┐
│ MS-DOS 1.0 │ 1981: First operating system on IBM PC
│ PC-DOS 1.0 │
└──────┬──────┘
│
┌──────▼──────┐
│ MS-DOS 1.25 │ Double-sided disk support and bug fixes added:
│ PC-DOS 1.1 │ widely distributed by OEMs other than IBM
└──────┬──────┘
│
┌──────▼──────┐ 1983: Introduced with IBM PC/XT;
│ MS-DOS 2.0 │ support for UNIX/XENIX-like hierarchical
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 11/813
10/16/2018 PCjs: Advanced MS-DOS Programming
What does the future hold for MS-DOS? Only the long-range planning teams
at Microsoft and IBM know for sure. But it seems safe to assume that
MS-DOS, with its relatively small memory requirements, adaptability to
diverse hardware configurations, and enormous base of users, will remain
important to programmers and software publishers for years to come.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 12/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Chapter 2 MS-DOS in Operation
It is unlikely that you will ever be called upon to configure the MS-DOS
software for a new model of computer. Still, an acquaintance with the
general structure of MS-DOS can often be very helpful in understanding the
behavior of the system as a whole. In this chapter, we will discuss how
MS-DOS is organized and how it is loaded into memory when the computer is
turned on.
MS-DOS is partitioned into several layers that serve to isolate the kernel
logic of the operating system, and the user's perception of the system,
from the hardware it is running on. These layers are
The MS-DOS kernel communicates with these device drivers through I/O
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 13/813
10/16/2018 PCjs: Advanced MS-DOS Programming
request packets; the drivers then translate these requests into the proper
commands for the various hardware controllers. In many MS-DOS systems,
including the IBM PC, the most primitive parts of the hardware drivers are
located in read-only memory (ROM) so that they can be used by stand-alone
applications, diagnostics, and the system startup program.
The terms resident and installable are used to distinguish between the
drivers built into the BIOS and the drivers installed during system
initialization by DEVICE commands in the CONFIG.SYS file. (Installable
drivers will be discussed in more detail later in this chapter and in
Chapter 14.)
■ Memory management
■ Character-device input/output
The DOS kernel is read into memory during system initialization from the
MSDOS.SYS file on the boot disk. (The file is called IBMDOS.COM in
PC-DOS.) This file is marked with the attributes hidden and system.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 14/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The default shell that is provided with MS-DOS is found in a file called
COMMAND.COM. Although COMMAND.COM prompts and responses constitute the
ordinary user's complete perception of MS-DOS, it is important to realize
that COMMAND.COM is not the operating system, but simply a special class
of program running under the control of MS-DOS.
■ A resident portion
■ An initialization section
■ A transient module
The resident portion is loaded in lower memory, above the DOS kernel and
its buffers and tables. It contains the routines to process Ctrl-C and
Ctrl-Break, critical errors, and the termination (final exit) of other
transient programs. This part of COMMAND.COM issues error messages and is
responsible for the familiar prompt
The resident portion also contains the code required to reload the
transient portion of COMMAND.COM when necessary.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 15/813
10/16/2018 PCjs: Advanced MS-DOS Programming
programs. The transient module issues the user prompt, reads the commands
from the keyboard or batch file, and causes them to be executed. When an
application program terminates, the resident portion of COMMAND.COM does a
checksum of the transient module to determine whether it has been
destroyed and fetches a fresh copy from the disk if necessary.
The user commands that are accepted by COMMAND.COM fall into three
categories:
■ Internal commands
■ External commands
■ Batch files
Batch files are text files that contain lists of other intrinsic,
extrinsic, or batch commands. These files are processed by a special
interpreter that is built into the transient portion of COMMAND.COM. The
interpreter reads the batch file one line at a time and carries out each
of the specified operations in order.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 16/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If a .COM file or a .EXE file is found, COMMAND.COM uses the MS-DOS EXEC
function to load and execute it. The EXEC function builds a special data
structure called a program segment prefix (PSP) above the resident portion
of COMMAND.COM in the transient program area. The PSP contains various
linkages and pointers needed by the application program. Next, the EXEC
function loads the program itself, just above the PSP, and performs any
relocation that may be necessary. Finally, it sets up the registers
appropriately and transfers control to the entry point for the program.
(Both the PSP and the EXEC function will be discussed in more detail in
Chapters 3 and 12.) When the transient program has finished its job, it
calls a special MS-DOS termination function that releases the transient
program's memory and returns control to the program that caused the
transient program to be loaded (COMMAND.COM, in this case).
The ROM bootstrap routine reads the disk bootstrap routine from the first
sector of the system startup disk (the boot sector) into memory at some
arbitrary address and then transfers control to it (Figure 2-2). (The
boot sector also contains a table of information about the disk format.)
The disk bootstrap routine checks to see if the disk contains a copy of
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 17/813
10/16/2018 PCjs: Advanced MS-DOS Programming
MS-DOS. It does this by reading the first sector of the root directory and
determining whether the first two files are IO.SYS and MSDOS.SYS (or
IBMBIO.COM and IBMDOS.COM), in that order. If these files are not present,
the user is prompted to change disks and strike any key to try again.
┌───────────────────────────────────────────────┐
│ ROM bootstrap routine │
├───────────────────────────────────────────────┤
│ │
├───────────────────────────────────────────────┤ ◄ Top of RAM
│ │
│ │
└──────────────────────┐ │
┌────────────────────┐ └────────────────────────┘
│ └──────────────────────────┐
│ │
│ │
│ │
00400H ├───────────────────────────────────────────────┤
│ Interrupt vectors │
00000H └───────────────────────────────────────────────┘
┌───────────────────────────────────────────────┐
│ ROM bootstrap routine │
├───────────────────────────────────────────────┤
│ │
├───────────────────────────────────────────────┤ ◄ Top of RAM
│ │
├───────────────────────────────────────────────┤
│ Disk bootstrap routine │
├───────────────────────────────────────────────┤ ◄ Arbitrary
│ │ load location
│ │
└──────────────────────┐ │
┌────────────────────┐ └────────────────────────┘
│ └──────────────────────────┐
│ │
│ │
00400H ├───────────────────────────────────────────────┤
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 18/813
10/16/2018 PCjs: Advanced MS-DOS Programming
│ Interrupt vectors │
00000H └───────────────────────────────────────────────┘
Figure 2-2. The ROM bootstrap routine loads the disk bootstrap routine
into memory from the first sector of the system startup disk and then
transfers control to it.
If the two system files are found, the disk bootstrap reads them into
memory and transfers control to the initial entry point of IO.SYS (Figure
2-3). (In some implementations, the disk bootstrap reads only IO.SYS into
memory, and IO.SYS in turn loads the MSDOS.SYS file.)
The IO.SYS file that is loaded from the disk actually consists of two
separate modules. The first is the BIOS, which contains the linked set of
resident device drivers for the console, auxiliary port, printer, block,
and clock devices, plus some hardware-specific initialization code that is
run only at system startup. The second module, SYSINIT, is supplied by
Microsoft and linked into the IO.SYS file, along with the BIOS, by the
computer manufacturer.
Next, SYSINIT calls the initialization code in MSDOS.SYS. The DOS kernel
initializes its internal tables and work areas, sets up the interrupt
vectors 20H through 2FH, and traces through the linked list of resident
device drivers, calling the initialization function for each. (See Chapter
14.)
┌───────────────────────────────────────────────┐
│ ROM bootstrap routine │
├───────────────────────────────────────────────┤
│ │
├───────────────────────────────────────────────┤ ◄ Top of RAM
│ │
├───────────────────────────────────────────────┤
│ Disk bootstrap routine │
├───────────────────────────────────────────────┤
│ │
└──────────────────────┐ │
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 19/813
10/16/2018 PCjs: Advanced MS-DOS Programming
┌────────────────────┐ └────────────────────────┘
│ └──────────────────────────┐
│ │
├───────────────────────────────────────────────┤
│ DOS kernel (from MSDOS.SYS) │
├───────────────────────────────────────────────┤ ◄ In temporary
│ SYSINIT (from IO.SYS) │ location
├───────────────────────────────────────────────┤
│ BIOS (from IO.SYS) │
├───────────────────────────────────────────────┤
│ │
00400H ├───────────────────────────────────────────────┤
│ Interrupt vectors │
00000H └───────────────────────────────────────────────┘
Figure 2-3. The disk bootstrap reads the file IO.SYS into memory. This
file contains the MS-DOS BIOS (resident device drivers) and the SYSINIT
module. Either the disk bootstrap or the BIOS (depending upon the
manufacturer's implementation) then reads the DOS kernel into memory from
the MSDOS.SYS file.
When the DOS kernel has been initialized and all resident device drivers
are available, SYSINIT can call on the normal MS-DOS file services to open
the CONFIG.SYS file. This optional file can contain a variety of commands
that enable the user to customize the MS-DOS environment. For instance,
the user can specify additional hardware device drivers, the number of
disk buffers, the maximum number of files that can be open at one time,
and the filename of the command processor (shell).
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 20/813
10/16/2018 PCjs: Advanced MS-DOS Programming
┌───────────────────────────────────────────────┐
│ ROM bootstrap routine │
├───────────────────────────────────────────────┤
│ │
├───────────────────────────────────────────────┤ ◄ Top of RAM
│ SYSINIT module │
├───────────────────────────────────────────────┤
│ │
└──────────────────────┐ │
┌────────────────────┐ └────────────────────────┘
│ └──────────────────────────┐
│ │
├───────────────────────────────────────────────┤
│ Installable drivers │
├───────────────────────────────────────────────┤
│ File control blocks │
├───────────────────────────────────────────────┤
│ Disk buffer cache │
├───────────────────────────────────────────────┤
│ DOS kernel │
├───────────────────────────────────────────────┤ ◄ In final
│ BIOS │ location
├───────────────────────────────────────────────┤
│ │
├───────────────────────────────────────────────┤
00400H ├───────────────────────────────────────────────┤
│ Interrupt vectors │
00000H └───────────────────────────────────────────────┘
Figure 2-4. SYSINIT moves itself to high memory and relocates the DOS
kernel, MSDOS.SYS, downward to its final address. The MS-DOS disk buffer
cache and file control block areas are allocated, and then the installable
device drivers specified in the CONFIG.SYS file are loaded and linked into
the system.
After all installable device drivers have been loaded, SYSINIT closes all
file handles and reopens the console (CON), printer (PRN), and auxiliary
(AUX) devices as the standard input, standard output, standard error,
standard list, and standard auxiliary devices. This allows a
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 21/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Finally, SYSINIT calls the MS-DOS EXEC function to load the command
interpreter, or shell. (The default shell is COMMAND.COM, but another
shell can be substituted by means of the CONFIG.SYS file.) Once the shell
is loaded, it displays a prompt and waits for the user to enter a command.
MS-DOS is now ready for business, and the SYSINIT module is discarded
(Figure 2-5).
┌───────────────────────────────────────────────┐
│ ROM bootstrap routine │
├───────────────────────────────────────────────┤
│ │
├───────────────────────────────────────────────┤ ◄ Top of RAM
│ Transient part of COMMAND.COM │
├───────────────────────────────────────────────┤
└──────────────────────┐ │
┌────────────────────┐ └────────────────────────┘
│ └──────────────────────────┐
│ Transient program area │
├───────────────────────────────────────────────┤
│ Resident part of COMMAND.COM │
├───────────────────────────────────────────────┤
│ Installable drivers │
├───────────────────────────────────────────────┤
│ File control blocks │
├───────────────────────────────────────────────┤
│ Disk buffer cache │
├───────────────────────────────────────────────┤
│ DOS kernel │
├───────────────────────────────────────────────┤
│ BIOS │
├───────────────────────────────────────────────┤
│ │
00400H ├───────────────────────────────────────────────┤
│ Interrupt vectors │
00000H └───────────────────────────────────────────────┘
Figure 2-5. The final result of the MS-DOS startup process for a typical
system. The resident portion of COMMAND.COM lies in low memory, above the
DOS kernel. The transient portion containing the batch-file interpreter
and intrinsic commands is placed in high memory, where it can be overlaid
by extrinsic commands and application programs running in the transient
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 22/813
10/16/2018 PCjs: Advanced MS-DOS Programming
program area.
────────────────────────────────────────────────────────────────────────────
Chapter 3 Structure of MS-DOS Application Programs
Programs that run under MS-DOS come in two basic flavors: .COM programs,
which have a maximum size of approximately 64 KB, and .EXE programs, which
can be as large as available memory. In Intel 8086 parlance, .COM programs
fit the tiny model, in which all segment registers contain the same value;
that is, the code and data are mixed together. In contrast, .EXE programs
fit the small, medium, or large model, in which the segment registers
contain different values; that is, the code, data, and stack reside in
separate segments. .EXE programs can have multiple code and data segments,
which are respectively addressed by long calls and by manipulation of the
data segment (DS) register.
Both .COM and .EXE programs are brought into memory for execution by the
same mechanism: the EXEC function, which constitutes the MS-DOS loader.
EXEC can be called with the filename of a program to be loaded by
COMMAND.COM (the normal MS-DOS command interpreter), by other shells or
user interfaces, or by another program that was previously loaded by EXEC.
If there is sufficient free memory in the transient program area, EXEC
allocates a block of memory to hold the new program, builds the program
segment prefix (PSP) at its base, and then reads the program into memory
immediately above the PSP. Finally, EXEC sets up the segment registers and
the stack and transfers control to the program.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 23/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Offset
0000H ┌────────────────────────────────────────────────────────┐
│ Int 20H │
0002H ├────────────────────────────────────────────────────────┤
│ Segment, end of allocation block │
0004H ├────────────────────────────────────────────────────────┤
│ Reserved │
0005H ├────────────────────────────────────────────────────────┤
│ Long call to MS-DOS function dispatcher │
000AH ├────────────────────────────────────────────────────────┤
│ Previous contents of termination handler │
│ interrupt vector (Int 22H) │
000EH ├────────────────────────────────────────────────────────┤
│ Previous contents of Ctrl-C interrupt vector (Int 23H) │
0012H ├────────────────────────────────────────────────────────┤
│ Previous contents of critical-error handler │
│ interrupt vector (Int 24H) │
0016H ├────────────────────────────────────────────────────────┤
│ Reserved │
002CH ├────────────────────────────────────────────────────────┤
│ Segment address of environment block │
002EH ├────────────────────────────────────────────────────────┤
│ Reserved │
005CH ├────────────────────────────────────────────────────────┤
│ Default file control block #1 │
006CH ├────────────────────────────────────────────────────────┤
│ Default file control block #2 │
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 24/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The word at offset 0002H in the PSP contains the segment address of the
top of the transient program's allocated memory block. The program can use
this value to determine whether it should request more memory to do its
job or whether it has extra memory that it can release for use by other
processes.
Offsets 000AH through 0015H in the PSP contain the previous contents of
the interrupt vectors for the termination, Ctrl-C, and critical-error
handlers. If the transient program alters these vectors for its own
purposes, MS-DOS restores the original values saved in the PSP when the
program terminates.
The word at PSP offset 002CH holds the segment address of the environment
block, which contains a series of ASCIIZ strings (sequences of ASCII
characters terminated by a null, or zero, byte). The environment block is
inherited from the program that called the EXEC function to load the
currently executing program. It contains such information as the current
search path used by COMMAND.COM to find executable programs, the location
on the disk of COMMAND.COM itself, and the format of the user prompt used
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 25/813
10/16/2018 PCjs: Advanced MS-DOS Programming
by COMMAND.COM.
The command tail──the remainder of the command line that invoked the
transient program, after the program's name──is copied into the PSP
starting at offset 0081H. The length of the command tail, not including
the return character at its end, is placed in the byte at offset 0080H.
Redirection or piping parameters and their associated filenames do not
appear in the portion of the command line (the command tail) that is
passed to the transient program, because redirection is transparent to
applications.
To provide compatibility with CP/M, MS-DOS parses the first two parameters
in the command tail into two default file control blocks (FCBs) at
PSP:005CH and PSP:006CH, under the assumption that they may be filenames.
However, if the parameters are filenames that include a path
specification, only the drive code will be valid in these default FCBs,
because FCB-type file- and record-access functions do not support
hierarchical file structures. Although the default FCBs were an aid in
earlier years, when compatibility with CP/M was more of a concern, they
are essentially useless in modern MS-DOS application programs that must
provide full path support. (File control blocks are discussed in detail in
Chapter 8 and hierarchical file structures are discussed in Chapter 9.)
The 128-byte area from 0080H through 00FFH in the PSP also serves as the
default disk transfer area (DTA), which is set by MS-DOS before passing
control to the transient program. If the program does not explicitly
change the DTA, any file read or write operations requested with the FCB
group of function calls automatically use this area as a data buffer. This
is rarely useful and is another facet of MS-DOS's handling of the PSP that
is present only for compatibility with CP/M.
──────────────────────────────────────────────────────────────────────────
WARNING
Programs must not alter any part of the PSP below offset 005CH.
──────────────────────────────────────────────────────────────────────────
Programs of the .COM persuasion are stored in disk files that hold an
absolute image of the machine instructions to be executed. Because the
files contain no relocation information, they are more compact, and are
loaded for execution slightly faster, than equivalent .EXE files. Note
that MS-DOS does not attempt to ascertain whether a .COM file actually
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 26/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Because .COM programs are loaded immediately above the program segment
prefix and do not have a header that can specify another entry point, they
must always have an origin of 0100H, which is the length of the PSP.
Location 0100H must contain an executable instruction. The maximum length
of a .COM program is 65,536 bytes, minus the length of the PSP (256 bytes)
and a mandatory word of stack (2 bytes).
When control is transferred to the .COM program from MS-DOS, all of the
segment registers point to the PSP (Figure 3-2). The stack pointer
register contains 0FFFEH if memory allows; otherwise, it is set as high as
possible in memory minus 2 bytes. (MS-DOS pushes a zero word on the stack
before entry.)
SS:SP ┌────────────────────────────────────────────────────────┐
│ │
│ Stack grows downward from top of segment │
│ │ │
│ ▼ │
│ │
│ │ │
│ Program code and data │
│ │
CS:0100H ├────────────────────────────────────────────────────────┤
│ Program segment prefix │
CS:0000H └────────────────────────────────────────────────────────┘
DS:0000H
ES:0000H
SS:0000H
Although the size of an executable .COM file can't exceed 64 KB, the
current versions of MS-DOS allocate all of the transient program area to
.COM programs when they are loaded. Because many such programs date from
the early days of MS-DOS and are not necessarily "well-behaved" in their
approach to memory management, the operating system simply makes the
worst-case assumption and gives .COM programs everything that is
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 27/813
10/16/2018 PCjs: Advanced MS-DOS Programming
When linking a .COM program, the linker will display the message
This message can be ignored. The linker output is a .EXE file, which must
be converted into a .COM file with the MS-DOS EXE2BIN utility before
execution. You can then delete the .EXE file. (An example of this process
is provided in Chapter 4.)
The NAME statement simply provides a module name for use during the
linkage process. This aids understanding of the map that the linker
produces. In MASM versions 5.0 and later, the module name is always the
same as the filename, and the NAME statement is ignored.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 28/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The PAGE command, when used with two operands, as in line 2, defines the
length and width of the page. These default respectively to 66 lines and
80 characters. If you use the PAGE command without any operands, a
formfeed is sent to the printer and a heading is printed. In larger
programs, use the PAGE command liberally to place each of your subroutines
on separate pages for easy reading.
──────────────────────────────────────────────────────────────────────────
1: name hello
2: page 55,132
3: title HELLO.COM--print hello on terminal
4:
5: ;
6: ; HELLO.COM: demonstrates various components
7: ; of a functional .COM-type assembly-
8: ; language program, and an MS-DOS
9: ; function call.
10: ;
11: ; Ray Duncan, May 1988
12: ;
13:
14: stdin equ 0 ; standard input handle
15: stdout equ 1 ; standard output handle
16: stderr equ 2 ; standard error handle
17:
18: cr equ 0dh ; ASCII carriage return
19: lf equ 0ah ; ASCII linefeed
20:
21:
22: _TEXT segment word public 'CODE'
23:
24: org 100h ; .COM files always have
25: ; an origin of 100h
26:
27: assume cs:_TEXT,ds:_TEXT,es:_TEXT,ss:_TEXT
28:
29: print proc near ; entry point from MS-DOS
30:
31: mov ah,40h ; function 40h = write
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 29/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Because this program is going to be converted into a .COM file, all of its
executable code and data areas must lie within one code segment. The
program must also have its origin at offset 0100H (immediately above the
program segment prefix), which is taken care of by the ORG statement
in line 24.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 30/813
10/16/2018 PCjs: Advanced MS-DOS Programming
overrides when they are necessary. It's important to notice that the
ASSUME statement doesn't take care of loading the segment registers with
the proper values; it merely notifies the assembler of your intent to do
that within the program. (Remember that, in the case of a .COM program,
MS-DOS initializes all the segment registers before entry to point to the
PSP.)
Within the code segment, we come to another type of block declaration that
begins with the PROC command on line 29 and closes with ENDP on line 40.
These two instructions declare the beginning and end of a procedure, a
block of executable code that performs a single distinct function. The
label in the leftmost field of the PROC statement (in this case, print)
gives the procedure a name. The operand field gives it an attribute. If
the procedure carries the NEAR attribute, only other code in the same
segment can call it, whereas if it carries the FAR attribute, code located
anywhere in the CPU's memory-addressing space can call it. In .COM
programs, all procedures carry the NEAR attribute.
For the purposes of this example program, I have kept the print procedure
ridiculously simple. It calls MS-DOS Int 21H Function 40H to send the
message Hello World! to the video screen, and calls Int 21H Function 4CH
to terminate the program.
The END statement in line 51 tells the assembler that it has reached the
end of the source file and also specifies the entry point for the program.
If the entry point is not a label located at offset 0100H, the .EXE file
resulting from the assembly and linkage of this source program cannot be
converted into a .COM file.
We have just discussed a program that was written in such a way that it
could be assembled into a .COM file. Such a program is simple in
structure, so a programmer who needs to put together this kind of quick
utility can concentrate on the program logic and do a minimum amount of
worrying about control of the assembler. However, .COM-type programs have
some definite disadvantages, and so most serious assembly-language efforts
for MS-DOS are written to be converted into .EXE files.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 31/813
10/16/2018 PCjs: Advanced MS-DOS Programming
parts of the file. Although the normal MS-DOS program loader does not take
advantage of this feature of .EXE files, the ability to load different
parts of large programs into several separate memory fragments, as well as
the opportunity to designate a "pure" code portion of your program that
can be shared by several tasks, is very significant in multitasking
environments such as Microsoft Windows.
The MS-DOS loader always brings a .EXE program into memory immediately
above the program segment prefix, although the order of the code, data,
and stack segments may vary (Figure 3-4). The .EXE file has a header, or
block of control information, with a characteristic format (Figures 3-5
and 3-6). The size of this header varies according to the number of
program instructions that need to be relocated at load time, but it is
always a multiple of 512 bytes.
Before MS-DOS transfers control to the program, the initial values of the
code segment (CS) register and instruction pointer (IP) register are
calculated from the entry-point information in the .EXE file header and
the program's load address. This information derives from an END statement
in the source code for one of the program's modules. The data segment (DS)
and extra segment (ES) registers are made to point to the PSP so that the
program can access the environment-block pointer, command tail, and other
useful information contained there.
SS:SP ┌────────────────────────────────────────────────────────┐
│ │
│ Stack segment: │
│ stack grows downward from top of segment │
│ │ │
│ ▼ │
SS:0000H ├────────────────────────────────────────────────────────┤
│ Data segment │
├────────────────────────────────────────────────────────┤
│ Program code │
CS:0000H ├────────────────────────────────────────────────────────┤
│ Program segment prefix │
DS:0000H └────────────────────────────────────────────────────────┘
ES:0000H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 32/813
10/16/2018 PCjs: Advanced MS-DOS Programming
statement in the main module of the program. When the program receives
control, the DS (data segment) and ES (extra segment) registers point to
the program segment prefix; the program usually saves this value and then
resets the DS and ES registers to point to its data area.
The initial contents of the stack segment (SS) and stack pointer (SP)
registers come from the header. This information derives from the
declaration of a segment with the attribute STACK somewhere in the
program's source code. The memory space allocated for the stack may be
initialized or uninitialized, depending on the stack-segment definition;
many programmers like to initialize the stack memory with a recognizable
data pattern so that they can inspect memory dumps and determine how much
stack space is actually used by the program.
Byte
offset
0000H ┌────────────────────────────────────────────────────────┐
│ First of .EXE file signature (4DH) │
0001H ├────────────────────────────────────────────────────────┤
│ Second part of .EXE file signature (5AH) │
0002H ├────────────────────────────────────────────────────────┤
│ Length of file MOD 512 │
0004H ├────────────────────────────────────────────────────────┤
│ Size of file in 512-byte pages, including header │
0006H ├────────────────────────────────────────────────────────┤
│ Number of relocation-table items │
0008H ├────────────────────────────────────────────────────────┤
│ Size of header in paragraphs (16-byte units) │
000AH ├────────────────────────────────────────────────────────┤
│ Minimum number of paragraphs needed above program │
000CH ├────────────────────────────────────────────────────────┤
│ Maximum number of paragraphs desired above program │
000EH ├────────────────────────────────────────────────────────┤
│ Segment displacement of stack module │
0010H ├────────────────────────────────────────────────────────┤
│ Contents of SP register at entry │
0012H ├────────────────────────────────────────────────────────┤
│ Word checksum │
0014H ├────────────────────────────────────────────────────────┤
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 33/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The input to the linker for a .EXE-type program can be many separate
object modules. Each module can use a unique code-segment name, and the
procedures can carry either the NEAR or the FAR attribute, depending on
naming conventions and the size of the executable code. The programmer
must take care that the modules linked together contain only one segment
with the STACK attribute and only one entry point defined with an END
assembler directive. The output from the linker is a file with a .EXE
extension. This file can be executed immediately.
──────────────────────────────────────────────────────────────────────────
C>DUMP HELLO.EXE
0 1 2 3 4 5 6 7 8 9 A B C D E F
0000 4D 5A 28 00 02 00 01 00 20 00 09 00 FF FF 03 00 MZ(..... .......
0010 80 00 20 05 00 00 00 00 1E 00 00 00 01 00 01 00 .. .............
0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
.
.
.
0200 B8 01 00 8E D8 B4 40 BB 01 00 B9 10 00 90 BA 08 ......@.........
0210 00 CD 21 B8 00 4C CD 21 0D 0A 48 65 6C 6C 6F 20 ..!..L.!..Hello
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 34/813
10/16/2018 PCjs: Advanced MS-DOS Programming
0220 57 6F 72 6C 64 21 0D 0A World!..
──────────────────────────────────────────────────────────────────────────
The NAME, TITLE, and PAGE directives were covered in the HELLO.COM example
program and are used in the same manner here, so we'll move to the first
new item of interest. After a few comments and EQU statements, we come to
a declaration of a code segment that begins on line 21 with a SEGMENT
command and ends on line 41 with an ENDS command. As in the HELLO.COM
example program, the label in the leftmost field of the line gives the
code segment the name _TEXT. The operand fields at the right end of the
line give the attributes WORD, PUBLIC, and `CODE'.
──────────────────────────────────────────────────────────────────────────
1: name hello
2: page 55,132
3: title HELLO.EXE--print Hello on terminal
4: ;
5: ; HELLO.EXE: demonstrates various components
6: ; of a functional .EXE-type assembly-
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 35/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 36/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Within the code segment, the main print procedure is declared by the PROC
command on line 25 and closed with ENDP on line 39. Because the procedure
resides in a .EXE file, we have given it the FAR attribute as an example,
but the attribute is really irrelevant because the program is so small and
the procedure is not called by anything else in the same program.
Lines 44 through 51 declare a data segment named _DATA, which contains the
variables and constants the program will use. If the various modules of a
program contain multiple data segments with the same name, the linker will
collect them and place them in the same physical memory segment.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 37/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The END statement on line 60 winds up our brief HELLO.EXE program, telling
the assembler that it has reached the end of the source file and providing
the label of the program's point of entry from MS-DOS.
The differences between .COM and .EXE programs are summarized in Figure
3-8.
╓┌─┌──────────────────┌──────────────────────────┌───────────────────────────╖
.COM program .EXE program
──────────────────────────────────────────────────────────────────────────
Maximum size 65,536 bytes minus 256 No limit
bytes for PSP and 2 bytes
for stack
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 38/813
10/16/2018 PCjs: Advanced MS-DOS Programming
whichever is lower
Exit method Int 21H Function 4CH Int 21H Function 4CH
preferred, NEAR RET if preferred
MS-DOS version 1
Figure 3-8. Summary of the differences between .COM and .EXE programs,
including their entry conditions.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 39/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Program Modules
Program Segments
As we discussed earlier in the chapter, .COM programs assume that all four
segment registers always point to the same place──the bottom of the
program. Thus, they are limited to a maximum size of 64 KB. .EXE programs,
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 40/813
10/16/2018 PCjs: Advanced MS-DOS Programming
on the other hand, can address many different physical segments and can
reset the segment registers to point to each segment as it is needed.
Consequently, the only practical limit on the size of a .EXE program is
the amount of available memory. The example programs throughout the
remainder of this book focus on .EXE programs.
Segments are declared with the SEGMENT and ENDS directives in the
following form:
The attributes of a segment include its align type (BYTE, WORD, or PARA),
combine type (PUBLIC, PRIVATE, COMMON, or STACK), and class type. The
segment attributes are used by the linker when it is combining logical
segments to create the physical segments of an executable program. Most of
the time, you can get by just fine using a small selection of attributes
in a rather stereotypical way. However, if you want to use the full range
of attributes, you might want to read the detailed explanation in the MASM
manual.
Programs are classified into one memory model or another based on the
number of their code and data segments. The most commonly used memory
model for assembly-language programs is the small model, which has one
code and one data segment, but you can also use the medium, compact, and
large models (Figure 3-9). (Two additional models exist with which we
will not be concerning ourselves further: the tiny model, which consists
of intermixed code and data in a single segment── for example, a .COM file
under MS-DOS; and the huge model, which is supported by the Microsoft C
Optimizing Compiler and which allows use of data structures larger than 64
KB.)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 41/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
Small One One
Medium Multiple One
Compact One Multiple
Large Multiple Multiple
──────────────────────────────────────────────────────────────────────────
For each memory model, Microsoft has established certain segment and class
names that are used by all its high-level-language compilers (Figure
3-10). Because segment names are arbitrary, you may as well adopt the
Microsoft conventions. Their use will make it easier for you to integrate
your assembly-language routines into programs written in languages such as
C, or to use routines from high-level-language libraries in your
assembly-language programs.
╓┌─┌───────────┌────────────┌───────────┌───────────┌────────────┌───────────╖
Memory Segment Align Combine Class Group
model name type type type
──────────────────────────────────────────────────────────────────────────
Memory Segment Align Combine Class Group
model name type type type
──────────────────────────────────────────────────────────────────────────
Small _TEXT WORD PUBLIC CODE
_DATA WORD PUBLIC DATA DGROUP
STACK PARA STACK STACK DGROUP
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 42/813
10/16/2018 PCjs: Advanced MS-DOS Programming
_DATA
STACK PARA STACK STACK DGROUP
Figure 3-10. Segments, groups, and classes for the standard memory models
as used with assembly-language programs. The Microsoft C Optimizing
Compiler and other high-level-language compilers use a superset of these
segments and classes.
For pure assembly-language programs that will run under MS-DOS, you can
ignore DGROUP. However, if you plan to integrate assembly-language
routines and programs written in high-level languages, you'll want to
follow the Microsoft DGROUP convention. For example, if you are planning
to link routines from a C library into an assembly-language program, you
should include the line
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 43/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Program Procedures
Procedures within a program are declared with the PROC and ENDP directives
in the following form:
Each program should have a main procedure that receives control from
MS-DOS. You specify the entry point for the program by including the name
of the main procedure in the END statement in one of the program's source
files. The main procedure's attribute (NEAR or FAR) is really not too
important, because the program returns control to MS-DOS with a function
call rather than a RET instruction. However, by convention, most
programmers assign the main procedure the FAR attribute anyway.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 44/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Chapter 4 MS-DOS Programming Tools
■ MAKE, which compares dates of files and carries out operations based on
the result of the comparison
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 45/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The survey in this chapter, together with the example programs and
reference section elsewhere in the book, should provide the experienced
programmer with sufficient information to immediately begin writing useful
programs. Readers who do not have a background in C, assembly language, or
the Intel 80x86 microprocessor architecture should refer to the tutorial
and reference works listed at the end of this chapter.
File Types
The MS-DOS programming tools can create and process many different file
types. The following extensions are used by convention for these files:
╓┌─┌──────────┌──────────────────────────────────────────────────────────────╖
Extension File type
Extension File type
──────────────────────────────────────────────────────────────────────────
.ASM Assembly-language source file
.C C source file
.COM MS-DOS executable load module that does not require relocation
at runtime
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 46/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 47/813
10/16/2018 PCjs: Advanced MS-DOS Programming
You can invoke MASM in two ways. If you enter the name of the assembler
alone, it prompts you for the names of each of the various input and
output files. The assembler supplies reasonable defaults for all the
responses except the source filename, as shown in the following example:
C>MASM <Enter>
0 Warning Errors
0 Severe Errors
C>
You can use a logical device name (such as PRN or COM1) at any of the MASM
prompts to send that output of the assembler to a character device rather
than a file. Note that the default for the listing and cross-reference
files is the NUL device──that is, no file is created. If you end any
response with a semicolon, MASM assumes that the remaining responses are
all to be the default.
For example, the following command lines are equivalent to the preceding
interactive session:
or
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 48/813
10/16/2018 PCjs: Advanced MS-DOS Programming
These commands use the file HELLO.ASM as the source, generate the
object-code file HELLO.OBJ, and send the listing and cross-reference files
to the bit bucket.
╓┌─┌──────────┌──────────────────────────────────────────────────────────────╖
Switch Meaning
──────────────────────────────────────────────────────────────────────────
/A Arrange segments in alphabetic order.
/Bn Set size of source-file buffer (in KB).
/C Force creation of a cross-reference (.CRF) file.
/D Produce listing on both passes (to find phase errors).
/Dsymbol Define symbol as a null text string (symbol can be referenced
by conditional assembly directives in file).
/E Assemble for 80x87 numeric coprocessor emulator using IEEE
real-number format.
/Ipath Set search path for include files.
/L Force creation of a program-listing file.
/LA Force listing of all generated code.
/ML Preserve case sensitivity in all names (uppercase names
distinct from their lowercase equivalents).
/MX Preserve lowercase in external names only (names defined with
PUBLIC or EXTRN directives).
Switch Meaning
──────────────────────────────────────────────────────────────────────────
PUBLIC or EXTRN directives).
/MU Convert all lowercase names to uppercase.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 49/813
10/16/2018 PCjs: Advanced MS-DOS Programming
MASM allows you to override the default extensions on any file──a feature
that can be rather dangerous. For example, if in the preceding example you
had responded to the Object filename prompt with HELLO.ASM, the assembler
would have accepted the entry without comment and destroyed your source
file. This is not too likely to happen in the interactive command mode,
but you must be very careful with file extensions when MASM is used in a
batch file.
Before using the C compiler and the linker, you need to set up four
environment variables:
Variable Action
──────────────────────────────────────────────────────────────────────────
PATH=path Specifies the location of the three executable C
compiler files (C1, C2, and C3) if they are not
in the current directory; used by CL.EXE.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 50/813
10/16/2018 PCjs: Advanced MS-DOS Programming
CL.EXE does not support an interactive mode or response files. You always
invoke it with a command line of the following form:
You may list any number of files──if a file has a .C extension, it will be
compiled into a relocatable-object-module (.OBJ) file. Ordinarily, if the
compiler encounters no errors, it automatically passes all resulting .OBJ
files and any additional .OBJ files specified in the command line to the
linker, along with the names of the appropriate runtime libraries.
The C compiler has many optional switches controlling its memory models,
output files, code generation, and code optimization. These are summarized
in Figure 4-2. The C compiler's arcane switch syntax is derived largely
from UNIX/XENIX, so don't expect it to make any sense.
╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
Switch Meaning
──────────────────────────────────────────────────────────────────────────
/Ax Select memory model:
C = compact model
H = huge model
L = large model
M = medium model
Switch Meaning
──────────────────────────────────────────────────────────────────────────
M = medium model
S = small model (default)
/c Compile only; do not invoke linker.
/C Do not strip comments.
/D<name>[=text] Define macro.
/E Send preprocessor output to standard output.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 51/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 52/813
10/16/2018 PCjs: Advanced MS-DOS Programming
calls
x = enable maximum optimization (equivalent to
/Oailt /Gs)
/P Send preprocessor output to file.
/Sx Select source-listing control:
l<columns> = set line width
p<lines> = set page length
s<string> = set subtitle string
t<string> = set title string
/Tc<file> Compile file without .C extension.
/u Remove all predefined macros.
Switch Meaning
──────────────────────────────────────────────────────────────────────────
/u Remove all predefined macros.
/U<name> Remove specified predefined macro.
/V<string> Set version string.
/W<n> Set warning level (0─3).
/X Ignore "standard places" for include files.
/Zx Select miscellaneous compilation control:
a = disable extensions
c = make Pascal functions case-insensitive
d = include line-number information
e = enable extensions (default)
g = generate declarations
i = include symbolic debugging information
l = remove default library info
p<n> = pack structures on n-byte boundary
s = check syntax only
──────────────────────────────────────────────────────────────────────────
The object module produced by MASM from a source file is in a form that
contains relocation information and may also contain unresolved references
to external locations or subroutines. It is written in a common format
that is also produced by the various high-level compilers (such as FORTRAN
and C) that run under MS-DOS. The computer cannot execute object modules
without further processing.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 53/813
10/16/2018 PCjs: Advanced MS-DOS Programming
C>LINK <Enter>
C>
If you are using LINK version 4.0 or later, the linker also asks for the
name of a module-definition (.DEF) file. Simply press the Enter key in
response to such a prompt. Module-definition files are used when building
Microsoft Windows or MS OS/2 "new .EXE" executable files but are not
relevant in normal MS-DOS applications.
The input file for this example was HELLO.OBJ; the output files were
HELLO.EXE (the executable program) and HELLO.MAP (the load map produced by
the linker after all references and addresses were resolved). Figure 4-3
shows the load map.
──────────────────────────────────────────────────────────────────────────
Start Stop Length Name Class
00000H 00017H 00018H _TEXT CODE
00018H 00027H 00010H _DATA DATA
00030H 000AFH 00080H STACK STACK
000B0H 000BBH 0000CH $$TYPES DEBTYP
000C0H 000D6H 00017H $$SYMBOLS DEBSYM
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 54/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 4-3. Map produced by the Microsoft Object Linker (LINK) during the
generation of the HELLO.EXE program from Chapter 3. The program contains
one CODE, one DATA, and one STACK segment. The first instruction to be
executed lies in the first byte of the CODE segment. The $$TYPES and
$$SYMBOLS segments contain information for the CodeView debugger and are
not part of the program; these segments are ignored by the normal MS-DOS
loader.
You can obtain the same result more quickly by entering all parameters in
the command line, in the following form:
or
If you enter a semicolon as the last character in the command line, LINK
assumes the default values for all further parameters.
LINK @filename
You can also enter the name of a response file at any prompt. If the
response file is not complete, LINK will prompt you for the missing
information.
When entering linker commands, you can specify multiple object files with
the + operator or with spaces, as in the following example:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 55/813
10/16/2018 PCjs: Advanced MS-DOS Programming
This command would link the files HELLO.OBJ, VMODE.OBJ, and DOSINT.OBJ,
searching the library file GRAPHICS.LIB to resolve any references to
symbols not defined in the specified object files, and would produce a
file named MYPROG.EXE. LINK uses the current drive and directory when they
are not explicitly included in a filename; it will not automatically use
the same drive and directory you specified for a previous file in the same
command line.
╓┌─┌────────┌───────────────────────────┌────────────────────────────────────╖
Switch Full form Meaning
Switch Full form Meaning
──────────────────────────────────────────────────────────────────────────
/A:n /ALIGNMENT:n Set segment sector alignment factor.
N must be a power of 2 (default =
512). Not related to logical-segment
alignment (BYTE, WORD, PARA, PAGE,
and so forth). Relevant to segmented
executable files (Microsoft Windows
and MS OS/2) only.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 56/813
10/16/2018 PCjs: Advanced MS-DOS Programming
by CodeView.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 57/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 58/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
items.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 59/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 60/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ The first location in the file must be specified as the entry point
in the source code's END directive.
Although .COM files are somewhat more compact than .EXE files, you should
avoid using them. Programs that use separate segments for code, data, and
stack are much easier to port to protected-mode environments such as MS
OS/2; in addition, .COM files do not support the symbolic debugging
information used by CodeView.
Unlike most of the other programming utilities, EXE2BIN does not have an
interactive mode. It always takes its source and destination filenames,
separated by spaces, from the MS-DOS command line, as follows:
For example, to convert the file HELLO.EXE into HELLO.COM, you would use
the following command line:
The EXE2BIN program also has other capabilities, such as pure binary
conversion with segment fixup for creating program images to be placed in
ROM; but because these features are rarely used during MS-DOS application
development, they will not be discussed here.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 61/813
10/16/2018 PCjs: Advanced MS-DOS Programming
C>CREF <Enter>
15 Symbols
C>
──────────────────────────────────────────────────────────────────────────
Microsoft Cross-Reference Version 5.10 Thu May 26 11:09:34 1988
HELLO.EXE --- print Hello on terminal
@CPU . . . . . . . . . . . . . . 1#
@VERSION . . . . . . . . . . . . 1#
CODE . . . . . . . . . . . . . . 21
CR . . . . . . . . . . . . . . . 17# 46 47
DATA . . . . . . . . . . . . . . 44
LF . . . . . . . . . . . . . . . 18# 46 47
MSG. . . . . . . . . . . . . . . 33 46#
MSG_LEN. . . . . . . . . . . . . 32 49#
PRINT. . . . . . . . . . . . . . 25# 39 60
STACK. . . . . . . . . . . . . . 23 54# 54 58
STDERR . . . . . . . . . . . . . 15#
STDIN. . . . . . . . . . . . . . 13#
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 62/813
10/16/2018 PCjs: Advanced MS-DOS Programming
STDOUT . . . . . . . . . . . . . 14# 31
_DATA. . . . . . . . . . . . . . 23 27 44# 51
_TEXT. . . . . . . . . . . . . . 21# 23 41
15 Symbols
──────────────────────────────────────────────────────────────────────────
The parameters may also be entered in the command line in the following
form:
If CREF cannot find the specified .CRF file, it displays an error message.
Otherwise, it leaves the cross-reference listing in the specified file on
the disk. You can send the file to the printer with the COPY command, in
the following form:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 63/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The LIB operations are simply the names of object files, with a prefix
character that specifies the action to be taken:
Prefix Meaning
──────────────────────────────────────────────────────────────────────────
- Delete an object module from the library.
* Extract a module and place it in a separate .OBJ file.
+ Add an object module or the entire contents of another library
to the library.
──────────────────────────────────────────────────────────────────────────
You can combine command prefixes. For example, -+ replaces a module, and
*- extracts a module into a new file and then deletes it from the library.
──────────────────────────────────────────────────────────────────────────
_abort............abort _abs..............abs
_access...........access _asctime..........asctime
_atof.............atof _atoi.............atoi
_atol.............atol _bdos.............bdos
_brk..............brk _brkctl...........brkctl
_bsearch..........bsearch _calloc...........calloc
_cgets............cgets _chdir............dir
_chmod............chmod _chsize...........chsize
.
.
.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 64/813
10/16/2018 PCjs: Advanced MS-DOS Programming
When you invoke LIB with its name alone, it requests the other information
it needs interactively, as shown in the following example:
C>LIB <Enter>
C>
In this example, LIB added the object module VIDEO.OBJ to the library
SLIBC.LIB, wrote a library table of contents into the file SLIBC.LST, and
named the resulting new library SLIBC2.LIB.
The Library Manager can also be run with a command line of the following
form:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 65/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Like LINK, LIB can also accept its commands from a response file. The
contents of the file are lines of text that correspond exactly to the
responses you would give LIB interactively. You specify the name of the
response file in the command line with a leading @ character, as follows:
LIB @filename
The MAKE utility (MAKE.EXE) compares dates of files and carries out
commands based on the result of that comparison. Because of this single,
rather basic capability, MAKE can be used to maintain complex programs
built from many modules. The dates of source, object, and executable files
are simply compared in a logical sequence; the assembler, compiler,
linker, and other programming tools are invoked as appropriate.
The MAKE utility processes a plain ASCII text file called, as you might
expect, a make file. You start the utility with a command-line entry in
the following form:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 66/813
10/16/2018 PCjs: Advanced MS-DOS Programming
By convention, a make file has the same name as the executable file that
is being maintained, but without an extension. The available MAKE switches
are listed in Figure 4-7.
command
command
If the date and time of any source file are later than those of the target
file, the accompanying list of commands is carried out. You may use
comment lines, which begin with a # character, freely in a make file. MAKE
can also process inference rules and macro definitions. For further
details on these advanced capabilities, see the Microsoft or IBM
documentation.
Switch Meaning
──────────────────────────────────────────────────────────────────────────
/D Display last modification date of each file as it is processed.
/I Ignore exit (return) codes returned by commands and programs
executed as a result of dependency statements.
/N Display commands that would be executed as a result of
dependency statements but do not execute those commands.
/S Do not display commands as they are executed.
/X Direct error messages from MAKE, or any program that MAKE runs,
<filename> to the specified file. If filename is a hyphen (-), direct
error messages to the standard output.
──────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 67/813
10/16/2018 PCjs: Advanced MS-DOS Programming
A Complete Example
Let's put together everything we've learned about using the MS-DOS
programming tools so far. Figure 4-8 shows a sketch of the overall
process of building an executable program.
Assume that we have the source code for the HELLO.EXE program from Chapter
3 in the file HELLO.ASM. To assemble the source program into the
relocatable object module HELLO.OBJ with symbolic debugging information
included, also producing a program listing in the file HELLO.LST and a
cross-reference data file HELLO.CRF, we would enter
┌───────────────┐ ┌───────────────┐
│ MASM │ │ C or other │
│ source-code │ │ HLL source- │
│ file │ │ code file │
└───┬───────────┘ └───┬───────────┘
│ ┌─────────────────────┘ Compiler
┌───▼───────▼───┐
│ Relocatable │
│ object-module ├────┐
│ file (.OBJ) │ │
└───┬───────────┘ │
│ LIB │
┌───▼───────────┐ │ ┌───────────────┐
│ Object-module │ ▼ LINK │ Executable │
│ libraries ├─────────────► program │
│ (.LIB) │ │ (.EXE) │
└───────────────┘ │ └───┬───────────┘
│ │ EXE2BIN
┌───────────────┐ │ ┌───▼───────────┐
│ HLL │ │ │ Executable │
│ runtime ├──────┘ │ program │
│ libraries │ │ (.COM) │
└───────────────┘ └───────────────┘
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 68/813
10/16/2018 PCjs: Advanced MS-DOS Programming
To convert the relocatable object file HELLO.OBJ into the executable file
HELLO.EXE, creating a load map in the file HELLO.MAP and appending
symbolic debugging information to the executable file, we would enter
hello.obj : hello.asm
masm /C /L /Zi /T hello;
cref hello,hello
hello.exe : hello.obj
link /MAP /CODEVIEW hello;
Then, when we have made some change to HELLO.ASM and want to rebuild the
executable HELLO.EXE file, we need only enter
MASM Tutorials
Assembly Language Primer for the IBM PC and XT, by Robert Lafore. New
American Library, New York, NY, 1984. ISBN 0-452-25711-5.
C Tutorials
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 69/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Microsoft C Programming for the IBM, by Robert Lafore. Howard K. Sams &
Co., Indianapolis, IN, 1987. ISBN 0-672-22515-8.
The IBM Personal Computer from the Inside Out (Revised Edition), by Murray
Sargent and Richard L. Shoemaker. Addison-Wesley Publishing Company,
Reading, MA, 1986. ISBN 0-201-06918-0.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 70/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Chapter 5 Keyboard and Mouse Input
The fundamental means of user input under MS-DOS is the keyboard. This
follows naturally from the MS-DOS command-line interface, whose lineage
can be traced directly to minicomputer operating systems with Teletype
consoles. During the first few years of MS-DOS's existence, when
8088/8086-based machines were the norm, nearly every popular application
program used key-driven menus and text-mode displays.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 71/813
10/16/2018 PCjs: Advanced MS-DOS Programming
These handles can be used for read and write operations without further
preliminaries. A program can also obtain a handle for a character device
by explicitly opening the device for input or output using its logical
name (as though it were a file). The handle functions support I/O
redirection, allowing a program to take its input from another device or
file instead of the keyboard, for example. Redirection is discussed in
detail in Chapter 15.
Use of the IBM ROM BIOS keyboard functions presupposes that the program is
running on an IBM PC─compatible machine. The ROM BIOS keyboard driver
operates at a much more primitive level than the MS-DOS functions and
allows a program to circumvent I/O redirection or MS-DOS's special
handling of certain control characters. Programs that use the ROM BIOS
keyboard driver are inherently less portable than those that use the
MS-DOS functions and may interfere with the proper operation of other
programs; many of the popular terminate-and-stay-resident (TSR) utilities
fall into this category.
The principal MS-DOS function for keyboard input using handles is Int 21H
Function 3FH (Read File or Device). The parameters for this function are
a handle, the segment and offset of a buffer, and the length of the
buffer. (For a more detailed explanation of this function, see Section
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 72/813
10/16/2018 PCjs: Advanced MS-DOS Programming
As an example, let's use the predefined standard input handle (0) and Int
21H Function 3FH to read a line from the keyboard:
──────────────────────────────────────────────────────────────────────────
buffer db 80 dup (?) ; keyboard input buffer
.
.
.
mov ah,3fh ; function 3fh = read file or device
mov bx,0 ; handle for standard input
mov cx,80 ; maximum bytes to read
mov dx,seg buffer ; DS:DX = buffer address
mov ds,dx
mov dx,offset buffer
int 21h ; transfer to MS-DOS
jc error ; jump if error detected
.
.
.
──────────────────────────────────────────────────────────────────────────
When control returns from Int 21H Function 3FH, the carry flag is clear if
the function was successful, and AX contains the number of characters
read. If there was an error, the carry flag is set and AX contains an
error code; however, this should never occur when reading the keyboard.
──────────────────────────────────────────────────────────────────────────
buffer db 80 dup (?) ; keyboard input buffer
fname db 'CON',0 ; keyboard device name
handle dw 0 ; keyboard device handle
.
.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 73/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
mov ah,3dh ; function 3dh = open
mov al,0 ; mode = read
mov dx,seg fname ; DS:DX = device name
mov ds,dx
mov dx,offset fname
int 21h ; transfer to MS-DOS
jc error ; jump if open failed
mov handle,ax ; save handle for CON
.
.
.
mov ah,3fh ; function 3fh = read file or device
mov bx,handle ; BX = handle for CON
mov cx,80 ; maximum bytes to read
mov dx,offset buffer ; DS:DX = buffer address
int 21h ; transfer to MS-DOS
jc error ; jump if error detected
.
.
.
──────────────────────────────────────────────────────────────────────────
When a programmer uses Int 21H Function 3FH to read from the keyboard, the
exact result depends on whether MS-DOS regards the handle to be in ASCII
mode or binary mode (sometimes known as cooked mode and raw mode). ASCII
mode is the default, although binary mode can be selected with Int 21H
Function 44H (IOCTL) when necessary.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 74/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The character-input functions (01H, 06H, 07H, and 08H) all return a
character in the AL register. For example, the following sequence waits
until a key is pressed and then returns it in AL:
──────────────────────────────────────────────────────────────────────────
mov ah,1 ; function 01h = read keyboard
int 21h ; transfer to MS-DOS
──────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 75/813
10/16/2018 PCjs: Advanced MS-DOS Programming
interference by using Int 21H Function 06H. Extended keys, such as the
IBM PC keyboard's special function keys, require two calls to a
character-input function.
──────────────────────────────────────────────────────────────────────────
buff db 81 ; maximum length of input
db 0 ; actual length (from MS-DOS)
db 81 dup (0) ; receives keyboard input
.
.
.
mov ah,0ah ; function 0ah = read buffered line
mov dx,seg buff ; DS:DX = buffer address
mov ds,dx
mov dx,offset buff
int 21h ; transfer to MS-DOS
.
.
.
──────────────────────────────────────────────────────────────────────────
Int 21H Function 0AH differs from Int 21H Function 3FH in several
important ways. First, the maximum length is passed in the first byte of
the buffer, rather than in the CX register. Second, the actual length is
returned in the second byte of the structure, rather than in the AX
register. Finally, when the user has entered one less than the specified
maximum number of characters, MS-DOS ignores all subsequent characters and
sounds a warning beep until the Enter key is pressed.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 76/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The first method is to call the ROM BIOS keyboard driver using Int 16H.
For example, the following sequence reads a single character from the
keyboard input buffer and returns it in the AL register:
──────────────────────────────────────────────────────────────────────────
mov ah,0 ; function 0=read keyboard
int 16h ; transfer to ROM BIOS
──────────────────────────────────────────────────────────────────────────
Int 16H Function 00H also returns the keyboard scan code in the AH
register, allowing the program to detect key codes that are not ordinarily
returned by MS-DOS. Other Int 16H services return the keyboard status
(that is, whether a character is waiting) or the keyboard shift state
(from the ROM BIOS data area 0000:0417H). For a more detailed explanation
of ROM BIOS keyboard functions, see Section III of this book, "IBM ROM
BIOS and Mouse Functions Reference."
You should consider carefully before building ROM BIOS dependence into an
application. Although this technique allows you to bypass any I/O
redirection that may be in effect, ways exist to do this without
introducing dependence on the ROM BIOS. And there are real disadvantages
to calling the ROM BIOS keyboard driver:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 77/813
10/16/2018 PCjs: Advanced MS-DOS Programming
In the discussion of keyboard input with the MS-DOS handle and traditional
functions, I made some passing references to the fact that Ctrl-C entries
can interfere with the expected behavior of those functions. Let's look at
this subject in more detail now.
During most character I/O operations, MS-DOS checks for a Ctrl-C (ASCII
code 03H) waiting at the keyboard and executes an Int 23H if one is
detected. If the system break flag is on, MS-DOS also checks for a Ctrl-C
entry during certain other operations (such as file reads and writes).
Ordinarily, the Int 23H vector points to a routine that simply terminates
the currently active process and returns control to the parent process──
usually the MS-DOS command interpreter.
──────────────────────────────────────────────────────────────────────────
push ds ; save data segment
; set int 23h vector...
mov ax,2523h ; function 25h = set interrupt
; int 23h = vector for
; Ctrl-C handler
mov dx,seg handler ; DS:DX = handler address
mov ds,dx
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 78/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The first part of the code (which alters the contents of the Int 23H
vector) would be executed in the initialization part of the application.
The handler receives control whenever MS-DOS detects a Ctrl-C at the
keyboard. (Because this handler consists only of an interrupt return, the
Ctrl-C will remain in the keyboard input stream and will be passed to the
application when it requests a character from the keyboard, appearing on
the screen as ^C.)
When an Int 23H handler is called, MS-DOS is in a stable state. Thus, the
handler can call any MS-DOS function. It can also reset the segment
registers and the stack pointer and transfer control to some other point
in the application without ever returning control to MS-DOS with an IRET.
Taking over the Int 1BH vector in an application is somewhat tricky but
extremely useful. Because the keyboard is interrupt driven, a press of
Ctrl-Break lets the application regain control under almost any
circumstance──often, even if the program has crashed or is in an endless
loop.
You cannot, in general, use the same handler for Int 1BH that you use for
Int 23H. The Int 1BH handler is more limited in what it can do, because it
has been called as a result of a hardware interrupt and MS-DOS may have
been executing a critical section of code at the time the interrupt was
serviced. Thus, all registers except CS:IP are in an unknown state; they
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 79/813
10/16/2018 PCjs: Advanced MS-DOS Programming
may have to be saved and then modified before your interrupt handler can
execute. Similarly, the depth of the stack in use when the Int 1BH handler
is called is unknown, and if the handler is to perform stack-intensive
operations, it may have to save the stack segment and the stack pointer
and switch to a new stack that is known to have sufficient depth.
Because Int 1BH is a ROM BIOS interrupt and not an MS-DOS interrupt,
MS-DOS does not restore the previous contents of the Int 1BH vector when a
program exits. If your program modifies this vector, it must save the
original value and restore it before terminating. Otherwise, the vector
will be left pointing to some random area in the next program that runs,
and the next time the user presses Ctrl-Break a system crash is the best
you can hope for.
The BREAK.ASM listing in Figure 5-1 contains source code for a Ctrl-Break
handler that can be linked with small-model Microsoft C programs running
on an IBM PC compatible. The short C program in Figure 5-2 demonstrates
use of the handler. (This code should be readily portable to other C
compilers.)
──────────────────────────────────────────────────────────────────────────
page 55,132
title Ctrl-C & Ctrl-Break Handlers
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 80/813
10/16/2018 PCjs: Advanced MS-DOS Programming
name break
;
; Ctrl-C and Ctrl-Break handler for Microsoft C
; programs running on IBM PC compatibles
;
; by Ray Duncan
;
; Assemble with: C>MASM /Mx BREAK;
;
; This module allows C programs to retain control
; when the user enters a Ctrl-Break or Ctrl-C.
; It uses Microsoft C parameter-passing conventions
; and assumes the C small memory model.
;
; The procedure _capture is called to install
; a new handler for the Ctrl-C and Ctrl-Break
; interrupts (1bh and 23h). _capture is passed
; the address of a static variable, which will be
; set to true by the handler whenever a Ctrl-C
; or Ctrl-Break is detected. The C syntax is:
;
; static int flag;
; capture(&flag);
;
; The procedure _release is called by the C program
; to restore the original Ctrl-Break and Ctrl-C
; handler. The C syntax is:
; release();
;
; The procedure ctrlbrk is the actual interrupt
; handler. It receives control when a software
; int 1bh is executed by the ROM BIOS or int 23h
; is executed by MS-DOS. It simply sets the C
; program's variable to true (1) and returns.
;
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 81/813
10/16/2018 PCjs: Advanced MS-DOS Programming
assume cs:_TEXT
public _capture
_capture proc near ; take over Ctrl-Break
; and Ctrl-C interrupt vectors
; save address of
; calling program's "flag"
mov ax,word ptr [bp+args]
mov word ptr cs:flag,ax
mov word ptr cs:flag+2,ds
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 82/813
10/16/2018 PCjs: Advanced MS-DOS Programming
_capture endp
public _release
_release proc near ; restore original Ctrl-C
; and Ctrl-Break handlers
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 83/813
10/16/2018 PCjs: Advanced MS-DOS Programming
ctrlbrk endp
_TEXT ends
end
──────────────────────────────────────────────────────────────────────────
Figure 5-1. BREAK.ASM: A Ctrl-C and Ctrl-Break interrupt handler that can
be linked with Microsoft C programs.
──────────────────────────────────────────────────────────────────────────
/*
TRYBREAK.C
#include <stdio.h>
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 84/813
10/16/2018 PCjs: Advanced MS-DOS Programming
while(1)
{
hit = kbhit(); /* check for key press */
/* (MS-DOS sees Ctrl-C
when keyboard polled) */
In the example handler, the procedure named capture is called with the
address of an integer variable within the C program. It saves the address
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 85/813
10/16/2018 PCjs: Advanced MS-DOS Programming
of the variable, points the Int 1BH and Int 23H vectors to its own
interrupt handler, and then returns.
When MS-DOS detects a Ctrl-C or Ctrl-Break, the interrupt handler sets the
integer variable within the C program to true (1) and returns. The C
program can then poll this variable at its leisure. Of course, to detect
more than one Ctrl-C, the program must reset the variable to zero again.
The procedure named release simply restores the Int 1BH and Int 23H
vectors to their original values, thereby disabling the interrupt handler.
Although it is not strictly necessary for release to do anything about Int
23H, this action does give the C program the option of restoring the
default handler for Int 23H without terminating.
Pointing Devices
╓┌─┌──────────────────┌──────────────────────────────────────────────────────╖
Function Meaning
──────────────────────────────────────────────────────────────────────────
00H Reset mouse and get status.
Function Meaning
──────────────────────────────────────────────────────────────────────────
00H Reset mouse and get status.
01H Show mouse pointer.
02H Hide mouse pointer.
03H Get button status and pointer position.
04H Set pointer position.
05H Get button-press information.
06H Get button-release information.
07H Set horizontal limits for pointer.
08H Set vertical limits for pointer.
09H Set graphics pointer type.
0AH Set text pointer type.
0BH Read mouse-motion counters.
0CH Install interrupt handler for mouse events.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 86/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Function Meaning
──────────────────────────────────────────────────────────────────────────
Although this list of mouse functions may appear intimidating, the average
application will only need a few of them.
A program first calls Int 33H Function 00H to initialize the mouse driver
for the current display mode and to check its status. At this point, the
mouse is "alive" and the application can obtain its state and position;
however, the pointer does not become visible until the process calls Int
33H Function 01H.
The program can then call Int 33H Functions 03H, 05H, and 06H to
monitor the mouse position and the status of the mouse buttons.
Alternatively, the program can register an interrupt handler for mouse
events, using Int 33H Function 0CH. This latter technique eliminates the
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 87/813
10/16/2018 PCjs: Advanced MS-DOS Programming
need to poll the mouse driver; the driver will notify the program by
calling the interrupt handler whenever the mouse is moved or a button is
pressed or released.
When the application is finished with the mouse, it can call Int 33H
Function 02H to hide the mouse pointer. If the program has registered an
interrupt handler for mouse events, it should disable further calls to the
handler by resetting the mouse driver again with Int 33H Function 00H.
──────────────────────────────────────────────────────────────────────────
/*
Simple Demo of Int 33H Mouse Driver
(C) 1988 Ray Duncan
#include <stdio.h>
#include <dos.h>
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 88/813
10/16/2018 PCjs: Advanced MS-DOS Programming
do {
regs.x.ax = 3; /* get mouse position */
int86(0x33, ®s, ®s); /* and button status */
buttons = regs.x.bx & 3;
x = regs.x.cx;
y = regs.x.dx;
gotoxy(0,0); /* display mouse position */
printf("X = %3d Y = %3d", x, y);
/*
Clear the screen
*/
void cls(void)
{
regs.x.ax = 0x0600; /* ROM BIOS video driver */
regs.h.bh = 7; /* int 10h function 06h */
regs.x.cx = 0; /* initializes a window */
regs.h.dh = 24;
regs.h.dl = 79;
int86(0x10, ®s, ®s);
}
/*
Position cursor to (x,y)
*/
void gotoxy(int x, int y)
{
regs.h.dl = x; /* ROM BIOS video driver */
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 89/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 5-3. MOUDEMO.C: A simple Microsoft C program that polls the mouse
and continually displays the coordinates of the mouse pointer in the upper
left corner of the screen. The program uses the ROM BIOS video driver,
which is discussed in Chapter 6, to clear the screen and position the
text cursor.
────────────────────────────────────────────────────────────────────────────
Chapter 6 Video Display
The following adapters are in common use as this book is being written:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 90/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ Video Graphics Array (VGA). Introduced by IBM in 1987 with the PS/2
models 50, 60, and 80, this adapter is upwardly compatible from the EGA
and supports 640-by-480, 16-color or 320-by-200, 256-color graphics on
analog RGB monitors. It also supports an MDA-compatible text mode.
■ Hercules Graphics Card, Graphics CardPlus, and InColor Cards. These are
upwardly compatible from the MDA for text display but offer graphics
capabilities that are incompatible with all of the IBM adapters.
The locations of the regen buffers for the various IBM PC─compatible
adapters are shown in Figure 6-1.
┌───────────────────────────────────────────────────────┐
│ ROM BIOS │
FE000H ├───────────────────────────────────────────────────────┤
│ System ROM, Stand-alone BASIC, etc. │
F4000H ├───────────────────────────────────────────────────────┤
│ Reserved for BIOS extensions │
│ (hard-disk controller, etc.) │
C0000H ├───────────────────────────────────────────────────────┤
│ Reserved │
BC000H ├───────────────────────────────────────────────────────┤
│ 16 KB regen buffer for CGA, EGA, MCGA, and VGA │
│ in text modes and 200-line graphics modes │
B8000H ├───────────────────────────────────────────────────────┤
│ Reserved │
B1000H ├───────────────────────────────────────────────────────┤
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 91/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Support Considerations
On IBM PC─compatible machines, the ROM BIOS contains a video driver that
programs can invoke directly, bypassing MS-DOS. The ROM BIOS functions
allow a program to write text or individual pixels to the screen or to
select display modes, video pages, palette, and foreground and background
colors. These functions are relatively efficient (compared with the MS-DOS
functions, at least), although the graphics support is primitive.
Unfortunately, the display functions of both MS-DOS and the ROM BIOS were
designed around the model of a cursor-addressable terminal and therefore
do not fully exploit the capabilities of the memory-mapped, high-bandwidth
display adapters used on IBM PC─compatible machines. As a result, nearly
every popular interactive application with full-screen displays or
graphics capability ignores both MS-DOS and the ROM BIOS and writes
directly to the video controller's registers and regen buffer.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 92/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Under MS-DOS versions 2.0 and later, the preferred method for sending text
to the display is to use handle-based Int 21H Function 40H (Write File or
Device). When an application program receives control, MS-DOS has already
assigned it handles for the standard output (1) and standard error (2)
devices, and these handles can be used immediately. For example, the
sequence at the top of the following page writes the message hello to the
display using the standard output handle.
──────────────────────────────────────────────────────────────────────────
msg db 'hello' ; message to display
msg_len equ $-msg ; length of message
.
.
.
mov ah,40h ; function 40h = write file or device
mov bx,1 ; BX = standard output handle
mov cx,msg_len ; CX = message length
mov dx,seg msg ; DS:DX = address of message
mov ds,dx
mov dx,offset msg
int 21h ; transfer to MS-DOS
jc error ; jump if error detected
.
.
.
──────────────────────────────────────────────────────────────────────────
If there is no error, the function returns the carry flag cleared and the
number of characters actually transferred in register AX. Unless a Ctrl-Z
is embedded in the text or the standard output is redirected to a disk
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 93/813
10/16/2018 PCjs: Advanced MS-DOS Programming
file and the disk is full, this number should equal the number of
characters requested.
──────────────────────────────────────────────────────────────────────────
fname db 'CON',0 ; name of CON device
handle dw 0 ; handle for CON device
msg db 'hello' ; message to display
msg_len equ $-msg ; length of message
.
.
.
mov ax,3d02h ; AH = function 3dh = open
; AL = mode = read/write
mov dx,seg fname ; DS:DX = device name
mov ds,dx
mov dx,offset fname
int 21h ; transfer to MS-DOS
jc error ; jump if open failed
mov handle,ax ; save handle for CON
.
.
.
mov ah,40h ; function 40h = write
mov cx,msg_len ; CX = message length
mov dx,seg msg ; DS:DX = address of message
mov ds,dx
mov dx,offset msg
mov bx,handle ; BX = CON device handle
int 21h ; transfer to MS-DOS
jc error ; jump if error detected
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 94/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
.
──────────────────────────────────────────────────────────────────────────
■ Int 21H Function 02H sends the character in the DL register to the
standard output device. It is sensitive to Ctrl-C interrupts, and it
handles carriage returns, linefeeds, bell codes, and backspaces
appropriately.
■ Int 21H Function 06H transfers the character in the DL register to the
standard output device, but it is not sensitive to Ctrl-C interrupts.
You must take care when using this function, because it can also be
used for input and for status requests.
■ Int 21H Function 09H sends a string to the standard output device. The
string is terminated by the $ character.
The sequence at the top of the following page sounds a warning beep by
sending an ASCII bell code (07H) to the display driver using the
traditional character-output call Int 21H Function 02H.
──────────────────────────────────────────────────────────────────────────
.
.
.
mov dl,7 ; 07h = ASCII bell code
mov ah,2 ; function 02h = display character
int 21h ; transfer to MS-DOS
.
.
.
──────────────────────────────────────────────────────────────────────────
The following sequence uses the traditional string-output call Int 21H
Function 09H to display a string:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 95/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
msg db 'hello$'
.
.
.
mov dx,seg msg ; DS:DX = message address
mov ds,dx
mov dx,offset msg
mov ah,9 ; function 09h = write string
int 21h ; transfer to MS-DOS
.
.
.
──────────────────────────────────────────────────────────────────────────
Note that MS-DOS detects the $ character as a terminator and does not
display it on the screen.
With version 2.0 or later, if MS-DOS loads the optional device driver
ANSI.SYS in response to a DEVICE directive in the CONFIG.SYS file,
programs can clear the screen, control the cursor position, and select
foreground and background colors by embedding escape sequences in the text
output. Escape sequences are so called because they begin with an escape
character (1BH), which alerts the driver to intercept and interpret the
subsequent characters in the sequence. When the ANSI driver is not loaded,
MS-DOS simply passes the escape sequence to the display like any other
text, usually resulting in a chaotic screen.
The escape sequences that can be used with the ANSI driver for screen
control are a subset of those defined in the ANSI 3.64─1979 Standard.
These standard sequences are summarized in Figure 6-2. Note that case is
significant for the last character in an escape sequence and that numbers
must always be represented as ASCII digit strings, not as their binary
values. (A separate set of escape sequences supported by ANSI.SYS, but not
compatible with the ANSI standard, may be used for reprogramming and
remapping the keyboard.)
╓┌─┌──────────────────┌──────────────────────────────────────────────────────╖
Escape sequence Meaning
──────────────────────────────────────────────────────────────────────────
Esc[2J Clear screen; place cursor in upper left corner (home
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 96/813
10/16/2018 PCjs: Advanced MS-DOS Programming
position).
Esc[K Clear from cursor to end of line.
Esc[row;colH Position cursor. (Row is the y coordinate in the range
1─25 and col is the x coordinate in the range 1─80 for
80-by-25 text display modes.) Escape sequences
terminated with the letter f instead of H have the same
effect.
Escape sequence Meaning
──────────────────────────────────────────────────────────────────────────
effect.
Esc[nA Move cursor up n rows.
Esc[nB Move cursor down n rows.
Esc[nC Move cursor right n columns.
Esc[nD Move cursor left n columns.
Esc[s Save current cursor position.
Esc[u Restore cursor to saved position.
Esc[6n Return current cursor position on the standard input
handle in the format Esc[row;colR.
Esc[nm Select character attributes:
0 = no special attributes
1 = high intensity
2 = low intensity
3 = italic
4 = underline
5 = blink
6 = rapid blink
7 = reverse video
8 = concealed text (no display)
Escape sequence Meaning
──────────────────────────────────────────────────────────────────────────
8 = concealed text (no display)
30 = foreground black
31 = foreground red
32 = foreground green
33 = foreground yellow
34 = foreground blue
35 = foreground magenta
36 = foreground cyan
37 = foreground white
40 = background black
41 = background red
42 = background green
43 = background yellow
44 = background blue
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 97/813
10/16/2018 PCjs: Advanced MS-DOS Programming
45 = background magenta
46 = background cyan
47 = background white
Esc[=nh Select display mode:
0 = 40-by-25, 16-color text (color burst off)
Escape sequence Meaning
──────────────────────────────────────────────────────────────────────────
0 = 40-by-25, 16-color text (color burst off)
1 = 40-by-25, 16-color text
2 = 80-by-25, 16-color text (color burst off)
3 = 80-by-25, 16-color text
4 = 320-by-200, 4-color graphics
5 = 320-by-200, 4-color graphics (color burst off)
6 = 620-by-200, 2-color graphics
14 = 640-by-200, 16-color graphics (EGA and VGA,
MS-DOS 4.0)
15 = 640-by-350, 2-color graphics (EGA and VGA,
MS-DOS 4.0)
16 = 640-by-350, 16-color graphics (EGA and VGA,
MS-DOS 4.0)
17 = 640-by-480, 2-color graphics (MCGA and VGA,
MS-DOS 4.0)
18 = 640-by-480, 16-color graphics (VGA, MS-DOS 4.0)
19 = 320-by-200, 256-color graphics (MCGA and VGA,
MS-DOS 4.0)
Escape sequences terminated with l instead of h have
Escape sequence Meaning
──────────────────────────────────────────────────────────────────────────
Escape sequences terminated with l instead of h have
the same effect.
Esc[=7h Enable line wrap.
Esc[=7l Disable line wrap.
──────────────────────────────────────────────────────────────────────────
Figure 6-2. The ANSI escape sequences supported by the MS-DOS ANSI.SYS
driver. Programs running under MS-DOS 2.0 or later may use these
functions, if ANSI.SYS is loaded, to control the appearance of the display
in a hardware-independent manner. The symbol Esc indicates an ASCII escape
code──a character with the value 1BH. Note that cursor positions in ANSI
escape sequences are one-based, unlike the cursor coordinates used by the
IBM ROM BIOS, which are zero-based. Numbers embedded in an escape sequence
must always be represented as a string of ASCII digits, not as their
binary values.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 98/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
; get device information...
mov bx,1 ; standard output handle
mov ax,4400h ; function 44h subfunction 00h
int 21h ; transfer to MS-DOS
Note that if a program changes the mode of any of the standard handles, it
should restore those handles to ASCII (cooked) mode before it exits.
Otherwise, subsequent application programs may behave in unexpected ways.
For more detailed information on the IOCTL function, see Section II of
this book, "MS-DOS Functions Reference."
You can somewhat improve the display performance of programs that are
intended for use only on IBM PC─compatible machines by using the ROM BIOS
video driver instead of the MS-DOS output functions. Accessed by means of
Int 10H, the ROM BIOS driver supports the following functions for all of
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 99/813
10/16/2018 PCjs: Advanced MS-DOS Programming
╓┌─┌──────────────────┌──────────────────────────────────────────────────────╖
Function Action
──────────────────────────────────────────────────────────────────────────
Display mode control
00H Set display mode.
0FH Get display mode.
Cursor control
01H Set cursor size.
02H Set cursor position.
03H Get cursor position and size.
Function Action
──────────────────────────────────────────────────────────────────────────
Graphics support
0CH Write pixel.
0DH Read pixel.
Miscellaneous
04H Read light pen.
05H Select display page.
0BH Select palette/set border color.
──────────────────────────────────────────────────────────────────────────
Additional ROM BIOS functions are available on the EGA, MCGA, VGA, and
PCjr to support the enhanced features of these adapters, such as
programmable palettes and character sets (fonts). Some of the functions
are valid only in certain display modes.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 100/813
10/16/2018 PCjs: Advanced MS-DOS Programming
As you can see from the preceding list, the ROM BIOS offers several
desirable capabilities that are not available from MS-DOS, including
initialization or scrolling of selected screen windows, modification of
the cursor shape, and reading back the character being displayed at an
arbitrary screen location. These functions can be used to isolate your
program from the hardware on any IBM PC─compatible adapter. However, the
ROM BIOS functions do not suffice for the needs of a high-performance,
interactive, full-screen program such as a word processor. They do not
support the rapid display of character strings at an arbitrary screen
position, and they do not implement graphics operations at the level
normally required by applications (for example, bit-block transfers and
rapid drawing of lines, circles, and filled polygons). And, of course,
they are of no use whatsoever in non-IBM display modes such as the
monochrome graphics mode of the Hercules Graphics Card.
Let's look at a simple example of a call to the ROM BIOS video driver. The
following sequence writes the string hello to the screen:
──────────────────────────────────────────────────────────────────────────
msg db 'hello'
msg_len equ $-msg
.
.
.
mov si,seg msg ; DS:SI = message address
mov ds,si
mov si,offset msg
mov cx,msg_len ; CX = message length
cld
next: lodsb ; get AL = next character
push si ; save message pointer
mov ah,0eh ; int 10h function 0eh = write
; character in teletype mode
mov bh,0 ; assume video page 0
mov bl,color ; (use in graphics modes only)
int 10h ; transfer to ROM BIOS
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 101/813
10/16/2018 PCjs: Advanced MS-DOS Programming
(Note that the SI and DI registers are not necessarily preserved across a
call to a ROM BIOS video function.)
Text Mode
(0,0)┌─────────────────────────────────┐(79,0)
│ │
│ │
│ │
│ │
│ │
│ │
│ │
(0,24)└─────────────────────────────────┘(79,24)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 102/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 6-3. Cursor addressing for 80-by-25 text display modes (IBM ROM
BIOS modes 2, 3, and 7).
Figure 6-4. Attribute byte for 80-by-25 monochrome text display mode on
the MDA, Hercules cards, EGA, and VGA (IBM ROM BIOS mode 7).
Value Color
──────────────────────────────────────────────────────────────────────────
0 Black
1 Blue
2 Green
3 Cyan
4 Red
5 Magenta
6 Brown
7 White
8 Gray
9 Light blue
10 Light green
11 Light cyan
12 Light red
13 Light magenta
14 Yellow
15 Intense white
──────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 103/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 6-5. Attribute byte for the 40-by-25 and 80-by-25 text display
modes on the CGA, EGA, MCGA, and VGA (IBM ROM BIOS modes 0─3). The table
of color values assumes default palette programming and that the B or I
bit controls intensity.
──────────────────────────────────────────────────────────────────────────
B000:0000 3e 07 73 07 65 07 6c 07 65 07 63 07 74 07 20 07
B000:0010 74 07 65 07 6d 07 70 07 20 07 20 07 20 07 20 07
B000:0020 20 07 20 07 20 07 20 07 20 07 20 07 20 07 20 07
B000:0030 20 07 20 07 20 07 20 07 20 07 20 07 20 07 20 07
B000:0040 20 07 20 07 20 07 20 07 20 07 20 07 20 07 20 07
B000:0050 20 07 20 07 20 07 20 07 20 07 20 07 20 07 20 07
B000:0060 20 07 20 07 20 07 20 07 20 07 20 07 20 07 20 07
B000:0070 20 07 20 07 20 07 20 07 20 07 20 07 20 07 20 07
B000:0080 20 07 20 07 20 07 20 07 20 07 20 07 20 07 20 07
B000:0090 20 07 20 07 20 07 20 07 20 07 20 07 20 07 20 07
──────────────────────────────────────────────────────────────────────────
Figure 6-6. Example dump of the first 160 bytes of the MDA's regen
buffer. These bytes correspond to the first visible line on the screen.
Note that ASCII character codes are stored in even bytes and their
respective character attributes in odd bytes; all the characters in this
example line have the attribute normal video.
You can calculate the memory offset of any character on the display as the
line number (y coordinate) times 80 characters per line times 2 bytes per
character, plus the column number (x coordinate) times 2 bytes per
character, plus (for the text/graphics adapters) the page number times the
size of the page (4 KB per page in 80-by-25 modes; 2 KB per page in
40-by-25 modes). In short, the formula for the offset of the
character-attribute pair for a given screen position (x,y) in 80-by-25
text modes is
Of course, the segment register being used to address the video buffer
must be set appropriately, depending on the type of display adapter.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 104/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
push ax ; save char and attribute
mov ax,160
mul cx ; DX:AX = Y * 160
shl bx,1 ; multiply X by 2
add bx,ax ; BX = (Y*160) + (X*2)
mov ax,0b000h ; ES = segment of monochrome
mov es,ax ; adapter refresh buffer
pop ax ; restore char and attribute
mov es:[bx],ax ; write them to video buffer
──────────────────────────────────────────────────────────────────────────
More frequently, we wish to move entire strings into the refresh buffer,
starting at a given coordinate. In the next example, assume that the DS:SI
registers point to the source string, the ES:DI registers point to the
starting position in the video buffer (calculated as shown in the previous
example), the AH register contains the attribute byte to be assigned to
every character in the string, and the CX register contains the length of
the string. The following code moves the entire string into the refresh
buffer:
──────────────────────────────────────────────────────────────────────────
xfer: lodsb ; fetch next character
stosw ; store char + attribute
loop xfer ; until all chars moved
──────────────────────────────────────────────────────────────────────────
Of course, the video drivers written for actual application programs must
take into account many additional factors, such as checking for special
control codes (linefeeds, carriage returns, tabs), line wrap, and
scrolling.
Programs that write characters directly to the CGA regen buffer in text
modes must deal with an additional complicating factor──they must examine
the video controller's status port and access the refresh buffer only
during the horizontal retrace or vertical retrace intervals. (A retrace
interval is the period when the electron beam that illuminates the screen
phosphors is being repositioned to the start of a new scan line.)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 105/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Otherwise, the contention for memory between the CPU and the video
controller is manifest as unsightly "snow" on the display. (If you are
writing programs for any of the other IBM PC─compatible video adapters,
such as the MDA, EGA, MCGA, or VGA, you can ignore the retrace intervals;
snow is not a problem with these video controllers.)
──────────────────────────────────────────────────────────────────────────
mov dx,03dah ; DX = video controller's
; status port address
cli ; disable interrupts
; if retrace is already
; in progress, wait for
; it to end...
wait1: in al,dx ; read status port
and al,1 ; check if retrace bit on
jnz wait1 ; yes, wait
mov es:[bx],cl
; write character to
; the regen buffer
sti ; enable interrupts again
──────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 106/813
10/16/2018 PCjs: Advanced MS-DOS Programming
the code also disables interrupts during accesses to the video buffer, so
that service of a hardware interrupt won't disrupt the synchronization
process.
Graphics Mode
(0,0)┌─────────────────────────────────┐(639,0)
│ │
│ │
│ │
│ │
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 107/813
10/16/2018 PCjs: Advanced MS-DOS Programming
│ │
│ │
│ │
(0,199)└─────────────────────────────────┘(639,199)
To find the regen buffer offset for a particular (x,y) coordinate, you
would use the following formula:
──────────────────────────────────────────────────────────────────────────
; assume AX = Y, BX = X
shr bx,1 ; divide X by 8
shr bx,1
shr bx,1
push ax ; save copy of Y
shr ax,1 ; find (Y/2) * 50h
mov cx,50h ; with product in DX:AX
mul cx
add bx,ax ; add product to X/8
pop ax ; add (Y AND 1) * 2000h
and ax,1
jz label1
add bx,2000h
label1: ; now BX = offset into
; video buffer
──────────────────────────────────────────────────────────────────────────
After calculating the correct byte address, you can use the following
formula to calculate the bit position for a given pixel coordinate:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 108/813
10/16/2018 PCjs: Advanced MS-DOS Programming
bit = 7 - (x MOD 8)
where bit 7 is the most significant bit and bit 0 is the least significant
bit. It is easiest to build an 8-byte table, or array of bit masks, and
use the operation X AND 7 to extract the appropriate entry from the table:
──────────────────────────────────────────────────────────────────────────
table db 80h ; X AND 7 = offset 0
db 40h ; X AND 7 = offset 1
db 20h ; X AND 7 = offset 2
db 10h ; X AND 7 = offset 3
db 08h ; X AND 7 = offset 4
db 04h ; X AND 7 = offset 5
db 02h ; X AND 7 = offset 6
db 01h ; X AND 7 = offset 7
.
.
.
; assume BX = X coordinate
and bx,7 ; isolate 0─7 offset
mov al,[bx+table]
; now AL = mask from table
.
.
.
──────────────────────────────────────────────────────────────────────────
The program can then use the mask, together with the byte offset
previously calculated, to set or clear the appropriate bit in the video
controller's regen buffer.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 109/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Chapter 7 Printer and Serial Port
Parallel ports are typically used for high-speed output devices, such as
line printers, over relatively short distances (less than 50 feet). They
are rarely used for devices that require two-way communication with the
computer. Serial ports are used for lower-speed devices, such as modems
and terminals, that require two-way communication (although some printers
also have serial interfaces). A serial port can drive its device reliably
over much greater distances (up to 1000 feet) over as few as three wires──
transmit, receive, and ground.
The most commonly used type of serial interface follows a standard called
RS-232. This standard specifies a 25-wire interface with certain
electrical characteristics, the use of various handshaking signals, and a
standard DB-25 connector. Other serial-interface standards exist──for
example, the RS-422, which is capable of considerably higher speeds than
the RS-232── but these are rarely used in personal computers (except for
the Apple Macintosh) at this time.
MS-DOS has built-in device drivers for three parallel adapters, and for
two serial adapters on the PC or PC/AT and three serial adapters on the
PS/2. The logical names for these devices are LPT1, LPT2, LPT3, COM1,
COM2, and COM3. The standard printer (PRN) and standard auxiliary (AUX)
devices are normally aliased to LPT1 and COM1, but you can redirect PRN to
one of the serial ports with the MS-DOS MODE command.
As with keyboard and video display I/O, you can manage printer and
serial-port I/O at several levels that offer different degrees of
flexibility and hardware independence:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 110/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Printer Output
The preferred method of printer output is to use the handle write function
(Int 21H Function 40H) with the predefined standard printer handle (4).
For example, you could write the string hello to the printer as follows:
──────────────────────────────────────────────────────────────────────────
msg db 'hello' ; message for printer
msg_len equ $-msg ; length of message
.
.
.
mov ah,40h ; function 40h = write file or device
mov bx,4 ; BX = standard printer handle
mov cx,msg_len ; CX = length of string
mov dx,seg msg ; DS:DX = string address
mov ds,dx
mov dx,offset msg
int 21h ; transfer to MS-DOS
jc error ; jump if error
.
.
.
──────────────────────────────────────────────────────────────────────────
If there is no error, the function returns the carry flag cleared and the
number of characters actually transferred to the list device in register
AX. Under normal circumstances, this number should always be the same as
the length requested and the carry flag indicating an error should never
be set. However, the output will terminate early if your data contains an
end-of-file mark (Ctrl-Z).
You can write independently to several list devices (for example, LPT1,
LPT2) by issuing a specific open request (Int 21H Function 3DH) for each
device and using the handles returned to access the printers individually
with Int 21H Function 40H. You have already seen this general approach in
Chapters 5 and 6.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 111/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
msg db 'hello' ; message for printer
msg_len equ $-msg ; length of message
.
.
.
mov bx,seg msg ; DS:BX = string address
mov ds,bx
mov bx,offset msg
mov cx,msg_len ; CX = string length
For example, the following sequence of instructions calls the ROM BIOS
printer driver to send the string hello to the line printer:
──────────────────────────────────────────────────────────────────────────
msg db 'hello' ; message for printer
msg_len equ $-msg ; length of message
.
.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 112/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
mov bx,seg msg ; DS:BX = string address
mov ds,bx
mov bx,offset msg
mov cx,msg_len ; CX = string length
mov dx,0 ; DX = printer number
Note that the printer numbers used by the ROM BIOS are zero-based, whereas
the printer numbers in MS-DOS logical-device names are one-based. For
example, ROM BIOS printer 0 corresponds to LPT1.
MS-DOS support for serial ports (often referred to as the auxiliary device
in MS-DOS manuals) is weak compared with its keyboard, video-display, and
printer support. This is one area where the application programmer is
justified in making programs hardware dependent to extract adequate
performance.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 113/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
msg db 'hello' ; message for serial port
msg_len equ $-msg ; length of message
.
.
.
mov ah,40h ; function 40h = write file or device
mov bx,3 ; BX = standard aux handle
mov cx,msg_len ; CX = string length
mov dx,seg msg ; DS:DX = string address
mov ds,dx
mov dx,offset msg
int 21h ; transfer to MS-DOS
jc error ; jump if error
.
.
.
──────────────────────────────────────────────────────────────────────────
The standard auxiliary handle gives access to only the first serial port
(COM1). If you want to read or write COM2 and COM3 using the handle calls,
you must issue an open request (Int 21H Function 3DH) for the desired
serial port and use the handle returned by that function with Int 21H
Functions 3FH and 40H.
MS-DOS also supports two traditional functions for serial-port I/O. Int
21H Function 03H inputs a character from COM1 and returns it in the AL
register; Int 21H Function 04H transmits the character in the DL register
to COM1. Like the other traditional calls, these two are direct
descendants of the CP/M auxiliary-device functions.
For example, the following code sends the string hello to COM1 using the
traditional Int 21H Function 04H:
──────────────────────────────────────────────────────────────────────────
msg db 'hello' ; message for serial port
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 114/813
10/16/2018 PCjs: Advanced MS-DOS Programming
For programs that are going to run on the IBM PC or compatibles, a more
flexible technique for serial-port I/O is to call the IBM ROM BIOS
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 115/813
10/16/2018 PCjs: Advanced MS-DOS Programming
serial-port driver by means of Int 14H. You can use this driver to
initialize the serial port to a desired configuration and baud rate,
examine the status of the controller, and read or write characters.
Section III of this book, "IBM ROM BIOS and Mouse Functions Reference,"
documents the functions available from the ROM BIOS serial-port driver.
For example, the following sequence sends the character X to the first
serial port (COM1):
──────────────────────────────────────────────────────────────────────────
.
.
.
mov ah,1 ; function 01h = send character
mov al,'X' ; AL = character to transmit
mov dx,0 ; DX = serial-port number
int 14h ; transfer to ROM BIOS
and ah,80h ; did transmit fail?
jnz error ; jump if transmit error
.
.
.
──────────────────────────────────────────────────────────────────────────
As with the ROM BIOS printer driver, the serial-port numbers used by the
ROM BIOS are zero-based, whereas the serial-port numbers in MS-DOS
logical-device names are one-based. In this example, serial port 0
corresponds to COM1.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 116/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
name talk
page 55,132
.lfcond ; List false conditionals too
title TALK--Simple terminal emulator
;
; TALK.ASM--Simple IBM PC terminal emulator
;
; Copyright (c) 1988 Ray Duncan
;
; To assemble and link this program into TALK.EXE:
;
; C>MASM TALK;
; C>LINK TALK;
;
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 117/813
10/16/2018 PCjs: Advanced MS-DOS Programming
if com1
com_data equ 03f8h ; port assignments for COM1
com_ier equ 03f9h
com_mcr equ 03fch
com_sts equ 03fdh
com_int equ 0ch ; COM1 interrupt number
int_mask equ 10h ; IRQ4 mask for 8259
endif
if com2
com_data equ 02f8h ; port assignments for COM2
com_ier equ 02f9h
com_mcr equ 02fch
com_sts equ 02fdh
com_int equ 0bh ; COM2 interrupt number
int_mask equ 08h ; IRQ3 mask for 8259
endif
assume cs:_TEXT,ds:_DATA,es:_DATA,ss:STACK
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 118/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 119/813
10/16/2018 PCjs: Advanced MS-DOS Programming
talk endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 120/813
10/16/2018 PCjs: Advanced MS-DOS Programming
com_in endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 121/813
10/16/2018 PCjs: Advanced MS-DOS Programming
com_out endp
pc_stat proc near ; read keyboard status; returns
; Z = false if character ready
; Z = true if nothing waiting
; register DX destroyed
pc_stat endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 122/813
10/16/2018 PCjs: Advanced MS-DOS Programming
ret
pc_in endp
pc_out endp
cls endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 123/813
10/16/2018 PCjs: Advanced MS-DOS Programming
clreol endp
home proc near ; put cursor at home position
home endp
gotoxy endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 124/813
10/16/2018 PCjs: Advanced MS-DOS Programming
getxy endp
ctrl_code proc near ; process control code
; call with AL = char
jmp ctrl9
ctrl7:
cmp al,escape ; is it Escape character?
jne ctrl9 ; no, throw it away
ctrl_code endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 125/813
10/16/2018 PCjs: Advanced MS-DOS Programming
esc_seq endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 126/813
10/16/2018 PCjs: Advanced MS-DOS Programming
asc_enb endp
asc_dsb endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 127/813
10/16/2018 PCjs: Advanced MS-DOS Programming
asc_int endp
_TEXT ends
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 128/813
10/16/2018 PCjs: Advanced MS-DOS Programming
msg1 db cr,lf
db 'Display must be text mode.'
db cr,lf
msg1_len equ $-msg1
_DATA ends
STACK ends
The TALK program illustrates the methods that an application should use to
take over and service interrupts from the serial port without running
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 129/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The program begins with some equates and conditional assembly statements
that configure the program for half- or full-duplex and for the desired
serial port (COM1 or COM2). At entry from MS-DOS, the main routine of the
program──the procedure named talk──checks the status of the serial port,
initializes the display, and calls the asc_enb routine to take over the
serial-port interrupt vector and enable interrupts. The talk procedure
then enters a loop that reads the keyboard and sends the characters out
the serial port and then reads the serial port and puts the characters on
the display──in other words, it causes the PC to emulate a simple CRT
terminal.
The TALK program intercepts and handles control codes (carriage return,
linefeed, and so forth) appropriately. It detects escape sequences and
handles them as a subset of the Televideo 950 terminal capabilities. (You
can easily modify the program to emulate any other cursor-addressable
terminal.) When one of the PC's special function keys is pressed, the
program disables serial-port interrupts, releases the serial-port
interrupt vector, and exits back to MS-DOS.
There are several TALK program procedures that are worth your attention
because they can easily be incorporated into other programs. These are
listed in the table on the following page.
╓┌─┌──────────────────┌──────────────────────────────────────────────────────╖
Procedure Action
──────────────────────────────────────────────────────────────────────────
asc_enb Takes over the serial-port interrupt vector and enables
interrupts by writing to the modem-control register of
the INS8250 and the interrupt-mask register of the
8259A.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 130/813
10/16/2018 PCjs: Advanced MS-DOS Programming
cls Calls the ROM BIOS video driver to clear the screen.
clreol Calls the ROM BIOS video driver to clear from the
current cursor position to the end of the line.
Procedure Action
──────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Chapter 8 File Management
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 131/813
10/16/2018 PCjs: Advanced MS-DOS Programming
I will refer to the set of file and record functions that are compatible
with CP/M as FCB functions. These functions rely on a data structure
called a file control block (hence, FCB) to maintain certain bookkeeping
information about open files. This structure resides in the application
program's memory space. The FCB functions allow the programmer to create,
open, close, and delete files and to read or write records of any size at
any record position within such files. These functions do not support the
hierarchical (treelike) file structure that was first introduced in MS-DOS
version 2.0, so they can be used only to access files in the current
subdirectory for a given disk drive.
I will refer to the set of file and record functions that provide
compatibility with UNIX/XENIX as the handle functions. These functions
allow the programmer to open or create files by passing MS-DOS a
null-terminated string that describes the file's location in the
hierarchical file structure (the drive and path), the file's name, and its
extension. If the open or create operation is successful, MS-DOS returns a
16-bit token, or handle, that is saved by the application program and used
to specify the file in subsequent operations.
When you use the handle functions, the operating system maintains the data
structures that contain bookkeeping information about the file inside its
own memory space, and these structures are not accessible to the
application program. The handle functions fully support the hierarchical
file structure, allowing the programmer to create, open, close, and delete
files in any subdirectory on any disk drive and to read or write records
of any size at any byte offset within such files.
Although we are discussing the FCB functions first in this chapter for
historical reasons, new MS-DOS applications should always be written using
the more powerful handle functions. Use of the FCB functions in new
programs should be avoided, unless compatibility with MS-DOS version 1.0
is needed.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 132/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Byte offset
00H ┌───────────────────────────────────────────────────────┐
│ Drive identification │ Note 1
01H ├───────────────────────────────────────────────────────┤
│ Filename (8 characters) │ Note 2
09H ├───────────────────────────────────────────────────────┤
│ Extension (3 characters) │ Note 2
0CH ├───────────────────────────────────────────────────────┤
│ Current block number │ Note 9
0EH ├───────────────────────────────────────────────────────┤
│ Record size │ Note 10
10H ├───────────────────────────────────────────────────────┤
│ File size (4 bytes) │ Notes 3, 6
14H ├───────────────────────────────────────────────────────┤
│ Date created/updated │ Note 7
16H ├───────────────────────────────────────────────────────┤
│ Time created/updated │ Note 8
18H ├───────────────────────────────────────────────────────┤
│ Reserved │
20H ├───────────────────────────────────────────────────────┤
│ Current-record number │ Note 9
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 133/813
10/16/2018 PCjs: Advanced MS-DOS Programming
21H ├───────────────────────────────────────────────────────┤
│ Relative-record number (4 bytes) │ Note 5
└───────────────────────────────────────────────────────┘
Figure 8-1. Normal file control block. Total length is 37 bytes (25H
bytes). See notes on pages 133─34.
In general, MS-DOS functions that use FCBs accept the full address of the
FCB in the DS:DX register and pass back a return code in the AL register
(Figure 8-2). For file-management calls (open, close, create, and
delete), this return code is zero if the function was successful and 0FFH
(255) if the function failed. For the FCB-type record read and write
functions, the success code returned in the AL register is again zero, but
there are several failure codes. Under MS-DOS version 3.0 or later, more
detailed error reporting can be obtained by calling Int 21H Function 59H
(Get Extended Error Information) after a failed FCB function call.
When a program is loaded under MS-DOS, the operating system sets up two
FCBs in the program segment prefix, at offsets 005CH and 006CH. These are
often referred to as the default FCBs, and they are included to provide
upward compatibility from CP/M. MS-DOS parses the first two parameters in
the command line that invokes the program (excluding any redirection
directives) into the default FCBs, under the assumption that they may be
file specifications. The application must determine whether they really
are filenames or not. In addition, because the default FCBs overlap and
are not in a particularly convenient location (especially for .EXE
programs), they usually must be copied elsewhere in order to be used
safely. (See Chapter 3.)
──────────────────────────────────────────────────────────────────────────
; filename was previously
; parsed into "my_fcb"
mov dx,seg my_fcb ; DS:DX = address of
mov ds,dx ; file control block
mov dx,offset my_fcb
mov ah,0fh ; function 0fh = open
int 21h
or al,al ; was open successful?
jnz error ; no, jump to error routine
.
.
.
my_fcb db 37 dup (0) ; file control block
──────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 134/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 8-2. A typical FCB file operation. This sequence of code attempts
to open the file whose name was previously parsed into the FCB named
my_fcb.
Note that the structures of FCBs under CP/M and MS-DOS are not identical.
However, the differences lie chiefly in the reserved areas of the FCBs
(which should not be manipulated by application programs in any case), so
well-behaved CP/M applications should be relatively easy to port into
MS-DOS. It seems, however, that few such applications exist. Many of the
tricks that were played by clever CP/M programmers to increase performance
or circumvent the limitations of that operating system can cause severe
problems under MS-DOS, particularly in networking environments. At any
rate, much better performance can be achieved by thoroughly rewriting the
CP/M applications to take advantage of the superior capabilities of
MS-DOS.
You can use a special FCB variant called an extended file control block to
create or access files with special attributes (such as hidden or
read-only files), volume labels, and subdirectories. An extended FCB has a
7-byte header followed by the 37-byte structure of a normal FCB (Figure
8-3). The first byte contains 0FFH, which could never be a legal drive
code and thus indicates to MS-DOS that an extended FCB is being used. The
next 5 bytes are reserved and are unused in current versions of MS-DOS.
The seventh byte contains the attribute of the special file type that is
being accessed. (Attribute bytes are discussed in more detail in Chapter
9.) Any MS-DOS function that uses a normal FCB can also use an extended
FCB.
The FCB file- and record-management functions may be gathered into the
following broad classifications:
Byte
offset
00H ┌───────────────────────────────────────────────────────┐
│ 0FFH │ Note 11
01H ├───────────────────────────────────────────────────────┤
│ Reserved (5 bytes, must be zero) │
06H ├───────────────────────────────────────────────────────┤
│ Attribute byte │ Note 12
07H ├───────────────────────────────────────────────────────┤
│ Drive identification │ Note 1
08H ├───────────────────────────────────────────────────────┤
│ Filename (8 characters) │ Note 2
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 135/813
10/16/2018 PCjs: Advanced MS-DOS Programming
10H ├───────────────────────────────────────────────────────┤
│ Extension (3 characters) │ Note 2
13H ├───────────────────────────────────────────────────────┤
│ Current-block number │ Note 9
15H ├───────────────────────────────────────────────────────┤
│ Record size │ Note 10
17H ├───────────────────────────────────────────────────────┤
│ File size (4 bytes) │ Notes 3, 6
1BH ├───────────────────────────────────────────────────────┤
│ Date created/updated │ Note 7
1DH ├───────────────────────────────────────────────────────┤
│ Time created/updated │ Note 8
1FH ├───────────────────────────────────────────────────────┤
│ Reserved │
27H ├───────────────────────────────────────────────────────┤
│ Current-record number │ Note 9
28H ├───────────────────────────────────────────────────────┤
│ Relative-record number (4 bytes) │ Note 5
└───────────────────────────────────────────────────────┘
Figure 8-3. Extended file control block. Total length is 44 bytes (2CH
bytes). See notes on pages 133─34.
╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
Function Action
──────────────────────────────────────────────────────────────────────────
Common FCB file operations
0FH Open file.
10H Close file.
16H Create file.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 136/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Function Action
──────────────────────────────────────────────────────────────────────────
Several of these functions have special properties. For example, Int 21H
Functions 27H (Random Block Read) and 28H (Random Block Write) allow
reading and writing of multiple records of any size and also update the
random-record field automatically (unlike Int 21H Functions 21H and
22H). Int 21H Function 28H can truncate a file to any desired size, and
Int 21H Function 17H used with an extended FCB can alter a volume label
or rename a subdirectory.
──────────────────────────────────────────────────────────────────────────
Notes for Figures 8-1 and 8-3
1. The drive identification is a binary number: 00=default drive,
01=drive A:, 02=drive B:, and so on. If the application program
supplies the drive code as zero (default drive), MS-DOS fills in the
code for the actual current disk drive after a successful open or
create call.
2. File and extension names must be left justified and padded with
blanks.
3. The file size, date, time, and reserved fields should not be
modified by applications.
4. All word fields are stored with the least significant byte at the
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 137/813
10/16/2018 PCjs: Advanced MS-DOS Programming
lower address.
F E D C B A 9 8 7 6 5 4 3 2 1 0
┌─────────────────────┬─────────────────────┬─────────────────────┐
│ Year │ Month │ Day │
└─────────────────────┴─────────────────────┴─────────────────────┘
Bits Contents
────────────────────────────────────────────────────────────────────────
00H─04H Day (1─31)
05H─08H Month (1─12)
09H─0FH Year, relative to 1980
────────────────────────────────────────────────────────────────────────
F E D C B A 9 8 7 6 5 4 3 2 1 0
┌───────────────────┬───────────────────────┬─────────────────────┐
│ Hours │ Minutes │ 2-second increments │
└───────────────────┴───────────────────────┴─────────────────────┘
Bits Contents
────────────────────────────────────────────────────────────────────────
00H─04H 2-second increments (0─29)
05H─0AH Minutes (0─59)
0BH─0FH Hours (0─23)
────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 138/813
10/16/2018 PCjs: Advanced MS-DOS Programming
10. The Int 21H open (0FH) and create (16H) functions set the
record-size field to 128 bytes, to provide compatibility with CP/M.
If you use another record size, you must fill it in after the open
or create operation.
11. An 0FFH (255) in the first byte of the structure signifies that it
is an extended file control block. You can use extended FCBs with
any of the functions that accept an ordinary FCB. (See also note
12.)
12. The attribute byte in an extended FCB allows access to files with
the special characteristics hidden, system, or read-only. You can
also use extended FCBs to read volume labels and the contents of
special subdirectory files.
──────────────────────────────────────────────────────────────────────────
2. Obtain the filename from the user, from the default FCBs, or from the
command tail in the PSP.
3. If the filename was not obtained from one of the default FCBs, parse
the filename into the new FCB using Int 21H Function 29H.
4. Open the file (Int 21H Function 0FH) or, if writing new data only,
create the file or truncate any existing file of the same name to zero
length (Int 21H Function 16H).
5. Set the record-size field in the FCB, unless you are using the default
record size. Recall that it is important to do this after a successful
open or create operation. (See Figure 8-5.)
6. Set the relative-record field in the FCB if you are performing random
record I/O.
7. Set the disk transfer area address using Int 21H Function 1AH, unless
the buffer address has not been changed since the last call to this
function. If the application never performs a set DTA, the DTA address
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 139/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
recsize equ 1024 ; file record size
.
.
.
mov ah,29h ; parse input filename
mov al,1 ; skip leading blanks
mov si,offset fname1 ; address of filename
mov di,offset fcb1 ; address of FCB
int 21h
or al,al ; jump if name
jnz name_err ; was bad
.
.
.
mov ah,29h ; parse output filename
mov al,1 ; skip leading blanks
mov si,offset fname2 ; address of filename
mov di,offset fcb2 ; address of FCB
int 21h
or al,al ; jump if name
jnz name_err ; was bad
.
.
.
mov ah,0fh ; open input file
mov dx,offset fcb1
int 21h
or al,al ; open successful?
jnz no_file ; no, jump
.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 140/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
mov ah,16h ; create and open
mov dx,offset fcb2 ; output file
int 21h
or al,al ; create successful?
jnz disk_full ; no, jump
.
.
. ; set record sizes
mov word ptr fcb1+0eh,recsize
mov word ptr fcb2+0eh,recsize
.
.
.
mov ah,1ah ; set disk transfer
mov dx,offset buffer ; address for reads
int 21h ; and writes
.
next: . ; process next record
.
mov ah,14h ; sequential read from
mov dx,offset fcb1 ; input file
int 21h
cmp al,01 ; check for end of file
je file_end ; jump if end of file
cmp al,03
je file_end ; jump if end of file
or al,al ; other read fault?
jnz bad_read ; jump if bad read
.
.
.
mov ah,15h ; sequential write to
mov dx,offset fcb2 ; output file
int 21h
or al,al ; write successful?
jnz bad_write ; jump if write failed
.
.
.
jmp next ; process next record
.
file_end: . ; reached end of input
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 141/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
mov ah,10h ; close input file
mov dx,offset fcb1
int 21h
.
.
.
mov ah,10h ; close output file
mov dx,offset fcb2
int 21h
.
.
.
mov ax,4c00h ; exit with return
int 21h ; code of zero
.
.
.
fname1 db 'OLDFILE.DAT',0 ; name of input file
fname2 db 'NEWFILE.DAT',0 ; name of output file
fcb1 db 37 dup (0) ; FCB for input file
fcb2 db 37 dup (0) ; FCB for output file
buffer db recsize dup (?) ; buffer for file I/O
──────────────────────────────────────────────────────────────────────────
Byte Offset FCB before open FCB contents FCB after open
┌────────────────────┬────────────────────┬────────────────────┐
00H │ 00 │ Drive │ 03 │
├────────────────────┼────────────────────┼────────────────────┤
01H │ 4D │ │ 4D │
02H │ 59 │ │ 59 │
03H │ 46 │ │ 46 │
04H │ 49 │ Filename │ 49 │
05H │ 4C │ │ 4C │
06H │ 45 │ │ 45 │
07H │ 20 │ │ 20 │
08H │ 20 │ │ 20 │
├────────────────────┼────────────────────┼────────────────────┤
09H │ 44 │ │ 44 │
0AH │ 41 │ Extension │ 41 │
0BH │ 54 │ │ 54 │
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 142/813
10/16/2018 PCjs: Advanced MS-DOS Programming
├────────────────────┼────────────────────┼────────────────────┤
0CH │ 00 │ │ 00 │
0DH │ 00 │ Current block │ 00 │
├────────────────────┼────────────────────┼────────────────────┤
0EH │ 00 │ │ 80 │
0FH │ 00 │ Record size │ 00 │
├────────────────────┼────────────────────┼────────────────────┤
10H │ 00 │ │ 80 │
11H │ 00 │ │ 3D │
12H │ 00 │ File size │ 00 │
13H │ 00 │ │ 00 │
├────────────────────┼────────────────────┼────────────────────┤
14H │ 00 │ │ 43 │
15H │ 00 │ File date │ 0B │
├────────────────────┼────────────────────┼────────────────────┤
16H │ 00 │ │ A1 │
17H │ 00 │ File time │ 52 │
├────────────────────┼────────────────────┼────────────────────┤
18H │ 00 │ │ 03 │
19H │ 00 │ │ 02 │
1AH │ 00 │ │ 42 │
1BH │ 00 │ │ 73 │
1CH │ 00 │ Reserved │ 00 │
1DH │ 00 │ │ 01 │
1EH │ 00 │ │ 35 │
1FH │ 00 │ │ 0F │
├────────────────────┼────────────────────┼────────────────────┤
20H │ 00 │ Current record │ 00 │
├────────────────────┼────────────────────┼────────────────────┤
21H │ 00 │ │ 00 │
22H │ 00 │ Relative-record │ 00 │
23H │ 00 │ number │ 00 │
24H │ 00 │ │ 00 │
└────────────────────┴────────────────────┴────────────────────┘
Figure 8-5. A typical file control block before and after a successful
open call (Int 21H Function 0FH).
Points to Remember
Here is a summary of the pros and cons of using the FCB-related file and
record functions in your programs.
Advantages:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 143/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ Under MS-DOS versions 1 and 2, the number of files that can be open
concurrently when using FCBs is unlimited. (This is not true under
MS-DOS versions 3.0 and later, especially if networking software is
running.)
■ MS-DOS supplies the size, time, and date for a file to its FCB after
the file is opened. The calling program can inspect this information.
Disadvantages:
■ FCBs offer no support for the hierarchical file structure (no access to
files outside the current directory).
■ You must use extended FCBs, which are incompatible with CP/M anyway, to
access or create files with special attributes such as hidden,
read-only, or system.
■ The FCB file functions have poor error reporting. This situation has
been improved somewhat in MS-DOS version 3 because a program can call
the added Int 21H Function 59H (Get Extended Error Information) after
a failed FCB function to obtain additional information.
■ Microsoft discourages use of FCBs. FCBs will make your program more
difficult to port to MS OS/2 later because MS OS/2 does not support
FCBs in protected mode at all.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 144/813
10/16/2018 PCjs: Advanced MS-DOS Programming
C:\SYSTEM\COMMAND.COM
43 3A 5C 53 59 53 54 45 4D 5C 43 4F 4D 4D 41 4E 44 2E 43 4F 4D 00
──────────────────────────────────────────────────────────────────────────
mov ah,3dh ; function 3dh = open
mov al,2 ; mode 2 = read/write
mov dx,seg filename ; address of ASCIIZ
mov ds,dx ; file specification
mov dx,offset filename
int 21h ; request open from DOS
jc error ; jump if open failed
mov handle,ax ; save file handle
.
.
.
filename db 'C:\MYDIR\MYFILE.DAT',0 ; filename
handle dw 0 ; file handle
──────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 145/813
10/16/2018 PCjs: Advanced MS-DOS Programming
was successful, or set if the operation failed; in the latter case, the AX
register contains a code describing the failure.
MS-DOS restricts the number of handles that can be active at any one
time──that is, the number of files and devices that can be open
concurrently when using the handle family of functions──in two different
ways:
■ The maximum number of concurrently open files in the system, for all
active processes combined, is specified by the entry
FILES=nn
The handle file- and record-management calls may be gathered into the
following broad classifications for study:
╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
Function Action
Function Action
──────────────────────────────────────────────────────────────────────────
Common handle file operations
3CH Create file (requires ASCIIZ string).
3DH Open file (requires ASCIIZ string).
3EH Close file.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 146/813
10/16/2018 PCjs: Advanced MS-DOS Programming
1. Get the filename from the user by means of the buffered input service
(Int 21H Function 0AH) or from the command tail supplied by MS-DOS in
the PSP.
3. Open the file using Int 21H Function 3DH and mode 2 (read/write
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 147/813
10/16/2018 PCjs: Advanced MS-DOS Programming
access), or create the file using Int 21H Function 3CH. (Be sure to
set the CX register to zero, so that you don't accidentally make a
file with special attributes.) Save the handle that is returned.
4. Set the file pointer using Int 21H Function 42H. You may set the
file-pointer position relative to one of three different locations:
the start of the file, the current pointer position, or the end of the
file. If you are performing sequential record I/O, you can usually
skip this step because MS-DOS will maintain the file pointer for you
automatically.
5. Read from the file (Int 21H Function 3FH) or write to the file (Int
21H Function 40H). Both of these functions require that the BX
register contain the file's handle, the CX register contain the length
of the record, and the DS:DX registers point to the data being
transferred. Both return the actual number of bytes transferred in the
AX register.
──────────────────────────────────────────────────────────────────────────
recsize equ 1024 ; file record size
.
.
.
mov ah,3dh ; open input file
mov al,0 ; mode = read only
mov dx,offset fname1 ; name of input file
int 21h
jc no_file ; jump if no file
mov handle1,ax ; save token for file
.
.
.
mov ah,3ch ; create output file
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 148/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 149/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
mov ax,4c00h ; exit with return
int 21h ; code of zero
.
.
.
fname1 db 'OLDFILE.DAT',0 ; name of input file
fname2 db 'NEWFILE.DAT',0 ; name of output file
handle1 dw 0 ; token for input file
handle2 dw 0 ; token for output file
buffer db recsize dup (?) ; buffer for file I/O
──────────────────────────────────────────────────────────────────────────
Points to Remember
Here is a summary of the pros and cons of using the handle file and record
operations in your program. Compare this list with the one given earlier
in the chapter for the FCB family of functions.
Advantages:
■ The handle calls provide direct support for I/O redirection and pipes
with the standard input and output devices in a manner functionally
similar to that used by UNIX/XENIX.
■ The handle calls make the use of random record access extremely easy.
The current file pointer can be moved to any byte offset relative to
the start of the file, the end of the file, or the current pointer
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 150/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Disadvantages:
When one of the handle file functions fails with the carry flag set, or
when a program calls Int 21H Function 59H (Get Extended Error
Information) following a failed FCB function or other system service, one
of the following error codes may be returned:
╓┌─┌────────────────────────┌────────────────────────────────────────────────╖
Value Meaning
──────────────────────────────────────────────────────────────────────────
MS-DOS version 2 error codes
01H Function number invalid
02H File not found
03H Path not found
04H Too many open files
05H Access denied
06H Handle invalid
07H Memory control blocks destroyed
08H Insufficient memory
09H Memory block address invalid
0AH (10) Environment invalid
0BH (11) Format invalid
0CH (12) Access code invalid
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 151/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 152/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Value Meaning
──────────────────────────────────────────────────────────────────────────
3AH (58) Incorrect response from network
3BH (59) Unexpected network error
3CH (60) Remote adapter incompatible
3DH (61) Print queue full
3EH (62) Not enough room for print file
3FH (63) Print file was deleted
40H (64) Network name deleted
41H (65) Network access denied
42H (66) Incorrect network device type
43H (67) Network name not found
44H (68) Network name limit exceeded
45H (69) NetBIOS session limit exceeded
46H (70) Temporary pause
47H (71) Network request not accepted
48H (72) Print or disk redirection paused
49H─4FH (73─79) Reserved
50H (80) File already exists
51H (81) Reserved
52H (82) Cannot make directory
Value Meaning
──────────────────────────────────────────────────────────────────────────
52H (82) Cannot make directory
53H (83) Fail on Int 24H (critical error)
54H (84) Too many redirections
55H (85) Duplicate redirection
56H (86) Invalid password
57H (87) Invalid parameter
58H (88) Net write fault
──────────────────────────────────────────────────────────────────────────
Under MS-DOS versions 3.0 and later, you can also use Int 21H Function
59H to obtain other information about the error, such as the error locus
and the recommended recovery action.
Critical-Error Handlers
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 153/813
10/16/2018 PCjs: Advanced MS-DOS Programming
To write a truly bombproof MS-DOS application, you must take over the
critical-error-handler vector and point it to your own routine, so that
your program intercepts all catastrophic hardware errors and handles them
appropriately. You can use MS-DOS Int 21H Function 25H to alter the Int
24H vector in a well-behaved manner. When your application exits, MS-DOS
will automatically restore the previous contents of the Int 24H vector
from information saved in the program segment prefix.
╓┌─┌──────────────────┌─────────────────┌────────────────────────────────────╖
Register Bit(s) Significance
──────────────────────────────────────────────────────────────────────────
AH 7 0, to signify disk error
6 Reserved
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 154/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 155/813
10/16/2018 PCjs: Advanced MS-DOS Programming
device.
┌───────┐─┐
│ Flags │ │
├───────┤ │ Flags and CS:IP pushed
│ CS │ ├─ on stack by original
├───────┤ │ Int 21H call
│ IP │ │
├───────┤═╡◄─SS:SP on entry to
│ ES │ │ Int 21H handler
├───────┤ │
│ DS │ │
├───────┤ │
│ BP │ │
├───────┤ │
│ DI │ │
├───────┤ ├─ Registers at point of
│ SI │ │ original Int 21H call
├───────┤ │
│ DX │ │
├───────┤ │
│ CX │ │
├───────┤ │
│ BX │ │
├───────┤ │
│ AX │ │
├───────┤═╡
│ Flags │ │
├───────┤ │
│ CS │ ├─ Return address for
├───────┤ │ Int 24H handler
│ IP │ │
└──────┘─┘
└───── SS:SP on entry to
Int 24H handler
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 156/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Code Meaning
──────────────────────────────────────────────────────────────────────────
0 Ignore the error (MS-DOS acts as though the original
function call had succeeded).
1 Retry the operation.
2 Terminate the process that encountered the error.
3 Fail the function (an error code is returned to the
requesting process). Versions 3.1 and later only.
──────────────────────────────────────────────────────────────────────────
The critical-error handler should preserve all other registers and must
not modify the device-driver header pointed to by BP:SI. A skeleton
example of a critical-error handler is shown in Figure 8-9.
──────────────────────────────────────────────────────────────────────────
; prompt message used by
; critical-error handler
prompt db cr,lf,'Critical Error Occurred: '
db 'Abort, Retry, Ignore, Fail? $'
;
; This code is executed during program's initialization
; to install the new critical-error handler.
;
.
.
.
push ds ; save our data segment
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 157/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 158/813
10/16/2018 PCjs: Advanced MS-DOS Programming
int24 endp
──────────────────────────────────────────────────────────────────────────
The programs DUMP.ASM (Figure 8-10) and DUMP.C (Figure 8-11) are
parallel examples of the use of the handle file and record functions. The
assembly-language version, in particular, illustrates features of a
well-behaved MS-DOS utility:
■ The program checks the version of MS-DOS to ensure that all the
functions it is going to use are really available.
■ The program parses the drive, path, and filename from the command tail
in the program segment prefix.
■ The program sends normal program output to the standard output device,
so that the dump output appears by default on the system console but
can be redirected to other character devices (such as the line printer)
or to a file.
The same features are incorporated into the C version of the program, but
some of them are taken care of behind the scenes by the C runtime library.
──────────────────────────────────────────────────────────────────────────
name dump
page 55,132
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 159/813
10/16/2018 PCjs: Advanced MS-DOS Programming
;
; DUMP--Display contents of file in hex and ASCII
;
; Build: C>MASM DUMP;
; C>LINK DUMP;
;
; Usage: C>DUMP unit:\path\filename.exe [ >device ]
;
; Copyright (C) 1988 Ray Duncan
;
assume cs:_TEXT,ds:_DATA,es:_DATA,ss:STACK
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 160/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 161/813
10/16/2018 PCjs: Advanced MS-DOS Programming
; display a heading
mov dx,offset hdg ; DS:DX = heading address
mov cx,hdg_len ; CX = heading length
mov bx,stdout ; BX = standard output
mov ah,40h ; function 40h = write
int 21h ; transfer to MS-DOS
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 162/813
10/16/2018 PCjs: Advanced MS-DOS Programming
dump endp
conv proc near ; convert block of data
; from input file
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 163/813
10/16/2018 PCjs: Advanced MS-DOS Programming
ret
conv endp
w2a proc near ; convert word to hex ASCII
; call with AX = value
; DI = addr for string
; returns AX, DI, CX destroyed
w2a endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 164/813
10/16/2018 PCjs: Advanced MS-DOS Programming
b2a endp
ascii endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 165/813
10/16/2018 PCjs: Advanced MS-DOS Programming
argc endp
or ax,ax ; is it argument 0?
jz argv8 ; yes, jump to get program name
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 166/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 167/813
10/16/2018 PCjs: Advanced MS-DOS Programming
argv endp
_TEXT ends
msg2 db cr,lf
db 'dump: missing file name'
db cr,lf
msg2_len equ $-msg2
msg3 db cr,lf
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 168/813
10/16/2018 PCjs: Advanced MS-DOS Programming
msg4 db cr,lf
db 'dump: empty file'
db cr,lf
msg4_len equ $-msg4
_DATA ends
db 64 dup (?)
STACK ends
end dump
──────────────────────────────────────────────────────────────────────────
──────────────────────────────────────────────────────────────────────────
/*
DUMP.C Displays the binary contents of a file in
hex and ASCII on the standard output device.
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#define REC_SIZE 16 /* input file record size */
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 169/813
10/16/2018 PCjs: Advanced MS-DOS Programming
/*
Display record (16 bytes) in hex and ASCII on standard output
*/
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 170/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Subroutine Action
──────────────────────────────────────────────────────────────────────────
argc Returns the number of command-line arguments.
argv Returns the address and length of a particular command-line
argument.
w2a Converts a binary word (16 bits) into hex ASCII for output.
b2a Converts a binary byte (8 bits) into hex ASCII for output.
ascii Converts 4 bits into a single hex ASCII character.
──────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Chapter 9 Volumes and Directories
Each file in an MS-DOS system is uniquely identified by its name and its
location. The location, in turn, has two components: the logical drive
that contains the file and the directory on that drive where the filename
can be found.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 171/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Every disk potentially has two distinct kinds of directories: the root
directory and all other directories. The root directory is always present
and has a maximum number of entries, determined when the disk is
formatted; this number cannot be changed. The subdirectories of the root
directory, which may or may not be present on a given disk, can be nested
to any level and can grow to any size (Figure 9-1). This is the
hierarchical, or tree, directory structure referred to in earlier
chapters. Every directory has a name, except for the root directory, which
is designated by a single backslash (\) character.
MS-DOS keeps track of a "current drive" for the system and uses this drive
when a file specification does not include an explicit drive code.
Similarly, MS-DOS maintains a "current directory" for each logical drive.
You can select any particular directory on a drive by naming in order──
either from the root directory or relative to the current directory──the
directories that lead to its location in the tree structure. Such a list
of directories, separated by backslash delimiters, is called a path. When
a complete path from the root directory is prefixed by a logical drive
code and followed by a filename and extension, the resulting string is a
fully qualified filename and unambiguously specifies a file.
┌────────────┐
│ Drive │
│ identifier │
└─────┬──────┘
│
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 172/813
10/16/2018 PCjs: Advanced MS-DOS Programming
┌───────┴────────┐
│ Root directory │
│ (volume label) │
└─┬──┬──┬───┬──┬─┘
┌───────────────────┘ │ │ │ └───────────────────┐
│ ┌───────────┘ │ └───────────┐ │
┌────┴───┐ ┌────┴──────┐ ┌───┴────┐ ┌──────┴────┐ ┌───┴────┐
│ File A │ │ Directory │ │ File B │ │ Directory │ │ File C │
└────────┘ └─┬───────┬─┘ └────────┘ └─┬─────────┘ └─┬──────┘
│ │ │ │
│ │ │ │
┌─────┘ │ │ │
│ │ │ │
┌────┴──────┐ ┌──┴─────┐ ┌─────┴──┐ ┌───┴────┐
│ Directory │ │ File D │ │ File E │ │ File F │
└───────────┘ └────────┘ └────────┘ └────────┘
You can examine, select, create, and delete disk directories interactively
with the DIR, CHDIR (CD), MKDIR (MD), and RMDIR (RD) commands. You can
select a new current drive by entering the letter of the desired drive,
followed by a colon. MS-DOS provides the following Int 21H functions to
give application programs similar control over drives and directories:
Function Action
──────────────────────────────────────────────────────────────────────────
0EH Select current drive.
19H Get current drive.
39H Create directory.
3AH Remove directory.
3BH Select current directory.
47H Get current directory.
──────────────────────────────────────────────────────────────────────────
The two functions that deal with disk drives accept or return a binary
drive code──0 represents drive A, 1 represents drive B, and so on. This
differs from most other MS-DOS functions, which use 0 to indicate the
current drive, 1 for drive A, and so on.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 173/813
10/16/2018 PCjs: Advanced MS-DOS Programming
ASCIIZ string that describes the path to the desired directory. As with
the handle-based file open and create functions, the address of the ASCIIZ
string is passed in the DS:DX registers. On return, the carry flag is
clear if the function succeeds or set if the function failed, with an
error code in the AX register. The directory functions can fail for a
variety of reasons, but the most common cause of an error is that some
element of the indicated path does not exist.
The last function in the preceding list, Int 21H Function 47H, allows you
to obtain an ASCIIZ path for the current directory on the specified or
default drive. MS-DOS supplies the path string without the drive
identifier or a leading backslash. Int 21H Function 47H is most commonly
used with Int 21H Function 19H to build fully qualified filenames. Such
filenames are desirable because they remain valid if the user changes the
current drive or directory.
Searching Directories
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 174/813
10/16/2018 PCjs: Advanced MS-DOS Programming
A program can call the second type of search service, called "search for
next," only after a successful "search for first." If the file
specification that was originally passed to "search for first" included
wildcard characters and at least one matching file was present, the
program can call "search for next" as many times as necessary to find all
additional matching files. Like "search for first," "search for next"
returns information about the matched files in a buffer designated by the
requesting program. When it can find no more matching files, "search for
next" returns an error flag.
As with nearly every other operation, MS-DOS provides two parallel sets of
directory-searching services:
Searches that use normal FCBs find only normal files. Searches that use
extended FCBs, or the handle-type functions, can be qualified with file
attributes. The attribute bits relevant to searches are as follows:
Bit Significance
──────────────────────────────────────────────────────────────────────────
0 Read-only file
1 Hidden file
2 System file
3 Volume label
4 Directory
5 Archive needed (set when file modified)
──────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 175/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Both the FCB and handle directory-searching functions require that the
disk transfer area address be set (with Int 21H Function 1AH), before the
call to "search for first," to point to a working buffer for use by
MS-DOS. The DTA address should not be changed between calls to "search for
first" and "search for next." When it finds a matching file, MS-DOS places
the information about the file in the buffer and then inspects the buffer
on the next "search for next" call, to determine where to resume the
search. The format of the data returned in the buffer is different for the
FCB and handle functions, so read the detailed descriptions in Section 2
of this book, "MS-DOS Functions Reference," before attempting to interpret
the buffer contents.
Figures 9-2 and 9-3 provide equivalent examples of searches for all
files in a given directory that have the .ASM extension, one example using
the FCB directory functions (Int 21H Functions 11H and 12H) and the
other using the handle functions (Int 21H Functions 4EH and 4FH). (Both
programs use the handle write function with the standard output handle to
display the matched filenames, to avoid introducing tangential differences
in the listings.)
──────────────────────────────────────────────────────────────────────────
start: ; set DTA address for buffer
; used by search functions
mov dx,seg buff ; DS:DX = buffer address
mov ds,dx
mov dx,offset buff
mov ah,1ah ; function 1ah = search for first
int 21h ; transfer to MS-DOS
; search for first match...
mov dx,offset fcb ; DS:DX = FCB address
mov ah,11h ; function 11h = search for first
int 21h ; transfer to MS-DOS
or al,al ; any matches at all?
jnz exit ; no, quit
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 176/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 177/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
start: ; set DTA address for buffer
; used by search functions
mov dx,seg buff ; DS:DX = buffer address
mov ds,dx
mov dx,offset buff
mov ah,1ah ; function 1ah = search for first
int 21h ; transfer to MS-DOS
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 178/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
.
Moving Files
The rename file function that was added in MS-DOS version 2.0, Int 21H
Function 56H, has the little-advertised capability to move a file from
one directory to another. The function has two ASCIIZ parameters: the
"old" and "new" names for the file. If the old and new paths differ,
MS-DOS moves the file; if the filename or extension components differ,
MS-DOS renames the file. MS-DOS can carry out both of these actions in the
same function call.
Of course, the old and new directories must be on the same drive, because
the file's actual data is not moved at all; only the information that
describes the file is removed from one directory and placed in another
directory. Function 56H fails if the two ASCIIZ strings include different
logical-drive codes, if the file is read-only, or if a file with the same
name and location as the "new" filename already exists.
The FCB-based rename file service, Int 21H Function 17H, works only on
the current directory and cannot be used to move files.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 179/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Volume Labels
Support for volume labels was first added to MS-DOS in version 2.0. A
volume label is an optional name of from 1 to 11 characters that the user
assigns to a disk during a FORMAT operation. You can display a volume
label with the DIR, TREE, CHKDSK, or VOL command. Beginning with MS-DOS
version 3.0, you can use the LABEL command to add, display, or alter the
label after formatting. In MS-DOS version 4, the FORMAT program also
assigns a semi-random 32-bit binary ID to each disk it formats; you can
display this value, but you cannot change it.
Hence, volume labels do not take the place of the logical-drive identifier
and cannot be used as part of a pathname to identify a file. In fact, in
MS-DOS version 2, the system does not use volume labels internally at all.
In MS-DOS versions 3.0 and later, a disk driver can use volume labels to
detect whether the user has replaced a disk while a file is open; this use
is optional, however, and is not implemented in all systems.
■ When you create a volume label after a disk is formatted, MS-DOS always
places it in the root directory, regardless of the current directory.
■ A disk can contain only one volume label; attempts to create additional
volume labels (even with different names) will fail.
■ MS-DOS always carries out searches for volume labels in the root
directory, regardless of the current directory, and does not also
return all normal files.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 180/813
10/16/2018 PCjs: Advanced MS-DOS Programming
In MS-DOS versions 3.0 and later, you can create a volume label in the
expected manner, using Int 21H Function 3CH and an attribute of 8, and
you can use the handle-type "search for first" function (4EH) to obtain
an existing volume label for a logical drive (Figure 9-5). However, you
still must use extended FCBs to change a volume label.
──────────────────────────────────────────────────────────────────────────
buff db 64 dup (?) ; receives search results
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 181/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
──────────────────────────────────────────────────────────────────────────
──────────────────────────────────────────────────────────────────────────
buff db 64 dup (?) ; receives search results
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 182/813
10/16/2018 PCjs: Advanced MS-DOS Programming
2. MS-DOS then passes the requests for logical sectors to the disk
device's driver, which maps them onto actual physical addresses (head,
track, and sector). Disk drivers are extremely hardware dependent and
are always written in assembly language for maximum speed. In most
versions of MS-DOS, a driver for IBM-compatible floppy- and fixed-disk
drives is built into the MS-DOS BIOS module (IO.SYS) and is always
loaded during system initialization; you can install additional
drivers for non-IBM-compatible disk devices by including the
appropriate DEVICE directives in the CONFIG.SYS file.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 183/813
10/16/2018 PCjs: Advanced MS-DOS Programming
┌───────────────────────────────────────────────────────┐
│ Boot sector │
│ Reserved area │
├───────────────────────────────────────────────────────┤
│ File allocation table #1 │
├───────────────────────────────────────────────────────┤
│ Possible additional copies of FAT │
├───────────────────────────────────────────────────────┤
│ Root directory │
├───────────────────────────────────────────────────────┤
│ │
│ Files area │
│ │
└───────────────────────────────────────────────────────┘
Figure 10-1. Map of a typical MS-DOS logical volume. The boot sector
(logical sector 0) contains the OEM identification, BIOS parameter block
(BPB), and disk bootstrap. The remaining sectors are divided among an
optional reserved area, one or more copies of the file allocation table,
the root directory, and the files area.
Logical sector 0, known as the boot sector, contains all of the critical
information regarding the disk medium's characteristics (Figure 10-2).
The first byte in the sector is always an 80x86 jump instruction──either a
normal intrasegment JMP (opcode 0E9H) followed by a 16-bit displacement or
a "short" JMP (opcode 0EBH) followed by an 8-bit displacement and then by
an NOP (opcode 90H). If neither of these two JMP opcodes is present, the
disk has not been formatted or was not formatted for use with MS-DOS. (Of
course, the presence of the JMP opcode does not in itself ensure that the
disk has an MS-DOS format.)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 184/813
10/16/2018 PCjs: Advanced MS-DOS Programming
in this area with the name of the computer manufacturer and the
manufacturer's internal MS-DOS version number.
00H ┌───────────────────────────────────────────────┐
│ E9 XX XX or EB XX 90 │
03H ├───────────────────────────────────────────────┤
│ OEM name and version │
│ (8 bytes) │
OBH ├───────────────────────────────────────────────┤─┐
│ Bytes per sector (2 bytes) │ │
ODH ├───────────────────────────────────────────────┤ │
│ Sectors per allocation unit (1 byte) │ │
0EH ├───────────────────────────────────────────────┤ │
│ Reserved sectors, starting at 0 (2 bytes) │ │
10H ├───────────────────────────────────────────────┤ │
│ Number of FATs (1 byte) │ B
11H ├───────────────────────────────────────────────┤ P
│ Number of root-directory entries (2 bytes) │ B
13H ├───────────────────────────────────────────────┤ │
│ Total sectors in logical volume (2 bytes) │ │
15H ├───────────────────────────────────────────────┤ │ MS-DOS
│ Media descriptor byte │ │ version 2.0
16H ├───────────────────────────────────────────────┤ │
│ Number of sectors per FAT (2 bytes) │ │
18H ├───────────────────────────────────────────────┤═╡
│ Sectors per track (2 bytes) │ │
1AH ├───────────────────────────────────────────────┤ │
│ Number of heads (2 bytes) │ │ MS-DOS
1CH ├───────────────────────────────────────────────┤ │ version 3.0
│ Number of hidden sectors (4 bytes) │═╡
20H ├───────────────────────────────────────────────┤ │ MS-DOS
│ Total sectors in logical volume │ │ version 4.0
│ (MS-DOS 4.0 and volume size >32 MB) │ │
24H ├───────────────────────────────────────────────┤═╡
│ Physical drive number │ │
25H ├───────────────────────────────────────────────┤ │
│ Reserved │ │
26H ├───────────────────────────────────────────────┤ │
│ Extended boot signature record (29H) │ │ Additional
27H ├───────────────────────────────────────────────┤ │ MS-DOS 4.0
│ 32-bit binary volume ID │ │ information
2BH ├───────────────────────────────────────────────┤ │
│ Volume label (11 bytes) │ │
36H ├───────────────────────────────────────────────┤ │
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 185/813
10/16/2018 PCjs: Advanced MS-DOS Programming
│ Reserved (8 bytes) │ │
3EH ├───────────────────────────────────────────────┤─┘
│ Bootstrap │
└───────────────────────────────────────────────┘
Figure 10-2. Map of the boot sector of an MS-DOS disk. Note the JMP at
offset 0, the OEM identification field, the MS-DOS version 2 compatible
BIOS parameter block (bytes 0BH─17H), the three additional WORD fields for
MS-DOS version 3, the double-word number-of-sectors field and 32-bit
binary volume ID for MS-DOS version 4.0, and the bootstrap code.
The third major component of the boot sector is the BIOS parameter block
(BPB) in bytes 0BH through 17H. (Additional fields are present in MS-DOS
versions 3.0 and later.) This data structure describes the physical disk
characteristics and allows the device driver to calculate the proper
physical disk address for a given logical-sector number; it also contains
information that is used by MS-DOS and various system utilities to
calculate the address and size of each of the disk control areas (file
allocation tables and root directory).
The final element of the boot sector is the disk bootstrap routine. The
disk bootstrap is usually read into memory by the ROM bootstrap, which is
executed automatically when the computer is turned on. The ROM bootstrap
is usually just smart enough to home the head of the disk drive (move it
to track 0), read the first physical sector into RAM at a predetermined
location, and jump to it. The disk bootstrap is more sophisticated. It
calculates the physical disk address of the beginning of the files area,
reads the files containing the operating system into memory, and transfers
control to the BIOS module at location 0070:0000H. (See Chapter 2.)
Figures 10-3 and 10-4 show a partial hex dump and disassembly of a
PC-DOS 3.3 floppy-disk boot sector.
──────────────────────────────────────────────────────────────────────────
0 1 2 3 4 5 6 7 8 9 A B C D E F
0000 EB 34 90 49 42 4D 20 20 33 2E 33 00 02 02 01 00 .4.IBM 3.3.....
0010 02 70 00 D0 02 FD 02 00 09 00 02 00 00 00 00 00 .p..............
0020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12 ................
0030 00 00 00 00 01 00 FA 33 C0 8E D0 BC 00 7C 16 07 .......3.....|..
.
.
.
01C0 0D 0A 44 69 73 6B 20 42 6F 6F 74 20 66 61 69 6C ..Disk Boot fail
01D0 75 72 65 0D 0A 00 49 42 4D 42 49 4F 20 20 43 4F ure...IBMBIO CO
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 186/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 10-3. Partial hex dump of the boot sector (track 0, head 0, sector
1) of a PC-DOS version 3.3 floppy disk. This sector contains the OEM
identification, a copy of the BIOS parameter block describing the medium,
and the bootstrap routine that reads the BIOS into memory and transfers
control to it. See also Figures 10-2 and 10-4.
──────────────────────────────────────────────────────────────────────────
jmp $+54 ; jump to bootstrap
nop
The boot sector is actually part of a reserved area that can span from one
to several sectors. The reserved-sectors word in the BPB, at offset 0EH in
the boot sector, describes the size of this area. Remember that the number
in the BPB field includes the boot sector itself, so if the value is 1 (as
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 187/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The file allocation table (FAT) is divided into fields that correspond
directly to the assignable clusters on the disk. These fields are 12 bits
in MS-DOS versions 1 and 2 and may be either 12 bits or 16 bits in
versions 3.0 and later, depending on the size of the medium (12 bits if
the disk contains fewer than 4087 clusters, 16 bits otherwise).
The first two fields in the FAT are always reserved. On IBM-compatible
media, the first 8 bits of the first reserved FAT entry contain a copy of
the media descriptor byte, which is also found in the BPB in the boot
sector. The second, third, and (if applicable) fourth bytes, which
constitute the remainder of the first two reserved FAT fields, always
contain 0FFH. The currently defined IBM-format media descriptor bytes are
as follows:
MS-DOS version
where first
Descriptor Medium supported
──────────────────────────────────────────────────────────────────────────
0F0H 3.5" floppy disk, 2-sided, 18-sector 3.3
0F8H Fixed disk 2.0
0F9H 5.25" floppy disk, 2-sided, 15-sector 3.0
3.5" floppy disk, 2-sided, 9-sector 3.2
0FCH 5.25" floppy disk, 1-sided, 9-sector 2.0
0FDH 5.25" floppy disk, 2-sided, 9-sector 2.0
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 188/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The remainder of the FAT entries describe the use of their corresponding
disk clusters. The contents of the FAT fields are interpreted as follows:
Value Meaning
──────────────────────────────────────────────────────────────────────────
(0)000H Cluster available
(F)FF0─(F)FF6H Reserved cluster
(F)FF7H Bad cluster, if not part of chain
(F)FF8─(F)FFFH Last cluster of file
(X)XXX Next cluster in file
──────────────────────────────────────────────────────────────────────────
Each file's entry in a directory contains the number of the first cluster
assigned to that file, which is used as an entry point into the FAT. From
the entry point on, each FAT slot contains the cluster number of the next
cluster in the file, until a last-cluster mark is encountered.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 189/813
10/16/2018 PCjs: Advanced MS-DOS Programming
00H ┌──────────────────────────────┐
│ Filename │ Note 1
08H ├──────────────────────────────┤
│ Extension │
0BH ├──────────────────────────────┤
│ File attribute │ Note 2
0CH ├──────────────────────────────┤
│ Reserved │
16H ├──────────────────────────────┤
│ Time created or last updated │ Note 3
18H ├──────────────────────────────┤
│ Date created or last updated │ Note 4
1AH ├──────────────────────────────┤
│ Starting cluster │
1CH ├──────────────────────────────┤
│ File size, 4 bytes │ Note 5
20H └──────────────────────────────┘
──────────────────────────────────────────────────────────────────────────
Notes for Figure 10-5
1. The first byte of the filename field of a directory entry may
contain the following special information:
Value Meaning
────────────────────────────────────────────────────────────────────────
00H Directory entry has never been used; end of occupied
portion of directory.
05H First character of filename is actually E5H.
2EH Entry is an alias for the current or parent directory.
If the next byte is also 2EH, the cluster field
contains the cluster number of the parent directory
(zero if the parent directory is the root directory).
E5H File has been erased.
────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 190/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Bit Meaning
────────────────────────────────────────────────────────────────────────
0 Read-only; attempts to open file for write or to
delete file will fail.
1 Hidden file; excluded from normal searches.
2 System file; excluded from normal searches.
3 Volume label; can exist only in root directory.
4 Directory; excluded from normal searches.
5 Archive bit; set whenever file is modified.
6 Reserved.
7 Reserved.
────────────────────────────────────────────────────────────────────────
Bits Contents
────────────────────────────────────────────────────────────────────────
00H─04H Binary number of 2-second increments (0─29,
corresponding to 0─58 seconds)
05H─0AH Binary number of minutes (0─59)
0BH─0FH Binary number of hours (0─23)
────────────────────────────────────────────────────────────────────────
Bits Contents
────────────────────────────────────────────────────────────────────────
00H─04H Day of month (1─31)
05H─08H Month (1─12)
09H─0FH Year (relative to 1980)
────────────────────────────────────────────────────────────────────────
──────────────────────────────────────────────────────────────────────────
The root directory has a number of special properties. Its size and
position are fixed and are determined by the FORMAT program when a disk is
initialized. This information can be obtained from the boot sector's BPB.
If the disk is bootable, the first two entries in the root directory
always describe the files containing the MS-DOS BIOS and the MS-DOS
kernel. The disk bootstrap routine uses these entries to bring the
operating system into memory and start it up.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 191/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 10-6 shows a partial hex dump of the first sector of the root
directory on a bootable PC-DOS 3.3 floppy disk.
──────────────────────────────────────────────────────────────────────────
0 1 2 3 4 5 6 7 8 9 A B C D E F
0000 49 42 4D 42 49 4F 20 20 43 4F 4D 27 00 00 00 00 IBMBIO COM'....
0010 00 00 00 00 00 00 00 60 72 0E 02 00 54 56 00 00 .......'r...TV..
0020 49 42 4D 44 4F 53 20 20 43 4F 4D 27 00 00 00 00 IBMDOS COM'....
0030 00 00 00 00 00 00 00 60 71 0E 18 00 CF 75 00 00 .......'q....u..
0040 43 4F 4D 4D 41 4E 44 20 43 4F 4D 20 00 00 00 00 COMMAND COM ....
0050 00 00 00 00 00 00 00 60 71 0E 36 00 DB 62 00 00 .......'q.6..b..
0060 42 4F 4F 54 44 49 53 4B 20 20 20 28 00 00 00 00 BOOTDISK (....
0070 00 00 00 00 00 00 A1 00 21 00 00 00 00 00 00 00 ........!.......
0080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
.
.
.
──────────────────────────────────────────────────────────────────────────
Figure 10-6. Partial hex dump of the first sector of the root directory
for a PC-DOS 3.3 disk containing the three system files and a volume
label.
The remainder of the volume after the root directory is known as the files
area. MS-DOS views the sectors in this area as a pool of clusters, each
containing one or more logical sectors, depending on the disk format. Each
cluster has a corresponding entry in the FAT that describes its current
use: available, reserved, assigned to a file, or unusable (because of
defects in the medium). Because the first two fields of the FAT are
reserved, the first cluster in the files area is assigned the number 2.
When a file is extended under versions 1 and 2, MS-DOS searches the FAT
from the beginning until it finds a free cluster (designated by a zero FAT
field); it then changes that FAT field to a last-cluster mark and updates
the previous last cluster of the file's chain to point to the new last
cluster. Under versions 3.0 and later, however, MS-DOS searches the FAT
from the most recently allocated cluster; this reduces file fragmentation
and improves overall access times.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 192/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Directories other than the root directory are simply a special type of
file. Their storage is allocated from the files area, and their contents
are 32-byte entries──in the same format as those used in the root
directory──that describe files or other directories. Directory entries
that describe other directories contain an attribute byte with bit 4 set,
zero in the file-length field, and the date and time that the directory
was created (Figure 10-7). The first cluster field points, of course, to
the first cluster in the files area that belongs to the directory. (The
directory's other clusters can be found only by tracing through the FAT.)
All directories except the root directory contain two special directory
entries with the names . and ... MS-DOS puts these entries in place when
it creates a directory, and they cannot be deleted. The . entry is an
alias for the current directory; its cluster field points to the cluster
in which it is found. The .. entry is an alias for the directory's parent
(the directory immediately above it in the tree structure); its cluster
field points to the first cluster of the parent directory. If the parent
is the root directory, the cluster field of the .. entry contains zero
(Figure 10-8).
──────────────────────────────────────────────────────────────────────────
.
.
.
0080 4D 59 44 49 52 20 20 20 20 20 20 10 00 00 00 00 MYDIR .....
0090 00 00 00 00 00 00 87 9A 9B 0A 2A 00 00 00 00 00 ..........*.....
.
.
.
──────────────────────────────────────────────────────────────────────────
Figure 10-7. Extract from the root directory of an MS-DOS disk, showing
the entry for a subdirectory named MYDIR. Bit 4 in the attribute byte is
set, the cluster field points to the first cluster of the subdirectory
file, the date and time stamps are valid, but the file length is zero.
──────────────────────────────────────────────────────────────────────────
0 1 2 3 4 5 6 7 8 9 A B C D E F
0000 2E 20 20 20 20 20 20 20 20 20 20 10 00 00 00 00 . .....
0010 00 00 00 00 00 00 87 9A 9B 0A 2A 00 00 00 00 00 ..........*.....
0020 2E 2E 20 20 20 20 20 20 20 20 20 10 00 00 00 00 .. .....
0030 00 00 00 00 00 00 87 9A 9B 0A 00 00 00 00 00 00 ................
0040 4D 59 46 49 4C 45 20 20 44 41 54 20 00 00 00 00 MYFILE DAT ....
0050 00 00 00 00 00 00 98 9A 9B 0A 2B 00 15 00 00 00 ..........+.....
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 193/813
10/16/2018 PCjs: Advanced MS-DOS Programming
0060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
.
.
.
──────────────────────────────────────────────────────────────────────────
Figure 10-8. Hex dump of the first block of the directory MYDIR. Note the
. and .. entries. This directory contains exactly one file, MYFILE.DAT.
Now that we understand how the disk is structured, let's see how we can
use this knowledge to find a FAT position from a cluster number.
1. Use the directory entry to find the starting cluster of the file in
question.
3. Use the integral part of the product as the offset into the FAT and
move the word at that offset into a register. Remember that a FAT
position can span a physical disk-sector boundary.
6. If the result is a value from 0FF8H through 0FFFH, the file has no
more clusters. Otherwise, the result is the number of the next cluster
in the file.
On disks with at least 4087 clusters formatted under MS-DOS version 3.0 or
later, the FAT entries use 16 bits, and the extraction of a cluster number
from the table is much simpler:
1. Use the directory entry to find the starting cluster of the file in
question.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 194/813
10/16/2018 PCjs: Advanced MS-DOS Programming
3. Use the product as the offset into the FAT and move the word at that
offset into a register.
4. If the result is a value from 0FFF8H through 0FFFFH, the file has no
more clusters. Otherwise, the result is the number of the next cluster
in the file.
As an example, let's work out the disk location of the file IBMBIO.COM,
which is the first entry in the directory shown in Figure 10-6. First, we
need some information from the BPB, which is in the boot sector of the
medium. (See Figures 10-3 and 10-4.) The BPB tells us that there are
■ 2 FATs
Length Sector
Area (sectors) numbers
──────────────────────────────────────────────────────────────────────────
Boot sector 1 00H
2 FATs * 2 sectors/FAT 4 01H─04H
112 directory entries 7 05H─0BH
*32 bytes/entry
/512 bytes/sector
Total sectors occupied by bootstrap, FATs, and 12
root directory
──────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 195/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The word at offset 01AH in the directory entry for IBMBIO.COM gives us the
starting cluster number for that file: cluster 2. To find the
logical-sector number of the first block in the file, we can follow the
procedure given earlier:
1. Cluster number - 2 = 2 - 2 = 0.
Now let's trace IBMBIO.COM's chain through the file allocation table
(Figures 10-9 and 10-10). This will be a little tedious, but a detailed
understanding of the process is crucial. In an actual program, we would
first read the boot sector using Int 25H, then calculate the address of
the FAT from the contents of the BPB, and finally read the FAT into
memory, again using Int 25H.
From IBMBIO.COM's directory entry, we already know that the first cluster
in the file is cluster 2. To examine that cluster's entry in the FAT, we
multiply the cluster number by 1.5, which gives 0003H as the FAT offset,
and fetch the word at that offset (which contains 4003H). Because the
product of the cluster and 1.5 is a whole number, we AND the word from the
FAT with 0FFFH, yielding the number 3, which is the number of the second
cluster assigned to the file.
──────────────────────────────────────────────────────────────────────────
0 1 2 3 4 5 6 7 8 9 A B C D E F
0000 FD FF FF 03 40 00 05 60 00 07 80 00 09 A0 00 0B ....@..'........
0010 C0 00 0D E0 00 0F 00 01 11 20 01 13 40 01 15 60 ......... ..@..'
0020 01 17 F0 FF 19 A0 01 1B C0 01 1D E0 01 1F 00 02 ................
0030 21 20 02 23 40 02 25 60 02 27 80 02 29 A0 02 2B ! .#@.%'.'..)..+
.
.
.
──────────────────────────────────────────────────────────────────────────
Figure 10-9. Hex dump of the first block of the file allocation table
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 196/813
10/16/2018 PCjs: Advanced MS-DOS Programming
(track 0, head 0, sector 2) for the PC-DOS 3.3 disk whose root directory
is shown in Figure 10-6. Notice that the first byte of the FAT contains
the media descriptor byte for a 5.25-inch, 2-sided, 9-sector floppy disk.
──────────────────────────────────────────────────────────────────────────
getfat proc near ; extracts the FAT field
; for a given cluster
; call AX = cluster #
; DS:BX = addr of FAT
; returns AX = FAT field
; other registers unchanged
To examine cluster 3's entry in the FAT, we multiply 3 by 1.5, which gives
4.5, and fetch the word at offset 0004H (which contains 0040H). Because
the product of 3 and 1.5 is not a whole number, we shift the word right
4 bits, yielding the number 4, which is the number of the third cluster
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 197/813
10/16/2018 PCjs: Advanced MS-DOS Programming
assigned to IBMBIO.COM.
In this manner, we can follow the chain through the FAT until we come to a
cluster (number 23, in this case) whose FAT entry contains the value
0FFFH, which is an end-of-file marker in FATs with 12-bit entries.
Fixed-Disk Partitions
Fixed disks have another layer of organization beyond the logical volume
structure already discussed: partitions. The FDISK utility divides a fixed
disk into one or more partitions consisting of an integral number of
cylinders. Each partition can contain an independent file system and, for
that matter, its own copy of an operating system.
Bytes Contents
──────────────────────────────────────────────────────────────────────────
000─1BDH Reserved
1BE─1CDH Partition #1 descriptor
1CE─1DDH Partition #2 descriptor
1DE─1EDH Partition #3 descriptor
1EE─1FDH Partition #4 descriptor
1FE─1FFH Signature word (AA55H)
──────────────────────────────────────────────────────────────────────────
The partition descriptors in the master boot record define the size,
location, and type of each partition, as follows:
Byte(s) Contents
──────────────────────────────────────────────────────────────────────────
00H Active flag (0 = not bootable, 80H = bootable)
01H Starting head
02H─03H Starting cylinder/sector
04H Partition type
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 198/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 10-11 contains a partial hex dump of a master block from a fixed
disk formatted under PC-DOS version 3.3. This dump illustrates the
partition descriptors for a normal partition with a 16-bit FAT and an
extended partition.
──────────────────────────────────────────────────────────────────────────
0000 .
.
.
0180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 01
01C0 01 00 04 04 D1 02 11 00 00 00 EE FF 00 00 00 00
01D0 C1 04 05 04 D1 FD 54 00 01 00 02 53 00 00 00 00
01E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA
──────────────────────────────────────────────────────────────────────────
Figure 10-11. A partial hex dump of a master block from a fixed disk
formatted under PC-DOS version 3.3. This disk contains two partitions. The
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 199/813
10/16/2018 PCjs: Advanced MS-DOS Programming
first partition has a 16-bit FAT and is marked "active" to indicate that
it contains a bootable copy of PC-DOS. The second partition is an
"extended" partition. The third and fourth partition entries are not used
in this example.
────────────────────────────────────────────────────────────────────────────
Chapter 11 Memory Management
The RAM area under the control of MS-DOS is divided into two major
sections:
Function Action
──────────────────────────────────────────────────────────────────────────
48H Allocate memory block.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 200/813
10/16/2018 PCjs: Advanced MS-DOS Programming
MS-DOS itself uses these functions when loading a program from disk at the
request of COMMAND.COM or another program. The EXEC function, which is the
MS-DOS program loader, calls Int 21H Function 48H to allocate a memory
block for the loaded program's environment and another for the program
itself and its program segment prefix. It then reads the program from the
disk into the assigned memory area. When the program terminates, MS-DOS
calls Int 21H Function 49H to release all memory owned by the program.
Although many MS-DOS application programs simply assume they own all
memory, this assumption is a relic of MS-DOS version 1 (and CP/M), which
could support only one active process at a time. Well-behaved MS-DOS
programs take pains to modify only memory that they actually own and to
release any memory that they don't need.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 201/813
10/16/2018 PCjs: Advanced MS-DOS Programming
MS-DOS always allocates all of the largest available memory block in the
TPA to programs loaded from .COM (memory-image) files. Because .COM
programs contain no file header that can pass segment and memory-use
information to MS-DOS, MS-DOS simply assumes the worst case and gives such
a program everything. MS-DOS will load the program as long as there is an
available memory block as large as the size of the file plus 256 bytes for
the PSP and 2 bytes for the stack. The .COM program, when it receives
control, must determine whether enough memory is available to carry out
its functions.
When loading a .EXE file, MS-DOS first attempts to allocate the number of
paragraphs in MAX_ALLOC plus the number of paragraphs required by the
program itself. If that much memory is not available, MS-DOS assigns all
of the largest available block to the program, provided that this is at
least the amount specified by MIN_ALLOC plus the size of the program
image. If that condition is not satisfied, the program cannot be executed.
After a .COM or .EXE program is loaded and running, it can use Int 21H
Function 4AH (Resize Memory Block) to release all the memory it does not
immediately need. This is conveniently done right after the program
receives control from MS-DOS, by calling the resize function with the
segment of the program's PSP in the ES register and the number of
paragraphs that the program requires to run in the BX register (Figure
11-1).
──────────────────────────────────────────────────────────────────────────
.
.
.
org 100h
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 202/813
10/16/2018 PCjs: Advanced MS-DOS Programming
;
release extra memory...
mov ah,4ah ;
function 4Ah =
;
resize memory block
;
BX = paragraphs to keep
mov bx,(offset stk - offset main + 10FH) / 16
int 21h ; transfer to MS-DOS
jc error ; jump if resize failed
.
.
.
main endp
.
.
.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 203/813
10/16/2018 PCjs: Advanced MS-DOS Programming
area and clears the carry flag (0), indicating that the function was
successful.
When the MS-DOS memory manager is searching the chain of arena headers to
satisfy a memory-allocation request, it can use one of the following
strategies:
■ First fit: Use the arena entry at the lowest address that is large
enough to satisfy the request.
■ Best fit: Use the smallest arena entry that will satisfy the request,
regardless of its location.
■ Last fit: Use the arena entry at the highest address that is large
enough to satisfy the request.
──────────────────────────────────────────────────────────────────────────
.
.
.
mov ah,48h ; function 48h = allocate mem bl
mov bx,0800h ; 800h paragraphs = 32 KB
int 21h ; transfer to MS-DOS
jc error ; jump if allocation failed
mov buff_seg,ax ; save segment of allocated bloc
.
.
.
mov es,buff_seg ; ES:DI = address of block
xor di,di
mov cx,08000h ; store 32,768 bytes
mov al,0ffh ; fill buffer with -1s
cld
rep stosb ; now perform fast fill
.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 204/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
mov cx,08000h ; length to write, bytes
mov bx,handle ; handle for prev opened file
push ds ; save our data segment
mov ds,buff_seg ; let DS:DX = buffer address
mov dx,0
mov ah,40h ; function 40h = write
int 21h ; transfer to MS-DOS
pop ds ; restore our data segment
jc error ; jump if write failed
.
.
.
mov es,buff_seg ; ES = seg of prev allocated blo
mov ah,49h ; function 49h = release mem blo
int 21h ; transfer to MS-DOS
jc error ; jump if release failed
.
error: .
.
handle dw 0 ; file handle
buff_seg dw 0 ; segment of allocated block
.
.
.
──────────────────────────────────────────────────────────────────────────
If the arena entry selected is larger than the size requested, MS-DOS
divides it into two parts: one block of the size requested, which is
assigned to the program that called Int 21H Function 48H, and an unowned
block containing the remaining memory.
The default MS-DOS allocation strategy is first fit. However, under MS-DOS
versions 3.0 and later, an application program can change the strategy
with Int 21H Function 58H.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 205/813
10/16/2018 PCjs: Advanced MS-DOS Programming
terminates.
Arena Headers
MS-DOS inspects the chain of arena headers whenever the program requests a
memory-block allocation, modification, or release function, or when a
program is EXEC'd or terminated. If any of the blocks appear to be
corrupted or if the chain is broken, MS-DOS displays the dreaded message
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 206/813
10/16/2018 PCjs: Advanced MS-DOS Programming
arena header #3. The highest arena header (#4) controls all of the
remaining TPA that has not been allocated to any program.
When the IBM Personal Computer and MS-DOS were first released, the 640 KB
limit that IBM placed on the amount of RAM that could be directly managed
by MS-DOS seemed almost unimaginably huge. But as MS-DOS has grown in both
size and capabilities and the popular applications have become more
powerful, that 640 KB has begun to seem a bit crowded. Although personal
computers based on the 80286 and 80386 have the potential to manage up to
16 megabytes of RAM under operating systems such as MS OS/2 and XENIX,
this is little comfort to the millions of users of 8086/8088-based
computers and MS-DOS.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 207/813
10/16/2018 PCjs: Advanced MS-DOS Programming
which was designed to head off rapid obsolescence of the older PCs because
of limited memory. Shortly afterward, Microsoft announced that it would
support the EMS and would enhance Microsoft Windows to use the memory made
available by EMS hardware and software. EMS versions 3.2 and 4.0, released
in fall 1985 and summer 1987, expanded support for multitasking operating
systems.
The LIM EMS (as it is usually known) has been an enormous success. EMS
memory boards are available from scores of manufacturers, and "EMS-aware"
software──especially spreadsheets, disk caches, and terminate-and-stay-
resident utilities──has become the rule rather than the exception.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 208/813
10/16/2018 PCjs: Advanced MS-DOS Programming
An application program can use either of two methods to test for the
existence of the Expanded Memory Manager:
■ Issue an open request (Int 21H Function 3DH) using the guaranteed
device name of the EMM driver: EMMXXXX0. If the open function succeeds,
either the driver is present or a file with the same name
coincidentally exists on the default disk drive. To rule out the
latter, the application can use IOCTL (Int 21H Function 44H)
subfunctions 00H and 07H to ensure that EMM is present. In either case,
the application should then use Int 21H Function 3EH to close the
handle that was obtained from the open function, so that the handle can
be reused for another file or device.
■ Use the address that is found in the Int 67H vector to inspect the
device header of the presumed EMM. Interrupt handlers and device
drivers must use this method. If the EMM is present, the name field at
offset 0AH of the device header contains the string EMMXXXX0. This
approach is nearly foolproof and avoids the relatively high overhead of
an MS-DOS open function. However, it is somewhat less well behaved
because it involves inspection of memory that does not belong to the
application.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 209/813
10/16/2018 PCjs: Advanced MS-DOS Programming
These two methods of testing for the existence of the Expanded Memory
Manager are illustrated in Figures 11-4 and 11-5.
──────────────────────────────────────────────────────────────────────────
.
.
.
; attempt to "open" EMM...
mov dx,seg emm_name ; DS:DX = address of name
mov ds,dx ; of Expanded Memory Manager
mov dx,offset emm_name
mov ax,3d00h ; function 3dh, mode = 00h
; = open, read only
int 21h ; transfer to MS-DOS
jc error ; jump if open failed
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 210/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 11-4. Testing for the Expanded Memory Manager by means of the
MS-DOS open and IOCTL functions.
──────────────────────────────────────────────────────────────────────────
emm_int equ 67h ; Expanded Memory Manager
; software interrupt
.
.
.
; first fetch contents of
; EMM interrupt vector...
mov al,emm_int ; AL = EMM int number
mov ah,35h ; function 35h = get vector
int 21h ; transfer to MS-DOS
; now ES:BX = handler address
emm_name db 'EMMXXXX0'
; guaranteed device name for
; Expanded Memory Manager
──────────────────────────────────────────────────────────────────────────
Figure 11-5. Testing for the Expanded Memory Manager by inspection of the
name field in the driver's device header.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 211/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
mov ah,function ; AH determines service type
. ; load other registers with
. ; values specific to the
. ; requested service
int 67h
──────────────────────────────────────────────────────────────────────────
Upon return from an EMM function, the AH register contains zero if the
function was successful; otherwise, it contains an error code with the
most significant bit set (Figures 11-6 and 11-7). Other values are
typically returned in the AL and BX registers or in a user-specified
buffer.
╓┌─┌──────────────────┌──────────────────────────────────────────────────────╖
Error code Meaning
──────────────────────────────────────────────────────────────────────────
00H Function successful.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 212/813
10/16/2018 PCjs: Advanced MS-DOS Programming
0─3).
Figure 11-6. Expanded Memory Manager error codes common to EMS versions
3.0, 3.2, and 4.0. After a call to EMM, the AH register contains zero if
the function was successful or an error code in the range 80H through 8FH
if the function failed.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 213/813
10/16/2018 PCjs: Advanced MS-DOS Programming
╓┌─┌──────────────────┌──────────────────────────────────────────────────────╖
Error code Meaning
──────────────────────────────────────────────────────────────────────────
Error code Meaning
──────────────────────────────────────────────────────────────────────────
90H Attribute type not defined.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 214/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 11-7. Expanded Memory Manager error codes unique to EMS version
4.0. Most of these errors are related to the EMS functions for use by
operating systems and would not normally be encountered by application
programs.
An application program that uses expanded memory should regard that memory
as a system resource, like a file or a device, and employ only the
documented EMM services to allocate, access, and release expanded-memory
pages. Such a program can use the following general strategy:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 215/813
10/16/2018 PCjs: Advanced MS-DOS Programming
3. Check the version number of EMM with EMS Function 46H, to ensure that
all services the application will request are available.
4. Obtain the segment of the page frame used by EMM with EMS Function
41H.
An interrupt handler or device driver that uses EMS follows the same
general procedure outlined in steps 1 through 8, with a few minor
variations. It may need to acquire an EMS handle and allocate pages before
the operating system is fully functional; in particular, you cannot assume
that the MS-DOS Open File or Device, IOCTL, and Get Interrupt Vector
functions are available. Thus, such a handler or driver must use a
modified version of the "get interrupt vector" technique (Figure 11-5) to
test for the existence of EMM, fetching the contents of the Int 67H vector
directly.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 216/813
10/16/2018 PCjs: Advanced MS-DOS Programming
be disturbed.
The EMM relies on the good behavior of application software to avoid the
corruption of expanded memory. If several applications that use expanded
memory are running under a multitasking manager such as Microsoft Windows
and one or more of them does not abide strictly by EMM conventions, the
data of some or all of the applications may be destroyed.
──────────────────────────────────────────────────────────────────────────
.
.
.
mov ah,40h ; test EMM status
int 67h
or ah,ah
jnz error ; jump if bad status from EMM
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 217/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
. ; now we are ready for other
. ; processing using EMM pages
.
; map in EMS memory page...
mov bx,log_page ; BX <- EMS logical page number
mov al,phys_page ; AL <- EMS physical page (0-3)
mov dx,emm_handle ; EMM handle for our pages
mov ah,44h ; function 44h = map EMS page
int 67h
or ah,ah
jnz error ; jump if mapping error
.
.
. ; program ready to terminate,
; give up allocated EMM pages...
mov dx,emm_handle ; handle for our pages
mov ah,45h ; EMS function 45h = release pages
int 67h
or ah,ah
jnz error ; jump if release failed
.
.
.
──────────────────────────────────────────────────────────────────────────
Extended Memory
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 218/813
10/16/2018 PCjs: Advanced MS-DOS Programming
runs in real mode on an 80286 or 80386, and programs running under its
control cannot ordinarily execute from extended memory or even address
that memory for storage of data. However, the ROM BIOS contains two
routines that allow real-mode programs restricted access to extended
memory:
You should use these ROM BIOS routines with caution. Data stored in
extended memory is, of course, volatile; it is lost if the machine is
turned off. The transfer of data to or from extended memory involves a
switch from real mode to protected mode and back, which is a relatively
slow process on 80286-based machines; in some cases it is only marginally
faster than actually reading the data from a fixed disk. In addition,
programs that use the ROM BIOS extended-memory functions are not
compatible with the MS-DOS compatibility mode of MS OS/2.
Finally, a major deficit in these ROM BIOS functions is that they do not
make any attempt to arbitrate between two or more programs or drivers that
are using extended memory for temporary storage. For example, if an
application program and an installed RAMdisk driver attempt to put data in
the same area of extended memory, no error will be returned to either
program, but the data of one or both may be destroyed.
──────────────────────────────────────────────────────────────────────────
bmdt db 30h dup (0) ; block move descriptor table
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 219/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
.
.
.
getblk proc near ; transfer block from extended
; memory to real memory
; call with
; DX:AX = source linear 32-bit
; extended-memory address
; DS:BX = segment and offset
; destination address
; CX = length in bytes
; ES:SI = block move descriptor
; table
; returns
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 220/813
10/16/2018 PCjs: Advanced MS-DOS Programming
; AH = 0 if transfer OK
getblk endp
putblk proc near ; transfer block from real
; memory to extended memory
; call with
; DX:AX = dest linear 32-bit
; extended-memory address
; DS:BX = segment and offset
; source address
; CX = length in bytes
; ES:SI = block move descriptor
; table
; returns
; AH = 0 if transfer OK
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 221/813
10/16/2018 PCjs: Advanced MS-DOS Programming
mov es:[si+18h],cx
putblk endp
──────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Chapter 12 The EXEC Function
The MS-DOS EXEC function (Int 21H Function 4BH) allows a program (called
the parent) to load any other program (called the child) from a storage
device, execute it, and then regain control when the child program is
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 222/813
10/16/2018 PCjs: Advanced MS-DOS Programming
finished.
MS-DOS suspends execution of the parent program until the child program
terminates. When the child program finishes its work, it can pass an exit
code back to the parent, indicating whether it encountered any errors. It
can also, in turn, load other programs, and so on through many levels of
control, until the system runs out of memory.
The MS-DOS command interpreter, COMMAND.COM, uses the EXEC function to run
its external commands and other application programs. Many popular
commercial programs, such as database managers and word processors, use
EXEC to run other programs (spelling checkers, for example) or to load a
second copy of COMMAND.COM, thereby allowing the user to list directories
or copy and rename files without closing all the application files and
stopping the main work in progress. EXEC can also be used to load program
overlay segments, although this use is uncommon.
In order for a parent program to use the EXEC function to load a child
program, sufficient unallocated memory must be available in the transient
program area.
When the parent itself was loaded, MS-DOS allocated it a variable amount
of memory, depending upon its original file type──.COM or .EXE──and any
other information that was available to the loader. (See Chapter 11 for
further details.) Because the operating system has no foolproof way of
predicting how much memory any given program will require, it generally
allocates far more memory to a program than is really necessary.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 223/813
10/16/2018 PCjs: Advanced MS-DOS Programming
prefix of the program releasing memory and the BX register containing the
number of paragraphs of memory to retain for that program. (See Figure
11-1 for an example.)
──────────────────────────────────────────────────────────────────────────
WARNING
A .COM program must move its stack to a safe area if it is reducing its
memory allocation to less than 64 KB.
──────────────────────────────────────────────────────────────────────────
To load and execute a child program, the parent must execute an Int 21H
with the registers set up as follows:
AH = 4BH
AL = 00H (subfunction to load child program)
DS:DX = segment:offset of pathname for child program
ES:BX = segment:offset of parameter block
The name of the program to be run, which the calling program provides to
the EXEC function, must be an unambiguous file specification (no wildcard
characters) and must include an explicit .COM or .EXE extension. If the
path and disk drive are not supplied in the program name, MS-DOS uses the
current directory and default disk drive. (The sequential search for .COM,
.EXE, and .BAT files in all the locations listed in the PATH variable is
not a function of EXEC, but rather of the internal logic of COMMAND.COM.)
You cannot EXEC a batch file directly; instead, you must EXEC a copy of
COMMAND.COM and pass the name of the batch file in the command tail, along
with the /C switch.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 224/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The space reserved in the parameter block for the address of the
environment block is only 2 bytes and holds a segment address. The
remaining three addresses are all double-word addresses; that is, they are
4 bytes, with the offset in the first 2 bytes and the segment address in
the last 2 bytes.
Each program that the EXEC function loads inherits a data structure called
an environment block from its parent. The pointer to the segment of the
block is at offset 002CH in the PSP. The environment block holds certain
information used by the system's command interpreter (usually COMMAND.COM)
and may also hold information to be used by transient programs. It has no
effect on the operation of the operating system proper.
The environment block for any given program is static, implying that if
more than one generation of child programs is resident in RAM, each one
will have a distinct and separate copy of the environment block.
Furthermore, the environment block for a program that terminates and stays
resident is not updated by subsequent PATH and SET commands.
You will find more details about the environment block later in this
chapter.
MS-DOS copies the command tail into the child program's PSP at offset
0080H, as described in Chapter 3. The information takes the form of a
count byte, followed by a string of ASCII characters, terminated by a
carriage return; the carriage return is not included in the count.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 225/813
10/16/2018 PCjs: Advanced MS-DOS Programming
the same information that would be present if the program had been run by
a direct user command at the MS-DOS prompt. EXEC ignores any
I/O-redirection parameters placed in the command tail; the parent program
must provide for redirection of the standard devices before the EXEC
call is made.
MS-DOS copies the two default file control blocks pointed to by the EXEC
parameter block into the child program's PSP at offsets 005CH and 006CH.
To emulate the function of COMMAND.COM from the child program's point of
view, the parent program should use Int 21H Function 29H (the system
parse-filename service) to parse the first two parameters of the command
tail into the default file control blocks before invoking the EXEC
function.
File control blocks are not much use under MS-DOS versions 2 and 3,
because they do not support the hierarchical file structure, but some
application programs do inspect them as a quick way to get at the first
two switches or other parameters in the command tail. Chapter 8 discusses
file control blocks in more detail.
Finally, the parent can use Int 21H Function 4DH to obtain the
termination type and return code of the child program.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 226/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 12-1 summarizes the calling convention for function 4BH. Figure
12-2 shows a skeleton of a typical EXEC call. This particular example
uses the EXEC function to load and run the MS-DOS utility CHKDSK.COM. The
SHELL.ASM program listing later in this chapter (Figure 12-5) presents a
more complete example that includes the use of Int 21H Function 4AH to
free unneeded memory.
──────────────────────────────────────────────────────────────────────────
Called with:
AH = 4BH
AL = function type
00 = load and execute program
03 = load overlay
ES:BX = segment:offset of parameter block
DS:DX = segment:offset of program specification
Returns:
If call succeeded
Carry flag clear. In MS-DOS version 2, all registers except for CS:IP may
be destroyed. In MS-DOS versions 3.0 and later, registers are preserved in
the usual fashion.
If call failed
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 227/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If AL = 3 (load overlay)
──────────────────────────────────────────────────────────────────────────
Figure 12-1. Calling convention for the EXEC function (Int 21H Function
4BH).
──────────────────────────────────────────────────────────────────────────
cr egu 0dh ; ASCII carriage return
.
.
.
mov stkseg,ss ; save stack pointer
mov stkptr,sp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 228/813
10/16/2018 PCjs: Advanced MS-DOS Programming
envir ends
──────────────────────────────────────────────────────────────────────────
Figure 12-2. A brief example of the use of the MS-DOS EXEC call, with all
necessary variables and command blocks. Note the protection of the
registers for MS-DOS version 2 and the masking of interrupts during
loading of SS:SP to circumvent a bug in some early 8088 CPUs.
NAME=PARAMETER
An additional zero byte (Figure 12-3) indicates the end of the entire set
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 229/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0000 43 4F 4D 53 50 45 43 3D 43 3A 5C 43 4F 4D 4D 41 COMSPEC=C:\COMMA
0010 4E 44 2E 43 4F 4D 00 50 52 4F 4D 50 54 3D 24 70 NDcom.PROMPT=$p
0020 24 5F 24 64 20 20 20 24 74 24 68 24 68 24 68 24 $_$d $t$h$h$h$
0030 68 24 68 24 68 20 24 71 24 71 24 67 00 50 41 54 h$h$h $q$q$g.PAT
0040 48 3D 43 3A 5C 53 59 53 54 45 4D 3B 43 3A 5C 41 H=C:\SYSTEM;C:\A
0050 53 4D 3B 43 3A 5C 57 53 3B 43 3A 5C 45 54 48 45 SM;C:\WS;C:\ETHE
0060 52 4E 45 54 3B 43 3A 5C 46 4F 52 54 48 5C 50 43 RNET;C:\FORTH\PC
0070 33 31 3B 00 00 01 00 43 3A 5C 46 4F 52 54 48 5C 31;....C:\FORTH\
0080 50 43 33 31 5C 46 4F 52 54 48 2E 43 4F 4D 00 20 PC31\FORTH.COM.
──────────────────────────────────────────────────────────────────────────
COMSPEC=variable
PATH=variable
PROMPT=variable
MS-DOS places these three strings into the environment block at system
initialization, during the interpretation of SHELL, PATH, and PROMPT
directives in the CONFIG.SYS and AUTOEXEC.BAT files. The strings tell the
MS-DOS command interpreter, COMMAND.COM, the location of its executable
file (to enable it to reload the transient portion), where to search for
executable external commands or program files, and the format of the user
prompt.
You can add other strings to the environment block, either interactively
or in batch files, with the SET command. Transient programs can use these
strings for informational purposes. For example, the Microsoft C Compiler
looks in the environment block for INCLUDE, LIB, and TMP strings to tell
it where to find its #include files and library files and where to build
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 230/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
/*
SHELL.C Simple extendable command interpreter
for MS-DOS versions 2.0 and later
Usage: C>SHELL
*/
#include <stdio.h>
#include <process.h>
#include <stdlib.h>
#include <signal.h>
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 231/813
10/16/2018 PCjs: Advanced MS-DOS Programming
} commands[] =
{ "CLS", cls_cmd,
"DOS", dos_cmd,
"EXIT", exit_cmd, };
/*
Try to match user's command with intrinsic command
table. If a match is found, run the associated routine
and return true; else return false.
*/
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 232/813
10/16/2018 PCjs: Advanced MS-DOS Programming
/*
Process an extrinsic command by passing it
to an EXEC'd copy of COMMAND.COM.
*/
/*
Issue prompt, get user's command from standard input,
fold it to uppercase.
*/
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 233/813
10/16/2018 PCjs: Advanced MS-DOS Programming
/*
Get the full path and file specification for COMMAND.COM
from the COMSPEC variable in the environment.
*/
if(buffer[0] == NULL)
{
fputs("\nNo COMSPEC in environment\n", stderr);
exit(1);
}
}
/*
This Ctrl-C handler keeps SHELL from losing control.
It just reissues the prompt and returns.
*/
void break_handler(void)
{
signal(SIGINT, break_handler); /* reset handler */
printf("\nsh: "); /* display prompt */
}
/*
These are the subroutines for the intrinsic commands.
*/
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 234/813
10/16/2018 PCjs: Advanced MS-DOS Programming
if (status)
fputs("\nEXEC of COMMAND.COM failed\n",stderr);
}
──────────────────────────────────────────────────────────────────────────
name shell
page 55,132
title SHELL.ASM--simple MS-DOS shell
;
; SHELL.ASM Simple extendable command interpreter
; for MS-DOS versions 2.0 and later
;
; Copyright 1988 by Ray Duncan
;
; Build: C>MASM SHELL;
; C>LINK SHELL;
;
; Usage: C>SHELL;
;
assume cs:_TEXT,ds:_DATA,ss:STACK
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 235/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 236/813
10/16/2018 PCjs: Advanced MS-DOS Programming
shell endp
intr2: cmp byte ptr [di],blank ; scan off any leading blanks
jne intr3
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 237/813
10/16/2018 PCjs: Advanced MS-DOS Programming
intrinsic endp
extrinsic proc near ; process extrinsic command
; by passing it to
; COMMAND.COM with a
; " /C " command tail
extrinsic endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 238/813
10/16/2018 PCjs: Advanced MS-DOS Programming
get_cmd endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 239/813
10/16/2018 PCjs: Advanced MS-DOS Programming
get_comspec endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 240/813
10/16/2018 PCjs: Advanced MS-DOS Programming
get_env endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 241/813
10/16/2018 PCjs: Advanced MS-DOS Programming
exec endp
cls_cmd endp
dos_cmd endp
exit_cmd proc near ; intrinsic EXIT command
_TEXT ends
dw 64 dup (?)
STACK ends
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 242/813
10/16/2018 PCjs: Advanced MS-DOS Programming
db 'DOS',0
dw dos_cmd
db 'EXIT',0
dw exit_cmd
db 0 ; end of table
; COMMAND.COM filespec
com_spec db 80 dup (0) ; from environment COMSPEC=
msg1 db cr,lf
db 'Unable to release memory.'
db cr,lf
msg1_length equ $-msg1
msg2 db cr,lf
db 'EXEC of COMMAND.COM failed.'
db cr,lf
msg2_length equ $-msg2
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 243/813
10/16/2018 PCjs: Advanced MS-DOS Programming
msg3 db cr,lf
db 'No COMSPEC variable in environment.'
db cr,lf
msg3_length equ $-msg3
_DATA ends
end shell
──────────────────────────────────────────────────────────────────────────
The SHELL program is table driven and can easily be extended to provide a
powerful customized user interface for almost any application. When SHELL
takes control of the system, it displays the prompt
sh:
and waits for input from the user. After the user types a line terminated
by a carriage return, SHELL tries to match the first token in the line
against its table of internal (intrinsic) commands. If it finds a match,
it calls the appropriate subroutine. If it does not find a match, it calls
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 244/813
10/16/2018 PCjs: Advanced MS-DOS Programming
the MS-DOS EXEC function and passes the user's input to COMMAND.COM with
the /C switch, essentially using COMMAND.COM as a transient command
processor under its own control.
Command Action
──────────────────────────────────────────────────────────────────────────
CLS Uses the ANSI standard control sequence to clear the
display screen and home the cursor.
DOS Runs a copy of COMMAND.COM.
EXIT Exits SHELL, returning control of the system to the
next lower command interpreter.
──────────────────────────────────────────────────────────────────────────
You can quickly add new intrinsic commands to either the C version or the
assembly-language version of SHELL. Simply code a procedure with the
appropriate action and insert the name of that procedure, along with the
text string that defines the command, into the table COMMANDS. In
addition, you can easily prevent SHELL from passing certain "dangerous"
commands (such as MKDIR or ERASE) to COMMAND.COM simply by putting the
names of the commands to be screened out into the intrinsic command table
with the address of a subroutine that prints an error message.
1. The program calls MS-DOS Int 21H Function 4AH (Resize Memory Block)
to shrink its memory allocation, so that the maximum possible space
will be available for COMMAND.COM if it is run as an overlay. (This is
explicit in the assembly-language version only. To keep the example
code simple, the number of paragraphs to be reserved is coded as a
generous literal value, rather than being figured out at runtime from
the size and location of the various program segments.)
2. The program searches the environment for the COMSPEC variable, which
defines the location of an executable copy of COMMAND.COM. If it can't
find the COMSPEC variable, it prints an error message and exits.
3. The program puts the address of its own handler in the Ctrl-C vector
(Int 23H) so that it won't lose control if the user enters a Ctrl-C
or a Ctrl-Break.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 245/813
10/16/2018 PCjs: Advanced MS-DOS Programming
5. The program reads a buffered line from the standard input device to
get the user's command.
8. The program repeats steps 4 through 7 until the user enters the
command EXIT, which is one of the intrinsic commands, and which causes
SHELL to terminate execution.
Loading overlays with the EXEC function is much less complex than using
EXEC to run another program. The overlay can be constructed as either a
memory image (.COM) or relocatable (.EXE) file and need not be the same
type as the program that loads it. The main program, called the root
segment, must carry out the following steps to load and execute an
overlay:
1. Make a memory block available to receive the overlay. The program that
calls EXEC must own the memory block for the overlay.
3. Call the MS-DOS EXEC function to load the overlay by issuing an Int
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 246/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 4BH
AL = 03H (EXEC subfunction to load overlay)
DS:DX = segment:offset of overlay file pathname
ES:BX = segment:offset of overlay parameter block
Upon return from the EXEC function, the carry flag is clear if the
overlay was found and loaded. The carry flag is set if the file could
not be found or if some other error occurred.
Figure 12-6 shows the use of EXEC to load and execute an overlay.
──────────────────────────────────────────────────────────────────────────
.
.
.
; allocate memory for overlay
mov bx,1000h ; get 64 KB (4096 paragraphs)
mov ah,48h ; function 48h = allocate block
int 21h ; transfer to MS-DOS
jc error ; jump if allocation failed
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 247/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 12-6. A code skeleton for loading and executing an overlay with
the EXEC function. The overlay file may be in either .COM or .EXE format.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 248/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Chapter 13 Interrupt Handlers
Interrupts are signals that cause the computer's central processing unit
to suspend what it is doing and transfer to a program called an interrupt
handler. Special hardware mechanisms that are designed for maximum speed
force the transfer. The interrupt handler determines the cause of the
interrupt, takes the appropriate action, and then returns control to the
original process that was suspended.
CPUs that support interrupts must also have the capability to block
interrupts while they are executing critical sections of code. Sometimes
the CPU can block interrupt levels selectively, but more frequently the
effect is global. While an interrupt is being serviced, the CPU masks all
other interrupts of the same or lower priority until the active handler
has completed its execution; similarly, it can preempt the execution of a
handler if a different interrupt with higher priority requires service.
Some CPUs can even draw a distinction between selectively masking
interrupts (they are recognized, but their processing is deferred) and
simply disabling them (the interrupt is thrown away).
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 249/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The interrupt handler itself must follow a simple but rigid sequence of
steps:
1. Save the system context (registers, flags, and anything else that the
handler will modify and that wasn't saved automatically by the CPU).
5. Take the appropriate action for the interrupt: receive and store data
from the serial port, set a flag to indicate the completion of a
disk-sector transfer, and so forth.
7. Reenable any interrupt levels that were blocked during this handler's
execution.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 250/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ Software interrupts
╓┌─┌──────────┌─────────┌────────────────────┌──────────┌─────────┌──────────╖
Interrupt Vector Interrupt 8086/88 80286 80386
level address trigger
──────────────────────────────────────────────────────────────────────────
00H 00H─03H Divide-by-zero x x x
01H 04H─07H Single step x x x
02H 08H─0BH Nonmaskable x x x
Interrupt Vector Interrupt 8086/88 80286 80386
level address trigger
──────────────────────────────────────────────────────────────────────────
02H 08H─0BH Nonmaskable x x x
interrupt (NMI)
03H 0CH─0FH Breakpoint x x x
04H 10H─13H Overflow x x x
05H 14H─17H BOUND exceeded x x
06H 18H─1BH Invalid opcode x x
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 251/813
10/16/2018 PCjs: Advanced MS-DOS Programming
07H 1CH─1FH
Processor extension x x
not available
08H 20H─23H Double fault x x
09H 24H─27H Segment overrun x x
0AH 28H─2BH Invalid task-state x x
segment
0BH 2CH─2FH Segment not present x x
0CH 30H─33H Stack segment x x
overrun
0DH 34H─37H General protection x x
fault
0EH 38H─3BH Page fault x
Interrupt Vector Interrupt 8086/88 80286 80386
level address trigger
──────────────────────────────────────────────────────────────────────────
0EH 38H─3BH Page fault x
0FH 3CH─3FH Reserved
10H 40H─43H Numeric coprocessor x x
error
11H─1FH 44H─7FH Reserved
──────────────────────────────────────────────────────────────────────────
Instead of being wired directly to the CPU, the interrupts from external
devices can be channeled through a device called the Intel 8259A
Programmable Interrupt Controller (PIC). The CPU controls the PIC through
a set of I/O ports, and the PIC, in turn, signals the CPU through the INTR
pin. The PIC allows the interrupts from specific devices to be enabled and
disabled, and their priorities to be adjusted, under program control.
A single PIC can handle only eight levels of interrupts. However, PICs can
be cascaded together in a treelike structure to handle as many levels as
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 252/813
10/16/2018 PCjs: Advanced MS-DOS Programming
INTR interrupts can be globally enabled and disabled with the CPU's STI
and CLI instructions. As you would expect, these instructions have no
effect on interrupts received on the CPU's NMI pin.
Software Interrupts
╓┌─┌──────────────────┌────────────────────────────────────┌─────────────────╖
Interrupt Usage Machine
──────────────────────────────────────────────────────────────────────────
00H Divide-by-zero PC, AT, PS/2
01H Single step PC, AT, PS/2
02H NMI PC, AT, PS/2
03H Breakpoint PC, AT, PS/2
Interrupt Usage Machine
──────────────────────────────────────────────────────────────────────────
03H Breakpoint PC, AT, PS/2
04H Overflow PC, AT, PS/2
05H ROM BIOS PrintScreen PC, AT, PS/2
BOUND exceeded AT, PS/2
06H Reserved PC
Invalid opcode AT, PS/2
07H Reserved PC
80287/80387 not present AT, PS/2
08H IRQ0 timer tick PC, AT, PS/2
Double fault AT, PS/2
09H IRQ1 keyboard PC, AT, PS/2
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 253/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 254/813
10/16/2018 PCjs: Advanced MS-DOS Programming
address
25H MS-DOS absolute disk read
26H MS-DOS absolute disk write
27H MS-DOS terminate and stay resident
28H MS-DOS idle interrupt
29H MS-DOS reserved
Interrupt Usage Machine
──────────────────────────────────────────────────────────────────────────
29H MS-DOS reserved
2AH MS-DOS network redirector
2BH─2EH MS-DOS reserved
2FH MS-DOS multiplex interrupt
30H─3FH MS-DOS reserved
40H ROM BIOS floppy-disk driver (if PC, AT, PS/2
fixed disk installed)
41H ROM BIOS fixed-disk parameters PC
ROM BIOS fixed-disk parameters AT, PS/2
(drive 0)
42H ROM BIOS default video driver (if PC, AT, PS/2
EGA installed)
43H EGA, MCGA, VGA character table PC, AT, PS/2
44H ROM BIOS font (characters 00H─7FH) PCjr
46H ROM BIOS fixed-disk parameters AT, PS/2
(drive 1)
4AH ROM BIOS alarm handler AT, PS/2
5AH Cluster adapter PC, AT
5BH Used by cluster program PC, AT
Interrupt Usage Machine
──────────────────────────────────────────────────────────────────────────
5BH Used by cluster program PC, AT
60H─66H User interrupts PC, AT, PS/2
67H LIM EMS driver PC, AT, PS/2
68H─6FH Unassigned
70H IRQ8 CMOS real-time clock AT, PS/2
71H IRQ9 software diverted to IRQ2 AT, PS/2
72H IRQ10 reserved AT, PS/2
73H IRQ11 reserved AT, PS/2
74H IRQ12 reserved AT
IRQ12 mouse PS/2
75H IRQ13 numeric coprocessor AT, PS/2
76H IRQ14 fixed-disk controller AT, PS/2
77H IRQ15 reserved AT, PS/2
78H─7FH Unassigned
80H─F0H BASIC PC, AT, PS/2
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 255/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 13-2. Interrupts with special significance on the IBM PC, PC/AT,
and PS/2 and compatible computers. Note that the IBM ROM BIOS uses several
interrupts in the range 00H─1FH, even though they were reserved by Intel
for CPU faults. IRQ numbers refer to Intel 8259A PIC priority levels.
The bottom 1024 bytes of system memory are called the interrupt-vector
table. Each 4-byte position in the table corresponds to an interrupt type
(0 through 0FFH) and contains the segment and offset of the interrupt
handler for that level. Interrupts 0 through 1FH (the lowest levels) are
used for internal hardware interrupts; MS-DOS uses Interrupts 20H through
3FH; all the other interrupts are available for use by either external
hardware devices or system drivers and application software.
When an 8259A PIC or other device interrupts the CPU by means of the INTR
pin, it must also place the interrupt type as an 8-bit number (0 through
0FFH) on the system bus, where the CPU can find it. The CPU then
multiplies this number by 4 to find the memory address of the interrupt
vector to be used.
Servicing an Interrupt
When the CPU senses an interrupt, it pushes the program status word (which
defines the various CPU flags), the code segment (CS) register, and the
instruction pointer (IP) onto the machine stack and disables the interrupt
system. It then uses the 8-bit number that was jammed onto the system bus
by the interrupting device to fetch the address of the handler from the
vector table and resumes execution at that address.
Usually the handler immediately reenables the interrupt system (to allow
higher-priority interrupts to occur), saves any registers it is going to
use, and then processes the interrupt as quickly as possible. Some
external devices also require a special acknowledgment signal so that they
will know the interrupt has been recognized.
If the interrupt was funneled through an 8259A PIC, the handler must send
a special code called end of interrupt (EOI) to the PIC through its
control port to tell it when interrupt processing is completed. (The EOI
has no effect on the CPU itself.) Finally, the handler executes the
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 256/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
pic_ctl equ 20h ; control port for 8259A
; interrupt controller
.
.
.
sti ; turn interrupts back on,
push ax ; save registers
push bx
push cx
push dx
push si
push di
push bp
push ds
push es
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 257/813
10/16/2018 PCjs: Advanced MS-DOS Programming
pop bx
pop ax
iret ; resume previous processing
──────────────────────────────────────────────────────────────────────────
Figure 13-3. Typical handler for hardware interrupts on the 80x86 family
of microprocessors. In real life, the interrupt handler would need to save
and restore only the registers that it actually modified. Also, if the
handler made extensive use of the machine stack, it would need to save and
restore the SS and SP registers of the interrupted process and use its own
local stack.
Valid reasons do exist, however, for writing your own interrupt handler
for use under MS-DOS:
■ To chain your own interrupt handler onto the default system handler for
a hardware device, so that both the system's actions and your own will
occur on an interrupt. (A typical example of this is the "clock-tick"
interrupt.)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 258/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Function Action
──────────────────────────────────────────────────────────────────────────
Int 21H Function 25H Set interrupt vector.
Int 21H Function 35H Get interrupt vector.
Int 21H Function 31H Terminate and stay resident.
──────────────────────────────────────────────────────────────────────────
These functions allow you to examine or modify the contents of the system
interrupt-vector table and to reserve memory for the use of a handler
without running afoul of other processes in the system or causing memory
use conflicts. Section 2 of this book, "MS-DOS Functions Reference,"
describes each of these functions in detail, with programming examples.
Handlers for external hardware interrupts under MS-DOS must operate under
some fairly severe restrictions:
■ A program should access the 8259A PIC with great care. The program
should not access the PIC unless that program is known to be the only
process in the system concerned with that particular interrupt level.
And it is vital that the handler issue an end-of-interrupt code to the
8259A PIC before performing the IRET; otherwise, the processing of
further interrupts for that priority level or lower priority levels
will be blocked.
The following are a few rules to keep in mind when you are writing an
interrupt driver:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 259/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ Use Int 21H Function 25H (Set Interrupt Vector) to modify the
interrupt vector; do not write directly to the interrupt-vector table.
■ If your program is not the only process in the system that uses this
interrupt level, chain back to the previous handler after performing
your own processing on an interrupt.
■ If your program is not going to stay resident, fetch and save the
current contents of the interrupt vector before modifying it and then
restore the original contents when your program exits.
■ If you are going to process hardware interrupts, keep the time that
interrupts are disabled and the total length of the service routine to
an absolute minimum. Remember that even after interrupts are reenabled
with an STI instruction, interrupts of the same or lower priority
remain blocked if the interrupt was received through the 8259A PIC.
The ZERODIV program has two major portions: the initialization portion and
the interrupt handler.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 260/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If the user enters a C to continue, the handler simply restores all the
registers and performs an IRET (INTERRUPT RETURN) to return control to the
application. (Of course, the results of the divide operation will be
useless.) If the user enters Q to quit, the handler exits to MS-DOS. Int
21H Function 4CH is particularly convenient in this case because it
allows the program to pass a return code and at the same time is the only
termination function that does not rely on the contents of any of the
segment registers.
──────────────────────────────────────────────────────────────────────────
name zdivide
page 55,132
title ZERODIV--Divide-by-zero handler
;
; ZERODIV.ASM--Terminate-and-stay-resident handler
; for divide-by-zero interrupts
;
; Copyright 1988 Ray Duncan
;
; Build: C>MASM ZERODIV;
; C>LINK ZERODIV;
; C>EXE2BIN ZERODIV.EXE ZERODIV.COM
; C>DEL ZERODIV.EXE
;
; Usage: C>ZERODIV
;
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 261/813
10/16/2018 PCjs: Advanced MS-DOS Programming
org 100H
assume cs:_TEXT,ds:_TEXT,es:_TEXT,ss:_TEXT
; DX = paragraphs to reserve
mov dx,((offset pgm_len+15)/16)+10h
mov ax,3100h ; function 31h = terminate and
; stay resident
int 21h ; transfer to MS-DOS
init endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 262/813
10/16/2018 PCjs: Advanced MS-DOS Programming
mov ds,ax
; display message
; "Continue or Quit?"
mov dx,offset msg2 ; DS:DX = message address
mov ah,9 ; function 09h = display string
int 21h ; transfer to MS-DOS
cmp al,'c' ; is it C or Q?
je zdiv3 ; jump, it's a C
cmp al,'q'
je zdiv2 ; jump, it's a Q
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 263/813
10/16/2018 PCjs: Advanced MS-DOS Programming
zdiv endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 264/813
10/16/2018 PCjs: Advanced MS-DOS Programming
_TEXT ends
end init
──────────────────────────────────────────────────────────────────────────
Figure 13-4. A simple example of an interrrupt handler for use within the
MS-DOS environment. ZERODIV makes itself permanently resident in memory
and handles the CPU's internal divide-by-zero interrupt.
────────────────────────────────────────────────────────────────────────────
Chapter 14 Installable Device Drivers
Device drivers are the modules of an operating system that control the
hardware. They isolate the operating-system kernel from the specific
characteristics and idiosyncrasies of the peripheral devices interfaced to
the central processor. Thus, the driver's relationship to the kernel is
analogous to the operating system's relationship to application programs.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 265/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ Block-device drivers
■ Character-device drivers
Character-Device Drivers
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 266/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ It can open them by name (CON, AUX, PRN, etc.) for input and output,
like any other character device.
■ It can use the special-purpose MS-DOS function calls (Int 21H Functions
01-0CH).
During ASCII-mode input, MS-DOS requests characters one at a time from the
driver and places them into its own internal buffer, echoing each to the
screen (if the input device is the keyboard) and checking each character
for a Ctrl-C (03H). When the number of characters requested by the
application program has been received, when a Ctrl-Z is detected, or when
the Enter key is pressed (in the case of the keyboard), MS-DOS terminates
the input and copies the data from its internal buffer into the requesting
program's buffer. Similarly, during ASCII-mode output, MS-DOS passes the
characters to the device driver one at a time and checks for a Ctrl-C
pending at the keyboard between each character. When a Ctrl-C is detected,
MS-DOS aborts the input or output operation and transfers to the routine
whose address is stored in the Int 23H vector.
In binary mode, MS-DOS reads or writes the exact number of bytes requested
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 267/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Block-Device drivers
A block driver can support more than one hardware unit, map a single
physical unit onto two or more logical units, or both. Block devices do
not have file-like logical names, as character devices do. Instead, MS-DOS
assigns drive designators to the block-device units or logical drives in
an alphabetic sequence: A, B, and so forth. Each logical drive contains a
file system: boot block, file allocation table, root directory, and so
forth. (See Chapter 10.)
■ A device header
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 268/813
10/16/2018 PCjs: Advanced MS-DOS Programming
┌────────────────────────┬─────────────────────────┐
│ │ Initialization │
│ ├─────────────────────────┤
│ │ Media check │
│ ├─────────────────────────┤
│ │ Build BPB │
│ ├─────────────────────────┤
│ │ IOCTL read and write │
│ ├─────────────────────────┤
│ │ Status │
│ ├─────────────────────────┤
│ │ Read │
│ ├─────────────────────────┤
│ │ Write, write/verify │
│ ├─────────────────────────┤
│ Interrupt routine │ Output until busy │
│ ├─────────────────────────┤
│ │ Flush buffers │
│ ├─────────────────────────┤
│ │ Device open │
│ ├─────────────────────────┤
│ │ Device close │
│ ├─────────────────────────┤
│ │ Check whether removable │
│ ├─────────────────────────┤
│ │ Generic IOCTL │
│ ├─────────────────────────┤
│ │ Get/Set logical device │
│ └─────────────────────────┤
├──────────────────────────────────────────────────┤
│ Strategy routine │
├──────────────────────────────────────────────────┤
│ Device-driver header │
└──────────────────────────────────────────────────┘
The device header (Figure 14-2) lies at the beginning of the driver. It
contains a link to the next driver in the chain, a set of attribute flags
for the device (Figure 14-3), offsets to the executable strategy and
interrupt routines for the device, and the logical-device name (if it is a
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 269/813
10/16/2018 PCjs: Advanced MS-DOS Programming
character device such as PRN or COM1) or the number of logical units (if
it is a block device).
Byte offset
00H ┌──────────────────────────────────────────────┐
│ Link to next driver, offset │
02H ├──────────────────────────────────────────────┤
│ Link to next driver, segment │
04H ├──────────────────────────────────────────────┤
│ Device attribute word │
06H ├──────────────────────────────────────────────┤
│ Strategy entry point, offset │
08H ├──────────────────────────────────────────────┤
│ Interrupt entry point, offset │
0AH ├──────────────────────────────────────────────┤
│ Logical name (8 bytes) if character device │
│ Number of units (1 byte) if block device, │
│ followed by 7 bytes of reserved space │
└──────────────────────────────────────────────┘
Figure 14-2. Device-driver header. The offsets to the strat and intr
routines are offsets from the same segment used to point to the device
header.
╓┌─┌──────────────┌──────────────────────────────────────────────────────────╖
Bit Significance
──────────────────────────────────────────────────────────────────────────
15 1 if character device, 0 if block device
14 1 if IOCTL read and write supported
13 for block devices:
1 if BIOS parameter block in boot sector should be used to
determine media characteristics, 0 if media ID byte should
be used
for character devices:
1 if output until busy supported
12 Reserved (should be 0)
11 1 if open/close/removable media supported (MS-DOS 3.0 and
later)
Bit Significance
──────────────────────────────────────────────────────────────────────────
later)
7─10 Reserved (should be 0)
6 1 if generic IOCTL and get/set logical drive supported
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 270/813
10/16/2018 PCjs: Advanced MS-DOS Programming
MS-DOS calls the strategy routine (strat) for the device when the driver
is first loaded and installed, and again whenever an application program
issues an I/O request for the device. MS-DOS passes the strategy routine a
double-word pointer to a data structure called a request header. This
structure contains information about the type of operation to be
performed. In current versions of MS-DOS, the strategy routine never
actually performs any I/O operation but simply saves the pointer to the
request header. The strat routine must not make any Int 21H function
calls.
The first 13 bytes of the request header are the same for all
device-driver functions and are therefore referred to as the static
portion of the header. The number and contents of the subsequent bytes
vary according to the type of function being requested (Figure 14-4).
Both MS-DOS and the driver read and write information in the request
header.
──────────────────────────────────────────────────────────────────────────
;
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 271/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 14-4. Format of request header. Only the first 13 bytes are common
to all driver functions; the number and definition of the subsequent bytes
vary, depending upon the function type. The structure shown here is the
one used by the read and write subfunctions of the driver.
The last and most complex part of a device driver is the interrupt routine
(intr), which MS-DOS calls immediately after it calls the strategy
routine. The interrupt routine implements the device driver proper; it
performs (or calls other resident routines to perform) the actual input or
output operations, based on the information passed in the request header.
The strat routine may not make any Int 21H function calls, except for a
restricted set during driver initialization.
When an I/O function is completed, the interrupt routine uses the status
field in the request header to inform the DOS kernel about the outcome of
the requested I/O operation. It can use other fields in the request header
to pass back such useful information as counts of the actual sectors or
bytes transferred.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 272/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ A centralized exit point that stores status and error codes into the
request header (Figures 14-5 and 14-6) and restores the previous
contents of the affected registers
Bit(s) Significance
──────────────────────────────────────────────────────────────────────────
15 Error
12─14 Reserved
9 Busy
8 Done
0─7 Error code if bit 15 = 1
──────────────────────────────────────────────────────────────────────────
Figure 14-5. Values for the return status word of the request header.
Code Meaning
──────────────────────────────────────────────────────────────────────────
0 Write-protect violation
1 Unknown unit
2 Drive not ready
3 Unknown command
4 Data error (CRC)
5 Bad request-structure length
6 Seek error
7 Unknown medium
8 Sector not found
9 Printer out of paper
0AH Write fault
0BH Read fault
0CH General failure
0D─0EH Reserved
0FH Invalid disk change (MS-DOS versions 3.0 and later)
──────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 273/813
10/16/2018 PCjs: Advanced MS-DOS Programming
A total of 20 command codes are defined for MS-DOS device drivers. The
command codes (which are not consecutive), the names of the associated
driver-interrupt routines, and the MS-DOS versions in which they are first
supported are as follows:
╓┌─┌───────────┌────────────────────────┌───────────┌────────────┌───────────╖
Command Function Character Block MS-DOS
code driver driver version
──────────────────────────────────────────────────────────────────────────
0 Init (Initialization) X X 2.0
1 Media Check X 2.0
2 Build BPB X 2.0
3 IOCTL Read X X 2.0
4 Read X X 2.0
5 Nondestructive Read X 2.0
6 Input Status X 2.0
7 Flush Input Buffers X 2.0
8 Write X X 2.0
9 Write with Verify X 2.0
10 Output Status X 2.0
11 Flush Output Buffers X 2.0
Command Function Character Block MS-DOS
code driver driver version
──────────────────────────────────────────────────────────────────────────
11 Flush Output Buffers X 2.0
12 IOCTL Write X X 2.0
13 Device Open X X 3.0
14 Device Close X X 3.0
15 Removable Media X 3.0
16 Output Until Busy X 3.0
19 Generic IOCTL X X 3.2
23 Get Logical Device X 3.2
24 Set Logical Device X 3.2
──────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 274/813
10/16/2018 PCjs: Advanced MS-DOS Programming
As you can see from the preceding table, a driver's interrupt section must
support functions 0 through 12 under all versions of MS-DOS. Drivers
tailored for MS-DOS 3.0 and 3.1 can optionally support an additional four
functions, and MS-DOS drivers for versions 3.2 and later can support three
more (for a total of 20). MS-DOS inspects the bits in the attribute word
of the device-driver header to determine which of the optional functions a
driver supports, if any.
Some of the functions are relevant only for character-device drivers and
some only for block-device drivers; a few have meaning to both types. In
any case, both driver types should have an executable routine present for
each function, even if it does nothing except set the done flag in the
status word of the request header.
MS-DOS uses the number of units returned by a block driver in the request
header to assign drive identifiers. For example, if the current maximum
drive is D and the driver being initialized supports four units, MS-DOS
will assign it the drive letters E, F, G, and H. Although the
device-driver header also has a field for number of units, MS-DOS does not
inspect it.
The BPB pointer array is an array of word offsets to BIOS parameter blocks
(Figure 14-7). Each unit defined by the driver must have one entry in the
array, although the entries can all point to the same BPB to conserve
memory. During the operating-system boot sequence, MS-DOS scans all the
BPBs defined by all the units in all the block-device drivers to determine
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 275/813
10/16/2018 PCjs: Advanced MS-DOS Programming
the largest sector size that exists on any device in the system and uses
this information to set its cache buffer size.
Many programmers position the initialization code at the end of the driver
and return that address as the location of the first free memory, so that
MS-DOS will reclaim the memory occupied by the initialization routine
after the routine is finished with its work. If the initialization routine
finds that the device is missing or defective and wants to abort the
installation of the driver completely so that it does not occupy any
memory, it should return number of units as zero and set the free memory
address to CS:0000H. (A character-device driver that wants to abort its
installation should clear bit 15 of the attribute word in the driver
header and then set the units field and free memory address as though it
were a block-device driver.)
Byte(s) Contents
──────────────────────────────────────────────────────────────────────────
00─01H Bytes per sector
02H Sectors per allocation unit (power of 2)
03H─04H Number of reserved sectors (starting at sector 0)
05H Number of file allocation tables
06H─07H Maximum number of root-directory entries
08H─09H Total number of sectors in medium
0AH Media descriptor byte
0BH─0CH Number of sectors occupied by a single FAT
0DH─0EH Sectors per track (versions 3.0 and later)
0FH─10H Number of heads (versions 3.0 and later)
11H─12H Number of hidden sectors (versions 3.0 and later)
13H─14H High-order word of number of hidden sectors
(version 4.0)
15H─18H If bytes 8─9 are zero, total number of sectors in
medium (version 4.0)
19H─1EH Reserved, should be zero (version 4.0)
──────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 276/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
RH + 2 BYTE Command code = 0
It returns:
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status
Code Meaning
──────────────────────────────────────────────────────────────────────────
0F0H 3.5", 2-sided, 18-sector
0F8H fixed disk
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 277/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 14-8. Current valid MS-DOS codes for the media descriptor byte of
the request header, assuming bit 13 in the attribute word of the driver
header is zero.
■ If the disk has not been changed, MS-DOS proceeds with the disk access.
■ If the disk has been changed, MS-DOS invalidates all buffers associated
with this unit, including buffers containing data waiting to be written
(this data is simply lost), performs a BUILD BPB call, and then reads
the disk's FAT and directory.
If bit 11 of the device-header attribute word is set (that is, the driver
supports the optional open/close/removable-media functions), the host
system is MS-DOS version 3.0 or later, and the function returns the
disk-changed code (-1), the function must also return the segment and
offset of the ASCIIZ volume label for the previous disk in the drive. (If
the driver does not have the volume label, it can return a pointer to the
ASCIIZ string NO NAME.) If MS-DOS determines that the disk was changed
with unwritten data still present in its buffers, it issues a
critical-error 0FH (invalid disk change). Application programs can trap
this critical error and prompt the user to replace the original disk.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 278/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
RH + 1 BYTE Unit code
It returns
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status
-1 if disk changed
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 279/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
RH + 1 BYTE Unit code
It returns
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status
Under MS-DOS versions 3.0 and later, if bit 11 of the header's device
attribute word is set, this routine should also read the volume label off
the disk and save it.
The IOCTL read function allows the device driver to pass information
directly to the application program. This function is called only if bit
14 is set in the device attribute word. MS-DOS performs no error check on
IOCTL I/O calls.
──────────────────────────────────────────────────────────────────────────
RH + 1 BYTE Unit code (block devices)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 280/813
10/16/2018 PCjs: Advanced MS-DOS Programming
It returns
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status
The read function transfers data from the device into the specified memory
buffer. If an error is encountered during the read, the function must set
the error status and, in addition, report the number of bytes or sectors
successfully transferred; it is not sufficient to simply report an error.
──────────────────────────────────────────────────────────────────────────
RH + 1 BYTE Unit code (block devices)
──────────────────────────────────────────────────────────────────────────
RH + 1 BYTE Unit code
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 281/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status
Under MS-DOS versions 3.0 and later, this routine can use the count of
open files maintained by the open and close functions (0DH and 0EH) and
the media descriptor byte to determine whether the disk has been illegally
changed.
──────────────────────────────────────────────────────────────────────────
RH + 2 BYTE Command code = 5
──────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 282/813
10/16/2018 PCjs: Advanced MS-DOS Programming
It returns
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status
──────────────────────────────────────────────────────────────────────────
RH + 2 BYTE Command code = 6
──────────────────────────────────────────────────────────────────────────
It returns
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 283/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
RH + 2 BYTE Command code = 7
──────────────────────────────────────────────────────────────────────────
It returns
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status
──────────────────────────────────────────────────────────────────────────
The write function transfers data from the specified memory buffer to the
device. If an error is encountered during the write, the write function
must set the error status and, in addition, report the number of bytes or
sectors successfully transferred; it is not sufficient to simply report an
error.
──────────────────────────────────────────────────────────────────────────
RH + 1 BYTE Unit code (block devices)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 284/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
RH + 1 BYTE Unit code
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status
Under MS-DOS versions 3.0 and later, this routine can use the reference
count of open files maintained by the open and close functions (0DH and
0EH) and the media descriptor byte to determine whether the disk has been
illegally changed.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 285/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
RH + 2 BYTE Command code = 10 (0AH)
──────────────────────────────────────────────────────────────────────────
It returns
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status:
──────────────────────────────────────────────────────────────────────────
RH + 2 BYTE Command code = 11 (0BH)
──────────────────────────────────────────────────────────────────────────
It returns
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 286/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
──────────────────────────────────────────────────────────────────────────
RH + 1 BYTE Unit code (block devices)
It returns
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status
The device-open function is supported only under MS-DOS versions 3.0 and
later and is called only if bit 11 is set in the device attribute word of
the device header.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 287/813
10/16/2018 PCjs: Advanced MS-DOS Programming
thus invalidating the open-files count. One way to protect against this
possibility is to reset the open-files count to zero, without flushing the
buffers, whenever the answer to a media-change call is yes and a
subsequent build BPB call is made to the driver.
──────────────────────────────────────────────────────────────────────────
RH + 1 BYTE Unit code (block devices)
It returns
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status
──────────────────────────────────────────────────────────────────────────
The device-close function is supported only under MS-DOS versions 3.0 and
later and is called only if bit 11 is set in the device attribute word of
the device header.
On block devices, this function can be used to manage local buffering and
to decrement a reference count of the number of open files on the device;
when the count reaches zero, all files have been closed and the driver
should flush buffers because the user may change disks.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 288/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
RH + 1 BYTE Unit code (block devices)
It returns
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status
──────────────────────────────────────────────────────────────────────────
──────────────────────────────────────────────────────────────────────────
RH + 1 BYTE Unit code
It returns
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 289/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
RH + 2 BYTE Command code = 16 (10H)
It returns
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status
The generic IOCTL function is supported only under MS-DOS versions 3.2 and
later and is called only if bit 6 is set in the device attribute word of
the device header. This function corresponds to the MS-DOS generic IOCTL
service supplied to application programs by Int 21H Function 44H
Subfunctions 0CH and 0DH.
Services that the generic IOCTL function may invoke, if the driver
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 290/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
RH + 1 BYTE Unit number (block devices)
It returns
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status
──────────────────────────────────────────────────────────────────────────
The get-logical-device function returns a code for the last drive letter
used to reference the device; if only one drive letter is assigned to the
device, the returned unit code should be zero. Thus, this function can be
used to determine whether more than one drive letter is assigned to the
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 291/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
RH + 1 BYTE Unit code
It returns
──────────────────────────────────────────────────────────────────────────
RH + 1 BYTE Last unit referenced, or zero
RH + 3 WORD Status
──────────────────────────────────────────────────────────────────────────
──────────────────────────────────────────────────────────────────────────
RH + 1 BYTE Unit code
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 292/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
It returns
──────────────────────────────────────────────────────────────────────────
RH + 3 WORD Status
──────────────────────────────────────────────────────────────────────────
1. MS-DOS inspects its internal tables and determines which device driver
should receive the I/O request.
3. MS-DOS calls the device driver's strat entry point, passing the
address of the request header in the ES:BX registers.
4. The device driver saves the address of the request header in a local
variable and performs a FAR RETURN.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 293/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ Reading from one to many sectors of the root directory to find the
entry for the subdirectory and obtain its starting-cluster number
■ Reading from one to many sectors of both the FAT and the subdirectory
itself to find the entry for the desired file
MS-DOS uses the CLOCK device for marking file control blocks and directory
entries with the date and time, as well as for providing the date and time
services to application programs. This device has a unique type of
interaction with MS-DOS──a 6-byte sequence is read from or written to the
driver that obtains or sets the current date and time. The sequence has
the following format:
┌─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐
│ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │
│ Days │ Days │ Minutes │ Hours │Seconds/ │ Seconds │
│low byte │high byte│ │ │ 100 │ │
└─────────┴─────────┴─────────┴─────────┴─────────┴─────────┘
The value passed for days is a 16-bit integer representing the number of
days elapsed since January 1, 1980.
The clock driver can have any logical-device name because MS-DOS uses the
CLOCK bit in the device attribute word of the driver's device header to
identify the device, rather than its name. On IBM PC systems, the clock
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 294/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Assembly
Device drivers for MS-DOS always have an origin of zero but are otherwise
assembled, linked, and converted into an executable module as though they
were .COM files. (Although MS-DOS is also capable of loading installable
drivers in the .EXE file format, this introduces unnecessary complexity
into writing and debugging drivers and offers no significant advantages.
In addition, it is not possible to use .EXE-format drivers with some IBM
versions of MS-DOS because the .EXE loader is located in COMMAND.COM,
which is not present when the installable device drivers are being
loaded.) The driver should not have a declared stack segment and must, in
general, follow the other restrictions outlined in Chapter 3 for
memory-image (.COM) programs. A driver can be loaded anywhere, so beware
that you do not make any assumptions in your code about the driver's
location in physical memory. Figure 14-9 presents a skeleton example that
you can follow as you read the next few pages.
──────────────────────────────────────────────────────────────────────────
name driver
page 55,132
title DRIVER.ASM Device-Driver Skeleton
;
; DRIVER.ASM MS-DOS device-driver skeleton
;
; The driver command-code routines are stubs only and have
; no effect but to return a nonerror "done" status.
;
; Copyright 1988 Ray Duncan
;
assume cs:_TEXT,ds:_TEXT,es:NOTHING
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 295/813
10/16/2018 PCjs: Advanced MS-DOS Programming
org 0
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 296/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Strat endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 297/813
10/16/2018 PCjs: Advanced MS-DOS Programming
jmp Intr2
xor ax,ax
ret
MediaChk endp
xor ax,ax
ret
BuildBPB endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 298/813
10/16/2018 PCjs: Advanced MS-DOS Programming
xor ax,ax
ret
IoctlRd endp
Read proc near ; function 4 = read (input)
xor ax,ax
ret
Read endp
xor ax,ax
ret
NdRead endp
xor ax,ax
ret
InpStat endp
xor ax,ax
ret
InpFlush endp
xor ax,ax
ret
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 299/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Write endp
xor ax,ax
ret
endp
xor ax,ax
ret
OutStat endp
xor ax,ax
ret
OutFlush endp
xor ax,ax
ret
IoctlWt endp
xor ax,ax
ret
DevOpen endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 300/813
10/16/2018 PCjs: Advanced MS-DOS Programming
xor ax,ax
ret
DevClose endp
RemMedia proc near ; function 15 = removable media
xor ax,ax
ret
RemMedia endp
xor ax,ax
ret
OutBusy endp
xor ax,ax
ret
GenIOCTL endp
xor ax,ax
ret
GetLogDev endp
xor ax,ax
ret
SetLogDev endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 301/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Init endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 302/813
10/16/2018 PCjs: Advanced MS-DOS Programming
hexasc endp
Ident db cr,lf,lf
db 'Advanced MS-DOS Example Device Driver'
db cr,lf
db 'Device driver header at: '
Ident1 db 'XXXX:0000'
db cr,lf,lf,eom
Intr endp
_TEXT ends
end
──────────────────────────────────────────────────────────────────────────
The driver's device header must be located at the beginning of the file
(offset 0000H). Both words in the link field in the header should be set
to -1. The attribute word must be set up correctly for the device type and
other options. The offsets to the strategy and interrupt routines must be
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 303/813
10/16/2018 PCjs: Advanced MS-DOS Programming
relative to the same segment base as the device header itself. If the
driver is for a character device, the name field should be filled in
properly with the device's logical name. The logical name can be any legal
8-character filename, padded with spaces and without a colon. Beware of
accidentally duplicating the names of existing character devices, unless
you are intentionally superseding a resident driver.
MS-DOS calls the strategy and interrupt routines for the device by means
of an intersegment call (CALL FAR) when the driver is first loaded and
installed and again whenever an application program issues an I/O request
for the device. MS-DOS uses the ES:BX registers to pass the strat routine
a double-word pointer to the request header; this address should be saved
internally in the driver so that it is available for use during the
subsequent call to the intr routine.
■ Don't implement them, and leave the associated bits in the device
header cleared. The resulting driver will work in either version 2 or
version 3 but does not take full advantage of the augmented
functionality of version 3.
■ Implement them, and test the MS-DOS version during the initialization
sequence, setting bits 6 and 11 of the device header appropriately.
Write all command-code routines so that they test this bit and adjust
to accommodate the host version of MS-DOS. Such a driver requires more
work and testing but will take full advantage of both the version 2 and
the version 3 environments.
■ Implement them, and assume that all the version 3 facilities are
available. With this approach, the resulting driver may not work
properly under version 2.
Remember that device drivers must preserve the integrity of MS-DOS. The
driver must preserve all registers, including flags (especially the
direction flag and interrupt enable bits), and if the driver makes heavy
use of the stack, it should switch to an internal stack of adequate depth
(the MS-DOS stack has room for only 40 to 50 bytes when a driver is
called).
If you install a new CON driver, be sure to set the bits for standard
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 304/813
10/16/2018 PCjs: Advanced MS-DOS Programming
input and standard output in the device attribute word in the device
header.
You'll recall that one file can contain multiple drivers. In this case,
the device-header link field of each driver should point to the segment
offset of the next, all using the same segment base, and the link field
for the last driver in the file should be set to -1,-1. The initialization
routines for all the drivers in the file should return the same break
address.
Linking
Use the standard MS-DOS linker to transform the .OBJ file that is output
from the assembler into a relocatable .EXE module. Then, use the EXE2BIN
utility (see Chapter 4) to convert the .EXE file into a memory-image
program. The extension on the final driver file can be anything, but .BIN
and .SYS are most commonly used in MS-DOS systems, and it is therefore
wise to follow one of these conventions.
Installation
DEVICE=[D:][PATH]FILENAME.EXT
During the MS-DOS boot sequence, the SYSINIT module (which is part of
IO.SYS) reads and processes the CONFIG.SYS file. It loads the driver into
memory and inspects the device header. If the driver is a character-device
driver, SYSINIT links it into the device chain ahead of the other
character devices; if it is a block-device driver, SYSINIT places it
behind all previously linked block devices and the resident block devices
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 305/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Next, SYSINIT calls the strat routine with a request header that contains
a command code of zero, and then it calls the intr routine. The driver
executes its initialization routine and returns the break address, telling
MS-DOS how much memory to reserve for this driver. Now MS-DOS can proceed
to the next entry in the CONFIG.SYS file.
NUL
│
▼
CON
│
▼
AUX
│
▼
PRN
│
▼
CLOCK
│
▼
Any other resident block
or character devices
NUL
│
▼
Installable character-
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 306/813
10/16/2018 PCjs: Advanced MS-DOS Programming
device drivers
│
▼
CON
│
▼
AUX
│
▼
PRN
│
▼
CLOCK
│
▼
Any other resident block
or character devices
│
▼
Installable block-
device drivers
Address Attribute
Strategy Interrupt Type Units Name
routine routine
──────────────────────────────────────────────────────────────────────────
00E3:0111 8004 0FD5 0FE0 C NUL
0070:0148 8013 008E 0099 C CON
0070:01DD 8000 008E 009F C AUX
0070:028E 8000 008E 00AE C PRN
0070:0300 8008 008E 00C3 C CLOCK
0070:03CC 0000 008E 00C9 B 02
0070:01EF 8000 008E 009F C COM1
0070:02A0 8000 008E 00AE C LPT1
0070:06F0 8000 008E 00B4 C LPT2
0070:0702 8000 008E 00BA C LPT3
0070:0714 8000 008E 00A5 C COM2
End of
device chain
──────────────────────────────────────────────────────────────────────────
Figure 14-12. Example listing of device chain under MS-DOS version 2.1,
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 307/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The most important thing to remember when testing new device drivers is to
maintain adequate backups and a viable fallback position. Don't modify the
CONFIG.SYS file and install the new driver on your fixed disk before it is
proven! Be prudent──create a bootable floppy disk and put the modified
CONFIG.SYS file and the new driver on that for debugging. When everything
is working properly, copy the finished product to its permanent storage
medium.
Tracing the installed driver when it is linked into the MS-DOS system in
the normal manner is more difficult. Breakpoints must be chosen carefully,
to yield the maximum possible information per debugging run. Because
current versions of MS-DOS maintain only one request header internally,
the request header that was being used by the driver you are tracing will
be overwritten as soon as your debugger makes an output request to display
information. You will find it helpful to add a routine to your
initialization subroutine that displays the driver's load address on the
console when you boot MS-DOS; you can then use this address to inspect the
device-driver header and set breakpoints within the body of the driver.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 308/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Although the interface between the DOS kernel and the device driver is
fairly simple, it is also quite strict. The command-code routines must
perform exactly as they are defined, or the system will behave
erratically. Even a very subtle discrepancy in the action of a
command-code routine can have unexpectedly large global effects.
────────────────────────────────────────────────────────────────────────────
Chapter 15 Filters
The standard MS-DOS package includes three simple filters: SORT, which
alphabetically sorts text on a line-by-line basis; FIND, which searches a
text stream to match a specified string; and MORE, which displays text one
screenful at a time.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 309/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The operation of a filter program relies on two MS-DOS features that first
appeared in version 2.0: standard devices and redirectable I/O.
The standard devices are represented by five handles that are originally
established by COMMAND.COM. Each process inherits these handles from its
immediate parent. Thus, the standard device handles are already open when
a process acquires control of the system, and it can use them with
Interrupt 21H Functions 3FH and 40H for read and write operations
without further preliminaries. The default assignments of the standard
device handles are as follows:
The CON device is assigned by default to the system's keyboard and video
display. AUX and PRN are respectively associated by default with COM1 (the
first physical serial port) and LPT1 (the first parallel printer port).
You can use the MODE command to redirect LPT1 to one of the serial ports;
the MODE command will also redirect PRN.
Symbol Effect
──────────────────────────────────────────────────────────────────────────
< file Takes standard input from the specified file instead of
the keyboard.
< device Takes standard input from the named device instead of
the keyboard.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 310/813
10/16/2018 PCjs: Advanced MS-DOS Programming
the display.
causes the SORT filter to read its input from the file MYFILE.TXT, sort
the lines alphabetically, and write the resulting text to the character
device PRN (the logical name for the system's list device).
The redirection requested by the <, >, >>, and | characters takes place at
the level of COMMAND.COM and is invisible to the program it affects. Any
other process can achieve a similar effect by redirecting the standard
input and standard output with Int 21H Function 46H before calling the
EXEC function (Int 21H Function 4BH) to run a child process.
Note that if a program circumvents MS-DOS to perform its input and output,
either by calling ROM BIOS functions or by manipulating the keyboard or
video controller directly, redirection commands placed in the program's
command line do not have the expected effect.
By convention, a filter program reads its text from the standard input
device and writes the results of its operations to the standard output
device. When it reaches the end of the input stream, the filter simply
terminates. As a result, filters are both flexible and simple.
Filter programs are flexible because they do not know, and do not care
about, the source of the data they process or the destination of their
output. Thus, any character device that has a logical name within the
system (CON, AUX, COM1, COM2, PRN, LPT1, LPT2, LPT3, and so on), any file
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 311/813
10/16/2018 PCjs: Advanced MS-DOS Programming
on any block device (local or network) known to the system, or any other
program can supply a filter's input or accept its output. If necessary,
you can concatenate several functionally simple filters with pipes to
perform very complex operations.
Although flexible, filters are also simple because they rely on their
parent processes to supply standard input and standard output handles that
have already been appropriately redirected. The parent must open or create
any necessary files, check the validity of logical character-device names,
and load and execute the preceding or following process in a pipe. The
filter concerns itself only with the transformation it applies to the
data.
Building a Filter
If you try out these programs, you'll notice that the C prototype filter
runs much faster than its MASM equivalent. This is because the C runtime
library is performing hidden blocking and deblocking of the input and
output stream, whereas the MASM filter is doing exactly what it appears to
be doing: making two calls to MS-DOS for each character processed. You can
easily restore the MASM filter's expected speed advantage by adapting it
to read and write lines instead of single characters.
──────────────────────────────────────────────────────────────────────────
name proto
page 55,132
title PROTO.ASM--prototype filter
;
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 312/813
10/16/2018 PCjs: Advanced MS-DOS Programming
assume cs:_TEXT,ds:_DATA,ss:STACK
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 313/813
10/16/2018 PCjs: Advanced MS-DOS Programming
main endp
;
; Perform any necessary translation on character
; from standard input stored in variable 'char'.
; This example simply leaves character unchanged.
;
translate proc near
translate endp
_TEXT ends
_DATA ends
dw 64 dup (?)
STACK ends
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 314/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
/*
PROTO.C: prototype character-oriented filter
#include <stdio.h>
/*
Perform any necessary translation on character
from input file. This example simply returns
the same character.
*/
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 315/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
name clean
page 55,132
title CLEAN--Text-file filter
;
; CLEAN.ASM Filter to turn document files into
; normal text files.
;
; Copyright 1988 Ray Duncan
;
; Build: C>MASM CLEAN;
; C>LINK CLEAN;
;
; Usage: C>CLEAN <infile >outfile
;
; All text characters are passed through with high
; bit stripped off. Formfeeds, carriage returns,
; and linefeeds are passed through. Tabs are expanded
; to spaces. All other control codes are discarded.
;
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 316/813
10/16/2018 PCjs: Advanced MS-DOS Programming
assume cs:_TEXT,ds:_DATA,es:_DATA,ss:STACK
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 317/813
10/16/2018 PCjs: Advanced MS-DOS Programming
; write failed...
mov dx,offset msg2 ; DS:DX = error message
mov cx,msg2_len ; CX = message length
mov bx,stderr ; BX = standard error handle
mov ah,40h ; function 40h = write
int 21h ; transfer to MS-DOS
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 318/813
10/16/2018 PCjs: Advanced MS-DOS Programming
clean endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 319/813
10/16/2018 PCjs: Advanced MS-DOS Programming
getc endp
putc endp
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 320/813
10/16/2018 PCjs: Advanced MS-DOS Programming
init endp
flush endp
_TEXT ends
_DATA segment word public 'DATA'
msg1 db cr,lf
db 'clean: need MS-DOS version 2 or greater.'
db cr,lf,'$'
msg2 db cr,lf
db 'clean: disk is full.'
db cr,lf
msg2_len equ $-msg2
_DATA ends
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 321/813
10/16/2018 PCjs: Advanced MS-DOS Programming
dw 64 dup (?)
STACK ends
end clean
──────────────────────────────────────────────────────────────────────────
Figure 15-3. CLEAN.ASM, the source code for the MASM version of the CLEAN
filter.
──────────────────────────────────────────────────────────────────────────
/*
CLEAN.C Filter to turn document files into
normal text files.
All text characters are passed through with high bit stripped
off. Formfeeds, carriage returns, and linefeeds are passed
through. Tabs are expanded to spaces. All other control codes
are discarded.
*/
#include <stdio.h>
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 322/813
10/16/2018 PCjs: Advanced MS-DOS Programming
/*
Write a character to the standard output. If
write fails, display error message and terminate.
*/
wchar(char c)
{
if((putchar(c) == EOF) && (c != EOFMK))
{
fputs("clean: disk full",stderr);
exit(1);
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 323/813
10/16/2018 PCjs: Advanced MS-DOS Programming
}
}
──────────────────────────────────────────────────────────────────────────
Figure 15-4. CLEAN.C, the source code for the C version of the CLEAN
filter.
When using the CLEAN filter, you must specify the source and destination
files with redirection parameters in the command line; otherwise, CLEAN
will simply read the keyboard and write to the display. For example, to
filter the document file MYFILE.DOC and leave the result in the file
MYFILE.TXT, you would enter the following command:
────────────────────────────────────────────────────────────────────────────
Chapter 16 Compatibility and Portability
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 324/813
10/16/2018 PCjs: Advanced MS-DOS Programming
At the beginning of this book, we surveyed the history of MS-DOS and saw
that new versions come along nearly every year, loosely coupled to the
introduction of new models of personal computers. We then focused on each
of the mainstream issues of MS-DOS applications programming: the user
interface; mass storage; memory management; control of "child" processes;
and special classes of programs, such as filters, interrupt handlers, and
device drivers.
It's now time to close the circle and consider two global concerns of
MS-DOS programming: compatibility and portability. For your programs to
remain useful in a constantly evolving software and hardware environment,
you must design them so that they perform reliably on any reasonable
machine configuration and exploit available system resources; in addition,
you should be able to upgrade them easily for new versions of MS-DOS, for
new machines, and, for that matter, for completely new environments such
as MS OS/2.
Degrees of Compatibility
■ MS-DOS─compatible applications
■ Hardware-compatible applications
■ "Ill-behaved" applications
ROM BIOS─compatible applications use the documented MS-DOS and ROM BIOS
function calls but do not access the hardware directly. As recently as
three years ago, this strategy might have significantly limited a
program's potential market. Today, the availability of high-quality
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 325/813
10/16/2018 PCjs: Advanced MS-DOS Programming
IBM-compatible ROM BIOSes from companies such as Phoenix has ensured the
dominance of the IBM ROM BIOS standard; virtually no machines are being
sold in which a program cannot rely as much on the ROM BIOS interface as
it might on the MS-DOS interface. However, as we noted in Chapters 6 and
7, the ROM BIOS display and serial drivers are still not adequate to the
needs of high-performance interactive applications, so the popular
programs that fall into this category are few.
Program structure
Design your programs as .EXE files with separate code, data, and stack
segments; shun the use of .COM files. Use the Microsoft conventions for
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 326/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Obtain the MS-DOS version number with Int 21H Function 30H during your
program's initialization and be sure that all of the functions your
program requires are actually available. If you find that the host MS-DOS
version is inadequate, be careful about which functions you call to
display an error message and to terminate.
Use the enhanced capabilities of MS-DOS versions 3 and 4 when your program
is running under those versions. For example, you can specify a sharing
mode when opening a file with Int 21H Function 3DH, you can create
temporary or unique files with Int 21H Functions 5AH and 5BH, and you
can obtain extended error information (including a recommended recovery
strategy) with Int 21H Function 59H. Section 2 of this book contains
version-dependency information for each MS-DOS function.
Use the handle file functions exclusively and extend full path support
throughout your application (being sure to allow for the maximum possible
path length during user input of filenames). Use buffered I/O whenever
possible. The device drivers in MS-DOS versions 2.0 and later can handle
strings as long as 64 KB, and performance will be improved if you write
fewer, larger records as opposed to many short ones.
Avoid the use of FCBs, the Int 25H or Int 26H functions, or the ROM BIOS
disk driver. If you must use FCBs, close them when you are done with them
and don't move them around while they are open. Avoid reopening FCBs that
are already open or reclosing FCBs that have already been closed──these
seemingly harmless practices can cause problems when network software is
running.
Memory management
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 327/813
10/16/2018 PCjs: Advanced MS-DOS Programming
As a general rule, don't touch any memory that is not owned by your
program. To set or inspect interrupt vectors, use Int 21H Functions 25H
and 35H rather than editing the interrupt vector table directly. If you
alter the contents of interrupt vectors, save their original values and
restore them before the program exits.
Process management
Exception handling
Install Ctrl-C (Int 23H) and critical-error (Int 24H) handlers so that
your program cannot be terminated unexpectedly by the user's entry of
Ctrl-C or Ctrl-Break or by a hardware I/O failure. This is particularly
important if your program uses expanded memory or installs its own
interrupt handlers.
When you feel the need to introduce ROM BIOS or hardware dependence for
performance reasons, keep it isolated to small, well-documented procedures
that can be easily modified when the hardware changes. Use macros and
equates to hide hardware characteristics and to avoid spreading "magic
numbers" throughout your program.
If you use ROM BIOS functions in your program, you must check the machine
model at runtime to be sure that the functions your program needs are
actually available. There is a machine ID byte at F000:FFFEH whose value
is interpreted as follows:
──────────────────────────────────────────────────────────────────────────
F8H PS/2 Models 70 and 80
F9H PC Convertible
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 328/813
10/16/2018 PCjs: Advanced MS-DOS Programming
FDH PCjr
FFH PC "Classic"
──────────────────────────────────────────────────────────────────────────
In some cases, submodels can be identified; see Int 15H Function C0H on
page 573. Section 3 of this book contains version-dependency information
for each ROM BIOS function.
When writing your own direct video drivers, you must determine the type
and capabilities of the video adapter by a combination of Int 10H calls,
reading ports, and inspection of the ROM BIOS data area at 0040:0000H and
the memory reserved for the EGA or VGA ROM BIOS, among other things. The
techniques required are beyond the scope of this book but are well
explained in Programmer's Guide to PC and PS/2 Video Systems (Microsoft
Press, 1987).
■ The 8253 timer chip's channels 0 and 2 (ports 40H, 42H, and 43H)
■ Control of the interrupt system via the 8259 PIC's mask register at
port 21H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 329/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Keyboard mapping, the keyboard controller, and the floppy and fixed disk
controllers are areas of relative hardware instability. Programs that
bypass MS-DOS for keyboard or disk access are much less likely to function
properly across the different PC models and are also prone to interfere
with each other and with well-behaved applications.
OS/2 Compatibility
The 3.x Box traps Int 21H function calls and remaps them into OS/2
function calls, emulating an MS-DOS 3.3 environment with the file-sharing
module (SHARE.EXE) loaded but returning a major version number of 10
instead of 3 for Int 21H Function 30H. The 3.x Box also supports most ROM
BIOS calls, either by emulating their function or by interlocking the
device and then calling the original ROM BIOS routine. In addition, the
3.x Box maintains the ROM BIOS data area, provides timer ticks to
applications via Int 1CH, and supports certain undocumented MS-DOS
services and data structures so that most TSR utilities can function
properly. Nevertheless, the 3.x Box's emulation of MS-DOS is not perfect,
and you must be aware of certain constraints on MS-DOS applications
running under OS/2.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 330/813
10/16/2018 PCjs: Advanced MS-DOS Programming
applications when they are in the background because they execute in real
mode and are thus not subject to hardware memory protection; nothing else
ensures that they will not interfere with a protected-mode process that
has control of the screen and keyboard.
Direct writes to a fixed disk using Int 26H or Int 13H are not allowed.
This prevents the file system from being corrupted, because protected-mode
applications running concurrently with the MS-DOS application may also be
writing to the same disk. Imagine the mess if a typical MS-DOS unerase
utility were to alter the root directory and FAT at the same time that a
protected-mode database program was updating its file and indexes!
To give you a feeling for both the nature of the OS/2 API and the
practices that should be avoided in MS-DOS programming if portability to
OS/2 is desired, I will outline my own strategy for converting existing
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 331/813
10/16/2018 PCjs: Advanced MS-DOS Programming
1. Segmentation
2. Rationalization
3. Encapsulation
4. Conversion
5. Optimization
The first three stages can (and should) be performed and tested in the
MS-DOS environment; only the last two require OS/2 and the protected-mode
programming tools. As you read on, you may notice that an MS-DOS program
that follows the compatibility guidelines presented earlier in this
chapter requires relatively little work to make it run in protected mode.
This is the natural benefit of working with the operating system instead
of against it.
Segmentation
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 332/813
10/16/2018 PCjs: Advanced MS-DOS Programming
After restructuring and segmentation, reassemble and link your program and
check to be sure it still works as expected under MS-DOS. Changing or
adding segmentation often uncovers hidden addressing assumptions in the
code, so it is best to track these problems down before making other
substantive changes to the program.
Rationalization
First, you must ruthlessly eliminate any elements that manipulate the
peripheral device adapters directly, alter interrupt priorities, edit the
system interrupt-vector table, or depend on CPU speed or characteristics
(such as timing loops). In protected mode, control of the interrupt system
is completely reserved to the operating system and its device drivers, I/O
ports may be read or written by an application only under very specific
conditions, and timing loops burn up CPU cycles that can be used by other
processes.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 333/813
10/16/2018 PCjs: Advanced MS-DOS Programming
manipulation of the video adapter and its regen buffer poses obvious
difficulties in a multitasking, protected-memory environment such as OS/2.
For porting purposes, you must convert all routines that write text to the
display, modify character attributes, or affect cursor shape or position
into Int 21H Function 40H calls using ANSI escape sequences or into ROM
BIOS Int 10H calls. Similarly, you must convert all hardware-dependent
keyboard operations to Int 21H Function 3FH or ROM BIOS Int 16H calls.
Once all hardware dependence has been expunged from your program, your
next priority is to make it well-behaved in its use of system memory.
Under MS-DOS an application is typically handed all remaining memory in
the system to do with as it will; under OS/2 the converse is true: A
process is initially allocated only enough memory to hold its code,
declared data storage, and stack. You can make the MS-DOS loader behave
like the OS/2 loader by linking your application with the /CPARMAXALLOC
switch. Alternatively, your program can give up all extra memory during
its initialization with Int 21H Function 4AH, as recommended earlier in
this chapter.
Finally, you must turn your attention to file and device handling. Replace
any calls to FCB file functions with their handle-based equivalents,
because OS/2 does not support FCBs in protected mode at all. Check
pathnames for validity within the application; although MS-DOS and the 3.x
Box silently truncate a name or extension, OS/2 refuses to open or create
a file in protected mode if the name or extension is too long and returns
an error instead. Replace any use of the predefined handles for the
standard auxiliary and standard list devices with explicit opens of COM1,
PRN, LPT1, and so on, using the resulting handle for read and write
operations. OS/2 does not supply processes with standard handles for the
serial communications port or printer.
Encapsulation
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 334/813
10/16/2018 PCjs: Advanced MS-DOS Programming
program that is specific to the host operating system. The objective here
is to localize the program's "knowledge" of the environment into small
procedures that can be subsequently modified without affecting the
remainder of the program.
──────────────────────────────────────────────────────────────────────────
stdin equ 0 ; standard input handle
stdout equ 1 ; standard output handle
stderr equ 2 ; standard error handle
.
.
.
mov dx,seg msg ; DS:DX = message address
mov ds,dx
mov dx,offset DGROUP:msg
mov cx,msg_len ; CX = message length
mov bx,stdout ; BX = handle
mov ah,40h ; AH = function 40h write
int 21h ; transfer to MS-DOS
jc error ; jump if error
cmp ax,msg_len ; all characters written?
jne diskfull ; no, device is full
.
.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 335/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
──────────────────────────────────────────────────────────────────────────
Figure 16-1. Typical in-line code for an MS-DOS function call. This
particular sequence writes a string to the standard output device. Since
the standard output might be redirected to a file without the program's
knowledge, it must also check that all of the requested characters were
actually written; if the returned length is less than the requested
length, this usually indicates that the standard output has been
redirected to a disk file and that the disk is full.
──────────────────────────────────────────────────────────────────────────
stdin equ 0 ; standard input handle
stdout equ 1 ; standard output handle
stderr equ 2 ; standard error handle
.
.
.
mov dx,seg msg ; DS:DX = message address
mov ds,dx
mov dx,offset DGROUP:msg
mov cx,msg_len ; CX = message length
mov bx,stdout ; BX = handle
call write ; perform the write
jc error ; jump if error
cmp ax,msg_len ; all characters written?
jne diskfull ; no, device is full
.
.
.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 336/813
10/16/2018 PCjs: Advanced MS-DOS Programming
write endp
.
.
.
──────────────────────────────────────────────────────────────────────────
Figure 16-2. Code from Figure 16-1 after "encapsulation." The portion of
the code that is operating-system dependent has been isolated inside a
subroutine that is called from other points within the application.
When you have completed the encapsulation of system services and access to
the PSP and environment, subject your program once more to thorough
testing under MS-DOS. This is your last chance, while you are still
working in a familiar milieu and have access to your favorite debugging
tools, to detect any subtle errors you may have introduced during the
three conversion steps discussed thus far.
Conversion
Next, you must rewrite each system-dependent procedure you created during
the encapsulation stage to conform to the OS/2 protected-mode API. In
contrast to MS-DOS functions, which are actuated through software
interrupts and pass parameters in registers, OS/2 API functions are
requested through a far call to a named entry point. Parameters are passed
on the stack, along with the addresses of variables within the calling
program's data segment that will receive any results returned by the
function. The status of an operation is returned in register AX──zero if
the function succeeded, an error code otherwise. All other registers are
preserved.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 337/813
10/16/2018 PCjs: Advanced MS-DOS Programming
no counterpart under MS-DOS; you can usually select reasonable values for
these extra parameters that will make their existence temporarily
invisible to the remainder of the application.
──────────────────────────────────────────────────────────────────────────
stdin equ 0 ; standard input handle
stdout equ 1 ; standard output handle
stderr equ 2 ; standard error handle
extrn DosWrite:far
.
.
.
mov dx,seg msg ; DS:DX = message address
mov ds,dx
mov dx,offset DGROUP:msg
mov cx,msg_len ; CX = message length
mov bx,stdout ; BX = handle
call write ; perform the write
jc error ; jump if error
cmp ax,msg_len ; all characters written?
jne diskfull ; no, device is full
.
.
.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 338/813
10/16/2018 PCjs: Advanced MS-DOS Programming
push bx ; handle
push ds ; address of data
push dx
push cx ; length of data
push ds ; receives length written
mov ax,offset DGROUP:wlen
push ax
call DosWrite ; transfer to OS/2
or ax,ax ; did write succeed?
jnz write1 ; jump, write failed
mov ax,wlen ; no error, OR cleared CY
ret ; and AX := bytes written
write endp
.
.
.
──────────────────────────────────────────────────────────────────────────
Figure 16-3. Code from Figure 16-2 after "conversion." The MS-DOS
function call has been replaced with the equivalent OS/2 function call.
Since the knowledge of the operating system has been hidden inside the
subroutine by the previous encapsulation step, the surrounding program's
requests for write operations should run unchanged. Note that the OS/2
function had to be declared as an external name with the "far" attribute,
and that a variable named wlen was added to the data segment of the
application to receive the actual number of bytes written.
Figures 16-4, 16-5, and 16-6 list the OS/2 services that are equivalent
to selected MS-DOS and ROM BIOS Int 21H, Int 10H, and Int 16H calls.
MS-DOS functions related to FCBs and PSPs are not included in these tables
because OS/2 does not support either of these structures. The MS-DOS
terminate-and-stay-resident functions are also omitted. Because OS/2 is a
true multitasking system, a process doesn't need to terminate in order to
stay resident while another process is running.
╓┌─┌───────────────────┌────────────────────────────────┌────────────────────╖
MS-DOS Description OS/2 function
──────────────────────────────────────────────────────────────────────────
Int 21H Function
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 339/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 340/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 16-4. Table of selected MS-DOS function calls and their OS/2
counterparts. Note that OS/2 functions are typically more powerful and
flexible than the corresponding MS-DOS functions, and that this is not a
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 341/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Figure 16-5. Table of ROM BIOS Int 10H video-display driver functions
used by MS-DOS applications and their OS/2 equivalents. This is not a
complete list of OS/2 video services.
Figure 16-6. Table of ROM BIOS Int 16H keyboard driver functions used by
MS-DOS applications and their OS/2 equivalents. This is not a complete
list of OS/2 keyboard services.
Optimization
1. Modifying the program's user-interface code for the more powerful OS/2
keyboard and display API functions.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 342/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 343/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
SECTION 2 MS-DOS FUNCTIONS REFERENCE
────────────────────────────────────────────────────────────────────────────
This section documents the services that the MS-DOS kernel provides to
application programs via software interrupts 20H─2FH. Each MS-DOS function
is described in the same format:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 344/813
10/16/2018 PCjs: Advanced MS-DOS Programming
For purposes of clarity, the examples may include instructions that would
not be necessary if the code were inserted into a working program. For
example, most of the examples explicitly set the segment registers when
passing the address of a filename or buffer to MS-DOS; in real
applications, the segment registers are usually initialized once at entry
to the program and left alone thereafter.
╓┌─┌───────┌────────┌───────────────────────────────────────┌───────┌────────╖
Hex Dec Function name Vers F/H☼
Hex Dec Function name Vers F/H☼
──────────────────────────────────────────────────────────────────────────
00H 0 Terminate Process 1.0+
01H 1 Character Input with Echo 1.0+
02H 2 Character Output 1.0+
03H 3 Auxiliary Input 1.0+
04H 4 Auxiliary Output 1.0+
05H 5 Printer Output 1.0+
06H 6 Direct Console I/O 1.0+
07H 7 Unfiltered Character Input Without Echo 1.0+
08H 8 Character Input Without Echo 1.0+
09H 9 Display String 1.0+
0AH 10 Buffered Keyboard Input 1.0+
0BH 11 Check Input Status 1.0+
0CH 12 Flush Input Buffer and Then Input 1.0+
0DH 13 Disk Reset 1.0+
0EH 14 Select Disk 1.0+
0FH 15 Open File 1.0+ F
10H 16 Close File 1.0+ F
11H 17 Find First File 1.0+ F
12H 18 Find Next File 1.0+ F
Hex Dec Function name Vers F/H☼
──────────────────────────────────────────────────────────────────────────
12H 18 Find Next File 1.0+ F
13H 19 Delete File 1.0+ F
14H 20 Sequential Read 1.0+ F
15H 21 Sequential Write 1.0+ F
16H 22 Create File 1.0+ F
17H 23 Rename File 1.0+ F
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 345/813
10/16/2018 PCjs: Advanced MS-DOS Programming
18H 24 Reserved
19H 25 Get Current Disk 1.0+
1AH 26 Set DTA Address 1.0+
1BH 27 Get Default Drive Data 1.0+
1CH 28 Get Drive Data 2.0+
1DH 29 Reserved
1EH 30 Reserved
1FH 31 Reserved
20H 32 Reserved
21H 33 Random Read 1.0+ F
22H 34 Random Write 1.0+ F
23H 35 Get File Size 1.0+ F
24H 36 Set Relative Record Number 1.0+ F
Hex Dec Function name Vers F/H☼
──────────────────────────────────────────────────────────────────────────
24H 36 Set Relative Record Number 1.0+ F
25H 37 Set Interrupt Vector 1.0+
26H 38 Create New PSP 1.0+
27H 39 Random Block Read 1.0+ F
28H 40 Random Block Write 1.0+ F
29H 41 Parse Filename 1.0+
2AH 42 Get Date 1.0+
2BH 43 Set Date 1.0+
2CH 44 Get Time 1.0+
2DH 45 Set Time 1.0+
2EH 46 Set Verify Flag 1.0+
2FH 47 Get DTA Address 2.0+
30H 48 Get MS-DOS Version Number 2.0+
31H 49 Terminate and Stay Resident 2.0+
32H 50 Reserved
33H 51 Get or Set Break Flag, Get Boot Drive 2.0+
34H 52 Reserved
35H 53 Get Interrupt Vector 2.0+
36H 54 Get Drive Allocation Information 2.0+
Hex Dec Function name Vers F/H☼
──────────────────────────────────────────────────────────────────────────
36H 54 Get Drive Allocation Information 2.0+
37H 55 Reserved
38H 56 Get or Set Country Information 2.0+
39H 57 Create Directory 2.0+
3AH 58 Delete Directory 2.0+
3BH 59 Set Current Directory 2.0+
3CH 60 Create File 2.0+ H
3DH 61 Open File 2.0+ H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 346/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 347/813
10/16/2018 PCjs: Advanced MS-DOS Programming
╓┌─┌───────┌────────┌───────────────────────────────────────┌───────┌────────╖
Hex Dec Function name Vers F/H
──────────────────────────────────────────────────────────────────────────
Character I/O
01H 1 Character Input with Echo 1.0+
02H 2 Character Output 1.0+
03H 3 Auxiliary Input 1.0+
04H 4 Auxiliary Output 1.0+
05H 5 Printer Output 1.0+
06H 6 Direct Console I/O 1.0+
Hex Dec Function name Vers F/H
──────────────────────────────────────────────────────────────────────────
06H 6 Direct Console I/O 1.0+
07H 7 Unfiltered Character Input Without Echo 1.0+
08H 8 Character Input Without Echo 1.0+
09H 9 Display String 1.0+
0AH 10 Buffered Keyboard Input 1.0+
0BH 11 Check Input Status 1.0+
0CH 12 Flush Input Buffer and Then Input 1.0+
File Operations
0FH 15 Open File 1.0+ F
10H 16 Close File 1.0+ F
11H 17 Find First File 1.0+ F
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 348/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Record Operations
14H 20 Sequential Read 1.0+ F
Hex Dec Function name Vers F/H
──────────────────────────────────────────────────────────────────────────
14H 20 Sequential Read 1.0+ F
15H 21 Sequential Write 1.0+ F
1AH 26 Set DTA Address 1.0+
21H 33 Random Read 1.0+ F
22H 34 Random Write 1.0+ F
24H 36 Set Relative Record Number 1.0+ F
27H 39 Random Block Read 1.0+ F
28H 40 Random Block Write 1.0+ F
2FH 47 Get DTA Address 2.0+
3FH 63 Read File or Device 2.0+ H
40H 64 Write File or Device 2.0+ H
42H 66 Set File Pointer 2.0+ H
5CH 92 Lock or Unlock File Region 3.0+ H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 349/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Directory Operations
39H 57 Create Directory 2.0+
3AH 58 Delete Directory 2.0+
3BH 59 Set Current Directory 2.0+
47H 71 Get Current Directory 2.0+
Hex Dec Function name Vers F/H
──────────────────────────────────────────────────────────────────────────
47H 71 Get Current Directory 2.0+
Disk Management
0DH 13 Disk Reset 1.0+
0EH 14 Select Disk 1.0+
19H 25 Get Current Disk 1.0+
1BH 27 Get Default Drive Data 1.0+
1CH 28 Get Drive Data 2.0+
2EH 46 Set Verify Flag 1.0+
36H 54 Get Drive Allocation Information 2.0+
54H 84 Get Verify Flag 2.0+
Process Management
00H 0 Terminate Process 1.0+
26H 38 Create New PSP 1.0+
31H 49 Terminate and Stay Resident 2.0+
4BH 75 Execute Program (EXEC) 2.0+
4CH 76 Terminate Process with Return Code 2.0+
4DH 77 Get Return Code 2.0+
Hex Dec Function name Vers F/H
──────────────────────────────────────────────────────────────────────────
4DH 77 Get Return Code 2.0+
62H 98 Get PSP Address 3.0+
Memory Management
48H 72 Allocate Memory Block 2.0+
49H 73 Release Memory Block 2.0+
4AH 74 Resize Memory Block 2.0+
58H 88 Get or Set Allocation Strategy 3.0+
Network Functions
5EH 94 Get Machine Name, Get or Set Printer 3.1+
Setup
5FH 95 Device Redirection 3.1+
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 350/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Reserved Functions
18H 24 Reserved
1DH 29 Reserved
1EH 30 Reserved
Hex Dec Function name Vers F/H
──────────────────────────────────────────────────────────────────────────
1EH 30 Reserved
1FH 31 Reserved
20H 32 Reserved
32H 50 Reserved
34H 52 Reserved
37H 55 Reserved
50H 80 Reserved
51H 81 Reserved
52H 82 Reserved
53H 83 Reserved
55H 85 Reserved
5DH 93 Reserved
60H 96 Reserved
61H 97 Reserved
64H 100 Reserved
69H 105 Reserved
6AH 106 Reserved
6BH 107 Reserved
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 351/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
Hex Dec Function name Vers F/H
──────────────────────────────────────────────────────────────────────────
──────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 20H [1.0]
Terminate process
────────────────────────────────────────────────────────────────────────────
■ File buffers are flushed and any open handles for files or devices owned
by the process are closed.
Call with:
Returns:
Nothing
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 352/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ Any files that have been written to using FCBs should be closed before
performing this exit call; otherwise, data may be lost.
· Int 27H
■ [2.0+] Int 21H Functions 31H and 4CH are the preferred methods for
termination, since they allow a return code to be passed to the parent
process.
Example:
.
.
.
int 20h ; transfer to MS-DOS
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 00H
Terminate process
────────────────────────────────────────────────────────────────────────────
■ File buffers are flushed and any open handles for files or devices owned
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 353/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 00H
CS = segment address of program segment prefix
Returns:
Nothing
Notes:
■ Any files that have been written to using FCBs should be closed before
performing this exit call; otherwise, data may be lost.
· Int 20H
· Int 27H
■ [2.0+] Int 21H Functions 31H and 4CH are the preferred methods for
termination, since they allow a return code to be passed to the parent
process.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 354/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Example:
.
.
.
mov ah,0 ; function number
int 21h ; transfer to MS-DOS
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 01H
Character input with echo
────────────────────────────────────────────────────────────────────────────
[1] Inputs a character from the keyboard, then echoes it to the display.
If no character is ready, waits until one is available.
[2.0+] Reads a character from the standard input device and echoes it to
the standard output device. If no character is ready, waits until one is
available. Input can be redirected. (If input has been redirected, there
is no way to detect EOF.)
Call with:
AH = 01H
Returns:
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 355/813
10/16/2018 PCjs: Advanced MS-DOS Programming
F10) on the IBM PC and compatibles, you must call this function twice.
The first call returns the value 00H to signal the presence of an
extended code.
■ See also Int 21H Functions 06H, 07H, and 08H, which provide character
input with various combinations of echo and/or Ctrl-C sensing.
■ [2.0+] You can also read the keyboard by issuing a read (Int 21H
Function 3FH) using the predefined handle for the standard input
(0000H), if input has not been redirected, or a handle obtained by
opening the logical device CON.
Example:
Read one character from the keyboard into register AL, echo it to the
display, and store it in the variable char.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 02H
Character output
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 02H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 356/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
Nothing
Notes:
■ If the standard output has not been redirected, a backspace code (08H)
causes the cursor to move left one position. If output has been
redirected, the backspace code does not receive any special treatment.
■ [2.0+] You can also send strings to the display by performing a write
(Int 21H Function 40H) using the predefined handle for the standard
output (0001H), if output has not been redirected, or a handle obtained
by opening the logical device CON.
Example:
.
.
.
mov ah,2 ; function number
mov dl,'*' ; character to output
int 21h ; transfer to MS-DOS
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 03H
Auxiliary input
────────────────────────────────────────────────────────────────────────────
[2.0+] Reads a character from the standard auxiliary device. The default
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 357/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 03H
Returns:
Notes:
■ At startup on the IBM PC, PC-DOS initializes the first serial port to
2400 baud, no parity, 1 stop bit, and 8 data bits. Other implementations
of MS-DOS may initialize the serial device differently.
■ There is no way for a user program to read the status of the auxiliary
device or to detect I/O errors (such as lost characters) through this
function call. On the IBM PC, more precise control can be obtained by
calling ROM BIOS Int 14H or by driving the communications controller
directly.
■ [2.0+] You can also input from the auxiliary device by requesting a read
(Int 21H Function 3FH) using the predefined handle for the standard
auxiliary device (0003H) or using a handle obtained by opening the
logical device AUX.
Example:
Read a character from the standard auxiliary input and store it in the
variable char.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 358/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 04H
Auxiliary output
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 04H
DL = 8-bit data for output
Returns:
Nothing
Notes:
■ If the output device is busy, this function waits until the device is
ready to accept a character.
■ There is no way to poll the status of the auxiliary device using this
function. On the IBM PC, more precise control can be obtained by calling
ROM BIOS Int 14H or by driving the communications controller directly.
■ [2.0+] You can also send strings to the auxiliary device by performing a
write (Int 21H Function 40H) using the predefined handle for the
standard auxiliary device (0003H) or using a handle obtained by opening
the logical device AUX.
Example:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 359/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
.
mov ah,4 ; function number
mov dl,'*' ; character to output
int 21h ; transfer to MS-DOS
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 05H
Printer output
────────────────────────────────────────────────────────────────────────────
[2.0+] Sends a character to the standard list device. The default device
is the printer on the first parallel port (LPT1), unless explicitly
redirected by the user with the MODE command.
Call with:
AH = 05H
DL = 8-bit data for output
Returns:
Nothing
Notes:
■ If the printer is busy, this function waits until the printer is ready
to accept the character.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 360/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ [2.0+] You can also send strings to the printer by performing a write
(Int 21H Function 40H) using the predefined handle for the standard
printer device (0004H) or using a handle obtained by opening the logical
device PRN or LPT1.
Example:
.
.
.
mov ah,5 ; function number
mov dl,'*' ; character to output
int 21h ; transfer to MS-DOS
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 06H
Direct console I/O
────────────────────────────────────────────────────────────────────────────
Used by programs that need to read and write all possible characters and
control codes without any interference from the operating system.
Call with:
AH = 06H
DL = function requested
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 361/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
Nothing
Notes:
■ See also Int 21H Functions 01H, 07H, and 08H, which provide character
input with various combinations of echo and/or Ctrl-C sensing, and
Functions 02H and 09H, which may be used to write characters to the
standard output.
■ [2.0+] You can also read the keyboard by issuing a read (Int 21H
Function 3FH) using the predefined handle for the standard input
(0000H), if input has not been redirected, or a handle obtained by
opening the logical device CON.
■ [2.0+] You can also send characters to the display by issuing a write
(Int 21H Function 40H) using the predefined handle for the standard
output (0001H), if output has not been redirected, or a handle obtained
by opening the logical device CON.
Examples:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 362/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
.
mov ah,6 ; function number
mov dl,'*' ; character to output
int 21h ; transfer to MS-DOS
.
.
.
Read a character from the standard input device and save it in the
variable char. If no character is ready, wait until one is available.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 07H
Unfiltered character input without echo
────────────────────────────────────────────────────────────────────────────
[1] Reads a character from the keyboard without echoing it to the display.
If no character is ready, waits until one is available.
[2.0+] Reads a character from the standard input device without echoing it
to the standard output device. If no character is ready, waits until one
is available. Input may be redirected. (If input has been redirected,
there is no way to detect EOF.)
Call with:
AH = 07H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 363/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
Notes:
■ See also Int 21H Functions 01H, 06H, and 08H, which provide character
input with various combinations of echo and/or Ctrl-C sensing.
■ [2.0+] You can also read the keyboard by issuing a read (Int 21H
Function 3FH) using the predefined handle for the standard input
(0000H), if input has not been redirected, or a handle obtained by
opening the logical device CON.
Example:
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 08H
Character input without echo
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 364/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
[1] Reads a character from the keyboard without echoing it to the display.
If no character is ready, waits until one is available.
[2.0+] Reads a character from the standard input device without echoing it
to the standard output device. If no character is ready, waits until one
is available. Input may be redirected. (If input has been redirected,
there is no way to detect EOF.)
Call with:
AH = 08H
Returns:
Notes:
■ See also Int 21H Functions 01H, 06H, and 07H, which provide character
input with various combinations of echo and/or Ctrl-C sensing.
■ [2.0+] You can also read the keyboard by issuing a read (Int 21H
Function 3FH) using the predefined handle for the standard input
(0000H), if input has not been redirected, or a handle obtained by
opening the logical device CON.
Example:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 365/813
10/16/2018 PCjs: Advanced MS-DOS Programming
char db 0
.
.
.
mov ah,8 ; function number
int 21h ; transfer to MS-DOS
mov char,al ; save character
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 09H
Display string
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 09H
DS:DX = segment:offset of string
Returns:
Nothing
Notes:
■ The string must be terminated with the character $ (24H), which is not
transmitted. Any other ASCII codes, including control codes, can be
embedded in the string.
■ See Int 21H Functions 02H and 06H for single-character output to the
video display or standard output device.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 366/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ [2.0+] You can also send strings to the display by performing a write
(Int 21H Function 40H) using the predefined handle for the standard
output (0001H), if it has not been redirected, or a handle obtained by
opening the logical device CON.
Example:
Send the string Hello World, followed by a carriage return and line feed,
to the standard output device.
cr equ 0dh
lf equ 0ah
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 0AH (10)
Buffered keyboard input
────────────────────────────────────────────────────────────────────────────
[2.0+] Reads a string of bytes from the standard input device, up to and
including an ASCII carriage return (0DH), and places them in a
user-designated buffer. The characters are echoed to the standard output
device. Input may be redirected. (If input has been redirected, there is
no way to detect EOF.)
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 367/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 0AH
DS:DX = segment:offset of buffer
Returns:
Notes:
Byte Contents
────────────────────────────────────────────────────────────────────────
0 maximum number of characters to read, set by program
1 number of characters actually read (excluding carriage
return), set
by MS-DOS
2+ string read from keyboard or standard input, terminated by
a carriage return (0DH)
────────────────────────────────────────────────────────────────────────
■ If the buffer fills to one fewer than the maximum number of characters
it can hold, subsequent input is ignored and the bell is sounded until a
carriage return is detected.
■ See Int 21H Functions 01H, 06H, 07H, and 08H for single-character input
from the keyboard or standard input device.
■ [2.0+] You can also read strings from the keyboard by performing a read
(Int 21H Function 3FH) using the predefined handle for the standard
input (0000H), if it has not been redirected, or a handle obtained by
opening the logical device CON.
Example:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 368/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 0BH (11)
Check input status
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 0BH
Returns:
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 369/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Example:
.
.
.
mov ah,0bh ; function number
int 21h ; transfer to MS-DOS
or al,al ; character waiting?
jnz ready ; jump if char ready
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 0CH (12)
Flush input buffer and then input
────────────────────────────────────────────────────────────────────────────
[1] Clears the type-ahead buffer and then invokes one of the keyboard
input functions.
[2.0+] Clears the standard input buffer and then invokes one of the
character input functions. Input can be redirected.
Call with:
AH = 0CH
AL = number of input function to be invoked after resetting
buffer (must be 01H, 06H, 07H, 08H, or 0AH)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 370/813
10/16/2018 PCjs: Advanced MS-DOS Programming
(if AL = 0AH)
Returns:
Notes:
■ A function number in AL other than 01H, 06H, 07H, 08H, or 0AH simply
flushes the input buffer and returns control to the calling program.
Example:
char db 0
.
.
.
mov ah,0ch ; function number
mov al,1 ; subfunction = input char
int 21h ; transfer to MS-DOS
mov char,al ; save character
.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 371/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 0DH (13)
Disk reset
────────────────────────────────────────────────────────────────────────────
Flushes all file buffers. All data that has been logically written by user
programs, but has been temporarily buffered within MS-DOS, is physically
written to the disk.
Call with:
AH = 0DH
Returns:
Nothing
Notes:
■ This function does not update the disk directory for any files that are
still open. If your program fails to properly close all files before the
disk is removed, and files have changed size, the data forced out to the
disk by this function may still be inaccessible because the directory
entries will not be correct.
■ [3.3+] Int 21H Function 68H (Commit File) should be used in preference
to this function, since it also updates the disk directory.
Example:
.
.
.
mov ah,0dh ; function number
int 21h ; transfer to MS-DOS
.
.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 372/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 0EH (14)
Select disk
────────────────────────────────────────────────────────────────────────────
Selects the specified drive to be the current, or default, disk drive and
returns the total number of logical drives in the system.
Call with:
AH = 0EH
DL = drive code (0 = A, 1 = B, etc.)
Returns:
Notes:
■ Logical drives means the total number of block devices: floppy disks,
simulated disk drives (RAMdisks), and hard-disk drives. A single
physical hard-disk drive is frequently partitioned into two or more
logical drives.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 373/813
10/16/2018 PCjs: Advanced MS-DOS Programming
is greater.
Example:
Make drive B the current (default) disk drive. Save the total number of
logical drives in the system in the variable drives.
drives db 0
.
.
.
mov ah,0eh ; function number
mov dl,1 ; drive 1 = B
int 21h ; transfer to MS-DOS
mov drives,al ; save total drives
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 0FH (15)
Open file
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 0FH
DS:DX = segment:offset of file control block
Returns:
AL = 00H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 374/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AL = 0FFH
Notes:
■ If your program is going to use a record size other than 128 bytes, it
should set the record-size field at FCB offset 0EH after the file is
successfully opened and before any other disk operation.
■ For format of directory time and date, see Int 21H Function 57H.
■ [2.0+] Int 21H Function 3DH, which allows full access to the
hierarchical directory structure, should be used in preference to this
function.
Example:
Attempt to open the file named QUACK.DAT on the default disk drive.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 375/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 10H (16)
Close file
────────────────────────────────────────────────────────────────────────────
Closes a file, flushes all MS-DOS internal disk buffers associated with
the file to disk, and updates the disk directory if the file has been
modified or extended.
Call with:
AH = 10H
DS:DX = segment:offset of file control block
Returns:
AL = 00H
AL = FFH
Notes:
Example:
Close the file that was previously opened using the file control block
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 376/813
10/16/2018 PCjs: Advanced MS-DOS Programming
named myfcb.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 11H (17)
Find first file
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 11H
DS:DX = segment:offset of file control block
Returns:
AL = 00H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 377/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AL = FFH
Notes:
■ Use Int 21H Function 1AH to set the DTA to point to a buffer of
adequate size before calling this function.
■ An extended FCB must be used to search for files that have the system,
hidden, read-only, directory, or volume-label attributes.
■ [2.0+] Int 21H Function 4EH, which allows full access to the
hierarchical directory structure, should be used in preference to this
function.
Example:
Search for the first file with the extension .COM in the current
directory.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 378/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 12H (18)
Find next file
────────────────────────────────────────────────────────────────────────────
Given that a previous call to Int 21H Function 11H has been successful,
returns the next matching filename (if any).
Call with:
AH = 12H
DS:DX = segment:offset of file control block
Returns:
AL = 00H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 379/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AL = FFH
Notes:
■ This function assumes that the FCB used as input has been properly
initialized by a previous call to Int 21H Function 11H (and possible
subsequent calls to Int 21H Function 12H) and that the filename or
extension being searched for contained at least one wildcard character.
■ As with Int 21H Function 11H, it is important to use Int 21H Function
1AH to set the DTA to a buffer of adequate size before calling this
function.
■ [2.0+] Int 21H Functions 4EH and 4FH, which allow full access to the
hierarchical directory structure, should be used in preference to this
function.
Example:
Assuming a previous successful call to function 11H, search for the next
file with the extension .COM in the current directory. If the DTA has not
been changed since the previous search, another call to Function 1AH is
not necessary.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 380/813
10/16/2018 PCjs: Advanced MS-DOS Programming
mov ds,dx
mov dx,offset myfcb
int 21h ; transfer to MS-DOS
or al,al ; check status
jnz error ; jump if no match
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 13H (19)
Delete file
────────────────────────────────────────────────────────────────────────────
Deletes all matching files from the current directory on the default or
specified disk drive.
Call with:
AH = 13H
DS:DX = segment:offset of file control block
Returns:
AL = 00H
AL = FFH
Notes:
■ [2.0+] Int 21H Function 41H, which allows full access to the
hierarchical directory structure, should be used in preference to this
function.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 381/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ [3.0+] If the program is running on a network, the user must have Create
rights to the directory containing the file to be deleted.
Example:
Delete the file MYFILE.DAT from the current disk drive and directory.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 14H (20)
Sequential read
────────────────────────────────────────────────────────────────────────────
Reads the next sequential block of data from a file, then increments the
file pointer appropriately.
Call with:
AH = 14H
DS:DX = segment:offset of previously opened file control block
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 382/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
■ The record is read into memory at the current disk transfer area (DTA)
address, specified by the most recent call to Int 21H Function 1AH. If
the size of the record and the location of the buffer are such that a
segment overflow or wraparound would occur, the function fails with a
return code of 02H.
■ The file location of the data that will be read is specified by the
combination of the current block field (offset 0CH) and current record
field (offset 20H) of the file control block (FCB). These fields are
also automatically incremented by this function.
■ [3.0+] If the program is running on a network, the user must have Read
access rights to the directory containing the file to be read.
Example:
Read 1024 bytes of data from the file specified by the previously opened
file control block myfcb.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 383/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 15H (21)
Sequential write
────────────────────────────────────────────────────────────────────────────
Writes the next sequential block of data into a file, then increments the
file pointer appropriately.
Call with:
AH = 15H
DS:DX = segment:offset of previously opened file control block
Returns:
Notes:
■ The file location of the data that will be written is specified by the
combination of the current block field (offset 0CH) and current record
field (offset 20H) of the file control block (FCB). These fields are
also automatically incremented by this function.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 384/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ [3.0+] If the program is running on a network, the user must have Write
access rights to the directory containing the file to be written.
Example:
Write 1024 bytes of data to the file specified by the previously opened
file control block myfcb.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 16H (22)
Create file
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 16H
DS:DX = segment:offset of unopened file control block
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 385/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
AL = 00H
AL = FFH
Notes:
■ Since this function also opens the file, a subsequent call to Int 21H
Function 0FH is not required.
■ For format of directory time and date, see Int 21H Function 57H.
■ [2.0+] Int 21H Functions 3CH, 5AH, 5BH, and 6CH, which provide full
access to the hierarchical directory structure, should be used in
preference to this function.
■ [3.0+] If the program is running on a network, the user must have Create
rights to the directory that will contain the new file.
Example:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 386/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Create a file in the current directory using the name in the file control
block myfcb.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 17H (23)
Rename file
────────────────────────────────────────────────────────────────────────────
Alters the name of all matching files in the current directory on the disk
in the specified drive.
Call with:
AH = 17H
DS:DX = segment:offset of "special" file control block
Returns:
AL = 00H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 387/813
10/16/2018 PCjs: Advanced MS-DOS Programming
existing file)
AL = FFH
Notes:
■ The special file control block has a drive code, filename, and extension
in the usual position (bytes 0 through 0BH) and a second filename
starting 6 bytes after the first (offset 11H).
■ The ? wildcard character can be used in the first filename. Every file
matching the first file specification will be renamed to match the
second file specification.
■ [2.0+] Int 21H Function 56H, which allows full access to the
hierarchical directory structure, should be used in preference to this
function.
Example:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 388/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 18H (24)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 19H (25)
Get current disk
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 19H
Returns:
Notes:
■ Some other Int 21H functions use drive codes beginning at 1 (that is,
1 = A, 2 = B, etc.) and reserve drive code zero for the default drive.
Example:
Get the current disk drive and save the code in the variable cdrive.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 389/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
.
mov ah,19h ; function number
int 21h ; transfer to MS-DOS
mov cdrive,al ; save drive code
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 1AH (26)
Set DTA address
────────────────────────────────────────────────────────────────────────────
Specifies the address of the disk transfer area (DTA) to be used for
subsequent FCB-related function calls.
Call with:
AH = 1AH
DS:DX = segment:offset of disk transfer area
Returns:
Nothing
Notes:
■ Int 21H Function 2FH can be used to determine the current disk transfer
address.
■ The only handle-type operations that rely on the DTA address are the
directory search functions, Int 21H Functions 4EH and 4FH.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 390/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Example:
Set the current disk transfer area address to the buffer labeled buff.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 1BH (27)
Get default drive data
────────────────────────────────────────────────────────────────────────────
Obtains selected information about the default disk drive and a pointer to
the media identification byte from its file allocation table.
Call with:
AH = 1BH
Returns:
If function successful
AL = FFH
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 391/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
■ To obtain information about disks other than the one in the default
drive, use Int 21H Function 1CH or 36H.
■ [1] The address returned in DS:BX points to a copy of the first sector
of the actual FAT, with the media ID byte in the first byte.
■ [2.0+] The address returned in DS:BX points only to a copy of the media
ID byte from the disk's FAT; the memory above that address cannot be
assumed to contain the FAT or any other useful information. If direct
access to the FAT is required, use Int 25H to read it into memory.
Example:
.
.
.
mov ah,1bh ; function number
int 21h ; transfer to MS-DOS
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 392/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 1CH (28)
Get drive data
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 1CH
DL = drive code (0 = default, 1 = A, etc.)
Returns:
If function successful
AL = FFH
Notes:
■ In general, this call is identical to Int 21H Function 1BH, except for
the ability to designate a specific disk drive. See also Int 21H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 393/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ [1] The address returned in DS:BX points to a copy of the first sector
of the actual FAT, with the media ID byte in the first byte.
■ [2.0+] The address returned in DS:BX points only to a copy of the media
ID byte from the disk's FAT; the memory above that address cannot be
assumed to contain the FAT or any other useful information. If direct
access to the FAT is required, use Int 25H to read it into memory.
Example:
.
.
.
mov ah,1ch ; function number
mov dl,3 ; drive code 3 = C
int 21h ; transfer to MS-DOS
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 1DH (29)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 1EH (30)
Reserved
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 394/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 1FH (31)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 20H (32)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 21H (33)
Random read
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 21H
DS:DX = segment:offset of previously opened file control block
Returns:
Notes:
■ The record is read into memory at the current disk transfer area
address, specified by the most recent call to Int 21H Function 1AH. It
is the programmer's responsibility to ensure that this area is large
enough for any record that will be transferred. If the size and location
of the buffer are such that a segment overflow or wraparound would
occur, the function fails with a return code of 02H.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 395/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ The current block field (offset 0CH) and current record field (offset
20H) are updated to agree with the relative-record field as a side
effect of the function.
■ [3.0+] If the program is running on a network, the user must have Read
access rights to the directory containing the file to be read.
Example:
Open the file MYFILE.DAT, set the record length to 1024 bytes, then read
record number 4 from the file into the buffer named buff.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 396/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 22H (34)
Random write
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 22H
DS:DX = segment:offset of previously opened file control block
Returns:
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 397/813
10/16/2018 PCjs: Advanced MS-DOS Programming
file from memory at the current disk transfer address, specified by the
most recent call to Int 21H Function 1AH. If the size and location of
the buffer are such that a segment overflow or wraparound would occur,
the function fails with a return code of 02H.
■ The current block field (offset 0CH) and current record field (offset
20H) are updated to agree with the relative-record field as a side
effect of the function.
■ If a record is written beyond the current end of file, the space between
the old end of file and the new record is allocated but not initialized.
■ [3.0+] If the program is running on a network, the user must have Write
access rights to the directory containing the file to be written.
Example:
Open the file MYFILE.DAT, set the record length to 1024 bytes, write
record number 4 into the file from the buffer named buff, then close the
file.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 398/813
10/16/2018 PCjs: Advanced MS-DOS Programming
mov ds,dx
mov dx,offset myfcb
int 21h ; transfer to MS-DOS
or al,al ; check status
jnz error ; jump if no file
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 23H (35)
Get file size
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 399/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 23H
DS:DX = segment:offset of unopened file control block
Returns:
AL = 00H
and FCB relative-record field (offset 21H) set to the number of records in
the file, rounded up if necessary to the next complete record
AL = FFH
Notes:
■ The record-size field can be set to 1 to find the size of the file in
bytes.
■ Because record numbers are zero based, this function can be used to
position the FCB's file pointer to the end of file.
Example:
Determine the size in bytes of the file MYFILE.DAT and leave the result in
registers DX:AX.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 400/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
mov ah,23h ; function number
mov dx,seg myfcb ; address of FCB
mov ds,dx
mov dx,offset myfcb
; record size = 1 byte
mov word ptr myfcb+0eh,1
int 21h ; transfer to MS-DOS
or al,al ; check status
jnz error ; jump if no file
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 24H (36)
Set relative record number
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 24H
DS:DX = segment:offset of previously opened file control block
Returns:
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 401/813
10/16/2018 PCjs: Advanced MS-DOS Programming
0CH), and current record (offset 20H) fields of the file control block.
■ All four bytes of the FCB relative-record field (offset 21H) should be
initialized to zero before calling this function.
Example:
; initialize relative
; record field to zero
mov word ptr myfcb+21h,0
mov word ptr myfcb+23h,0
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 25H (37)
Set interrupt vector
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 402/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 25H
AL = interrupt number
DS:DX = segment:offset of interrupt handling routine
Returns:
Nothing
Notes:
Example:
Install a new interrupt handler, named zdiv, for "divide by zero" CPU
exceptions.
.
.
.
mov ah,25h ; function number
mov al,0 ; interrupt number
mov dx,seg zdiv ; address of handler
mov ds,dx
mov dx,offset zdiv
int 21h ; transfer to MS-DOS
.
.
.
zdiv: ; int 00h handler
iret ; (does nothing)
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 403/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Copies the program segment prefix (PSP) of the currently executing program
to a specified segment address in free memory, then updates the new PSP to
make it usable by another program.
Call with:
AH = 26H
DX = segment of new program segment prefix
Returns:
Nothing
Notes:
■ After the executing program's PSP is copied into the new segment, the
memory size information in the new PSP is updated appropriately and the
current contents of the termination (Int 22H), Ctrl-C handler (Int 23H),
and critical-error handler (Int 24H) vectors are saved starting at
offset 0AH.
■ This function does not load another program or in itself cause one to be
executed.
■ [2.0+] Int 21H Function 4BH (EXEC), which can be used to load and
execute programs or overlays in either .COM or .EXE format, should be
used in preference to this function.
Example:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 404/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
mov ah,26h ; function number
mov dx,cs ; PSP segment of
; this program
add dx,1000h ; add 64 KB as
; paragraph address
int 21h ; transfer to MS-DOS
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 27H (39)
Random block read
────────────────────────────────────────────────────────────────────────────
Reads one or more sequential records from a file into memory, starting at
a designated file location.
Call with:
AH = 27H
CX = number of records to read
DS:DX = segment:offset of previously opened file control block
Returns:
Notes:
■ The records are read into memory at the current disk transfer area
address, specified by the most recent call to Int 21H Function 1AH. It
is the programmer's responsibility to ensure that this area is large
enough for the group of records that will be transferred. If the size
and location of the buffer are such that a segment overflow or
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 405/813
10/16/2018 PCjs: Advanced MS-DOS Programming
wraparound would occur, the function fails with a return code of 02H.
■ After the disk transfer is performed, the current block (offset 0CH),
current record (offset 20H), and relative-record (offset 21H) fields of
the FCB are updated to point to the next record in the file.
■ Compare with Int 21H Function 21H, which transfers only one record per
function call and does not update the FCB relative-record field.
■ [3.0+] If the program is running on a network, the user must have Read
access rights to the directory containing the file to be read.
Example:
Read four 1024-byte records starting at record number 8 into the buffer
named buff, using the file control block myfcb.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 406/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 28H (40)
Random block write
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 28H
CX = number of records to write
DS:DX = segment:offset of previously opened file control block
Returns:
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 407/813
10/16/2018 PCjs: Advanced MS-DOS Programming
the buffer are such that a segment overflow or wraparound would occur,
the function fails with a return code of 02H.
■ After the disk transfer is performed, the current block (offset 0CH),
current record (offset 20H), and relative-record (offset 21H) fields of
the FCB are updated to point to the next record in the file.
■ Compare with Int 21H Function 22H, which transfers only one record per
function call and does not update the FCB relative-record field.
■ [3.0+] If the program is running on a network, the user must have Write
access rights to the directory containing the file to be written.
Example:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 408/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 29H (41)
Parse filename
────────────────────────────────────────────────────────────────────────────
Parses a text string into the various fields of a file control block
(FCB).
Call with:
AH = 29H
AL = flags to control parsing
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 409/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 410/813
10/16/2018 PCjs: Advanced MS-DOS Programming
to ?.
■ This function (and file control blocks in general) cannot be used with
file specifications that include a path.
Example:
Parse the string fname into the file control block myfcb.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 2AH (42)
Get date
────────────────────────────────────────────────────────────────────────────
Obtains the system day of the month, day of the week, month, and year.
Call with:
AH = 2AH
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 411/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
■ This function's register format is the same as that required for Int 21H
Function 2BH (Set Date).
■ This function can be used together with Int 21H Function 2BH to find
the day of the week for an arbitrary date. The current date is first
obtained with Function 2AH and saved. The date of interest is then set
with Function 2BH, and the day of the week for that date is obtained
with a subsequent call to Function 2AH. Finally, the current date is
restored with an additional call to Function 2BH, using the values
obtained with the original Function 2AH call.
Example:
Obtain the current date and save its components in the variables year,
day, and month.
year dw 0
month db 0
day db 0
.
.
.
mov ah,2ah ; function number
int 21h ; transfer to MS-DOS
mov year,cx ; save year (word)
mov month,dh ; save month (byte)
mov day,dl ; save day (byte)
.
.
.
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 412/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Initializes the system clock driver to a specific date. The system time is
not affected.
Call with:
AH = 2BH
CX = year (1980 through 2099)
DH = month (1 through 12)
DL = day (1 through 31)
Returns:
Note:
■ This function's register format is the same as that required for Int 21H
Function 2AH (Get Date).
Example:
Set the system date according to the contents of the variables year, day,
and month.
year dw 0
month db 0
day db 0
.
.
.
mov ah,2bh ; function number
mov cx,year ; get year (word)
mov dh,month ; get month (byte)
mov dl,day ; get day (byte)
int 21h ; transfer to MS-DOS
or al,al ; check status
jnz error ; jump if date invalid
.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 413/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 2CH (44)
Get time
────────────────────────────────────────────────────────────────────────────
Obtains the time of day from the system real-time clock driver, converted
to hours, minutes, seconds, and hundredths of seconds.
Call with:
AH = 2CH
Returns:
Notes:
■ This function's register format is the same as that required for Int 21H
Function 2DH (Set Time).
■ On most IBM PC─compatible systems, the real-time clock does not have a
resolution of single hundredths of seconds. On such machines, the values
returned by this function in register DL are discontinuous.
Example:
Obtain the current time and save its two major components in the variables
hours and minutes.
hours db 0
minutes db 0
.
.
.
mov ah,2ch ; function number
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 414/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 2DH (45)
Set time
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 2DH
CH = hours (0 through 23)
CL = minutes (0 through 59)
DH = seconds (0 through 59)
DL = hundredths of seconds (0 through 99)
Returns:
Note:
■ This function's register format is the same as that required for Int 21H
Function 2CH (Get Time).
Example:
Set the system time according to the contents of the variables hours and
minutes. Force the current seconds and hundredths of seconds to zero.
hours db 0
minutes db 0
.
.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 415/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
mov ah,2dh ; function number
mov ch,hours ; get hours (byte)
mov cl,minutes ; get minutes (byte)
mov dx,0 ; force seconds and
; hundredths to zero
int 21h ; transfer to MS-DOS
or al,al ; check status
jnz error ; jump if time invalid
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [1.0]
Function 2EH (46)
Set verify flag
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 2EH
AL = 00H if turning off verify flag
01H if turning on verify flag
Returns:
Nothing
Notes:
■ The current state of the verify flag can be determined using Int 21H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 416/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Function 54H.
■ The state of the verify flag is also controlled by the MS-DOS commands
VERIFY OFF and VERIFY ON.
Example:
Save the current state of the system verify flag in the variable vflag,
then force all subsequent disk writes to be verified.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 2FH (47)
Get DTA address
────────────────────────────────────────────────────────────────────────────
Obtains the current address of the disk transfer area (DTA) for FCB file
read/write operations.
Call with:
AH = 2FH
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 417/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Note:
■ The disk transfer area address is set with Int 21H Function 1AH. The
default DTA is a 128-byte buffer at offset 80H in the program segment
prefix.
Example:
Obtain the current disk transfer area address and save it in the variable
olddta.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 30H (48)
Get MS-DOS version number
────────────────────────────────────────────────────────────────────────────
Returns the version number of the host MS-DOS operating system. This
function is used by application programs to determine the capabilities of
their environment.
Call with:
AH = 30H
AL = 00H
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 418/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AL = 00H
Notes:
■ Because this function was not defined under MS-DOS version 1, it should
always be called with AL = 00H. In an MS-DOS version 1 environment, AL
will be returned unchanged.
Example:
Get the MS-DOS version number, terminating the current process with an
error message if not running under MS-DOS version 2.0 or later.
msg db cr,lf
db 'Wrong MS-DOS version'
db cr,lf,'$'
.
.
.
mov ax,3000h ; function number
int 21h ; transfer to MS-DOS
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 419/813
10/16/2018 PCjs: Advanced MS-DOS Programming
; terminate process
mov ah,0 ; function number
int 21h ; transfer to MS-DOS
label1: .
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 31H (49)
Terminate and stay resident
────────────────────────────────────────────────────────────────────────────
■ File buffers are flushed and any open handles for files or devices owned
by the process are closed.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 420/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 31H
AL = return code
DX = amount of memory to reserve (in paragraphs)
Returns:
Nothing
Notes:
■ This function attempts to set the initial memory allocation block to the
length in paragraphs specified in register DX. If other memory blocks
have been requested by the application using Int 21H Function 48H, they
will not be released by this function.
· Int 20H
· Int 27H
■ The return code may be retrieved by a parent process with Int 21H
Function 4DH (Get Return Code). It can also be tested in a batch file
with an IF ERRORLEVEL statement. By convention, a return code of zero
indicates successful execution, and a nonzero return code indicates an
error.
■ This function should not be called by .EXE programs that are loaded at
the high end of the transient program area (that is, linked with the
/HIGH switch) because doing so reserves the memory that is normally used
by the transient part of COMMAND.COM. If COMMAND.COM cannot be reloaded,
the system will fail.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 421/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Example:
.
.
.
mov ah,31h ; function number
mov al,1 ; return code for parent
mov dx,0400h ; paragraphs to reserve
int 21h ; transfer to MS-DOS
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 32H (50)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 33H (51)
Get or set break flag, get boot drive
────────────────────────────────────────────────────────────────────────────
Obtains or changes the status of the operating system's break flag, which
influences Ctrl-C checking during function calls. Also returns the system
boot drive in version 4.0.
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 422/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 33H
AL = 00H
AH = 33H
AL = 01H
DL = 00H if turning break flag OFF
01H if turning break flag ON
AH = 33H
AL = 05H
Returns:
Notes:
■ When the system break flag is on, the keyboard is examined for a Ctrl-C
entry whenever any operating-system input or output is requested; if
Ctrl-C is detected, control is transferred to the Ctrl-C handler (Int
23H). When the break flag is off, MS-DOS only checks for a Ctrl-C entry
when executing the traditional character I/O functions (Int 21H
Functions 01H through 0CH).
■ The break flag is not part of the local environment of the currently
executing program; it affects all programs. An application that alters
the flag should first save the flag's original status, then restore the
flag before terminating.
Example:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 423/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Save the current state of the system break flag in the variable brkflag,
then turn the break flag off to disable Ctrl-C checking during most MS-DOS
function calls.
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 34H (52)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 35H (53)
Get interrupt vector
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 35H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 424/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AL = interrupt number
Returns:
Note:
■ Together with Int 21H Function 25H (Set Interrupt Vector), this
function is used by well-behaved application programs to modify or
inspect the machine interrupt vector table.
Example:
Obtain the address of the current interrupt handler for hardware interrupt
level 0 (divide by zero) and save it in the variable oldint0.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 36H (54)
Get drive allocation information
────────────────────────────────────────────────────────────────────────────
Obtains selected information about a disk drive, from which the drive's
capacity and remaining free space can be calculated.
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 425/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 36H
DL = drive code (0 = default, 1 = A, etc.)
Returns:
If function successful
AX = FFFFH
Notes:
■ This function regards "lost" clusters as being in use and does not
report them as part of the number of available clusters, even though
they are not assigned to a file.
Example:
Calculate the capacity of disk drive C in bytes, leaving the result in the
variable drvsize. (This code assumes that the product of sectors/cluster *
bytes/sector will not overflow 16 bits.)
mul cx ; sectors/cluster
; * bytes/sector
mul dx ; * total clusters
; result now in DX:AX
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 426/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 37H (55)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 38H (56)
Get or set country information
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 38H
AL = 0 to get "current" country information
AH = 38H
AL = 0 to get "current" country information
1─FEH to get information for countries with code < 255
FFH to get information for countries with code >=
255
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 427/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 38H
AL = 1─FEH country code for countries with code < 255
FFH for countries with code >= 255
Returns:
If function successful
BX = country code
DS:DX = segment:offset of buffer holding internationalization
information
Byte(s) Contents
00H─01H date format
0 = USA m d y
1 = Europe d m y
2 = Japan y m d
(for MS-DOS versions 2.0 and later, PC-DOS versions 3.0 and later)
Byte(s) Contents
00H─01H date format
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 428/813
10/16/2018 PCjs: Advanced MS-DOS Programming
0 = USA m d y
1 = d m y
Europe
2 = Japan y m d
If function unsuccessful
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 429/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ [3.3+] Int 21H Function 65H (Get Extended Country Information) returns
a superset of the information supplied by this function.
Examples:
If the program is running under PC-DOS 3.3 and the current country code is
49 (West Germany), ctrybuf is filled in with the following information:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 430/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 39H (57)
Create directory
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 39H
DS:DX = segment:offset of ASCIIZ pathname
Returns:
If function successful
If function unsuccessful
Note:
· a directory with the same name at the end of the same path already
exists.
· the parent directory for the new directory is the root directory and
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 431/813
10/16/2018 PCjs: Advanced MS-DOS Programming
is full.
· [3.0+] the program is running on a network and the user running the
program has insufficient access rights.
Example:
dname db 'C:\MYSUB',0
.
.
.
mov ah,39h ; function number
mov dx,seg dname ; address of pathname
mov ds,dx
mov dx,offset dname
int 21h ; transfer to MS-DOS
jc error ; jump if create failed
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 3AH (58)
Delete directory
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 3AH
DS:DX = segment:offset of ASCIIZ pathname
Returns:
If function successful
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 432/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Note:
· [3.0+] the program is running on a network and the user running the
program has insufficient access rights.
Example:
dname db 'C:\MYSUB',0
.
.
.
mov ah,3ah ; function number
mov dx,seg dname ; address of pathname
mov ds,dx
mov dx,offset dname
int 21h ; transfer to MS-DOS
jc error ; jump if delete failed
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 3BH (59)
Set current directory
────────────────────────────────────────────────────────────────────────────
Sets the current, or default, directory using the specified drive and
path.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 433/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 3BH
DS:DX = segment:offset of ASCIIZ pathname
Returns:
If function successful
If function unsuccessful
Notes:
■ The function fails if any element of the pathname does not exist.
■ Int 21H Function 47H can be used to obtain the name of the current
directory before using Int 21H Function 3BH to select another, so that
the original directory can be restored later.
Example:
dname db 'C:\MYSUB',0
.
.
.
mov ah,3bh ; function number
mov dx,seg dname ; address of pathname
mov ds,dx
mov dx,offset dname
int 21h ; transfer to MS-DOS
jc error ; jump if bad path
.
.
.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 434/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 3CH (60)
Create file
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 3CH
CX = file attribute (bits may be combined)
Returns:
If function successful
If function failed
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 435/813
10/16/2018 PCjs: Advanced MS-DOS Programming
· the file is being created in the root directory and the root directory
is full.
· a file with the same name and the read-only attribute already exists
in the specified directory.
· [3.0+] the program is running on a network and the user running the
program has insufficient access rights.
■ [3.0+] See the entries for Int 21H Functions 5AH and 5BH, which may
also be used to create files.
■ [4.0+] Int 21H Function 6CH combines the services of Functions 3CH,
3DH, and 5BH.
Example:
Create and open, or truncate to zero length and open, the file
C:\MYDIR\MYFILE.DAT, and save the handle for subsequent access to the
file.
fname db 'C:\MYDIR\MYFILE.DAT',0
fhandle dw ?
.
.
.
mov ah,3ch ; function number
xor cx,cx ; normal attribute
mov dx,seg fname ; address of pathname
mov ds,dx
mov dx,offset fname
int 21h ; transfer to MS-DOS
jc error ; jump if create failed
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 436/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 3DH (61)
Open file
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 3DH
AL = access mode
Bit(s) Significance
0─2 access mode
000 = read access
001 = write access
010 = read/write access
3 reserved (0)
4─6 sharing mode (MS-DOS versions 3.0 and later)
000 = compatibility mode
001 = deny all
010 = deny write
011 = deny read
100 = deny none
7 inheritance flag (MS-DOS versions 3.0 and later)
0 = child process inherits handle
1 = child does not inherit handle
Returns:
If function successful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 437/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
Notes:
■ Any normal, system, or hidden file with a matching name will be opened
by this function. If the file is read-only, the success of the operation
also depends on the access code in bits 0─2 of register AL. After
opening the file, the file read/write pointer is set to offset zero (the
first byte of the file).
· the file is opened with an access mode of read/write and the file has
the read-only attribute.
· [3.0+] SHARE.EXE is loaded and the file has already been opened by one
or more other processes in a sharing mode that is incompatible with
the current program's request.
■ The file's date and time stamp can be accessed after a successful open
call with Int 21H Function 57H.
■ [2] Only bits 0─2 of register AL are significant; the remaining bits
should be zero for upward compatibility.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 438/813
10/16/2018 PCjs: Advanced MS-DOS Programming
with an error code of 02H. Int 21H Function 59H can be used to obtain
information about the sharing violation.
■ [4.0+] Int 21H Function 6CH combines the services of Functions 3CH,
3DH, and 5BH.
Example:
Open the file C:\MYDIR\MYFILE.DAT for both reading and writing, and save
the handle for subsequent access to the file.
fname db 'C:\MYDIR\MYFILE.DAT',0
fhandle dw ?
.
.
.
mov ah,3dh ; function number
mov al,2 ; mode = read/write
mov dx,seg fname ; address of pathname
mov ds,dx
mov dx,offset fname
int 21h ; transfer to MS-DOS
jc error ; jump if open failed
mov fhandle,ax ; save file handle
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 3EH (62)
Close file
────────────────────────────────────────────────────────────────────────────
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 439/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 3EH
BX = handle
Returns:
If function successful
If function unsuccessful
Note:
■ If you accidentally call this function with a zero handle, the standard
input device is closed, and the keyboard appears to go dead. Make sure
you always call the close function with a valid, nonzero handle.
Example:
fhandle dw 0
.
.
.
mov ah,3eh ; function number
mov bx,fhandle ; file handle
int 21h ; transfer to MS-DOS
jc error ; jump if close failed
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 3FH (63)
Read file or device
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 440/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 3FH
BX = handle
CX = number of bytes to read
DS:DX = segment:offset of buffer
Returns:
If function successful
If function unsuccessful
Notes:
■ If the carry flag is returned clear but AX = 0, then the file pointer
was already at end of file when the program requested the read.
■ If the carry flag is returned clear but AX < CX, then a partial record
was read at end of file or there is an error.
■ [3.0+] If the program is running on a network, the user must have Read
access rights to the directory and file.
Example:
Using the file handle from a previous open or create operation, read 1024
bytes at the current file pointer into the buffer named buff.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 441/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 40H (64)
Write file or device
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 40H
BX = handle
CX = number of bytes to write
DS:DX = segment:offset of buffer
Returns:
If function successful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 442/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AX = bytes transferred
If function unsuccessful
Notes:
■ If the carry flag is returned clear but AX < CX, then a partial record
was written or there is an error. This can be caused by a Ctrl-Z (1AH)
embedded in the data if the destination is a character device in cooked
mode or by a disk full condition if the destination is a file.
■ [3.0+] If the program is running on a network, the user must have Write
access rights to the directory and file.
Example:
Using the handle from a previous open or create operation, write 1024
bytes to disk at the current file pointer from the buffer named buff.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 443/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 41H (65)
Delete file
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 41H
DS:DX = segment:offset of ASCIIZ pathname
Returns:
If function successful
If function unsuccessful
Notes:
■ Only one file at a time may be deleted with this function. Unlike the
FCB-related Delete File function (Int 21H Function 13H), the * and ?
wildcard characters are not allowed in the file specification.
· the designated file exists but has the read-only attribute. (Int 21H
Function 43H can be used to examine and modify a file's attribute
before attempting to delete it.)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 444/813
10/16/2018 PCjs: Advanced MS-DOS Programming
· [3.0+] the program is running on a network, and the user running the
program has insufficient access rights.
Example:
Delete the file named MYFILE.DAT from the directory \MYDIR on drive C.
fname db 'C:\MYDIR\MYFILE.DAT',0
.
.
.
mov ah,41h ; function number
mov dx,seg fname ; filename address
mov ds,dx
mov dx,offset fname
int 21h ; transfer to MS-DOS
jc error ; jump if delete failed
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 42H (66)
Set file pointer
────────────────────────────────────────────────────────────────────────────
Sets the file location pointer relative to the start of file, end of file,
or current file position.
Call with:
AH = 42H
AL = method code
00H absolute offset from start of file
01H signed offset from current file pointer
02H signed offset from end of file
BX = handle
CX = most significant half of offset
DX = least significant half of offset
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 445/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function successful
If function unsuccessful
Notes:
■ Method 02H may be used to find the size of the file by calling Int 21H
Function 42H with an offset of 0 and examining the pointer location
that is returned.
Examples:
Using the file handle from a previous open or create operation, set the
current file pointer position to 1024 bytes after the start of file.
fhandle dw ?
.
.
.
mov ah,42h ; function number
mov al,0 ; method = absolute
mov bx,fhandle ; file handle
mov cx,0 ; upper half of offset
mov dx,1024 ; lower half of offset
int 21h ; transfer to MS-DOS
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 446/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The following subroutine accepts a record number, record size, and handle
and sets the file pointer appropriately.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 43H (67)
Get or set file attributes
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 43H
AL = 00H to get attributes
01H to set attributes
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 447/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
If function successful
If function unsuccessful
Notes:
■ Bits 3 and 4 of register CX must always be clear (0) when this function
is called; in other words, you cannot change an existing file into a
directory or volume label. However, you can assign the "hidden"
attribute to an existing directory with this function.
■ [3.0+] If the program is running on a network, the user must have Create
access rights to the directory containing the file whose attribute is to
be modified.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 448/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Example:
fname db 'D:\MYDIR\MYFILE.DAT',0
.
.
.
mov ah,43h ; function number
mov al,01h ; subfunction = modify
mov cx,rdonly ; read-only attribute
mov dx,seg fname ; filename address
mov ds,dx
mov dx,offset fname
int 21h ; transfer to MS-DOS
jc error ; jump if modify failed
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 44H (68)
IOCTL (I/O control)
────────────────────────────────────────────────────────────────────────────
The IOCTL subfunctions and the MS-DOS versions in which they first became
available are:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 449/813
10/16/2018 PCjs: Advanced MS-DOS Programming
╓┌─┌──────────────┌──────────────────────────────────────────┌───────────────╖
Subfunction Name MS-DOS version
──────────────────────────────────────────────────────────────────────────
00H Get Device Information 2.0
01H Set Device Information 2.0
02H Receive Control Data from Character 2.0
Device Driver
03H Send Control Data to Character Device 2.0
Driver
04H Receive Control Data from Block Device 2.0
Driver
05H Send Control Data to Block Device Driver 2.0
06H Check Input Status 2.0
07H Check Output Status 2.0
08H Check If Block Device Is Removable 3.0
Subfunction Name MS-DOS version
──────────────────────────────────────────────────────────────────────────
08H Check If Block Device Is Removable 3.0
09H Check If Block Device Is Remote 3.1
0AH (10) Check If Handle Is Remote 3.1
0BH (11) Change Sharing Retry Count 3.1
0CH (12) Generic I/O Control for Character Devices
CL = 45H: Set Iteration Count 3.2
CL = 4AH: Select Code Page 3.3
CL = 4CH: Start Code Page Preparation 3.3
CL = 4DH: End Code Page Preparation 3.3
CL = 5FH: Set Display Information 4.0
CL = 65H: Get Iteration Count 3.2
CL = 6AH: Query Selected Code Page 3.3
CL = 6BH: Query Prepare List 3.3
CL = 7FH: Get Display Information 4.0
0DH (13) Generic I/O Control for Block Devices
CL = 40H: Set Device Parameters 3.2
CL = 41H: Write Track 3.2
CL = 42H: Format and Verify Track 3.2
CL = 47H: Set Access Flag 4.0
Subfunction Name MS-DOS version
──────────────────────────────────────────────────────────────────────────
CL = 47H: Set Access Flag 4.0
CL = 60H: Get Device Parameters 3.2
CL = 61H: Read Track 3.2
CL = 62H: Verify Track 3.2
CL = 67H: Get Access Flag 4.0
0EH (14) Get Logical Drive Map 3.2
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 450/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Only IOCTL Subfunctions 00H, 06H, and 07H may be used for handles
associated with files. Subfunctions 00H─08H are not supported on network
devices.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 44H (68) Subfunction 00H
IOCTL: get device information
────────────────────────────────────────────────────────────────────────────
Returns a device information word for the file or device associated with
the specified handle.
Call with:
AH = 44H
AL = 00H
BX = handle
Returns:
If function successful
For a file:
Bit(s) Significance
0─5 drive number (0 = A, 1 = B, etc.)
6 0 if file has been written
1 if file has not been written
7 0, indicating a file
8─15 reserved
For a device:
Bit(s) Significance
0 1 if standard input
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 451/813
10/16/2018 PCjs: Advanced MS-DOS Programming
1 1 if standard output
2 1 if NUL device
3 1 if clock device
4 reserved
5 0 if handle in ASCII mode
1 if handle in binary mode
6 0 if end of file on input
7 1, indicating a device
8─13 reserved
14 0 if IOCTL subfunctions 02H and 03H not
supported
1 if IOCTL subfunctions 02H and 03H supported
15 reserved
If function unsuccessful
Notes:
Example:
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 44H (68) Subfunction 01H
IOCTL: set device information
────────────────────────────────────────────────────────────────────────────
Sets certain flags for a handle associated with a character device. This
subfunction may not be used for a handle that is associated with a file.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 452/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 44H
AL = 01H
BX = handle
DX = device information word
Bit(s) Significance
0 1 if standard input
1 1 if standard output
2 1 if NUL device
3 1 if clock device
4 reserved (0)
5 0 to select ASCII mode
1 to select binary mode
6 reserved (0)
7 1, indicating a device
8─15 reserved (0)
Returns:
If function successful
If function unsuccessful
Notes:
■ If register DH does not contain 00H, control returns to the program with
the carry flag set and error code 0001H (invalid function) in register
AX.
Example:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 453/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Place the standard output handle into binary ("raw") mode. This speeds up
output by disabling checking for Ctrl-C, Ctrl-S, and Ctrl-P between each
character.
.
.
.
; get device information
mov ax,4400h ; function & subfunction
mov bx,1 ; standard output handle
int 21h ; transfer to MS-DOS
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 44H (68) Subfunction 02H
IOCTL: read control data from character device driver
────────────────────────────────────────────────────────────────────────────
Reads control data from a character-device driver. The length and contents
of the data are specific to each device driver and do not follow any
standard format. This function does not necessarily result in any input
from the physical device.
Call with:
AH = 44H
AL = 02H
BX = handle
CX = number of bytes to read
DS:DX = segment:offset of buffer
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 454/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function successful
If function unsuccessful
Notes:
Example:
Read a control string from the standard list driver into the buffer buff.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 455/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 44H (68) Subfunction 03H
IOCTL: write control data to character-device driver
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 44H
AL = 03H
BX = handle
CX = number of bytes to write
DS:DX = segment:offset of data
Returns:
If function successful
If function unsuccessful
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 456/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Example:
Write a control string from the buffer buff to the standard list device
driver. The length of the string is assumed to be in the variable ctllen.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 44H (68) Subfunction 04H
IOCTL: read control data from block-device driver
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 457/813
10/16/2018 PCjs: Advanced MS-DOS Programming
application program's buffer. The length and contents of the data are
specific to each device driver and do not follow any standard format. This
function does not necessarily result in any input from the physical
device.
Call with:
AH = 44H
AL = 04H
BL = drive code (0 = default, 1 = A, 2 = B, etc.)
CX = number of bytes to read
DS:DX = segment:offset of buffer
Returns:
If function successful
If function unsuccessful
Notes:
Example:
Read a control string from the block-device driver for drive C into the
buffer buff.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 458/813
10/16/2018 PCjs: Advanced MS-DOS Programming
mov ds,dx
mov dx,offset buff
int 21h ; transfer to MS-DOS
jc error ; jump if read failed
mov ctllen,ax ; save control string length
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 44H (68) Subfunction 05H
IOCTL: write control data to block-device driver
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 44H
AL = 05H
BL = drive code (0 = default, 1 = A, 2 = B, etc.)
CX = number of bytes to write
DS:DX = segment:offset of data
Returns:
If function successful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 459/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
Notes:
Example:
Write a control string from the buffer buff to the block-device driver for
drive C. The length of the string is assumed to be in the variable ctllen.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 460/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 44H (68) Subfunction 06H
IOCTL: check input status
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 44H
AL = 06H
BX = handle
Returns:
If function successful
If function unsuccessful
Note:
■ This function can be used to check the status of character devices, such
as the serial port, that do not have their own "traditional" MS-DOS
status calls.
Example:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 461/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 44H (68) Subfunction 07H
IOCTL: check output status
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 44H
AL = 07H
BX = handle
Returns:
If function successful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 462/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AL = FFH
If function unsuccessful
Note:
■ When used with a handle for a file, this function always returns a ready
status, even if the disk is full or no disk is in the drive.
Example:
Check whether the standard auxiliary device (usually COM1) can accept a
character for output.
────────────────────────────────────────────────────────────────────────────
Int 21H [3.0]
Function 44H (68) Subfunction 08H
IOCTL: check if block device is removable
────────────────────────────────────────────────────────────────────────────
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 463/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 44H
AL = 08H
BL = drive number (0 = default, 1 = A, 2 = B, etc.)
Returns:
If function successful
If function unsuccessful
Notes:
Example:
.
.
.
mov ax,4408h ; function & subfunction
mov bl,3 ; drive 3 = C
int 21h ; transfer to MS-DOS
jc error ; jump if function failed
and al,1 ; test type of medium
jnz fixed ; jump if not removable
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 464/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [3.1]
Function 44H (68) Subfunction 09H
IOCTL: check if block device is remote
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 44H
AL = 09H
BL = drive number (0 = default, 1 = A, 2 = B, etc.)
Returns:
If function successful
If function unsuccessful
Note:
Example:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 465/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
.
mov ax,4409h ; function & subfunction
mov bl,4 ; drive 4 = D
int 21h ; transfer to MS-DOS
jc error ; jump if function failed
and dx,1000h ; test local/remote bit
jnz remote ; jump if network drive
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [3.1]
Function 44H (68) Subfunction 0AH (10)
IOCTL: check if handle is remote
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 44H
AL = 0AH
BX = handle
Returns:
If function successful
bit 15 = 0 if local
1 if remote
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 466/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AX = error code
Notes:
■ If the network has not been started, control returns to the calling
program with the carry flag set and error code 0001H (invalid function)
in register AX.
Example:
────────────────────────────────────────────────────────────────────────────
Int 21H [3.1]
Function 44H (68) Subfunction 0BH (11)
IOCTL: change sharing retry count
────────────────────────────────────────────────────────────────────────────
Sets the number of times MS-DOS retries a disk operation after a failure
caused by a file-sharing violation before it returns an error to the
requesting process. This subfunction is not available unless the
file-sharing module (SHARE.EXE) is loaded.
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 467/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 44H
AL = 0BH
CX = delays per retry (default = 1)
DX = number of retries (default = 3)
Returns:
If function successful
If function unsuccessful
Notes:
xor cx,cx
loop $
■ The sharing retry count affects the behavior of the system as a whole
and is not a local parameter for the process. If a program changes the
sharing retry count, it should restore the default values before
terminating.
Example:
.
.
.
mov ax,440bh ; function & subfunction
mov cx,1 ; delays per retry
mov dx,5 ; number of retries
int 21h ; transfer to MS-DOS
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 468/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [3.2]
Function 44H (68) Subfunction 0CH (12)
IOCTL: generic I/O control for character devices
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 44H
AL = 0CH
BX = handle
CH = category (major) code:
00H = unknown
01H = COM1, COM2, COM3, or COM4 (3.3)
03H = CON (keyboard and display) (3.3)
05H = LPT1, LPT2, or LPT3 (3.2)
CL = function (minor) code:
45H = Set Iteration Count (3.2)
4AH = Select Code Page (3.3)
4CH = Start Code Page Preparation (3.3)
4DH = End Code Page Preparation (3.3)
5FH = Set Display Information (4.0)
65H = Get Iteration Count (3.2)
6AH = Query Selected Code Page (3.3)
6BH = Query Prepare List (3.3)
7FH = Get Display Information (4.0)
DS:DX = segment:offset of parameter block
Returns:
If function successful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 469/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
Notes:
■ If the minor code is 45H (Set Iteration Count) or 65H (Get Iteration
Count), the parameter block is simply a 2-byte buffer containing or
receiving the iteration count for the printer. This call is valid only
for printer drivers that support Output Until Busy, and determines the
number of times the device driver will wait for the device to signal
ready before returning from the output call.
■ The parameter block for minor code 4DH (End Code Page Preparation) has
the following format:
■ For MS-DOS version 3.3, the parameter block for minor codes 4AH (Select
Code Page) and 6AH (Query Code Page) has the following format:
For MS-DOS version 4.0, minor codes 4AH and 6AH also set or get the
double-byte character set (DBCS) lead byte table, and the following format
is used:
■ The parameter block for minor code 4CH (Start Code Page Preparation) has
the following format:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 470/813
10/16/2018 PCjs: Advanced MS-DOS Programming
dw 0 ; font type
; bit 0 = 0 downloaded
; = 1 cartridge
; bits 1-15 = reserved (0)
dw (n+1)*2 ; length of remainder of
; parameter block
dw n ; number of code pages in
; the following list
dw ? ; code page 1
dw ? ; code page 2
.
.
.
dw ? ; code page n
■ The parameter block for minor code 6BH (Query Prepare List) has the
following format, assuming n hardware code pages and m prepared code
pages (n <= 12, m <= 12):
■ After a minor code 4CH (Start Code Page Preparation) call, the data
defining the code page font is written to the driver using one or more
calls to the IOCTL Write Control Data subfunction (Interrupt 21H,
Function 44H, Subfunction 03H). The format of the data is device- and
driver-specific. After the font data has been written to the driver, a
minor code 4DH (End Code Page Preparation) call must be issued. If no
data is written to the driver between the minor code 4CH and 4DH calls,
the driver interprets the newly prepared code pages as hardware code
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 471/813
10/16/2018 PCjs: Advanced MS-DOS Programming
pages.
■ A special variation of the minor code 4CH (Start Code Page Preparation)
call, called "Refresh," is required to actually load the peripheral
device with the prepared code pages. The refresh operation is obtained
by requesting minor code 4CH with each code page position in the
parameter block set to -1, followed by an immediate call for minor code
4DH (End Code Page Preparation).
■ [4.0+] For minor codes 5FH (Set Display Information) and 7FH (Get
Display Information), the parameter block is formatted as follows:
Example:
Get the current code page for the standard list device.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 472/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [3.2]
Function 44H Subfunction 0DH (13)
IOCTL: generic I/O control for block devices
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 44H
AL = 0DH
BL = drive code (0 = default, 1 = A, 2 = B, etc.)
CH = category (major) code:
08H = disk drive
CL = function (minor) code:
40H = Set Device Parameters
41H = Write Track
42H = Format and Verify Track
47H = Set Access Flag (4.0)
60H = Get Device Parameters
61H = Read Track
62H = Verify Track
67H = Get Access Flag (4.0)
DS:DX = segment:offset of parameter block
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 473/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function successful
If function unsuccessful
Notes:
■ The minor code 40H (Set Device Parameters) function must be used before
an attempt to write, read, format, or verify a track on a logical drive.
In general, the following sequence applies to any of these operations:
· Get the current parameters (minor code 60H). Examine and save them.
· Retrieve the original parameters and restore them with minor code 40H.
■ For minor codes 40H (Set Device Parameters) and 60H (Get Device
Parameters), the parameter block is formatted as follows:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 474/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Value Meaning
0 320/360 KB, 5.25-inch disk
1 1.2 MB, 5.25-inch disk
2 720 KB, 3.5-inch disk
3 single-density, 8-inch disk
4 double-density, 8-inch disk
5 fixed disk
6 tape drive
7 other type of block device
Value Meaning
0 1.2 MB, 5.25-inch disk
1 320/360 KB, 5.25-inch disk
Length Meaning
Word number of sectors in track
Word number of first sector in track
Word size of first sector in track
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 475/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
.
Word number of last sector in track
Word size of last sector in track
■ The device BPB field is a 31-byte data structure that describes the
current disk and its control areas. The field is formatted as follows:
Byte(s) Meaning
00H─01H bytes per sector
02H sectors per cluster (allocation unit)
03─04H reserved sectors, beginning at sector 0
05H number of file allocation tables (FATs)
06H─07H maximum number of root-directory entries
08H─09H number of sectors
0AH media descriptor
0BH─0CH sectors per FAT
0DH─0EH sectors per track
0FH─10H number of heads
11H─14H number of hidden sectors
15H─18H large number of sectors (if bytes 08H─09H=0)
19H─1EH reserved
■ When minor code 40H (Set Device Parameters) is used, the number of
cylinders should not be altered, or some or all of the volume may become
inaccessible.
■ For minor codes 41H (Write Track) and 61H (Read Track), the parameter
block is formatted as follows:
Byte(s) Meaning
00H special-functions field (must be 0)
01H─02H head
03H─04H cylinder
05H─06H starting sector
07H─08H sectors to transfer
09H─0CH transfer buffer address
■ For minor codes 42H (Format and Verify Track) and 62H (Verify Track),
the parameter block is formatted as follows:
Byte(s) Meaning
00H special-functions field
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 476/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Bit(s) Significance
0 0 = Format/Verify track
1 = Format status call (MS-DOS 4.0 only)
1─7 reserved (0)
01H─02H head
03H─04H cylinder
Value Meaning
0 specified number of tracks and sectors per track supported
1 this function not supported by the ROM BIOS
2 specified number of tracks and sectors per track not
supported
3 no disk in drive
■ For minor codes 47H (Set Access Flag) and 67H (Get Access Flag), the
parameter block is formatted as follows:
Byte Meaning
00H special-functions field (must be 0)
01H disk access flag
When the disk access flag is zero, access to the medium is blocked by
the driver. The flag is set to zero when the driver detects an
unformatted medium or a medium with an invalid boot record. When the
access flag is nonzero, read/write operations to the medium are allowed
by the driver. A formatting program must clear the disk access flag with
minor code 47H before it requests minor code 42H (Format and Verify
Track).
Example:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 477/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [3.2]
Function 44H (68) Subfunction 0EH (14)
IOCTL: get logical drive map
────────────────────────────────────────────────────────────────────────────
Returns the logical drive code that was most recently used to access the
specified block device.
Call with:
AH = 44H
AL = 0EH
BL = drive code (0 = default, 1 = A, 2 = B, etc.)
Returns:
If function successful
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 478/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AX = error code
Note:
■ If a drive has not been assigned a logical mapping with Function 44H
Subfunction 0FH, the logical and physical drive codes are the same.
Example:
Check whether drive A has more than one logical drive code.
.
.
.
mov ax,440eh ; function & subfunction
mov bl,1 ; drive 1 = A
int 21h ; transfer to MS-DOS
jc error ; jump if function failed
or al,al ; test drive code
jz label1 ; jump, no drive aliases
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [3.2]
Function 44H (68) Subfunction 0FH (15)
IOCTL: set logical drive map
────────────────────────────────────────────────────────────────────────────
Sets the next logical drive code that will be used to reference a block
device.
Call with:
AH = 44H
AL = 0FH
BL = drive code (0 = default, 1 = A, 2 = B, etc.)
Returns:
If function successful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 479/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
Note:
■ When a physical block device is aliased to more than one logical drive
code, this function can be used to inform the driver which drive code
will next be used to access the device.
Example:
Notify the floppy-disk driver that the next access will be for logical
drive B.
.
.
.
mov ax,440fh ; function & subfunction
mov bl,2 ; drive 2 = B
int 21h ; transfer to MS-DOS
jc error ; jump if function failed
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 45H (69)
Duplicate handle
────────────────────────────────────────────────────────────────────────────
Given a handle for a currently open device or file, returns a new handle
that refers to the same device or file at the same position.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 480/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 45H
BX = handle to be duplicated
Returns:
If function successful
If function unsuccessful
Notes:
■ A seek, read, or write operation that moves the file pointer for one of
the two handles also moves the file pointer associated with the other.
■ This function can be used to efficiently update the directory for a file
that has changed in length, without incurring the overhead of closing
and then reopening the file. The handle for the file is simply
duplicated with this function and the duplicate is closed, leaving the
original handle open for further read/write operations.
Example:
Duplicate the handle stored in the variable fhandle, then close the
duplicate. This ensures that all buffered data is physically written to
disk and that the directory entry for the corresponding file is updated,
but leaves the original handle open for subsequent file operations.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 481/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 46H (70)
Redirect handle
────────────────────────────────────────────────────────────────────────────
Given two handles, makes the second handle refer to the same device or
file at the same location as the first handle. The second handle is then
said to be redirected.
Call with:
AH = 46H
BX = handle for file or device
CX = handle to be redirected
Returns:
If function successful
If function unsuccessful
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 482/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ A seek, read, or write operation that moves the file pointer for one of
the two handles also moves the file pointer associated with the other.
■ This function is commonly used to redirect the standard input and output
handles to another file or device before a child process is executed
with Int 21H Function 4BH.
Example:
Redirect the standard output to the list device, so that all output
directed to the console will appear on the printer instead. Later, restore
the original meaning of the standard output handle.
stdin equ 0
stdout equ 1
stderr equ 2
stdaux equ 3
stdprn equ 4
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 483/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 47H (71)
Get current directory
────────────────────────────────────────────────────────────────────────────
Obtains an ASCIIZ string that describes the path from the root to the
current directory, and the name of that directory.
Call with:
AH = 47H
DL = drive code (0 = default, 1 = A, etc.)
DS:SI = segment:offset of 64-byte buffer
Returns:
If function successful
and buffer is filled in with full pathname from root of current directory.
If function unsuccessful
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 484/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ The returned path name does not include the drive identifier or a
leading backslash (\). It is terminated with a null (00H) byte.
Consequently, if the current directory is the root directory, the first
byte in the buffer will contain 00H.
■ The current directory may be set with Int 21H Function 3BH.
Example:
Get the name of the current directory for drive C into the buffer named
dbuff.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 48H (72)
Allocate memory block
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 48H
BX = number of paragraphs of memory needed
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 485/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
If function successful
If function unsuccessful
Notes:
■ If the function succeeds, the base address of the newly allocated block
is AX:0000.
■ The default allocation strategy used by MS-DOS is "first fit"; that is,
the memory block at the lowest address that is large enough to satisfy
the request is allocated. The allocation strategy can be altered with
Int 21H Function 58H.
Example:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 486/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 49H (73)
Release memory block
────────────────────────────────────────────────────────────────────────────
Releases a memory block and makes it available for use by other programs.
Call with:
AH = 49H
ES = segment of block to be released
Returns:
If function successful
If function unsuccessful
Notes:
■ This function assumes that the memory block being released was
previously obtained by a successful call to Int 21H Function 48H.
■ The function will fail or can cause unpredictable system errors if:
· the program releases a memory block that does not belong to it.
Example:
Release the memory block that was previously allocated in the example for
Int 21H Function 48H (page 438).
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 487/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 4AH (74)
Resize memory block
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 4AH
BX = desired new block size in paragraphs
ES = segment of block to be modified
Returns:
If function successful
If function unsuccessful
Notes:
■ This function modifies the size of a memory block that was previously
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 488/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ A program that uses EXEC (Int 21H Function 4BH) to load and execute a
child program must call this function first to make memory available for
the child, passing the address of its PSP in register ES and the amount
of memory needed for its own code, data, and stacks in register BX.
Example:
Resize the memory block that was allocated in the example for Int 21H
Function 48H (page 438), shrinking it to 32 KB.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 4BH (75)
Execute program (EXEC)
────────────────────────────────────────────────────────────────────────────
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 489/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 4BH
AL = subfunction
00H = Load and Execute Program
03H = Load Overlay
ES:BX = segment:offset of parameter block
DS:DX = segment:offset of ASCIIZ program pathname
Returns:
If function successful
If function unsuccessful
Notes:
■ The parameter block format for Subfunction 00H (Load and Execute
Program) is as follows:
Bytes Contents
00H─01H segment pointer to environment block
02H─03H offset of command line tail
04H─05H segment of command line tail
06H─07H offset of first FCB to be copied into new PSP + 5CH
08H─09H segment of first FCB
0AH─0BH offset of second FCB to be copied into new PSP + 6CH
0CH─0DH segment of second FCB
Bytes Contents
00H─01H segment address where overlay is to be loaded
02H─03H relocation factor to apply to loaded image
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 490/813
10/16/2018 PCjs: Advanced MS-DOS Programming
db 'COMSPEC=A:\COMMAND.COM',0
db 6,' *.DAT',0dh
■ Before a program uses Int 21H Function 4BH to run another program, it
must release all memory it is not actually using with a call to Int 21H
Function 4AH, passing the segment address of its own PSP and the number
of paragraphs to retain.
■ After return from the EXEC function call, the termination type and
return code of the child program may be obtained with Int 21H Function
4DH.
Example:
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 4CH (76)
Terminate process with return code
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 491/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ File buffers are flushed and any open handles for files or devices owned
by the process are closed.
Call with:
AH = 4CH
AL = return code
Returns:
Nothing
Notes:
· Int 20H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 492/813
10/16/2018 PCjs: Advanced MS-DOS Programming
· Int 27H
■ Any files that have been opened using FCBs and modified by the program
should be closed before program termination; otherwise, data may be
lost.
■ The return code can be retrieved by the parent process with Int 21H
Function 4DH (Get Return Code). It can also be tested in a batch file
with an IF ERRORLEVEL statement. By convention, a return code of zero
indicates successful execution, and a non-zero return code indicates an
error.
Example:
.
.
.
mov ah,4ch ; function number
mov al,01h ; return code
int 21h ; transfer to MS-DOS
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 4DH (77)
Get return code
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 4DH
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 493/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
AH = exit type
00H if normal termination by Int 20H, Int 21H Function
00H, or Int 21H Function 4CH
01H if termination by user's entry of CtrlDC
02H if termination by critical-error handler
03H if termination by Int 21H Function 31H or Int 27H
AL = return code passed by child process (0 if child terminated
by Int 20H, Int 21H Function 00H, or Int 27H)
Notes:
■ This function will yield the return code of a child process only once. A
subsequent call without an intervening EXEC (Int 21H Function 4BH) will
not necessarily return any valid information.
■ This function does not set the carry flag to indicate an error. If no
previous child process has been executed, the values returned in AL and
AH are undefined.
Example:
Get the return code and termination kind of child process that was
previously executed with Int 21H Function 4BH (EXEC).
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 4EH (78)
Find first file
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 494/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 4EH
CX = search attribute (bits may be combined)
Returns:
Byte(s) Description
00H─14H reserved (0)
15H attribute of matched file or directory
16H─17H file time
bits 00H─04H = 2-second increments (0─29)
bits 05H─0AH = minutes (0─59)
bits 0BH─0FH = hours (0─23)
18H─19H file date
bits 00H─04H = day (1─31)
bits 05H─08H = month (1─12)
bits 09H─0FH = year (relative to 1980)
1AH─1DH file size
1EH─2AH ASCIIZ filename and extension
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 495/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
■ This function assumes that the DTA has been previously set by the
program with Int 21H Function 1AH to point to a buffer of adequate
size.
Example:
fname db 'C:\MYDIR\*.COM',0
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 496/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 4FH (79)
Find next file
────────────────────────────────────────────────────────────────────────────
Assuming a previous successful call to Int 21H Function 4EH, finds the
next file in the default or specified directory on the default or
specified drive that matches the original file specification.
Call with:
AH = 4FH
Assumes DTA points to working buffer used by previous successful Int 21H
Function 4EH or 4FH.
Returns:
and search results returned in current disk transfer area as described for
Int 21H Function 4EH
Notes:
■ Use of this call assumes that the original file specification passed to
Int 21H Function 4EH contained one or more * or ? wildcard characters.
■ When this function is called, the current disk transfer area (DTA) must
contain information from a previous successful call to Int 21H Function
4EH or 4FH.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 497/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Example:
Continuing the search operation in the example for Int 21H Function 4EH,
find the next .COM file (if any) in the directory \MYDIR on drive C.
fname db 'C:\MYDIR\*.COM',0
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 50H (80)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 51H (81)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 52H (82)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 498/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 54H (84)
Get verify flag
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 54H
Returns:
Notes:
■ The state of the system verify flag can be changed through a call to Int
21H Function 2EH or by the MS-DOS commands VERIFY ON and VERIFY OFF.
Example:
.
.
.
mov ah,54h ; function number
int 21h ; transfer to MS-DOS
cmp al,01h ; check verify state
je label1 ; jump if verify on
; else assume verify off
.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 499/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 55H (85)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 56H (86)
Rename file
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 56H
DS:DX = segment:offset of current ASCIIZ pathname
ES:DI = segment:offset of new ASCIIZ pathname
Returns:
If function successful
If function unsuccessful
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 500/813
10/16/2018 PCjs: Advanced MS-DOS Programming
· the file is being moved to the root directory, and the root directory
is full.
■ The * and ? wildcard characters are not allowed in either the current or
new pathname specifications.
Example:
Change the name of the file MYFILE.DAT in the directory \MYDIR on drive C
to MYTEXT.DAT. At the same time, move the file to the directory \SYSTEM on
the same drive.
oldname db 'C:\MYDIR\MYFILE.DAT',0
newname db 'C:\SYSTEM\MYTEXT.DAT',0
.
.
.
mov ah,56h ; function number
mov dx,seg oldname ; old filename address
mov ds,dx
mov dx,offset oldname
mov di,seg newname ; new filename address
mov es,di
mov di,offset newname
int 21h ; transfer to MS-DOS
jc error ; jump if rename failed
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [2.0]
Function 57H (87)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 501/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Obtains or modifies the date and time stamp in a file's directory entry.
Call with:
AH = 57H
AL = 00H
BX = handle
AH = 57H
AL = 01H
BX = handle
CX = time
bits 00H─04H = 2-second increments (0─29)
bits 05H─0AH = minutes (0─59)
bits 0BH─0FH = hours (0─23)
DX = date
bits 00H─04H = day (1─31)
bits 05H─08H = month (1─12)
bits 09H─0FH = year (relative to 1980)
Returns:
If function successful
CX = time
DX = date
If function unsuccessful
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 502/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ The file must have been previously opened or created via a successful
call to Int 21H Function 3CH, 3DH, 5AH, 5BH, or 6CH.
■ If the 16-bit date for a file is set to zero, that file's date and time
are not displayed on directory listings.
■ A date and time set with this function will prevail, even if the file is
modified afterwards before the handle is closed.
Example:
Get the date that the file MYFILE.DAT was created or last modified, and
then decompose the packed date into its constituent parts in the variables
month, day, and year.
fname db 'MYFILE.DAT',0
month dw 0
day dw 0
year dw 0
.
.
.
; first open the file
mov ah,3dh ; function number
mov al,0 ; read-only mode
mov dx,seg fname ; filename address
mov ds,dx
mov dx,offset fname
int 21h ; transfer to MS-DOS
jc error ; jump if open failed
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 503/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [3.0]
Function 58H (88)
Get or set allocation strategy
────────────────────────────────────────────────────────────────────────────
Obtains or changes the code indicating the current MS-DOS strategy for
allocating memory blocks.
Call with:
AH = 58H
AL = 00H
AH = 58H
AL = 01H
BX = desired strategy code
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 504/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
If function successful
If function unsuccessful
Notes:
· First fit: MS-DOS searches the available memory blocks from low
addresses to high addresses, assigning the first one large enough to
satisfy the block allocation request.
· Best fit: MS-DOS searches all available memory blocks and assigns the
smallest available block that will satisfy the request, regardless of
its position.
· Last fit: MS-DOS searches the available memory blocks from high
addresses to low addresses, assigning the highest one large enough to
satisfy the block allocation request.
■ The default MS-DOS memory allocation strategy is First Fit (code 0).
Example:
Save the code indicating the current memory allocation strategy in the
variable strat, then change the system's memory allocation strategy to
"best fit."
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 505/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [3.0]
Function 59H (89)
Get extended error information
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 59H
BX = 00H
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 506/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 507/813
10/16/2018 PCjs: Advanced MS-DOS Programming
BH = error class
BL = recommended action
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 508/813
10/16/2018 PCjs: Advanced MS-DOS Programming
CH = error locus
01H unknown
02H block device (disk or disk emulator)
03H network
04H serial device
05H memory
Notes:
■ This function may be called after any other Int 21H function call that
returned an error status, in order to obtain more detailed information
about the error type and the recommended action. If the previous Int 21H
function call had no error, 0000H is returned in register AX. This
function may also be called during the execution of a critical-error
(Int 24H) handler.
■ The contents of registers CL, DX, SI, DI, BP, DS, and ES are destroyed
by this function.
■ Note that extended error codes 13H─1FH (19─31) and 34 (22H) correspond
exactly to the error codes 0─0CH (0─12) and 0FH (15) returned by Int
24H.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 509/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ You should not code your programs to recognize only specific error
numbers if you wish to ensure upward compatibility, because new error
codes are added in each version of MS-DOS.
Example:
Attempt to open the file named NOSUCH.DAT using a file control block; if
the open request fails, get the extended error code.
────────────────────────────────────────────────────────────────────────────
Int 21H [3.0]
Function 5AH (90)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 510/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 5AH
CX = attribute (bits may be combined)
Returns:
If function successful
If function unsuccessful
Notes:
■ Files created with this function are not automatically deleted when the
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 511/813
10/16/2018 PCjs: Advanced MS-DOS Programming
· the file is being created in the root directory, and the root
directory is full.
■ See also Int 21H Functions 3CH, 5BH, and 6CH, which provide
additional facilities for creating files.
Example:
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 512/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 5BH
CX = attribute (bits may be combined)
Returns:
If function successful
If function unsuccessful
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 513/813
10/16/2018 PCjs: Advanced MS-DOS Programming
· a file with the identical pathname (i.e., the same filename and
extension in the same location in the directory structure) already
exists.
· the file is being created in the root directory, and the root
directory is full.
■ The file is usually given a normal attribute (0) when it is created, and
is opened for both read and write operations. The attribute can
subsequently be modified with Int 21H Function 43H.
■ See also Int 21H Functions 3CH, 5AH, and 6CH, which provide
alternative ways of creating files.
Example:
Create and open a file named MYFILE.DAT in the directory \MYDIR on drive
C; MS-DOS returns an error if a file with the same name already exists in
that location.
fname db 'C:\MYDIR\MYFILE.DAT',0
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 514/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [3.0]
Function 5CH (92)
Lock or unlock file region
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 5CH
AL = 00H if locking region
01H if unlocking region
BX = handle
CX = high part of region offset
DX = low part of region offset
SI = high part of region length
DI = low part of region length
Returns:
If function successful
If function unsuccessful
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 515/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ Programs that are loaded with the EXEC call (Int 21H Function 4BH)
inherit the handles of their parent but not any active locks.
Example:
Assume that a file was previously opened and that its handle was saved in
the variable fhandle. Lock a 4096 byte region of the file, starting at
32,768 bytes from the beginning of the file, so that it cannot be accessed
by other programs.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 516/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 5DH (93)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H [3.1]
Function 5EH (94) Subfunction 00H
Get machine name
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 5EH
AL = 00H
DS:DX = segment:offset of buffer to receive string
Returns:
If function successful
If function unsuccessful
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 517/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Example:
Get the machine name of the local computer into the buffer named mname.
────────────────────────────────────────────────────────────────────────────
Int 21H [3.1]
Function 5EH (94) Subfunction 02H
Set printer setup string
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 5EH
AL = 02H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 518/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
If function successful
If function unsuccessful
AX = error code
Notes:
■ See also Function 5EH Subfunction 03H, which may be used to obtain the
existing setup string for a particular network printer.
Example:
Initialize the setup string for the printer designated by redirection list
index 2 so that the device is put into boldface mode before printing a
file requested by this network node.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 519/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [3.1]
Function 5EH (94) Subfunction 03H
Get printer setup string
────────────────────────────────────────────────────────────────────────────
Obtains the printer setup string for a particular network printer. This
function call is only available when Microsoft Networks is running.
Call with:
AH = 5EH
AL = 03H
BX = redirection list index
ES:DI = segment:offset of buffer to receive setup string
Returns:
If function successful
If function unsuccessful
Notes:
■ See also Int 21H Function 5EH Subfunction 02H, which is used to specify
a setup string for a network printer.
Example:
Get the setup string for this network node associated with the printer
designated by redirection list index 2.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 520/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [3.1]
Function 5FH (95) Subfunction 02H
Get redirection list entry
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 5FH
AL = 02H
BX = redirection list index
DS:SI = segment:offset of 16-byte buffer to receive local device
name
ES:DI = segment:offset of 128-byte buffer to receive network name
Returns:
If function successful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 521/813
10/16/2018 PCjs: Advanced MS-DOS Programming
BL = device type
03H if printer
04H if drive
If function unsuccessful
Note:
Example:
Get the local and network names for the device specified by the first
redirection list entry.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 522/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [3.1]
Function 5FH (95) Subfunction 03H
Redirect device
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 5FH
AL = 03H
BL = device type
03H if printer
04H if drive
Returns:
If function successful
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 523/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
Example:
Redirect the local drive E to the directory \FORTH on the server named
LMI, using the password FRED.
netname db '\\LMI\FORTH',0
db 'FRED',0
.
.
.
mov ax,5f03h ; function & subfunction
mov bl,4 ; code 4 = disk drive
mov si,seg locname ; address of local name
mov ds,si
mov si,offset locname
mov di,seg netname ; address of network name
mov es,di
mov di,offset netname
int 21h ; transfer to MS-DOS
jc error ; jump if redirect failed
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [3.1]
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 524/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 5FH
AL = 04H
DS:SI = segment:offset of ASCIIZ local device name
Returns:
If function successful
If function unsuccessful
Note:
Example:
locname db 'E:',0
.
.
. mov ax,5f04h ; function & subfunction
mov si,seg locname ; address of local name
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 525/813
10/16/2018 PCjs: Advanced MS-DOS Programming
mov ds,si
mov si,offset locname
int 21h ; transfer to MS-DOS
jc error ; jump if cancel failed
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 60H (96)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 61H (97)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H [3.0]
Function 62H (98)
Get PSP address
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 62H
Returns:
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 526/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Example:
Get the segment base of the program segment prefix, then copy the command
tail from the PSP into the local buffer named buff.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 527/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [2.25 only]
Function 63H (99)
Get DBCS lead byte table
────────────────────────────────────────────────────────────────────────────
Obtains the address of the system table of legal lead byte ranges for
double-byte character sets (DBCS), or sets or obtains the interim console
flag. Int 21H Function 63H is available only in MS-DOS version 2.25; it
is not supported in MS-DOS versions 3.0 and later.
Call with:
AH = 63H
AL = subfunction
If AL = 01H
Returns:
If function successful
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 528/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AX = error code
Notes:
■ The DBCS lead byte table consists of a variable number of two byte
entries, terminated by two null (00H) bytes. Each pair defines the
beginning and ending value for a range of lead bytes. The value of a
legal lead byte is always in the range 80─0FFH.
■ If the interim console flag is set, Int 21H Functions 07H (Unfiltered
Character Input), 08H (Character Input without Echo), and 0BH
(Keyboard Status) will support interim characters.
■ Unlike most other MS-DOS services, this function call does not
necessarily preserve any registers except SS:SP.
■ [4.0] The address of the DBCS lead byte table can also be obtained with
Int 21H Function 65H.
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 64H (100)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H [3.3]
Function 65H (101)
Get extended country information
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 65H
AL = subfunction
01H = Get General Internationalization Information
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 529/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
If function successful
If function unsuccessful
Notes:
■ This function may fail if either the country code or the code page
number is invalid, or if the code page does not match the country code.
■ The function fails if the specified buffer length is less than five
bytes. If the buffer to receive the information is at least five bytes
long but is too short for the requested information, the data is
truncated and no error is returned.
Byte(s) Contents
00H information ID code (1)
01H─02H length of following buffer
03H─04H country ID
05H─06H code page number
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 530/813
10/16/2018 PCjs: Advanced MS-DOS Programming
0 = USA m d y
1 = Europe d m y
2 = Japan y m d
■ The format of the data returned by Subfunctions 02H, 04H, 06H, and 07H
is:
Byte(s) Contents
00H information ID code (2, 4, or 6)
01H─05H double-word pointer to table
■ The uppercase and filename uppercase tables are a maximum of 130 bytes
long. The first two bytes contain the size of the table; the following
bytes contain the uppercase equivalents, if any, for character codes
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 531/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ The collating table is a maximum of 258 bytes long. The first two bytes
contain the table length, and the subsequent bytes contain the values to
be used for the corresponding character codes (0─FFH) during a sort
operation. This table maps uppercase and lowercase ASCII characters to
the same collating codes so that sorts will be case-insensitive, and it
maps accented vowels to their plain vowel equivalents.
dw length
db start1,end1
db start2,end2
.
.
.
db 0,0
For example:
dw 4
db 81h,9fh
db 0e0h,0fch
db 0,0
Examples:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 532/813
10/16/2018 PCjs: Advanced MS-DOS Programming
.
.
.
mov ax,6501h ; function & subfunction
mov bx,437 ; code page
mov cx,41 ; buffer length
mov dx,-1 ; default country
mov di,seg buffer ; buffer address
mov es,di
mov di,offset buffer
int 21h ; transfer to MS-DOS
jc error ; jump if function failed
.
.
.
Obtain the pointer to the uppercase table associated with the default
country and code page 437.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 533/813
10/16/2018 PCjs: Advanced MS-DOS Programming
In this case, MS-DOS filled the following values into the buffer:
0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDE
1140:0200 80 00 80 9A 45 41 8E 41 8F 80 45 45 ....EA.A..E
1140:0210 45 49 49 49 8E 8F 90 92 92 4F 99 4F 55 55 59 99 EIII.....O.OUUY
1140:0220 9A 9B 9C 9D 9E 9F 41 49 4F 55 A5 A5 A6 A7 A8 A9 ......AIOU.....
1140:0230 AA AB AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 ...............
1140:0240 BA BB BC BD BE BF C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 ...............
1140:0250 CA CB CC CD CE CF D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 ...............
1140:0260 DA DB DC DD DE DF E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 ...............
1140:0270 EA EB EC ED EE EF F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 ...............
1140:0280 FA FB FC FD FE FF ......
────────────────────────────────────────────────────────────────────────────
Int 21H [3.3]
Function 66H (102)
Get or set code page
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 66H
AL = subfunction
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 534/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
If function successful
If function unsuccessful
Note:
■ When the Select Code Page subfunction is used, MS-DOS gets the new code
page from the COUNTRY.SYS file. The device must be previously prepared
for code page switching with the appropriate DEVICE= directive in the
CONFIG.SYS file and NLSFUNC and MODE CP PREPARE commands (placed in the
AUTOEXEC.BAT file, usually).
Example:
Force the active code page to be the same as the system's default code
page, that is, restore the code page that was active when the system was
first booted.
.
.
.
; get current and
; default code page
mov ax,6601h ; function number
int 21h ; transfer to MS-DOS
jc error ; jump if function failed
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 535/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H [3.3]
Function 67H (103)
Set handle count
────────────────────────────────────────────────────────────────────────────
Sets the maximum number of files and devices that may be opened
simultaneously using handles by the current process.
Call with:
AH = 67H
BX = number of desired handles
Returns:
If function successful
If function unsuccessful
Notes:
■ This function call controls the size of the table that relates handle
numbers for the current process to MS-DOS's internal, global table for
all of the open files and devices in the system. The default table is
located in the reserved area of the process's PSP and is large enough
for 20 handles.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 536/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Example:
Set the maximum handle count for the current process to thirty, so that
the process can have as many as 30 files or devices opened simultaneously.
(Five of the handles are already assigned to the standard devices when the
process starts up.) Note that a FILES=30 (or greater value) entry in the
CONFIG.SYS file would also be required for the process to successfully
open 30 files or devices.
.
.
.
mov ah,67h ; function number
mov bx,30 ; maximum number of handles
int 21h ; transfer to MS-DOS
jc error ; jump if function failed
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 21H [3.3]
Function 68H (104)
Commit file
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 68H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 537/813
10/16/2018 PCjs: Advanced MS-DOS Programming
BX = handle
Returns:
If function successful
If function unsuccessful
Notes:
Example:
Assume that the file MYFILE.DAT has been previously opened and that the
handle for that file is stored in the variable fhandle. Call the Commit
File function to ensure that any data in MS-DOS's internal buffers
associated with the handle is written out to disk and that the directory
and file allocation table are up to date.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 538/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 69H (105)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 6AH (106)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H
Function 6BH (107)
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 21H [4.0]
Function 6CH (108)
Extended open file
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 6CH
AL = 00H
BX = open mode
Bit(s) Significance
0─2 access type
000 = read-only
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 539/813
10/16/2018 PCjs: Advanced MS-DOS Programming
001 = write-only
010 = read/write
3 reserved (0)
4─6 sharing mode
000 = compatibility
001 = deny read/write (deny all)
010 = deny write
011 = deny read
100 = deny none
7 inheritance
0 = child process inherits handle
1 = child does not inherit handle
8─12 reserved (0)
13 critical error handling
0 = execute Int 24H
1 = return error to process
14 write-through
0 = writes may be buffered and deferred
1 = physical write at request time
15 reserved (0)
DX = open flag
Bits Significance
0─3 action if file exists
0000 = fail
0001 = open file
0010 = replace file
4─7 action if file doesn't exist
0000 = fail
0001 = create file
8─15 reserved (0)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 540/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
If function successful
If function failed
Notes:
· the file is being created in the root directory and the root directory
is full.
· the file is being created and a file with the same name and the
read-only attribute already exists in the specified directory.
· the program is running on a network and the user running the program
has insufficient access rights.
■ This function combines the capabilities of Int 21H Functions 3CH, 3DH,
and 5BH. It was added to MS-DOS for compatibility with the DosOpen
function of OS/2.
Example:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 541/813
10/16/2018 PCjs: Advanced MS-DOS Programming
\MYDIR on drive C, and save the handle for subsequent access to the file.
fname db 'C:\MYDIR\MYFILE.DAT',0
fhandle dw ?
.
.
.
mov ax,6c00h ; function number
mov bx,4042h ; read/write, deny none,
; write-through mode
xor cx,cx ; normal attribute
mov dx,0010h ; create if doesn't exist,
; fail if exists
mov si,seg fname ; address of pathname
mov ds,si
mov si,offset fname
int 21h ; transfer to MS-DOS
jc error ; jump if open failed
mov fhandle,ax ; save file handle
.
.
.
────────────────────────────────────────────────────────────────────────────
Int 22H [1.0]
Terminate handler address
────────────────────────────────────────────────────────────────────────────
The machine interrupt vector for Int 22H (memory locations 0000:0088H
through 0000:008BH) contains the address of the routine that receives
control when the currently executing program terminates via Int 20H, Int
27H, or Int 21H Functions 00H, 31H, or 4CH. The address in this vector
is also copied into offsets 0AH through 0DH of the program segment prefix
(PSP) when a program is loaded but before it begins executing, and is
restored from the PSP (in case it was modified by the application) as part
of MS-DOS's termination handling.
────────────────────────────────────────────────────────────────────────────
Int 23H [1.0]
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 542/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The machine interrupt vector for Int 23H (memory locations 0000:008CH
though 0000:008FH) contains the address of the routine which receives
control when a Ctrl-C is detected during any character I/O function and,
if the Break flag is ON, during most other MS-DOS function calls. The
address in this vector is also copied into locations 0EH through 11H of
the program segment prefix (PSP) when a program is loaded but before it
begins executing, and is restored from the PSP (in case it was modified by
the application) as part of MS-DOS's termination handling.
Notes:
■ The initialization code for an application can use Int 21H Function
25H to reset the Interrupt 23H vector to point to its own routine for
Ctrl-C handling. In this way, the program can avoid being terminated
unexpectedly as the result of the user's entry of a Ctrl-C or
Ctrl-Break.
■ When a Ctrl-C is detected and the program's Int 23H handler receives
control, all registers are set to their values at the point of the
original function call. The handler can then do any of the following:
· Set a local flag for later inspection by the application, or take any
other appropriate action, and perform an IRET. All registers must be
preserved. The MS-DOS function in progress will be restarted from
scratch and will proceed to completion, control finally returning to
the application in the normal manner.
· Take appropriate action and then perform a RET FAR to give control
back to MS-DOS. The state of the carry flag is used by MS-DOS to
determine what action to take. If the carry flag is set, the
application will be terminated; if the carry flag is clear, the
application will continue in the normal manner.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 543/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ Any MS-DOS function call may be used within the body of an Int 23H
handler.
Example:
See Chapter 5.
────────────────────────────────────────────────────────────────────────────
Int 24H [1.0]
Critical-error handler address
────────────────────────────────────────────────────────────────────────────
The machine interrupt vector for Int 24H (memory locations 0000:0090H
through 0000:0093H) contains the address of the routine that receives
control when a critical error (usually a hardware error) is detected. This
address is also copied into locations 12H through 15H of the program
segment prefix (PSP) when a program is loaded but before it begins
executing, and is restored from the PSP (in case it was modified by the
application) as part of MS-DOS's termination handling.
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 544/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Note that these are the same error codes returned by the device driver
in the request header. Also, upon entry, the stack is set up as shown in
Figure 8-8, page 149.
■ When a disk I/O error occurs, MS-DOS automatically retries the operation
before issuing a critical-error Int 24H. The number of retries varies
in different versions of MS-DOS, but is typically in the range three to
five.
■ Int 24H handlers must preserve the SS, SP, DS, ES, BX, CX, and DX
registers. Only Int 21H Functions 01H─0CH and 59H can be used by an
Int 24H handler; other function calls will destroy the MS-DOS stack and
its ability to retry or ignore an error.
■ When the Int 24H handler issues an IRET, it should return an action code
in AL that will be interpreted by DOS as follows:
Example:
See Chapter 8.
────────────────────────────────────────────────────────────────────────────
Int 25H [1.0]
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 545/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Provides a direct linkage to the MS-DOS BIOS module to read data from a
logical disk sector into memory.
Call with:
Returns:
If function successful
If function unsuccessful
Notes:
■ When this function returns, the CPU flags originally pushed on the stack
by the INT 25H instruction are still on the stack. The stack must be
cleared by a POPF or ADD SP,2 to prevent uncontrolled stack growth and
to make accessible any other values that were pushed on the stack before
the call to INT 25H.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 546/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ The error code is interpreted as follows: The lower byte (AL) is the
same error code that is returned in the lower byte of DI when an Int 24H
is issued. The upper byte (AH) contains:
Bytes Description
00H─03H 32-bit sector number
04H─05H number of sectors to read
06H─07H offset of buffer
08H─09H segment of buffer
Example:
Read logical sector 1 of drive A into the memory area named buff. (On most
MS-DOS floppy disks, this sector contains the beginning of the file
allocation table.)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 547/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 26H [1.0]
Absolute disk write
────────────────────────────────────────────────────────────────────────────
Provides a direct linkage to the MS-DOS BIOS module to write data from
memory to a logical disk sector.
Call with:
Returns:
If function successful
If function unsuccessful
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 548/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ When this function returns, the CPU flags originally pushed onto the
stack by the INT 26H instruction are still on the stack. The stack must
be cleared by a POPF or ADD SP,2 to prevent uncontrolled stack growth
and to make accessible any other values that were pushed on the stack
before the call to INT 26H.
■ The error code is interpreted as follows: The lower byte (AL) is the
same error code that is returned in the lower byte of DI when an Int
24H is issued. The upper byte (AH) contains:
Bytes Description
00H─03H 32-bit sector number
04H─05H number of sectors to read
06H─07H offset of buffer
08H─09H segment of buffer
Example:
Write the contents of the memory area named buff into logical sector 3 of
drive C.
Warning: Verbatim use of the following code could damage the file system
on your fixed disk. There is, unfortunately, no way to provide a really
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 549/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 27H [1.0]
Terminate and stay resident
────────────────────────────────────────────────────────────────────────────
■ File buffers are flushed and any open handles for files or devices owned
by the process are closed.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 550/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
Returns:
Nothing
Notes:
■ This function attempts to set the initial memory allocation block to the
length in bytes specified in register DX. If other memory blocks have
been requested by the application via Int 21H Function 48H, they will
not be released by this function.
· Int 20H
■ This function should not be called by .EXE programs that are loaded at
the high end of the transient program area (i.e., linked with the /HIGH
switch), because doing so reserves the memory normally used by the
transient part of COMMAND.COM. If COMMAND.COM cannot be reloaded, the
system will fail.
■ This function does not work correctly when DX contains values in the
range 0FFF1H─0FFFFH. In this case, MS-DOS discards the high bit of the
value in DX, resulting in the reservation of 32 KB less memory than was
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 551/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Example:
Terminate and stay resident, reserving enough memory to contain the entire
program.
.
.
.
mov dx,offset pend ; DX = bytes to reserve
int 27h ; terminate, stay resident
.
.
.
pend equ $ ; offset, end of program
end
────────────────────────────────────────────────────────────────────────────
Int 28H
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 29H
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 2AH
Reserved
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 552/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 2BH
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 2CH
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 2DH
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 2EH
Reserved
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 2FH [3.0]
Multiplex interrupt
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 2FH [3.0]
Function 01H
Print spooler
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 553/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Submits a file to the print spooler, removes a file from the print
spooler's queue of pending files, or obtains the status of the printer.
The print spooler, which is contained in the file PRINT.COM, was first
added to MS-DOS in version 2.0, but the application program interface to
the spooler was not documented until MS-DOS version 3.
Call with:
AH = 01H
AL = subfunction
00H = Get Installed State
01H = Submit File to be Printed
02H = Remove File from Print Queue
03H = Cancel All Files in Queue
04H = Hold Print Jobs for Status Read
05H = Release Hold
DS:DX = segment:offset of packet (Subfunction 01H)
segment:offset of ASCIIZ pathname (Subfunction 02H)
Returns:
If function successful
DX = error count
DS:SI = segment:offset of print queue file list
If function unsuccessful
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 554/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ The packet passed to Subfunction 01H consists of five bytes. The first
byte contains the level, which should be 00H for current versions of
MS-DOS. The following four bytes contain the segment:offset of an ASCIIZ
pathname, which may not include wildcard characters. If the specified
file exists, it is added to the print queue.
────────────────────────────────────────────────────────────────────────────
Int 2FH [3.2]
Function 02H
ASSIGN
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 02H
AL = subfunction
00H = Get Installed State
Returns:
If function successful
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 555/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 2FH [3.2]
Function 10H (16)
SHARE
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 10H
AL = subfunction
00H = Get Installed State
Returns:
If function successful
If function unsuccessful
────────────────────────────────────────────────────────────────────────────
Int 2FH [3.3]
Function B7H (183)
APPEND
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 556/813
10/16/2018 PCjs: Advanced MS-DOS Programming
is resident, returns the APPEND version, state, and the path used to
search for data files.
Call with:
AH = B7H
AL = subfunction
00H = Get Installed State
02H = Get Append Version (4.0)
04H = Get Append Path Pointer (4.0)
06H = Get Append Function State (4.0)
07H = Set Append Function State (4.0)
11H = Set Return Found Name State (4.0, see Note)
BX = APPEND state (if AL = 07H)
Returns:
If function successful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 557/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
Note:
■ If the Return Found Name State is set with Subfunction 11H, the fully
qualified filename is returned to the next application to call Int 21H
Function 3DH, 43H, or 6CH. The name is placed at the same address as the
ASCIIZ parameter string for the Int 21H function, so the application
must be sure to provide a buffer of adequate size. The Return Found Name
State is reset after APPEND processes one Int 21H function call.
────────────────────────────────────────────────────────────────────────────
SECTION 3 IBM ROM BIOS AND MOUSE FUNCTIONS REFERENCE
────────────────────────────────────────────────────────────────────────────
In the headers for ROM BIOS video driver (Int 10H) function calls, the
following icons are used:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 558/813
10/16/2018 PCjs: Advanced MS-DOS Programming
ROM BIOS functions that are unique to the PC Convertible have been
omitted.
╓┌─┌──────┌────────────┌─────────────┌───────────────────────────────────────╖
Int Function Subfunction Name
──────────────────────────────────────────────────────────────────────────
10H Video Driver
10H 00H Set Video Mode
10H 01H Set Cursor Type
10H 02H Set Cursor Position
10H 03H Get Cursor Position
10H 04H Get Light Pen Position
10H 05H Set Display Page
10H 06H Initialize or Scroll Window Up
10H 07H Initialize or Scroll Window Down
10H 08H Read Character and Attribute at Cursor
10H 09H Write Character and Attribute at Cursor
10H 0AH (10) Write Character at Cursor
Int Function Subfunction Name
──────────────────────────────────────────────────────────────────────────
10H 0AH (10) Write Character at Cursor
10H 0BH (11) Set Palette, Background, or Border
10H 0CH (12) Write Graphics Pixel
10H 0DH (13) Read Graphics Pixel
10H 0EH (14) Write Character in Teletype Mode
10H 0FH (15) Get Video Mode
10H 10H (16) 00H Set Palette Register
10H 10H (16) 01H Set Border Color
10H 10H (16) 02H Set Palette and Border
10H 10H (16) 03H Toggle Blink/Intensity Bit
10H 10H (16) 07H Get Palette Register
10H 10H (16) 08H Get Border Color
10H 10H (16) 09H Get Palette and Border
10H 10H (16) 10H (16) Set Color Register
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 559/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 560/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 561/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 562/813
10/16/2018 PCjs: Advanced MS-DOS Programming
──────────────────────────────────────────────────────────────────────────
16H 04H Set Keyclick
16H 05H Push Character and Scan Code
16H 10H (16) Read Character from Enhanced Keyboard
16H 11H (17) Get Enhanced Keyboard Status
16H 12H (18) Get Enhanced Keyboard Flags
17H Parallel Port Printer Driver
17H 00H Write Character to Printer
17H 01H Initialize Printer Port
17H 02H Get Printer Status
18H ROM BASIC
19H Reboot System
1AH Real-time (CMOS) Clock Driver
1AH 00H Get Tick Count
1AH 01H Set Tick Count
1AH 02H Get Time
1AH 03H Set Time
1AH 04H Get Date
1AH 05H Set Date
1AH 06H Set Alarm
Int Function Subfunction Name
──────────────────────────────────────────────────────────────────────────
1AH 06H Set Alarm
1AH 07H Reset Alarm
1AH 0AH (10) Get Day Count
1AH 0BH (11) Set Day Count
1AH 80H (128) Set Sound Source
33H Microsoft Mouse Driver
33H 00H Reset Mouse and Get Status
33H 01H Show Mouse Pointer
33H 02H Hide Mouse Pointer
33H 03H Get Mouse Position and Button Status
33H 04H Set Mouse Pointer Position
33H 05H Get Button Press Information
33H 06H Get Button Release Information
33H 07H Set Horizontal Limits for Pointer
33H 08H Set Vertical Limits for Pointer
33H 09H Set Graphics Pointer Shape
33H 0AH (10) Set Text Pointer Type
33H 0BH (11) Read Mouse Motion Counters
33H 0CH (12) Set User-defined Mouse Event Handler
Int Function Subfunction Name
──────────────────────────────────────────────────────────────────────────
33H 0CH (12) Set User-defined Mouse Event Handler
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 563/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 10H [MDA] [CGA] [PCjr] [EGA] [MCGA] [VGA]
Function 00H
Set video mode
────────────────────────────────────────────────────────────────────────────
Selects the current video display mode. Also selects the active video
controller, if more than one video controller is present.
Call with:
AH = 00H
AL = video mode (see Notes)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 564/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
Nothing
Notes:
■ The video modes applicable to the various IBM machine models and video
adapters are as follows:
╓┌─┌─────┌───────────┌────────┌───────────┌─────┌─────┌────┌─────┌─────┌─────╖
Mode Resolution Colors Text/ MDA CGA PCjr EGA MCGA VGA
graphics
──────────────────────────────────────────────────────────────────────────
00H 40-by-25 16 text * * * * *
color burst
off
Mode Resolution Colors Text/ MDA CGA PCjr EGA MCGA VGA
graphics
──────────────────────────────────────────────────────────────────────────
off
01H 40-by-25 16 text * * * * *
02H 80-by-25 16 text * * * * *
color burst
off
03H 80-by-25 16 text * * * * *
04H 320-by-200 4 graphics * * * * *
05H 320-by-200 4 graphics * * * * *
color burst
off
06H 640-by-200 2 graphics * * * * *
07H 80-by-25 2☼ text * * *
08H 160-by-200 16 graphics *
09H 320-by-200 16 graphics *
0AH 640-by-200 4 graphics *
0BH reserved
0CH reserved
0DH 320-by-200 16 graphics * *
Mode Resolution Colors Text/ MDA CGA PCjr EGA MCGA VGA
graphics
──────────────────────────────────────────────────────────────────────────
0DH 320-by-200 16 graphics * *
0EH 640-by-200 16 graphics * *
0FH 640-by-350 2☼ graphics * *
10H 640-by-350 4 graphics *☼
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 565/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ On the PC/AT, PCjr, and PS/2, if bit 7 of AL is set, the display buffer
is not cleared when a new mode is selected. On the PC or PC/XT, this
capability is available only when an EGA or VGA (which have their own
ROM BIOS) is installed.
────────────────────────────────────────────────────────────────────────────
Int 10H [MDA] [CGA] [PCjr] [EGA] [MCGA] [VGA]
Function 01H
Set cursor type
────────────────────────────────────────────────────────────────────────────
Selects the starting and ending lines for the blinking hardware cursor in
text display modes.
Call with:
AH = 01H
CH bits 0─4 = starting line for cursor
CL bits 0─4 = ending line for cursor
Returns:
Nothing
Notes:
■ In text display modes, the video hardware causes the cursor to blink,
and the blink cannot be disabled. In graphics modes, the hardware cursor
is not available.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 566/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ On the EGA, MCGA, and VGA in text modes 00H─03H, the ROM BIOS accepts
cursor start and end values as though the character cell were 8 by 8 and
remaps the values as appropriate for the true character cell dimensions.
This mapping is called cursor emulation.
■ You can turn off the cursor in several ways. On the MDA, CGA, and VGA,
setting register CH = 20H causes the cursor to disappear. Techniques
that involve setting illegal starting and ending lines for the current
display mode are unreliable. An alternative is to position the cursor to
a nondisplayable address, such as (x,y)=(0,25).
────────────────────────────────────────────────────────────────────────────
Int 10H [MDA] [CGA] [PCjr] [EGA] [MCGA] [VGA]
Function 02H
Set cursor position
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 02H
BH = page
DH = row (y coordinate)
DL = column (x coordinate)
Returns:
Nothing
Notes:
■ A separate cursor is maintained for each display page, and each can be
set independently with this function regardless of the currently active
page. The number of available display pages depends on the video adapter
and current display mode. See Int 10H Function 05H.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 567/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ Text coordinates (x,y)=(0,0) are the upper left corner of the screen.
■ The maximum value for each text coordinate depends on the video adapter
and current display mode, as follows:
────────────────────────────────────────────────────────────────────────────
Int 10H [MDA] [CGA] [PCjr] [EGA] [MCGA] [VGA]
Function 03H
Get cursor position
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 03H
BH = page
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 568/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
Note:
■ A separate cursor is maintained for each display page, and each can be
inspected independently with this function regardless of the currently
active page. The number of available display pages depends on the video
adapter and current display mode. See Int 10H Function 05H.
────────────────────────────────────────────────────────────────────────────
Int 10H [CGA] [PCjr] [EGA]
Function 04H
Get light pen position
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 04H
Returns:
Notes:
■ On the CGA, the graphics coordinates returned by this function are not
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 569/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 10H [CGA] [PCjr] [EGA] [MCGA] [VGA]
Function 05H
Set display page
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 05H
AL = page
0─7 for modes 00H and 01H (CGA, EGA, MCGA, VGA)
0─3 for modes 02H and 03H (CGA)
0─7 for modes 02H and 03H (EGA, MCGA, VGA)
0─7 for mode 07H (EGA, VGA)
0─7 for mode 0DH (EGA, VGA)
0─3 for mode 0EH (EGA, VGA)
0─1 for mode 0FH (EGA, VGA)
0─1 for mode 10H (EGA, VGA)
AH = 05H
AL = subfunction
80H = read CRT/CPU page registers
81H = set CPU page register
82H = set CRT page register
83H = set both CPU and CRT page registers
BH = CRT page (Subfunctions 82H and 83H)
BL = CPU page (Subfunctions 81H and 83H)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 570/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
Nothing
Notes:
■ Video mode and adapter combinations not listed above support one display
page (for example, a Monochrome Adapter in mode 7).
■ On the PCjr, the CPU page determines the part of the physical memory
region 00000H─1FFFFH that will be hardware mapped onto 16 KB of memory
beginning at segment B800H. The CRT page determines the starting address
of the physical memory used by the video controller to refresh the
display. Smooth animation effects can be achieved by manipulation of
these registers. Programs that write directly to the B800H segment can
reach only the first 16 KB of the video refresh buffer. Programs
requiring direct access to the entire 32 KB buffer in modes 09H and 0AH
can obtain the current CRT page from the ROM BIOS variable PAGDAT at
0040:008AH.
────────────────────────────────────────────────────────────────────────────
Int 10H [MDA] [CGA] [PCjr] [EGA] [MCGA] [VGA]
Function 06H
Initialize or scroll window up
────────────────────────────────────────────────────────────────────────────
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 571/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 06H
AL = number of lines to scroll (if zero, entire window is
blanked)
BH = attribute to be used for blanked area
CH = y coordinate, upper left corner of window
CL = x coordinate, upper left corner of window
DH = y coordinate, lower right corner of window
DL = x coordinate, lower right corner of window
Returns:
Nothing
Notes:
■ In video modes that support multiple pages, this function affects only
the page currently being displayed.
■ If AL contains a value other than 00H, the area within the specified
window is scrolled up by the requested number of lines. Text that is
scrolled beyond the top of the window is lost. The new lines that appear
at the bottom of the window are filled with ASCII blanks carrying the
attribute specified by register BH.
■ To scroll down the contents of a window, see Int 10H Function 07H.
────────────────────────────────────────────────────────────────────────────
Int 10H [MDA] [CGA] [PCjr] [EGA] [MCGA] [VGA]
Function 07H
Initialize or scroll window down
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 07H
AL = number of lines to scroll (if zero, entire window is
blanked)
BH = attribute to be used for blanked area
CH = y coordinate, upper left corner of window
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 572/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
Nothing
Notes:
■ In video modes that support multiple pages, this function affects only
the page currently being displayed.
■ If AL contains a value other than 00H, the area within the specified
window is scrolled down by the requested number of lines. Text that is
scrolled beyond the bottom of the window is lost. The new lines that
appear at the top of the window are filled with ASCII blanks carrying
the attribute specified by register BH.
────────────────────────────────────────────────────────────────────────────
Int 10H [MDA] [CGA] [PCjr] [EGA] [MCGA] [VGA]
Function 08H
Read character and attribute at cursor
────────────────────────────────────────────────────────────────────────────
Obtains the ASCII character and its attribute at the current cursor
position for the specified display page.
Call with:
AH = 08H
BH = page
Returns:
AH = attribute
AL = character
Note:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 573/813
10/16/2018 PCjs: Advanced MS-DOS Programming
attributes may be read from any page, regardless of the page currently
being displayed.
────────────────────────────────────────────────────────────────────────────
Int 10H [MDA] [CGA] [PCjr] [EGA] [MCGA] [VGA]
Function 09H
Write character and attribute at cursor
────────────────────────────────────────────────────────────────────────────
Writes an ASCII character and its attribute to the display at the current
cursor position.
Call with:
AH = 09H
AL = character
BH = page
BL = attribute (text modes) or color (graphics modes)
CX = count of characters to write (replication factor)
Returns:
Nothing
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 574/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ For the CGA and PCjr in graphics modes 04H─06H, the bit patterns for
character codes 80H─FFH are obtained from a table whose address is
stored in the vector for Int 1FH. On the PCjr, the address of the table
for character codes 00H─7FH is stored in the vector for Int 44H.
Alternative character sets may be installed by loading them into memory
and updating this vector.
■ For the EGA, MCGA, and VGA in graphics modes, the address of the
character definition table is stored in the vector for Int 43H. See Int
10H Function 11H.
────────────────────────────────────────────────────────────────────────────
Int 10H [MDA] [CGA] [PCjr] [EGA] [MCGA] [VGA]
Function 0AH (10)
Write character at cursor
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 0AH
AL = character
BH = page
BL = color (graphics modes, PCjr only)
CX = count of characters to write (replication factor)
Returns:
Nothing
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 575/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ For the CGA and PCjr in graphics modes 04H─06H, the bit patterns for
character codes 80H─FFH are obtained from a table whose address is
stored in the vector for Int 1FH. On the PCjr, the address of the table
for character codes 00H─7FH is stored in the vector for Int 44H.
Alternative character sets may be installed by loading them into memory
and updating this vector.
■ For the EGA, MCGA, and VGA in graphics modes, the address of the
character definition table is stored in the vector for Int 43H. See Int
10H Function 11H.
────────────────────────────────────────────────────────────────────────────
Int 10H [CGA] [PCjr] [EGA] [MCGA] [VGA]
Function 0BH (11)
Set palette, background, or border
────────────────────────────────────────────────────────────────────────────
Call with:
To set the background color and border color for graphics modes or the
border color for text modes
AH = 0BH
BH = 00H
BL = color
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 576/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 0BH
BH = 01H
BL = palette (see Notes)
Returns:
Nothing
Notes:
■ In text modes, this function selects only the border color. The
background color of each individual character is controlled by the upper
4 bits of that character's attribute byte.
■ On the CGA and EGA, this function is valid for palette selection only in
320-by-200 4-color graphics modes.
■ See also Int 10H Function 10H, which is used for palette programming on
the PCjr, EGA, MCGA, and VGA.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 577/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 10H [CGA] [PCjr] [EGA] [MCGA] [VGA]
Function 0CH (12)
Write graphics pixel
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 0CH
AL = pixel value
BH = page
CX = column (graphics x coordinate)
DX = row (graphics y coordinate)
Returns:
Nothing
Notes:
■ The range of valid pixel values and (x,y) coordinates depends on the
current video mode.
■ Register BH is ignored for display modes that support only one page.
────────────────────────────────────────────────────────────────────────────
Int 10H [CGA] [PCjr] [EGA] [MCGA] [VGA]
Function 0DH (13)
Read graphics pixel
────────────────────────────────────────────────────────────────────────────
Obtains the current value of the pixel on the display at the specified
graphics coordinates.
Call with:
AH = 0DH
BH = page
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 578/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
AL = pixel value
Notes:
■ The range of valid (x,y) coordinates and possible pixel values depends
on the current video mode.
■ Register BH is ignored for display modes that support only one page.
────────────────────────────────────────────────────────────────────────────
Int 10H [MDA] [CGA] [PCjr] [EGA] [MCGA] [VGA]
Function 0EH (14)
Write character in teletype mode
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 0EH
AL = character
BH = page
BL = foreground color (graphics modes)
Returns:
Nothing
Notes:
■ The special ASCII codes for bell (07H), backspace (08H), carriage return
(0DH), and line feed (0AH) are recognized, and the appropriate action is
taken. All other characters are written to the display (even if they are
control characters), and the cursor is moved to the next position.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 579/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ Line wrapping and scrolling are provided. If the cursor is at the end of
a line, it is moved to the beginning of the next line. If the cursor
reaches the end of the last line on the screen, the screen is scrolled
up by one line and the cursor is placed at the beginning of a new blank
line. The attribute for the entire new line is taken from the last
character that was written on the preceding line.
■ The default MS-DOS console driver (CON) uses this function to write text
to the screen. You cannot use this function to specify the attribute of
a character. One method of writing a character to the screen with a
specific attribute is to first write an ASCII blank (20H) with the
desired attribute at the current cursor location using Int 10H Function
09H and then write the actual character with Int 10H Function 0EH.
This technique, although somewhat clumsy, does not require the program
to explicitly handle line wrapping and scrolling.
────────────────────────────────────────────────────────────────────────────
Int 10H [MDA] [CGA] [PCjr] [EGA] [MCGA] [VGA]
Function 0FH (15)
Get video mode
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 0FH
Returns:
Note:
■ This function can be called to obtain the screen width before clearing
the screen with Int 10H Functions 06H or 07H.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 580/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 10H [PCjr] [EGA] [MCGA] [VGA]
Function 10H (16) Subfunction 00H
Set palette register
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 10H
AL = 00H
BH = color value
BL = palette register (00─0FH)
On the MCGA
AH = 10H
AL = 00H
BX = 0712H
Returns:
Nothing
Note:
■ On the MCGA, this function can only be called with BX = 0712H and
selects a color register set with eight consistent colors.
────────────────────────────────────────────────────────────────────────────
Int 10H [PCjr] [EGA] [VGA]
Function 10H (16) Subfunction 01H
Set border color
────────────────────────────────────────────────────────────────────────────
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 581/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 10H
AL = 01H
BH = color value
Returns:
Nothing
────────────────────────────────────────────────────────────────────────────
Int 10H [PCjr] [EGA] [VGA]
Function 10H (16) Subfunction 02H
Set palette and border
────────────────────────────────────────────────────────────────────────────
Sets all palette registers and the border color (overscan) in one
operation.
Call with:
AH = 10H
AL = 02H
ES:DX = segment:offset of color list
Returns:
Nothing
Notes:
■ The color list is 17 bytes long. The first 16 bytes are the color values
to be loaded into palette registers 0─15, and the last byte is stored in
the border color register.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 582/813
10/16/2018 PCjs: Advanced MS-DOS Programming
07H white
08H gray
09H light blue
0AH light green
0BH light cyan
0CH light red
0DH light magenta
0EH yellow
0FH intense white
────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 10H [PCjr] [EGA] [MCGA] [VGA]
Function 10H (16) Subfunction 03H
Toggle blink/intensity bit
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 10H
AL = 03H
BL = blink/intensity toggle
0 = enable intensity
1 = enable blinking
Returns:
Nothing
────────────────────────────────────────────────────────────────────────────
Int 10H [VGA]
Function 10H (16) Subfunction 07H
Get palette register
────────────────────────────────────────────────────────────────────────────
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 583/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 10H
AL = 07H
BL = palette register
Returns:
BH = color
────────────────────────────────────────────────────────────────────────────
Int 10H [VGA]
Function 10H (16) Subfunction 08H
Get border color
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 10H
AL = 08H
Returns:
BH = color
────────────────────────────────────────────────────────────────────────────
Int 10H [VGA]
Function 10H (16) Subfunction 09H
Get palette and border
────────────────────────────────────────────────────────────────────────────
Gets the contents of all palette registers and the border color (overscan)
in one operation.
Call with:
AH = 10H
AL = 09H
ES:DX = segment:offset of 17-byte buffer
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 584/813
10/16/2018 PCjs: Advanced MS-DOS Programming
and buffer contains palette values in bytes 00H─0FH and border color in
byte 10H.
────────────────────────────────────────────────────────────────────────────
Int 10H [MCGA] [VGA]
Function 10H (16) Subfunction 10H (16)
Set color register
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 10H
AL = 10H
BX = color register
CH = green value
CL = blue value
DH = red value
Returns:
Nothing
Note:
────────────────────────────────────────────────────────────────────────────
Int 10H [MCGA] [VGA]
Function 10H (16) Subfunction 12H (18)
Set block of color registers
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 585/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 10H
AL = 12H
BX = first color register
CX = number of color registers
ES:DX = segment:offset of color table
Returns:
Nothing
Notes:
■ The table consists of a series of 3-byte entries, one entry per color
register to be programmed. The bytes of an individual entry specify the
red, green, and blue values (in that order) for the associated color
register.
────────────────────────────────────────────────────────────────────────────
Int 10H [VGA]
Function 10H (16) Subfunction 13H (19)
Set color page state
────────────────────────────────────────────────────────────────────────────
Selects the paging mode for the color registers, or selects an individual
page of color registers.
Call with:
AH = 10H
AL = 13H
BH = paging mode
00H for 4 pages of 64 registers
01H for 16 pages of 16 registers
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 586/813
10/16/2018 PCjs: Advanced MS-DOS Programming
BL = 00H
AH = 10H
AL = 13H
BH = page
BL = 01H
Returns:
Nothing
Note:
────────────────────────────────────────────────────────────────────────────
Int 10H [MCGA] [VGA]
Function 10H (16) Subfunction 15H (21)
Get color register
────────────────────────────────────────────────────────────────────────────
Returns the contents of a color register as its red, green, and blue
components.
Call with:
AH = 10H
AL = 15H
BX = color register
Returns:
CH = green value
CL = blue value
DH = red value
────────────────────────────────────────────────────────────────────────────
Int 10H [MCGA] [VGA]
Function 10H (16) Subfunction 17H (23)
Get block of color registers
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 587/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Allows the red, green, and blue components associated with each of a set
of color registers to be read in one operation.
Call with:
AH = 10H
AL = 17H
BX = first color register
CX = number of color registers
ES:DX = segment:offset of buffer to receive color list
Returns:
Note:
────────────────────────────────────────────────────────────────────────────
Int 10H [VGA]
Function 10H (16) Subfunction 1AH (26)
Get color page state
────────────────────────────────────────────────────────────────────────────
Returns the color register paging mode and current color page.
Call with:
AH = 10H
AL = 1AH
Returns:
BH = color page
BL = paging mode
00H if 4 pages of 64 registers
01H if 16 pages of 16 registers
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 588/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Note:
■ See Int 10H Function 10H Subfunction 13H, which allows selection of the
paging mode or current color page.
────────────────────────────────────────────────────────────────────────────
Int 10H [MCGA] [VGA]
Function 10H (16) Subfunction 1BH (27)
Set gray-scale values
────────────────────────────────────────────────────────────────────────────
Transforms the red, green, and blue values of one or more color registers
into the gray-scale equivalents.
Call with:
AH = 10H
AL = 1BH
BX = first color register
CX = number of color registers
Returns:
Nothing
Note:
■ For each color register, the weighted sum of its red, green, and blue
values is calculated (30% red + 59% green + 11% blue) and written back
into all three components of the color register. The original red,
green, and blue values are lost.
────────────────────────────────────────────────────────────────────────────
Int 10H [EGA] [MCGA] [VGA]
Function 11H (17) Subfunctions 00H and 10H (16)
Load user font
────────────────────────────────────────────────────────────────────────────
Loads the user's font (character definition) table into the specified
block of character generator RAM.
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 589/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 11H
AL = 00H or 10H (see Notes)
BH = points (bytes per character)
BL = block
CX = number of characters defined by table
DX = first character code in table
ES:BP = segment:offset of font table
Returns:
Nothing
Notes:
────────────────────────────────────────────────────────────────────────────
Int 10H [EGA] [VGA]
Function 11H (17) Subfunctions 01H and 11H (17)
Load ROM 8-by-14 font
────────────────────────────────────────────────────────────────────────────
Loads the ROM BIOS default 8-by-14 font table into the specified block of
character generator RAM.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 590/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 11H
AL = 01H or 11H (see Notes)
BL = block
Returns:
Nothing
Notes:
■ Subfunctions 01H and 11H are reserved on the MCGA. If either is called,
Subfunction 04H is executed.
────────────────────────────────────────────────────────────────────────────
Int 10H [EGA] [MCGA] [VGA]
Function 11H (17) Subfunctions 02H and 12H (18)
Load ROM 8-by-8 font
────────────────────────────────────────────────────────────────────────────
Loads the ROM BIOS default 8-by-8 font table into the specified block of
character generator RAM.
Call with:
AH = 11H
AL = 02H or 12H (see Notes)
BL = block
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 591/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
Nothing
Notes:
────────────────────────────────────────────────────────────────────────────
Int 10H [EGA] [MCGA] [VGA]
Function 11H (17) Subfunction 03H
Set block specifier
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 11H
AL = 03H
BL = character generator block select code (see Notes)
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 592/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Nothing
Notes:
Bits Significance
────────────────────────────────────────────────────────────────────────
0─1 character block selected by attribute bytes with bit 3 = 0
2─3 character block selected by attribute bytes with bit 3 = 1
4─7 not used (should be 0)
────────────────────────────────────────────────────────────────────────
Bits Significance
────────────────────────────────────────────────────────────────────────
0,1,4 character block selected by attribute bytes with bit 3 = 0
2,3,5 character block selected by attribute bytes with bit 3 = 1
6─7 not used (should be 0)
────────────────────────────────────────────────────────────────────────
■ When using a 256-character set, both fields of BL should select the same
character block. In such cases, character attribute bit 3 controls the
foreground intensity. When using 512-character sets, the fields of BL
designate the blocks holding each half of the character set, and bit 3
of the character attribute selects the upper or lower half of the
character set.
────────────────────────────────────────────────────────────────────────────
Int 10H [MCGA] [VGA]
Function 11H (17) Subfunctions 04H and 14H (20)
Load ROM 8-by-16 font
────────────────────────────────────────────────────────────────────────────
Loads the ROM BIOS default 8-by-16 font table into the specified block of
character generator RAM.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 593/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 11H
AL = 04H or 14H (see Notes)
BL = block
Returns:
Nothing
Notes:
────────────────────────────────────────────────────────────────────────────
Int 10H [EGA] [MCGA] [VGA]
Function 11H (17) Subfunction 20H (32)
Set Int 1FH font pointer
────────────────────────────────────────────────────────────────────────────
Sets the Int 1FH pointer to the user's font table. This table is used for
character codes 80H─FFH in graphics modes 04H─06H.
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 594/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 11H
AL = 20H
ES:BP = segment:offset of font table
Returns:
Nothing
Notes:
────────────────────────────────────────────────────────────────────────────
Int 10H [EGA] [MCGA] [VGA]
Function 11H (17) Subfunction 21H (33)
Set Int 43H for user's font
────────────────────────────────────────────────────────────────────────────
Sets the vector for Int 43H to point to the user's font table and updates
the video ROM BIOS data area. The video controller is not reprogrammed.
Call with:
AH = 11H
AL = 21H
BL = character rows specifier
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 595/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Nothing
Notes:
────────────────────────────────────────────────────────────────────────────
Int 10H [EGA] [MCGA] [VGA]
Function 11H (17) Subfunction 22H (34)
Set Int 43H for ROM 8-by-14 font
────────────────────────────────────────────────────────────────────────────
Sets the vector for Int 43H to point to the ROM BIOS default 8-by-14 font
and updates the video ROM BIOS data area. The video controller is not
reprogrammed.
Call with:
AH = 11H
AL = 22H
BL = character rows specifier
Returns:
Nothing
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 596/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 10H [EGA] [MCGA] [VGA]
Function 11H (17) Subfunction 23H (35)
Set Int 43H for ROM 8-by-8 font
────────────────────────────────────────────────────────────────────────────
Sets the vector for Int 43H to point to the ROM BIOS default 8-by-8 font
and updates the video ROM BIOS data area. The video controller is not
reprogrammed.
Call with:
AH = 11H
AL = 23H
BL = character rows specifier
Returns:
Nothing
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 597/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 10H [MCGA] [VGA]
Function 11H (17) Subfunction 24H (36)
Set Int 43H for ROM 8-by-16 font
────────────────────────────────────────────────────────────────────────────
Sets the vector for Int 43H to point to the ROM BIOS default 8-by-16 font
and updates the video ROM BIOS data area. The video controller is not
reprogrammed.
Call with:
AH = 11H
AL = 24H
BL = row specifier
Returns:
Nothing
Notes:
────────────────────────────────────────────────────────────────────────────
Int 10H [EGA] [MCGA] [VGA]
Function 11H (17) Subfunction 30H (48)
Get font information
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 598/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns a pointer to the character definition table for a font and the
points (bytes per character) and rows for that font.
Call with:
AH = 11H
AL = 30H
BH = font code
00H = current Int 1FH contents
01H = current Int 43H contents
02H = ROM 8-by-14 font (EGA, VGA only)
03H = ROM 8-by-8 font (characters 00H─7FH)
04H = ROM 8-by-8 font (characters 80H─FFH)
05H = ROM alternate 9-by-14 font (EGA, VGA only)
06H = ROM 8-by-16 font (MCGA, VGA only)
07H = ROM alternate 9-by-16 font (VGA only)
Returns:
────────────────────────────────────────────────────────────────────────────
Int 10H [EGA] [VGA]
Function 12H (18) Subfunction 10H (16)
Get configuration information
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 12H
BL = 10H
Returns:
BH = display type
0 if color display
1 if monochrome display
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 599/813
10/16/2018 PCjs: Advanced MS-DOS Programming
00H if 64 KB
01H if 128 KB
02H if 192 KB
03H if 256 KB
Notes:
■ The feature bits are set from Input Status register 0 in response to an
output on the specified Feature Control register bits:
■ The bits in the switch settings byte indicate the state of the EGA's
configuration DIP switch (1 = off, 0 = on).
Bit(s) Significance
────────────────────────────────────────────────────────────────────────
0 configuration switch 1
1 configuration switch 2
2 configuration switch 3
3 configuration switch 4
4─7 not used
────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 10H [EGA] [VGA]
Function 12H (18) Subfunction 20H (32)
Select alternate printscreen
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 600/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Selects an alternate print-screen routine for the EGA and VGA that works
properly if the screen length is not 25 lines. The ROM BIOS default
print-screen routine always prints 25 lines.
Call with:
AH = 12H
BL = 20H
Returns:
Nothing
────────────────────────────────────────────────────────────────────────────
Int 10H [VGA]
Function 12H (18) Subfunction 30H (48)
Set scan lines
────────────────────────────────────────────────────────────────────────────
Selects the number of scan lines for alphanumeric modes. The selected
value takes effect the next time Int 10H Function 00H is called to select
the display mode.
Call with:
AH = 12H
AL = scan line code
00H = 200 scan lines
01H = 350 scan lines
02H = 400 scan lines
BL = 30H
Returns:
AL = 12H
AL = 00H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 601/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 10H [MCGA] [VGA]
Function 12H (18) Subfunction 31H (49)
Enable/disable default palette loading
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 12H
AL = 00H to enable default palette loading
01H to disable default palette loading
BL = 31H
Returns:
If function supported
AL = 12H
────────────────────────────────────────────────────────────────────────────
Int 10H [MCGA] [VGA]
Function 12H (18) Subfunction 32H (50)
Enable/disable video
────────────────────────────────────────────────────────────────────────────
Enables or disables CPU access to the video adapter's I/O ports and video
refresh buffer.
Call with:
AH = 12H
AL = 00H to enable access
01H to disable access
BL = 32H
Returns:
If function supported
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 602/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AL = 12H
────────────────────────────────────────────────────────────────────────────
Int 10H [MCGA] [VGA]
Function 12H (18) Subfunction 33H (51)
Enable/disable gray-scale summing
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 12H
AL = 00H to enable gray-scale summing
01H to disable gray-scale summing
BL = 33H
Returns:
If function supported
AL = 12H
Note:
────────────────────────────────────────────────────────────────────────────
Int 10H [VGA]
Function 12H (18) Subfunction 34H (52)
Enable/disable cursor emulation
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 12H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 603/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
If function supported
AL = 12H
────────────────────────────────────────────────────────────────────────────
Int 10H [MCGA] [VGA]
Function 12H (18) Subfunction 35H (53)
Switch active display
────────────────────────────────────────────────────────────────────────────
Allows selection of one of two video adapters in the system when memory
usage or port addresses conflict between the two adapters.
Call with:
AH = 12H
AL = switching function
BL = 35H
ES:DX = segment:offset of 128-byte buffer (if AL = 00H, 02H, or
03H)
Returns:
If function supported
AL = 12H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 604/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
■ If there is no conflict between the system board video and the adapter
board video in memory or port usage, both video controllers can be
active simultaneously and this subfunction is not required.
────────────────────────────────────────────────────────────────────────────
Int 10H [VGA]
Function 12H (18) Subfunction 36H (54)
Enable/disable screen refresh
────────────────────────────────────────────────────────────────────────────
Enables or disables the video refresh for the currently active display.
Call with:
AH = 12H
AL = 00H to enable refresh
01H to disable refresh
BL = 36H
Returns:
If function supported
AL = 12H
────────────────────────────────────────────────────────────────────────────
Int 10H [MDA] [CGA] [PCjr] [EGA] [MCGA] [VGA]
Function 13H (19)
Write string in teletype mode
────────────────────────────────────────────────────────────────────────────
Transfers a string to the video buffer for the currently active display,
starting at the specified position.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 605/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 13H
AL = write mode
BH = page
BL = attribute, if AL = 00H or 01H
CX = length of character string
DH = y coordinate (row)
DL = x coordinate (column)
ES:BP = segment:offset of string
Returns:
Nothing
Notes:
────────────────────────────────────────────────────────────────────────────
Int 10H [PS/2]
Function 1AH (26)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 606/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 1AH
AL = subfunction
00H = get display combination code
01H = set display combination code
BH = inactive display code (if AL = 01H)
BL = active display code (if AL = 01H)
Returns:
If function supported
AL = 1AH
Note:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 607/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 10H [PS/2]
Function 1BH (27)
Get functionality/state information
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 1BH
BX = implementation type (always 00H)
ES:DI = segment:offset of 64-byte buffer
Returns:
If function supported
AL = 1BH
Notes:
╓┌───┌─────────┌─────────────────────────────────────────────────────────────╖
Byte(s) Contents
────────────────────────────────────────────────────────────────────────
00H─03H pointer to functionality information (see next Note)
04H current video mode
05H─06H number of character columns
07H─08H length of video refresh buffer (bytes)
09H─0AH starting address in buffer of upper left corner of display
0BH─1AH cursor position for video pages 0─7 as eight 2-byte entries;
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 608/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Bit(s) Significance
0 = 1 if all modes on all displays active
(always 0 on MCGA)
1 = 1 if gray-scale summing active
2 = 1 if monochrome display attached
Byte(s) Contents
────────────────────────────────────────────────────────────────────────
2 = 1 if monochrome display attached
3 = 1 if mode set default palette loading
disabled
4 = 1 if cursor emulation active (always 0 on
MCGA)
5 = state of I/B toggle (0 = intensity, 1 =
blink)
6─7 = reserved
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 609/813
10/16/2018 PCjs: Advanced MS-DOS Programming
2EH─30H reserved
31H video memory available
00H = 64 KB
01H = 128 KB
02H = 192 KB
03H = 256 KB
32H save pointer state information
Bit(s) Significance
0 = 1 if 512-character set active
Byte(s) Contents
────────────────────────────────────────────────────────────────────────
0 = 1 if 512-character set active
1 = 1 if dynamic save area active
2 = 1 if alpha font override active
3 = 1 if graphics font override active
4 = 1 if palette override active
5 = 1 if display combination code (DCC)
extension active
6─7 = reserved
33H─3FH reserved
────────────────────────────────────────────────────────────────────────
╓┌───┌─────────┌─────────────────────────────────────────────────────────────╖
Byte(s) Contents
Byte(s) Contents
────────────────────────────────────────────────────────────────────────
00H video modes supported
Bit Significance
0 = 1 if mode 00H supported
1 = 1 if mode 01H supported
2 = 1 if mode 02H supported
3 = 1 if mode 03H supported
4 = 1 if mode 04H supported
5 = 1 if mode 05H supported
6 = 1 if mode 06H supported
7 = 1 if mode 07H supported
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 610/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Bit Significance
0 = 1 if mode 08H supported
1 = 1 if mode 09H supported
2 = 1 if mode 0AH supported
3 = 1 if mode 0BH supported
Byte(s) Contents
────────────────────────────────────────────────────────────────────────
3 = 1 if mode 0BH supported
4 = 1 if mode 0CH supported
5 = 1 if mode 0DH supported
6 = 1 if mode 0EH supported
7 = 1 if mode 0FH supported
Bit(s) Significance
0 = 1 if mode 10H supported
1 = 1 if mode 11H supported
2 = 1 if mode 12H supported
3 = 1 if mode 13H supported
4─7 = reserved
03H─06H reserved
07H scan lines available in text modes
Bit(s) Significance
Byte(s) Contents
────────────────────────────────────────────────────────────────────────
Bit(s) Significance
0 = 1 if 200 scan lines
1 = 1 if 350 scan lines
2 = 1 if 400 scan lines
3─7 = reserved
08H character blocks available in text modes (see Int 10H Function
11H)
09H maximum number of active character blocks in text modes
0AH miscellaneous BIOS capabilities
Bit Significance
0 = 1 if all modes active on all displays
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 611/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Bit(s) Significance
0 = 1 if light pen available
1 = 1 if save/restore video state available
(always 0 on MCGA)
2 = 1 if background intensity/blinking
control available
3 = 1 if get/set display combination code
available
4─7 = reserved
0CH─0DH reserved
Byte(s) Contents
────────────────────────────────────────────────────────────────────────
0CH─0DH reserved
0EH save area capabilities
Bit(s) Significance
0 = 1 if supports 512-character sets
1 = 1 if dynamic save area available
2 = 1 if alpha font override available
3 = 1 if graphics font override available
4 = 1 if palette override available
5 = 1 if display combination code extension
available
6─7 = reserved
0FH reserved
────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 612/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 10H [PS/2]
Function 1CH (28)
Save or restore video state
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 1CH
AL = subfunction
CX = requested states
Returns:
If function supported
AL = 1CH
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 613/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
■ The current video state is altered during a save state operation (AL =
01H). If the requesting program needs to continue in the same video
state, it can follow the save state request with an immediate call to
restore the video state.
────────────────────────────────────────────────────────────────────────────
Int 11H [PC] [AT] [PS/2]
Get equipment configuration
────────────────────────────────────────────────────────────────────────────
Obtains the equipment list code word from the ROM BIOS.
Call with:
Nothing
Returns:
Bit(s) Significance
0 = 1 if floppy disk drive(s) installed
1 = 1 if math coprocessor installed
2 = 1 if pointing device installed (PS/2)
00 = 16 KB
01 = 32 KB
10 = 48 KB
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 614/813
10/16/2018 PCjs: Advanced MS-DOS Programming
11 = 64 KB
00 reserved
01 40-by-25 color text
10 80-by-25 color text
11 80-by-25 monochrome
00 = 1
01 = 2
10 = 3
11 = 4
8 reserved
9─11 number of RS-232 ports installed
Note:
■ Bits 2─3 of the returned value are used only in the ROM BIOS for the
original IBM PC with the 64 KB system board and on the PCjr.
────────────────────────────────────────────────────────────────────────────
Int 12H [PC] [AT] [PS/2]
Get conventional memory size
────────────────────────────────────────────────────────────────────────────
Returns the amount of conventional memory available for use by MS-DOS and
application programs.
Call with:
Nothing
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 615/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
Notes:
■ The value returned does not reflect any extended memory (above the 1 MB
boundary) that may be installed on 80286 or 80386 machines such as the
PC/AT or PS/2 (Models 50 and above).
────────────────────────────────────────────────────────────────────────────
Int 13H [PC] [AT] [PS/2]
Function 00H
Reset disk system
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 00H
DL = drive
00H─7FH floppy disk
80H─FFH fixed disk
Returns:
If function successful
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 616/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
■ This function should be called after a failed floppy disk Read, Write,
Verify, or Format request before retrying the operation.
■ If called with DL >= 80H (i.e., selecting a fixed disk drive), the
floppy disk controller and then the fixed disk controller are reset. See
also Int 13H Function 0DH, which allows the fixed disk controller to be
reset without affecting the floppy disk controller.
────────────────────────────────────────────────────────────────────────────
Int 13H [PC] [AT] [PS/2]
Function 01H
Get disk system status
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 01H
DL = drive
Returns:
AH = 00H
AL = status of previous disk operation
00H no error
01H invalid command
02H address mark not found
03H disk write-protected (F)
04H sector not found
05H reset failed (H)
06H floppy disk removed (F)
07H bad parameter table (H)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 617/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Note:
■ On fixed disks, error code 11H (ECC data error) indicates that a
recoverable error was detected during a preceding Read Sector (Int 13H
Function 02H) function.
────────────────────────────────────────────────────────────────────────────
Int 13H [PC] [AT] [PS/2]
Function 02H
Read sector
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 02H
AL = number of sectors
CH = cylinder
CL = sector
DH = head
DL = drive
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 618/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
If function successful
If function unsuccessful
Notes:
■ On fixed disks, the upper 2 bits of the 10-bit cylinder number are
placed in the upper 2 bits of register CL.
■ On fixed disks, error code 11H indicates that a read error occurred that
was corrected by the ECC algorithm; in this event, register AL contains
the burst length. The data returned is probably good, although there is
a small chance that the data was not corrected properly. If a
multi-sector transfer was requested, the operation was terminated after
the sector containing the read error.
■ On floppy disk drives, an error may result from the drive motor being
off at the time of the request. The ROM BIOS does not automatically wait
for the drive to come up to speed before attempting the read operation.
The requesting program should reset the floppy disk system (Int 13H
Function 00H) and retry the operation three times before assuming that
the error results from some other cause.
────────────────────────────────────────────────────────────────────────────
Int 13H [PC] [AT] [PS/2]
Function 03H
Write sector
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 619/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 03H
AL = number of sectors
CH = cylinder
CL = sector
DH = head
DL = drive
Returns:
If function successful
If function unsuccessful
Notes:
■ On fixed disks, the upper 2 bits of the 10-bit cylinder number are
placed in the upper 2 bits of register CL.
■ On floppy disk drives, an error may result from the drive motor being
off at the time of the request. The ROM BIOS does not automatically wait
for the drive to come up to speed before attempting the write operation.
The requesting program should reset the floppy disk system (Int 13H
Function 00H) and retry the operation three times before assuming that
the error results from some other cause.
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 620/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 04H
AL = number of sectors
CH = cylinder
CL = sector
DH = head
DL = drive
Returns:
If function successful
If function unsuccessful
Notes:
■ On PCs, PC/XTs, and PC/ATs with ROM BIOS dated earlier than 11/15/85,
ES:BX should point to a valid buffer.
■ On fixed disks, the upper 2 bits of the 10-bit cylinder number are
placed in the upper 2 bits of register CL.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 621/813
10/16/2018 PCjs: Advanced MS-DOS Programming
floppy disk drive. An error may result from the drive motor being off at
the time of the request, because the ROM BIOS does not automatically
wait for the drive to come up to speed before attempting the verify
operation. The requesting program should reset the floppy disk system
(Int 13H Function 00H) and retry the operation three times before
assuming that a readable floppy disk is not present.
────────────────────────────────────────────────────────────────────────────
Int 13H [PC] [AT] [PS/2]
Function 05H
Format track
────────────────────────────────────────────────────────────────────────────
Initializes disk sector and track address fields on the specified track.
Call with:
AH = 05H
AL = interleave (PC/XT fixed disks)
CH = cylinder
DH = head
DL = drive
Returns:
If function successful
If function unsuccessful
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 622/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Byte(s) Contents
0 cylinder
1 head
2 sector
3 sector-size code
■ On floppy disks, the number of sectors per track is taken from the BIOS
floppy disk parameter table whose address is stored in the vector for
Int 1EH.
■ When this function is used for floppy disks on the PC/AT or PS/2, it
should be preceded by a call to Int 13H Function 17H to select the type
of medium to be formatted.
■ On fixed disks, the upper 2 bits of the 10-bit cylinder number are
placed in the upper 2 bits of register CL.
Byte(s) Contents
0 00H for good sector
80H for bad sector
1 sector number
db 00h,01h,00h,0ah,00h,02h,00h,0bh,00h,03h,00h,0ch
db 00h,04h,00h,0dh,00h,05h,00h,0eh,00h,06h,00h,0fh
db 00h,07h,00h,10h,00h,08h,00h,11h,00h,09h
────────────────────────────────────────────────────────────────────────────
Int 13H [PC]
Function 06H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 623/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Initializes a track, writing disk address fields and data sectors and
setting bad sector flags.
Call with:
AH = 06H
AL = interleave
CH = cylinder
DH = head
DL = drive
Returns:
If function successful
If function unsuccessful
Notes:
■ For additional information, see Notes for Int 13H Function 05H.
────────────────────────────────────────────────────────────────────────────
Int 13H [PC]
Function 07H
Format drive
────────────────────────────────────────────────────────────────────────────
Formats the entire drive, writing disk address fields and data sectors,
starting at the specified cylinder.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 624/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 07H
AL = interleave
CH = cylinder
DL = drive
Returns:
If function successful
If function unsuccessful
Notes:
■ For additional information, see Notes for Int 13H Function 05H.
────────────────────────────────────────────────────────────────────────────
Int 13H [PC] [AT] [PS/2]
Function 08H
Get drive parameters
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 08H
DL = drive
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 625/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
If function successful
If function unsuccessful
Notes:
────────────────────────────────────────────────────────────────────────────
Int 13H [PC] [AT] [PS/2]
Function 09H
Initialize fixed disk characteristics
────────────────────────────────────────────────────────────────────────────
Initializes the fixed disk controller for subsequent I/O operations, using
the values found in the ROM BIOS disk parameter block(s).
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 626/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 09H
DL = drive
Returns:
If function successful
If function unsuccessful
Notes:
■ For PC and PC/XT fixed disks, the parameter block format is as follows:
Byte(s) Contents
00H─01H maximum number of cylinders
02H maximum number of heads
03H─04H starting reduced write current cylinder
05H─06H starting write precompensation cylinder
07H maximum ECC burst length
08H drive options
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 627/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ For PC/AT and PS/2 fixed disks, the parameter block format is as
follows:
Byte(s) Contents
00H─01H maximum number of cylinders
02H maximum number of heads
03H─04H reserved
05H─06H starting write precompensation cylinder
07H maximum ECC burst length
08H drive options
09H─0BH reserved
0CH─0DH landing zone cylinder
0EH sectors per track
0FH reserved
────────────────────────────────────────────────────────────────────────────
Int 13H [PC] [AT] [PS/2]
Function 0AH (10)
Read sector long
────────────────────────────────────────────────────────────────────────────
Reads a sector or sectors from disk into memory, along with a 4-byte ECC
code for each sector.
Call with:
AH = 0AH
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 628/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AL = number of sectors
CH = cylinder
CL = sector (see Notes)
DH = head
DL = drive
Returns:
If function successful
If function unsuccessful
Notes:
■ The upper 2 bits of the 10-bit cylinder number are placed in the upper 2
bits of register CL.
■ Unlike the normal Read Sector function (Int 13H Function 02H), ECC
errors are not automatically corrected. Multisector transfers are
terminated after any sector with a read error.
────────────────────────────────────────────────────────────────────────────
Int 13H [PC] [AT] [PS/2]
Function 0BH (11)
Write sector long
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 629/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 0BH
AL = number of sectors
CH = cylinder
CL = sector (see Notes)
DH = head
DL = drive
If function successful
If function unsuccessful
Notes:
■ The upper 2 bits of the 10-bit cylinder number are placed in the upper 2
bits of register CL.
────────────────────────────────────────────────────────────────────────────
Int 13H [PC] [AT] [PS/2]
Function 0CH (12)
Seek
────────────────────────────────────────────────────────────────────────────
Positions the disk read/write heads to the specified cylinder, but does
not transfer any data.
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 630/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 0CH
CH = lower 8 bits of cylinder
CL = upper 2 bits of cylinder in bits 6─7
DH = head
DL = drive
Returns:
If function successful
If function unsuccessful
Notes:
■ The upper 2 bits of the 10-bit cylinder number are placed in the upper 2
bits of register CL.
■ The Read Sector, Read Sector Long, Write Sector, and Write Sector Long
functions include an implied seek operation and need not be preceded by
an explicit call to this function.
────────────────────────────────────────────────────────────────────────────
Int 13H [PC] [AT] [PS/2]
Function 0DH (13)
Reset fixed disk system
────────────────────────────────────────────────────────────────────────────
Resets the fixed disk controller, recalibrates attached drives (moves the
read/write arm to cylinder 0), and prepares for subsequent disk I/O.
Call with:
AH = 0DH
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 631/813
10/16/2018 PCjs: Advanced MS-DOS Programming
DL = drive
Returns:
If function successful
If function unsuccessful
Note:
■ This function is supported on fixed disks only. It differs from Int 13H
Function 00H in that the floppy disk controller is not reset.
────────────────────────────────────────────────────────────────────────────
Int 13H [PC]
Function 0EH (14)
Read sector buffer
────────────────────────────────────────────────────────────────────────────
Transfers the contents of the fixed disk adapter's internal sector buffer
to system memory. No data is read from the physical disk drive.
Call with:
AH = 0EH
ES:BX = segment:offset of buffer
Returns:
If function successful
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 632/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Note:
────────────────────────────────────────────────────────────────────────────
Int 13H [PC]
Function 0FH (15)
Write sector buffer
────────────────────────────────────────────────────────────────────────────
Transfers data from system memory to the fixed disk adapter's internal
sector buffer. No data is written to the physical disk drive.
Call with:
AH = 0FH
ES:BX = segment:offset of buffer
Returns:
If function successful
If function unsuccessful
Notes:
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 633/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Tests whether the specified fixed disk drive is operational and returns
the drive's status.
Call with:
AH = 10H
DL = drive
Returns:
If function successful
If function unsuccessful
Note:
────────────────────────────────────────────────────────────────────────────
Int 13H [PC] [AT] [PS/2]
Function 11H (17)
Recalibrate drive
────────────────────────────────────────────────────────────────────────────
Causes the fixed disk adapter to recalibrate itself for the specified
drive, positioning the read/write arm to cylinder 0, and returns the
drive's status.
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 634/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 11H
DL = drive
Returns:
If function successful
If function unsuccessful
Note:
────────────────────────────────────────────────────────────────────────────
Int 13H [PC]
Function 12H (18)
Controller RAM diagnostic
────────────────────────────────────────────────────────────────────────────
Causes the fixed disk adapter to carry out a built-in diagnostic test on
its internal sector buffer, indicating whether the test was passed by the
returned status.
Call with:
AH = 12H
Returns:
If function successful
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 635/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Note:
────────────────────────────────────────────────────────────────────────────
Int 13H [PC]
Function 13H (19)
Controller drive diagnostic
────────────────────────────────────────────────────────────────────────────
Causes the fixed disk adapter to run internal diagnostic tests of the
attached drive, indicating whether the test was passed by the returned
status.
Call with:
AH = 13H
Returns:
If function successful
If function unsuccessful
Note:
────────────────────────────────────────────────────────────────────────────
Int 13H [PC] [AT] [PS/2]
Function 14H (20)
Controller internal diagnostic
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 636/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 14H
Returns:
If function successful
If function unsuccessful
Note:
────────────────────────────────────────────────────────────────────────────
Int 13H [AT] [PS/2]
Function 15H (21)
Get disk type
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 15H
DL = drive
Returns:
If function successful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 637/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
Note:
────────────────────────────────────────────────────────────────────────────
Int 13H [AT] [PS/2]
Function 16H (22)
Get disk change status
────────────────────────────────────────────────────────────────────────────
Returns the status of the change line, indicating whether the disk in the
drive may have been replaced since the last disk access.
Call with:
AH = 16H
DL = drive
00H─7FH floppy disk
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 638/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
■ If this function returns with the carry flag set, the disk has not
necessarily been changed; the change line can be activated by simply
unlocking and locking the disk drive door without removing the floppy
disk.
────────────────────────────────────────────────────────────────────────────
Int 13H [AT] [PS/2]
Function 17H (23)
Set disk type
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 17H
AL = floppy disk type code
Returns:
If function successful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 639/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
Notes:
■ If the change line is active for the specified drive, it is reset. The
ROM BIOS then sets the data rate for the specified drive and media type.
────────────────────────────────────────────────────────────────────────────
Int 13H [AT] [PS/2]
Function 18H (24)
Set media type for format
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 18H
CH = number of cylinders
CL = sectors per track
DL = drive
Returns:
If function successful
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 640/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
■ This function should be called prior to formatting a disk with Int 13H
Function 05H so that the ROM BIOS can set the correct data rate for the
media.
────────────────────────────────────────────────────────────────────────────
Int 13H [PS/2]
Function 19H (25)
Park heads
────────────────────────────────────────────────────────────────────────────
Moves the read/write arm to a track that is not used for data storage, so
that data will not be damaged when the drive is turned off.
Call with:
AH = 19H
DL = drive
Returns:
If function successful
If function unsuccessful
Note:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 641/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 13H [PS/2]
Function 1AH (26)
Format ESDI drive
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 1AH
AL = relative block address (RBA) defect table count
0 if no RBA table
>0 if RBA table used
Returns:
If function successful
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 642/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
■ This operation is sometimes called a "low level format" and prepares the
disk for physical read/write operations at the sector level. The drive
must be subsequently partitioned with the FDISK command and then given a
"high level format" with the FORMAT command to install a file system.
0 = reserved
1 = surface analysis
2 = formatting
────────────────────────────────────────────────────────────────────────────
Int 14H [PC] [AT] [PS/2]
Function 00H
Initialize communications port
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 00H
AL = initialization parameter (see Notes)
DX = communications port number (0 = COM1, 1 = COM2, etc.)
Returns:
AH = port status
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 643/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AL = modem status
Notes:
7 6 5 4 3 2 1 0
Baud rate Parity Stop bits Word length
────────────────────────────────────────────────────────────────────────
000 = 110 X0 = none 0 = 1 bit 10 = 7 bits
001 = 150 01 = odd 1 = 2 bits 11 = 8 bits
010 = 300 11 = even
011 = 600
100 = 1200
101 = 2400
110 = 4800
111 = 9600
────────────────────────────────────────────────────────────────────────
■ To initialize the serial port for data rates greater than 9600 baud on
PS/2 machines, see Int 14H Functions 04H and 05H.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 644/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 14H [PC] [AT] [PS/2]
Function 01H
Write character to communications port
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 01H
AL = character
DX = communications port number (0 = COM1, 1 = COM2, etc.)
Returns:
If function successful
AH bit 7 = 0
AH bits = port status
0─6
Bit Significance (if set)
0 receive data ready
1 overrun error detected
2 parity error detected
3 framing error detected
4 break detected
5 transmit holding register empty
6 transmit shift register empty
AL = character (unchanged)
AH bit 7 = 1
AL = character (unchanged)
────────────────────────────────────────────────────────────────────────────
Int 14H [PC] [AT] [PS/2]
Function 02H
Read character from communications port
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 645/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 02H
DX = communications port number (0 = COM1, 1 = COM2, etc.)
Returns:
If function successful
AH bit 7 = 0
AH bits 0─6 = status
AL = character
AH bit 7 = 1
────────────────────────────────────────────────────────────────────────────
Int 14H [PC] [AT] [PS/2]
Function 03H
Get communications port status
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 03H
DX = communications port number (0 = COM1, 1 = COM2, etc.)
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 646/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 14H [PS/2]
Function 04H
Extended initialize communications port
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 04H
AL = break flag
00H no break
01H break
BH = parity
00H none
01H odd
02H even
03H stick parity odd
04H stick parity even
BL = stop bits
CH = word length
00H 5 bits
01H 6 bits
02H 7 bits
03H 8 bits
CL = baud rate
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 647/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
────────────────────────────────────────────────────────────────────────────
Int 14H [PS/2]
Function 05H
Extended communications port control
────────────────────────────────────────────────────────────────────────────
Reads or sets the modem control register (MCR) for the specified serial
communications port.
Call with:
AH = 05H
AL = subfunction
Bit(s) Significance
0 data-terminal ready
1 request-to-send
2 Out1
3 Out2
4 loop (for testing)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 648/813
10/16/2018 PCjs: Advanced MS-DOS Programming
5─7 reserved
Returns:
────────────────────────────────────────────────────────────────────────────
Int 15H [PC]
Function 00H
Turn on cassette motor
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 00H
Returns:
If function successful
If function unsuccessful
AH = status
Note:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 649/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 15H [PC]
Function 01H
Turn off cassette motor
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 01H
Returns:
If function successful
If function unsuccessful
Note:
────────────────────────────────────────────────────────────────────────────
Int 15H [PC]
Function 02H
Read cassette
────────────────────────────────────────────────────────────────────────────
Reads one or more 256-byte blocks of data from the cassette tape drive to
memory.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 650/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 02H
CX = number of bytes to read
ES:BX = segment:offset of buffer
Returns:
If function successful
If function unsuccessful
Note:
────────────────────────────────────────────────────────────────────────────
Int 15H [PC]
Function 03H
Write cassette
────────────────────────────────────────────────────────────────────────────
Writes one or more 256-byte blocks of data from memory to the cassette
tape drive.
Call with:
AH = 03H
CX = number of bytes to write
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 651/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
If function successful
If function unsuccessful
Note:
────────────────────────────────────────────────────────────────────────────
Int 15H [PS/2]
Function 0FH (15)
Format ESDI drive periodic interrupt
────────────────────────────────────────────────────────────────────────────
Invoked by the ROM BIOS on the ESDI Fixed Disk Drive Adapter/A during a
format or surface analysis operation after each cylinder is completed.
Call with:
AH = 0FH
AL = phase code
0 = reserved
1 = surface analysis
2 = formatting
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 652/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
■ The default ROM BIOS handler for this function returns with the carry
flag set.
────────────────────────────────────────────────────────────────────────────
Int 15H [PS/2]
Function 21H (33) Subfunction 00H
Read POST error log
────────────────────────────────────────────────────────────────────────────
Returns error information that was accumulated during the most recent
power-on self-test (POST).
Call with:
AH = 21H
AL = 00H
Returns:
If function successful
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 653/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = status
Notes:
────────────────────────────────────────────────────────────────────────────
Int 15H [PS/2]
Function 21H (33) Subfunction 01H
Write POST error log
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 21H
AL = 01H
BH = device identifier
BL = device error code
Returns:
If function successful
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 654/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Note:
────────────────────────────────────────────────────────────────────────────
Int 15H [PS/2]
Function 4FH (79)
Keyboard intercept
────────────────────────────────────────────────────────────────────────────
Invoked for each keystroke by the ROM BIOS's Int 09H keyboard interrupt
handler.
Call with:
AH = 4FH
AL = scan code
Returns:
Notes:
■ A program can call Int 15H Function C0H to determine whether the host
machine's ROM BIOS supports this keyboard intercept.
────────────────────────────────────────────────────────────────────────────
Int 15H [AT] [PS/2]
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 655/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 80H
BX = device ID
CX = process ID
Returns:
If function successful
If function unsuccessful
Note:
■ This function call, along with Int 15H Functions 81H and 82H, defines
a simple protocol that can be used to arbitrate usage of devices by
multiple processes. A multitasking program manager would be expected to
capture Int 15H and provide the appropriate service. The default BIOS
routine for this function simply returns with the carry flag clear and
AH = 00H.
────────────────────────────────────────────────────────────────────────────
Int 15H [AT] [PS/2]
Function 81H (129)
Device close
────────────────────────────────────────────────────────────────────────────
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 656/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 81H
BX = device ID
CX = process ID
Returns:
If function successful
If function unsuccessful
Note:
────────────────────────────────────────────────────────────────────────────
Int 15H [AT] [PS/2]
Function 82H (130)
Process termination
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 82H
BX = process ID
Returns:
If function successful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 657/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
Note:
────────────────────────────────────────────────────────────────────────────
Int 15H [AT] [PS/2]
Function 83H (131)
Event wait
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 83H
AL = 00H
CX:DX = microseconds
ES:BX = segment:offset of semaphore byte
AH = 83H
AL = 01H
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 658/813
10/16/2018 PCjs: Advanced MS-DOS Programming
active)
Nothing
Notes:
■ See also Int 15H Function 86H, which suspends the calling program for
the specified interval in milliseconds.
────────────────────────────────────────────────────────────────────────────
Int 15H [AT] [PS/2]
Function 84H (132)
Read joystick
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 84H
DX = subfunction
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 659/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
If function successful
AX = A(x) value
BX = A(y) value
CX = B(x) value
DX = B(y) value
If function unsuccessful
Notes:
■ Using a 250 KOhm joystick, the potentiometer values usually lie within
the srange 0─416 (0000─01A0H).
────────────────────────────────────────────────────────────────────────────
Int 15H [AT] [PS/2]
Function 85H (133)
SysReq key
────────────────────────────────────────────────────────────────────────────
Invoked by the ROM BIOS keyboard driver when the SysReq key is detected.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 660/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 85H
AL = key status
Returns:
If function successful
If function unsuccessful
Note:
■ The ROM BIOS handler for this function call is a dummy routine that
always returns a success status unless called with an invalid
subfunction number in AL. A multitasking program manager would be
expected to capture Int 15H so that it can be notified when the user
strikes the SysReq key.
────────────────────────────────────────────────────────────────────────────
Int 15H [AT] [PS/2]
Function 86H (134)
Delay
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 86H
CX:DX = microseconds to wait
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 661/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
■ See also Int 15H Function 83H, which triggers a semaphore after a
specified interval but does not suspend the calling program.
────────────────────────────────────────────────────────────────────────────
Int 15H [AT] [PS/2]
Function 87H (135)
Move extended memory block
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 87H
CX = number of words to move
ES:SI = segment:offset of Global Descriptor Table (see Notes)
Returns:
If function successful
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 662/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
■ The Global Descriptor Table (GDT) used by this function must be set up
as follows:
Byte(s) Contents
────────────────────────────────────────────────────────────────────────
00H─0FH reserved (should be 0)
10H─11H segment length in bytes (2*CX - 1 or greater)
12H─14H 24-bit source address
15H access rights byte (always 93H)
16H─17H reserved (should be 0)
18H─19H segment length in bytes (2*CX - 1 or greater)
1AH─1CH 24-bit destination address
1DH access rights byte (always 93H)
1EH─2FH reserved (should be 0)
────────────────────────────────────────────────────────────────────────
■ The addresses used in the descriptor table are linear (physical) 24-bit
addresses in the range 000000H─FFFFFFH──not segments and offsets──with
the least significant byte at the lowest address and the most
significant byte at the highest address.
■ The block move is performed with interrupts disabled; thus, use of this
function may interfere with the operation of communications programs,
network drivers, or other software that relies on prompt servicing of
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 663/813
10/16/2018 PCjs: Advanced MS-DOS Programming
hardware interrupts.
■ Programs and drivers that access extended memory with this function
cannot be executed in the Compatibility Environment of OS/2.
────────────────────────────────────────────────────────────────────────────
Int 15H [AT] [PS/2]
Function 88H (136)
Get extended memory size
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 88H
Returns:
Notes:
■ Programs and drivers that use this function cannot be executed in the
Compatibility Environment of OS/2.
────────────────────────────────────────────────────────────────────────────
Int 15H [AT] [PS/2]
Function 89H (137)
Enter protected mode
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 664/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 89H
BH = interrupt number for IRQ0, written to ICW2 of 8259 PIC #1
(must be evenly divisible by 8, determines IRQ0─IRQ7)
BL = interrupt number for IRQ8, written to ICW2 of 8259 PIC #2
(must be evenly divisible by 8, determines IRQ8─IRQ15)
ES:SI = segment:offset of Global Descriptor Table (GDT)
Returns:
Notes:
The user must initialize the first seven descriptors; the eighth is
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 665/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 15H [AT] [PS/2]
Function 90H (144)
Device wait
────────────────────────────────────────────────────────────────────────────
Invoked by the ROM BIOS fixed disk, floppy disk, printer, network, and
keyboard drivers prior to performing a programmed wait for I/O completion.
Call with:
AH = 90H
AL = device type
Returns:
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 666/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 15H [AT] [PS/2]
Function 91H (145)
Device post
────────────────────────────────────────────────────────────────────────────
Invoked by the ROM BIOS fixed disk, floppy disk, network, and keyboard
drivers to signal that I/O is complete and/or the device is ready.
Call with:
AH = 91H
AL = device type
Returns:
AH = 00H
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 667/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ The ROM BIOS printer routine does not invoke this function because
printer output is not interrupt driven.
────────────────────────────────────────────────────────────────────────────
Int 15H [AT] [PS/2]
Function C0H (192)
Get system environment
────────────────────────────────────────────────────────────────────────────
Call with:
AH = C0H
Returns:
Notes:
Byte(s) Contents
────────────────────────────────────────────────────────────────────────
00H─01H length of table in bytes
02H system model (see following Note)
03H system submodel (see following Note)
04H BIOS revision level
05H configuration flags
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 668/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 15H [PS/2]
Function C1H (193)
Get address of extended BIOS data area
────────────────────────────────────────────────────────────────────────────
Returns the segment address of the base of the extended BIOS data area.
Call with:
AH = C1H
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 669/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function successful
If function unsuccessful
Notes:
■ The extended BIOS data area is allocated at the high end of conventional
memory during the POST (Power-On-Self-Test) sequence. The word at
0040:0013H (memory size) is updated to reflect the reduced amount of
memory available for MS-DOS and application programs. The first byte in
the extended BIOS data area is initialized to its length in KB.
■ A program can determine whether the extended BIOS data area exists with
Int 15H Function C0H.
────────────────────────────────────────────────────────────────────────────
Int 15H [PS/2]
Function C2H (194) Subfunction 00H
Enable/disable pointing device
────────────────────────────────────────────────────────────────────────────
Call with:
AH = C2H
AL = 00H
BH = enable/disable flag
00H = disable
01H = enable
Returns:
If function successful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 670/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
────────────────────────────────────────────────────────────────────────────
Int 15H [PS/2]
Function C2H (194) Subfunction 01H
Reset pointing device
────────────────────────────────────────────────────────────────────────────
Resets the system's mouse or other pointing device, setting the sample
rate, resolution, and other characteristics to their default values.
Call with:
AH = C2H
AL = 01H
Returns:
If function successful
If function unsuccessful
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 671/813
10/16/2018 PCjs: Advanced MS-DOS Programming
· disabled;
· and scaling at 1 to 1.
■ The application can use the other Int 15H Function C2H subfunctions to
initialize the pointing device to other sample rates, resolution, and
scaling, and then enable the device with Int 15H Function C2H
Subfunction 00H.
■ See also Int 15H Function C2H Subfunction 05H, which incidentally
resets the pointing device in a similar manner.
────────────────────────────────────────────────────────────────────────────
Int 15H [PS/2]
Function C2H (194) Subfunction 02H
Set sample rate
────────────────────────────────────────────────────────────────────────────
Sets the sampling rate of the system's mouse or other pointing device.
Call with:
AH = C2H
AL = 02H
BH = sample rate value
Returns:
If function successful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 672/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
Note:
■ The default sample rate is 100 reports per second after a reset
operation (Int 15H Function C2H Subfunction 01H).
────────────────────────────────────────────────────────────────────────────
Int 15H [PS/2]
Function C2H (194) Subfunction 03H
Set resolution
────────────────────────────────────────────────────────────────────────────
Call with:
AH = C2H
AL = 03H
BH = resolution value
Returns:
If function successful
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 673/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Note:
────────────────────────────────────────────────────────────────────────────
Int 15H [PS/2]
Function C2H (194) Subfunction 04H
Get pointing device type
────────────────────────────────────────────────────────────────────────────
Returns the identification code for the system's mouse or other pointing
device.
Call with:
AH = C2H
AL = 04H
Returns:
If function successful
If function unsuccessful
────────────────────────────────────────────────────────────────────────────
Int 15H [PS/2]
Function C2H (194) Subfunction 05H
Initialize pointing device interface
────────────────────────────────────────────────────────────────────────────
Sets the data package size for the system's mouse or other pointing
device, and initializes the resolution, sampling rate, and scaling to
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 674/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = C2H
AL = 05H
BH = data package size in bytes (1─8)
Returns:
If function successful
If function unsuccessful
Note:
· disabled;
· and scaling at 1 to 1.
────────────────────────────────────────────────────────────────────────────
Int 15H [PS/2]
Function C2H (194) Subfunction 06H
Set scaling or get status
────────────────────────────────────────────────────────────────────────────
Returns the current status of the system's mouse or other pointing device
or sets the device's scaling factor.
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 675/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = C2H
AL = 06H
BH = extended command
Returns:
If function successful
BL = status byte
Bit Significance
0 = 1 if right button pressed
1 = reserved
2 = 1 if left button pressed
3 = reserved
4 = 0 if 1:1 scaling
1 if 2:1 scaling
5 = 0 if device disabled
1 if device enabled
6 = 0 if stream mode
1 if remote mode
7 = reserved
CL = resolution
DL = sample rate
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 676/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
────────────────────────────────────────────────────────────────────────────
Int 15H [PS/2]
Function C2H (194) Subfunction 07H
Set pointing device handler address
────────────────────────────────────────────────────────────────────────────
Notifies the ROM BIOS pointing device driver of the address for a routine
to be called each time pointing device data is available.
Call with:
AH = C2H
AL = 07H
ES:BX = segment:offset of user routine
Returns:
If function successful
If function unsuccessful
Notes:
■ The user's handler for pointing device data is entered via a far call
with four parameters on the stack:
SS:SP+0AH status
SS:SP+08H x coordinate
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 677/813
10/16/2018 PCjs: Advanced MS-DOS Programming
SS:SP+06H y coordinate
SS:SP+04H z coordinate (always 0)
The handler must exit via a far return without removing the parameters
from the stack.
────────────────────────────────────────────────────────────────────────────
Int 15H [PS/2]
Function C3H (195)
Set watchdog time-out
────────────────────────────────────────────────────────────────────────────
Call with:
AH = C3H
AL = subfunction
Returns:
If function successful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 678/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
Notes:
────────────────────────────────────────────────────────────────────────────
Int 15H [PS/2]
Function C4H (196)
Programmable option select
────────────────────────────────────────────────────────────────────────────
Call with:
AH = C4H
AL = subfunction
Returns:
If function successful
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 679/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
Port Function
100H MCA ID (low byte)
101H MCA ID (high byte)
102H Option Select Byte 1
bit 0 = 1 if enabled, = 0 if disabled
103H Option Select Byte 2
104H Option Select Byte 3
105H Option Select Byte 4
bits 6─7 = channel check indicators
106H Subaddress Extension (low byte)
107H Subaddress Extension (high byte)
────────────────────────────────────────────────────────────────────────────
Int 16H [PC] [AT] [PS/2]
Function 00H
Read character from keyboard
────────────────────────────────────────────────────────────────────────────
Reads a character from the keyboard, also returning the keyboard scan
code.
Call with:
AH = 00H
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 680/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 16H [PC] [AT] [PS/2]
Function 01H
Get keyboard status
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 01H
Returns:
If no key waiting
Note:
■ The character returned by this function when the zero flag is clear is
not removed from the type-ahead buffer. The same character and scan code
will be returned by the next call to Int 16H Function 00H.
────────────────────────────────────────────────────────────────────────────
Int 16H [PC] [AT] [PS/2]
Function 02H
Get keyboard flags
────────────────────────────────────────────────────────────────────────────
Returns the ROM BIOS flags byte that describes the state of the various
keyboard toggles and shift keys.
Call with:
AH = 02H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 681/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
AL = flags
Bit Significance (if set)
0 right Shift key is down
1 left Shift key is down
2 Ctrl key is down
3 Alt key is down
4 Scroll Lock on
5 Num Lock on
6 Caps Lock on
7 Insert on
Note:
■ The keyboard flags byte is stored in the ROM BIOS data area at
0000:0417H.
────────────────────────────────────────────────────────────────────────────
Int 16H [PC] [AT] [PS/2]
Function 03H
Set repeat rate
────────────────────────────────────────────────────────────────────────────
Sets the ROM BIOS key repeat ("typematic") rate and delay.
Call with:
AH = 03H
AL = 05H
BH = repeat delay (see Notes)
BL = repeat rate (see Notes)
On the PCjr
AH = 03H
AL = subfunction
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 682/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
Nothing
Notes:
■ Subfunctions 00H─04H are available on the PCjr but are not supported by
the PC or PC/XT ROM BIOS. Subfunction 05H is available on PC/ATs with
ROM BIOS's dated 11/15/85 and later, and on the PS/2.
■ On the PC/AT and PS/2, the value in BH controls the amount of delay
before the first repeat key is generated. The delay is always a multiple
of 250 milliseconds:
■ On the PC/AT and PS/2, the value for the repeat rate in characters per
second can be chosen from the following table:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 683/813
10/16/2018 PCjs: Advanced MS-DOS Programming
0FH 8.0
10H 7.5
11H 6.7
12H 6.0
13H 5.5
14H 5.0
15H 4.6
16H 4.3
17H 4.0
18H 3.7
19H 3.3
1AH 3.0
1BH 2.7
1CH 2.5
1DH 2.3
1EH 2.1
1FH 2.0
────────────────────────────────────────────────────────────────────────────
Int 16H [PC]
Function 04H
Set keyclick
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 04H
AL = subfunction
Returns:
Nothing
Note:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 684/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 16H [AT] [PS/2]
Function 05H
Push character and scan code
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 05H
CH = scan code
CL = character
Returns:
If function successful
Note:
────────────────────────────────────────────────────────────────────────────
Int 16H [AT] [PS/2]
Function 10H (16)
Read character from enhanced keyboard
────────────────────────────────────────────────────────────────────────────
Reads a character and scan code from the keyboard type-ahead buffer.
Call with:
AH = 10H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 685/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
Note:
■ Use this function for the enhanced keyboard instead of Int 16H Function
00H. It allows applications to obtain the scan codes for the additional
F11, F12, and cursor control keys.
────────────────────────────────────────────────────────────────────────────
Int 16H [AT] [PS/2]
Function 11H (17)
Get enhanced keyboard status
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 11H
Returns:
If no key waiting
Notes:
■ Use this function for the enhanced keyboard instead of Int 16H Function
00H. It allows applications to test for the additional F11, F12, and
cursor control keys.
■ The character returned by this function when the zero flag is clear is
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 686/813
10/16/2018 PCjs: Advanced MS-DOS Programming
not removed from the type-ahead buffer. The same character and scan code
will be returned by the next call to Int 16H Function 10H.
────────────────────────────────────────────────────────────────────────────
Int 16H [AT] [PS/2]
Function 12H (18)
Get enhanced keyboard flags
────────────────────────────────────────────────────────────────────────────
Obtains the status of various enhanced keyboard special keys and keyboard
driver states.
Call with:
AH = 12H
Returns:
AX = flags
Note:
■ Use this function for the enhanced keyboard instead of Int 16H Function
02H.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 687/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 17H [PC] [AT] [PS/2]
Function 00H
Write character to printer
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 00H
AL = character
DX = printer number (0 = LPT1, 1 = LPT2, 2 = LPT3)
Returns:
AH = status
────────────────────────────────────────────────────────────────────────────
Int 17H [PC] [AT] [PS/2]
Function 01H
Initialize printer port
────────────────────────────────────────────────────────────────────────────
Initializes the specified parallel printer interface port and returns its
status.
Call with:
AH = 01H
DX = printer number (0 = LPT1, 1 = LPT2, 2 = LPT3)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 688/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
────────────────────────────────────────────────────────────────────────────
Int 17H [PC] [AT] [PS/2]
Function 02H
Get printer status
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 02H
DX = printer number (0 = LPT1, 1 = LPT2, 2 = LPT3)
Returns:
────────────────────────────────────────────────────────────────────────────
Int 18H [PC] [AT] [PS/2]
ROM BASIC
────────────────────────────────────────────────────────────────────────────
Call with:
Nothing
Returns:
Nothing
Note:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 689/813
10/16/2018 PCjs: Advanced MS-DOS Programming
are unsuccessful.
────────────────────────────────────────────────────────────────────────────
Int 19H [PC] [AT] [PS/2]
Reboot system
────────────────────────────────────────────────────────────────────────────
Reboots the operating system from the floppy disk or fixed disk drive.
Call with:
Nothing
Returns:
Nothing
Notes:
■ If location 0000:0472H does not contain the value 1234H, a memory test
will be performed before reading the boot sector.
────────────────────────────────────────────────────────────────────────────
Int 1AH [AT] [PS/2]
Function 00H
Get tick count
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 00H
Returns:
AL = rolled-over flag
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 690/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
■ This function is supported by the PC/XT and PCjr ROM BIOS, but is not
present in the ROM BIOS for the original PC.
■ The rolled-over flag is cleared by this function call, so the flag will
only be returned nonzero once per day.
■ Int 1AH Function 01H can be used to set the clock tick counter to an
arbitrary 32-bit value.
────────────────────────────────────────────────────────────────────────────
Int 1AH [AT] [PS/2]
Function 01H
Set tick count
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 01H
CX:DX = tick count (high 16 bits in CX)
Returns:
Nothing
Notes:
■ This function is supported by the PC/XT and PCjr ROM BIOS, but is not
present in the ROM BIOS for the original PC.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 691/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ Int 1AH Function 00H is used to read the value of the clock tick
counter.
────────────────────────────────────────────────────────────────────────────
Int 1AH [AT] [PS/2]
Function 02H
Get time
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 02H
Returns:
────────────────────────────────────────────────────────────────────────────
Int 1AH [AT] [PS/2]
Function 03H
Set time
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 692/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 03H
CH = hours in binary coded decimal (BCD)
CL = minutes in BCD
DH = seconds in BCD
DL = daylight-saving-time code
Returns:
Nothing
────────────────────────────────────────────────────────────────────────────
Int 1AH [AT] [PS/2]
Function 04H
Get date
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 04H
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 693/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 1AH [AT] [PS/2]
Function 05H
Set date
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 05H
CH = century (19 or 20) in binary coded decimal (BCD)
CL = year in BCD
DH = month in BCD
DL = day in BCD
Returns:
Nothing
────────────────────────────────────────────────────────────────────────────
Int 1AH [AT] [PS/2]
Function 06H
Set alarm
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 06H
CH = hours in binary coded decimal (BCD)
CL = minutes in BCD
DH = seconds in BCD
Returns:
If function successful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 694/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
■ A side effect of this function is that the clock chip's interrupt level
(IRQ8) is enabled.
■ Only one alarm may be active at any given time. The alarm occurs every
24 hours at the specified time until it is reset with Int 1AH Function
07H.
■ The program using this function must place the address of its interrupt
handler for the alarm in the vector for Int 4AH.
────────────────────────────────────────────────────────────────────────────
Int 1AH [AT] [PS/2]
Function 07H
Reset alarm
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 07H
Returns:
Nothing
Note:
■ This function does not disable the clock chip's interrupt level (IRQ8).
────────────────────────────────────────────────────────────────────────────
Int 1AH [PS/2]
Function 0AH (10)
Get day count
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 695/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 0AH
Returns:
If function successful
If function unsuccessful
────────────────────────────────────────────────────────────────────────────
Int 1AH [PS/2]
Function 0BH (11)
Set day count
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 0BH
CX = count of days since January 1, 1980
Returns:
If function successful
If function unsuccessful
────────────────────────────────────────────────────────────────────────────
Int 1AH [PC]
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 696/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Sets up the source for tones that will appear on the PCjr's "Audio Out" or
RF modulator.
Call with:
AH = 80H
AL = sound source
Returns:
Nothing
Note:
────────────────────────────────────────────────────────────────────────────
Int 33H
Microsoft Mouse driver
────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 00H
Reset mouse and get status
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 697/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Initializes the mouse driver and returns the driver status. If the mouse
pointer was previously visible, it is removed from the screen, and any
previously installed user handlers for mouse events are disabled.
Call with:
AX = 0000H
Returns:
AX = FFFFH
BX = number of mouse buttons
AX = 0000H
Note:
· Mouse pointer at screen center (see Int 33H Functions 03H and 04H)
· Display page for mouse pointer set to zero (see Int 33H Functions
1DH and 1EH)
· Mouse pointer hidden (see Int 33H Functions 01H, 02H, and 10H)
· User mouse event handler disabled (see Int 33H Functions 0CH and
14H)
· Light pen emulation enabled (see Int 33H Functions 0DH and 0EH)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 698/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 01H
Show mouse pointer
────────────────────────────────────────────────────────────────────────────
Displays the mouse pointer, and cancels any mouse pointer exclusion area
previously defined with Int 33H Function 10H.
Call with:
AX = 0001H
Returns:
Nothing
Note:
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 02H
Hide mouse pointer
────────────────────────────────────────────────────────────────────────────
Removes the mouse pointer from the display. The driver continues to track
the mouse position.
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 699/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AX = 0002H
Returns:
Nothing
Note:
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 03H
Get mouse position and button status
────────────────────────────────────────────────────────────────────────────
Call with:
AX = 0003H
Returns:
Note:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 700/813
10/16/2018 PCjs: Advanced MS-DOS Programming
mode. Position (x,y) = (0,0) is the upper left corner of the screen.
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 04H
Set mouse pointer position
────────────────────────────────────────────────────────────────────────────
Sets the position of the mouse pointer. The pointer is displayed at the
new position unless it has been hidden with Int 33H Function 02H, or the
new position lies within an exclusion area defined with Int 33H Function
10H.
Call with:
AX = 0004H
CX = horizontal (X) coordinate
DX = vertical (Y) coordinate
Returns:
Nothing
Notes:
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 05H
Get button press information
────────────────────────────────────────────────────────────────────────────
Returns the current status of all mouse buttons, and the number of presses
and position of the last press for a specified mouse button since the last
call to this function for that button. The press counter for the button is
reset to zero.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 701/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AX = 0005H
BX = button identifier
0 = left button
1 = right button
2 = center button
Returns:
AX = button status
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 06H
Get button release information
────────────────────────────────────────────────────────────────────────────
Returns the current status of all mouse buttons, and the number of
releases and position of the last release for a specified mouse button
since the last call to this function for that button. The release counter
for the button is reset to zero.
Call with:
AX = 0006H
BX = button identifier
0 = left button
1 = right button
2 = center button
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 702/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
AX = button status
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 07H
Set horizontal limits for pointer
────────────────────────────────────────────────────────────────────────────
Limits the mouse pointer display area by assigning minimum and maximum
horizontal (X) coordinates for the mouse pointer.
Call with:
AX = 0007H
CX = minimum horizontal (X) coordinate
DX = maximum horizontal (X) coordinate
Returns:
Nothing
Notes:
■ If the minimum value is greater than the maximum value, the two values
are swapped.
■ The mouse pointer will be moved if necessary so that it lies within the
specified horizontal coordinates.
■ See also Int 33H Function 10H, which defines an exclusion area for the
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 703/813
10/16/2018 PCjs: Advanced MS-DOS Programming
mouse pointer.
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 08H
Set vertical limits for pointer
────────────────────────────────────────────────────────────────────────────
Limits the mouse pointer display area by assigning minimum and maximum
vertical (Y) coordinates for the mouse pointer.
Call with:
AX = 0008H
CX = minimum vertical (Y) coordinate
DX = maximum vertical (Y) coordinate
Returns:
Nothing
Notes:
■ If the minimum value is greater than the maximum value, the two values
are swapped.
■ The mouse pointer will be moved if necessary so that it lies within the
specified vertical coordinates.
■ See also Int 33H Function 10H, which defines an exclusion area for the
mouse pointer.
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 09H
Set graphics pointer shape
────────────────────────────────────────────────────────────────────────────
Defines the shape, color, and hot spot of the mouse pointer in graphics
modes.
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 704/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AX = 0009H
BX = hot spot offset from left
CX = hot spot offset from top
ES:DX = segment:offset of pointer image buffer
Returns:
Nothing
Notes:
■ The pointer image buffer is 64 bytes long. The first 32 bytes contain a
bit mask which is ANDed with the screen image, and the second 32 bytes
contain a bit mask which is XORed with the screen image.
■ The hot spot is relative to the upper left corner of the pointer image,
and each pixel offset must be in the range -16 through 16. In display
modes 4 and 5, the horizontal offset must be an even number.
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 0AH (10)
Set text pointer type
────────────────────────────────────────────────────────────────────────────
Defines the shape and attributes of the mouse pointer in text modes.
Call with:
AX = 000AH
BX = pointer type
0 = software cursor
1 = hardware cursor
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 705/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Nothing
Notes:
■ If the software text cursor is selected (BX = 0), the masks in CX and DX
are mapped as follows:
Bit(s) Significance
────────────────────────────────────────────────────────────────────────
0─7 character code
8─10 foreground color
11 intensity
12─14 background color
15 blink
────────────────────────────────────────────────────────────────────────
For example, the following values would yield a software mouse cursor
that inverts the foreground and background colors:
AX = 000AH
BX = 0000H
CX = 77FFH
DX = 7700H
■ When the hardware text cursor is selected (BX = 1), the values in CX and
DX are the starting and ending scan lines for the blinking cursor
generated by the video adapter. The maximum scan line which may be used
depends on the type of adapter and the current display mode.
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 0BH (11)
Read mouse motion counters
────────────────────────────────────────────────────────────────────────────
Returns the net mouse displacement since the last call to this function.
The returned value is in mickeys; a positive number indicates travel to
the right or downwards, a negative number indicates travel to the left or
upwards. One mickey represents approximately 1/200 of an inch of mouse
movement.
Call with:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 706/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AX = 000BH
Returns:
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 0CH (12)
Set user-defined mouse event handler
────────────────────────────────────────────────────────────────────────────
Sets the address and event mask for an application program's mouse event
handler. The handler is called by the mouse driver whenever the specified
mouse events occur.
Call with:
AX = 000CH
CX = event mask
Returns:
Nothing
Notes:
■ The user-defined event handler is entered from the mouse driver by a far
call with registers set up as follows:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 707/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ Calls to the handler are disabled with Int 33H Function 00H or by
calling this function with an event mask of zero.
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 0DH (13)
Turn on light pen emulation
────────────────────────────────────────────────────────────────────────────
Enables light pen emulation by the mouse driver for IBM BASIC. A "pen
down" condition is created by pressing the left and right mouse buttons
simultaneously.
Call with:
AX = 000DH
Returns:
Nothing
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 708/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 0EH (14)
Turn off light pen emulation
────────────────────────────────────────────────────────────────────────────
Disables light pen emulation by the mouse driver for IBM BASIC.
Call with:
AX = 000EH
Returns:
Nothing
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 0FH (15)
Set mickeys to pixels ratio
────────────────────────────────────────────────────────────────────────────
Sets the number of mickeys per 8 pixels for horizontal and vertical mouse
motion. One mickey represents approximately 1/200 of an inch of mouse
travel.
Call with:
AX = 000FH
CX = horizontal mickeys (1─32,767, default = 8)
DX = vertical mickeys (1─32,767, default = 16)
Returns:
Nothing
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 10H (16)
Set mouse pointer exclusion area
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 709/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Defines an exclusion area for the mouse pointer. When the mouse pointer
lies within the specified area, it is not displayed.
Call with:
AX = 0010H
CX = upper left X coordinate
DX = upper left Y coordinate
SI = lower right X coordinate
DI = lower right Y coordinate
Returns:
Nothing
Note:
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 13H (19)
Set double speed threshold
────────────────────────────────────────────────────────────────────────────
Sets the threshold speed for doubling pointer motion on the screen. The
default threshold speed is 64 mickeys/second.
Call with:
AX = 0013H
DX = threshold speed in mickeys/second
Returns:
Nothing
Note:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 710/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 14H (20)
Swap user-defined mouse event handlers
────────────────────────────────────────────────────────────────────────────
Sets the address and event mask for an application program's mouse event
handler and returns the address and event mask for the previous handler.
The newly installed handler is called by the mouse driver whenever the
specified mouse events occur.
Call with:
AX = 0014H
CX = event mask
Returns:
Notes:
■ The Notes for Int 33H Function 0CH describe the information passed to
the user-defined event handler. See also Int 33H Function 18H.
■ Calls to the event handler are disabled with Int 33H Function 00H or by
setting an event mask of zero.
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 711/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Int 33H
Function 15H (21)
Get mouse save state buffer size
────────────────────────────────────────────────────────────────────────────
Gets the size of the buffer required to store the current state of the
mouse driver.
Call with:
AX = 0015H
Returns:
Note:
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 16H (22)
Save mouse driver state
────────────────────────────────────────────────────────────────────────────
Saves the mouse driver state in a user buffer. The minimum size for the
buffer must be determined by a previous call to Int 33H Function 15H.
Call with:
AX = 0016H
ES:DX = segment:offset of buffer
Returns:
Nothing
Note:
■ Call this function before executing a child program with Int 21H
Function 4BH (EXEC), in case the child also uses the mouse. After the
EXEC call, restore the previous mouse driver state with Int 33H Function
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 712/813
10/16/2018 PCjs: Advanced MS-DOS Programming
17H.
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 17H (23)
Restore mouse driver state
────────────────────────────────────────────────────────────────────────────
Call with:
AX = 0017H
ES:DX = segment:offset of buffer
Returns:
Nothing
Note:
■ The mouse driver state must have been previously saved into the same
buffer with Int 33H Function 16H. The format of the data in the buffer
is undocumented and subject to change.
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 18H (24)
Set alternate mouse event handler
────────────────────────────────────────────────────────────────────────────
Sets the address and event mask for a an application program mouse event
handler. As many as three handlers with distinct event masks can be
registered with this function. When an event occurs that matches one of
the masks, the corresponding handler is called by the mouse driver.
Call with:
AX = 0018H
CX = event mask
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 713/813
10/16/2018 PCjs: Advanced MS-DOS Programming
0 mouse movement
1 left button pressed
2 left button released
3 right button pressed
4 right button released
5 Shift key pressed during button press or release
6 Ctrl key pressed during button press or release
7 Alt key pressed during button press or release
8─15 reserved (0)
Returns:
If function successful
AX = 0018H
If function unsuccessful
AX = FFFFH
Notes:
■ When this function is called, at least one of the bits 5, 6, and 7 must
be set in register CX.
■ The user-defined event handler is entered from the mouse driver by a far
call with registers set up as follows:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 714/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ Calls to the handler are disabled with Int 33H Function 00H.
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 19H (25)
Get address of alternate mouse event handler
────────────────────────────────────────────────────────────────────────────
Returns the address for the mouse event handler matching the specified
event mask.
Call with:
AX = 0019H
CX = event mask (see Int 33H Function 18H)
Returns:
If function successful
CX = event mask
ES:DX = segment:offset of alternate event handler
CX = 0000H
Note:
■ Int 33H Function 18H allows as many as three event handlers with
distinct event masks to be installed. This function can be called to
search for a handler that matches a specific event, so that it can be
replaced or disabled.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 715/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 1AH (26)
Set mouse sensitivity
────────────────────────────────────────────────────────────────────────────
Sets the number of mickeys per 8 pixels for horizontal and vertical mouse
motion and the threshold speed for doubling pointer motion on the screen.
One mickey represents approximately 1/200 of an inch of mouse travel.
Call with:
AX = 001AH
BX = horizontal mickeys (1─32,767, default = 8)
CX = vertical mickeys (1─32,767, default = 16)
DX = double speed threshold in mickeys/second (default = 64)
Returns:
Nothing
Note:
■ See also Int 33H Functions 0FH and 13H, which allow the mickeys to
pixels ratio and threshold speed to be set separately, and Int 33H
Function 1BH, which returns the current sensitivity values.
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 1BH (27)
Get mouse sensitivity
────────────────────────────────────────────────────────────────────────────
Returns the current mickeys to pixels ratios for vertical and horizontal
screen movement and the threshold speed for doubling of pointer motion.
Call with:
AX = 001BH
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 716/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Note:
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 1CH (28)
Set mouse interrupt rate
────────────────────────────────────────────────────────────────────────────
Sets the rate at which the mouse driver polls the status of the mouse.
Faster rates provide better resolution in graphics mode but may degrade
the performance of application programs.
Call with:
AX = 001CH
BX = interrupt rate flags
Bit(s) Significance
0 no interrupts allowed
1 30 interrupts/second
2 50 interrupts/second
3 100 interrupts/second
4 200 interrupts/second
5─15 reserved (0)
Returns:
Nothing
Notes:
■ If more than one bit is set in register BX, the lowest order bit
prevails.
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 717/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Int 33H
Function 1DH (29)
Select pointer page
────────────────────────────────────────────────────────────────────────────
Call with:
AX = 001DH
BX = page
Returns:
Nothing
Note:
■ The valid page numbers depend on the current display mode. See Int 10H
Function 05H.
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 1EH (30)
Get pointer page
────────────────────────────────────────────────────────────────────────────
Call with:
AX = 001EH
Returns:
BX = page
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 1FH (31)
Disable mouse driver
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 718/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Disables the mouse driver and returns the address of the previous Int 33H
handler.
Call with:
AX = 001FH
Returns:
If function successful
AX = 001FH
ES:BX = segment:offset of previous Int 33H handler
If function unsuccessful
AX = FFFFH
Notes:
■ When this function is called, the mouse driver releases any interrupt
vectors it has captured other than Int 33H (which may include Int 10H,
Int 71H, and/or Int 74H). The application program can complete the
process of logically removing the mouse driver by restoring the original
contents of the Int 33H vector with Int 21H Function 25H, using the
address returned by this function in ES:BX.
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 20H (32)
Enable mouse driver
────────────────────────────────────────────────────────────────────────────
Call with:
AX = 0020H
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 719/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Nothing
Note:
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 21H (33)
Reset mouse driver
────────────────────────────────────────────────────────────────────────────
Resets the mouse driver and returns driver status. If the mouse pointer
was previously visible, it is removed from the screen, and any previously
installed user handlers for mouse events are disabled.
Call with:
AX = 0021H
Returns:
AX = FFFFH
BX = number of mouse buttons
AX = 0021H
Note:
■ This function differs from Int 33H Function 00H in that there is no
initialization of the mouse hardware.
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 22H (34)
Set language for mouse driver messages
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 720/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Selects the language that will be used by the mouse driver for prompts and
error messages.
Call with:
AX = 0022H
BX = language number
0 = English
1 = French
2 = Dutch
3 = German
4 = Swedish
5 = Finnish
6 = Spanish
7 = Portuguese
8 = Italian
Returns:
Nothing
Note:
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 23H (35)
Get language number
────────────────────────────────────────────────────────────────────────────
Returns the number of the language that is used by the mouse driver for
prompts and error messages.
Call with:
AX = 0023H
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 721/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Note:
────────────────────────────────────────────────────────────────────────────
Int 33H
Function 24H (36)
Get mouse information
────────────────────────────────────────────────────────────────────────────
Returns the mouse driver version number, mouse type, and the IRQ number of
the interrupt used by the mouse adapter.
Call with:
AX = 0024H
Returns:
1 = bus mouse
2 = serial mouse
3 = InPort mouse
4 = PS/2 mouse
5 = HP mouse
CL = IRQ number
0 = PS/2
2, 3, 4, 5, or 7 = IRQ number
────────────────────────────────────────────────────────────────────────────
SECTION 4 LOTUS/INTEL/MICROSOFT EMS FUNCTIONS REFERENCE
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 722/813
10/16/2018 PCjs: Advanced MS-DOS Programming
After ensuring that the EMM is present (see Chapter 11), an application
program communicates directly with the EMM using software interrupt 67H. A
particular EMM function is selected by the value in register AH and a
success or error status is returned in register AH (error codes are listed
on pages 207─209). Other parameters and results are passed or returned in
registers or buffers.
An icon in each function heading indicates the EMS version in which that
function was first supported. You can assume that the function is
available in all subsequent EMS versions unless explicitly noted
otherwise.
The material in this section has been verified against the Expanded Memory
Specification version 4.0, dated October 1987, Intel part number
300275-005. This document can be obtained from Intel Corporation, 5200
N.E. Elam Young Parkway, Hillsboro, OR 97124.
╓┌─┌────────────┌───────────────┌────────────────────────────────────────────╖
Function Subfunction Description
──────────────────────────────────────────────────────────────────────────
40H (64) Get Status
41H (65) Get Page Frame Address
42H (66) Get Number of Pages
43H (67) Allocate Handle and Pages
44H (68) Map Expanded Memory Page
45H (69) Release Handle and Expanded Memory
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 723/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 724/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.0]
Function 40H (64)
Get status
────────────────────────────────────────────────────────────────────────────
Returns a status code indicating whether the expanded memory software and
hardware are present and functional.
Call with:
AH = 40H
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 725/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Note:
■ This call should be used only after an application has established that
the Expanded Memory Manager is in fact present, using one of the
techniques described in Chapter 11.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.0]
Function 41H (65)
Get page frame address
────────────────────────────────────────────────────────────────────────────
Returns the segment address of the page frame used by the Expanded Memory
Manager.
Call with:
AH = 41H
Returns:
If function successful
AH = 00H
BX = segment base of page frame
If function unsuccessful
AH = error code
Notes:
■ The page frame is divided into four 16 KB pages, which are used to map
logical expanded memory pages into the physical memory space of the CPU.
■ The application need not have already acquired an EMM handle to use this
function.
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 726/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Obtains the total number of logical expanded memory pages present in the
system and the number of pages that are not already allocated.
Call with:
AH = 42H
Returns:
If function successful
AH = 00H
BX = unallocated pages
DX = total pages
If function unsuccessful
AH = error code
Notes:
■ The application need not have already acquired an EMM handle to use this
function.
■ [EMS 4.0] See also Int 67H Function 59H Subfunction 01H.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.0]
Function 43H (67)
Allocate handle and pages
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 43H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 727/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
If function successful
AH = 00H
DX = EMM handle
If function unsuccessful
AH = error code
Notes:
■ This is the equivalent of a file open function for the expanded memory
manager. The handle that is returned is analogous to a file handle and
owns a certain number of expanded memory pages. The handle must be used
with every subsequent request to map memory and must be released by a
close operation before the application terminates.
■ This function may fail because there are no handles left to allocate or
because there is an insufficient number of expanded memory pages to
satisfy the request. In the latter case, Int 67H Function 42H can be
used to determine the actual number of pages available.
■ [EMS 4.0] Int 67H Function 51H can be called to change the number of
pages allocated to an EMM handle.
■ [EMS 4.0] The pages allocated by this function are always 16 KB for
compatibility with earlier versions of EMS. See also Int 67H Function
5AH Subfunctions 00H and 01H.
■ [EMS 4.0] Handle 0000H is always available for use by the operating
system, and a prior call to this function is not required. The operating
system must call Int 67H Function 51H to assign the desired number of
pages to its reserved handle.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.0]
Function 44H (68)
Map expanded memory page
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 728/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Maps one of the logical pages of expanded memory assigned to a handle onto
a physical memory page that can be accessed by the CPU.
Call with:
AH = 44H
AL = physical page
BX = logical page
DX = EMM handle
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Notes:
■ The logical page number is in the range {0...n-1}, where n is the number
of pages allocated or reallocated to the handle by a previous call to
Int 67H Function 43H, 51H, or 5AH. Logical pages allocated by Int 67H
Function 43H or Function 5AH Subfunction 00H are always 16 KB long;
logical pages allocated by Int 67H Function 5AH Subfunction 01H are
referred to as raw pages and are not necessarily 16 KB.
■ [EMS 3] The physical page is in the range 0─3 and lies within the EMM
page frame, whose base address is obtained from Int 67H Function 41H.
■ [EMS 4.0] A list of the available physical pages and their addresses may
be obtained from Int 67H Function 58H Subfunction 00H.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.0]
Function 45H (69)
Release handle and expanded memory
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 729/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 45H
DX = EMM handle
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Notes:
■ [EMS 4.0] When a handle is released, its name is set to all ASCII nulls.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.0]
Function 46H (70)
Get version
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 46H
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 730/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function successful
AH = 00H
AL = version number
If function unsuccessful
AH = error code
Notes:
■ The version number is returned in binary code decimal (BCD) format, with
the integer portion in the upper 4 bits of AL and the fractional portion
in the lower 4 bits. For example, under an EMM that supports EMS version
3.2, AL is returned as the value 32H.
■ Applications should always check the EMM version number to ensure that
all of the EMM functions they require are available.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.0]
Function 47H (71)
Save page map
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 47H
DX = EMM handle
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 731/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Notes:
■ [EMS 4.0] This function saves only the mapping state for the 64 KB page
frame defined in EMS 3. Programs that are written to take advantage of
the additional capabilities of EMS 4.0 should use Int 67H Function 4EH
or 4FH in preference to this function.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.0]
Function 48H (72)
Restore page map
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 48H
DX = EMM handle
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 732/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ [EMS 4.0] This function restores only the mapping state for the 64 KB
page frame defined in EMS 3. Programs that are written to take advantage
of the additional capabilities of EMS 4.0 should use Int 67H Function
4EH or 4FH in preference to this function.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.0]
Function 49H (73)
Reserved
────────────────────────────────────────────────────────────────────────────
This function was defined in EMS version 3.0 but is not documented for
later EMS versions, so it should be avoided in application programs.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.0]
Function 4AH (74)
Reserved
────────────────────────────────────────────────────────────────────────────
This function was defined in EMS version 3.0 but is not documented for
later EMS versions, so it should be avoided in application programs.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.0]
Function 4BH (75)
Get handle count
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 4BH
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 733/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function successful
AH = 00H
BX = number of active EMM handles
If function unsuccessful
AH = error code
Notes:
■ The value returned by this function is not necessarily the same as the
number of programs using expanded memory because one program may own
multiple EMM handles.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.0]
Function 4CH (76)
Get handle pages
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 4CH
DX = EMM handle
Returns:
If function successful
AH = 00H
BX = number of EMM pages
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 734/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = error code
Notes:
■ [EMS 4.0] The total number of pages allocated to a handle never exceeds
2048. A handle may have zero pages of expanded memory.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.0]
Function 4DH (77)
Get pages for all handles
────────────────────────────────────────────────────────────────────────────
Returns an array that contains all the active handles and the number of
expanded memory pages associated with each handle.
Call with:
AH = 4DH
ES:DI = segment:offset of buffer (see Notes)
Returns:
If function successful
AH = 00H
BX = number of active EMM handles
If function unsuccessful
AH = error code
Notes:
■ The buffer is filled in with a series of DWORD (32-bit) entries, one per
active EMM handle. The first word of an entry contains the handle, and
the second word contains the number of pages allocated to that handle.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 735/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.2]
Function 4EH (78) Subfunction 00H
Save page map
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 4EH
AL = 00H
ES:DI = segment:offset of buffer (see Notes)
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Notes:
■ The size of the buffer required by this function can be determined with
Int 67H Function 4EH Subfunction 03H.
■ Unlike Int 67H Function 47H, this function does not require a handle.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 736/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.2]
Function 4EH (78) Subfunction 01H
Restore page map
────────────────────────────────────────────────────────────────────────────
Restores the page-mapping state of the expanded memory hardware using the
information in the specified buffer.
Call with:
AH = 4EH
AL = 01H
DS:SI = segment:offset of buffer (see Notes)
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Notes:
■ Unlike Int 67H Function 48H, this function does not require a handle.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.2]
Function 4EH (78) Subfunction 02H
Save and restore page map
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 737/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 4EH
AL = 02H
DS:SI = segment:offset of buffer containing mapping information
(see Notes)
ES:DI = segment:offset of buffer to receive mapping information
(see Notes)
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Notes:
■ Unlike Int 67H Functions 47H and 48H, this function does not require a
handle.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 3.2]
Function 4EH (78) Subfunction 03H
Get size of page map information
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 738/813
10/16/2018 PCjs: Advanced MS-DOS Programming
information using Int 67H Function 4EH Subfunctions 00H and 02H.
Call with:
AH = 4EH
AL = 03H
Returns:
If function successful
AH = 00H
AL = size of buffer (bytes)
If function unsuccessful
AH = error code
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 4FH (79) Subfunction 00H
Save partial page map
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 4FH
AL = 00H
DS:SI = segment:offset of map list (see Notes)
ES:DI = segment:offset of buffer to receive mapping state (see
Notes)
Returns:
If function successful
AH = 00H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 739/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
AH = error code
Notes:
■ The map list contains the number of mappable segments in the first word,
followed by the segment addresses of the mappable memory regions (one
segment per word).
■ To determine the size of the buffer required for the mapping state, use
Int 67H Function 4FH Subfunction 02H.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 4FH (79) Subfunction 01H
Restore partial page map
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 4FH
AL = 01H
DS:SI = segment:offset of buffer (see Note)
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Note:
■ The buffer contains mapping information and must have been prepared by a
previous call to Int 67H Function 4FH Subfunction 00H.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 740/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 4FH (79) Subfunction 02H
Get size of partial page map information
────────────────────────────────────────────────────────────────────────────
Returns the size of the buffer which will be required to receive partial
page-mapping information using Int 67H Function 4FH Subfunction 00H.
Call with:
AH = 4FH
AL = 02H
BX = number of pages
Returns:
If function successful
AH = 00H
AL = size of array (bytes)
If function unsuccessful
AH = error code
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 50H (80) Subfunction 00H
Map multiple pages by number
────────────────────────────────────────────────────────────────────────────
Maps one or more of the logical expanded memory pages assigned to a handle
onto physical memory pages that can be accessed by the CPU. Physical pages
are referenced by their numbers.
Call with:
AH = 50H
AL = 00H
CX = number of pages to map
DX = EMM handle
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 741/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Note:
■ The buffer contains a series of DWORD (32-bit) entries that control the
pages to be mapped. The first word of each entry contains the logical
expanded memory page number, and the second word contains the physical
page number to which it should be mapped. If the logical page is -1, the
physical page is unmapped (made inaccessible for reading or writing).
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 50H (80) Subfunction 01H
Map multiple pages by address
────────────────────────────────────────────────────────────────────────────
Maps one or more of the logical expanded memory pages assigned to a handle
onto physical memory pages that can be accessed by the CPU. Physical pages
are referenced by their segment addresses.
Call with:
AH = 50H
AL = 01H
CX = number of pages to map
DX = EMM handle
DS:SI = segment:offset of buffer (see Notes)
Returns:
If function successful
AH = 00H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 742/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
AH = error code
Notes:
■ The buffer contains a series of DWORD (32-bit) entries that control the
pages to be mapped. The first word of each entry contains the logical
page number, and the second word contains the physical page segment
address to which it should be mapped. If the logical page is -1, the
physical page is unmapped (made inaccessible for reading or writing).
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 51H (81)
Reallocate pages for handle
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 51H
BX = new number of pages
DX = EMM handle
Returns:
If function successful
AH = 00H
BX = logical pages owned by EMM handle
If function unsuccessful
AH = error code
Note:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 743/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 52H (82) Subfunction 00H
Get handle attribute
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 52H
AL = 00H
DX = EMM handle
Returns:
If function successful
AH = 00H
AL = attribute
0 = volatile
1 = nonvolatile
If function unsuccessful
AH = error code
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 52H (82) Subfunction 01H
Set handle attribute
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 744/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 52H
AL = 01H
BL = attribute
0 = volatile
1 = nonvolatile
DX = EMM handle
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Note:
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 52H (82) Subfunction 02H
Get attribute capability
────────────────────────────────────────────────────────────────────────────
Returns a code indicating whether the Expanded Memory Manager and hardware
can support the nonvolatile attribute for EMM handles.
Call with:
AH = 52H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 745/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AL = 02H
Returns:
If function successful
AH = 00H
AL = attribute capability
0 = only volatile handles supported
1 = volatile and nonvolatile handles supported
If function unsuccessful
AH = error code
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 53H (83) Subfunction 00H
Get handle name
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 53H
AL = 00H
DX = EMM handle
ES:DI = segment:offset of 8-byte buffer
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Note:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 746/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 53H (83) Subfunction 01H
Set handle name
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 53H
AL = 01H
DX = EMM handle
DS:SI = segment:offset of 8-byte name
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Notes:
■ The bytes in a handle name need not be ASCII characters, but the
sequence of 8 zero bytes is reserved for no name (the default after a
handle is allocated or deallocated). A handle name should be padded with
zero bytes, if necessary, to a length of 8 bytes.
■ All handle names are initialized to 8 zero bytes when the system is
turned on. The name of a nonvolatile handle is preserved across a warm
boot. (See Int 67H Function 52H Subfunctions 00H and 02H.)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 747/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 54H (84) Subfunction 00H
Get all handle names
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 54H
AL = 00H
ES:DI = segment:offset of buffer (see Notes)
Returns:
If function successful
AH = 00H
AL = number of active handles
If function unsuccessful
AH = error code
Notes:
■ The function fills the buffer with a series of 10-byte entries. The
first 2 bytes of each entry contain an EMM handle, and the next 8 bytes
contain the name associated with the handle. Handles that have never
been assigned a name have 8 bytes of 0 as a name.
■ Because there is a maximum of 255 active handles, the buffer need not be
longer than 2550 bytes.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 54H (84) Subfunction 01H
Search for handle name
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 748/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 54H
AL = 01H
DS:SI = segment:offset of 8-byte handle name
Returns:
If function successful
AH = 00H
DX = EMM handle
If function unsuccessful
AH = error code
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 54H (84) Subfunction 02H
Get total handles
────────────────────────────────────────────────────────────────────────────
Returns the total number of handles that are supported by the Expanded
Memory Manager, including the operating-system handle (0).
Call with:
AH = 54H
AL = 02H
Returns:
If function successful
AH = 00H
BX = number of handles
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 749/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = error code
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 55H (85) Subfunctions 00H and 01H
Map pages and jump
────────────────────────────────────────────────────────────────────────────
Alters the expanded memory mapping context and transfers control to the
specified address.
Call with:
AH = 55H
AL = subfunction
DX = EMM handle
DS:SI = segment:offset of buffer (see Notes)
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 750/813
10/16/2018 PCjs: Advanced MS-DOS Programming
The map list in turn consists of DWORD (32-bit) entries, one per page.
The first word of each entry contains the logical page number, and the
second word contains the physical page number or segment (depending on
the value in register AL) to which it should be mapped.
■ A request to map zero pages and jump is not considered an error; the
effect is a simple far jump.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 56H (86) Subfunctions 00H and 01H
Map pages and call
────────────────────────────────────────────────────────────────────────────
Alters the expanded memory mapping context and performs a far call to the
specified address. When the destination routine executes a far return, the
EMM again alters the page-mapping context as instructed and then returns
control to the original caller.
Call with:
AH = 56H
AL = subfunction
DX = EMM handle
DS:SI = segment:offset of buffer (see Notes)
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 751/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ The format of the buffer containing map and call information is:
Both map lists have the same format and consist of a series of
double-word entries, one per page. The first word of each entry contains
the logical page number, and the second word contains the physical page
number or segment (depending on the value in register AL) to which it
should be mapped.
■ A request to map zero pages and call is not an error; the effect is a
simple far call.
■ This function uses extra stack space to save information about the
mapping context; the amount of stack space required can be determined by
calling Int 67H Function 56H Subfunction 02H.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 56H (86) Subfunction 02H
Get stack space for map page and call
────────────────────────────────────────────────────────────────────────────
Returns the number of bytes of stack space required by Int 67H Function
56H Subfunction 00H or 01H.
Call with:
AH = 56H
AL = 02H
Returns:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 752/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function successful
AH = 00H
BX = stack space required (bytes)
If function unsuccessful
AH = error code
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 57H (87) Subfunction 00H
Move memory region
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 57H
AL = 00H
DS:SI = segment:offset of buffer (see Notes)
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 753/813
10/16/2018 PCjs: Advanced MS-DOS Programming
expanded)
05H 2 source memory handle
07H 2 source memory offset
09H 2 source memory segment or physical page
number
0BH 1 destination memory type (0 = conventional,
1 = expanded)
0CH 2 destination memory handle
0EH 2 destination memory offset
10H 2 destination memory segment or physical page
number
────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 57H (87) Subfunction 01H
Exchange memory regions
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 57H
AL = 01H
DS:SI = segment:offset of buffer (see Notes)
Returns:
If function successful
AH = 00H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 754/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
AH = error code
Notes:
■ The format of the buffer controlling the exchange operation is the same
as for Int 67H Function 57H Subfunction 00H.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 58H (88) Subfunction 00H
Get addresses of mappable pages
────────────────────────────────────────────────────────────────────────────
Returns the segment base address and physical page number for each
mappable page in the system.
Call with:
AH = 58H
AL = 00H
ES:DI = segment:offset of buffer (see Notes)
Returns:
If function successful
AH = 00H
CX = number of entries in mappable physical page array
If function unsuccessful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 755/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = error code
Notes:
■ The size of the buffer required can be calculated with the information
returned by Int 67H Function 58H Subfunction 01H.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 58H (88) Subfunction 01H
Get number of mappable pages
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 58H
AL = 01H
Returns:
If function successful
AH = 00H
CX = number of mappable physical pages
If function unsuccessful
AH = error code
Note:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 756/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 59H (89) Subfunction 00H
Get hardware configuration
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 59H
AL = 00H
ES:DI = segment:offset of buffer (see Notes)
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Notes:
■ Upon return from the function, the buffer has been filled in with
hardware configuration information in the following format:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 757/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ The size returned for the mapping-context save area is the same as the
size returned by Int 67H Function 4EH Subfunction 03H.
■ This function is intended for use by operating systems only and can be
disabled by the operating system at any time.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 59H (89) Subfunction 01H
Get number of raw pages
────────────────────────────────────────────────────────────────────────────
Obtains the total number of raw expanded memory pages present in the
system and the number of raw pages that are not already allocated. Raw
memory pages may have a size other than 16 KB.
Call with:
AH = 59H
AL = 01H
Returns:
If function successful
AH = 00H
BX = unallocated raw pages
DX = total raw pages
If function unsuccessful
AH = error code
Note:
■ If the Expanded Memory Manager supports only pages of standard size, the
values returned by this function are the same as those returned by Int
67H Function 42H.
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 758/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 5AH (90) Subfunction 00H
Allocate handle and standard pages
────────────────────────────────────────────────────────────────────────────
Allocates an EMM handle and associates standard (16 KB) expanded memory
pages with that handle.
Call with:
AH = 5AH
AL = 00H
BX = number of standard pages to allocate
Returns:
If function successful
AH = 00H
DX = EMM handle
If function unsuccessful
AH = error code
Note:
■ Unlike Int 67H Function 43H, allocating zero pages with this function
is not an error.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 5AH (90) Subfunction 01H
Allocate handle and raw pages
────────────────────────────────────────────────────────────────────────────
Allocates a raw EMM handle and associates raw expanded memory pages with
that handle.
Call with:
AH = 5AH
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 759/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AL = 01H
BX = number of raw pages to allocate
Returns:
If function successful
AH = 00H
DX = handle for raw EMM pages
If function unsuccessful
AH = error code
Notes:
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 5BH (91) Subfunction 00H
Get alternate map registers
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 5BH
AL = 00H
Returns:
AH = 00H
BL = current active alternate map register set
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 760/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 00H
BL = 00H
ES:DI = segment:offset of alternate map register save area
(if BL = 0)
If function unsuccessful
AH = error code
Notes:
■ The address of the save area must have been specified in a previous call
to Int 67H Function 5BH Subfunction 01H, and the save area must have
been initialized by a previous call to Int 67H Function 4EH Subfunction
00H. If there was no previous call to Int 67H Function 5BH Subfunction
01H, the address returned is zero, and the registers are not saved.
■ This function is intended for use by operating systems only and can be
disabled by the operating system at any time.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 5BH (91) Subfunction 01H
Set alternate map registers
────────────────────────────────────────────────────────────────────────────
Selects an alternate map register set or (if alternate sets are not
supported) restores the mapping context from the specified buffer.
Call with:
AH = 5BH
AL = 01H
BL = alternate register set number or 00H
ES:DI = segment:offset of map register context restore area
(if BL = 0)
Returns:
If function successful
AH = 00H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 761/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
AH = error code
Notes:
■ The save area must have been initialized by a previous call to Int 67H
Function 4EH Subfunction 00H.
■ This function is intended for use by operating systems only and can be
disabled by the operating system at any time.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 5BH (91) Subfunction 02H
Get size of alternate map register save area
────────────────────────────────────────────────────────────────────────────
Returns the amount of storage needed by Int 67H Function 5BH Subfunctions
00H and 01H.
Call with:
AH = 5BH
AL = 02H
Returns:
If function successful
AH = 00H
DX = size of buffer (bytes)
If function unsuccessful
AH = error code
Note:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 762/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ This function is intended for use by operating systems only and can be
disabled by the operating system at any time.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 5BH (91) Subfunction 03H
Allocate alternate map register set
────────────────────────────────────────────────────────────────────────────
Allocates an alternate map register set for use with Int 67H Function 5BH
Subfunctions 00H and 01H. The contents of the currently active map
registers are copied into the newly allocated alternate map registers in
order to provide an initial context when they are selected.
Call with:
AH = 5BH
AL = 03H
Returns:
If function successful
AH = 00H
BL = alternate map register set number or zero, if no alternate
sets are available
If function unsuccessful
AH = error code
Note:
■ This function is intended for use by operating systems only and can be
disabled by the operating system at any time.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 5BH (91) Subfunction 04H
Deallocate alternate map register set
────────────────────────────────────────────────────────────────────────────
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 763/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Releases an alternate map register set that was previously allocated with
Int 67H Function 5BH Subfunction 03H.
Call with:
AH = 5BH
AL = 04H
BL = alternate register set number
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Notes:
■ This function is intended for use by operating systems only and can be
disabled by the operating system at any time.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 5BH (91) Subfunction 05H
Allocate DMA register set
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 5BH
AL = 05H
Returns:
If function successful
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 764/813
10/16/2018 PCjs: Advanced MS-DOS Programming
AH = 00H
BL = DMA register set number (0 = none available)
If function unsuccessful
AH = error code
Note:
■ This function is intended for use by operating systems only and can be
disabled by the operating system at any time.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 5BH (91) Subfunction 06H
Enable DMA on alternate map register set
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 5BH
AL = 06H
BL = alternate map register set
DL = DMA channel number
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 765/813
10/16/2018 PCjs: Advanced MS-DOS Programming
■ This function is intended for use by operating systems only and can be
disabled by the operating system at any time.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 5BH (91) Subfunction 07H
Disable DMA on alternate map register set
────────────────────────────────────────────────────────────────────────────
Disables DMA accesses for all DMA channels associated with a specific
alternate map register set.
Call with:
AH = 5BH
AL = 07H
BL = alternate register set number
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Note:
■ This function is intended for use by operating systems only and can be
disabled by the operating system at any time.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 5BH (91) Subfunction 08H
Deallocate DMA register set
────────────────────────────────────────────────────────────────────────────
Deallocates a DMA register set that was previously allocated with Int 67H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 766/813
10/16/2018 PCjs: Advanced MS-DOS Programming
Call with:
AH = 5BH
AL = 08H
BL = DMA register set number
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Note:
■ This function is intended for use by operating systems only and can be
disabled by the operating system at any time.
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 5CH (92)
Prepare Expanded Memory Manager for warm boot
────────────────────────────────────────────────────────────────────────────
Prepares the expanded memory hardware for an impending warm boot. This
function affects the current mapping context, the alternate register set
in use, and any other expanded memory hardware dependencies that would
ordinarily be initialized at system boot time.
Call with:
AH = 5CH
Returns:
If function successful
AH = 00H
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 767/813
10/16/2018 PCjs: Advanced MS-DOS Programming
If function unsuccessful
AH = error code
Note:
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 5DH (93) Subfunction 00H
Enable EMM operating-system functions
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 5DH
AL = 00H
BX:CX = access key (if not first call to function)
Returns:
If function successful
AH = 00H
BX:CX = access key (if first call to function)
If function unsuccessful
AH = error code
Notes:
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 768/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 5DH (93) Subfunction 01H
Disable EMM operating-system functions
────────────────────────────────────────────────────────────────────────────
Call with:
AH = 5DH
AL = 01H
BX:CX = access key (if not first call to function)
Returns:
If function successful
AH = 00H
BX:CX = access key (if first call to function)
If function unsuccessful
AH = error code
Notes:
────────────────────────────────────────────────────────────────────────────
Int 67H [EMS 4.0]
Function 5DH (93) Subfunction 02H
Release access key
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 769/813
10/16/2018 PCjs: Advanced MS-DOS Programming
────────────────────────────────────────────────────────────────────────────
Releases the access key obtained by a previous call to Int 67H Function
5DH Subfunction 00H or 01H.
Call with:
AH = 5DH
AL = 02H
BX:CX = access key
Returns:
If function successful
AH = 00H
If function unsuccessful
AH = error code
Notes:
■ This function is intended for use by operating systems only and can be
disabled by the operating system at any time.
────────────────────────────────────────────────────────────────────────────
Index
Special Characters
| 298-99
. 187
.. 187-88
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 770/813
10/16/2018 PCjs: Advanced MS-DOS Programming
; 60
< 298-99
> 298-99
>> 298-99
@ 60
A
Absolute disk read 482-84
Absolute disk write 484-85
adapters, video display 86-87
alarm
reset 592
set 591-92
align type 38
Allocate alternate map register set (EMS) 641
Allocate DMA register set (EMS) 642
Allocate handle and pages (EMS) 617-18
Allocate handle and raw pages (EMS) 639
Allocate handle and standard pages (EMS) 638-39
Allocate memory block 438-39
ANSI.SYS device driver, screen control 91
escape sequences used with 92-93
APPEND 490-91
application program interface (API) 320
application programs. See MS-DOS application programs, porting to OS/2;
MS-DOS application programs, structure of; MS-DOS application programs,
writing compatible
arena entries 196
arena headers 196, 201
diagram example 202
ASCII escape code 92-93
ASCII mode 69
character-device drivers in 261-62
ASCII text files 56
ASCIIZ strings 24, 139, 168
.ASM files 45. See also assembly-language programs
assembly-language programs 37-42
to access file allocation table 191
BREAK.ASM 75-78
CLEAN.ASM 304-9
DRIVER.ASM 283-91
DUMP.ASM 152-61
HELLO.COM example 27-30, 33-36
program modules 37
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 771/813
10/16/2018 PCjs: Advanced MS-DOS Programming
B
background, set 508-9
BACKUP command 15
.BAT (batch) files 15
Batch files 15
binary mode 69
character-device drivers in 261-62
output 93-94
BIOS module 12-13, 17
get address of extended, 574
BIOS parameter block (BPB) 181, 189
build 272
structure 269
bit planes 101
blink/intensity bit, toggle 513
block-device drivers 260, 262
check for remoteness 423-24
check removability of 422-23
generic I/O control of 429-32
read control data from 418-19
write control data to 419-20
Boot disk device (block device) 12
boot drive, get 392-93
boot sector, disk 179-82
map of 180
partial disassembly of 182
partial hex dump 181
bootstrap routine 16, 17
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 772/813
10/16/2018 PCjs: Advanced MS-DOS Programming
border
get color 514
get palette and 514
set 508-9
set color 512
BREAK.ASM program 75-78
break flag, get or set 392-93
Buffered keyboard input 351-52
Build BIOS Parameter Block (function 02H) 272
C
CALL instructions 41
Cancel device redirection 467-68
cassette motor
read 561
turn off 560-61
turn on 560
write 562
.C files 45. See also C language
Change sharing retry count 425-26
character blocks, set specifier 520
character-device drivers 260, 261-62
ASCII vs binary mode 261-62
generic I/O control 426-29
read control data from 415-16
write control data to 416-17
character input/output. See also keyboard input; mouse, input; pointing
device, input; printer output; serial port
Int 21H 44H IOCTL (I/O control) 411-43
Int 21H functions, summary 337-38 (table)
processing typical I/O request 281-82
Character input with echo 343
Character input without echo 349-50
Character output 344
CHDIR (CD) command 167
Check if block device is remote 423-24
Check if block device is removable 422-23
Check if handle is remote 424-25
Check input status 353, 420-21
Check output status 421-22
child programs 218
CHKDSK command 15, 174, 222
C language
CLEAN.C 309-11
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 773/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 774/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 775/813
10/16/2018 PCjs: Advanced MS-DOS Programming
cooked mode 69
C Optimizing Compiler 44, 48-50
environmental variables 48
version 5.1 switches 49-50
COPY command 14, 58
Country information
get extended 470-74
get or set 395-98
CP/M operating system 4, 5
FCB compatibility with 129, 130-31
program segment prefix compatibility with 24, 25
Create directory 398-99
Create file 364-65, 401-2
Create new file 458-59
Create new PSP 378-79
Create temporary file 457-58
CREF utility 44, 56-58
cross-reference listing for HELLO.REF 57
.CRF files 45, 56
Critical-error handler address 481-82
critical-error handlers 24, 145, 147-51
address 481-82
skeleton program example 150-51
stack at entry to 148, 149
cross-reference listing. See CREF utility
Ctrl-Break and Ctrl-C handlers 72-80
compatibility issues 317
Ctrl-C handler address 480-81
high-level languages and 75-80
cursor
addressing 97
enable/disable emulation 528
get position 502-3
read character and attribute at 506
set position 501-2
set type 501
write character and attribute at 506-7
write character at 507-8
D
data segment 38
data segment (DS) register 31, 35
Date and time device (CLOCK$) 12
day count
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 776/813
10/16/2018 PCjs: Advanced MS-DOS Programming
get 592-93
set 593
Deallocate alternate map register set (EMS) 642
Deallocate DMA register set (EMS) 644
.DEF files 45
Delay 568-69
DEL(ETE) command 14
Delete directory 399
Delete file 361-62, 40, sug>8
dependency statements 61
descriptors, memory segment 321
device
cancel redirection 467-68
close 565
get device information 412-13
open 564-65
post 572-73
read file or 405-6
redirect 466-67
set device information 414-15
wait 571
write file or 406-7
Device Close (command code function 0EH) 277-78
Device close (MS-DOS function) 565
DEVICE commands 12
device drivers, installable 12-13, 259-96
CLOCK driver 282
command-code routines 267-81
debugging 295-96
chain before/after driver installation 294
chain listing 295
device attribute word 264
error codes 267
MS-DOS type 260-63
processing of typical input/output requests 281-82
structure of MS-DOS 263-67
device header 263-64
interrupt routine 26-67
strategy routine 265
writing and installing 282-95
assembly 283-92
installation 293-95
linking 293
device drivers, resident 12-13
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 777/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 778/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 779/813
10/16/2018 PCjs: Advanced MS-DOS Programming
E
echo
character input with 343
character input without 349-50
unfiltered character input without 348-49
EMS. See Expanded Memory Specification (EMS)
Enable/disable cursor emulation 528
Enable/disable default palette loading 526-27
Enable/disable gray-scale summing 527
Enable/disable pointing device 574-75
Enable/disable screen refresh 529
Enable/disable video 527
Enable DMA on alternate map register set (EMS) 643
Enable EMM operating system functions (EMS) 645
Enable mouse driver 609
encapsulation of subroutines 323, 324-25
end of interrupt (EOI) 250
ENDP command 35, 41
ENDS command 29, 38
END statement 30-31, 36, 41
Enhanced Graphics Adapter (EGA) 86, 97, 98, 102
Enter protected mode 570-71
environment block 24, 220, 224-25
dump of a typical 224
three strings contained in 225
EQU statement 33
error codes, device driver 267
error codes, MS-DOS 145-51
critical 145, 147-51
expanded memory 207-9
error information, get/set 453-56
escape sequences, ANSI 92-93
ESDI Fixed Disk Drive Adapter (EP>
format drive 555
format periodic interrupt 562-63
Event wait 566-67
Exchange memory regions (EMS) 635-36
EXE2BIN utility 44, 55-56
EXEC function 15, 217-42. See also Int 21H Function 4BH
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 780/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 781/813
10/16/2018 PCjs: Advanced MS-DOS Programming
FAR attribute 35
vs NEAR 29
faults (internal hardware interrupts) 246, 321
file(s)
area, in disks 186-88
close 357-58, 404
commit 476-77
create 364-65, 401-2
create new 458-59
create temporary 457-58
delete 361-62, 407-8
extended open 478-80
find first 358-59, 445-46
find next 360-61, 446-47
get file size 375-76
get/set date and time 450-51
lock/unlock file region 460-61
logical drive 166
moving 123
name and location 166
open 356-57, 402-4
read 405-6
rename 366, 449-50
types 45
write 406-7
file-access skeleton program
using FCB functions 134, 135-37
using handle functions 141, 142-43
file allocation table (FAT) 16, 182-84
assembly program to access 191
contents 183
interpreting 188-92
media descriptor bytes 183
file attributes, get or set 410-11
file control blocks (FCBs) 25, 128
default 130, 221
directory searching with 169, 170-71
extended 131, 133-34, 175
file management with FCB functions 129-39
advantages/disadvantages 138-39
file-access skeleton program 134-38
functions listed 132
vs handle functions 128
normal 129, 133-34
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 782/813
10/16/2018 PCjs: Advanced MS-DOS Programming
G
Generic I/O control for block devices 429-32
Generic I/O control for character devices 426-29
Generic IOCTL (function 13H) 279-80
Get addresses of mappable pages (EMS) 636
Get address of alternate mouse event handler 606
Get address of extended BIOS data area 574
Get all handle names (EMS) 631
Get alternate map registers (EMS) 639-40
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 783/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 784/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 785/813
10/16/2018 PCjs: Advanced MS-DOS Programming
H
handle functions
check if handle is remote 424-25
directory searching 169-70, 172-73
DUMP.ASM program 151, 152-62
DUMP.C program 151, 161-63
duplicate handle 435
file/record management with 139-44
advantages/disadvantages 144
vs FCB functions 128
file access skeleton program 141-43
functions listed 140-41
typical operation 139
keyboard input 62, 67-69
redirect handle 436-37
set handle count 475-76
use for compatible MS-DOS applications 316
volume-label search using176
hardware-compatible applications 314-15, 317-18
header(EP>
device 263, 264, 269
.EXE program files 30
Hercules Graphics Card 87, 97, 98
HELLO.COM program 27, 28-29, 30
hex dump of 33
map produced by Object Linker during generation of 51
HELLO.EXE program 33, 34-35, 36
HELLO.REF program, cross-reference listing 57
.H files 45
Hide mouse pointer 595
I
IBMBIO.COM file 16
disk location 189-92
IBM Corporation, role in MS-DOS development 4-5
IBMDOS.COM file 13, 16
IBM PC 64
PC/AT 64
PS/2 64
regen buffers in memory for various adapters 87
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 786/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 787/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 788/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 789/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 790/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 791/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 792/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 793/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 794/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 795/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 796/813
10/16/2018 PCjs: Advanced MS-DOS Programming
J
Japanese character set 6
joystick, read 567
K
kernel. See DOS kernel
keyboard
get enhanced flags 586-87
get enhanced status 586
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 797/813
10/16/2018 PCjs: Advanced MS-DOS Programming
L
.LIB files 44, 45, 58. See also Library Manager (LIB)
Library Manager (LIB) 44, 58-60
operations prefix characters 58
table-of-contents listing for SLIBC.LIB 59
light pen
get position 503
turn off emulation 601
turn on emulation 601
line printer (PRN) 12, 106, 298
LINK. See Object Linker (LINK)
Load ROM 8-by-8 font 519
Load ROM 8-by-14 font 518-19
Load ROM 8-by-16 font 520-21
Load user font 518
Lock or unlock file region 460-61
Lotus/Intel/Microsoft Expanded Memory (LIM EMS). See Expanded Memory
Specification (EMS)
LPT1, LPT2, LPT3 devices 106, 298
.LST files 45
M
machine name, get 461-62
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 798/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 799/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 800/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 801/813
10/16/2018 PCjs: Advanced MS-DOS Programming
N
NAME statement 27, 33
NEAR attribute 27
vs FAR 29
NEAR RETURN 27
network functions, Int 21H functions summary 339
Nondestructive Read (function 05H) 274
non-disk-related errors 147, 148 (table)
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 802/813
10/16/2018 PCjs: Advanced MS-DOS Programming
P
PAGE command 27, 33
page frame 203
palette
enable/disable default 526-27
get border and 514
get register 513
set 508-9
set border and 512-13
set register 511-12
parallel ports 106
parameter block, requesting EXEC function 220-21
parent programs 218
Park heads 554-55
Parse filename 382-84
partitions, fixed-disk 192-94
Paterson, Tim 4
path 166
PC-DOS
version 1.0 4
version 1.1 5
version 2.0 5-6
version 3.0 193-94
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 803/813
10/16/2018 PCjs: Advanced MS-DOS Programming
piping parameters 24
pixel 101
formula to calculate bit position for 102-3
read graphics 510
set mickeys to pixel ratio 601-2
write graphics 509
pointing device
enable/disable 574-75
get device type 577
get scaling or get status 578-79
initialize interface 577-78
input 80-83
reset 575
set handler address 579-80
set resolution 576-77
set sample rate 576
POP instruction 35
portability. See compatibility and portability
POST (power-on self-test)
read error log 563
write error log 563-64
Prepare expanded memory manager for warm boot (EMS) 644-45
Presentation Manager, OS/2 318
printer 106, 107-9. See also line printer (PRN); standard printer (stdprn)
get setup strings 463-64
get status 588
initialize port 587
write character to 587
printer output 106, 107-9, 346-47. See also TALK.ASM program
printer setup string
get 463-64
set 462-63
printscreen, select alternate 526
Print spooler 488-89
PRN device 12, 106, 298-99
PROC command 29, 35, 41
procedure, declaring beginning/end of 29
process management
for compatibility in MS-DOS applications 317
Int 21H functions summary 339
terminate process 566
Process termination 566
Programmable Interrupt Controller (PIC) 247
Programmable option select 580-81
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 804/813
10/16/2018 PCjs: Advanced MS-DOS Programming
R
Random block read 379-80
Random block write 381-82
Random read 372-73
Random write 373-75
rationalizing code 322-23
raw mode 69
Read (function 04H) 273
Read cassette 561
Read character and attribute at cursor 506
Read character from communications port 558
Read character from enhanced keyboard 585
Read character from keyboard 581
Read control data from block-device driver 418-19
Read control data from character device driver 415-16
Read file or device 405-6
Read graphics pixel 510
Read joystick 567
Read mouse motion counters 599-600
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 805/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 806/813
10/16/2018 PCjs: Advanced MS-DOS Programming
S
Save and restore page map (EMS) 624-25
Save mouse driver state 604
Save or restore video state 534-35
Save page map (EMS) 620, 623
Save partial page map (EMS) 625-26
scan lines, set 526
screen control with MS-DOS functions 91-93
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 807/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 808/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 809/813
10/16/2018 PCjs: Advanced MS-DOS Programming
T
TALK.ASM program 113-26
teletype mode
write character in 510-11
write string in 529-30
terminal-emulator program. See TALK.ASM program
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 810/813
10/16/2018 PCjs: Advanced MS-DOS Programming
U
Unfiltered character input without echo 348-49
UNIX/XENIX operating system 66, 128, 139
user font
load 518
set Int 1FH pointer 521
set Int 43H for 522
V
verify flag, get 448
Verify sector 540
video display 85-103
adapters 86-87
enable/disable 527
get functionality/state information 531-34
get or set combination code 530-31
memory-mapped techniques 96-103
graphics mode 101-3
text mode 96-101
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 811/813
10/16/2018 PCjs: Advanced MS-DOS Programming
W
watchdog time-out, set 580
window
initialize or scroll down 505-6
initialize or scroll up 505
Windows 7, 318
Write (function 08H) 275
Write cassette 562
Write character and attribute at cursor 506-7
Write character at cursor 507-8
Write character in teletype mode 510-11
Write character to communications port 557
Write character to printer 587
Write control data to block-device driver 419-20
Write control data to character-device driver 416-17
Write File or Device 406-7
Write graphics pixel 509
Write POST error log 563-64
Write screen in teletype mode 529-30
Write sector 539
Write sector buffer 549
Write sector long 546-47
Write with Verify (function 09H) 276
Z
ZERODIV.ASM program 254, 255-58
Zilog Z-80 microprocessor 4
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 812/813
10/16/2018 PCjs: Advanced MS-DOS Programming
https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/advdos/ 813/813