# HG changeset patch # User John Tsiombikas # Date 1379898429 -10800 # Node ID da4c014bb055e768f4491138c78acbed878af14f # Parent cb82d9a86b22e9ef5492eb1cc2fd3aa4fb47c09c implemented kb_isdown(KB_ANY) correctly diff -r cb82d9a86b22 -r da4c014bb055 keyb.c --- a/keyb.c Mon Sep 23 03:45:39 2013 +0300 +++ b/keyb.c Mon Sep 23 04:07:09 2013 +0300 @@ -42,6 +42,7 @@ static int buffer_size, buf_ridx, buf_widx; static int last_key; +static unsigned int num_pressed; static unsigned char keystate[256]; #define ADVANCE(x) ((x) = ((x) + 1) % buffer_size) @@ -62,6 +63,7 @@ last_key = -1; memset(keystate, 0, sizeof keystate); + num_pressed = 0; /* set our interrupt handler */ _disable(); @@ -88,6 +90,9 @@ int kb_isdown(int key) { + if(key == KB_ANY) { + return num_pressed; + } return (int)keystate[key]; } @@ -155,8 +160,14 @@ if(code >= 128) { press = 0; code -= 128; + + if(num_pressed > 0) { + num_pressed--; + } } else { press = 1; + + num_pressed++; } key = scantbl[code]; diff -r cb82d9a86b22 -r da4c014bb055 test.c --- a/test.c Mon Sep 23 03:45:39 2013 +0300 +++ b/test.c Mon Sep 23 04:07:09 2013 +0300 @@ -12,6 +12,15 @@ */ kb_init(16); + printf("Press any key to continue ...\n"); + + /* example of active polling... The same can be done better by using + * kb_wait() + */ + while(!kb_isdown(KB_ANY)); + kb_getkey(); /* discard the key we just detected */ + + printf("Key tester, quit by pressing esc\n"); for(;;) { kb_wait(); /* wait for any keypress */ key = kb_getkey(); /* get the pressed key */