gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Tile graphics help plz.

#154088 - Alphanoob - Thu Apr 10, 2008 9:17 pm

Ok so here's my question. How do I do simple background tile graphics? I have read guides, and they tend to go way more in depth on how they work than I would like. All I want to know is how to create tiles and assign them to spots on the backround manually. I know there is a way because I have seen part of an example, but it didnt give enough to actually make my own from it. I have actually made my own sort of tiling program in BASIC once for use in a calculator game, but that is too inefficient for my liking and I would like to know how this works.

#154090 - silent_code - Thu Apr 10, 2008 9:53 pm

check out cearn's tonc.

#154091 - Alphanoob - Thu Apr 10, 2008 10:45 pm

Is that guide with devkitARM or PAlib? I have never looked into PAlib, as I am new to C++. I am still learning a lot of stuff from my C++ book that I bought, but I figured since I made my own sort of tile engine, it would be worth looking into. The dev-scene tutorial seemed to have a much simpler way of doing things, it just cut off before finishing its explanation.

#154097 - tepples - Fri Apr 11, 2008 12:34 am

TONC works with straight-up devkitARM and libgba, not HAM or PAlib.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#154101 - silent_code - Fri Apr 11, 2008 1:44 am

it's THE hb gba programming bible. actually, it really doesn't depend on any specific api. :^)
throw away all other tutorials and get tonc! :^D

#154103 - Alphanoob - Fri Apr 11, 2008 2:11 am

ok, lol. I will look into it. It just bothers me trying to switch guides because between dev-scene and my C++ book I have learned some. This leads to me getting bored with stuff I have already seen while trying to gather what little extra bits the guide has here and there. They all organize stuff differently and teach it a bit different, leading to a mesh of my old teaching and new ways to do it. that makes life confusing, lol. btw, does anyone know how to force my computer to use the devkitpro compiler? I got a new thing for PC programs, and now whenever I try to compile using "make makefile" my computer freaks out because it uses the wrong compiler for some dumb reason. When I got the 2nd compiler, it changed all the thumbs for the main.c files too... any ideas?

#154105 - Dwedit - Fri Apr 11, 2008 2:22 am

If you've installed devkitpro's msys, then run that, and you get devkitpro.
If you've also installed a different msys or cygwin, run that and develop for your pc.

The ARM compilers have a different prefix on them, arm-eabi-gcc for the DS, and regular gcc for the PC.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#154106 - Alphanoob - Fri Apr 11, 2008 2:24 am

ty, I will try that right away =).

#154107 - Alphanoob - Fri Apr 11, 2008 2:28 am

it worked =)! you rock! ty soooo much.

#154115 - silent_code - Fri Apr 11, 2008 10:49 am

the solution to this problem i personally use is: working with code::blocks, i simply set the arm gcc up in the ide's compiler settings presets (that's easy to do) and use that. no need for freaking environment variables, that might get messed up with the windows gcc env. variables.
that way i have a consistent development environment and i don't need to use msys and whatnot. :^)
plus, if you make batch files that start your rom with any emulator, you can put each .bat into the projects workspace and run a .bat simply by doubleclicking it in the project file tree. :^D

#154148 - Alphanoob - Fri Apr 11, 2008 11:21 pm

Would one of you guys mind teaching me some of the basics of this C++ for the DS? there seem to be a lot of different ways to do it, and I just want to learn the basics for now. In truth, if you would just tell me the commands to manually make a map of tiles, then I could easily make a simple game. I am presently just trying to get my little tile engine that I made in BASIC converted, and it seems to be working fine. A real command to do it would be very nice though.

#154165 - silent_code - Sat Apr 12, 2008 2:25 am

lesson one:
there is no such thing as "this c++ for the DS".
but there is:
1) a gcc version targeting the nds' arm processors
2) a library to handle most (which means it doesn't include things like wifi etc) of the hardware's specific features, libnds

which of these two do you need help with?

#154187 - Alphanoob - Sat Apr 12, 2008 6:17 pm

rofl, I feel sooooo noobish right now. especially knowing what I am about to say. I have no idea which one I have. I am guessing I need help with the second one, as I have downloaded devkitPRO and devkitARM, which included a new lib for me, thus my so noobishly calling it "C++ for DS". So whatever devkitPro/Arm is, I need help with that.

#154190 - tepples - Sat Apr 12, 2008 7:13 pm

So as far as I can tell, "this c++ for the DS" refers to the task of learning all of the following at the same time:
  1. The parts of C++ that are in C
  2. How to use GCC to compile C++
  3. The parts of C++ that are not in C
  4. How to use wintermute's build system
  5. How to use libnds to talk to the DS hardware

Alphanoob: What experience do you have with C++ on your computer, making programs for your computer (no DS involved)? There is a way to learn the above steps one at a time if you're willing to take a detour through MinGW-land.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.


Last edited by tepples on Sat Apr 12, 2008 7:18 pm; edited 1 time in total

#154192 - Alphanoob - Sat Apr 12, 2008 7:17 pm

I started very recently, and bought a book. I have most of the basics down, like making different variables, inputting numbers, outputting text or variables, and I know how to make If loops and whatnot. As for the DS, I do know how to compile my stuff, and I have been working on a very simple program. I can get it to move a 4 pixel box around the screen in accordance with the arrow keys, and output the box's coordinates as well as tell you where you are touching the touch screen.

#154193 - tepples - Sat Apr 12, 2008 7:22 pm

It might be easier for you to learn tile graphics on the Game Boy Advance first, where you don't have to worry about A. loading your graphics from FAT into RAM, or 2. setting up VRAM banks. You can take the TONC tutorial verbatim on the GBA instead of having to adapt some parts in ways that might not be obvious to people new to the DS. Do you have any SLOT-2 flash equipment?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#154198 - Alphanoob - Sat Apr 12, 2008 8:15 pm

I will tell you what I am using in the way of equipment:
-A flashed DS lite
-Supercard Lite, a slot 2 device (used to use superkey in slot 1, but I flashed it =))
-2GB micro SD card.
A quick question:
Do you think I should just use my self made tiler?
All I do is enter a tile's number and where I want it on the screen. It is easy enough to do in BASIC, as I have said many times. This eliminates all of that other confusing stuff.

#154199 - PlagueSpark - Sat Apr 12, 2008 8:24 pm

On some good tutorial "how to began developing for Nintendo DS" there Is a good advice to have at least 20 hours of just C/C++ self-training before ever looking on ds code :)
I also strongly recommend to learn tricks about fixed-point math.

#154200 - Alphanoob - Sat Apr 12, 2008 8:31 pm

Yeah, I kinda figured that DS programming would only come after quite a while of C++. I still wanna at least get a handle on the basics of it while all of this C++ jargon is fresh in my mind. Its not so much that I don't understand how all of this works as that I just cant remember all of the new commands added with DevkitPRO/ARM. I am quite proud of myself though, I have managed to split the screen up into 256 working tiles =).

#154205 - silent_code - Sat Apr 12, 2008 9:53 pm

lesson 2: it's ok to be a starter. just be a nice person, that's all it takes. lesson passed, successfully. ;^)

lesson 3: what are if loops? ;^)

if/else if/else are called conditional branches. switch/case/default is somewhat similar to this.

while, for, do/while are loops. by nature, they have conditional execution. even if it's just a constant "true" condition. :^)

#154222 - Alphanoob - Sun Apr 13, 2008 12:12 am

oh yeah, the while loops... I never got those. If you make it while(1), when does it end? I mean, can you only have one while in a whole program? or do you make something like if(X = 7) then end?

#154223 - silent_code - Sun Apr 13, 2008 12:51 am

an infinit loop (e.g. while(true){...}) can be left with with the usual "break;" in a conditional branch.

of course you can have more than one loop in your program! but usually, these will be finite, e.g. while(doStuff) { ... at some point set "doStuff = false;" to quit} or any other conditional statement - note, that this reads "while(doStuff == true)" or "while(doStuff != 0)", but as doStuff has a value you can omit the "== true" or "!= 0" part.
don't forget to set your conditional variable ("doStuff" in this case) according to the starting conditions before the loop or the loop body will not be entered in case of "doStuff == false", because "while" checks the condition BEFOREHAND in contrast to "do{...}while(doStuff)" which checks it after the first and each execution.

#154225 - Alphanoob - Sun Apr 13, 2008 12:59 am

ok... so just make sure that if I make something like
while(X = 1)
doStuff

then I should make sure that X = 1 to start with, otherwise it is just a bunch of wasted code...
this makes so much more sense to me now! This could be used to program in each level of a simple game
while(level = 1)
level one's code
while(level = 2)
level two's code
=)

#154226 - silent_code - Sun Apr 13, 2008 1:16 am

wrong!
because, in your example you assign x the value 1 at the beginning of the loop. that's why the loop would yield the same result over and over again.

