Ejemplo n.º 1
0
int main_menu()
{
	continue_condition = true;
	fade_condition = false;
	function_to_call = NULL;
	darken = 127;
	int failure = 0;
	initialize_main_menu_buttons();
	int ipc_status;
	message msg;
	int r;
	char * display_name = (char*)malloc(sizeof(char) * strlen("Player name: ")+MAX_PLAYER_NAME_LENGTH);
	strcpy(display_name, "Player name: ");
	display_name = strcat(display_name, get_program_playername());
	if(!failure){
		do{
			/* Get a request message. */
			if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) {
				printf("driver_receive failed with: %d", r);
				continue;
			}
			if (is_ipc_notify(ipc_status)) { /* received notification */
				switch (_ENDPOINT_P(msg.m_source)) {
				case HARDWARE: /* hardware interrupt notification */
					if (msg.NOTIFY_ARG & get_kbd_irq_set()){  /* subscribed kbd interrupt */
						kbd_int_handler();
					}
					if (msg.NOTIFY_ARG & get_rtc_irq_set()) { /* subscribed timer interrupt */
						if(rtc_ih())
							failure = 1;
						getDateString(get_date_str_ptr());
					}
					if(msg.NOTIFY_ARG & get_timer_irq_set()){
						timer_int_handler();
						main_menu_render();
					}
					if (msg.NOTIFY_ARG & get_mouse_irq_set()) { /* subscribed timer interrupt */
						mouse_int_handler();
				}
					break;
				default:
					break; /* no other notifications expected: do nothing */
				}
			} else {/* received a standard message, not a notification */
				/* no standard messages expected: do nothing */
			}
			if(mouse_is_updated())
			{
				assign_mouse(get_previous_mouse(), get_mouse());
				assign_mouse(get_mouse(), get_mouse_state());
				main_menu_mouse_event(get_previous_mouse(), get_mouse());
				move_cursor(get_cursor(), get_mouse()->coords);
			}
		} while(continue_condition);
	}
	return failure;
}
Ejemplo n.º 2
0
int test_line(unsigned short xi, unsigned short yi, 
		           unsigned short xf, unsigned short yf, unsigned long color) {
	
	char* video_mem = NULL;
	int failure =0;
	if((video_mem=(char *)vg_init(VBE_MODE_RES_1024x768)) == NULL)
	{
		printf("test_line(): vg_init() failed");
		return 1;
	}
	draw_line(video_mem,xi,yi, xf,yf,color);
	int kbd_irq_set = 0;
	if((kbd_irq_set = kbd_subscribe_int(0)) < 0){//subscribe kbd interrupts
		printf("test_line(): kbd_subscribe_int() failed \n");
		failure = 1;
	}
	int ipc_status;
	message msg;
	int r;
	if(!failure){
		do{
			/* Get a request message. */
			if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) {
				printf("driver_receive failed with: %d", r);
				continue;
			}
			if (is_ipc_notify(ipc_status)) { /* received notification */
				switch (_ENDPOINT_P(msg.m_source)) {
				case HARDWARE: /* hardware interrupt notification */
					if (msg.NOTIFY_ARG & kbd_irq_set) { /* subscribed kbd interrupt */
						if(kbd_int_handler())
							failure = 1;
					}
					break;
				default:
					break; /* no other notifications expected: do nothing */
				}
			} else {/* received a standard message, not a notification */
				/* no standard messages expected: do nothing */
			}
		} while(get_scancode() != ESC_BREAK && !failure);
	}
	if(kbd_unsubscribe_int()){//unsubscribe interrupts
		printf("test_square(): kbd_unsubscribe_int() failed\n");
		failure = 1;
	}
	printf("Done\n");

	if(vg_exit()){
		printf("test_line(): vg_exit() failed");
		return 1;
	}
	return failure;
	
}
Ejemplo n.º 3
0
/**********************************************************************
 *	timer : 割り込みハンドラー.
 **********************************************************************
 */
