src/keyboard.c

changeset 91
781c15e60012
parent 90
934ae2efdd01
child 92
3d5680edc1f0
     1.1 --- a/src/keyboard.c	Wed Feb 09 22:05:42 2011 +0000
     1.2 +++ b/src/keyboard.c	Wed Feb 09 23:45:55 2011 +0000
     1.3 @@ -160,6 +160,9 @@
     1.4  
     1.5  	// Reset the R/W pointers and length
     1.6  	ks->readp = ks->writep = ks->buflen = 0;
     1.7 +
     1.8 +	// Clear the update flag
     1.9 +	ks->update_flag = false;
    1.10  }
    1.11  
    1.12  void keyboard_event(KEYBOARD_STATE *ks, SDL_Event *ev)
    1.13 @@ -179,6 +182,9 @@
    1.14  			return;
    1.15  	}
    1.16  
    1.17 +	// If we got here, then the keystate must have changed...!
    1.18 +	ks->update_flag = true;
    1.19 +
    1.20  	// scan the keymap
    1.21  	for (int i=0; i < sizeof(keymap)/sizeof(keymap[0]); i++) {
    1.22  		if (keymap[i].key == ev->key.keysym.sym) {
    1.23 @@ -204,10 +210,13 @@
    1.24  {
    1.25  	int nkeys = 0;
    1.26  
    1.27 +	// Skip doing the scan if the keyboard hasn't changed state
    1.28 +	if (!ks->update_flag) return;
    1.29 +
    1.30  	// if buffer empty, do a keyboard scan
    1.31  	if (ks->buflen == 0) {
    1.32  		// Keyboard Data Begins Here (BEGKBD)
    1.33 -		ks->buffer[ks->writep] = 0xDF;
    1.34 +		ks->buffer[ks->writep] = KEY_BEGIN_KEYBOARD;
    1.35  		ks->writep = (ks->writep + 1) % KEYBOARD_BUFFER_SIZE;
    1.36  		if (ks->buflen < KEYBOARD_BUFFER_SIZE) ks->buflen++;
    1.37  
    1.38 @@ -223,7 +232,7 @@
    1.39  
    1.40  		// If no keys down, then send All Keys Up byte
    1.41  		if (nkeys == 0) {
    1.42 -			ks->buffer[ks->writep] = 0x40;
    1.43 +			ks->buffer[ks->writep] = KEY_ALL_UP;
    1.44  			ks->writep = (ks->writep + 1) % KEYBOARD_BUFFER_SIZE;
    1.45  			if (ks->buflen < KEYBOARD_BUFFER_SIZE) ks->buflen++;
    1.46  		}
    1.47 @@ -231,10 +240,13 @@
    1.48  		// TODO: inject "mouse data follows" chunk header and mouse movement info
    1.49  
    1.50  		// Last Entry In List
    1.51 -		ks->buffer[ks->writep] = 0x80;
    1.52 -		ks->writep = (ks->writep + 1) % KEYBOARD_BUFFER_SIZE;
    1.53 -		if (ks->buflen < KEYBOARD_BUFFER_SIZE) ks->buflen++;
    1.54 +//		ks->buffer[ks->writep] = 0x80;
    1.55 +//		ks->writep = (ks->writep + 1) % KEYBOARD_BUFFER_SIZE;
    1.56 +//		if (ks->buflen < KEYBOARD_BUFFER_SIZE) ks->buflen++;
    1.57  	}
    1.58 +
    1.59 +	// Clear the update flag
    1.60 +	ks->update_flag = false;
    1.61  }
    1.62  
    1.63  bool keyboard_get_irq(KEYBOARD_STATE *ks)
    1.64 @@ -302,6 +314,10 @@
    1.65  	} else {
    1.66  		// Write command to KBC -- TODO!
    1.67  		printf("KBC TODO: write keyboard data 0x%02X\n", val);
    1.68 +		if (val == KEY_CMD_RESET) {
    1.69 +			printf("\tKBC: KEYBOARD RESET!\n");
    1.70 +			ks->readp = ks->writep = ks->buflen = 0;
    1.71 +		}
    1.72  	}
    1.73  }
    1.74