User manual
Tutorial: Handel-C and PSL basics
To run the example yourself, open the TutorialVGA workspace (Start>Programs>Celoxica>Platform
Developer's Kit
>Tutorials>TutorialVGA on the Start Menu), set GraphicsDemo1 as the active project, set the
Active Configuration to Sim, then build and run the project. For a Celoxica RC200 board with a VGA
monitor connected, set the Active Configuration to RC200, rebuild, then use the Place and Route tools
to generate a bitfile to download to the board.
5.2 Responding to user input
The GraphicsDemo2 project in the TutorialVGA workspace (Start>Programs>Celoxica>Platform Developer's
Kit
>Tutorials>TutorialVGA on the Start Menu) contains the code for this example. This example takes the
GraphicsDemo1, which drew a white grid on the screen, and adds a red box, drawn underneath the white
grid. The size of the box can be varied using the switches in the PalSim Virtual Platform and on the
Celoxica RC200 board.
To enable the use of switches for user input, they should be required at the start of the program, at the
same time as requesting video output and PAL version. In this case a minimum of two switches are
requested, as shown below. Switches do not require a Run macro (like the video output does), as they
are simple devices and can be accessed directly.
PalVersionRequire (1, 0);
PalVideoOutRequire (1);
PalSwitchRequire (2);
The
RunOutput macro must first be modified to draw a box as well as the white grid, so some additional
macros are defined to help in this task, as shown below.
MaxX and MaxY return the maximum number of
pixels visible,
XWidth and YWidth return the bit width required to hold the X and Y VGA scan variables,
and
XPos and YPos are used to mark the center of the box which will be displayed.
macro expr MaxX = PalVideoOutGetVisibleXCT (VideoOut, ClockRate);
macro expr MaxY = PalVideoOutGetVisibleYCT (VideoOut);
macro expr XWidth = PalVideoOutGetXWidthCT (VideoOut);
macro expr YWidth = PalVideoOutGetYWidthCT (VideoOut);
macro expr XPos = MaxX/2;
macro expr YPos = MaxY/2;
As the size of the box to be drawn will be changed according to user input, it needs to be a variable with
an initial value assigned:
static unsigned YWidth BoxSize = 20;
To actually draw the box, the display output code must be changed to detect when the VGA scan
position is within the box region:
while (1)
{
if ((ScanY <- 5 == 0) || (ScanX <- 5 == 0))
PalVideoOutWrite (VideoOut, White);
else if((ScanX > (Xpos - BoxSize)) && (ScanX < (Xpos + BoxSize)) &&
(ScanY > (YPos - BoxSize)) && (ScanY < (YPos + BoxSize)))
PalVideoOutWrite (VideoOut, Red);
else
PalVideoOutWrite (VideoOut, Black);
}
In parallel with the
while(1) loop running the display output, there must be another while(1) loop
which reads the switches and modifies the box size to account for any user input detected. The size of
the box should be limited so that it does not go below zero, and does not go above the maximum visible
www.celoxica.com
Page 65