TI-59 Fast Mode: Running Programs at ROM Speed

What fast mode is

The TI-59 runs some programs that are not in RAM. The built-in functions Σ+, x̄, P→R, D.MS and Op 11–15 are short keycode programs stored in ROM, and Solid State Software modules hold up to 5000 more steps. TI built a faster way to run these programs. Between two steps the firmware skips work that a user program normally needs:

For a ROM routine such as P→R this is exactly right: 20–40 internal steps should look like a single operation, with no flicker and no way to interrupt them halfway. The same steps run in 40–50 % less time, depending on the program. Martin Neef's 69! (CHIP 10/1980, p. 49) took 29.2 s in normal mode and 14.6 s in fast mode on his calculator; the emulator takes 29.0 s and 14.3 s.

The hack

The firmware keeps a program source digit that says where the running program comes from: 0 for RAM, 1 for the module, 8 for the ROM routines. The digit is tested in two different ways:

TI's code never leaves 2, 4 or 6 there while a program runs: 2 appears only for a few instructions inside a RTN back into a module. They pass the first test but match neither bit of the second. With one of them in place, a user program in RAM runs on the fast path. No normal key writes this digit, so getting such a value there takes a firmware bug. TI-59 users' clubs found and published such bugs.

Rules for fast-mode programs

Allowed:

Not allowed. Each of these leaves fast mode and loses the result:

Differences you must expect:

Ending the program. This is where most fast-mode programs go wrong. The program must end with RST or R/S, and at that moment X must be 0, a number still being typed, a value just shown by Pause or Prt, or a value that has been through EE INV EE. If X holds any other result, the calculator hangs with a dark display, and only switching it off helps. Switching off erases the program.

The keyboard during a stop (after a program R/S, still in fast mode; Neef's list, checked on the emulator):

LRN during a stop. A program entered this way is unreliable:

Cards. n Write and n INV Write in a fast-mode program work and stay in fast mode. A card read at a stop makes the program go on, as Neef says: on a real TI-59 and on the emulator, a card with CLR R/S at step 040 leaves 0 on the display instead of the bank number. In our emulator runs, the rest of the current 8-step block ran from the old buffer ("Why the program starts at step 008"); that part is an inference.

Ways in

All methods except the LRN entry put X = 1.000000000002 (or …04, …06) on the display first; 1 + 2 EE 12 +/- = produces it exactly.

The LRN entry

The program is 00000 Pgm 02 SBR 239, or Neef's form 240 STO 00 Pgm 02 SBR Ind 00 (CHIP 10/1980; 239 works too). Both need the Master Library module, and RST R/S starts them.

Why keycodes can come out shifted

The steps 008–015 of the entry land in the status register, two digits per step. Later on, a keyboard SBR rewrites the step counter there and clears one of the two digits of step 012, but the other stays. It sits just where the code that stores a key in LRN adds the keycode, so it adds to the keycode's tens digit. So with Neef's 99 at step 012, a key in LRN stores its keycode − 10: CLR as 15, R/S as 81, 7 as 97. Without it they are stored correctly. Both results checked on a real TI-59 (SBR 48 LRN CLR BST shows 048 15 with Dsz 99 Prt, 048 25 without). This makes Neef's recipe for entering a program in fast mode (CLR R/S) fail with his own entry, which suggests the program is meant to be entered before fast mode.

Flags and Fix after entry

Entry overwrites all ten user flags and the Fix setting. Set any flags you need inside the fast-mode program.

How the hack works

You need three facts about the calculator's internals to follow it.

  1. The status register. The firmware keeps its bookkeeping in one 16-digit scratch register. That register holds the Fix setting, the current program step, the user flags, and the program source digit.
  2. Operations come in pieces. A key such as St flg needs a second key, the flag number. The firmware stores the half-finished operation, waits for the digit, and then jumps to the code that completes it. It computes that jump target by combining address bits.
  3. HIR registers. HIR STO n copies X, digit for digit, into internal register n. HIR normally accepts only n = 1–8. Register 0 would be the status register.

The bug. Run from a program, St flg expects a two-digit flag number. If a key such as STO, EE or x⇄t arrives after the first digit, the firmware ends the operation early. But the code that decoded that key leaves one stray address bit behind, and St flg's completion adds its own bits on top of it. The jump lands in the wrong routine. After one more misrouted jump, execution ends in the code of HIR STO, with register number 0.

The payload. X is now copied into the status register, digit for digit. 1.000000000002 is laid out so that each digit lands in a useful field:

Why it starts running. Like every operation, the misrouted St flg ends in the display routine. That routine sees a non-zero source, assumes a ROM routine such as P→R is between two of its steps, and fetches the next step instead of formatting X. This is TI's own mechanism for running ROM routines; from here on every step takes the fast path, and the fetch still reads RAM.

Why the program starts at step 008. The RAM chips transfer only whole registers of 16 digits. A register is either one data register or 8 program steps (000–007, 008–015, …). The firmware therefore copies a whole block of 8 steps into a buffer, a shift register with the current step at the bottom. Within a block it only shifts the buffer down by one step; it reads memory only when the step counter moves on to the next block. Each shift moves an empty step (keycode 00) in at the top. Each regular jump (GTO, RST, SBR, BST, label search) marks the buffer stale, so counter and buffer always agree. The next fetch reads the target's block and shifts it down until the target step is at the bottom. After GTO 007, for example, the buffer holds step 007 and seven empty steps above it.

HIR STO knows nothing about the buffer. The hack sets the counter to 000 but leaves the buffer as it was, at the step that held St flg's flag number. Until the counter leaves block 000–007, the two disagree:

St flg therefore goes on the last step of a block: 007, 015, … (8k+7). Then nothing is left over: GTO 007 already filled the buffer with empty steps above St flg, so steps 001–007 are all empty, and the real program starts at 008. With St flg on step 003 and 1 2 3 4 on steps 004–007, the run types 234000 before step 008.

Acosta's "hi2" reads the flag number from the program. With St flg at 135 (8·16+7), that read already moves into the block 136–143. Steps 001–007 then run 137–143, and Acosta puts GTO 062 there.

Steps 000–006 are never read during the run, so they can hold anything.

Why the restrictions follow. All the other places that look at the source digit also ask only "non-zero?", and each draws the conclusion that suits a module program:

Sources and limits

Martin Neef, "Verdoppelung der Rechengeschwindigkeit beim TI-58/59", CHIP 10/1980, p. 49, and his corrections in CHIP 12/1980, p. 10; K-J Meusch in TI PPC Notes V5N9-10.

Unless a paragraph says otherwise, everything here was observed on Calc-U-59, which runs the original TI-59 ROM unmodified, and not on a real TI-59. The real calculator was checked for the memory clear and the keycode shift of the LRN entry, for RTN after a keyboard SBR, for the program going on after a card read, and for = resuming a stopped program. Op 09 was not tested in fast mode, and no TI-58 was available: the LRN entry on it is assumed to behave the same.