×   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

B1F7 Load SWA with String value

Submitted by Steve Fewell

Routine:loadstring
Name: Load String value
Starting Address: &B1F7
Entry criteria: &2A and &2B point to the address of the variable's value; or
&2B contains 0 and &2A contains the character for a 1-character string.
Y is &80 for a 1 character string or a String input that is terminated with &0D.
Y is anything else (probably &81) for a String variable).
Exit: The SWA contains the value of the variable.

Description:

If Y is &80 then the value is either a string input (which is terminated by a carriage return
(<CR> character) or a single character (determined by the address MSB being zero).
Otherwise (Y is &81) the string value is a String variable.
Each of these cases is explained in their own section below:

String Variable
The address pointed to by (&2A, &2B) is the string parameter block.
The first 2 bytes of this parameter block point to the address of the String value
[first byte = Low byte, second byte = High byte of address].
The third byte contains the maximum size allocated to the string value (not needed during
the Load operation).
The forth byte contains the current length of the string.
To load the string variable, the following is done:
* Store the forth byte of the parameter block (length of string) in &36 (length of SWA).
* Set (&37 and &38) to the address of the string value (low byte first).
* Load each character of the string value (last character first), and store the character
at the appropriate SWA potition.
* Exit with A = &00 (indicating a string result) when the entire string has been copied
to the SWA.

String Input (terminated by a carriage return character)
The address pointed to by (&2A, &2B) is the first character of the value.
Store each character of the value in the next available SWA position (Starting at &0600).
When a &0D (carriage return) character is found then store the &0D character in the SWA,
stop getting further characters, set &36 to the current SWA position and exit.
After 255 characters have been processed, without a &0D character being found,
exit with A = &00 and &36 (SWA length) also set to zero.

Single Character value
&2A contains the character to place in the SWA and &2B contains zero.
Load A with the character (&2A) and jump to &AE6C (part of GET$) to put
the ASCII character (in A) into the SWA, set the SWA length (&36 to 1) and exit
with A = &00 (as the result is a string value).


Disassembly for the Load SWA with String value routine

B1F7   192 128 C0 80 CPY#&80
B1F9   240 030 F0 1E BEQ 30 --> &B219 Load SWA with String input (terminated with <CR>) or a 1 char value
B1FB   160 003 A0 03 LDY#&03
B1FD * 177 042 B1 2A LDA (&2A),Y
B1FF 6 133 054 85 36 STA &36
B201   240 021 F0 15 BEQ 21 --> &B218
B203   160 001 A0 01 LDY#&01
B205 * 177 042 B1 2A LDA (&2A),Y
B207 8 133 056 85 38 STA &38
B209 * 178 042 B2 2A LDA (&2A)
B20B 7 133 055 85 37 STA &37
B20D 6 164 054 A4 36 LDY &36
B20F   136 88 DEY
B210 7 177 055 B1 37 LDA (&37),Y
B212   153 000 006 99 00 06 STA &0600,Y
B215   152 98 TYA
B216   208 247 D0 F7 BNE -9 --> &B20F
B218 ` 096 60 RTS
B219 + 165 043 A5 2B LDA &2B
B21B   240 021 F0 15 BEQ 21 --> &B232 Set SWA to 1-character value
B21D   160 000 A0 00 LDY#&00
B21F * 177 042 B1 2A LDA (&2A),Y
B221   153 000 006 99 00 06 STA &0600,Y
B224 I 073 013 49 0D EOR#&0D
B226   240 004 F0 04 BEQ 4 --> &B22C
B228   200 C8 INY
B229   208 244 D0 F4 BNE -12 --> &B21F
B22B   152 98 TYA
B22C 6 132 054 84 36 STY &36
B22E ` 096 60 RTS

 


 Back to 8BS
Or