#167260 - zodiacdagreat - Sat Mar 07, 2009 9:53 am
I've recently started with GBA programming, can anyone here help me with a few questions.
1) How do you declare variables in your code, say a byte, halfword, and a word. I noticed people do *unsigned int* or something lol.
2) Can you include files in your code with the exception of library files, like .bin which contains tileset/tilemap data.
#167262 - Griffin - Sat Mar 07, 2009 11:55 am
You seriously should consider learning the language (C/C++) before starting GBA development.
To declare variables you could do something similar to:
Code: |
int i; // 32 bit integer (signed)
long l; // 32 bit integer (signed)
signed short s; // 16 bit integer (signed)
unsigned char c; // 8 bit integer (unsigned)
|
Note: short, long and int are signed by default, char could vary.
Typically you would typedef the types to make it more explicit: so unsigned long would be equivalent to u32 for example.
You can't include bin files like that unless they're in some form of C array, and even then you'd be better off linking them in instead of having tons of #includes.
#167270 - Ruben - Sat Mar 07, 2009 4:24 pm
As Griffin said, *don't* #include your code/data/etc. The reasons not to do so outweigh the reasons to do so. (Even if you are just beginning, you should get into the habit of not doing this.. it takes a while to break out of)
To make a variable, you'd first have to select your programming language (C or C++) and then you use typedef's. Like this..
Code: |
typedef unsigned char u8; //Unsigned 8-bit value
typedef unsigned short u16; //Unsigned 16-bit value
typedef unsigned int u32; //Unsigned 32-bit value, etc |
If you plan to have map/tile data in your project, have separate .c files (or better yet, .s files as these compile faster) and have the compiler make them into objects and link them to your binary at link time.
From the looks of it, you don't seem to know much C/C++, but seem to come from a language that uses "byte, short, long, word, double word, etc."
What I'd recommend is that you read a C/C++ programming tutorial, and make some applications for Windows or something, first (not 100% necessary, but helps), then you read TONC. You won't pick up many (if any) bad practices from coding under the guidance of that tutorial.
#167271 - Ruben - Sat Mar 07, 2009 4:27 pm
Oh, and I said you should select C or C++, as C++ has size and (possibly?) some speed differences to C.. another small factor, also, is that standard C doesn't have a "bool/true/false" thing.. you'll have to make your own for C.
In short..
C = Good for applications that don't need complicated stuff (like classes)
C++ = Good for applications that will need complicated stuff (like classes with child functions, etc)
#167279 - Griffin - Sat Mar 07, 2009 6:29 pm
Ruben wrote: |
standard C doesn't have a "bool/true/false" thing.. you'll have to make your own for C.
|
Yes it does, that's what stdbool.h is for!
#167290 - Ruben - Sun Mar 08, 2009 8:32 am
Yeah, I just meant that it's not included with your project unless you explicitly include that file. :P