This is essentially the two's complement representation we discussed in Chapter 6 for integers with two extra bytes, one before and one after the number and an entire byte dedicated to the sign as opposed to one bit only. Compared to the integer type supplied by the Integer Expressions evaluator, it is wasteful memory-wise and slower to process.
Now that we've examined more thoroughly what the memory map looks like to NextBASIC, it's time to revisit the commands and functions that read and modify its contents.
To inspect the contents of one or more memory locations, we use the PEEK, DPEEK and PEEK$() functions; The PEEK variant functions are always safe to use as they change nothing in memory; they can however give unpredictable results in cases where a memory location is marked for moving. As we saw however, there are places in memory which are unmovable; reading in the System Variables area for example is a always a predictable scenario. For instance, this program prints out the first 21 bytes in ROM (and their addresses):
10 PRINT "Address"; TAB 8; "Byte"
20 FOR a=0 TO 20
30 PRINT a; TAB 8; PEEK a
40 NEXT a
All these bytes will probably be quite meaningless to you, but the processor understands them to be instructions telling it what to do.
DPEEK is similar but since it returns 16 bit values, the example above would have to be rewritten as follows:
10 PRINT "Address"; TAB 8; "Word"
20 FOR %a=0 TO 20 STEP 2
30 PRINT %a; TAB 8; DPEEK %a
40 NEXT %a
Generally speaking, (D)PEEKing into ROM is very much useless and it's much more likely that you'll use (D)PEEK to either read a system variable or read a value you've previously POKEd. (D)PEEK$ () on the other hand returns the values at an address in memory in the form of a string. Its syntax is as follows:
PEEK$ (address, argument)
where address is any address in the memory map, while argument can be one of the following:
Let's look at an example which helps us search in memory (albeit very slowly):
10 RUN AT 3: REM this takes a
long time!
20 FOR %a=0 TO 65535
30 PRINT AT 0,0;"Now scanning
address:";%a
40 a$= PEEK$ (%a,8)
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.