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 on sub screen with background

#104475 - smoggie83 - Fri Sep 29, 2006 4:10 pm

I am trying to display text above a background but no matter what i try it wont display any text that i tell it too! any ideas anyone?

Code:

#include <nds.h>

#include <nds/arm9/console.h>
#include <stdio.h>

//make file automaticaly makes a header file for access
//to the binary data in any file ending in .bin that is in
//the data folder.  It also links in that data to your project

#include "drunkenlogo_bin.h"
#include "palette_bin.h"

#include "diceRoll_bin.h"
#include "diceRollPalette_bin.h"

#include "players_bin.h"
#include "playersPalette_bin.h"

enum { CONTINUOUS, SINGLE } TouchType = CONTINUOUS;

volatile int frame = 0;

//---------------------------------------------------------------------------------
void Vblank() {
//---------------------------------------------------------------------------------
   frame++;
}

void initVideo() {
   //enable vram and map it to the right places
    vramSetMainBanks(   VRAM_A_MAIN_BG_0x6000000,      //map A and B to main background memory
                        VRAM_B_LCD,
                        VRAM_C_SUB_BG_0x6200000,      //map C to sub background memory
                        VRAM_D_LCD                  //map D to LCD free space
                  //allows adjacent banks to overflow into D if a bug like that was ever to occur
                        );
   
   //map a bank for use with sprites
   //vramSetBankE(VRAM_E_MAIN_SPRITE); //mapping E to main sprites gives us 64k for sprites
   //(64k is the max space that 1024 tiles take up in 256 color mode)
   
   //set the video mode
    videoSetMode(  MODE_5_2D |   
                   DISPLAY_BG3_ACTIVE     //turn on background 3
               );
   
   videoSetModeSub(MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG3_ACTIVE | DISPLAY_SPR_1D   );
}


void initBackgrounds() {

   //setup exrot bg 3 on main as a 16bit color background
   BG3_CR = BG_BMP8_256x256 ;
   //attributes of the affine translation matrix
   BG3_XDX = 1 << 8; //scale x
   BG3_XDY = 0; //rotation x
   BG3_YDX = 0; //rotation y
   BG3_YDY = 1 << 8; //scale y
   BG3_CX = 0; //translation x
   BG3_CY = 0; //translation y
   
   //setup exrot bg 3 on sub
   SUB_BG3_CR = BG_BMP8_256x256 ;
   //attributes of the affine translation matrix
   SUB_BG3_XDX = 1 << 8; //scale x
   SUB_BG3_XDY = 0; //rotation x
   SUB_BG3_YDX = 0; //scale y
   SUB_BG3_YDY = 1 << 8; //scale y
   SUB_BG3_CX = 0; //translation x
   SUB_BG3_CY = 0; //translation y
}

int main(void) {
//---------------------------------------------------------------------------------
   int min_x  = 4096 , min_y  = 4096, max_x  = 0, max_y   = 0;
   int min_px = 4096 , min_py = 4096, max_px = 0 , max_py = 0;
   touchPosition touch;


   powerON(POWER_ALL);
   
   //initialise the interrupt system
   irqInit();
   //install our simple vblank handler
   irqSet(IRQ_VBLANK, Vblank);
   //enable the interrupt
   irqEnable(IRQ_VBLANK);
   
   //set the mode for 2 text layers and two extended background layers
   initVideo();

   ///////////////set up our bitmap background///////////////////////
   initBackgrounds();
   
   
   // black backdrop
   BG_PALETTE[0]=RGB15(0,0,0);
   SUB_BG0_CR = BG_COLOR_256;//use bg0 for the text
   //SUB_BG0_CR = BG_MAP_BASE(31);
   BG_PALETTE[255] = RGB15(200,0,0);//by default font rendered with color 255
   
   //consoleInit() is a lot more flexible but this gets you up and running quick
   consoleInitDefault((u16*)SCREEN_BASE_BLOCK(31), (u16*)CHAR_BASE_BLOCK(0), 16);

   dmaCopy(drunkenlogo_bin, BG_GFX, 256*192);
   dmaCopy(palette_bin, BG_PALETTE, 256*2);
   
   dmaCopy(drunkenlogo_bin, BG_GFX_SUB, 256*192);
   dmaCopy(palette_bin, BG_PALETTE_SUB, 256*2);
   
   while(1) {
      swiWaitForVBlank();
      
      // read the button states
      scanKeys();

      // read the touchscreen coordinates
      touch=touchReadXY();
      
      int pressed = keysDown();   // buttons pressed this loop
      int held = keysHeld();      // buttons currently held

      // Right Shoulder button toggles the mode
      if ( pressed & KEY_R) TouchType ^= SINGLE;
      
      iprintf("\xTEST TEXT HERE!!!");
      
      if ( TouchType == SINGLE && !(pressed & KEY_TOUCH) ) continue;

      if ( !(held & KEY_TOUCH) || touch.x == 0 || touch.y == 0) continue;
      
      if ( touch.x > max_x)      max_x = touch.x;
      if ( touch.y > max_y)      max_y = touch.y;
      if ( touch.px > max_px)   max_px = touch.px;
      if ( touch.py > max_py)   max_py = touch.py;

      if ( touch.x < min_x)      min_x = touch.x;
      if ( touch.y < min_y)      min_y = touch.y;
      if ( touch.px < min_px)   min_px = touch.px;
      if ( touch.py < min_py)   min_py = touch.py;
   }

   return 0;
}


