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,

TLSS_N

No rice, No life! ~唯
Member
Joined
Aug 16, 2010
Messages
547
Trophies
1
Age
34
Location
Around
XP
375
Country
United States
Bookmarked! I've got three weeks until spring break, so I'll have to wait till then, but this will certainly help me to learn early! I'm doing the basics right now in school, but when I start game development later on, I'll be able to have a foot hold and won't fall flat, THANK YOU FOXI4!
 
  • Like
Reactions: 1 person

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,825
Trophies
3
Location
Gaming Grotto
XP
29,844
Country
Poland
Thank you for the kind words, The Living Shadow, I'll do my best not to disappoint. :) That said, the time has come for another Introductory Chapter - the long awaited Chapter 4 concerning creating Conditions! I hope you'll all enjoy it! :)

Introductory Chapter 4: Conditions


Now that we know Operators, we are pretty much set to start learning about creating various Conditions in C. What is a Condition? Well, it is a Statement that specifies how our program is going to react when a given event happens. We can divide those statements into two basic groups, if Statements and switches. Firstly we'll have a look at both, then we're going to compare them as to know exactly when to use them efficiently.

We've actually seen a few if statements already in the previous Chapter, I'm sure you've noticed! These were however very short - they were the shortest possible form of that kind:

if (Condition) Result;

With that kind of a statement we can only specify one Result and one Condition, so naturally this is a really limited statement. To fully utilize if Statements we need to be familiar with their entire structure, which is as follows:

Code:
if (Condition){
Statements;
}
else if(Condition2){
Statements;
}
else{
Statements;
}
We can see that this is a much more flexible implementation of an if Statement, we can not only specify as many Conditions and Results as we want using else if's, we can also set a Result that will occour if neither of the Conditions are met! It is divided into three parts, our first if, a number of following else if's and finishes with else - the latter two parts are entirely optional and you can ommit either of them if you don't need them.

To show how this works in a more practical way, let's have a look at this example:

Code:
if (Age>=18){
iprintf("You're an adult!");
}
else if(Age=0){
iprintf("You're a minor!");
}
else{
iprintf("Very funny. You were supposed to input your age!");
}
Here, if the Variable Age's Value is greater or equal to 18, the program will inform the user that he is an adult by printing a message on the screen. If the Value is less then 18, but more then 0, the program will state that the user is a minor. If the Variable has a value that is incorrect, such as less then 0, the program snarkly remarks that the user inputted an incorrect value.

Of course we could just do this:

Code:
if (Age>=18){
iprintf("You're an adult!");
}
else{
iprintf("You're a minor!");
}
But this presents a degree of ambiguity - if the user would input a value that is less then 0, the program would still refer to him as a minor despite the fact that the value is incorrect. This could be prevented by doing this:

Code:
if (Age>=18){
iprintf("You're an adult!");
}
else if(Age<18){
iprintf("You're a minor!");
}
However again, the program would be confused if the inputted value was of incorrect type, for example a character rather then a digit and this would result in a glitch - the character would be transcribed into a numerical value. Why am I saying all this? You're going to say "we're not brain-dead, this is obvious!". Well, let me tell you, it's not. I'm doing this to teach you to avoid being ambiguous at all costs, this will save you time when debugging your applications. Keeping these issues in mind will help you avoid glitches in your program and prevent it from acting in a manner that you would not expect. Computers are not intelligent, they will not do your work for you. You have to imagine you're giving orders to a complete simpleton who requires really specific instructions as to not make a mistake. Simplify your code when it is possible, by all means, but where there is room for error, specify your intentions in detail.

To conclude the section about if Statements, we'll have a look at the Ternary Operator as promised last time. Sometimes our conditions can be thoroughly simplified and we can ommit the use of if Statements or switches altogether by using the Ternary Operator "?".

Let's consider this snippet of code:

Code:
if (Variable==10){
Result = 1;
}
else{
Result = 0;
}
We created an if Statement which checks whether the Variable is equal to 10. If it is, the program will assign the value 1 (true) to Result, otherwise it will assign 0 (false). We can simplify this with a simple Ternary Operation, like this:

Code:
Result = Variable==10 ? 1 : 0;
This will automatically assign the values to Result depending on whether the Condition will turn out to be true or false! Much quicker, isn't it?

Now that we are accustomed with if Statements, we can learn about switches, which are very similar in function however may come in handy simply because they are more see-through and easier to debug. Let's have a look, shall we?

