Paeryn's SDL


Paeryn is working on a hadware accelerated version of the SDL library for the GP2X.



  • Hardware accelerated surfaces.
  • Hardware screen scaling! When you ask for (using SDL_SetVideoMode) a screen that's larger (or smaller) than the LCD it will automagically scale it to fit the screen. An added extra function to allow dynamic scaling too (see README.GP2X).
  • Colour expansion of 1bpp blits. When you blit a 1bpp surface it will expand 0s to background and 1s to forground. An added function lets you set what these colours are (see README.GP2X).
  • Preliminary TV-Out support.

The 16MB release

This release adds Initial large memory support, and uses the first 16M of the upper 32M for the frame buffer and the surfaces. The old version only uses 5M of the upper memory.

This release also fixes the swapped buttons in previous versions. The buttons that were swapped were X-Y and L-R.

Additional (non standard) gp2x functions

Paeryn's SDL adds some useful functions that are documented in the file README.GP2X.

int SDL_GP2X_GetPhysicalScreenSize(SDL_Rect *size);

Fills size->w and size->h with dimensions of the current screen,

  • LCD  : 320x240
  • NTSC : 720x480
  • PAL  : 720x576


  • 0 for progressive (LCD)
  • 1 for interlaced (NTSC & PAL)
  • -1 if SDL_Init hasn't been called yet

void SDL_GP2X_Display(SDL_Rect *area);

Sets the hardware scaler to show requested area of primary surface as fullscreen. The scaler does not physically alter the surface, it just affects how the surface will appear on-screen. This allows you to pan around a surface larger than the screen, and/or zoom in/out.

You cannot zoom out further than having the full surface on-screen.

area->x and area->y set which pixel of the primary surface will appear at the top-left corner of the display, area->w and area->h set the width and height of the area to fill the display.

void SDL_GP2X_MiniDisplay(int x, int y);

Similar to the above function, but does not scale and blanks the borders. Only really useful if your videomode is less than 320x240. Gives rise to possible small speed increase as the display hardware doesn't access memory in the borders. Region 1 (see SDL_GP2X_DefineRegion below) area is set to {x, y, x+videomode_width-1, y+videomodeheight-1}.

The x & y values are where the top-left corner of you screen will placed on the display. e.g. for a 200x200 videomode centred in the middle of the display you'd use x=60 y=20

NO checking is done to make sure your screen fits!

void SDL_GP2X_SetCursorColour(SDL_Cursor *cursor, int b_red, b_green, b_blue, b_alpha, int f_red, f_green, f_blue, f_alpha);

Sets the background and foreground colours of the hardware cursor. SDL assumes black and white for all cursors, this lets you choose your own colours for each cursor. Cursor colours are full 24bit, each component wraps instead of clamping (so if you try setting red to 257 you'll actually get 1 etc.)

Also, the background and foreground colours have seperate levels of alpha-blending (0=transparent -> 15=opaque). Again, the values wrap.

void SDL_GP2X_DefineRegion(int region, SDL_Rect *area);

Allows you to define regions (1-4) that will be visible. By default region 1 is set to fullscreen (apart from when using MiniDisplay).

Regions work by defining rectangles of the display that the video hardware will show. Think of it like painting your LCD black and for each region you use, scrape the paint off for that rectangle.

Region areas are in hardware coordinates, 0x0 is the top-left, 319x239 is bottom-right regardless of size and position of your surface.

void SDL_GP2X_ActivateRegion(int region, int activate);

After defining regions above, use this to switch individual regions on (activate = 1) or off (activate=0). By default only region 1 is active.

There is a fifth region, region 5, but this is fullscreen only and hence not available to SDL_GP2X_DefineRegion().

void SDL_SYS_JoystickGp2xSys(SDL_Joystick joystick, int command);

Joystick must be the value returned by SDL_JoystickOpen(0). This is because this function relies on data that is stored in the joystick structure of the internal joystick. To be doing anything on the GP2X you'll more than likely be wanting access to the buttons anyway.

The values you can pass as the command are as follows:

  • BACK_LIGHT_OFF - Switches the backlight off ;)
  • BACK_LIGHT_ON - Switches the backlight back on.
  • BATT_LED_OFF - Switches the red battery light on.
  • BATT_LED_ON - Switches the red battery light off.
  • FCLK_200 - Runs the CPU at 200 MHz.
  • FCLK_166 - Runs the CPU at 166 MHz.
  • FCLK_133 - Runs the CPU at 133 MHz.
  • FCLK_100 - Runs the CPU at 100 MHz.
  • FCLK_78 - Runs the CPU at 78 MHz.
  • FCLK_64 - Runs the CPU at 64 MHz.

The following is allowed, but I've just checked the source for /dev/gpio to see what speed it corresponded to and found that it doesn't actually do anything.

  • FCLK_DEFAULT - Runs the CPU at it's default speed.

void SDL_GP2X_SetMonoColours(int background, int foreground);


When blitting a 1bpp surface, this sets what colour the 0s and 1s will be translated into. Useful for drawing fonts. This is a global setting, not per-surface.


Paeryn only replaces a few libraries, so you'll want to install the full SDL development libraries before nabbing.

Latest source

For grabbing the latest sources, use svn.

svn checkout


If you use the SDL Joystick mapping from this Wiki, the X and Y buttons are switched.

See this forum thread for more info and discussion.

Personal tools