website statistics

The GD library

The GD library (download) is a set of routines that make it easier to control the Gameduino.

The GD library is a very thin layer between your code and the hardware.

While it is possible to control the Gameduino using the Arduino SPI library, the samples use the GD library to do some common operations. For example, “hello world” using GD:

#include <SPI.h>
#include <GD.h>

void setup()

  // Load the standard ascii font

  GD.putstr(0, 0, "Hello world");

void loop()
bool GD::begin()

Initialize the connection to the adapter, and reset the adapter.

byte GD::rd(unsigned int addr)

Read a byte from memory location addr

void GD::wr(unsigned int addr, byte v)

Write byte v to memory location addr.

unsigned int GD::rd16(unsigned int addr)

Read a 16-bit word from memory locations addr and addr+1

void GD::wr16(unsigned int addr, unsigned int v)

Write 16-bit word v to memory locations addr and addr+1

void GD::fill(int addr, byte v, unsigned int count)

Fill count memory locations starting at addr with value v

void GD::copy(unsigned int addr, prog_uchar* src, int count)

Copy count bytes from AVR flash memory location src to addr. See also Use PROGMEM for graphics data.

void GD::setpal(int pal, unsigned int rgb)

Set character palette entry pal to color rgb. See also RGB() for rgb encoding.

void GD::sprite(int spr, int x, int y, byte image, byte palette, byte rot=0, byte jk=0)

Set attributes of sprite spr

  • spr – sprite number, 0-255
  • x – x coordinate, 0-511. 0 is left edge of screen.
  • y – y coordinate, 0-511. 0 is top edge of screen.
  • image – image number, 0-63
  • palette – palette control 0-15
  • rot – rotate/flip control 0-7
  • jk – J/K collision select, 0-1

For details on these attributes, see the reference poster or Sprite graphics.

void GD::sprite2x2(int spr, int x, int y, byte image, byte palette, byte rot=0, byte jk=0)

Set attributes of four sprites in a 2x2 configuration. (x,y) specifies the center of the group. Other arguments are as for GD::sprite().

void GD::waitvblank()

Waits for the start of the vertical blanking period. By waiting for vertical blanking:

  • any animation is guaranteed to be smooth
  • the sprite collision RAM is valid
void GD::microcode(prog_uchar* src, int count)

Copy count bytes from AVR flash memory location src into the coprocessor’s instruction RAM, and restart the coprocessor. The use of the coprocessor is described in Coprocessor.

void GD::ascii()

Load a standard 8x8 ASCII font into character RAM. This is useful for debugging and status display.

void GD::putstr(int x, int y, const char* s)

Draw string s at character screen position (x,y). Assumes that a standard character set has been loaded, e.g. by GD::ascii().

void GD::voice(int v, byte wave, unsigned int freq, byte lamp, byte ramp)

Set audio voice waveform, frequency and amplitude

  • voice – hardware voice number, 0-63
  • wave – waveform, 0 is sine wave, 1 is noise
  • freq – frequency in quarter-Hz, e.g. 100 Hz is 400
  • lamp – left amplitude, 0-255
  • ramp – right amplitude, 0-255

The 64 audio voices are summed for final output. So to guarantee no audio clipping, the sum of all voices’ amplitudes should be 255 or less.

unsigned int RGB(byte r, byte g, byte b)

Return the 15-bit encoding of an RGB color. r, g and b are 0-255.

Last modified $Date: 2011-07-31 15:23:57 -0700 (Sun, 31 Jul 2011) $