Index: subsystems/ntvdm/dos/dem.c
===================================================================
--- subsystems/ntvdm/dos/dem.c	(revision 66215)
+++ subsystems/ntvdm/dos/dem.c	(working copy)
@@ -423,7 +423,7 @@
     RegisterBop(BOP_START_DOS, NULL);
 
     /* Load the mouse driver */
-    // DosMouseInitialize();
+    DosMouseInitialize();
 
 #ifndef STANDALONE
 
Index: subsystems/ntvdm/dos/mouse32.c
===================================================================
--- subsystems/ntvdm/dos/mouse32.c	(revision 66215)
+++ subsystems/ntvdm/dos/mouse32.c	(working copy)
@@ -19,10 +19,11 @@
 
 #include "io.h"
 #include "dos32krnl/dos.h"
+#include "hardware/video/vga.h"
 
 /* PRIVATE VARIABLES **********************************************************/
 
-static BOOLEAN DriverEnabled = TRUE;
+static BOOLEAN DriverEnabled = FALSE;
 static MOUSE_DRIVER_STATE DriverState;
 
 /**/
@@ -41,8 +42,8 @@
 
         EmulatorReadMemory(&EmulatorContext,
                            VideoAddress
-                           + (DriverState.Position.Y * Bda->ScreenColumns
-                           + DriverState.Position.X) * sizeof(WORD),
+                           + (DriverState.Position.Y/8 * Bda->ScreenColumns
+                           + DriverState.Position.X/8) * sizeof(WORD),
                            (LPVOID)&Character,
                            sizeof(WORD));
 
@@ -52,8 +53,8 @@
 
         EmulatorWriteMemory(&EmulatorContext,
                             VideoAddress
-                            + (DriverState.Position.Y * Bda->ScreenColumns
-                            + DriverState.Position.X) * sizeof(WORD),
+                            + (DriverState.Position.Y/8 * Bda->ScreenColumns
+                            + DriverState.Position.X/8) * sizeof(WORD),
                             (LPVOID)&Character,
                             sizeof(WORD));
     }
@@ -72,8 +73,8 @@
 
         EmulatorWriteMemory(&EmulatorContext,
                             VideoAddress
-                            + (DriverState.Position.Y * Bda->ScreenColumns
-                            + DriverState.Position.X) * sizeof(WORD),
+                            + (DriverState.Position.Y/8 * Bda->ScreenColumns
+                            + DriverState.Position.X/8) * sizeof(WORD),
                             (LPVOID)&DriverState.Character,
                             sizeof(WORD));
     }
@@ -88,6 +89,7 @@
 {
     USHORT i;
     USHORT AX, BX, CX, DX, SI, DI;
+    /*  avoid  callback bug*/ return;
 
     /* Call handler 0 */
     if ((DriverState.Handler0.CallMask & CallMask) != 0 &&
@@ -107,20 +109,26 @@
         DI = getDI();
 
         setAX(CallMask);
-        setBX(DriverState.ButtonState);
+        setBX(DriverState.ButtonState); 
         setCX(DriverState.Position.X);
         setDX(DriverState.Position.Y);
-        setSI(DriverState.MickeysPerCellHoriz);
-        setDI(DriverState.MickeysPerCellVert);
+        setSI(DriverState.HorizCount);
+        setDI(DriverState.VertCount);
+        /* DPRINT1("Calling Handler0 AX:%04X BX:%08d CX:%08d DX:%08d SI:%08d DI:%08d DS:%04X \n",
+          getAX(),getBX(),getCX(),getDX(),getSI(),getDI(),getDS()); */
+        
 
         DPRINT("Calling Handler0 %04X:%04X with CallMask 0x%04X\n",
                HIWORD(DriverState.Handler0.Callback),
                LOWORD(DriverState.Handler0.Callback),
-               CallMask);
+               CallMask); 
 
         /* Call the callback */
         RunCallback16(&DosContext, DriverState.Handler0.Callback);
-
+        
+        /*DPRINT1("Called  Handler0 AX:%04X BX:%04X CX:%04X DX:%04X SI:%04X DI:%04X DS:%04X",
+          getAX(),getBX(),getCX(),getDX(),getSI(),getDI(),getDS()); */
+          
         setAX(AX);
         setBX(BX);
         setCX(CX);
@@ -152,9 +160,9 @@
             setBX(DriverState.ButtonState);
             setCX(DriverState.Position.X);
             setDX(DriverState.Position.Y);
-            setSI(DriverState.MickeysPerCellHoriz);
-            setDI(DriverState.MickeysPerCellVert);
-
+            setSI(DriverState.HorizCount);
+            setDI(DriverState.VertCount);
+            
             DPRINT1("Calling Handler[%d] %04X:%04X with CallMask 0x%04X\n",
                     i,
                     HIWORD(DriverState.Handlers[i].Callback),
@@ -174,77 +182,135 @@
     }
 }
 
