Index: src/gui/sdlmain.cpp
===================================================================
--- src/gui/sdlmain.cpp	(revision 4024)
+++ src/gui/sdlmain.cpp	(working copy)
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <stdarg.h>
+#include <fcntl.h>
 #include <sys/types.h>
 #ifdef WIN32
 #include <signal.h>
@@ -50,6 +51,9 @@
 #include "cross.h"
 #include "control.h"
 
+FILE* commLogFile;
+int arduinoISAComm;
+
 #define MAPPERFILE "mapper-" VERSION ".map"
 //#define DISABLE_JOYSTICK
 
@@ -1909,6 +1913,19 @@
 		Config_Add_SDL();
 		DOSBOX_Init();
 
+		commLogFile = fopen("commLog.bin", "wb");
+		if(!commLogFile){
+			printf("Couldn't open commLog.bin for writing\n");
+			return 0;
+		}
+
+		arduinoISAComm = open("/dev/ttyACM0", O_RDWR | O_NOCTTY);
+		if(arduinoISAComm < 0){
+			printf("Couldn't open /dev/ttyACM0 for read/write\n");
+			return 0;
+		}		
+		
+
 		std::string editor;
 		if(control->cmdline->FindString("-editconf",editor,false)) launcheditor();
 		if(control->cmdline->FindString("-opencaptures",editor,true)) launchcaptures(editor);
Index: src/hardware/iohandler.cpp
===================================================================
--- src/hardware/iohandler.cpp	(revision 4024)
+++ src/hardware/iohandler.cpp	(working copy)
@@ -18,6 +18,7 @@
 
 
 #include <string.h>
+#include <stdlib.h>
 #include "dosbox.h"
 #include "inout.h"
 #include "setup.h"
@@ -25,11 +26,20 @@
 #include "../src/cpu/lazyflags.h"
 #include "callback.h"
 
+#include <stdint.h>
+#include <unistd.h>
+#include <termios.h>
 //#define ENABLE_PORTLOG
 
 IO_WriteHandler * io_writehandlers[3][IO_MAX];
 IO_ReadHandler * io_readhandlers[3][IO_MAX];
 
+extern FILE* commLogFile;
+unsigned char commWriteBuff[8];
+const int ISAIOStart = 0x300, ISAIOEnd = 0x308;
+
+extern int arduinoISAComm;
+
 static Bitu IO_ReadBlocked(Bitu /*port*/,Bitu /*iolen*/) {
 	return ~0;
 }
