Problem getting PS/2 Mouse cursor to display on VGA with DE2 FPGA

Status
Not open for further replies.

stevenniu927

Newbie level 1
Joined
Mar 29, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,308
Hi everyone.
Im trying to display mouse cursor on a VGA screen.
the LDA memory mapped device is implemented in SOPC and Verilog.
its function is basically drawing a straight line from coordinate LDA_start to LDA_end.
now im trying to load a C program routine to my customized embedded system.
however, the cursor just doesn't seem to work.
the VGA resolution is set to be 320*240.
and when running the program, only the initial point is displayed, but no movement is presented.
Will someone help me out and indicate what might be the potential problems?

#include <stdio.h>
volatile int* LDA_mode = 0x00700000;//stall mode: 0. poll mode: 1.
volatile int* LDA_status = 0x00700004;//used in poll mode.
volatile int* LDA_go = 0x00700008;//signals the LDA peripheral to draw a line on VGA
volatile int* LDA_start = 0x0070000c;//starting coordinate.
volatile int* LDA_end = 0x00700010;//ending coordinate.
volatile int* LDA_colour = 0x00700014;//line color.
volatile int* mouse = 0x10000100;//base address of mouse data register.

void cursor ()
{
char byte1 = 0;
char byte2 = 0;
char byte3 = 0;
int data, r_avail;
*(mouse) = 0xFF;//reset mode.
while(1)
{
data = *(mouse);
r_avail = (data&0xFFFF0000)>>16;
if(r_avail>0)
{
byte1 = byte2;
byte2 = byte3;
byte3 = data&0xFF;
}
if((byte2 == (char)0xAA)&&(byte3 == (char)0x00))
{//Checking if initialization of mouse is completed.
*mouse = 0xE8;//Set resolution
*mouse = 0x00;//resolution: 1 count/mm
*mouse = 0xE6;//Set scaling to 1:1
*mouse = 0xF0;//Set operation mode: remote mode
*mouse = 0xF4;//Enable data reporting
break;
}
}//at this point mouse is ready.
//now plot the initial position of the cursor.
*LDA_start = (120<<9)+160;//set starting point of cursor
*LDA_end = (120<<9)+160;//set ending point of cursor
//since the drawing straight line functionality is not used, so i just set the starting and ending point to the same coordinate. however the line drawing algorithm will be used for other parts of the project
*LDA_colour = 0x07;//cursor color: white
*LDA_go = 0;//draw initial cursor position.
int x = 160;//initial x-coordinate.
int y = 120;//initial y-coordinate.
while(1)
{
*mouse = 0xEB;//read 3 bytes packet
data = *(mouse);
r_avail = (data&0xFFFF0000)>>16;
while (r_avail>0)
{
byte1 = byte2;//State byte
byte2 = byte3;//X-Movement
byte3 = data&0xFF;//Y-Movement
data = *(mouse);
r_avail = (data&0xFFFF0000)>>16;
}
y = y+(((((int)(byte1&0x20))<<26)>>23)|byte3);//updated y-position.
if(y>239) y = 239;
else if(y<0) y = 0;
x = x+(((((int)(byte1&0x10))<<27)>>23)|byte2);//updated x-position.
if(x>319) x = 319;
else if(x<0) x = 0;
*LDA_start = (y<<9)+x;
*LDA_end = (y<<9)+x;
*LDA_colour = 0x07;
*LDA_go = 0;//draw cursor point.
int count;
for(count = 0;count<250;count++);//delay
}
}

void clear()//this function clears the screen.
{
int x_start = 0;
int x_end = 319;
int y;
int i = 0;
for(y = 0; y<=319; y++)
{
*LDA_start = (y<<9)+x_start;
*LDA_end = (y<<9)+x_end;
*LDA_colour = 0x00;
*LDA_go = 0;
}
}

int main ()
{
int mode = 0x00;
*LDA_mode = mode;
clear();
cursor();
return 0;
}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…