How to do FOR without structured programming (retro investigation)

You can talk about almost anything that you want to on this board.

Moderator: Moderators

User avatar
aa-dav
Posts: 220
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: How to do FOR without structured programming (retro investigation)

Post by aa-dav »

Pokun wrote: Sat Jan 28, 2023 12:34 pm Family BASIC doesn't have an assembler, but you can at least call subroutines you have written in machine code (usually by POKEing the hand-assembled bytes directly to RAM) with the CALL command, it's pretty fun.
It's very common thing in Basics with rare exceptions (the only one I know is Wang-2200 PC which intentionally restricts user from hardware by Basic interpreter). USR x function calls machine routine at address x returning value from some of the CPU registers as result (BC register pair in ZX Spectrum). However being function USR has to be written always to use result. Like in LET x = USR(32768). This led to short variants for economy and in ZX Spectrum subculture this take form of RANDOMIZE USR x. Almost every usage of USR there looks like RANDOMIZE USR ...; RANDOMIZE operator initializes random seed generator which almost never was used in such scenarios, so this operator was used to ignore result of USR.
You may ask - but why so long token 'RANDOMIZE'? 9 letters is very big for economy. However ZX Spectrum basic doesn't keep all letters of operators in memory - just opcode of operator (all Basic keywords, operators and functions were binded to position in ASCII set in upper 128 values of byte), so it is not waste of bytes. If you execute PRINT CHR$(249) it will print 'RANDOMIZE '. In fact Basic procedure for printing one character in ROM does it.
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: How to do FOR without structured programming (retro investigation)

Post by Pokun »

Yeah some BASIC dialects such as MSX-BASIC allows you to choose if you want to store a program in tokenized or in pure ASCII form when you save it to a tape or floppy. I think it's always in tokenized form when loaded in memory on MSX though, just like the Speccy (even though you have to type out commands in full unlike the Speccy).
The main use of ASCII is that certain commands like MERGE requires ASCII. MERGE allows you to merge a tape/disk ASCII program with one already in memory to patch it, so you would need to store such a patch in ASCII form on the tape/disk.

Family BASIC only uses tokenized I think, and there is no MERGE command.
Post Reply