Prev: 2951 Up: Map Next: 2A52
2996: THE 'STK-VAR' SUBROUTINE
Used by the routines at VAR_A_1, S_LETTER and DIM.
This subroutine is used either to find the parameters that define an existing string entry in the variables area, or to return in the HL register pair the base address of a particular element or an array of numbers. When called from DIM the subroutine only checks the syntax of the BASIC statement.
Note that the parameters that define a string may be altered by calling SLICING if this should be specified.
Initially the A and the B registers are cleared and bit 7 of the C register is tested to determine whether syntax is being checked.
Input
C Bit 5: Set if the variable is numeric, reset if it's a string
C Bit 6: Set if the variable is simple, reset if it's an array
C Bit 7: Set if checking syntax, reset if executing
HL Address of the last letter of the variable's name (in the variables area)
STK_VAR 2996 XOR A Clear the array flag.
2997 LD B,A Clear the B register for later.
2998 BIT 7,C Jump forward if syntax is being checked.
299A JR NZ,SV_COUNT
Next, simple strings are separated from array variables.
299C BIT 7,(HL) Jump forward if dealing with an array variable.
299E JR NZ,SV_ARRAYS
The parameters for a simple string are readily found.
29A0 INC A Signal 'a simple string'.
SV_SIMPLE 29A1 INC HL Move along the entry.
29A2 LD C,(HL) Pick up the low length counter.
29A3 INC HL Advance the pointer.
29A4 LD B,(HL) Pick up the high length pointer.
29A5 INC HL Advance the pointer.
29A6 EX DE,HL Transfer the pointer to the actual string.
29A7 CALL STK_STO Pass these parameters to the calculator stack.
29AA RST $18 Fetch the present character and jump forward to see if a 'slice' is required.
29AB JP SV_SLICE2
The base address of an element in an array is now found. Initially the 'number of dimensions' is collected.
SV_ARRAYS 29AE INC HL Step past the length bytes.
29AF INC HL
29B0 INC HL
29B1 LD B,(HL) Collect the 'number of dimensions'.
29B2 BIT 6,C Jump forward if handling an array of numbers.
29B4 JR Z,SV_PTR
If an array of strings has its 'number of dimensions' equal to '1' then such an array can be handled as a simple string.
29B6 DEC B Decrease the 'number of dimensions' and jump if the number is now zero.
29B7 JR Z,SV_SIMPLE
Next a check is made to ensure that in the BASIC line the variable is followed by a subscript.
29B9 EX DE,HL Save the pointer in DE.
29BA RST $18 Get the present character.
29BB CP "(" Is it a '('?
29BD JR NZ,REPORT_3 Report the error if it is not so.
29BF EX DE,HL Restore the pointer.
For both numeric arrays and arrays of strings the variable pointer is transferred to the DE register pair before the subscript is evaluated.
SV_PTR 29C0 EX DE,HL Pass the pointer to DE.
29C1 JR SV_COUNT Jump forward.
The following loop is used to find the parameters of a specified element within an array. The loop is entered at the mid-point - SV_COUNT - where the element count is set to zero.
The loop is accessed B times, this being, for a numeric array, equal to the number of dimensions that are being used, but for an array of strings B is one less than the number of dimensions in use as the last subscript is used to specify a 'slice' of the string.
SV_COMMA 29C3 PUSH HL Save the counter.
29C4 RST $18 Get the present character.
29C5 POP HL Restore the counter.
29C6 CP "," Is the present character a ','?
29C8 JR Z,SV_LOOP Jump forward to consider another subscript.
29CA BIT 7,C If a line is being executed then there is an error.
29CC JR Z,REPORT_3
29CE BIT 6,C Jump forward if dealing with an array of strings.
29D0 JR NZ,SV_CLOSE
29D2 CP ")" Is the present character a ')'?
29D4 JR NZ,SV_RPT_C Report an error if not so.
29D6 RST $20 Advance CH-ADD.
29D7 RET Return as the syntax is correct.
For an array of strings the present subscript may represent a 'slice', or the subscript for a 'slice' may yet be present in the BASIC line.
SV_CLOSE 29D8 CP ")" Is the present character a ')'?
29DA JR Z,SV_DIM Jump forward and check whether there is another subscript.
29DC CP $CC Is the present character a 'TO'?
29DE JR NZ,SV_RPT_C It must not be otherwise.
SV_CH_ADD 29E0 RST $18 Get the present character.
29E1 DEC HL Point to the preceding character and set CH-ADD.
29E2 LD ($5C5D),HL
29E5 JR SV_SLICE Evaluate the 'slice'.
Enter the loop here.
SV_COUNT 29E7 LD HL,$0000 Set the counter to zero.
SV_LOOP 29EA PUSH HL Save the counter briefly.
29EB RST $20 Advance CH-ADD.
29EC POP HL Restore the counter.
29ED LD A,C Fetch the discriminator byte.
29EE CP $C0 Jump unless checking the syntax for an array of strings.
29F0 JR NZ,SV_MULT
29F2 RST $18 Get the present character.
29F3 CP ")" Is it a ')'?
29F5 JR Z,SV_DIM Jump forward as finished counting elements.
29F7 CP $CC Is to 'TO'?
29F9 JR Z,SV_CH_ADD Jump back if dealing with a 'slice'.
SV_MULT 29FB PUSH BC Save the dimension-number counter and the discriminator byte.
29FC PUSH HL Save the element-counter.
29FD CALL DE_DE_1 Get a dimension-size into DE.
2A00 EX (SP),HL The counter moves to HL and the variable pointer is stacked.
2A01 EX DE,HL The counter moves to DE and the dimension-size to HL.
2A02 CALL INT_EXP1 Evaluate the next subscript.
2A05 JR C,REPORT_3 Give an error if out of range.
2A07 DEC BC The result of the evaluation is decremented as the counter is to count the elements occurring before the specified element.
2A08 CALL GET_HLxDE Multiply the counter by the dimension-size.
2A0B ADD HL,BC Add the result of INT_EXP1 to the present counter.
2A0C POP DE Fetch the variable pointer.
2A0D POP BC Fetch the dimension-number and the discriminator byte.
2A0E DJNZ SV_COMMA Keep going round the loop until B equals zero.
The SYNTAX/RUN flag is checked before arrays of strings are separated from arrays of numbers.
2A10 BIT 7,C Report an error if checking syntax at this point.
SV_RPT_C 2A12 JR NZ,SL_RPT_C
2A14 PUSH HL Save the counter.
2A15 BIT 6,C Jump forward if handling an array of strings.
2A17 JR NZ,SV_ELEM
When dealing with an array of numbers the present character must be a ')'.
2A19 LD B,D Transfer the variable pointer to the BC register pair.
2A1A LD C,E
2A1B RST $18 Fetch the present character.
2A1C CP ")" Is it a ')'?
2A1E JR Z,SV_NUMBER Jump past the error report unless it is needed.
This entry point is used by the routines at SLICING and DIM.
Report 3 - Subscript out of range.
REPORT_3 2A20 RST $08 Call the error handling routine.
2A21 DEFB $02
The address of the location before the actual floating-point form can now be calculated.
SV_NUMBER 2A22 RST $20 Advance CH-ADD.
2A23 POP HL Fetch the counter.
2A24 LD DE,$0005 There are 5 bytes to each element in an array of numbers.
2A27 CALL GET_HLxDE Compute the total number of bytes before the required element.
2A2A ADD HL,BC Make HL point to the location before the required element.
2A2B RET Return with this address.
When dealing with an array of strings the length of an element is given by the last 'dimension-size'. The appropriate parameters are calculated and then passed to the calculator stack.
SV_ELEM 2A2C CALL DE_DE_1 Fetch the last dimension-size.
2A2F EX (SP),HL The variable pointer goes on the stack and the counter to HL.
2A30 CALL GET_HLxDE Multiply 'counter' by 'dimension-size'.
2A33 POP BC Fetch the variable pointer.
2A34 ADD HL,BC This gives HL pointing to the location before the string.
2A35 INC HL So point to the actual 'start'.
2A36 LD B,D Transfer the last dimension-size to BC to form the 'length'.
2A37 LD C,E
2A38 EX DE,HL Move the 'start' to DE.
2A39 CALL STK_ST_0 Pass these parameters to the calculator stack. Note: the first parameter is zero indicating a string from an 'array of strings' and hence the existing entry is not to be reclaimed.
There are three possible forms of the last subscript:
  • A$(2,4 TO 8)
  • A$(2)(4 TO 8)
  • A$(2)
The last of these is the default form and indicates that the whole string is required.
2A3C RST $18 Get the present character.
2A3D CP ")" Is it a ')'?
2A3F JR Z,SV_DIM Jump if it is so.
2A41 CP "," Is it a ','?
2A43 JR NZ,REPORT_3 Report the error if not so.
SV_SLICE 2A45 CALL SLICING Use SLICING to modify the set of parameters.
SV_DIM 2A48 RST $20 Fetch the next character.
SV_SLICE2 2A49 CP "(" Is It a '('?
2A4B JR Z,SV_SLICE Jump back if there is a 'slice' to be considered.
When finished considering the last subscript a return can be made.
2A4D RES 6,(IY+$01) Signal - string result (reset bit 6 of FLAGS).
2A51 RET Return with the parameters of the required string forming a 'last value' on the calculator stack.
Prev: 2951 Up: Map Next: 2A52