It is currently Sun Jun 24, 2018 11:52 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Sep 06, 2016 7:07 am 
Offline

Joined: Tue May 28, 2013 5:49 am
Posts: 973
Location: Sweden
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 Y-coordinates of the sprite if I know the nametable address? The scroll register is 0.


Top
 Profile  
 
PostPosted: Tue Sep 06, 2016 7:34 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20168
Location: NE Indiana, USA (NTSC)
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.


Top
 Profile  
 
PostPosted: Tue Sep 06, 2016 8:21 am 
Offline

Joined: Tue May 28, 2013 5:49 am
Posts: 973
Location: Sweden
Thanks a lot! These formulas works like a charm!


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 4 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