Cheers

Dave

#104477 - psycorpse - Fri Sep 29, 2006 4:45 pm

are you trying to use the top screen or bottom screen?

#104478 - smoggie83 - Fri Sep 29, 2006 4:49 pm

i was wanting the text displayed on the bottom screen as that is where the interface and questions will come up in my project.

thanks in advance

#104480 - psycorpse - Fri Sep 29, 2006 5:08 pm

Change your code to this and tell me what it does

Code:

SUB_BG0_CR = BG_MAP_BASE(31) | BG_PRIORITY(0);
BG_PALETTE_SUB[255] = RGB(31, 31, 31);


you also need (adding_SUB to the blocks):
Code:
consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);


you need to change your sub bg 3 to priority(1) and change the BASE()

Code:
SUB_BG3_CR = BG_BMP8_256x256 | BG_BMP_BASE(8) | BG_PRIORITY(1) ;

#104482 - knight0fdragon - Fri Sep 29, 2006 5:24 pm

also your dmaCopy to the BG_PALETTE_SUB is also going to screw up with your text color, so stick the BG_PALETTE_SUB[255] = blah after that for now
_________________
http://www.myspace.com/knight0fdragonds

MK DS FC: Dragon 330772 075464
AC WW FC: Anthony SamsClub 1933-3433-9458
MPFH: Dragon 0215 4231 1206

#104485 - smoggie83 - Fri Sep 29, 2006 5:50 pm

cheers for the help. With them changes the background which for now is the same as the top screen doesnt display! i get a black background with the text on with a kindof red semi-transparent layer above it.[/img]

#104488 - psycorpse - Fri Sep 29, 2006 5:58 pm

Your image link didn't show up. Can you post a pic?

#104491 - smoggie83 - Fri Sep 29, 2006 6:19 pm

i dont have a site to upload to sorry, its something to do with these lines though

SUB_BG0_CR = BG_MAP_BASE(31) | BG_PRIORITY(0);

and

SUB_BG3_CR = BG_BMP8_256x256 | BG_BMP_BASE(8) | BG_PRIORITY(1) ;

i think its to do with the BASE part?

#104492 - psycorpse - Fri Sep 29, 2006 6:27 pm

Your right. It does have something to do with the BASE. I believe that you need to copy your background to

dmaCopy(drunkenlogo_bin, (void*)BG_BMP_RAM_SUB(8), 256*192);

instead of

dmaCopy(drunkenlogo_bin, BG_GFX_SUB, 256*192);

#104575 - smoggie83 - Sat Sep 30, 2006 3:59 pm

the text now displays no problem but there is still no background, the image isnt displayed at all. The new code is
Code:

#include <nds.h>

#include <nds/arm9/console.h>
#include <stdio.h>

