HP 21xx

One of the software products Hewlett-Packard produced for the early 2116 series machines was a single-user BASIC interpreter. Around 2010 a version of the assembly source, dating from 1970, for the interpreter and associated configuration program became available on bitsavers. This was thanks to Guy Sotomayor who had kept it around since high school in 1971.

This article descibes the process to produce an executable of the BASIC interpreter to run on a 21xx-series processor, starting from this original HP source.

Contents (this page): Resources: Sources & References:
  • Source for HP BASIC at bitsavers
  • From "A Pocket Guide to Hewlett-Packard Computers", 7/70:
    • BASIC Manual: BASIC Chapter
    • Running BASIC: BASIC A-1
    • Running Prepare-BASIC-System: BASIC E-1
    • Absolute Tape Format: BCS F-1

System Requirements

HPBASIC should run on all the early machines (2116, 2115, 2114), the 2100, and, I expect, the later-series machines. 8KW minimum of memory is required. The interpreter talks to the user through the console (originally a teletype), connected via either a 12531A or 12531B/C/D I/O interface.

Storage for user BASIC programs is based around paper tape. The paper-tape devices may be separate 'high-speed' reader and punch devices, or the reader and punch on a console teletype. In the case of reading, the BASIC interpreter needs time after an EOL (carriage return) to process an input line - even low bit rates (150 or even lower) and two stop bits is insufficient. In the original scenario, both the high-speed reader and the teletype paper-tape reader are controlled by a signal from their I/O interface to provide flow control on a per-character basis.

In a modern context a console teletype with reader and punch may be simulated with an async-line serial communication program (SCOMM is such a program, prepared for both text-based console operation and binary-transparent transfer of files). The interpreter seems to send the 8th bit always 1 so the receiving host needs to ignore it. The flow control requirement for 'paper-tape' reading can present a difficulty. Adding nulls after the EOL is not adequate due to the way the 12531B/C/D interfaces work - when the interpeter starts a read part way into transmission of a null character a bad character may be read, as the 12531 is not edge-triggered on the start bit. Explicit time delays after EOL may not work with USB-serial interfaces due to bufferring in the interface. If the console simulator supports hardware flow-control the READ-COMMAND signal from the 12531 might be adapted to RS-232 levels to provide actual flow-control. Alternatively, the PBS reader-driver routines might be hacked to keep a read pending and do some character queuing.

Supported Language and Commands

HPBASIC is a spare and simple BASIC. Some of the limitations are:

User commands are limited to:

Input-line editing is also limited:

Preparing & Running HP BASIC

The HPBASIC interpreter is contained in 11 assembly source files, but merely assembling these does not produce a final executable. The "Prepare BASIC System" program (another 3 assembly source files) must be run to produce an I/O driver package which the BASIC interpreter then relies upon when running. PBS produces the I/O package configured suitably for the target processor/system based on input responses when PBS is run. The I/O package is roughly equivalent to what would be called the BIOS in CP/M and MS-DOS a few years later.

The workflow is shown in the diagram below. Assembling the source (steps 1, 2, 3) may be avoided if one uses the .abs load files contained in the download archive linked above.

If HP BASIC is loaded at step 5b, before PBS is run, PBS will produce an absolute tape with both the configured I/O package and the BASIC interpreter, thus a single boot tape. Otherwise, the output from PBS will contain only the configured I/O package and loading the complete BASIC system is two steps: loading the I/O package (step 7a) and loading the interpreter (step 7b). In either case, HP BASIC must be loaded after it's compatriot as it intentionally overwrites some memory locations.

Also, if HP BASIC was loaded, after running PBS it is permissible to skip step 7 and run the now-configured BASIC system directly from core. Note though, that to do so one must not allow PBS to dump (punch) the configured system. Apparently PBS corrupts the system in the course of dumping it, attempting to run the in-core system after dumping will result in BASIC responding with "ERROR IN LINE " to all input.

Once the complete BASIC system is loaded into the processor, the non-volatility of core should work to advantage when re-booting BASIC. At power-up, assuming the data switches are left at the BASIC start address of 0100, booting is just 3 button pushes on a 2116: PRESET, LOAD-ADDR, RUN.


Memory Layout

