Every computer has one or more terminals used to communicate with it.
Terminals have a large number of different forms.
The terminal device drivers must hide these differences from the device-independent software.
There are two broad categories: serial interfaced terminals (usually using RS-232) and memory-mapped terminals.
Serial terminals are standalone with a keyboard and display.
They are attached to the computer usually via an RS-232 interface, which needs at least three wires: ground, data in, data out.
Characters to/from the terminal are sent in a serial fashion, e.g 7 bits per character, one start bit and one or more stop bits.
The start/stop bits are used to delimit the characters.
Characters are transmitted asynchronously: that is, the computer has no idea when the next character will arrive.
Common data speeds are (in bits per second): 300, 1200, 2400, 9600 and 19200.
The terminal and the computer use chips called UARTs to do the character-to-serial and serial-to-character conversion.
At 9600 bps, with 7 data bits, one start bit and two stop bits (i.e 10 overall), we get 960 characters per second, or around 1 ms per character.
This is a long time for an OS. Usually the OS asks the UART to return an interrupt after sending/receiving a character.
Some UARTs have small buffers (2,4,16 characters), and are able to send less interrupts to the OS.
Hard-copy terminals just print the characters they receive to paper.
Dumb terminals just pretend they are hard-copy, but without any paper.
Intelligent terminals can move the cursor, change fonts, clear the screen, scroll backwards, bold characters etc.
tty: /T-T-Y/ n. A terminal of the teletype variety, characterized by a noisy mechanical printer, a very limited character set, and poor print quality. Usage: antiquated (like the TTYs themselves).
glass tty: /glas T-T-Y/ n. A terminal that has a display screen but which, because of hardware or software limitations, behaves like a teletype or some other printing terminal, thereby combining the disadvantages of both: like a printing terminal, it can't do fancy display hacks, and like a display terminal, it doesn't produce hard copy. An example is the early `dumb' version of Lear-Siegler ADM 3 (without cursor control).
smart terminal: n. A terminal that has enough computing capability to render graphics or to offload some kind of front-end processing from the computer it talks to. The development of workstations and personal computers has made this term and the product it describes semi-obsolescent, but one may still hear variants of the phrase `act like a smart terminal' used to describe the behavior of workstations or PCs with respect to programs that execute almost entirely out of a remote server's storage, using said devices as displays.
These terminals have their display memory-mapped into the computer. A good example are the video displays on most microcomputers.
With a character-mapped display, writing a character in a memory location causes the character to be displayed.
With a bit-mapped display, every bit in the video memory controls one pixel on the screen. The OS must `paint' the characters on the screen.
In both cases, scrolling involves copying every byte in video memory from one address to another.
The keyboard is completely decoupled from the display. It is usually parallel connected to one memory address, which is where the OS received the characters.
With many keyboards, the actual character is not exchanged. Instead a key code is transmitted, indicating which key was pressed. For example, different key codes will be generated for `left shift', `right shift', `caps lock', `control', `A' etc.
The OS must convert these key codes into the appropriate characters.
The device driver must present the device-independent software with a flow of characters in/out.
The terminal independent software must present an abstract device to the user, one where characters can be read/written.
Input: Many programs just want lines of characters to arrive. They don't want to be bothered with line editing.
Some programs, however, want to receive one character at a time, including the user's mistyped characters.
The latter mode is known as raw mode, as the characters are passed raw. The former is known as cooked mode, and the terminal independent software performs the editing.
Thus, it must buffer a partial line while the user is editing it. In fact, the software must buffer characters until the programs request the characters.
There are two buffering methods: a central buffer pool, or a buffer per input terminal. The first is more complicated, but saves a lot of memory (especially if there are 100 terminals connected), and can also prevent individual buffers from overflowing.
In cooked mode, the user needs several characters in order to perform the line editing. These can usually be chosen by the user, but the standard Unix ones are:
[tabbing382]
Most users expect to see the characters they type on the screen. However, in some situations (e.g changing passwords), this needs to be disabled.
The terminal independent software thus must also perform echoing, and must provide an interface so that programs can turn it on/off.
Echoing present problems:
How to erase the last character when the user types backspace? What about lines longer than the screen width? Does the terminal understand about tabs on output? Conversion of OS-specific end of line to that used by the terminal. Unix uses LF, MS-DOS uses CR-LF, Macs use LF-CR.
Output is simpler than input. However, serial terminal present problems that memory-mapped ones do not.
With serial output around 1ms per character, processes can output data faster than can be transmitted. The OS must buffer output or it will be lost.
Memory-mapped terminals are as fast as memory, 1 to 100 microseconds per character.
Another problem is how to output the BELL (^G) character on memory-mapped terminals? The OS should toggle the speaker to simulate the bell.
The output driver may need to keep track of where the cursor is on memory-mapped displays, It also must perform scrolling.
To take advantage of the capabilities of smart serial terminals, the software needs to know the special command sequences to user them. These capabilities also need to be simulated on memory-mapped displays by the output software.
The sorts of capabilities are:
Move cursor up, down, left, right. Move cursor to (x,y). Insert line or character at cursor. Delete line or character at cursor. Scroll screen up/down n lines. Clear entire screen. Clear from cursor to end of line/screen. Go to bold/blinking/reverse/normal mode.