PCjs Machines

Home of the original IBM PC emulator for browsers.


PCjs Blog

Introducing the Intel 8080 CPU

Or rather, introducing PCx80, a new 8080-based machine emulator recently added to the PCjs Project.

Our first 8080 Test Machine loads a copy of the 8080 Exerciser (specifically, 8080EX1) and intercepts the exerciser’s CP/M console calls so that you can see its progress in the PCjs Debugger window. It’s a “headless” test machine (no keyboard or display), so that’s all you get.

The good news: PCx80 passes all the 8080 Exerciser tests. And it doesn’t do it by using all sorts of weird “flags tables” that most other 8080 emulators seem to fall back on.

Like all the other CPU emulations in the PCjs Project, PCx80 never “calculates” the flags unless/until they are actually required, which considerably speeds up arithmetic operations.

Of particular note are the 8080’s subtract, compare, and decrement operations, which actually perform addition, not subtraction, by using two’s complement arithmetic in “stages”: the first stage (inverting the source operand) occurs before the addition, and the second stage (incrementing the inverted operand) occurs after the addition. And it appears to be the result of the first stage, not the second, that determines the state of the Auxiliary Carry flag (AF).

The behavior of the Auxiliary Carry flag (AF) and the associated DAA instruction are probably the most significant (and least understood) arithmetic differences between the 8080 and all later x86-based CPUs. Well, there’s also the fact that the 8080 doesn’t provide an Overflow flag (OF). Internally however, PCx80 retains the ability to calculate overflow (since PCx80 was a fork of PCjs), which should be useful when we add Z80 support to PCx80.

On a related note, Ken Shirriff has some fascinating blog posts on the 8085 that also provide clues as to how the 8080 likely operates:

The idea is to make PCx80 sufficiently configurable so that it will work with a variety of 8080-based systems, including those with memory-mapped video displays (like Space Invaders), as well as simpler terminal-based systems, like the CP/M-based systems of old.

In fact, as soon as Space Invaders is working, my next planned adaptation is a DEC VT100 terminal emulator (itself an 8080-based machine) which can then be “wired up” to other PCjs machine simulations. This will not be yet-another VT100-compatible emulation – which, like 8080 emulators, has been done to death – but rather a simulation of the original VT100 hardware, building on Adam Mayer’s work reverse-engineering the VT100.

Jeff Parsons
Apr 30, 2016