Nintendo DS


Introduction


Version History

Day 1
Environment Setup

Links

WiFiMe

PA_Lib

Linux

Emulators

Downloads

Demos




NDS Magic Key MK2/MK3

   Hosted by
FrogNet


Document made with Nvu

 

Nintendo DS Development Tutorial :: Day 1 :: "Hello, World!"

 

Okay, so you have everything setup and you want to actually code & compile something!  
Well, let's start out with the usual, and very simple, text output code (which no one probably ever uses again).  Take a look at the following code.  It should be pretty simple to follow along.

 

// Includes
#include <PA9.h> // Include for PA_Lib
// Function: main()
int main(int argc, char ** argv)
{
PA_Init(); // Initializes PA_Lib
PA_InitVBL(); // Initializes a standard VBL

//PA_LoadSplash(); // PA_Lib splash screen

PA_InitText(1, 0); // Text system for top screen
PA_InitText(0, 0); // Text system for botton screen

PA_SetTextCol(1, 31, 31, 31);
// 1 = botton screen, 31,31,31 = white

PA_OutputSimpleText(1, 0, 0, "Hello, World!");
// 1 = top screen, 0 = Tile X, 0 = Tile Y
PA_OutputSimpleText(1, 19, 23, "World, Hello!");
// 0 = bottom screen, 19 = Tile X, 23 = Tile Y

PA_SetTextCol(0, 31, 0, 0);
// 0 = botton screen, 31,0,0 = red
PA_OutputText(0, 8, 12, "Text Color = %s", "Red");
// 0 = bottom screen, 0 = Tile X, 0 = Tile Y

// Infinite loop to keep the program running
while (1)
{
PA_WaitForVBL();
}

return 0;
} // End of main()

 

Code Explanation

I hope that most of this makes sense to you.

PA_Init();
Used to initialize PA_Lib.

PA_Init_VBL();
VBL stands for Verticle Blanking Interrupt.  Basically, this happens once a frame and updates the keypad, stylus, and sprite information.  I'll go into this in more detail in on another day.

PA_LoadSplash();
Shows a PA_Lib splash screen.

PA_Init_Text();
Initialize the text output system.  The first parameter is the screen (0=bottom, 1=top) and the second parameter is the background (0-3).  There are 4 backgrounds you can use (0-3), but we'll go into this in more detail later.  For now, we'll use background 0.

PA_SetTextCol():
Sets the text output color.  The first parameter is the screen (0=bottom, 1=top) and the other three are red, green, and blue attribute (0-31).  NOTE: You can only have one text color per screen.

RGB15 Value Color
RGB15(31,0,0) Red
RGB15(0,31,0) Green
RGB15(0,0,31) Blue
RGB15(0,0,0) Black
RGB15(31,31,31) White
Handy RGB15 Reference Chart

PA_OutputSimpleText();
A quick, easy way to output text on the screen.  The parameters are the screen (0=bottom, 1=top),  the X (0-31) & Y (0-24) co-ordinates, and finally the actual text to display.

PA_OutputText();
A more powerful way of outputting text on the screen.  The parameters are the same except that you can manipulate the string.  For example, you can use %s to output a string value, %d to output an integer value, %fX to output a float with X digits, and \n to output a newline.  Notice how I put %s in the first string parameter, and then added a ,"Red" parameter.  If you want further examples of how to use these, take a look at this C++ printf page.

PA_WaitForVBL();
This is used to wait for the next VBL.  Basically, you want to wait for the screen to finish being  drawn before moving on.  Otherwise you'll have trouble with flickering, etc.  Again, we'll go into this in more detail later.

 

Download

Day1_Hello_World.zip

Extract this file into C:\devkitpro\examples\palib\Day1_Hello_World.  You will find the code mentioned above in arm9\source\main.cpp.  Notice that we will not do anything in the arm7 directory - at least not for today.  If you want to test out the compiled binary in an emulator, you'll find Day1_Hello_World.gba & Day1_Hello_World.nds in the arm9 directory.

 

Screenshot

Day1_Hello_World

 

Last Updated: 10/31/2005

 

Google
 
Web aaronrogers.com/nintendods

 

<<

HOME

>>