Page 1 of 1

console over background in MODE_5_2d doesn't work

Posted: Fri Dec 12, 2008 7:15 pm
by yrro
I am trying to use MODE_5_2D to render a background image and then use the default console to write text over that image.

My image is a 256*192 PCX, which I have calculated uses up 128k of a VRAM bank. Now I would like to only use one VRAM bank for all of this as I have other things planned, so I thought I would try to map the PCX and the font for the console to the same bank.

I am using the SUB engine for something else, so that isn't an answer either :(

The tile base should in theory be block 6 and the screen/map should be 24.

However, when I munge it all together, i get a corrupted result. The image is being displayed, as is the text, but there are a load of stray characters all over the place.

I have the following code:

Code: Select all

/* Main screen VRAM */
    vramSetBankA (VRAM_A_MAIN_BG_0x06000000);
    consoleInitDefault ((u16*)SCREEN_BASE_BLOCK(24), (u16*)CHAR_BASE_BLOCK(6), 16);
    BG_PALETTE[0] = RGB15(0,0,0);
    BG_PALETTE[255] = RGB15(31,31,31);

    /* Sub screen VRAM */
    vramSetBankC (VRAM_C_SUB_BG);
    // draw stuff to BG_GFX_SUB

    /* Video modes */
    videoSetMode (MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG3_ACTIVE);

    //set up main engine (leaving the console as is)
    BG0_CR = BG_TILE_BASE(6) | BG_MAP_BASE(24);

    BG3_CR = BG_BMP16_256x256;

    // Set translations / / Set translations 
    BG3_XDX = 1<<8;
    BG3_XDY = 0;
    BG3_YDX = 0;
    BG3_YDY = 1<<8;
    BG3_CY = 0;
    BG3_CX = 0;
so, any ideas?

Thanks

Re: console over background in MODE_5_2d doesn't work

Posted: Sat Dec 13, 2008 5:49 am
by eKid
What color depth does the PCX have? You say it uses up 128k of VRAM A, which is the entire bank. A 256x192 16bpp image will use 96KB of memory, leaving you with 32k for the console. BG_MAP_BASE(24) will start at the 48k mark, which is still inside the 96k for the 16bpp image.

Re: console over background in MODE_5_2d doesn't work

Posted: Mon Dec 15, 2008 11:50 am
by yrro
Ah, yes, what I meant to say was the PCX takes up 96k, not 128k (oops).

It is a 8 bpp image that I am then converting to 16 bpp via image8to16().

Ok, so if BG_MAP_BASE(24) is at 48k, what value should I use? I thought the max value allowed was 31?

I had tried setting DISPLAY_SCREEN_BASE(1) of BG0_CR, but that didn't seem to help...

Re: console over background in MODE_5_2d doesn't work

Posted: Mon Dec 15, 2008 12:12 pm
by eKid
Yes, the screen base block is maximum 31, but DISPLAY_SCREEN_OFFSET(x) can be combined with the display mode to extend this. It is used to offset all BG maps by a certain amount (64K * x). It doesn't affect bitmap offsets though.

Code: Select all

videoSetMode( MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG3_ACTIVE | DISPLAY_SCREEN_OFFSET(1) );
BG0_CR = BG_TILE_BASE(6) | BG_MAP_BASE(20);
BG3_CR = BG_BMP16_256x256;
consoleInitDefault( (u16*)SCREEN_BASE_BLOCK(20+32), (u16*)CHAR_BASE_BLOCK(6), 16 );
Using this setup, BG3 will be the bitmap which takes up the first 96K (limited to 256x192), the BG0 tiles (console font) will be at 96K (6*16), and the BG0 map will start at the 104K mark (64 + 20*2), leaving 8KB of space for the console tiles.

Re: console over background in MODE_5_2d doesn't work FIXED :)

Posted: Mon Dec 15, 2008 1:40 pm
by yrro
Yay! Thanks for that eKid, it all works properly.

Now I can use my extra banks for other things.

Cheers.

Re: console over background in MODE_5_2d doesn't work

Posted: Mon Dec 15, 2008 5:35 pm
by yrro
I have just upgraded to devkitPro 24, and initially couldn't make the above concept function with the new library code.

After a bit off hunting around, I realised that as the new PrintConsole routine sets up the background layers for me, the only thing i had to do to replicate the above was to reset the PrintConsole fontBgMap pointer to be BG_MAP_RAM(20 + 32)

