Index: kbd/xtk/code/Makefile
===================================================================
--- kbd/xtk/code/Makefile	(revision 071dc14bb917e291ad4b6f8e6778be44b4035d98)
+++ kbd/xtk/code/Makefile	(revision c2c5ac99db2ae81721f659b75eef938dd6975754)
@@ -2,4 +2,6 @@
 OBJCOPY := $(shell { which avr-objcopy || which avr-objcopy-x86; } 2>/dev/null)
 AVRDUDE := $(shell { which avrdude || which avrdude-x86; } 2>/dev/null)
+
+MCU=atmega48p
 
 keyboard.hex: keyboard.bin
@@ -7,12 +9,15 @@
 
 keyboard.bin: keyboard.o main.o
-	$(CC) $^ -o $@ -mmcu=atmega8 -Os
+	$(CC) $^ -o $@ -mmcu=$(MCU) -Os
 
 main.o: main.c ../../../libs/ps2_keyboard/ps2_keyboard.h
-	$(CC) -std=c99 -c $< -mmcu=atmega8 -Os -o $@ -mmcu=atmega8 -Os
+	$(CC) -std=c99 -c $< -mmcu=$(MCU) -Os -o $@ -Os
 
 keyboard.o: ../../../libs/ps2_keyboard/ps2_keyboard.c ../../../libs/ps2_keyboard/ps2_keyboard.h ../../../libs/ps2_keyboard/keymap.h
-	$(CC) -DCALLBACK="callback();" -c $< -mmcu=atmega8 -Os -o $@
+	$(CC) -DCALLBACK="callback();" -c $< -mmcu=$(MCU) -Os -o $@
+
+clean:
+	rm *.o *.bin *.hex
 
 flash: keyboard.hex
-	$(AVRDUDE) -c usbasp -p atmega8 -Uflash:w:$^
+	$(AVRDUDE) -c usbasp -p $(MCU) -Uflash:w:$^
Index: kbd/xtk/code/keyboard.hex
===================================================================
--- kbd/xtk/code/keyboard.hex	(revision 071dc14bb917e291ad4b6f8e6778be44b4035d98)
+++ kbd/xtk/code/keyboard.hex	(revision c2c5ac99db2ae81721f659b75eef938dd6975754)
@@ -1,50 +1,53 @@
-:1000000092C0A1C0A1C09FC09EC09DC09CC09BC00B
-:100010009AC099C098C097C096C095C094C093C02C
-:1000200092C091C090C03F3F3F3F3F3F3F3F3F3F67
-:100030003F3F3F3F3F3F3F3F3F3F3F71313F3F3FAC
-:100040007A736177323F3F6378646534333F3F2092
-:1000500076667472353F3F6E62686779363F3F3F20
-:100060006D6A7537383F3F3F6B696F30393F3F3FAF
-:100070003F6C3F703F3F3F3F3F3F3F3F3F3F3F3F32
-:100080003F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F80
+:1000000099C0A8C0A8C0A6C0A5C0A4C0A3C0A2C0D3
+:10001000A1C0A0C09FC09EC09DC09CC09BC09AC0F4
+:1000200099C098C097C096C095C094C093C092C024
+:1000300091C090C03F3F3F3F3F3F3F3F3F3F3F3F2B
+:100040003F3F3F3F3F3F3F3F3F71313F3F3F7A732D
+:100050006177323F3F6378646534333F3F20766693
+:100060007472353F3F6E62686779363F3F3F6D6A15
+:100070007537383F3F3F6B696F30393F3F3F3F6CCB
+:100080003F703F3F3F3F3F3F3F3F3F3F3F3F3F3F4F
 :100090003F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F70
