If you find ROM, RAM & PORT addressing and decoding confusing, here’s some explanation of what’s what. Except in the diagram, here we call control lines by name without distinguishing RD and NOT READ. On the schematic, a line over the name XX means negation NOT XX.
Each address includes a number and several control signals; equal numbers specify separate locations if the control signals differ. Z80 CPUs use a 16-bit address buss–16 wires that can assume 65536 permutations of 0 and 5V–as well as 13 control lines that we can combine. But only MREQ & IORQ are usually used to create different addresses.
Decoding an address means to create circuitry to select a device based on both numeric and control addresses. Full decoding chooses an exact permutation. Not fully decoded, or partial decoding, means ignore some bits and control lines and respond based on the rest. In either case, the circuit combines address signals to form a few control signals for our device. For example, RAM CS combines MREQ and A14′ in a ZX/TS.
All partially decoded schemes respond to many addresses. So if you PEEK 1 or PEEK (1+8192) on your ZX/TS, you get 253 because the ROM isn’t fully decoded. You can leave your 16K ZX/TS pack on to try this, but a 64K gives different answers–it’s fully decoded.
IORQ & MREQ differentiate port or memory requests of Z80 addresses 0-255. IORQ indicates that the CPU will communicate with the location whose number is on the buss and process the data as to or from a PORT. MREQ tells your decoder the CPU will process the data for this location as though it were to or from MEMORY. See the Zilog CPU Technical Manual for details.
RD and WR separate the ReaD and WRite operations–but you may also use them in the address.
Thus you can read port 254 & have it be the keyboard, a read-only device, and write to port 254 & have it be the display, a write-only device. These expect IORQ to be selected. But ROM location 254 responds to 254 and RD and MREQ. You could then assign a write-only device at 254 and MREQ and WR.–KO
Sinclair computers expect the address lines A0-A7 each to control one device, treated as a port. A device responds when its line (Ax) is 0 during IORQ. Each device reacts to 128 addresses; only one is proper. This specific form of partial decoding is not recognized in the notes by Paul Donnelly and KO in SYNTAX Aug.83. To access one device keep A0-A7 high except for the ONE that selects it.
A A A A A A A A ADDRESS PORT 7 6 5 4 3 2 1 0 HEX DEC DEVICE 1 1 1 1 1 1 1 1 FF 255 DISPLAY ** 1 1 1 1 1 1 1 0 FE 254 KBD, CASS * 1 1 1 1 1 1 0 1 FD 253 DISPLAY 1 1 1 1 1 0 1 1 FB 251 PRINTER 1 1 1 1 0 1 1 1 F7 247 RESERVED 1 1 1 0 1 1 1 1 EF 239 RESERVED 1 1 0 1 1 1 1 1 DF 223 RESERVED 1 0 1 1 1 1 1 1 BF 191 USER ASSIGN 0 1 1 1 1 1 1 1 7F 127 USER ASSIGN * This port is fully decoded. ** Used for speaker and border in the ZX Spectrum.
According to the SPECTRUM manual, bits A6 & A7 are ignored; you can use them. For 512 more addresses, use register indirect addressing of the port. Take any permutation of A8-A15 with either USER ASSIGN I/O address preceding. Use opcodes:
LD BC,portaddr ;portaddr=**7FH or
;**BFH. 00<**<FF
OUT (C),r ;write to ** from r
IN r,(C) ;read from ** to r
Or use partial decoding again with A8-A15 to let one gate access both of Paul’s devices. Use A14 & A15 as the single low bit to read from two external devices as shown in the sample circuit. One device is port 7FBF & device 2 is at BFBF. Just 3/4 of another chip can decode the write function. I recommend using a 74LS32 Quad OR gate because of its lower power requirement and better availability.
