Received: from eggs.gnu.org ([2001:4830:134:3::10]:56339) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aecI8-0002Py-3o for qemu-devel@nongnu.org; Sat, 12 Mar 2016 00:40:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aecI4-0007Gc-39 for qemu-devel@nongnu.org; Sat, 12 Mar 2016 00:40:44 -0500 Received: from mail-io0-x243.google.com ([2607:f8b0:4001:c06::243]:34022) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aecI3-0007GS-Sq for qemu-devel@nongnu.org; Sat, 12 Mar 2016 00:40:39 -0500 Received: by mail-io0-x243.google.com with SMTP id z76so13085872iof.1 for ; Fri, 11 Mar 2016 21:40:39 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Programmingkid In-Reply-To: Date: Sat, 12 Mar 2016 00:40:37 -0500 Content-Transfer-Encoding: quoted-printable Message-Id: <41EC2072-FB9D-4003-A0CB-1DBFA0B2A27D@gmail.com> References: <8768A4C2-CEBF-411A-9B43-9F43EA755238@gmail.com> Subject: Re: [Qemu-devel] [PATCH v4 4/4] hw/input/adb.c: implement QKeyCode support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Gerd Hoffmann , qemu-devel qemu-devel On Mar 11, 2016, at 10:30 PM, Peter Maydell wrote: >=20 >> + } >> + keycode =3D s->data[s->rptr]; >> + if (++s->rptr =3D=3D sizeof(s->data)) { >> + s->rptr =3D 0; >> } >> + s->count--; >> + >> + obuf[0] =3D keycode; >=20 > You are still trying to put a two byte keycode (ADB_KEY_POWER) > into this one-byte array slot. I don't know what the right way to > send a two-byte keycode is but this is obviously not it, as > I said before. >=20 >> + /* NOTE: could put a second keycode if needed */ >> + obuf[1] =3D 0xff; >> + olen =3D 2; >> + >> return olen; >> } Is this ok? /* The power key is the only two byte value key, so it is a special = case. */ if (keycode =3D=3D (ADB_KEY_POWER & 0x00ff)) { obuf[0] =3D ADB_KEY_POWER & 0x00ff; obuf[1] =3D ADB_KEY_POWER & 0xff00 >> 8; olen =3D 2; } else { obuf[0] =3D keycode; /* NOTE: could put a second keycode if needed */ obuf[1] =3D 0xff; olen =3D 2; } The keycode value comes from an 8 bit array so holding the full value of = the power key is not possible. That is the reason for the "if (keycode = =3D=3D (ADB_KEY_POWER & 0x00ff))".=20 The code might be a little more efficient if we did this: /* The power key is the only two byte value key, so it is a special = case. */ if (keycode =3D=3D 0x7f) { obuf[0] =3D 0x7f; obuf[1] =3D 0x7f; olen =3D 2; } else { obuf[0] =3D keycode; /* NOTE: could put a second keycode if needed */ obuf[1] =3D 0xff; olen =3D 2; } The speed difference isn't noticeable so either way works well.=