Me, myself, and my code

Using KDevelop With Libnds and devkitARM

| Comments

KDevelop is a full featured IDE for the K Desktop Environment.

In order to take full advantage of the facilities KDevelop has to offer, we’re going to take an existing template based project, and import it as a Makefile project in KDevelop. In order to do this, first create a template based project as described in the “Using the provided template Makefile” tutorial.

Now that you have your project directory set up it’s time to import the directory into KDevelop and make a KDevelop project file.

To do this, click the “Project” menu, and then the “Import Existing…” to bring up the import existing project dialog. Select the project directory you made in the first part of this tutorial and give the project a name.

For project type you’re going to want to select either “Generic C Project (Custom Makefiles)” or “Generic C++ Project (Custom Makefiles)” your choice of C or C++ doesn’t matter too much at this juncture, so just stick with C. We select “Custom Makefiles” because we want to use the provided nds-example template makefile.

Finally enter your name and e-mail address and click next. When it asks you if you want to populate the project with files from the source, go ahead and click yes.

You now have a project file for your project directory!

Unfortunately you’re not done yet. If you attempted to compile your project now you’d notice that you wouldn’t get very far. KDevelop will start with a clean environment for the project, so we need to set DEVKITARM and DEVKITPRO in our project.

To do this click “Project” then “Project Options” then select “Build Options” and finally the “Make” tab. There will be a section for environment variables. Add the appropriate variables for DEVKITARM and DEVKITPRO and click “Ok”. At this point your project should now successfully compile!

You could start developing right now, but you’d quickly notice that code completion doesn’t work for types and functions. This is because KDevelop needs to be told where the devkitARM and libnds include files reside.

To set this select “Project” then “Project Options” and choose “C++ Support”. At the bottom of the dialog there is a section for custom “Code Completion Databases” this is really just a collection of paths to the include files you’ll be using to develop your application.

Create one of type “KDevelop Custom Directory PCS Importer” and provide the paths to the devkitARM and libnds include directories. If you followed the environment instructions exactly these should be:


Click next and name the PCS importer something witty and original like… oh… “NDS Homebrew Includes”.

Click ok and you should now have working code completion!A word of warning, there is a known issue with the current stable KDevelop (3. 2 tree) which causes typedefs for structs of the form below not to work.

    typedef struct {
        struct members
    } typeName;

Any structs declared as such will not complete correctly. In addition, KDevelop will not code complete #define variables such as the VRAM_A_* types. I have yet to find a way to fix this.

So you can compile and code complete. But I’ll bet my dinner that you want to be able to actually EXECUTE our compiled source so that the “Run” command does what you would expect right? Well, if you’ve installed an emulator you can tell KDevelop to use that emulator to execute your nds file.

To set the emulator as your executable click “Project” and “Project Options” then select “Run Options” enter the full path to your emulator on the executable line, and in the arguments line give the full path to your project NDS file. In most cases this will just be the name of your project directory with .nds at the end. For our helloworld project the resulting file will be “helloworld.nds”.

You now have a full featured KDevelop project!

One word of warning: If you did set an executable in the Run Options, then every time you open up the project options KDevelop will screw this section up. You’ll need to edit the file to remove the “file://” that KDevelop inserts at the beginning.

Using the Libnds Example Template Makefiles

| Comments

Of the different methods for setting up a project, using the provided template Makefiles is by far the easiest.

Packaged with the Nintendo DS examples package that you downloaded (you did download the examples package at my suggestion… didn’t you?) there is a directory called “templates”.

This directory contains a number of template project directories, each designed to make use of the environment variables set during the tool chain install step.

Using these templates is a very simple process. I will describe how to do this both in Linux and in Windows. Following in the grandest of programming traditions, lets call our project “helloworld”.

In Linux:

First lets create a directory for our project in our home directory:

    mkdir ~/helloworld

