Author Topic: Build your own AMX Compatible Mouse Adapter  (Read 586 times)

Offline Bryce

  • CPC6128
  • ****
  • Posts: 185
  • Country:
  • Gender: Male
Build your own AMX Compatible Mouse Adapter
« on: 01:25, 24 December 09 »
Hi All,
       Everyone's getting all festive and coming up with Xmas games, Christmas Demos etc. And as a hardware person I felt left out :D So seeing as there has been a lot of discussions about AMX Mice and Atari ST adapters, I decided to use my time off constructively and have built a PS/2 / USB adapter that's AMX compatible. You can check out the plans at http://www.cpcwiki.eu/index.php/PS2Mouse and let me know what you think. The page is still a bit rough and the software needs cleaning up to, but it all works and might give you something to do before you get back to work in Jan. When I get around to it, I'll fix up both.

Happy Christmas,
Bryce.

Offline Octoate

  • CPC664
  • ***
  • Posts: 102
  • Country: de
    • Octoate.de
Re: Build your own AMX Compatible Mouse Adapter
« Reply #1 on: 12:20, 24 December 09 »
Wow, that is an awesome christmas present :-). Thanks a lot Bryce, at least I will build it for sure!

Happy Christmas,
Octo
--

Offline Bryce

  • CPC6128
  • ****
  • Posts: 185
  • Country:
  • Gender: Male
Re: Build your own AMX Compatible Mouse Adapter
« Reply #2 on: 13:21, 24 December 09 »
Your welcome,
            had an after thought about the Hardware last night... If you add a push-button between 0V and MCLR (Pin 4 of the PIC) this will allow you to reset the PIC, so that you could "Hot-Swap" the mouse without restarting the CPC. Might be useful? I haven't allowed for it on the PCB, but if the PCB is housed, you could just solder the leads directly to the back of the board. Maybe I'll do a version 2 board after all....

Bryce.

Offline Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 1255
  • Country: gr
  • Gender: Male
  • CPC-Wiki maintainer
    • CPCWiki
Re: Build your own AMX Compatible Mouse Adapter
« Reply #3 on: 10:44, 25 December 09 »
You're a god... could we pay you to make one for us or something? :)


:Visit now!:

Offline Bryce

  • CPC6128
  • ****
  • Posts: 185
  • Country:
  • Gender: Male
Re: Build your own AMX Compatible Mouse Adapter
« Reply #4 on: 16:51, 25 December 09 »
That's probably going a bit too far, but if so... Yeeeh today must be MY birthday :D Lol, but on a more serious note, I had mentioned before, that I was going to develop a few "Exclusive to CPCWiki" projects, and this is more or less the first complete one. I intend doing more, so suggestions are welcome. Like I said, I will try to concentrate on small, cheap circuits that even beginners should be able to build, rather than major Symbiface expansions.

I don't usually do "production runs", and my aim isn't to make money anything I build, I'm very much an Open Source person and just do the design stuff, but I may have a few working prototypes on offer later. I'll let you know...

Bryce.

Offline fano

  • CPC6128
  • ****
  • Posts: 154
  • Country:
  • Gender: Male
    • Bien fait !
Re: Build your own AMX Compatible Mouse Adapter
« Reply #5 on: 13:42, 26 December 09 »
Thx Brice, this is a great present for Xmas  ;D

Offline Bryce

  • CPC6128
  • ****
  • Posts: 185
  • Country:
  • Gender: Male
Re: Build your own AMX Compatible Mouse Adapter
« Reply #6 on: 15:14, 26 December 09 »
Morning All,
          due to the fact that I'm not a very "Christmas person" and the weather is too lousy to play golf, I have managed to find the time to finish the Firmware and add all the stuff I planned. The hardware hasn't changed, so the schematic and layout are still valid (other than the fact that I changed the label in one of the switches). The new firmware has added the following features:

1. Start-up - You no longer need to have the mouse connected at start-up, it will initialise any time the mouse is connected  (this may be useful to people who intend installing the mouse circuit inside the CPC?)

2. Plug & Play - It is now possible to dis-connect and re-connect the mouse without a re-start, including swapping to a different mouse completely (even between PS/2 and USB mice)

3. Auto-Detect - The firmware now auto-detects whether your mouse has a scroll wheel and enables the scroll wheel if present. If you have some fancy mouse that confuses it, the switch nearest the power socket will disable Auto-detect and force the mouse into non-scroll wheel mode (whether it has one or not).

