vendredi 23 janvier 2009

Introducing nds: workshop 1

Workshop 1: (draft version)

1. What is nds?
2. Installing the emulator and playing nds programs
3. Installing IDE, and other development tools (DevkitPro, Grit, Sox)
4. Basic C (variabels, types, iterations, selections, array's, includes)
5. Make your first program (what about....Hello World?)

1. discovering the console nds

it has two screens!
it has so many buttons
it has a touch screen
it has a 3D mode
it has two processors! But these two processors are not the same.
you can program it yourself!
how to get a program on the nds

2.

Nocash GBA Emulator: NO$GBA.EXE
*most reliable
NDeSmuME
*first notions discovering the memory: viewing maps, registers, (dont understand this now :-)

3.
Installing the DevkitPro, working with Programmer's NotePad, Wingrit, grit and Sox.

4. A first bite of C. Is it like JAVA?

variables:
The memory of the nds is limited, so try using as small variables as possible

(even smaller variables will be introduced later :-)

char, of type character 8 bits
short, int, long, of type integer 16/32 bits
double, float of type real 32/64 bits

then you have signed and unsigned:

short -32,768 to 32,767
unsigned short 0 to 65,535, the thing is simply shifted

declarations: you have to declare variables before using them

int start, time1, time2;

special numbers can be defined like this:

#define PI 3.141592654

Arrays (actually pointers, but about pointers later)

int myarray[10];
unsigned int list[5] = { 10, 15, 12, 19, 23 }; //giving the elements right away!
float rdata[128], grid[5][5];

the first element is myArray[0];

asking an element of an array: a = myArray[3];

there is no boundery checking, because an array is a pointer to a position in memory.
What a pointer is: later

when you declare an array the elements are not initialized.

a loop with an array:

for( i = 0; i <= 127; i = i + 1 )
{
printf ( "\f\n", rdata[i] );
}

what is wrong? Yep!
you forgot this:
int i;

dynamically declaring an array:
int *myArray; // don't know exactly how big it will be....
//do a lot of stuff here....
myArray = malloc(10*sizeof(int));

be careful to free the memory again:
free( myArray ); //when aloc then free




while loop:

while ( i <= 100 ) /* loop until i > 100 */
{
printf ( "the number %i \n ", i );
i++;
}

structure of a well known C program:

#include <>
void main()
{
printf("\nHello World\n");
}




conditionals:

if(i <>88)
{
i=88;
}

if ( i ==88)
printf("\n88\n");

the switch is sometimes handy:

switch (i)
{
case 1:
{
printf("it was a one!");
break;
}
case 2:
{
printf("it was a two");
break;
}
default:
{
...block of statements..
}
}


5.
look closer at small example programs in the DevkitPro example folder, running on the emulator, practice some C, using the printing of characters on the upper or lower screen, switching between the screens:

C programming: make the order like this:


void setup()
{
//prepare your stuff
}

void loop()
{
//do something a lot of times
}

main()
{
setup();
loop();
}


The problem with every programming is not only the language but also the special effects.....special methods written for this language to serve the purpose faster...more comfortable sometimes, but these methods have to be learnt too....like for instance consoleInit

assignment 1: now restructure the HelloWorld example in the examples of DevkitPro like this setup-loop scheme.

assignment 2:make the printBothscreens like this setup-loop scheme (this will be more difficult because the consoleInit is rather specialized, be careful!)


have fun!