use "while(x == 1)" instead. ;^)

and normally you wouldn't do levels like that, but for learning the approach is ok, although the "algorithm" is sub optimal. ;^)

#154231 - Alphanoob - Sun Apr 13, 2008 4:39 am

rofl, u got me. I made a noob mistake already. Ty for all of this help.

#154280 - Alphanoob - Mon Apr 14, 2008 12:49 am

I was just looking at that TONC guide that you guys keep talking about. It seemed like a pretty good guide, but I had to stop reading it, as I was in danger of getting a massive headache. How do you guys decipher all of those numbers? I mean, is that really how most of programming for the NDS is? because if so, i should definitely get a heck of a lot more computer stuff under my belt first. I am starting to feel as though all that I have learned so far from the dev-scene tutorial is almost a joke compared to how programming really is, lol.

#154282 - tepples - Mon Apr 14, 2008 2:20 am

Alphanoob wrote:
How do you guys decipher all of those numbers?

Macros. Lots of macros. But if you do it right, you have to do the low-level stuff once and only once, then encapsulate it in a library.

Quote:
I mean, is that really how most of programming for the NDS is? because if so, i should definitely get a heck of a lot more computer stuff under my belt first.

Here's a list of basic computer science topics that I've prepared for a tutorial for homebrew development on another platform.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#154285 - silent_code - Mon Apr 14, 2008 2:42 am

lesson... ah, crap! ;^P

well. AN, you're basically right. it's kind of an infinite (yet terminating!) loop of learning. every time you think you know "quite much" about a topic, something pops into your consciousness that you have never encountered before... and there you go again. anyone familiar with sisyphus? (btw: ulysses31, anyone remeber that?) ;^)

but this also keeps programming an interesting and always challenging field of interest.

happy coding!

#154292 - Alphanoob - Mon Apr 14, 2008 4:17 am

definitely challenging, lol. So, to truly get good at this stuff should I learn C++ more fully and then make my own library? because I have downloaded devkitPro and devkitARM, which are libraries, right? I would always try to avoid thinking about how they made those things, but I guess I should think about it more, lol. If that is the deal though, I guess its back to "Sams Teach Yourself C++ in 24 Hours" with me =) (that is the book I got, and it is really helpful). But a library, its just like splitting commands up into a LOT of different vars, right? like when you tell it that "held = keysHeld()" to make programming a bit more manageable? btw, u guys are sooooo helpful. I think my head may have exploded when I looked at Tonc if tepples hadn't explained that it only has to be done once.

#154294 - Alphanoob - Mon Apr 14, 2008 5:06 am

I started looking over some of those sources from the link tepples posted... and a thought occurred to me. When I finally start taking the 2 programming classes at my school (which I hear are quite easy), you guys will probably have taught me more than the teacher can (if you havent already, that is). Someone told me that the first assignment is the oh so classic hello world program, which isnt looking that bad compared to the boolean logic and binary stuff on the wiki page. All of that "low level" stuff is definitely helping me understand the basics better. once again, thanks.
EDIT: I write waaay to much, don't I?

#154306 - silent_code - Mon Apr 14, 2008 2:18 pm

libs - short answer: no.
long answer: the devkits are NOT libraries! the are DEVKITS containing compilers, linkers, as well as language standard libraries and misc. utilities.

these are required to compile anything for a specific platform (x86/x64, ARM, pwrPC, 68000 etc. in all variations, e.g. nds, gba, ps3, x360, ngc, win32...).

