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 > Blanking background

#174196 - JackUzi - Sun May 23, 2010 8:45 am

Well, on the home stretch now. :) The only problem I have left is that the part of the bottom screen that doesn't contain the keyboard is garbled. I presume I need to initialise the bit of memory that it is mapped to or something, but the more I read on this the less I know...

This is the code I'm using at the moment to start the app:

Code:


    vramSetBankA(VRAM_A_MAIN_BG);
    vramSetBankC(VRAM_C_SUB_BG);

    videoSetMode(MODE_0_2D);
    videoSetModeSub(MODE_0_2D);

    consoleInit(&topScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true);
    consoleInit(&bottomScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 31, 0, false, true);
    consoleSelect(&topScreen);

    keyboardInit(kbd, 3, BgType_Text4bpp, BgSize_T_256x256, 31, 0, false, true);
    keyboardShow();


The top screen is fine, just a plain text console, and the lower half of the bottom screen is fine too, the nice on-screen keyboard. It is just the area above the keyboard on the bottom screen that contains the garbage. Originally I was hoping to use that space to output more text, but at this stage I would be happy for it to be just plain black.

Can anyone tell me what I am doing wrong?

Regards,
Stuart

#174255 - JackUzi - Wed May 26, 2010 3:36 am

If any kind/ brave soul wants to have an experiment with this (I've tried every combination of everything I can think of...), here is a short compilable test that demonstrates the problem:

Code:

int main(void) {
 
    Keyboard *kbd = NULL;
    PrintConsole topScreen;
    PrintConsole bottomScreen;

    vramSetBankA(VRAM_A_MAIN_BG);
    vramSetBankC(VRAM_C_SUB_BG);

    videoSetMode(MODE_0_2D);
    videoSetModeSub(MODE_0_2D);

    consoleInit(&topScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true);
    consoleInit(&bottomScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 31, 0, false, true);

    keyboardInit(kbd, 2, BgType_Text4bpp, BgSize_T_256x256, 30, 0, false, true);
    keyboardShow();

    consoleSelect(&topScreen);
    printf("Top screen okay.\nGarbage above keyboard.\n");
    while (1) {};
}


Last edited by JackUzi on Wed May 26, 2010 11:08 am; edited 1 time in total

#174257 - relminator - Wed May 26, 2010 4:08 am

Don't quote me on this but from my experiments, VRAM bank C is used by the console fonts.
_________________
http://rel.betterwebber.com

#174259 - elhobbs - Wed May 26, 2010 5:46 am

It looks like the keyboard VRAM and the bottomscreen VRAM overlap - 31,0 and 30,0 - both are loading tiles at 0 for the sub screen. You are loading the keyboard last so it is not garbled.

#174264 - elhobbs - Wed May 26, 2010 7:01 am

try this
Code:
    consoleInit(&bottomScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 14, 0, false, true);

    keyboardInit(kbd, 2, BgType_Text4bpp, BgSize_T_256x256, 31, 2, false, true);

#174268 - JackUzi - Wed May 26, 2010 11:22 am

elhobbs wrote:
try this
Code:
    consoleInit(&bottomScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 14, 0, false, true);

    keyboardInit(kbd, 2, BgType_Text4bpp, BgSize_T_256x256, 31, 2, false, true);


I appreciate the suggestion, but alas just more cyan and white speckles. I tired putting the keyboard on 14 and leaving the bottom console on 31 and that had more black, but still stripes through it.

Regards,
Stuart

#174269 - relminator - Wed May 26, 2010 1:44 pm

Did you try this?

Code:

vramSetBankD(VRAM_D_SUB_BG);


instead of
Code:

vramSetBankC(VRAM_C_SUB_BG);


Bank C is somehow used by the console fonts. At least that's what my experiments tell me.
_________________
http://rel.betterwebber.com

#174273 - elhobbs - Wed May 26, 2010 3:04 pm

it may just be layer 0. you are using layers 2 and 3 for the keyboard and console respectively. not sure what you have planned for layer 0 but it is enabled using videoSetModeSub(MODE_0_2D);

I recommend that you try this out in desmume and use the layer, map, and tile tools to see how things are being laid out in vram.

#174292 - JackUzi - Thu May 27, 2010 12:43 am

relminator wrote:
Did you try this?

Code:

vramSetBankD(VRAM_D_SUB_BG);


instead of
Code:

vramSetBankC(VRAM_C_SUB_BG);


Bank C is somehow used by the console fonts. At least that's what my experiments tell me.


Sorry, I should have got back to you. I did try that but I get, "error: 'VRAM_D_SUB_BG' undeclared (first use in this function)"

Doing a grep through the libnds directory there appears to only be C, H and I for "_SUB_BG". I tried using H and I but then the keyboard didn't display at all.

Thanks,
Stuart


Last edited by JackUzi on Thu May 27, 2010 12:49 am; edited 1 time in total

#174294 - JackUzi - Thu May 27, 2010 12:49 am

elhobbs wrote:
it may just be layer 0. you are using layers 2 and 3 for the keyboard and console respectively. not sure what you have planned for layer 0 but it is enabled using videoSetModeSub(MODE_0_2D);

I recommend that you try this out in desmume and use the layer, map, and tile tools to see how things are being laid out in vram.


I wasn't aware of the layer, map and title tools, so I'll look into those today. I don't have any plans for layer 0, it's just a plain console app and I was just cut-and-paste coding from the examples. Does this mean that I should set the video mode in a different way so that only layers 2 and 3 are active or that I should assign something to layer 0 to stop it being in an undefined state?

Thanks for your help, I really appreciate it,
Stuart

#174297 - elhobbs - Thu May 27, 2010 5:37 am

I tested this out and I am not seeing any cyan and white speckles.
Code:
#include <nds.h>
#include <stdio.h>
//---------------------------------------------------------------------------------
int main(void) {
   PrintConsole topScreen,bottomScreen;
   Keyboard kbd;
//---------------------------------------------------------------------------------
    vramSetBankA(VRAM_A_MAIN_BG);
    vramSetBankC(VRAM_C_SUB_BG);

    videoSetMode(MODE_0_2D);
    videoSetModeSub(MODE_0_2D);

    consoleInit(&topScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true);
    consoleInit(&bottomScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 14, 0, false, true);
    consoleSelect(&topScreen);

    keyboardInit(&kbd, 2, BgType_Text4bpp, BgSize_T_256x256, 31, 2, false, true);
    keyboardShow();


    consoleSelect(&topScreen);
   iprintf("top screen\nHello World!");
   
   consoleSelect(&bottomScreen);
   iprintf("bottom screen\nHello World!");
   
   while(1) {
      keyboardUpdate();
      swiWaitForVBlank();
   }

}

#174298 - JackUzi - Thu May 27, 2010 7:18 am

Thank you for giving this a try. I compiled it and it runs perfectly on desmume, as does some versions of my original program, but gives the cyan and white pattern instead of the bottom screen text when running on actual DS hardware (in this case, a DSi XL with an M3i Zero)

Incidentally, one thing I have noticed with desmume is that although the text appears without any random pattern, the background of the bottom screen is grey. Using a different example such as the 'print_both_screens' example (that comes with devKitPro), both screens have a completely black background and it runs just fine on real hardware. This example doesn't display a keyboard however, as soon as the keyboard is added the problem appears.

Maybe I am out of luck in that this should work, but just doesn't with this particular card/ DS combination.

Thanks again,
Stuart

#174300 - samel - Thu May 27, 2010 11:42 am

I think you have to check how much big are the tiles image [keyboard and text] because VRAM_BANK_C is 128Kb and it should contain 2 background [BgType_Text4bpp, BgSize_T_256x256] quite easly.

VRAM_BANK_D cannot be mapped for sub_bg

take a look here:

http://tobw.net/dswiki/index.php?title=Graphic_modes

VRAM_BANK_H and I can be mapped to sub_bg, but if i remember right they overlap .... too much time withoout ndsdev 8_(

Anyway, i've to admit that i've never used
consoleInit,consoleSelect,keyboardInit and keyboardShow so maybe i'm wrong

#174301 - elhobbs - Thu May 27, 2010 1:37 pm

JackUzi wrote:
Thank you for giving this a try. I compiled it and it runs perfectly on desmume, as does some versions of my original program, but gives the cyan and white pattern instead of the bottom screen text when running on actual DS hardware (in this case, a DSi XL with an M3i Zero)Stuart
I should have been clearer. this works fine on my DS Lite with an ezflavh v.

that being said - the libnds headers use these values to fit everything in the lower 64k of the vram bank without overlapping.
Code:
    consoleInit(&bottomScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 22, 3, false, true);

    keyboardInit(&kbd, 2, BgType_Text4bpp, BgSize_T_256x256, 20, 0, false, true);


though, I suspect the issue may just be related to how the different cards leave the hardware in a different state.

#174306 - JackUzi - Fri May 28, 2010 3:09 am

Hmmm, it certainly is starting to look like it is an M3i related issue which is a shame. Oh well, I'm starting to think that I might just use both screens for output and code up a chordal keyboard using all the buttons. There will be a bit of a learning curve when typing but with a bit of thoughtful optimisation it might be quite usable. At the very least it will be an interesting experiment.

Thanks again to everyone for your help,
Stuart