!lm10
!rm70
Improved Applesoft Fast String Input....Bob Sander-Cederlof

In the April 1981 issue of AAL I printed a subroutine to read a line from the keyboard or a text file into an Applesoft string.  The original version had a minor flaw (or major, if you happened to run into it): it left the high-order bit on in each byte, so that Applesoft could not compare them properly with strings from other sources.  I printed a correction in a later issue, which stripped off the leading bit from each byte before putting it in the string.

Now Sherm Ostrowsky (from Goleta, California) has pointed out a more elegant solution.  He uses a subroutine inside Applesoft that reads a line, terminates it with  hex 00, and strips off the leading bit from each byte.  The subroutine starts at $D52C.  The only thing it doesn't do that we need is give us the length of the input line.  Here is a commented listing of it.

    <D52E listing here>

Since $D52C stores $80 (null) in the prompt character, you might want to load the X-register with $87 (bell) and enter at $D52E instead.

Since the subroutine returns with $FF in the X-register, and we need the length of the input line instead, we can use the following code to get the line length in X:

!lm15
       JSR $D52C
.1     INX
       LDA $200,X
       BNE .1
!lm10

Here is a new version, then, of my fast string input subroutine:

   <subroutine here>

Here is how you might use it from an Applesoft program, to read a series of lines from a file:

!lm15

100 D$ = CHR$ (4)
110 PRINT D$"BLOAD B.FAST READ"
120 POKE 1013,76 : POKE 1014,0 : POKE 1015,3
210 PRINT D$"OPEN MY.FILE"
220 PRINT D$"READ MY.FILE"
230 FOR I = 1 TO 10
240 & GET A$(I)
250 NEXT I
!lm10

Note that the subroutine is fully relocatable.  Since there are no internal JMP's or JSR's, and no internal variables, you can load the program anywhere it will fit and run it without any modifications.  Just be sure to change line 120 above to POKE the correct address in 1014 and 1015.
