User manual
Tutorial: Handel-C and PSL basics
5 Tutorial: Handel-C and VGA graphics output
The Handel-C and VGA graphics tutorial illustrates how to use Handel-C to generate simple VGA
graphics and respond to user input. Three examples are used, each building on the previous one to add
new features.
The
TutorialVGA workspace contains the code for each of the examples. To open the workspace, select
Start>Programs>Celoxica>Platform Developer's Kit>Tutorials>TutorialVGA.
A basic knowledge of Handel-C is assumed, and some knowledge of digital electronics and design
techniques will also be helpful. New users are recommended to work through the examples in order:
•
GraphicsDemo1 project: Generating VGA graphics (see page 63)
•
GraphicsDemo2 project: Responding to user input (see page 65)
•
GraphicsDemo3 project: Adding mouse input (see page 68)
5.1 Generating VGA graphics
The GraphicsDemo1 project in the TutorialVGA workspace (Start>Programs>Celoxica>Platform Developer's
Kit>Tutorials>TutorialVGA on the Start Menu) contains the code for this example. The first step in
generating VGA graphics using DK and Handel-C is to set up a PAL workspace for one or more targets.
This has already been done in the GraphicsDemo1 project for Simulation and RC200, but the procedure is
explained fully in Setting up a PAL workspace (see page 55).
In the main function, a macro is defined which returns the
PalHandle representing the optimal video
mode for the chosen clock rate, and the version of PAL and the resources required are specified:
macro expr VideoOut = PalVideoOutOptimalCT (ClockRate);
PalVersionRequire (1, 0);
PalVideoOutRequire (1);
The next step is to run the video driver in parallel with the code which will generate the graphics to be
displayed, in this case a macro called
RunOutput. Note that the video output must also be enabled. The
ClockRate macro should be defined to return the actual clock rate of the system. In GraphicsDemo1 the
clock rate is
PAL_ACTUAL_CLOCK_RATE.
par
{
PalVideoOutRun (VideoOut, ClockRate);
seq
{
PalVideoOutEnable (VideoOut);
RunOutput (VideoOut);
}
}
In order to display graphics, the
RunOutput macro will need to know what the current VGA scan
position is and have some predefined colours to write to the screen. PAL uses 24-bit RGB colour format,
which is then reduced to the colour depth supported by the target device. To determine the current VGA
scan position, a pointer to the video PalHandle is passed into
RunOutput, and the standard PAL video
macros are used. The code sample below shows the definitions of the colours and two macro
expressions to give quick access to the current VGA scan position.
www.celoxica.com
Page 63