Input/Output, or I/O as it is more commonly called, is an extremely important part of any computer. Without it, the various parts of the computer wouldn't be able to talk to each other. Such communication isn't limited to disk drives and printers, either. The keyboard, television set, and screen editor must all be able to tell the computer what's going on, and all of this is I/O's responsibility. Unfortunately, because I/O has so much to do, it can be a little complicated. Luckily, complicated doesn't mean difficult in this case, so despite all the memory locations that deal with I/O, the basic concept is relatively simple.
There are three main routines that take care of I/O for a given device ("device" is just a fancy word for the keyboard, printer, or whatever it is we want to talk to). They are shown in Figure 59a.
|Central Input/Output Routine||(CIO)|
|Serial Input/Output Routine||(SIO)|
FIGURE 59a. I/O devices
To help these three routines talk to each other (I told you this got complicated), there are also four "control blocks" (Figure 59b).
|Input/Output Control Block||(IOCB)|
|Zero-page I/O Control Block||(ZIOCB)|
|Device Control Block||(DCB)|
|Command Frame Buffer||(CFB)|
FIGURE 59b. I/O control blocks
Now that we've got the names straight, let's look at what each does, where it can be found, and how everything is tied together.
Actually, it should be IOCBs, since there are eight of them. The IOCBs are found starting at location 832. Each one is made up of 16 bytes that are used to describe what kind of I/O we want to do. Although we can have information in all eight IOCBs at once, we can still only do one I/O operation at a time. IOCBs usually get their information from the user.
There is only one ZIOCB, starting at location 32. It is set up exactly like an IOCB, and as a matter of fact contains the information for the IOCB that is currently being used. Why is it necessary? Because page zero is faster than regular memory, and we want to do I/O as quickly as possible. Since only one IOCB can be used at any one time, it would be a waste of precious page zero memory to put all eight IOCBs in page zero. CIO transfers the information from the IOCB to the ZIOCB.
The CIO routine can be found in the OS ROM, starting at location 58534. CIO takes the information in the IOCB that is currently being used and stores it in the ZIOCB. It then uses that information along with HATABS (794) to figure out which device handler is needed and then passes control to the device handler.
Again, it should be device handlers, since there is one for each device. The device handlers can be anywhere in memory, with HATABS containing a list of where to find them. A device handler does one of two things. If the device in question is the keyboard, the screen, or the screen editor, then the device handler takes care of the I/O itself. If it's something like the disk drive or printer that's plugged into the computer, then the device handler sets up the DCB with the information it needs.
The exception to this is the disk interface routine, which is also known as the internal disk handler. If you're not using DOS, then you have to set up the DCB yourself in order to talk to the disk drive. If you are using DOS, then a regular disk handler has been loaded into the computer and you can communicate with the disk drive through the IOCBs.
The DCB (there is only one) is found starting at location 768. It is 12 bytes long and is sort of like the IOCBs in the respect that it holds information that describes what kind of I/O we want to do. This time, however, the information is for SIO instead of CIO.
The SIO routines, like the CIO ones, are in the OS ROM, starting at location 59716. SIO takes the information in the DCB and uses it to talk to devices that use serial I/O (printer, disk drive, cassette player, etc.). It also sets up and uses the CFB.
Last of all, we have the CFB. Made up of four bytes starting at location 570, it helps SIO talk to the devices. The CFB is the one part of the I/O system that you should not mess around with yourself.
Let's summarize by looking at the flow of information. The user sets up an IOCB and calls CIO. CIO takes the information in the IOCB, transfers it to the ZIOCB, figures out what device handler is needed, and transfers control to that handler. From there, the handler takes care of internal devices, or sets up the DCB and calls SIO if we need to communicate with a serial (external) device. Finally, SIO takes the information in the DCB, sets up the CFB, and does the I/O. After the I/O has been completed, whether by the handler or SIO, control is transferred back to the user. As a programmer, you can skip any of these steps with the exception of SIO. You should not skip all the way to the CFB.
BASIC programmers may want to look at the excellent article in issue 13 of Analog Computing for ways to go straight to CIO.
Return to Table of Contents | Previous Chapter | Next Chapter