| |
Trap
Registered: Jul 2010 Posts: 223 |
checking multiple conditions
Hi,
Still trying to get up to speed. So, I have this boundary check I want to do. For some reason it is turning out to be a struggle.
I want to do an upper and lower boundary check on a set of coordinates. I can have the plot anywhere, so the boundary check must take into account that the plot can be way out of boundary.
For some reason I can't get around it - my memory is not serving me well right now.
I have a currentpos and I want to compare it to a lower and upper boundary. If it is out of bounds I want to branch.
Any help is appreciated.
Trap |
|
| |
Oswald
Registered: Apr 2002 Posts: 5094 |
http://www.6502.org/tutorials/compare_instructions.html
see the part:
"Use of Branch Instructions with Compare" |
| |
Trap
Registered: Jul 2010 Posts: 223 |
Awesome. Thanks Oswald.
Another great website added to the list :)
Trap |
| |
null Account closed
Registered: Jun 2006 Posts: 645 |
ldx currentpos
cpx boundry_x
bpl main
cpx boundry_y
bpl main
;--- plot stuff here ---
jmp main
Okay, maybe that's not the best way to do it, if it works at all, but... yeah.
edit: whoops, I'm a bit late. And I think wrong as well. oh well. You can still laugh at me. ;_)
------------------------------------
http://zomgwtfbbq.info |
| |
Fresh
Registered: Jan 2005 Posts: 101 |
The easiest solution is:
check: lda coord
cmp lower
bcc out
cmp upper
bcs out
...
out: ...
but this code does an asymmetric check (lower<=coord<upper).
You can instead use this:
check: lda coord
cmp upper
bcs out
sbc lower
bcc out
adc lower
...
out: ...
Which checks if lower<coord<Upper. |