3. Minor reaction time improvement - There was a 20µs second delay at certain times (Yeah I know, it only detectable on an oscilloscope, but I'm fussy about these things!)

These changes also remove the need for the Reset switch I mentioned above.
I have updated the Wiki page to reflect these changes and I might add more about how to program the PIC and possibly a layout for USB only (ie: USB socket instead of PS/2 socket) if it is requested.

Happy New Year, frohes neues Jahr, bonne année, etc...

Bryce

Offline Bryce

  • CPC6128
  • ****
  • Posts: 185
  • Country:
  • Gender: Male
Re: Build your own AMX Compatible Mouse Adapter
« Reply #7 on: 16:08, 26 December 09 »
Oops, just spotted a mistake on the Schematic. In case you have already downloaded the one on the Wiki, the Schematic shows the part 74LS244, it should be a 74LS240 ! The parts list was correct though.

Bryce.

Offline nocash

  • CPC664
  • ***
  • Posts: 119
  • Country:
Re: Build your own AMX Compatible Mouse Adapter
« Reply #8 on: 15:17, 03 January 10 »
Nice project - only one thing is missing: it'd be nice if you'd explain how it works! I mean, what is a AMX mouse, and how does it transfer the data to the CPC?

I've had a look at the original AMX Art software. At first glance, it seems to be joystick compatible... so my first question would be:

Is that all about it? It works like a simple joystick? Or did I miss something important? Like a mouse-detection which switches between special-mouse-protocol-mode and normal-joystick-mode?

If it's really simply using the joystick-style protocol. What I've found out is that it seems to check the joystick port once every 300Hz, and seems to treat joystick up/down/left/right signals as mickeys in the corresponding direction(s). So I guess, on vertical movement, the mouse interface generates a LOW pulse of 1/300s duration (per mickey) on UP or DOWN joystick input.

Oh, and how does the scroll wheel work exactly? The document says it connects to "5" (joy2up) and "6" (joy2down). First of, isn't that vice-versa? 6=up, 5=down?

And, concerning scrolling, the terms "up" and "down" are rather confusing... If you move UP-wards in a document, then text scrolls DOWN-wards on the screen. So "Move DOWN" could have opposite meaning as "Scroll DOWN". I guess "turn wheel away from user" and "towards user" would be much more precise.

Finally, a lisz of the buttons would be nice, like
 Joy1Fire2 (X) = which button
 Joy1Fire1 (Z) = which button
 Joy1Fire3 (-) = which button (middle?)

Whereas, looking at the documentation (pdf file) for the original AMX mouse, left and right buttons seem to have been arranged/used confusingly. There's a strange drawing that looks as if the Right Button is used as Execute Button... ie. much like PC mouse in left-handed mode? Although, the drawing is top-down, so the right button is actually on the left side in the drawing... though I guess that wasn't the way how one should use the mouse, with the buttons & cable pointing towards the user? :-)

Offline Bryce

  • CPC6128
  • ****
  • Posts: 185
  • Country:
  • Gender: Male
Re: Build your own AMX Compatible Mouse Adapter
« Reply #9 on: 21:13, 03 January 10 »
Hi Nocash,
       I'm not sure exactly how much detail of "How it works" you'd like, but I'll answer your questions and if I missed anything let me know:

Firstly, I think that having read the original documentation you now know what the AMX is, in short, it was a mouse which connected to the joystick port and moving the mouse sent the corresponding joystick up/down/left/right pulses to the CPC, while the three buttons sent the three possible fire signals (As you correctly stated, it more or less pulled the particular pin to 0V), but obviously in sequence with the polled common pin, otherwise any of the keyboard characters could appear instead of the joystick arrows, as the joystick common is being polled as part of the keyboard matrix, merely connecting the "up" pin to ground will give you the series of other keys which are in the same column of the matrix if it is grounded while the other column is being polled. The 74LS240 has an output enable pin, which is connected to the common, this means, the pulses are only passed on to the CPC at the correct moment.

