Forum unknown
· Tech Notes & Util.
#MODEL 100 BUG
7 messages in this thread
Recently a customer informed me of problem he was having with his TRS-80 Model
100. We constructed a five line BASIC program that demonstrated the bug:
10 CLEAR 256,MAXRAM
20 A$="This is a "+"string."
30 PRINT A$
40 PRINT FRE$("")
50 PRINT A$
The expression in 20 forces A$'s contents to be placed in the string buffering
area. The FRE("") in 40 forces compression of the buffer and prints the number
of free bytes in it. Between the end of 30 and 50 the value of A$ has changed
from "This is a string." to "……………..". After investigating the
machine code that handles the BASIC commands in this program I discovered that
the bug actually occurs during 10. When the BASIC CLEAR command has a second
argument AND the first string that was placed in the buffer has not be
redefined by the time compression occurs, all characters in strings whose
contents reside in the buffer will be redefined as the last character in that
first string.
Fortunately, there is a simple measure to prevent this bug from getting into
your program. Immediately follow any CLEAR that assigns HIMEM by a CLEAR
without any arguments. Hence, to fix the above program change 10 to:
10 CLEAR 256,MAXRAM:CLEAR
It is important to realize that even if HIMEM is unchanged by the statement
"CLEAR 256,<value>" that this bug may occur.
You might still be wondering why you haven't seen this problem. It seems like
it would show up often. Its rarity is explained by the second requirement: the
first string that was placed in the buffer must not have been redefined before
compression. If this second condition is not met, compression will proceed
smoothly and correctly. Few programs meet this condition, however, some
programs may meet this condition in certain situations. Such programs may
appear to work correctly when actually data corruption is just waiting for the
proper sequence of events.
WORDS TO THE WISE: If you use CLEAR with a second parameter follow it with a
CLEAR.
..Tom Bennett (PEaC)
Tom, without being facetious, there is a simpler way to avoid that bug; simply
do not use the FRE$("") statement, which is neither supported in the manual (or
probably in Microsoft Basic for the M100), nor a clear construct with any
purpose. It you want to clear the buffer, isn't it easier to use the normal
form: A$="":PRINTFRE(0) ?
Undoubtedly, there are several such "undiscovered" bugs in the ROM,
particularly in the area of using those "unsuported" Op-Codes. You can force
them to reveal themselves by attempting to use non-standard mnemonics, or in
the case of BASIC, non-standard command syntax.
Believe "FRE$" was a typo in Tom's note; MY M100 gives a syntax error on the
call to "FRE$". If line 40 is changed to:
40 PRINT FRE("")
instead (surely what was intended), I get the result he described (&, of
course, using FRE w/ a string arugment IS a documented feature). Downright
scary, really! – tim
Believe "FRE$" was a typo in Tom's note; MY M100 gives a syntax error on the
call to "FRE$". If line 40 is changed to:
40 PRINT FRE("")
instead (surely what was intended), I get the result he described (&, of
course, using FRE w/ a string arugment IS a documented feature). Downright
scary, really! – tim
Aha! The problem has nothing to do w/ "FRE" (or "FRE$"): FRE("") was just a
quick way to force string compaction. The same error shows up here:
1 CLEAR50,MAXRAM
2 INPUT I$
3 FOR I=1 TO 50:J$=I$:NEXT
4 PRINT I$
Tom's right – it's a BIG bug! – tim
Aha! The problem has nothing to do w/ "FRE" (or "FRE$"): FRE("") was just a
quick way to force string compaction. The same error shows up here:
1 CLEAR50,MAXRAM
2 INPUT I$
3 FOR I=1 TO 50:J$=I$:NEXT
4 PRINT I$
Tom's right – it's a BIG bug! – tim
Tom, without being facetious, there is a simpler way to avoid that bug; simply
do not use the FRE$("") statement, which is neither supported in the manual (or
probably in Microsoft Basic for the M100), nor a clear construct with any
purpose. It you want to clear the buffer, isn't it easier to use the normal
form: A$="":PRINTFRE(0) ?
Undoubtedly, there are several such "undiscovered" bugs in the ROM,
particularly in the area of using those "unsuported" Op-Codes. You can force
them to reveal themselves by attempting to use non-standard mnemonics, or in
the case of BASIC, non-standard command syntax.