News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

How do you test for NC?

Started by IndyUK, 21:48, 01 July 20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

IndyUK

Hi Folks

I need a little help please. I'm converting my current sprite routine to use the Stack to plot to the screen. That's kind of working fine but, I do have a problem. I use a bit of code to test if one of my inner loops has reached the end of the scanline. This is so I can check if I need to proceed to the next scanline (in this case previous because we're working in reverse due to using the Stack) of the sprite. This approach worked absolutely perfectly with my non-Stack version, however, when I try and use the following in the new version, the logic check never seems to work. Here's the code I'm using;

xor a          ;this block checks to see if we have reached the end of the scanline
ld a,40       ;load value 40 into A
sub c         ;deduct A from the C register (contains the current width count)
jr nc,skip   ;if no-carry occurs, then the number in C was wholly divisible by 40, meaning we reached the end of the scanline


Using the inbuilt debugger in WinApe I can see the NC flag does get set (11 under NC) but, my jump never works. Because this never fires the plotting is garbled. I don't know if it's my code that isn't correct or my lack of knowledge of how the NC flag should be interpreted. I would appreciate any help.

Thanks

dthrone

One thing to note is that sub c deducts C from the A register not vice versa unless it's just your comments that are incorrect  ;)

Axelay

In addition to what dthrone mentioned, also note that 'NC' in the flags indicator in the Winape debugger is not 'No Carry'.


The 'N' is the add/subtract flag (set to 1 if the previous operation was a subtract).


The 'C' is the carry flag.  Carry is set to 1 if there is overflow from the last instruction to affect the flag, so where you are seeing a 1 in the carry flag, carry is set, and so a test for NC will be false.  It will not make your NC jump unless you see a 0 in the carry flag.

IndyUK

Hi Guys,

I would like to thank both of you.

Quote from: dthrone on 00:25, 02 July 20
One thing to note is that sub c deducts C from the A register not vice versa unless it's just your comments that are incorrect  ;)
You were absolutely right, I had thought that A was being deducted from C. Thanks for claifying this

Quote from: Axelay on 13:57, 02 July 20
In addition to what dthrone mentioned, also note that 'NC' in the flags indicator in the Winape debugger is not 'No Carry'.


The 'N' is the add/subtract flag (set to 1 if the previous operation was a subtract).


The 'C' is the carry flag.  Carry is set to 1 if there is overflow from the last instruction to affect the flag, so where you are seeing a 1 in the carry flag, carry is set, and so a test for NC will be false.  It will not make your NC jump unless you see a 0 in the carry flag.
Thanks for clearing this up for me. I always struggled with getting my head around this because I always assumed the labels NC were working in tandem. Hopefully I can now go back to my code and get it working.


Once again, thanks for helping.

Powered by SMFPacks Menu Editor Mod