See below...

Code: Select all

    /* Main screen VRAM */
    vramSetBankA (VRAM_A_MAIN_BG_0x06000000);

    /* Sub screen VRAM */
    vramSetBankC (VRAM_C_SUB_BG);

    /* Video modes */
    videoSetMode (MODE_5_2D | DISPLAY_SCREEN_BASE(1));
    videoSetModeSub (MODE_5_2D);

    //BG0_CR = BG_TILE_BASE(6) | BG_MAP_BASE(20);
    PrintConsole* pc = consoleInit (/* ConsoleData* */ 0,
	/* layer */ 0,
	BgType_Text4bpp,
	BgSize_T_256x256,
	/* screen base */ 20,
	/* tile base */ 6,
	/* main/sub */ true);
    pc->fontBgMap = BG_MAP_RAM(20 + 32);
    consoleDebugInit (DebugDevice_CONSOLE);

Re: console over background in MODE_5_2d doesn't work

Posted: Tue Jan 06, 2009 10:42 pm
by Catweazle
Hello,
I'm new in NDS dev so excuse the maybe stupid question...
what has to be done for the following:

Console on both screens each with Bitmap background. (MODE_5_2D)
I want print text with the Console functions on BG0 and some lines and rectangles("gfx") on BG2
to do a simple GUI for a Synth Project (realtime audio streaming works fine).

I don't need 3D and pictures only a setpixel(x,y,color) function to set a pixel in the bitmap background.
The rest (drawing lines, rectangeles ... is done by using the setpixel function)

... using the newest Version of devkitARM (24)

thanks for help
gtz
eric

Re: console over background in MODE_5_2d doesn't work

Posted: Thu Jan 08, 2009 11:24 am
by cizcuz
Hi, try this code

Code: Select all

// set vram banks
vramSetMainBanks( VRAM_A_MAIN_BG, VRAM_B_MAIN_SPRITE, VRAM_C_SUB_BG, VRAM_D_SUB_SPRITE );

// set the mode for 2 text layers and two extended background layers
videoSetMode(MODE_5_2D | DISPLAY_SPR_ACTIVE | DISPLAY_BG3_ACTIVE );
videoSetModeSub(MODE_5_2D | DISPLAY_SPR_ACTIVE | DISPLAY_BG3_ACTIVE );

// Init print consoles
PrintConsole pcTop = *consoleInit( 0, 1, BgType_Text4bpp, BgSize_T_256x256, 0, 1, true );
PrintConsole pcBtm = *consoleInit( 0, 1, BgType_Text4bpp, BgSize_T_256x256, 0, 1, false );

int bgOffsetTop = 2;
int bgOffsetBtm = 2;

// set up our top bitmap background
int bgTop = bgInit( 3, BgType_Bmp16, BgSize_B16_256x256, bgOffsetTop , 0 );
bgSet( bgTop, 0, 1<<8, 1<<8, 0, 0, 0, 0 );
bgSetPriority( bgTop, 3 );
bgUpdate( bgTop );

// set up our bottom bitmap background
int bgBtm = bgInitSub( 3, BgType_Bmp16, BgSize_B16_256x256, bgOffsetBtm , 0 );
bgSet( bgBtm, 0, 1<<8, 1<<8, 0, 0, 0, 0 );
bgSetPriority( bgBtm, 3 );
bgUpdate( bgBtm );

// Load bitmap to top background
u16* gfxTopBG = BG_GFX + ((bgOffsetTop * 16384) >> 1);
dmaCopy( topBackgroundData, gfxTopBG, 256*192*sizeof(u16) );

// Load bitmap to bottom background
u16* gfxBtmBG = BG_GFX_SUB + ((bgOffsetBtm * 16384) >> 1);
dmaCopy( bottomBackgroundData, gfxBtmBG, 256*192*sizeof(u16) );

// Print some text @ top screen
consoleSelect( &pcTop );
iprintf( "Top Screen" );

// Print some text @ bottomscreen
consoleSelect( &pcBtm );
iprintf( "Bottom Screen" );

hope this helps...

Re: console over background in MODE_5_2d doesn't work

Posted: Thu Jan 08, 2009 5:34 pm
by Catweazle
Thanks a lot cizcuz !!!!!
Works fine.
so setpixel can be done ...

Code: Select all

gfxTopBG[(y<<8)+x] = color | BIT(15);
color can be set with RGB15(31,31,31) for example