DIY PS2 -> NeXT non-adb keyboard converter

NeXT Computer, Inc. -> NeXT Black Hardware

Title: DIY PS2 -> NeXT non-adb keyboard converter
Post by: jroark on January 16, 2013, 01:43:46 AM
I've started a project to create a ps2 -> NeXT non-adb keyboard/mouse converter. So far I have keyboard somewhat working (key repeat rate is too high and special keys are not mapped yet). The source code is here
https://code.google.com/p/teensy-nextkb/

I'm using a Teensy 2.0 but it should work with any atmega32u board.

eventually i'd like to build a complete soundbox replacement. I encourage anyone to submit patches.

Here is a pic of my POC prototype. I've simply cut a ps2 extension cable in half, broke off pin 6 and plugged it into my NeXT soundbox. The to KBD (pin 2) is hooked to port PB0 on the Teensy and the from KBD (pin 3) is hooked to PB1 port. On the PS2 side VCC/GND are hooked up to USB (no reason the NeXT couldn't power the whole thing) and the CLK is hooked up to PD0 (an interrupt port) and DATA on PD1.

The software sets up an interrupt and buffer for the PS2 keyboard, then sits waiting for a command from the soundbox, when the edge drops, it reads the NeXT cmd and if it's a keyboard query checks if there is a PS2 cmd in the interrupt buffer and responds with a translated NeXT scancode or tells the soundbox there is nothing. When I add PS2 mouse support it will do basically the same thing on the mouse side.

If it works well enough this will be (in conjuction with a NeXT -> vga) a nice way to hook up my NeXT to my vintage computer KVM (most of those already being PS2/VGA).



Title: DIY PS2 -> NeXT non-adb keyboard converter
Post by: gtnicol on January 16, 2013, 06:24:33 PM
I actually started on a similar project some time ago. The bus to the soundbox is (from memory) running at 5MHz and encodes audio, keyboard, and mouse. The same cable carries power and video as well.

I got a propeller and an xmos to play with for talking to the bus, which seems like the hard part of a soundbox replacement.

BTW. You know the signal from the keyboard multiplexes the mouse signal in there too right?
Title: DIY PS2 -> NeXT non-adb keyboard converter
Post by: jroark on January 16, 2013, 06:33:17 PM
Quote from: "gtnicol"BTW. You know the signal from the keyboard multiplexes the mouse signal in there too right?

Yes, 0x22 for a mouse query. That's next on the list. I've got my LA hooked up and will sniff some of the mouse responses. Just have to decode the format. Do you have any info on that?

A propeller might be a better choice. You could dedicate a core to each input and one for response.

How's your project coming? The monitor bus seems to be running at a very hi rate. It overwhelms my teensy (haven't tried my LA yet). Do you know what the voltage on the monitor bus I/o is? My LA can only handle 5V.
Title: Mouse
Post by: pergamon on January 16, 2013, 08:16:40 PM
Funny you should ask, guess what I was working on a few nights ago:

https://github.com/mgrdcm/USB-NeXT-Keyboard/tree/mouse

Still needs some tweaking, but basic operation is there.
Title: Monitor Bus
Post by: pergamon on January 16, 2013, 08:21:00 PM
Also, if you want to know about the monitor bus check out:

http://www.68k.org/~degs/nextkeyboard.html
Title: DIY PS2 -> NeXT non-adb keyboard converter
Post by: jroark on January 16, 2013, 10:41:49 PM
It appears the CLK from the Monitor bus is only 5Mhz not 20Mhz. That's a relief! Maybe the Teensy can handle it after all.



Perhaps we should pool our efforts?
Title: DIY PS2 -> NeXT non-adb keyboard converter
Post by: gtnicol on January 20, 2013, 12:01:36 PM
Yep, it's 5Mhz clock. I haven't figured out the bus protocol but my understanding is that it was based off something else from around the same time period (I forget, but I think it was a digital audio protocol).

I think the 1st generation propeller is still a little underpowered for bit-banging the bus (I think the general rule is you need 8 instructions per cycle for bit banging,),  but the next generation (80Mhz) should be fine. I do like the idea of running a core per channel... mouse, keyboard, mic, sound, etc. which is one reason I picked up an XMOS as well (hardware threads). I don't think the teensy will have quite enough power to talk to the bus.

I was actually doing something similar to your teensy work, but using a PIC12/PIC16... wrestling with the timing constraints etc. because of an underpowered MCU before  I also got side-tracked writing an eclipse plugin for the propeller, and a concurrent pascal-lite language to program the PIC and propeller in.

I do have a teensy though, so yes, I think it makes good sense to pool efforts. Having everything on github is a good idea.
Title: DIY PS2 -> NeXT non-adb keyboard converter
Post by: jroark on January 20, 2013, 12:59:05 PM
I was hoping to use the teensy because I felt silly building a keyboard/mouse interface with more Mhz than the system it was communicating with. I've been looking at the monitor bus protocol with my LA and I think I've got enough of it figured out for mouse and and keyboard support. Unfortunately my teensy is incapable of generating an accurate/fast enough signal. I was hoping to use a bastardized SPI like interface something like this:


