INPUT, OUTPUT, and Other Confusing Things
In this issue Perceptions will take up I/O (Input/Output) ports. The fundamental issues are discussed, and a sample method for their application to the TS1000/ZX81 is described.
Introduction
I sit in front of a video terminal. A cursor flashes in a corner of the screen. I press the key labeled ENTER on my computer. From behind, I hear a ‘ka-chunk’ – the familiar taka-taka-taka of my main printer.
Soon a message appears on the screen. It reads: ‘PRINTING COMPLETE. O.K. TO CONTINUE?” I activate the tired muscles in my arm, reach to the keyboard and, extending my index finger, press the Y key. The red LED on one of my disk drives begins to flash!once, twice, and again. Soon they glow constantly.
Then, to my great surprise, the speech section of my computer wakes from its day-old sleep, and begins to recite the alphabet. Next each light in the room begins to cycle: first off, then on, then off, and then back to its original state. The television in the next room goes on, and I hear gunshots from the western movie. I decide to sit back, smoke a cigarette, and go quietly out of my mind contemplating the reason for my computer’s apparent loss of its mental faculties.
Contemplation, as usual, leads me nowhere. Pressing, repeatedly, the RESET button seems to have little or no effect on its trip into never-never land. I pull the plug.
The above scenario may sound like an excerpt from HAL’s adventures in 2001, but it is not. It is a scene that occurred in my study a few nights ago. Such an occurrence is, admittedly, a rare occurrence in my house. It is, however, more likely to occur in my house than in the average house in, say, a less technically-oriented environment. It usually comes about during the testing of some new feature that I am adding to my computer. Often an I/O port. I scramble a few wires, plug in a board upside—down, or backwards, —whatever.
This time, however, the event was unprecedented: I had a witness. Someone would, finally, be there to back me up when I told my friends what had happened.
My friend (or should I say savior?), a novice in the computer field, was amazed. “What is happening?” and “Can I help?” seemed to the most frequent comments. Once I had cleared up the mystery in my head (a solder bridge), we went to the local coffehouse and discussed music, good coffees, and the events of the evening.
Not surprisingly, the evening’s events dominated the conversation. What had happened, he wanted to know. What ensued was an explanation of I/O. Input/Output: those operations which concern the computer’s communication, and interaction with the outside world. Soon the cafe closed, and we returned home. The discussion continued, and continued, and continued…. Upon reflection the next day, it occurred to me that the material that we discussed would make a good article. What follows is just that: a summary of that discussion.
What Is an I/O Port?
My friend, having heard me use the term dozens of times that night in conversations with myself, asked me: “What is an I/O port?” An I/O port is a channel, through which, a computer “talks” to the outside world. When a computer wants a printer to print a particular character, it sends, via an I/O port, the code that represents the desired character to the printer. The printer then decodes the charater into the proper internal format (i.e., dots), and eventually yields a character on a piece of paper.
More properly, the computer sends the character that it wants printed to the printer via an output port connected to the computer. Hopefully, a sane printer is listening to the output of that output port. The printer will notice that the computer has sent a character to it, and it will read that character through its internal input port.
Noticing the questioning look on my friend’s face, I ordered two more cups of coffee, and dove head on into a detailed description of I/O ports.
Types of Ports
There are two kinds of I/O ports: parallel and serial. Parallel ports are the easiest to understand, so I will tell you about them first.
A parallel port transfers data, usually, eight bits at a time. Eight bits, as you know, comprise a byte—the basic chunk of data in a microcomputer. Larger computers, using parallel ports, may transfer as many as 32 bits in a shot. It depends on how the processor is organized. The Timex/Sinclair 1000 uses an eight-bit microprocessor, the Z80. The Z80 has an eight bit data-bus. A data bus is, conceptually, a series of wires (i.e., eight) that carry around data. The Z80, having eight of these “wires,” will use an eight bit I/O port. I reached for an “engineer’s best friend”—the napkin.
“Let me illustrate,” I said. I drew a box with eight lines coming out of each side. One line extended from the top. This is a simple I/O port. (See Figure 1.)

