We can instruct the processor to read from and write to memory by using PEEK, POKE and their variants. For all the possibilities, examine Chapter 23 – The Memory. The processor itself does not really care whether memory is ROM, RAM or even nothing at all; it just knows that there are 65536 memory addresses, and it can read a byte from each one, even if it's nonsense, and write a byte to each one, even if it gets lost because the address is read-only. In a completely analogous way, there are also 65536 hardware addresses, called I/O ports (Input/Output ports) that are separate from memory. These are used by the processor for communicating with attached devices like the keyboard or the display, and they can be controlled from NextBASIC by using the IN function and the OUT statement. There's a number of I/O ports, specific to the ZX Spectrum Next which control its advanced functions; they too, are accessible with IN and OUT, but two of them, are also accessible via a special dual statement/function, called REG.
IN is a function like the simplest form of PEEK:
IN port
It has one argument, the hardware address port, and its result is a byte read from that port. OUT on the other hand is a statement like a simple POKE:
OUT port, v
which writes value v to the hardware address port.
How the address is interpreted depends on the hardware in the computer and attached devices. In previous versions of the ZX Spectrum line of computers and especially in legacy peripherals, many different port addresses mapped to the same device. This is called partial decoding and happened because some address bits were ignored in the hardware to save on cost. As a consequence, entire ranges of port addresses were reserved by individual peripherals. This made it hard for new peripherals to find non-conflicting ports to use and, in reality, many did not and only managed to use ports that didn't conflict with the most popular peripherals. The situation was somewhat mitigated by the fact that only a couple of peripherals could be connected to the older ZX Spectrum machines at once, due to electrical limitations. Today, where modern ZX Spectrum implementations pack many devices into their hardware, this port conflict problem returns with renewed urgency, as any pair of devices with conflicting port addresses are not compatible with each other.
The ZX Spectrum Next fully decodes port addresses for new peripherals (meaning it does not ignore any address line), but because a lot of the hardware it contains is based on existing devices, those must continue to be partially decoded. In order to best understand the issues at hand, and in the table that follows which contains all available port addresses on the ZX Spectrum Next, it is best if we approach them as written in binary. That way we can easily show which bits are being ignored by a specific peripheral. Each hardware address is 16 bits wide, which we shall call (using A for address):
| A15 | A14 | A13 | A12 | A11 | A10 | A9 | A8 | A7 | A6 | A5 | A4 | A3 | A2 | A1 | A0 |
Here A0 is the 1st bit, A1 the 2nd bit, A2 the 3rd bit, A3 the 4th bit and so on. The table that follows shows which bits are important for the corresponding device. For example, the ULA only needs A0 to be 0 in order to respond, which means it will respond to all 32768 even port addresses and not just its official port 254 (FEh). The byte read or written has 8 bits, and these are often referred to (using D for data) as:
| D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
ZX Spectrum Next User Manual, 3rd Edition (ISBN 978-1-5272-5496-1), written and illustrated by Phoebus R. Dokos. Copyright © 2020-2024 Phoebus Dokos / SpecNext Ltd. Licensed under CC BY-NC-SA 4.0. This is a transcription and can contain errors; check any doubt against the printed page.