/* scan to tcode test program */
#include <stdio.h>
#include <bios.h>
#include <unistd.h>
#include <signal.h>
#include "kdefines.h"
#include "tcodes.h"

int main(void){
	unsigned int a, s;
	t_scan sc;
	t_ascii asc;
	t_tcode t;
	t_flags f;

	printf("Key test program ... press sth ... "
		"RCtrl+LCtrl+LAlt+Ralt+C = quit\n");
	/*__djgpp_set_ctrl_c(0);*/ /* no ^C */
	signal(SIGINT, SIG_IGN); /* no ^BREAK */
	while(1){
		while(!bioskey(0x11)) usleep(10);
		s = bioskey(0x12);
		a = bioskey(0x10);
/*		if((a & 0xff) == 27) break; */ /* ESC */
		if(((a>>8) == 46) && (s & 3852) == 3852){ /* RCtrl+LCtrl+RAlt+LAlt+C */
			break;			
		}
		
/*		printf("SC: %u Ascii: %u ('%c') all: %u states: %u(%x)\n", a >> 8,
			a & 0xff, (a&0xff)>30?(a&0xff):'-', a, s, s);*/
		f = s;
		sc = a >> 8;
		asc = a & 0xff;
		t = scan_to_tcode(sc, asc, f);
		printf("Got key: %s - %s (tcode: %d, ascii: %d, flags: 0x%x)\n",
			tcode_to_ascii(t), flags_to_ascii(f), t, asc, f);
	}
	return 0;
}

/* vim: set ts=4 cindent shiftwidth=4 tw=0 : */