@@ -287,6 +297,19 @@
 
 
 void IO_WriteB(Bitu port,Bitu val) {
+	// IO Write Byte
+	if (port >= ISAIOStart && port < ISAIOEnd )
+	{
+		commWriteBuff[0] = 0x01;
+		*((uint16_t*)&commWriteBuff[1]) = port;
+		commWriteBuff[3] = val;
+		commWriteBuff[4] = 0;
+		fwrite(commWriteBuff, 1, 5, commLogFile);
+
+		// out8(port,val);		
+		return;
+	}
+
 	log_io(0, true, port, val);
 	if (GCC_UNLIKELY(GETFLAG(VM) && (CPU_IO_Exception(port,1)))) {
 		LazyFlags old_lflags;
@@ -323,6 +346,19 @@
 }
 
 void IO_WriteW(Bitu port,Bitu val) {
+	// Write Word
+	if (port >= ISAIOStart && port < ISAIOEnd )
+	{		
+		commWriteBuff[0] = 0x02;
+		*((uint16_t*)&commWriteBuff[1]) = port;
+		*((uint16_t*)&commWriteBuff[3]) = val;
+		fwrite(commWriteBuff, 1, 5, commLogFile);
+		
+		dprintf(arduinoISAComm, "OUT%lx,%lx\n", port, val);
+		//out16(port,val);
+		return;
+	}
+
 	log_io(1, true, port, val);
 	if (GCC_UNLIKELY(GETFLAG(VM) && (CPU_IO_Exception(port,2)))) {
 		LazyFlags old_lflags;
@@ -392,6 +428,19 @@
 }
 
 Bitu IO_ReadB(Bitu port) {
+	//Read byte
+	if (port >= ISAIOStart && port < ISAIOEnd )
+	{
+		Bitu retval = 0xFF; //in8(port);
+
+		commWriteBuff[0] = 0x03;
+		*((uint16_t*)&commWriteBuff[1]) = port;
+		*((uint16_t*)&commWriteBuff[3]) = retval;
+		fwrite(commWriteBuff, 1, 5, commLogFile);
+
+		return retval;
+	}
+
 	Bitu retval;
 	if (GCC_UNLIKELY(GETFLAG(VM) && (CPU_IO_Exception(port,1)))) {
 		LazyFlags old_lflags;
@@ -431,6 +480,45 @@
 }
 
 Bitu IO_ReadW(Bitu port) {
+	// Read word
+	if (port >= ISAIOStart && port < ISAIOEnd )
+	{
+		char buf[32];
+		Bitu inVal = 0xFFFF;
+
+		tcflush(arduinoISAComm, TCIOFLUSH);	 //make sure there's nothing leftover in the buffer from elsewhere
+		dprintf(arduinoISAComm, "IN%lx\n", port);
+
+		//read, blocking, until newline
+		int n;
+		for(n=0; n < 31; n++){
+			int ret = read(arduinoISAComm, buf+n, 1);
+			if(ret < 1){
+				printf("read error on arduinoISAComm\n");
+				break;
+			}
+			if(buf[n] == '\n')
+				break;		
+		}
+		buf[n] = 0x00;
+		//printf("ArduinoISAComm: '%s' n=%i\n", buf);
+
+		//expect something like 'IN 302 = FFFE, t_RDY = 0'		
+		char *valStr = strchr(buf, '=');
+
+		if(valStr != NULL){
+			inVal = strtol(valStr+1, NULL, 16);
+		}
+
+		commWriteBuff[0] = 0x04;
+		*((uint16_t*)&commWriteBuff[1]) = port;
+		*((uint16_t*)&commWriteBuff[3]) = inVal;
+
+		fwrite(commWriteBuff, 1, 5, commLogFile);
+
+		return inVal;
+	}
+
 	Bitu retval;
 	if (GCC_UNLIKELY(GETFLAG(VM) && (CPU_IO_Exception(port,2)))) {
 		LazyFlags old_lflags;
Index: src/hardware/keyboard.cpp
===================================================================
--- src/hardware/keyboard.cpp	(revision 4024)
+++ src/hardware/keyboard.cpp	(working copy)
@@ -25,6 +25,9 @@
 #include "mixer.h"
 #include "timer.h"
 
+extern FILE* commLogFile;
+unsigned char commWriteBuffKB[8];
+
 #define KEYBUFSIZE 32
 #define KEYDELAY 0.300f			//Considering 20-30 khz serial clock and 11 bits/char
 
@@ -219,18 +222,19 @@
 
 void KEYBOARD_AddKey(KBD_KEYS keytype,bool pressed) {
 	Bit8u ret=0;bool extend=false;
+	char c = 0x00;
 	switch (keytype) {
-	case KBD_esc:ret=1;break;
-	case KBD_1:ret=2;break;
-	case KBD_2:ret=3;break;
-	case KBD_3:ret=4;break;		
-	case KBD_4:ret=5;break;
-	case KBD_5:ret=6;break;
-	case KBD_6:ret=7;break;		
-	case KBD_7:ret=8;break;
-	case KBD_8:ret=9;break;
-	case KBD_9:ret=10;break;		
-	case KBD_0:ret=11;break;
+	case KBD_esc:c=27;ret=1;break;
+	case KBD_1:c='1';ret=2;break;
+	case KBD_2:c='2';ret=3;break;
+	case KBD_3:c='3';ret=4;break;		
+	case KBD_4:c='4';ret=5;break;
+	case KBD_5:c='5';ret=6;break;
+	case KBD_6:c='6';ret=7;break;		
+	case KBD_7:c='7';ret=8;break;
+	case KBD_8:c='8';ret=9;break;
+	case KBD_9:c='9';ret=10;break;		
+	case KBD_0:c='0';ret=11;break;
 
 	case KBD_minus:ret=12;break;
 	case KBD_equals:ret=13;break;
@@ -237,31 +241,31 @@
 	case KBD_backspace:ret=14;break;
 	case KBD_tab:ret=15;break;
 
-	case KBD_q:ret=16;break;		
-	case KBD_w:ret=17;break;
-	case KBD_e:ret=18;break;		
-	case KBD_r:ret=19;break;
-	case KBD_t:ret=20;break;		
-	case KBD_y:ret=21;break;
-	case KBD_u:ret=22;break;		
-	case KBD_i:ret=23;break;
-	case KBD_o:ret=24;break;		
-	case KBD_p:ret=25;break;
+	case KBD_q:c='q';ret=16;break;		
+	case KBD_w:c='w';ret=17;break;
+	case KBD_e:c='e';ret=18;break;		
+	case KBD_r:c='r';ret=19;break;
+	case KBD_t:c='t';ret=20;break;		
+	case KBD_y:c='y';ret=21;break;
+	case KBD_u:c='u';ret=22;break;		
+	case KBD_i:c='i';ret=23;break;
+	case KBD_o:c='o';ret=24;break;		
+	case KBD_p:c='p';ret=25;break;
 
 	case KBD_leftbracket:ret=26;break;
 	case KBD_rightbracket:ret=27;break;
-	case KBD_enter:ret=28;break;
+	case KBD_enter:c='\n';ret=28;break;
 	case KBD_leftctrl:ret=29;break;
 
-	case KBD_a:ret=30;break;
-	case KBD_s:ret=31;break;
-	case KBD_d:ret=32;break;
-	case KBD_f:ret=33;break;
-	case KBD_g:ret=34;break;		
-	case KBD_h:ret=35;break;		
-	case KBD_j:ret=36;break;
-	case KBD_k:ret=37;break;		
-	case KBD_l:ret=38;break;
+	case KBD_a:c='a';ret=30;break;
+	case KBD_s:c='s';ret=31;break;
+	case KBD_d:c='d';ret=32;break;
+	case KBD_f:c='f';ret=33;break;
+	case KBD_g:c='g';ret=34;break;		
+	case KBD_h:c='h';ret=35;break;		
+	case KBD_j:c='j';ret=36;break;
+	case KBD_k:c='k';ret=37;break;		
+	case KBD_l:c='l';ret=38;break;
 
 	case KBD_semicolon:ret=39;break;
 	case KBD_quote:ret=40;break;
@@ -268,13 +272,13 @@
 	case KBD_grave:ret=41;break;
 	case KBD_leftshift:ret=42;break;
 	case KBD_backslash:ret=43;break;
-	case KBD_z:ret=44;break;
-	case KBD_x:ret=45;break;
-	case KBD_c:ret=46;break;
-	case KBD_v:ret=47;break;
-	case KBD_b:ret=48;break;
-	case KBD_n:ret=49;break;
-	case KBD_m:ret=50;break;
+	case KBD_z:c='z';ret=44;break;
+	case KBD_x:c='x';ret=45;break;
+	case KBD_c:c='c';ret=46;break;
+	case KBD_v:c='v';ret=47;break;
+	case KBD_b:c='b';ret=48;break;
+	case KBD_n:c='n';ret=49;break;
+	case KBD_m:c='m';ret=50;break;
 
 	case KBD_comma:ret=51;break;
 	case KBD_period:ret=52;break;
@@ -282,7 +286,7 @@
 	case KBD_rightshift:ret=54;break;
 	case KBD_kpmultiply:ret=55;break;
 	case KBD_leftalt:ret=56;break;
-	case KBD_space:ret=57;break;
+	case KBD_space:c=' ';ret=57;break;
 	case KBD_capslock:ret=58;break;
 
 	case KBD_f1:ret=59;break;
@@ -319,7 +323,7 @@
 
 	//The Extended keys
 
-	case KBD_kpenter:extend=true;ret=28;break;
+	case KBD_kpenter:c='\n';extend=true;ret=28;break;
 	case KBD_rightctrl:extend=true;ret=29;break;
 	case KBD_kpdivide:extend=true;ret=53;break;
 	case KBD_rightalt:extend=true;ret=56;break;
@@ -348,6 +352,13 @@
 		E_Exit("Unsupported key press");
 		break;
 	}
+
+	if(c != 0 && pressed){
+		commWriteBuffKB[0] = 0x07;
+		commWriteBuffKB[1] = c;
+		fwrite(commWriteBuffKB, 1, 2, commLogFile);
+	}
+
 	/* Add the actual key in the keyboard queue */
 	if (pressed) {
 		if (keyb.repeat.key == keytype) keyb.repeat.wait = keyb.repeat.rate;		
Index: src/hardware/serialport/serialport.cpp
===================================================================
--- src/hardware/serialport/serialport.cpp	(revision 4024)
+++ src/hardware/serialport/serialport.cpp	(working copy)
@@ -36,6 +36,11 @@
 
 #include "cpu.h"
 
+
+#include <stdint.h>
+extern FILE* commLogFile;
+unsigned char commWriteBuffSP[8];
+
 #define LOG_SER(x) log_ser 
 
 bool device_COM::Read(Bit8u * data,Bit16u * size) {
@@ -135,6 +140,12 @@
 			break;
 	}
 
+	if(index==0){
+		commWriteBuffSP[0] = 0x06;
+		commWriteBuffSP[1] = retval;
+		fwrite(commWriteBuffSP, 1, 2, commLogFile);
+	}
+
 #if SERIAL_DEBUG
 	const char* const dbgtext[]=
 		{"RHR","IER","ISR","LCR","MCR","LSR","MSR","SPR","DLL","DLM"};
@@ -158,7 +169,13 @@
 		default: return;
 	}
 	if(serialports[i]==0) return;
-	
+
+	if(index==0){
+		commWriteBuffSP[0] = 0x05;
+		commWriteBuffSP[1] = val;
+		fwrite(commWriteBuffSP, 1, 2, commLogFile);
+	}
+
 #if SERIAL_DEBUG
 		const char* const dbgtext[]={"THR","IER","FCR",
 			"LCR","MCR","!LSR","MSR","SPR","DLL","DLM"};
