Prev: 10577 Up: Map Next: 10834
10646: 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 10646 XOR A Clear the array flag.
10647 LD B,A Clear the B register for later.
10648 BIT 7,C Jump forward if syntax is being checked.
10650 JR NZ,SV_COUNT
Next, simple strings are separated from array variables.
10652 BIT 7,(HL) Jump forward if dealing with an array variable.
10654 JR NZ,SV_ARRAYS
The parameters for a simple string are readily found.
10656 INC A Signal 'a simple string'.
SV_SIMPLE 10657 INC HL Move along the entry.
10658 LD C,(HL) Pick up the low length counter.
10659 INC HL Advance the pointer.
10660 LD B,(HL) Pick up the high length pointer.
10661 INC HL Advance the pointer.
10662 EX DE,HL Transfer the pointer to the actual string.
10663 CALL STK_STO Pass these parameters to the calculator stack.
10666 RST 24 Fetch the present character and jump forward to see if a 'slice' is required.
10667 JP SV_SLICE2
The base address of an element in an array is now found. Initially the 'number of dimensions' is collected.
SV_ARRAYS 10670 INC HL Step past the length bytes.
10671 INC HL
10672 INC HL
10673 LD B,(HL) Collect the 'number of dimensions'.
10674 BIT 6,C Jump forward if handling an array of numbers.
10676 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.
10678 DEC B Decrease the 'number of dimensions' and jump if the number is now zero.
10679 JR Z,SV_SIMPLE
Next a check is made to ensure that in the BASIC line the variable is followed by a subscript.
10681 EX DE,HL Save the pointer in DE.
10682 RST 24 Get the present character.
10683 CP "(" Is it a '('?
10685 JR NZ,REPORT_3 Report the error if it is not so.
10687 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 10688 EX DE,HL Pass the pointer to DE.
10689 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 10691 PUSH HL Save the counter.
10692 RST 24 Get the present character.
10693 POP HL Restore the counter.
10694 CP "," Is the present character a ','?
10696 JR Z,SV_LOOP Jump forward to consider another subscript.
10698 BIT 7,C If a line is being executed then there is an error.
10700 JR Z,REPORT_3
10702 BIT 6,C Jump forward if dealing with an array of strings.
10704 JR NZ,SV_CLOSE
10706 CP ")" Is the present character a ')'?
10708 JR NZ,SV_RPT_C Report an error if not so.
10710 RST 32 Advance CH-ADD.
10711 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 10712 CP ")" Is the present character a ')'?
10714 JR Z,SV_DIM Jump forward and check whether there is another subscript.
10716 CP 204 Is the present character a 'TO'?
10718 JR NZ,SV_RPT_C It must not be otherwise.
SV_CH_ADD 10720 RST 24 Get the present character.
10721 DEC HL Point to the preceding character and set CH-ADD.
10722 LD (23645),HL
10725 JR SV_SLICE Evaluate the 'slice'.
Enter the loop here.
SV_COUNT 10727 LD HL,0 Set the counter to zero.
SV_LOOP 10730 PUSH HL Save the counter briefly.
10731 RST 32 Advance CH-ADD.
10732 POP HL Restore the counter.
10733 LD A,C Fetch the discriminator byte.
10734 CP 192 Jump unless checking the syntax for an array of strings.
10736 JR NZ,SV_MULT
10738 RST 24 Get the present character.
10739 CP ")" Is it a ')'?
10741 JR Z,SV_DIM Jump forward as finished counting elements.
10743 CP 204 Is to 'TO'?
10745 JR Z,SV_CH_ADD Jump back if dealing with a 'slice'.
SV_MULT 10747 PUSH BC Save the dimension-number counter and the discriminator byte.
10748 PUSH HL Save the element-counter.
10749 CALL DE_DE_1 Get a dimension-size into DE.
10752 EX (SP),HL The counter moves to HL and the variable pointer is stacked.
10753 EX DE,HL The counter moves to DE and the dimension-size to HL.
10754 CALL INT_EXP1 Evaluate the next subscript.
10757 JR C,REPORT_3 Give an error if out of range.
10759 DEC BC The result of the evaluation is decremented as the counter is to count the elements occurring before the specified element.
10760 CALL GET_HLxDE Multiply the counter by the dimension-size.
10763 ADD HL,BC Add the result of INT_EXP1 to the present counter.
10764 POP DE Fetch the variable pointer.
10765 POP BC Fetch the dimension-number and the discriminator byte.
10766 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.
10768 BIT 7,C Report an error if checking syntax at this point.
SV_RPT_C 10770 JR NZ,SL_RPT_C
10772 PUSH HL Save the counter.
10773 BIT 6,C Jump forward if handling an array of strings.
10775 JR NZ,SV_ELEM
When dealing with an array of numbers the present character must be a ')'.
10777 LD B,D Transfer the variable pointer to the BC register pair.
10778 LD C,E
10779 RST 24 Fetch the present character.
10780 CP ")" Is it a ')'?
10782 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 10784 RST 8 Call the error handling routine.
10785 DEFB 2
The address of the location before the actual floating-point form can now be calculated.
SV_NUMBER 10786 RST 32 Advance CH-ADD.
10787 POP HL Fetch the counter.
10788 LD DE,5 There are 5 bytes to each element in an array of numbers.
10791 CALL GET_HLxDE Compute the total number of bytes before the required element.
10794 ADD HL,BC Make HL point to the location before the required element.
10795 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 10796 CALL DE_DE_1 Fetch the last dimension-size.
10799 EX (SP),HL The variable pointer goes on the stack and the counter to HL.
10800 CALL GET_HLxDE Multiply 'counter' by 'dimension-size'.
10803 POP BC Fetch the variable pointer.
10804 ADD HL,BC This gives HL pointing to the location before the string.
10805 INC HL So point to the actual 'start'.
10806 LD B,D Transfer the last dimension-size to BC to form the 'length'.
10807 LD C,E
10808 EX DE,HL Move the 'start' to DE.
10809 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.
10812 RST 24 Get the present character.
10813 CP ")" Is it a ')'?
10815 JR Z,SV_DIM Jump if it is so.
10817 CP "," Is it a ','?
10819 JR NZ,REPORT_3 Report the error if not so.
SV_SLICE 10821 CALL SLICING Use SLICING to modify the set of parameters.
SV_DIM 10824 RST 32 Fetch the next character.
SV_SLICE2 10825 CP "(" Is It a '('?
10827 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.
10829 RES 6,(IY+1) Signal - string result (reset bit 6 of FLAGS).
10833 RET Return with the parameters of the required string forming a 'last value' on the calculator stack.
Prev: 10577 Up: Map Next: 10834