but to use any specific functionality/hw (like MMX, SSE on the pc, OAM on gba/nds etc.), you have to interface the platform in a specific way. this is done e.g. via writing specific values (depending on the effect you want to have on the hw) to specific memory locations (all the 0x00430434F's ;^) ) in specific ways (byte/half/word writes etc).

to ease the use of that hw, which is not directly addressed (you don't need to explicitly program the fpu, just use floats! ;^) ) by the language/compiler (c/c++), you define names for those memory locations (or "addresses") as well as functions to do common tasks. like a function, that uses the hw divider. it is common to define macros for addresses.

a library is therefore a set of supporting code. like openGL/AL are helping you to program your graphics/audio hw. you have an API in most, if not all, libraries, which can be a set of definitions (macros), functions, data structures and sometimes also data.

libs (like libnds - in gcc most, if not all, libs have the lib prefix and one of the following suffixes: .a, .lib and others, with those two the most common to me) are basically compiles code, that needs to be linked to other code, that will provide a program entry point (main(...)) to create the executable. note, that the entry point can also be in a lib! but as long as you don't make a build with an executable compiler target (which links the code and yields the exe instead of just object files or libs), you can't execute the code!

at this stage, i don't think you "need" to write your own library. use an existing one, like libnds, to interface the hw. ;^)

puuuh. hope that's clear (an correct) enough. make sure you check terms in wikipedia, that should give you enough information. :^)

happy learning!

ps: write as much as needed. till now, i, personally, find your post ok. those who want to learn, need to ask! ;^)

#154339 - Alphanoob - Mon Apr 14, 2008 11:47 pm

I get the main point, but a couple of those abbreviations escaped me. what do hw and fpu stand for? Oh, and how important is making prototypes for functions. today I read about it, and noticed that not only have I not been making those, but I haven't been declaring parameters either. Are those a big deal? The way it looks to me, it is a miracle any of my functions work without those elements properly implimented.

#154340 - tepples - Tue Apr 15, 2008 12:17 am

Alphanoob wrote:
I get the main point, but a couple of those abbreviations escaped me. what do hw and fpu stand for?

Hardware and floating-point unit, respectively.

Quote:
Oh, and how important is making prototypes for functions.

If you want to reliably call a function in one file from a function in another file, or from a function closer to the top of the same file, you need a prototype.

Quote:
today I read about it, and noticed that not only have I not been making those, but I haven't been declaring parameters either. Are those a big deal?

Yes. Without prototypes, the compiler won't reliably translate between integer and floating-point types or between 32-bit and 64-bit numeric types. Without prototypes, the compiler won't check to make sure that structs and pointers are specified in a way that has well-defined behavior.

Add -Wall to your CFLAGS if it isn't already there. It will help you find some kinds of program defects more easily.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.


Last edited by tepples on Tue Apr 15, 2008 12:22 am; edited 1 time in total

#154341 - silent_code - Tue Apr 15, 2008 12:20 am

example please?

hw = hardware
fpu = floating point unit, a.k.a. math co processor - well, not really, because it's been an integrated part of the cpu in most "big" processors for many years. the gba/nds don't have one, though. that's why we use fixed point instead.

you only need to declare functions that either (1) are used in other .c/.cpp files (a.k.a. modules) or (2) when two functions are in the same source file, but need to call each other, you must at least declare the second one. that's because the compiler will create it's symbol table in the order you write your functions.

example:

Code:

// warning: this program is absolute nonsense, HITS SI UNST!

int run(int woooot, int gnahl); // you can specify a parameter name, but all that's needed are the types. well, names are always better, so that you don't have to look it up in the source file (when working with bigger bunches of code)! i'm making up words, too!

void do(int arrrr)
{
    int brrr = 0;
 // do some stuff...
    --brrr;
    arrr++; //yes, you can do that! arrrr is a local variable just like brrrr, but it's initial value is assigned via the function call.
    brrrr = run(arrrr, 5); // we can call run(), even though, that the definition comes later and the compiler has no idea what it does, because we have declared it beforehand and the compiler at least can check the types and parameter count etc. it also knows that sooner or later there must be some definition, else it'll shout at you in foreign tongues!
}

int run(int waffle, int baffle)
{
// uh, did i just change the parameter names? makes no difference, as just the names for the definition count, because these have to be used in there! means here:

    int ruffle = waffle * baffle & waffle;
    int shnizzle = baffle - ruffle;
    do(shnizzle); // do() has been already defined, so for this call, a declaration is not needed.
    return(256 & ruffle);
}



make sure, that when you have to call a function inside another module, you either put the declaration directly into the source file (might seem noobish, i don't know) or you make a nice header file and put it there. that way, whenever you need to access do() or run(), you just have to include the header.

don't include source files. don't define functions inside headers, unless you make them inline (and extern for c++). but that's a topic for later.

now check out what you've just learned. (if that amount to > 0, that is. ;^D )

PS: i think we might be a bit offtopic here, with all this "teaching" etc. at least that's not really nds dev related. split and move?

#154343 - Alphanoob - Tue Apr 15, 2008 12:53 am

I guess i should post this in C++...
btw, that was the most awesome program I have ever seen. There is only one thing that throws me off about it though (and I can guarantee that this is a very noob thing for me to not know)

when you say:
"int ruffle = waffle * baffle & waffle;"

what does the "baffle & waffle" part do?
note: I am going to go make a new post in the C++ section, so answer there =). oh, and how do you know whether a variable you declare is global or local?