student-distrib/keyboard.c
void keyboard_handler(void) {
 	// Recieve key pressed
 	uint32_t press_code = inb(KEYBOARD_DATA_PORT);
 	uint8_t char_to_print;
 	char_to_print = '\0';

	// check whether the press_code is within bonds
 	if ((press_code <0 ) || (press_code > 0xBD)){
		send_eoi(KEYBOARD_IRQ_NUM);
		return;
	}
 	if ((press_code >0x3D) && (press_code < 0x81)) {
		send_eoi(KEYBOARD_IRQ_NUM);
		return;
	}

	// record key press
 	if (press_code <= function3_key){
 		scan_codes[press_code][3] = 1;
 	}
 	else{
	// record key release
 		if (press_code != 0xBA)
 			scan_codes[press_code-press_release_offset][3] = 0;
 	}

	// after key press check whether capslock is on
 	if ( press_code <= CapsLock){
 	if (press_code == CapsLock){
 		if (scan_codes[press_code][3] ==1)
 			scan_codes[press_code][3] = 0;
 		else
 			scan_codes[press_code][3] = 1;
 	}

	// when capslock is off
 	if (scan_codes[CapsLock][3] ==0) {
		//shift is on
 		if (scan_codes[leftshift][3]== 1 || scan_codes[rightshift][3] ==1){
 				char_to_print = scan_codes[press_code][1];
 		}
 		else
 				char_to_print = scan_codes[press_code][0];
 	}
	// when capslock is on
 	if (scan_codes[CapsLock][3] ==1){
		// when shift is also on
 		if (scan_codes[leftshift][3]== 1 || scan_codes[rightshift][3] ==1){
			//when the char to print is letters
 				if (scan_codes[press_code][1] == scan_codes[press_code][2])
 					char_to_print = scan_codes[press_code][0];
 				else
				// print lowercase
 					char_to_print = scan_codes[press_code][1];
 		}
 		else
 			char_to_print = scan_codes[press_code][2];
 	}
 	}
 	//////////////////////////////////////////////////////////
 	//check for special circumstances, ctrl+i and ctrl+l
 	if ((scan_codes[leftCtrl][3] == 1) && (scan_codes[0x26][3] ==1) ){
 		clear_screen();
		 
 	}
 	else if (press_code == 0x0E ){
 		terminal_backspace(); 
 	}
	
	else if ((scan_codes[leftAlt][3] == 1) && (scan_codes[function1_key][3] ==1)){
		switch_display_terminal(0);
	}

	else if ((scan_codes[leftAlt][3] == 1) && (scan_codes[function2_key][3] ==1)){
		switch_display_terminal(1);
	}

	else if ((scan_codes[leftAlt][3] == 1) && (scan_codes[function3_key][3] ==1)){
		switch_display_terminal(2);
	}


	//print the char
 	else if ( char_to_print != '\0')
 		terminal_buf_add (char_to_print);
 	// Send EOI to PIC
 	send_eoi(KEYBOARD_IRQ_NUM);
 }
/* keyboard_handler() (heffley) (xunli3)
 * Inputs: none
 * Outputs: none
 * Effects: updated for checkpoint 2, will handle uppercase switching and function keys, also checks for invalid inputs
 */
keyboard_handler() (heffley) (xunli3)
Inputs: none
Outputs: none
Effects: updated for checkpoint 2, will handle uppercase switching and function keys, also checks for invalid inputs
keyboard_handler () ( heffley ) ( xunli3 ) Inputs : none Outputs : none Effects : updated for checkpoint 2 will handle uppercase switching and function keys also checks for invalid inputs
void keyboard_handler(void) {
 	uint32_t press_code = inb(KEYBOARD_DATA_PORT);
 	uint8_t char_to_print;
 	char_to_print = '\0';
 	if ((press_code <0 ) || (press_code > 0xBD)){
		send_eoi(KEYBOARD_IRQ_NUM);
		return;
	}
 	if ((press_code >0x3D) && (press_code < 0x81)) {
		send_eoi(KEYBOARD_IRQ_NUM);
		return;
	}
 	if (press_code <= function3_key){
 		scan_codes[press_code][3] = 1;
 	}
 	else{
 		if (press_code != 0xBA)
 			scan_codes[press_code-press_release_offset][3] = 0;
 	}
 	if ( press_code <= CapsLock){
 	if (press_code == CapsLock){
 		if (scan_codes[press_code][3] ==1)
 			scan_codes[press_code][3] = 0;
 		else
 			scan_codes[press_code][3] = 1;
 	}
 	if (scan_codes[CapsLock][3] ==0) {
 		if (scan_codes[leftshift][3]== 1 || scan_codes[rightshift][3] ==1){
 				char_to_print = scan_codes[press_code][1];
 		}
 		else
 				char_to_print = scan_codes[press_code][0];
 	}
 	if (scan_codes[CapsLock][3] ==1){
 		if (scan_codes[leftshift][3]== 1 || scan_codes[rightshift][3] ==1){
 				if (scan_codes[press_code][1] == scan_codes[press_code][2])
 					char_to_print = scan_codes[press_code][0];
 				else
 					char_to_print = scan_codes[press_code][1];
 		}
 		else
 			char_to_print = scan_codes[press_code][2];
 	}
 	}
 	if ((scan_codes[leftCtrl][3] == 1) && (scan_codes[0x26][3] ==1) ){
 		clear_screen();
 	}
 	else if (press_code == 0x0E ){
 		terminal_backspace(); 
 	}
	else if ((scan_codes[leftAlt][3] == 1) && (scan_codes[function1_key][3] ==1)){
		switch_display_terminal(0);
	}
	else if ((scan_codes[leftAlt][3] == 1) && (scan_codes[function2_key][3] ==1)){
		switch_display_terminal(1);
	}
	else if ((scan_codes[leftAlt][3] == 1) && (scan_codes[function3_key][3] ==1)){
		switch_display_terminal(2);
	}
 	else if ( char_to_print != '\0')
 		terminal_buf_add (char_to_print);
 	send_eoi(KEYBOARD_IRQ_NUM);
 }
