• Updated 2023-07-12: Hello, Guest! Welcome back, and be sure to check out this follow-up post about our outage a week or so ago.

PS2 Keyboard on Mac Plus

mcdermd

Well-known member
Later NeXT machines used ADB. Early ones had a NeXT-specific DIN connection. The mouse plugs into the keyboard which plugs into the monitor (or sound box) which plugs into the computer.

 

bbraun

Well-known member
I've got a turbo slab with an ADB soundbox around here somewhere, I can give that a shot.

I've ordered a half dozen of the stm32f0discovery cpu boards that should be here early next week, and can then start sending out units to the adventurous among you.

 

mcdermd

Well-known member
Very cool. I have a turbo, non-ADB slab on my desk at work. Every now and again I use it for actual work.

 

bbraun

Well-known member
I was cleaning up my desk a little, and found all the various incarnations of the adapter board, so I lined them all up for a picture. It's a little embarrassing it took me so many iterations (and so long) to get things to where they are. But maybe sharing my learning process can get other people involved, and take the leap on some of their own projects.

ps2progress-s.jpg

On the far left, the initial hand wired adapter for pre-ADB keyboard to PS2 keyboard.

Then the first PCB without any connectors.

Then connectors added.

Then realized I didn't need those level converters after all, and wired them out.

Then revised the PCB to remove the level converters and add pre-ADB and PS2 mouse connectors. The pre-ADB mouse connector was also wired backwards.

Finally, fixed the pre-ADB mouse wiring and added the ADB connector.

Each PCB revision takes about 3-4 weeks of shipping time, during which I can work on the software side of things to fix bugs or add any support needed for the new PCB revision, and each PCB order is for about 10 boards. So, I've got 8 or 9 of each of the older revisions sitting around, probably never to be used. :)

And that's the course of the project since the initial posting back in June. These projects take a lot of time.

 

bigmessowires

Well-known member
Very cool! Are you still looking for help with programming and testing the board? I've already got one of those Discovery boards, as well as a few PS/2 keyboards and mice.

Maybe I read too hastily, but how do you connect the the board to the Mac? You said *not* to use a phone cable for the keyboard, but if you need a real Mac keyboard cable, that would seem to defeat the purpose of having a keyboard replacement. :) And for the mouse, you need a DB-9 straight through male to male cable?

 

bbraun

Well-known member
It'd be great if you wanted to test one out. I just sent out 4 boards attached to the discovery board, but always looking for more people interested.

When I originally setup the keyboard port, I didn't realized telephone handset cords were rolled, so yeah. techknight has suggested a couple fancy tricks to autodetect which cable is being used, but dunno.

The mouse connects with a male/female DB9 straight through cable. The connector on the board is male and the connector on the computer is female. There's also ADB.

 

MinerAl

Well-known member
techknight has suggested a couple fancy tricks to autodetect which cable is being used, but dunno.
Couldn't this be accomplished with a fairly simple switch the user could flip if he was using a telephone handset cable? The logic would be in wetware instead of software, but even rudimentary instructions should handle that.

 

Trash80toHP_Mini

NIGHT STALKER
It ought to be easy enough to crimp a conversion connector/cable in the meantime. For mine a round/straight cable will work fine as it's going on a KVM setup. I'll see what I've got in the box in terms of spare parts for anyone who needs one.

 

bigmessowires

Well-known member
A manual switch to select normal/reverse polarity on the keyboard connection would do the trick, but something automatic would be cool. :) Are the circuit schematics available for viewing? Because now that I think about it, you shouldn't even need the 5V line coming from the Mac, right? Since the board is powered by USB and not by the Mac? And I'm not sure you need the ground line connected to the Mac either. Both the Mac and your board should be at the same ground potential, through their power supplies to your home's wiring, but it might be bad practice to rely on that. If you could omit both the power and ground connections, then using a reverse-polarity cable wouldn't hurt anything. Then you could modify your software to swap the clock and data connections if it saw that "data" was changing at a faster rate than "clock".

If you don't want to eliminate the ground connection, then a reverse-polarity cable would connect the Mac's 5V to the board's ground, which is bad. You could use a diode to constrain the current to only flow in one direction, or a polyfuse to break the circuit if the current got too high, which would prevent any damage, but the board wouldn't work with the wrong cable.

I was going to suggest an automatic circuit consisting of a couple of transistors, but after more thought I'm not sure if it would actually work reliably. If the two (unknown) power connections from the Mac are A and B, then you want to connect the board's ground to A if B is 5V, and connect the board's ground to B if A is 5V. I think you could use two NPN transistors as switches. Both transistors would have their collector connected to the board's ground. T1 would have its emitter connected to A and base connected to B, and T2 would have its emitter connected to B and base connected to A. You'd also need a current-limiting resistor in the base connections. But I'm not totally certain this would work, for a few reasons I don't feel like describing now. Maybe the manual switch combined with a polyfuse isn't such a bad idea. :)

 

