6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Sep 29, 2024 4:25 am

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Mon Mar 10, 2014 7:13 pm 
Offline
User avatar

Joined: Wed May 30, 2012 7:45 pm
Posts: 58
Location: Dallas, TX
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.

_________________
http://www.thestarrlab.com


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 10, 2014 7:37 pm 
Offline

Joined: Mon Aug 05, 2013 10:43 pm
Posts: 258
Location: Southampton, UK
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.


Parity is a count of the number of set bits. For oddness/eveness, just test the lowest bit. If it is 0, it's even. if it is 1 it is odd.

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/


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 10, 2014 7:43 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8405
Location: Midwestern USA
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.

It's very simple:

Code:
         lda scanline          ;current scan line number
         lsr a                 ;shift bit 0 to carry
         bcc is_even           ;even number
         bcs is_odd            ;odd number

Alternatively, with the 65C02/65C816:

Code:
         lda scanline          ;current scan line number
         bit #%00000001        ;is bit 0 set?
         beq is_even           ;no, even number
         bne is_odd            ;yes, odd number

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 10, 2014 8:06 pm 
Offline
User avatar

Joined: Wed May 30, 2012 7:45 pm
Posts: 58
Location: Dallas, TX
Of course! Shift right, check carry. That's what I get for overthinking it huh?

_________________
http://www.thestarrlab.com


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 10, 2014 8:35 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8521
Location: Southern California
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?


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 10, 2014 9:39 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8405
Location: Midwestern USA
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.

BIT immediate is the least destructive and produces the same result.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 10, 2014 10:47 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
But you can't do that on a proper 6502!


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 11, 2014 2:45 am 
Offline

Joined: Sun Nov 08, 2009 1:56 am
Posts: 398
Location: Minnesota
If all you're interested in is odd/even and not the particular scanline, you can do this on all 65xx-family processors:

Code:
  LDA #%00000001
  BIT  scanline
  BEQ doeven
  BNE do odd


It's not as fast as load-and-shift, though.

BTW, 0..192 is 193 lines, not 192. Just sayin'.


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 11, 2014 4:57 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8405
Location: Midwestern USA
BigEd wrote:
But you can't do that on a proper 6502!

Right. I was thinking 'C02 or '816. BIT immediate is one of the many reasons to not use the NMOS 6502 if you have a choice.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 12, 2014 4:57 am 
Offline

Joined: Tue Jul 24, 2012 2:27 am
Posts: 674
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.

_________________
WFDis Interactive 6502 Disassembler
AcheronVM: A Reconfigurable 16-bit Virtual CPU for the 6502 Microprocessor


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 12, 2014 3:24 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1948
Location: Sacramento, CA, USA
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: