doskeyb

changeset 2:da4c014bb055 tip

implemented kb_isdown(KB_ANY) correctly
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 23 Sep 2013 04:07:09 +0300
parents cb82d9a86b22
children
files keyb.c test.c
diffstat 2 files changed, 20 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/keyb.c	Mon Sep 23 03:45:39 2013 +0300
     1.2 +++ b/keyb.c	Mon Sep 23 04:07:09 2013 +0300
     1.3 @@ -42,6 +42,7 @@
     1.4  static int buffer_size, buf_ridx, buf_widx;
     1.5  static int last_key;
     1.6  
     1.7 +static unsigned int num_pressed;
     1.8  static unsigned char keystate[256];
     1.9  
    1.10  #define ADVANCE(x)	((x) = ((x) + 1) % buffer_size)
    1.11 @@ -62,6 +63,7 @@
    1.12  	last_key = -1;
    1.13  
    1.14  	memset(keystate, 0, sizeof keystate);
    1.15 +	num_pressed = 0;
    1.16  
    1.17  	/* set our interrupt handler */
    1.18  	_disable();
    1.19 @@ -88,6 +90,9 @@
    1.20  
    1.21  int kb_isdown(int key)
    1.22  {
    1.23 +	if(key == KB_ANY) {
    1.24 +		return num_pressed;
    1.25 +	}
    1.26  	return (int)keystate[key];
    1.27  }
    1.28  
    1.29 @@ -155,8 +160,14 @@
    1.30  	if(code >= 128) {
    1.31  		press = 0;
    1.32  		code -= 128;
    1.33 +
    1.34 +		if(num_pressed > 0) {
    1.35 +			num_pressed--;
    1.36 +		}
    1.37  	} else {
    1.38  		press = 1;
    1.39 +
    1.40 +		num_pressed++;
    1.41  	}
    1.42  
    1.43  	key = scantbl[code];
     2.1 --- a/test.c	Mon Sep 23 03:45:39 2013 +0300
     2.2 +++ b/test.c	Mon Sep 23 04:07:09 2013 +0300
     2.3 @@ -12,6 +12,15 @@
     2.4  	 */
     2.5  	kb_init(16);
     2.6  
     2.7 +	printf("Press any key to continue ...\n");
     2.8 +
     2.9 +	/* example of active polling... The same can be done better by using
    2.10 +	 * kb_wait()
    2.11 +	 */
    2.12 +	while(!kb_isdown(KB_ANY));
    2.13 +	kb_getkey();	/* discard the key we just detected */
    2.14 +
    2.15 +	printf("Key tester, quit by pressing esc\n");
    2.16  	for(;;) {
    2.17  		kb_wait();			/* wait for any keypress */
    2.18  		key = kb_getkey();	/* get the pressed key */