No0ne / ps2x2pico

USB keyboard/mouse to PS/2 interface converter using a Raspberry Pi Pico
MIT License
196 stars 35 forks source link

Adapter causing dropped keyboard input on 386 machine #42

Closed seritools closed 3 weeks ago

seritools commented 1 month ago

Machine details:

TMC/MyComp/MyNix/Megastar PAT38PX V3.10
1MB SIMM 30pin 70ns (x8 set)
Tseng Labs ET4000AX 1MB VGA ISA 16bit
3Com Etherlink III 3c509-COMBO
UM82C862F Multi I/O 16-Bit ISA (Floppy, IDE, 2x COM, LPT, Gameport)
Teac DF354H911A 3.5" Floppy Drive High Density
Sony CDU611 IDE CD-ROM Drive 24x
AMD Am386 DX/DXL-40 386 40MHz
3C87-33 80387 Math Coprocessor, 33MHz
Quantum Maverick ProDrive 540MB IDE
SoundMan 16 / Pro Audio Spectrum 16 Basic ISA

On MS-DOS and in games (e.g. Epic Pinball) some few inputs are dropped. If I load EMM386, the issue is exacerbated (but also happens without it).

With a regular PS/2 keyboard there are no issues :S

Tested with the latest firmware, both the regular one and the one that forces a 100 Hz rate.

No0ne commented 1 month ago

A shot in the dark, I just made the output queue longer. Please try this: queue128.zip

seritools commented 1 month ago

Sadly no change - it doesn't seem like a full queue or anything. I can just press e.g. arrow down, and it's ignored fully, sometimes. The behavior seems to be different for different applications and even keys, which is super confusing.

With the queue128 firmware:

https://github.com/No0ne/ps2x2pico/assets/5844066/35a72ff2-21f1-4de8-a0b6-84ad0c065c1f

With the keeb connected directly (it has a PS/2 mode through a passive USB/PS/2 adapter):

https://github.com/No0ne/ps2x2pico/assets/5844066/55c9e56a-0e5d-44af-a3b8-5b089d1c74c5

I've tried with a powered USB Hub as well, just in case - no difference, though. Also tried with an old AT keyboard directly, also works fine. I'll quickly test with another USB keyboard too, that's the only remaining part I haven't swapped. (I have even swapped the USB OTG cable and PS/2-AT adapter, just in case x))

EDIT: Tested with another keyboard too - no difference :c

No0ne commented 1 month ago

Thats very odd and not a queue issue indeed, reverted that. Maybe the clock is too fast, made this slower here: slowerclk.zip

No0ne commented 1 month ago

Btw. can you hook up a serial debug cable on GPIO0? the serial settings are 115200 baud, 8 data bits and no parity.

seritools commented 1 month ago

Just tested again with the new FW, still no difference. But nice, just connected my UART dongle.

I can definitely see it sending the correct kb > host lines. My guess would be that the system doesn't like the timing for the multi-byte keys. Any single-byte keys seem to work fine.

Arrow-down is

// press
kb > host e0
kb > host 72
// release
kb > host e0
kb > host f0
kb > host 72

Here's the bootup log if it's helpful.

ps2x2pico-1.1
Setting defaults for keyboard
scancodeset set to 2
kb > host aa
Blinking keyboard LEDs
HID(1,0,KEYBOARD) mounted
 ID: 04d9:0169
 Manufacturer:
 Product:      USB Keyboard

HID(1,0,KEYBOARD) registered for reports
HID(1,1,MOUSE) mounted
 ID: 04d9:0169
 Manufacturer:
 Product:      USB Keyboard

HID(1,1,MOUSE) registered for reports
host > kb ff
KBHOSTCMD_RESET_FF
Setting defaults for keyboard
scancodeset set to 2
kb > host fa
kb > host aa
Blinking keyboard LEDs
HID(1,0): LEDs = 7
HID(1,0): LEDs = 0
host > kb f2
KBHOSTCMD_READ_ID_F2
kb > host fa
kb > host ab
kb > host 83
host > kb ed
KBHOSTCMD_SET_LEDS_ED
kb > host fa
host > kb 02
HID(1,0): LEDs = 1
kb > host fa
kb > host e0
kb > host 72
kb > host e0
kb > host f0
kb > host 72
kb > host 5a
kb > host f0
kb > host 5a
kb > host 24
kb > host f0
kb > host 24
kb > host 23
kb > host f0
kb > host 23
...
No0ne commented 1 month ago

I'll test that with my 386.

No0ne commented 3 weeks ago

I'm afraid I can't reproduce this issue :( its always working perfectly.

I tested on my 386 which has a Soyo SY-019C (491/493) board and an Intel P8042AHP keyboard controller running AMI KB Bios Version F.

Also tested on two additional 486 boards, no problems found :(

Which keyboard controller does your board have? Does the issue also appear in the BIOS setup or only in DOS?

seritools commented 3 weeks ago

Intel P8042AHP keyboard controller running AMI KB Bios Version F.

dang, that is the very exact same chip as in mine. 😢

Does the issue also appear in the BIOS setup or only in DOS?

It also happens in real-mode DOS, but is much rarer. When loading emm386 it becomes really bad. IIRC it also happens in the BIOS - I'll try to verify again.

No0ne commented 3 weeks ago

Ok I just tested in BIOS setup and in edit.com on a Win98 floppy. I'll retest this with EMM386 and Epic Pinball, on DOS 6.22 right?

seritools commented 3 weeks ago

By far the clearest way the issue shows is like in my video above - DOS 6.22 with himem + emm386, open edit.com, open the menu and use up/down. Lmk if you'd like to see the full config.sys/autoexec.bat ^^

Now that i think about it - Epic Pinball showed dropped inputs on the two SHIFT keys for the flippers - don't remember if those are also multi-byte?

seritools commented 3 weeks ago

Just tested again - it's actually just as bad in BIOS as in edit.com with EMM386 - about half the up/down keys are dropped.

It seems like only some ways of getting keyboard input are affected. Testing currently in Norton Diagnostics (NDIAGS.EXE), which has a nice Keyboard Press Test that shows the scan codes as well. It's super funny, the NDIAGS TUI shows the same issue of dropping some input, but once I open the keyboard press test itself, all key presses are recorded and shown perfectly.

I assume the BIOS routines on this particular system (AMI) are wonky in some way 🤔

EDIT: I'll also try to swap keyboard controller chips, got a few more around, just to see if there's a difference.

seritools commented 3 weeks ago

PROGRESS:

The chip that works: image

Lifting the sticker: It's a NEC D80C42C from 1990, Week 42.

seritools commented 3 weeks ago

I just tested my last one, an Intel P8242 with a Phoenix Copyright - also works fine.

In conclusion, the top two have the issue, the bottom two are fine:

image

No0ne commented 3 weeks ago

Wow! Thanks for the extensive testing! Thats indeed a strange problem. I'll come back when I had run my 386 with EMM386.

No0ne commented 3 weeks ago

Maybe the only way is to check clock and data of your real keyboard vs. ps2x2pico with a logic analyzer. Do you have one? I use a cheap 8 Channel with Logic2.

seritools commented 3 weeks ago

Yup, I'll try setting something up (probably next weekend)

No0ne commented 3 weeks ago

Don't whats different but now I reproduced it on my machine. I'll check with Logic2!

No0ne commented 3 weeks ago

I think I found the issue in the locking cooldown timer, try this please: timerfix.zip

seritools commented 3 weeks ago

Awesome, just put in one of the AMI keyboard controllers and yup, this fixed the issue 🎉

Thank you 💜

No0ne commented 3 weeks ago

Cool! Thanks again for testing!