MTX Pi

Everything about Andy Key's great Emulator MEMU
User avatar
Dave
Posts: 676
Joined: 11 Aug 2012 18:16
Contact:

MTX Pi

Post by Dave » 03 Sep 2015 12:23

Hi guys,

another one of my interminable MTX projects is a plan to put a Raspberry PI inside an original MTX case and use the MTX keyboard to drive the Pi running MEMU.

I had a brief discussion with Bill on this a while ago, but it never really progressed as I couldn't get hold of an MTX keyboard that wasn't part of a functional MTX. However, that has just changed, and although I had to spend more than I wanted to, I bought the orphan MTX keyboard that was just on ebay.
So, now I have the keyboard and a Raspberry Pi, all that remains is to tie them together :-)

That's where I need some help please . . . . . .

I have included some extracts from the e-mail conversation that Bill and I had, I'd like to finalise the hardware so that I can do the construction, so your input into the discussion would be most welcome. At the moment, I am just thinking about going with the hardware list that Bill suggested (below), but am open to other suggestions too.

The bigger issue though is the software, I'd need a willing volounteer to do the MEMU patches to work with the keyboard and potentially, other I/O ports.

Any takers ?

regards
Dave

<DS>
I would like to build a MEMU-Pi inside a real MTX, replacing a duff mother board and using the old MTX keyboard. Yes, I know that the keyboard might not be great, but it would look fantastic. My question is, how much work would I it be to directly connect the MTX keyboard connector to the GPIB pins in the Pi and write some code to translate the key presses to MEMU speak? I guess that some of the PC hot key functions would need to be remapped to, say, MTX Function keys, but is there anything major in the way of being able to do this?

- - - - - - - - - -

<BB>
With regard to interfacing a real MTX keyboard to MEMU-Pi, it is certainly possible, but there are a few issues. The MTX keyboard requires 8 drive lines and 10 sense lines, so at least 18 GPIO ports, 19 if you also want to monitor the reset keys. The RPi has at most 17 GPIO on P1. On the Rev. 2 boards there are a few more GPIO on P5, so it would be just about possible. However, a better solution would be to use an I2C based I/O expansion board to provide the necessary number of connections. There are a number of commercial expansion boards that would be sufficient to connect the keyboard.

However, I have been fantasising about a custom board that would supply keyboard connector, joystick connections (in parallel with keyboard, as per MTX), printer port, two serial ports, and perhaps even the internal MTX PIO port. Attempting to emulate the expansion bus would probably be a stretch too far.

With regard to user interface, the reset keys could act as the SysReq key, bringing up the configuration screen. If this then included an option to select which of the screens to display, then you would not need to change any of the functionality of the main keyboard at all. Even better would be if it was possible to monitor the two reset keys separately. Then one key could be SysReq, while the other toggles between screens. However, that would require a modification to the keyboard PCB. There are a number of ways this could be done, either adding wires or diodes, without having to cut any of the tracks.

- - - - - - - - - -

<DS>

Thanks for the info. Your custom I/O board sounds just the thing, if you get time to do it, I'd be really interested in seeing the design. I imagine that you'd make your own board (?), but if it ever became a reality, I would get a PCB manufactured.

Separate reset key functions would be neat, if the MTX keyboard was interfaced with your expansion board, could any required modification be done on the board, rather than on the keyboard PCB? As no tracks need cutting, this might be possible?

- - - - - - - - - -
<BB>

In order to get separate reset keys, you have to modify the keyboard PCB in some way in order to get at the connection between the two reset keys.
The simplest solution is to solder a wire from the track joining the two reset keys keys (not connected to the plug), and solder the other end to one of the main keyboard drive lines. Then the two reset key connections become additional sense lines.

Another approach is to solder diodes across the reset keys, with cathodes on the sides that connect to the plug, and anodes on the sides that just connect to each other. Then on the interface board, put pull ups on both reset key lines. Drive one side low and the other side becomes sense for one of the keys. Remove the drive from the first side, and apply it to the second. The first side is then sense for the other reset key.
Unfortunately, both of these approaches would interfere with the operation with a standard MTX motherboard. The only fully compatible solution I can think of so far is to add a separate 21st connection to the track joining the two reset keys.

