Was there any BASIC or extension or toolbox for BASIC allowing to
PEEK multiple bytes from memory in one instruction - besides the often-used
DPEEK (or alike) to read a word?
I'm asking specifically for a
PEEK-like general purpose function, not specialized ones like for screen access or similar and especially not any kind of programming tricks.
Giving examples of specialized functions in addition will still be nice for comparison and bonus points.
I just learned of an awesome new piece of ancient, ancient usage from an answer given by Tofro. There has been a BASIC extension for the Sinclair Spectrum allowing to POKE whole byte sequences to memory. In Beta BASIC a line like
40 POKE 16384,A$
will poke the content of
A$ into address
4000h and the following memory.
This is such a genuine simple and perfect sensible implementation. By now I'm mad at myself. Over the years I created many solutions beating around that bush, but that I've never thought about utilizing
PEEK that way. It's brilliant.
Sure, it introduces a little bit of polymorphism into BASIC, which otherwise only goes for a fixed type and optional conversion, like float to int with conventional
POKE, but that has been done in other places as well.
Now while extending
POKE is straight forward (from a language point), the much needed counterpart of
PEEK is not. That's mainly due the fact that BASIC strings are by default of variable length, thus the interpreter can not take the length to be read from the string (*1,2). Tofro cites in his answer a special access function:
20 LET A$=MEMORY$()(16384 TO 22527)
Not that I would call this elegant, but more important, it's a quite Sinclair-ish notation. So my desire would be to find something more generic with a syntax compatible to more .. lets say standard BASIC.
And that's what I'm looking for.
A discovery like this tickles my urge to code. I want this. So far my own approach would be an extension to
<var> = PEEK(<adr> [,<len])
Here compatibility is maintained by having an implied length of 1 if not given. In addition it also needs to act differently based on the type of the receiving variable.
If it's an integer (
A%) then the bytes addressed get assigned as integer, so optional twisted for byte order (replacing the
If it's a string (
A$) then they get just assigned there.
If it's a float (
A!) everything gets blurry and must be settled by definition.
In fact, having such a function adds several possible errors - like selecting a range to large for the string data type (many BASICs can do only 255 char), or for an integer selecting more bytes than fit in one, and so on.
So I'm even more interested in what kind of solutions in that area were available back then (or today) in BASIC.
*1 - Ignoring for the moment, that this again would be a violation of the basic BASIC design.
*2 - Yes, it would be possible to make the string to contain the wanted amount of bytes beforehand (like in
A$=SPACE$(16)) but that's not only clumsy but also a horrible design, quite hard to read and error prone.