Prev: 1F54 Up: Map Next: 1FC3
1F60: THE 'DEF FN' COMMAND ROUTINE
The address of this routine is found in the parameter table.
During syntax checking a DEF FN statement is checked to ensure that it has the correct form. Space is also made available for the result of evaluating the function.
But in 'run-time' a DEF FN statement is passed by.
Input
A Code of the next character in the statement
DEF_FN 1F60 CALL SYNTAX_Z Jump forward if checking syntax.
1F63 JR Z,DEF_FN_1
1F65 LD A,$CE Otherwise pass by the 'DEF FN' statement.
1F67 JP PASS_BY
First consider the variable of the function.
DEF_FN_1 1F6A SET 6,(IY+$01) Signal 'a numeric variable' (set bit 6 of FLAGS).
1F6E CALL ALPHA Check that the present code is a letter.
1F71 JR NC,DEF_FN_4 Jump forward if not.
1F73 RST $20 Fetch the next character.
1F74 CP "$" Jump forward unless it is a '$'.
1F76 JR NZ,DEF_FN_2
1F78 RES 6,(IY+$01) Reset bit 6 of FLAGS as it is a string variable.
1F7C RST $20 Fetch the next character.
DEF_FN_2 1F7D CP "(" A '(' must follow the variable's name.
1F7F JR NZ,DEF_FN_7
1F81 RST $20 Fetch the next character.
1F82 CP ")" Jump forward if it is a ')' as there are no parameters of the function.
1F84 JR Z,DEF_FN_6
A loop is now entered to deal with each parameter in turn.
DEF_FN_3 1F86 CALL ALPHA The present code must be a letter.
DEF_FN_4 1F89 JP NC,REPORT_C
1F8C EX DE,HL Save the pointer in DE.
1F8D RST $20 Fetch the next character.
1F8E CP "$" Jump forward unless it is a '$'.
1F90 JR NZ,DEF_FN_5
1F92 EX DE,HL Otherwise save the new pointer in DE instead.
1F93 RST $20 Fetch the next character.
DEF_FN_5 1F94 EX DE,HL Move the pointer to the last character of the name to the HL register pair.
1F95 LD BC,$0006 Now make six locations after that last character and enter a 'number marker' into the first of the new locations.
1F98 CALL MAKE_ROOM
1F9B INC HL
1F9C INC HL
1F9D LD (HL),$0E
1F9F CP "," If the present character is a ',' then jump back as there should be a further parameter; otherwise jump out of the loop.
1FA1 JR NZ,DEF_FN_6
1FA3 RST $20
1FA4 JR DEF_FN_3
Next the definition of the function is considered.
DEF_FN_6 1FA6 CP ")" Check that the ')' does exist.
1FA8 JR NZ,DEF_FN_7
1FAA RST $20 The next character is fetched.
1FAB CP "=" It must be an '='.
1FAD JR NZ,DEF_FN_7
1FAF RST $20 Fetch the next character.
1FB0 LD A,($5C3B) Save the nature - numeric or string - of the variable (bit 6 of FLAGS).
1FB3 PUSH AF
1FB4 CALL SCANNING Now consider the definition as an expression.
1FB7 POP AF Fetch the nature of the variable and check that it is of the same type as found for the definition (specified by bit 6 of FLAGS).
1FB8 XOR (IY+$01)
1FBB AND $40
DEF_FN_7 1FBD JP NZ,REPORT_C Give an error report if it is required.
1FC0 CALL CHECK_END Exit via CHECK_END (thereby moving on to consider the next statement in the line).
This routine continues into UNSTACK_Z.
Prev: 1F54 Up: Map Next: 1FC3