The Programmer's Guide to TRSDOS Version 6 - Tim Mann's Home ...
The Programmer's Guide to TRSDOS Version 6 - Tim Mann's Home ...
The Programmer's Guide to TRSDOS Version 6 - Tim Mann's Home ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
3. Device Input/Output Interfacing<br />
3.1 Device I/O In General<br />
Devices interface <strong>to</strong> the operating system through driver modules. Character-oriented<br />
devices (keyboards, video display tubes, printers, and serial terminals, <strong>to</strong> name but a<br />
few), have their drivers connected <strong>to</strong> the DOS by Device Control Block (DCB) tables [this<br />
is in contrast <strong>to</strong> disk-type devices which have drivers connected <strong>to</strong> the system through<br />
Drive Control Tables (DCT)]. <strong>The</strong> purpose of the DCB is <strong>to</strong> associate a device name with<br />
the device hardware itself. A device specification (abbreviated as "devspec") is formed<br />
by prefixing an asterisk <strong>to</strong> the device name. Programs may then reference the device via<br />
the device specification in order <strong>to</strong> identify a particular device for character I/O.<br />
<strong>The</strong>re are three input/output functions that are associated with all character-oriented<br />
devices. <strong>The</strong> "GET" function obtains a character from the device. <strong>The</strong> "PUT" function sends<br />
a character <strong>to</strong> the device. <strong>The</strong> "CTL" function provides a means of communicating with the<br />
device driver and generally does not invoke input/output with the physical device itself.<br />
It is up <strong>to</strong> the device driver <strong>to</strong> ensure that the device is currently able <strong>to</strong> take the<br />
character in the case of PUT as well as detect the availability of a character in the<br />
case of GET and return the proper condition.<br />
Disk files may also be interfaced via character I/O as well as record I/O [file access<br />
via record I/O is discussed in chapter 6, DISK FILE ACCESS AND CONTROL]. A disk file's<br />
actual physical s<strong>to</strong>rage location on a disk drive is transparent <strong>to</strong> the user by<br />
referencing the file with its associated name (more properly termed its file<br />
specification or "filespec"). <strong>The</strong> operating system permits filespecs and devspecs <strong>to</strong> be<br />
used equivalently in most cases. Character I/O is thus independent of a device or file.<br />
<strong>The</strong> DOS permits the redirection of character I/O at the command level. Because of this,<br />
applications must expect character I/O <strong>to</strong> be associated with a disk file as well as a<br />
standard character-oriented device. <strong>The</strong> DOS provides a uniform pro<strong>to</strong>col for I/O<br />
handshaking regardless of character device.<br />
<strong>The</strong>re are three major operations associated with devices. One of these is "routing" which<br />
implements the support of I/O redirection. Another is linking which is used <strong>to</strong> connect<br />
two or more devices <strong>to</strong>gether. <strong>The</strong> third operation associated with devices uses filters <strong>to</strong><br />
achieve filtering. Filters are program modules that can be logically placed between the<br />
Device Control Block associated with a device and the device driver connected <strong>to</strong> the DCB.<br />
This operation will form what is called a "device chain". More than one filter module may<br />
be placed in the DCB-<strong>to</strong>-driver chain. <strong>The</strong>se filters bear a very close resemblance <strong>to</strong><br />
device drivers. In fact, they also utilize the Device Control Block tables <strong>to</strong> associate<br />
their memory s<strong>to</strong>rage location with the name assigned <strong>to</strong> them when they are installed.<br />
This section will discuss the activities that take place between a Device Control Block<br />
and a device so that you will better understand the concepts of character I/O. In this<br />
manner, you will have no problem in writing device filters and drivers - at least as far<br />
as DOS interfacing goes.<br />
3.2 <strong>The</strong> Device Control Block<br />
<strong>The</strong> Device Control Block (DCB) is used <strong>to</strong> interface with various logical devices such as<br />
the keyboard, the video display, a printer, a communications line, or other device<br />
defined by your hardware implementation. <strong>The</strong> DCB is composed of eight bytes divided in<strong>to</strong><br />
four fields: TYPE, VECTOR, SYSDATA, and NAME. Figure 3-1 illustrates the DCB. <strong>The</strong> TYPE<br />
field is a one-byte field that describes the capabilities and current state of the DCB<br />
(state indicative of routed, linked, filtered, etc.). <strong>The</strong> VECTOR field is a two-byte<br />
field that initially is a pointer <strong>to</strong> the entry-point of the driver or filter module<br />
associated with the DCB. <strong>The</strong> SYSDATA field is a three-byte field that is used by the<br />
3-1