3DS Dev Notes

2017-02-09

Introduction

Nothing much to say here, just some notes for myself. Not a tutorial. Very likely outdated by the time you see this.

Toolchain

Do as described on https://www.3dbrew.org/wiki/Setting\_up\_Development\_Environment

Perosnally I would also do sudo chown -R YOUR\_USER\_NAME /opt/devkitpro/ so installing 3rd-party libraries no longer requires root priviledge.

Using Netbeans

There are already descriptions about NetBeans. Additional notes: manually configuring the search path for C/C++ seems to be unnecessary.

Using Citra

Debugging using a real machine could be a painful thing to do, so emulator comes handy. Due to incompatility between the binary package and glibc of my system, I am compling it myself:

https://github.com/citra-emu/citra/wiki/Building-For-Linux

Using Citra is simple, run citra-qt launches the GUI.

To run Citra directly from NetBeans, open the project properties, in Target option in the Make tab, set the output 3dsx file, set the Run Command to citra “${OUTPUT\_PATH}” and done.

Using SDL-1.2

This doesn't actually work (note: it wasn't working by the time I wrote these)

First clone, compile, and install:

git clone https://github.com/nop90/SDL-3DS.git
cd SDL-3DS/SDL-1.2.15
cp Makefile.n3ds Makefile
make
make install

Now a simple demo.

Copy an example project, create a folder called romfs if not exist already. Put a reasonably sized image there, name it as test.bmp.

Enable ROMFS definition in Makefile:

ROMFS       :=  romfs

Add these CFLAGS needed by SDL port:

CFLAGS  +=  $(INCLUDE) -DARM11 -D\_3DS -D\_\_3DS\_\_

Add portlibs to library path:

LIBDIRS := $(CTRULIB) $(PORTLIBS)

Link against SDL:

LIBS    := -lSDL -lcitro3d -lctru -lm

The include path should have been taken care automatically.

Test code:

#include <3ds.h>
#include <stdio.h>
#include "SDL/SDL.h"

int main(int argc, char **argv)
{
    SDL\_Init(SDL\_INIT\_VIDEO);
    SDL\_Surface *screen;
    SDL\_Surface *bitmap;

    screen = SDL\_SetVideoMode(320, 240, 16, SDL\_SWSURFACE | SDL\_TOPSCR | 
            SDL\_CONSOLEBOTTOM);

    Result rs = romfsInit();
    if (rs)
        printf("romfsInit: %08lx\n", rs);
    else {
        printf("romfs Initialization succeed.\n");
        bitmap = SDL\_LoadBMP("romfs:/test.bmp");
        if (bitmap == NULL)
            printf("Open Bitmap failed!\n");
        else
            SDL\_BlitSurface(bitmap, NULL, screen, NULL);
    }
    printf("Should be bilted\n");
    SDL\_Flip(screen);
    printf("Should be flipped\n");
    SDL\_Delay(2000);
    SDL\_Quit();

    return 0;
}

And this doesn't work. There seems to be some requirements on the flipping. There are some features that I need but are missing from the port, so I am probably going to do a port myself.