AVGA C Tutorials
1. The simplest example
#include <stdio.h>
// The global AVGA include file.
#include "AVGA/avga.h"
// The header file containing tileset definition for your project.
#include "tileset.h"
// allocate memory spaces for the driver
unsigned char screen[DRIVER_REFTABLE_SIZE];
const unsigned char pgmmap[] PROGMEM = TILESET;
unsigned char rammap[DRIVER_RAMMAP_SIZE];
int main( void )
{
//map memory spaces for video driver
driver_mmap(screen, pgmmap, rammap);
//initialization for PAL signal
video_init(PAL);
//start engine
enable();
//wait a second for TV to get in sync.
wait_seconds(1);
//print a string
driver_print_C(6, 8, "Hello, world!");
//halt so we can see it :)
while (1);
}
2. Bit more complicated: The jumping ball
#include <stdio.h>
// The global AVGA include file.
#include "AVGA/avga.h"
// The header file containing tileset definition for your project.
#include "tileset.h"
// allocate memory spaces for the driver
unsigned char screen[DRIVER_REFTABLE_SIZE];
const unsigned char pgmmap[] PROGMEM = TILESET;
unsigned char rammap[DRIVER_RAMMAP_SIZE];
int main( void )
{
//map memory spaces for video driver
driver_mmap(screen, pgmmap, rammap);
//initialization for PAL signal
video_init(PAL);
//start engine
enable();
//wait a second for TV to get in sync.
wait_seconds(1);
//fill the whole screen with tile number 21
driver_fill(21);
//variables holding ball's position
unsigned int x = (DRIVER_MAXX/2);
unsigned int y = (DRIVER_MAXY/4) << 8;
//variables holding velocity
signed int dx = 1;
signed int dy = 0;
//loop forever
while (1)
{
//clear all previously rendered overlay things
overlay_clear();
//render a ball (source graphics = tile ID 1)
overlay_draw_sprite(x, y>>8, 1);
//integrate velocity
x+=dx;
y+=dy;
//right bump
if(x >= (DRIVER_RESX-DRIVER_BLOCK_WIDTH))
{
x = DRIVER_RESX-DRIVER_BLOCK_WIDTH;
dx=-dx;
}
//left bump
if(x <= 0)
{
x = 0;
dx=-dx;
}
//hit the ground?
if(y > ((DRIVER_RESY-DRIVER_BLOCK_HEIGHT)<<8))
{
y = (DRIVER_RESY-DRIVER_BLOCK_HEIGHT) << 8;
dy=-dy;
}
//integrate earth's acceleration
dy += 10;
//wait for retrace
sync();
}
}