Installing a Development Environment

Here, we'll give detailed instructions for installing PAlib on Windows and Linux. Tutorials for any other operating systems still need to be written. No matter what operating system you use, we strongly advise that all PAlib users read the PAlib Template Mysteries Explained section.

Good luck!

Installing PAlib on Windows

Stage 1: Installing the toolchain and the supporting libraries

The first thing you need to do to get you started is download the latest versions of devkitARM and the libraries that come with it, provided by devkitPro. This is the core to all/most homebrew programs on the DS, as it provides the basic functions to access the various hardware functions of the DS. Luckily, the folks have supplied an easy-to-use program called devkitPro Updater, which allows you to install the whole package in just a few clicks.

Download devkitPro Updater 1.5.0

Upon downloading and opening, a basic setup dialogue should appear. There isn’t much you need to change here, though, if you want, you can choose to remove your downloaded files. Simply click through until you get to a screen looking like this:

PAlib itself only requires 8 of these components, but you can install all of them if you wish. The components that need to be installed are:

  • minimal system

[under the expanded 'devkitARM' tree]

  • devkitARM
  • libnds
  • libfat-nds
  • maxmodds
  • dswifilib
  • nds default arm7
  • filesystem

It is also recommended that you also install ‘nds examples’ (examples for libnds) and ‘Programmer’s Notepad’ (a basic IDE), though they don’t necessarily affect the functionality of PAlib.

Once you have chosen your options, proceed to the next page, which will allow you to choose where you want to install the toolchain and the libraries - basically your place for DS development. Put it wherever you like – it doesn’t affect the compilation, as long as you don’t put it in a directory that contains spaces (eg, ‘C:/NintendoDS/devkitPro’ would be fine, but ‘C:/Nintendo DS/devkitPro’ will cause compilation problems).

The updater/installer will then start downloading and installing the required packages. A few dialogs may pop up, displaying ‘Extracting…’ with a status bar, but you don’t need to worry about them – the installation requires no further actions.


Stage 2: Installing PAlib

With the installation of the toolchain and the supporting libraries complete, it’s now time to download and ‘install’ PAlib. Unfortunately, PAlib doesn’t come with an automatic installer, but it’s as easy to set up. First off, we’ll need to download the latest PAlib archive, which can be found at this thread:

Download latest PAlib beta

After the download is finished, you have to create a PAlib folder in the path of your devkitPro folder and unpack it there. This should result in a folder structure similar/identical to this:

  …/devkitPro/PAlib/lib/…
  …/devkitPro/PAlib/template/…
  …/devkitPro/PAlib/examples/…
  …/devkitPro/PAlib/…

Finished! We’ve successfully set up a DS homebrew development environment, and are almost ready to start developing. Now, all we need to do is optionally set up and IDE and try compiling an example.

Installing PAlib on Linux

Download

Download the latest versions of:
devkitARM (x86_64-linux for 64 bit systems or i686-linux for 32 bit systems)
dswifi (not the src one)
libnds (again, not the src one)
libfat-nds
maxmod-nds
default arm7 (not the src one)
PAlib 0912XX Beta

Install

  1. open a terminal and cd to where you downloaded the files. e.g.
    cd ~/Downloads
  2. make a “devkitPro” directory in your home folder.
    mkdir ~/devkitPro
  3. copy the archives to the devkitPro directory and cd to it.
    cp devkitARM* dswifi* libnds* libfat* maxmod* default_arm7* PAlib* ~/devkitPro; cd ~/devkitPro
  4. extract the devkitARM and PAlib archives into the devkitPro folder.
    tar -xjf devkitARM*
    tar -xjf PAlib*
  5. make a libnds directory.
    mkdir ~/devkitPro/libnds
  6. extract the libnds, dswifi, libfat, maxmod, and default arm archives into the devkitPro folder.
    tar -xjf libnds* -C ./libnds
    tar -xjf dswifi* -C ./libnds
    tar -xjf libfat* -C ./libnds
    tar -xjf maxmod* -C ./libnds
    tar -xjf default* -C ./libnds

You should now have:

--/devkitPro
----/devkitARM
----/libnds
------/include
--------all the .h files
------/lib
--------all the .a files
------/default.arm7
------/default.elf
----/PAlib

Paths

After setting up the files you need to set some global paths

Set Paths: (This just needs to be once, as long you dont change the path of devkitPro you dont need to do this again ) Open a terminal and type:

gedit ~/.bashrc

A texteditor should pop up, if it's empty try

gedit ~/.bashrc_vanilla

or

gedit ~/.bash_profile

This is some kind of “auto-start” that is run for every console At the end of the file, add the following lines:

export DEVKITPRO=~/devkitPro  #this will need to change if your devkitPro folder is elsewhere
export DEVKITARM=$DEVKITPRO/devkitARM