A PS/2 mouse needs to be initialised and configured by a host before it will do anything useful and after this has been done, it sends back a 3 or 4 Byte serial signal on the data line (4 if in scroll-wheel mode). The first byte primarily contains 3 bits for the three button states and 2 bits for the sign (+/-) of the relative movements of the x and y axis, the second byte is a two's compliment value of the x movement and the third is the same for y movements. The fourth byte, which is only sent if the mouse has been switched to scroll-wheel mode contains the Z movement (ie: the scroll-wheel), the PIC in my circuit  auto-detects the type of mouse and does all the required initialisation and then continuously polls the mouse and converts the two's compliment values into the associated up/down/left/right signals. It also has error handling, so that if the mouse is disconnected, it will wait for a new mouse and then re-initialise and re-start the polling.

Did you miss something important? No, probably not. The AMX software will work perfectly well with a 3 button joystick, but some people just like the idea of using the software with a mouse as it was originally intended. As well as that, modern CPC GUIs such as FutureOS and Symbos fully support AMX hardware and are much more comfortable to use with a mouse than a joystick.

The scroll wheel is a difficult one. Obviously it wasn't available on the original, so there is no standard to adhere to, but I thought, why waste a good scroll-wheel when it's there. As you also correctly stated (my confusing description of the scroll-wheel up/down signal) 6 is indeed up and 5 is down. The reason I swapped these, is because that's exactly what a PC scroll-wheel does, it swaps the concept of up and down, I could have just as easily used the signals the other way around, but I had to decide on one of them. To better explain the function: Rolling the scroll-wheel away from you (finger heading towards screen) will result in a 5, rolling your finger back towards yourself will result in a 6. If there's a compelling reason to reverse this, then let me know and I'd be happy to supply a new version of the firmware with the logic reversed. I will edit the project page and improve the description also.

The buttons are mapped the same as the AMX mouse (yes the original AMX documentation went out of its way to confuse the user): Assuming a right-handed mouse... The left button (index finger) will return an X, the right button will return a Z and the centre button is fire 3 (this one doesn't result in any character).

Does that explain it better? If I left anything out let me know...

Bryce.

Offline nocash

  • CPC664
  • ***
  • Posts: 119
  • Country:
Re: Build your own AMX Compatible Mouse Adapter
« Reply #10 on: 23:01, 03 January 10 »
Hi, I've just added a new section, called "Mapping to Joystick Signals", on the PS2Mouse page. I hope it helps to understand how to access it by software, and that I didn't get any mistakes in there.

So the AMX hardware can handle max 300 mickeys per second? Don't know for sure, but I guess a mouse can send more than 300 mickeys when it's moved quickly... so you need to clip it to max 300...?

Looking at the AMX Art software, it seems to translate 1 mickey to 2 pixels (or maybe other values when using the SLOW and FAST mode), but without supporting double-speed threshold. I guess that feels "sticky". Anyways, that's a software problem, not a hardware problem.

Yes, up/down can be confusing concerning scrolling. And, no, don't change the firmware. Just make the description less confusing - towards user / towards screen should be better than up / down.

And, no! You CANNOT rename Joy2Up to Joy2Down. It's totally okay if you assign Joy2Up=ScrollThisOrThatWay, but how can you assign Joy2Up=Joy2Down? That's crazy! :-)

Btw. USB mice are really pin-compatible with PS/2 mice? Does USB have a CLK signal at all? I thought USB-to-PS/2 adapters would contain a microprocessor, too, for protocol conversion.

Offline Bryce

  • CPC6128
  • ****
  • Posts: 185
  • Country:
  • Gender: Male
Re: Build your own AMX Compatible Mouse Adapter
« Reply #11 on: 00:09, 04 January 10 »
Hi nocash,
           a PS/2 mouse connected to a PC sends a value between 0 and 255 for each direction and the PC reacts according to the value received, but it can do this much faster than the CPC requires, so to make things easy, I just ignore the value more or less, and just check the direction and that the value is above zero. So any movement will trigger a single joystick signal. I can also set the sensitivity of the mouse internally so that a small movement triggers the mouse immediately, I have reduced this to make the mouse less sensitive. The mouse is a little "sticky" and also accelerates logarithmically (ie: it gets faster with distance) I think this is a side effect of the key repeat function of the CPC. This has the effect that the mouse reacts differently to a PC mouse. If I move a PC mouse really quickly, the value will be 255 and the mouse shoots across the screen (255 notches). This is impossible with the CPCs joystick port speed, the CPC moves one notch (2 pixels in the AMX art package) every time the mouse direct signal is low, so the movement speed can not be relative to the mouse movement speed.

On USB mice and converters:

