Nintendo DS

From Free Pascal wiki
Jump to navigationJump to search

Nintendo DS port

History

NDS port began and was created by Francesco Lombardi with the knowledge gained from the making of the GBA port. This endeavor is an extension of the original goals of the FPC 4 GBA project.

Status

  • All fpc major features are fully supported
  • ASM THUMB mode is not supported yet.
  • The compiler is built for Win32 and Linux

Port notes

Nintendo DS can run executables made for ARM9 and/or ARM7 cpu. It is possible to switch between ARM9 and ARM7 by using

{$apptype arm9} 
and
{$apptype arm7}

That generates .nef.bin and .nlf.bin binaries. If not specified, fpc assumes arm9 as default apptype and, in this case, calls ndstool.exe (a tool you can find as part of devkitPro) in order to generate a patched binary with .nds extension. This file should work on your hardware/emulator. In case of an arm7/arm9 mixed program, it is necessary to compile separately arm7 and arm9 code, then convert the .nef.bin and .nlf.bin binaries with ndstool.exe in this way:

ndstool -c myprog.nds -9 myprog.nef.bin -7 myprog.nlf.bin

The current NDS port is tested and reported as working with the latest devkitPro arm-eabi binutils.

Why .nef and .nlf?

.nef means "not executable file" and it is the extension that no$gba debugger uses for loading arm9's synmbolic debug infos from. In the same way it loads arm7's debug infos from .nlf files.

What I need to start coding for Nintendo DS?


Documentation

(All these docs are aimed to C/C++ language)

  • Dev-Scene tutorials: some good tutorials about Nintendo DS programming.
  • Patater's manual: a manual that covers topics including the legality of homebrew and the politics behind it, displaying backgrounds on both screens, sprites, and a bit of game mechanics.
  • TONC tutorial: this is a tutorial aimed to Gameboy Advance programming, but it is perfectly adaptable to Nintendo DS. You can find a lot of tricks about optimizing your code too.
  • Homebrew Nintendo DS Development
  • The DS Wiki a Wiki aimed to Nintendo DS programming.
  • GBATEK: GBA and NDS technical infos. THE Bible!

Tools

  • DeSmuME emulator: a pretty good NDS emulator. The emulator has some debugger functions and it implements a GDB stub mechanism.
  • No$GBA emulator: at this time, it's the best NDS and GBA emulator. The emulator itself is freeware; for 15$ you can get the debugger.
  • iDeaS emulator: another good emulator. Though its level is not comparable to no$gba, it comes for windows and linux too, and has some debugger funcs.

Using Lazarus for Nintendo DS development

A fpc 2.4.0 based distribution of Lazarus is needed.

  • Select Project->New project->Program
  • Modify the code removing the unneded parts:
program Project1;
{$mode objfpc}
uses
  ctypes, nds9;

begin

end.
  • From the menu Project->Project options...->Compiler options select "NoGUI" as LCL widget type
  • Move on Compiler options->Code then select "arm" as Target CPU and "nds" as Target OS
  • Move on Compiler options->Other then check "Use additional Compiler Config file", writing the config file of your nds compiler (maybe something like c:\lazarus\fpc\2.4.0\bin\arm-nds\fpc.cfg). Lazarus will complain about some conflicting names, but just do ok and all will be fine
  • From the menu Run->Run parameters...->Local->Host Application select your emulator with full path (something like c:\desmume\desmume.exe)
  • Put $ProjPath()\$NameOnly($ProjFile()).nds on "Command line parameters" field

What works: Code completion and all code related features (tooltips, refactoring, ...)

What DOES NOT work: the debugger (use the debugger on the emulator); the LCL (you can't make applications in the visual way. The NDS coding is somewhat similar to console application programming)

Links