#include <io.h>
#include <system.h>
#include <stdio.h>
#include <stddef.h>

#define win_delay1 25000
#define win_delay2 80000
#define lose_delay1 3
#define lose_delay2 25000
#define lose_delay3 80000



  
 #define IOWR_VGA_DATA(base, offset, data) \
  IOWR_16DIRECT(base, (offset) * 2, data)  
  
  #define IORD_IRCOMP_INST_DATA(base, offset) \
  IORD_16DIRECT(base, (offset) * 2)
  
  #define IOWR_SRAM(base, offset, data) \
  IOWR_16DIRECT(base, (offset) * 2, data)   
#define IOWR_DE2_WM8731_AUDIO_INST_DATA(base, offset, data) \
  IOWR_16DIRECT(base, (offset) * 2, data)  
  

  int i;
  int j;
  int q ;
  int m,pa,v;
  int aaa = 0; // control siganl of aaaa voice
  int aaa_flag=0;
  //int aa[7];
  int aa_mark1=0;
  int aa_mark2=0;
  int yun_sound1=0;
  int yun_sound2=0;
  
  int i,j,h,k,t,cx;
  int h=290;
  int v=380;
  float sh=1;
  float sv=1;
  int c0=0; int c1=0;int c2=0;int c3=0;int c4=0;int c5=0;int c6=0;int c7=0;
  int a=0;
  int hb=0;
  int vb=0;
  int key;
  int hy=300;
  int vy=200;
  unsigned char code;
  
  float ball_v;
  float ball_h;
  float up_v,up_h,down_v,down_h,left_v,left_h,right_v,right_h;
  int y_mid;
  int count=60;
  //y_mid=hy+29;
  
  int life=4;
  int final_score=0;
  int yun_count=0;  //number of yun that have been hit
  int hit_count=0;  //number that board has bounced
  //int 
  
  int lose_flag=0;
  int win_flag=0;
  
  int slow_speed=350;
  int fast_speed=500;
  
  int easy=1;
  int hard=0;
  
  int lifeball_v;
  int lifeball_h;
  int lv;
  int lh;
  
  float llh=640;//lose life
  float llv=-480;
  float ll_h=0.01;
  float ll_v=0.01;
  int ll_flag=0;
  
  float speedh=320;
  float speedv=240;
  float speed_h;
  float speed_v;
  int speed_flag=0;
  int speed_count=0;
  
  int bak[16][12] ={
    
    {0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,1,1,1,1,1,1,0,0,0},
    {0,0,0,1,1,1,1,1,1,0,0,0},
    {0,0,0,1,1,1,1,1,1,0,0,0},
    {0,0,0,1,1,1,1,1,1,0,0,0},
    {0,0,0,1,1,1,1,1,1,0,0,0},
    {0,0,0,1,1,1,1,1,1,0,0,0},
    {0,0,0,1,1,1,1,1,1,0,0,0},
    {0,0,0,1,1,1,1,1,1,0,0,0},
    {0,0,0,1,1,1,1,1,1,0,0,0},
    {0,0,0,1,1,1,1,1,1,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0}
  
  };

  #define IOWR_SRAM(base, offset, data) \
  IOWR_16DIRECT(base, (offset) * 2, data)   
#define IOWR_DE2_WM8731_AUDIO_INST_DATA(base, offset, data) \
  IOWR_16DIRECT(base, (offset) * 2, data)  
  
static void irqhandler_rot (void * context, alt_u32 id)
{
    
    if (IORD_16DIRECT (IRCOMP_INST_BASE,0) == 2 && hy<555) {hy=hy+25;}  
    else if ( IORD_16DIRECT (IRCOMP_INST_BASE,0)  == 3 && hy>20) {hy=hy-25;}
    IOWR_16DIRECT(IRCOMP_INST_BASE, 0, 0);  // reset the interrupt request
    for (i=0; i<3000; i++){}  // introduce delay to avoid multi-interruput per rotation
}

