GO9800 Emulator

What is GO9800

GO9800 is intended as a complete emulation of the hardware of the famous first family of Hewlett-Packard desktop calculators, i.e. HP9810A, HP9820A, HP9821A, and HP9830A/B.

The emulator is able to run the complete ROM-based firmware of the above models and the application programs written in the model specific programming language. Moreover the user interfaces (display, keyboard, printer), mass memory devices (magnetic card reader, tape drive, disc drive), and other external devices can be emulated to resemble the complete functionality of the original machine.

To enhance the realism of the emulation part of the outside appearance is graphically displayed and some of the mechanical sounds (beeper, cooling fan, drive motors, etc.) can be output via a sound card.

The emulator is completely written in Java and platform independent.




Disclaimer

GO9800 and the project site is in no way associated with the Hewlett-Packard Company.
Hewlett-Packard, HP, and the HP logos are all trademarks of the Hewlett-Packard Company.
This website is intended solely for research and education purposes.


The Project

The objectives of this project where to understand and preserve the firmware of the Hewlett-Packard series 9800 calculators and to create a fully functional real-time simulation of the complete hardware.

Of course there where some legal concerns which had to be examined. As of April 2007 all patents are long since expired and there are no registered trademarks affected except the HP logo. The firmware ROMs, software tapes and magnetic cards don't carry any copyright notice. Also the contents of the most ROMs are disclosed as source code in the appropriate patents. Nevertheless all HP firmware and software is still regarded as copyrighted and used as is, without any changes.

The project began with acquisition of the ROM contents of the HP9810A and HP9820A by means of a logic analyzer. The next step was programming a disassembler in Java to get a deeper understanding of the 9800 CPU instructions. Furthermore by analyzing the disassembled firmware it was possible to understand the I/O procedure and interrupt structure.

One more result was the ability to create my own assembler programs for the 9800 CPU and run them on the real hardware. I discovered undocumented features in the 9810 Peripheral Control ROM which allowed to store and run binary machine programs. The first one was a kind of PEEK function for the HP9810A. By means of this the complete memory contents could be dumped. It was a good verification of the correctness of the logic analyzer read out. The next assembler program was a PEEK function for the HP9830A, whose firmware contents was not available so far. This also succeeded in a complete dump of the system ROM and additional plug-in ROMs.

The last phase of the project was the Java programming of a 9800 CPU emulator. Because of the properties of the display and keyboard I/O devices the HP9830A seemed to be the easiest candidate for emulation of the whole hardware. There where several risks in this phase as it was not sure whether the CPU instructions where completely documented in the various U.S. patents of the series 9800 machines. Also it was difficult to estimate the execution speed of the emulator. The machines should at least run in real time speed. Moreover the I/O principles where very poor documented and difficult to understand in detail.

In fact during the first tests of the emulator it showed that some CPU instructions had to behave different from the available 'documentation'. Esp. the floating point macro instructions took some weeks of debugging and step-by-step analyzing until they produced correct results. Also the stack handling of JSM /RET and the interrupt service routine gave some unexpected surprises. Late in the project, when testing the HP9820A together with the HP9865A, there showed one more anomaly in the IO interface. After many hours of testing, debugging, and re-programming it was only one possible solution left: the handling of the CEO handshake in the instruction STF 1 was wrong. There was only one constellation in the firmware of all three calculators where this special situation occurred.

With the core functionalities of the HP9830 and getting the machine up running with a very simple output and input interface, the proof of concept was done. After that I added a simulated keyboard and LED matrix display. Photographs and sound recordings of the original machine where used to resemble a most naturalistic simulation.

The display simulation is somewhat tricky: in the original machine the display output is controlled and multiplexed by the CPU. That means the CPU outputs every displayed character many times a second to give to the human eye a quasi steady display. When implemented 1:1 in software, this resulted in heavy flickering and high load of the host CPU. So I decided to update the display output only if a character changed, i.e. when a new output was generated by DISP command, user entry and the like. This has only onedisadvantage: the display keeps visible even if the calculator is busy. This issue finally is solved by clearing the simulated display if the DEN (display enable) signal is false for more than a certain amount of executed CPU instructions.

In the next steps several peripheral devices where added: the HP9860A marked card reader, the HP9866A thermal printer, and the HP9862A plotter. The device which caused the most work was the HP9865A cassette tape drive, which is available build-in to the HP9830A and as external device. The I/O protocol is very complicated and the timing crucial, since the 9865 reads and writes asynchronously to the main machine. Some tape operations run completely in background and send interrupts to the calculator. JAVA multi threading techniques had to be used intensely. It took several weeks until the 9865 worked satisfactory.

When the HP9830 and the peripherals where completed the next machine to be implemented was the HP9810A. Reusing or extending most of the classes of the HP9830, the 9810 was basically brought up in a few days. Again the display simulation required a special timing logic. Most work had to be spend in the magnetic card reader. It has a similar I/O protocol as the HP9865, but the timing even more critical. Again it took more than two weeks to get a stable solution.

The last one was the HP9820A. With the experience of the first two machines it would have take only a few days to complete the 9820. If there didn't occur this annoying problem with the cassette memory ROM and the 9865 (see above).

