Prev: 13769 Up: Map Next: 13855
13790: THE 'VAL' AND 'VAL$' FUNCTIONS (offsets 24, 29)
The address of this routine is found in the table of addresses. It is called indirectly via fp_calc_2.
This subroutine handles the functions VAL X$ and VAL$ X$. When handling VAL X$, it returns a 'last value' that is the result of evaluating the string (without its bounding quotes) as a numerical expression. when handling VAL$ X$, it evaluates X$ (without its bounding quotes) as a string expression, and returns the parameters of that string expression as a 'last value' on the calculator stack.
Input
B Offset (24 or 29)
val 13790 LD HL,(23645) The current value of CH-ADD is preserved on the machine stack.
13793 PUSH HL
13794 LD A,B The 'offset' for 'val' or 'val$' must be in the B register; it is now copied to A.
13795 ADD A,227 Produce 0 and carry set for 'val', 251 and carry reset for 'val$'.
13797 SBC A,A Produce 255 (bit 6 therefore set) for 'val', but 0 (bit 6 reset) for 'val$'.
13798 PUSH AF Save this 'flag' on the machine stack.
13799 CALL STK_FETCH The parameters of the string are fetched; the starting address is saved; one byte is added to the length and room made available for the string (+1) in the work space.
13802 PUSH DE
13803 INC BC
13804 RST 48
13805 POP HL The starting address of the string goes to HL as a source address.
13806 LD (23645),DE The pointer to the first new space goes to CH-ADD and to the machine stack.
13810 PUSH DE
13811 LDIR The string is copied to the work space, together with an extra byte.
13813 EX DE,HL Switch the pointers.
13814 DEC HL The extra byte is replaced by a 'carriage return' character.
13815 LD (HL),13
13817 RES 7,(IY+1) The syntax flag (bit 7 of FLAGS) is reset and the string is scanned for correct syntax.
13821 CALL SCANNING
13824 RST 24 The character after the string is fetched.
13825 CP 13 A check is made that the end of the expression has been reached.
13827 JR NZ,V_RPORT_C If not, the error is reported.
13829 POP HL The starting address of the string is fetched.
13830 POP AF The 'flag' for 'val/val$' is fetched and bit 6 is compared with bit 6 of the result (FLAGS) of the syntax scan.
13831 XOR (IY+1)
13834 AND 64
V_RPORT_C 13836 JP NZ,REPORT_C Report the error if they do not match.
13839 LD (23645),HL Start address to CH-ADD again.
13842 SET 7,(IY+1) The flag (bit 7 of FLAGS) is set for line execution.
13846 CALL SCANNING The string is treated as a 'next expression' and a 'last value' produced.
13849 POP HL The original value of CH-ADD is restored.
13850 LD (23645),HL
13853 JR STK_PNTRS The subroutine exits via STK_PNTRS which resets the pointers.
Prev: 13769 Up: Map Next: 13855