HelloWorld

 

The purpose of this assignment is to help you get started, comfortable with programming the nintendoDS.


In this assignment you will basically learn how to compile programs for the nintendo DS and then run them on the console.


Going forward it is expected that your nintendoDS works with the downloaded kernel. In case you haven’t- go through the Getting started page before continuing.


devKitArm- that we have downloaded already has a helloWorld example. We are going to:


  1. 1.Understand the code

  2. 2.Compile it

  3. 3.Run it on the emulator

  4. 4.Run it on the console

...and it shouldn’t take too long

  1. 1.Understanding the code

Here is the a simplified version of code from the helloWorld example that comes with devKitArm, along with comments explaining it.


The following code displays hello world along with a counter counting the number of frames that have been displayed till now.


But before we go into it- IRQ-VBLANK is the interrupt raised when the entire frame(screen) has been drawn.


/*---------------------------------------------------------------------------------


$Id: main.cpp,v 1.13 2008-12-02 20:21:20 dovoto Exp $


Simple console print demo

-- dovoto



---------------------------------------------------------------------------------*/

#include <nds.h> //from libnds (more on this later)

#include <stdio.h>


volatile int frame = 0; //set the frame counter to 0


void Vblank() {

frame++; //increment the frame counter. We do this only once per frame

}


int main(void) {


consoleDemoInit(); //Initialize the console

irqSet(IRQ_VBLANK, Vblank); //this line says: When the IRQ_VBLANK interrupt occours execute function VBlank


iprintf("      Hello DS dev'rs\n");


while(1) {


iprintf("\x1b[10;0HFrame = %d",frame); //print out the current frame number

swiWaitForVBlank(); //This line basically pauses the while loop and makes it wait for the IRQ_VBLANK interrupt to occour. This way, we print only once per frame.

}


return 0;

}


This program is in an infinite loop and will never end

2. Compiling the code

This code is located at: C:\devKitPro\examples\nds\hello_world\source


  1. 1.We use Programmers Notepad to compile this code. This is found at: C:\devKitPro\Programmers Notepad. Run the pn.exe file.

  2. 2.File > Open > C:\devKitPro\examples\nds\hello_world\makefile

  3. 3.Don’t worry about what you see in the editor!

  4. 4.Click Tools > make

  5. 5.That should be all. Make sure you have a C:\devKitPro\examples\nds\hello_world\hello_world.nds file.

3. Running it on the emulator

  1. 1.Run the DeSmuME.exe

  2. 2.Open > Open ROM > select the C:\devKitPro\examples\nds\hello_world\hello_world.nds file that you just compiled.

  3. 3.You should see the following…

4. Running it on the console

  1. 1.Copy the C:\devKitPro\examples\nds\hello_world\hello_world.nds file that you just compiled to the microSD card. This is just like you copied the kernel files earlier.

  2. 2.Select “Star wars lethal alliance..“

  3. 3.Select the yellow face icon to the left

  4. 4.You should now see a hello_world.nds. Select it.

  5. 5.This program can not be stopped. You need to switch off the console to exit it.

 
This homepage is created by Joshi Shreyas.