It is currently Mon Sep 24, 2018 10:31 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: 1008
Location: Hokkaido, Japan
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: 20570
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: 1008
Location: Hokkaido, Japan
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: battagline and 5 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