> @@ -137,7 +139,7 @@ void ps2_queue(void *opaque, int b) > PS2State *s = (PS2State *)opaque; > PS2Queue *q = &s->queue; > > - if (q->count >= PS2_QUEUE_SIZE) > + if (q->count >= PS2_QUEUE_SIZE - 1)
Why? > if (!(s->mouse_status & MOUSE_STATUS_REMOTE) && > - (s->common.queue.count < (PS2_QUEUE_SIZE - 16))) { > + (s->common.queue.count < PS2_QUEUE_SIZE)) { To me this looks like an attempt to make sure the queue has enough space for the whole mouse message. Message size is 3 or 4 bytes (depending on mode), so I think we should make that "... < (PS2_QUEUE_SIZE-4)". > for(;;) { > /* if not remote, send event. Multiple events are sent if > too big deltas */ ... and move the check into the loop. Or, maybe even better, into the ps2_mouse_send_packet() function. > + for (i = 0; i < size; i++) { > + /* move the queue elements to the temporary buffer */ > + tmp_data[i] = q->data[q->rptr]; > + if (++q->rptr == 256) { > + q->rptr = 0; > + } > + } > + /* move the queue elements to the start of data array */ > + if (size > 0) { > + memcpy(q->data, tmp_data, size); > + } You can move the loop into the "if (size > 0) { ... }" section. > static const VMStateDescription vmstate_ps2_mouse = { > .name = "ps2mouse", > .version_id = 2, > .minimum_version_id = 2, > .minimum_version_id_old = 2, > + .post_load = ps2_mouse_post_load, You have to call ps2_common_post_load in pre_save too. cheers, Gerd