Module Name | Description | Type | Data Size | Function |
---|---|---|---|---|
cpu_0 | NiosII Processor | N/A | N/A | build processing unit - needed components connected |
sdram_0 | SDRAM Controller | N/A | 16 bits | use SDRAM memory to store values |
wideOut | PIO (Parallel I/O) | Output port | 32 bits | transfer line 1 pixel values - 30 bits used |
wideOut1 | PIO (Parallel I/O) | Output port | 32 bits | transfer line 2 pixel values - 30 bits used |
mouse_xy | PIO (Parallel I/O) | Output port | 32 bits | transfer location of mouse, (x,y) values - 10 bits each |
ball_xy | PIO (Parallel I/O) | Output port | 32 bits | transfer ball location, (x,y) values - 10 bits each |
new_walker
', and initializes the
end points of the lines being drawn and the location of the ball by retrieving those
values from the variables passed in from software (see above table). The first ball is
also drawn.
init
', initializes temporary variables that hold the
pixel value of the point that the line generator needs to draw next. In addition, the
previously drawn ball is erased.
test1
', where the algorithm
determines which line out of the two it is working on and whether that line is finished
drawing.
test1
', to work on the unfinished line. new_walker
', which
completes this iteration of the cycle.test2
'. The ball is also drawn in this state.test2
' state, if the state machine is in sync, and thus lock is on,
the next point of a line is drawn and state machine goes into 'update_walker
'
state. The previously drawn ball will be erased if a line was not drawn in
'test2
' state and the state machine will then loop back to 'test1
'
to try to get back into sync with the lock variable.
update_walker
', it means that a line point
was just written to the VGA and needs to be updated. Knowing the direction of the line,
the code will change the next point to be in the appropriate pixel location and send the
state back into 'test1
' and start this process over again in that state.
addr_reg <= {Coord_X[9:1], Coord_Y[8:0]};
main
' function in the software is in the hello_led.c file. All the
.h
header files and .c
C code files are either in the
software
folder or ISP362
folder. However, the original code
written by Altera is in the hello_led_0
folder. The main file that is worked
with and holds the majority of the code relevant to the game is in the mouse.c
file. In this file and the included files, the USB mouse is connected and activated. A
function inside the PTD.c
file, the function 'send_int
' is
called to continuously poll for any movement or clicking of the mouse. Within this
function, the function, 'move_ball
', that handles the movement and drawing
command of the ball is called. Once the mouse event occurs, the 'send_int
'
function breaks out of a while loop and returns to 'play_mouse
' function. This
is where all the line and ball collision detection, location of mouse, update line end point
variable values, determination of next level or end game, etc. occurs.
BALL DYNAMICSball_h2s
. These right bit values picked
out from this variable, as shown below:
ballxy = IORD(BALL_H2S_BASE, 0);
ballx = ((ballxy << 22) >> 22); // [9:0]
bally = (((ballxy >> 10) << 22) >> 22); // [19:0]
if
statements. The newly computed xy coordinates is compressed into one variable to pass
back the pixel location of the ball into the hardware to be drawn.
cmdball = (ballx) | (bally << 10); // add 6 to offset x_corr
IOWR(BALL_XY_BASE, 0, cmdball);
if(timecnt!=0)
{
X=(rbuf[4]>>8);
Y=(rbuf[5]&0x00FF);
B=(rbuf[4]&0x000F);
}
oX=pX;
oY=pY;
pX=pX+X;
pY=pY+Y;
mouse
function call. Once in the mouse
function, there is a while loop that runs.
However, since another function (play_mouse
) with a do/while loop that
always repeats is called, the mouse
function's while loop only runs once.
Thus, it is the do/while loop in the play_mouse
function that continues
in a constant loop. Or rather, the do/while loop SHOULD continue to run in a constant
loop. The code seems like it was written to trigger the do/while loop when the USB
mouse was moved or clicked. However, after much further investigation, another
function call, send_int
, with a while loop was found within the
play_mouse
. This problem was solved by moving the code that should always
be running in the background into the send_int
function. However, to do
this, all the variables used must be made into global variables. So, when other
functions refer to those variables, they can register that the calculations have been
done and be able to retrieve the values that have been updated.software
folder and open the
hello_led.c
. Build the project.