Statistics
| Branch: | Revision:

root / hw / msmouse.c @ 7830cf78

History | View | Annotate | Download (2.7 kB)

1 aa71cf80 aurel32
/*
2 aa71cf80 aurel32
 * QEMU Microsoft serial mouse emulation
3 aa71cf80 aurel32
 *
4 aa71cf80 aurel32
 * Copyright (c) 2008 Lubomir Rintel
5 aa71cf80 aurel32
 *
6 aa71cf80 aurel32
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 aa71cf80 aurel32
 * of this software and associated documentation files (the "Software"), to deal
8 aa71cf80 aurel32
 * in the Software without restriction, including without limitation the rights
9 aa71cf80 aurel32
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 aa71cf80 aurel32
 * copies of the Software, and to permit persons to whom the Software is
11 aa71cf80 aurel32
 * furnished to do so, subject to the following conditions:
12 aa71cf80 aurel32
 *
13 aa71cf80 aurel32
 * The above copyright notice and this permission notice shall be included in
14 aa71cf80 aurel32
 * all copies or substantial portions of the Software.
15 aa71cf80 aurel32
 *
16 aa71cf80 aurel32
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 aa71cf80 aurel32
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 aa71cf80 aurel32
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 aa71cf80 aurel32
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 aa71cf80 aurel32
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 aa71cf80 aurel32
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 aa71cf80 aurel32
 * THE SOFTWARE.
23 aa71cf80 aurel32
 */
24 aa71cf80 aurel32
#include <stdlib.h>
25 28ecbaee Paolo Bonzini
#include "qemu-common.h"
26 927d4878 Paolo Bonzini
#include "char/char.h"
27 28ecbaee Paolo Bonzini
#include "ui/console.h"
28 aa71cf80 aurel32
29 aa71cf80 aurel32
#define MSMOUSE_LO6(n) ((n) & 0x3f)
30 aa71cf80 aurel32
#define MSMOUSE_HI2(n) (((n) & 0xc0) >> 6)
31 aa71cf80 aurel32
32 aa71cf80 aurel32
static void msmouse_event(void *opaque,
33 aa71cf80 aurel32
                          int dx, int dy, int dz, int buttons_state)
34 aa71cf80 aurel32
{
35 aa71cf80 aurel32
    CharDriverState *chr = (CharDriverState *)opaque;
36 aa71cf80 aurel32
37 aa71cf80 aurel32
    unsigned char bytes[4] = { 0x40, 0x00, 0x00, 0x00 };
38 aa71cf80 aurel32
39 aa71cf80 aurel32
    /* Movement deltas */
40 aa71cf80 aurel32
    bytes[0] |= (MSMOUSE_HI2(dy) << 2) | MSMOUSE_HI2(dx);
41 aa71cf80 aurel32
    bytes[1] |= MSMOUSE_LO6(dx);
42 aa71cf80 aurel32
    bytes[2] |= MSMOUSE_LO6(dy);
43 aa71cf80 aurel32
44 aa71cf80 aurel32
    /* Buttons */
45 aa71cf80 aurel32
    bytes[0] |= (buttons_state & 0x01 ? 0x20 : 0x00);
46 aa71cf80 aurel32
    bytes[0] |= (buttons_state & 0x02 ? 0x10 : 0x00);
47 aa71cf80 aurel32
    bytes[3] |= (buttons_state & 0x04 ? 0x20 : 0x00);
48 aa71cf80 aurel32
49 aa71cf80 aurel32
    /* We always send the packet of, so that we do not have to keep track
50 aa71cf80 aurel32
       of previous state of the middle button. This can potentially confuse
51 aa71cf80 aurel32
       some very old drivers for two button mice though. */
52 fa5efccb Anthony Liguori
    qemu_chr_be_write(chr, bytes, 4);
53 aa71cf80 aurel32
}
54 aa71cf80 aurel32
55 aa71cf80 aurel32
static int msmouse_chr_write (struct CharDriverState *s, const uint8_t *buf, int len)
56 aa71cf80 aurel32
{
57 aa71cf80 aurel32
    /* Ignore writes to mouse port */
58 aa71cf80 aurel32
    return len;
59 aa71cf80 aurel32
}
60 aa71cf80 aurel32
61 aa71cf80 aurel32
static void msmouse_chr_close (struct CharDriverState *chr)
62 aa71cf80 aurel32
{
63 7267c094 Anthony Liguori
    g_free (chr);
64 aa71cf80 aurel32
}
65 aa71cf80 aurel32
66 5ab8211b Anthony Liguori
static CharDriverState *qemu_chr_open_msmouse(QemuOpts *opts)
67 aa71cf80 aurel32
{
68 aa71cf80 aurel32
    CharDriverState *chr;
69 aa71cf80 aurel32
70 7267c094 Anthony Liguori
    chr = g_malloc0(sizeof(CharDriverState));
71 aa71cf80 aurel32
    chr->chr_write = msmouse_chr_write;
72 aa71cf80 aurel32
    chr->chr_close = msmouse_chr_close;
73 aa71cf80 aurel32
74 aa71cf80 aurel32
    qemu_add_mouse_event_handler(msmouse_event, chr, 0, "QEMU Microsoft Mouse");
75 aa71cf80 aurel32
76 1f51470d Markus Armbruster
    return chr;
77 aa71cf80 aurel32
}
78 5ab8211b Anthony Liguori
79 5ab8211b Anthony Liguori
static void register_types(void)
80 5ab8211b Anthony Liguori
{
81 5ab8211b Anthony Liguori
    register_char_driver("msmouse", qemu_chr_open_msmouse);
82 5ab8211b Anthony Liguori
}
83 5ab8211b Anthony Liguori
84 5ab8211b Anthony Liguori
type_init(register_types);