Eight LEDs (Light Emitting Diodes) are arranged so as to light when their corresponding control lines are activated. To make them all light, the computer must activate all the control lines. It does this by sending an FFh (1111b) to the output port. To turn on LED 2, LED 5, and LED 6, the computer must send a 00110010b.
To send data the computer must place the desired data on its data bus, and activate the STROBE line on the output port. Activation of the strobe line says, in effect, to the output port: “Take what I’m giving you on the data bus. Put it on your output lines, and keep it there—even if I go away. Don’t change it until I tell you to (i.e., activate the STROBE line again).” This effect is known as latching. The device (an integrated circuit, probably) that performs the action of latching is known as a latch. When one piece of data is latched, it stays on the output of the latch—until something new is latched.
Address, Control and Data
When the computer wishes to read data from a keyboard, or read data from a cassette tape recorder, or send characters to a printer, it must know how to tell all those devices (i.e., I/O ports) which one is being talked to. In the case of an average computer, there may be as many as a dozen—or more—output ports. How does it (the computer) know which STROBE line to activate. how does it “activate” them, for that matter?
Let me try to explain by way of an old analogy. Imagine, that the printer to which a character is to be sent lives on a road, He—Mr. Printer, that is—has a mailbox. If he has a mailbox, then he has an address. When Mr. Printer’s friend the computer wants to send a message (output) to Mr. Printer, he gives that message to Mr. Mailman (the Data Bus). Mr. Mailman carries the message to Mr. Printer’s mailbox (Output Port.) Mr. Mailman then puts it into the mailbox, and strobes it (i.e., he raises the “mail-here” flag). Actually, the mailbox combines both the output port of the computer and the input port of the printer.
When Mr. Printer is ready to read his mail, he goes to his mailbox. He removes the message, and reads (processes/prints) it. He also signals to Mr. Computer that he is ready to receive more mail by lowering the “mail-here” flag. This is a common feature of I/O port arrangements. It says to the sending device, that the receiving device is ready to accept more data. When the data is sent to the I/O port, the DATA AVAILABLE flag is set. (This was the “mail-here” flag in the above example.) This interaction between output device, and input device is called handshaking.
Without proper handshaking, at least two fatal occurrences are possible. First is the case where the output device is sending data faster than the input device can read and process it. An extreme example might be the case in which a computer is sending characters at a rate of 150,000 cps (characters per second). An average printer can read characters at a rate of approximately 150 characters per second. Every second, the printer would miss 149,850 characters—clearly an unacceptable number. Handshaking solves this problem. The computer reads the DATA AVAILABLE flag that it set (i.e., turned on). It waits until the printer has reset the line before sending another character.
The other problem arises when the computer is reading data from a device that is presenting data slower than the microcomputer is reading. A keyboard is such a device, and a keyboard is a commonly used device indeed. The keyboard has an output port, in this example. When the user presses the W key, the output latch grabs the code for a W, and holds it on its output.
Meanwhile the keyboard is being read by the computer 50,000 times per second. How many times, in that second, do you think the computer will read the key W. Clearly, the synchronization provided by handshaking is critical.
Returning to the issue at hand, a typical microprocessor, such as the Z80, has an eight bit data bus, a 16 bit address bus, and a collection of control lines. These control lines indicate the conditions of the data bus, and the address bus. They dictate, for example, that the 16 bit number on the address bus is the address of a memory location, and that the data on the data bus should be written into that memory location. They might specify that the address on the address bus is currently specifying a particular input port, and that the designated port should place its data on the data bus for the Z80 to read into one of its internal registers.
The address bus, being 16-bit wide. can specify any of 65536 addresses (65536=2**16). The number 65536 is often referred to as 64K. One “K” is 1024 (2**10). The 64K addressing area (address space) of a computer is usually filed with various items: RAM, ROM, and I/O ports. The Timex/ Sinclair 1000’s memory space is shown in block form in Figure 2.

FFFF
RAM
C000
ROM
A000
ROM
8000
RAM
4000
ROM
2000
ROM
0000
In the next issue, I will continue discussing I/O ports. I will describe a way to open up some of the apparently filled address space of the Timex/Sinclair 1000.
Until next time, same relativistic time period, same non-Euclidian universe.