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 > Newb: Text over ExtRot Background

#114242 - cheapo - Fri Jan 05, 2007 7:39 pm

Heyas!

I'm trying to print text over a 16bit Extended Rotation Background, but it's not working. Can anyone point me what's wrong? Here's how I'm doing:

1. I set two main VRAM banks:

vramSetBankA( VRAM_A_MAIN_BG_0x6000000 );
vramSetBankB( VRAM_B_MAIN_BG_0x6020000 );

2. I set the main screen to use two backgrounds:

videoSetMode( MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_BG0_ACTIVE );

3. Init BG3 CR:

BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(3);
BG3_XDX = 1 << 8;
BG3_XDY = 0;
BG3_YDX = 0;
BG3_YDY = 1 << 8;
BG3_CX = 0;
BG3_CY = 0;

4. Init BG0 CR:

BG0_CR = BG_MAP_BASE(31) | BG_PRIORITY(0);
BG_PALETTE[255] = RGB15(31,31,31);

5. Init Console:

consoleInitDefault((u16*)SCREEN_BASE_BLOCK(31), (u16*)CHAR_BASE_BLOCK(0), 16);

That's it. Then I'm trying to draw something to BG3 (setting pixels using BG_GFX as the buffer) and then writing text over it (using iprintf), but the screen gets all garbled up.

If I disable all things related to BG0 and text, then BG3 gets painted correctly.

Thanks for any help!
_________________
There's no place like 127.0.0.1

#114243 - NeX - Fri Jan 05, 2007 8:00 pm

I do not think you need the second VRAM bank - not sure though.

#114254 - josath - Fri Jan 05, 2007 9:27 pm

BG0 and BG3 are using the same location in VRAM
BG3 - BG_BMP_BASE(0)
BG0 - BG_TILE_BASE(0) // implied, even though you didn't explicity set it

you need to move one of them -- you'll need to look up how much VRAM they each use, and how much VRAM you have available, in order to set them correctly so they don't overlap.

Same with BG_MAP_BASE on BG0 as well, you need to ensure that it doesn't overlap with either of the BMP or TILE bases.

Final note: make sure to update the consoleInit line as well, if you change the bases of BG0.

#114511 - cheapo - Mon Jan 08, 2007 3:50 pm

Thanks josath, it somewhat worked better now, but I still quite don't get it. Let me explain:

1. I'm setting two main VRAM banks (128 KB each):

vramSetBankA( VRAM_A_MAIN_BG_0x6000000 );
vramSetBankB( VRAM_B_MAIN_BG_0x6020000 );

2. I set the main screen to work with two backgrounds:

videoSetMode( MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_BG0_ACTIVE );

3. I initialize BG3 at position 0, which will be (as I understand) the beginning of VRAM_A:

BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(3);

