50 IF a$="Variable" THEN PRINT
AT 1,0;"Found word at
address:";%a: GO TO 70: REM
stop iterating here and go
below
60 NEXT %a
70 FOR %a=0 TO 65535
80 PRINT AT 3,0: "Now scanning
address:";%a
90 a$ = PEEK$ (%a, ~101)
100 IF a$="Variabl" THEN PRINT AT
4,0; "Found word at address ";%a
110 NEXT %a
You'll undoubtedly notice that line 100 says Variabl instead of Variable and that's because the terminator character we set in like 90 to look for, is not included in the string returned by PEEK$(). What this program actually finds is the address in the memory map where line 50 is stored! The second half of this example (lines 70 on) is very much pointless but was made to show the flexibility of PEEK$()'s arbitrary termination character search.
Normally, it is much more likely to read for NUL terminated strings (~0), FFh terminated strings (~255), often used in +3DOS/IDEDOS and perhaps CR terminated strings (~13), if for example the data you're searching for has been PRINTed with line separators.
To change the contents of a RAM address in the memory map, we use the POKE or DPOKE statements. These have the form:
POKE address, value1[,value2[,value3...[,valueN]]]
DPOKE address, value1[,value2[,value3...[,valueN]]]
The ability to POKE gives you immense power over the computer if you know how to wield it; and immense destructive possibilities if you don't. It is very easy, by poking the wrong value in the wrong address, to lose vast programs that took you hours to type in. Fortunately, you won't do the computer any permanent damage.
As we mentioned earlier, POKE is generally not safe to use within the confines of the memory map, unless you either know what you're doing, or the area you're modifying is fixed (like say the Layer 0 screen or attribute areas or the System Variables – the latter always with caution). It's also safe to POKE within the memory map if you have used the CLEAR command and modify the area above it.
Let's try modifying a system variable to show how powerful POKEing can be:
First, type test in the editor and once you hit ENTER your computer will complain with a buzzing sound. The variable that holds let length of that buzz is called RASP and it's located in address 23608 (5C38h) within the System Variables area.
Now, let's see how can we adjust that buzz. We'll start by looking what is its current value with:
PRINT PEEK 23608
Then modify it with
POKE 23608, 16
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.