User manual
Tutorial: Handel-C and PSL basics
5.3 Adding mouse input
The GraphicsDemo3 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 extends
the
GraphicsDemo2, by allowing the red box drawn on the screen to be moved around using a mouse and
changing the colour of the box when the mouse buttons are pressed.
To use the mouse under PAL, the
pal_mouse.hch header must be included and the pal_mouse.hcl
library added to the linker settings for both
Sim and RC200 targets. A pointer of type PalMouse must be
created, and a PS2 port will be required to connect the mouse to. It is also useful to create a macro
expression to provide quick access to the PS2 port, as shown in the code below:
macro expr PS2 = PalPS2PortCT (0);
PalMouse *MousePtr;
PalPS2PortRequire (1);
The mouse driver must be run and enabled in parallel with the video driver and the
RunOutput macro,
the limits on the cursor position should be set and wrapping (what happens to the cursor at the edge of
the screen) turned off, as show below.
MaxX and MaxY are macro expressions returning the number of
visible pixels.
par
{
PalVideoOutRun (VideoOut, ClockRate);
PalMouseRun (&MousePtr, PS2, ClockRate);
seq
{
par
{
PalVideoOutEnable (VideoOut);
PalMouseEnable (MousePtr);
}
par
{
PalMouseSetMaxX (MousePtr, MaxX);
PalMouseSetMaxY (MousePtr, MaxY);
PalMouseSetWrap (MousePtr, 0);
}
RunOutput (VideoOut, MousePtr, ClockRate);
}
}
The final code to add for this example takes the mouse input and uses it to control the position and
colour of the box displayed on the VGA output. This code is in the
RunOutput macro, running in parallel
with the code reading the switches and updating the box size. The mouse coordinates are copied into
the box position every cycle, if the left mouse button is pressed the 24 bit box colour is incremented, and
if the right mouse button is pressed, the colour is reset to red. Two new macro expressions,
MouseX and
MouseY are created to provide easy access to the current mouse coordinates, and their use can be
seen in the code below:
www.celoxica.com
Page 68