#include "system.h"
#include "VGA.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <io.h>
#include "sys/alt_irq.h"
#include "altera_avalon_pio_regs.h"
volatile int edge_capture;
short s[120000];
long cnttime=0;
//int keyword;
short flag=0,num=0;
unsigned long base;
static void handle_button_interrupts(void* context, alt_u32 id)
{
volatile int* edge_capture_ptr = (volatile int*) context;
*edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE);
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0);
// printf("in the button pio!edge capture is:%d\n",edge_capture);
}
static void init_button_pio()
{
void* edge_capture_ptr = (void*) &edge_capture;
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0xf);
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0x0);
alt_irq_register( BUTTON_PIO_IRQ, edge_capture_ptr, handle_button_interrupts );
}
void main(void)
{
init_button_pio();
unsigned short mmm,site=3,over,xs,ys;
int i,cnt;
VGA_Ctrl_Reg vga_ctrl_set;
vga_ctrl_set.VGA_Ctrl_Flags.RED_ON = 1;
vga_ctrl_set.VGA_Ctrl_Flags.GREEN_ON = 1;
vga_ctrl_set.VGA_Ctrl_Flags.BLUE_ON = 1;
vga_ctrl_set.VGA_Ctrl_Flags.CURSOR_ON = 1;
Vga_Write_Ctrl(VGA_0_BASE, vga_ctrl_set.Value);
Set_Pixel_On_Color(1023,0,0);
Set_Pixel_Off_Color(0,0,1023);
int cnti=3;
Vga_Move_instruct(VGA_0_BASE,7);
usleep(1000000);
//while(1)
///////////////////////////////////////
Vga_Move_instruct(VGA_0_BASE,7);//清屏
usleep(100000);
Vga_Move_instruct(VGA_0_BASE,7);//清屏
usleep(100000);
///////////////////////////////////////
Vga_Game_Start(VGA_0_BASE,0);
usleep(1000);
Vga_Game_Start(VGA_0_BASE,0);
usleep(1000);
IOWR(VGA_0_BASE,OSD_MEM_ADDR+12,0x3);
Vga_Move_instruct(VGA_0_BASE,7);
usleep(200000);
Vga_Game_Start(VGA_0_BASE,1);
usleep(1000);
Vga_Game_Start(VGA_0_BASE,1);
usleep(1000);
IORD(VGA_0_BASE,OSD_MEM_ADDR+15);
IORD(VGA_0_BASE,OSD_MEM_ADDR+15);
//Vga_Move_instruct(VGA_0_BASE,site%5);
// Vga_Move_instruct(VGA_0_BASE,3);
printf("begin:\n");
//usleep(2000000); Vga_Move_instruct(VGA_0_BASE,2);
//usleep(2000000); Vga_Move_instruct(VGA_0_BASE,1);
//usleep(2000000); Vga_Move_instruct(VGA_0_BASE,4);
usleep(2000000); Vga_Move_instruct(VGA_0_BASE,2);
printf("eheng:\n");
usleep(1000000);
// while(1);
while(1)
{
/////clear the car and the point ,then set the stop bit//////
IOWR(VGA_0_BASE,OSD_MEM_ADDR+12,0x4);
/////clear the car and the point ,then set the stop bit//////
/////close the game//////////
Vga_Game_Start(VGA_0_BASE,0);
usleep(1000);
/////close the game//////////
/////clear the screen/////////
Vga_Move_instruct(VGA_0_BASE,7);
usleep(1000000);
/////clear the screen/////////
/////open the game//////////
Vga_Game_Start(VGA_0_BASE,1);
usleep(1000);
/////open the game//////////
/////light the car and the point ,then clear the stop bit//////
IOWR(VGA_0_BASE,OSD_MEM_ADDR+12,0x3);
/////light the car and the point ,then clear the stop bit//////
while(1)
{
// printf("begin:\n");
Vga_Move_instruct(VGA_0_BASE,edge_capture%5);
mmm=IORD(VGA_0_BASE,OSD_MEM_ADDR+15);
mmm=IORD(VGA_0_BASE,OSD_MEM_ADDR+15);
mmm=IORD(VGA_0_BASE,OSD_MEM_ADDR+15);
if(mmm!=0)
{
// usleep(100);
// mmm=IORD(VGA_0_BASE,OSD_MEM_ADDR+15);
// mmm=IORD(VGA_0_BASE,OSD_MEM_ADDR+15);
// mmm=IORD(VGA_0_BASE,OSD_MEM_ADDR+15);
//if(mmm!=0)
{
printf("the enter mmm = %x\t",mmm);
///////////stop the game//////////
IOWR(VGA_0_BASE,OSD_MEM_ADDR+12,0x0);
///////////stop the game//////////
////////////clear the car and set the clear bit//////////
Vga_Move_instruct(VGA_0_BASE,4);
////////////clear the car and set the clear bit//////////
Vga_Game_Start(VGA_0_BASE,0);
//mmm=0;
// mmm=0;
break;
}
}
printf(" mmm = %x\n",mmm);
}
/////////////////clear the car and the point///////////
IOWR(VGA_0_BASE,OSD_MEM_ADDR+12,0);
usleep(20);
/////////////////clear the car and the point///////////
/////////////////clear screen/////////////////
printf("clear screen!\n");
Vga_Move_instruct(VGA_0_BASE,7);
usleep(1000000);
/////////////////clear screen/////////////////
/////////////show the result///////////////
if(mmm==1)
{
Vga_Move_instruct(VGA_0_BASE,5);
usleep(5000000);
printf("fail!\n");
}
else if(mmm==2)
{
Vga_Move_instruct(VGA_0_BASE,6);
usleep(5000000);
printf("win!\n");
}
mmm=0;
/////////////show the result///////////////
/////////////get the key data//////////////
//
while(1){if(edge_capture==1)break;}
printf("key1:\n");
while(1){if(edge_capture==2)break;}
printf("key2:\n");
/////////////get the key data//////////////
/////////close the game/////////
Vga_Game_Start(VGA_0_BASE,0);
usleep(1000);
Vga_Game_Start(VGA_0_BASE,0);
usleep(1000);
/////////close the game/////////
}
}