Trash80toHP_Mini

NIGHT STALKER
I was under the impression that USB would be for programming the unit? In that case the power wouldn't be provided under general use.

 

bbraun

Well-known member
I've been working on an 'owner's manual' of sorts wiki page: https://mac68k.info/wiki/display/mac68k/PS2+Adapter

It has discussion on the power situation.

The mac's 5V is not connected to the adapter board. Only 3 of the 4 keyboard wires are connected.

I'd prefer to keep it simple, maybe with small incremental changes, unless someone else wants to do the layout work.

 

bigmessowires

Well-known member
I got my PS2 adapter in the mail today. Rob, this thing is really impressive!

I tested an old Compaq PS2 keyboard with a Mac Plus. I don't have a DB-9 cable yet for mouse testing, and I don't have an ADB Mac handy either. I can confirm that it works with the Compaq keyboard. It's quite a trip, typing on a Mac Plus with a PC-style 101 key keyboard! A few bug reports:

  • The adapter doesn't seem to work when first powered on, until you press the reset button. I'm not sure if that's expected. After pressing the reset button, a blue LED labeled LD4 turns on, and the adapter works. But at first power-up, LD4 is off.
     
    A few keys on the numeric keypad do unexpected things: The numbers, decimal point, enter key, and the - minus sign work. Num lock does nothing, which is fine. / (forward slash) functions as up arrow. * functions as right arrow, + functions as left arrow.
     
    I also got into a state where the arrow keys did nothing. But after a reset, they worked again. Another time I got into a state where left arrow would type +, right arrow would type *, up arrow would type slash, and down arrow would type =. I think maybe I got this to happen by holding down the arrow keys until the key repeat action kicked in, but not sure.
     
    Function keys, print screen, scroll lock, and pause/break do nothing, which is what I would expect.
     
    I got into a state where Caps Lock turned on the keyboard's indicator LED, and letters typed appeared in all caps. Pressing caps lock a second time turned off the LED, but the keyboard remained in all caps mode. There didn't seem to be any way back to normal mode, expect to reset the board. I tried that test a second time, but couldn't repeat it.


Also a couple of thoughts about the board itself, if you ever decide to do another revision:

  • It's 4-ways ambiguous which way the adapter board should be connected to the ST discovery board. It could conceivably be plugged in with the ARM chip facing the adapter board, or away from it, and with the USB port on the same end as the PS2 ports, or the opposite end. In fact I pulled the two boards apart as an experiment, then forgot which way they go together again. :) Can you remind me? I remember that the ARM chip was away from the adapter board, but not which ends were aligned. An outline of the ST board in the silkscreen on the back of the adapter board would help.
     
    The alignment of the two boards seems backwards to me. You end up with a two-board sandwich with nothing on the inside, and components on the outside. Since you can rest the sandwich adapter-side down (the DB-9 mouse cable would interfere), you have to rest it on the desk with the ARM components on the desk, so the weight of the whole thing is supported by the reset button. Luckily it's a fairly stiff button, but I think it would be nicer if both boards had their components on the "top".
     
    Lastly, I think you could make the adapter board much smaller, and save some money on the PCB. I there a reason the adapter board needs to be the same size as the discovery board? It looks like you could make a smaller board that just connects to the 10-or-so pins on both sides of the USB-end of the discovery board, as that includes power, ground, and a bunch of digital I/Os. Then your board could be about 1/3 the size it is now.
     
    As discussed earlier, it would also be nice to have support for regular phone cable as well as keyboard (reverse-polarity) cable. :cool:


Once again, great work! I'll report in again once I have a DB-9 cable, and drag an ADB Mac out of storage for testing. Meanwhile if you can tell me how to plug the two boards back together, I'd appreciate it. :I

 

bbraun

Well-known member
Thanks for testing it!

The adapter doesn't seem to work when first powered on, until you press the reset button. I'm not sure if that's expected. After pressing the reset button, a blue LED labeled LD4 turns on, and the adapter works. But at first power-up, LD4 is off.
I think I've seen that too. It sounds pretty reproducible, I'll take a look.

A few keys on the numeric keypad do unexpected things: The numbers, decimal point, enter key, and the - minus sign work. Num lock does nothing, which is fine. / (forward slash) functions as up arrow. * functions as right arrow, + functions as left arrow.
This should be a simple mapping thing. The docs on the keypad are a bit wonky, but I'll take another look.

I also got into a state where the arrow keys did nothing. But after a reset, they worked again. Another time I got into a state where left arrow would type +, right arrow would type *, up arrow would type slash, and down arrow would type =. I think maybe I got this to happen by holding down the arrow keys until the key repeat action kicked in, but not sure.
Weird. For PS2 keyboards, the keyboard will do the key repeat and repeatedly send a keydown event. For the mac, they don't, the system handles the autorepeat. I attempt to send a command to the PS2 keyboard to disable the key repeat in the keyboard. It could be that command is failing on your particular keyboard. But the keypad stuff is also a little weird in the protocol, so it could be messed up there as well.

I got into a state where Caps Lock turned on the keyboard's indicator LED, and letters typed appeared in all caps. Pressing caps lock a second time turned off the LED, but the keyboard remained in all caps mode. There didn't seem to be any way back to normal mode, expect to reset the board. I tried that test a second time, but couldn't repeat it.
The current behavior is the adapter drives the PS2 keyboard's LED. So when the adapter sees the capslock keydown/keyup, it keeps track of the capslock key state internally and then sends PS2 commands to the keyboard to turn the LED on & off. I originally implemented this behavior when the adapter was pre-ADB only, since pre-ADB keyboards have no LEDs and the protocol has no notion of the computer being able to tell the keyboard to turn them on/off. So the adapter drove the LED state to make it work without OS support.

ADB is a bit of a different story, since the Apple Extended Keyboard introduced the 3 LEDs, and the protocol allows for the computer to turn them on/off. Right now, the adapter does not honor the computer's commands to toggle the LEDs, the command is silently ignored. For the most part this doesn't matter, since what the computer is telling the adapter is what the adapter does anyway (turn capslock led on when capslock is pressed, turn it off when pressed again, etc). However, there's a couple little utilities out there to mess with the LEDs of the keyboard for other purposes. I know of at least 2: one that toggles the LEDs to reflect system activity (disk/floppy/etc), and one that just cycles the LEDs.

My current inclination is to leave the existing behavior, since it usually doesn't matter, and it makes the LEDs work with pre-ADB systems.

It's 4-ways ambiguous which way the adapter board should be connected to the ST discovery board.
Yeah, I should add that to the wiki. The adapter board connects to the bottom of the discovery board (the side with the longer pins), with the PS2 adapters on the same end as the micro USB port on the discovery board.

The board could be made smaller, although for the board shop I'm using, seeed, unless I got it down to a 50cm x 50cm square, it doesn't make any price difference. For price, they come out to about $3 each as-is, and getting down to a 50cm x 50cm square would bring it down to about $1.50 each.

As for the orientation, if the board went on top of the discovery board, the reset button is obscured (not terrible, but hey) and I'm not sure how solid the connection would be between the adapter board and the discovery board, since the pins are shorter. With the current orientation of the adapter board on the bottom, the connectors are too tall to fit between the adapter board and the discovery board, and then the DB9 kinda sticks out anyway. I could experiment with the board being on top.

For the rj11 keyboard connector... As you can see, this board is completely devoid of any electronics. It's purely an adapter board. So far, it's also the most advanced electronics I've done. :)

For a switch, wouldn't this have to be a 4PDT switch to get it right?

For autodetection, I've gotten several suggestions that are over my head, so... I'm not sure I'm going to get that right.

I'm kind of leading towards just changing it to be telephone handset cord only, and maybe I can get some help on figuring out how to protect the adapter when the computer's 5V is connected to the adapter's ground.

 

NJRoadfan

Well-known member
I'm curious as to how this adapter handles the right mouse button. Does it ignore it, or does it map a function to it? Most 2 button ADB mice assign the right button as a click lock, but it wouldn't surprise me if any late production 3rd party mice somehow sent a right button command to the OS even though it wasn't designed for it.

 

bbraun

Well-known member
I currently ignore the right click button, does not pass it to MacOS, and do not enable ps2 intellimouse features (such as all the extra buttons, scroll wheel, etc). It could do something with it, but 1) pre-ADB has no way to pass a second button, since the mouse button is a switch on a wire, and there's no second wire, 2) I'll just focus on getting existing functionality working well, I think.

 

techknight

Well-known member
Well.... Now that you mention it, I was thinking about this the other day.

You can make the code if using a keyboard AND mouse with the adapter, to send a Control-click with the right click. Newer OSes use control-click to bring up the contextual menu.

So using a right click on an ADB system (older systems obviously no context). itll fire the context menu.

 

bbraun

