It is currently Tue Nov 13, 2018 5:07 pm

 All times are UTC - 7 hours

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Odd / Even issuePosted: Tue Feb 17, 2015 2:15 pm

Joined: Tue Jul 01, 2014 4:02 pm
Posts: 321
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

 Post subject: Re: Odd / Even issuePosted: Tue Feb 17, 2015 2:21 pm

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3676
Location: Mountain View, CA
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

 Post subject: Re: Odd / Even issuePosted: Tue Feb 17, 2015 2:24 pm

Joined: Tue Jul 01, 2014 4:02 pm
Posts: 321
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

 Post subject: Re: Odd / Even issuePosted: Wed Feb 18, 2015 9:37 am

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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 4 posts ]

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: No registered users and 3 guests

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

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2018 NESdev Competition       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki