-WINCC=c:\mingw\bin\gcc
+CC=gcc
 #COMMON_FLAGS = -m32
 
 VPATH = ../common
 QTLDLIBS = $(shell pkg-config --libs QtCore QtGui 2>/dev/null)
 
 CMDSRCS = \
-                       $(VPATH)\crc16.c \
-                       $(VPATH)\iso14443crc.c \
+                       crc16.c \
+                       iso14443crc.c \
                        data.c \
                        graph.c \
                        ui.c \
 all-static: LDLIBS:=-static $(LDLIBS)
 all-static: snooper cli flasher
 
-prox.exe: prox.c wingui.c $(CMDSRCS) flash.c
-       $(WINCC) $(CFLAGS) $(DEFINES) -o prox.exe prox.c wingui.c $(CMDSRCS) flash.c $(WINLIBS)
+prox.exe: prox.o wingui.o $(CMDOBJS) flash.o
+       $(CC) $(CFLAGS) $(DEFINES) -o prox.exe prox.o wingui.o $(CMDOBJS) flash.c $(WINLIBS)
        
 proxmark3: LDLIBS+=$(QTLDLIBS)
 proxmark3: proxmark3.o $(CMDOBJS) proxusb.o $(QTGUI)
 
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
-#ifdef WIN32
-#include <windows.h>
-#endif
+#include "sleep.h"
 #include "cmdparser.h"
 #include "data.h"
 #include "usb_cmd.h"
 #include "cmdhw.h"
 #include "cmdlf.h"
 #include "cmdmain.h"
-#include "proxusb.h"
 
 unsigned int current_command = CMD_UNKNOWN;
 unsigned int received_command = CMD_UNKNOWN;
 {
   while (received_command != response_type) {
 #ifdef WIN32
+    // FIXME: Do we really need this under windows or is it
+    // just some historical code?
+    // pthread seems to be availabe for win32 nowadays
+    // so we should be able to port the code and get rid
+    // of this part.
     UsbCommand c;
     if (ReceiveCommandPoll(&c))
       UsbCommandReceived(&c);
-    Sleep(0);
-#else
-    usleep(10000); // XXX ugh
 #endif
+    msleep(10); // XXX ugh
   }
   received_command = CMD_UNKNOWN;
 }
 
 
 static uint32_t ExpectedAddr;
 static uint8_t QueuedToSend[256];
-static bool AllWritten;
 #define PHYSICAL_FLASH_START 0x100000
 #define PHYSICAL_FLASH_END   0x200000
 
   memcpy(c.d.asBytes, temp_buf+240, 16);
   SendCommand(&c);
   WaitForAck();
-
-  AllWritten = true;
 }
 
 void LoadFlashFromFile(const char *file, int start_addr, int end_addr)
 
 #ifndef __FLASH_H__
 #define __FLASH_H__
 
+#include <stdint.h>
+
 struct partition {
   int start;
   int end;
 
 #include <stdio.h>\r
 #include <ctype.h>\r
 #include <stdlib.h>\r
-#include <stdint.h>\r
 //extern "C" {\r
 #include "include/hidusage.h"\r
 #include "include/hidpi.h"\r
 #include "include/hidsdi.h"\r
 //}\r
 \r
-#include "ui.h"\r
 #include "flash.h"\r
-#include "proxusb.h"\r
+#include "usb_cmd.h"\r
+#include "ui.h"\r
 \r
 #define OUR_VID 0x9ac4\r
 #define OUR_PID 0x4b8f\r
 
 #ifndef PROXUSB_H__
 #define PROXUSB_H__
 
-#ifdef _MSC_VER
-typedef DWORD uint32_t;
-typedef BYTE uint8_t;
-typedef WORD uint16_t;
-#define bool BOOL
-#else
 #include <stdint.h>
 #include <stdbool.h>
+#ifndef WIN32
+#include <usb.h>
 #endif
 #include "usb_cmd.h"
 
 
 
 static char *logfilename = "proxmark3.log";
 
+// FIXME: ifndef not really nice...
+// We should eventually get rid of it once
+// we fully factorize the code between *nix and windows
+// (using pthread and alikes...)
+#ifndef WIN32
 void PrintAndLog(char *fmt, ...)
 {
   va_list argptr, argptr2;
   va_end(argptr);
   printf("\n");
   if (logging && logfile) {
-#if 0
-    char zeit[25];
-    time_t jetzt_t;
-    struct tm *jetzt;
-
-    jetzt_t = time(NULL);
-    jetzt = localtime(&jetzt_t);
-    strftime(zeit, 25, "%b %e %T", jetzt);
-
-    fprintf(logfile,"%s ", zeit);
-#endif
     vfprintf(logfile, fmt, argptr2);
     fprintf(logfile,"\n");
     fflush(logfile);
   }
   va_end(argptr2);
 }
+#endif
 
 void SetLogFilename(char *fn)
 {
 
 #include <stdlib.h>\r
 #include <stdio.h>\r
 #include <math.h>\r
-#include "graph.h"\r
+\r
 #include "proxusb.h"\r
-#include "cmdmain.h"\r
+#include "graph.h"\r
 #include "ui.h"\r
+#include "cmdmain.h"\r
 \r
 #define oops() do { \\r
        char line[100]; \\r
        return 1;\r
 }\r
 \r
-void PrintToScrollback(char *fmt, ...)\r
+void PrintAndLog(char *fmt, ...)\r
 {\r
        va_list f;\r
        char str[1024];\r
        ResizeCommandWindow();\r
        SetFocus(CommandEdit);\r
 \r
-       PrintToScrollback(">> Started prox, built " __DATE__ " " __TIME__);\r
-       PrintToScrollback(">> Connected to device");\r
+       PrintAndLog(">> Started prox, built " __DATE__ " " __TIME__);\r
+       PrintAndLog(">> Connected to device");\r
 \r
        GreyPenLite = CreatePen(PS_SOLID, 1, RGB(50, 50, 50));\r
        GreyPen = CreatePen(PS_SOLID, 1, RGB(100, 100, 100));\r