Rotating a tile map
in The Brewery
06/14th/2014 Update
Challenge accomplished using a neutral background and changing the sprites positions instead of rotating the background itself. See last post.

I leave the original post here below:
---
Hi all,
I tried to ask this question in the "Ask all programming questions here!" thread, but I had tough luck.
I would like to know if, starting from the code below I learned from NN, it is possible to "rotate" a portion
of the background tiles on screen; for example, from something like this:

get the green and red sections "rotating" (changing their position) 90° right or left pushing a specific
button, which in this case would mean have the green tiles moving on top or bottom of the area
(rotating left or right), switching squares of 16x16px or 32x32px (it doesn't matter) positions.
The tiles appearance doesn't need to be rotated (what is up in the tile image, can still up: also
if the tile changed position rotating right or left its own pattern doesn't change).
On the other thread I posted further images on the concept. The tiles outside that region would just
stay the way they are.
The idea is to test an outworld map with a kind of "relative (to direction taken) view" in a section of
the NES screen. Afterwards, I'm planning also to add scrolling to move on the map, leaving the
sprite in the center maybe.
I'm not requesting the code to solve all the task, I'm planning to write it myself as a learning task,
but I'd like to have feedback on:

Thanks in advance to anyone could spend few minutes to clear out my doubts.
As always, I hope my English is understandable enough to make sense.
@Mods: if it was wrong to post twice the same question on the forum, I apologize about that.
I thought maybe someone interested in giving an aswer to this could skip checking the sticky
threads every time visits this section. Feel free to move/remove this post if uncorrect.
Cheers!
Edit: formatted the text a bit better, it should be a bit more readable, I guess.
Edit II: revoved useless code from the post.
Edit III: added an update note in the beginning of the post.
Challenge accomplished using a neutral background and changing the sprites positions instead of rotating the background itself. See last post.

I leave the original post here below:
---
Hi all,
I tried to ask this question in the "Ask all programming questions here!" thread, but I had tough luck.
I would like to know if, starting from the code below I learned from NN, it is possible to "rotate" a portion
of the background tiles on screen; for example, from something like this:

get the green and red sections "rotating" (changing their position) 90° right or left pushing a specific
button, which in this case would mean have the green tiles moving on top or bottom of the area
(rotating left or right), switching squares of 16x16px or 32x32px (it doesn't matter) positions.
The tiles appearance doesn't need to be rotated (what is up in the tile image, can still up: also
if the tile changed position rotating right or left its own pattern doesn't change).
On the other thread I posted further images on the concept. The tiles outside that region would just
stay the way they are.
The idea is to test an outworld map with a kind of "relative (to direction taken) view" in a section of
the NES screen. Afterwards, I'm planning also to add scrolling to move on the map, leaving the
sprite in the center maybe.
I'm not requesting the code to solve all the task, I'm planning to write it myself as a learning task,
but I'd like to have feedback on:
do you think it is reasonably possible to implement this feature in a NES game?
what algorithm (also as pseudo code) I better use?
in general, what you suggest as the fastest way to switch 2 background tiles?
everything should go in to the nmi routine? (I doubt there is time enough)?
do you think this approach (attribute part) could help in this task?
any other suggestion?

Thanks in advance to anyone could spend few minutes to clear out my doubts.
As always, I hope my English is understandable enough to make sense.
@Mods: if it was wrong to post twice the same question on the forum, I apologize about that.
I thought maybe someone interested in giving an aswer to this could skip checking the sticky
threads every time visits this section. Feel free to move/remove this post if uncorrect.
Cheers!
Edit: formatted the text a bit better, it should be a bit more readable, I guess.
Edit II: revoved useless code from the post.
Edit III: added an update note in the beginning of the post.
Comments
Originally posted by: KHAN Games
I certainly don't know any easy way to do this. You'd have to physically re-write all of the tiles individually.
Thanks! Truly appreciated feedback.
At least I quit wasting my time on something over-complicated!
So, as an alternative, I think I'll just leave identical "base" tiles on the area (like a black tile - 16x16 or 32x32 - with a dotted white line right and bottom so it makes a grid), and have few sprites as items on that map (with only those sprites "rotating" direction wise): changing position to sprites seems way easier than for bg tiles on the NES. This will make a good enough learning challenge too I guess.
Thanks again!
Cheers!
Left: view rotate from... to...
Right: view rotate from... to...
First task solved. Pretty easy, to be honest.
In case this can be useful to someone, the code is attached (comments are welcome).
And these are the graphics made for testing purposes, if needed for some reason.
Cheers!
Edit: just formatting
Edit II: just cleaned up the code a bit, renaming few labels
Edit III: corrected a misleading comment in the code (switched x and y in label spr comments)
Edit IV: rewrote the rotate L and rotate R sections of the code, using the y register instead of the
address $00 to temporarily store the previous value (the old code is commented out).
Just some refactoring, the code seems to work both ways.
Edit V: removed the code from the post, copy-pasted and attached below (as code.txt) instead.
Now it works also with 16x16px sprites.
.nes file attached (rom.nes) feel free to download it.
L rotate view left
R rotate view right
D simulating animated walking on the center sprite*
Next I will need to move the other spites relatively to the central one "walking" on the x or y axis.
*(I also need to figure out how to timer this feature, for now you need to push-release-push-release... to "walk").
Comments, as always, are welcome.
Cheers!
Edit: corrections
Originally posted by: KHAN Games
In the original post you said you wanted to flip background tiles, but in the solution you're flipping sprites. Did you just use the wrong terminology?
No. But you are correct: the thread title is now quite misleading. I changed the approach after reading your first reply (see my post above): since this was the first experiment programming for the NES (actually the first experiment programming in Assembly) I decided to avoid something over-complicated, and since my goal was just to simulate a map oriented in the direction taken (N/S/E/W), this solution sounded good enough as a first experiment answer.
Thanks again for your feedback.
Cheers!
Edit: I added a note about this also on the first post of this thread.