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 > text mode doesnt work, why?

#152421 - ben0bi - Sat Mar 15, 2008 6:11 pm

i try to make normal text mode over a background. text mode alone works, background alone works too. but both together put out a mess on the screen.

can anyone tell me why that does not work and what to do to fix it?

here is my code:
Code:

videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE);
videoSetModeSub(MODE_5_2D | DISPLAY_BG2_ACTIVE DISPLAY_BG0_ACTIVE);
vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
vramSetBankB(VRAM_B_LCD);
vramSetBankC(VRAM_C_SUB_BG);
vramSetBankD(VRAM_D_LCD);

// text mode init
SUB_BG0_CR = BG_MAP_BASE(31);
BG_PALETTE_SUB[255] = RGB15(31,31,31);
consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);

// graphics mode
SUB_BG2_XDY = 0;
SUB_BG2_XDX = 1 << 8;
SUB_BG2_YDX = 0;
SUB_BG2_YDY = 1 << 8;
SUB_BG2_CX = 0;
SUB_BG2_CY = 0;

u8* sub_buffer[2];
sub_buffer[0]=(u8*)BG_BMP_RAM_SUB(0);
sub_buffer[1]=(u8*)BG_BMP_RAM_SUB(3);
bool actualBuffer=false;
...
while(1)
{
      if(bActualBuffer)
      {
         bActualBuffer=0;
         gfxSetDrawBuffer(sub_buffer[bActualBuffer]);
         SUB_BG2_CR = BG_BMP8_256x256 | BG_BMP_BASE(3);
      }else{
         bActualBuffer=1;
         gfxSetDrawBuffer(sub_buffer[bActualBuffer]);
      
         SUB_BG2_CR = BG_BMP8_256x256 | BG_BMP_BASE(0);
      }


...
print, draw, whatever
...

swiWaitForVBlank
}


i did not include the clearscreen function and the main screen buffer things here..

why does this not work?
on my machine, the pixels on bg2 are drawed. but the bg0 interfereres everywhere on screen, not only on the position where it should print.

#152429 - Cearn - Sat Mar 15, 2008 8:13 pm

From video.h:

Code:
#define BG_MAP_RAM(base)      (((base)*0x800) + 0x06000000)
#define BG_MAP_RAM_SUB(base)   (((base)*0x800) + 0x06200000)

#define BG_TILE_RAM(base)      (((base)*0x4000) + 0x06000000)
#define BG_TILE_RAM_SUB(base)   (((base)*0x4000) + 0x06200000)

#define BG_BMP_RAM(base)      (((base)*0x4000) + 0x06000000)
#define BG_BMP_RAM_SUB(base)   (((base)*0x4000) + 0x06200000)

In other words, the memory that BG_x_RAM and BG_x_RAM_SUB point to overlap. Choose your tile/map/bmp blocks so that writing one set of data doesn't clobber another.

#152438 - ben0bi - Sun Mar 16, 2008 1:38 am

i don't get it.
how should i do that?

i map SUB_BG0 to MAP_BASE(31) and SUB_BG2 to BMP_BASE(0) to BMP_BASE(5) --- so there should be enough blank memory between...

could you please give some code where it works, i am stuck here since 2 weeks trying to set up this f***in screens...:(

thanks.

[edit]
ok i checked it and i do not know what to do:
it gives grafic artefacts when i use
videoSetModeSub(ANY_MODE | BG0_ACTIVE | BG2_ACTIVE);
so, if i use BG0 or BG1 with BG2 or BG3 it gives artefacts, no matter what.

i wrote this line and used the initialisation of bg2 but NOTHING with bg0.

same with bg1...

#152441 - Cearn - Sun Mar 16, 2008 2:32 am

You're forgetting about SUB_BG0's tile/char-base. This line:
Code:

SUB_BG0_CR = BG_MAP_BASE(31);
implicitly sets the char-base to 0, which overlaps with bmp-base 0. Furthermore, screen-base 31 is actually inside bmp-base 3; since a 256x256@8 bitmap actually spans 4 bmp-bases, you may be overwriting that one as well.

This arrangement should work better (note: untested) :

Code:

// sub-bg0 : char-base 0, screen-base 7
//   (yes, screen-base 7 is the last 64 tiles of char-base 0,
//   but you're not using that many tiles so it's still safe)
SUB_BG0_CR = BG_MAP_BASE(7) | BG_TILE_BASE(0);
consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(7),
    (u16*)CHAR_BASE_BLOCK_SUB(0), 16);

// sub-bg3 : bmp-base 4 and 8
...


Calculate how much memory you're actually using, translate that to the number of bmp/char/screen bases, and then assign the numbers accordingly.

#152581 - silent_code - Mon Mar 17, 2008 11:39 pm

okay, a hint to (old but) working code: the infamous volume shadow demo on my site. ;^)

hope it helps!

ps: the others are right. a bit of tinkering with the memory banks and offsets will give you the result you need. just take a look at how i have done it.

pps: yes, i've used a custom font, but that shouldn't get you off course, really. you can still use the default font.