-:1000A0003F3F3F3F3F3F3F203FA000023F123F0303
-:1000B000A43F3F84263F3FA7263FA183803F3F3F89
-:1000C00087748573813F3F7677757270713F3F57B4
-:1000D00067656362613F3F5666546453603F3F3FCC
-:1000E00046555251503F3F2C45434240413F3F37D8
-:1000F00023443533313F3F3F3F1132303F3F862568
-:10010000222136343F3F3F3F3F3F3F3F973F3F171E
-:100110003F15243F3F3F01A60716051482A513276C
-:1001200006A3A204103F11241FBECFE5D4E0DEBF1A
-:10013000CDBF10E0A0E6B0E001C01D92A736B10728
-:10014000E1F7A5D0E3C05CCF1F920F920FB60F92DC
-:1001500011242F933F934F935F936F937F938F93CC
-:100160009F93AF93BF93EF93FF9383994EC080917A
-:100170006200811108C0849926C081E080936200EA
-:100180001092610027C020916100283090F4849B78
-:100190000CC03091640081E090E0022E01C0880F15
-:1001A0000A94EAF7382B309364002F5F20936100A4
-:1001B0002CC0283021F489E08093610026C0109281
-:1001C00062001092610080916400803F31F481E010
-:1001D000809366001092640018C090916400809132
-:1001E0006600923149F4811104C081E0809360007F
-:1001F0000CC01092600002C0882319F010926600B3
-:1002000004C081E08093630037D0FF91EF91BF91EC
-:10021000AF919F918F917F916F915F914F913F919E
-:100220002F910F900FBE0F901F901895E82FF0E0C0
-:10023000EA5DFF4F84919091600091118052089582
-:10024000809163008823E1F3109263008091640041
-:1002500008951092620010926400109261008B98D1
-:10026000839A85B7886085BF85B78B7F85BF8BB73D
-:1002700080688BBF78940895E3DF109265008091C9
-:100280006600882319F080E88093650008958FEF59
-:1002900080936500DEDF18BA17BA8E9A20E43FEF2C
-:1002A00082B3822782BB809165008F3F09F4FFCF24
-:1002B000CF5F30936500B99A4AE74A95F1F700C0DD
-:1002C000BA9880E38A95F1F788E090E0B998E7E082
-:1002D000F1E03197F1F700C00000B99AFAE7FA951A
-:1002E000F1F700C0C0FF02C0BA9801C0BA9A40E35B
-:1002F0004A95F1F7C6950197009741F7B99887E0BD
-:1003000091E00197F1F700C00000CACFF894FFCF49
+:1000A0003F3F3F3F3F3F3F3F3F3F3F3F3F3F3F3F60
+:1000B0003F3F3F3F3F433F3F3D3B3C58644442400E
+:1000C0003E0F293F65382A701D10023F66712C1FB4
+:1000D0001E11035B672E2D201205045C68392F2149
+:1000E0001413065D693130232215075E6A723224CB
+:1000F0001608095F6B332517180B0A6C3F34352639
+:1001000027190C3F6D7328741A0D3F3F3A361C1B9C
+:10011000752B63763F56773F793F0E7B3F4F7D4B84
+:10012000477E3F6F5253504C4D480145574E514A00
+:100130003749463F11241FBECFEFD2E0DEBFCDBF0F
+:1001400021E0A0E0B1E001C01D92A730B207E1F7C5
+:10015000AAD0F1C055CF1F920F920FB60F92112463
+:100160002F933F934F935F936F937F938F939F93BF
+:10017000AF93BF93EF93FF934B994EC080910201D1
+:10018000811108C04C9926C081E080930201109231
+:10019000010127C020910101283090F44C9B0CC034
+:1001A0003091040181E090E0022E01C0880F0A9492
+:1001B000EAF7382B309304012F5F209301012CC004
+:1001C000283021F489E08093010126C010920201B9
+:1001D0001092010180910401803F31F481E080930D
+:1001E00006011092040118C090910401809106014B
+:1001F000923149F4811104C081E0809300010CC068
+:100200001092000102C0882319F01092060104C068
+:1002100081E08093030135D0FF91EF91BF91AF91C1
+:100220009F918F917F916F915F914F913F912F910E
+:100230000F900FBE0F901F901895E82FF0E0EC5C28
+:10024000FF4F849190910001911180520895809107
+:1002500003018823E1F310920301809104010895C2
+:1002600010920201109204011092010153984B9ACE
+:1002700085B7886085BF85B78B7F85BFE99A7894FD
+:100280000895E5DFE82FF0E0EC54FF4FE491E093B0
+:10029000050180910601882329F08091050180687D
+:1002A0008093050108958AEA80930501D9DF15B886
+:1002B00014B8569A30E44FEF83B186708630E1F778
+:1002C000809105018F3FE1F38BB183278BB920919A
+:1002D000050140930501229887EC90E00197F1F722
+:1002E00000C00000219AE7ECF0E03197F1F700C080
+:1002F0000000219888E090E020FF02C0229801C011
+:10030000229AE7ECF0E03197F1F700C00000219A63
+:10031000E7ECF0E03197F1F700C000002198269556
+:100320000197009749F722988FE891E00197F1F73C
+:0A03300000C00000C1CFF894FFCF19
 :00000001FF
Index: kbd/xtk/code/main.c
===================================================================
--- kbd/xtk/code/main.c	(revision 071dc14bb917e291ad4b6f8e6778be44b4035d98)
+++ kbd/xtk/code/main.c	(revision c2c5ac99db2ae81721f659b75eef938dd6975754)
@@ -7,18 +7,20 @@
 #include "../../../libs/ps2_keyboard/ps2_keyboard.h"
 
-static uint8_t key;
+static volatile uint8_t key;
 
