4.2.1 Input and Output Modes

Input/output (I/O) modes determine how character devices process input and output. MS-DOS has two I/O modes: ASCII and binary. (These are sometimes called “cooked” and “raw” modes, respectively.)

The chief difference between these two modes is the way in which MS-DOS processes control characters. In ASCII mode, MS-DOS checks for control characters as it processes input or output for a device. If it encounters a control character, it removes the character from the input and carries out its corresponding action, described in the following table:

Control character Action in ASCII mode

CTRL+C Passes control to the CTRL+C exception handler. Subsequent actions depend on the current handler; the default handler terminates the program.
CTRL+P Copies all subsequent input characters, up to the next CTRL+P, to the printer device.
CTRL+S Suspends further output to the device. The next input character restores output.
CTRL+Z Marks the end of the file. Subsequent calls to Read File or Device (Interrupt 21h Function 3Fh) return zero bytes.

In binary mode, no action is carried out and control characters remain as input until they are read by a program.

ASCII mode also may affect the way characters are displayed. For example, a screen device expands tab characters to space characters in ASCII mode, but not in binary mode.

By default, the MS-DOS I/O mode is ASCII. A program can determine the current I/O mode for a device by using Get Device Data (Interrupt 21h Function 4400h). This function takes a device handle as a parameter and returns a value indicating the device status. If bit 5 is set, the device is in binary mode. Otherwise, the device is in ASCII mode. Set Device Data (Interrupt 21h Function 4401h) changes the mode for a device.

The I/O mode is a property of the device handle and affects the input and output of only those programs that own the handle.