Python on Nintendo DS

lickspittle at lickspittle at
Wed Dec 21 01:46:28 CET 2005


I tried porting Python to the Nintendo DS, and it was surprisingly
easy.  Installing something called devkitPro, devkitARM, libNDS, msys,
msys-DTK and then just using that to cross compile a python

Heres a screenshot of it running in the Dualis emulator.  It runs
flawlessly for what has been compiled into it:

You can download the source code to link against the static library and
add a method of input (which you can see in the picture).  Also
included is a .nds file for running on your Nintendo DS:;4497277;;/fileinfo.html

You click on keys on the touch screen to enter input.  Notes: The
clicking on keys in the emulator is extremely non-responsive, on the
DS, it is perfect.  Also, the emulators do not handle displaying the
right bits and pieces to the right screen, so the keyboard is displayed
on the top screen and the console on the touch screen (so its kind of
hard to use as you can't see the regions on the touch screen to click
on).  The .nds file can be recompiled to use the lcd screens right for
emulators, but the .nds file was compiled to work correctly on a DS.

A problem..  On Dualis, the interpreter works perfectly.  However, on
the Nintendo DS, it is completely unreliable and seems to corrupt at
random points.  Occasionally you can get to the command line and enter
one command or two, but its guaranteed to corrupt at some point.  I
have no idea why this is.  I have to assume that Dualis implements the
processor and hardware specs more flexibly than they actually are on
the DS.  And that there is some way the compilation options or linking
options can be modified to restrict the output to what the DS can
actually run.

If anyone has the time and interest to give it a shot at getting it
working, you will need a Nintendo DS with some form of homebrewing
hardware which lets you put storage mediums into the DS with custom
media.. like compiled .nds files.  I use a Supercard, the compact flash

As for the installation of tools required to compile .nds files, I used
the following page:
Then I went to the mingw sourceforge page and got msys-dtk and
installed that so that I would have autoconf and automake.
Then I extracted Python2.4 source code and opened a dos console, cd to
the directory with the Python source code and type the following:

set BASECFLAGS=-mcpu=arm9tdmi -mtune=arm946e-s -ffast-math -mthumb
-mthumb-interwork -DARM9
set CFLAGS=-mcpu=arm9tdmi -mtune=arm946e-s -ffast-math -mthumb
-mthumb-interwork -DARM9
set LDFLAGS=-specs=ds_arm9.specs -g -mthumb -mthumb-interwork
sh configure --host=arm-elf

This should give you a makefile, now you need to edit it.  Change AR to
have a value of arm-elf-ar (configure doesn't pick that up properly).
Also, where there are references to OBJECT_OBJS, you need to also enter
NDS_OBJS to get included along with it.  And enter the following in the
makefile somewhere, maybe after OBJECT_OBJS

NDS_OBJS = RISCOS/Python/getcwd_riscos.o

Also, go into Modules and edit Setup.  Comment out all four of the
modules still listed uncommented in the same block, posix, errno, ...
Now in the top level python source code directory, type make.
It should make and then error claiming it can't link against some
function to do with ThreadState, locate all calls of that function in
Python/pystate.c and comment them out -- this is a bug in the Python
2.4.2 source distribution that pops up when threads are disabled.  Now
it should compile the static library and error on the python.exe (which
is of no use to us).

You should now be able to compile the contents of
against that library (you'll need to make cosmetic changes to the
Makefile of course).

Anyway, if anyone can help with working out how to change the
compilation or linking options to get the code to work properly on the
DS, please email me.

More information about the Python-list mailing list