# "DevkitPro -> libnds" or "how to create my own game?".

#### AKOTb

##### Member
OP
Newcomer
Hi friends!
I recently decided to try writing a game for the legendary Nintendo DS. And since I'm new to this area, I decided to write the simplest game that I only know. Game "Guess the number". The player is given the opportunity to guess the number in a certain range (for example, up to 1 to 100). If the entered number is greater, then the message "TOO MUCH" pops up, if the number is less, then "TOO SMALL". If the player wins, we must also notify him of the successful completion of the game.
The first thing I started with was the installation of "DevkitPro" and the "libnds" library. Next, I installed "Visual Studio Code" and inserted one of the examples provided in the "libnds" library into it.
Everything was successfully opened, the project was assembled, and at the output I received a file with the *nds extension.

I started creating my game, for this I changed the text from the example, it's simple. Next, I decided to insert funny images with a notification about "too large" or too small value entered by the player. But I don't understand how to insert images.
I found an example with the name "backgrounds -> 256_color_bmp", there is a demonstration of a picture from a folder, but it's so incomprehensible. The picture is called as "#include mypicture.h". And where exactly does the image conversion from png to .h take place, I still don’t understand.
Unfortunately, all links to instructions for the library are dead for a long time, and I could not find any understandable documentation. And I would like to have a description of all the functions available in this library, and how to use them. I could not even write such a simple game, and I can’t even imagine how to do something more difficult without documentation.

Friends, if someone has information on how to use this library, I would be very grateful to you. Maybe this tool is already outdated and there is something more relevant for game development on Nintendo DS? I would also be happy to hear from you good advice.
Thanks a lot.

Tarmfot

#### elhobbs

##### Well-Known Member
Member
Take a look at this example. It is uses grit to convert image files.
https://github.com/devkitPro/nds-examples/tree/master/Graphics/gl2d/sprites

This example uses the 3D hardware to display sprites/images. But you could also use the 2d engine, or use bitmap mode.

You don’t have to use grit for images. You could read file from the file system. Write your own file parser and image converter or use a library.

AKOTb and godreborn

#### godreborn

##### Welcome to the Machine
Member
I'm not really an expert at this stuff, but I think there's a libpng library with devkitpro. it may be what you need.

#### Technicmaster0

##### Well-Known Member
Member
The easiest way to make 2D games with the DS is to use NFLib. It has premade functions to use the 2D engine of the DS and simplifies many things (like memory bank management etc). The other 2D lib that's officially included in devkitpro is libgl2d. You can find examples in the examples/nds/Graphics/gl2d folder. It can use more graphical effects because the 3D engine is beeing used to render 2d graphics

#### AKOTb

##### Member
OP
Newcomer

But I have a problem with running the example program. After starting I see the following error:

> Executing task: & 'make.exe' '-f' 'c:\devkitPro\nds_nflib-master\examples\text\text16\Makefile' <

make.exe": *** [build] Error 127
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command & 'make.exe' '-f' 'c:\devkitPro\nds_nflib-master\examples\text\text16\Makefile' terminated with exit code: 1.

Can you please tell me how to fix this error?

#### godreborn

##### Welcome to the Machine
Member

But I have a problem with running the example program. After starting I see the following error:

> Executing task: & 'make.exe' '-f' 'c:\devkitPro\nds_nflib-master\examples\text\text16\Makefile' <

make.exe": *** [build] Error 127
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command & 'make.exe' '-f' 'c:\devkitPro\nds_nflib-master\examples\text\text16\Makefile' terminated with exit code: 1.

Can you please tell me how to fix this error?
I just tested it on my laptop. no issues compiling:

try running pacman -Syu nds-dev

#### NotImpLife

##### Member
Newcomer
The images are converted to a DS understandable binary format via grit from the Makefile. if you place a "mypicture.png" file along with "mypicture.grit" (which tells grit how to convert your image) and the build your ROM, in the "build/" folder you'll se two "human-readable" files:
• Code:
mypicture.s
, an assembly file containing the raw DS bitmap data and the used palette (if bmp8 is used)
• Code:
mypicture.h
, the header which makes the data from
Code:
mypicture.s
accessbible through some arrays like mypictureBitmap or mypicturePal.
The "*.grit" file contains some command line arguments which decides how your png is encoded in your DS's memory (I mean, an image is not necessarily a bitmap, it can be a tiled map, a sprite or anything else). If you only want static 256 color images in your game, it is enough to just copy-paste the grit file from the example. To explain its content, there are two argument options:
Code:
-gb
(tells grit to convert the image to bitmap),
Code:
-gB8
(specifies the number of bits per pixel: 4-bit and 8-bit pictures also generate a color palette, 16-bit pictures aka "true color mode" do not).

Note that each png file you have in the graphics folder must have its own grit file with the same name, otherwise the build will fail.

