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
The hardware does not support rotation by 90 degrees, no. Only horizontal and vertical flips, which together are equivalent to a 180 degree rotation.
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.
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)
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
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).
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
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.
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.
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.
It could be useful for CHR compression algorithms I suppose.
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.