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 > Console Help!!

#128786 - kalus - Tue May 15, 2007 7:52 am

Ok, i have got 3D on top screen, and a 2D hud on bottom screen. Id like to use console text ontop of the HUD, but cant quite get it to work... is this a stupid idea, or should it work, and ive made a stupid mistake? Code below, please help!

Code:
   powerON(POWER_ALL);
   

   //put 3D on top
   lcdMainOnTop();
   // Setup the Main screen for 3D
   videoSetMode(MODE_0_3D);
   videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE); //sub bg 0 will be used to print text

     vramSetMainBanks(   VRAM_A_MAIN_BG_0x06000000, VRAM_B_TEXTURE,
                  VRAM_C_SUB_BG , VRAM_D_LCD);
    SUB_BG0_CR = BG_MAP_BASE(31);

   BG_PALETTE_SUB[255] = RGB15(31,31,31);//by default font will be rendered with color 255

   consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);


   SUB_BG3_CR = BG_BMP8_256x256;

   SUB_BG3_XDX = 1 << 8;
      SUB_BG3_XDY = 0;
      SUB_BG3_YDX = 0;
      SUB_BG3_YDY = 1 << 8;
   

   dmaCopy(hud_texture_bin, BG_GFX_SUB, 256*256);
   dmaCopy(palette_bin, BG_PALETTE_SUB, 256*2);
   

#128791 - mml - Tue May 15, 2007 10:11 am

Have a look at what the various bits in the SUB_BGx_CR registers actually mean, and explicitly set all of them, even if you're just setting them to their default of zero.

The macros for the defaults are usually just (0<<n) for some n position, and I've noticed a *lot* of the beginner-level example code just leaves them out, because they're not needed for the example -- but they don't explain a) that they're leaving it out, or b) why! Which means when you go to modify your code later, you don't realise that you need to set more flags for more complex stuff. At least if you've got all the defaults right there in your face, as soon as you go to modify it later you'll notice immediately that there's that extra place you need to change it.

In short, I'd be willing to bet that both your SUB_BG0 and SUB_BG3 are looking in the same chunk of memory for their information, because you've left the bits in their _CR registers that tell it where to find it blank, and they default to the same. And so they each interpret whatever you pu there in whatever way they feel like, and you end up with garbage on your screen.

You might also need to carefully poke around in the source for the consoleInit* functions to see how they work, since their interface docs for consoleInitDefault and consoleInitDemo don't actually explain what they default to or why (so as soon as you need to do something more complex, you have no idea what you can do, let alone how to do it). This will only work if you have libnds sitting around in source form somewhere.

This bit me the other day. :P

#128796 - kalus - Tue May 15, 2007 10:49 am

cheers, will look into it :)

#128804 - tepples - Tue May 15, 2007 12:37 pm

mml wrote:
You might also need to carefully poke around in the source for the consoleInit* functions to see how they work, since their interface docs for consoleInitDefault and consoleInitDemo don't actually explain what they default to or why (so as soon as you need to do something more complex, you have no idea what you can do, let alone how to do it). This will only work if you have libnds sitting around in source form somewhere.

Do you plan on submitting revised documentation for some of these functions so that the maintainers can incorporate it into the next version of libnds?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#128871 - mml - Wed May 16, 2007 5:36 am

I imagine so, if such still doesn't exist by the time I wrap my head around it adequately. I've been at this for like, a week. :)

#128902 - kalus - Wed May 16, 2007 5:47 pm

Ok, with this code:

Code:
   irqInit();
   irqSet(IRQ_VBLANK, 0);
   // Turn on everything
   powerON(POWER_ALL);
   

   //put 3D on top
   lcdMainOnTop();
   // Setup the Main screen for 3D
   videoSetMode(MODE_0_3D);
   videoSetModeSub(MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG3_ACTIVE); //sub bg 0 will be used to print text

//   vramSetBankA();                        //NEW  must set up some memory for textures
     vramSetMainBanks(   VRAM_A_MAIN_BG_0x06000000, VRAM_B_TEXTURE,
                  VRAM_C_SUB_BG , VRAM_D_LCD);
 
   SUB_BG3_CR = BG_BMP8_256x256 | BG_BMP_BASE(0) | BG_TILE_BASE(2) | BG_PRIORITY(3);
   SUB_BG0_CR = BG_MAP_BASE(4) | BG_TILE_BASE(5) | BG_PRIORITY(0);

//   BG_PALETTE_SUB[255] = RGB15(31,31,31);//by default font will be rendered with color 255

   consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(4), (u16*)CHAR_BASE_BLOCK_SUB(5), 16);



      SUB_BG3_XDX = 1 << 8;
      SUB_BG3_XDY = 0;
      SUB_BG3_YDX = 0;
      SUB_BG3_YDY = 1 << 8;
   // our bitmap looks a bit better if we center it so scroll down (256 - 192) / 2
      SUB_BG3_CX = 0;
      SUB_BG3_CY = 0;;

   dmaCopy(drunkenlogo_bin, BG_GFX_SUB, 256*192);
   dmaCopy(palette_bin, BG_PALETTE_SUB, 256*2);


it MOSTLY works, except im still getting some overflow into BG3 from BG0. Pics below, when first run, it looks like this:

[Images not permitted - Click here to view it]

then as the text scrolls down, the wierdness mostly scrolls up to this:

[Images not permitted - Click here to view it]

Please, someone has to know whats going on with this![/img]

#128969 - mml - Thu May 17, 2007 5:42 am

Quote:
SUB_BG3_CR = BG_BMP8_256x256 | BG_BMP_BASE(0) | BG_TILE_BASE(2) | BG_PRIORITY(3);
SUB_BG0_CR = BG_MAP_BASE(4) | BG_TILE_BASE(5) | BG_PRIORITY(0);


Check those offsets into BG_BMP_BASE(), BG_MAP_BASE() and BG_TILE_BASE() carefully. The _MAP_ and _TILE_ ones start at the same address with different multipliers, and I suspect the _BMP_ one will be much the same (don't have headers with me at present).

For example, IIRC, BG_MAP_BASEs 0-7 will overlap the same area of memory as BG_TILE_BASE 0; BG_MAP_BASEs 8-15 will overlap BG_TILE_BASE 1; etc. So you'll need to be careful how you decide which bmp, tile, and map bases you use so they aren't overlapping each other. Otherwise, when you copy your bitmap data in, you may or may not be crapping it all over your tile or map data (which is used by the console), and/or when you print to the console it might be crapping all over your bitmap.

From memory, these macros are defined in nds/arm9/video.h

#128978 - kalus - Thu May 17, 2007 9:34 am

cheers! its coming along in leap and bounds now, thats only problem so far! Will have a bash at fixing tonight :)