Making your Hello World!

Like anywhere else the first program we’ll be making will be a simple hello world! In this tutorial you’ll learn how to use the console (not the 3DS but the text console), and how to make a custom SMDH file.

First download the 3DS homebrew template. The template will compile but won’t do anything, so we’ll have to add some code!

In this tutorial we will be working in the main.c file. For this and all other tutorials it’s assumed you have some experience with programming (and of course C). If you don’t you can simply google a for C or C++ tutorial! I recommend you use Sublime Text to edit the code, but you can also use a different editor.

First we will have to initialize the console, the console is what is going to allow us to display text on screen, the console is really handy in development, however it cannot be used when also displaying images (or rendering anything else but the console text). The console is usually used for debugging (testing) only. Or to display a message like “Press start to exit” if only one of the 2 screens is being used for the application/game. You need to initialize it before the main while loop (while (aptMainLoop())). You initialize the console like this:

consoleInit(GFX_TOP, NULL);

Now to actually display the text “Hello World!” on the screen:

printf("Hello World!");

This line will need to be placed after the consoleInit(), but also before the main loop. If you place it in the main loop it will be placed over and over again (resulting in a list of Hello World! messages).

If you want the message to be displayed on a specific place on the console screen you can put “\x1b[x;yH” in front of the text and replace the second x with the row and the y with the column you want the message to be displayed in. The top screen has 30 rows and 50 columns while the bottom screen has 30 rows and 40 columns.

Your main.c file should now look like this:


#include <3ds.h>
#include <stdio.h>

int main(int argc, char **argv)
{
//Initialize gfx (note: not needed if you're using SF2Dlib)
gfxInitDefault();

consoleInit(GFX_TOP, NULL);

printf("\x1b[15;19HHello World!");

// Main loop
while (aptMainLoop())
{
//Scan all the inputs. This should be done once for each frame
hidScanInput();

//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
//hidKeysHeld returns information about which buttons are currently pressed (regardless if they were pressed or not pressed in the previous frame)
//hidKeysUp returns information about which buttons are not pressed but were pressed in the previous frame
u32 kDown = hidKeysDown();

if (kDown & KEY_START) break; // break in order to return to hbmenu

// Flush and swap framebuffers, this is needed for rendering these will not be needed when using SF2D lib
gfxFlushBuffers();
gfxSwapBuffers();

//Wait for VBlank, this is needed for rendering these will not be needed when using SF2D lib
gspWaitForVBlank();
}

gfxExit();
return 0;
}

You can now compile your masterpiece by running the “make” command in the terminal. If you put it on your 3DS the same way as any other homebrew title (this won’t make a .3ds or .cia so you’ll need something that runs .3dsx like ninjhax ironhax or tubehax). But you’ll notice that it won’t have the correct icon, title, or author. To do this you’ll have to make edits to the Makefile (recommended to also use Sublime Text for this though notepad could be used).

You will have to add and fill in these fields in the Makefile: (add them after the line “INCLUDES := include”)

APP_TITLE := Your app name
APP_DESCRIPTION := What even is your app?
APP_AUTHOR := Your name/username

To add a icon just add a file called icon.png and make sure the image is 48px by 48px.

After doing this run “make” again, and you should now also have a file with a .SMDH extension. When placed together with the .3dsx file you should now see your icon, title, description and your name in the homebrew launcher menu!

7 thoughts on “Making your Hello World!

  1. Why don’t you use sftd lib to write the text instead of using the console?
    With sftd you can use custom fonts easily so the text isn’t as ugly as with the console.

    Like

    1. There is actually a good reason. The console comes with ctrulib, and if you follow the tutorials in order the setting up of sftd (and possibly sftd in the future) is not yet done at that point. So for this tutorial it was simply easier to use the console. For text in homebrews sftd is currently the way to go, but it is not perfect. For instance big text often becomes very blurry and ugly.

      Like

  2. I can compile it, but all I get is the .elf extension and the .smdh and .3dsx don’t compile. What’s wrong?

    Like

Leave a comment