It is currently Sat Oct 21, 2017 5:24 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Odd / Even issue
PostPosted: Tue Feb 17, 2015 2:15 pm 
Offline

Joined: Tue Jul 01, 2014 4:02 pm
Posts: 254
So for this one part of my collision detection routine, I am essentially trying to find out where the point of contact will be on the 8x8 px grid, and then compare it to bits 7-4 of the tile byte, which represents a 16x16px area (each bit corresponding to a 'quadrant'). Seems pretty logical.

The method was to get the tile info on the 16x16px grid (working fine) and then load the newPosition data on a 32x32px grid and determine whether the position falls on an even numbered tile or odd numbered tile on that grid, which will determine whether to look at bytes 7 and 6 or 5 and 4 for horizontal collision data.

So I do this:

Code:

     LDA newPositionX   ; x position of player + playerSpeed...the new potential position
     ASL A                      ; divide by 32 to get spot on the 8px grid
     ASL A
     ASL A
     ASL A
     ASL A
     STA tileCollsionX   ; store it into this variable

........


     LDA tileCollisionX ; load the variable
     AND #%00000001 ; 'zero' all the bits except the last one
                                   ;logically, a zero and one AND witha resulting zero, so
                                   ;if the last bit is zero, this will return zero...if it's one, this will return one.
     BEQ itIsEven           ; if the last bit is zero, that means it must be aligned on an even tile.  If a 1, an odd tile.
     ;;do whatever if it is odd.
itIsEven:
     ;;do whatever if it is even.




...however, this ALWAYS seems to return even. Anyone see a fundamental problem with my understanding here?



EDIT: Wow....nevermind. All I needed to do was 'write it out' to figure out that should be LSR and not ASL. *smacks forehead*


Top
 Profile  
 
 Post subject: Re: Odd / Even issue
PostPosted: Tue Feb 17, 2015 2:21 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3192
Location: Mountain View, CA, USA
Three things:

1. ASL is for multiplication, LSR is for divide. Your comment says divide by, but you're using ASL. Think about what does bit-wise. ASL means shift LEFT, e.g. starting with a value of 2:

%00000010 (2) << 1 == %00000100 (4)
%00000100 (4) << 1 == %00001000 (8)
%00001000 (8) << 1 == %00010000 (16)
...etc..

LSR is the opposite of that.

2. Your lda/and/beq is correct -- meaning it does exactly what your comments say it does. It masks off bits 7-1, leaving bit 0 intact. If the result is 0, then the beq will be taken, otherwise it won't be. Where I come from ( :-) ), 0 == even number, 1 == odd number.

3. Don't forget that the code that runs if the beq isn't taken needs to have a jmp or bra or rts or something to ensure the code under itIsEven doesn't get run. You probably know this but just want to make sure since the code in question doesn't show it (probably just a quick copy/paste job, no biggie).


Top
 Profile  
 
 Post subject: Re: Odd / Even issue
PostPosted: Tue Feb 17, 2015 2:24 pm 
Offline

Joined: Tue Jul 01, 2014 4:02 pm
Posts: 254
Thanks - yeah...as soon as I looked at it posted I chuckled. Wow. I've been looking at code too long today, that's the ultimate sign. haha.

Thanks for the input, though! :-) Glad to know my method isn't completely crazy. haha

3. And yeah, the actual code has an RTS there. Thanks!


Top
 Profile  
 
 Post subject: Re: Odd / Even issue
PostPosted: Wed Feb 18, 2015 9:37 am 
Offline
User avatar

Joined: Sun Jan 02, 2011 11:50 am
Posts: 522
Small suggestion:
Use a ROR then branch on the carry to check bit 0. (Unless it helps you later to have the result of that test in the accumulator.)


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 6 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:  
Powered by phpBB® Forum Software © phpBB Group