Difference between revisions of "GSREAD"
(→Workspace: new section) |
m (→Workspace) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
| 6502 || align="left" | '''On entry:''' || align="left" | '''On exit:''' | | 6502 || align="left" | '''On entry:''' || align="left" | '''On exit:''' | ||
|- align="center" valign="top" | |- align="center" valign="top" | ||
− | + | | A || align="left" | undefined || align="left" | Current character of string, terminating character if end of string | |
− | |||
− | | A || align="left" | undefined || align="left" | Current character of string, | ||
|- align="center" valign="top" | |- align="center" valign="top" | ||
| X || align="left" | undefined || align="left" | preserved | | X || align="left" | undefined || align="left" | preserved | ||
Line 15: | Line 13: | ||
|- align="center" valign="top" | |- align="center" valign="top" | ||
| (&F2),Y || align="left" | the string being parsed || align="left" | (&F2) preserved | | (&F2),Y || align="left" | the string being parsed || align="left" | (&F2) preserved | ||
+ | |- align="center" valign="top" | ||
+ | | Cy || align="left" | undefined || align="left" | CC = Character valid<br> VS = 7-bit control character, (A AND &7F)<&20<br> VC = not 7-bit control character, (A AND &7F)>&1F<br> PL/MI set from A: PL if A<&80, MI if A>&7F<br> EQ/NE set from A: EQ if A=0, NE if A<>0<br>CS = End of string reached<br> EQ = end of line<br> NE = not end of line, more text on line | ||
|} | |} | ||
Line 49: | Line 49: | ||
The character returned by [[GSINIT]] is ''not'' necessarily the character | The character returned by [[GSINIT]] is ''not'' necessarily the character | ||
returned by the first call to GSREAD. | returned by the first call to GSREAD. | ||
+ | |||
+ | ==Examples== | ||
+ | \ Testing for no string present at all: | ||
+ | JSR GSINIT | ||
+ | BEQ errNoString | ||
+ | |||
+ | \ Testing for null string: | ||
+ | JSR GSINIT | ||
+ | JSR GSREAD | ||
+ | BCS nullstring | ||
+ | |||
+ | \ Stepping past a string (eg to step past a filename to following parameters): | ||
+ | JSR GSINIT | ||
+ | .loop | ||
+ | JSR GSREAD | ||
+ | BCC loop | ||
+ | \ Y now points to any parameter after the string | ||
+ | |||
+ | \ Copying a string | ||
+ | JSR GSINIT | ||
+ | LDX #0 | ||
+ | .loop | ||
+ | JSR GSREAD:BCS done | ||
+ | STA buffer,X | ||
+ | INX:BNE loop | ||
+ | .done | ||
+ | \ X=length of string parsed | ||
+ | \ Y=updated to parse another parameter, if present | ||
==Workspace== | ==Workspace== | ||
− | GSREAD tests the top two bits of location &E4, a zero page location set up | + | GSREAD tests the top two bits of GSFLAG in location &E4, a zero page location set up |
− | by GSINIT but also modified while processing | + | by GSINIT, but this location is also modified while processing *commands with |
− | (<code>*FX</code>, <code>*OPT</code>, <code>*TV</code> ''etc.'') | + | decimal parameters, eg (<code>*FX</code>, <code>*OPT</code>, <code>*TV</code> ''etc.''). |
− | is preserved during the call, and is made up as follows: | + | The value is preserved during the call to GSREAD, and is made up as follows: |
{| class="wikitable" | {| class="wikitable" | ||
Line 61: | Line 89: | ||
| 7 || <tt>"</tt> found at start of string | | 7 || <tt>"</tt> found at start of string | ||
|- | |- | ||
− | | 6 || CS on entry to GSINIT; only CR terminates unquoted string | + | | 6 || CS on entry to GSINIT; only CR terminates an unquoted string |
|- | |- | ||
| 5..0 || Unused | | 5..0 || Unused | ||
|} | |} | ||
+ | |||
+ | GSREAD also updates GSCHAR in location &E5, clearing or setting bit seven to process the |! sequence. | ||
==Entry points== | ==Entry points== |
Latest revision as of 23:58, 1 November 2022
Read character from string
Specification
6502 | On entry: | On exit: |
A | undefined | Current character of string, terminating character if end of string |
X | undefined | preserved |
Y | Offset of current character | Offset of next character |
(&F2),Y | the string being parsed | (&F2) preserved |
Cy | undefined | CC = Character valid VS = 7-bit control character, (A AND &7F)<&20 VC = not 7-bit control character, (A AND &7F)>&1F PL/MI set from A: PL if A<&80, MI if A>&7F EQ/NE set from A: EQ if A=0, NE if A<>0 CS = End of string reached EQ = end of line NE = not end of line, more text on line |
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),Y and scans forward.
If the string began with " then a character is returned with Carry Clear unless the closing " has been reached, then Carry Set is returned with A=&0D. CR encountered before the closing " causes error &FD, Bad string.
Otherwise a character is returned with Carry Clear unless it is a CR, or a space if GSINIT was called with Carry Clear, then Carry Set is returned with A=&0D.
(&F2),Y is left pointing to the next character unless Carry Set is returned, in which case GSREAD skips any spaces following the end of the string.
While processing a command line, GSINIT returning Not Equal indicates that an argument is present. When the first call to GSREAD returns Carry Set, 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 Carry Set 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.
Examples
\ Testing for no string present at all: JSR GSINIT BEQ errNoString
\ Testing for null string: JSR GSINIT JSR GSREAD BCS nullstring
\ Stepping past a string (eg to step past a filename to following parameters): JSR GSINIT .loop JSR GSREAD BCC loop \ Y now points to any parameter after the string
\ Copying a string JSR GSINIT LDX #0 .loop JSR GSREAD:BCS done STA buffer,X INX:BNE loop .done \ X=length of string parsed \ Y=updated to parse another parameter, if present
Workspace
GSREAD tests the top two bits of GSFLAG in location &E4, a zero page location set up
by GSINIT, but this location is also modified while processing *commands with
decimal parameters, eg (*FX
, *OPT
, *TV
etc.).
The value is preserved during the call to GSREAD, and is made up as follows:
Bit | Meaning |
---|---|
7 | " found at start of string |
6 | CS on entry to GSINIT; only CR terminates an unquoted string |
5..0 | Unused |
GSREAD also updates GSCHAR in location &E5, clearing or setting bit seven to process the |! sequence.
Entry points
- 6502 Entry Address: &FFC5 (I/O processor only)