#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(VGA_BASE, 0, xCoordinate);
        IOWR_VGA_DATA(VGA_BASE, 15, yCoordinate);
    	}
    	int soundByte = IORD(AUDIN_BASE,0);
    	printf("%d",soundByte);
    }


    return 0;
}