NeXT    Soundbox
----    --------
SCLK--->SCLK
MOSI--->MOSI
MISO<---MISO
SS-\  ->SS-
     |___|


This looked very promising and I could regularly get bit widths +/- 0.02us of 0.2us. Unfortunately the SPI SCLK input on the teensy 2.0 is limited to F_CPU/4 meaning without changing the clock to 20Mhz, it is not capable of receiving a 5Mhz clk signal reliably, so I would see lots of other garbage trailing the output.

The Teensy 3.0 is capable of receiving up to 12Mhz SCLK but it signals at 3.3v so a logic level converter will be required. Likewise the Propeller operates at 3.3v.

I've got a p8x32a-q44 based propeller board that I've started to play with. The more I play with it, the more I think it will be the best option.

The monitor bus may be I2S (http://en.wikipedia.org/wiki/I2s) from the notes pergamon linked to.
Title: DIY PS2 -> NeXT non-adb keyboard converter
Post by: gtnicol on January 20, 2013, 10:10:09 PM
It does feel strange to be hooking up a processor that's faster than the main CPU to emulate the soundboard, but I think that's the only option. Either that or do everything in an FPGA... I wish someone had schematics for the soundbox.

I think the current generation of propeller chips will be hard-pushed to talk to the bus reliably at 5Mhz. The propeller2 should do the trick, or the XMOS.
Title: DIY PS2 -> NeXT non-adb keyboard converter
Post by: jroark on January 21, 2013, 05:07:28 PM
The latest code in git supports PS2 kb -> NeXT non-adb. It works remarkable well. I have yet to see it miss a key or translate incorrectly. I'm going to start on the PS2 mouse next. The mouse will be much more chatty, hopefully it won't overwhelm the Teensy.

Here is my breadboard with a power switch, power led, and activity led. The Teensy is powered by the bus.

If you play with this, be careful not to have the USB and NeXT power hooked up to the Teensy at the same time!

Title: DIY PS2 -> NeXT non-adb keyboard converter
Post by: pergamon on January 22, 2013, 11:59:23 AM
Nice!  Well done!
Title: DIY PS2 -> NeXT non-adb keyboard converter
Post by: jroark on January 22, 2013, 07:09:17 PM
The PS2 mouse protocol is too chatty to work very well. I even turned the sample rate down to 10 samples a second, but no luck. It's choppy and very slow. Typing while moving the mouse is nearly impossible. A converter could probably be made with a multi core MCU like the propeller, but not the little Teensy or Arduino. It may be possible to optimize the code enough to get it work better, but it will never be a fully usable solution without some extra electronics.
Title: DIY PS2 -> NeXT non-adb keyboard converter
Post by: gtnicol on January 22, 2013, 08:43:08 PM
Seems like you're running into the same issue I had with the PIC processors... they're just too slow to get reliable timing.

I had contemplated doing a multi-MCU solution where one (or maybe 2, depending on the PIC) would talk to the PS/2 keyboard and mouse, and the other would talk to the NeXT, with the PS/2 PIC(s) sending translated packets to the PIC talking to the NeXT. That way you can do delta encoding etc. and buffer packets (using a ring buffer or some such), and spool them off to the NeXT based on it's timing.

Trying to do it all on one MCU, and wrestling with both PS/2 timing, and NeXT timing, seemed pretty close to impossible on a single PIC.
Title: DIY PS2 -> NeXT non-adb keyboard converter
Post by: cuby on January 22, 2013, 11:02:47 PM
Quote from: "gtnicol"Seems like you're running into the same issue I had with the PIC processors... they're just too slow to get reliable timing.

Emulating the soundbox should work well on XMOS controllers - the I/O is even fast enough to implement Fast Ethernet in software by using bit banging (and I/O ports with timed shift registers). We have some experience with the XMOS chips and I have some devboards on my desk. Prices for the chips start at about 5 Eur for a 400 MIPS single-core controller.

However, my impression was that the protocol from the NeXT to the soundbox was not yet fully reverse engieered? Did I miss an update here?

-- Michael
Title: DIY PS2 -> NeXT non-adb keyboard converter
Post by: gtnicol on January 23, 2013, 03:48:43 PM
I have an XMOS development board (not sure the version), but yes, I think that's probably the best processor out there right now, though I think the Propeller II might be better (once it finally comes out).
Title: DIY PS2 -> NeXT non-adb keyboard converter
Post by: gilles on March 23, 2013, 04:18:18 AM
nice project.
For the PS2 mouse maybe you can use a poll mode when the teensy has time to handle it
(I did not read your code in details but it seems you use stream mode  
Quotewrite_mouse (0xF4);
).

Go to top  Forum index