This procedure transmits to the system console the character which was passed as a parameter.
It illustrates in a small way the basic features of i/o operations on the PDP11 computer.
“SW” is defined on line 0166 as the value “0177570”. This is the kernel address of a read only processor register which stores the setting of the console switch register.
The meaning of the statement is clear: get the contents at location 0177570 and see if they are zero. The problem is to express this in “C”. The code
if (SW == 0)
would not have conveyed this meaning. Clearly “SW” is a pointer value which should be dereferenced. The compiler might have been changed to accept
if (SW- == 0)
but as it stands, this is syntactically incorrect. By inventing a dummy structure, with an element “integ” (see line 0175), the programmer has found a satisfactory solution to his problem.
Several other examples of this programming device will be found in this procedure and elsewhere.
In hardware terms, the system console terminal interface consists of four 16 bit control registers which are given consecutive addresses on the Unibus beginning at kernel address 0177560 (see the declaration for “KL” on line 0165.) For a description of the formats and usage of these registers, see Chapter Twenty-Four of the “PDP11 Peripherals Handbook”.
In software terms, this interface is the unnamed structure which is defined beginning on line 2313, with four elements which name the four control registers. It does not matter that the structure is unnamed because it is not necessary to allocate any instances of it (the one we are interested in is essentially predefined, at the address given by “KL”).
While bit 7 of the transmitter status register (“XST”) is off, keep doing nothing, because the interface is not ready to accept another character.
This is a classic case of “busy waiting” where the processor is allowed to cycle uselessly through a set of instructions until some externally defined event occurs. Such waste of processing power cannot normally be tolerated but this procedure is only used in unusual situations.
The need for this statement is tied up with the statement on line 2405;
Save the current contents of the transmitter status register;
Clear the transmitter status register preparatory to sending the next character:
With bit 7 of the control status register reset, move the next character to be transmitted to the transmitter buffer register. This initiates the next output operation;
A “new line” character needs to be accompanied by a “carriage return” character and this is accomplished by a recursive call on “putchar”.
A couple of extra “delete” characters are thrown in also to allow for any delays in completing the carriage return operation at the terminal;
This call on “putchar” with an argument of zero effectively results in a re-execution of lines 2391 to 2394.
(It is very hard to see why the programmer chose to use a recursive call here in preference to simply repeating lines 2393 and 2394, since both code efficiency and compactness not to mention clarity seem to have suffered.);
Restore the contents of the transmitter status register. In particular if bit 6 was formerly set to enable interrupts then this resets it.