2018-04-30 20:53:07 -04:00
|
|
|
#include "kbrd.h"
|
2020-07-19 19:24:48 -04:00
|
|
|
#include "dglkbrd.h"
|
2018-04-30 20:53:07 -04:00
|
|
|
#include <dos.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "helpers.h"
|
|
|
|
|
|
|
|
void display_key_states(void) {
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
gotoxy(0, 2);
|
|
|
|
for (y = 0; y < 8; ++y) {
|
|
|
|
for (x = 0; x < 16; ++x) {
|
|
|
|
unsigned char pressed;
|
|
|
|
pressed = keys[y * 16 + x] > 0;
|
|
|
|
printf("%d", pressed);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_keyboard(void) {
|
2020-07-19 19:24:48 -04:00
|
|
|
bool result;
|
2018-04-30 20:53:07 -04:00
|
|
|
KEY k;
|
|
|
|
|
|
|
|
clrscr(0);
|
|
|
|
|
2020-07-19 19:24:48 -04:00
|
|
|
ASSERT(keyboard_is_initialized() == false);
|
2018-04-30 20:53:07 -04:00
|
|
|
|
|
|
|
result = keyboard_init();
|
2020-07-19 19:24:48 -04:00
|
|
|
ASSERT(result == true);
|
|
|
|
ASSERT(keyboard_is_initialized() == true);
|
2018-04-30 20:53:07 -04:00
|
|
|
|
|
|
|
printf("Keyboard state\n");
|
|
|
|
display_key_states();
|
|
|
|
|
|
|
|
while (!keys[1]) {
|
|
|
|
display_key_states();
|
|
|
|
}
|
|
|
|
|
|
|
|
// delay to give enough time for key to be released before next ...
|
|
|
|
delay(500);
|
|
|
|
|
|
|
|
gotoxy(0, 18);
|
|
|
|
printf("Press any key ...\n");
|
|
|
|
|
|
|
|
k = keyboard_read_key();
|
|
|
|
printf("Pressed key %d\n", k);
|
|
|
|
|
|
|
|
// same thing, giving enough time for key to be released ...
|
|
|
|
delay(500);
|
|
|
|
printf("Press that same key again ...\n");
|
|
|
|
keyboard_wait_for_key(k);
|
|
|
|
|
|
|
|
result = keyboard_shutdown();
|
2020-07-19 19:24:48 -04:00
|
|
|
ASSERT(result == true);
|
|
|
|
ASSERT(keyboard_is_initialized() == false);
|
2018-04-30 20:53:07 -04:00
|
|
|
|
|
|
|
gotoxy(0, 23);
|
|
|
|
printf("Press a key to continue...\n");
|
|
|
|
|
|
|
|
getch();
|
|
|
|
}
|
|
|
|
|