News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

Zero flag issue

Started by IndyUK, 15:51, 01 November 20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

IndyUK

Hi folks
Hope you're all doing well and keeping safe. I need some help with understanding the following piece of code;



ld de,&edaf
;ld de,&c04e
xor a

inc de
ld   a,e
and  &7

ret  nz



I'm using this piece of logic in my sprite handling routine to help detect if any of the pixels being plotted end up on a new character (row) line due to screen wrap on the x-axis. It all seemed to be working until I randomly placed my sprite on an xpos of 15 pixels (away from any screen wrap) and then noticed the zeroing of the Z bit didn't work. For example - If I use &edaf as the start screen address the Z flag is not set to 0, however &c04e works fine. In fact what I also saw was if set the xpos to any value which is a multiple of 15 (20, 45, 60 etc.) this logic fails.

I just don't understand why this is the case. Can anyone see what is wrong or suggest an alternative approach?
Thanks

andycadley

0xAF + 1 = 0xB0
0xB0 AND 7 = 0


So RET NZ will not return


0x4E + 1 = 0x4F
0x4F AND 7 = 7


So RET NZ will return

IndyUK

Quote from: andycadley on 18:45, 01 November 20
0xAF + 1 = 0xB0
0xB0 AND 7 = 0


So RET NZ will not return


0x4E + 1 = 0x4F
0x4F AND 7 = 7


So RET NZ will return

Hi

Thanks for the explanation but, could you please explain what is being checked when "anding" the value? I have to admit I didn't come up with this logic myself. I looked through the firmware disassembly for &BC20 and noticed how it was checking for the next character line and compensating. I simply adapted some of it's code for my needs and it appeared to work until I discovered the issue. Maybe there is no workaround and I just have to accept the quirks (more likely my limitations) of what I'm trying to do. Trying to write an all-in-one sprite plotting routine in which I try and cater for wrapping and clipping is probably getting too complicated to do as one piece of code. I still have transparency to incorporate and God only knows what fun and games that's going to be.

Thanks

robcfg

The and is used to 'mask' the bits the bits you want to compare and rule the rest out by setting them to zero.


That code means that you're looking for the three lowest bits on the byte to be 1 (1+2+4 = 7) regardless of the value on the upper 5 bits.

Powered by SMFPacks Menu Editor Mod