-static VOID WINAPI DosMouseService(LPWORD Stack)
+static VOID InitializeMouseRange(VOID)
 {
-    switch (getAX())
-    {
-        /* Reset Driver */
-        case 0x00:
-        {
-            SHORT i;
+    /* Initialize Mouse Range */
+    DriverState.ScreenResolution = VgaGetDisplayResolution();
+    DriverState.MinX = DriverState.MinY = 0;
+    DriverState.VideoMode = Bda->VideoMode;
+    if (DriverState.VideoMode <= 0x03) {
+       DriverState.ScreenResolution.X*=8;
+       DriverState.ScreenResolution.Y*=8;
+    }
+      DriverState.MaxX = DriverState.ScreenResolution.X -1;
+      DriverState.MaxY = DriverState.ScreenResolution.Y -1;
+    
+    /* DPRINT1("InitializeMouseRange VideoMode:0x%04X Width:%04d Height:%04d\n",Bda->VideoMode,DriverState.MaxX,DriverState.MaxY);	*/
+}
 
-            DriverEnabled = TRUE;
-            DriverState.ShowCount = 0;
-            DriverState.ButtonState = 0;
+static VOID DosCursorSetPosition(SHORT X, SHORT Y)
+{  
+   HWND hWnd;
+   HDC hDC;	
+   POINT Point;
+   SHORT WidthPixels;
+   SHORT HeightPixels;
+   /* Set Internal Position*/
+   DriverState.Position.X = X;
+   DriverState.Position.Y = Y;
+   /* Reset the counters */
+    DriverState.HorizCount = DriverState.VertCount = 0;
+    
+   /* Get the console window */
+    hWnd = GetConsoleWindow();
+    if (hWnd == NULL) return ;
 
-            /* Set the default text cursor */
-            DriverState.TextCursor.ScreenMask = 0xFFFF; /* Display everything */
-            DriverState.TextCursor.CursorMask = 0xFF00; /* ... but with inverted attributes */
+    /* Get the console window's device context */
+    hDC = GetWindowDC(hWnd);
+    if (hDC == NULL) return ;
 
-            /* Set the default graphics cursor */
-            DriverState.GraphicsCursor.HotSpot.X = 3;
-            DriverState.GraphicsCursor.HotSpot.Y = 1;
+    /* Get the parameters */
+    WidthPixels  = (SHORT)GetDeviceCaps(hDC, HORZRES);
+    HeightPixels = (SHORT)GetDeviceCaps(hDC, VERTRES); 	
+        
+    Point.x = X*WidthPixels/DriverState.ScreenResolution.X;
+    Point.y = Y*HeightPixels/DriverState.ScreenResolution.Y;	
+       
+    /* DPRINT1("DosCursorSetPosition X:%04d Y:%04d -> X:%04d Y:%04d\n",X,Y,Point.x,Point.y); */
+    ClientToScreen(GetConsoleWindow(), &Point);
+    SetCursorPos(Point.x, Point.y);
+    /* Release the device context */
+    ReleaseDC(hWnd, hDC);
+}
 
-            DriverState.GraphicsCursor.ScreenMask[0] = 0xC3FF;  // 1100001111111111
-            DriverState.GraphicsCursor.ScreenMask[1] = 0xC0FF;  // 1100000011111111
-            DriverState.GraphicsCursor.ScreenMask[2] = 0xC07F;  // 1100000001111111
-            DriverState.GraphicsCursor.ScreenMask[3] = 0xC01F;  // 1100000000011111
-            DriverState.GraphicsCursor.ScreenMask[4] = 0xC00F;  // 1100000000001111
-            DriverState.GraphicsCursor.ScreenMask[5] = 0xC007;  // 1100000000000111
-            DriverState.GraphicsCursor.ScreenMask[6] = 0xC003;  // 1100000000000011
-            DriverState.GraphicsCursor.ScreenMask[7] = 0xC007;  // 1100000000000111
-            DriverState.GraphicsCursor.ScreenMask[8] = 0xC01F;  // 1100000000011111
-            DriverState.GraphicsCursor.ScreenMask[9] = 0xC01F;  // 1100000000011111
-            DriverState.GraphicsCursor.ScreenMask[10] = 0xC00F; // 1100000000001111
-            DriverState.GraphicsCursor.ScreenMask[11] = 0xC60F; // 1100011000001111
-            DriverState.GraphicsCursor.ScreenMask[12] = 0xFF07; // 1111111100000111
-            DriverState.GraphicsCursor.ScreenMask[13] = 0xFF07; // 1111111100000111
-            DriverState.GraphicsCursor.ScreenMask[14] = 0xFF87; // 1111111110000111
-            DriverState.GraphicsCursor.ScreenMask[15] = 0xFFCF; // 1111111111001111
+static VOID DosMouseReset(VOID)
+{
+    SHORT i;
+    DriverState.ShowCount = 0;
+    DriverState.ButtonState = 0;
 
-            DriverState.GraphicsCursor.CursorMask[0] = 0x0000;  // 0000000000000000
-            DriverState.GraphicsCursor.CursorMask[1] = 0x1C00;  // 0001110000000000
-            DriverState.GraphicsCursor.CursorMask[2] = 0x1F00;  // 0001111100000000
-            DriverState.GraphicsCursor.CursorMask[3] = 0x1F80;  // 0001111110000000
-            DriverState.GraphicsCursor.CursorMask[4] = 0x1FE0;  // 0001111111100000
-            DriverState.GraphicsCursor.CursorMask[5] = 0x1FF0;  // 0001111111110000
-            DriverState.GraphicsCursor.CursorMask[6] = 0x1FF8;  // 0001111111111000
-            DriverState.GraphicsCursor.CursorMask[7] = 0x1FE0;  // 0001111111100000
-            DriverState.GraphicsCursor.CursorMask[8] = 0x1FC0;  // 0001111111000000
-            DriverState.GraphicsCursor.CursorMask[9] = 0x1FC0;  // 0001111111000000
-            DriverState.GraphicsCursor.CursorMask[10] = 0x19E0; // 0001100111100000
-            DriverState.GraphicsCursor.CursorMask[11] = 0x00E0; // 0000000011100000
-            DriverState.GraphicsCursor.CursorMask[12] = 0x0070; // 0000000001110000
-            DriverState.GraphicsCursor.CursorMask[13] = 0x0070; // 0000000001110000
-            DriverState.GraphicsCursor.CursorMask[14] = 0x0030; // 0000000000110000
-            DriverState.GraphicsCursor.CursorMask[15] = 0x0000; // 0000000000000000
+    /* Set the default text cursor */
+    DriverState.TextCursor.ScreenMask = 0xFFFF; /* Display everything */
+    DriverState.TextCursor.CursorMask = 0xFF00; /* ... but with inverted attributes */
 
-            /* Initialize the counters */
-            DriverState.HorizCount = DriverState.VertCount = 0;
+    /* Set the default graphics cursor */
+    DriverState.GraphicsCursor.HotSpot.X = 3;
+    DriverState.GraphicsCursor.HotSpot.Y = 1;
 
-            for (i = 0; i < NUM_MOUSE_BUTTONS; i++)
-            {
-                DriverState.PressCount[i] = DriverState.ReleaseCount[i] = 0;
-            }
+    DriverState.GraphicsCursor.ScreenMask[0] = 0xC3FF;  // 1100001111111111
+    DriverState.GraphicsCursor.ScreenMask[1] = 0xC0FF;  // 1100000011111111
+    DriverState.GraphicsCursor.ScreenMask[2] = 0xC07F;  // 1100000001111111
+    DriverState.GraphicsCursor.ScreenMask[3] = 0xC01F;  // 1100000000011111
+    DriverState.GraphicsCursor.ScreenMask[4] = 0xC00F;  // 1100000000001111
+    DriverState.GraphicsCursor.ScreenMask[5] = 0xC007;  // 1100000000000111
+    DriverState.GraphicsCursor.ScreenMask[6] = 0xC003;  // 1100000000000011
+    DriverState.GraphicsCursor.ScreenMask[7] = 0xC007;  // 1100000000000111
+    DriverState.GraphicsCursor.ScreenMask[8] = 0xC01F;  // 1100000000011111
+    DriverState.GraphicsCursor.ScreenMask[9] = 0xC01F;  // 1100000000011111
+    DriverState.GraphicsCursor.ScreenMask[10] = 0xC00F; // 1100000000001111
+    DriverState.GraphicsCursor.ScreenMask[11] = 0xC60F; // 1100011000001111
+    DriverState.GraphicsCursor.ScreenMask[12] = 0xFF07; // 1111111100000111
+    DriverState.GraphicsCursor.ScreenMask[13] = 0xFF07; // 1111111100000111
+    DriverState.GraphicsCursor.ScreenMask[14] = 0xFF87; // 1111111110000111
+    DriverState.GraphicsCursor.ScreenMask[15] = 0xFFCF; // 1111111111001111
 
-            /* Initialize the resolution */
-            DriverState.MickeysPerCellHoriz = 8;
-            DriverState.MickeysPerCellVert = 16;
+    DriverState.GraphicsCursor.CursorMask[0] = 0x0000;  // 0000000000000000
+    DriverState.GraphicsCursor.CursorMask[1] = 0x1C00;  // 0001110000000000
+    DriverState.GraphicsCursor.CursorMask[2] = 0x1F00;  // 0001111100000000
+    DriverState.GraphicsCursor.CursorMask[3] = 0x1F80;  // 0001111110000000
+    DriverState.GraphicsCursor.CursorMask[4] = 0x1FE0;  // 0001111111100000
+    DriverState.GraphicsCursor.CursorMask[5] = 0x1FF0;  // 0001111111110000
+    DriverState.GraphicsCursor.CursorMask[6] = 0x1FF8;  // 0001111111111000
+    DriverState.GraphicsCursor.CursorMask[7] = 0x1FE0;  // 0001111111100000
+    DriverState.GraphicsCursor.CursorMask[8] = 0x1FC0;  // 0001111111000000
+    DriverState.GraphicsCursor.CursorMask[9] = 0x1FC0;  // 0001111111000000
+    DriverState.GraphicsCursor.CursorMask[10] = 0x19E0; // 0001100111100000
+    DriverState.GraphicsCursor.CursorMask[11] = 0x00E0; // 0000000011100000
+    DriverState.GraphicsCursor.CursorMask[12] = 0x0070; // 0000000001110000
+    DriverState.GraphicsCursor.CursorMask[13] = 0x0070; // 0000000001110000
+    DriverState.GraphicsCursor.CursorMask[14] = 0x0030; // 0000000000110000
+    DriverState.GraphicsCursor.CursorMask[15] = 0x0000; // 0000000000000000
 
-            /* Return mouse information */
+    /* Initialize the counters */
+    DriverState.HorizCount = DriverState.VertCount = 0;
+
+    for (i = 0; i < NUM_MOUSE_BUTTONS; i++)
+    {
+        DriverState.PressCount[i] = DriverState.ReleaseCount[i] = 0;
+    }
+
+    /* Initialize the resolution */
+    DriverState.MickeysPerCellHoriz = 8;
+    DriverState.MickeysPerCellVert = 8;
+    InitializeMouseRange();
+    /* Center Mouse cursor */
+    DosCursorSetPosition(DriverState.ScreenResolution.X / 2, DriverState.ScreenResolution.Y /2);
+    /* Return mouse information */
+    DriverEnabled = TRUE;
+}
+
+
+static VOID WINAPI DosMouseService(LPWORD Stack)
+{   /*int logevent=1; */
+    switch (getAX())
+    {
+            
+        /* Reset Driver */
+        case 0x00:
+        {
+            DosMouseReset();
             setAX(0xFFFF);  // Hardware & driver installed
             setBX(NUM_MOUSE_BUTTONS);
-
             break;
         }
 
@@ -278,14 +344,7 @@
         /* Position Mouse Cursor */
         case 0x04:
         {
-            POINT Point;
-
-            Point.x = getCX();
-            Point.y = getDX();
-
-            ClientToScreen(GetConsoleWindow(), &Point);
-            SetCursorPos(Point.x, Point.y);
-
+            DosCursorSetPosition(  getCX(),getDX());
             break;
         }
 
@@ -322,7 +381,28 @@
 
         }
 
-        /* Define Graphics Cursor */
+        /* Set  Horizontal Range */
+        case 0x07:
+        {
+            DriverState.MinX = getCX();
+            DriverState.MaxX = getDX();
+            if (DriverState.MinX>DriverState.MaxX){
+                DriverState.MinX = getDX();
+                DriverState.MaxX = getCX();
+            }
+        }
+    
+        /* Set  Vertical Range */
+        case 0x08:
+        {
+            DriverState.MinY = getCX();
+            DriverState.MaxY = getDX();
+            if (DriverState.MinY>DriverState.MaxY){
+                DriverState.MinY = getDX();
+                DriverState.MaxY = getCX();
+            }
+        }
+    
         case 0x09:
         {
             PWORD MaskBitmap = (PWORD)SEG_OFF_TO_PTR(getES(), getDX());
@@ -392,14 +472,14 @@
             break;
         }
 
-        /* Define Mickey/Pixel Ratio */
+        /* Define Mickey/Pixel Ratio  */
         case 0x0F:
         {
-            DriverState.MickeysPerCellHoriz = getCX();
-            DriverState.MickeysPerCellVert  = getDX();
+            /*  DriverState.MickeysPerCellHoriz = getCX();
+            DriverState.MickeysPerCellVert  = getDX(); */
             break;
         }
-
+       
         /* Exchange Interrupt Subroutines, compatible MS MOUSE v3.0+ (see function 0x0C) */
         case 0x14:
         {
@@ -604,27 +684,47 @@
             DPRINT1("BIOS Function INT 33h, AX = 0x%04X NOT IMPLEMENTED\n", getAX());
         }
     }
+  /* if (logevent) DPRINT1("Exiting DosMouseService AX:0x%04X BX:0x%04X CX:0x%04X DX:0x%04X  \n", getAX(), getBX(), getCX(), getDX());	*/
+    
+    
 }
 
 /* PUBLIC FUNCTIONS ***********************************************************/
 
 VOID DosMouseUpdatePosition(PCOORD NewPosition)
-{
-    SHORT DeltaX = NewPosition->X - DriverState.Position.X;
-    SHORT DeltaY = NewPosition->Y - DriverState.Position.Y;
-
+{   
+    SHORT DeltaX, DeltaY;
+    DeltaX = DeltaY = 0; 
     if (!DriverEnabled) return;
-
-    DriverState.HorizCount += (DeltaX * (SHORT)DriverState.MickeysPerCellHoriz) / 8;
-    DriverState.VertCount  += (DeltaY * (SHORT)DriverState.MickeysPerCellVert ) / 8;
-
-    if (DriverState.ShowCount > 0) EraseMouseCursor();
-    DriverState.Position = *NewPosition;
-    if (DriverState.ShowCount > 0) PaintMouseCursor();
-
-    /* Call the mouse handlers */
-    // if (DeltaX || DeltaY)
-    CallMouseUserHandlers(0x0001); // We use MS MOUSE v1.0+ format
+    /* HACK check video mode  */ 
+    if (DriverState.VideoMode != Bda->VideoMode){
+        InitializeMouseRange();
+     }
+    /*DPRINT1("DosMouseUpdatePosition Horizontal:0x%04d Vertical:0x%04d \n",NewPosition->X,NewPosition->Y);
+    DPRINT1("DosMouseUpdatePosition MickeysPerCellHoriz:0x%04d MickeysPerCellVert:0x%04d \n",DriverState.MickeysPerCellHoriz,DriverState.MickeysPerCellVert); */
+    if (NewPosition->X !=0) DeltaX = (NewPosition->X) / ((SHORT)DriverState.MickeysPerCellHoriz /8);
+    if (NewPosition->Y!=0)  DeltaY = (NewPosition->Y) /  ((SHORT)DriverState.MickeysPerCellVert /8);
+     /* no raw data in micky.... in text mode we have to multiply * 8 */
+     if (DriverState.VideoMode <= 3){
+         DeltaX *=8;
+         DeltaY *=8;
+    }
+    /*DPRINT1("DosMouseUpdatePosition DeltaX:0x%04d DeltaY:0x%04d \n",DeltaX,DeltaY); */
+    DriverState.HorizCount += DeltaX;
+    DriverState.VertCount  += DeltaY;
+    if (DeltaX || DeltaY){
+        if (DriverState.ShowCount > 0) EraseMouseCursor();
+        DriverState.Position.X += DeltaX;
+        DriverState.Position.Y += DeltaY;
+        /* 	Limit position to defined range */
+        if (DriverState.Position.X < DriverState.MinX)  DriverState.Position.X = DriverState.MinX;
+        if (DriverState.Position.X > DriverState.MaxX)  DriverState.Position.X = DriverState.MaxX;
+        if (DriverState.Position.Y < DriverState.MinY)  DriverState.Position.Y = DriverState.MinY;
+        if (DriverState.Position.Y > DriverState.MaxY)  DriverState.Position.Y = DriverState.MaxY;
+        if (DriverState.ShowCount > 0) PaintMouseCursor();
+        /* Call the mouse handlers */
+        CallMouseUserHandlers(0x0001); // We use MS MOUSE v1.0+ format
+    }
 }
 
 VOID DosMouseUpdateButtons(WORD ButtonState)
@@ -667,10 +767,9 @@
 {
     /* Clear the state */
     RtlZeroMemory(&DriverState, sizeof(DriverState));
-
     /* Initialize the interrupt handler */
     RegisterDosInt32(DOS_MOUSE_INTERRUPT, DosMouseService);
-
+    DosMouseReset();
     return TRUE;
 }
 
Index: subsystems/ntvdm/dos/mouse32.h
===================================================================
--- subsystems/ntvdm/dos/mouse32.h	(revision 66215)
+++ subsystems/ntvdm/dos/mouse32.h	(working copy)
@@ -49,6 +49,12 @@
     SHORT VertCount;
     WORD MickeysPerCellHoriz;
     WORD MickeysPerCellVert;
+    WORD MinX;
+    WORD MinY;
+    WORD MaxX;
+    WORD MaxY;
+    COORD ScreenResolution;
+    BYTE VideoMode;
 
     /*
      * User Subroutine Handlers called on mouse events
Index: subsystems/ntvdm/hardware/mouse.c
===================================================================
--- subsystems/ntvdm/hardware/mouse.c	(revision 66215)
+++ subsystems/ntvdm/hardware/mouse.c	(working copy)
@@ -11,6 +11,7 @@
 #define NDEBUG
 
 #include "mouse.h"
+#include "dos\mouse32.h"
 #include "ps2.h"
 // #include "pic.h"
 
@@ -17,10 +18,8 @@
 /* PRIVATE VARIABLES **********************************************************/
 
 static MOUSE_MODE Mode, PreviousMode;
-static COORD Position;
-static ULONG WidthMm, HeightMm, WidthPixels, HeightPixels;
 static ULONG SampleRate;
-static ULONG Resolution;
+static SHORT Resolution; 
 static BOOLEAN Scaling;
 static BOOLEAN Reporting;
 static BYTE MouseId;
@@ -27,8 +26,16 @@
 static ULONG ButtonState;
 static SHORT HorzCounter;
 static SHORT VertCounter;
-static CHAR ScrollCounter;
+static SHORT ScrollCounter;
+static MOUSE_PACKET MousePacket;
 
+//Emulation Variables
+static SHORT WidthPPI, HeightPPI, WidthPixels, HeightPixels;
+static SHORT MickeyPerPixelH; // in 1/100 mickey 
+static SHORT MickeyPerPixelW; // in 1/100 mickey  
+static SHORT EmuResolution;  // CPI
+static PCOORD Position; // windows use absolute position 
+static PCOORD RelativePosition;
 static BYTE PS2Port = 1;
 
 /* PRIVATE FUNCTIONS **********************************************************/
@@ -42,6 +49,42 @@
     Reporting = FALSE;
 }
 
+static VOID MouseEmulationResetConfig(VOID)
+{
+    HWND hWnd;
+    HDC hDC;
+    EmuResolution = 96;
+    MickeyPerPixelH = 100;
+    MickeyPerPixelW = 100;
+    
+    /* Get the console window */
+    hWnd = GetConsoleWindow();
+    if (hWnd == NULL) return ;
+
+    /* Get the console window's device context */
+    hDC = GetWindowDC(hWnd);
+    if (hDC == NULL) return ;
+
+    /* Get the parameters */
+    WidthPPI      = (SHORT)GetDeviceCaps(hDC, LOGPIXELSX);
+    HeightPPI     = (SHORT)GetDeviceCaps(hDC, LOGPIXELSY);
+    WidthPixels  = (SHORT)GetDeviceCaps(hDC, HORZRES);
+    HeightPixels = (SHORT)GetDeviceCaps(hDC, VERTRES); 
+    
+    /* mouse at  96 CPI monitor 96 PPI 1:1 , PPI : CPI = 1 :x  */
+    
+    MickeyPerPixelH =  EmuResolution *100 / WidthPPI;
+    MickeyPerPixelW = EmuResolution *100 / HeightPPI;
+    
+     /* DPRINT("DC size: WPPI:%04u HPPI:%04u,Wpix:%04u Hpix:%04u\n",WidthPPI,HeightPPI,WidthPixels,HeightPixels);	
+       DPRINT("Cent MickeyPerPixel:  W:%04u, H:%04u ",MickeyPerPixelH,MickeyPerPixelW); */
+     
+     
+     // should release this
+    Position = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(COORD));
+    RelativePosition = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(COORD));
+}
+
 static VOID MouseResetCounters(VOID)
 {
     /* Reset all flags and counters */
@@ -63,9 +106,9 @@
     PS2QueuePush(PS2Port, MouseId);
 }
 
