Revisiting my Color BASIC String Theory series… Here is one to ponder…
CLEAR 0 can be used to reserve 0 bytes for string storage. With no string space, we obviously expect something like this to NOT work:
A$="THIS WON'T WORK WITH CLEAR 0"
Indeed, that would give us “?OS ERROR” — Out of string space.
The exception to this rule are “constant strings” that are embedded inside the BASIC program itself. In a YouTube video I recently posted, I demonstrated how constant strings in a program do not use string space:
You can see twenty nine other short Color BASIC videos I posted to YouTube during the month of #SepTandy 2021.
But I digress…
Here are some other things that won’t work without string space, even if, at first glance, it seems like they would:
It seems you can’t SAVE, LOAD or even PRINT a “constant” string if there is no string space.
Consider this… The same thing happens with string functions such as LEFT$, RIGHT$, MID$ and even INSTR:
Looking at those, and recalling my String Theory article, we know LEFT$, RIGHT$ and MID$ are trying to create a new string. With no string space, there is no way to create it. That must be why they fail. This makes sense.
But INSTR does not create any strings. It merely returns the position where one string appears inside of another, or 0 if the string is not found. (Or 1 if you give it an empty string, which truly does seem like a bug but other flavors Microsoft BASIC behave the same way with their implementations of INSTR. But I digress…)
And SAVE, LOAD and PRINT are similar. They just print something, not create a string.
That does not make sense.
Let’s speculate a bit.
What’s all this, then?
Without consulting the Color BASIC Unravelled disassembly, my guess is that the ROM code for SAVE, LOAD, PRINT, etc. probably expects some register to be pointing to where the string exists in memory (a location pointer in the variable data). This might be code space, in the case of a constant string embedded in a BASIC line, or string space, in the case of a dynamic string.
But when you are entering a command directly in to BASIC, there is no program memory for that command (even though it seems like it could just point to the keyboard input buffer and then make the ROM call). BASIC needs to put that constant string data somewhere before jumping to the ROM call.
That’s weird, and quite possibly unnecessary, but would, at least, make sense.
I am going to add this to my “look this up in the disassembly to see what’s going on” list for future investigation.
In the meantime … I wonder what else won’t work without string space?
Until next time…