Mouse issues under Windows and modifying keycodes (SOLVED)

About Qemu-system-ppc, a PPC Mac emulator for Windows, macOS and Linux that can run Mac OS 9.0 up to Mac OS X 10.5

Moderators: Cat_7, Ronald P. Regensburg

Post Reply
User avatar
siddhartha
Student Driver
Posts: 16
Joined: Wed Nov 30, 2022 12:59 am

Mouse issues under Windows and modifying keycodes (SOLVED)

Post by siddhartha »

I have long been dealing with terrible mouse performance under Windows emulating OS 9.2.2. In a 800x600 guest, rarely would the QEMU mouse cursor be anywhere near the Windows mouse on the screen and I would have to resort to flicking my mouse to get the QEMU mouse cursor to get to the corners or edges of my Mac guest. This was especially annoying when VNCing into my host machine to control QEMU from my iPad. Finally, I found a solution:

The trick is to not run QEMU with:

Code: Select all

via=pmu
Instead use:

Code: Select all

via=cuda
This will force an ADB keyboard and mouse in the guest instead of USB.

Also, I was never able to get QEMU to read any keymaps properly. I guess that's only for Linux hosts. I always wanted the guest Command key to be the host's Ctrl key to match SheepShaver (and again to play nicely with VNC). Luckily, since we are now using an ADB keyboard, we can modify hw/input/adb-kbd.c and swap around:

Code: Select all

    [Q_KEY_CODE_CTRL]          = ADB_KEY_COMMAND,
    [Q_KEY_CODE_CTRL_R]        = ADB_KEY_COMMAND,
    [Q_KEY_CODE_META_L]        = ADB_KEY_LEFT_CONTROL,
    [Q_KEY_CODE_META_R]        = ADB_KEY_RIGHT_CONTROL,
Hopefully at least the cuda setting will help some users.
User avatar
Cat_7
Expert User
Posts: 6172
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: Mouse issues under Windows and modifying keycodes (SOLVED)

Post by Cat_7 »

Hi,

Thanks for the suggestions. Using adb mouse/kbd can result in jumpy behaviour when under load.
You say the mouse doesn't follow the host pointer. Were you running the default -display gtk? This has the issues you describe in Windows.
We suggest using -display sdl on Windows hosts. Whether this is possible with vnc I don't know.

You do not need to set ,via=cuda is that is the default setting.

Sheepshaver/Basilisk use an sdl keycodes file to map the keys. I have no idea whether qemu can also be set or made to use such a file.

Best,
Cat_7
User avatar
siddhartha
Student Driver
Posts: 16
Joined: Wed Nov 30, 2022 12:59 am

Re: Mouse issues under Windows and modifying keycodes (SOLVED)

Post by siddhartha »

Cat_7 wrote: Tue Aug 08, 2023 7:28 am We suggest using -display sdl on Windows hosts.
I actually have done that and it has an added benefit of locking the mouse to the bounds of the window, so it's even more accurate -- thanks for that! The only issue now is that the QEMU monitor has garbage characters in the display when typing things like 'nmi'. I also realized that via=cuda doesn't allow for NMIs, so I have it changed to:

Code: Select all

via=pmu-adb
This allows for NMIs and has the added benefit that I can change keycodes in hw/input/adb-kbd.c. It would be nice to be able to change keycodes with an external file like those keymaps that I can't get QEMU to read, but I can patch in the meantime. Maybe at least the ADB keycodes can be read in externally.
User avatar
adespoton
Forum All-Star
Posts: 4279
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: Mouse issues under Windows and modifying keycodes (SOLVED)

Post by adespoton »

siddhartha wrote: Tue Aug 08, 2023 11:06 pm
Cat_7 wrote: Tue Aug 08, 2023 7:28 am We suggest using -display sdl on Windows hosts.
I actually have done that and it has an added benefit of locking the mouse to the bounds of the window, so it's even more accurate -- thanks for that! The only issue now is that the QEMU monitor has garbage characters in the display when typing things like 'nmi'. I also realized that via=cuda doesn't allow for NMIs, so I have it changed to:

Code: Select all

via=pmu-adb
This allows for NMIs and has the added benefit that I can change keycodes in hw/input/adb-kbd.c. It would be nice to be able to change keycodes with an external file like those keymaps that I can't get QEMU to read, but I can patch in the meantime. Maybe at least the ADB keycodes can be read in externally.
If you're using SDL, you should be able to use an SDL keymap file. Having said that, I've always struggled with those, and hw/input/adb-kbd.c is relatively straightforward.
User avatar
siddhartha
Student Driver
Posts: 16
Joined: Wed Nov 30, 2022 12:59 am

Re: Mouse issues under Windows and modifying keycodes (SOLVED)

Post by siddhartha »

adespoton wrote: Tue Aug 08, 2023 11:09 pm If you're using SDL, you should be able to use an SDL keymap file. Having said that, I've always struggled with those, and hw/input/adb-kbd.c is relatively straightforward.
Even when setting directories via the command line, I just can't seem to get QEMU to read from share/keymaps. It doesn't even throw a code.