//make file automaticaly makes a header file for access
//to the binary data in any file ending in .bin that is in
//the data folder.  It also links in that data to your project

#include "drunkenlogo_bin.h"
#include "palette_bin.h"

#include "diceRoll_bin.h"
#include "diceRollPalette_bin.h"

#include "players_bin.h"
#include "playersPalette_bin.h"

enum { CONTINUOUS, SINGLE } TouchType = CONTINUOUS;

volatile int frame = 0;

//---------------------------------------------------------------------------------
void Vblank() {
//---------------------------------------------------------------------------------
   frame++;
}

void initVideo() {
   //enable vram and map it to the right places
    vramSetMainBanks(   VRAM_A_MAIN_BG_0x6000000,      //map A and B to main background memory
                        VRAM_B_LCD,
                        VRAM_C_SUB_BG_0x6200000,      //map C to sub background memory
                        VRAM_D_LCD                  //map D to LCD free space
                  //allows adjacent banks to overflow into D if a bug like that was ever to occur
                        );
   
   //map a bank for use with sprites
   //vramSetBankE(VRAM_E_MAIN_SPRITE); //mapping E to main sprites gives us 64k for sprites
   //(64k is the max space that 1024 tiles take up in 256 color mode)
   
   //set the video mode
    videoSetMode(  MODE_5_2D |   
                   DISPLAY_BG3_ACTIVE     //turn on background 3
               );
   
   videoSetModeSub(MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG3_ACTIVE   );
}


void initBackgrounds() {

   //setup exrot bg 3 on main as a 16bit color background
   BG3_CR = BG_BMP8_256x256 ;
   //attributes of the affine translation matrix
   BG3_XDX = 1 << 8; //scale x
   BG3_XDY = 0; //rotation x
   BG3_YDX = 0; //rotation y
   BG3_YDY = 1 << 8; //scale y
   BG3_CX = 0; //translation x
   BG3_CY = 0; //translation y
   
   //setup exrot bg 3 on sub
   SUB_BG3_CR = BG_BMP8_256x256 | BG_BMP_BASE(8) | BG_PRIORITY(1) ;
   //attributes of the affine translation matrix
   SUB_BG3_XDX = 1 << 8; //scale x
   SUB_BG3_XDY = 0; //rotation x
   SUB_BG3_YDX = 0; //scale y
   SUB_BG3_YDY = 1 << 8; //scale y
   SUB_BG3_CX = 0; //translation x
   SUB_BG3_CY = 0; //translation y
}

int main(void) {
//---------------------------------------------------------------------------------
   int min_x  = 4096 , min_y  = 4096, max_x  = 0, max_y   = 0;
   int min_px = 4096 , min_py = 4096, max_px = 0 , max_py = 0;
   touchPosition touch;


   powerON(POWER_ALL);
   
   //initialise the interrupt system
   irqInit();
   //install our simple vblank handler
   irqSet(IRQ_VBLANK, Vblank);
   //enable the interrupt
   irqEnable(IRQ_VBLANK);
   
   //set the mode for 2 text layers and two extended background layers
   initVideo();

   ///////////////set up our bitmap background///////////////////////
   initBackgrounds();
   
   // black backdrop
   BG_PALETTE[0]=RGB15(0,0,0);
   SUB_BG0_CR = BG_MAP_BASE(31) | BG_PRIORITY(0); ;//use bg0 for the text
   
   
   //consoleInit() is a lot more flexible but this gets you up and running quick
   consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);

   dmaCopy(drunkenlogo_bin, BG_GFX, 256*192);
   dmaCopy(palette_bin, BG_PALETTE, 256*2);
   
   dmaCopy(drunkenlogo_bin,  (void*)BG_BMP_RAM_SUB(8), 256*192);
   dmaCopy(palette_bin, BG_PALETTE_SUB, 256*2);
   
   BG_PALETTE[255] = RGB15(31,31,31);//by default font rendered with color 255
   iprintf("TEST TEXT HERE!!!");
   while(1) {
      swiWaitForVBlank();
      
      // read the button states
      scanKeys();

      // read the touchscreen coordinates
      touch=touchReadXY();
      
      int pressed = keysDown();   // buttons pressed this loop
      int held = keysHeld();      // buttons currently held

      // Right Shoulder button toggles the mode
      if ( pressed & KEY_R) TouchType ^= SINGLE;
      
      
      
      if ( TouchType == SINGLE && !(pressed & KEY_TOUCH) ) continue;

      if ( !(held & KEY_TOUCH) || touch.x == 0 || touch.y == 0) continue;
      
      if ( touch.x > max_x)      max_x = touch.x;
      if ( touch.y > max_y)      max_y = touch.y;
      if ( touch.px > max_px)   max_px = touch.px;
      if ( touch.py > max_py)   max_py = touch.py;

      if ( touch.x < min_x)      min_x = touch.x;
      if ( touch.y < min_y)      min_y = touch.y;
      if ( touch.px < min_px)   min_px = touch.px;
      if ( touch.py < min_py)   min_py = touch.py;
   }

   return 0;
}

