示例#1
0
int getchar_replacement() {
	int code   = bgetc();
	int status = readKeyboardShiftFlags();
	uint8_t  scancode = code >> 8;

	// Special scancode sent when alt + some keys are pressed
	if (scancode >= 0x78 && scancode <= 0x83)
		scancode -= 0x76;

	if (scancode < KEYBOARD_MAP_SIZE && !(status & (STATUS_LCTRL| STATUS_RCTRL))) {
		int key;
		if ((status & (STATUS_LALT|STATUS_RALT)) &&
			(status & (STATUS_LSHIFT|STATUS_RSHIFT|STATUS_CAPS))) {
			key=current_layout->keyboard_map_shift_alt[scancode];
		}
		else if (status & (STATUS_LSHIFT|STATUS_RSHIFT|STATUS_CAPS))
			key=current_layout->keyboard_map_shift[scancode];
		else if (status & (STATUS_LALT|STATUS_RALT))
			key=current_layout->keyboard_map_alt[scancode];
		else
			key=current_layout->keyboard_map[scancode];

		if (key != 0) // do the mapping
			code = key;
	}

	if (ASCII_KEY(code) != 0) // if ascii not null return it
		code = ASCII_KEY(code);

	//printf("Code: %04x\n",code);
	return (code);
}
示例#2
0
int selectAlternateBootDevice(int bootdevice)
{
	int key;
	int newbootdevice;
	int digitsI = 0;
	char *end;
	char digits[3] = {0,0,0};

	// We've already printed the current boot device so user knows what it is
	printf("Typical boot devices are 80 (First HD), 81 (Second HD)\n");
	printf("Enter two-digit hexadecimal boot device [%02x]: ", bootdevice);
	do {
		key = getchar();
		switch (ASCII_KEY(key)) {
		case KEY_BKSP:
			if (digitsI > 0) {
				int x, y, t;
				getCursorPositionAndType(&x, &y, &t);
				// Assume x is not 0;
				x--;
				setCursorPosition(x,y,0); // back up one char
				// Overwrite with space without moving cursor position
				putca(' ', 0x07, 1);
				digitsI--;
			} else {
				// TODO: Beep or something
			}
			break;

		case KEY_ENTER:
			digits[digitsI] = '\0';
			newbootdevice = strtol(digits, &end, 16);
			if (end == digits && *end == '\0') {
				// User entered empty string
				printf("\nUsing default boot device %x\n", bootdevice);
				key = 0;
			} else if(end != digits && *end == '\0') {
				bootdevice = newbootdevice;
				printf("\n");
				key = 0; // We gots da boot device
			} else {
				printf("\nCouldn't parse. try again: ");
				digitsI = 0;
			}
			break;

		default:
			if (isxdigit(ASCII_KEY(key)) && digitsI < 2) {
				putchar(ASCII_KEY(key));
				digits[digitsI++] = ASCII_KEY(key);
			} else {
				// TODO: Beep or something
			}
			break;
		};
	} while (key != 0);

	return bootdevice;
}
/* keyboard module is character device - in this implementation return only
   single number that represent keystroke */
static int i8042_get ( void *data, size_t size, uint flags, device_t *d )
{
	int32 key = (int32) 0;

	if ( buf_size > 0 )
	{
		if ( ( flags & ONLY_LAST )  && buf_last != buf_first )
		{
			/* return last keystroke, drop all before */
			buf_last = buf_first;
			buf_size = 1;
		}

		do {
			key = keyb_buffer[buf_first];
			buf_first = ( buf_first + 1 ) % KEYB_BUFF_SIZE;
			buf_size--;
		}
		while ( ( flags & ONLY_ASCII ) && !( key = ASCII_KEY (key) ) &&
			buf_size > 0 );

		if ( flags & CLEAR_BUFFER )
			buf_first = buf_last = buf_size = 0;

		if ( key && data )
			*( (int32 *) data ) = key;
	}

	return ( key ? 1 : 0 );
}
/*! Keyboard interrupt handler - read new keystrokes and process them */
static void i8042_interrupt_handler ( int irq_num, void *device )
{
	int32 c;
	int new_keystrokes = FALSE;

	while ( ( c = i8042_read () ) >= 0 )
	{
		new_keystrokes |= i8042_insert_keystroke ( c );

		if ( ASCII_KEY ( c ) && ( keyb_flags & ECHO_ON ) )
			kprint ( "%c", ASCII_KEY ( c ) );
	}

	/* halt on Ctrl+p */
	//if ( ASCII_KEY(c) == 'p' && (spec_keys_down & LCTRL) )
	//	halt ();

	if ( new_keystrokes && kernel_interrupt_callback_function )
		kernel_interrupt_callback_function ();
}
示例#5
0
static void updateBootArgs( int key )
{
    key = ASCII_KEY(key);

    switch ( key )
    {
        case KEY_BKSP:
            if ( gBootArgsPtr > gBootArgs )
            {
                *--gBootArgsPtr = '\0';

                int x, y, t;
                getCursorPositionAndType( &x, &y, &t );
                if ( x == 0 && y )
                {
                    x = 80; y--;
                }
                if (x) {
			x--;
		}

		if( bootArgs->Video.v_display == VGA_TEXT_MODE )
		{
			setCursorPosition( x, y, 0 );
			putca(' ', 0x07, 1);
		}
                else
		{
			updateGraphicBootPrompt();
		}
	}
			break;

        default:
		if ( key >= ' ' && gBootArgsPtr < gBootArgsEnd)
		{
			*gBootArgsPtr++ = key;

			if( bootArgs->Video.v_display != VGA_TEXT_MODE )
				updateGraphicBootPrompt();
			else if ( key >= ' ' && key < 0x7f)
				putchar(key);
		}

		break;
	}
}
/*! Insert keystroke into keyboard software buffer */
static int i8042_insert_keystroke ( int c )
{
	if ( c == (int32) 0 ) /* empty keystroke changes nothing */
		return 0;

	if ( ( keyb_flags & ONLY_ASCII ) && ASCII_KEY ( c ) == 0 )
		return 0;

	/* if buffer is full - overwrite oldest keystroke */

	keyb_buffer[buf_last] = c | spec_keys_down;

	buf_last = ( buf_last + 1 ) % KEYB_BUFF_SIZE;

	if ( buf_size < KEYB_BUFF_SIZE )
		buf_size++; /* buffer not full */
	else
		buf_first = ( buf_first + 1 ) % KEYB_BUFF_SIZE;
		/* buffer full, oldest keystroke is overwritten with new */

	return 1;
}