| 151 | } |
| 152 | |
| 153 | uint32_t ps2_read_data(void *opaque) |
| 154 | { |
| 155 | PS2State *s = (PS2State *)opaque; |
| 156 | PS2Queue *q; |
| 157 | int val, index; |
| 158 | |
| 159 | q = &s->queue; |
| 160 | if (q->count == 0) { |
| 161 | /* NOTE: if no data left, we return the last keyboard one |
| 162 | (needed for EMM386) */ |
| 163 | /* XXX: need a timer to do things correctly */ |
| 164 | index = q->rptr - 1; |
| 165 | if (index < 0) |
| 166 | index = PS2_QUEUE_SIZE - 1; |
| 167 | val = q->data[index]; |
| 168 | } else { |
| 169 | val = q->data[q->rptr]; |
| 170 | if (++q->rptr == PS2_QUEUE_SIZE) |
| 171 | q->rptr = 0; |
| 172 | q->count--; |
| 173 | /* reading deasserts IRQ */ |
| 174 | s->update_irq(s->update_arg, 0); |
| 175 | /* reassert IRQs if data left */ |
| 176 | s->update_irq(s->update_arg, q->count != 0); |
| 177 | } |
| 178 | return val; |
| 179 | } |
| 180 | |
| 181 | static void ps2_reset_keyboard(PS2KbdState *s) |
| 182 | { |