Daily Archives: 6/11/2011

Some more simple test code for the Gameduino

Without explanation or screen dump, here’s a little program I hacked together.

Update: The syntax highlighter I was using is munging this stuff. So, here’s a link to a zip file containing the code.

#include
#include
#include

unsigned char h, m, s, f ;

static PROGMEM prog_uchar pacman_img[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 68, 68, 68, 68, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 68, 68, 68, 68, 68, 68, 68, 68, 0, 0, 0, 0,
0, 0, 0, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 0, 0, 0,
0, 0, 68, 68, 68, 17, 17, 68, 68, 68, 68, 17, 17, 68, 0, 0,
0, 0, 68, 68, 17, 17, 17, 17, 68, 68, 17, 17, 17, 17, 0, 0,
0, 0, 68, 68, 17, 17, 34, 34, 68, 68, 17, 17, 34, 34, 0, 0,
0, 68, 68, 68, 17, 17, 34, 34, 68, 68, 17, 17, 34, 34, 68, 0,
0, 68, 68, 68, 68, 17, 17, 68, 68, 68, 68, 17, 17, 68, 68, 0,
0, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 0,
0, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 0,
0, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 0,
0, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 0,
0, 68, 68, 4, 68, 64, 68, 4, 4, 68, 64, 68, 4, 68, 68, 0,
0, 64, 4, 4, 0, 64, 64, 4, 4, 64, 64, 0, 4, 4, 64, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 85, 85, 85, 85, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 85, 85, 85, 85, 85, 85, 85, 85, 0, 0, 0, 0,
0, 0, 0, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 0, 0, 0,
0, 0, 85, 85, 85, 17, 17, 85, 85, 85, 85, 17, 17, 85, 0, 0,
0, 0, 85, 85, 17, 17, 17, 17, 85, 85, 17, 17, 17, 17, 0, 0,
0, 0, 85, 85, 17, 17, 34, 34, 85, 85, 17, 17, 34, 34, 0, 0,
0, 85, 85, 85, 17, 17, 34, 34, 85, 85, 17, 17, 34, 34, 85, 0,
0, 85, 85, 85, 85, 17, 17, 85, 85, 85, 85, 17, 17, 85, 85, 0,
0, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 0,
0, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 0,
0, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 0,
0, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 0,
0, 85, 85, 5, 85, 80, 85, 5, 5, 85, 80, 85, 5, 85, 85, 0,
0, 80, 5, 5, 0, 80, 80, 5, 5, 80, 80, 0, 5, 5, 80, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 102, 102, 102, 102, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 102, 102, 102, 102, 102, 102, 102, 102, 0, 0, 0, 0,
0, 0, 0, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 0, 0, 0,
0, 0, 102, 102, 102, 17, 17, 102, 102, 102, 102, 17, 17, 102, 0, 0,
0, 0, 102, 102, 17, 17, 17, 17, 102, 102, 17, 17, 17, 17, 0, 0,
0, 0, 102, 102, 17, 17, 34, 34, 102, 102, 17, 17, 34, 34, 0, 0,
0, 102, 102, 102, 17, 17, 34, 34, 102, 102, 17, 17, 34, 34, 102, 0,
0, 102, 102, 102, 102, 17, 17, 102, 102, 102, 102, 17, 17, 102, 102, 0,
0, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 0,
0, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 0,
0, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 0,
0, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 0,
0, 102, 102, 6, 102, 96, 102, 6, 6, 102, 96, 102, 6, 102, 102, 0,
0, 96, 6, 6, 0, 96, 96, 6, 6, 96, 96, 0, 6, 6, 96, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 119, 119, 119, 119, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 119, 119, 119, 119, 119, 119, 119, 119, 0, 0, 0, 0,
0, 0, 0, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 0, 0, 0,
0, 0, 119, 119, 119, 17, 17, 119, 119, 119, 119, 17, 17, 119, 0, 0,
0, 0, 119, 119, 17, 17, 17, 17, 119, 119, 17, 17, 17, 17, 0, 0,
0, 0, 119, 119, 17, 17, 34, 34, 119, 119, 17, 17, 34, 34, 0, 0,
0, 119, 119, 119, 17, 17, 34, 34, 119, 119, 17, 17, 34, 34, 119, 0,
0, 119, 119, 119, 119, 17, 17, 119, 119, 119, 119, 17, 17, 119, 119, 0,
0, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 0,
0, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 0,
0, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 0,
0, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, 0,
0, 119, 119, 7, 119, 112, 119, 7, 7, 119, 112, 119, 7, 119, 119, 0,
0, 112, 7, 7, 0, 112, 112, 7, 7, 112, 112, 0, 7, 7, 112, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

} ;

