|
Tech archive -
Consoles
 |
Sega Master System/SMS/Mark3/GameGear
|
 |
Nintendo Gameboy |
 |
NEC PC Engine/TG-16 |
 |
Sega Genesis/Megadrive |
 |
Sega MegaCD |
 |
Sega 32X |
 |
Super Nintendo/Super Famicom/SNES |
 |
Sega Saturn |
 |
SNK NeoGeo |
 |
SNK NeoGeo Pocket (and Color)/NGP/NGPC |
 |
Commodore Amiga CD32 |
 |
Sony Playstation |
 |
Nintendo 64 |
 |
Sega Dreamcast |
 |
Sony Playstation 2 |
Computers
Chips
Arcade machines
 |
Capcom CPS1/2/3 |
 |
Sega System 16/18 |
 |
Sega Model 1 |
 |
Sega Model 2 |
 |
Sega Model 3 |
Theory
 |
CPU emulation |
 |
Dynamic recompilation |
 |
Static recompilation |
 |
High-level emulation (HLE) |
Tools & Utilities
|
Ah, what can be said about ZiLOG's amazing Z80 chip. The most
popular chip for video games, during the 8-bit era, used in many different
systems. It's amazing cheapness, simplicity and elegance ensured it would
remain in constant use throughout the 1980s and still in some systems
in the 1990s.
This unit powered many arcade games, such as Pacman, Mr Do, Galaxian, etc.
It was also the brain behind the Sega Master System, the ZX Spectrum, the MSX,
and many more. Towards the end of it's life cycle, it was relegated to the role
of a sound CPU in many machines, such as the NeoGeo, the Sega Genesis, etc.
Here's the register set it used -
| Register |
Description |
| AF |
Accumulator & Flags |
| BC |
Counter |
| HL |
General purpose |
| DE |
| IX |
Indexing |
| IY |
| PC |
Program counter |
| SP |
Stack pointer
|
| IR |
Interrupt & Refresh |
| IFF1 |
Interrupt flip-flop 1 |
| IFF2 |
Interrupt flip-flop 2 |
| IM |
Interrupt mode |
All these registers are 16-bit. The AF/BC/HL/DE registers could be accessed
as either a 16-bit register, or two 8-bit registers, as in the Intel x86 series.
In fact, many of the Z80's features were shared with the Intel range. The IR
register was only viewable as two 8-bit registers, the I and R registers.
There are also the prime registers (AF', BC', DE', HL'), which are kind
of like a secondary set of registers. They can be switched with their normal
equivalents at any time.
Upon power-up, the Z80 would clear all the registers to zero, except for the
IX/IY registers which would be 0xFFFF. It would then start to read an opcode
from the current PC, decode it, and execute it. This would repeat until it was
powered down.
The Z80 had a 64Kb memory space, as well as a 64Kb I/O address space. The memory
space was accessed using the normal instructions as well as being used for opcode-fetching,
but the I/O space could only be accessed using special I/O instructions. Many
systems only decoded the low 8-bits of the I/O addresses, to provide a 256 byte
I/O space.
There are two types of Z80 - the Z80A and the Z80B. As far as I am aware, the
only difference is that the B model can go faster. Anyone know anything about
this?
Resources
Pin descriptions
Based from the excellent
book "Understanding Your Spectrum", By Dr. Ian Logan (ISBN 0 86161 111
X, but probably out-of-print anyway...) -
The Z80 is a silicon chip with forty pins numbered from 1 to 40. The above
diagram shows the pin arrangement of the Z80, and the names associated with
each pin. The lines labelled +5v, GND, Clock, and the Dx/Ax bus lines, are active
high. All the rest are active-low.
- +5v - the power line. A +5v supply is required by the Z80 microprocessor.
- GND - the ground line.
- Clock - the clock input, usually around the 4MHz range.
- D0-D7 - these eight lines form the data bus that carries data bytes to and
from the processor to the memory.
- A0-A15 - these sixteen lines form the address bus that carries address from
the processor to the memory.
- RD - the read line. This will be active whenever a byte of data needs to
be read from memory.
- WR - the write line. This will be active whenever a byte of data needs to
be written to memory.
- MREQ - the memory request line. This line is activated whenever a byte of
data is being passed to, or from, the processor.
- RFSH - the refresh line. This line is used to refresh dynamic memories.
- M1 - the memory fetch line. This can be raised during a read operation,
to indicate that the byte being fetched is an instruction. As far as I can
tell, this is generally only used for encryption purposes.
- IORQ - the input/output line. This line is used instead of MREQ, when an
IN/OUT instruction wants to access the I/O address space.
- HALT - the halt line. This line is active only while the HALT machine code
instruction is being executed.
- BUSRQ - the bus request line. The Z80 allows external devices to temporarily
stop the Z80, so that they can have access to the buses/memory/etc. A device
asserts this line, then waits for the Z80 to respond with the BUSAK signal.
- BUSAK - the bus acknowledge line. Raised when the processor has given the
go ahead for a device to take control of the bus.
- RESET - This line is used to initialise the microprocessor. It is therefore
activated as soon as the power is connected to the machine.
- WAIT - the wait line. A slow memory chip may require extra time in order
to complete a read/write operation. It does this by signalling the Z80 via
this line. Some systems like the Spectrum's
ULA chip use this to allow sharing of RAM between two processors.
- NMI - the non-maskable interrupt line. This line, when active, leads to
the microprocessor stopping the execution of the current program. Instead,
the processor executes a special interrupt routine. This line is rising-edge
triggered (probably), so that a NMI won't be repeatedly handled.
- INT - the maskable interrupt line. This works like the NMI line, except
can be disabled by software. Also, this is level-triggered, so the Z80 needs
to disable interrupts as soon as it receives one, so that if the line remains
active it won't cause multiple interrupts.
To do a complete read cycle, for example, the Z80 would first set the address
lines to the required address, then assert the MREQ and RD lines to indicate
that the data should be supplied. The memory hardware will respond to the MREQ
line, and will supply the byte via the data lines.
The Flag register
| Bit |
Initial |
Name |
Description |
| 7 |
S |
Sign |
Set when the result was negative. |
| 6 |
Z |
Zero |
Set when the result was zero. |
| 5 |
5 |
Bit 5 (undocumented) |
Usually a copy of bit 5 of the result. |
| 4 |
H |
Half-carry |
Set when a carry occurred between bit 3/4 of the result (used for BCD). |
| 3 |
3 |
Bit 3 (undocumented) |
Usually a copy of bit 3 of the result. |
| 2 |
P or V |
Parity/Overflow |
Set to indicate either even parity in the result, or a 2's complement
sign overflow. |
| 1 |
N |
Negative |
Set when the previous instruction was a subtraction, clear when it was
an addition (used for BCD) |
| 0 |
C |
Carry |
Set when a standard carry occurred. |
Sometimes the P/V flag is called P or V, depending on whether parity or overflow
is meant. It depends on what sort of instruction you've just executed as to
what you should treat it as.
The instruction set
This is a complete list of all the opcodes for the Z80, both documented
and undocumented. This was compiled by the Z80 guru Sean Young, and is also
available on his Z80
page.
Click here to read it.
The Z80 is infamous for having a large number of undocumented instructions,
which ZiLOG probably never intended to be used. However, a lot of people did
find out what they were, and made the most out of them. So, any Z80 emulator
worth it's salt should be able to handle them. This file,
again from Sean Young's
site, details them all.
Z80 emulators
This is a list of the major software emulators available for various platforms.
Some are Intel only, some are in C.
- RAZE. I'm a bit biased towards
this one (seeing as I wrote it ;-), but it is probably the best Z80 emulator
available. It only runs on the Intel x86 platform though, but is quite fast,
has a clean interface, and features almost perfect emulation. Also has proper
IRQ line handling, unlike most others.
- Marat Fayzullin's
emulator is one of the most famous ones out there, and is used in many
projects. It is quite slow though, and has a number of bugs. Written
in portable C.
- Marcel de Kogel's.
Based off Marat's one, but has an optional x86 component to make it
slightly faster on that platform. Was used in MAME till they wrote their
own. I prefer this to Marat's. Written in portable C, with optional
x86 assembly.
- MAME. The MAME Z80 core
is quite good, being fast and portable. It comes in two flavours, a C version
and a Intel x86 version. However, it is extremely hard to extract it from
the rest of the MAME source code, and also any code using it will probably
fall under the MAME license...
- MZ80
is Neil Bradley's effort. It is very fast, being written in x86 assembler.
However, it does have a lot of bugs, can't really handle bank switching too
well and IMHO the interrupt handling is a bit dodgy. Some people seem to like
it though, so give it a try ;-)
- MAZE was written by Ishmair, who now seems
to have left the scene, so don't expect any updates here. This emulator
is quite good, a bit like MZ80. At the time, this was *the* emulator
to use, but now MZ80 is a better bet. x86 asm only.
Links 'n' stuff
Go see Sean Young's page! Now!
There's always the ZiLOG
page, but there's not much there...
There's a *lot* of stuff on the Official
Z80 Support Page. Pinouts, hardware stuff, software stuff, etc. Far
too much stuff in fact :-)
The Spectrum
FAQ has lots of Z80 tech stuff in too.
And lastly, the most important thing for anyone writing a Z80 emulator. There
is a Z80 emulator called YAZE, by Frank Cringle,
which comes with a CP/M program called ZEX. This little proggie will test
your Z80 emulator and see how accurate it is! Definitely worth using...
|