Useful SuperBASIC POKEs and PEEKs?
Posted: Thu Aug 19, 2021 12:08 pm
The thought has just occurred: is there a list of POKEs and PEEKs for the (original black box) QL out there anywhere?
I have a fairly chunky list for the Spectrum, as you might expect - from POKE 23658,8 (which everyone knows - this forces CAPS LOCK on) to PEEK 2899 (=165 for a 16K/48K Spectrum, =159 for a toastrack/+2, =126 for a +2A/+3, and this is far less well known). I found myself thinking: "wouldn't it be great if the Spectrum (and ZX81 and ZX80) had a POKE_W and PEEK_W so that poking a two-byte number into two addresses without having to calculate the two bytes manually in BASIC?"
For instance: if I want to know the bytes of memory remaining (very important on a 16K Spectrum), I need to type this:
PRINT (PEEK 23730+256*PEEK 23731)-(PEEK 23653+256*PEEK 23654)
This is PEEKing the system variables RAMTOP and STKEND and subtracting the second from the first. But wouldn't this be great:
PRINT (PEEK_W 23730-PEEK_W 23653)
And yes, I know, odd numbers won't work with PEEK_W on the QL, this is merely an illustration.
Likewise: I wrote a short machine code routine to convert decimal into hex and binary in one shot, and started with a two-byte equivalent. The BASIC proof-of-concept program to get the value for conversion starts with:
10 INPUT d
20 POKE 60003,INT(d/256): POKE 60002,d-256*PEEK 60003
I'd find 20 POKE_W d to be a lot more convenient.
So I think of the QL more times than you'd realise when programming its predecessors, but I know little about the QL's own equivalents. And if anyone is ever going to say "RTFM", then the famous Spectrum POKE I've just given above would not have been even slightly obvious from the manual - all it says in the list of system variables is that 23658 is "various flags". It makes no mention of bit 3 showing whether the CAPS LOCK is on or off.
I have a fairly chunky list for the Spectrum, as you might expect - from POKE 23658,8 (which everyone knows - this forces CAPS LOCK on) to PEEK 2899 (=165 for a 16K/48K Spectrum, =159 for a toastrack/+2, =126 for a +2A/+3, and this is far less well known). I found myself thinking: "wouldn't it be great if the Spectrum (and ZX81 and ZX80) had a POKE_W and PEEK_W so that poking a two-byte number into two addresses without having to calculate the two bytes manually in BASIC?"
For instance: if I want to know the bytes of memory remaining (very important on a 16K Spectrum), I need to type this:
PRINT (PEEK 23730+256*PEEK 23731)-(PEEK 23653+256*PEEK 23654)
This is PEEKing the system variables RAMTOP and STKEND and subtracting the second from the first. But wouldn't this be great:
PRINT (PEEK_W 23730-PEEK_W 23653)
And yes, I know, odd numbers won't work with PEEK_W on the QL, this is merely an illustration.
Likewise: I wrote a short machine code routine to convert decimal into hex and binary in one shot, and started with a two-byte equivalent. The BASIC proof-of-concept program to get the value for conversion starts with:
10 INPUT d
20 POKE 60003,INT(d/256): POKE 60002,d-256*PEEK 60003
I'd find 20 POKE_W d to be a lot more convenient.
So I think of the QL more times than you'd realise when programming its predecessors, but I know little about the QL's own equivalents. And if anyone is ever going to say "RTFM", then the famous Spectrum POKE I've just given above would not have been even slightly obvious from the manual - all it says in the list of system variables is that 23658 is "various flags". It makes no mention of bit 3 showing whether the CAPS LOCK is on or off.