Well-known member
A few keys on the numeric keypad do unexpected things: The numbers, decimal point, enter key, and the - minus sign work. Num lock does nothing, which is fine. / (forward slash) functions as up arrow. * functions as right arrow, + functions as left arrow.
Actually, does anyone have a physical Plus keyboard or separate keypad? I'm interested in knowing what these buttons do on the real keyboard.

I'm returning the codes defined in Guide to the Macintosh Family Hardware, but they are the same codes as the keys you're getting (keypad / keycode is 0x1B, which is also the same as up arrow). The keypad behaves a little differently in that it returns a special code to the OS when a keypad key event occurs (0x79), then the OS sends an Instant query command, and then the keypad returns the depressed key. This is what I'm doing, and it seems to be doing what it's supposed to, just what's supposed to happen is a bit odd.

Can you try pressing an upper case keypad forward slash? So hold down shift, press keypad's forward slash key, release forward slash key, release shift. That generates the forward slash for me. According to my reading of Guide to the Macintosh Family Hardware, this is how the physical keypads behave, but again, I don't have one so don't know for sure.

I could map these to their non-keypad equivalent keys, but I'm a little concerned about breaking compatibility with software that cares about the physical position of keys, such as games.

Edit: oh, I have a workaround for the problem of needing a reset when first powered on. I haven't tracked down the source of the cause yet, but I know where it is happening, and can reset from there, since it never recovers from that error condition.

 

bbraun

Well-known member
I also got into a state where the arrow keys did nothing. But after a reset, they worked again. Another time I got into a state where left arrow would type +, right arrow would type *, up arrow would type slash, and down arrow would type =. I think maybe I got this to happen by holding down the arrow keys until the key repeat action kicked in, but not sure.
I'm trying to reproduce this and the capslock one, and can't at the moment. It may be related to the keyboard and the keyboard generated autorepeat stuff. I'll try to get some additional ps2 keyboards to test with.

The capslock one, I can see that happening if a key down/up event was missed somewhere along the way. Actually, holding down capslock with other keys pressed might cause it, the pre-ADB keyboard buffer is shallow and might be fixed with using the buffering I'm using with the ADB keyboard.

You can make the code if using a keyboard AND mouse with the adapter, to send a Control-click with the right click
Yeah, I've thought about doing this and some other fancy stuff, particularly when enabling the PS2 intellimouse extensions for the scrollwheel and extra buttons, then you can use the extra buttons for all kinds of crazy macros and the scroll wheel for arrow up/down or page up/down. Then the next step is a macos control panel to customize those, which then gets into other issues.

At this point, a grand total of 5 people in the universe have these (6 tomorrow, if USPS doesn't mess it up even more), I've only heard from BMOW, and there's a laundry list of things to look at. :) So, I'd like to focus on those before getting too far ahead on macros.

 

bigmessowires

Well-known member
The board could be made smaller, although for the board shop I'm using, seeed, unless I got it down to a 50cm x 50cm square, it doesn't make any price difference. For price, they come out to about $3 each as-is, and getting down to a 50cm x 50cm square would bring it down to about $1.50 each.
At a glance I'd think 50mm x 50mm is doable. It's not a huge price difference, but you might as well save a few dollars if it doesn't make everything else more difficult.

Regarding the numeric keypad, don't those keys send two-byte scan codes? That may be what's goofing things up.

Thinking more about the board orientation, I just realized that once you've made the "sandwich", you can rest the boards on their edges and it's pretty stable.

But if you did shrink to a 50mm x 50mm board, you could fit the adapter on top of the Discovery board without covering the buttons - double win!

For the rj11 keyboard connector... As you can see, this board is completely devoid of any electronics. It's purely an adapter board. So far, it's also the most advanced electronics I've done. :)

For a switch, wouldn't this have to be a 4PDT switch to get it right?

For autodetection, I've gotten several suggestions that are over my head, so... I'm not sure I'm going to get that right.

I'm kind of leading towards just changing it to be telephone handset cord only, and maybe I can get some help on figuring out how to protect the adapter when the computer's 5V is connected to the adapter's ground.
Let me know if there's anything I can help with on the layout or electronics. I'm no expert either, but I've done a few boards now and they all worked. :)

If you used a switch for keyboard vs. telephone cable, I think you're right you'd need some kind of multi-pole switch. Maybe just keep it simple and use a couple of jumpers instead.

Making it only use telephone cords sounds like a fine solution to me. The auto-detection would be really cool, but I know how it can be to have people clamoring to add random extra features to your projects. :)

But if you want to try it, I got a pretty good auto-detection suggestion from the EEVblog forums - let me make some diagrams and post them in a bit.

 
Top