It is currently Wed Nov 14, 2018 6:40 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Wed Oct 10, 2018 2:22 pm 
Offline
User avatar

Joined: Wed Sep 05, 2018 11:13 am
Posts: 141
Location: Colorado
Is it possible to rotate a sprite by 90 degrees? Or do I need to do it in photoshop and include it in the .chr file that way?

Thanks

_________________
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com


Top
 Profile  
 
PostPosted: Wed Oct 10, 2018 2:26 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 7714
Location: Seattle
The hardware does not support rotation by 90 degrees, no. Only horizontal and vertical flips, which together are equivalent to a 180 degree rotation.


Top
 Profile  
 
PostPosted: Wed Oct 10, 2018 2:54 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 6949
Location: Canada
If you're using CHR-RAM you could write some code to rotate the sprite tile before uploading it to the PPU. This would only really be helpful if you have a lot of stuff that needs a rotated form, though. Doesn't really solve any problems of e.g. pattern table management.


Top
 Profile  
 
PostPosted: Wed Oct 10, 2018 3:27 pm 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2331
Location: DIGDUG
It'd be terribly slow.

Rotate 1 tile left 90°

LDY #0
LDX #0
Loop:
LDA Source, Y
Loop2:
LSR a
ROL Dest, X
INX
CPX #8
BNE Loop2
LDX #0
INY
CPY #8
BNE Loop
LDX #8
;x and y should be 8 now
Loop3:
LDA Source, Y
Loop4:
LSR a
ROL Dest, X
INX
CPX #16
BNE Loop4
LDX #8
INY
CPY #16
BNE Loop3

Edit, wrote the 2nd half.

Hasn't been tested. Only in my head.


Edit, and I think, rotate right 90° would be...replace LSR with ASL and ROL with ROR. (edited about 6 times)

_________________
nesdoug.com -- blog/tutorial on programming for the NES


Top
 Profile  
 
PostPosted: Wed Oct 10, 2018 4:12 pm 
Offline
User avatar

Joined: Wed Sep 05, 2018 11:13 am
Posts: 141
Location: Colorado
It sounds like the best thing to do is just rotate it 90 degrees photoshop and have 2 versions in the .chr

Thanks for your help, was just hoping there was some better way

_________________
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com


Top
 Profile  
 
PostPosted: Thu Oct 11, 2018 6:03 am 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 2331
Location: DIGDUG
It works. I made a demo, with source. Also included flip tile H and flip tile V, which were easier.

It is very slow. About 2250 cycles per tile. (and only 300 cycles for flip V).


Attachments:
ROTATE.zip [2.39 KiB]
Downloaded 47 times
ROTATE.png
ROTATE.png [ 4.46 KiB | Viewed 1786 times ]

_________________
nesdoug.com -- blog/tutorial on programming for the NES
Top
 Profile  
 
PostPosted: Thu Oct 11, 2018 6:36 am 
Offline
User avatar

Joined: Thu Aug 13, 2015 4:40 pm
Posts: 308
Location: Rio de Janeiro - Brazil
Would it make it faster to use a pre-calculated table of conversion? (I couldn't understand your code, where are you writing to?) edit: oh okay, it's the LSR and ROL. I'm rusty :)

_________________
https://twitter.com/bitinkstudios <- Follow me on twitter! Thanks!


Last edited by nesrocks on Thu Oct 11, 2018 6:52 am, edited 2 times in total.

Top
 Profile  
 
PostPosted: Thu Oct 11, 2018 6:39 am 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7568
Location: Chexbres, VD, Switzerland
I'm fairely sure at least one of the Dragon Quest/Warrior games does this (in software), could probably be 3 I don't remember. As this is a complex/slow operation they probably do it when loading the graphics on the screen, not on the fly.


Top
 Profile  
 
PostPosted: Thu Oct 11, 2018 10:38 am 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 7714
Location: Seattle
dougeff wrote:
It is very slow. About 2250 cycles per tile.
A partial unroll (replacing the inner X: lsr A / rol $0300,x / inx / cpx #8 / bne X) speeds up each row from 127 cycles to 64 cycles, speeding it up in total to just 1242 cycles.


Top
 Profile  
 
PostPosted: Thu Oct 11, 2018 11:15 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 6949
Location: Canada
I would only think it should be useful if you need to mass rotate a bunch of tiles, e.g. if you wanted to rotate your world map or something like that. Could save a bunch of ROM space, maybe. Wasn't really suggesting it as a realtime effect, though that's not entirely out of the question.


Top
 Profile  
 
PostPosted: Thu Oct 11, 2018 1:00 pm 
Offline
User avatar

Joined: Thu Mar 31, 2016 11:15 am
Posts: 418
It could be useful for CHR compression algorithms I suppose.


Top
 Profile  
 
PostPosted: Thu Oct 11, 2018 1:32 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 20766
Location: NE Indiana, USA (NTSC)
JRoatch's Donut codec, developed for a forthcoming version of Action 53, has a rotation mode. But it's not for reusing the same tile in unrotated and 90 degree rotated modes; it's for handling non-tile data in CHR ROM.


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: Haruka and 3 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