4. I initialize BG0 at TILE position 8 (if BG3 takes 128 KB / 16 KB blocks, it will take slots 0 thru 7, hence I'm using 8 here, so BG0 starts at the beginning of VRAM_B). I'm using MAP position 16 since I saw an example using TILE 0 and MAP 8, so I just assumed that since I started at 8 I should use 16 for MAP:

BG0_CR = BG_TILE_BASE(8) | BG_MAP_BASE(16) | BG_PRIORITY(0);

5. Then I init Console Mode using the same positions for TILE and MAP:

consoleInitDefault((u16*)SCREEN_BASE_BLOCK(16), (u16*)CHAR_BASE_BLOCK(8), 16);

---

Now I can see the text over the things I initially painted in BG3, but it's still wrong, since it's painting a blue horizontal line at about half screen (which shouldn't be there) in BG3 and if I keep painting in BG3 the text disappears randomically.

I still can't understand what I'm doing wrong. Could you help me?

Thanks a lot!
_________________
There's no place like 127.0.0.1

#114513 - cheapo - Mon Jan 08, 2007 4:11 pm

Well, I've found out that if I swap the BG positions, it works. Now BG3 is at BG_BMP_BASE(8) (VRAM_B) and BG0 is at TILE_BASE(0) and MAP_BASE(31) (all in VRAM_A).

The only thing I had to change is to paint BG3 to (u16*)BG_BMP_RAM(8) (VRAM_B) instead of BG_GFX (VRAM_A), which was the address I was using before.

But I still don't get why my previous example didn't work.
_________________
There's no place like 127.0.0.1

#114881 - JessTicular - Thu Jan 11, 2007 6:43 am

I've found the information available at DSPassme.com very usefull for this...

DSPassme Registers Info

You'll notice from the information there that what you were doing wrong was setting BG0 to be TILE_BASE(8) since it only goes up to 4 :P

However, changing that wouldn't have helped if you're using BG3 as an extended rotation since it is in bitmap mode rather than tile-mode.

So, you'd effectively be writing straight over the top of your actual BG data when trying to put BG0's information at anything other than before where you're copying BG3's info to.

Here's a bit of code that I wrote for my most recent project:

Code:

   // We want an extended-rotation background since we're going to be using sprites
   //  & a full-screen background. We can have up to 512x512 on BG3, but since we
   //  only want a single full-screen image, then we'll just be using 512x256
   //  (which conveiniently fits into just two VRAMs)
   videoSetMode(MODE_3_2D | DISPLAY_BG3_ACTIVE | DISPLAY_BG0_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_BMP);

   // Setting VRAM A & B to the main BG - givnig us 256KiB, exactly what we need for a 512x256x16 image
   // However, we're using the first 6KiB for text-information
   // Thus, we need to map an extra 123KiB of memory to the end so that the over-flow from the 256KiB of
   //  BG image has somewhere to go.
   vramSetBankA(VRAM_A_MAIN_BG_0x6000000);
   vramSetBankB(VRAM_B_MAIN_BG_0x6020000);
   vramSetBankD(VRAM_D_MAIN_BG_0x6040000);

   // Setting VRAM E to be sprite memory
   // This gives us 64 KiB of Sprite Memory
   vramSetBankE(VRAM_E_MAIN_SPRITE);

   // Make sure our text draws on-top of BG3
   // Give the Map base as 2 - ((base)*0x800) + 0x06000000
   // Give the Tile base as 0 - ((base)*0x4000) + 0x06000000
   // We're setting the Tile base to be the very start of VRAM
   // And the map-base to be just past where the tile data ends
   BG0_CR = BG_MAP_BASE(2) | BG_TILE_BASE(0) | BG_PRIORITY(0);

   // Tell the DS that we're using BG3 for a 512x256x16 bitmap
   // Turn on Wrapping of the Background as it scrolls
   // Give the Map (BMP) base as 3 - ((base)*0x800) + 0x06000000
   // This map-base just clears the text-map
   // We could set the tile base here to be something (1), but it is pointless
   //  since we're using a bitmap, there are no 'tiles' assosciated with it
   //  and as such, the tile-base never gets written to or read from.
   BG3_CR = BG_BMP_BASE(3) | BG_BMP16_512x256 | BG_PRIORITY(3) | BG_WRAP_ON;


Enjoy :)
_________________
Nintendo DS & Dominos :: DS Dominos
http://jt0.org

#114894 - cheapo - Thu Jan 11, 2007 11:12 am

Hey JessTicular, thanks a lot!

So, if I get it, I just can't map text TILE and MAP base to VRAM_B, since TILE base only goes up to 3 and MAP base to 31, right? So everytime I want to use tile data on BG0 and bitmap data on BG2/BG3, I always have to put tile data first on the memory, and bitmap data after. Correct?

BTW, I see in your code that you set MAP base to 2 and TILE base to 0. So by this you mean that TILE data for text only takes 4 KB? I know, for example, that a 256x256x16bit BMP takes 128K of VRAM, but how can I know how much space will the TILE data for text take?

I'm sorry I keep asking questions even after I made my prog work, but that's just how I am... To make it work is not enough, I need to fully understand what I did... hehehe
_________________
There's no place like 127.0.0.1