Slashdot Mirror


Why the Z-80's Data Pins Are Scrambled

An anonymous reader writes "The Z-80 microprocessor has been around since 1976, and it was used in many computers at the beginning of the PC revolution. (For example, the TRS-80, Commodore 128, and ZX Spectrum.) Ken Shirriff has been working on reverse engineering the Z-80, and one of the things he noticed is that the data pins coming out of the chip are in seemingly random order: 4, 3, 5, 6, 2, 7, 0, 1. (And a +5V pin is stuck in the middle.) After careful study, he's come up with an explanation for this seemingly odd design. "The motivation behind splitting the data bus is to allow the chip to perform activities in parallel. For instance an instruction can be read from the data pins into the instruction logic at the same time that data is being copied between the ALU and registers.

[B]ecause the Z-80 splits the data bus into multiple segments, only four data lines run to the lower right corner of the chip. And because the Z-80 was very tight for space, running additional lines would be undesirable. Next, the BIT instructions use instruction bits 3, 4, and 5 to select a particular bit. This was motivated by the instruction structure the Z-80 inherited from the 8080. Finally, the Z-80's ALU requires direct access to instruction bits 3, 4, and 5 to select the particular data bit. Putting these factors together, data pins 3, 4, and 5 are constrained to be in the lower right corner of the chip next to the ALU. This forces the data pins to be out of sequence, and that's why the Z-80 has out-of-order data pins."

