/*
 * "Hello World" example.
 *
 * This example prints 'Hello from Nios II' to the STDOUT stream. It runs on
 * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example
 * designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT
 * device in your system's hardware.
 * The memory footprint of this hosted application is ~69 kbytes by default
 * using the standard reference design.
 *
 * For a reduced footprint version of this template, and an explanation of how
 * to reduce the memory footprint for a given application, see the
 * "small_hello_world" template.
 *
 */
#include <io.h>
#include <system.h>
#include <stdio.h>

#define IOWR_VGA_DATA(base, offset, data) \
  IOWR_16DIRECT(base, (offset) * 2, data)



int main()
{

    int xCoordinate;
    int yCoordinate;
    int xSpeed;
    int ySpeed;
    int xLowBound;
    int xHighBound;
    int yLowBound;
    int yHighBound;
    int radius;
    int counter=10000;

   printf("software 111works \n");

    //IOWR_VGA_SPEED(VGA_BASE, 0x0040);

    xCoordinate = 200;
    yCoordinate = 240;
    xSpeed = 2;
    ySpeed = 2;
    xLowBound = 0;
    xHighBound = 640;
    yLowBound = 0;
    yHighBound = 480;
    radius = 8;


    for(;;){
    	counter--;
    	if (counter ==0)
    	{
    		counter=10000;

        if(xCoordinate - xLowBound <= radius){
            ySpeed = - ySpeed;
        }
        if(xHighBound - xCoordinate <= radius){
            ySpeed = - ySpeed;
        }
        if(yCoordinate - yLowBound <= radius){
            xSpeed = - xSpeed;
        }
        if(yHighBound - yCoordinate <= radius){
            xSpeed = - xSpeed;
        }

        xCoordinate = xCoordinate + ySpeed;
        yCoordinate = yCoordinate + xSpeed;

        //IOWR_VGA_DATA(RASTER_BASE, 0, xCoordinate);


    	}
        int a = IORD_16DIRECT(AUDIOSLAVE_BASE, 0);
        printf("%d\n",a);
    }


    return 0;
}
