Difference between revisions of "GSREAD"

From BeebWiki
Jump to: navigation, search
m (Cy)
(GSREAD safety)
Line 29: Line 29:
 
(?&F2,?&F3)+Y is left pointing to the next character unless Cy=1, in which case GSREAD skips any spaces following the end of the string.
 
(?&F2,?&F3)+Y is left pointing to the next character unless Cy=1, in which case GSREAD skips any spaces following the end of the string.
  
It is safe to call GSREAD at least once following GSINIT, and repeatedly on reaching CR.
+
While processing a command line, Z=0 on exit from GSINIT indicates that an argument is present.  When the first call to GSREAD returns Cy=1, the flag from GSINIT distinguishes between an empty argument and no argument.
 +
 
 +
It is safe to call GSREAD at least once following GSINIT.  However, after GSREAD returns Cy=1 it must not be called again without an intervening GSINIT; otherwise, overshooting a closing <tt>"</tt> and reaching CR also raises a '''Bad string''' error.
  
 
;Note
 
;Note

Revision as of 11:07, 29 September 2020

Read character from string

Specification

 6502  On entry: On exit:
Cy undefined 0=Character valid
1=End of string reached
A undefined Current character of string; =&0D if end of string reached
X undefined preserved
Y Offset of current character Offset of next character
 ?&F2 LSB of start of array preserved
 ?&F3 MSB of start of array preserved

Returns one character at a time from a string found using GSINIT. The string may be enclosed in double quotes (") in which case spaces in the string are preserved. The string may also contain control codes and high-order characters encoded with an escape sequence.

GSREAD parses the character sequence at the position given by (?&F2,?&F3)+Y and scans forward.

If the string began with " then a character is returned with Cy=0 unless the closing " has been reached; then Cy=1 and A=&0D is returned. CR encountered before the closing " causes error &FD, Bad string.

Otherwise a character is returned with Cy=0 unless CR, or also space if GSINIT was called with Cy=0, has been reached; then Cy=1 and A=&0D is returned.

(?&F2,?&F3)+Y is left pointing to the next character unless Cy=1, in which case GSREAD skips any spaces following the end of the string.

While processing a command line, Z=0 on exit from GSINIT indicates that an argument is present. When the first call to GSREAD returns Cy=1, the flag from GSINIT distinguishes between an empty argument and no argument.

It is safe to call GSREAD at least once following GSINIT. However, after GSREAD returns Cy=1 it must not be called again without an intervening GSINIT; otherwise, overshooting a closing " and reaching CR also raises a Bad string error.

Note

The character returned by GSINIT is not necessarily the character returned by the first call to GSREAD.

Calling from BBC BASIC

Entry points

  • 6502 Entry Address: &FFC5 (I/O processor only)

Regregex (talk) 18:31, 11 January 2019 (CET)