Exemplo n.º 1
0
void do_keyboard_irq(void *context, alt_u32 id)
{
	char ascii;
	int status = 0;
	unsigned char key = 0;
	KB_CODE_TYPE decode_mode;
	struct threshold t = {0, 0};

	status = decode_scancode(context, &decode_mode , &key , &ascii) ;
	if ((status == 0) && (decode_mode == KB_ASCII_MAKE_CODE)) {
		switch (key) {
		case 0x42:	// k
		case 0x75:	// up
			t.freq = 0.1;
			break;
		case 0x3b:	// j
		case 0x72:	// down
			t.freq = -0.1;
			break;
		case 0x33:	// h
		case 0x6b:	// left
			t.roc = -0.1;
			break;
		case 0x4b:	// l
		case 0x74:	// right
			t.roc = 0.1;
			break;
		}
		portBASE_TYPE ignored;
		xQueueSendFromISR(threshold_queue, &t, &ignored);
	}
}
Exemplo n.º 2
0
alt_u8 getKeyboard(){
	alt_u8 data;

	if (keyboard_init == 1){
	
		ps2 = alt_up_ps2_open_dev("/dev/ps2_0");
		
		alt_up_ps2_init(ps2); //initialize device
		if(ps2->device_type == PS2_KEYBOARD){
			printf("keyboard connected\n");
		}
		else if(ps2->device_type  == PS2_MOUSE ){
			printf("connected to mouse\n");
		}
		else if(ps2->device_type  == PS2_UNKNOWN){
			printf("unknown device\n");
		}
		else
			printf("Not connected\n");


		alt_up_ps2_clear_fifo(ps2); //clear buffer
		set_keyboard_rate(ps2, 0x00);
		keyboard_init = 0; //initialize device once per reset
	}
	decode_scancode(ps2, &decode, &data, &ascii);
	return data;
}
Exemplo n.º 3
0
void draw_help_menu(alt_up_pixel_buffer_dma_dev* pixel_buffer, alt_up_char_buffer_dev* char_buffer, alt_up_ps2_dev *ps2_kb, KB_CODE_TYPE  decode_mode) {
	int count = 0;
	int exit_flag = 0;
	int current_menu = HOW_TO_PLAY_MENU;
	alt_u8 data;
	char ascii;
	alt_up_pixel_buffer_dma_draw_box(pixel_buffer, 0, 10, 319, 30, BLUE, 0);
	draw_menu_text(char_buffer);
	draw_how_to_play_guide(pixel_buffer, char_buffer);
	while(exit_flag == 0) {
		if (decode_scancode(ps2_kb, &decode_mode, &data, &ascii) == 0) {
			if(data == LEFT || data == RIGHT || data == ESC) count++;
			if(data == LEFT && count >= 2) {
				if(current_menu != HOW_TO_PLAY_MENU) current_menu--;
				draw_current_menu(pixel_buffer, char_buffer, current_menu);
				count = 0;
			}
			if(data == RIGHT && count >= 2) {
				if(current_menu != DEVS_MENU) current_menu++;
				draw_current_menu(pixel_buffer, char_buffer, current_menu);
				count = 0;
			}
			if(data == ESC && count >= 2) {
				exit_flag = 1;
			}
		}

	}
	alt_up_char_buffer_clear(char_buffer);
	alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 0);
}
Exemplo n.º 4
0
/* Reads the PS2 buffers for predetermined player movement keys
 * and updates global player direction variables
 */
