Toastie

Sinclair ZX Spectrum (1982) and LEGO Interface A (1986): #9750 controlled by a Speccy

Recommended Posts

Dear All,

motivated by Evan's Eurobricks 9750 hacking challenge, I tried to get my beloved ZX Spectrum (Speccy) in touch with the LEGO Interface A (#9750). It appears as if TLG never wondered into Sinclair world; they were more on the professional IBM, Apple, Acorn, Commodore, and Philips side of things. Expensive things that is; not on the el cheapo side, were I was.

My Spectrum is an Issue.3 machine from 1983 –Sinclair introduced the legendary ZX Spectrum in 1982 – as successor of their legendary ZX81 from 1981, which was the successor of their legendary ZX80 from, guess when, yeah 1980. And yes, I do like the Sinclair machines very much, as they taught me (a low income chemistry student) how computers work on the hardware level, at the lowest price tag possible (so I could afford these machines) and they taught me how machine language and assembly works.

A very nice coincidence regarding LEGO Technic Control and computer hardware for the masses in the 1980’s is shown in the photograph below:

800x445.jpg

The background is a copy of one page of the service manual of the ZX Printer, which came out in 1981. I also had one for printing endless lines of Z80 disassembly code (mostly for cracking the copy protection of video games, see “print” on the right). At the top center there is a Technic 4.5V motor (#6216), a Technic disk with 4/8 black sections (#2958) attached to the hole of an 4.5V light sensor brick (#1161); actually the latter has an IR emitter and IR sensor inside. The Interface A powers and reads these and thus the status of the disk: Black = 1/off, white = 0/on. TCLogo running on a PC samples the >change event< with 1kHz temporal resolution, has two counters, and calculates the frequency of the changes, among other things, and makes them all available to the user. Well written assembly code >is< fast … On the bottom there is the main board of the ZX Printer along with its DC motor – and a disk and the light emitting diode. The disk has transparent and reflective sections (many more as compared to the Technic disk) but the principle of operation is absolutely the same. The Ferranti ULA took care of all the above; the Spectrum (or ZX81) just had to send “make dot”.

Spoiler

My ZX Printer was totally toast – the belt disintegrated to pieces, the stylus was also damaged – about 5 years of almost continuous operation, 38 years in total and 4 household moves (one over the big pond to the US) was simply too much. I kept it, though, as I love the concept of literally burning holes into the surface of aluminum metallized black paper (https://en.wikipedia.org/wiki/ZX_Printer). This is what it does, using "high voltage" … as a side effect, such a printer generates good levels of ozone – which in turn kills germs. So printing out several meters of assembly code did affect breathing a bit – but no germs around the working space. The 1980's – it was a different time …

I got my Speccy in 1985, and more or less immediately begun to tinker with the hardware, learned Z80 machine code, cracked Sinclair computer games for friends (and for electronic stuff in return; I never made it into video games, something is wired incorrectly in my head, I guess). Wrote my advance chemistry reports using Tasword II … and always dreamt of controlling “something” with the Speccy. The June/1984 issue of the Elektor magazine had a bunch of hardware additions for both the ZX81 and the ZX Spectrum. One was a 32k bit memory expansion circuit; it was simply used for bank switching of a regular set of eight 1-bit x 64k dynamic RAM chips (4164). Back in the days, Sinclair offered a 32k expansion set (8x 1bit x 32k dynamic RAM chips, and three TTL chips to be placed in empty sockets on the 16k ZX’ PCB. I never figured out who made or sold 32k chips until recently – they were never sold to earthlings like me. These were defective 4164 chips – defective in terms of one bank of 1bit x 32k was faulty. With appropriate markings, a set of 8 4164s with the same bank (0/1) defect, resembled a 32kByte expansion. Sinclair apparently purchased these (otherwise trashed) chips in great numbers and sold them with great profit to customers. All you had to do is getting the 8+3 chips into the corresponding sockets, and solder one of two possible bridges selecting bank 0/1 - depending on the batch of chips you got from Sinclair. Not to me though; I got hold of intact 4164’s and then added the Elektor bank switching circuitry within the Speccy by gluing the additional chips onto the CPU and parts; I simply needed the free edge connector to attach the ZX Interface A, which had an RS232 port for printing my reports on the printer of a friend …

I did change the Elektor layout, though. I kept the 2 RS flip-flops build with two 74LS02 4x2 input NOR gates to switch a) the two memory banks and b) for turning an LED attached to the case of the Speccy (as I said, I wanted to switch at least “something” … and be it an LED …). Instead of decoding 1 address for switching the memory banks, I used a 74154 "4 to 16 de-multiplexer", which was giving me essentially 16 output channels. However, according to the Z80 documentation, only 256 I/O ports are available, which are accessed via address decoding + pulling IORQ#, RD# (read data bus) or WR# (write to data bus) low. As my Speccy was (resurrected two years ago) I used exactly this circuitry to reach out to #9750 …)

Here we go:

Inside my Speccy, the address lines A5 to A7 and the I/O request (IORQ#) line of the Z80 CPU are already hooked up to provide 8 “chip enable” signals (L=enabled), that I can “freely” use. Due to the “interesting” I/O port address decoding of the Spectrum’s very own hardware (>every< even address activates something in the ULA – Ferranti’s uncommitted logic array chip. It does almost everything other than CPU/memory stuff), care has to be taken upon addressing further I/O ports. Address 1 works, 2 does not, 3 works etc. Sinclair did that for cost saving purposes of course, as the address decoding is kept to the absolute minimum. The Z80 CPU has 16 address lines, which means a lot of decoding to filter out one specific address. Now, other add-on hardware (Sinclair Interfaces 1 and 2, or one of the myriads of third party vendor products, for example) then need to tip-toe between the even addresses – and when they went cheap as well, entire address ranges are blocked as well. Back then (1986 that is) I “blocked” the address range A5 - A7 with all A0 – A4 = 1 (no even addresses!), which gave me 31 (0x1F, bin 1 1111), 0x3F, 0x5F, 0x7F, 0x9F, 0xBF, and 0xFF as I/O port addresses. My ZX Interface 1 does not use these, so they actually work, even today.

I used I/O port 1 = 0x1F for 32k bank switching, 0x3F for turning an LED on and off. The latter is the port I am using here to control #9750 as well. The BASIC commands are (as usual …):

OUT 63, data (data = 0 to 63 for any of the 6 channel configurations) – this turns also the front panel LED on

LET i = IN 63 (which returns the status of the 6 9750 output channels as well as the 2 sensor channels – this also turns the LED off).

I simply copied the LEGO #9771 ISA card approach using two 74LS373 transparent D-flip flop latched as described in detail here. This is a rather elegant way of getting instantaneous feedback on the output status using rather cheap, but electrically powerful chips (TTL drivers). I/O address decoding is done in the Spectrum’s gut as shown in lower left blue box in the schematic below, with the 3 “extra” (see below)

lines RD#, WR#, CE#:

1280x705.jpg

How does it work?

When the Z80 writes to an I/O port, it puts the corresponding address on the address bus, pulls IOREQ# low, puts the corresponding data on the data bus and then pulls WR# low. The address is decoded by 74154; the corresponding output (0 – 15) goes low, but only when the chip’s outputs are enabled, which is the case, when EN1# and EN#2 are both low. EN2# is always low as it is tied to GND, EN1# when IOREQ# is low. IC3c (NOR gate) receives the Q1# output signal on one input, WR# on the other. When both are low, C of IC5a goes high and the transparent latches follow the signal at its 8 (6 only used for #9750) D inputs which are connected to the data bus of the Speccy. During this time, the Z80 holds the data from the BASIC "OUT" command static on the data bus. Upon pulling C high again (write cycle is over), IC5b freezes-in the 8 data inputs and clocks them onto the corresponding Q outputs connected to #9750. As OC# is always low, the outputs of IC5a are always enabled.

When the Z80 reads from an I/O port, essentially the same things as above happen; now the RD# line is pulled low (somewhat delayed, i.e., closer to the rising edge of IOREQ#), and data are transferred to Z80 the accumulator register. However, the outputs of IC4a, again transparent D latches, are only enabled, when the correct address + IOREQ# + RD# is active, i.e., for a very brief moment. It has to be this way, because the Q outputs of IC4a are connected to the system’s data bus and would crash it at once when RD# goes high again (read cycle done). Most of the time pin C of IC4a is high (in contrast to IC5a, where it is always low = enabled), so the Q outputs are in tristate (high impedance or simply “not there)”, but the D inputs constantly read a) the state of IC5a’s outputs and b) the two sensor lines from 9750, i.e. they are always up to date. Upon a valid read request, pin C of IC4a goes low – at the same time its outputs are enabled: #9750 status freezes-in and is clocked onto the Q outputs = Z80 data bus.

I like this approach using the transparent latches very much! This is of course owing to the fact that TLG’s programs (TCLogo and the like) write the “code” 00010101 (0x15) to #9750, then read back the #9750 status (the sensor readings are stripped, as they may have changed in between OUT and IN).

The remaining connections required for the interface (data lines D0 – D7, +5V, GND) are obtained from the edge connector of the Spectrum’s PCB. Although I have the corresponding bare plug, I wanted to use the ZX Printer cable and case as interface box, as an homage to Sir Clive Sinclair :pir-huzzah2::

800x622.jpg

For the parallel Atari and the serial PC interface (USB and/or RS232), I made brick-built cases. Initially I tried using an Intel 8255 PIO (https://en.wikipedia.org/wiki/Intel_8255) as communication hub for #9750 (= total overkill, but I had three of the PIOs) – because it is a fun chip, debuting in the mid 1970’s. I guess I got the addressing wrong; a 8255 wants to know, what to do upon powering up, default is all three 8-bit I/O ports = inputs. I could not get the configuration right – I guess the ULA was addressed as well and things totally screwed up. I shall give it a second try “later”.

I thus reverted to TLG’s “2x 74LS373” design, and made a perfboard version of the circuit shown in the schematic above, which fits into the ZX Printer case. I used the original printer cable (rewired inside the plug, as the printer uses other signals then #9750, such as address lines) and made no changes to the outer appearance of the printer. There are only 12 wires available; thus the 3 extra wires from the Speccy came in handy as additional inputs to the interface. Absolutely not nice, but: works. I guess a black ribbon cable looks nicer, but right now I don’t have one.

400x264.jpg400x383.jpg

Upper two pictures: (Left) Perfboard mounted into the printer case and (right) connector to #9750 and address decoding board. The latter is simply tying together RD#, WR#, and CE# controlling the C and OC# inputs of the two 74LS373. I made this extra board so that a different approach using 74LS374 just requires exchanging them for the 373’s (they have the same pinout), which are clocking in the data upon any rising edge at their CLK input (recall that 373’s freeze in data when C = low and set their outputs accordingly; no edge trigger required, and the Q outputs follow the D inputs when C = high). 374’s thus need a slightly different address decoding using NOR gates – and thus only the additional board needs to be replaced. This board is attached with Dupont type connectors.

640x657.jpg640x664.jpg

Upper two pictures: Finished interface without (left) and with (right) metalized paper roll inserted. I need to make a cover for the soldered pins of the 20 pin flat cable connector I desoldered from an old Shimadzu mass spec in the lab; otherwise the paper may cause shorts.

Almost forgot: The switch S1 in the schematic above is actually the original paper feed switch of the ZX Printer, located at the top right of the case. Sinclair used this switch upside down: The knob sits in a fitting mount on the bottom of the printer case; a plastic rod extension with a little knob at its upper end is the switch’s actuator – you are pressing the switch body onto its fixed knob – I love it. Simply ingenious. In my setup, the switch pulls the "OC#" line of IC 5a high, and thus turns it's outputs off - should something go wrong on your TC LEGO model and #9750 is not in reach.   

And finally here is the entire ZX Spectrum + ZX Printer interface + LEGO Interface A – the program running is the old-fashioned TLG version; but this time, the presence of #9750 and the interface is checked by asking for the answer to the ultimate question of life, the universe, and everything, which is 101010 of course:

1280x540.jpg

BTW: I think the LEGO Interface A “look” very nicely matches up with the ZX Spectrum and ZX Printer design; too bad TLG did not see that, back in 1986.

Sinclair BASIC at its best:

800x597.jpg

The program does this:

https://bricksafe.com/files/Toastie/zx-spectrum-and-9750/ZX9750.m4v

Best wishes,
Thorsten

 

 

Edited by Toastie

Share this post


Link to post
Share on other sites

A sweet topic for us, older Technic and computer fans!

It reminds me my attempts to link the Lego and ZX Spectrum worlds back in late 1980s.

I was lucky to have had the Spectrum+ version whose larger case allowed me to build in a 3-port parallel interface (8255) and additional memory banks. I have also designed and built an interface for controlling LEGO models (up to 4 motors, 8 LEDs and 4 photodiodes used for feedback control). Here are several pictures:

lm-01-control-unit-and-computer.jpg

lm-03-control-unit-rear-view.jpg

lm-04-control-unit-inside.jpg

It allowed me to control various manipulators ... 

lm-20-manipulator1.jpg

... and also vehicles (via a joystick connected to the parallel interface as well).

lm-23-car-with-joystick.jpg

Some other pictures can be seen on my Brickshelf.

Share this post


Link to post
Share on other sites

@Jonas

Holy moly - attempts? You call that attempts? Attempts? I call that LEGO Interface A++!!!

This is extremely nice - I have tears of joy in my eyes! Are you in the picture above and on Brickshelf? When did you build that nice interface? When did you take the b/w photographs? Do you have any schematics? Programs? Did you program in Sinclair BASIC, machine code, or both? I guess the photodiodes needed some fast code to give reliable feedback? Questions over questions

It is so nice to see a Spectrum+ along with a powerful home-built interface for LEGO Technic!

Thank you very much for sharing!

All the best,
Thorsten 

Share this post


Link to post
Share on other sites

Hi Thorsten,

thanks for your warm response. And yes, it was so nice times with old good Speccys,

I had built my interface in 1988. I have no schematic anymore, but I still remember that I used integrated stereo amplifiers to make small-footprint H-bridge drivers for motors.

My programs were written mainly in Basic but the time-critical parts, such as controlling motors with opto-sensor feedback or joystick control, were coded in Z80 assembler.

BTW, I had built also another interface with 8-bit AD and DA converters and used it for my experiments in those early times of speech recognition. A large part of my dissertation in 1980s was made on my Spectrum.

Unfortunately, the computer does not function anymore. But it still has a place of honor in my private exhibition.

 

Edited by Jonas

Share this post


Link to post
Share on other sites

Oh yes, I saw these monsters - how nice to use stereo amps as H-bridge drivers!

What's wrong with your Speccy? Any wish to get it up and running again on your side?

Best,
Thorsten

Share this post


Link to post
Share on other sites
7 hours ago, Toastie said:

What's wrong with your Speccy? Any wish to get it up and running again on your side?

If I remember well, one of the key circuits was damaged during my HW experiments in 1990s. I switched to PCs in my professional work and to embedded systems (like Arduino) in my hobby. See here.

Share this post


Link to post
Share on other sites
9 hours ago, Jonas said:

one of the key circuits was damaged during my HW experiments in 1990s

Oh yes - I wonder why I did not kill any of them back in the days - I glued one additional TTL to the CPU and piggybacked others ...

16k%20and%2048k%20SpectrumsRed.jpg

But you know that you can get all system components including the ULA, 4116, 4164, Z80A CPU, etc., for relatively small money. There are so many people out there still enjoying these machines! Even mass storage is available for less than €100.

That seem to be very exciting projects you have going with the Mega and Unos!!!

Did you see this? I am also very much into Arduinos and even more so into ESP32's - this interface works with all sorts of computers (via the blessed RS232 port) ...

All the best,
Thorsten
 

Edited by Toastie

Share this post


Link to post
Share on other sites

Interesting projects! I also learnt to program for the first time on a speccy. And I remember the old sinclair printer. I only had a small bedroom and the metallic smell generated after printing for more than about a minute used to hang around all evening.

Share this post


Link to post
Share on other sites
On 10/11/2023 at 2:08 PM, MAB said:

printing for more than about a minute used to hang around all evening

Oh yes! It consists of vaporized aluminum (turned into oxides, so no worries!) and the tiny electric discharge produces - among other things - ozone. And most importantly, some vapors from the black paper underneath the aluminum layer, which are adding a little smoky smell to it. Whenever I take a sniff from a glass of 12 years old Lagavulin, it reminds me of ... well, I liked this smell :pir-laugh:

Best,
Thorsten

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.