Index: code/C/HxCHost/Makefile
===================================================================
--- code/C/HxCHost/Makefile	(revision cc8f3af64f28bfcbacec9c284f828f60c17d9d25)
+++ code/C/HxCHost/Makefile	(revision 7cabd49d88d394d6aac1e08f352cbca932b9bb59)
@@ -5,13 +5,19 @@
 ifeq ($(TARGET),TO8)
   CFLAGS += -DPLATFORM=8
-endif
-
+else
 ifeq ($(TARGET),MO5)
   CFLAGS += -DPLATFORM=5
+else
+# No target defined. Fail.
+all: 
+	echo "make TARGET=MO5 or make TARGET=TO8"
+	false
+endif
 endif
 
 # System settings -----------------------------------------------
-CC=m6809-thomson-none-gcc
-AS=m6809-thomson-none-as
+PREFIX=m6809-thomson
+CC=$(PREFIX)-gcc
+AS=$(PREFIX)-as
 
 # Generic rules -------------------------------------------------
@@ -19,4 +25,7 @@
 out_sap.hfe: out.sap
 	hxcfloppyemulator_convert out.sap -HFE
+	cp out_sap.hfe /mo5/MO5/
+	unmount /mo5
+	rm -r /mo5
 
 # Disk Image
@@ -26,10 +35,11 @@
 
 # Linking
-TEST.BIN: $(OBJECTS)
-	$(CC) -Os $(OBJECTS) -o TEST.BIN -Wl,--map -Wl,-Ttext,0x6100 -nostdlib -lgcc
+TEST.BIN TEST.map: $(OBJECTS) TEST.script
+	#$(CC) -v -Os $(OBJECTS) -o TEST.BIN -Wl,--map -Wl,-m -Wl,-Ttext,0x6100 -nostdlib -lgcc
+	lwlink --decb $(OBJECTS) --output=TEST.BIN --map=TEST.map --script=TEST.script --library-path=/boot/home/config/lib/gcc/m6809-thomson/4.6.1 --library-path=/boot/home/config/m6809-thomson/lib -lgcc
 
 #Compiling
 obj/$(TARGET)/%.o: %.c obj/$(TARGET)
-	$(CC) $(CFLAGS) -c $< -o $@
+	$(CC) -save-temps $(CFLAGS) -c $< -o $@
 
 obj/$(TARGET)/%.o: pff/%.c obj/$(TARGET)
Index: code/C/HxCHost/TEST.script
===================================================================
--- code/C/HxCHost/TEST.script	(revision 7cabd49d88d394d6aac1e08f352cbca932b9bb59)
+++ code/C/HxCHost/TEST.script	(revision 7cabd49d88d394d6aac1e08f352cbca932b9bb59)
@@ -0,0 +1,6 @@
+section .text.startup load 5000
+section .text
+section *,!bss
+section *,bss
+
+entry _main
Index: code/C/HxCHost/macros.h
===================================================================
--- code/C/HxCHost/macros.h	(revision cc8f3af64f28bfcbacec9c284f828f60c17d9d25)
+++ code/C/HxCHost/macros.h	(revision 7cabd49d88d394d6aac1e08f352cbca932b9bb59)
@@ -4,4 +4,6 @@
 	#error "make TARGET=TO8 or make TARGET=MO5"
 #endif
+
+#define FCB "fcb"
 
 ///////////////////////////////////////
@@ -40,6 +42,6 @@
 	/* MONITOR ENTRY POINTS */
 	#define mon_putc(car) { \
-    	asm("swi \t  \t; MO5 monitor\n"\
-		    ".fcb \t2 \t; putc"\
+    	asm(" swi \n"\
+		    " fcb 2"\
 			::"B" ((unsigned char) (car))\
 		); \
@@ -53,6 +55,6 @@
 		DKBUF = (unsigned int)buffer;\
 \
-    	asm("swi \t  \t; MO5 monitor\n"\
-		    ".fcb \t0x26 \t; DKCONT"\
+    	asm(" swi \n"\
+		    " fcb 0x26"\
 			); \
 	}
@@ -68,6 +70,6 @@
 		DKBUF = (unsigned int)output;
 
-    	asm("swi \t  \t; MO5 monitor\n"
-		    ".fcb \t0x26 \t; DKCONT"
+    	asm(" swi \n"
+		    " fcb 0x26"
 			);
 
Index: code/C/HxCHost/main.c
===================================================================
--- code/C/HxCHost/main.c	(revision cc8f3af64f28bfcbacec9c284f828f60c17d9d25)
+++ code/C/HxCHost/main.c	(revision 7cabd49d88d394d6aac1e08f352cbca932b9bb59)
@@ -9,10 +9,5 @@
 void asm_write();
 
-#if PLATFORM == 5
-	#define DIRECTORY_BUFFER (FILINFO*)0x3000
-#else
-	// Thomson TO8 code
-	#define DIRECTORY_BUFFER (FILINFO*)0xA000
-#endif
+FILINFO DIRECTORY_BUFFER[23];
 
 unsigned char mark[512 + 16] = "HxCFEDA";
@@ -102,5 +97,5 @@
 	{"\x1B\x50\x0CHxC floppy emulator setup\r\n"
 	"UP/DOWN move - +/- change\r\n"
-	"space save - left quit\r\n"
+	"space save - left quit\r\n\n"
 		 "Step sound       ", 16, 0}, 
 	{"\r\nGUI sound        ", 17, 0}, 
@@ -112,7 +107,10 @@
 };
 
+#define getcfg(off) *(char*)((int)confbuf+off)
+#define putcfg(off, val) *(char*)((int)confbuf+off) = val
+
 inline static void config()
 {
-	unsigned char* confbuf[29];
+	char confbuf[29];
 	// If it's HXCSDFE.CFG, enter config mode
 	// Read the config part of the file
@@ -121,5 +119,6 @@
 	if (r != 0 || byteCount != 29) 
 	{
-		my_puts("read error");
+		my_puts("read error ");
+		printhex(r);
 		abort();
 	}
@@ -133,7 +132,7 @@
 			mon_putc(selected == j ? 0x54: 0x50) // Blue
 			if(options[j].type)
-				printhex(*(confbuf+options[j].off));
+				printhex(getcfg(options[j].off));
 			else
-				my_puts(*(confbuf+options[j].off) ? "ON":"OFF");
+				my_puts(getcfg(options[j].off) ? "ON":"OFF");
 			mon_putc(0x1B); // Select back color
 			mon_putc(0x50); // Select back color
@@ -141,6 +140,6 @@
 
 		do {
-			asm("SWI \t    \t;\n"
-				".fcb \t0x0A\t;GETC\n");
+			asm(" SWI\n"
+				" FCB 0x0A\n");
 		} while(KEY == 0);
 
@@ -170,8 +169,4 @@
 				}
 				// fall through
-		do {
-			asm("SWI \t    \t;\n"
-				".fcb \t0x0A\t;GETC\n");
-		} while(KEY == 0);
 			case 0x10: // LEFT
 				// Quit (without saving)
@@ -180,5 +175,5 @@
 			case 0x18: // DOWN
 				// select previous file
-				if (++selected > 7) selected = 7;
+				if (++selected > 6) selected = 6;
 				// TODO previous page ?
 				break;
@@ -186,13 +181,13 @@
 				// decrease current option value
 				if(options[selected].type)
-					--*(confbuf+options[selected].off);
+					--*(char*)((int)confbuf+options[selected].off);
 				else
-					*(confbuf+options[selected].off) = 0;
+					putcfg(options[selected].off, 0);
 				break;
 			case 0x0B: // +
 				if(options[selected].type)
-					++*(confbuf+options[selected].off);
+					++*(char*)((int)confbuf+options[selected].off);
 				else
-					*(confbuf+options[selected].off) = 0xFF;
+					putcfg(options[selected].off, 0xFF);
 				break;
 		}
