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,

NumberXIIIEdwin

Jack In! MegaMan, Execute!!
Member
Joined
Aug 12, 2010
Messages
286
Trophies
1
Age
27
Location
Pherae
XP
2,736
Country
United States
Thanks for the guide! I'm currently taking a class in C# for college and I figure I'll use this as practice when the semester ends so I don't get rusty. Very interesting indeed! I'm not interested in developing anything but I think it would be fun to tinker around a bit.
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,824
Trophies
3
Location
Gaming Grotto
XP
29,819
Country
Poland
Thanks for the guide! I'm currently taking a class in C# for college and I figure I'll use this as practice when the semester ends so I don't get rusty. Very interesting indeed! I'm not interested in developing anything but I think it would be fun to tinker around a bit.
Keep in mind that C# is very different from C as it's interpreted, not pre-compiled. The syntax is similar, but the principles are a little different. C also has no automatic garbage collection and lacks many of the handy tools both C++ and C# have access to. ;)
 
  • Like
Reactions: NumberXIIIEdwin

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,824
Trophies
3
Location
Gaming Grotto
XP
29,819
Country
Poland
I'm unaware of how development would look like on a non-x86 machine. Probably? Can't you just ask? Surely you know someone who does have admin access to the machine, right?
 
  • Like
Reactions: MrMcTiller

Sledgehogg

Active Member
Newcomer
Joined
Dec 1, 2018
Messages
25
Trophies
0
Age
21
XP
140
Country
Denmark
I don't know if anyone will ever respond to this, but the drunkencoders webpage doesn't exist anymore, so i can't download the wizard. I've been searching a bit around the internet without any luck, so i pray that whoever sees this, has a download link.
Thank you in advance!
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,824
Trophies
3
Location
Gaming Grotto
XP
29,819
Country
Poland
Yeah, there's no more wizard unfortunately, you have to compile with MAKE.exe from the devkit as usual. You might want to switch from Visual Studio to Notepad ++ as well.
 
  • Like
Reactions: MrMcTiller

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,824
Trophies
3
Location
Gaming Grotto
XP
29,819
Country
Poland
So @Foxi4 a friend of mine wanted to get into DS Programming and I immediately recommended your guide, but he was wondering what guides to use after learning the basics, could you recommend any
Once you get the basics I recommend going straight into pure Libnds. The DS is a very simple platform with a very rich documentation, it's perfect for your own experiments. When you understand what's going on and why, there's not much further guidance you really need.
 

Pomegrenade

photon readings negative
Member
Joined
Feb 20, 2017
Messages
314
Trophies
0
Location
Location
Website
gbatemp.net
XP
770
Country
Netherlands
Once you get the basics I recommend going straight into pure Libnds. The DS is a very simple platform with a very rich documentation, it's perfect for your own experiments. When you understand what's going on and why, there's not much further guidance you really need.
Got it
 
Last edited by Pomegrenade,

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,824
Trophies
3
Location
Gaming Grotto
XP
29,819
Country
Poland
@Foxi4 okay another question, I see that you've written this guide by teaching the basics of C, however if someone were to learn c++, could they still use the guide (or at least the later parts?)
C++ is effectively C on steroids. They're both compiled to native machine code, you can use either and achieve the same result. On the DS I personally like to have full control over garbage collection and memory allocation, C++ is set up to do these things automatically. The DS doesn't have a whole lot of memory, so knowing exactly where everything is was handy for me. I guess it's a matter of preference, but in any case, you can use either, or even both, really.
 

Coto

-
Member
Joined
Jun 4, 2010
Messages
2,979
Trophies
2
XP
2,565
Country
Chile
C++ is effectively C on steroids. They're both compiled to native machine code, you can use either and achieve the same result. On the DS I personally like to have full control over garbage collection and memory allocation, C++ is set up to do these things automatically. The DS doesn't have a whole lot of memory, so knowing exactly where everything is was handy for me. I guess it's a matter of preference, but in any case, you can use either, or even both, really.

not to mention C++ on the DS is unstable since the OOP paradigm runs around the new and delete operators, and in the lower level, these are (at least in GCC) dependant on malloc/free, and the dmalloc (Doug Lea malloc) implementation used widely in GCC causes memory fragmentation. Making C++ code on the DS to cause memory issues sometimes.

so for NDS it's best to use C and control the memory yourself, or pull a John Carmack and use static buffers but these take much memory depending on the linker settings.
 
Last edited by Coto,

Wooaw2005

Well-Known Member
Newcomer
Joined
Feb 5, 2019
Messages
48
Trophies
0
Age
18
XP
227
Country
United Kingdom
I'd like to get in to ds homebrew but there is one problem
I can't find drunkencoders anywhere.
If somebody can find them or atleast upload their libraries it would be awesome!
 

Pomegrenade

photon readings negative
Member
Joined
Feb 20, 2017
Messages
314
Trophies
0
Location
Location
Website
gbatemp.net
XP
770
Country
Netherlands
I'd like to get in to ds homebrew but there is one problem
I can't find drunkencoders anywhere.
If somebody can find them or atleast upload their libraries it would be awesome!
Awesome, we need more active members in DS homebrew, ask me anything you need :)

And for drunkencoders, ill look around my old PC for it, if not ill let you know
 

Pomegrenade

photon readings negative
Member
Joined
Feb 20, 2017
Messages
314
Trophies
0
Location
Location
Website
gbatemp.net
XP
770
Country
Netherlands
Awesome!!!
I really appreciate it!!
Finally I could get into homebrew!!! :yaynds::nds:
Hmm unfortunately im unable to find it (what happens when you have an old messy computer)
At most you should try what Foxi4 said before
Yeah, there's no more wizard unfortunately, you have to compile with MAKE.exe from the devkit as usual. You might want to switch from Visual Studio to Notepad ++ as well.
 

toberkel

Well-Known Member
Member
Joined
Nov 21, 2016
Messages
184
Trophies
0
Location
Germany
XP
164
Country
Germany
Can Someone help me out? I cant build a .plg file with the build.bat because i get a ton of errors.

I tried to build it from an backup of the source - Errors
Local Copy - Errors
Official Plugin with source from RyDog - Errors

I always get a lot of "undefined reference to new_enty_with_note"
But how is it possible that i can´t build the plugin with original source files?
Am I missing something? Devkit and Phyton is installed...
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    SylverReZ @ SylverReZ: @realtimesave, Yea?