Prev: 35C9 Up: Map Next: 361F
35DE: THE 'VAL' AND 'VAL$' FUNCTIONS (offsets +18, +1D)
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 (+18 or +1D)
val 35DE LD HL,($5C5D) The current value of CH-ADD is preserved on the machine stack.
35E1 PUSH HL
35E2 LD A,B The 'offset' for 'val' or 'val$' must be in the B register; it is now copied to A.
35E3 ADD A,$E3 Produce +00 and carry set for 'val', +FB and carry reset for 'val$'.
35E5 SBC A,A Produce +FF (bit 6 therefore set) for 'val', but +00 (bit 6 reset) for 'val$'.
35E6 PUSH AF Save this 'flag' on the machine stack.
35E7 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.
35EA PUSH DE
35EB INC BC
35EC RST $30
35ED POP HL The starting address of the string goes to HL as a source address.
35EE LD ($5C5D),DE The pointer to the first new space goes to CH-ADD and to the machine stack.
35F2 PUSH DE
35F3 LDIR The string is copied to the work space, together with an extra byte.
35F5 EX DE,HL Switch the pointers.
35F6 DEC HL The extra byte is replaced by a 'carriage return' character.
35F7 LD (HL),$0D
35F9 RES 7,(IY+$01) The syntax flag (bit 7 of FLAGS) is reset and the string is scanned for correct syntax.
35FD CALL SCANNING
3600 RST $18 The character after the string is fetched.
3601 CP $0D A check is made that the end of the expression has been reached.
3603 JR NZ,V_RPORT_C If not, the error is reported.
3605 POP HL The starting address of the string is fetched.
3606 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.
3607 XOR (IY+$01)
360A AND $40
V_RPORT_C 360C JP NZ,REPORT_C Report the error if they do not match.
360F LD ($5C5D),HL Start address to CH-ADD again.
3612 SET 7,(IY+$01) The flag (bit 7 of FLAGS) is set for line execution.
3616 CALL SCANNING The string is treated as a 'next expression' and a 'last value' produced.
3619 POP HL The original value of CH-ADD is restored.
361A LD ($5C5D),HL
361D JR STK_PNTRS The subroutine exits via STK_PNTRS which resets the pointers.
Prev: 35C9 Up: Map Next: 361F