Learning from Open Source


This webpage cannot succeed without volunteer effort. Your help in improving existing or adding new apps is very welcome. Simply contact via  e-mail any apps you think we should add.

Draw Sprite

Copy an N-bit (for N=8, 2, or 1) sprite/image to the VRAM buffer.


const unsigned char* data:

  • int x: X-coordinate of top-left of sprite
  • int y: Y-coordinate of top-left of sprite
  • int width: Width of sprite, in pixels
  • int height: Height of sprite, in pixels
  • color_t* palette: A palette, returned from SourceCoder
  • unsigned int bitwidth: The bit-width. This is designed for 8-, 2-, and 1-bit images, but it would also work with 4-bit.


Sprite drawn to VRAM

#include <fxcg/display.h>
void CopySpriteNbit(const unsigned char* data, int x, int y, int width, int height, color_t* palette, unsigned int bitwidth) {
   color_t* VRAM = (color_t*) GetVRAMAddress();
   VRAM += (LCD_WIDTH_PX*y + x);
   int offset = 0;
   unsigned char buf;
   for(int j=y; j<y+height; j++) {
      int availbits = 0;
      for(int i=x; i<x+width;  i++) {
         if (!availbits) {
            buf = data[offset++];
            availbits = 8;
         color_t this = ((color_t)buf>>(8-bitwidth));
         *VRAM = palette[(color_t)this];
      VRAM += (LCD_WIDTH_PX-width);