void keyboard_handler ( void ) { uint32_t press_code = inb ( KEYBOARD_DATA_PORT ) ; uint8_t char_to_print ; char_to_print = ' \0 ' ; if ( ( press_code < 0 ) || ( press_code > 0xBD ) ) { send_eoi ( KEYBOARD_IRQ_NUM ) ; return ; } if ( ( press_code > 0x3D ) && ( press_code < 0x81 ) ) { send_eoi ( KEYBOARD_IRQ_NUM ) ; return ; } if ( press_code <= function3_key ) { scan_codes [ press_code ] [ 3 ] = 1 ; } else { if ( press_code != 0xBA ) scan_codes [ press_code - press_release_offset ] [ 3 ] = 0 ; } if ( press_code <= CapsLock ) { if ( press_code == CapsLock ) { if ( scan_codes [ press_code ] [ 3 ] == 1 ) scan_codes [ press_code ] [ 3 ] = 0 ; else scan_codes [ press_code ] [ 3 ] = 1 ; } if ( scan_codes [ CapsLock ] [ 3 ] == 0 ) { if ( scan_codes [ leftshift ] [ 3 ] == 1 || scan_codes [ rightshift ] [ 3 ] == 1 ) { char_to_print = scan_codes [ press_code ] [ 1 ] ; } else char_to_print = scan_codes [ press_code ] [ 0 ] ; } if ( scan_codes [ CapsLock ] [ 3 ] == 1 ) { if ( scan_codes [ leftshift ] [ 3 ] == 1 || scan_codes [ rightshift ] [ 3 ] == 1 ) { if ( scan_codes [ press_code ] [ 1 ] == scan_codes [ press_code ] [ 2 ] ) char_to_print = scan_codes [ press_code ] [ 0 ] ; else char_to_print = scan_codes [ press_code ] [ 1 ] ; } else char_to_print = scan_codes [ press_code ] [ 2 ] ; } } if ( ( scan_codes [ leftCtrl ] [ 3 ] == 1 ) && ( scan_codes [ 0x26 ] [ 3 ] == 1 ) ) { clear_screen ( ) ; } else if ( press_code == 0x0E ) { terminal_backspace ( ) ; } else if ( ( scan_codes [ leftAlt ] [ 3 ] == 1 ) && ( scan_codes [ function1_key ] [ 3 ] == 1 ) ) { switch_display_terminal ( 0 ) ; } else if ( ( scan_codes [ leftAlt ] [ 3 ] == 1 ) && ( scan_codes [ function2_key ] [ 3 ] == 1 ) ) { switch_display_terminal ( 1 ) ; } else if ( ( scan_codes [ leftAlt ] [ 3 ] == 1 ) && ( scan_codes [ function3_key ] [ 3 ] == 1 ) ) { switch_display_terminal ( 2 ) ; } else if ( char_to_print != ' \0 ' ) terminal_buf_add ( char_to_print ) ; send_eoi ( KEYBOARD_IRQ_NUM ) ; }
keyboard_handler() (heffley) (xunli3)
 Inputs: none
 Outputs: none
 Effects: updated for checkpoint 2, will handle uppercase switching and function keys, also checks for invalid inputs
keyboard_handler () ( heffley ) ( xunli3 ) Inputs : none Outputs : none Effects : updated for checkpoint 2 will handle uppercase switching and function keys also checks for invalid inputs
// Recieve key pressed // check whether the press_code is within bonds // record key press // record key release // after key press check whether capslock is on // when capslock is off //shift is on // when capslock is on // when shift is also on //when the char to print is letters // print lowercase ////////////////////////////////////////////////////////// //check for special circumstances, ctrl+i and ctrl+l //print the char // Send EOI to PIC