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?

## Help with 16 bit compare. is it even possible?

**Moderator:** Moderators

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

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.

P.S. If you don't get this note, let me know and I'll write you another.

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

Quietust wrote: ↑Mon Apr 06, 2020 8:42 amAt its most basic level, comparing two numbers is really justsubtractingone 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.

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

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

I continually refer to this excellent article on the subject:

Beyond 8-bit Unsigned Comparisons by Bruce Clark

Beyond 8-bit Unsigned Comparisons by Bruce Clark

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

Same. That's a great page.rainwarrior wrote: ↑Mon Apr 06, 2020 8:13 pmI continually refer to this excellent article on the subject:

Beyond 8-bit Unsigned Comparisons by Bruce Clark