 |
X_Splinter Moderator


Joined: Jul 03, 2004 Posts: 793 Location: Portugal
|
| |
|
Posted: Sat Jan 02, 2010 7:45 pm Post subject: [Tut] Start coding for DS on Visual C++ 2008 Express |
|
| |
Hey guys this is a tutorial for introduction how to code for the Nintendo DS
What you need (all are free)
-[IED] Visual C++ 2008 Express (free download from Microsoft.com)
-[library] DevkitPro (This are legal libraries)
-DS emulator for fast testing
-Basic knowledge of C++
What we are going to do is make an "Hello World" for the DS.
1)
First download and install DevkitPro (devkitProUpdater-1.5.0.exe)
http://sourceforge.net/projects/devkitpro/files/Automated%20Installer/
Select to devKitARM as minimal system box for installation (thats all you need).
NOTE: Install it in a place with no spaces like "c:\DevkitPro"
2)
Download and install Visual C++ 2008 Express
VC++ will be your IDE (integrated development environment)
http://www.microsoft.com/express/
3)
Setting up the Environment
When you install devkitPro and PALib, they already add some environment variables for you. But these variables are for the make tool, so the path names are written in “UNIX Style”. So, in order to compile PALib and devkitPro inside Visual Studio, first we need to set a new Environment Variable.
Open “Start → Control Panel → System”. Select “Advanced” then click on “Environment Variables”.
Now, click on the “New” button inside “System Variables” (the lower one) and add a variable with the name “DKP_HOME”. In the “Value” box, write the root folder of your devkitPro installation, “Windows Style” (i.e. “c:\...” instead of “/c/...”).
5)
Download and install the wizard project for Visual C++
http://thepernproject.com/tools/DS/visual_studio_wizard.zip
Now when you start a project in Visual C++ you will see Nintendo DS project.
Select Arm9 project to code.
5.1) (Optional but highly recommended)
Setting Up an Emulator inside Visual C++
Download and install DeSmuME or your favorite emulator.
Click on “Tools”, “External Tools”. Then click on “Add” to create a new External Tool. You can create an External Tool for each emulator you use, but here I show you how to create one for NDeSmuME, the one I use.
Type the emulator name in the “Title” field, then the full path to the emulator EXE file in the “Command” field. In the “Arguments” field you can type “$(TargetDir)\$(TargetName).nds” (without the quotes), and in “Initial Directory” type “$(TargetDir)”. This way you’re passing the .nds file you just built as an argument to the emulator, so it will start automatically.
6)
When start a new project you will already have coded an simple Hello Word.
So lets make something better for your first demo.
Delete all and write the following
| Code: |
#include <nds.h>
#include <stdio.h>
int main(void)
{
int i;
consoleDemoInit();
videoSetMode(MODE_FB0);
vramSetBankA(VRAM_A_LCD);
printf("Hello World!\n");
printf("360-hq.com psp-hq.com");
for(i = 0; i < 256 * 192; i++)
VRAM_A[i] = RGB15(31,0,0);
return 0;
}
|
The first real line of code (consoleDemoInit()) initializes the console (DOS-like) functionality in the library so printf will print text to one screen. Printing is the most complicated thing this demo is doing by far.
Next we set the video mode of the DS. The DS has many video modes with differing uses, all of which will be covered as we go along. For now, just realize that we are putting the DS into frame buffer mode. What this is and how it works will be the subject of much of the next chapter.
The DS has a very flexible video system that allows memory to be assigned to many locations and for many purposes. The next line of code just assigns the first bank of video memory to the LCD. This both unlocks the memory for easy writing and allows the DS to use it as the direct display memory.
The next lines print the infamous hello world.
Finally we write the color data (red in this case) to video memory. Because the screen is 256*192 we loop through each pixel and set its color to red.
VRAM_A is a pointer to the video memory bank A. RGB15 converts the color value to a 15-bit value the DS can understand (more on how color works in the next chapter).
Click on Build
Now go Tools - DeSmuME
And you will see your first demo app for the DS
Now you have a fully working IDE to develop your NDS games and applications. _________________

|
|
|
|