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 > Help the newbie!

#99148 - MaHe - Sat Aug 19, 2006 8:08 pm

I started programming with PA_Lib in quickly got hang of it. But I was a bit annoyed with it - it sure is easy to use, but it's got it's own limitations, and since Mollusk isn't the main coder anymore, it's really buggy. I've decided to move to libnds and figured out, that I'm actually still a newbie. I didn't know zilch. So here's a 'Hello, World' code I wrote for myself:
Code:
/*********************************************
Name: Hello, world!
Author: Matjaz 'MaHe' Hegedic
Version: 0.01
**********************************************/

// Includes //

#include <nds.h>              // Include 'libnds' in our application
#include <nds/arm9/console.h> // Include the basic print functionality in our application
#include <stdio.h>            // Include 'stdio' in our application

// Functions //

int main() {
   videoSetMode(0);                                 // Use the top screen only
   videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); // Use subbackground 0 to display text
   vramSetBankC(VRAM_C_SUB_BG);           // Map VRAM bank C to subbackground

   SUB_BG0_CR = BG_MAP_BASE(31);           // Set subbackground 0 to 'black'
   BG_PALETTE_SUB[255] = RGB15(31,31,31); // Set the text color to 'white'
   
   // Initialise the default console settings for the text output
   consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
   
   // Output 'Pozdravljen, svet' to the screen
   iprintf("Pozdravljen, svet!");
   
   // Loop infinitely
   while(1) { swiWaitForVBlank(); }
   
   return 0;
}
(yes, the comments are wrong, but I don't care just yet)
This will output 'Pozdravljen, svet!' (Hello, world in my language) on the touch-screen. I'm fine with that, but now I'd like to put it on the top screen. So, I've modified the code:
Code:
int main() {
   videoSetMode(MODE_0_2D | DISPLAY_BG0_ACTIVE);
   videoSetModeSub(0);
   vramSetBankC(VRAM_C_MAIN_BG);

   BG0_CR = BG_MAP_BASE(31);         
   BG_PALETTE[255] = RGB15(31,31,31);
   
   // Initialise the default console settings for the text output
   consoleInitDefault((u16*)SCREEN_BASE_BLOCK(31), (u16*)CHAR_BASE_BLOCK(0), 16);
   
   // Output 'Pozdravljen, svet' to the screen
   iprintf("Pozdravljen, svet!");
   
   // Loop infinitely
   while(1) { swiWaitForVBlank(); }
   
   return 0;
}
Now, this won't work. It only colors the top screen to black, but won't output anything.
Now, I'm sure this is very, very stupid to most of you, experienced coders, but I want to know what have I overlooked ... ?

Thanks in advance! =)
_________________
[ Crimson and Black Nintendo DS Lite | CycloDS Evolution | EZ-Flash 3-in-1 | 1 GB Transcend microSD ]

#99153 - Sausage Boy - Sat Aug 19, 2006 8:48 pm

Try:
vramSetBankA(VRAM_A_MAIN_BG);
_________________
"no offense, but this is the gayest game ever"

#99163 - Lick - Sat Aug 19, 2006 9:55 pm

Does it work on hardware?
_________________
http://licklick.wordpress.com

#99239 - dovoto - Sun Aug 20, 2006 5:57 am

to put it on the top screne change nothing from the first demo but add

Code:
lcdMainOnBottom();


(should not matter where).

This will cause the sub display to render to the top screen. Because the console uses the sub display by default this should be the only change to make.

If you want the console to use the main display you will need to init the console with:


Code:
/*! \fn void consoleInit(u16* font, u16* charBase, u16 numCharacters, u8 charStart, u16* map, u8 pal, u8 bitDepth)
   \brief Initialise the console.
   \param font   base address of the 16 color font to use
   \param charBase   VRAM address to load the font
   \param numCharacters number of characters in the font
   \param charStart ascii code of the first character in the font
   \param map base address of the map to use for printing
   \param pal 16 color palette index to use
   \param bitDepth 256/16 color tile flag.
   
   Initializes the console with the given parameters. When pal is greater than 15 and
   bitDepth is 16 then   all non zero entries in the font are set to index 255. When bitDepth
   is not 16 then the font tiles are created as 8bit (256 color).
 
*/
void consoleInit(u16* font, u16* charBase, u16 numCharacters, u8 charStart, u16* map, u8 pal, u8 bitDepth);


Although the libnds console is pretty flexible it is not intended for extensive in game use...more for prototyping and debuging and quick tests. I recomend you stick with consoleInitDefault() or consoleDemoInit() (which is even simpler) and when you find you need a better looking text renderer you write one.
_________________
www.drunkencoders.com

#99302 - MaHe - Sun Aug 20, 2006 3:56 pm

Thanks a lot to all of you :)
Now, can libFB (www.dragonminded.com) completely replace the current console? I'm leaning towards it, since it has a plethora of useful features...
_________________
[ Crimson and Black Nintendo DS Lite | CycloDS Evolution | EZ-Flash 3-in-1 | 1 GB Transcend microSD ]