Code:
switch(Variable){
case 1:
Statements;
break;
case 2:
Statements;
break;
default:
Statements;
break;
}
In this example switch, we have two cases and the default case. If the Value of Variable is equal to 1, it performs the Statements specified in case 1, if it is equal to 2, it performs the Statements specified in case 2, if it is neither, it performs the Statements specified in the default case, which is optional. Each case is separated by break; as to conclude the case, however it is optional if you want to recieve the same result in several cases, like here:

Code:
switch(Variable){
case 0:
iprintf("Variable is equal to 0");
break;
case 1:
case 2:
iprintf("Variable is equal to either 1 or 2");
break;
default:
iprintf("Variable is neither 0 nor 1 or 2");
break;
}
By not adding the break; after case 0, we specified the same Statement for both case 1 and case 2, thus saving time and simplifying the switch.

The default; case again is optional, however I'm reminding you about possible ambiguity of code. This is a disadvantage of using switches - if the Variable will not fall in either case specified and there will be no default case present, the program will simply ignore the input altogether! Another disadvantage of switches is that the Variable used must be a simple Variable - either an Integer or a char, thus we cannot use it with Strings or Structures.

This concludes Introductory Chapter 4, in the next and final introductory chapter we will have a look at Loops, specifically for Loops and while Loops. The rest of C-related material will be discussed as we progress if needs-be. Thank you for reading and see you next time!
 

LeRodeur

Well-Known Member
Member
Joined
Dec 12, 2009
Messages
162
Trophies
0
Age
30
XP
190
Country
France
Great work man, I wanted to do such tutorial a while ago though I did never take time to do it. I don't think you need help on this project but feel free to ask for!
Do you plan to explain how to build a game engine later?
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,825
Trophies
3
Location
Gaming Grotto
XP
29,844
Country
Poland
Great work man, I wanted to do such tutorial a while ago though I did never take time to do it. I don't think you need help on this project but feel free to ask for!
Do you plan to explain how to build a game engine later?
Once C, libnds input, NightFox graphics and maxmod and ASLib sound are covered, we'll move on strictly to game mechanics, logic and so on and so forth. So far I didn't need any help but I'm glad you're offering, I will definatelly ask when I'm unsure of something and I urge you to hop in and have a read from time to time, even if this is nothing new to you. I believe that every tutorial needs proof-reading so do post comments/questions when you think some things need further explaination or clarification, and of course, do post if you actually find bugs. :)
 

LeRodeur

Well-Known Member
Member
Joined
Dec 12, 2009
Messages
162
Trophies
0
Age
30
XP
190
Country
France
Great work man, I wanted to do such tutorial a while ago though I did never take time to do it. I don't think you need help on this project but feel free to ask for!
Do you plan to explain how to build a game engine later?
Once C, libnds input, NightFox graphics and maxmod and ASLib sound are covered, we'll move on strictly to game mechanics, logic and so on and so forth. So far I didn't need any help but I'm glad you're offering, I will definatelly ask when I'm unsure of something and I urge you to hop in and have a read from time to time, even if this is nothing new to you. I believe that every tutorial needs proof-reading so do post comments/questions when you think some things need further explaination or clarification, and of course, do post if you actually find bugs. :)
Ok, by the way I think you should talk about filesystem before maxmod, so that you could explain how to stream sound instead of using AsLib. It was a nice library but some people had problems with the arm7 code used by it and it is not updated to latest devkitpro sadly.
I will be able to help for playing sounds music and streaming with maxmod as I made a mini library for my project.
Last thing :P, maybe it would be nice to talk about headers and multiple source files.
Too many beginners use only the main.c and so they can't understand everything when they come back on the sources ^^
I didn't read everything but I ll be following next parts, so far nothing to say its pretty good ;)
edit:you might illustrate the switch with the what does the code.
I mean you could just say that in reality, its a jump in the code to the line with case and the program will read all the lines until it finds break;
that's not well explained but I think the word "jump" is very explicit.
And maybe stress a bit the fact it should, no, must be used instead of if else if, when there is more than 3-4 conditions on one variable only.
Because it only JUMPS and not verify all statements, a way faster. It is a common error which make a gap of performance.
Anyway sorry for my English ^^
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,825
Trophies
3
Location
Gaming Grotto
XP
29,844
Country
Poland
Ok, by the way I think you should talk about filesystem before maxmod
NFLib automatically includes both FAT and Nitro, thus a typical beginner won't really need to know how to include it properly. As for using FAT functions, of course, this will be included (for saving and the sort).
It was a nice library but some people had problems with the arm7 code used by it and it is not updated to latest devkitpro sadly.
When well-implemented it still does the job and it's the only library to date that streams MP3's, so although it is not recommended, it will be included alongside maxmod.
I will be able to help for playing sounds music and streaming with maxmod as I made a mini library for my project.
Again, NightFox did it "for us", playing mod sound is really limited to initializing the sound system and picking a module. :)
Last thing :P, maybe it would be nice to talk about headers and multiple source files.
Precisely why we're using Visual Studio - I absolutely hate a cluttered main.c and yes, we'll be using a whole lot of function wrappers and header files.
Too many beginners use only the main.c and so they can't understand everything when they come back on the sources ^^
I recieved more source files that were ambiguous and difficult to read to the point that they made me facepalm then I can possibly count - this will be covered in the Appendix of the tutorial. ;) It's better to have a ton of included files but have readable code then to have everything in one file and immediatelly get lost in it, that's why beginners should be briefed on how to properly organize data, I agree. It's "same difference" for the compiler while the programmer can fluently jump from one point to the other. :)
I didn't read everything but I ll be following next parts, so far nothing to say its pretty good ;)
Thanks, doing my best. ;)
edit:you might illustrate the switch with the what does the code.
I mean you could just say that in reality, its a jump in the code to the line with case and the program will read all the lines until it finds break;
This will be better ilustrated in the following excercises, I want to cover the basics before we get to the examples. IMO, you can't analyze something unless you know how it works, so a physical illustration with more material then the readers already know would be futile. That said - it's in the works. ;)
And maybe stress a bit the fact it should, no, must be used instead of if else if, when there is more than 3-4 conditions on one variable only.
And why would that be? A switch is too limited for some conditions as it only refers to integer or character values as a condition. Using it for any other purpose would be stretching it for no reason. But yeah, I agree that an if/else statement shouldn't be longer then it needs to be.
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,825
Trophies
3
Location
Gaming Grotto
XP
29,844
Country
Poland
This is still a bit too advanced for a beginner like myself but I have bookmarked it and will come back once i get it.
Precisely why the forum posts form was chosen over an independent Wiki - the tutorial is entirely organic, when in doubt just ask and I will do my best to clarify things. :)
 

Coto

-
Member
Joined
Jun 4, 2010
Messages
2,979
Trophies
2
XP
2,565
Country
Chile
Foxi4 I too agree, that you should at least do a small briefing on FAT initialization so we can stream content by using a more rudimentary way (the way one should learn C) rather than using a fixed function, which is indeed more easy to most of users, but leaving a hole in both bugs and knowledge.
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,825
Trophies
3
Location
Gaming Grotto
XP
29,844
Country
Poland
Foxi4 I too agree, that you should at least do a small briefing on FAT initialization so we can stream content by using a more rudimentary way (the way one should learn C) rather than using a fixed function, which is indeed more easy to most of users, but leaving a hole in both bugs and knowledge.
Like I said, FAT/Nitro will be covered. :) Just not for the resources that are loaded automatically by NightFoxLib. The mechanism is really all the same for just about any file you'd like to load, so I chose to leave it for an entirely separate chapter. We're miles from getting there anyways. ;)
 

lostdwarf

Well-Known Member
Member
Joined
Nov 2, 2008
Messages
1,071
Trophies
0
Location
ENGLAND
Website
www.rockstarleeds.com
XP
271
Country
This is still a bit too advanced for a beginner like myself but I have bookmarked it and will come back once i get it.
Precisely why the forum posts form was chosen over an independent Wiki - the tutorial is entirely organic, when in doubt just ask and I will do my best to clarify things. :)

Great, I have enroled myself on a javascript course (I know this is not c or c++ but it will be helpfull for the basics I think) I look forward to being adept enough to come back to this guide as it is well written and start programming my own app.
 

LeRodeur

Well-Known Member
Member
Joined
Dec 12, 2009
Messages
162
Trophies
0
Age
30
XP
190
Country
France
And why would that be? A switch is too limited for some conditions as it only refers to integer or character values as a condition. Using it for any other purpose would be stretching it for no reason. But yeah, I agree that an if/else statement shouldn't be longer then it needs to be.

I do agree thats it's limited but I talked about conditions "on one variable only." not complex ones ;)
Well let me illustrate why i said that, typycal error...
Taken from old version of Dscraft2D :
Code:
void worldUpdate(worldObject* world,void* player2){
playerActor* player=(playerActor*)player2;
for (i=player->blockx-16;iblockx+16 && iblocky-16;jblocky+16 && jCamY);	  
else if (world->blocks[i][j]==GRASS) GRASS_render(i*32-world->CamX,j*32-world->CamY);  
else if (world->blocks[i][j]==DIRT) DIRT_render(i*32-world->CamX,j*32-world->CamY);	
else if (world->blocks[i][j]==LOG) LOG_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==PLACED_LOG) LOG_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==LEAVES) LEAVES_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==PLANKS) PLANKS_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==TORCH) TORCH_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==COBBLE) COBBLE_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==BEDROCK) BEDROCK_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==SAND) SAND_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==DOOR_OPEN_TOP) DOOR_OPEN_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==DOOR_OPEN_BOTTOM) DOOR_OPEN_render(i*32-world->CamX,j*32-world->CamY-32);
else if (world->blocks[i][j]==DOOR_CLOSED_TOP) DOOR_CLOSED_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==DOOR_CLOSED_BOTTOM) DOOR_CLOSED_render(i*32-world->CamX,j*32-world->CamY-32);
else if (world->blocks[i][j]==GRAVEL) GRAVEL_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==WHITE_WOOD) WHITE_WOOD_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==DARK_WOOD) DARK_WOOD_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==PLACED_LOG_W) WHITE_WOOD_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==PLACED_LOG_D) DARK_WOOD_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==SANDSTONE) SANDSTONE_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==COAL_ORE) COAL_ORE_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==IRON_ORE) IRON_ORE_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==GOLD_ORE) GOLD_ORE_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==DIAMOND_ORE) DIAMOND_ORE_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==REDSTONE_ORE) REDSTONE_ORE_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==LAPIS_ORE) LAPIS_ORE_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==GLASS) GLASS_render(i*32-world->CamX,j*32-world->CamY);
//Here Lapis-BLOCK
else if (world->blocks[i][j]==WOOL_WHITE) WOOL_WHITE_render(i*32-world->CamX,j*32-world->CamY);
else if (world->blocks[i][j]==PLACED_LEAF) LEAVES_render(i*32-world->CamX,j*32-world->CamY);
}	  
}
}

instead of:
Code:
void worldUpdate(worldObject* world,void* player2){
playerActor* player=(playerActor*)player2;
for (i=player->blockx-16;iblockx+16 && iblocky-16;jblocky+16 && jCamX,j*32-world->CamY); break;
case GRASS: GRASS_render(i*32-world->CamX,j*32-world->CamY); break;	
case SNOW_GRASS: SNOW_GRASS_render(i*32-world->CamX,j*32-world->CamY); break;  
case DIRT: DIRT_render(i*32-world->CamX,j*32-world->CamY); break;
case SAND: SAND_render(i*32-world->CamX,j*32-world->CamY);	   break;
case WHITE_WOOD: WHITE_WOOD_render(i*32-world->CamX,j*32-world->CamY); break;
case DARK_WOOD: DARK_WOOD_render(i*32-world->CamX,j*32-world->CamY); break;
case PLACED_LOG_W: WHITE_WOOD_render(i*32-world->CamX,j*32-world->CamY); break;
case PLACED_LOG_D: DARK_WOOD_render(i*32-world->CamX,j*32-world->CamY); break;
case LOG: LOG_render(i*32-world->CamX,j*32-world->CamY); break;
case PLACED_LOG: LOG_render(i*32-world->CamX,j*32-world->CamY); break;
case LEAVES: LEAVES_render(i*32-world->CamX,j*32-world->CamY); break;
case PLANKS: PLANKS_render(i*32-world->CamX,j*32-world->CamY); break;
case TORCH: TORCH_render(i*32-world->CamX,j*32-world->CamY); break;
case COBBLE: COBBLE_render(i*32-world->CamX,j*32-world->CamY); break;
case BEDROCK: BEDROCK_render(i*32-world->CamX,j*32-world->CamY); break;
case DOOR_OPEN_TOP: DOOR_OPEN_render(i*32-world->CamX,j*32-world->CamY); break;
case DOOR_OPEN_BOTTOM: DOOR_OPEN_render(i*32-world->CamX,j*32-world->CamY-32); break;
case DOOR_CLOSED_TOP: DOOR_CLOSED_render(i*32-world->CamX,j*32-world->CamY); break;
case DOOR_CLOSED_BOTTOM: DOOR_CLOSED_render(i*32-world->CamX,j*32-world->CamY-32); break;
case GRAVEL: GRAVEL_render(i*32-world->CamX,j*32-world->CamY); break;
case SANDSTONE: SANDSTONE_render(i*32-world->CamX,j*32-world->CamY); break;
case COAL_ORE: COAL_ORE_render(i*32-world->CamX,j*32-world->CamY); break;
case IRON_ORE: IRON_ORE_render(i*32-world->CamX,j*32-world->CamY); break;
case GOLD_ORE: GOLD_ORE_render(i*32-world->CamX,j*32-world->CamY); break;
case DIAMOND_ORE: DIAMOND_ORE_render(i*32-world->CamX,j*32-world->CamY); break;
case REDSTONE_ORE: REDSTONE_ORE_render(i*32-world->CamX,j*32-world->CamY); break;
case LAPIS_ORE: LAPIS_ORE_render(i*32-world->CamX,j*32-world->CamY); break;
case GLASS: GLASS_render(i*32-world->CamX,j*32-world->CamY); break;
case CACTUS: CACTUS_render(i*32-world->CamX,j*32-world->CamY); break;
//Here Lapis-BLOCK
case WOOL_WHITE: WOOL_WHITE_render(i*32-world->CamX,j*32-world->CamY); break;
case PLACED_LEAF: LEAVES_render(i*32-world->CamX,j*32-world->CamY); break;
}
}
}	  
}
}