Save and close the file, then run

source ~/.bashrc

If you used the .bashrc_vanilla or .bash_profile, substitute it for .bashrc in the above command.

Check

To check if the path is set, enter this in a console:

env | grep DEVKITPRO

This should print out the path to devkitPro

And then it hopefully works … just try to compile an example

PAlib Template Mysteries Explained

Now that you've got a working installation of PAlib, you'll probably want to jump right in and start coding. You should start by checking out the PAlib template in the PAlib/template folder. Go there and you can see that it contains a few files, and three directories. I'll explain a bit about how it works…

Template Description

What is a template? A template is a device to provide the form or structure for content. In other words, it's an empty structure that you will eventually fill with all your development files for a given project like C/C++ (code) files, graphics images, sounds, etc. Then, because you used the template that was already set up with the correct structure, you'll be able to compile your working NDS file easily.

Here's the structure of the PAlib template:

Folders:

  • data - Contains data files that you want to include in your project.
  • include - Contains header files (.h).
  • source - Contains source files (.c, .cpp and .s). Those are your program.
  • gfx - Contains PAGfx (a graphics converter) and the graphics for your program.
  • music - Contains module files (mod, s3m, xm and it) and sound effects (wav) when using MaxMod.
  • efsroot - Contains files which you will be able to read using EFS/other filesystem drivers.

Files:

  • build.bat and clean.bat - These are used to compile and clean your project, respectively.
  • Makefile - This is a special file that tells your system how to convert your project files into a NDS ROM (how to compile your project).
  • logo.bmp - This is the logo that will be shown on the application loader of your Nintendo DS.
  • Template.pnproj - This are the project files that can be used with Programmers' Notepad, a source code editor.
  • source/main.c - This contains your program.

The Code of the Template

Now you should open template.pnproj (Programmer's Notepad) or just go into the “source” folder and open main.c in the editor of your choice. Like its name suggests, main.c is your main program file. It contains the main() function and all the stuff that will be loaded by default when the ROM starts. The template's main.c contains all the basic stuff needed to run PAlib. If you compiled and ran the ROM in an emulator or on DS, it wouldn't do anything, though, just display 2 white screens because you haven't done anything yet but initialize the basics…

Here is what you see when you first open main.c :

////////////////////////////
// PAlib project template //
////////////////////////////
 
// Lines starting with two slashes are ignored by the compiler
// Basically you can use them to comment what are you doing
// In fact, this kind of lines are called comments :P
 
// Include PAlib so that you can use it
#include <PA9.h>
 
int main(){
	// Initialize PAlib
	PA_Init();
	PA_InitVBL();
 
	// Put your initialization code here
 
	// Infinite loop to keep the program running
	while(true){
		// Put your game logic here
 
		// Wait until the next frame.
		// The DS runs at 60 frames per second.
		PA_WaitForVBL();
	}
}

Decoding the Code

If you already know C programming (which you must) this is probably very clear to you. For others, it might not be, so I'll detail everything line by line, even though the comments are there…

#include <PA9.h>

This means: please include definitions for all the PAlib functions into my code, I'll need them! If you don't put this, the PAlib functions will not be recognized, and you will get errors. The concept of using includes will become very important later on as includes are used to add in graphical files, other important code, and more.

int main(){

This may seem weird, but you'll have in every project: it's the start of your program, where everything begins. Just know that anything beyond the '{' will be the executing code!

// Initialize PAlib
PA_Init();
PA_InitVBL();

These two lines will be found in every project using PAlib. The first one is a general initialization. It prepares your program to use sprites, backgrounds, text, everything. Not putting this will prevent PAlib from working. The second one is about the VBL. Basically, the VBL allows to synchronize the program with the screen, at 60 frames per second. If you don't initialize the VBL your program will fail to update stuff that is usually done at VBL (keys, stylus, sprites, etc).

// Infinite loop to keep the program running
while(true){

The while structure executes the code that follows, in brackets, while the result of the command in it (here, it's true (1)), is different from false (0). Here, it's always true (1), so basically this is a loop that will go on forever. What for? Well, if you don't have such a loop, every line of code would be executed just once, and then the program would exit, not displaying anything anymore. This allows the program to continue forever, or at least until the player hits that power button. The concept is that in each run through the while loop, the program will figure out everything it needs to know for the next time it will draw to the screen and then it will draw it.

PA_WaitForVBL();

This last command synchronizes the infinite loop we just saw with the screen rate (60 fps). If you don't put it, the program will function A LOT faster than the screen rate (like 9999 fps which is unplayable) and many things just won't work at all.

	}
}

All this is the closing code, always there, always like this, don't bother about it, just leave it alone :p

Now that you know everything about the template, go on and see how to display text!

 
installation.txt · Last modified: 2010/07/15 09:58 by fincs
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki