Submitted by Steve Fewell
Call routine &96AF to obtain the result of the expression after the STRING$( keyword and convert the result to Integer
(or issue 'Type mismatch' error if the result was a String value).
Push the Integer result to the BASIC stack. This is the number of times that the String value (the second parameter) is
required to be repeated.
Call routine &8EF1 to check that the next non-space character is a comma ',' (issuing 'Missing ,' error if it isn't).
Call routine &ADAC to get the result of the expression after the comma and then check for a closing bracket character
')', and issue 'Missing )' error if a closing bracket was not the next non-space character.
If the result of the expression is not a String value then issue 'Type mismatch' error.
Retrieve the Integer value from the BASIC Stack.
Now the IWA contains the number of times to copy the SWA String value and the SWA contains the String value
to be duplicated.
If the length of the String value to duplicate (SWA) is zero then exit with A = 0 (as the SWA already contains the
result - a null string!
Set Y to the String length (from location &36).
Set A to the IWA's LSB value (location &2A), as only the first byte is taken into account when obtaining the number
of copies required.
If A (number of copies) is zero then set the SWA length (location &36) to zero and exit with A = 0, as the result of
'zero copies' is a null String value.
Decrement the IWA value (&2A). If the result is now zero (i.e. the IWA value was 1) then exit with A = 0, as the SWA
contains the correct result - a single copy of the String value.
[&AF64] Set X to zero.
Now X points to the start of the SWA String Value (offset from &0600) and Y points to the start of the location within
the SWA to copy the duplication of the String value to (i.e. the first free character after the current SWA value, offset
[&AF66] Copy the next character from the X offset to the Y offset of the SWA
Increment X to point to the next character of the original SWA's value.
Increment Y to point to the next free character in the 'new' SWA value.
If Y has reached zero then we have reached the end of the SWA storage space (more than 255 characters), so issue the 'String
too long' error message.
If X is less than the SWA Length byte (location &36) then jump back to &AF66 to copy the next character of the
original String's value.
Otherwise, we have duplicated another copy of the String value and added it to the end of the original SWA value,
so decrement the IWA value (location &2A), if &2A is now zero then set the SWA length (location &36) to Y and
exit with A = 0; otherwise, jump back to &AF64 to copy the original String value again.
|AF47||032 175 150||20 AF 96||JSR &96AF Get expression result & convert it to Integer|
|AF4A||&||032 038 188||20 26 BC||JSR &BC26 Push IWA value to the BASIC Stack [pushi]|
|AF4D||032 241 142||20 F1 8E||JSR &8EF1 Check for ',' and issue error if not found|
|AF50||032 172 173||20 AC AD||JSR &ADAC Evaluate expression & check for ')'|
|AF53||208 239||D0 EF||BNE -17 --> &AF44 'Type mismatch' error|
|AF55||032 230 188||20 E6 BC||JSR &BCE6 Retrieve IWA value from the BASIC Stack [popi]|
|AF58||6||164 054||A4 36||LDY &36|
|AF5A||240 030||F0 1E||BEQ 30 --> &AF7A|
|AF5C||*||165 042||A5 2A||LDA &2A|
|AF5E||240 029||F0 1D||BEQ 29 --> &AF7D|
|AF60||*||198 042||C6 2A||DEC &2A|
|AF62||240 022||F0 16||BEQ 22 --> &AF7A|
|AF64||162 000||A2 00||LDX#&00|
|AF66||189 000 006||BD 00 06||LDA &0600,X|
|AF69||153 000 006||99 00 06||STA &0600,Y|
|AF6E||240 016||F0 10||BEQ 16 --> &AF80|
|AF70||6||228 054||E4 36||CPX &36|
|AF72||144 242||90 F2||BCC -14 --> &AF66|
|AF74||*||198 042||C6 2A||DEC &2A|
|AF76||208 236||D0 EC||BNE -20 --> &AF64|
|AF78||6||132 054||84 36||STY &36|
|AF7A||169 000||A9 00||LDA#&00|
|AF7D||6||133 054||85 36||STA &36|
|AF80||L||076 016 158||4C 10 9E||JMP &9E10 String Too Long error|