static void irqhandler_rot2 (void * context, alt_u32 id)
{
    
    if (IORD_16DIRECT (IRCOMP2_INST_BASE,0) == 2 && vy<395) {vy=vy+25;}  
    else if ( IORD_16DIRECT (IRCOMP2_INST_BASE,0)  == 3 && vy>25) {vy=vy-25;}
    IOWR_16DIRECT(IRCOMP2_INST_BASE, 0, 0);  // reset the interrupt request
    for (i=0; i<3000; i++){}  // introduce delay to avoid multi-interruput per rotation
}

int qa,ma,ra,sa;

  
static void irqhandler_audio (void * context, alt_u32 id)
{ 

   if(aaa==0 && yun_sound1==0 && yun_sound2==0)
(qa !=1000)
   {
       for (i=0;i<32;i++)
      { 
        ma = music[i+qa*32];
        IOWR_DE2_WM8731_AUDIO_INST_DATA(DE2_WM8731_AUDIO_INST_BASE, i, ma) ;

      }
 
      if (qa< 2626)
        qa=qa+1;
      else
        qa=0;
    
  }
  
  else if(aaa)
  {        //aaaa 
    for (i=0;i<32;i++)
    {
        ma = music[84084+i+pa*32];
        IOWR_DE2_WM8731_AUDIO_INST_DATA(DE2_WM8731_AUDIO_INST_BASE, i, ma) ;
    }   
        if (aaa>1)
        {
            aaa--;
            pa=0;
            //i=0;
        }
        else if (yun_sound1==1 || yun_sound2==1)
        {
            //i=32;
            aaa--;
        }
       
    
    if(pa<252)  pa = pa+1;  //max = 169
    else {
            pa = 0;
            aaa = 0;
          }
    } 
    
  else if (aaa==0 && yun_sound1==1) //aaaa 
  {
    for (i=0;i<32;i++)
    {
        ma = music[84084+8095+i+ra*32];
        IOWR_DE2_WM8731_AUDIO_INST_DATA(DE2_WM8731_AUDIO_INST_BASE, i, ma) ;
        
    }
   
    if(ra<98)  ra = ra+1;  //max = 169
    else {
            ra = 0;
            yun_sound1 = 0;
            //qa = 1001;
          }
  } 
    
  else if (aaa==0 && yun_sound2==1) //aaaa 
  {
    for (i=0;i<32;i++)
    {
        ma = music[84084+8095+3143+i+sa*32];
        IOWR_DE2_WM8731_AUDIO_INST_DATA(DE2_WM8731_AUDIO_INST_BASE, i, ma) ;
        
    }
   
    if(sa<119)  sa = sa+1;  //max = 169
    else {
            sa = 0;
            yun_sound2 = 0;
            //qa = 1001;
          }
  } 
}





static void irqhandler (void * context, alt_u32 id)
{
    
    

//  printf ("interrupt occurred\n");
  IOWR_VGA_DATA(VGA_BASE, 5, h);
  IOWR_VGA_DATA(VGA_BASE, 6, v);
  IOWR_VGA_DATA(VGA_BASE, 7, hy);
 // IOWR_16DIRECT(VGA_BASE, 0, 0);  // reset the interrupt request
}