-#if 0
 static VOID MouseGetPacket(PMOUSE_PACKET Packet)
 {
+
     /* Clear the packet */
     RtlZeroMemory(Packet, sizeof(*Packet));
 
@@ -107,33 +150,62 @@
     if (MouseId >= 3)
     {
         /* Set the scroll counter */
-        Packet->Extra |= (UCHAR)ScrollCounter & 0x0F;
+        Packet->Extra |= ScrollCounter & 0x0F;
     }
 
     /* Store the counters in the packet */
     Packet->HorzCounter = LOBYTE(HorzCounter);
     Packet->VertCounter = LOBYTE(VertCounter);
-
-    /* Reset the counters */
-    MouseResetCounters();
 }
-#endif
 
 /*static*/ VOID MouseUpdatePosition(PCOORD NewPosition)
 {
     /* Update the counters */
-    HorzCounter += ((NewPosition->X - Position.X) * WidthMm  * Resolution) / WidthPixels;
-    VertCounter += ((NewPosition->Y - Position.Y) * HeightMm * Resolution) / HeightPixels;
+    VertCounter += NewPosition->X ;
+    HorzCounter += NewPosition->Y ;
+}
 
-    /* Update the position */
-    Position = *NewPosition;
+static PCOORD EmulateRelativePosition(PCOORD NewPosition){
+    /* Calculate a Relative position in Mickey */
+    RelativePosition->X = (NewPosition->X - Position->X) * MickeyPerPixelH /100;
+    RelativePosition->Y = (NewPosition->Y - Position->Y) * MickeyPerPixelW /100;
+    Position->X=NewPosition->X;
+    Position->Y=NewPosition->Y;
+    return RelativePosition;
 }
 