#104636 - psycorpse - Sun Oct 01, 2006 12:47 am

I think that this is because you are filling the BG_PALLETE_SUB. Since you are filling up BG_PALLETE_SUB[0] with the dma copy you are telling it that the transparent color is something else. Take out the
Code:
   dmaCopy(palette_bin, BG_PALETTE_SUB, 256*2);


and add
Code:
BG_PALETTE_SUB[255] = RGB15(31,31,31);


Let me know if this works and I will check again later tonight. Leaving for a couple of hours. I do think that this will work though.

Mike

#104698 - smoggie83 - Sun Oct 01, 2006 5:20 pm

still no luck :s

Im completely stumped something like this should be so simple!! it only displays the background when i use dmaCopy(drunkenlogo_bin, BG_GFX_SUB, 256*192); but then the text doesnt work - with the other suggestion only text works :(

#104709 - psycorpse - Sun Oct 01, 2006 7:43 pm

Ok I was able to get this to work. The only problem is that I can only get it to work with the main screen. In this case the top. You could use this screen and just flip the screens so that it is in the bottom. I think that we didn't have the extra memory mapped as well as all the other changes. I have commented the changes that I have made to your existing code. My Comments are in:
/*
* comment here
*/

Also the filp code is
lcdMainOnBottom();

You could try to load that around your videoSetMode() functions.

Code:
#include <nds.h>

#include <nds/arm9/console.h>
#include <stdio.h>

//make file automaticaly makes a header file for access
//to the binary data in any file ending in .bin that is in
//the data folder.  It also links in that data to your project

#include "drunkenlogo_bin.h"
#include "palette_bin.h"

/*
* I didn't have this bin files so I commented them out
*/

//#include "diceRoll_bin.h"
//#include "diceRollPalette_bin.h"

//#include "players_bin.h"
//#include "playersPalette_bin.h"

enum { CONTINUOUS, SINGLE } TouchType = CONTINUOUS;

volatile int frame = 0;

//---------------------------------------------------------------------------------
void Vblank() {
//---------------------------------------------------------------------------------
   frame++;
}

void initVideo() {
   //enable vram and map it to the right places

/*
*  I added VRAM_B_MAIN_BG_0x602000
*/

    vramSetMainBanks(   VRAM_A_MAIN_BG_0x6000000,      //map A and B to main background memory
                        VRAM_B_MAIN_BG_0x6020000,
                        VRAM_C_SUB_BG_0x6200000,      //map C to sub background memory
                        VRAM_D_LCD                  //map D to LCD free space
                  //allows adjacent banks to overflow into D if a bug like that was ever to occur
                        );
   
   //map a bank for use with sprites
   //vramSetBankE(VRAM_E_MAIN_SPRITE); //mapping E to main sprites gives us 64k for sprites
   //(64k is the max space that 1024 tiles take up in 256 color mode)
   
   //set the video mode

/*
* I changed the videoSetModes to this
*/

    videoSetMode(  MODE_5_2D | DISPLAY_BG0_ACTIVE |   
                   DISPLAY_BG3_ACTIVE     //turn on background 3
               );
   
   videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE   );
}


