Emulating the NeXT Non-ADB protocol

Started by drakar, January 07, 2017, 03:28:56 am

Previous topic - Next topic

drakar

Hello NeXT fans,

A while ago I picked up a nextstation color without a keyboard and mouse. How hard could it be to emulate them? (Very.) Thanks to info from this forum I got a soundboard converted and working and have gradually figured out the full protocol. With a USB microcontroller and an Arduino I can successfully emulate the keyboard and mouse with their USB equivalents.

Details and some code are on my page: https://drak.org/next-keyboard-protocol
I'll put the important parts below.

Most of the info out there about the keyboard is right, but it usually treats the responses as 22 bits. It makes more sense if you treat it as 2 bytes with some start/stop bits. The mouse was a lot harder to figure out although it seems really simple now. The movement isn't quite the same as the real deal but it works pretty well.


- = high
_ = low
50us each character
LSB first

From the computer:
KB Query
-----_____-____----- 0x10
Mouse Query
-----_-___-____----- 0x11
KB Reset
-----_----_------__________-----

LEDs Off
-----__________--__________----- 0x0, 0x0
Left LED On
-----__________--_-________----- 0x0, 0x1
Right LED On
-----__________--__-_______----- 0x0, 0x2
Both LEDs On
-----__________--_--_______----- 0x0, 0x3


From the keyboard:
KB Idle
-----__________--__________----- 0x0, 0x0

KB Packet
-----_BCCCCCCC_--_MMMMMMMM_-----
B: Make/Break (0/1)
C: 7-bit keycode
M: Modifiers

Mouse Packet
-----_1XXXXXXX_--_2YYYYYYY_-----
1: Button 1, 0 = down
2: Button 2
XXXXXXX: X movement, 7 bit two's complement
YYYYYYY: Same thing for Y axis


KB and mouse queries:


It works!


Right now I just have a breadboard set up with some wires and dev boards. Someday I'll put together a PCB design, right after I learn how to do that :)

Edit - Here's a video demo: https://www.youtube.com/watch?v=tVobmMhLYDg

barcher174

Excellent work! The USB host functionality has been the biggest hurdle to doing this. Hopefully one day soon there will be a good uC with built in support. I think a lot of people would be OK with giving up sound if this was cheap/easy enough.

Daxziz

Brilliant :)

Personally I don't understand the code. But I would love to; would you consider writing a detailed post about the reverse engineering, debugging, tools and programming language that led you to this success :)

drakar

The VNC2 controller that I'm using is pretty good for the USB part but I ran into some issues with getting the timing right. It would miss a query and get reset or it would see a KB query, get delayed, then send the response, so I'd press a key and the mouse would move. Combining it with an Arduino turned out to work pretty well.
I've been looking at PIC stuff too, they have a few that can do USB. If I could do everything on one controller that'd be nice.


Most of the reverse engineering was already done, there was an adafruit project that converted a NeXT keyboard to USB. I basically just had to flip that around and figure out the mouse part.
Debugging was some work with a cheap oscilloscope and lots of trial and error. Start up the nextstation, try some keys, adjust the timing, try a slightly different format, repeat. A logic analyzer would have made it a lot easier.

Rob Blessin Black Hole

Rob Blessin President computerpowwow ebay  sales@blackholeinc.com http://www.blackholeinc.com
303-741-9998 Serving the NeXT Community  since 2/9/93