+
 /*static*/ VOID MouseUpdateButtons(ULONG NewButtonState)
 {
     ButtonState = NewButtonState;
 }
 
+static VOID MouseSendPacket(VOID) {
+    MouseGetPacket(&MousePacket);
+    /* HACK  Bypass PS/2 and call the driver with raw data
+       PS2QueuePush(PS2Port, MousePacket.Flags);
+      PS2QueuePush(PS2Port, MousePacket.HorzCounter);
+      PS2QueuePush(PS2Port, MousePacket.VertCounter);
+      PS2QueuePush(PS2Port, MousePacket.Extra);
+     */
+    DosMouseUpdatePosition(RelativePosition);
+    DosMouseUpdateButtons(ButtonState);
+    MouseResetCounters();
+}
+
+
+static VOID MouseResendPacket(VOID) {
+    
+    /*  Bypass PS/2
+    PS2QueuePush(PS2Port, MousePacket.Flags);
+    PS2QueuePush(PS2Port, MousePacket.HorzCounter);
+    PS2QueuePush(PS2Port, MousePacket.VertCounter);
+    PS2QueuePush(PS2Port, MousePacket.Extra);
+      */
+    return;
+}
+
+
 /*static*/ VOID MouseScroll(LONG Direction)
 {
     ScrollCounter += Direction;
@@ -141,7 +213,7 @@
 
 /*static*/ COORD MouseGetPosition(VOID)
 {
-    return Position;
+    return *Position;
 }
 
 static VOID WINAPI MouseCommand(LPVOID Param, BYTE Command)
@@ -283,8 +355,7 @@
         /* Resend */
         case 0xFE:
         {
-            // TODO: NOT IMPLEMENTED
-            UNIMPLEMENTED;
+            MouseResendPacket();
             break;
         }
 
@@ -305,44 +376,22 @@
 
 /* PUBLIC FUNCTIONS ***********************************************************/
 
+// FIXME: We need raw data in mickey not in pixel or Cell!
 VOID MouseEventHandler(PMOUSE_EVENT_RECORD MouseEvent)
 {
-extern COORD DosNewPosition;
-extern WORD  DosButtonState;
-
-    // FIXME: Sync our private data
-    MouseUpdatePosition(&MouseEvent->dwMousePosition);
+    /* We should calcolate a relative position for now
+       MouseUpdatePosition(&MouseEvent->dwMousePosition); */
+    MouseUpdatePosition(EmulateRelativePosition(&MouseEvent->dwMousePosition));
+    
     MouseUpdateButtons(MouseEvent->dwButtonState);
-
-    // HACK: Bypass PS/2 and instead, notify the MOUSE.COM driver directly
-    DosNewPosition = MouseEvent->dwMousePosition;
-    DosButtonState = LOWORD(MouseEvent->dwButtonState);
-
-    // PS2QueuePush(PS2Port, Data);
+    
+    // FIXME check mode and timed packet send missing
+    MouseSendPacket();
 }
 
 BOOLEAN MouseInit(BYTE PS2Connector)
 {
-    HWND hWnd;
-    HDC hDC;
-
-    /* Get the console window */
-    hWnd = GetConsoleWindow();
-    if (hWnd == NULL) return FALSE;
-
-    /* Get the console window's device context */
-    hDC = GetWindowDC(hWnd);
-    if (hDC == NULL) return FALSE;
-
-    /* Get the parameters */
-    WidthMm      = (ULONG)GetDeviceCaps(hDC, HORZSIZE);
-    HeightMm     = (ULONG)GetDeviceCaps(hDC, VERTSIZE);
-    WidthPixels  = (ULONG)GetDeviceCaps(hDC, HORZRES);
-    HeightPixels = (ULONG)GetDeviceCaps(hDC, VERTRES);
-
-    /* Release the device context */
-    ReleaseDC(hWnd, hDC);
-
+    MouseEmulationResetConfig();
     /* Finish to plug the mouse to the specified PS/2 port */
     PS2Port = PS2Connector;
     PS2SetDeviceCmdProc(PS2Port, NULL, MouseCommand);