Now to display the image you just need to copy the palette to the BG_PALETTE slot and the picture data to the VRAM region reserved for your bitmap background (you can give it a raw address if you know it like 0x06000000, or trust bgGetGfxPtr(bgid) function to get it for you). Remember to enable a bitmap supporting video mode (Mode 4 - background 3 or Mode 5 - background 2 or background 3 can be bitmapped).

In your case, it would be (briefly) like this:

C++:
#include "pic_msg_greater.h"
#include "pic_msg_less.h"

...
int bg3 = bgInit(3, BgType_Bmp8, BgSize_B8_256x256, 0,0);
...
while(1) {
swiWaitForVBlank();
// do the game loop
if(chosen_number < number_to_guess) {
dmaCopy(pic_msg_lessBitmap, bgGetGfxPtr(bg3), 256*192);
dmaCopy(pic_msg_lessPal, BG_PALETTE, 256*sizeof(u16));
} else if(chosen_number > number_to_guess) {
dmaCopy(pic_msg_greaterBitmap, bgGetGfxPtr(bg3), 256*192);
dmaCopy(pic_msg_greaterPal, BG_PALETTE, 256*sizeof(u16));
}
}

AKOTb

#### AKOTb

##### Member
OP
Newcomer
I just tested it on my laptop. no issues compiling:

I just tried to build a project from the standard ndslib examples, and also met the same error. make.exe": make: Command not found make.exe": *** [build] Error 127 Can you please tell me where can I find the setting for the location of the makefile?

Note that each png file you have in the graphics folder must have its own grit file with the same name, otherwise the build will fail
Mega thank you for such a detailed description of adding an image to the project! I really appreciate the information, because I haven't been able to find any documentation for the library. Whereas the documentation for the Palib and Nightfox libraries is present, and it is very detailed.

NotImpLife

#### godreborn

##### Welcome to the Machine
Member
I just tried to build a project from the standard ndslib examples, and also met the same error. make.exe": make: Command not found make.exe": *** [build] Error 127 Can you please tell me where can I find the setting for the location of the makefile?

Mega thank you for such a detailed description of adding an image to the project! I really appreciate the information, because I haven't been able to find any documentation for the library. Whereas the documentation for the Palib and Nightfox libraries is present, and it is very detailed.
Sounds like an environmental variable problem then. Check if the bin folder is listed in path.

#### AKOTb

##### Member
OP
Newcomer
I think I understand what is wrong. The program displays the following error message:
/bin/sh: /c/devkitPro/examples/nds/hello_world/c:/devkitPro/msys/bin/make.exe: No such file or directory
make.exe": *** [build] Error 127
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command & 'make.exe' '-f' 'c:\devkitPro\examples\nds\hello_world\Makefile'" terminated with exit code: 1.
/bin/sh: /c/devkitPro/examples/nds/hello_world/c:/devkitPro/msys/bin/make.exe

Of course this is a mistake, but I do not understand where this can be corrected? Maybe someone knows?

#### godreborn

##### Welcome to the Machine
Member
shouldn't it be msys2 in environmental variables. I think it's looking in the wrong place.

#### AKOTb

##### Member
OP
Newcomer
No, I have an old version of Devkitpro 1.5 installed. It was not msys2 but just msys. Here is a screenshot of the folder:

#### godreborn

##### Welcome to the Machine
Member
Is make.exe in the bin folder?

#### AKOTb

##### Member
OP
Newcomer
Is make.exe in the bin folder?
Yes, I checked

And also checked that the file runs without errors

#### NotImpLife

##### Member
Newcomer
/c/devkitPro/examples/nds/hello_world/c:/devkitPro/msys/bin/make.exe
Possibly the makefile has been modified? Looks like it's trying to do $(CURDIR)/$(MAKE)... Can you send an archive of your project? It may also woth trying to run make in another terminal if you have installed (like git bash).

#### AKOTb

##### Member
OP
Newcomer
Does make work in another directory?
yes, it works

Possibly the makefile has been modified? Looks like it's trying to do $(CURDIR)/$(MAKE)... Can you send an archive of your project?

I'm not writing my project yet, but just trying to run projects from the "examples" folder.
I attached an archive with all the projects in the "examples" folder to the message, now I'm trying to run the "hello world" project, but the error is the same with the rest of the projects.

#### Attachments

• nds.zip
1.5 MB · Views: 5

#### NotImpLife

##### Member
Newcomer
From which path do you run your makefile?
Have you tried this:
Code:
cd C:\devkitPro\examples\nds\hello_world
make -f Makefile

Also try open cmd and run this just to make sure the make command is found:
Code:
where make

#### AKOTb

##### Member
OP
Newcomer
From which path do you run your makefile?
Have you tried this:
I use Visual Studio Code, it works with the makefile itself, I just click on the play button

TTried the option you suggested, same error:

and where make result:

Newcomer
AKOTb

Replies
13
Views
716
Replies
3
Views
357
Replies
10
Views
744
Replies
3
Views
438
Replies
3
Views
1K

### Recent Content

12. #### Burned out...:-(

Help Users
@ Dark_Phoras: Is a doctor specialized in feces called The Poopmaster?