@@ -211,4 +206,5 @@
 	FATFS fs;
 	FRESULT r = pf_mount(&fs);
+
 	if (r != 0) {
 		my_puts("mount error ");
@@ -265,6 +261,6 @@
 		// Allow the user to select a file
 		do {
-			asm("SWI \t    \t;\n"
-				".fcb \t0x0A\t;GETC\n");
+			asm(" SWI \n"
+				" fcb 0x0A\n");
 		} while(KEY == 0);
 
@@ -300,10 +296,4 @@
 				} else {
 					const char* cmp = HXCSDFECFG;
-					FRESULT res = pf_open(cmp);
-					if (res) {
-						my_puts("Can't open CFG file: ");
-						printhex(res);
-						exit(0);
-					}
 					if (*(long*)(fp->fname) == *(long*)(cmp)
 						&& *(long*)(fp->fname + 4) == *(long*)(cmp+4)
@@ -311,4 +301,10 @@
 					)
 					{
+						FRESULT res = pf_open(cmp);
+						if (res) {
+							my_puts("Can't open CFG file: ");
+							printhex(res);
+							exit(0);
+						}
 						config();
 					} else {
@@ -316,6 +312,32 @@
 						// If it's an HFE file, load it in HxCSDFE.CFG, then reboot
 						
+						// We need to open the file to get the starting cluster.
+						// This is a PFF "limitation".
+						pf_open(fp->fname);
+						long off = LD_DWORD(&fs.org_clust);
+
+						FRESULT res = pf_open(cmp);
+						if (res) {
+							my_puts("Can't open CFG file: ");
+							printhex(res);
+							exit(0);
+						}
+						pf_lseek(0x200);
+
+						int count = 12;
+						pf_write(fp->fname, count, &count);
+						count = 1;
+						pf_write(&fp->fattrib, count, &count);
+						count = 4;
+						pf_write(&off, count, &count);
+						off = LD_DWORD(&fp->fsize);
+						pf_write(&off, count, &count);
+						count = 17;
+						pf_write(fp->fname, count, &count);
+						pf_write(0,0,&count);
+
 						// reboot
-						exit(0);
+						asm(" SWI\n"
+							" FCB 0");
 					}
 				}
Index: code/C/HxCHost/pff/diskio.c
===================================================================
--- code/C/HxCHost/pff/diskio.c	(revision cc8f3af64f28bfcbacec9c284f828f60c17d9d25)
+++ code/C/HxCHost/pff/diskio.c	(revision 7cabd49d88d394d6aac1e08f352cbca932b9bb59)
@@ -96,10 +96,12 @@
 
 DRESULT disk_writep (
-	const BYTE* buff,/* Pointer to the data to be written, NULL:Initiate/Finalize write operation */
+	const BYTE* buff,
+        /* Pointer to the data to be written,
+         * NULL:Initiate/Finalize write operation */
 	DWORD sc		/* Sector number (LBA) or Number of bytes to send */
 )
 {
 	static WORD ptr;
-	static char* wrbuf[256];
+	static char wrbuf[256];
 		// Separate buffer because we need to use map_sector, and it kills secbuf
 
@@ -114,5 +116,5 @@
 			for(;ptr < 512; ++ptr)
 			{
-				*(wrbuf + ptr) = 0;
+				wrbuf[ptr] = 0;
 			}
 
@@ -126,6 +128,8 @@
 		for(int j = 0; j <sc;++j)
 		{
-	    	*(char*)(wrbuf+ptr) = *(char*)(ptr++ + buff);
+	    	wrbuf[ptr] = *(char*)(j+buff);
+			++ptr;
 		}
+        mon_putc(' ');
 	}
 
