 
 M: dinput-game-input-backend reset-mouse
     +mouse-device+ get [ f MOUSE-BUFFER-SIZE read-device-buffer ]
-    [ 2drop ] [ ] with-acquisition ;
+    [ 2drop ] [ ] with-acquisition
+    +mouse-state+ get
+        0 >>dx
+        0 >>dy
+        0 >>scroll-dx
+        0 >>scroll-dy
+        drop ;

    [ "DIDEVICEOBJECTDATA" heap-size ] 2dip <uint>
    [ 0 IDirectInputDevice8W::GetDeviceData ole32-error ] 2keep *uint ;

: (fill-mouse-state) ( state DIDEVICEOBJECTDATA -- )
    [ DIDEVICEOBJECTDATA-dwData ] [ DIDEVICEOBJECTDATA-dwOfs ] bi {
        { DIMOFS_X [ [ + ] curry change-dx drop ] }
        { DIMOFS_Y [ [ + ] curry change-dy drop ] }
        { DIMOFS_Z [ [ + ] curry change-scroll-dy drop ] }
        [ [ c-bool> ] [ DIMOFS_BUTTON0 - ] bi* rot buttons>> set-nth ] 
    } case ;

: fill-mouse-state ( buffer count -- )
    [ +mouse-state+ get ] 2dip swap
    [ DIDEVICEOBJECTDATA-nth (fill-mouse-state) ] curry each ;

: get-device-state ( device byte-array -- )
    [ dup IDirectInputDevice8W::Poll ole32-error ] dip

math.rectangles accessors math alien alien.strings
io.encodings.utf16 io.encodings.utf16n continuations
byte-arrays game-input.dinput.keys-array game-input
ui.backend.windows windows.errors struct-arrays
math.bitwise ;
IN: game-input.dinput

CONSTANT: MOUSE-BUFFER-SIZE 16
