Scratchpad

If you are new to Scratchpad, and want full access as a Scratchpad editor, create an account!
If you already have an account, log in and have fun!!

READ MORE

Scratchpad
(Bits 3 and 5 of F)
Line 19: Line 19:
 
Woody confirmed that bits 3 and 5 of the flags are copied on all BIT instructions on both a Zilog Z80 and an NEC clone (stated on the link above as being "unverified").
 
Woody confirmed that bits 3 and 5 of the flags are copied on all BIT instructions on both a Zilog Z80 and an NEC clone (stated on the link above as being "unverified").
   
Patrik Rak [http://www.worldofspectrum.org/forums/showthread.php?p=666561 has discovered] that the way bits 3 and 5 of the F register are set depends on a hidden 'Q' register, which is updated with the new value of F whenever F changes, but is cleared to 0 otherwise. The Q register is also cleared to 0 whenever an interrupt is taken (at least in IM2).  Bits 3 and 5 are updated according to (Q XOR F) + A. After execution of an instruction that does not update flags, Q XOR F = 0 XOR F and therefore bits 3 and 5 are updated with F + A. After execution of an instruction that does update flags, Q XOR F = F XOR F = 0 and therefore bits 3 and 5 are updated with A.
+
Patrik Rak [http://www.worldofspectrum.org/forums/showthread.php?p=666561 has discovered] that the way bits 3 and 5 of the F register are set depends on a hidden 'Q' register, which is updated with the new value of F whenever F changes, but is cleared to 0 otherwise. The Q register is also cleared to 0 whenever an interrupt is taken (at least in IM2).  Bits 3 and 5 are updated according to (Q XOR F) + A. After execution of an instruction that does not update flags, Q XOR F = 0 XOR F = F and therefore bits 3 and 5 are updated with F + A. After execution of an instruction that does update flags, Q XOR F = F XOR F = 0 and therefore bits 3 and 5 are updated with A.
   
 
Stuart Brady discovered that how bits 3 and 5 of the flags are set after the SCF and CCF instructions actually depends on the variant of Z80 in use. On a Zilog Z80, bits 3 and 5 of the flags were set by ORing their previous values with that of A. On an NEC clone, bit 3 was unaffected, while bit 5 appears to be set by ANDing the previous value with something unknown. Previously, Ian Greenway tested this and found that bits 3 and 5 seemed simply to be copied from A, although it is not known which CPU these tests were run on. For more details, see [http://sourceforge.net/mailarchive/forum.php?thread_name=20040217082529.GH17981%40philos.lan.philosys.de&forum_name=fuse-emulator-devel here], [http://sourceforge.net/mailarchive/forum.php?thread_name=20070522223156.GA12009%40miranda.arrow&forum_name=fuse-emulator-devel here] and a more recent investigation [http://groups.google.co.uk/group/comp.sys.sinclair/msg/56dd1fd4ccb5fb3b here].
 
Stuart Brady discovered that how bits 3 and 5 of the flags are set after the SCF and CCF instructions actually depends on the variant of Z80 in use. On a Zilog Z80, bits 3 and 5 of the flags were set by ORing their previous values with that of A. On an NEC clone, bit 3 was unaffected, while bit 5 appears to be set by ANDing the previous value with something unknown. Previously, Ian Greenway tested this and found that bits 3 and 5 seemed simply to be copied from A, although it is not known which CPU these tests were run on. For more details, see [http://sourceforge.net/mailarchive/forum.php?thread_name=20040217082529.GH17981%40philos.lan.philosys.de&forum_name=fuse-emulator-devel here], [http://sourceforge.net/mailarchive/forum.php?thread_name=20070522223156.GA12009%40miranda.arrow&forum_name=fuse-emulator-devel here] and a more recent investigation [http://groups.google.co.uk/group/comp.sys.sinclair/msg/56dd1fd4ccb5fb3b here].

Revision as of 22:06, 14 March 2014

For technical information on the Z80, three very good resources are:

A basic Flags test program for emulators is available here. Note that the program makes heavy use of ROM data during the tests and so should only be used with an unpatched copy of the original 48K ROM to obtain correct results.

A Z80 instruction exerciser, ZEXALL2, originally by Frank D. Cringle and updated for the Spectrum initially by J.G.Harston and later by Patrik Rak is available here.

OUT (C),0 / OUT (C),255 Instruction

In 1996, Simon Cooke noted in a Usenet posting that the undocumented instruction usually referred to as 'OUT (C),0' behaves instead as 'OUT (C),255' on CMOS Z80s.

Later, in 2004, Colin Piggot rediscovered this with his own SAM Coupé, when running a demo for SCPDU 6, coincidentally written by Simon Cooke. With the CMOS Z80, a white background colour was set over part of the screen in the demo. This was described in SAM Revival Issue 9 (March/April 2004).

In 2008, this was once again rediscovered by the MSX community.

Bits 3 and 5 of the F Register

Woody confirmed that bits 3 and 5 of the flags are copied on all BIT instructions on both a Zilog Z80 and an NEC clone (stated on the link above as being "unverified").

Patrik Rak has discovered that the way bits 3 and 5 of the F register are set depends on a hidden 'Q' register, which is updated with the new value of F whenever F changes, but is cleared to 0 otherwise. The Q register is also cleared to 0 whenever an interrupt is taken (at least in IM2).  Bits 3 and 5 are updated according to (Q XOR F) + A. After execution of an instruction that does not update flags, Q XOR F = 0 XOR F = F and therefore bits 3 and 5 are updated with F + A. After execution of an instruction that does update flags, Q XOR F = F XOR F = 0 and therefore bits 3 and 5 are updated with A.

Stuart Brady discovered that how bits 3 and 5 of the flags are set after the SCF and CCF instructions actually depends on the variant of Z80 in use. On a Zilog Z80, bits 3 and 5 of the flags were set by ORing their previous values with that of A. On an NEC clone, bit 3 was unaffected, while bit 5 appears to be set by ANDing the previous value with something unknown. Previously, Ian Greenway tested this and found that bits 3 and 5 seemed simply to be copied from A, although it is not known which CPU these tests were run on. For more details, see here, here and a more recent investigation here.

Replacement Z80s

If you're looking for a replacement Z80 for a duff one currently in a Spectrum, these aren't hard to source as the Z80 is still manufactured by Zilog. In the UK, one source are Farnell, where you want their part number 1081890.