void initBackgrounds() {

/*
* I added | BG_BMP_BASE(8) | BG_PRIORITY(1)
*/

   //setup exrot bg 3 on main as a 16bit color background
   BG3_CR = BG_BMP8_256x256 | BG_BMP_BASE(8) | BG_PRIORITY(1);
   //attributes of the affine translation matrix
   BG3_XDX = 1 << 8; //scale x
   BG3_XDY = 0; //rotation x
   BG3_YDX = 0; //rotation y
   BG3_YDY = 1 << 8; //scale y
   BG3_CX = 0; //translation x
   BG3_CY = 0; //translation y

/*
* I took off the SUB_ on BG0_CR
*/
   BG0_CR = BG_MAP_BASE(31) | BG_PRIORITY(0); //use bg0 for the text     

   //setup exrot bg 3 on sub
   SUB_BG3_CR = BG_BMP8_256x256 | BG_PRIORITY(1) ;
   //attributes of the affine translation matrix
   SUB_BG3_XDX = 1 << 8; //scale x
   SUB_BG3_XDY = 0; //rotation x
   SUB_BG3_YDX = 0; //scale y
   SUB_BG3_YDY = 1 << 8; //scale y
   SUB_BG3_CX = 0; //translation x
   SUB_BG3_CY = 0; //translation y
}

int main(void) {
//---------------------------------------------------------------------------------
   int min_x  = 4096 , min_y  = 4096, max_x  = 0, max_y   = 0;
   int min_px = 4096 , min_py = 4096, max_px = 0 , max_py = 0;
   touchPosition touch;


   powerON(POWER_ALL);
   
   //initialise the interrupt system
   irqInit();
   //install our simple vblank handler
   irqSet(IRQ_VBLANK, Vblank);
   //enable the interrupt
   irqEnable(IRQ_VBLANK);
   
   //set the mode for 2 text layers and two extended background layers
   initVideo();

   ///////////////set up our bitmap background///////////////////////
   initBackgrounds();
   
/*
* I took off _SUB on both BLOCKS
*/

   //consoleInit() is a lot more flexible but this gets you up and running quick
   consoleInitDefault((u16*)SCREEN_BASE_BLOCK(31), (u16*)CHAR_BASE_BLOCK(0), 16);

/*
* I changed BG_GFX to (void*)BG_BMP_RAM(8)
*/

   dmaCopy(drunkenlogo_bin, (void*)BG_BMP_RAM(8), 256*192);
   dmaCopy(palette_bin, BG_PALETTE, 256*2);
   
   dmaCopy(drunkenlogo_bin,  BG_GFX_SUB, 256*192);
   dmaCopy(palette_bin, BG_PALETTE_SUB, 256*2);

/*
* I changed the text color  to white
*/
   BG_PALETTE[255] = RGB15(31,31,31);//by default font rendered with color 255

   iprintf("TEST TEXT HERE!!!");
   while(1) {
      swiWaitForVBlank();
       
      // read the button states
      scanKeys();

      // read the touchscreen coordinates
      touch=touchReadXY();
       
      int pressed = keysDown();   // buttons pressed this loop
      int held = keysHeld();      // buttons currently held

      // Right Shoulder button toggles the mode
      if ( pressed & KEY_R) TouchType ^= SINGLE;
       
       
       
      if ( TouchType == SINGLE && !(pressed & KEY_TOUCH) ) continue;

      if ( !(held & KEY_TOUCH) || touch.x == 0 || touch.y == 0) continue;
       
      if ( touch.x > max_x)      max_x = touch.x;
      if ( touch.y > max_y)      max_y = touch.y;
      if ( touch.px > max_px)   max_px = touch.px;
      if ( touch.py > max_py)   max_py = touch.py;

      if ( touch.x < min_x)      min_x = touch.x;
      if ( touch.y < min_y)      min_y = touch.y;
      if ( touch.px < min_px)   min_px = touch.px;
      if ( touch.py < min_py)   min_py = touch.py;
   }

   return 0;
}

#104771 - smoggie83 - Mon Oct 02, 2006 4:01 pm

hey, thanks for the help! weird to get your head round but at least i can crack on with the rest of the project now! thanks again