/*
 * "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;
    int counter2 = 100000;
    int counter3 = 10000;
    int flag;
   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(;;){



        int a = IORD_16DIRECT(AUDIOSLAVE_BASE,0);
        if( a < 1500 || a >64035 || (a>32000 && a< 33000))
        {
        	counter2--;
        	//counter3 = 10000;
        	if(counter2==0){
        		if(flag == 1){
        			flag = 0;

                	printf("player shot now at %d \n", yCoordinate);
        		}else{

            		flag = 0;
                    yCoordinate = yCoordinate + 1;
            		counter2 = 100000;
                	printf("player drop now at %d \n", yCoordinate);
        		}
        	}
        }else{
        	counter2 = 100000;
        	counter3--;

        	if(counter3==0){

        		flag = flag + 1;
                yCoordinate = yCoordinate - 1;
        		counter3 = 10000;
        		printf("player fly now at %d\n", yCoordinate);
        		if(flag  > 3){
        			flag = 0;
        		}
        	}
            //printf("%d\n",a);
        }
    }



    return 0;
}
