Reverse Engineering The Z80’s 16-bit Increment/Decrement Circuit

z80

Increment and decrement. They sound like simple functions. But even the simplest functions can get quite complex in a microprocessor design. Ken Shirriff has written up a great blog post about his reverse engineering of the Z80’s 16-bit increment/decrement circuit. The Zilog Z80 was one of the most popular microprocessors of the 70’s and 80’s. It was used in many classic computers such as the Osborne 1. These machines would often use the Z80 to run the popular CP/M operating system.

The increment/decrement circuit is responsible for updating the program counter register during normal (non branch) operations. The increment/decrement circuit also handles the stack pointer register during stack operations, as well as several other functions. One might wonder why a separate adder would be used when the microprocessor has a big ALU available to it. The answer is twofold. First the ALU is already in use handling user math operations. Secondly the increment/decrement circuit has to be fast. A generic ALU just won’t be fast enough.

One classic adding circuit is a Ripple Carry Adder. Ripple Carry Adders get the job done, but they are slow. Note slow is measured in nanoseconds here – there are no clocks involved in the circuit. The whole thing becomes a classic combinational logic optimization problem. Each layer of logic adds a gate delay to the circuit. As the carry has to ripple through all 16 bits, there are 16 gate delays before the final result is available at the outputs. Delays like these are what limits the maximum clock speed for a given circuit.

The Z80 uses some tricks in its increment/decrement circuit. The first is Carry-lookahead. A carry-lookahead circuit will calculate the carry values directly from the inputs. This reduces the gate delays significantly, but it requires more real estate on the die. A second trick is the carry-skip circuit. Carry-skip calculates the result for groups of bits rather than each bit individually. Again, it will reduce gate delays, at the cost of real estate. The actual Z80 implementation uses a mix of both circuits. Several other “helper” circuits are also used. Surprisingly the Z80 has specific logic just to check for 1 (0x0001) on the internal address bus. This circuit is used during memory move loops to inform other parts of the chip that a loop is about to complete. 

VFD Display Becomes An Amplifier

Born well into the transistor era of the late 80s, [Fernando] missed out on all the fun you can have with high voltage and vacuum tubes. He wanted to experience this very cool tech, but since you won’t find a tube checker down at the five and dime anymore, where exactly do you get a vacuum tube to play around with? [Fernando]’s solution was to rip apart the vacuum fluorescent display from an old radio (Google Translate) and use that as a triode.

Inside every VFD is a filament, grid, and cathode – three simple elements also found in the triodes of just about every tube amp ever made. By applying a small voltage to the filament, a larger voltage to the cathode, and sending an audio signal to the grid, this triode amplifies the electrical signal coming from a stereo or guitar.

[Fernando] built his circuit on a breadboard, and with a little tweaking managed to get a fairly respectable amount of gain from parts salvaged from a radio. While using VFDs as amplifiers is nothing new – we’ve seen it a few times before, tube builds are always great to see, and bodged up electronics even more so.

A New Old Lathe For Your Hackerspace Or Garage

3D printers, or even small CNC routers may seem like relatively easy machine tools to obtain for your hackerspace or garage. They are both very useful, but at some point you may want to start working with round parts (or convert square-ish items into round parts). For this, there is no better tool than a lathe. You can buy a small and relatively cheap lathe off of any number of distributors, but what if you were to get a good deal on a larger lathe? Where would you even start?

In my case, I was offered a lathe by a shop that no longer had a use for it. Weighing in at 800 pounds and using 3 phase power, this South Bend Lathe might have been obtained economically, but getting it running in my garage seemed like it would be a real challenge. It definitely was, but there are a few mistakes that I’ve made that hopefully you can avoid.

Continue reading “A New Old Lathe For Your Hackerspace Or Garage”

The Tiniest Video Game

As we read [Adam]’s writeup for an extremely tiny video game system through coke bottle glasses, we’re reminded of the countless times we were told that sitting, ‘too close to the Nintendo’ would ruin our eyes. We’ll happily dismiss any article from a medical journal that says there was any truth to that statement, but [Adam]’s tiny video game system will most certainly hurt your eyes.

A few years ago, Atari sold keychain-sized joysticks that contained classics such as PongBreakout, Centipede, and Asteroids. [Adam] apparently ran into a cache of these cool classic baubles and immediately thought of turning them into a stand-alone video game system.

For the display, [Adam] used a CRT module from an old Sony Handicam. These modules had the right connections – power, ground, and composite video input – to connect directly to the Atari keychain games. The result is a video game that’s even smaller than a postage stamp. The picture above shows the tiny CRT next to a 25mm postage stamp; it’s small by any measure.

Deconstructing Apollo Flight Hardware

[Fran] has been researching the Saturn V Launch Vehicle Digital Computer – the computer that flew all the Apollo flights into orbit and onwards towards the moon – for a while now. Even though she’s prodded parts of the LVDC with x-rays and multimeters, this is the first time she’s committed to a little destructive testing.

After [Fran] took a flight-ready LVDC spare to the dentist’s office for x-raying and did an amazing amount of research on this artifact from the digital past, there was only so much she could learn without prying apart a few of these small, strange chip packages. Not wanting to destroy her vintage LVDC board, she somehow found another LVDC board for destructive reverse engineering.

This new circuit board was a bit different from the piece in her collection. Instead of the chip leads being soldered, these were welded on, much to the chagrin of [Fran] and her desoldering attempts. After removing one of these chips from the board, she discovered they were potted making any visual inspection a little difficult.

While [Fran]’s attempts at reverse engineering the computer for a Saturn V were a bit unsuccessful, we’ve got to hand it to her for getting this far; it’s very, very likely the tech behind the LVDC was descended from ICBMs and would thus be classified. Documenting the other computer used in every Apollo launch is an impressive feat on its own, and reverse engineering it from actual hardware, well, we can’t think of anything cooler.

An Overly-Complicated Logic Chip Clock

Clock

When a normal alarm clock just won’t do, the only option is to build your own, entirely out of discrete logic chips. [jvok] built this alarm clock for last year’s 7400 Logic Competition. In a desire to go against the grain a little bit, [jvok] decided to use 4000-series logic chips. It was allowed under the rules, and the result is a wonderful example of what can be done without a microcontroller.

Most clock projects we’ve seen use a single button to increase each digit. [jvok] wanted to do something unique, so he is able to set his clock with a ‘mode’ button that allows him to independently set the hours, minutes, and seconds. He’s only ever seen this method of setting a clock’s time used with microcontroller-based projects, and translating even that simple code into pure circuitry is quite impressive.

This clock also includes an alarm function, set by a bunch of DIP switches in binary coded decimal. It’s a great piece of work, and deserving of much more attention than it received during the Open Logic Competition.

A Twitter Connected Mechanical Calculator

The TwitALU

Two students at the University of Bristol wanted to create a computer to demonstrate how ALUs work. The result is the TwitALU, a Twitter connected mechanical calculator.

The device uses a custom 7400 series ALU based on the famous MOS 6502 processor. Instead of doing the calculations on a silicon die, the ALU drives mechanical relays. This produces a nice clicky-clacky sound as the calculation is computed.

To start a calculation, you tweet @twittithmetic with your input. A Raspberry Pi is used to load the instructions into the ALU. Once the computation is done, it’s tweeted back to you and displayed on the Nixie tube display. It’s not efficient, or fast, but it does the job of demonstrating the inner workings of the device while doing simple math.

The device’s schematics are all available on the website, and are helpful for understanding how a simple ALU works. After the break, check out a quick clip of the TwitALU in action.

Continue reading “A Twitter Connected Mechanical Calculator”