Here is a tip for Z80 programmers. At some time, you may find that you need to manipulate the flags register. This is usually done using the set, reset and bit instructions (for looking). The trouble comes when you want to alter the flags. The following sequence should help:
PUSH AF; Store AF on stack
POP BC; Load BC from stack, getting AF in process
Manipulate C as required since it contains the Flag register.
PUSH BC; Stack BC
POP AF; and return to Flag reg
NB: BC can be any of the double registers.