×   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

98AE Evaluate variable name & Create if new variable

Submitted by Steve Fewell

Routine:CreateNewVariable
Name: Evaluate variable name & Create if new variable
Starting Address: &98AE
Entry criteria: The BASIC Text Pointer A points to the start of a variable name.
Exit: The Variable has been created (or no action if it already exists).
Zero flag is set if the variable name was not valid (Syntax error).
C = 0 if the variable is numerical; otherwise, C = 1 (for String variable).

Description:

Call routine &98F5 to reset the BASIC Text pointer B to the BASIC Text pointer A location,
and evaluate the variable name at that location.
If the variable name is already allocated then exit [A = non zero, BNE).
If the variable name is a direct memory access (? or !) then exit [A = non zero].
If the variable name is not a valid name then exit [Carry flag is set].

Othwise, the variable doesn't exist yet, so it needs to be created.
So, call &9854 to add the variable name to the variable pointer table.
Next, If the variable type is not 5 then call &9883 with X = 4 (Integer/String).
Otherwise, increment X to 5, and call &9883. &9883 will allocate parameter
block space for the new variable.

Next, call &98F5 again to evaluate the variable name again and set &2A, &2B to
point to the variable's value and set &2C to the variable type.
We need to call &98F5 again, as we would not have the variable vaue address in &2A-&2B if
we didn't.


Disassembly for the Evaluate variable name & Create if new variable routine

98AB   032 131 152 20 83 98 JSR &9883 Allocate space for variable
98AE   032 245 152 20 F5 98 JSR &98F5 PtrB=PtrA & evaluate variable name & obtain address of value
98B1   208 029 D0 1D BNE 29 --> &98D0   [RTS]
98B3   176 027 B0 1B BCS 27 --> &98D0   [RTS]
98B5 T 032 084 152 20 54 98 JSR &9854 Create new variable name in variable pointer table
98B8   162 005 A2 05 LDX#&05
98BA , 228 044 E4 2C CPX &2C
98BC   208 237 D0 ED BNE -19 --> &98AB
98BE   232 E8 INX
98BF   128 234 80 EA BRA -22 --> &98AB

 


 Back to 8BS
Or