void detect_keys(void) {

	//Detect make and break code
	if( ! decode_scancode(ps2_dev, &decode_mode, buffer, &ascii)){

		// Detect if any predetermined key is pressed
		if (decode_mode == KB_ASCII_MAKE_CODE || decode_mode == KB_BINARY_MAKE_CODE){

			switch (buffer[0]){

			case A_KEY: //If 'A' is pressed
				player1_direction = LEFT;
				printf("Play1 detected: %i\n",player1_direction);
				break;

			case S_KEY: //If 'S' is pressed
				player1_direction = DOWN;
				printf("Play1 detected: %i\n",player1_direction);
				break;

			case D_KEY: //If 'D' is pressed
				player1_direction = RIGHT;
				printf("Play1 detected: %i\n",player1_direction);
				break;

			case W_KEY: //If 'W' is pressed
				player1_direction = UP;
				printf("Play1 detected: %i\n",player1_direction);
				break;

			case LEFT_ARROW: //If left arrow is pressed
				player2_direction = 1;
				printf("Play2 detected: %i\n",player2_direction);
				break;

			case DOWN_ARROW: //If down arrow is pressed
				player2_direction = 4;
				printf("Play2 detected: %i\n",player2_direction);
				break;

			case RIGHT_ARROW: //If right arrow is pressed
				player2_direction = 2;
				printf("Play2 detected: %i\n",player2_direction);
				break;

			case UP_ARROW: //If up arrow is pressed
				player2_direction = 3;
				printf("Play2 detected: %i\n",player2_direction);
				break;

			default:
				break;
			}

		}
	}
}
Exemplo n.º 5
0
void ps2_isr (void* context, alt_u32 id)
{
  char ascii;
  int status = 0;
  unsigned char key = 0;
  KB_CODE_TYPE decode_mode;
  status = decode_scancode (context, &decode_mode , &key , &ascii) ;
  if ( status == 0 ) //success
  {
    // print out the result
    switch ( decode_mode )
    {
      case KB_ASCII_MAKE_CODE :
        printf ( "ASCII   : %x\n", key ) ;
        switch(key){
        case 0x75:  thres_freq += 0.2;
        	printf("new freq %.2f", thres_freq);
        	break;
        case 0x72:  thres_freq -= 0.2;
        		printf("new freq %.2f", thres_freq);
        	break;
        case 0x6B:  thres_delta -= 0.2;
        		printf("new delta %.2f", thres_delta);
        	break;
        case 0x74:  thres_delta += 0.2;
        		printf("new delta %.2f", thres_delta);
        	break;
        default:
        	printf("Unwanted input\n");
        	break;

        }
        break ;
      case KB_LONG_BINARY_MAKE_CODE :
        // do nothing
      case KB_BINARY_MAKE_CODE :
        printf ( "MAKE CODE : %x\n", key ) ;
        break ;
      case KB_BREAK_CODE :
        // do nothing
      default :
        printf ( "DEFAULT   : %x\n", key ) ;
        break ;
    }
    IOWR(SEVEN_SEG_BASE,0 ,key);
  }
}
Exemplo n.º 6
0
int main(void) {
	while (1) {
		state = 0;
		int setTime = 15;
		numPlayers = 2;
		initScreen();
		clearScreen();
		initCharBuffer();
		clean_up();
		initKeyboard();
		initState0();
		initAI();


		//Bypass the menu system for testing
		if (IORD(keys,0) == 8) {
			initPlayer(pOne, MARIO, "pOne", 50, 100, HUMAN);
			initPlayer(pTwo, LUIGI, "pTwo", 50, 100, COMPUTER);
			state = 2;
		} else {
			while (state == 0) {
				decode_scancode(ps2, &decode_mode, buf, &ascii);
				state_0(decode_mode, buf[0]);
			};
			initState1(pOne);
			if(aOn)file_handle = initAudio(fname);
			if(aOn)alt_irq_register(AUDIO_0_IRQ, &ab, (alt_isr_func) write_fifo);
			if(aOn)		alt_up_audio_enable_write_interrupt(ab->audio);
			while (state == 1) {
				decode_scancode(ps2, &decode_mode, buf, &ascii);
				state_1(decode_mode, buf[0], ascii);
				if(aOn)loop_audio(file_handle, fname, ab);
			};
		}

		//clean_up();
		clearCharBuffer();
		clearScreen();

		//enable keyboard IRQ
		void* keyboard_control_register_ptr = (void*) (KEYBOARD_BASE + 4);
		alt_irq_register(KEYBOARD_IRQ, keyboard_control_register_ptr,
				keyboard_ISR);
		alt_up_ps2_enable_read_interrupt(ps2);

		//Draw field and UI to both buffers
		initField();

		updateField();
		drawName(p[pOne].name, p[pTwo].name, p[pThree].name, p[pFour].name);
		drawGas(p[pOne].gas);
		drawHealth(p[pOne].hp, p[pTwo].hp, p[pThree].hp, p[pFour].hp);
		drawBullet(p[pOne].bulletType);
		//drawWindIndicator(1);
		updateScreen();

		updateField();
		drawName(p[pOne].name, p[pTwo].name, p[pThree].name, p[pFour].name);
		drawGas(p[pOne].gas);
		drawHealth(p[pOne].hp, p[pTwo].hp, p[pThree].hp, p[pFour].hp);
		drawBullet(p[pOne].bulletType);
		//drawWindIndicator(1);

		float time;
		alt_timestamp_start();


		int start_timer_flag = 1;
		//printf("NUM PLAYERA %i\n", numPlayers);
		int i;
		while (state == 2) {
			int fallFlag = 1;

			//Checks to see if any players are falling
			while (fallFlag == 1) {
				fallFlag = 0;
				for (i = 0; i < numPlayers; i++) {
					if (p[i].alive) {
						if (p[i].y + TANK_HEIGHT >= SCREEN_HEIGHT-1) {
							p[i].hp = 0;
							p[i].alive = DEAD;
						}
						checkPlayerFalling(i);
						if (p[i].isFalling) {
							undrawPlayer(i);
							updatePlayer(i);
							fallFlag = 1;
						}
					}
				}
				if (fallFlag == 1) {
					updateScreen();
				}
			}

			if(start_timer_flag){
				start_time = (float) alt_timestamp() / (float) alt_timestamp_freq();
				start_timer_flag = 0;
			}
			time = (float) alt_timestamp() / (float) alt_timestamp_freq()-start_time;
			if (time >= setTime) {
				setPlayerTurn();
			}
			if (p[turn].type == HUMAN) {
				runGame();

			} else {
				p[turn].deg = 0;
				aiMain(turn);
				setPlayerTurn();
			}
			printTimer(setTime - time);
			int deadCount = 0;
			for (i = 0; i < numPlayers; i++) {
				if (p[i].alive == DEAD)
					deadCount++;
			}
			if (deadCount == numPlayers - 1) {
				usleep(500000);
				state = 3;
			}
		}

		alt_up_ps2_disable_read_interrupt(ps2);
		if(aOn)alt_up_audio_disable_write_interrupt(ab->audio);

		GameOverScreen();
	}
}
Exemplo n.º 7
0
//Keyboard ISR sets the appropriate flags
static void keyboard_ISR(void *c, alt_u32 id) { //keyboard interrupt handler
	if (decode_scancode(ps2, &decode_mode, buf, &ascii) == 0) {
		printf("Touched %c\n", ascii);
		printf("%d is the code\n", decode_mode);
		if (decode_mode == KB_BINARY_MAKE_CODE && buf[0] == SPACEBAR) {
			fFire = 1;
			//theres no power int in the player struct
		} else if (decode_mode == KB_ASCII_MAKE_CODE) {
			printf("Pressed %c\n", ascii);
			switch (ascii) {
			case 'A': //left arrow
				fLeft = 1;
				break;
			case 'D': //right arrow
				fRight = 1;
				break;
			case 'W': //up arrow
				fUp = 1;
				break;
			case 'S': //down arrow
				fDown = 1;
				break;
			case 'Q': //down arrow
				fBullet = 1;
				break;
			case 0: //page up
				break;
			case 1: //page down
				break;
			}
		} else if (decode_mode == KB_LONG_BINARY_MAKE_CODE) {
			printf("Pressed %c\n", ascii);
			switch (buf[0]) {
			case LEFT_ARROW: //left arrow
				fLeft = 1;
				break;
			case RIGHT_ARROW: //right arrow
				fRight = 1;
				break;
			case UP_ARROW: //up arrow
				fUp = 1;
				break;
			case DOWN_ARROW: //down arrow
				fDown = 1;
				break;
			case PAGE_UP: //page up
				fpUp = 1;
				break;
			case PAGE_DOWN: //page down
				fpDown = 1;
				break;
			}
		} else if (decode_mode == KB_BREAK_CODE) {
			printf("Released %c\n", ascii);
			printf("Released %i\n", buf[0]);
			switch (buf[0]) {
			case 28: //left arrow
				fLeft = 0;
				break;
			case 35: //right arrow
				fRight = 0;
				break;
			case 29: //up arrow
				fUp = 0;
				break;
			case 27: //down arrow
				fDown = 0;
				break;
			case 21: //bullet switchs
				fBullet = 0;
				break;
			}

		} else if (decode_mode == KB_LONG_BREAK_CODE) {
			printf("Released %c\n", ascii);
			printf("Released %i\n", buf[0]);
			switch (buf[0]) {
			case LEFT_ARROW: //left arrow
				fLeft = 0;
				break;
			case RIGHT_ARROW: //right arrow
				fRight = 0;
				break;
			case UP_ARROW: //up arrow
				fUp = 0;
				break;
			case DOWN_ARROW: //down arrow
				fDown = 0;
				break;
			case SPACEBAR: //space bar
				fFire = 0;
				break;
			case PAGE_UP: //page up
				fpUp = 0;
				break;
			case PAGE_DOWN: //page down
				fpDown = 0;
				break;
			}

		}

		printf("Exited the keyboard IRQ\n");
	}
}