15 of 167 comments (clear)

  1. C=128 by rossdee · · Score: 4, Informative

    There was a Z-80 in the C=128 , but it wasn't used.
    There was virtually no CPM software adapted to the C=128

    Typically 128s mostly were used in C=64 mode

    1. Re:C=128 by scsirob · · Score: 5, Informative

      Too bad no company ever came up with a killer 8-bit machine. Z80 CPU, more than 64 kB RAM, sound and graphics like SID and VIC-II.

      Really? Ever heard of MSX? See: http://en.wikipedia.org/wiki/M...
      It came with graphics, sprites (TMS9918/9929) and was a standard design carried by several manufacturers.

      --
      To Terminate, or not to Terminate, that's the question - SCSIROB
    2. Re:C=128 by MindPrison · · Score: 5, Informative

      Too bad no company ever came up with a killer 8-bit machine. Z80 CPU, more than 64 kB RAM, sound and graphics like SID and VIC-II.

      Really? Ever heard of MSX? See: http://en.wikipedia.org/wiki/M... It came with graphics, sprites (TMS9918/9929) and was a standard design carried by several manufacturers.

      Ah, MSX... weirdest computers in history. The Yamaha MSX computer was an awesome music computer with built in FM synthesis, and then you had the vastly different Spectravideo MSX, it was fully compliant with the MSX standard...but it's just that, not everyone was compliant - every MSX computer seemed to be a special variant of itself, something that confused me something so fierce back in the days, I even had a Memotech MSX, weird WEIRD computer.

      The games on the MSX computers wasn't mind blowing, nowhere near the commodore 64 games, it simply lacked the awesome sound capabilities of the 64. They had a wider color range though.

      I remember the war between us Commodore users (65xx type processors) vs the Z80 series, yes - the Z80 was a far superior processor in many ways and sometimes I wished we had that processor just for the extended registers alone, not to mention that the speed was 4 mhz instead of our meager 0.97mhz (could be doubled if you turned off the screen). But the hardware sprites & scrolling is what beat the living bejeezus outta the other competing products.

      And I nearly cried snot when the Commodore 65 didn't make it. It was a super-cool Commodore 64 with beefed up hardware, higher resolution, stereo SID sound (6 channels!) of pure ring-modulated goodness.

      Ah, I'll go stare at my stash of Z0840004PSC, 27xxxx's and the rest of the Chip Pron in my vast land of NOS components...aaaahh.. :)

      --
      What this world is coming to - is for you and me to decide.
    3. Re:C=128 by Sun · · Score: 5, Informative

      And then Commodore went on to (half inherit, half design) the Amiga. Maybe "cobbled together" is too harsh for it, but still. Floppy controller that can decide, per track, whether to work in MFM or RLL (but not read a single sector, mind you), more DMA channels than the CPU can handle, and a display processor with a built-in three commands machine language (one of which was only ever used by one application ever) to change display resolution mid-monitor.

      I loved it, but the Amiga gave the impression that it was designed by engineers that couldn't make up their mind on what choice to make, so they created hardware that would offload all decisions to software.

      One last anecdote. Many have heard of the famous "Guru meditation". What only Amiga users know is that you knew one was coming because the power led would blink three times. Yes, the power led was software controlled, making the Amiga the first ever computer that could play dead.

      Shachar

    4. Re: C=128 by Anonymous Coward · · Score: 2, Informative

      Actually Z-80 vs 65xx is still a valid debate. The 65xx was much more capable at lower clocks. A good example being the "Woz Machine" floppy controller compared with many Z-80 boxes needing a second 6mhz Z-80 to run their floppy drives.

    5. Re:C=128 by oldhack · · Score: 4, Informative

      Speed of Z80 at 4Mhz was comparable to that of 65xx at 1Mhz - many of Z80 instructions took more cycles to execute than those of 65xx. Sort of CISC-vs.-RISC before the phrase/concepts were invented.

      --
      Fuck systemd. Fuck Redhat. Fuck Soylent, too. Wait, scratch the last one.
    6. Re:C=128 by Anonymous Coward · · Score: 4, Informative

      What only Amiga users know is that the only way the power led can be controlled is by enabling/disabling the low-pass filter on the audio output since the status of the enable signal is indicated by dimming the led. It's not possible to turn it off completely to simulate the computer being dead.
      It's controlled by bit 1 of ciaa->pra. (Address $BFE001)

      It's also possible to read a single sector, but that would require starting the DMA on a timer so it's more cumbersome than reading the entire track and it's not guaranteed to be faster since it's a spinning media. The memory is there so reading a single sector is just pointless. As for MFM/RLL encoding the floppy controller does neither, it reads the raw bits. The order of the bits is interleaved on Amiga formatted disks to allow for blitter accelerated MFM-(de)coding.

      Don't trust anecdotes, the developer guides are available online.

    7. Re:C=128 by AmiMoJo · · Score: 3, Informative

      The 6502 may have run at a little under 1MHz, but it was efficient. Most instructions were one or two cycles and they did a lot. It's actually a really fun processor to write for because it's both a nice architecture and very challenging to get the most from.

      --
      const int one = 65536; (Silvermoon, Texture.cs)
      SJW, n: "Someone I don't like, and by the way I'm a fuckwit" - AC
    8. Re:C=128 by ChrisMaple · · Score: 3, Informative

      Most Z80 code was written to be compatible with the 8080. As a result, the second register set wasn't used. Floating point math using the second register set for temporary variables made possible a substantial speedup.

      If the 6502 and Z80 waveforms for various instructions are examined, it quickly becomes apparent that the Z80 effectively divided its clock by 2 before using it. This is why, for the technology available in any particular year, they had comparable performance but the Z80 used twice as many clock cycles.

      The 6502 was a tremendously clever design for making effective use of a small number of transistors. The Z80, striving to be a superset of the 8080, was also a clever and powerful design for its time.

      --
      Contribute to civilization: ari.aynrand.org/donate
  2. Re:BASIC vs. Z80 assembly language by david.given · · Score: 3, Informative

    If you're interested in Z80 operating systems, go look at CP/M (seriously: get an emulator, some tools, and write programs for it). It's a fascinating look into just how minimal you can make an operating system and still have something that's not just functional but which spawned, back in the day, a vast ecosystem of tools and software. You suddenly realise just how much fat there is in a modern system (and also why modern systems have all this fat).

  3. 5v lines by Alioth · · Score: 4, Informative

    It's not at all unusual for the 5v and 0v (Vcc and GND) lines to be in the middle of a DIP package (the Slashdot summary sort of implies it's an odd thing). It means the leads within the package are shorter for those lines, lowering parasitic inductance and capacitance for the power supply to the chip, generally you want the decoupling capacitors to be as close to the actual chip as possible so they can be as effective as possible as the power demands change. Putting the supply pins at opposite corners (like it's done on things like 14 pin 74-series standard logic) would very significantly lengthen the distance that the actual supply rails on the chip are from the decoupling capacitors.

  4. Re:C=128 + 6502 cost. by Anonymous Coward · · Score: 2, Informative

    Also cost was a huge factor - the 6502 was significantly less expensive than the Z80s at the time.

    And the 6502 gracefully entered the 16 bit field with 100% backward compatibility in the 65C816.
    Sadly, too late to make a big dent as the 68000 was just around the corner, although Nintendo took
    great advantage of it in their SNES. Franklin Electronic Publishers used the 6502 exclusively in
    their early hand-held spell checkers.

  5. Re:6502 to Z80 work per clock ratio by Anonymous Coward · · Score: 2, Informative

    I don't know about the 6502, but the Z80 takes 4 clockticks per (basic) instruction. IOW, it's a bit below 1 MIPS at 3.57MHz. The later R800, used in the MSX turbo-R, ran at 7MHz at took 1 clocktick per instruction, which gave it the "28MHz Z80 speed" it was sometimes quoted.

  6. Re:6502 to Z80 work per clock ratio by tepples · · Score: 3, Informative

    The 6502 takes 2 to 6 clocks for most instructions: 2 to fetch the instruction itself and the first byte of the operand, then additional cycles to fetch the rest of the operand, perform address generation if necessary, and fetch a value from memory. With fewer register-to-register opcodes, more operations have to use memory. But there are probably plenty of studies from the C64 vs. Speccy flamewars of how this plays out in practice.

  7. Re:Why didn't they just ask Federico Faggin? by Anonymous Coward · · Score: 2, Informative

    Not only is it still manufactured, but it is still used. There is a good probability that your DVD burner has a Z80 in it running the show.

    The Z80 is a great example of a 'limited' CISC design (not enough transistors to be complete CISC like say a Motorola 68000 or a DEC NVAX).

    The 6502 is a great example of a 'limited' RISC design, and quite an efficient one. http://www.visual6502.org is still out there, and you can enjoy that yourself. I'm looking forward to the Z80 version, myself.

    And you can build your own brand-new Z80 machine in the N8VEM system, if you'd like something a bit more satisfying than an emulator and a bit more reliable than an old Kaypro or TRS-80. (Heh, I have a pair of TRS-80 Model 4P's myself......). The Z80 is a great way to learn the fine art of computer engineering with a chip that is easy to understand and apply, with an OS that one person can fully understand and work on (whether that be CP/M or the, in my opinion at least, superior LS-DOS 6.3.1 OS). Both of these OS's are small enough that you can read the full source code in a single weekend, and three or four months of study will be enough to where you can pretty much fully understand it.

    Because, regardless of what toolkits may be available these days, it really does boil down to electrons and machine language (or assembly language mnemonics). Get a good grasp of those basics, and you can learn anything in the computer engineering field. (Computer engineering is not computer science, and vice-versa.)