×   Main Menu ALL The 8BS News Manuals (New menu) Links Worth a Look Tools Disc and Basic Webring Site Map 8BS Guestbook Old Guest Book Me The Barnsley Rovers   
8-Bit Software

The BBC and Master Computer Public Domain Library

B8B6 INPUT

Submitted by Steve Fewell

Description:

Check the next non-space character. If it's a '#' then jump to the PRINT# routine [&B847].

If the next character is a 'LINE' keyword token then set the carry flag; otherwise, decrement BASIC Text Pointer A
Offset (&0A), as we do not need the next character yet, and clear the carry flag.
Set bit 6 of location &4C to the value of the carry flag [by setting the top bit & shifting right one position].
Set &4D to #&FF (field extraction offset flag, #&FF if not currently extracting fields from the Input String).

[&B8CA] Call routine &9299, which does the following:
* Get the next non-space character.
* Call routine &927A to process any ' [quote], TAB( and SPC special print characters
* If carry is clear on return from routine &927A, then a special function was carried out (either New line, TAB(
or SPC), so exit routine.
* If next character is not " [double-quote] then a String is not present, so set the carry flag and exit.
* Otherwise, we need to extract and output the String value, as follows:
*    [&92A5] Get next character.
*    If next character is <cr> [carriage return] then issue 'Missing "' error [as a closing double quote
wasn't present before the end of the statement line.
*    If the next character is a double quote and the characer after it is not then clear carry, set BASIC
Text Pointer A to BASIC Text Pointer B location and exit, as we have outputted the string value. Otherwise, we need to
output a single double quote character (as two double quotes were found inside the string value).
*    Call routine &BD98 to output the character.
*    Jump back to &92A5 to get next character of the string.
If the carry flag is clear on return from routine &9299, then a special character was found & processed, so keep
calling routine &9299 to check for further special operations (i.e. New line ('), TAB(, SPC or String (")), until
the carry flag is set (indicating that no further special characters were found); Set &4D to #&FF & clear carry flag
(as special characters terminate a field extraction).

[&B8D9] Shift byte &4C (the LINE-status byte) left 1-position (so that the top bit is set if we are in 'LINE'-mode)
(the processor flags are temporarily saved while this is done). This also removes the previous Top-bit setting (special
character) of &4C. Shift the carry flag into the top byte of &4C (moving the 'LINE'-mode flag right a position,
again). (The carry flag is clear if special characters were not found, or set if special characters were found).
So, now Bit 7 of &4C is clear if special PRINT characters (',",TAB(,SPC) were processed, and Bit 6 is set if were are
in 'LINE'-mode.

If the next character is "," or ";", then jump back to &B8CA to check for, and process, and special characters
after the field separator.
[Note: If special characters were found after the last ',' or ';', then a '?'-prompt is not output; also, additional
fields cannot be extracted from a previous input entry for any additional variables supplied - instead, the user will be
prompted for another entry value]

Next, we should either have a variable or the end of the statement, as we have processed all valid characters that can precede
a variable in an INPUT statement, namely: double quote ("), Comma (,), Semi-Colon (;), SPC, TAB( and quote (').
Decrement BASIC Text pointer A offset (so that the variable name starts at the next character, rather than the current one).
Save bytes &4C and &4D to the stack.
Call routine &98AE to evaluate the variable name (and create it if the variable doesn't already exist and isn't a
direct memory access (!x, ?x, $x).
If the zero flag is set on return from &98AE, then a variable was not specified, so retrieve the 2-bytes pushed to
the stack and jump to &9002 (to continue to the next statement if end of statement was found; otherwise, issue a
Syntax error).

Retrieve bytes &4C and &4D from the stack.
Call routine &9275 to Set BASIC Text pointer A offset to BASIC Text pointer B offset.
Store the processor flags to the stack (this stores whether the variable is a String or not).
if bit 6 of &4C is clear (i.e. we are not in LINE mode), and &4D location is not #&FF (i.e. not first field)
then jump to &B91F (to extract the next field).
If the top bit of &4C is set (Special characters were not found after the last field break), then output a
'?'-character - this is the default user input prompt.
Call routine &BA70 to get the user's input, as follows:
* Set &38 to 6 and zero &37. This is the address to place the user's input entry: &0600 (The SWA).
[Note: If called from &BA74, the address to place the user's input entry is &0700 (The Command Line)].
* Set &39 to #&EE. This is the maximum input line length.
* Set &3A to #&20 and &3B to #&FF. These are the minimum and maximum characters.
* Set Y to #&00 (parameter block MSB), X to #&37 (parameter block LSB).
* Set A to #&00 (OSWORD call 0 - get input characters from current device).
* Call OSWORD (&FFF1) with A = 0 and the parameter block data in locatons &0037 - &003B.
* If the carry flag is set after OSWORD call (with A = 0), then Escape was pressed, so generate an 'Escape' error;
otherwise, all is ok, so zero COUNT (&1E) and exit the &BA70 routine.
Store Y (the length of the input field) in &36 (SWA length field).
Clear the top bit of &4C (the special characters not found flag).
If bit 6 of &4C is clear (i.e. we are not in LINE mode), then fields are separated by commas (etc...), so:
* [B91F] Set &1B (the current SWA offset) to A (this is 0 for the first field, & &4D for other fields).
* Zero &19 and set &1A to #&06 (So that &19-&1A is a Pointer to the SWA value).
* Call routine &ACF8 to Extract the next field from the SWA (& place it in the SWA starting at location &0600)
* Call routine &8EEB to Get the next non-space character and compare with ",".
* If comma not found (then <cr> found [if not <cr> get next char until ',' or <cr>] - end of input entry (SWA)); so,
set Y to #&FE (Next statement will increment this to #&FF - indicating that we are no longer extracting fields
from the input line).
* Increment Y (SWA offset) [This equals #&FF when we are not extracting fields from the SWA] and store Y in &4D.

Retrieve the processor flags from the stack.
If the variable is an Integer (carry flag clear) then set the variable as follows:
* [&B93B] Call routine &BC43 to store the variable address & type details (&2A,&2B,&2C) on the 6502 stack.
* Call ASCII to Numeric conversion routine (ASCNUM, &AB4E) to convert SWA string value to a binary number.
* Call routine &B32B to set the numeric variable to the numeric value (which is either a Floating-Point or Integer
value)
* Jump back to &B8CA to check for further variables or special characters on the INPUT statement.
If the variable is a String (carry flag set) then set the variable as follows:
* [&B946] Zero &27 - (Set current result type to String).
* Call routine &90AE to Set the String variable to the SWA value.
* Jump back to &B8CA to check for further variables or special characters on the INPUT statement.


Disassembly for the INPUT routine

B8B2 h 104 68 PLA
B8B3 h 104 68 PLA
B8B4   128 142 80 8E BRA -114 --> &B844 [JMP &9002] check end of statement & process next program statement
B8B6   032 223 140 20 DF 8C JSR &8CDF Get next non-space char (PTR A) and compare with '#'
B8B9   240 140 F0 8C BEQ -116 --> &B847 PRINT#
B8BB   201 134 C9 86 CMP#&86 'LINE'-token
B8BD   240 003 F0 03 BEQ 3 --> &B8C2
B8BF   198 010 C6 0A DEC &0A
B8C1   024 18 CLC
B8C2 fL 102 076 66 4C ROR &4C
B8C4 FL 070 076 46 4C LSR &4C
B8C6   169 255 A9 FF LDA#&FF
B8C8 M 133 077 85 4D STA &4D
B8CA   032 153 146 20 99 92 JSR &9299
B8CD   176 010 B0 0A BCS 10 --> &B8D9
B8CF   032 153 146 20 99 92 JSR &9299
B8D2   144 251 90 FB BCC -5 --> &B8CF
B8D4   162 255 A2 FF LDX#&FF
B8D6 M 134 077 86 4D STX &4D
B8D8   024 18 CLC
B8D9   008 08 PHP
B8DA L 006 076 06 4C ASL &4C
B8DC ( 040 28 PLP
B8DD fL 102 076 66 4C ROR &4C
B8DF , 201 044 C9 2C CMP#&2C ','
B8E1   240 231 F0 E7 BEQ -25 --> &B8CA
B8E3 ; 201 059 C9 3B CMP#&3B ';'
B8E5   240 227 F0 E3 BEQ -29 --> &B8CA
B8E7   198 010 C6 0A DEC &0A
B8E9 L 165 076 A5 4C LDA &4C
B8EB H 072 48 PHA
B8EC M 165 077 A5 4D LDA &4D
B8EE H 072 48 PHA
B8EF   032 174 152 20 AE 98 JSR &98AE Evaluate variable name & create if new variable
B8F2   240 190 F0 BE BEQ -66 --> &B8B2 exit & process next statement
B8F4 h 104 68 PLA
B8F5 M 133 077 85 4D STA &4D
B8F7 h 104 68 PLA
B8F8 L 133 076 85 4C STA &4C
B8FA u 032 117 146 20 75 92 JSR &9275 PTR A Offset = PTR B offset
B8FD   008 08 PHP
B8FE $L 036 076 24 4C BIT &4C
B900 p 112 006 70 06 BVS 6 --> &B908
B902 M 165 077 A5 4D LDA &4D
B904   201 255 C9 FF CMP#&FF
B906   208 023 D0 17 BNE 23 --> &B91F
B908 $L 036 076 24 4C BIT &4C
B90A   016 005 10 05 BPL 5 --> &B911
B90C ? 169 063 A9 3F LDA#&3F '?'
B90E   032 238 255 20 EE FF JSR &FFEE OSBYTE
B911 p 032 112 186 20 70 BA JSR &BA70
B914 6 132 054 84 36 STY &36
B916 L 006 076 06 4C ASL &4C
B918   024 18 CLC
B919 fL 102 076 66 4C ROR &4C
B91B $L 036 076 24 4C BIT &4C
B91D p 112 025 70 19 BVS 25 --> &B938
B91F   133 027 85 1B STA &1B
B921 d 100 025 64 19 STZ &19
B923   169 006 A9 06 LDA#&06
B925   133 026 85 1A STA &1A
B927   032 248 172 20 F8 AC JSR &ACF8 Extract next field (PTR B)
B92A   032 235 142 20 EB 8E JSR &8EEB Get next non-space char (PTR B) & compare with ','
B92D   240 006 F0 06 BEQ 6 --> &B935
B92F   201 013 C9 0D CMP#&0D
B931   208 247 D0 F7 BNE -9 --> &B92A
B933   160 254 A0 FE LDY#&FE
B935   200 C8 INY
B936 M 132 077 84 4D STY &4D
B938 ( 040 28 PLP
B939   176 011 B0 0B BCS 11 --> &B946
B93B C 032 067 188 20 43 BC JSR &BC43 Push &2A, &2B & &2C to the 6502 Stack
B93E N 032 078 171 20 4E AB JSR &AB4E ASCNUM (Convert ASCII String to Numeric value)
B941 + 032 043 179 20 2B B3 JSR &B32B Set numeric variable
B944   128 132 80 84 BRA -124 --> &B8CA
B946 d' 100 039 64 27 STZ &27
B948   032 174 144 20 AE 90 JSR &90AE Set String variable
B94B   128 247 80 F7 BRA -9 --> &B944

9299

9299   032 224 142 20 E0 8E JSR &8EE0 Get next non-space char (PTR A)
929C z 032 122 146 20 7A 92 JSR &927A Check for "'", 'TAB(' or 'SPC'
929F   144 242 90 F2 BCC -14 --> &9293 [RTS]
92A1 " 201 034 C9 22 CMP#&22
92A3   208 237 D0 ED BNE -19 --> &9292 [SEC : RTS]
92A5   200 C8 INY
92A6   177 025 B1 19 LDA (&19),Y
92A8   201 013 C9 0D CMP#&0D
92AA   240 232 F0 E8 BEQ -24 --> &9294 'Missing "' error
92AC " 201 034 C9 22 CMP#&22
92AE   208 009 D0 09 BNE 9 --> &92B9
92B0   200 C8 INY
92B1   132 027 84 1B STY &1B
92B3   177 025 B1 19 LDA (&19),Y
92B5 " 201 034 C9 22 CMP#&22
92B7   208 177 D0 B1 BNE -79 --> &926A Clear carry flag, Set PTR A offset = PTR B offset & exit
92B9   032 152 189 20 98 BD JSR &BD98 Output character in A
92BC   128 231 80 E7 BRA -25 --> &92A5

BA70 Prompt for and get the user's input line

BA70   169 006 A9 06 LDA#&06
BA72   128 002 80 02 BRA 2 --> &BA76
BA74   169 007 A9 07 LDA#&07
BA76 d7 100 055 64 37 STZ &37
BA78 8 133 056 85 38 STA &38
BA7A   169 238 A9 EE LDA#&EE
BA7C 9 133 057 85 39 STA &39
BA7E   169 032 A9 20 LDA#&20
BA80 : 133 058 85 3A STA &3A
BA82   160 255 A0 FF LDY#&FF
BA84 ; 132 059 84 3B STY &3B
BA86   200 C8 INY
BA87 7 162 055 A2 37 LDX#&37
BA89   152 98 TYA
BA8A   032 241 255 20 F1 FF JSR &FFF1 OSWORD
BA8D   144 006 90 06 BCC 6 --> &BA95 Zero COUNT (&1E) and exit routine
BA8F L} 076 125 155 4C 7D 9B JMP &9B7D Escape error

 


 Back to 8BS
Or