The HP65 Buffer

There is a variable in the HP65 emulator named simply “buffer”. What is it? What does it do? Why is it there?

Program Memory Instructions

Looking through the code shows its main use is between the program memory and the calculator itself. Program memory in the HP65 is said to be a huge 600 bit shift register. The buffer is used for adding information into and getting information out of that memory. It is the interface.

The memory insert microinstruction copies the contents of the buffer into program memory just before the ’61’ that is used as the next step marker.

The memory delete microinstruction: finds the marker, deletes the step before it, and then copies the step before that to the buffer.

The pointer advance microinstruction moves the marker forward one step and also puts the instruction just before the marker, in the buffer.

As far as program memory is concerned, the buffer holds the current program step.

However, there are a couple of other interesting uses for it.

key -> rom

The “key -> rom” microinstruction normally jumps to (pc & 0300) + the scan code for the current key press. However, in some cases (f7 = 1) it also places the scan code into the buffer. For the HP65, the scan codes vary from 2 to 62 so they are in range for being able to be stored in a 6-bit register.

Scan codes for the HP65 are based on an 8×8 grid with code = row*8+col. The top row ([A]-[E]) is wired up as row 3. The next row (DSP GTO LBL RTN SST) as row 5, then row 1, 7, 6, 2, 0 and 4. The column values are (left to right) 6, 4, 3, 2 and 0. The ENTER key occupies two spaces and has a column value of 6 with subsequent keys (CHS, EEX and CLx) having col values 3, 2 and 0. The lower 4 rows only have four columns and use col= 6, 4, 3 and 2 (left to right).

The scan codes for [A] – [E] are 30, 28, 27, 26 and 24 (or 036, 034, 033, 032, 030). These match the HP65 Program Codes for those keys.

A similar situation exists for the other rows of keys: the scan codes match the program codes for the corresponding key / functions.

The merged key codes all show up with program codes using col= 1, 5 or 7 – the unused col values for the keyboard.

It looks like there is a good reason for loading a key scan code into “the buffer”. It is a value that may need to be stored in program memory.

Computed Goto

A similar looking microinstruction doesn’t seem to do much at all. This is the “buffer -> rom address” instruction. It simply copies the buffer content to another register called “offset”.

It turns out that offset is very useful. It is “wired into” the goto microinstruction. Whilst this normally does what we normally expect it to do, it does something different if f7 = 1. If f7 = 1 then “goto addr” does “goto addr+offset”.

jsb addr

An even stranger one is “jsb addr”. This behaves as expected; BUT if f7 = 1, it also places addr in the buffer. Such could be useful if program memory were in a “learn” mode where every step done is recorded for later playback. However, I’ve never seen this (execute AND store) on a HP calculator.

Interestingly, this technique IS used in the ’65 microcode. It happens at startup. There are a series of jsb instructions that jump into the same bit of code that simply stores the buffer content at the current program step, moves the pointer forward and then waits for program memory to settle down. You can see the jsb instructions in 65-start.txt at 05315 – 5343. They all jump into 05037 which does: “memory insert”, wait for f5 to indicate program memory is no longer busy, and “return”. The “jsb”s match the HP65 Default Program after the start of program memory marker (63 61)(=077 075).

Summary

It is used to move a program step in and out of program memory.

It can be used (1 -> f7 : key -> rom address) to transfer a key scan code to program memory.

It can be used (buffer -> rom address : goto addr) to jump to addr+buffer.

It is used in the startup code to load the default program into memory.

In all cases, buffer is a 6-bit value (0-63) (000-077).

It's only fair to share...Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUponDigg thisPin on PinterestEmail this to someone

Leave a Reply

Your email address will not be published. Required fields are marked *