I've been using the hugs98-Sep2006 source from www.haskell.org/hugs in this port.
Prerequisites
To re-trace the steps I've made when porting you will need the following:
- the hugs source
- an on-screen keyboard (OSK) implementation e.g. HeadKaze's keyboard
- some means to run homebrew. I'm using the M3 DS Simply, more notes below.
- a dldi patcher and the appropriate driver for your target
DevkitPro is a tool-chain for, among others, the Nintendo DS. It's a MinGW for ARM, including libraries for DS development; libNDS and libFAT.
Regarding running homebrew, I would've liked to be able to develop against an emulator, but I've had problems getting the FAT library working. That forced me to compile and deploy on device to be able to test. To do this I've used the M3 DS Simply, which is a slot-1 cartridge that uses microSD cards. The emulator that I found the most usable is Dualis, but it won't, as noted, play nice with libFAT.
Setup
DevkitPro comes with a couple of example applications. These all use a standard Makefile template from the devkitPro installation and to make things easy for us we'll use this Makefile as well. The Makefile assumes that project data is stored in the following structure:
Makefile
data
source
build
include
Copy the hugs source c files from the src dir into source and the header files into include (except array.c, dirprim.c, iomonad.c, preds.c, scc.c, timer.c, bignums.c, interns.c, parser.c, printer.c, timeprim.c, unitable.c which should go into include as well). We do not use runhugs.c at the moment since the Makefile assumes that there is only one main, hugsscript.c isn't needed either so delete both.
Copy the keyboard sources into the working directory as well, c-files to source and h-files to include.
Now we need to turn on the defines appropriate in config.h and options.h. These I determined through trial and error, since the devkitPro tool-chain lacks both configure and autoconf. You might want to either copy the *.in files or run an external configure to get the actual header files. Platform.h was altered to reflect the platform. I also took the liberty to define a couple of new values for the platform in config.h. I won't bother listing all here, but just give you the altered headers (see below).
Note HUGSPATH and HUGSDIR, since these will determine where we will put our Haskell libraries source files. These we'll copy from e.g. a Windows installation of Hugs.
This should get us almost all the way to a compiling system!
Porting
LibFAT is mostly POSIX, but directories are handled separately. Hence we need to implement scanSubDirs in machdeps.c to be able to load stuff. It's pretty straightforward since the directory iterator in libFAT stats while doing next. We'll also need to initialise libFAT in main in hugs.c
We need input in some way. To use the keyboard from HeadKaze we need to implement functionality similar to readline in consoleInput in input.c and also initialise the keyboard in main in hugs.c
There is also some more initialising to be done to set up the video mode and ram banks and initialise the console.
In dirprim.c we'll have to comment out rmdir and chmod, since these aren't present in the devkitPro SDK.
Deploying
Patch your nds-file with the correct driver patch, more information here
Copy the nds-file to your memory card, along with the libraries (remember HUGSPATH and HUGSDIR?, libraries in /lib/hugs/packages hugs.nds in root in my case).
Now it's just to boot up and run hugs.nds according to your system! This is the result:
Summary
There are probably a lot of things that just don't work, and it's not the prettiest of ports. It would e.g. be more convenient to use the existing directory structure. Still as a proof of concept of a Hugs port on the Nintendo DS it shows that it's both possible and pretty simple.
The Windows Haskell libraries are not really suited for this task, but they're sufficient to just get the Prelude up and running. This should be replaced with something more suitable, preferably with something compiled with and for devkitPro. Should really try to work towards getting configure and autoconf up and running.
The next steps will be stabilising and bugfixing the port, maybe re-work it using the existing Makefile, implement the devkitPro NDS SDK as a Hugs built in library in some form or another. And probably a lot more.
Finally, for those not wanting to go through the process and want to test right away, here's the unpatched binary. Just patch it as described here and try it out. As said above, it assumes libraries are at /lib/hugs/packages).
The source files that has been altered can be found here.
6 comments:
Great job
Pretty cool. You might want to try iDeaS or no$gba for emulators. iDeaS has decent libFAT support (and dldi) and I've also got it working (sort of) with no$gba.
And I still can't get it to compile on my MacBook Pro. You put me to shame.
iDeaS worked great! Many thanks.
Link http://r4revolutions.blogspot.com This is a great guide to get you started with the R4DS. It's a great bit of kit. You can find out most stuff by using http://r4revolutions.blogspot.com As mentioned in the video though please dont ask for requests becuase this is not my DS and i never intend on getting on either.
Awesome, this is exactly what I want.
Great job, but the hugsds.zip is regrettably down at: http://farre.se/files/hugsds.zip
So, can you upload the file for me again?
Thanks for porting this fantastic program.
Post a Comment