void timer0_int_handler(void)
{
    if(	INTCONbits.T0IF){		// タイマ0割り込み?
        INTCONbits.T0IF=0;		// タイマ0割り込みフラグを0にする

		timer_count ++;
		if(	timer_count==0) {
			timer_count_high++;
		}
		timer_tick ++;
	}

#if	PS2KBD_USE_INTERRUPT
//  use PCINT8 hardhandler
#else
//	use TIMER1 softhandler
	kbd_int_handler();
#endif

}
Ejemplo n.º 4
0
/**********************************************************************
 *	timer : 割り込みハンドラー.
 **********************************************************************
 */
void timer2_int_handler(void)
{
    if(	PIR1bits.TMR2IF){		// タイマ2割り込み?
#if	TIMER2_INT_SAMPLE			// タイマー2割り込みでPORTサンプル.
		mon_int_handler();
#endif

#if	TIMER2_INT_BLINK			// タイマー2割り込みでLEDブリンク.
		static ushort cnt=0;
		cnt++;
		if(cnt >= 1000) {
			cnt = 0;
			mLED_1 = !mLED_1;	// LEDを反転.
		}
#endif

#if	USE_PS2KEYBOARD		// PS/2キーボードI/F を使用する.
		kbd_int_handler();
#endif
        PIR1bits.TMR2IF=0;		// タイマ2割り込みフラグを0にする
	}
}
Ejemplo n.º 5
0
int mp_lobby()
{
	int failure = 0;
	if((set_com1_irq_set(generic_ser_subscribe_int_tx_rx(COM1))) < 0)
	{//subscribe interrupts
		printf("mp_lobby(): generic_ser_subscribe_int_tx_rx() failed \n");
		failure = 1;
	}
	if(SET_COMMUNICATION_PARAM())
	{
		printf("ser_set() failed\n");
		return 1;
	}
	initialize_lobby_buttons();
	set_role(SEARCHING);
	lobby_state = NOT_READY;
	enable_per_second_alarm(on_rtc_alarm_int_transmission);
	if(im_message_log != NULL)
		{
			size_t del_i;
			for(del_i = 0 ; del_i < size(im_message_log); del_i++)
			{
				free(*(char**)at(im_message_log, del_i));
			}
			delete_vector_t(im_message_log);
		}
	im_message_log = new_vector_t(sizeof(char*));
	memset(current_im, 0, sizeof(char)*IM_MESSAGE_MAX);
	current_im_index = 0;
	draw_im_index = 0;
	int wait = 0;
	function_to_call = NULL;
	continue_condition = true;
	fade_condition = false;
	darken = FADE_MAX;
	int ipc_status;
	message msg;
	int r;
	set_program_player2name((char*)malloc(sizeof(char)*MAX_PLAYER_NAME_LENGTH+1));
	if(get_program_playername2() == NULL)
		return 1;
	memset(get_program_playername2(),0,sizeof(char)*MAX_PLAYER_NAME_LENGTH+1);
	size_t next_char_index = 0;
	char last_char = 0;
	if(!failure){
		do{
			/* Get a request message. */
			if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) {
				printf("driver_receive failed with: %d", r);
				continue;
			}
			if (is_ipc_notify(ipc_status)) { /* received notification */
				switch (_ENDPOINT_P(msg.m_source)) {
				case HARDWARE: /* hardware interrupt notification */
					if (msg.NOTIFY_ARG & get_com1_irq_set()) { /* subscribed interrupt */
						if(ser_ih(COM1))
							failure = 1;
					}
					if (msg.NOTIFY_ARG & get_kbd_irq_set()){  /* subscribed kbd interrupt */
						kbd_int_handler();
						if(get_scancode() == ESC_BREAK)
						{
							lobby_state = NOT_READY;
							fade_condition = true;
							transmit_message(MES_BYE);
						}
						if(get_role() == SERVER || get_role() == CLIENT)
						{
							if(get_scancode() == ENTER_MAKE && current_im_index != 0)
							{


								current_im_index = 0;
								transmit_protocol(current_im, TYPE_STRING, strlen(current_im)+1);
								char* temp = (char*) calloc(IM_MESSAGE_MAX + 4,1);
								strcpy(temp, "me: ");
								strcat(temp,current_im);

								push_back(im_message_log, &temp);

								memset(current_im, 0, IM_MESSAGE_MAX);
								memset(transmission_message,0,IM_MESSAGE_MAX+4);

							}
							else
							{
								int action;
								action = process_input(get_scancode(), &last_char);
								if(action == CHAR_RECEIVED)
								{
									if(current_im_index < IM_MESSAGE_MAX -1)
									{
										current_im[current_im_index] = last_char;
										current_im_index++;
									}
								}
								else if(action == BACKSPACE_MAKE)
								{
									if(current_im_index > 0)
									{
										current_im_index--;
										current_im[current_im_index] = '\0';
									}
								}
							}
						}
					}
					if (msg.NOTIFY_ARG & get_rtc_irq_set()) { /* subscribed timer interrupt */
						if(rtc_ih())
							failure = 1;
						getDateString(get_date_str_ptr());
					}
					if(msg.NOTIFY_ARG & get_timer_irq_set()){
						timer_int_handler();
						mp_lobby_render();
						//establish_connection_transmission();
					}
					if (msg.NOTIFY_ARG & get_mouse_irq_set()) { /* subscribed timer interrupt */
						mouse_int_handler();
					}
					break;
				default:
					break; /* no other notifications expected: do nothing */
				}
			} else {
			}
			establish_connection_reception();
			if(mouse_is_updated())
			{
				assign_mouse(get_previous_mouse(), get_mouse());
				assign_mouse(get_mouse(), get_mouse_state());
				if(get_role() == SERVER || get_role() == CLIENT)
					lobby_mouse_event(get_previous_mouse(), get_mouse());
				move_cursor(get_cursor(), get_mouse()->coords);
			}

		} while(continue_condition);
	}
	if(im_message_log != NULL)
	{
		size_t del_i;
		for(del_i = 0 ; del_i < size(im_message_log); del_i++)
		{
			free(*(char**)at(im_message_log, del_i));
		}
		delete_vector_t(im_message_log);
		im_message_log = NULL;
	}
	if(generic_ser_unsubscribe_int_tx_rx(COM1))
	{//unsubscribe interrupts
		printf("ser_int_receive(): generic_ser_unsubscribe_int() failed \n");
		failure = 1;
	}
	disable_per_second_alarm();
	continue_condition = true;
	fade_condition = false;
	darken = FADE_MAX;
	return 0;
}
Ejemplo n.º 6
0
int get_player_name()
{
		continue_condition = true;
		fade_condition = false;
		darken = FADE_MAX;
		int failure = 0;
		int ipc_status;
		message msg;
		int r;
		if(get_program_playername() == NULL)
		{
			if(set_program_playername((char*)malloc(sizeof(char)*MAX_PLAYER_NAME_LENGTH)) ==NULL)return 1;
			memset(get_program_playername(),0,sizeof(char)*MAX_PLAYER_NAME_LENGTH);
		}
		size_t next_char_index = strlen(get_program_playername());
		char last_char = 0;
		if(!failure){
			do{
				/* Get a request message. */
				if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) {
					printf("driver_receive failed with: %d", r);
					continue;
				}
				if (is_ipc_notify(ipc_status)) { /* received notification */
					switch (_ENDPOINT_P(msg.m_source)) {
					case HARDWARE: /* hardware interrupt notification */
						if (msg.NOTIFY_ARG & get_kbd_irq_set()){  /* subscribed kbd interrupt */
							kbd_int_handler();
							if(get_scancode() == ENTER_MAKE && next_char_index != 0)
							{
								fade_condition = true;
							}
							else
							{
								int action;
								action = process_input(get_scancode(), &last_char);
								if(action == CHAR_RECEIVED)
								{
									//printf("last_char: %c, %d\n", last_char,last_char);
									if(next_char_index < MAX_PLAYER_NAME_LENGTH-1)
									{
										get_program_playername()[next_char_index] = last_char;
										next_char_index++;
									}
								}
								else if(action == BACKSPACE_MAKE)
								{
									if(next_char_index > 0)
										{
											next_char_index--;
											get_program_playername()[next_char_index] = '\0';
										}
								}
							}
						}
						if (msg.NOTIFY_ARG & get_rtc_irq_set()) { /* subscribed timer interrupt */
							if(rtc_ih())
								failure = 1;
							getDateString(get_date_str_ptr());
						}
						if(msg.NOTIFY_ARG & get_timer_irq_set()){
							timer_int_handler();
							get_player_name_render();
						}
						if (msg.NOTIFY_ARG & get_mouse_irq_set()) { /* subscribed timer interrupt */
							mouse_int_handler();
						}
						break;
					default:
						break; /* no other notifications expected: do nothing */
					}
				} else {/* received a standard message, not a notification */
					/* no standard messages expected: do nothing */
				}

			} while(continue_condition);
		}
		get_program_playername()[next_char_index] = '\0';
		continue_condition = true;
				fade_condition = false;
				darken = FADE_MAX;
		return 0;
}
Ejemplo n.º 7
0
int test_move(unsigned short xi, unsigned short yi, char *xpm[], 
				unsigned short hor, short delta, unsigned short time1)
{
	if(xpm == NULL)
		return 1;
	char* video_mem = NULL;
	int failure =0;
	int width, height;
	char* pix = NULL;
	if((pix = (char*) read_xpm(xpm, &width, &height)) == NULL)
		return 1;
	if((video_mem=(char *)vg_init(VBE_MODE_RES_1024x768)) == NULL)
	{
		printf("test_move(): vg_init() failed");
		return 1;
	}
	int kbd_irq_set = 0;
	int timer_irq_set=0;
	if((kbd_irq_set = kbd_subscribe_int(0)) < 0){//subscribe kbd interrupts
		printf("test_move(): kbd_subscribe_int() failed \n");
		failure = 1;
	}
	if((timer_irq_set = timer_subscribe_int()) < 0){//subscribe timer 0 interrupts
		printf("test_move(): timer_subscribe_int() failed \n");
		failure = 1;
	}
	int ipc_status;
	message msg;
	int r;
	double step = (double)delta/(time1*60);
	double xfp = xi;
	double yfp = yi;
	if(!failure){
		do{
			/* Get a request message. */
			if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) {
				printf("driver_receive failed with: %d", r);
				continue;
			}
			if (is_ipc_notify(ipc_status)) { /* received notification */
				switch (_ENDPOINT_P(msg.m_source)) {
				case HARDWARE: /* hardware interrupt notification */
					if (msg.NOTIFY_ARG & kbd_irq_set)  /* subscribed kbd interrupt */
						if(kbd_int_handler())
							failure = 1;
					if(msg.NOTIFY_ARG & timer_irq_set){
						if(get_ticks() < time1 * 60){//enquanto tempo desjado nao passou
							timer_int_handler();
							blank_secondary_buf();//clear buffer
							draw_pixmap(get_secondary_buf(),(int) xfp, (int) yfp, height, width, pix);
							commit_to_video_mem();
							if(hor)
								xfp += step;//se movimento horizontal incrementar x
							else yfp +=step;//senao incrementar y
						}
					}
					break;
				default:
					break; /* no other notifications expected: do nothing */
				}
			} else {/* received a standard message, not a notification */
				/* no standard messages expected: do nothing */
			}
		} while(get_scancode() != ESC_BREAK && !failure);
	}
	if(timer_unsubscribe_int()){//unsubscribe interrupts
		printf("test_move(): timer_unsubscribe_int() failed\n");
		failure = 1;
	}
	if(kbd_unsubscribe_int()){//unsubscribe interrupts
		printf("test_move(): kbd_unsubscribe_int() failed\n");
		failure = 1;
	}
	printf("Done\n");
	if(vg_exit()){
		printf("test_move(): vg_exit() failed");
		return 1;
	}
	return failure;
}