int px[4] = {0, 0, 0, 0} ;
int vx[4] = { 11, 12, 14, 16 } ;
int cnt = 0 ;

void
setup()
{
int i;

delay(2500) ;
GD.begin() ;

GD.ascii() ;

h = m = s = 0 ;

GD.copy(RAM_SPRIMG, pacman_img, sizeof(pacman_img)) ;
GD.copy(RAM_SPRIMG, pacman_img, sizeof(pacman_img)) ;
GD.wr16(PALETTE16A+0, TRANSPARENT) ;
GD.wr16(PALETTE16A+2, RGB(255,255,255)) ;
GD.wr16(PALETTE16A+4, RGB(0, 0, 64)) ;
GD.wr16(PALETTE16A+14, RGB(255, 0, 0)) ;
GD.wr16(PALETTE16A+12, RGB(0, 192, 192)) ;
GD.wr16(PALETTE16A+10, RGB(255, 128, 128)) ;
GD.wr16(PALETTE16A+8, RGB(255, 160, 0)) ;

GD.fill(RAM_PIC+22*64, 1, 64) ;
GD.wr16(RAM_CHR+16*1+0, 0) ;
GD.wr16(RAM_CHR+16*1+2, 0) ;
GD.wr16(RAM_CHR+16*1+4, 0) ;
GD.wr16(RAM_CHR+16*1+6, 0x4001) ;
GD.wr16(RAM_CHR+16*1+8, 0x4001) ;
GD.wr16(RAM_CHR+16*1+10, 0) ;
GD.wr16(RAM_CHR+16*1+12, 0) ;
GD.wr16(RAM_CHR+16*1+14, 0) ;
GD.wr16(RAM_PAL+8*1+0, TRANSPARENT) ;
GD.wr16(RAM_PAL+8*1+2, RGB(255,255,0)) ;

GD.putstr(15, 17, “It’s time for PacMan!”) ;

for (i=0; i<4; i++)
px[i] = random(-16*16, 400*16) ;

}

void
loop()
{
char timebuf[9] ;
int i ;

for (;;) {
for (i=0; i<4; i++) {
px[i] += vx[i] ;
if (vx[i] >= 400*16)
px[i] -= 401 * 16 ;
}

cnt = cnt + 1 ;
if (cnt >= 16) cnt = 0 ;
f ++ ;
if (f >= 72) {
f = 0 ;
s++ ;
if (s >= 60) {
s = 0 ;
m ++ ;
if (m >= 60) {
m = 0 ;
h++ ;
if (h >= 24) h = 0 ;
}
}
}
GD.waitvblank() ;
for (i=0; i<4; i++)
GD.sprite(i, px[i]/16, 180-8, i, 4+2*(cnt >= 8), 0, 0) ;
sprintf(timebuf, “%02d:%02d:%02d”, h, m, s) ;
GD.putstr(21, 19, timebuf) ;
}
}

Papilio – An Introductory FPGA Kit

My own explorations of FPGA have been, well, slow. Well, let’s be truthful: since buying a BASYS-2 board, I have done little more than ensure that it powers up. But I’m still interested in FPGAs, and so I thought I’d draw attention to a board that I saw for the first time at the Maker Faire: the Papilio. For $50, you can get a cute little board with a 250K gate Xilinx FPGA on board (similar to the Gameduino, but it is an empty slate, upon which any design can be imposed, and it is meant to stand alone, not be chained to an Arduino). Expansion is provided via a series of “wings”: little plugin boards (smaller than the traditional Arduino shields) that include things like a joystick interface and a VGA interface. For around $100, you can get Papilio and a set of wings that can enable you to recreate some of the classic arcade games like PacMan and Frogger.

FPGAs have a bit of a higher learning curve than something as simple as the Arduino, but ultimately much more powerful and flexible. Very cool, and at an attractive price point.

Papilio.