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,

agentalexandre

Member
Newcomer
Joined
Sep 12, 2009
Messages
6
Trophies
0
XP
143
Country
United States
Anyone know if it's possible to use extended palettes with tiled backgrounds? I'm looking to use some fairly high quality tiles and they always lose a lot of colour when I save them as 256 colour bitmaps.

I've seen the example for extended palettes in the example folder but it's not very helpful in explaining how you actually generate extended palettes.
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,815
Trophies
3
Location
Gaming Grotto
XP
29,768
Country
Poland
Anyone know if it's possible to use extended palettes with tiled backgrounds? I'm looking to use some fairly high quality tiles and they always lose a lot of colour when I save them as 256 colour bitmaps.

I've seen the example for extended palettes in the example folder but it's not very helpful in explaining how you actually generate extended palettes.
Unfortunately, this is not possible. To my knowledge, each resource references one palette. There are a few ways around this problem - you could create a multi-layered background so that you can use more than one palette, you could over-write the palette in-between blanks or you could display your high-quality background as a raster instead.

Extended palettes refer to palettes external to the standard 256-colour [BG_PALETTE] one that refers to the whole screen, however each resource in tiled mode still refers to one 256 colours palette and going beyond that limit is quite the task.

Personally I found out that when converting resources, the decrease in quality highly depends on the software used. Do try Paint.Net and IrfanView - they're both pretty efficient at saving images with 8-bit palettes without a substantial decrease in quality. ;)
 

agentalexandre

Member
Newcomer
Joined
Sep 12, 2009
Messages
6
Trophies
0
XP
143
Country
United States
Unfortunately, this is not possible. To my knowledge, each resources references one palette. There are a few ways around this problem - you could create a multi-layered background so that you can use more than one palette, you could over-write the palette in-between blanks or you could display your high-quality background as a raster instead.

Extended palettes refer to palettes external to the standard 256-colour [BG_PALETTE] one that refers to the whole screen, however each resource in tiled mode still refers to one 256 colours palette and going beyond that limit is quite the task.

Personally I found out that when converting resources, the decrease in quality highly depends on the software used. Do try Paint.Net and IrfanView - they're both pretty efficient at saving images with 8-bit palettes without a substantial decrease in quality. ;)
Thanks for the help. I ended up using photoshop and using it to index the colours and then was able to save as an 8 bit bmp. Teaches me never to use mspaint again!
 

p3rand0r

Well-Known Member
Newcomer
Joined
Mar 10, 2014
Messages
83
Trophies
0
Location
On the ⌨
Website
portfolio.al
XP
93
Country
Albania
Well this is an awesome tutorial !
im a little confident with java and i would like to learn more about c/c++ , i think this is the write place
do you have any plans releasing a guide about 3ds homebrew for beginners ? :wub::shy:
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,815
Trophies
3
Location
Gaming Grotto
XP
29,768
Country
Poland
Ever since I became a reporter I had my hands full of work plus the 3DS currently lacks convenient libraries for developers, but if there will ever be a lib3ds and I'll have the right gear for the job, I'll definitely try to tackle it. :)
 

NicEXE

Well-Known Member
Member
Joined
Dec 6, 2009
Messages
411
Trophies
1
XP
706
Country
Cyprus
I am getting a project creation failed error:
a7f2ad4403.jpg


Here is the content of C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcprojects\Nintendo DS and GBA Project Wizard.vsz
Code:
VSWIZARD 7.0
Wizard=VsWizard.VsWizardEngine.8.0
 
Param="WIZARD_NAME = Nintendo DS and GBA Project Wizard"
Param="RELATIVE_PATH = VCWizards\AppWiz\Nintendo Game Console"
Param="FALLBACK_LCID = 1033"
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,815
Trophies
3
Location
Gaming Grotto
XP
29,768
Country
Poland
Huh. To be honest, this has never happened to me, the wizard always worked fine for me, so I don't know where to even start helping you. If you want to get your feet wet stat, you could simply use the empty template provided with NFLib and start coding from there, you don't *really* need to create a VC project. Just use the blank main file and you should be fine, VC2010 is only used for the sake of keeping your project structurally sound in case it grows to some larger proportions, simple training can easily be done in Programmer's Notepad. If you're getting any error codes with the wizard, I suggest looking them up on Google - perhaps someone came across them before. You could also try re-installing the DS/GBA Project data. ;)
 

Ooka

Active Member
Newcomer
Joined
Sep 12, 2014
Messages
30
Trophies
0
Age
31
XP
212
Country
United States
Thanks for this Foxi, just know that your work has probably helped to create lots of new developers who otherwise never would have graced NDS development!

I personally am using what I learned to attempt integrating Webkit to develop a new menu for the DSTwo. :) It probably goes without saying that progress is non-existent currently. xD
 
  • Like
Reactions: Foxi4

CyberMick

New Member
Newbie
Joined
Dec 18, 2015
Messages
1
Trophies
0
Age
42
XP
41
Country
This tutorial worked great up for me up until using NITROFS, after this point was unable to test using NO$GBA.
Anyone know of a work around for this?

Also, is there a template for using Visual Studio 2015 (Community Edition)?
 

RocketRobz

Stylish TWiLight Hero
Developer
Joined
Oct 1, 2010
Messages
16,492
Trophies
3
Age
24
XP
20,785
Country
United States
So, I have a source code that has PAlib code. Because PAlib's outdated, how do I get rid of the code without causing errors?
 

Charles_Toone

New Member
Newbie
Joined
Oct 30, 2016
Messages
3
Trophies
0
Age
28
XP
52
Country
I am trying to build and the command line of the build is returning with error 255...
Which in theory means it can't find the file path... what i don't understand is the file path is correct at least from what i can tell...

File Path:

C:\devKitPro\nflib\makefiles
 

polomint

New Member
Newbie
Joined
Mar 25, 2010
Messages
1
Trophies
0
XP
160
Country
United States
Thank you for this tutorial, I haven't quite read it all yet.
I intend to port my Sokoban clone Bozxle from the ZX Spectrum to the NDS, and this tutorial seems to be the best way to do it, even though I have very little experience with c/c++, although I do write applications with C# and have done for many years, so it shouldn't be too much trouble to follow the tutorial.
I'm currently compiling using VS2017 for NDS and I must admit that it seems to be working quite well.

Once again, thank you for the tutorial :D
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    K3Nv2 @ K3Nv2: Sorry for accidentally bending over