#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <asm/io.h>

int main(void) {
	ioperm(0x379,1,1);
	int i;
	char scanres, curbit, keytxt;
	
		scanres=0x0;
		curbit=0x1;
		ioperm(0x379,1,1);

		/* wait for clock to go low, high, and low again */
		while((inb(0x379) & 0x40) != 0x00){} 
		while((inb(0x379) & 0x40) != 0x40){}
		while((inb(0x379) & 0x40) != 0x00){}
		
		/* ok, ready for 8 bits. Rotate curbit w/ data */
		for (i=0;i<=7;i++) { 
			if((inb(0x379) & 0x20) == 0x20)
				scanres=scanres + curbit;
			/* wait for high, low */
			while((inb(0x379) & 0x40) != 0x40){} 
			while((inb(0x379) & 0x40) != 0x00){}
			curbit= curbit << 1;
		}

		switch (scanres) {
			case 0x16: printf("1");break;
			case 0x1e: printf("2");break;
			case 0x26: printf("3");break;
			case 0x25: printf("4");break;
			case 0x2e: printf("5");break;
			case 0x36: printf("6");break;
			case 0x3d: printf("7");break;
			case 0x3e: printf("8");break;
			case 0x46: printf("9");break;
			case 0x45: printf("0");break;
			case 0x15: printf("Q");break;
			case 0x1d: printf("W");break;
			case 0x24: printf("E");break;
			case 0x2d: printf("R");break;
			case 0x2c: printf("T");break;
			case 0x35: printf("Y");break;
			case 0x3c: printf("U");break;
			case 0x43: printf("I");break;
			case 0x44: printf("O");break;
			case 0x4d: printf("P");break;
			case 0x1c: printf("A");break;
			case 0x1b: printf("S");break;
			case 0x23: printf("D");break;
			case 0x2b: printf("F");break;
			case 0x34: printf("G");break;
			case 0x33: printf("H");break;
			case 0x3b: printf("J");break;
			case 0x42: printf("K");break;
			case 0x4b: printf("L");break;
			case 0x1a: printf("Z");break;
			case 0x22: printf("X");break;
			case 0x21: printf("C");break;
			case 0x2a: printf("V");break;
			case 0x32: printf("B");break;
			case 0x31: printf("N");break;
			case 0x3a: printf("M");break;
			case 0x29: printf(" ");break;
		}	

printf ("\n");

}