Hi, I'm just starting to learn the intricacies of libnds through Patater's manual; I have some questions about setting the addresses for backgrounds with BG_BMP_BASE() macro.
In the example I'm looking at, there is a BG2 set at 256x256 pixels with 16-bit color, mapped at BG_BMP_BASE(0). The next init of BG3 is a 128x128 pixel, 16-bit and it starts at BG_BMP_BASE(8).
I was able to use mtheall's VRAM mapping utility to see that if I were to put BG3 at any other offset less than 8, it would have led to conflicts. My question is, is there any simple math trick to figure out exactly what the offset should be for the next background? Another question is, what is the difference between BG0, BG1 and BG2, BG3? What are BGs 0 and 1 commonly used for ?
Thanks,
bttf
Understanding Backgrounds and Memory
Re: Understanding Backgrounds and Memory
I'm glad to see that people are using my tool. The math is easy.
A bmp map base is 16KB (it is equivalent to a tile base but it uses the map base parameter). Let's start with BG2: you have a 256x256 16bpp image. This means 256x256x2 (2 bytes in 16 bits) total bytes for this image. That is 128KB. You put it at bmp base 0, that means it starts at offset 0KB. So...
The "+ (16*KB-1)" part is to round up if necessary (the result will be truncated to the correct value). You will see that you arrive at the result:
You can repeat by setting currentBmpBase = nextBmpBase and then update the values for the next image. Of course, this only works for bitmap images.
Side note: Your BG2 is using 128KB of VRAM. If you want any other backgrounds, you need to allocate an additional bank for backgrounds.
Additional side note: Patater manual is pretty outdated relative to the new API's available. Look at the nds examples that you can get with devkitARM and start using those API's. It will help to keep you sane.
A bmp map base is 16KB (it is equivalent to a tile base but it uses the map base parameter). Let's start with BG2: you have a 256x256 16bpp image. This means 256x256x2 (2 bytes in 16 bits) total bytes for this image. That is 128KB. You put it at bmp base 0, that means it starts at offset 0KB. So...
Code: Select all
#define KB 1024
width = 256;
height = 256;
depth = 16/8; // 16 bits divided by 8 bits per byte = 2 bytes
imgBytes = width*height*depth;
currentBmpBase = 0;
nextBmpBase = (currentBmpBase*16*KB + imgBytes + (16*KB-1)) / (16*KB);
Code: Select all
8
Side note: Your BG2 is using 128KB of VRAM. If you want any other backgrounds, you need to allocate an additional bank for backgrounds.
Additional side note: Patater manual is pretty outdated relative to the new API's available. Look at the nds examples that you can get with devkitARM and start using those API's. It will help to keep you sane.
Who is online
Users browsing this forum: No registered users and 1 guest