-const uint8_t pcw[128] PROGMEM = {
+const uint8_t at2xt[128] PROGMEM = {
 // 0   1   2   3    4    5    6    7    8    9    A    B    C    D    E    F
-'?' ,0x20,'?' ,0xA0,0x00,0x02,'?' ,0x12,'?' ,0x03,0xA4,'?' ,'?' ,0x84,0x26,'?', // 0
-'?' ,0xA7,0x26,'?' ,0xA1,0x83,0x80,'?' ,'?' ,'?' ,0x87,0x74,0x85,0x73,0x81,'?', // 1
-'?' ,0x76,0x77,0x75,0x72,0x70,0x71,'?' ,'?' ,0x57,0x67,0x65,0x63,0x62,0x61,'?', // 2
-'?' ,0x56,0x66,0x54,0x64,0x53,0x60,'?' ,'?' ,'?' ,0x46,0x55,0x52,0x51,0x50,'?', // 3
-'?' ,',' ,0x45,0x43,0x42,0x40,0x41,'?' ,'?' ,0x37,0x23,0x44,0x35,0x33,0x31,'?', // 4
-'?' ,'?' ,'?' ,0x11,0x32,0x30,'?' ,'?' ,0x86,0x25,0x22,0x21,0x36,0x34,'?' ,'?', // 5
-'?' ,'?' ,'?' ,'?' ,'?' ,'?' ,0x97,'?' ,'?' ,0x17,'?' ,0x15,0x24,'?' ,'?' ,'?', // 6
-0x01,0xA6,0x07,0x16,0x05,0x14,0x82,0xA5,0x13,0x27,0x06,0xA3,0xA2,0x04,0x10,'?'  // 7
+'?' ,0x43,'?' ,0x3F,0x3D,0x3B,0x3C,0x58,0x64,0x44,0x42,0x40,0x3E,0x0F,0x29,'?', // 0
+0x65,0x38,0x2A,0x70,0x1D,0x10,0x02,'?' ,0x66,0x71,0x2C,0x1F,0x1E,0x11,0x03,0x5B, // 1
+0x67,0x2E,0x2D,0x20,0x12,0x05,0x04,0x5C,0x68,0x39,0x2F,0x21,0x14,0x13,0x06,0x5D, // 2
+0x69,0x31,0x30,0x23,0x22,0x15,0x07,0x5E,0x6A,0x72,0x32,0x24,0x16,0x08,0x09,0x5F, // 3
+0x6B,0x33,0x25,0x17,0x18,0x0B,0x0A,0x6C,'?' ,0x34,0x35,0x26,0x27,0x19,0x0C,'?', // 4
+0x6D,0x73,0x28,0x74,0x1A,0x0D,'?' ,'?' ,0x3A,0x36,0x1C,0x1B,0x75,0x2B,0x63,0x76, // 5
+'?' ,0x56,0x77,'?' ,0x79,'?' ,0x0E,0x7B,'?' ,0x4F,0x7D,0x4B,0x47,0x7E,'?' ,0x6F, // 6
+0x52,0x53,0x50,0x4C,0x4D,0x48,0x01,0x45,0x57,0x4E,0x51,0x4A,0x37,0x49,0x46,'?'  // 7
 };
 
+// 83 > 41 (F7)
+// 84 > 54 (SysRq)
 
 void callback()
@@ -27,5 +29,5 @@
 	key_code = read_char(); // TODO this function is blocking. Can it disturb main?
 
-	key = 0 /*pgm_read_byte(&(pcw[key_code]))*/;
+	key = pgm_read_byte(&(at2xt[key_code]));
 	if(release)
 		key |= 0x80;
@@ -34,5 +36,5 @@
 
 int main() {
-	key = 0xFF;
+	key = 0xAA;
 	init_keyboard(); // PS/2 KBD handler
 
@@ -44,34 +46,30 @@
 	DDRD |= (1<<PD6);
 
-	static const int PCLK = 2;
-	static const int PDAT = 4;
+	static const int PCLK = (1<<PB1);
+	static const int PDAT = (1<<PB2);
 
 	uint8_t k;
 	while(1) {
-#if 0
-		while ((PINB & 2) == 0)
+		while ((PINB & (PDAT|PCLK)) != (PDAT|PCLK))
 			; // Wait for PC to be ready to receive data
-#endif
 
-PORTD ^= (1<<PD6);
 		while(key == 0xFF)
 			; // Wait for data to send
 
-		k = k+1; /*key;*/ // local copy so we can receive another code from PS/2
+		PORTD ^= (1<<PD6);
+
+		k = key; // local copy so we can receive another code from PS/2
 		// before we're done sending this one.
 		key = 0xFF;
 
 		// SEND START BIT
+		DDRB &= ~PDAT; // DAT HI
+		_delay_us(50);
 		DDRB |= PCLK; // CLK LOW
-		_delay_us(23);
-		DDRB &= ~PDAT; // DAT HI
-		_delay_us(9);
+		_delay_us(50);
+		DDRB &= ~PCLK; // CLK HI
 
 		for(int i = 0; i < 8; i++)
 		{
-			DDRB &= ~PCLK; // CLK HI
-			_delay_us(66);
-			DDRB |= PCLK; // CLK LOW
-			_delay_us(23);
 			if (k & 1)
 				DDRB &= ~PDAT;
@@ -79,12 +77,15 @@
 				DDRB |= PDAT;
 
-			_delay_us(9);
+			_delay_us(50);
+			DDRB |= PCLK; // CLK LOW
+			_delay_us(50);
+			DDRB &= ~PCLK; // CLK HI
 
 			k >>= 1;
 		}
 
-		DDRB &= ~PCLK; // CLK HI
-		_delay_us(66);
+		DDRB &= ~PDAT; // DAT HI
 
+		_delay_us(100);
 	}
 
