Beispiel #1
0
platform::scancode keyboard::get_scancode( XKeyEvent &ev )
{
	KeySym symbol;
	char buffer[32];
	XLookupString( &ev, buffer, sizeof(buffer), &symbol, nullptr );
	if ( symbol != NoSymbol )
		return get_scancode( ev, symbol );

	return platform::scancode::KEY_UNKNOWN;
}
Beispiel #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;
	
}
Beispiel #3
0
bool InputEventKey::action_match(const Ref<InputEvent> &p_event) const {

	Ref<InputEventKey> key = p_event;
	if (key.is_null())
		return false;

	uint32_t code = get_scancode_with_modifiers();
	uint32_t event_code = key->get_scancode_with_modifiers();

	return get_scancode() == key->get_scancode() && (!key->is_pressed() || (code & event_code) == code);
}
Beispiel #4
0
/* this is the routine you should call whenever you would normally
 * read a keypress. However, to actually tell if a key is pressed,
 * call is_key_pressed() with a scancode as arg.
 */
static int scan_keyboard(void)
{
    int c, key, flag;

/* we use BFI to fix the PrtSc/Pause problem - i.e. we don't :^) */
    while ((c = get_scancode()) == 0xE0);
    if (c == 0xE1)
	c = get_scancode();

    if (c == -1)
	return -1;		/* no key was pressed */

    key = c & 127;
    flag = (c & 128) ? 0 : 1;	/* 1 = down */

    if (flag || key_down[key] != flag)
      key_down[key] = flag;
    else
      return (scan_keyboard ());

    if (key == LEFT_ALT)
	alt_pressed = flag;

    if (alt_pressed && flag && key >= FUNC_KEY(1) && key <= FUNC_KEY(10)) {
	struct vt_stat vts;
	int newvt;

	ioctl(tty_fd, VT_GETSTATE, &vts);
	newvt = c - FUNC_KEY(1) + 1;
	if (vts.v_active != newvt && vtswitch_allowed) {
	    ioctl(tty_fd, VT_ACTIVATE, newvt);
	    restart_con = 0;
	    while (restart_con == 0)
		usleep(50000);
	}
	return -1;		/* Got VT switch */
    }
    if (flag && key == 46 && key_down[LEFT_CTRL])
	raise(SIGINT);
    return key;			/* No VT switch */
}
Beispiel #5
0
void scproc(SDL_Event e, int release) {
    /*if (e.key.keysym.sym == SDLK_UP) {
        if (!release)
            dump_mem();
    } else {*/
        unsigned int scancode = get_scancode(e);
        unsigned char esc = (scancode>>8)&0xFF;
        unsigned char pkt = (scancode>>0)&0xFF;
        if (release)
            add_to_buf(0xF0);
        if (esc)
            add_to_buf(esc);
        if (pkt)
            add_to_buf(pkt);
    /*}*/
}
Beispiel #6
0
bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {

	Ref<InputEventKey> key = p_event;
	if (key.is_null())
		return false;

	uint32_t code = get_scancode_with_modifiers();
	uint32_t event_code = key->get_scancode_with_modifiers();

	bool match = get_scancode() == key->get_scancode() && (!key->is_pressed() || (code & event_code) == code);
	if (match) {
		if (p_pressed != NULL)
			*p_pressed = key->is_pressed();
		if (p_strength != NULL)
			*p_strength = (*p_pressed) ? 1.0f : 0.0f;
	}
	return match;
}
Beispiel #7
0
void isr_kbd_int(void) {
  u8 key = get_scancode();

  if (key & 0x80) {
    if (key == 170)
      shift_locked = 0;
  }
  else {
    if (key == 42) {
      shift_locked = 1;
    }
    else if (key == 58)
      shift_locked = !shift_locked;
    else {
      u8 c = scancode_to_ascii(key);
      if (c)
        putchar(c);
    }

  }
  send_eoi(1);
}
/*
RING<1>
*/
PUBLIC	int	keyboard_read(TTY *p)
{
	/*deal with the buffer*/
	t_32	key=0;
	t_bool	make=FALSE;//make=TRUE:key presses,make=FALSE:key released

	char code1,code2;

	code1=get_scancode(kb_input,1);
	if(code1==-1)
		return -1;	
	/*Pause Press*/
	if((t_8)code1==0xE1){
		if(kb_input->count<4){
			//可能这个时候时钟中断还没有把扫描码写入缓冲区,所以暂时先不做处理。
			return -1;
		}
		key=PAUSEBREAK;
		make=TRUE;
		shift_outM(kb_input,6);
	}
	/*Special Keys*/
	else if((t_8)code1==0xE0){
		if(kb_input->count<2){
			//可能这个时候时钟中断还没有把扫描码写入缓冲区,所以暂时先不做处理。
			return -1;
		}
		code2=get_scancode(kb_input,2);
		if(code2>=0 && (unsigned int)code2<=0x7f){
			key=keymap[MAP_COLS*code2+2];//get the special key from keymap
			make=TRUE;
		}else if( code2 & FLAG_BREAK !=0 ){//if code2 & 0x080 !=0
			make=FALSE;
		}
		switch((t_8)code2){
			case 0x1D://right ctrl press
				r_ctrl=TRUE;
				break;
			case 0x1D+FLAG_BREAK://right ctrl released
				r_ctrl=FALSE;
				break;
			case 0x38://right alt press
				r_alt=TRUE;
				break;
			case 0x38+FLAG_BREAK://right alt released
				r_alt=FALSE;
				break;
			case 0x2A://Print Screen press
				if(kb_input->count<4)
					//可能这个时候时钟中断还没有把扫描码写入缓冲区,所以暂时先不做处理。
					return -1;
				else{
					key=PRINTSCREEN;
					make=TRUE;
					shift_outM(kb_input,4);
					return -1;
				}
			case 0xB7://Print Screen released
				if(kb_input->count<4)
					return -1;
				else{
					key=PRINTSCREEN;
					make=FALSE;
					shift_outM(kb_input,4);
					return -1;
				}
			default:
				break;
		}
		shift_outM(kb_input,2);
	}
	/*Normal keys Press*/
	else if(code1>=0 && (unsigned int)code1<=0x7f){
		switch(code1){
			case	0x36://right shift press
				r_shift=TRUE;
				break;
			case	0x2A://left shift press
				l_shift=TRUE;
				break;
			case	0x1D://left ctrl press
				l_ctrl=TRUE;
				break;
			case	0x38://left alt press
				l_alt=TRUE;
				break;
			default:	//normal character key scan code
				break;
		}
		key=keymap[code1*MAP_COLS];
		keymap[code1*MAP_COLS+3]=PRESSED;
		if(l_shift==TRUE||r_shift==TRUE)
			key=keymap[code1*MAP_COLS+1];
		make=TRUE;
		shift_out(kb_input);
	}
	/*Normal keys released*/
	else{
		switch((t_8)code1){
			case	0x36+FLAG_BREAK://right shift released
				r_shift=FALSE;
				break;
			case	0x2A+FLAG_BREAK://left shift released
				l_shift=FALSE;
				break;
			case	0x1D+FLAG_BREAK://left ctrl released
				l_ctrl=FALSE;
				break;
			case	0x38+FLAG_BREAK://left alt released
				l_alt=FALSE;
				break;
			default:
				break;
		}
		keymap[MAP_COLS*(code1&0x7f)+3]=RELEASED;
		make=FALSE;
		shift_out(kb_input);
	}

	if(make==TRUE){
		if(l_alt==1||r_alt==1){
			switch(key){
				case	F1:
				//	printf("ALT-F1 ");
					return	0;
				case	F2:
				//	printf("ALT-F2 ");
					return	1;
				case	F3:
				//	printf("ALT-F3 ");
					return	2;
				default:
					break;
			}
		}
		if(keymap[0x1E*MAP_COLS+3]==PRESSED)/*'a' pressed*/{
			if(keymap[0x2c*MAP_COLS+3]==PRESSED)/*'z' pressed*/{
				return 0;
			}
			if(keymap[0x2d*MAP_COLS+3]==PRESSED)/*'x' pressed*/{
				return 1;
			}
			if(keymap[0x2e*MAP_COLS+3]==PRESSED)/*'c' pressed*/{
				return 2;
			}
		}

		key|=l_shift?FLAG_SHIFT_L:0;
		key|=r_shift?FLAG_SHIFT_R:0;
		key|=l_alt?FLAG_ALT_L:0;
		key|=r_alt?FLAG_ALT_R:0;
		key|=l_ctrl?FLAG_CTRL_L:0;
		key|=r_ctrl?FLAG_CTRL_R:0;

		printChar(tty2id(p),key);
	}
	return	-1;
}
Beispiel #9
0
unsigned char get_char(void){
	unsigned char tmpchar;
	tmpchar=get_scancode();
	return kbdus[tmpchar&0xFF];
}
Beispiel #10
0
unsigned char get_char(void){
	unsigned char tmpchar;
	tmpchar=get_scancode();
	tmpchar=translate_scancode(tmpchar);
	return tmpchar;
}
Beispiel #11
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;
}
Beispiel #12
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;
}
Beispiel #13
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;
}