PS/2 mice have a small microprocessor to handle the settings and handshaking required. USB mice (at least the basic ones) have a software compatibility for PS/2, this means that if they receive a USB command (Request ID) at initialisation they will act as a USB mouse, but if the host sends a PS/2 command (reacts to the AA message from mouse), the mouse assumes PS/2 functionality. My circuit attempts to force a USB mouse to PS/2 functionality and if the mouse doesn't answer properly it will report an error by flashing the LED. As far as the hardware is concerned, they have exactly the same pins: 5V, GND, CLK and Data, just a different connector and protocol. Probably the biggest difference is that with PS/2 the mouse controls the clock signal, whereas with USB, the host controls the clock, the clock speed is also much higher with USB and more than one device is possible, because each device has a unique device ID integrated into the protocol packages. The little green PS/2 to USB converters are nothing more than two connectors soldered together. Cut one open and see for yourself.

Bryce.

Offline redbox

  • CPC664
  • ***
  • Posts: 127
  • Country:
Re: Build your own AMX Compatible Mouse Adapter
« Reply #12 on: 02:26, 04 January 10 »
This is incredibly cool and I will give it go after the success of building my parallel cable (!).

Offline nocash

  • CPC664
  • ***
  • Posts: 119
  • Country:
Re: Build your own AMX Compatible Mouse Adapter
« Reply #13 on: 03:57, 04 January 10 »
> PS/2 mouse connected to a PC sends a value
> between 0 and 255 for each direction
Yup. I know the RS232 mouse protocol, which is probably similar.
RS232 mice can send max 128 mickeys per 3-byte packet, and about 40 packets per second. So the total maximum would be 5120 mickeys per second.

> to make things easy, I just ignore the value
> more or less, and just check the direction
> and that the value is above zero.
Uhm, you are ignoring it? You mean, for each packet, you are simply turning the joystick signal on or off? And if yes, how many packets are you getting per second? If it's not more than 40 packets (as for RS232 mice), then you'd have only 40 mickeys per second, right?

> The mouse is a little "sticky" and also accelerates
> logarithmically (ie: it gets faster with distance)
> I think this is a side effect of the key repeat
> function of the CPC.
Err. Yes. That would happen when accidently moving the mouse at the BASIC prompt. I hope you aren't using the Keyboard Buffer for reading the Mouse Data! That'd get you only 10 mickeys per second or so ;-)

> If I move a PC mouse really quickly, the value will be 255
> and the mouse shoots across the screen (255 notches).
Sorts of. The modern MSDOS/Windows mouse drivers are a bit more clever, and they'd typically step twice as far: 510 notches, since they use the double speed threshold thing (eg. if mickeys<10 then pixel_step=mickeys*1, else pixel_step=mickeys*2).

> This is impossible with the CPCs joystick port speed
But it is possible. At hardware side, everything up to 300 mickeys/second should be perfectly working as on PCs. The only problem is that the AMX can't handle bigger values like the RS232-maximim of 5120 mickeys/second.

Btw. you are aware of the 300Hz thing, aren't you?
(Just asking because I haven't seen it mentioned anywhere on the PS2Mouse page)
Ie. the AMX software uses the CPC's 300Hz interrupt to read the joystick port (of course via IN opcodes, not via BIOS). So, I guess, it would be extremly important that your PIC firmware follows that method, and updates the joystick signals exactly 300 times per second.

Hmmm, unless you are intentionally updating it much more often, like 3000 times...? So the AMX software would "randomly" read only every 10th value...? I guess, even if it the software misses 9 of 10 values, maybe that could somehow give statistically correct results...?

Offline Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 1255
  • Country: gr
  • Gender: Male
  • CPC-Wiki maintainer
    • CPCWiki
Re: Build your own AMX Compatible Mouse Adapter
« Reply #14 on: 10:42, 04 January 10 »
I guess I learned more than I ever wanted to know about cpc mice. Here's a toast for more similar discussion, with special thanks to Bryce and Nocash!

By the way: I haven't used my AMX mouse for a looong time, but I wanted to ask - does it support accelerated movement? Meaning, does the cursor moves according to the speed you move the mouse? I'd think it's an obvious 'yes', and the polling speed is there for that (although a bit slow), but somehow I seem to remember it being otherwise...


:Visit now!:

 


CPC-Topsites
Webspace + Domain zum sonnigen Preis