In several releases of the emulator more add-on ROM blocks and application programs where added to the distribution. Some of them where borrowed by contributors (see chapter 7) and read out using the mentioned assembler programs. Some ROM blocks are obviously very rare and could not be acquired until now. Amongst these are the HP9810A User Defined Functions ROM and the Typewriter ROM. Since their contents are completely listed in the HP9810A patent I decided to re-create them from scratch and type the octal values from the patent listings. By disassembling and cross-checking the instructions all typing errors could be eliminated. The graphics of the ROM blocks and keyboard overlays where also created artificially using GIMP on basis of other existing ROMs.

In 2007 the HP9880A/B mass memory system was added to the project, in 2008 the HP9861A impact printer, and in 2011 the HP9866B graphics capable thermal printer. At this time the complete printer and plotter output was reworked for scalability and hardcopy to a real printing device. The last major addition and intended finish of the project was the HP9821A in 2011. This was made possible by a acquisition of the original HP9821A system ROMs.

As of May 2012 and release 1.61 the project took more than 1000 hours of time for research, design, programming, and testing. Writing this manual took another 100+ hours.

In 2016 I reopened the project to implement execution of the CPU micro-code. Up to release 1.6 the arithmetic and logic functions and the instruction decoding where programmed in plain java code. This gave a rather fast execution but led to the problems described above. In the real hardware the main logic of the CPU is coded in a micro-program contained in seven ROMs. This micro-program is responsible of decoding the CPU instructions (on assembler code level) and executing them. Two additional ROMs contain the logic of the binary and decimal (BCD) arithmetic operations. The ROM contents are well known as they are printed as binary values in the patent documents. There where three main issues which where unsolved until 2016: first, the ROM contents had to be dumped or alternatively the binary values had to be retyped from the patent prints, which is very unpleasant and error prone. Second, the binary code had to be decoded to micro-instructions, and third the micro-program had to be analyzed and understood.

In 2016 I stumbled over the work of Brent Hilpert (see link below), who had typed the contents of all CPU ROMs from the patent print and decoded it to a complete listing of the micro-program. He also scrutinized the CPU hardware to understand the micro-code and its control functions. By using this work I was able to implement the micro-code execution in GO9800 in about 100 hours of work. The implementation required the detailed simulation of major parts of the CPU hardware, such as shift-registers, buses, flip-flops, and several logic gates. Also it was neccessary to rework the complete I/O logic as it is entangled with the CPU and bus structure. Up to release 1.6 the functionality of the 'I/O-register and gate interface' where also programmed based on the description in the patent documents. Now also parts of the hardware are simulated in Java code, e.g. the I/O state machine and the I/O shift-register.

After another 100 hours of testing and debugging the release 2.0 was running, but as expected, much slower (about 25-30 times) than the previous releases. This is mainly due to the simulation of the bit-serial CPU buses and ALU functions. Nevertheless the advantage of this implementation is, that no assumptions on the CPU functions have to be made, such as, how the BCD arithmetic is working. It simply works by executing the micro-program. But this 'simplicity' was not as easy to realize as I thought. During testing several problems arose, as the micro-code execution has a somewhat complicate 'timing' which required an in-depth understanding of the state machine and clock cycles. To accomplish this, the running emulator release 1.6 was extremely helpful, as I was able to compare the results on instruction level step-by-step. As the last work the still Java-programmed 1-bit arithmetic functions where replaced by readout of the ALU and BCD ROMs. Now the emulator didn't need any more 'calculus knowledge'. But switching to the ALU and BCD ROMs slowed down the emulation again by nearly a factor of two. Also, testing revealed a few typing errors in Brents ROM data and also in the patent prints. There is one error in the printed binary code of the BCD ROM which, if this was manufactured 1:1 in the ROM hardware, would lead to erroneous results in BCD subtraction of certain values (e.g. 3 – 8 + carry). Strange enough, this error could never occur in the real calculators, as BCD subtraction is only used in two CPU instructions, the complement CMX and CMY. Both subtract values from 0 (zero) and the special constellation of operators, which leads to the error, never happens.





Links

GO9800 project site and download pages: sourceforge.net/projects/go9800


The architecture of the HP9800 series is most completely described in the following patents available from the U.S. patent office (www.uspto.gov):

HP9810A: 3,859,635 Programmable Calculator

HP9820A: 3,839,630 Programmable Calculator Employing Algebraic Language

HP9830A: 4,012,725 Programmable Calculator

There are also german patents available from Deutsches Patent- und Markenamt (www.dpma.de):

HP9810A: 2264920, 2264923, 2264871

HP9820A: 2262725, 2264896, 2264897, 2264898

HP9830A: 2333908, 2365567, 2365568, 2365570

Further information about the history and technology of HP calculators can be found at

www.hpmuseum.org

www.hpmuseum.net

www.hp9825.com

www.hp9831.com

www.hp9845.net

http://www.classiccmp.org/hp/9800.htm



Most calculator and peripheral manuals are available for download from

www.hpmuseum.net


In-depth informations on the HP9830A hardware, the CPU architecture and micro-code and many more can be found on Brent Hilperts site

http://www.cs.ubc.ca/~hilpert/e/HP9830/


A nice video with the real HP2116 control panel in action

https://www.youtube.com/watch?v=9NWvNHGFRI8