Qemu-0.8.0-openstep-busmouse-2.diff

From Computer History Wiki
Revision as of 13:39, 4 July 2009 by Neozeed (talk | contribs) (initial version)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

This diff adds busmouse support to Qemu 0.8.0

Caveat

There may be some wordwrap issues as I just copied this out of a terminal... But this diff is too important to lose!

Credit

Full credit goes to Michael Engel who uploaded this diff onto the Qemu-devel list

Dr. rer. nat. Michael Engel   - [EMAIL PROTECTED]
University of Marburg         - Dept. of Mathematics and Computer Science
Hans-Meerwein-Str.            - D-35032 Marburg, Germany
Phone: +49 6421 / 28 21562    - Fax: +49 6421 / 28 21573

diff

diff -urN qemu-0.8.0/Makefile.target qemu-0.8.0-openstep/Makefile.target
--- qemu-0.8.0/Makefile.target  2005-12-19 23:51:53.000000000 +0100
+++ qemu-0.8.0-openstep/Makefile.target 2005-12-30 20:19:21.000000000 +0100
@@ -308,7 +308,7 @@
 # Hardware support
 VL_OBJS+= ide.o ne2000.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
 VL_OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pc.o
-VL_OBJS+= cirrus_vga.o mixeng.o apic.o parallel.o
+VL_OBJS+= cirrus_vga.o mixeng.o apic.o parallel.o busmouse.o
 DEFINES += -DHAS_AUDIO
 endif
 ifeq ($(TARGET_BASE_ARCH), ppc)
diff -urN qemu-0.8.0/hw/busmouse.c qemu-0.8.0-openstep/hw/busmouse.c
--- qemu-0.8.0/hw/busmouse.c    1970-01-01 01:00:00.000000000 +0100
+++ qemu-0.8.0-openstep/hw/busmouse.c   2006-01-01 19:33:33.000000000 +0100
@@ -0,0 +1,160 @@
+/*
+ * QEMU Busmouse emulation
+ *
+ * Copyright (c) 2005 Michael Engel (engel-at-informatik.uni-marburg.de)
+ * using hints from parallel.c and ps2.c
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM
,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "vl.h"
+
+/*
+ * These are the definitions for the busmouse controller registers
+ * and internal state
+ */
+
+struct BusmouseState {
+    uint8_t data;
+    uint8_t signature;
+    uint8_t control;
+    uint8_t interrupt;
+    uint8_t config;
+    uint8_t command;
+    int irq;
+    int irq_pending;
+    CharDriverState *chr;
+    int hw_driver;
+    uint16_t mouse_dx;
+    uint16_t mouse_dy;
+    uint16_t mouse_dz;
+    uint16_t mouse_buttons;
+};
+
+static void busmouse_update_irq(BusmouseState *s);
+
+static void busmouse_event(void *opaque,
+                            int dx, int dy, int dz, int buttons_state)
+{
+    BusmouseState *s = opaque;
+
+    s->mouse_dx += dx;
+    s->mouse_dy += dy;
+    s->mouse_dz += dz;
+    /* XXX: SDL sometimes generates nul events: we delete them */
+    if (s->mouse_dx == 0 && s->mouse_dy == 0 && s->mouse_dz == 0 &&
+        s->mouse_buttons == buttons_state)
+       return;
+    s->mouse_buttons = buttons_state;
+
+    s->irq_pending = 1;
+    busmouse_update_irq(s);
+}
+
+static void busmouse_update_irq(BusmouseState *s)
+{
+    if (s->irq_pending)
+        pic_set_irq(s->irq, 1);
+    else
+        pic_set_irq(s->irq, 0);
+}
+
+static void busmouse_ioport_write(void *opaque, uint32_t addr, uint32_t val)
+{
+    BusmouseState *s = opaque;
+
+    addr &= 0xf;
+    switch(addr) {
+    case 0xc: /* data port */
+        break;
+    case 0xd: /* signature port */
+        break;
+    case 0xe: /* control/interrupt port */
+        s->command = val;
+        break;
+    case 0xf: /* config port */
+        break;
+    }
+}
+
+static uint32_t busmouse_ioport_read(void *opaque, uint32_t addr)
+{
+    BusmouseState *s = opaque;
+    uint32_t ret = 0x00;
+    static int interrupt_val = 0x01;
+
+    addr &= 0xf;
+    switch(addr) {
+    case 0xc: /* data port */
+        s->irq_pending = 0;
+        switch (s->command) {
+        case 0x00: /* no op? */
+            break;
+        case 0x80: /* x low */
+            ret = s->mouse_dx & 0xf;
+            ret += (7 - s->mouse_buttons) << 5; /* button state */
+            break;
+        case 0xa0: /* x high */
+            ret = (s->mouse_dx >> 4) & 0xf;
+            s->mouse_dx = 0;
+            break;
+        case 0xc0: /* y low */
+            ret = s->mouse_dy & 0xf;
+            break;
+        case 0xe0: /* y high */
+            ret =  (s->mouse_dy >> 4) & 0xf;
+            s->mouse_dy = 0;
+            break;
+        }
+        busmouse_update_irq(s);
+        break;
+    case 0xd: /* signature port */
+        ret = 0xa5; /* return signature byte */
+        busmouse_update_irq(s);
+        break;
+    case 0xe: /* control/interrupt port */
+        ret = interrupt_val;
+        interrupt_val = (interrupt_val << 1) & 0xff;
+        if (interrupt_val == 0) interrupt_val = 1;
+
+        break;
+    case 0xf: /* config port */
+        break;
+    }
+    return ret;
+}
+
+/* If fd is zero, it means that the busmouse device uses the console */
+BusmouseState *busmouse_init(int base, int irq, CharDriverState *chr)
+{
+    BusmouseState *s;
+
+    s = qemu_mallocz(sizeof(BusmouseState));
+    if (!s)
+        return NULL;
+    s->chr = chr;
+    s->hw_driver = 0;
+    s->irq = irq;
+    s->data = 0;
+    s->mouse_buttons = 0x0;
+    register_ioport_write(base, 8, 1, busmouse_ioport_write, s);
+    register_ioport_read(base, 8, 1, busmouse_ioport_read, s);
+    qemu_add_mouse_event_handler(busmouse_event, s);
+
+    return s;
+}
diff -urN qemu-0.8.0/hw/pc.c qemu-0.8.0-openstep/hw/pc.c
--- qemu-0.8.0/hw/pc.c  2005-12-19 23:51:53.000000000 +0100
+++ qemu-0.8.0-openstep/hw/pc.c 2006-01-01 18:22:58.000000000 +0100
@@ -574,6 +574,9 @@
 static int parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc };
 static int parallel_irq[MAX_PARALLEL_PORTS] = { 7, 7, 7 };

+static int busmouse_io[MAX_BUSMOUSE_PORTS] = { 0x238 };
+static int busmouse_irq[MAX_BUSMOUSE_PORTS] = { 5 };
+
 #ifdef HAS_AUDIO
 static void audio_init (PCIBus *pci_bus)
 {
@@ -800,6 +803,10 @@
         }
     }

+    for(i = 0; i < 1; i++) {
+        busmouse_init(busmouse_io[i], busmouse_irq[i], 0);
+    }
+
     if (pci_enabled) {
         for(i = 0; i < nb_nics; i++) {
             pci_ne2000_init(pci_bus, &nd_table[i]);
diff -urN qemu-0.8.0/hw/ps2.c qemu-0.8.0-openstep/hw/ps2.c
--- qemu-0.8.0/hw/ps2.c 2005-12-19 23:51:53.000000000 +0100
+++ qemu-0.8.0-openstep/hw/ps2.c        2006-01-01 18:25:49.000000000 +0100
@@ -506,7 +506,9 @@
     s->common.update_arg = update_arg;
     ps2_reset(&s->common);
     register_savevm("ps2mouse", 0, 1, ps2_mouse_save, ps2_mouse_load, s);
-    qemu_add_mouse_event_handler(ps2_mouse_event, s);
+
+    /* disabled for busmouse emulation (req'd for running OpenStep) */
+    /* qemu_add_mouse_event_handler(ps2_mouse_event, s); */
     qemu_register_reset(ps2_reset, &s->common);
     return s;
 }
diff -urN qemu-0.8.0/vl.h qemu-0.8.0-openstep/vl.h
--- qemu-0.8.0/vl.h     2005-12-19 23:51:53.000000000 +0100
+++ qemu-0.8.0-openstep/vl.h    2006-01-01 18:14:28.000000000 +0100
@@ -271,6 +271,10 @@

 #define MAX_PARALLEL_PORTS 3

+/* busmouse ports */
+
+#define MAX_BUSMOUSE_PORTS 1
+
 extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];

 /* VLANs support */
@@ -755,6 +759,11 @@
 typedef struct ParallelState ParallelState;
 ParallelState *parallel_init(int base, int irq, CharDriverState *chr);

+/* busmouse.c */
+
+typedef struct BusmouseState BusmouseState;
+BusmouseState *busmouse_init(int base, int irq, CharDriverState *chr);
+
 /* i8259.c */

 typedef struct PicState2 PicState2;