×   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

9703 LOCAL

Submitted by Steve Fewell

Description:

[&9703] If the 6502 Stack pointer address is not less than #&FC, then we are not inside a Subroutine call (as a
subroutine call pushes 4 bytes of information to the 6502 stack), so issue 'Not LOCAL' error.

Call routine &98AE to evaluate the variable name following the LOCAL-keyword and create the variable if it has not been
created yet.
If the zero flag is set on return from &98AE then the variable name is not valid, so jump to &9002 to issue
'Syntax error', unless the end of statement (either a carriage return, ELSE-token or ':' character) is found. This means
that a LOCAL-keyword without any following variable names is valid, but has no effect.

Call routine &B181 to load the variable's value and push the value to the BASIC stack and then push the variable's
value address (&2A-&2B) and variable's type (&2C) to the BASIC Stack.

Set Y to the value at location &2C, which is the Variable's type.
If Y is negative (variable is a String), then jump to &96FB to store zero in the 3rd byte of the variable's value
parameter block (the location pointed to by the address stored in &2A-&2B + 3) and then jump to location &971F to
continue the LOCAL-statement. This initialises the String variable to null (i.e. String value is zero characters long).

If Y is not negative (i.e. the variable's type is Floating-Point or Integer) so:
* Call routine &BC43 to push the variable's address (&2A-&2B) and type (&2C) details to
    the 6502 stack.
* Call routine &ABE8 to set the IWA to FALSE (i.e. Set the IWA value to zero).
* Set location &27 to the type of the current value (i.e. #&40 (the value in A), as the current
    value is an Integer, and is stored in the IWA.
* Call routine &B32B to set the Numeric variable (retrieving the variable value address and type stored
    on the 6502 stack) to the current value (i.e. zero), converting the current value to Integer/Float as required.

[&971F] Increment the number of arguments/local variables in the subroutine by incrementing the 6th byte from the
current position on the 6502 stack (i.e. the location pointed to by the Stack pointer value + &0106 (i.e. location
&01FB in the table below)).
I.e. The BASIC stack should contain the following information:
Address &01FF - The Subroutine type - FN/PROC (i.e. either the PROC token or the FN token)
Address &01FE - The address to return to once the subroutine has executed (PTR A) - Offset (&0A)
Address &01FD - The address to return to once the subroutine has executed (PTR A) - LSB (&0B)
Address &01FC - The address to return to once the subroutine has executed (PTR A) - MSB (&0C)
Address &01FB - The number of Arguments or LOCAL variables used by the Subroutine
Address &01FA - BASIC Text Pointer B - LSB (&19)
Address &01F9 - BASIC Text Pointer B - MSB (&1A)
Address &01F8 - BASIC Text Pointer B - Offset (&1B)
Address &01F7 - Return address for the JSR &900B statement in the Call Subroutine routine - LSB
Address &01F6 - Return address for the JSR &900B statement in the Call Subroutine routine - MSB
Address &01F5 - <The next free Stack position - pointed to by the 6502 Stack Pointer>
[&9723] Set the BASIC Text Pointer A offset to the BASIC Text Pointer B value - to update the Text pointer A, so
that it now points to the program location after the variable name.
Get the next character pointed to by BASIC Text Pointer A; if it is a Comma (as checked by routine &8CE5), then jump
back to &9703 (the beginning of the LOCAL routine) to declare the next LOCAL variable.

Otherwise, jump to &9000 to check for end of statement (check that statement is followed by a ':', carriage return or
'ELSE-token' character), [issuing 'Syntax error' if the statement was not terminated correctly], and continue to execute
the next program statement.


Disassembly for the LOCAL routine

96FB   160 003 A0 03 LDY#&03
96FD   169 000 A9 00 LDA#&00
96FF * 145 042 91 2A STA (&2A),Y
9701   240 028 F0 1C BEQ 28 --> &971F
9703   186 BA TSX
9704   224 252 E0 FC CPX#&FC
9706 * 176 042 B0 2A BCS 42 --> &9732 'Not LOCAL' error
9708   032 174 152 20 AE 98 JSR &98AE Evaluate variable name & create it if it's a new variable
970B " 240 034 F0 22 BEQ 34 --> &972F   (issue 'Syntax error' if not end of statement)
970D   032 129 177 20 81 B1 JSR &B181 Load Variable & Push its value, address and type to the BASIC Stack
9710 , 164 044 A4 2C LDY &2C
9712 0 048 231 30 E7 BMI -25 --> &96FB Check whether there are any more LOCAL variables to declare (if so then declare them)
9714 C 032 067 188 20 43 BC JSR &BC43 Push &2A, &2B & &2C (the variable info) to the 6502 Stack
9717   032 232 171 20 E8 AB JSR &ABE8 Set IWA to FALSE (0)
971A ' 133 039 85 27 STA &27
971C + 032 043 179 20 2B B3 JSR &B32B Set numeric variable
971F   186 BA TSX
9720   254 006 001 FE 06 01 INC &0106,X
9723   164 027 A4 1B LDY &1B
9725   132 010 84 0A STY &0A
9727   032 229 140 20 E5 8C JSR &8CE5 Compare next non-space [PTR A] character with ','
972A   240 215 F0 D7 BEQ -41 --> &9703 LOCAL (Declare LOCAL variable)
972C L 076 000 144 4C 00 90 JMP &9000   Check end of statement & execute the next statement on the Command/Program line
972F L 076 002 144 4C 02 90 JMP &9002 'Syntax error' if not end of statement; otherwise, execute next statement/program line

 


 Back to 8BS
Or