static void sunmouse_event(void *opaque,

                               int dx, int dy, int dz, int buttons_state)

{

    ChannelState *s = opaque;

    int ch;



    MS_DPRINTF("dx=%d dy=%d buttons=%01x\n", dx, dy, buttons_state);



    ch = 0x80 | 0x7; /* protocol start byte, no buttons pressed */



    if (buttons_state & MOUSE_EVENT_LBUTTON)

        ch ^= 0x4;

    if (buttons_state & MOUSE_EVENT_MBUTTON)

        ch ^= 0x2;

    if (buttons_state & MOUSE_EVENT_RBUTTON)

        ch ^= 0x1;



    put_queue(s, ch);



    ch = dx;



    if (ch > 127)

        ch=127;

    else if (ch < -127)

        ch=-127;



    put_queue(s, ch & 0xff);



    ch = -dy;



    if (ch > 127)

        ch=127;

    else if (ch < -127)

        ch=-127;



    put_queue(s, ch & 0xff);



    // MSC protocol specify two extra motion bytes



    put_queue(s, 0);

    put_queue(s, 0);

}

static void sunmouse_event(void *opaque,

                               int dx, int dy, int dz, int buttons_state)

{

    ChannelState *s = opaque;

    int ch;



    MS_DPRINTF("dx=%d dy=%d buttons=%01x\n", dx, dy, buttons_state);



    ch = 0x80 | 0x7; 



    if (buttons_state & MOUSE_EVENT_LBUTTON)

        ch ^= 0x4;

    if (buttons_state & MOUSE_EVENT_MBUTTON)

        ch ^= 0x2;

    if (buttons_state & MOUSE_EVENT_RBUTTON)

        ch ^= 0x1;



    put_queue(s, ch);



    ch = dx;



    if (ch > 127)

        ch=127;

    else if (ch < -127)

        ch=-127;



    put_queue(s, ch & 0xff);



    ch = -dy;



    if (ch > 127)

        ch=127;

    else if (ch < -127)

        ch=-127;



    put_queue(s, ch & 0xff);



    



    put_queue(s, 0);

    put_queue(s, 0);

}

static void FUNC_0(void *VAR_0,

                               int VAR_1, int VAR_2, int VAR_3, int VAR_4)

{

    ChannelState *s = VAR_0;

    int VAR_5;



    MS_DPRINTF("VAR_1=%d VAR_2=%d buttons=%01x\n", VAR_1, VAR_2, VAR_4);



    VAR_5 = 0x80 | 0x7; 



    if (VAR_4 & MOUSE_EVENT_LBUTTON)

        VAR_5 ^= 0x4;

    if (VAR_4 & MOUSE_EVENT_MBUTTON)

        VAR_5 ^= 0x2;

    if (VAR_4 & MOUSE_EVENT_RBUTTON)

        VAR_5 ^= 0x1;



    put_queue(s, VAR_5);



    VAR_5 = VAR_1;



    if (VAR_5 > 127)

        VAR_5=127;

    else if (VAR_5 < -127)

        VAR_5=-127;



    put_queue(s, VAR_5 & 0xff);



    VAR_5 = -VAR_2;



    if (VAR_5 > 127)

        VAR_5=127;

    else if (VAR_5 < -127)

        VAR_5=-127;



    put_queue(s, VAR_5 & 0xff);



    



    put_queue(s, 0);

    put_queue(s, 0);

}

static void FUNC_0(void *VAR_0,
int VAR_1, int VAR_2, int VAR_3, int VAR_4)
{ ChannelState *s = VAR_0; int VAR_5; MS_DPRINTF("VAR_1=%d VAR_2=%d buttons=%01x\n", VAR_1, VAR_2, VAR_4); VAR_5 = 0x80 | 0x7; if (VAR_4 & MOUSE_EVENT_LBUTTON)
VAR_5 ^= 0x4; if (VAR_4 & MOUSE_EVENT_MBUTTON)
VAR_5 ^= 0x2; if (VAR_4 & MOUSE_EVENT_RBUTTON)
VAR_5 ^= 0x1; put_queue(s, VAR_5); VAR_5 = VAR_1; if (VAR_5 > 127)
VAR_5=127; else if (VAR_5 < -127)
VAR_5=-127; put_queue(s, VAR_5 & 0xff); VAR_5 = -VAR_2; if (VAR_5 > 127)
VAR_5=127; else if (VAR_5 < -127)
VAR_5=-127; put_queue(s, VAR_5 & 0xff); put_queue(s, 0); put_queue(s, 0); }