which made a great loss of performance..
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,825
Trophies
3
Location
Gaming Grotto
XP
29,844
Country
Poland
You're forgetting that "world->blocks[j]" is not really a complex variable and definitely not what I had in mind when I said that non-simple variables cannot be used - in this switch the variable used is a simple integer stored in the blocks array at point [j]. ;)

I agree with you though to the point that I will even bold it - using a switch is infinitelly less taxing on the CPU then using long set of if/else statements. :)

Take in mind though that you wouldn't be able to do the same thing with this:

Code:
switch(world->blocks){[/I]
[I]case 0,1:[/I]
[I]Statement;[/I]
[I]break;[/I]
[I]}

You cannot pass the whole array as the argument - just simple integers that it stores.
 

Walthor

Well-Known Member
Newcomer
Joined
Feb 2, 2009
Messages
56
Trophies
0
XP
76
Country
Netherlands
part 3 and 4 are good. just read them and they jugged my memory in writing some things.
got a simple peace of software wich loads some other classes in and call a function of the classes. Also got keyboard to work on the touchscreen.

I do have one question. I can only show text on the bottom screen due to calling consoleDemoInit(). i also want the topscreen to show text. Is there a way to get text to appear on both screens? for example when i press A some text appears on the top screen and when i press b some text appears on the bottom screen.

i did do some googling but this resolved into text not showing up at all lol.

This is my current code:
Code:
#include 
#include 
#include "Classie.h"
void OnKeyPressed(int key) {
if(key > 0)
iprintf("%c", key);
}
int main(void) {

consoleDemoInit();
Keyboard *kbd =  keyboardDemoInit();
kbd->OnKeyPressed = OnKeyPressed;
char myName[256];
iprintf("Wally DS Demo.");
printf("Press A to open up the keyboard and type your name.");
Classie * c = new Classie;
bool  stoppen = false;
while(!stoppen) {
scanKeys();

switch(keysUp()){
case KEY_A:
scanf("%s", myName);
iprintf("\nHello %s", myName);
break;
case KEY_START:
c->PrintData();
printf("boejah bitch\0");
break;
case KEY_SELECT:
iprintf("Quitting Game");
stoppen = true;
break;
}

swiWaitForVBlank();
}
}
 

LeRodeur

Well-Known Member
Member
Joined
Dec 12, 2009
Messages
162
Trophies
0
Age
30
XP
190
Country
France
You cannot pass the whole array as the argument - just simple integers that it stores.
I totally agree it was only to avoid the kind of things i've talked about ;)

Quote

I will be able to help for playing sounds music and streaming with maxmod as I made a mini library for my project.

Again, NightFox did it "for us", playing mod sound is really limited to initializing the sound system and picking a module. :)