Next lets copy over the arm9 template ( I assume you’ve extracted the examples archive to your devkitPRO directory ):

    cp -R ${DEVKITPRO}/examples/templates/arm9/* ~/helloworld/

That’s all there is to it!

Each template already comes with a default main.c file containing the equivelent of a hello world application, so you’re ready to go!

To test it, change to the helloworld directory and type make.

    cd ~/helloworld/make

In Windows:

The instructions for Windows are almost identical to the instructions for Linux. The only differences between the two are really the Windows style commands and paths.

Create a new folder for your project.

Note: You must make sure that your project directory path does not contain any spaces!

For this reason I would suggest creating a directory under c:devkitPro called “projects” in which you will put all of your NDS Homebrew Projects.

Once the directory has been created, copy everything inside the directory “C:\devkitPro\examples\ndstemplates\arm9” into your new project directory.

To build your project open a command shell

Start –> Run –> Type “cmd” –> click ‘Ok’

Change directories to your project directory

    cd c:\devkitPro\projects\helloworld

type ‘make’

If all is set up correctly in either operating system, when your make process is complete you should find two files one called helloworld. nds and one called helloworld. ds. gba. These two files are for the different respective types of NDS Flash Carts.

If you boot up your new NDS program you will see the “Hello DS dev’rs” hello world app!

Congratulations, you have your first project.

For more information read the documentation provided with the example templates, and poke around the provided example code.

Using devkitARM and Libnds With Visual Studio 2005

| Comments

I’m primarily a Linux user, as such I do almost all of my development in Linux either using gVim or KDevelop. Despite my affinity for the aforementioned IDEs and OS I would still be hard pressed to find an IDE better than Microsoft Visual Studio 2005.

This being said, using Visual Studio 2005 with devkitARM and libnds is both simple and a joy. The setup procedure can seem a little daunting (especially if you’ve never had to configure your own Visual Studio project before) but it’s not too bad.

Note: The NDS Example files do come with a Visual C++ project which can be imported, and can be used as a good building block to start a full solution from, however, if we did that we wouldn’t learn anything. ;)

First follow the instructions for creating a template based project.

In order to create a solution you’re going to have to open Visual Studio and import our existing template as a project. Luckily for us Microsoft Visual Studio 2005 has a nifty wizard which will help us with just that.

Click the “File” menu, select “New”, and click “Project from Existing Code…”.

You will be presented with the dialog shown below. You’re going to want to select Visual C++ project as the type and click next.

Visual Studio 2005 Setup - Step 1

The next screen allows us to select our project name and directory. Choose the project template directory mentioned earlier as the project directory, ensure that “Add files to the project from these folders” is checked. The project wizard will automatically add the project directory to the list of directories to populate the project with.

Visual Studio 2005 Setup - Step 2

Next we get to chose our build system. Make sure to chose external make system and select next.

Visual Studio 2005 Setup - Step 3

This screen is where the build magic happens. Lucky for us the amazing people over at devkitPro. org have already devised a simple make/sed combo which will allow the make output to be interpreted by visual studio as error reports it can understand.

The string is: make -r 2>&1 | sed -e ’s/(.[a-zA-Z]+):([0-9]+):/1(2):/‘This string should be used as both the build command line, as well as the rebuild command line. Use “make clean” for the clean command line. Finally use the name of the project directory with .nds at the end as the Debugging output.

Visual Studio 2005 Setup - Step 4

Click next, select same as Debug settings, and click finish!

You should now have a working project solution!

You can now build your project and watch as Visual Studio chugs along and builds with our magic build command line. This is fine and dandy, but after a little development you’ll notice that IntelliSense (Microsoft’s proprietary code-completion) doesn’t completely work. In addition you have no way to effectively debug the Nintendo DS applications that have been built.

With a little bit of project configuration you can make IntelliSense work and cause debugging to launch your application in your emulator of choice.

Configuring IntelliSense

To configure IntelliSense you’ll need to add your devkitARM and libnds directories to both the project include directory list.

To get to the list, right click the project icon ( it will be located under the solution in the “Solution Explorer” sidebar ) and select “Properties”.

Once inside of the properties window make sure to select “All Configurations” from the configurations drop-down. Not doing so will cause the changes only to be applied to the Debug release, and changing the setting to Release will produce unexpected results.

Visual Studio 2005 Setup - Step 5

Executing your emulator of choice on application debugging

Select the “NMake” category under “Configuration Properties” and select “Include Search Path”. Clicking “Include Search Path” should make a “…” button visible. Click the “…” to open the Include Search Path edit dialog. Add your Devkit Pro directories to the search path and click ok.

Finally, to set up your emulator to launch on project debug select the “Debugging Category” under “Configuration Properties”.

In this section you should be able to select your emulator command, arguments, and working directory.

Set “Command” to the emulator executable, set the “Command Arguments” to “$(TargetPath)” and set the “Working Directory” to the full path to the executable.

Visual Studio 2005 Setup - Step 5

Click ok and you should now have a fully functional Solution complete with IntelliSense and debug to emulator!

Setting Up an NDS Homebrew Tool Chain in Linux and Mac OSX! (Ok… Windows Too…)

| Comments

UPDATE: Given the updates made in the DevkitPro project since this article was written, it is quite out of date. For Linux, there is a little bit of hope! Commenter Namoul has created an installer script which can be used to get your development environment up and running. Find it here:

Well, I realize I had promised to give instructions for both Windows and Linux, but as it turns out, the instructions for Windows are so simple it’s almost laughable.

Are you windows users ready?

Installing devkitARM and setting up your environment in Windows. 1. Run the updater script you downloaded in the previous section. 2. Select devkitARM, libnds, the examples, programmers notepad 3. Finish the install

That’s right. That’s it. You’re done Windows users. Now go have a coffee while us linux users get ourselves up and running. :)

Installing devkitARM and setting up your environment in Linux and Mac OSX.

To be honest, the process isn’t all that much more complex, but it does assume you know a little bit about setting environment variables.

The first thing you’ll need to do is make sure you’ve downloaded the devkitARM binary package, the libnds source package, and the example code package mentioned in the previous post.

Step 1) Setting up the directory structure:

First we need to set up a development path. This path can be anywhere, but for the sake of this tutorial we’ll assume you’re installing to /usr/local/devkitPRO/.

The first thing we need to do is create our directory structure:

For now this is as simple as

    mkdir /usr/local/devkitPRO

But by the time we’re finished it should look something like


Step 2) Installing the devkitPro binaries:

Next we’ll want to uncompress our devkitARM tar. bz2. Assuming you’ve downloaded the devkitARM archive to your home directory, this can be acomplished by changing to the devkitPRO directory we’ve just created and running:

    cd /usr/local/devkitPRO/
    tar -xjvf ~/devkitARM_r20-linux.tar.bz2

the devkitARM tar.bz2contains a root directory called devkitARM which when compressed will contain the toolchain and a series of helpful binaries located within its “bin” directory.

Step 3) Decompress the libnds source:

Next we’ll need to decompress libnds. Unlike the devkitARM archive, libnds does not contain it’s own base directory, so we should create one for it now, and decompress to that directory.

    mkdir /usr/local/devkitPRO/libnds
    cd /usr/local/devkitPRO/libnds
    tar -xzvf ~/libnds-20070503.tar.bz2

Now you have the source and tool chain necessary to build libnds into a fully fledged library for your linking pleasure. Unfortunately, if you’re at all familiar with Linux, you’ve likely already typed make, and to your surprise you’ve received a warning!

We need to set up some environment variables so the makefiles know where the tool chain and other libraries live.

Step 4) Set some environment variables:

First we need to set the DEVKITPRO variable to point to our devkitPRO install directory:

    export DEVKITPRO=/usr/local/devkitPRO

Then we need to set DEVKITARM to point to our devkitARM install location

    export DEVKITARM=${DEVKITPRO}/devkitARM

To make things easier for me, I just added the following three lines to the bottom of my ~/. bashrc file so every interactive shell would have access to these environment variables.

    #Set Variables for DEVKIT_PRO
    export DEVKITPRO=/usr/local/devkitPRO
    export DEVKITARM=${DEVKITPRO}/devkitARM

Step 5) Compile libnds:

Now that we have our environment variable set, we can compile libnds. Just go back to our libnds directory and type make!

    cd /usr/local/devkitPRO/libnds

If all went well, you should see a bunch of text fly by, and eventually successful completion!

Step 6) Bake until golden brown:

Congratulations, you now have a successfully built Nintendo DS development tool chain and libraries.

If you’d like to test your toolchain you can extract the example source tarball that I suggested you download in the previous tutorial, and type make in it’s root directory. If everything is correctly set up, it should create a Nintendo DS ROM for each example in the examples directory.

The examples may not make much sense now, but make sure to poke around the examples. They’re one of the most useful resources a Nintendo DS homebrew developer has at his or her disposal.

Final Notes:

A final suggestion would be to install a Nintendo DS Emulator on your computer if you haven’t already. This way you can begin experimenting with your Nintendo DS examples even if you don’t yet have a DS or development hardware. However, when it comes to testing your shiny new Nintendo DS programs, nothing beats booting them on a Nintendo DS.

I would highly recommend that every budding Nintendo DS developer own at least one Nintendo DS. Besides… when you’re not developing you can pop in your Mario Kart or Tetris cartridge and enjoy Nintendo’s awesome handy-work!

Now that you have a working tool chain set up, you should go on to configure your IDE of choice to use devkitARM and libnds.

Nintendo DS Homebrew: Tools of the Trade

| Comments

How the heck do you do this?

There are few things more essential to the budding homebrew developer than their development environment. As we’re just starting out, we have yet to even get our environment together. As such our first task should be to gather our tools and get ready to install.

There are two very important packages every homebrew developer should be aware of.

The first of these two is a package called devkitARM. DevkitARM is a full compiler toolchain for the ARM chipset on which all Nintendo DS games run.

Why do you need a toolchain?

Because executables differ from platform to platform. If you just take your home Visual Studio install and compile a “hello world” application, it will compile for your host operating system and architecture. Unfortunately the set of instructions that your (likely intel) CPU and the instructions that the Nintendo DS’s ARM CPUs understand are not very similar at all. As such you need a set of tools which can create executables for your target platform.

Getting devkitARM.

DevkitARM provides just those tools, as well as an additional set of tools which should make your homebrew development that much more fun.

Now that you’re excited to get those files, devkitARM can be found at the following addreses:

For windows, you’ll want the devkitPro updater, which is a full installer for windows, and will get you up and running with minimal work.

Download the devkitProUpdater for Windows from Sourceforge.

For Linux or Mac OSX, you’ll want to grab the binaries for devkitARM at the following address:

(There are windows binaries as well, but windows users should just use the super spiffy auto updater.. it’s much easier.)

Download the devkitARM binary archive from Sourceforge

Now that your programming arsenal has increased by one cool package, it’s time to get your Nintendo DS development library.

Getting libnds.

The only library you should concern yourself with at this point is libnds. Libnds began as a series of useful #define statements to make Nintendo DS development a bit easier. Over time it evolved into a full development library with support for most of the functionality of the Nintendo DS. Through libnds, the enterprising developer even has support for 3d through a series of functions which look incredibly similar to OpenGL.

If you’re running Linux or Mac OSX you can get the library here:

Download the libnds source archive from Sourceforge

If you’re running Windows, don’t fret, the auto updater will fetch libnds for you!

Example code anyone?

The final archive I would suggest everybody have on hand is the latest copy of the nds examples. This archive contains a series of example code showing most of the implemented functionality within libnds.

As above, Linux and OSX users use the below URL. Windows programmers should use the auto updater to get these files.

Download the Nintendo DS example code from Sourceforge

Tune in later for information on how to turn these archives into a full fledged development environment!

Firefox Extension Development

| Comments

My current position gives me the opportunity to do web development on a daily basis. Thanks to tools like the Web Developer Toolbar, and Firebug extensions for Mozilla Firefox, web development has been made much less painful than it once was.

These extensions are a boon to my daily development schedule. The extensions increase my productivity by keeping me from spending a majority of my time tracking down simple problems and instead let me focus on fixing the big things. In addition they provide a number of tools that allow me to carefully tweak my pages without altering any actual backend code, experimenting on the fly, and saving precious time which might be lost to repeated “edit –> page load –> test” cycles.

No matter how much I optimise my process I keep finding situations in my current development at work which could be streamlined through the careful application of custom scripting in my browser. Until recently I would satisfy my need for automation of repetitive tasks by creating a carefully crafted Greasemonkey script or by crafting a cleaver bookmarklet. At the end of the day yesterday I decided to take stock of the tools that I had created or modified to help speed up the majority of my repetitive day-to-day development tasks. Needless to say, there were more than a few.

Inspired by the web developer toolbar I’ve decided to develop my own Firefox extension. This extension would provide a number of tools to simplify my life when developing within Oracle’s Application Express which will provide a number of customization options to the existing Application Express editor, as well as a number of shortcuts for common development tasks.

I’ve only just begun development, but I’m hoping the end result will be a benefit to more than just myself.

My initial experience with extension development has been full of swinging mixed emotions.

At this point I have a number of thoughts on Firefox Extension Development:

  1. I love XUL… well.. I love XML, so it isn’t that much of a stretch. XUL’s simplicity and ability to extend the browser through overlays is amazing.
  2. I hate the default directory structure that the majority of the tutorials out there tell you to use.
  3. I hate that the default tutorial on XulPlanet makes note of required directory structure, but lacks any mention of the proper structure for extension development.
  4. I love that someone created a build script for extensions that follows a defined directory structure so I don’t have to worry about number 3.
  5. I love the built in localization functionality.
  6. I hate the chrome.manifest file. The only reason I can stand it is because the build script mentioned above will allow you to write it in such a way that it will work in both development and packaged form.

All and all I’ve learned a whole bunch about Firefox extension development over the past two days.

Maybe once I’m finished I’ll write my own Firefox extension development tutorial since I’ve found the majority of the tutorials on the internet to be severely lacking (with the exception of the XUL Tutorials from XulPlanet. Those are amazingly in depth).

Well folks, I’m officially overloaded with projects.

Wish me luck.

The Internet Returns!

| Comments

For the past week or so I’ve been without a reliable internet connection. But now, I’m proud to say we have a reliable means of digital communication!

Now that I can get on the web I can get back to work on my Nintendo DS development and tutorial writing.

For those of you who I know are waiting on my tutorials keep in mind that the devkitPro website contains a good many tutorials in their FAQ and Setting Up websites (which I will be citing information from). So if you just can’t wait to get up and running, I highly suggest visiting their site.

So You Want to Make Nintendo DS Homebrew…

| Comments

If you’re like me, and you’re new to the Nintendo DS scene, the first thing you’ll notice is that you have a long road ahead of you before you can call yourself an expert homebrew developer. You’ve probably scoured message boards, websites, IRC channels, and source code soaking up as much information as you could so you could be somewhat ready to begin developing.

Well you’re ready to start… but how do you do that? Where are the tools? How do you install them?

Never fear folks, I’ve collected this information and will provide you with step by step instructions for getting your development information up and running!

Over the next few days I’ll be posting these how-to tutorials on my site which should explain every step you need in order to start developing for your Nintendo DS.

Topics which will be covered are as follows:

  1. Getting the tools of the trade.
    • devkitARM
    • libnds
  2. Setting up your development tool chain.
    • In Windows
    • In Linux
  3. Creating your first Nintendo DS development project

You’ve Won a New Job!

| Comments

I’m excited to announce that I’ve officially been selected for, and have started working as a Software Engineer, Associate, position at Paetec Communication’s Software Division Pinnacle.

I will return to work with my colleagues from my first and second co-op blocks. I’m happy to be back with everybody and I’ll keep those who care posted on my progress and exciting adventures in Pinnacle land!

For those of you who are interested in tracking my job progress feel free to click my profile link for the corporate social networking tool LinkedIn.

A Plethora of Summer Projects

| Comments

As is always the case, when I’m not studying, I’m working on my own little projects.

Last summer I set up this blog, developed my resume website, and learned Ruby. This summer I have my eyes set on something a little bit loftier.

Near the end of last summer I broke down and purchased a Nintendo DS. Rumored to stand for “developers system” I purchased the console for five very distinct reasons.

  1. New Super Mario Brothers (A new 2D side scrolling Mario game?! I’m in!)
  2. Mario Kart DS. (Mario Kart in your pocket! Who could say no!)
  3. Tetris DS. (Fit the blocks into rows… the 8bit music compels you!)
  4. The prospect of a new Zelda game (Still waiting for this to come out.)
  5. Homebrew Nintendo DS Development

That’s right, you read the last one correctly. Ever since I saw one of my friends complete his Computer Graphics 2 coursework on a Game Boy Advance I’ve wanted to write something for a Nintendo video game system. On one of my various expeditions onto the internet I stumbled across which in turn pointed me to a whole host of homebrew Nintendo DS development resources. Well, 70 dollars of development hardware later I have a working homebrew Nintendo DS SDK.

Now it would be a shame to go through all that trouble to get my SDK working and not do anything with it, right?

Well as it would happen, I’ve had an idea for a console game which would work very nicely on a Nintendo DS! All I needed was the time, and the incentive. Now that I’m working full time again, I have quite a few weekday nights where I won’t be working on school projects! As for incentive, if I manage to complete this game maybe I’ll become famous! (Unlikely… but as good an incentive as any.)

As the weeks go on you should be able to find an ever growing number of posts about my progress in developing this game, as well as a chronicle of the things I’ll learn as I do my best to develop a Nintendo DS game.

Here goes nothing!