Memory Map & Notable Addresses
Contents or Use
0 000000 A
000001 B
000002 JMP 3,I PBS start jmp
000003 016333
000004 HLT 4,C (power fail) link area begin
000005 HLT 5 (parity fault) ..
000006 0 ..
.. 0 .. ..
000027 0 ..
.. ..
63 000077 HLT 077 .. BASIC begin
64 000100 JMP START,I .. ..
000101 PREAD addr of .HSPR [P] .. ..
000102 WRITE addr of TTY.P [P] .. ..
000103 PUNCH addr of .PUNCH [P] .. ..
000104 REED addr of TTY.I [P] .. ..
000105 addr of stop routine [S] .. ..
000106 LWBM LWAM for BOSS [B1] .. ..
000107 BOSS linkage [B2] .. ..
000110 FWAM ptr to first avail. word .. ..
000111 LWAM ptr to last avail. word .. ..
000112 PBUFF * .. ..
000113 PBPTR * .. ..
000114 FWABP * .. ..
000115 FCORE * .. ..
000116 SYMTF * .. ..
000117 SYMTA * .. ..
000120 LSTAK * .. ..
000121 ASBTB * .. ..
000122 SBTBE * .. ..
000123 IMOFF kbd intr disb [P] .. ..
000124 IMON kbd intr enb [P] .. ..
000125 TLINK tty intr [P] .. ..
000126 PLSTR plist addr .. ..
000127 LISTR list dev .. ..
000130 TLSTR list output addr .. ..
000131 .BUFA * .. ..
000132 BADDR * .. ..
000133 CCNT * .. ..
000134 SBUFA * link area end ..
000135 SBPTR * .. <-- FWAM (I/O Pkg)
.. ..
000201 START ptr to ENTRY ..
.. ..
1023 001777 base-page end ..
.. ..
002010 ENTRY BASIC start entry .. <-- jmp from 100
.. ..
4096 010000   ..
.. ..
5729 013141 * BASIC end
013142   user/runtime begin <-- FWAM (BASIC)
.. ..
015073 * I/O 'serial' begin ..
.. .. ..
015677 * I/O 'serial' end ..
.. ..
016333 PBS start entry PBS begin .. <-- jmp from 2,3
.. .. ..
017324 * PBS end ..
.. ..
017346 LWAMP   user/runtime end <-- LWAM
7911 017347 .PNCH PT punch routine I/O 'bufferred' beginI/O drivers begin
.. .. ..
017367 LWAMR   .. .. <-- LWAM
017370 .HSPR HS PT read routine .. ..
.. .. ..
017425   .. .. <-- LWAM
017426 TTY.I TTY read routine .. ..
.. .. ..
017445 TTY.P TTY print/punch routine .. ..
.. .. ..
8127 017677 * I/O 'bufferred' end I/O drivers end <-- LWM
8128 017700 BBL start entry BBL begin BBL begin
.. .. ..
017777 * BBL end BBL end
8192 020000  
16384 040000  
24576 060000  
32768 100000  
The table to the right presents the layout in memory of the four program elements at play: the BASIC interpreter (red), PBS (blue), the I/O driver package (green), and the Basic Binary Loader (yellow). During configuration (when PBS is running), all four elements can reside in memory at the same time. When BASIC is running, PBS is not needed and that portion of address space is available for the user program.

Two template I/O packages are included and initially loaded with PBS, one for the 'serial' and one for the 'bufferred' teletype options. Only one of these will be included in the configured system. When BASIC is running, the I/O package will reside near the top of memory, just below the Basic Binary Loader. The bufferred routines are initially loaded right where they should be for an 8KW system (as shown). If more core is available, PBS will specify them to be reloaded appropriately higher in memory. The serial (bit-banged) routines will similarly be relocated as necessary, in an 8KW system they will be relocated to where the bufferred routines are shown.

The BASIC interpreter resides near the beginning of memory. When BASIC is running, memory between the end of the interpreter and the beginning of the I/O package - identified respectively as FWAM / First Word of Available Memory and LWAM / Last Word of Available Memory - is available for the user BASIC program and runtime needs. PBS configures LWAM to one of several locations depending on which I/O devices were specified as available.

When PBS is loaded, FWAM points to a low address, just enough to include the I/O linkage for subsequent use by BASIC. If the interpreter is to be included in the absolute tape punched by PBS, PBS must be loaded before the interpreter. Loading the interpreter will overwrite FWAM with a higher value so it will be included in the punch.

Table Notes:

The colored areas in the execution columns of the table indicate memory locations which are loaded as part of the according PBS, I/O package or BASIC interpreter.

(Note the table areas are not proportionate relative to actual address range.)

[P] These are the links for the interpreter to invoke routines in the I/O package. They are prepared by PBS and loaded as part of the I/O package.

[S] This is a link for I/O routines to callback to a stop routine in the interpreter. It is prepared by the interpreter.

[B1] The sources make several references to BOSS. BOSS seems to be some sort of executive. BOSS involvement seems to be limited to starting and quitting BASIC. The I/O Package sets LWBM to the same as LWAM. BOSS may adjust LWBM. When the interpreter runs it sets LWAM to the same as LWBM if they differ.

[B2] Not explained.

PBS Execution

When PBS is loaded, the I/O driver links are initially set to point to the drivers in the bufferred I/O package, and LWAM is appropriate for this package. When run, PBS performs the following sequence of activities:
  1. Select the bufferred (switch down / default) or serial (switch up) I/O driver for the TTY/console, based on front-panel data-switch 15. The device select-code is set in the selected driver, as indicated by front-panel data-switches 0-5. If serial: The TTY/console is the device used for both PBS queries and interpreter interaction.
  2. Query for high-speed paper-tape photo-reader. This is the device used by the interpreter PTAPE command for loading user programs. Defaults to a STOP handler.
    If specified: In the absence of a photo-reader, programs are loaded from the TTY/console paper-tape reader (or file transfer in a modern context) via the TAPE command.
  3. Query for paper-tape punch. This is the device used by the interpreter for storing user programs via the PLIST command. Defaults to the TTY/console.
    If specified:
  4. Query for dump device.
    This is the device to which PBS will output the configured system in absolute-load format.
    Defaults to the TTY/console.
  5. Query for core size in kilowords.
    Defaults to 8. If more than 8:
  6. Set assorted table pointers.
  7. Dump two segments of absolute-load data:

CTµL | 2116 | I/O Interfaces | Programming Ref | Software | 2116C Refurb
HP 21xx Series
2014 Sep