I'm working on a routine for an Atari 2600 game. The portion of the code is the 192 visible scanlines. I'm attempting to achieve a visual effect by updating the background every other scanline.
The scanline loop simply counts from 192 to 0. In this scheme, #192 represents the top line, #0 the bottom or last line. It seems that there should be a way to determine odd / even numbers to accomplish this. I'm not sure if this is considered "parity" or not, but I haven't found the right flag for odds / evens.
Looking for a quick way to find odd / even numbers
- Johnny Starr
- Posts: 58
- Joined: 30 May 2012
- Location: Dallas, TX
- Contact:
Re: Looking for a quick way to find odd / even numbers
Johnny Starr wrote:
I'm working on a routine for an Atari 2600 game. The portion of the code is the 192 visible scanlines. I'm attempting to achieve a visual effect by updating the background every other scanline.
The scanline loop simply counts from 192 to 0. In this scheme, #192 represents the top line, #0 the bottom or last line. It seems that there should be a way to determine odd / even numbers to accomplish this. I'm not sure if this is considered "parity" or not, but I haven't found the right flag for odds / evens.
The scanline loop simply counts from 192 to 0. In this scheme, #192 represents the top line, #0 the bottom or last line. It seems that there should be a way to determine odd / even numbers to accomplish this. I'm not sure if this is considered "parity" or not, but I haven't found the right flag for odds / evens.
Edit: But from the sounds of it you just want to update all the even lines (say) then the odd ones. It is so simple I must be misunderstanding, but can't you simply add 2 on each loop iteration?
8 bit fun and games: https://www.aslak.net/
- BigDumbDinosaur
- Posts: 9428
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: Looking for a quick way to find odd / even numbers
Johnny Starr wrote:
I'm working on a routine for an Atari 2600 game. The portion of the code is the 192 visible scanlines. I'm attempting to achieve a visual effect by updating the background every other scanline.
The scanline loop simply counts from 192 to 0. In this scheme, #192 represents the top line, #0 the bottom or last line. It seems that there should be a way to determine odd / even numbers to accomplish this. I'm not sure if this is considered "parity" or not, but I haven't found the right flag for odds / evens.
The scanline loop simply counts from 192 to 0. In this scheme, #192 represents the top line, #0 the bottom or last line. It seems that there should be a way to determine odd / even numbers to accomplish this. I'm not sure if this is considered "parity" or not, but I haven't found the right flag for odds / evens.
Code: Select all
lda scanline ;current scan line number
lsr a ;shift bit 0 to carry
bcc is_even ;even number
bcs is_odd ;odd numberCode: Select all
lda scanline ;current scan line number
bit #%00000001 ;is bit 0 set?
beq is_even ;no, even number
bne is_odd ;yes, odd numberx86? We ain't got no x86. We don't NEED no stinking x86!
- Johnny Starr
- Posts: 58
- Joined: 30 May 2012
- Location: Dallas, TX
- Contact:
Re: Looking for a quick way to find odd / even numbers
Of course! Shift right, check carry. That's what I get for overthinking it huh?
- GARTHWILSON
- Forum Moderator
- Posts: 8774
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: Looking for a quick way to find odd / even numbers
or AND#1, BNE/BEQ. The AND# takes 2 clocks, and if the conditional branch is not taken, it's 2 more, or if the branch is taken, it's usually 3 more instead of 2. You can probably get away with one branch instruction, as the drop-thru is automatically the other condition.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
- BigDumbDinosaur
- Posts: 9428
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: Looking for a quick way to find odd / even numbers
GARTHWILSON wrote:
or AND#1, BNE/BEQ. The AND# takes 2 clocks, and if the conditional branch is not taken, it's 2 more, or if the branch is taken, it's usually 3 more instead of 2. You can probably get away with one branch instruction, as the drop-thru is automatically the other condition.
x86? We ain't got no x86. We don't NEED no stinking x86!
Re: Looking for a quick way to find odd / even numbers
But you can't do that on a proper 6502!
-
teamtempest
- Posts: 443
- Joined: 08 Nov 2009
- Location: Minnesota
- Contact:
Re: Looking for a quick way to find odd / even numbers
If all you're interested in is odd/even and not the particular scanline, you can do this on all 65xx-family processors:
It's not as fast as load-and-shift, though.
BTW, 0..192 is 193 lines, not 192. Just sayin'.
Code: Select all
LDA #%00000001
BIT scanline
BEQ doeven
BNE do odd
BTW, 0..192 is 193 lines, not 192. Just sayin'.
- BigDumbDinosaur
- Posts: 9428
- Joined: 28 May 2009
- Location: Midwestern USA (JB Pritzker’s dystopia)
- Contact:
Re: Looking for a quick way to find odd / even numbers
BigEd wrote:
But you can't do that on a proper 6502!
x86? We ain't got no x86. We don't NEED no stinking x86!
-
White Flame
- Posts: 704
- Joined: 24 Jul 2012
Re: Looking for a quick way to find odd / even numbers
If you store the value 1 to a zero page memory location const1, then you can do "BIT const1" to perform the test without modifying the accumulator on ye olde 6502.
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: Looking for a quick way to find odd / even numbers
I was thinking the same thing, White Flame. Or just find a 1 somewhere in your program or the firmware ... there are bound to be several. Code-as-constants is a tried-and-true tradition in the 65xx world, even more so than self-modifying.
Mike
Mike