×   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

AF1C STR$

Submitted by Steve Fewell

Description:

Set Y to #&FE (meaning that Hexadecimal output of the value is required).
Get the next non-space character after the STR$-token.
If the next charaxcter is not a '~' (tilde), then set Y to 0 (meaning that decimal output of the numeric
value is required), and decrement &1B (BASIC Text Pointer B offset) so that the non-space character
we obtained will be the first one read by the Get value routine (&AD36).
Store Y to the stack, while we get the value.
Call the Get Value routine (&AD36) to return the value pointed to by the BASIC Test Pointer B.
A single value will be returned. If the value starts with an open bracket ("("), then the expression
within the brackets will be evaluated.
If the type of the returned value (A) is 0 (String), then the value is not numeric, so generate a Type mismatch
error.

Otherwise, retrieve the byte from the stack and store the value in location &15. The ASCNUM routine will
use this value to determine whether the numeric value will be converted to a Hexadecimal String or a Decimal String.
Set Y to the type of the variable returned from the Get value routine (A).

If the 4th byte of @% (&0403) is not zero then the @%-number format settings will be used in the conversion of
the numeric value, so call NUMASC routine (at location &A118) to convert the numeric value to an ASCII
string (located in the SWA), Set A to 0 (meaning that the Current value is a String) and exit.

If the 4th byte of @% (&0403) is zero then the @%-number format settings will not be used in the conversion of
the numeric value, so set &37 to 0 (Output format type = General) and call NUMASC routine (at location &A132)
convert the numeric value to an ASCII string (located in the SWA), Set A to 0 (meaning that the Current
value is a String) and exit.


Disassembly for the STR$ routine

AF1C   032 213 142 20 D5 8E JSR &8ED5 Get next non-space character (PTR B)
AF1F   160 255 A0 FF LDY#&FF
AF21 ~ 201 126 C9 7E CMP#&7E '~'
AF23   240 004 F0 04 BEQ 4 --> &AF29
AF25   160 000 A0 00 LDY#&00
AF27   198 027 C6 1B DEC &1B
AF29 Z 090 5A PHY
AF2A 6 032 054 173 20 36 AD JSR &AD36 Get value / result of expression (if bracketed)
AF2D   240 021 F0 15 BEQ 21 --> &AF44 Type Mismatch error
AF2F   168 A8 TAY
AF30 h 104 68 PLA
AF31   133 021 85 15 STA &15
AF33   173 003 004 AD 03 04 LDA &0403
AF36   208 007 D0 07 BNE 7 --> &AF3F
AF38 7 133 055 85 37 STA &37
AF3A 2 032 050 161 20 32 A1 JSR &A132 ASCNUM (Convert number to ASCII) [Skip @%-format settings]
AF3D ; 128 059 80 3B BRA 59 --> &AF7A [LDA#&00 : RTS]
AF3F   032 024 161 20 18 A1 JSR &A118 ASCNUM (Convert number to ASCII) [With @%-format settings]
AF42 6 128 054 80 36 BRA 54 --> &AF7A [LDA#&00 : RTS]
AF44 L 076 146 144 4C 92 90 JMP &9092 Type mismatch error

 


 Back to 8BS
Or