nesdev.com http://forums.nesdev.com/ 

Calculate sprite coordinates on the nametable http://forums.nesdev.com/viewtopic.php?f=10&t=14788 
Page 1 of 1 
Author:  Pokun [ Tue Sep 06, 2016 7:07 am ] 
Post subject:  Calculate sprite coordinates on the nametable 
Let's say I want to draw a 8x8 sprite so that it exactly covers a 8x8 BG tile. Is there an easy way to calculate the X and Ycoordinates of the sprite if I know the nametable address? The scroll register is 0. 
Author:  tepples [ Tue Sep 06, 2016 7:34 am ] 
Post subject:  Re: Calculate sprite coordinates on the nametable 
X coordinate: (((address << 3) & 0xF8)  camera_x) % 256 Y coordinate: (((address >> 2) & 0xF8)  (camera_y + 1)) % 240 A simplification is possible if your scroll position is (0, 0), as you mentioned: X coordinate: (address << 3) & 0xF8 Y coordinate: ((address >> 2) & 0xF8)  1 Translation of these expressions from C to 6502 assembly code is an exercise for the reader. 
Author:  Pokun [ Tue Sep 06, 2016 8:21 am ] 
Post subject:  Re: Calculate sprite coordinates on the nametable 
Thanks a lot! These formulas works like a charm! 
Page 1 of 1  All times are UTC  7 hours 
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ 