Greetings to All ZX SPECTRUM Enthusiasts!
Starting with this issue of ZX LAND and for the next few issues, we’ll be looking at controlling and monitoring devices connected to our wonderful microcomputer.
At the same time, I’d like to remind everyone that connecting any devices can end tragically, so it should only be done by people who have some experience in this area.
In this first part, I’ll describe how to get an input/output port.
An input/output port is an electronic device that allows the computer to communicate with the outside world. There are many different solutions, including the cassette or disk drive interface, the joystick port, etc. Anyone who decides to control a device should have such an interface in their collection: a window between the computer and the device or devices being controlled.
The best solution is to get the well-known port bearing the designation 8255. Unfortunately, not everyone can do this because of the cost, or simply because ready-made interfaces for our ZX are not available. So I suggest using an old SOUND AY 3-8910 for this purpose (probably everyone already has one).
Not everyone knows that our good old AY 3-8910 has two programmable ports that can be put to use for our purposes.
All you need to do is bring these signals out and fit them with a suitable edge connector, and you can then control almost any device or read its current state. Pins 6 to 13 carry the signals for the port provisionally called “B”; the successive bits are 76543210. Pins 14 to 21 inclusive carry the signal bits for port “A”, in the order 76543210.
You should also remember to bring ground out to the connector, because our signals need a common reference.
A counterpart to the AY 3-8910 has also appeared on our market: a somewhat stripped-down version designated AY 3-8912.
The difference is that this chip has only one freely programmable input/output port. On this one, pins 7 to 14 carry the signal bits in the order 76543210, just as before.
Unfortunately, merely bringing out the signals is not enough; you also need to know how to program our new ports.
Programmable means they can be set as either input or output. In other words, they can receive signals from the outside world or send them there, as instructed by the processor. Our AY 3-8910 SOUND has 16 registers (the AY 3-8912 has 15), as follows:
- Register 7 determines the role of each port. Bit 7 corresponds to port “B”, and bit 6 to port “A”. Setting a bit to “1” sets the corresponding port as input, and “0” sets it as output.
- Register 14 — port A register.
- Register 15 — port B register.
Control is done in two stages: first, enter the register number, then the data for that register. For example, suppose we want port “A” to act as an output and port “B” as an input:
10 OUT 65533,7
20 OUT 49149,BIN 10xxxxxx
In assembler:
5 ORG ADRES; e.g.: 60000
10 LD A,7
20 LD BC,65533
30 OUT (C),A
40 LD A,%10XXXXXX
50 LD BC,49149
60 OUT (C),A
x means either “1” or “0”; it doesn’t matter. The ports have now been assigned their roles, but we still need to learn how to read and send data.
If port “A” is set as an output in our example, sending any information to it looks like this:
30 OUT 65533,14
40 OUT 49149,BIN xxxxxxxx
In assembler:
70 LD A,14
80 LD BC,65533
90 OUT (C),A
100 LD A,%XXXXXXXX
110 LD BC,49149
120 OUT (C),A
Reading information from port “B” looks like this:
30 OUT 65533,15
40 LET L=IN 65533
After typing PRINT L, we will see this value on the screen.
In assembler:
70 LD A,14
80 LD BC,65533
90 OUT (C),A
100 IN A,(C)
Passing the data to BASIC:
110 LD B,0
120 LD C,A
130 RET
Start from BASIC:
LET L=USR ADRES
PRINT L
Now we all know everything about the AY. I’ll just add that the AY 3-8912 is controlled in a similar way; you only need to take bit 7 in register 7 into account, and use register number 14 as the port register.
In the next part, you’ll learn how to connect an input/output port to our ZX, based on a cloned 8255 chip.
If anyone needs more information about the problem described here, please contact me by phone or letter. I’ll send anyone interested a ready-made program for controlling a light snake, along with its description and a description of the AY 3-8910. I ask only that you cover the postage or the cost of the medium if I have to obtain one myself.
All the pinouts are described in detail in BAJTEK no. 7–8 from 1990, on page 30. The external AY interface is also described in BAJTEK 3–4/90, on page 13, unfortunately with a small error in the PCB that is easy to correct.
Tomasz Kaczorowski
ul. Kilińskiego 8m17 bl.2
95-200 Pabianice
tel. (0-42) 155749
Share your thoughts about the article