Actually, the second approach would almost work, except that one of the two reset keys (but not the other) would be sufficient to reset the MTX.

- - - - - - - - - -

<BB>

A possible solution using available hardware:
* RPi
* One (or possibly two) IO expansion boards (http://www.pi-supply.com/product/quick2 ... board-kit/)
* 4 port powered USB hub.
* Two USB to serial convertors
* One USB to parallel converter.
There should be room for all of that inside the MTX case.
Then it is only a question of software.

- - - - - - - - - -

<DS>

What we need is some one with lots of experience coding for the Z80 and the RPi, where are we going to find someone like that I wonder :-)

- - - - - - - - - -

Bill B
Posts: 148
Joined: 26 Jan 2014 16:31

Re: MTX Pi

Post by Bill B » 03 Sep 2015 14:13

Dave,

OK, I will bite.
  • Use a Raspberry Pi B+ or 2B. They have more than enough GPIO lines to work the MTX drive and sense lines directly. Connect the appropriate ones to the joystick ports as well and those come free. Software wise it is dead easy. Skip all the complex event trapping and keyboard mapping, and just have the appropriate emulated Z80 I/O commands read and write the GPIO pins. A few hours work.
  • These RPi have four USB ports, so you can plug two USB to serial devices in. I already have all the necessary MEMU code from my work on NODE. EDIT: Or for one of the serial ports you can use the RPi built in serial, in which case all you need is a 3.3v to RS232 level shifter. (One of the MAXnnnn chips, I forget which one).
  • Printer port is more interesting. It would be possible to use a USB to parallel, which would be OK if all you want to do is print. However, I think it would be better to use an I2C port expander. This would then give MEMU the ability to drive all the pins with the same flexibility as the MTX, if you want to control devices such as my device programmers. Requirements are:
    • Does not block access to the other GPIO pins,
    • 5v tolerant inputs.
    • Preferably 5v logic output (rather than 3.3v).
    • Because of space requirements in MTX case, a separate board wired to the RPi, rather than on top.
    There probably is such a board, but a bit of research needed. This will require a bit more software development.
  • If you really want the PIO as well then another I2C port expander with a different I2C address.
Bill.

Bill B
Posts: 148
Joined: 26 Jan 2014 16:31

Re: MTX Pi

Post by Bill B » 03 Sep 2015 19:17

Dave,

Thinking about this further, will a B+ or 2B fit in the MTX case? As Martin remarked recently, there is not much room under the keyboard.

If not, then an A+ is indicated. Still possible, but it does change the additional hardware needed.

Bill.

User avatar
Dave
Posts: 676
Joined: 11 Aug 2012 18:16
Contact:

Re: MTX Pi

Post by Dave » 04 Sep 2015 00:48

Hi Bill,

thanks a lot for taking the bait :-)

I have a B+ that I could use for this. As you said, the space in the MTX case is pretty tight, I need to measure it, but with no MTX computer board in there, or at the RHS where there would not normally be a board installed, there will probably be enough room to fit a Pi at the back of the case, in the deepest part.

I will measure the space in the morning and then, hopefully, fix the RPi model and go from there

regards
Dave

Bill B
Posts: 148
Joined: 26 Jan 2014 16:31

Re: MTX Pi

Post by Bill B » 04 Sep 2015 13:52

Dave,

Too many ideas (as usual).

I remembered this post on the Raspberry Pi blog. With this, it would be possible for MTX Pi to have simultaneous 40 & 80 column displays, as per the real MTX. Only problem is that it takes up most of the GPIO pins.

More research needed to determine whether at least one of the I2C interfaces are still available. If so, it would still be possible to use an I2C port expander to connect the keyboard.

EDIT: Now available to buy here.

Bill.

Bill B
Posts: 148
Joined: 26 Jan 2014 16:31

Re: MTX Pi

Post by Bill B » 05 Sep 2015 11:12

I have now researched the VGA option a bit. Use of this blocks the use of i2c1. If not using a HAT, and since will not be using the camera, i2c0 should be possible, although it is not recommended.

Also, driving the two displays would require use of the DISPMANX API, which is less than well documented. This would require a total re-write of the display code. While, in the long term, it may have some performance advantages, it is not going to happen in a hurry.

So, an inteersting idea for the Mk 2, but not for the Mk 1.

User avatar
Dave
Posts: 676
Joined: 11 Aug 2012 18:16
Contact:

Re: MTX Pi

Post by Dave » 05 Sep 2015 11:25

Hi Bill,

thanks a lot for the research / info.

OK, single video output for Version 1 it is then :-)

regards
Dave

Bill B
Posts: 148
Joined: 26 Jan 2014 16:31

Re: MTX Pi

Post by Bill B » 05 Sep 2015 11:45

For the printer port, this is one board that appears to meet the requirements. There are probably many others.

Note that the circuit is actually fairly simple. You might want to consider a single custom PCB that:
  • Interfaces the keyboard & joystick connectors to the GPIO pins.
  • Implements the MCP23017 circuit for the parallel port.
  • Uses a MAX3232 chip to provide RS232 levels from the RPi serial port.
*** CORRECTION ***

Having read all the documentation carefully, you cannot use this board with 5v Logic on a RPi :oops:

Using the MCP23017 chip there are two options for obtaining 5v logic:
  • Run the chip at 5v, and use I2C compatible level shifters between it and the RPi.
  • Connect the chip directly to the RPi, and use level shifters on the inputs / outputs. Since for a printer port the connections are uni-directional, these can be simpler (just resistors for the inputs).
Bill.

Bill B
Posts: 148
Joined: 26 Jan 2014 16:31

Re: MTX Pi

Post by Bill B » 08 Nov 2015 11:58

MEMU-Pi+MTX-Kbd.jpg
MTX Keyboard Attached to MEMU-Pi
MEMU-Pi+MTX-Kbd.jpg (214.3 KiB) Viewed 2405 times
Some Alpha code. An MTX keyboard being used to type into MEMU-Pi. The keyboard bounce seems to be slightly worse than on my MTX, but that may be due to the surface I am working on.

The observant may have noticed the connector of a USB keyboard also attached. That is only used to start MEMU-Pi, during development I don't have auto-run setup. All the text visible on the screen was typed using the MTX keyboard.

It would probably be possible to make the MTX keyboard work in Linux, but that is a problem for another day. Also it would not me helpful for MEMU, converting MTX key presses into Linux scan codes, only to have MEMU convert them back into MTX key presses.

More work to be done before I release any code. At present the Reset keys are not doing anything, and I need to make the configuration screen work, and that does need scan codes.

One point I have discussed with Dave, I am using a hardware configuration file to specify which RPi pins the keyboard is connected to, rather than having a fixed configuration. This should (eventually) allow:
  • MTX keyboard
  • Atari style joysticks, either connected to the keyboard scan & sense lines as per the real MTX, or connected to their own GPIO pins as per previous MEMU-Pi (but using any GPIO pins rather than the fixed ones used previously)
  • Centronics printer
  • Use of an MCP23017 port expander to provide enough connections for all the above.

User avatar
Dave
Posts: 676
Joined: 11 Aug 2012 18:16
Contact:

Re: MTX Pi

Post by Dave » 08 Nov 2015 13:07

Hi Bill,

Great news!

I am progressing the hardware for my project - albeit a bit slowly!

I have made a start with wiring up the MTX SIL to RPI GPIO interconnector. I thought a bit more about the reset keys, and your method of reading them separately is a great idea, so I will make that small mod to the keyboard PCB - it is trivial and easy to remove if I ever wanted to get back to a standard MTX keyboard connection.

I have got a mini SD card extension cable to bring the SD card connector to the back of the case and have ordered a 3.5mm TRRS socket to split the composite and audio signals out for the case I/O port layouts. I also have a HDMI connector extender to bring the HDMI connector out of the case, but I am struggling to mount it neatly without ruining the case and/or plastic spacer with the ports on it. Ideally, I would be able to get an MTX end-plate and mount the HDMI bulkhead connector on it, but that's another "to-do". Composite will be fine to start with.

I am also thinking about brining out the network connector too, although I don't have a reason to (yet)

It's all coming together though !

regards
Dave

Post Reply