Tutorial  Updated

DS Programming for Newbies!

3Lwpv.png

Table of Contents:

Introductory Chapters:
  1. Preparing the environment
  2. Variables!
  3. Functions!
  4. Operators in C
  5. Conditions - if/else Statements and switches
  6. Looping - for() and while() Loops
  7. Containers of Variables - Arrays and Structures
Introduction to DS Hardware:
  1. RAM and VRAM
  2. OAM and 2D Sprites
Practical use of libnds:
  1. Input: Keys and the Touchscreen
Practical Use of NightFox Lib:
  1. NightFox Lib Integration
  2. 2D MODE-0 Part 1 - Tiled Backgrounds
  3. 2D MODE-0 Part 2 - Tiled Sprites
Excercises:
  1. Your first program!
  2. MODE-0 Tiled Backgrounds Example
  3. MODE-0 Tiled Sprites Example
  4. Our very first game: Tic Tac Toe!
Additional Utilities:
  1. GRIT


:download: PDF Version maintained by CannonFoddr available on FileTrip HERE!

:download: PDF Version maintained by Pomegrenade GBAtemp Mirror HERE!




Preface


Hello and welcome! If you are reading this then it’s likely that you’re interested in getting to know more about programming for the Nintendo DS! If you are not, then you likely took the wrong turn, but let’s not get into that. Let’s also start with establishing one important thing – as the title suggests, this is a “From Zero to Hero” guide. If you are an experienced programmer then it is likely that you will not benefit from it much, if at all. It is going to introduce the very basics to users who have never even seen a compiler before and never coded in their life – stuff that you probably already know and aren’t interested in anymore. You are however still welcome as this is my first tutorial and will likely require a certain degree of proof-reading, plus, you may of course have useful suggestions! Keep in mind the target audience though, I’m doing my best not to introduce complicated concepts early on. If you’re not an experienced programmer or never programmed at all, this is a great place to start!

I’ve seen many guides approaching this subject – some were more helpful, some were rather vague, but there is one thing that was common in all of them, and it became apparent to me that something has to be done about it. The guides I’ve seen so-far are dedicated to users who are familiar with programming and only require an introduction to the DS environment, none of them are actually “tutorials” from the ground up. Does this mean that a non-experienced user simply cannot program for the DS or should not begin his adventure with programming on this exact platform? No, it does not! In fact, the DS is likely the easiest platform to program for when it comes to consoles – libnds is really not that hard to wrap your mind around and there are numerous libraries out there that facilitate programming for it even further. You probably want to ask: “If it’s so easy, why do You think it requires some sort of an explanation? The libraries are well-documented, do you expect the readers to be dill-wits who can’t follow simple examples?” and the answer to that is “No, in fact, I do believe that everybody is capable of programming, however one has to learn and acquire some basic programming habits and have some practice in C to be successful at it” and this is exactly the main goal of this tutorial. Depending on the interest shown by users and my workload at Uni this may or may not be a full-featured guide, however I promise that I will at least try to keep it up-to-date and expand upon it from time to time.

Now that the purpose is established, let’s move on to the juicy parts! I hope you will enjoy learning together and in case of any questions or suggestions, do write! Dear readers, keep in mind that the first few tutorials will be an incredibly rapid course in C, applicable to any type of programming, not just for the DS! We won’t be compiling much until this material is covered and thoroughly understood! So… Let’s get it on!
 
Last edited by Foxi4,

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,815
Trophies
3
Location
Gaming Grotto
XP
29,767
Country
Poland
Come to think of it @GigaGuenther, have you tried testing both of them individually, as opposed together? I vaguely remember having a hard time with a joint pallet way back when. Before I do anything in my end, so you mind trying just the sprite or just the background? If you batched them both at the same time then they might share a pallet file (unbeknownst to you). Just comment // the unwanted sections away for the test.
 

GigaGuenther

Member
Newcomer
Joined
Mar 20, 2023
Messages
10
Trophies
0
Age
20
XP
34
Country
Germany
Yes i tried it with backgrounds only, where I basically just used the Example2 but changed the Code to use my own Background and that didn't work.
 

GigaGuenther

Member
Newcomer
Joined
Mar 20, 2023
Messages
10
Trophies
0
Age
20
XP
34
Country
Germany
As long as the color depth and size are correct you should be alright. Any chance you could attach your images here so we could take a look together?
Are you talking about Bitdepth there? When i look into the properties of my .bmp files, it shows that both have a Bitdepth of 4. How much is optimal?
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,815
Trophies
3
Location
Gaming Grotto
XP
29,767
Country
Poland
Are you talking about Bitdepth there? When i look into the properties of my .bmp files, it shows that both have a Bitdepth of 4. How much is optimal?
Sprites and backgrounds using tiles should have a maximum of 256 colours, which translates to 8 bits (0-255). You can change the color depth of the bitmap using GIMP or IrfanView. There are also palette limitations for the total screen, but you’re nowhere near that point. :)
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,815
Trophies
3
Location
Gaming Grotto
XP
29,767
Country
Poland
Is this guide still up-to-date and worth following? I see some essential links like the ones from the tools are dead.
Everything in it is still valid, although the Drunken Coders wizard is unfortunately no longer available. Not that it matters since you wouldn’t be using such an old release of Visual Studio anyway. You can just as easily do everything in Notepad. Some errors have slipped here and there due to multiple forum software transitions over the years (killing the formatting as a result), but they’re easily spotted.
 

GigaGuenther

