gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > setting a singlt tile on a rotbg?

#100514 - spinal_cord - Mon Aug 28, 2006 12:03 pm

Can someone tell me how to place a single tile on a rot background? I'm using PALib but it doesn't have a function to do that. The game im working on requires a scaled background with the abilit to change some of the tiles. PALib can only change tiles of regular tiles backgrounds, not rotating/scaled ones.

Can someone please help me?
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage

#100519 - gmiller - Mon Aug 28, 2006 12:19 pm

Not sure about this but from looking at the code you just need to do the tiles the standard way. The rotation and scaling effect the bg but the tile mapping and stuff (map manipulation) is the same for both. The background size choices are differnent between rot and non-rot (text) backgounds. On the GBA the map layout is different as well but I have not spent that much time on the DS yet to know more.

#100524 - spinal_cord - Mon Aug 28, 2006 12:57 pm

It messes up when i do it the normal way, it sets the tile 2*x,2*y instead of x,y.
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage

#100599 - josath - Mon Aug 28, 2006 10:11 pm

spinal_cord wrote:
It messes up when i do it the normal way, it sets the tile 2*x,2*y instead of x,y.

That seems pretty easy to fix, just divide x and y by 2?

#100606 - tepples - Mon Aug 28, 2006 10:41 pm

Then how do you set the odd tiles?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#100628 - spinal_cord - Tue Aug 29, 2006 12:17 am

I cant, I tried x/2,y/2, but all that did was set half the number of tiles still exevry second tile.

surely someone can do this without palib? molusc suggests i edit the normal tile function to do rotbg suff. he said something about the rotbg values being 8bit instead of 16bit. but thats way over my head.
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage

#100630 - gmiller - Tue Aug 29, 2006 12:33 am

The tile map for non-rotational background is 16 bits per entry with low order 10 bit for the tile number the high order 4 bits for which 16 color palette to use. The other two bits are for flipping the tile horiz./vert. For rotation background the map is 8 bits per entry and all 8 bits are the tile number and there are no other bits so only 256 color and no horz/vert flipping allowed. Now I took this from the GBA so there may be differences for the system running in DS mode but this does not seem be be the case from my reading of the code.

#100657 - spinal_cord - Tue Aug 29, 2006 10:05 am

But what code do I use to set a single tile (without using palib)?
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage

#100680 - gmiller - Tue Aug 29, 2006 5:04 pm

I think this will work as an addition for the PALIB
Code:

inline void PA_SetRotMapTile(u8 screen, u8 bg_select, s16 x, s16 y, u16 tile_number) {
u16 hold, *where;
tile_number = tile_number & 0x00FF;
// Calculate offset into rotational background map x + (y*32) ... tile is 8x8 and each pixel is 8 bits to 32  bytes wide
where = (u16*)(PA_bgmap[screen][bg_select] + ((x)) + ((y) << 5));
// Get current value as 16 bit but we only have 8 bits per pixes (must be written as 16 bit)
hold = *where;
// Odd or even (high or low byte
if ((x & 1) == 0)
  hold = (hold & 0xFF00) | tile_number; // change low order byte
else
  hold = (hold & 0x00FF) | (tile_number << 8); // change high order byte
*where = hold; // save as 16 bit, as required by hardware
}



I can't test it yet on my system so the offset calculation may be off.

#100690 - gmiller - Tue Aug 29, 2006 8:08 pm

The line:
Code:

where = (u16*)(PA_bgmap[screen][bg_select] + ((x)) + ((y) << 5));


I think is wrong, I believe it should be:
Code:

where = (u16*)(PA_bgmap[screen][bg_select] + (((x) + ((y) << 5)) >> 1);


Since the map for a rotational bg is an array of char the x/y offset is in bytes so in an array of shorts it's offset is half.

#100785 - gmiller - Wed Aug 30, 2006 2:41 pm

Sorry for the screup I was thinking 16 color palette and that can't be with rotational BG. so the line should be:
Code:


where = (u16*)(PA_bgmap[screen][bg_select] + (((x) + ((y) << 6)) >> 1);


Since a tile is 8x8 (so 64 pixles) and there are 2 per short, to get the index requires us to figure the offset in pixels and then divide by to to get the subscript. I did test the algorithm but not this code. I do not use PAlib so it took some time to look through the code to see what was being done. Of course then I screwed up the offset calculation. Some days I am not much help.

#100880 - spinal_cord - Thu Aug 31, 2006 10:08 am

gmiller wrote:
Some days I am not much help.

You have been more help than enyone else I have asked (thankyou).

The offset seems to be a little off, I don't know much about whats going on in the routine, so i cant fix it myself.

my map should be like this
[Images not permitted - Click here to view it]
but its turning out like this
[Images not permitted - Click here to view it]

[edit]
the line should be
Code:
where = (u16*)(PA_bgmap[screen][bg_select] + (x + (y << 5)));


Thankyou, you may have helped a small minority of PALib users that wish to use a RotBg.
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage

#100887 - gmiller - Thu Aug 31, 2006 12:40 pm

damn .. my first "guess" was right ... who would have guessed.