Hello world

Simple sample to write ‘Hello world’ to screen.

Using library

GP2X minimal library by rlyeh, 2005

License

  • Free for non-commercial projects (it would be nice receiving a mail from you).  Other cases, ask me first.
  • GamePark Holdings is not allowed to use this library and/or use parts from it.

Source code

#include "minimal.h"

int main(int argc, char *argv[])
{
gp2x_init(1000, 16, 11025,16,1,60, 1);

//printfs a text to screen
gp2x_printf(NULL,0,0,"Hello world\n");

//updates video changes
gp2x_video_RGB_flip(0);

while(!(gp2x_joystick_read() & GP2X_A));
}

void gp2x_sound_frame(void *blah, void *buff, int samples) { }

Explanation

  • Our gp2x_init line inits the whole library.  We set 1000 ticks per second, 16 bits video mode, 11025/16bits/stereo/60Hz sound mode, and solid font.
  • Our gp2x_printf line writes a ‘hello world’ string into screen, at coordinates (0,0) and using default font.
  • Our gp2x_video_RGB_flip updates all video changes (in this case, our printed line).
  • Our gp2x_joystick_read line reads the joystick.  In this case we do a loop until any press is found.
  • Our gp2x_sound_frame line fills our sound buffer.  Note that this function will not generate any sound since we have written a void function.

C Compilation

arm-linux-gcc minimal.c hello.c -static -lpthread -lm

C++ Compilation

arm-linux-g++ minimal.c hello.c -static -lpthread -lm

Output

  • this program prints hello world to screen, then it waits for A button before exiting.
void gp2x_init(int ticks_per_second,
int bpp,
int rate,
int bits,
int stereo,
int Hz,
int solid_font)
This function sets up the whole library.
void gp2x_printf(gp2x_font *f,
int x,
int y,
const char *format,
 ...)
This function printfs a string into the RGB layer.
void gp2x_video_RGB_flip(int layer)
This function flips video buffers.
unsigned long gp2x_joystick_read(void)
This function returns the active GP2X joystick values.
extern void gp2x_sound_frame(void *blah,
void *buffer,
int samples)
This function is automatically called by the library, and expects a sound buffer to be filled in.