Member
Newcomer
Joined
Mar 20, 2023
Messages
10
Trophies
0
Age
20
XP
34
Country
Germany
Hey small update, i finally got the Backgrounds working, but Sprites still won't show. Even weirder, the background only shows when the InitSpriteBuffer function comes after the CreateTiledBG function in the code... Otherwise it only shows a black screen. Any idea what the problem could be?
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,815
Trophies
3
Location
Gaming Grotto
XP
29,767
Country
Poland
Hey small update, i finally got the Backgrounds working, but Sprites still won't show. Even weirder, the background only shows when the InitSpriteBuffer function comes after the CreateTiledBG function in the code... Otherwise it only shows a black screen. Any idea what the problem could be?
The two should have no impact on each other whatsoever, this is very weird behaviour. What are you using for testing, out of plain curiosity? Work’s been keeping me busy, so I haven’t had the chance to sit down and test your code yet.
 

joe132

New Member
Newbie
Joined
Jul 21, 2023
Messages
1
Trophies
0
Age
17
XP
21
Country
Singapore
does anyone know how to change the text size with the "NF_WriteText();", or if i am able to use floats as the x and y pos?, eg:
NF_WriteText(1, 0, 15.8, 13, counterchar);, any help would be great, thank you

also if anyone knows where to find full documentation on NF it would be great as well, I've been going off the examples which come with the library and I'm unable to properly understand the code with them, like the parameters which should be inserted in to functions, thank you!

could anyone help me with NF_DeleteTextLayer()? it seems to behave like NF_DeleteTiledBg(), and it says the text layer is not an available background
 
Last edited by joe132,

Valkyrience

Member
Newcomer
Joined
Aug 12, 2023
Messages
14
Trophies
0
Age
24
XP
17
Country
Ukraine
Hi,sorry for my english, it`s not my native language. Can somebody tell is there some way to create several backgrounds with one tileset (for example if want to create several levels in game with one block set)?
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,815
Trophies
3
Location
Gaming Grotto
XP
29,767
Country
Poland
Hi,sorry for my english, it`s not my native language. Can somebody tell is there some way to create several backgrounds with one tileset (for example if want to create several levels in game with one block set)?
Good question, and yes! A map file is nothing more than a background broken down into tile numbers, you can have multiple maps that use the same tileset. I can’t quite recall any specific software that could aid you at this time, but as long as you have your tiles and palette, you can make as many maps as you want - they’re just long strings of numbers. Here’s an example:

https://github.com/devkitPro/nds-ex...cs/Backgrounds/all_in_one/source/handmade.cpp

The screen is 192x256, if we divide it into tiles, that’s 24x32 using 8x8 tiles visible tiles, however the map should be at least 32x32 to facilitate scrolling.
Your tutorial is amazing. English is spot on, very well written. :wub:
You flatter me, but this thread is 11 years old. My English wasn’t nearly as good as it is now, though I did try to make it a pleasant read. :)
 
Last edited by Foxi4,
  • Like
Reactions: SylverReZ

BlueFalconNDS

Member
Newcomer
Joined
Aug 16, 2023
Messages
20
Trophies
0
XP
15
Country
Canada
@Foxi4 Is there a pdf copy is this tutorial? For being made in 2012, it still looks great and I'm wondering if it still holds up, and if there a pdf version as it seems the linked pdf version is no longer available.
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,815
Trophies
3
Location
Gaming Grotto
XP
29,767
Country
Poland
@Foxi4 Is there a pdf copy is this tutorial? For being made in 2012, it still looks great and I'm wondering if it still holds up, and if there a pdf version as it seems the linked pdf version is no longer available.
While libnds has changed substantially in the last 11 years, NightFox lib should still work exactly the same and there’s no reason why anything in this tutorial would be inaccurate (besides some formatting bugs I pointed out which were a result of two subsequent forum migrations). There was a PDF version available, maintained by @CannonFoddr, but with the closure of File Trip it may have been lost to the sands of time. I can always check if it was archived at any point, or perhaps @CannonFoddr still has a local copy available. Worst case scenario the thing’s not terribly long, so I imagine you could just save the relevant posts in a document.


EDIT: Wouldn’t you know it, @Pomegrenade scores a big W for a re-upload in our download section:

https://gbatemp.net/download/ds-programming-101-from-zero-to-hero.37350/

I will update the OP for the first time in over a decade to add this new mirror, it’s mighty handy and probably free from export-related errors. Might be useful to future readers. Cheers!
does anyone know how to change the text size with the "NF_WriteText();", or if i am able to use floats as the x and y pos?, eg:
NF_WriteText(1, 0, 15.8, 13, counterchar);, any help would be great, thank you

also if anyone knows where to find full documentation on NF it would be great as well, I've been going off the examples which come with the library and I'm unable to properly understand the code with them, like the parameters which should be inserted in to functions, thank you!

could anyone help me with NF_DeleteTextLayer()? it seems to behave like NF_DeleteTiledBg(), and it says the text layer is not an available background
I must’ve missed this comment, or my notifications derped. Text on a DS is normally achieved on a tiled layer, there’s no real way of “changing the size” of the text unless you opt for a raster layer and render the text yourself. Technically you could create your own font with a custom size, or you can use the large 16x8 fonts provided which offer double height. There used to be a neat site with the complete documentation, but it might be lost to time now. I have found this link though, and it seems pretty complete.

https://akbatten.com/files/nflib_eng_20120318.pdf

You’ll find everything you need there, sorry for the late response.
 
Last edited by Foxi4,
  • Like
Reactions: BlueFalconNDS

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Xdqwerty @ Xdqwerty: Good night