int main(void){
	TExaS_Init(SSI0_Real_Nokia5110_Scope);  // set system clock to 80 MHz
	
	DisableInterrupts();
	
	
	Random_Init(1);
	
  Nokia5110_Init();
  Nokia5110_ClearBuffer();
	Nokia5110_DisplayBuffer();
	
	SysTick_Init();
	// initialize Timer2 after Nokia5110_Init because of
	// error-prone registers operations (old and new registers
	// are not working good together)
	// 80MHz/11,025 cycles, which is about 7256
	Timer2_Init(7256);
	Ports_Init();
	
	InitSprites(NumberOfEnemies);
	RestartGame();
	
	// Countdown, after which all interrupts are enabled!
	// print 3
	Nokia5110_ClearBuffer();
	Nokia5110_PrintBMP(28, 41, _my_Countdown_03, 0);
	Nokia5110_DisplayBuffer();
	Delay100ms(3);
	// print 2
	Nokia5110_ClearBuffer();
	Nokia5110_PrintBMP(28, 41, _my_Countdown_02, 0);
	Nokia5110_DisplayBuffer();
	Delay100ms(3);
	// print 1
	Nokia5110_ClearBuffer();
	Nokia5110_PrintBMP(28, 41, _my_Countdown_01, 0);
	Nokia5110_DisplayBuffer();
	Delay100ms(3);
	// print GO
	Nokia5110_ClearBuffer();
	Nokia5110_PrintBMP(28, 41, _my_Countdown_GO, 0);
	Nokia5110_DisplayBuffer();
	Delay100ms(3);
	
	
	EnableInterrupts();
	
  while(1){
		if (Flag == 1) {
			Nokia5110_DisplayBuffer();
			
			Flag = 0;
		}
	}
	
}
Beispiel #2
0
void GPIOPortF_Handler(void){

	SW1 = GPIO_PORTF_DATA_R&0x10;     // read PF4 into SW1
  SW2 = GPIO_PORTF_DATA_R&0x01;     // read PF0 into SW2
		if(SW1==0 ){                     // both pressed
			z=0;
			if((LFish.y+4)>=47)
				LFish.y=47;
			else
				LFish.y+=4;
		
  Nokia5110_ClearBuffer();
		for(p=0;p<30;p++){
			if(vector[p].fl==1){
				z++;
				Nokia5110_PrintBMP(vector[p].x, vector[p].y,vector[p].image[0], 0);
	}
		if(z>=o)
			break;
		}
		Nokia5110_PrintBMP(LFish.x,LFish.y, LFish.image[0], 0);
			Nokia5110_DisplayBuffer();
		GPIO_PORTF_ICR_R = 0x10; 
		}

else if(SW2==0 ){  	// neither switch
	z=0;		
	
	if ((LFish.y-4)<=16)
		LFish.y=16;
	else
		LFish.y-=4;
	
   Nokia5110_ClearBuffer();
	
	for(p=0;p<30;p++){
			if(vector[p].fl==1){
				z++;
				Nokia5110_PrintBMP(vector[p].x, vector[p].y,vector[p].image[0], 0);
		}
		if(z>=o)
			break;
		}
	
	Nokia5110_PrintBMP(LFish.x, LFish.y,LFish.image[0], 0);
			Nokia5110_DisplayBuffer();
	GPIO_PORTF_ICR_R = 0x01; 		
}

	     // acknowledge flag4
}
Beispiel #3
0
//Task 1 implementation. 
void Task1(void *pvParameter)
{
	
	player.carname = player_car;
	
	while(1)
	{
		// Player car placed at the beginning of the road. 
		player.car_xpos = 10;
		//Enable sampling on already enabled sampler of ADC. 
		ADC0_PSSI_R = 0x08;	
    //Check sampling status. 		
		while((ADC0_RIS_R&0x08)==0);
		//if no collision than draw "blank car" on the  player car current position. 
		if(collide_flag==0)
		{
		Nokia5110_PrintBMP(player.car_xpos, 15+slider_pos, Blank_car, 0);
		}
		//read ADC reading from the FIFO. 
		slider_pos = ADC0_SSFIFO3_R;
		//If slider and car position movement is in opposite direction than minus adc reading from 4096. Otherwise 
		//directly jump to the next instruction. 
		slider_pos = 4096-slider_pos;
		//Calibrate ADC reading for the car-position so car will always stays between the road. 
		slider_pos = slider_pos/157;
		//Add 15 pixels offset to avoid over-lapping of car and left-side road. car will be drawn from the 
		//left bottom-side X-Y pixel position. 
		player.car_ypos = 15+slider_pos;
		//Blocks this task for 30ms. This is the minimum frequency required for flicker-free display on LCD. 
		vTaskDelay(30/portTICK_RATE_MS);
	
	}
}
int main(void){
  TExaS_Init(SSI0_Real_Nokia5110_Scope);  // set system clock to 80 MHz
  Random_Init(1);
  Nokia5110_Init();
  Nokia5110_ClearBuffer();
	Nokia5110_DisplayBuffer();      // draw buffer

  Nokia5110_PrintBMP(32, 47, PlayerShip0, 0); // player ship middle bottom
  Nokia5110_PrintBMP(33, 47 - PLAYERH, Bunker0, 0);

  Nokia5110_PrintBMP(0, ENEMY10H - 1, SmallEnemy10PointA, 0);
  Nokia5110_PrintBMP(16, ENEMY10H - 1, SmallEnemy20PointA, 0);
  Nokia5110_PrintBMP(32, ENEMY10H - 1, SmallEnemy20PointA, 0);
  Nokia5110_PrintBMP(48, ENEMY10H - 1, SmallEnemy30PointA, 0);
  Nokia5110_PrintBMP(64, ENEMY10H - 1, SmallEnemy30PointA, 0);
  Nokia5110_DisplayBuffer();     // draw buffer

  Delay100ms(50);              // delay 5 sec at 50 MHz


  Nokia5110_Clear();
  Nokia5110_SetCursor(1, 1);
  Nokia5110_OutString("GAME OVER");
  Nokia5110_SetCursor(1, 2);
  Nokia5110_OutString("Nice try,");
  Nokia5110_SetCursor(1, 3);
  Nokia5110_OutString("Earthling!");
  Nokia5110_SetCursor(2, 4);
  Nokia5110_OutUDec(1234);
  while(1){
  }

}
Beispiel #5
0
void Draw(void){ int i;
  Nokia5110_ClearBuffer();
  for(i=0;i<4;i++){
    if(Enemy[i].life > 0){
     Nokia5110_PrintBMP(Enemy[i].x, Enemy[i].y, Enemy[i].image, 0);
    }
  }
  Nokia5110_DisplayBuffer();      // draw buffer
}
void Draw(void){ int i;
  Nokia5110_ClearBuffer();
  for(i=0;i<4;i++){
    if(Enemy[i].life > 0){
     Nokia5110_PrintBMP(Enemy[i].x, Enemy[i].y, Enemy[i].image[FrameCount], 0);
    }
  }
  Nokia5110_DisplayBuffer();      // draw buffer
  FrameCount = (FrameCount+1)&0x01; // 0,1,0,1,...
}
int main(void){ int AnyLife = 1; int i;
  TExaS_Init(NoLCD_NoScope);  // set system clock to 80 MHz
  // you cannot use both the Scope and the virtual Nokia (both need UART0)
  Random_Init(1);
  Nokia5110_Init();
  EnableInterrupts(); // virtual Nokia uses UART0 interrupts
  
  Nokia5110_ClearBuffer();
	Nokia5110_DisplayBuffer();      // draw buffer

  Nokia5110_PrintBMP(32, 47, PlayerShip0, 0); // player ship middle bottom
  Nokia5110_PrintBMP(33, 47 - PLAYERH, Bunker0, 0);

  Nokia5110_PrintBMP(0, ENEMY10H - 1, SmallEnemy10PointA, 0);
  Nokia5110_PrintBMP(16, ENEMY10H - 1, SmallEnemy20PointA, 0);
  Nokia5110_PrintBMP(32, ENEMY10H - 1, SmallEnemy20PointA, 0);
  Nokia5110_PrintBMP(48, ENEMY10H - 1, SmallEnemy30PointA, 0);
  Nokia5110_PrintBMP(64, ENEMY10H - 1, SmallEnemy30PointA, 0);
  Nokia5110_DisplayBuffer();   // draw buffer

  Delay100ms(50);              // delay 5 sec at 80 MHz

  Init();
  Timer2_Init(80000000/30);  // 30 Hz
  while(AnyLife){
    while(Semaphore == 0){};
    Semaphore = 0; // runs at 30 Hz
    AnyLife = 0;
    for(i=0; i<4 ; i++){
      AnyLife |= Enemy[i].life;
    }
    Draw();
  }
  Nokia5110_Clear();
  Nokia5110_SetCursor(1, 1);
  Nokia5110_OutString("GAME OVER");
  Nokia5110_SetCursor(1, 2);
  Nokia5110_OutString("Nice try,");
  Nokia5110_SetCursor(1, 3);
  Nokia5110_OutString("Earthling!");
  Nokia5110_SetCursor(2, 4);
  Nokia5110_OutUDec(1234);
  Nokia5110_SetCursor(0, 0); // renders screen
  while(1){
  }

}
Beispiel #8
0
 void Timer2A_Handler(void){ 
	ST enemy;
  TIMER2_ICR_R = 0x00000001;   // acknowledge timer2A timeout
  q++;
	 d=(Random())%4;
	 k=(Random())%4;
	 s=(d+k)%4;
	 if(q<10){
	 enemy.x=Enemy[s].x;
	 enemy.y=Enemy[s].y;
	 enemy.life=1;
		 enemy.b=0;
	 enemy.image[0]=Black;
	 enemy.image[1]=Dead;
	 }
	 else 
	 {
	 enemy.x=Enemy[s].x;
	 enemy.y=Enemy[s].y;
	 enemy.life=1;
	 enemy.image[0]=bomp;
	 enemy.image[1]=bomp;
	 enemy.b=1;
	 q=0;
	 }
	 for(i=0;i<30;i++)
	 {
		 if(vector[i].fl==0)
		 {
			 vector[i]=enemy;
			 vector[i].fl=1;
			 vector[i].life=1;
			 o++;
		 break;
		 }
	 }
	 Nokia5110_ClearBuffer();
	Nokia5110_PrintBMP(LFish.x, LFish.y, LFish.image[0], 0);
	
    for(p=0;p<30;p++){
			if(vector[p].fl==1 && vector[p].life==1){
	 if(vector[p].x >0){
      vector[p].x -= 10;
      if(((((LFish.y-16)<vector[p].y) && (vector[p].y<=(LFish.y)))||((vector[p].y-16)<LFish.y && (vector[p].y-16)<LFish.y))&& (vector[p].x<=17) && (vector[p].b==0 ))
			{				
				Score+=10;
				vector[p].life=0;
				Nokia5110_PrintBMP(vector[p].x, vector[p].y,vector[p].image[1], 0);
				o--;
			}
			else if((((LFish.y-16)<vector[p].y)&& (vector[p].y<=(LFish.y+4))) &&(vector[p].x<=17) && vector[p].b==1){
	 Nokia5110_ClearBuffer();
		Nokia5110_DisplayBuffer(); 
			 Nokia5110_SetCursor(1, 1);
  Nokia5110_OutString("GAME OVER");
  Nokia5110_SetCursor(1, 2);
  Nokia5110_OutString("Nice try,");
			Nokia5110_SetCursor(1, 4);
			Nokia5110_OutString("Score: ");
		 Nokia5110_SetCursor(6, 4);
  Nokia5110_OutUDec(Score);
		 Delay100ms(50);   
exit(0);			
	 }
			else
				Nokia5110_PrintBMP(vector[p].x, vector[p].y,vector[p].image[0], 0);
			
		}
		else if (vector[p].x==0){
			vector[p].fl=0;
			vector[p].life=0;
	    o--;
		}
	}
		if(p>=o)break;
		}
 Nokia5110_DisplayBuffer();
}