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 > Help: text on image problem [solved]

#163551 - Kayvon - Sat Oct 04, 2008 9:42 pm

I've been lurking since about a week ago, when I first started programming on the DS. I'm an experienced coder and I'm almost done with a simple "Missile Command" homebrew, but I'm stuck.

I can't text over an image on the subscreen to work:

Code:

int main()
{
   static const int DMA_CHANNEL = 3; // low priority DMA channel to background copy

   powerON(POWER_ALL);

   irqInit();
   irqSet(IRQ_VBLANK, 0);

   vramSetBankC(VRAM_C_SUB_BG_0x06200000); // map bank C to sub screen background memory
   videoSetModeSub(MODE_3_2D | DISPLAY_BG3_ACTIVE | DISPLAY_BG0_ACTIVE);
   SUB_BG3_X0 = 0;         // X-Pos
   SUB_BG3_Y0 = 0;         // Y-Pos
   SUB_BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(0) | BG_PRIORITY(3);
   SUB_BG3_XDX = 1 << 8;
   SUB_BG3_XDY = 0;
   SUB_BG3_YDX = 0;
   SUB_BG3_YDY = 1 << 8;
   SUB_BG3_CX = 0;
   SUB_BG3_CY = 0;
   dmaCopyHalfWords(DMA_CHANNEL,
                     splashBitmap, // This variable is generated for us by grit.
                     (uint16 *)BG_BMP_RAM_SUB(0), // address for sub background 3
                     splashBitmapLen);

   BG_PALETTE_SUB[255] = RGB15(31,31,31);   // white font
   SUB_BG0_CR = BG_MAP_BASE(2);
   consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(2), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
   iprintf("Testing...\n1, 2, 3!");

   while(1);
}


I can get the splash image to appear on the subscreen no problem. I can get normal text (helpful in debugging) without a problem. But I can't get the both to work at once.

Any help here is appreciated. I suspect I've done something wrong with the memory banks[/code]


Last edited by Kayvon on Sun Oct 05, 2008 3:55 am; edited 1 time in total

#163554 - Maxxie - Sat Oct 04, 2008 10:14 pm

The memory indexes you use for text and bmp background are overlapping:

SCREEN_BASE_BLOCK_SUB(2) and CHAR_BASE_BLOCK_SUB(0)

conflict with

BG_BMP_RAM_SUB(0)

If you write to the map/tiles of the text BG (i.e. on console init) you are overwriting part of the image you have previously put there.
Take a look at gbatek and/or the macro defines to check where those macros point to and how large they are. Then move them so that they do not overlap anymore.
_________________
Trying to bring more detail into understanding the wireless hardware

#163557 - silent_code - Sat Oct 04, 2008 11:24 pm

Especially read up on the limitations and boundaries. One type's (map or character / tile memory) block size is 16kB, the other's is 4kB. So you can have maps and tiles parallel in memory, but they must not overlap! If you map data is small enough, you can make it overlap, though. Just be clever. :^)

Otherwise, I can just write, that i've answered that question a few times already. Please search the forum (you'll find examples, like text over a bezier curve etc.) or take a look at my VSD on my site. It even loads a custom font (which isn't that hard to do). :^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#163560 - Kayvon - Sun Oct 05, 2008 12:06 am

Curses! I usually pride myself on searching exhaustively before asking a question in a forum, so I'm rather embarrassed.

Thanks for the info. I'll read the various threads and post the new code when I fix it (so future readers with the same problem can see the solution).

#163561 - Kayvon - Sun Oct 05, 2008 12:42 am

The main problem was that I didn't understand what SUB_BG3_CY was and did. I still don't, actually, so I need to research some more, unless someone wants to share. It seems to be a memory offset, telling how many bytes of memory to "ignore" before the background actually starts. So change the line above to:

Code:
   SUB_BG3_CY = (16*256)*2;


And, since the memory is stored in a different location, the BG_BMP_RAM_SUB(0) needs to bump up to a (1) to stay consistent:

Code:

   dmaCopyHalfWords(DMA_CHANNEL,
                     splashBitmap, // This variable is generated for us by grit.
                     (uint16 *)BG_BMP_RAM_SUB(1), // address for sub background 3
                     splashBitmapLen);


Everything else works just grand. And now I'm late for an event, so I'll be wondering what CX and CY mean until I can research later.

#163605 - Cearn - Mon Oct 06, 2008 12:57 pm

Kayvon wrote:
The main problem was that I didn't understand what SUB_BG3_CY was and did. I still don't, actually, so I need to research some more, unless someone wants to share. It seems to be a memory offset, telling how many bytes of memory to "ignore" before the background actually starts.


SUB_BG3_CY is one of the scrolling offsets for sub-BG 3. Basically, it CX and CY indicate at which map coordinates the viewport is. You can find what they do in GBATek:BG rotscale and Tonc:affine BG under the old names of REG_BGnX/Y.