In the end, my final solution was to use this INIT and enable usb-tablet, which provides near perfect mouse accuracy. My final command line is:

Code: Select all

"C:\Program Files\qemu\qemu-system-ppc" ^
    -M mac99 -m 512^
    -hda macos922.img -hdb storage.img -boot c ^
    -netdev user,id=mynet0 ^
    -device sungem,netdev=mynet0 ^
    -device usb-tablet ^
    -monitor stdio
This has mouse accuracy, allows me to modify hw/input/adb-kbd.c to change the Command key, and all plays nice with VNC. The only thing that's missing is that cuda (the default QEMU machine) doesn't support NMIs as of yet. To get around that, I invoke MacsBug with Debugger! or CS Debugger.

I think I finally now have a useable and remotely accessible CodeWarrior 6 build environment that allows the use of a debugger. Whew.
User avatar
siddhartha
Student Driver
Posts: 16
Joined: Wed Nov 30, 2022 12:59 am

Re: Mouse issues under Windows and modifying keycodes (SOLVED)

Post by siddhartha »

So, it now appears that using usb-tablet will disable mouse movement (buttons still work) in MacsBug. Ugh. I tried the command line version as well, but that doesn't work. Anyone with deep MacsBug knowledge know how to get a tablet to play nice?

As an aside, to get that giant command line into Windows, you can append this to your batchfile/command line:

Code: Select all

    -device usb-tablet ^
    -prom-env "use-nvramrc?=true" ^
    -prom-env nvramrc=": b64 do 0 4 0 do 6 lshift i j + c@ 2e - dup b > 7 and - dup 25 > 6 and - or loop 3 0 do dup c, 8 rshift loop drop 4 +loop ; variable lzd variable lzi : lzp c@ dup c, lzd @ lzi @ + c! lzi @ 1+ fff and lzi ! ; : lz lzd ! fee lzi ! 1 -rot do dup 1 = if drop i c@ 100 + 1 else dup 2 / swap 1 and if i lzp 1 else i 1+ c@ i c@ over f0 and 4 lshift + swap f and -3 do dup lzd @ + lzp 1+ fff and loop drop 2 then then +loop drop ; 20 parse PofzQ03tNaNZRr1z.4Bk.E..YfHbwDfo.kU/oU6.zk2/.E.K5bk2.6.6.U4f8.YJ4EEu.D1v.E8b0FI1W.I/6D1v.EHv0.EPjuM0zzz/.N1sZ.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5K.Rs/eELa4zwJUg.V.Ew0.Dy.q.4w.Lk/.Tz6h./U.9U..CxME..kE/0WzXE0Jn.ZJYs/9yXzQ.zzuOg5.5V6G.HzvDxu.5d6G1dTzDxiv3.1rI1rI.A30r1cS2Hp/jI81Y1zQ325uOgMLYvzF5JCOLNZNKDzMKl1.5BnA4HxNJ7GXUFa.Tw06E36A./.RTwYN47n.c21/jg2.aQb8.61zp25JIp3Ma3Iys2Nn.Q/../.6U.FG.0z0E41ADZEZ1xsq9mgczkZ2aYE3eakZUIK2phR3UU.UdEIg/0WMF0XJek.nFad6WdN/VWdLZL8./2F./2Mem/W2IY.2Jw.2LE.ubw.XE.F1VFIM/Bezoc00I62F.34zs...4/L.E/8TkS/.s/0E./64bM4I31zR5BjNLN3R4vzMIA.JKlgOKvzQaJqP43nQZ1z.4BjEZBJNJCLIH3m2LxnFa/kPabzNItYI5FsQ4brMKxZPax1OFxaQbJb3bNZaqZyRhteNJ6EPqFVQ2xVPaJnPpAjNItV3bNrI25SO3E.M5/Zzb72F43YMrBZQ4ZmOLGDtatjIXJUI4DgRKnzPaZbQqZ2ML1TO4BoP3/ahDtZIlRG6E1YiY1jc./b0/0XNk2..9Q.dV0X...U over + swap here >r 2000 allot here >r b64 here r> here r@ here! lz here r> tuck - dev / \" pef,AAPL,MacOS,PowerPC,prepare\" property \" Tab\" encode-string \" code,AAPL,MacOS,name\" property"
User avatar
Cat_7
Expert User
Posts: 6172
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: Mouse issues under Windows and modifying keycodes (SOLVED)

Post by Cat_7 »

Ah, nice. I could never get that command line to be read on a Windows host.
I can't help with macsbug.

btw: I was wondering what you are up to with Qemu ;-)

Best,
Cat_7
User avatar
siddhartha
Student Driver
Posts: 16
Joined: Wed Nov 30, 2022 12:59 am

Re: Mouse issues under Windows and modifying keycodes (SOLVED)

Post by siddhartha »

Cat_7 wrote: Fri Aug 11, 2023 5:08 am btw: I was wondering what you are up to with Qemu ;-)
Does my avatar give it away? ;)
User avatar
Cat_7
Expert User
Posts: 6172
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: Mouse issues under Windows and modifying keycodes (SOLVED)

Post by Cat_7 »

Haha, certainly you are not going to pirate anything ;-)
But perhaps cuddle it from the dead to the living...

Best,
Cat_7
mcayland
Mac Mechanic
Posts: 152
Joined: Sun Nov 01, 2015 10:33 pm

Re: Mouse issues under Windows and modifying keycodes (SOLVED)

Post by mcayland »

siddhartha wrote: Thu Aug 10, 2023 2:11 am Even when setting directories via the command line, I just can't seem to get QEMU to read from share/keymaps. It doesn't even throw a code.
Last time I built and tested on Windows I seem to recall that some of the paths were different compared to Linux - it has been a while though, so that issue is likely fixed. I suspect that some "debug with printf" will point you in the right direction fairly quickly.
siddhartha wrote: Thu Aug 10, 2023 2:11 am The only thing that's missing is that cuda (the default QEMU machine) doesn't support NMIs as of yet.
The only reason this is missing is because I don't know how it should be wired up on cuda (the NMI on pmu is activated via the programmer switch gpio). If you can find out which line the NMI on cuda should toggle and let me know, it's a reasonably trivial piece of coding to get this working.
User avatar
adespoton
Forum All-Star
Posts: 4279
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: Mouse issues under Windows and modifying keycodes (SOLVED)

Post by adespoton »

Cat_7 wrote: Fri Aug 11, 2023 10:12 am Haha, certainly you are not going to pirate anything ;-)
But perhaps cuddle it from the dead to the living...

Best,
Cat_7
Sidd hosts https://os9.ca/ and studies ancient software registration systems :)
User avatar
siddhartha
Student Driver
Posts: 16
Joined: Wed Nov 30, 2022 12:59 am

Re: Mouse issues under Windows and modifying keycodes (SOLVED)

Post by siddhartha »

mcayland wrote: Fri Aug 11, 2023 11:43 am If you can find out which line the NMI on cuda should toggle and let me know, it's a reasonably trivial piece of coding to get this working.
From user powermax:

That depends on the I/O controller Cuda is attached to. NMI signal is active low on PC2.
Cuda's PC2 output pin is usually attached directly to the NMI pin of the machine specific I/O controller.
User avatar
siddhartha
Student Driver
Posts: 16
Joined: Wed Nov 30, 2022 12:59 am

Re: Mouse issues under Windows and modifying keycodes (SOLVED)

Post by siddhartha »

Another way to trigger an NMI is to modify hw/input/adb-kbd.c and change to mapping to something like:

Code: Select all

[Q_KEY_CODE_PAUSE]         = ADB_KEY_POWER,
This will turn your Pause key into the Power key in QEMU. With that change, you can then install Programmer's Key and trigger an NMI with Command-Power (or if you have been following this thread, Ctrl-Pause).
mcayland
Mac Mechanic
Posts: 152
Joined: Sun Nov 01, 2015 10:33 pm

Re: Mouse issues under Windows and modifying keycodes (SOLVED)

Post by mcayland »

siddhartha wrote: Fri Aug 11, 2023 7:53 pm
mcayland wrote: Fri Aug 11, 2023 11:43 am If you can find out which line the NMI on cuda should toggle and let me know, it's a reasonably trivial piece of coding to get this working.
From user powermax:

That depends on the I/O controller Cuda is attached to. NMI signal is active low on PC2.
Cuda's PC2 output pin is usually attached directly to the NMI pin of the machine specific I/O controller.
According to the QEMU model the via-cuda is attached to the macio device which is connected to either the Heathrow PIC for Old World machines or OpenPIC for New World machines. There appear to be plenty of spare IRQ lines on both of these, so where to start...? The Apple OSS repositories are now hosted on github, but I did find this: https://github.com/apple-oss-distributi ... w.cpp#L503 which could be a clue.
User avatar
siddhartha
Student Driver
Posts: 16
Joined: Wed Nov 30, 2022 12:59 am

Re: Mouse issues under Windows and modifying keycodes (SOLVED)

Post by siddhartha »

User avatar
siddhartha
Student Driver
Posts: 16
Joined: Wed Nov 30, 2022 12:59 am

Re: Mouse issues under Windows and modifying keycodes (SOLVED)

Post by siddhartha »

siddhartha wrote: Thu Aug 17, 2023 6:32 am Another way to trigger an NMI is to modify hw/input/adb-kbd.c and change to mapping to something like:

Code: Select all

[Q_KEY_CODE_PAUSE]         = ADB_KEY_POWER,
This will turn your Pause key into the Power key in QEMU. With that change, you can then install Programmer's Key and trigger an NMI with Command-Power (or if you have been following this thread, Ctrl-Pause).
To follow-up on this, you don't actually need to have Programmer's Key installed. In fact, you can trigger an NMI right from the QEMU monitor with

Code: Select all

sendkey meta_l-power
Or, if you have remapped the Command/Apple key to something like Control, it's:

Code: Select all

sendkey ctrl-power
Post Reply