Author Topic: Zero flag issue  (Read 936 times)

0 Members and 1 Guest are viewing this topic.

Offline IndyUK

  • CPC464
  • **
  • Posts: 22
  • Country: gb
  • Liked: 3
  • Likes Given: 2
Zero flag issue
« on: 16:51, 01 November 20 »
Hi folks
Hope you're all doing well and keeping safe. I need some help with understanding the following piece of code;

Code: [Select]

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

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.003
  • Liked: 487
  • Likes Given: 82
Re: Zero flag issue
« Reply #1 on: 19: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

Offline IndyUK

  • CPC464
  • **
  • Posts: 22
  • Country: gb
  • Liked: 3
  • Likes Given: 2
Re: Zero flag issue
« Reply #2 on: 11:15, 02 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

Offline robcfg

  • Supporter
  • 6128 Plus
  • *
  • Posts: 2.423
  • Country: se
  • 8-Bit Technomancer
    • index.php?action=treasury
  • Liked: 1102
  • Likes Given: 2685
Re: Zero flag issue
« Reply #3 on: 12:48, 02 November 20 »
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.