Help with 16 bit compare. is it even possible?

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
bjones
Posts: 19
Joined: Mon Apr 29, 2019 4:34 pm

Help with 16 bit compare. is it even possible?

Post by bjones » Mon Apr 06, 2020 6:33 am

So basically this has to do with drawing or not drawing sprites. The problem is that i cannot think of good way to compare 16bit positions.
For example:

the current camera spans from X high: 1 and X low 100 which makes the edge of the screen X high: 2 to X low: 100.

my current draw routine cannot accoiunt for half of the sprites being at X high: 1 and X low 248 and the others at X high:2 and X low 00.

Is there a way to actual compare 16bit numbers without having long braches?

User avatar
Quietust
Posts: 1555
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Help with 16 bit compare. is it even possible?

Post by Quietust » Mon Apr 06, 2020 8:42 am

At its most basic level, comparing two numbers is really just subtracting one from the other and checking if the result is positive, negative, or zero, and multi-byte subtraction is trivial on the 6502:

Code: Select all

SEC             # initialize carry flag to 1 for subtraction
LDA var1+0
SBC var2+0      # subtract the lowest byte first
STA result+0
LDA var1+1
SBC var2+1      # then subtract the next byte using the carry output from the previous byte
STA result+1
...             # and so forth
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.

bjones
Posts: 19
Joined: Mon Apr 29, 2019 4:34 pm

Re: Help with 16 bit compare. is it even possible?

Post by bjones » Mon Apr 06, 2020 11:21 am

Quietust wrote:
Mon Apr 06, 2020 8:42 am
At its most basic level, comparing two numbers is really just subtracting one from the other and checking if the result is positive, negative, or zero, and multi-byte subtraction is trivial on the 6502:

Code: Select all

SEC             # initialize carry flag to 1 for subtraction
LDA var1+0
SBC var2+0      # subtract the lowest byte first
STA result+0
LDA var1+1
SBC var2+1      # then subtract the next byte using the carry output from the previous byte
STA result+1
...             # and so forth

as usual i figured it out as soon as i posted lol!

I was converting the sprites to screen space after doing the caculations instead of before.
This caused a glitch whenever sprites where moving across high bits.

User avatar
rainwarrior
Posts: 7812
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Help with 16 bit compare. is it even possible?

Post by rainwarrior » Mon Apr 06, 2020 8:13 pm

I continually refer to this excellent article on the subject:

Beyond 8-bit Unsigned Comparisons by Bruce Clark

turboxray
Posts: 75
Joined: Thu Oct 31, 2019 12:56 am

Re: Help with 16 bit compare. is it even possible?

Post by turboxray » Thu Apr 09, 2020 12:25 am

rainwarrior wrote:
Mon Apr 06, 2020 8:13 pm
I continually refer to this excellent article on the subject:

Beyond 8-bit Unsigned Comparisons by Bruce Clark
Same. That's a great page.

Post Reply