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 > Display 8bit image mistery

#62044 - pt3r - Sat Nov 26, 2005 8:03 pm

I wrote following code to display a 256 color 8bit image on the 3 background of the main display:

Code:

int main(void)
{
  powerON(POWER_ALL); 
  videoSetMode(MODE_5_2D |DISPLAY_BG3_ACTIVE);
  vramSetBankA(VRAM_A_MAIN_BG_0x6000000);

  BG3_CR = BG_BMP8_256x256 | BG_BMP_RAM(0);
  BG3_XDX = 1<<8;
  BG3_XDY = 0;
  BG3_YDX = 0;
  BG3_YDY = 1<<8;
  BG3_CY = 0;
  BG3_CX = 0;
 
  dmaCopy(screen_256Bitmap, (uint16*)BG_BMP_RAM(0), 256*192);
  dmaCopy(screen_256Pal, BG_PALETTE, 256*2);
...


This code works well on the dualis emulator as well as on my DS. Since I'm still very new to the DS coding I decided to experiment a bit with the code in order to check whether my assumptions regarding VRAM were correct. So i decided to use bank B instead of bank A. This code failed to work on the dualis emulator but it works without a fault on the DS. Is this a bug in the dualis emulator? The same thing happens when I use Bank C
with a vramSetBankC(VRAM_C_MAIN_BG_0x6000000);

Code:

int main(void)
{
  powerON(POWER_ALL); 
  videoSetMode(MODE_5_2D |DISPLAY_BG3_ACTIVE);
  vramSetBankB(VRAM_B_MAIN_BG_0x6000000);

  BG3_CR = BG_BMP8_256x256 | BG_BMP_RAM(0);
  BG3_XDX = 1<<8;
  BG3_XDY = 0;
  BG3_YDX = 0;
  BG3_YDY = 1<<8;
  BG3_CY = 0;
  BG3_CX = 0;
 
  dmaCopy(screen_256Bitmap, (uint16*)BG_BMP_RAM(0), 256*192);
  dmaCopy(screen_256Pal, BG_PALETTE, 256*2);
...


I decided to push the experiment a bit further and tried to map a different VRAM area to my background. This code gives a black screen both on dualis and on my DS.

Code:

int main(void)
{
  powerON(POWER_ALL); 
  videoSetMode(MODE_5_2D |DISPLAY_BG3_ACTIVE);
  vramSetBankA(VRAM_A_MAIN_BG_0x6040000);

  BG3_CR = BG_BMP8_256x256 | BG_BMP_RAM(16);
  BG3_XDX = 1<<8;
  BG3_XDY = 0;
  BG3_YDX = 0;
  BG3_YDY = 1<<8;
  BG3_CY = 0;
  BG3_CX = 0;
 
  dmaCopy(screen_256Bitmap, (uint16*)BG_BMP_RAM(16), 256*192);
  dmaCopy(screen_256Pal, BG_PALETTE, 256*2);
...


What am I missing? Any help/hints are highly appreciated.

#62114 - pt3r - Sun Nov 27, 2005 3:57 pm

Is nobody able to answer my question ? Perhaps I should rephrase it. How is it possible that this code works

Code:

powerON(POWER_ALL); 
  videoSetMode(MODE_5_2D|DISPLAY_BG3_ACTIVE);
  vramSetBankA(VRAM_A_MAIN_BG_0x6000000);
  BG3_CR = BG_BMP8_256x256|BG_BMP_RAM(0);
  BG3_XDX = 1<<8;
  BG3_XDY = 0;
  BG3_YDX = 0;
  BG3_YDY = 1<<8;
  BG3_CY = 0;
  BG3_CX = 0;
 
  dmaCopy(screen_256Bitmap, (uint16*)BG_BMP_RAM(0), 256*192);
  dmaCopy(screen_256Pal, BG_PALETTE, 256*2);


But this code does not work, the only thing I changed is the VRAM bank address from 0x06000000 to 0x06400000 and I of course copied the image data to the corresponding address:

Code:

powerON(POWER_ALL); 
  videoSetMode(MODE_5_2D|DISPLAY_BG3_ACTIVE);
  vramSetBankA(VRAM_A_MAIN_BG_0x6040000);

  BG3_CR = BG_BMP8_256x256|BG_BMP_RAM(16);
  BG3_XDX = 1<<8;
  BG3_XDY = 0;
  BG3_YDX = 0;
  BG3_YDY = 1<<8;
  BG3_CY = 0;
  BG3_CX = 0;
 
  dmaCopy(screen_256Bitmap, (uint16*)BG_BMP_RAM(16), 256*192);
  dmaCopy(screen_256Pal, BG_PALETTE, 256*2);


Where do I make a mistake in my code and/or reasoning, Why am I able to display the image in background 3 when mapped to VRAM_A_MAIN_BG_0x6000000 but not when I map it to VRAM_A_MAIN_BG_0x6040000? I read the ndslib document as well as the dstek document but I can not find a clue on why this coud doesn't work. :(

#62224 - pt3r - Mon Nov 28, 2005 2:15 pm

Nevermind I did some more studying and figured out where my train of thought ran of the rails.
When initialising the BGx_CR is must use BG_BMP_BASE(x) instead of BG_BMP_RAM(x).