‘open mode’

The difference between basic and basica is not like the difference between IBM's/Microsoft's BASIC and BASICA, that they were named after. They both provide the same language. The difference is that whilst basic is a conventional Unix(‐esque) filter program that is entirely indifferent to terminal devices, basica works in what Bill Joy's original vi editor named ‘open mode’.

basic and canonical input mode

basic, when its standard input or output (or both) is a terminal device, uses what in POSIX terminology is called ‘canonical input mode’. Ironically, since the advent of line editing and full screen programs in the 1980s, terminals in practice are rarely in this mode for interactive programs, and usually only in it when a non‐interactive program is running.

Some of the functionality of Home Computer Era BASIC is simply not possible in canonical input mode. It is impossible to poll for or read a single character of input with INPUT$() or GET$, because the operating system's ‘line discipline’ always reads an entire line before returning input to a program. The line discipline can also do things like mess up the terminal's actual tabstops by turning TAB into SPC, change where the cursor ends up after LF, or stall output entirely.

basic is, however, useful where there is no terminal device involved, in dæmon context. A BASIC program could be a UCSPI-TCP server when run with this utility, for example.

basica and open mode

Further reading:

basica requires access to a controlling terminal device, in contrast, and puts it into ‘non‐canonical input mode’ where the line discipline makes no changes to the input and output streams, and characters can be read one at a time, immediately as the terminal sends them. It provides its own interactive line editing, rather than letting the operating system do that.

Open mode is largely forgotten nowadays. Although Joy and Horton vi is still available in Illumos and all of its derivatives (OmniOS, Tribblix, SmartOS, OpenIndiana) and the open mode code is there to this day, none of the vi clones ever copied open mode, as it was largely a relic of video terminals that were outdated even at the time that the clones were written.

However, open mode is also exactly how many Unix shells, that have line editing capabilities, still work.

The driving force behind open mode is that the terminal lacks the ability to do ‘cursor addressing’. The cursor cannot be moved around to arbitrary points on the screen, a necessary piece of functionality for full‐screen programs like vi.

There did exist early video terminals where the cursor could be moved around within a single line, using either simple tricks like printing the Carriage Return (CR) or Backspace (BS) characters and re‐printing text, or a limited set of relative cursor motions that did not provide absolute positioning. Bill Joy famously used an ADM-3A, which had cursor addressing and the ability to clear to the end of a line. But its immediate predecessor, the ADM-3, did not have either of those.

vi's open mode allowed one to ‘visually’ edit one line of the program at a time. Moving from line to line did not move the cursor up and down a full screen display. It moved down to the next line on the screen (i.e. CR+LF) and printed the newly moved‐to line to be edited in its turn.

This seemed quite odd if one happened to be moving backwards through an editing buffer, as the history of lines that had been edited would appear in reverse order on the screen.

When a BASIC program is running, the line editor is not active. But the system underpinning it remains active, and the terminal remains in non‐canonical mode. This is how basica is able to queue up keystrokes as type‐ahead. It is, however, also why basica will swallow all typed‐ahead input for itself, even if it never actually gets around to giving it to a BASIC program.