saturnus docs
Open the app

The keyboard

The keys of a Saturn calculator are a matrix of wires on two of the CPU's own registers: OUT drives the rows, IN reads the columns. The chip scans the matrix by itself and interrupts the CPU when a key goes down. The ON key has a line of its own.

At a glance

HP 48SX, 48G series49 keys: 48 on 9 OUT lines × 6 IN lines, and ON
HP 49G51 keys: 50 on 8 OUT lines × 8 IN lines, and ON
ON keyits own pin, read as IN bit 15 whatever OUT holds
Hardware scanevery 1 ms, an interrupt on a key going down
Releaseno interrupt: the system watches for it with a timer
Debouncingin software, five equal samples 2 ms apart
Beeperalso on OUT, bit 11

The matrix

Each OUT bit drives one row of keys. Each IN bit reports whether a column is connected to a driven row through a pressed key. To read one row, a program writes that row's bit to OUT and reads IN. Rows can be combined: with all nine bits set, IN is non-zero if any key is down.

The matrix of the 48 series, from the Saturn assembly tutorial. The column heads are the IN bits, the row heads the OUT bits, in hexadecimal:

OUTIN 20IN 10IN 08IN 04IN 02IN 01
100BCDEF
080PRGCSTVAR▲NXT
040STOEVAL◀▼▶
020COSTAN√xyˣ1/x
010ENTER+/−EEXDEL←
008αSIN789÷
004left shiftMTH456×
002right shiftA123−
001'0.SPC+

The keys are named as on the 48SX; A to F are the six menu keys. The 48G series has the same positions with its own labels. The 38G uses this matrix too, with 47 of its positions.

The 49G has a different keyboard and a different matrix, eight rows by eight columns. The 39G and 40G use the 49G's positions. Matrix tables for both are in the tutorial and in Sylvester's hardware note on the 49G keyboard.

The OUT lines are not only the keyboard's. On the 48GX's board they share pins with the address bus, and bit 11 drives the beeper: OUT set to 800 and back to 000 clicks it. OUT cannot be read back, so the system keeps a copy in RAM and restores OUT from it after each interrupt. A program that scans the keyboard itself, with interrupts on, has to update that copy before it writes OUT.

The ON key

ON is wired to its own pin of the CPU. It shows as bit 15 of IN, whatever OUT holds, and its interrupt cannot be masked: INTOFF, which stops the keyboard interrupt, leaves ON working. Holding ON while pressing another key gives the 48's system functions:

KeysWhat they do
ON and + or −darker or lighter display
ON and Cwarm start: clears the stack and PICT, keeps memory
ON and A and Fcold start: offers "Try To Recover Memory?"
ON and Bcancels the other ON combinations, before ON is released
ON and Dinteractive self-test
ON and Elooping self-test
ON and 4cancels repeating alarms
ON and 1screen dump
ON and SPCcoma mode: all clocks stop until ON, and the warm start log is cleared

The other models have their own combinations: the 38G takes ON with a menu key to reset.

The hardware scan

Unless the CPU has executed INTOFF, the chip itself scans the whole keyboard every millisecond, with no software involved, and raises an interrupt when a key goes down. Holding the key causes no further interrupts, and releasing it causes none.

So the operating system does the rest in its interrupt handler:

  1. On the interrupt, it reads the matrix row by row to find the key.
  2. It debounces: it samples the whole keyboard every 2 ms until five samples in a row agree. A keystroke therefore takes more than 10 ms to register.
  3. It puts the key's code into a key buffer. While the calculator is busy, up to 15 keys wait there.
  4. It sets the 16 Hz timer to come back every 1/16 s while any key is down, and so notices the release. Without that, two presses of the same key would look like one.

The shift and alpha annunciators are updated by the system outside this keyboard routine.

With the display turned off, the keyboard does not respond. And when SHUTDN has put the CPU to sleep, a key going down wakes it (see Timers and interrupts).

Emulating it

For an emulator, the timing matters more than the matrix:

The HP 48SX page and the HP 49G page describe the two keyboards as their owners see them.

Sources