int main()
{  
      
 
  alt_irq_register( IRCOMP_INST_IRQ, NULL,(void*)irqhandler_rot );
  alt_irq_register( IRCOMP2_INST_IRQ, NULL,(void*)irqhandler_rot2 );
   
  alt_irq_register (VGA_IRQ, NULL, irqhandler );
  
   alt_irq_register (DE2_WM8731_AUDIO_INST_IRQ, NULL, irqhandler_audio );
  
 
  for (;;)
  { 
    IOWR_VGA_DATA(VGA_BASE, 9, vy);
    IOWR_VGA_DATA(VGA_BASE, 2, 89);
    IOWR_VGA_DATA(VGA_BASE, 3, 78);
    IOWR_VGA_DATA(VGA_BASE, 16, life);

  up_v=v;
  up_h=h+7.5;
  
  down_v=v+15;
  down_h=h+7.5;
  
  left_v=v+7.5;
  left_h=h;
  
  right_v=v+7.5;
  right_h=h+15;
  
  ball_v=v+7.5;
  ball_h=h+7.5; 
  hb=ball_h/40;
  vb=ball_v/40;
  
  
  
  
  if (sh<0 && sv<0 && ball_h>hb*40+30-3 && ball_h<hb*40+40 
            && ball_v>=vb*40+35-3 && ball_v<vb*40+40+3 && bak[hb][vb]==1)
  {
        a=0x1000;
        c4=a+vb+16*hb;
        sh=1;
        sv=1;
        bak[hb][vb]=0;
          count--;
          yun_count++;
          aaa++;
        
  else if (sh<0 && sv>0 && ball_h>=hb*40+30-3 && ball_h<hb*40+40 
           && ball_v>=vb*40+30-3 && ball_v<vb*40+40+3 && bak[hb][vb+1]==1)  
  {
        a=0x1000;
        c5=a+vb+1+16*hb;
        sh=1;
        sv=-1;
        bak[hb][vb+1]=0;
          count--;
          yun_count++;
          aaa++;
   
  }
  //left & bottom corner
  else if (sh>0 && sv<0 && ball_h>=hb*40+30-3 && ball_h<hb*40+35+3 
            && ball_v>=vb*40+35-3 && ball_v<vb*40+37.5+3 && bak[hb+1][vb]==1)
  {
        a=0x1000;
        c6=a+vb+16*(hb+1);
        sh=-1;
        sv=1;
        bak[hb+1][vb]=0;
          count--;
          yun_count++;
          aaa++;
          
  }
  
  else if (sh>0 && sv>0 && ball_h>=hb*40+30-3 && ball_h<hb*40+35+3 
           && ball_v>=vb*40+30-3 && ball_v<vb*40+35+3 && bak[hb+1][vb+1]==1)
  {
        a=0x1000;
        c7=a+vb+1+16*(hb+1);
        sh=-1;
        sv=-1;
        bak[hb+1][vb+1]=0;
          count--;
          yun_count++;
          aaa++;
   
  }
  
  //top edge
 else if (((sh>=0 && sv>0)||(sh<=0 && sv>0)) && ball_v==(vb*40+32.5)
    //down_v>=((vb+1)*40) && down_v<=((vb+1)*40+5) 
        //&& down_h>(hb*40-5) && down_h<(hb*40+35) && bak[hb][vb+1]==1)
        && ball_h>=(hb*40-5) && ball_h<=(hb*40+30+5) && bak[hb][vb+1]==1)
//  if (ball_h==hb*40 && ball_v>vb*40 && ball_v<(vb+1)*40 && bak[hb][vb]==1)
  {

          a=0x1000;
          c0=a+vb+1+16*hb;
          sv=-sv;
          bak[hb][vb+1]=0;
          count--;
          yun_count++;
          aaa++;
    
  }
  //bottom edge
  else if (((sh>=0 && sv<0)||(sh<=0 && sv<0)) && ball_v==vb*40+37.5
            //up_v>=((vb*40)-20) && up_v<=((vb*40)-7) 
            //&& up_h>(hb*40-5) && up_h<(hb*40+35) && bak[hb][vb-1]==1
            && ball_h>=(hb*40-5) && ball_h<=(hb*40+30+5) && bak[hb][vb]==1)
  {
            a=0x1000;
          c1=a+vb+16*hb;
          sv=-sv;
          bak[hb][vb]=0;
          count--;
          yun_count++;
          aaa++;
  
  }
  //left edge
  else if (((sh>0 && sv>=0)||(sh>0 && sv<=0)) && ball_h==(hb*40+32.5)
            //right_h<=(hb*40+45) && right_h>=(hb*40+40) 
            //&& right_v>(vb*40-5) && right_v<(vb*40+30+5) 
            && ball_v>=(vb*40-3) && ball_v<=(vb*40+30+3)
            && bak[hb+1][vb]==1)
  {
            a=0x1000;
          c2=a+vb+16*(hb+1);
          sh=-sh;
          bak[hb+1][vb]=0;
          count--;
          yun_count++;
          aaa++;
          //aa[6]=1;
          //printf("count is %d\n",count);
         // printf("yun_count is %d\n",yun_count);
//         for (i=0; i<300; i++)
//         {
//            IOWR_VGA_DATA(VGA_BASE, 8, c2); 
//         }
  }
  // right edge 
  else if (((sh<0 && sv>0)||(sh<0 && sv<0)) && ball_h==(hb*40+37.5)
        //left_h<=(hb*40) && left_h>=((hb*40)-15) 
            //&& left_v>(vb*40-5) && left_v<(vb*40+35)
            && ball_v>=(vb*40-5) && ball_v<=(vb*40+30+5) && bak[hb][vb]==1 ) 
  {
            a=0x1000;
          c3=a+vb+16*hb;
          sh=-sh;
          bak[hb][vb]=0;
          count--;
          yun_count++;
          aaa++;
          //aa[7]=1;
          //printf("count is %d\n",count);
         // printf("yun_count is %d\n",yun_count);
//         for (i=0; i<300; i++)
//         {
//            IOWR_VGA_DATA(VGA_BASE, 8, c3); 
//         }
  }
    if (easy==1)
   {
          for (i=0; i<slow_speed; i++)
      {
        IOWR_VGA_DATA(VGA_BASE, 8, c0); 
        IOWR_VGA_DATA(VGA_BASE, 8, c1); 
        IOWR_VGA_DATA(VGA_BASE, 8, c2); 
        IOWR_VGA_DATA(VGA_BASE, 8, c3); 
        IOWR_VGA_DATA(VGA_BASE, 8, c4); 
        IOWR_VGA_DATA(VGA_BASE, 8, c5); 
        IOWR_VGA_DATA(VGA_BASE, 8, c6); 
        IOWR_VGA_DATA(VGA_BASE, 8, c7);  
      }
   }
   else if (hard==1)
   {
          for (i=0; i<fast_speed; i++)
      {
        IOWR_VGA_DATA(VGA_BASE, 8, c0); 
        IOWR_VGA_DATA(VGA_BASE, 8, c1); 
        IOWR_VGA_DATA(VGA_BASE, 8, c2); 
        IOWR_VGA_DATA(VGA_BASE, 8, c3); 
        IOWR_VGA_DATA(VGA_BASE, 8, c4); 
        IOWR_VGA_DATA(VGA_BASE, 8, c5); 
        IOWR_VGA_DATA(VGA_BASE, 8, c6); 
        IOWR_VGA_DATA(VGA_BASE, 8, c7);  
      }
   }
   
//  for (i=0; i<3000; i++)
//  {
//  }
  
//  if (ball_v>49 && ball_v<79 && ball_h>49 && ball_h<79 && !(sh>0 && sv>0))
//  {
//    if (hit_count%2==0)
//    {
//        h=550;
//        v=49;
//        sh=-1;
//        sv=1;
//    }
//    else
//    {
//        h=420;
//        v=320;
//        sh=-1;
//        sv=1;
//    }
//  }
//  else if (ball_v>49 && ball_v<79 && ball_h>550 && ball_h<580 && !(sh<0 &&sv>0))
//  {
//    if (hit_count%2==0)
//    {
//        h=49;
//        v=49;
//        sh=1;
//        sv=1;
//    }
//    else
//    {
//        h=420;
//        v=320;
//        sh=-1;
//        sv=1;
//    }
//  }
//  else if (ball_v>320 && ball_v<350 && ball_h>420 && ball_h<450 && !(sh<0&&sv>0))
//  {
//    if (hit_count%2==0)
//    {
//        h=49;
//        v=49;
//        sh=1;
//        sv=1;
//    }
//    else
//    {
//        h=550;
//        v=49;
//        sh=-1;
//        sv=1;
//    }
//  }
  
  
  if (hit_count%15==0 && ll_flag==0)
  {
     llh=320;
     llv=240;
     ll_h=sh;
     ll_v=sv;
     ll_flag=1;
    //IOWR_VGA_DATA(VGA_BASE, 2, ll_h);
    //IOWR_VGA_DATA(VGA_BASE, 3, ll_v);
  }
  
  if (ll_flag==1)
  {
      //if ((llv+22)>=440 && (llv+22)<460 && (llh+7.5)>=(hy-2) && (llh+7.5)<=(hy+60))
      if ((llv+22)==442 && (llh+7.5)>=(hy-2) && (llh+7.5)<=(hy+60))
      {
        llh=640;
        llv=480;
        life--;
        ll_flag=0;
      }
      //else if (llv>=18 && llv<=38 && (llh+7.5)>=(hy-2) && (llh+7.5)<=(hy+60))
      else if (llv==38 && (llh+7.5)>=(hy-2) && (llh+7.5)<=(hy+60))
      {
        llh=640;
        llv=480;
        life--;
        ll_flag=0;
      }
      //else if (llh>=18 && llh<=38 && (llv+11)>=(vy-2) && (llv+11)<=(vy+60))
      else if (llh==38 && (llv+11)>=(vy-2) && (llv+11)<=(vy+60))
      {
        llh=640;
        llv=480;
        life--;
        ll_flag=0;
      }
      //else if ((llh+15)>=602 && (llh+15)<=622 && (llv+11)>=(vy-2) && (llv+11)<=(vy+60))
      else if ((llh+15)==602 && (llv+11)>=(vy-2) && (llv+11)<=(vy+60))
      {
        llh=640;
        llv=480;
        life--;
        ll_flag=0;
      }
      else if (llh>480 || llh<0 || llv>640 || llv<0)
      {
        llh=640;
        llv=480;
        ll_flag=0;
      }
      else
      {
        llh+=ll_h;
        llv+=ll_v;
      }
      //IOWR_VGA_DATA(VGA_BASE, 2, ll_h);
      //IOWR_VGA_DATA(VGA_BASE, 3, ll_v);
      //printf("life is %d\n",life);
  }
  
     if (h<=0)
     {
        for (i=0;i<2000;i++)
        {
            h=90;
            v=200;
        }
        h=90;
        v=200;
        sh=-1;
        sv=1;
        life--;
        //sh=1;
     } 
     if (h>=624)
     {
        for (i=0;i<2000;i++)
        {
            h=550;
            v=200;
        }
        h=550;
        v=200;
        sh=1;
        sv=1;
        life--;
        //sh=-1;
     } 
      
     if (v>=464)  
     {
        for (i=0;i<2000;i++)
        {
            h=290;
            v=380;
        }
        h=290;
        v=380;
        sh=1;
        sv=1;
        life--;
        //  sv=-1;
     }
     
     if (v<=0)  
     {
        for (i=0;i<2000;i++)
        {
            h=290;
            v=80;
        }
        h=290;
        v=80;
        sh=-1;
        sv=-1;
        life--;
         // sv=1;
     }
     

    //bottom board
     if (down_v>=440 && down_v <460 && down_h>=(hy-2) && down_h<=(hy+60))
     {
//        for (h=0;h<50;h++)
//        {
//            IOWR_VGA_DATA(VGA_BASE, 1, 1);
//        }
        hit_count++;
        //printf("hit_count is %d\n",hit_count);
        if (sh>0 && sv>0)
        {
            
            if (hy+29>down_h)
            {
                sh=-sh;
                sv=-sv;
                int tmp=hy+29-down_h;
                if (tmp>=20 && sh<=3 && sv<=3)
                {
                    sh*=1.6;
                    sv*=1.6;
                }
                else if (tmp>=9 && tmp<20 && sh<=3 && sv<=3)
                {
                    sh*=1.3;
                    sv*=1.3;
                }
                
            }
            else
            {
                sv=-sv;
                int tmp=down_h-hy-29;
                if (tmp>=20 && sh<=3 && sv<=3)
                {
                    sh*=1.6;
                    sv*=1.6;
                }
                else if (tmp>=9 && tmp<20 && sh<=3 && sv<=3)
                {
                    sh*=1.3;
                    sv*=1.3;
                }
            }
        }
        else if (sh<0 && sv>0)
        {
            if (hy+29>=down_h)
            {
                sv=-sv;
                int tmp=hy+29-down_h;
                if (tmp>=20 && sh<=3 && sv<=3)
                {
                    sh*=1.6;
                    sv*=1.6;
                }
                else if (tmp>=9 && tmp<20 && sh<=3 && sv<=3)
                {
                    sh*=1.3;
                    sv*=1.3;
                }
                
            }
            else
            {
                sv=-sv;
                sh=-sh;
                int tmp=down_h-hy-29;
                if (tmp>=20 && sh<=3 && sv<=3)
                {
                    sh*=1.6;
                    sv*=1.6;
                }
                else if (tmp>=9 && tmp<20 && sh<=3 && sv<=3)
                {
                    sh*=1.3;
                    sv*=1.3;
                }
            }
        }
        yun_sound1=1;
        //for (k=0;k<5000;k++)
        //IOWR_VGA_DATA(VGA_BASE, 12, 1);
     }


    //top board
    if (up_v>=18 && up_v <=38 && up_h>=(hy-2) && up_h<=(hy+60))
     {
//        for (h=0;h<50;h++)
//        {
//            IOWR_VGA_DATA(VGA_BASE, 1, 2);
//        }
        hit_count++;
        //printf("hit_count is %d\n",hit_count);
        if (sh>0 && sv<0)
        {
            if (hy+29>up_h)
            {
                sh=-sh;
                sv=-sv;
                int tmp=hy+29-up_h;
                if (tmp>=20 && sh<=3 && sv<=3)
                {
                    sh*=1.6;
                    sv*=1.6;
                }
                else if (tmp>=9 && tmp<20 && sh<=3 && sv<=3)
                {
                    sh*=1.3;
                    sv*=1.3;
                }
                
            }
            else
            {
                sv=-sv;
                int tmp=up_h-hy-29;
                if (tmp>=20 && sh<=3 && sv<=3)
                {
                    sh*=1.6;
                    sv*=1.6;
                }
                else if (tmp>=9 && tmp<20 && sh<=3 && sv<=3)
                {
                    sh*=1.3;
                    sv*=1.3;
                }
            }
        }
        else if (sh<0 && sv<0)
        {
            if (hy+29>=up_h)
            {
                sv=-sv;
                int tmp=hy+29-up_h;
                if (tmp>=20 && sh<=3 && sv<=3)
                {
                    sh*=1.6;
                    sv*=1.6;
                }
                else if (tmp>=9 && tmp<20 && sh<=3 && sv<=3)
                {
                    sh*=1.3;
                    sv*=1.3;
                }
                
            }
            else
            {
                sv=-sv;
                sh=-sh;
                int tmp=up_h-hy-29;
                if (tmp>=20 && sh<=3 && sv<=3)
                {
                    sh*=1.6;
                    sv*=1.6;
                }
                else if (tmp>=9 && tmp<20 && sh<=3 && sv<=3)
                {
                    sh*=1.3;
                    sv*=1.3;
                }
            }
        }
        yun_sound1=1;
     }

    //left board
    if (left_h>=18 && left_h<=38 && left_v>=(vy-2) && left_v<=(vy+60))
     {
//        for (h=0;h<50;h++)
//        {
//           IOWR_VGA_DATA(VGA_BASE, 1, 8);
//        }
        hit_count++;
        //printf("hit_count is %d\n",hit_count);
        if (sh<0 && sv<0)
        {
            if (vy+29<left_v)
            {
                sh=-sh;
                sv=-sv;
                int tmp=left_v-vy-29;
                if (tmp>=20 && sh<=3 && sv<=3)
                {
                    sh*=1.4;
                    sv*=1.4;
                }
                else if (tmp>=9 && tmp<20 && sh<=3 && sv<=3)
                {
                    sh*=1.2;
                    sv*=1.2;
                }
                
            }
            else
            {
                sh=-sh;
                int tmp=left_v-vy-29;
                if (tmp>=20 && sh<=3 && sv<=3)
                {
                    sh*=1.4;
                    sv*=1.4;
                }
                else if (tmp>=9 && tmp<20 && sh<=3 && sv<=3)
                {
                    sh*=1.2;
                    sv*=1.2;
                }
            }
        }
        else if (sh<0 && sv>0)
        {
            if (vy+29<=left_v)
            {
                sh=-sh;
                int tmp=left_v-vy-29;
                if (tmp>=20 && sh<=3 && sv<=3)
                {
                    sh*=1.4;
                    sv*=1.4;
                }
                else if (tmp>=9 && tmp<20 && sh<=3 && sv<=3)
                {
                    sh*=1.2;
                    sv*=1.2;
                }
                
            }
            else
            {
                sv=-sv;
                sh=-sh;
                int tmp=left_v-vy-29;
                if (tmp>=20 && sh<=3 && sv<=3)
                {
                    sh*=1.4;
                    sv*=1.4;
                }
                else if (tmp>=9 && tmp<20 && sh<=3 && sv<=3)
                {
                    //sh*=1  IOWR_VGA_DATA(VGA_BASE, 2, llh);
  //IOWR_VGA_DATA(VGA_BASE, 3, llv);.2;
                    sv*=1.2;
                }
            }
        }
        yun_sound2=1;
     }

  
    //right board
    if (right_h>=602 && right_h<=622 && right_v>=(vy-2) && right_v<=(vy+60))
     {
//        for (h=0;h<50;h++)
//        {
//            IOWR_VGA_DATA(VGA_BASE, 1, 4);
//        }
        hit_count++;
        //printf("hit_count is %d\n",hit_count);
        if (sh>0 && sv<0)
        {
            if (vy+29<right_v)
            {
                sh=-sh;
                sv=-sv;
                int tmp=right_v-vy-29;
                if (tmp>=20 && sh<=3 && sv<=3)
                {
                    sh*=1.4;
                    sv*=1.4;
                }
                else if (tmp>=9 && tmp<20 && sh<=3 && sv<=3)
                {
                    sh*=1.2;
                    sv*=1.2;
                }
                
            }
            else
            {
                sh=-sh;
                int tmp=right_v-vy-29;
                if (tmp>=20 && sh<=3 && sv<=3)
                {
                    sh*=1.4;
                    sv*=1.4;
                }
                else if (tmp>=9 && tmp<20 && sh<=3 && sv<=3)
                {
                    sh*=1.2;
                    sv*=1.2;
                }
            }
        }
        else if (sh>0 && sv>0)
        {
            if (vy+29<=right_v)
            {
                sh=-sh;
                int tmp=right_v-vy-29;
                if (tmp>=20 && sh<=3 && sv<=3)
                {
                    sh*=1.4;
                    sv*=1.4;
                }
                else if (tmp>=9 && tmp<20 && sh<=3 && sv<=3)
                {
                    sh*=1.2;
                    sv*=1.2;
                }
                
            }
            else
            {
                sv=-sv;
                sh=-sh;
                int tmp=right_v-vy-29;
                if (tmp>=20 && sh<=3 && sv<=3)
                {
                    sh*=1.4;
                    sv*=1.4;
                }
                else if (tmp>=9 && tmp<20 && sh<=3 && sv<=3)
                {
                    sh*=1.2;
                    sv*=1.2;
                }
            }
        }
        yun_sound2=1;
     }   
     
     //if (hy==0)
     h=h+sh;
     v=v+sv;
     

    




   if (count==0)
   {
        win_flag=1;
        //final_score=yun_count*100;
        final_score=6000+(60-hit_count)*50+life*500;
        //printf("life is %d\n",life);
          //a=0x1000;
       int c;

       while(count==0)
          {

              a=0x1000;
              t=0x1000;
              for (h=0; h<win_delay1; h++)
              {
                   c=a+7+16*12;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+8+16*11;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              a=0x1100;
              for (h=0; h<win_delay1; h++)
              {
                   c=a+3+16*3;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   //cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);     
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+4+16*3;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   //cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+5+16*3;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   //cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+6+16*3;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   //cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+7+16*4;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   //cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+6+16*5;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   //cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+5+16*5;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                  // cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+4+16*5;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   //cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+3+16*5;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   //cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+7+16*6;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   //cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+6+16*7;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                  // cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+5+16*7;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   //cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+4+16*7;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   //cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+3+16*7;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   //cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+3+16*8;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   //cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+4+16*8;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                  // cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+5+16*8;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   //cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+6+16*8;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   //cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+7+16*8;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                  // cx=t+8+16*12;
                  // IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+7+16*9;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   //cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+6+16*9;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                  // cx=t+8+16*12;
                  // IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+5+16*9;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                  // cx=t+8+16*12;
                  // IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+4+16*9;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                  // cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+3+16*9;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                 //  cx=t+8+16*12;
                   //IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+5+16*10;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                  // cx=t+8+16*12;
                  // IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+6+16*11;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                 //  cx=t+8+16*12;
                  // IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+7+16*12;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                 //  cx=t+8+16*12;
                 //  IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+6+16*12;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                 //  cx=t+8+16*12;
                 //  IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+5+16*12;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                //   cx=t+8+16*12;
                 //  IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+4+16*12;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                 //  cx=t+8+16*12;
                 //  IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
              for (h=0; h<win_delay1; h++)
              {
                   c=a+3+16*12;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                 //  cx=t+8+16*12;
               //    IOWR_VGA_DATA(VGA_BASE, 8, cx);   
              }
 
              for (h=0; h<win_delay2; h++)
              {
              }
              
              for (h=0; h<win_delay1; h++)
              {
                  a=0x1000;
                  c=a+7+16*3;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+8+16*3;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+3+16*4;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+4+16*4;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+5+16*4;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+6+16*4;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+8+16*4;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+7+16*5;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+8+16*5;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+3+16*6;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+4+16*6;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+5+16*6;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+6+16*6;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+8+16*6;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+7+16*7;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+8+16*7;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+8+16*8;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+8+16*9;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+8+16*12;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+3+16*10;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+4+16*10;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+6+16*10;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+7+16*10;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+8+16*10;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+3+16*11;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+4+16*11;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+5+16*11;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+7+16*11;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                  c=a+7+16*12;
                  IOWR_VGA_DATA(VGA_BASE, 8, c);
                   
                   //a=0x1000;
                   c=a+3+16*3;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+4+16*3;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+5+16*3;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+6+16*3;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+7+16*4;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+6+16*5;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+5+16*5;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+4+16*5;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+3+16*5;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+7+16*6;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+6+16*7;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+5+16*7;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+4+16*7;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+3+16*7;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+6+16*8;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+5+16*8;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+4+16*8;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+3+16*8;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+7+16*8;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+6+16*9;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+5+16*9;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+4+16*9;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+3+16*9;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+7+16*9;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+5+16*10;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+6+16*11;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+6+16*12;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+5+16*12;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+4+16*12;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+3+16*12;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
                   c=a+8+16*11;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              

          }
   }   
   if (life==0)
   {
        lose_flag=1;
        //final_score=yun_count*100;
        //final_score=6000+(60-hit_count)*50+life*500;
       // printf("final_score is %d\n",final_score);
        
       int c;


       while(life==0)
       {

               //a=0x1000;
               for (i=0;i<16;i++)
               {
                   for (j=0;j<12;j++)
                   {
                      for (h=0; h<lose_delay1; h++)
                      {
                        c=4096+j+16*i;
                        IOWR_VGA_DATA(VGA_BASE, 8, c);
                      }
                   }
               }
              
              a=0x1100;
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+3+16*2;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+4+16*2;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+5+16*2;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+6+16*2;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+7+16*2;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+7+16*3;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+7+16*4;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+3+16*5;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+4+16*5;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+5+16*5;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+6+16*5;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+7+16*5;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+7+16*6;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+7+16*7;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+6+16*7;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+5+16*7;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+4+16*7;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+3+16*7;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+3+16*6;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+3+16*10;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+3+16*9;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+3+16*8;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+4+16*8;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+5+16*8;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+5+16*9;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+5+16*10;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+6+16*10;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+7+16*10;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+7+16*9;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+7+16*8;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+3+16*13;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+3+16*12;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+3+16*11;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+4+16*11;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+5+16*11;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+5+16*12;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+5+16*13;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+6+16*11;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+7+16*11;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }    
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+7+16*12;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              for (h=0; h<lose_delay2; h++)
              {
                   c=a+7+16*13;
                   IOWR_VGA_DATA(VGA_BASE, 8, c);
              }
              
              for (h=0; h<lose_delay3; h++)
              {
              }

          }
   }
      
     
  }       
  return 0;
}
 

 