SCF and CCF z80 instructions

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
Morkin
Bugaboo
Posts: 3270
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

SCF and CCF z80 instructions

Post by Morkin »

Ok, so similar to the "there's a hover key in Jetpac??" revelation, where everyone rolls their eyes in a 'didn't you know that already?' sort of way...

...I've just read that the CCF instruction doesn't actually 'clear the carry flag', but toggles it.

Is this right? If so, does it mean that every time you want use the instruction to clear the carry flag, you would have to:

SCF
CCF

(P.S. If someone now tells me that I was wrong about SCF as well, I'm going to assume that I've entered the matrix...)
My Speccy site: thirdharmoniser.com
catmeows
Manic Miner
Posts: 716
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Re: SCF and CCF z80 instructions

Post by catmeows »

You are right, CCF switches CY flag. But to clear CY, you can use OR A, AND A. They affect Z flag too.
Proud owner of Didaktik M
catmeows
Manic Miner
Posts: 716
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Re: SCF and CCF z80 instructions

Post by catmeows »

Morkin wrote: Tue May 26, 2020 1:30 pm Ok, so similar to the "there's a hover key in Jetpac??" revelation, where everyone rolls their eyes in a 'didn't you know that already?' sort of way...
Wait... What hover key are you talking about ? Please, tell me you are joking.
There is no hover key in Jetpac. I KNOW there is no such key in Jetpac.
Proud owner of Didaktik M
User avatar
Lethargeek
Manic Miner
Posts: 742
Joined: Wed Dec 11, 2019 6:47 am

Re: SCF and CCF z80 instructions

Post by Lethargeek »

catmeows wrote: Tue May 26, 2020 1:42 pm
Morkin wrote: Tue May 26, 2020 1:30 pm Ok, so similar to the "there's a hover key in Jetpac??" revelation, where everyone rolls their eyes in a 'didn't you know that already?' sort of way...
Wait... What hover key are you talking about ? Please, tell me you are joking.
There is no hover key in Jetpac. I KNOW there is no such key in Jetpac.
but there IS a hover key in Jetpac :mrgreen: (unlike Santa, who does not exist) :twisted:
catmeows
Manic Miner
Posts: 716
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Re: SCF and CCF z80 instructions

Post by catmeows »

I have no words. I will ve back later to ask what key it is then. But now I have to contemplate about fact I lived for more than thirty years in a lie.
Proud owner of Didaktik M
Dr beep
Manic Miner
Posts: 381
Joined: Mon Oct 01, 2018 8:53 pm

Re: SCF and CCF z80 instructions

Post by Dr beep »

To reset carry I just do 1 of these:
AND A
OR A
CP A
Andrew771
Drutt
Posts: 42
Joined: Mon May 04, 2020 9:59 pm
Location: Moscow, Russia

Re: SCF and CCF z80 instructions

Post by Andrew771 »

For completeness: XOR A is reset A instead of long LD A,0 ;)
Coder of ZXOOM, Euphoria 2D, ZX Like Pascal, Russian Railway Magnate...
dfzx
Manic Miner
Posts: 681
Joined: Mon Nov 13, 2017 6:55 pm
Location: New Forest, UK
Contact:

Re: SCF and CCF z80 instructions

Post by dfzx »

Morkin wrote: Tue May 26, 2020 1:30 pm ...I've just read that the CCF instruction doesn't actually 'clear the carry flag', but toggles it.

Is this right?
I hit that exact issue when looking at the Z88DK display handling code just a few weeks ago. I was patiently corrected by the guys in the Z88DK support forum. Still felt a bit stupid though. :)
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2641
Joined: Mon Nov 13, 2017 3:16 pm

Re: SCF and CCF z80 instructions

Post by Ast A. Moore »

Morkin wrote: Tue May 26, 2020 1:30 pm I've just read that the CCF instruction doesn't actually 'clear the carry flag', but toggles it.
Indeed. The first C stands for “complement,” not “clear.”
Last edited by Ast A. Moore on Tue May 26, 2020 3:49 pm, edited 1 time in total.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
User avatar
Morkin
Bugaboo
Posts: 3270
Joined: Mon Nov 13, 2017 8:50 am
Location: Bristol, UK

Re: SCF and CCF z80 instructions

Post by Morkin »

Ah, that's it... 'Complement'...

Always wondered why people were more inclined to do things like OR A, as it seemed to affect other stuff a bit more that could potentially give me future debugging headaches. But now I know...
My Speccy site: thirdharmoniser.com
Andrew771
Drutt
Posts: 42
Joined: Mon May 04, 2020 9:59 pm
Location: Moscow, Russia

Re: SCF and CCF z80 instructions

Post by Andrew771 »

Morkin wrote: Tue May 26, 2020 3:35 pm Always wondered why people were more inclined to do things like OR A, as it seemed to affect other stuff a bit more that could potentially give me future debugging headaches. But now I know...
AND A not only resets the flag Z, but is used instead CP 0
Coder of ZXOOM, Euphoria 2D, ZX Like Pascal, Russian Railway Magnate...
Post Reply