Seitenleiste

Community

Spieleprogrammierung

Allgemein

Tutorials

Das HelloWorld-Programm

Das HelloWorld Programm ist ein einfaches Programm, welches man in einer neuen Programmiersprache zuerst Programmieren sollte. Dieses Hello World Programm gibt nichts anderes aus, als den Text „Hello World“ (Hallo Welt). Das Programm wird oft benutzt um die Compilereinrichtung zu überprüfen, und sich in Compiler und Testumgebung einzufinden.

Erstellen Sie eine Datei main.c und fügen Sie mit einem Programmierereditor (z.B. Notepad++) folgenden Code ein:

#define RGB16(r,g,b)  ((r)+(g<<5)+(b<<10)) 
 
int main()
{
    char x,y;  
    unsigned short* Screen = (unsigned short*)0x6000000; 
    *(unsigned long*)0x4000000 = 0x403;
 
    for(x = 0; x<240;x++)
    {
        for(y = 0; y<160; y++)
        {
            Screen[x+y*240] = RGB16(0,0,0);  
        }
    }
 
    for(x = 20; x<=60; x+=15)
    {
        for(y = 30; y<50; y++)  
        {
            Screen[x+y*240] = RGB16(31,31,31);  
        }
    }
    for (x = 20; x < 35; x++)
    {
        Screen[x+40*240] = RGB16(31,31,31);  
    }
 
    while(1){}
}

Kompilieren Sie den Code mit folgenden beiden Befehlen:

gcc -o hello.elf hello.c -lm
objcopy -O binary hello.elf hello.gba