8

I'm writing an emulator for the z80 CPU using the "z80 CPU User Manual" from zilog.com as reference.

When I got into the AND operator I got confused. In the Condition Bits Affected is declared "P/V is reset if overflow; otherwise, it is reset."

I've tried to research somewhere and inside the Intel 8080 manual appears that the P flag is set, but the 8080 manual is not as clear as the z80 manual.

Page 158 of the manual. Inside "8-Bit Arithmetic Group".

Does this mean that AND affects P/V, or P/V is just reset? I want to mimic the correct behaviour of the z80 CPU, I don't want to mimic the manual, but I don't have a z80 to test it.

I know that are some unexplained areas in this manual, if anyone has a better reference for this case I will appreciate it.

2
  • 2
    Welcome to Retrocomputing Stack Exchange. Thanks for the question; you might find this other question useful.
    – wizzwizz4
    Mar 25, 2017 at 17:32
  • Thank you @wizzwizz4. This differences is what im looking for.
    – h0m3
    Mar 26, 2017 at 16:18

1 Answer 1

12

Referring to this reference manual: www.zilog.com/docs/z80/um0080.pdf See the bottom of page 78:

This flag is also used with logical operations and rotate instructions to indicate the resulting parity is Even. The number of 1 bits in a byte are counted. If the total is Odd, ODD parity is flagged (P=0). If the total is Even, EVEN parity is flagged (P=1).

Their description of AND is broken just as you say, as is OR. On page 157 the description of XOR is correct.

If you want an unambiguous reference, the MAME source code is the way to go: https://github.com/mamedev/mame/tree/master/src/devices/cpu/z80

It will give you exact timings, undocumented instructions and undocumented flags.

3
  • @h0m3 MAME is unambiguous documentation of hardware in software form. The compiler understands it so there's no reason that humans shouldn't. (Unfortunately, MAME also works as an emulator so you'll really just be porting it.)
    – wizzwizz4
    Mar 26, 2017 at 18:52
  • Alternatively, Z80.NET is another open source Z80 emulator you can take a look at.
    – Konamiman
    Mar 27, 2017 at 13:19
  • 2
    MAME may be unambiguous documentation of its author's understanding of hardware in software form, but that doesn't mean that it will always behave the same way as the devices being emulated. Because the Z80 is so widely used, the authors of MAME tried to support match any aspects of its behavior upon which any program might rely, but I wouldn't expect them to use such care with every detail of every obscure hardware platform in cases that code would be unlikely to rely upon (e.g. the value read when performing a load from a device that only drives part of the data bus).
    – supercat
    Dec 3, 2018 at 21:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .