PS/2 Direction for the Commander X16

Announcements by the development team or forum staff.
Post Reply
Kevin Williams
Posts: 15
Joined: Sun May 17, 2020 10:08 pm

PS/2 Direction for the Commander X16

Post by Kevin Williams »


Hello everyone, 



  I wanted to discuss an issue we have been struggling with, and that is PS/2 keyboard and mouse support.  This is probably not a secret to anyone watching the videos on the X16 as most of the time we are running at 4MHz or 2MHz.  This is completely due to PS/2 timing issues.  I've spoken with Michael Steil about this issue many times and he has taken several approaches to get it to working stably.  After adding the microcontroller to control the ATX power supply, I proposed the idea of adding a few more pins to also control the PS/2 ports.  Like many in the community, he would perfer to get it working as it stands, so I proposed adding jumpers to select between the microcontroller, or the 65c22.   So, I did just that on the third prototype.  With tiny revisions, this will become our development board so it will give folks the option to try either approach. 

  I initially thought about writing the code for the Arduino myself.  I've messed around with Atmel microcontrollers going on 20 years now, but the truth is, I'm probably not the best one for this task.  The code I wrote for the ATX power control is working, but I can't seem to get my reboot function to work for some reason.... Anyway, I digress, I guess the real reason I'm making this post is to ask for some help from the community!

  We are not committed to one approach or the other necessarily.  IE, we are still planning to work on the 65c22 'bit-bang' approach (heck, we maybe could use some help here too), but alternately I wanted to start working on the microcontroller code to at least evaluate it before the final version of the board.  

  If you're interested, here are some details wrt to how I have the HW setup on the current prototype.  The attached pic shows U18, which is the ATTINY861 microcontroller.  I really wanted to stick with no more than a 20 pin IC if possible, to make it look like it matches the board.  This chip can run at 8 or 16MHz without an external crystal, but I gather the 16MHz mode may not be as stable.  Not sure if this will be an issue later, but I wanted to mention it.  I sort of just guessed the chip would be fast enough to handle both the mouse and the keyboard.  There are certainly plenty of keyboard libraries out there, and at least one mouse library I'm aware of, but I'm not sure if they have ever been combined.  I am running the microcontroller as an I2C device with the 6522 acting as the host to this IC.  Right now, it is only listening for commands to power-off the system, reboot, reset, NMI & HDD LED control.  I also hooked a line up to the 65C02 IRQ, so it could be polled.   (Just as an FYI, the real-time clock is U10, which is read via I2C.  J16 is the external I2C header to drive other devices if desired.  J16 will also work as a 6-pin ISP header to program the ATTINY861.  J6-J9 toggles the clock/data line for each PS/2 port from 65c22 to the ATTINY861.)

 In a nutshell, I'd like it to maintain the existing functions which should be taking next to nothing in terms of CPU, except maybe the I2C library.  Integrate IRQ driven PS/2 mouse and keyboard routines and make the code as clean as possible for easy editing.  If we do wind up going this route, your work could be part of the open-source library at the end of the rainbow for the system.  Clearly, there will need to be some interaction on the kernal-side to process the data from these interrupts.  This will take some coordination too, but I suspect the Arduino-side could be tested with another Arduino reading the data for the time being.  Keep in mind, we could also wind up not using it too, just fair warning.

  Keep the responses on this thread for the time-being.  I know this is a big ask, but I really want to make sure we have a nice solid library, so I decided it would be better to get a rock-star developer out there.  Assembly is fine too, if you want to do it the hard way ?but I suspect C will be fine.  I also attached the code which is running on the proto for now.

Please let me know if you have any questions, I'm looking forward to testing this out!

Thanks!

-Kevin


micro.png
X16_Power-current.zip
User avatar
StephenHorn
Posts: 565
Joined: Tue Apr 28, 2020 12:00 am
Contact:

PS/2 Direction for the Commander X16

Post by StephenHorn »


Hrrrng... if I didn't have a day-job that I loved dearly, I would be all over both this and offering to help out with the kernal. I mean, I'm continuing to work on the emulator; albeit in my own fork that I haven't formally announced here, but has been named dropped here by others. Suddenly, so many things I want to add to my precious hobby time. And I've previously worked with 2-way communications in microcontrollers for various sensors, so adding a PS/2 communication routine here sounds like fun to me. I hope someone pops up who can help out with this.

Developer for Box16, the other X16 emulator. (Box16 on GitHub)
I also accept pull requests for x16emu, the official X16 emulator. (x16-emulator on GitHub)
ZeroByte
Posts: 714
Joined: Wed Feb 10, 2021 2:40 pm

PS/2 Direction for the Commander X16

Post by ZeroByte »


Someone get Ben Eater on the phone!

EMwhite
Posts: 220
Joined: Mon Sep 07, 2020 1:02 pm

PS/2 Direction for the Commander X16

Post by EMwhite »



2 hours ago, ZeroByte said:




Someone get Ben Eater on the phone!



He's been messing with PS/2 and USB in his last 3 or 4 videos.  Pretty sure he will be able to solve this in 30 minutes or recommend a different, yet elegant approach.

I wasn't joking when I suggested somebody get the guy that did the "C=key" on the line.  It maps PS/2 to traditional Commodore style row/column scanning; in a worst case scenario, just get it over with using something that works even if it costs an additional $1.29 per unit.

 

Chandler Klüser
Posts: 11
Joined: Sat May 08, 2021 2:49 am

PS/2 Direction for the Commander X16

Post by Chandler Klüser »


I have until the next wednesday on vacation from my full time job here in Brazil to help you.

Although I have not worked with that mcu (nor have it in hands) in particular, I am use to work with ATtiny+ATmega series as a hobbyist (not as a professional). The mcu datasheet seems pretty familiar comparing to other models I have used.

I can develop in C with Arduino, when it finish I can also try to make it work without the Arduino Bootloader to save more memory. I can do in assembly too, but there is no need to do that way.

I do not have experience working with keyboard+mouse interfaces (w/ PS2) with microcontrolers, there is a good library in github for that. Even so, I will have to study deeper to work with that.

Until my vacation's end, I can help to work in this task. But I have no experience (as a professional) in doing that job!!!











 

 

VincentF
Posts: 75
Joined: Mon Jun 29, 2020 8:22 pm

PS/2 Direction for the Commander X16

Post by VincentF »


I would gladly help too but I don't think I'm a wizard-level developper with Arduinos (hobby programmer on Arduino and ESP32). Anyway, if any help is needed, i'll try as hard as I can. I'm also on vacation for the next 2,5 week.

__________

By the way, I found a library for PS/2 mouse handling to add with the keyboard library. Not sure if that could help but putting it anyway.

pzembrod
Posts: 94
Joined: Sat Aug 29, 2020 9:21 pm

PS/2 Direction for the Commander X16

Post by pzembrod »


Hi @Kevin Williams, @Michael Steil,

I might be able to offer some help around the 65c22 bit-bang approach. It's unusual that this works fine at lower and runs into problems at higher clock rates. Just reach out.

Cheers

/Philip

Stefan
Posts: 456
Joined: Thu Aug 20, 2020 8:59 am

PS/2 Direction for the Commander X16

Post by Stefan »


I looked around a bit for trustworthy information on PS/2 timing.

I found this 1991 IBM manual titled "Keyboard and Auxiliary Device Controller" page 16 (page 230 in the file).

https://archive.org/details/bitsavers_ibmpcps284erfaceTechnicalReferenceCommonInterfaces_39004874/page/n229/mode/2up?q=keyboard

Possible timing problems:


  • The time it takes after PS/2 lines are released by the host before the keyboard starts sending data. The current X16 Kernal waits about 108 us @ 8 MHz according to my manual clock counting. I have found no documentation stating when the keyboard must start sending data, only that it cannot begin before 50 us after the PS/2 lines were released. It would be interesting to see what happens if the time the Kernal is waiting for the keyboard to start sending data is made longer.


  • The current Kernal samples the data line immediately after the clock goes low. This should be fine according to the specification, if the keyboard in question follows the specification. It would, however, be interesting to see what happens if the data data line is sampled in the middle of the clock low period, for example about 15-20 us after the clock transition.



ps2 timing.png
a9m
Posts: 11
Joined: Wed Jul 22, 2020 5:37 am

PS/2 Direction for the Commander X16

Post by a9m »


I would like to help you too but I don't have any keyboard and mouse with a PS/2 connector. At least I have a basic knowledge in microcontrollers and knows how to approach both it and 6522 bit-banging methods. So hit me up if you're interested.

For a background, I used an Arduino to display Bad Apple on 240 7-segment displays

Wavicle
Posts: 284
Joined: Sun Feb 21, 2021 2:40 am

PS/2 Direction for the Commander X16

Post by Wavicle »


I can do the embedded implementation, and I have an oscilloscope and logic analyzer on my bench to verify timing correctness. I haven't worked with an ATTINY861 before and I only have ATTINY85s in my bins here so I'd have to order an 861 from Mouser and hope that the 861 has a pretty similar toolchain to the 85. I'm not sure what the 861 needs for programming, but I assume if nothing else, my TL866II can do so. It would help, but isn't completely necessary, to have the X16 schematic page (or portion of a page) that details the 861 connection so that I can replicate a similar circuit on my benchtop.

I'm competent with most assembly languages, however I'm probably all thumbs when it comes to 65xx assembly specifically. I can read it well enough, but have limited hobbyist experience writing it and zero professional experience with it. I'd be most useful for the embedded/861 implementation.

I'm in the Seattle area (I work at the tech giant in Redmond) so it would have to be all remote work. Send me a DM if interested and I'll order the 861 parts from Mouser and we can take this to email/zoom.

Post Reply