Dont remember nflib to be able to stream music, it simply loads it into memory and then read it from memory with default libnds sound functions, while maxmod is far better with his sfx, mod and streaming =)
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,825
Trophies
3
Location
Gaming Grotto
XP
29,844
Country
Poland
part 3 and 4 are good. just read them and they jugged my memory in writing some things.
got a simple peace of software wich loads some other classes in and call a function of the classes. Also got keyboard to work on the touchscreen.

I do have one question. I can only show text on the bottom screen due to calling consoleDemoInit(). i also want the topscreen to show text. Is there a way to get text to appear on both screens? for example when i press A some text appears on the top screen and when i press b some text appears on the bottom screen.

i did do some googling but this resolved into text not showing up at all lol.
The standard console can only be initialized on the bottom screen as far as I know as it is a debug tool, not an actual layer to display text. You can however initialize consoles on both screens... BUT! If you want to display proper text, you need to either use a tiled Text layer or print text directly onto a Bitmap layer.

If you want to stick to clean libnds then I suggest reading the devkitpro examples for libnds - you will find one that's called Graphics\print_both_screens, there you will have detailed information on how to call up a console on both screens. If you want "prettier" tiled text then I refer you to the Graphics\custom_font one.

That, or you can do yourself a favour and get a proper graphics library like NightFox and simply include it in your project. :)
 

Walthor

Well-Known Member
Newcomer
Joined
Feb 2, 2009
Messages
56
Trophies
0
XP
76
Country
Netherlands
part 3 and 4 are good. just read them and they jugged my memory in writing some things.
got a simple peace of software wich loads some other classes in and call a function of the classes. Also got keyboard to work on the touchscreen.

I do have one question. I can only show text on the bottom screen due to calling consoleDemoInit(). i also want the topscreen to show text. Is there a way to get text to appear on both screens? for example when i press A some text appears on the top screen and when i press b some text appears on the bottom screen.

i did do some googling but this resolved into text not showing up at all lol.
The standard console can only be initialized on the bottom screen as far as I know as it is a debug tool, not an actual layer to display text. You can however initialize consoles on both screens... BUT! If you want to display proper text, you need to either use a tiled Text layer or print text directly onto a Bitmap layer.

If you want to stick to clean libnds then I suggest reading the devkitpro examples for libnds - you will find one that's called Graphics\print_both_screens, there you will have detailed information on how to call up a console on both screens. If you want "prettier" tiled text then I refer you to the Graphics\custom_font one.

That, or you can do yourself a favour and get a proper graphics library like NightFox and simply include it in your project. :)
I see, i learned how to use the keyboard from using the examples so i will definitively check the others out then :) didn't know there was a example for this. Thnx :)
 

LeRodeur

Well-Known Member
Member
Joined
Dec 12, 2009
Messages
162
Trophies
0
Age
30
XP
190
Country
France
"If you want to stick to clean libnds then I suggest reading the devkitpro examples for libnds" : +1
Examples are really nice to understand how it works, if youre not a beginner i'd suggest to take a look at gbatek ;)
Pre-Edit: seems no$gba website is off so no access to gbatek at the moment.
 

Foxi4

Endless Trash
OP
Global Moderator
Joined
Sep 13, 2009
Messages
30,825
Trophies
3
Location
Gaming Grotto
XP
29,844
Country
Poland
"If you want to stick to clean libnds then I suggest reading the devkitpro examples for libnds" : +1
Examples are really nice to understand how it works, if youre not a beginner i'd suggest to take a look at gbatek ;)
Pre-Edit: seems no$gba website is off so no access to gbatek at the moment.
Yeah, the whole GBATek page seems to be offline... for a worryingly long period of time, actually... I tried to access it earlier this week and no go either.
 

Slashmolder

Well-Known Member
Newcomer
Joined
Jul 5, 2008
Messages
66
Trophies
0
XP
205
Country
United States
I agree with you though to the point that I will even bold it - using a switch is infinitelly less taxing on the CPU then using long set of if/else statements. :)

Though I believe that it's a good idea to do that for clean code, wouldn't the generated assembly be exactly the same?
Something like:
Code:
compare a,#0
jump if not equal, to next compare
//stuff for condition
jump to end of switch/if else block
compare a,#1
jump if not equal, to next compare
//stuff for condition
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    Psionic Roshambo @ Psionic Roshambo: I did use a bot for Diablo III though but no ban there lol